コード例 #1
0
        public async Task <TTACPrescriptionBarcodeResponse> CallCheckSingleBarcodeApi(TTACPrescriptionBarcodeRequest tTACPrescriptionBarcodeRequest)
        {
            var res     = new TTACPrescriptionBarcodeResponse();
            var request = (HttpWebRequest)WebRequest.Create(Constants.TTAC_BaseUrl + Constants.TTAC_CheckApiName);

            request.Method = "POST";
            request.Headers.Add("X-SSP-Api-Key", Constants.TTAC_CheckApiKey);
            request.ContentType = @"application/json";

            try
            {
                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    streamWriter.Write(JsonConvert.SerializeObject(tTACPrescriptionBarcodeRequest));
                }
                var httpResponse = (HttpWebResponse)(await request.GetResponseAsync().ConfigureAwait(false));
                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");
                    if (jObject["ItemsInfo"].ToString() != "[]")
                    {
                        res.ItemsInfo = new List <TTACPrescriptionBarcodeDetailesResponse>();
                        JToken jInfo = jObject["ItemsInfo"];
                        for (int i = 0; i < jInfo.Count(); i++)
                        {
                            TTACPrescriptionBarcodeDetailesResponse tTACPrescriptionBarcodeDetailesResponse = new TTACPrescriptionBarcodeDetailesResponse();
                            tTACPrescriptionBarcodeDetailesResponse.EnglishName   = jInfo[i]["EnglishName"] == null ? "" : jInfo[0]["EnglishName"].ToString();
                            tTACPrescriptionBarcodeDetailesResponse.GenericCode   = jInfo[i]["GenericCode"] == null ? "" : jInfo[0]["GenericCode"].ToString();
                            tTACPrescriptionBarcodeDetailesResponse.Irc           = jInfo[i]["Irc"] == null ? "" : jInfo[0]["Irc"].ToString();
                            tTACPrescriptionBarcodeDetailesResponse.Expiration    = jInfo[i]["Expiration"] == null ? "" : jInfo[0]["Expiration"].ToString();
                            tTACPrescriptionBarcodeDetailesResponse.Status        = int.Parse(jInfo[i]["Status"] == null ? "-1" : jInfo[0]["Status"]?.ToString());
                            tTACPrescriptionBarcodeDetailesResponse.StatusMessage = jInfo[i]["StatusMessage"] == null ? "" : jInfo[0]["StatusMessage"].ToString();
                            tTACPrescriptionBarcodeDetailesResponse.ProductType   = jInfo[i]["ProductType"] == null ? "" : jInfo[0]["ProductType"].ToString();
                            tTACPrescriptionBarcodeDetailesResponse.ProductTypeId = int.Parse(jInfo[i]["ProductTypeId"] == null ? "0" : jInfo[0]["ProductTypeId"].ToString());
                            tTACPrescriptionBarcodeDetailesResponse.Price         = int.Parse(jInfo[i]["Price"] == null ? "0" : jInfo[0]["Price"].ToString());
                            tTACPrescriptionBarcodeDetailesResponse.TrackingCode  = int.Parse(jInfo[i]["TrackingCode"] == null ? "0" : jInfo[0]["TrackingCode"].ToString());
                            tTACPrescriptionBarcodeDetailesResponse.BarcodeUid    = jInfo[0]["BarcodeUid"] == null ? "" : jInfo[0]["BarcodeUid"].ToString();
                            tTACPrescriptionBarcodeDetailesResponse.Uid           = jInfo[0]["Uid"] == null ? "" : jInfo[0]["BarcodeUid"].ToString();
                            res.ItemsInfo.Add(tTACPrescriptionBarcodeDetailesResponse);
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                res.ErrorCode    = (int)HealthESBApiResponseCode.ServiceProviderNotResponse;
                res.ErrorMessage = HealthESBApiResponseMessages.ServiceProviderNotResponse;
            }

            return(res);
        }
コード例 #2
0
        public async Task <PrescriptionBarcodeResponse> Create(PrescriptionBarcodeRequest prescriptionBarcodeRequest)
        {
            var response = new PrescriptionBarcodeResponse();

            response.ItemsInfo = new List <PrescriptionBarcodeDetailesResponse>();
            var  prescriptionBarcodeDetailes = new PrescriptionBarcodeDetailes();
            TTAC tTAC = new TTAC(_serviceProvider);
            var  prescriptionBarcodeDetailesResponse = new PrescriptionBarcodeDetailesResponse();

            try
            {
                if (string.IsNullOrEmpty(prescriptionBarcodeRequest.BarcodeUid) || string.IsNullOrEmpty(prescriptionBarcodeRequest.GenericCode) || prescriptionBarcodeRequest.Amount == 0 || prescriptionBarcodeRequest.PrescriptionId == 0)
                {
                    return(response.ToIncompleteInput <PrescriptionBarcodeResponse>());
                }

                if (string.IsNullOrEmpty(prescriptionBarcodeRequest.ReCheckCode))
                {
                    prescriptionBarcodeRequest.ReCheckCode = Guid.NewGuid().ToString();
                }

                PrescriptionBarcode prescriptionBarcode = new PrescriptionBarcode();
                prescriptionBarcodeRequest.CopyPropertiesTo(prescriptionBarcode);
                var result = await _prescriptionRepository.FirstOrDefault(a => a.OutPrescriptionId == prescriptionBarcodeRequest.PrescriptionId);

                if (result == null)
                {
                    return(response.ToNotFoundPrescription <PrescriptionBarcodeResponse>());
                }


                prescriptionBarcode.PrescriptionId = result.Id;
                prescriptionBarcode.PrescriptionBarcodeStatusId = (int)PrescriptionBarcodeStatusEnum.InsertRequest;
                await _prescriptionBarcodeRepository.Add(prescriptionBarcode);

                if (prescriptionBarcodeRequest.BarcodeUid.Length > 80)
                {
                    prescriptionBarcode.OutErrorCode    = (int)HealthESBApiResponseCode.InvalidLenghtBarcodeUcid;
                    prescriptionBarcode.OutErrorMessage = HealthESBApiResponseMessages.InvalidLenghtBarcodeUcid;
                    await _prescriptionBarcodeRepository.Update(prescriptionBarcode);

                    return(response.ToInvalidLenghtBarcodeUcid <PrescriptionBarcodeResponse>());
                }

                TTACPrescriptionBarcodeRequest  tTACPrescriptionBarcodeRequest  = new TTACPrescriptionBarcodeRequest();
                TTACPrescriptionBarcodeResponse tTACPrescriptionBarcodeResponse = new TTACPrescriptionBarcodeResponse();
                prescriptionBarcodeRequest.CopyPropertiesTo(tTACPrescriptionBarcodeRequest);


                tTACPrescriptionBarcodeRequest.Username = Constants.TTAC_UserName;
                tTACPrescriptionBarcodeRequest.Password = Constants.TTAC_Password;


                tTACPrescriptionBarcodeResponse = await tTAC.CallCheckSingleBarcodeApi(tTACPrescriptionBarcodeRequest);

                prescriptionBarcode.OutErrorCode    = tTACPrescriptionBarcodeResponse.ErrorCode;
                prescriptionBarcode.OutErrorMessage = tTACPrescriptionBarcodeResponse.ErrorMessage;
                response.ErrorCode      = tTACPrescriptionBarcodeResponse.ErrorCode;
                response.ErrorMessage   = tTACPrescriptionBarcodeResponse.ErrorMessage;
                response.PrescriptionId = tTACPrescriptionBarcodeResponse.PrescriptionId;
                prescriptionBarcode.PrescriptionBarcodeStatusId = (int)PrescriptionBarcodeStatusEnum.GetResponseFromServiceProvider;
                prescriptionBarcode.ReCheckCode = prescriptionBarcodeRequest.ReCheckCode;
                await _prescriptionBarcodeRepository.Update(prescriptionBarcode);

                foreach (var item in tTACPrescriptionBarcodeResponse.ItemsInfo)
                {
                    prescriptionBarcodeDetailes = new PrescriptionBarcodeDetailes();
                    item.CopyPropertiesTo(prescriptionBarcodeDetailes);
                    item.CopyPropertiesTo(prescriptionBarcodeDetailesResponse);
                    response.ItemsInfo.Add(prescriptionBarcodeDetailesResponse);
                    prescriptionBarcodeDetailes.PrescriptionBarcodeId = prescriptionBarcode.Id;
                    prescriptionBarcodeDetailes.PrescriptionBarcodeDetailesTypesId = (int)PrescriptionBarcodeDetailesTypeEnum.RegisterBarcodeItems;
                    await _prescriptionBarcodeDetailesRepository.Add(prescriptionBarcodeDetailes);
                }

                response.HasError = false;
                return(response);
            }
            catch (Exception e)
            {
                _logService.LogText("PrescriptionBarcodeInternalError" + e.Message.ToString());
                throw new Exception(e.Message);
            }
        }