コード例 #1
0
ファイル: JSONConvertor.cs プロジェクト: radtek/VideoTherapy
        /// <summary>
        /// Parse from json content to current patient treatment
        /// </summary>
        /// <param name="_JSONcontent">The response json</param>
        /// <param name="_patient">The _patient object</param>
        public static void GettingPatientTreatment(Patient _patient, string _JSONcontent)
        {
            //todo - run over the treatments
            dynamic d =
                (JsonConvert.DeserializeObject <IDictionary <string, object> >(_JSONcontent));


            bool checkError = checkForErrors((int)d["code"]);

            if (checkError)
            {
                ErrorEvent(null, new ErrorMessege(((ServerCode)d["code"]).ToString(), (int)d["code"]));
                return;
            }

            dynamic list = (JsonConvert.DeserializeObject <IDictionary <string, object> >(_JSONcontent))["data"];

            List <Treatment> treatments = new List <Treatment>();

            foreach (var item in list)
            {
                Treatment treatment = new Treatment();

                //treatment details
                treatment.TreatmentNumber   = list.IndexOf(item) + 1;
                treatment.TreatmentId       = item.treatmentId;
                treatment.StartDate         = DateTime.Parse((string)item.treatmentStartTime["date"]);
                treatment.EndDate           = DateTime.Parse((string)item.treatmentEndTime["date"]);
                treatment.TreatmentProgress = DateFormat.CalcTreatementDateProgress(treatment.StartDate, treatment.EndDate);

                //treatment scoring
                try
                {
                    Dictionary <string, float> scoringDic = JsonConvert.DeserializeObject <Dictionary <string, float> >(item.scoring.ToString());
                    treatment.TreatmentCompliance = (int)(scoringDic["num_repition_done"] / scoringDic["num_repition_total"] * 100);
                    treatment.TreatmentScore      = (int)(scoringDic["motion_quality"] * 100);
                }
                catch
                {
                    treatment.TreatmentCompliance = 0;
                    treatment.TreatmentScore      = 0;
                }


                //therapist details
                treatment.TreatmentTherapist            = new Therapist();
                treatment.TreatmentTherapist.AccountId  = item.therapistId;
                treatment.TreatmentTherapist.FirstName  = item.therapistFirst;
                treatment.TreatmentTherapist.LastName   = item.therapistLast;
                treatment.TreatmentTherapist.ImageThumb = item.therapistThumbnail;
                //todo - change when will be a the date of start connection between therapist and patient
                treatment.TreatmentTherapist.StartDate = treatment.StartDate;

                //trainings:
                treatment.TrainingList = CreateTrainingList(item["trainings"].ToString());

                //set recomended training to treatment
                //todo
                foreach (var training in treatment.TrainingList)
                {
                    if (training.IsRecommended)
                    {
                        treatment.RecommendedTraining = training;
                        break;
                    }
                }

                treatments.Add(treatment);
            }

            //Now there is only one treatment:
            _patient.PatientTreatment = treatments.First();
        }