Example #1
0
        public async Task <TTACPrescriptionResponse> CallPrescriptionApi(TTACPrescriptionRequest prescriptionRequest)
        {
            var res     = new TTACPrescriptionResponse();
            var request = (HttpWebRequest)WebRequest.Create(Constants.TTAC_BaseUrl + Constants.TTAC_RegisterApiName);

            request.Method = "POST";
            //request.Headers.Add("X-SSP-Api-Key", "56c671ff-4cdf-4907-8e7d-3158fa7dec3e");
            request.Headers.Add("X-SSP-Api-Key", Constants.TTAC_RegisterApiKey);
            request.ContentType = @"application/json";

            try
            {
                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    streamWriter.Write(JsonConvert.SerializeObject(prescriptionRequest));
                }

                _rabbitMqService.PublishToQueue(RabbitMQ.Config.RabbitQueue.ElasticLogs, JsonConvert.SerializeObject(request));
                var httpResponse = (HttpWebResponse)(await request.GetResponseAsync().ConfigureAwait(false));
                _rabbitMqService.PublishToQueue(RabbitMQ.Config.RabbitQueue.ElasticLogs, JsonConvert.SerializeObject(httpResponse));
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = await streamReader.ReadToEndAsync().ConfigureAwait(false);

                    JObject jObject = JObject.Parse(result);
                    res.ErrorCode      = int.Parse(jObject["ErrorCode"]?.ToString() ?? "-1");
                    res.ErrorMessage   = jObject["ErrorMessage"]?.ToString() ?? "";
                    res.PrescriptionId = int.Parse(jObject["PrescriptionId"]?.ToString() ?? "0");
                }
            }
            catch (WebException ex)
            {
                res.ErrorCode    = (int)HealthESBApiResponseCode.ServiceProviderNotResponse;
                res.ErrorMessage = HealthESBApiResponseMessages.ServiceProviderNotResponse;
            }

            return(res);
        }