private String Serialize(iSOFT.ANZ.PatientManagerServiceLibrary.Patient iPMpatient) { var resource = PatientMapper.MapModel(iPMpatient); String payload = String.Empty; if (WebOperationContext.Current != null) { var response = WebOperationContext.Current.OutgoingResponse; response.LastModified = iPMpatient.ModifDttm; string accept = WebOperationContext.Current.IncomingRequest.Accept; if (!String.IsNullOrEmpty(accept) && accept == "application/json") { payload = FhirSerializer.SerializeResourceToJson(resource); response.ContentType = "application/json+fhir"; } else { payload = FhirSerializer.SerializeResourceToXml(resource); response.ContentType = "application/xml+fhir"; } } return(payload); }
public HttpResponseMessage Read(int patientId, string _format = "application/xml+FHIR", bool _summary = false) { HttpResponseMessage message = new HttpResponseMessage(); Patient patient = db.Patients.Find(patientId); if (patient == null) { message.StatusCode = HttpStatusCode.NotFound; message.Content = new StringContent("Patient with id " + patientId + " not found!", Encoding.UTF8, "text/html"); return(message); } Hl7.Fhir.Model.Patient fhirPatient = PatientMapper.MapModel(patient); string fixedFormat = ControllerUtils.FixMimeString(_format); string payload = ControllerUtils.Serialize(fhirPatient, fixedFormat, _summary); message.Content = new StringContent(payload, Encoding.UTF8, fixedFormat); return(message); }