Example #1
0
        public IActionResult UpdateDevice(string deviceId,
                                          [FromQuery] string name,
                                          [FromQuery] int patientId,
                                          [FromQuery] string lastsync)
        {
            //Check if valid patient ID entered
            Patient p = (from a in _context.Patients
                         where a.Id == patientId
                         select a).SingleOrDefault();

            if (p == null)
            {
                return(BadRequest(String.Format("Patient ID: {0} not found.", patientId)));
            }

            Device data = (from a in _context.Devices
                           where (a.Id == deviceId)
                           select a).SingleOrDefault();

            if (data == null)
            {
                //Add new device
                Device nDev = new Device()
                {
                    Id           = deviceId,
                    FriendlyName = "MetaMotion",
                    PatientID    = patientId,
                    LastSync     = DateTime.Now
                };

                _context.Devices.Add(nDev);
                _context.SaveChanges(); //save changes here to get the new ID

                //Update patient
                p.DeviceId = nDev.Id;
            }
            else
            {
                p.DeviceId = data.Id;

                var date = new DateTime();

                if (DateTime.TryParse(lastsync, out date))
                {
                    data.LastSync = date;
                }
                else
                {
                    data.LastSync = DateTime.Now;
                }

                data.Id           = deviceId;
                data.FriendlyName = name;
                data.PatientID    = patientId;
            }

            _context.SaveChanges();
            return(new JsonResult(p));
        }
        public void Test_GetPatients()
        {
            // Arrange
            context.Patients.Add(new Patient {
                Id        = patientId,
                DeviceId  = deviceId,
                FirstName = firstName,
                LastName  = lastName
            });

            context.SaveChanges();

            var evaluator = new PatientsEvaluator(context);

            // Act
            var patientsResult = evaluator.GetPatients();

            // Assert
            var patientsResultJson = patientsResult as JsonResult;

            Assert.NotNull(patientsResultJson);

            var jsonResult = JsonConvert.SerializeObject(patientsResultJson.Value).ToString();
            var patients   = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(jsonResult);

            var insertedPatient = from patient in patients
                                  where patient["Id"] == patientId.ToString()
                                  select patient;

            Assert.Equal(insertedPatient.Count(), 1);
        }
Example #3
0
 public JsonResult GetPatients()
 {
     if (isFirstRun)
     {
         var demoPatients = new List <Patient> {
             new Patient {
                 DeviceId  = "1",
                 FirstName = "Joe",
                 LastName  = "Johnson"
             },
             new Patient {
                 DeviceId  = "2",
                 FirstName = "Ruth",
                 LastName  = "Reynolds",
             },
             new Patient {
                 DeviceId  = "3",
                 FirstName = "Marie",
                 LastName  = "Anderson"
             }
         };
         _context.Patients.AddRange(demoPatients);
         _context.SaveChanges();
         isFirstRun = false;
     }
     return(new JsonResult(_context.Patients.ToList()));
 }
Example #4
0
        public IActionResult SignUp(string email, string firstName, string lastName, string password)
        {
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            byte[] buffer = new byte[128];

            rng.GetBytes(buffer);
            string salt     = Convert.ToBase64String(buffer);
            var    saltedPw = password + salt;

            var hashedPw = generateHash(saltedPw);

            User data = new User();

            data.Email     = email;
            data.FirstName = firstName;
            data.LastName  = lastName;
            data.Password  = hashedPw;
            data.Salt      = salt;

            _context.Users.Add(data);
            _context.SaveChanges();

            return(Ok());
        }
Example #5
0
        public void AddSensorData(int patientId, IFormFile accelerometerFile, IFormFile gyroscopeFile)
        {
            var result = readData(accelerometerFile);
            var AccelerometerObjects = result.Skip(1)
                                       .Select(line => line.Split(","))
                                       .Select(tokens => new Accelerometer
            {
                Id        = Guid.NewGuid().ToString(),
                PatientId = Convert.ToInt32(patientId),
                Epoch     = Convert.ToInt64(tokens[0]),
                Timestamp = DateTime.Parse(tokens[1]),
                Elapsed   = Convert.ToDouble(tokens[2]),
                XAxis     = Convert.ToDouble(tokens[3]),
                YAxis     = Convert.ToDouble(tokens[4]),
                ZAxis     = Convert.ToDouble(tokens[5])
            })
                                       .ToList();

            _context.AccelerometerData.AddRange(AccelerometerObjects);

            result = readData(gyroscopeFile);
            var GyroscopeObjects = result.Skip(1)
                                   .Select(line => line.Split(","))
                                   .Select(tokens => new Gyroscope
            {
                Id        = Guid.NewGuid().ToString(),
                PatientId = Convert.ToInt32(patientId),
                Epoch     = Convert.ToInt64(tokens[0]),
                Timestamp = DateTime.Parse(tokens[1]),
                Elapsed   = Convert.ToDouble(tokens[2]),
                XAxis     = Convert.ToDouble(tokens[3]),
                YAxis     = Convert.ToDouble(tokens[4]),
                ZAxis     = Convert.ToDouble(tokens[5])
            })
                                   .ToList();

            _context.GyroscopeData.AddRange(GyroscopeObjects);
            _context.SaveChanges();

            sendDataToMlService(patientId, accelerometerFile, gyroscopeFile);
        }
