public DetailViewModel getDetailViewModel(long id) { FullPatientData dataModel = cache.loadPatientDataModel(id); DetailViewModel model = new DetailViewModel(); if (dataModel != null) { model.observations = dataModel.observations; model.patient = dataModel.patient; model.patientID = dataModel.patientID; model.QRs = dataModel.QRs; model.questionnaireMap = dataModel.questionnaireMap; } //load selected charts ChartSelection charts = chartSelectionRepo.getChartsByTherapistId(0); //0 is therapistID, replace with ID when authentication is impl if (charts != null && charts.chartMap.Keys.Contains(id.ToString())) //saved settings exist { model.selectedCharts = charts.chartMap[id.ToString()]; } else { model.selectedCharts = new Dictionary <string, string>(); } return(model); }
public void cacheFullPatientData(FullPatientData model) { /* * FullPatientData model = new FullPatientData();//Possibly move this * model.observations = viewModel.observations; * model.patient = viewModel.patient; * model.patientID = viewModel.patientID; * model.QRs = viewModel.QRs; * model.questionnaireMap = viewModel.questionnaireMap; * */ var prev = fullPatientDataModels.Find(x => x.patientID == model.patientID).FirstOrDefault(); if (prev != null) { model.id = prev.id; fullPatientDataModels.ReplaceOne(x => x.patientID == model.patientID, model); } else { fullPatientDataModels.InsertOne(model); } }
public void updateCachedPatientDataModelById(long id) { FHIRRepository repo = new FHIRRepository(); FhirJsonSerializer serializer = new FhirJsonSerializer(); FullPatientData model = new FullPatientData(); //add patient details Patient patient = repo.getPatientById(id); if (patient != null) { string patJson = serializer.SerializeToString(patient); model.patient = patJson; } //add QRs Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); List <QuestionnaireResponse> QRs = repo.getAllQRsByPatId(id); //< 1 sec stopwatch.Stop(); log.logTimeSpan("getAllQRsByPatID(" + id.ToString() + ")_from_cache", stopwatch.Elapsed, QRs.Count); if (QRs != null) { List <string> QRJsonList = new List <string>(); foreach (var QR in QRs) { string json = serializer.SerializeToString(QR); QRJsonList.Add(json); } model.QRs = QRJsonList; } //observations stopwatch.Restart(); List <Observation> observations = repo.getAllObservationsByPatId(id); // ~2 sec stopwatch.Stop(); log.logTimeSpan("getAllObservationsByPatId(" + id.ToString() + ")_from_server", stopwatch.Elapsed, observations.Count); if (observations != null) { List <string> observationList = new List <string>(); foreach (var obs in observations) { string json = serializer.SerializeToString(obs); observationList.Add(json); } model.observations = observationList; } //questionnaireMap - <name, id> stopwatch.Restart(); Dictionary <string, string> qMap = repo.getQMap(id); //~2 sec stopwatch.Stop(); log.logTimeSpan("getQMap(" + id.ToString() + ")", stopwatch.Elapsed); model.questionnaireMap = qMap; model.patientID = id; cache.cacheFullPatientData(model); //update charts independently //runs in < 0.01 sec }