// this will overwrite the current patient information with the value from the FHIR repo // if the patient is deleted, the patient will be reactivated public static void update_fhir_patient(FHIR_Patient fp) { using (var dal = new Company.ClinicalDAL.ClinicalDAL(context)) { var pat = dal.GetPatient_External_Id_Source(fp.External_id, fp.External_source); if (pat != null) { pat.LastName = fp.LastName; pat.FirstName = fp.FirstName; pat.Sex = !string.IsNullOrEmpty(fp.Gender) ? fp.Gender.Substring(0, 1) : "U"; pat.DateOfBirth = !string.IsNullOrEmpty(fp.Birthdate) ? DateTime.Parse(fp.Birthdate) : (DateTime?)null; pat.AddressLine1 = fp.Address; pat.City = fp.City; pat.State = fp.State; pat.Zip = fp.Zip; pat.HomePhone = fp.Phone; pat.Active = true; dal.UpdatePatient(pat); UserAction ua = new UserAction { User = GlobalVariables.Instance.ClinicalUser, Action_id = UserActionCode.External_Patient_Updated.ToString(), Action_desc = UserActionDesc[UserActionCode.External_Patient_Updated], Action_date = DateTime.Now, Patient_id = pat.id, External_id = pat.External_id, External_source = pat.External_source }; dal.AddUserAction(ua); } } }
// this is just to validate if an MRN exist. If used to query patient will need to be logged. public static ClinicalDAL.Patient GetPatient_External_Id_Source(FHIR_Patient fp) { using (var dal = new Company.ClinicalDAL.ClinicalDAL(context)) { return(dal.GetPatient_External_Id_Source(fp.External_id, fp.External_source)); } }
public static List <FHIR_Patient> find_fhir_patients(string _Url, string _Name) { var endpoint = new Uri(_Url); var client = new FhirClient(endpoint); client.UseFormatParam = true; client.PreferredFormat = ResourceFormat.Json; var list_fhir = new List <FHIR_Patient>(); var query = new string[] { "name=" + _Name }; try { var bundle = client.Search("Patient", query); UserAction ua = new UserAction { User = "******", Action_id = UserActionCode.External_FHIR_Queried.ToString(), Action_desc = UserActionDesc[UserActionCode.External_FHIR_Queried], External_source = _Url }; Console.WriteLine("Got " + bundle.Entry.Count() + " records!"); foreach (var pt in bundle.Entry) { Hl7.Fhir.Model.Patient p = (Hl7.Fhir.Model.Patient)pt.Resource; var fc = new FHIR_Patient(); fc.External_id = p.Id; fc.External_source = _Url; fc.LastName = p.Name.First().Family.FirstOrDefault(); fc.FirstName = p.Name.First().Given.FirstOrDefault(); fc.Birthdate = p.BirthDate.ToString(); fc.Gender = p.Gender.ToString(); fc.Address = ""; fc.City = ""; fc.State = ""; fc.Zip = ""; if (p.Address.Count > 0) { fc.Address = p.Address.First().Line.FirstOrDefault(); fc.City = p.Address.First().City; fc.State = p.Address.First().State; fc.Zip = p.Address.First().PostalCode; } ; list_fhir.Add(fc); } } catch (Exception exp) { throw exp; } return(list_fhir); }
// Only take the 1st character for sex/gender public static int add_fhir_patient(FHIR_Patient fp) { var pat = new Company.ClinicalDAL.Patient(); pat.MRN = fp.MRN; pat.LastName = fp.LastName; pat.FirstName = fp.FirstName; pat.Sex = !string.IsNullOrEmpty(fp.Gender) ? fp.Gender.Substring(0, 1) : "U"; pat.DateOfBirth = !string.IsNullOrEmpty(fp.Birthdate) ? DateTime.Parse(fp.Birthdate) : (DateTime?)null; pat.AddressLine1 = fp.Address; pat.City = fp.City; pat.State = fp.State; pat.Zip = fp.Zip; pat.HomePhone = fp.Phone; pat.External_id = fp.External_id; pat.External_source = fp.External_source; return(AddPatient(pat)); }