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); } }
public void sendHelpButtonNotificationToCareGivers(string patientID) { PatientController patientController = new PatientController(); string patientName = patientController.GetPatientName(patientID); Trace.TraceInformation(String.Format("Patient {0} pressed Help Button sending alerts to all caregivers", patientName)); CaregiverController caregiverController = new CaregiverController(); IEnumerable <Caregiver> caregiversArr = caregiverController.GetCaregiversforPatientID(patientID); static_send(patientID, patientName, caregiversArr, AlgoUtils.Status.NeedsAssistance); }
/// 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)); }
/// **notice: T1>T2>T3** ///////////////TO BE CALLED FROM SERVER////////////// public void wanderingDetectionAlgo(string currentPatientID) { Trace.AutoFlush = true; patientID = currentPatientID; if (AlgoUtils.learningStage(currentPatientID)) //if less than 200 samples { //case Learning Trace.TraceInformation(String.Format("Patient status is {0}", AlgoUtils.Status.Learning.ToString())); PatientController patientController = new PatientController(); CaregiverController caregiverController = new CaregiverController(); caregiversArr = caregiverController.GetCaregiversforPatientID(currentPatientID); patientName = patientController.GetPatientName(currentPatientID); NotificationHub.static_send(patientID, patientName, caregiversArr, AlgoUtils.Status.Learning); return; } preprocessAlgoData(currentPatientID); //update latest sample for our patient & his caregiversArr Trace.TraceInformation(String.Format("Preprocess stage is finished")); AlgoUtils.Status patientStatus = monitorAndAlert(currentPatientID); //main business logic Trace.TraceInformation(String.Format("Monitor and alert stage is done")); Trace.TraceInformation(String.Format("Patient status is {0}", patientStatus)); //Call2Action switch (patientStatus) { case AlgoUtils.Status.Safety: { NotificationHub.static_send(patientID, patientName, caregiversArr, patientStatus); //AlgoUtils.sendSMS(caregiversArr, patientStatus); //TODO:SAFETY stuff break; } case AlgoUtils.Status.Wandering: { NotificationHub.static_send(patientID, patientName, caregiversArr, patientStatus); //AlgoUtils.sendSMS(caregiversArr, patientStatus); //TODO:WANDERING stuff /// Step C - POSSIBLE_WANDERING_MODE /// 1. send PUSH to caregiver - "Do you know your beloved John is currently at (sample.location)? /// It's a strange time for him to be there" /// 1.1 if caregiver knows then /// 1.1.1 add sample.time to sample.location (if it's not happening automatically) /// 1.1.2 enter MONITORING_MODE /// 1.2 else if caregiver marks patient as wandering then enter POSSIBLE_RISK_MODE break; } case AlgoUtils.Status.Distress: { NotificationHub.static_send(patientID, patientName, caregiversArr, patientStatus); //AlgoUtils.sendSMS(caregiversArr, patientStatus); //TODO:DISTRESS stuff /// Step D - POSSIBLE_DISTRESS_MODE /// 1. send PUSH to caregiver - "Your beloved John is currently at (sample.location)? /// His heartrate is a bit abnormal - please contact him" /// 2. after 2 minutes send PUSH to caregiver - "Is your beloved John okay?" /// 1.1 if caregiver says he's okay, enter MONITORING_MODE /// 1.2 else enter POSSIBLE_RISK_MODE break; } case AlgoUtils.Status.Risk: { NotificationHub.static_send(patientID, patientName, caregiversArr, patientStatus); //AlgoUtils.sendSMS(caregiversArr, patientStatus); //TODO:RISK stuff /// Step E - POSSIBLE_RISK_MODE /// 1. Speed up sample rate (?) - every 1-3 minutes /// 2. Notify all patient's caregivers /// 3. Speak to patient (?) /// 4. Open patient's microphone and transmit to caregivers /// 5. Make alarm sounds - "I need help" - so passbyers can quickly assist (?) /// 6. When caregiver hits "I'm safe" button - enter MONITORING_MODE (can also mark I'm safe remotely?) break; } case AlgoUtils.Status.ConnectionLost: { NotificationHub.static_send(patientID, patientName, caregiversArr, patientStatus); //TODO: connectionLost stuff break; } } }