public ActionResult HeartbeatFromDevice(string deviceId)
 {
     if (deviceId == null || deviceId.Length == 0)
     {
         return(BadRequest());
     }
     heartbeat.AddHeartbeat(deviceId);
     return(Json("success"));
 }
Exemple #2
0
        public JsonResult RecordMedicationEvent(string deviceId, string medicationId, string recurrenceId, DateTimeOffset time, bool wasTakenOnTime)
        {
            // TODO: authenticate
            var associatedRecurrence = dataContext.Recurrence.First(x => x.RecurrenceId == recurrenceId);

            if (associatedRecurrence == null)
            {
                return(Json("failed"));
            }

            // add heartbeat
            heartbeat.AddHeartbeat(deviceId);

            // TODO: ensure the patient for the device was prescribed that medicationId and has a matching recurrenceId for it
            // TODO: Add a Dose record, associated it with the recurrence
            var dose = new Dose {
                AssociatedRecurrence = associatedRecurrence, TimeTaken = time, wasOnTime = wasTakenOnTime
            };

            associatedRecurrence.Doses.Append(dose);
            dataContext.SaveChanges();

            return(Json("success"));
        }