/// Step A - PREPROCESS public void preprocessAlgoData(string currentPatientID) { /// 1. Get latest sample SampleController sampleController = new SampleController(); latestSample = sampleController.GetLatestSampleForPatient(currentPatientID); //insert caregivers to caregiversArr PatientController patientController = new PatientController(); caregiversArr = patientController.GetCaregiversforPatientID(currentPatientID); //extract patient's known locations LocationController locationController = new LocationController(); knownLocations = locationController.GetKnownLocationsforPatientID(currentPatientID); //get latest sample time sampleTime = latestSample.CreatedAt.Value; //get avg patient's HR, and set our limits AVG_PATIENT_HR = AlgoUtils.avgHeartRate(currentPatientID); HEART_RATE_BOTTOM_LIMIT = 1.7 * AVG_PATIENT_HR; HEART_RATE_TOP_LIMIT = 0.5 * AVG_PATIENT_HR; }
public void RegisterCaregiver(string ID) { Trace.TraceInformation(String.Format("Attempting to register cargiver: {0}", ID)); try { Trace.AutoFlush = true; string deadConnectionId; string ConnID = Context.ConnectionId; ConnectionDictionary.mapUidToConnection.TryRemove(ID, out deadConnectionId); ConnectionDictionary.mapUidToConnection[ID] = ConnID; Trace.TraceInformation(String.Format("Added caregiver: {0} connectionId {1}", ID, ConnectionDictionary.mapUidToConnection[ID])); Caregiver currCaregiver = CaregiverController.GetCaregiverObject(ID); Patient currPatient = PatientController.GetPatientObjectbyGroupID(currCaregiver.GroupID); //send patient ID to caregiver SampleController sampleController = new SampleController(); if (SampleController.GetSampleCountforPatientID(currPatient.Id) == 0) { Trace.TraceInformation("No samples found for patient"); Message message = new Message() { ID = currPatient.Id, status = AlgoUtils.Status.Learning, name = "", lat = 32.0808800F, lon = 34.7805700F }; Clients.Client(ConnectionDictionary.mapUidToConnection[ID]).receiveNotification(message); WanderingAlgo algo = new WanderingAlgo(); Trace.TraceInformation("Starting Detection Algo for Patient {0} due to caregiver registration", currPatient.Id); algo.wanderingDetectionAlgo(currPatient.Id); } else { Sample latestSample = sampleController.GetLatestSampleForPatient(currPatient.Id); Trace.TraceInformation("Sending message back to caregiver with patient ID"); Message message = new Message() { ID = currPatient.Id, status = AlgoUtils.Status.Safety, name = "", lat = latestSample.Latitude, lon = latestSample.Longitude }; Clients.Client(ConnectionDictionary.mapUidToConnection[ID]).receiveNotification(message); WanderingAlgo algo = new WanderingAlgo(); Trace.TraceInformation("Starting Detection Algo for Patient {0} due to caregiver registration", currPatient.Id); algo.wanderingDetectionAlgo(currPatient.Id); } } catch (Exception e) { Trace.TraceError("Registration of " + ID + " failed or Exception in wandering Algo: " + e.Message); } }
/// Step A - PREPROCESS public void preprocessAlgoData(string currentPatientID) { Trace.TraceInformation(String.Format("Current PatientID is {0}", currentPatientID)); /// 1. Get latest sample SampleController sampleController = new SampleController(); latestSample = sampleController.GetLatestSampleForPatient(currentPatientID); Trace.TraceInformation(String.Format("Latest sample timestamp is {0}", latestSample.CreatedAt)); //insert caregivers to caregiversArr PatientController patientController = new PatientController(); CaregiverController caregiverController = new CaregiverController(); caregiversArr = caregiverController.GetCaregiversforPatientID(currentPatientID); patientName = patientController.GetPatientName(currentPatientID); Trace.TraceInformation(String.Format("Patient name is {0}", patientName)); Trace.TraceInformation(String.Format("Caregivers array first email is {0}", (caregiversArr.First()).Email)); //extract patient's known locations LocationController locationController = new LocationController(); knownLocations = locationController.GetKnownLocationsforPatientID(currentPatientID); Trace.TraceInformation(String.Format("Found {0} known locations for this patient", knownLocations.Length)); Trace.TraceInformation(String.Format("First known location is {0}", knownLocations[0].Description)); //set currentLoc and closestKnowLocation currentLoc = new GeoCoordinate(latestSample.Latitude, latestSample.Longitude); closestKnownLocation = AlgoUtils.closestKnownLocation(currentLoc, knownLocations); Trace.TraceInformation(String.Format("Current location is {0}", currentLoc.ToString())); Trace.TraceInformation(String.Format("Closest known location is {0}", closestKnownLocation.Description)); Trace.TraceInformation(String.Format("Current world time is {0}", DateTime.Now)); //get latest sample time sampleTime = latestSample.CreatedAt.Value; Trace.TraceInformation(String.Format("Latest sample time is {0}", sampleTime)); //get avg patient's HR, and set our limits AVG_PATIENT_HR = AlgoUtils.avgHeartRate(currentPatientID); HEART_RATE_TOP_LIMIT = 1.4 * AVG_PATIENT_HR; HEART_RATE_BOTTOM_LIMIT = 0.5 * AVG_PATIENT_HR; Trace.TraceInformation(String.Format("Avg patient heartrate is {0}", AVG_PATIENT_HR)); Trace.TraceInformation(String.Format("BottomLimit patient heartrate is {0}", HEART_RATE_BOTTOM_LIMIT)); Trace.TraceInformation(String.Format("TopLimit patient heartrate is {0}", HEART_RATE_TOP_LIMIT)); }
public static void static_send(string patientID, string patientName, IEnumerable <Caregiver> caregiversArr, AlgoUtils.Status status) { Trace.TraceInformation(String.Format("Sending Patient {0} status: {1} to all caregivers", patientID, status.ToString())); ConnectionDictionary.mapUidToStatus[patientID] = status; //update patient status SampleController sampleController = new SampleController(); Sample latestSample = sampleController.GetLatestSampleForPatient(patientID); Message message = new Message() { ID = patientID, status = status, name = patientName, lat = latestSample.Latitude, lon = latestSample.Longitude }; foreach (var caregiver in caregiversArr) { try { ConnectionDictionary.mapUidToStatus[caregiver.Id] = status; hubContext.Clients.Client(ConnectionDictionary.mapUidToConnection[caregiver.Id]).receiveNotification(message); Trace.TraceInformation(String.Format("Sent message to caregiver {0}", caregiver.Id)); } catch (Exception e) { Trace.TraceError(e.Message); } } //Trace.TraceInformation(String.Format("Sending message to patient for testing")); //try //{ // hubContext.Clients.Client(ConnectionDictionary.mapUidToConnection[patientID]).receiveNotification(message); // Trace.TraceInformation(String.Format("Sent message back to patient {0}", patientName)); //} //catch (Exception e) //{ // Trace.TraceError(e.Message); //} }