public bool ClearVDW() { bool result = false; m_ProgressBar.Maximum = 5; m_ProgressBar.Step = 1; m_ProgressBar.Value = 0; using (var context = new VDW_3_1_Entities()) { try { // clear priority 1 tables context.CENSUS_LOCATION.RemoveRange(context.CENSUS_LOCATION); m_ProgressBar.Value = m_ProgressBar.Value + 1; context.DIAGNOSES.RemoveRange(context.DIAGNOSES); m_ProgressBar.Value = m_ProgressBar.Value + 1; context.ENCOUNTERS.RemoveRange(context.ENCOUNTERS); m_ProgressBar.Value = m_ProgressBar.Value + 1; context.VITAL_SIGNS.RemoveRange(context.VITAL_SIGNS); m_ProgressBar.Value = m_ProgressBar.Value + 1; context.DEMOGRAPHICS.RemoveRange(context.DEMOGRAPHICS); m_ProgressBar.Value = m_ProgressBar.Value + 1; // clear priority 2 tables ; // clear priority 3 tables ; context.SaveChanges(); result = true; } catch (Exception ex) { log.Info("Error: " + ex.Message); m_Status.Items.Add("Error: " + ex.Message); m_Status.SelectedIndex = m_Status.Items.Count - 1; } } if (result) { m_Status.Items.Add("VDW Cleared."); m_Status.SelectedIndex = m_Status.Items.Count - 1; } return(result); }
private void CHORD_VDWBuilder_Load(object sender, EventArgs e) { //FHIR_URL.Text = "http://hapi.fhir.org/baseDstu3"; FHIR_URL.Text = "https://sb-fhir-stu3.smarthealthit.org/smartstu3/open"; using (var context = new VDW_3_1_Entities()) { try { vdwServerTB.Text = context.Database.Connection.ConnectionString; } catch (Exception ex) { vdwServerTB.Text = ex.Message; } } mFHIRClient = new FhirClient(FHIR_URL.Text); mFHIRToVDW = new FHIRToVDW(mFHIRClient, statusLB, patientsProgressBar); }
public List <FHIRPatientSummary> LoadVDW() { List <FHIRPatientSummary> results = new List <FHIRPatientSummary>(); log.Info("Start Importing Patients"); using (var context = new VDW_3_1_Entities()) { try { Bundle bundles = m_FhirClient.Search <Patient>(new string[] { "_count=100" }); // get all the patients from all the pages List <Patient> patients = new List <Patient>(); while (bundles != null) { foreach (Bundle.EntryComponent item in bundles.Entry) { Patient p = (Patient)item.Resource; patients.Add(p); } bundles = m_FhirClient.Continue(bundles); } m_ProgressBar.Maximum = patients.Count; m_ProgressBar.Step = 1; m_ProgressBar.Value = 0; int total = patients.Count; int cur = 1; foreach (var p in patients) { FHIRPatientSummary sum = new FHIRPatientSummary(); sum.PERSON_ID = p.Id; // build and save DEMOGRAPHIC record for patient DEMOGRAPHICS demo = buildDemographic(p); if (demo != null) { try { context.DEMOGRAPHICS.Add(demo); context.SaveChanges(); // build and save CENSUS_LOCATION records List <CENSUS_LOCATION> locs = buildGeocode(p); foreach (var loc in locs) { try { context.CENSUS_LOCATION.Add(loc); context.SaveChanges(); } catch (Exception ex) { log.Info("Error Census Location: " + ex.Message); } } // build and save Encounter records for patient try { Bundle encounters = m_FhirClient.Search <Encounter>(new string[] { "patient=" + p.Id }); foreach (var e_item in encounters.Entry) { Encounter e_temp = (Encounter)e_item.Resource; ENCOUNTERS tENCOUNTERS = buildEncounter(e_temp, p); if (tENCOUNTERS != null) { try { context.ENCOUNTERS.Add(tENCOUNTERS); context.SaveChanges(); } catch (Exception ex) { log.Info("Error Encounter: " + ex.Message); } } else { log.Info("Error Encounter: bad encounter record for patient " + p.Id); } } } catch (Exception ex) { log.Info("Error Encounter: " + ex.Message); } // build and save Diagnose records for patient try { Bundle diagnosis = m_FhirClient.Search <DiagnosticReport>(new string[] { "patient=" + p.Id }); foreach (var d_item in diagnosis.Entry) { DiagnosticReport tDiagnoses = null; ; } } catch (Exception ex) { log.Info("Error Diagnosis: " + ex.Message); } // build and save VITAL_SIGN records for patient try { Bundle o = m_FhirClient.Search <Observation>(new string[] { "patient=" + p.Id }); foreach (var tempD in o.Entry) { Observation obs = (Observation)tempD.Resource; foreach (CodeableConcept cc in obs.Category) { foreach (var code in cc.Coding) { if (code.Code == "vital-signs") { sum.VitalSignTotalCount++; } } } } } catch (Exception ex) { log.Info("Error Vital Sign: " + ex.Message); } } catch (Exception ex) { log.Info("Error: " + ex.Message); } } else { log.Info("Error in patient: " + p.Id); } // Location Count sum.LocationTotalCount = p.Address.Count; // Encounter Count Bundle en = m_FhirClient.Search <Encounter>(new string[] { "patient=" + p.Id }); sum.EncounterTotalCount = en.Entry.Count; // Diagnoses Count Bundle d = m_FhirClient.Search <DiagnosticReport>(new string[] { "patient=" + p.Id }); sum.DiagnosesTotalCount = d.Entry.Count; results.Add(sum); cur++; m_ProgressBar.Value = m_ProgressBar.Value + 1; } log.Info("Number of Patients " + results.Count.ToString()); log.Info("End Importing Patients"); } catch (Exception ex) { log.Info("Error: " + ex.Message); } } return(results); }