/// <summary> /// Calls PatientSystem data domain to insert an Engage System record for the newly created patient. /// </summary> /// <param name="request">IDataDomainRequest object</param> /// <returns>PatientSystemData object.</returns> private PatientSystemData insertEngagePatientSystem(string patientId, IDataDomainRequest request) { PatientSystemData data = null; try { InsertPatientSystemDataRequest psRequest = new InsertPatientSystemDataRequest { PatientId = patientId, IsEngageSystem = true, PatientSystemsData = new PatientSystemData { PatientId = patientId }, Context = request.Context, ContractNumber = request.ContractNumber, UserId = Constants.SystemContactId,// the requirement says that the engage Id should have createdby user as 'system'. Version = request.Version }; string DDPatientSystemServiceUrl = ConfigurationManager.AppSettings["DDPatientSystemServiceUrl"]; IRestClient client = new JsonServiceClient(); //[Route("/{Context}/{Version}/{ContractNumber}/Patient/{PatientId}/PatientSystem", "POST")] string url = Helpers.BuildURL(string.Format("{0}/{1}/{2}/{3}/Patient/{4}/PatientSystem", DDPatientSystemServiceUrl, psRequest.Context, psRequest.Version, psRequest.ContractNumber, psRequest.PatientId), psRequest.UserId); InsertPatientSystemDataResponse dataDomainResponse = client.Post <InsertPatientSystemDataResponse>(url, psRequest as object); if (dataDomainResponse != null) { data = dataDomainResponse.PatientSystemData; } } catch (Exception ex) { throw ex; } return(data); }
public InsertPatientSystemDataResponse Post(InsertPatientSystemDataRequest request) { InsertPatientSystemDataResponse response = new InsertPatientSystemDataResponse(); try { RequireUserId(request); response.PatientSystemData = Manager.InsertPatientSystem(request); response.Version = request.Version; } catch (Exception ex) { RaiseException(response, ex); } return(response); }
public InsertPatientSystemDataResponse InsertPatientSystem(InsertPatientSystemDataRequest request) { //[Route("/{Context}/{Version}/{ContractNumber}/Patient/{PatientId}/PatientSystem", "POST")] Uri theUriPS = new Uri(string.Format("{0}/PatientSystem/{1}/{2}/{3}/Patient/{4}/PatientSystem?UserId={5}", Url, Context, Version, ContractNumber, request.PatientId, HeaderUserId)); HttpClient clientPS = GetHttpClient(theUriPS); DataContractJsonSerializer jsonSerPS = new DataContractJsonSerializer(typeof(InsertPatientSystemDataRequest)); // use the serializer to write the object to a MemoryStream MemoryStream msPS = new MemoryStream(); jsonSerPS.WriteObject(msPS, request); msPS.Position = 0; //use a Stream reader to construct the StringContent (Json) StreamReader srPS = new StreamReader(msPS); StringContent theContentPS = new StringContent(srPS.ReadToEnd(), System.Text.Encoding.UTF8, "application/json"); msPS.Dispose(); //Post the data var responsePS = clientPS.PostAsync(theUriPS, theContentPS); var responseContentPS = responsePS.Result.Content; string responseStringPS = responseContentPS.ReadAsStringAsync().Result; InsertPatientSystemDataResponse responsePatientPS = null; using (var msResponsePS = new MemoryStream(Encoding.Unicode.GetBytes(responseStringPS))) { var serializerPS = new DataContractJsonSerializer(typeof(InsertPatientSystemDataResponse)); responsePatientPS = (InsertPatientSystemDataResponse)serializerPS.ReadObject(msResponsePS); } return(responsePatientPS); }