Example #6
0
        public DevicesEvaluatorTests()
        {
            // Arrange
            context.Patients.Add(new Patient {
                Id        = patientId,
                DeviceId  = deviceId,
                FirstName = firstName,
                LastName  = lastName
            });

            context.Devices.Add(new Device {
                Id           = deviceId,
                FriendlyName = friendlyName,
                PatientID    = patientId,
                LastSync     = lastsync
            });
            context.SaveChanges();
        }
Example #7
0
        public void CreatePatient(string patientData)
        {
            JObject parsedPatientData = JObject.Parse(patientData);

            Patient p = new Patient()
            {
                DeviceId  = "",
                FirstName = (string)parsedPatientData["firstName"],
                LastName  = (string)parsedPatientData["lastName"]
            };

            _context.Patients.Add(p);
            _context.SaveChanges(); //Save changes here to retrieve the db generate Id for patient


            Patient_Impl data = new Patient_Impl()
            {
                Id   = p.Id,
                Data = parsedPatientData.ToString()
            };

            _context.Patients_Impl.Add(data);
            _context.SaveChanges();
        }
        public async Task <IActionResult> AddSensorData(int patientId, IFormFile accelerometerFile, IFormFile gyroscopeFile)
        {
            var result = readData(accelerometerFile);
            var AccelerometerObjects = result.Skip(1)
                                       .Select(line => line.Split(","))
                                       .Select(tokens => new Accelerometer
            {
                Id        = Guid.NewGuid().ToString(),
                PatientId = Convert.ToInt32(patientId),
                Epoch     = Convert.ToInt64(tokens[0]),
                Timestamp = DateTime.Parse(tokens[1]),
                Elapsed   = Convert.ToDouble(tokens[2]),
                XAxis     = Convert.ToDouble(tokens[3]),
                YAxis     = Convert.ToDouble(tokens[4]),
                ZAxis     = Convert.ToDouble(tokens[5])
            })
                                       .ToList();

            _context.AccelerometerData.AddRange(AccelerometerObjects);

            result = readData(gyroscopeFile);
            var GyroscopeObjects = result.Skip(1)
                                   .Select(line => line.Split(","))
                                   .Select(tokens => new Gyroscope
            {
                Id        = Guid.NewGuid().ToString(),
                PatientId = Convert.ToInt32(patientId),
                Epoch     = Convert.ToInt64(tokens[0]),
                Timestamp = DateTime.Parse(tokens[1]),
                Elapsed   = Convert.ToDouble(tokens[2]),
                XAxis     = Convert.ToDouble(tokens[3]),
                YAxis     = Convert.ToDouble(tokens[4]),
                ZAxis     = Convert.ToDouble(tokens[5])
            })
                                   .ToList();

            _context.GyroscopeData.AddRange(GyroscopeObjects);
            _context.SaveChanges();


            var accelMs = new MemoryStream();

            accelerometerFile.OpenReadStream().CopyTo(accelMs);

            var gyroMs = new MemoryStream();

            gyroscopeFile.OpenReadStream().CopyTo(gyroMs);

            var callbackId = Guid.NewGuid().ToString();

            MultipartFormDataContent form = new MultipartFormDataContent();

            form.Add(new StringContent("false"), "test");
            form.Add(new StringContent(SERVER_URL + "api/SensorData/Callback?Id=" + callbackId), "callback_url");
            form.Add(new ByteArrayContent(accelMs.ToArray()), "file[]", accelerometerFile.FileName);
            form.Add(new ByteArrayContent(gyroMs.ToArray()), "file[]", gyroscopeFile.FileName);

            HttpResponseMessage response = await client.PostAsync(ML_SERVER_URL + "windowify", form);

            response.EnsureSuccessStatusCode();

            mlCallbackIds.TryAdd(callbackId, patientId);

            return(Ok());
        }