public async Task <ActionResult> UpdateMonitor(List <string> ListId) { AppContext.MonitorPatients.IsLoading = true; PatientsList newMonitorList = new PatientsList(); PatientsList queryPatients = new PatientsList(); // Only add Patients haven't queried observations to avoid repeated query // One patient only needs to query once at the first time it is selected foreach (Patient patient in AppContext.Patients) { if (ListId.Contains(patient.Id)) { patient.Selected = true; if (!patient.HasObservations) { queryPatients.AddPatient(patient); } else { newMonitorList.AddPatient(patient); } } else { patient.Selected = false; } } // query list of patients haven't queried Cholesterol PatientsList queriedPatients = await FhirService.GetObservationValues(queryPatients); foreach (Patient patient in queriedPatients) { newMonitorList.AddPatient(patient); } AppContext.MonitorPatients = newMonitorList; return(View("Monitor")); }
/// <summary> /// Get Data for ML Task /// </summary> /// <returns>a list of patients contain observation data for ML task</returns> public static async Task <PatientsList> GetData() { int count = 0; bool stop = false; PatientsList data = new PatientsList(); try { var PatientQuery = new SearchParams() .OrderBy("birthdate") .LimitTo(LIMIT_ENTRY); Bundle PatientResult = await Client.SearchAsync <Hl7.Fhir.Model.Patient>(PatientQuery); // paging to search for all patient until reaching NUMBER_OF_DATA_RECORD value while (PatientResult != null) { if (stop) { break; } foreach (var Entry in PatientResult.Entry) { Hl7.Fhir.Model.Patient fhirPatient = (Hl7.Fhir.Model.Patient)Entry.Resource; PatientMapper mapper = new PatientMapper(); Models.Patient patient = mapper.Map(fhirPatient); if (!AppContext.AnalysisData.Contains(patient) && !data.Contains(patient)) { var CholesterolQuery = new SearchParams() .Where("patient=" + patient.Id) .Where("code=2093-3") .OrderBy("-date") .LimitTo(1); // Only GetData for patient that has Cholesterol value Bundle CholesterolResult = await Client.SearchAsync <Hl7.Fhir.Model.Observation>(CholesterolQuery); if (CholesterolResult.Entry.Count > 0) { data.AddPatient(await GetDataForAnalysis(patient)); count++; } } // Stop if count reachs NUMBER_OF_DATA_RECORD if (count == NUMBER_OF_DATA_RECORD) { stop = true; break; } } PatientResult = Client.Continue(PatientResult, PageDirection.Next); } } catch (FhirOperationException FhirException) { System.Diagnostics.Debug.WriteLine("Fhir error message: " + FhirException.Message); } catch (Exception GeneralException) { System.Diagnostics.Debug.WriteLine("General error message: " + GeneralException.Message); } return(data); }
/// <summary> /// Get Observation values of a patients list (Total Cholesterol, Blood Pressure) /// </summary> /// <param name="patients"> given list of patients </param> /// <returns> list of patients that contain Cholesterol and Blood Pressure values </returns> public static async Task <PatientsList> GetObservationValues(PatientsList patients) { PatientsList MonitoredPatientList = new PatientsList(); foreach (Models.Patient MonitoredPatient in patients) { try { Models.Patient patient = MonitoredPatient; patient.Observations = new List <Models.Observation>(); patient.HasObservations = true; // sort by date, limit to 1 so only take the newest Cholesterol observation var ObservationQuery = new SearchParams() .Where("patient=" + MonitoredPatient.Id) .Where("code=" + CHOLESTEROL_CODE) .OrderBy("-date") .LimitTo(1); Bundle ObservationResult = await Client.SearchAsync <Hl7.Fhir.Model.Observation>(ObservationQuery); if (ObservationResult.Entry.Count > 0) { // Map the FHIR Observation object to App's Observation object Hl7.Fhir.Model.Observation fhirObservation = (Hl7.Fhir.Model.Observation)ObservationResult.Entry[0].Resource; ObservationMapper mapper = new ObservationMapper(); Models.Observation cholesterolObservation = mapper.Map(fhirObservation); patient.Observations.Add(cholesterolObservation); } // sort by date, limit to 5 so only take the lastest Blood Pressure observation ObservationQuery = new SearchParams() .Where("patient=" + MonitoredPatient.Id) .Where("code=" + BLOOD_PRESSURE_CODE) .OrderBy("-date") .LimitTo(5); ObservationResult = await Client.SearchAsync <Hl7.Fhir.Model.Observation>(ObservationQuery); for (int i = 0; i < ObservationResult.Entry.Count; i++) { // Map the FHIR Observation object to App's Observation object Hl7.Fhir.Model.Observation fhirObservation = (Hl7.Fhir.Model.Observation)ObservationResult.Entry[i].Resource; ComponentObservationMapper mapper = new ComponentObservationMapper(); Models.Observation diastolicObservation = mapper.Map(fhirObservation.Component[0]); diastolicObservation.Id = fhirObservation.Id; Models.Observation systolicObservation = mapper.Map(fhirObservation.Component[1]); systolicObservation.Id = fhirObservation.Id; if (fhirObservation.Issued != null) { diastolicObservation.Issued = ((DateTimeOffset)fhirObservation.Issued).DateTime; systolicObservation.Issued = ((DateTimeOffset)fhirObservation.Issued).DateTime; } else { diastolicObservation.Issued = null; systolicObservation.Issued = null; } patient.Observations.Add(diastolicObservation); patient.Observations.Add(systolicObservation); } MonitoredPatientList.AddPatient(patient); } catch (FhirOperationException FhirException) { System.Diagnostics.Debug.WriteLine("Fhir error message: " + FhirException.Message); } catch (Exception GeneralException) { System.Diagnostics.Debug.WriteLine("General error message: " + GeneralException.Message); } } return(MonitoredPatientList); }
static void Main() { var fileService = new FileService(); var employeeList = new EmployeeList(); var patientList = new PatientsList(); var eventService = new EventService(); eventService.Events = eventService.DeserializeEvents(); Main2(); void Main2() { Console.WriteLine("Enter 1 to add a new event"); Console.WriteLine("Enter 2 to remove an event"); Console.WriteLine("Enter 3 to view all events"); Console.WriteLine("Enter 4 to add a new employee"); Console.WriteLine("Enter 5 to remove an employee"); Console.WriteLine("Enter 6 to view employee info"); Console.WriteLine("Enter 7 to add a patient"); Console.WriteLine("Enter 8 to remove a patiet"); Console.WriteLine("Enter 9 to view a patients info"); Console.WriteLine("Enter 10 to save all added information"); Console.WriteLine("Enter 11 to save data"); Console.WriteLine("Enter 12 to exit program"); int selection = Convert.ToInt32(Console.ReadLine()); switch (selection) { case (1): while (true) { Console.WriteLine("Please enter event date and time in the following format 2020-09-06 12:35"); var input = Console.ReadLine(); try { var date = DateTime.ParseExact(input, "yyyy-MM-dd HH:mm", null); Console.WriteLine("Enter the name of the event"); var newEventName = Console.ReadLine(); eventService.AddEventServiceDate(newEventName, date); Console.WriteLine("Thank you"); break; } catch (FormatException e) { Console.WriteLine("Wrong format!"); } } Main2(); break; case (2): if (eventService.Events.Count == 0) { Console.WriteLine("There are no events"); Console.WriteLine(""); Main2(); break; } for (int i = 0; i < eventService.Events.Count; i++) { Console.WriteLine(i + ". " + eventService.Events[i].EventName); Console.WriteLine(""); } Console.WriteLine("Which event would you like to remove?"); int EvntRmSelection = Convert.ToInt32(Console.ReadLine()); eventService.Events.RemoveAt(EvntRmSelection); Console.WriteLine(eventService.Events.Count); Main2(); break; case (3): for (int i = 0; i < eventService.Events.Count; i++) { Console.WriteLine(eventService.Events[i].EventName); Console.WriteLine("On " + eventService.Events[i].Date); Console.WriteLine(""); } if (eventService.Events.Count == 0) { Console.WriteLine("There are no events"); Console.WriteLine(""); Main2(); break; } Main2(); break; case (4): while (true) { try { Console.WriteLine("Enter employee's name"); string EmplName = Console.ReadLine(); Console.WriteLine("Enter employee's phone number"); long EmplPhoneNum = Convert.ToInt64(Console.ReadLine()); Console.WriteLine("Enter employee's Email"); string EmplEMail = Console.ReadLine(); Console.WriteLine("Enter employee's job title"); string EmplPosition = Console.ReadLine(); employeeList.AddEmployee(EmplName, EmplPhoneNum, EmplEMail, EmplPosition); break; } catch (FormatException e) { Console.WriteLine("Wrong format!"); } } Main2(); break; case (5): if (employeeList.EmployeeCount == 0) { Console.WriteLine("There are no employees"); Console.WriteLine(""); Main2(); break; } for (int i = 0; i < employeeList.EmployeeCount; i++) { Console.WriteLine(i + ". " + employeeList.Empl[i].Name); Console.WriteLine(""); } Console.WriteLine("Which employee would you like to remove?"); int EmplRmSelection = Convert.ToInt32(Console.ReadLine()); employeeList.Empl.RemoveAt(EmplRmSelection); employeeList.EmployeeCount--; Main2(); break; case (6): if (employeeList.EmployeeCount == 0) { Console.WriteLine("There are no employees"); Console.WriteLine(""); Main2(); break; } for (int i = 0; i < employeeList.EmployeeCount; i++) { Console.WriteLine(i + ". " + employeeList.Empl[i].Name); Console.WriteLine(""); } Console.WriteLine("Which employees info would you like to see?"); int EmplInfSelection = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The phone number of " + employeeList.Empl[EmplInfSelection].Name + " is " + employeeList.Empl[EmplInfSelection].PhoneNum); Console.WriteLine("The email of " + employeeList.Empl[EmplInfSelection].Name + " is " + employeeList.Empl[EmplInfSelection].EMail); Console.WriteLine("The job title of " + employeeList.Empl[EmplInfSelection].Name + " is " + employeeList.Empl[EmplInfSelection].Position); Console.WriteLine(""); Main2(); break; case (7): Console.WriteLine("Enter the patients name"); var Name = Console.ReadLine(); Console.WriteLine("Enter the patients email"); var EMail = Console.ReadLine(); Console.WriteLine("Enter the patients medical history"); var MedicalHistory = Console.ReadLine(); long PhoneNum; string ImportantInf; while (true) { try { Console.WriteLine("Enter patients phone number"); PhoneNum = Convert.ToInt64(Console.ReadLine()); break; } catch (FormatException e) { Console.WriteLine("Wrong format!"); } } while (true) { try { Console.WriteLine("Does the patient have any special needs?"); Console.WriteLine("Enter Y or N"); var NeedSelect = Console.ReadLine(); if (NeedSelect == "Y") { Console.WriteLine("Enter the info"); ImportantInf = Console.ReadLine(); break; } if (NeedSelect == "N") { ImportantInf = null; break; } } catch (FormatException e) { Console.WriteLine("Wrong format!"); } } patientList.AddPatient(Name, PhoneNum, EMail, ImportantInf, MedicalHistory); Main2(); break; case (8): if (patientList.PatientCount == 0) { Console.WriteLine("There are no patients"); Console.WriteLine(""); Main2(); break; } for (int i = 0; i < patientList.PatientCount; i++) { Console.WriteLine(i + ". " + patientList.Ptn[i].Name); Console.WriteLine(""); } Console.WriteLine("Which patient would you like to remove?"); int PtnRmSelection = Convert.ToInt32(Console.ReadLine()); patientList.Ptn.RemoveAt(PtnRmSelection); patientList.PatientCount--; Main2(); break; case (9): if (patientList.PatientCount == 0) { Console.WriteLine("There are no patients"); Console.WriteLine(""); Main2(); break; } for (int i = 0; i < patientList.PatientCount; i++) { Console.WriteLine(i + ". " + patientList.Ptn[i].Name); Console.WriteLine(""); } Console.WriteLine("Which patients info would you like to see?"); int PtnlInfSelection = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The phone number of " + patientList.Ptn[PtnlInfSelection].Name + " is " + patientList.Ptn[PtnlInfSelection].PhoneNum); Console.WriteLine("The email of " + patientList.Ptn[PtnlInfSelection].Name + " is " + patientList.Ptn[PtnlInfSelection].EMail); Console.WriteLine("The medical history of " + patientList.Ptn[PtnlInfSelection].Name + " is " + patientList.Ptn[PtnlInfSelection].MedicalHistory); if (patientList.Ptn[PtnlInfSelection].ImportantInf != null) { Console.WriteLine("The special needs of " + patientList.Ptn[PtnlInfSelection].Name + " are " + patientList.Ptn[PtnlInfSelection].ImportantInf); } Console.WriteLine(""); Main2(); break; case (10): string serializedEvents = eventService.SerializeEvents(); Console.WriteLine(serializedEvents); try { StreamWriter sw = new StreamWriter("Sample.txt"); sw.WriteLine(serializedEvents); sw.Close(); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } finally { Console.WriteLine("Executing finally block."); } break; //case (11): // eventService.DeserializeEvents(); //break; case (11): eventService.DataBase(eventService.Events); break; default: Console.WriteLine("None selected"); break; } } }