/// <summary> /// save patient demography to file/Azure Storage /// </summary> /// <param name="savePath"></param> /// <param name="id"></param> /// <returns></returns> public PatientViewModel GetPatient(string savePath, string id, bool saveToFile = true) { string getPatientUrl = AppSettings.FhirAPIBaseUrl + string.Format("Patient/{0}", id); //call API to get patient list string response = APIHelper.CallFhirApi(BearerToken, getPatientUrl); string fhirXml = RemoveAllEmptyNode(response); if (saveToFile) { if (AppSettings.StoredPatientInAzure) { //stored the patient information into azure storage to demo MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); writer.Write(fhirXml); writer.Flush(); stream.Position = 0; AzureStorageHelper.UploadBlobToAzure("", string.Format("{0}.xml", id), stream); } else { //stored the patient information into local folder to demo string saveFilePath = Path.Combine(savePath, string.Format("{0}.xml", id)); File.WriteAllText(saveFilePath, fhirXml); } } FhirXmlParser fxp = new FhirXmlParser(); var patient = fxp.Parse <Hl7.Fhir.Model.Patient>(fhirXml); return(ConvertFhirToViewModel(patient)); }
/// <summary> /// Search pathent from API /// </summary> /// <param name="family"></param> /// <param name="given"></param> /// <param name="dob"></param> /// <param name="gender"></param> /// <returns></returns> public List <PatientViewModel> SearchPatients(string _id, string family, string given, string birthdate, string gender, string MRN) { List <PatientViewModel> results = new List <PatientViewModel>(); string searchPatientUrl = AppSettings.FhirAPIBaseUrl + "Patient?"; if (!string.IsNullOrEmpty(_id)) { searchPatientUrl += string.Format("_id={0}", _id); } else { if (!string.IsNullOrEmpty(family)) { searchPatientUrl += string.Format("family={0}", family); } if (!string.IsNullOrEmpty(given)) { searchPatientUrl += "&" + string.Format("given={0}", given); } if (!string.IsNullOrEmpty(birthdate)) { searchPatientUrl += "&" + string.Format("birthdate={0}", birthdate); } if (!string.IsNullOrEmpty(gender)) { searchPatientUrl += "&" + string.Format("gender={0}", GetGenderFromHl7(gender).ToString().ToLower()); } if (!string.IsNullOrEmpty(MRN)) { searchPatientUrl += "&" + string.Format("identifier={0}", MRN); } searchPatientUrl = searchPatientUrl.Replace("?&", "?"); } //call API to get patient list string response = APIHelper.CallFhirApi(BearerToken, searchPatientUrl); if (CheckIfNotEmptyBundle(response)) { FhirXmlParser fxp = new FhirXmlParser(); var bundle = fxp.Parse <Hl7.Fhir.Model.Bundle>(RemoveAllEmptyNode(response)); results = ExtraFhirResourceFromBundle(bundle, "Patient").Select(r => ConvertFhirToViewModel((Patient)r)).ToList(); //ConvertFhirBundleToViewModel(bundle); } return(results.OrderBy(p => p.FullName).ToList()); }
/// <summary> /// get patient details information. (include demographic/encounter/observations...) /// </summary> /// <param name="filePath"></param> /// <param name="id"></param> /// <returns></returns> public PatientViewModel GetPatientDetails(string filePath, string id) { PatientViewModel patient = GetPatient(filePath, id, false); //Get encounter information string apiUrl = AppSettings.FhirAPIBaseUrl + string.Format("Encounter?patient={0}", id); //call API to get encounter string response = APIHelper.CallFhirApi(BearerToken, apiUrl); FhirXmlParser fxp = new FhirXmlParser(); if (CheckIfNotEmptyBundle(response)) { var bundle = fxp.Parse <Hl7.Fhir.Model.Bundle>(RemoveAllEmptyNode(response)); patient.PatientEncounters = ExtraFhirResourceFromBundle(bundle, "Encounter").Select(o => o as Encounter).ToList(); patient.PatientEncounters.ForEach(item => { if (item.Location == null) { item.Location = new List <Encounter.LocationComponent>(); } }); } else { patient.PatientEncounters = new List <Encounter>(); } //set patient.location if (patient.PatientEncounters.Count > 0 && patient.PatientEncounters[0].Location != null && patient.PatientEncounters[0].Location.Count > 0 && patient.PatientEncounters[0].Location[0] != null && patient.PatientEncounters[0].Location[0].Location != null && !string.IsNullOrEmpty(patient.PatientEncounters[0].Location[0].Location.Display)) { patient.Location = patient.PatientEncounters[0].Location[0].Location.Display; } //Get observation information apiUrl = AppSettings.FhirAPIBaseUrl + string.Format("Observation?patient={0}", id); response = APIHelper.CallFhirApi(BearerToken, apiUrl); if (CheckIfNotEmptyBundle(response)) { var bundle = fxp.Parse <Hl7.Fhir.Model.Bundle>(RemoveAllEmptyNode(response)); patient.PatientObservations = ExtraFhirResourceFromBundle(bundle, "Observation").Select(o => o as Observation).ToList(); } else { patient.PatientObservations = new List <Observation>(); } //Get Coverage apiUrl = AppSettings.FhirAPIBaseUrl + string.Format("Coverage?patient={0}", id); response = APIHelper.CallFhirApi(BearerToken, apiUrl); if (CheckIfNotEmptyBundle(response)) { var bundle = fxp.Parse <Hl7.Fhir.Model.Bundle>(RemoveAllEmptyNode(response)); patient.PatientCoverages = ExtraFhirResourceFromBundle(bundle, "Coverage").Select(o => o as Coverage).ToList(); } else { patient.PatientCoverages = new List <Coverage>(); } if (patient.PatientCoverages.Count > 0 && patient.PatientCoverages[0].Grouping != null && !string.IsNullOrEmpty(patient.PatientCoverages[0].Grouping.PlanDisplay)) { patient.Payor = patient.PatientCoverages[0].Grouping.PlanDisplay; } //get AllergyIntolerance apiUrl = AppSettings.FhirAPIBaseUrl + string.Format("AllergyIntolerance?patient={0}", id); response = APIHelper.CallFhirApi(BearerToken, apiUrl); if (CheckIfNotEmptyBundle(response)) { var bundle = fxp.Parse <Hl7.Fhir.Model.Bundle>(RemoveAllEmptyNode(response)); patient.PatientAllergyIntolerances = ExtraFhirResourceFromBundle(bundle, "AllergyIntolerance").Select(o => o as AllergyIntolerance).ToList(); patient.PatientAllergyIntolerances.ForEach(item => { if (item.Reaction == null || item.Reaction.Count == 0) { item.Reaction = new List <AllergyIntolerance.ReactionComponent>() { new AllergyIntolerance.ReactionComponent() { Substance = new CodeableConcept() { Text = "" }, Manifestation = new List <CodeableConcept>() { new CodeableConcept() { Text = "" } } } } } ; if (item.Reaction[0].Substance == null) { item.Reaction[0].Substance = new CodeableConcept() { Text = "" }; } if (item.Reaction[0].Manifestation == null || item.Reaction[0].Manifestation.Count == 0) { item.Reaction[0].Manifestation = new List <CodeableConcept>() { new CodeableConcept() { Text = "" } }; } }); } else { patient.PatientAllergyIntolerances = new List <AllergyIntolerance>(); } //get Medicatioin apiUrl = AppSettings.FhirAPIBaseUrl + string.Format("MedicationRequest?patient={0}", id); response = APIHelper.CallFhirApi(BearerToken, apiUrl); if (CheckIfNotEmptyBundle(response)) { var bundle = fxp.Parse <Hl7.Fhir.Model.Bundle>(RemoveAllEmptyNode(response)); patient.PatientMedications = ExtraFhirResourceFromBundle(bundle, "MedicationRequest").Select(o => o as MedicationRequest).ToList(); } else { patient.PatientMedications = new List <MedicationRequest>(); } return(patient); }