private string EncodePayLoad(string deviceId, int compartmentId)
        {
            using (var context = new MedicalDataManagerDataBaseContainer())
            {
                var medPlans = context.MedicationPlans.Where(x => x.DeviceId == deviceId && x.CompartmentNbr == compartmentId);
                var device   = context.Devices.SingleOrDefault(x => x.Id == deviceId);
                if (device != null)
                {
                    // List<string> allCompartmentDataOfDevice = new List<string>();
                    foreach (var medicationPlan in medPlans)
                    {
                        short token       = (short)medicationPlan.TokenId;
                        byte  dosage      = (byte)medicationPlan.DosageId;
                        long  from        = UnixTimestampFromDateTime(medicationPlan.ValidFrom);
                        long  to          = UnixTimestampFromDateTime(medicationPlan.Validto);
                        byte  compartment = (byte)medicationPlan.CompartmentNbr;
                        byte  critical    = (byte)(medicationPlan.Critical ? 1 : 0);

                        StringBuilder sb = new StringBuilder();
                        sb.Append(compartment.ToString("X2"));
                        sb.Append(token.ToString("X4"));
                        sb.Append(dosage.ToString("X2"));
                        sb.Append(from.ToString("X16"));
                        sb.Append(to.ToString("X16"));
                        sb.Append(critical.ToString("X2"));
                        return(sb.ToString());
                    }
                }
            }
            return("00FFFF");
        }
Ejemplo n.º 2
0
 public TokenEditdialogViewModel()
 {
     using (var context = new MedicalDataManagerDataBaseContainer())
     {
         this.Persons = new ObservableCollection <Person>(context.People.ToList());
     }
 }
Ejemplo n.º 3
0
 public void SaveData()
 {
     using (var context = new MedicalDataManagerDataBaseContainer())
     {
         Token newToken = new Token();
         newToken.Person_Id = SelectedPerson.Id;
         newToken.Id        = int.Parse(TokenId);
         context.Tokens.Add(newToken);
         context.SaveChanges()
         ;
     }
 }
        public string ReturnAlarmdata(string payLoad)
        {
            int token = DecryptPayload(payLoad);

            using (var context = new MedicalDataManagerDataBaseContainer())
            {
                var personId = context.Tokens.Where(x => x.Id == token).FirstOrDefault();
                var pers     = context.People.FirstOrDefault(x => x.Id == personId.Person_Id);
                return
                    (string.Format("{0}, {1}, {2}, {3}, {4}", pers.Lastname, pers.Firstname, pers.PhoneNumber, pers.Email,
                                   pers.Twitter));
            }
        }
        public void SaveAction(int actionid, string payload, DateTime timeStamp, string devUid)
        {
            int token = DecryptPayload(payload);

            using (var context = new MedicalDataManagerDataBaseContainer())
            {
                Action act = new Action();
                act.ActionTypeId = actionid;
                act.DeviceId     = devUid;
                act.Payload      = payload;
                act.TimeStamp    = timeStamp;
                act.TokenId      = token;
                context.Actions.Add(act);
                context.SaveChanges();
            }
        }