Пример #1
0
        public static void WorkAllDevices()
        {
            Random rnd = new Random();

            do
            {
                Thread.Sleep(180000);

                EntityModelContainer container = new EntityModelContainer();

                foreach (Device device in container.DeviceSet)
                {
                    int choice = rnd.Next(0, 50);

                    if (choice != 49)
                    {
                        MeasuredData newData = CreateMeasure(device, device.Patient);
                        AddMeasuredData(newData, device.Patient, device);
                    }
                    else
                    {
                        DeviceMessage message = CreateDeviceMessage(device);
                        AddDeviceMessage(message);
                    }
                }
            } while (true);
        }
Пример #2
0
        public static void AddMeasuredData(MeasuredData data, Patient owner, Device device)
        {
            EntityModelContainer container = new EntityModelContainer();

            container.MeasuredDataSet.Add(data);
            //   container.SaveChanges();

            owner  = container.PatientSet.Find(owner.UserCode);
            data   = container.MeasuredDataSet.Find(data.Number);
            device = container.DeviceSet.Find(device.DeviceCode);

            owner.MeasuredData.Add(data);
            data.Patient = owner;

            container.SaveChanges();
        }
Пример #3
0
        /*    static int GetHealthStatusCode()
         *  {
         *      int statusCode = 0;
         *      bool hasStatus = false;
         *      EntityModelContainer container = new EntityModelContainer();
         *
         *      do
         *      {
         *          statusCode++;
         *          HealthStatus exist = container.HealthStatusSet.Find(statusCode);
         *
         *          hasStatus = (exist != null);
         *      } while (hasStatus);
         *
         *      return statusCode;
         *  }*/

        public static MeasuredData CreateMeasure(Device device, Patient owner)
        {
            string measure = string.Empty;

            switch (device.Function)
            {
            case DeviceFunction.Glucometer:
                double prevLevel;

                GetPreviousSugarLevel(device, out prevLevel);
                measure = MeasureGenerator.BloodSugarLevelGenerator(prevLevel);
                break;

            case DeviceFunction.HeartRateMonitor:
                int prevRate;
                GetPreviousPulse(device, out prevRate);

                measure = MeasureGenerator.HeartRateGenerator(prevRate);
                break;

            case DeviceFunction.BloodPressureMonitor:
                int prevHigh;
                int prevLow;

                GetPreviousPressure(device, out prevHigh, out prevLow);

                measure = MeasureGenerator.BloodPressureGenerator(prevHigh, prevLow);
                break;
            }

            MeasuredData data = new MeasuredData();

            data.Value        = measure;
            data.CreatingTime = DateTime.Now;
            data.DeviceCode   = device.DeviceCode;
            data.OwnerCode    = owner.UserCode;
            //  data.Number = GetMeasuredDataCode();

            return(data);
        }
Пример #4
0
        static void GetPreviousSugarLevel(Device device, out double level)
        {
            level = 0;

            EntityModelContainer container = new EntityModelContainer();
            Patient owner = container.PatientSet.Find(device.OwnerCode);

            List <MeasuredData> list = (from data in owner.MeasuredData
                                        where data.DeviceCode == device.DeviceCode
                                        select data)
                                       .ToList();

            if (list.Count != 0)
            {
                MeasuredData last = list.Max();

                string measurePattern = @"([\d|,]+) ммоль/л.";

                string[] value = Regex.Split(last.Value, measurePattern);

                level = double.Parse(value[1]);
            }
        }
Пример #5
0
        static void GetPreviousPulse(Device device, out int rate)
        {
            rate = 0;

            EntityModelContainer container = new EntityModelContainer();
            Patient owner = container.PatientSet.Find(device.OwnerCode);

            List <MeasuredData> list = (from data in owner.MeasuredData
                                        where data.DeviceCode == device.DeviceCode
                                        select data)
                                       .ToList();

            if (list.Count != 0)
            {
                MeasuredData last = list.Max();

                string measurePattern = @"([\d]+) уд/мин.";

                string[] value = Regex.Split(last.Value, measurePattern);

                rate = int.Parse(value[1]);
            }
        }
Пример #6
0
        static void GetPreviousPressure(Device device, out int high, out int low)
        {
            high = 0;
            low  = 0;

            EntityModelContainer container = new EntityModelContainer();
            Patient owner = container.PatientSet.Find(device.OwnerCode);

            List <MeasuredData> list = (from data in owner.MeasuredData
                                        where data.DeviceCode == device.DeviceCode
                                        select data)
                                       .ToList();

            if (list.Count != 0)
            {
                MeasuredData last = list.Max();

                string measurePattern = @"([\d]+)\s/\s([\d]+)";

                string[] values = Regex.Split(last.Value, measurePattern);
                high = int.Parse(values[1]);
                low  = int.Parse(values[2]);
            }
        }