Example #1
0
        public static Patient GetPatient(this Models.ForApi.Patient apiPatient, Models.ForApi.PatientInitial patientInitial, Models.ForApi.Login login, List <Models.ForApi.Medic> medics)
        {
            Patient patient = new Patient();

            patient.Name             = apiPatient.Name;
            patient.Surname          = apiPatient.Surname;
            patient.Age              = apiPatient.Age;
            patient.Phone            = apiPatient.Phone;
            patient.Address_home     = apiPatient.Address_home;
            patient.Address_hospital = apiPatient.Address_hospital;
            patient.Email_notify     = apiPatient.Email_notify;
            patient.Sms_notify       = apiPatient.Sms_notify;

            patient.Pregnancy_start_date = patientInitial.Pregnancy_start_date;
            patient.Weight = patientInitial.Weight;
            patient.Height = patientInitial.Height;
            patient.Bmi    = patientInitial.Bmi;
            patient.Twin   = patientInitial.Twin;

            patient.Email = login.Email;

            foreach (Models.ForApi.Medic medic in medics)
            {
                if (medic.Id != 0)
                {
                    patient.Medics.Add(new MedicsForPatient(medic.Id, medic.Name, medic.Surname, medic.Specialization));
                }
            }

            return(patient);
        }
Example #2
0
        public static Weights GetWeights(this Models.ForApi.WeightsList weightsList, Models.ForApi.PatientInitial patientInitial, Models.ForApi.Threshold threshold)
        {
            Weights  weights   = new Weights();
            DateTime startDate = DateTime.Parse(patientInitial.Pregnancy_start_date);

            weights.Date.Add(DateTime.ParseExact(startDate.ToString(), Constant.DATETIME_FORMAT, CultureInfo.InvariantCulture).ToString(Constant.DATE_API_FORMAT));
            weights.Weight.Add(patientInitial.Weight);
            startDate = startDate.AddDays(1);
            double max = 0;

            double avg;
            double count;

            for (int i = 1; i <= Constant.WEIGHT_LIMIT; i++)
            {
                weights.Date.Add(DateTime.ParseExact(startDate.ToString(), Constant.DATETIME_FORMAT, CultureInfo.InvariantCulture).ToString(Constant.DATE_API_FORMAT));

                avg   = 0d;
                count = 0d;
                for (int j = 0; j < 7; j++)
                {
                    if (weightsList != null)
                    {
                        foreach (Models.ForApi.Weights w in weightsList.Weights)
                        {
                            if (DateTime.Parse(w.Date).Equals(startDate))
                            {
                                avg   += w.Weight;
                                count += 1;
                                break;
                            }
                        }
                    }
                    startDate = startDate.AddDays(1);
                }

                if (count != 0)
                {
                    weights.Weight.Add(avg / count);
                    if (avg / count > max)
                    {
                        max = avg / count;
                    }
                }
                else
                {
                    weights.Weight.Add(null);
                }
            }

            weights.LowerThreshold = threshold.Min;
            weights.UpperThreshold = threshold.Max;

            if (threshold.Max.Last() > max)
            {
                max = threshold.Max.Last();
            }

            weights.Min = patientInitial.Weight - 2;
            weights.Max = max + 2;

            return(weights);
        }