public HttpResponseMessage SavePatient([FromBody] AddPatienModel model) { try { var res = new PlatformService().AddPatient(model); var status = new PlatformService().ResetLoginCredentials(model.EmailAddress, model.Password); if (res.Success && status) { var token = Guid.NewGuid().ToString(); var patient = new PlatformService().GetPatient(int.Parse(res.Body)); UserHelper.SetPatient(token, patient); return(Request.CreateResponse(HttpStatusCode.OK, new { Token = token, Patient = patient })); } return(Request.CreateResponse(HttpStatusCode.OK, new { Error = res.Body })); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.OK, new { Error = e.GetBaseException().Message })); } }
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}" }); }