Пример #1
0
        public ApiResponse AddPatient(AddPatienModel model)
        {
            //Build the body of the request
            var savePPRequestBody = new SavePathwayPatientInformationRequestBody
            {
                PatientId       = 0,
                FirstName       = model.FirstName,
                LastName        = model.LastName,
                EmailAddress    = model.EmailAddress,
                DateOfBirth     = model.Dob,
                AddressLine     = model.AddressLine,
                City            = model.City,
                StateId         = model.StateId, //Shared with other client data
                Gender          = Gender.Male,
                PatientPathways = new List <PatientPathwayShortDto>()
                {
                    new PatientPathwayShortDto {
                        PatientPathwayId = 0, PathwayId = Convert.ToInt32(ConfigurationSettings.AppSettings["PathwayId"])
                    }
                },
                MedicalRecordNumber = model.MedicalRecordNumber,
                Optins = new List <CommunicationOptinDto>()
                {
                    new CommunicationOptinDto {
                        CommunicationType = CommunicationType.Email, Optin = true
                    },
                    new CommunicationOptinDto {
                        CommunicationType = CommunicationType.Phone, Optin = true
                    },
                    new CommunicationOptinDto {
                        CommunicationType = CommunicationType.Sms, Optin = true
                    }
                },
                IdentityUserId = ConfigurationSettings.AppSettings["IdentityUserId"],
                CreatedDate    = DateTime.UtcNow.ToString(),
                CommandId      = System.Guid.NewGuid()
            };

            //Build the request
            var apiRequest = new APIRequest
            {
                Source     = string.Empty,
                TrackingId = Guid.NewGuid().ToString(),
                Type       = "SavePathwayPatientInformation",
                Body       = JsonConvert.SerializeObject(savePPRequestBody)
            };

            //Generate the HttpContent
            var content = new StringContent(JsonConvert.SerializeObject(apiRequest), System.Text.Encoding.UTF8, "application/json");


            // post the json content to the service.
            var response = httpClient.PostAsync(RequestURL, content);

            response.Wait();
            if (response.Result.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <ApiResponse>(response.Result.Content.ReadAsStringAsync().Result));
            }
            return(new ApiResponse
            {
                Success = false,
                Body = $"Error Response Code from service - {response.Result.ReasonPhrase}"
            });
        }
Пример #2
0
        public void UpdatePatient(UpdatePatienModel model)
        {
            //Build the body of the request
            var savePPRequestBody = new SavePathwayPatientInformationRequestBody
            {
                PatientId           = model.PatientId, //patient id created while saving new patient
                FirstName           = model.FirstName,
                LastName            = model.LastName,
                EmailAddress        = model.EmailAddress,
                DateOfBirth         = model.Dob,
                AddressLine         = model.AddressLine,
                City                = model.City,
                StateId             = model.StateId,                       //Shared with other client data
                Gender              = Gender.Male,
                PatientPathways     = new List <PatientPathwayShortDto>(), //leave empty unless pathway details need to be updated
                MedicalRecordNumber = model.MedicalRecordNumber,
                Optins              = new List <CommunicationOptinDto>()
                {
                    new CommunicationOptinDto {
                        CommunicationType = CommunicationType.Email, Optin = true
                    },
                    new CommunicationOptinDto {
                        CommunicationType = CommunicationType.Phone, Optin = true
                    },
                    new CommunicationOptinDto {
                        CommunicationType = CommunicationType.Sms, Optin = true
                    }
                },
                CellPhone      = model.CellPhone, //updating with new information
                HomePhone      = model.HomePhone, //updating with new information
                IdentityUserId = ConfigurationSettings.AppSettings["IdentityUserId"],
                CreatedDate    = DateTime.UtcNow.ToString(),
                CommandId      = System.Guid.NewGuid()
            };

            //Build the request
            var apiRequest = new APIRequest
            {
                Source     = string.Empty,
                TrackingId = Guid.NewGuid().ToString(),
                Type       = "SavePathwayPatientInformation",
                Body       = JsonConvert.SerializeObject(savePPRequestBody)
            };

            //Generate the HttpContent
            var content = new StringContent(JsonConvert.SerializeObject(apiRequest), System.Text.Encoding.UTF8, "application/json");


            // post the json content to the service.
            var response = httpClient.PostAsync(RequestURL, content);

            response.Wait();
            if (response.Result.IsSuccessStatusCode)
            {
                var getPatientResult = JsonConvert.DeserializeObject <ApiResponse>(response.Result.Content.ReadAsStringAsync().Result);

                if (getPatientResult.Success)
                {
                    return;
                }
                throw new Exception($"Failed Updating Existing Patient {getPatientResult.Body}");
            }
            throw new Exception($"Error Response Code from service - {response.Result.ReasonPhrase}");
        }