Exemple #1
0
        public string UploadPrescription(FormCollection form)
        {
            string prescriptionFilePath = "~/Attachments/Prescriptions/" +
                                          Path.GetRandomFileName().Replace(".", "") + ".jpg";
            List <List <string> > medicinesAlternatives = new List <List <string> >();
            long medicalPlaceID = Convert.ToInt64(Request.Cookies["placeInfo"].Values["id"]);

            string[] symptoms       = form.GetValues("symptomName");
            string[] diseases       = form.GetValues("diseaseName");
            string[] genticDiseases = form.GetValues("genetic");
            string[] medicines      = form.GetValues("drugName");
            string[] doses          = form.GetValues("dose");
            string   remarks        = form["remarks"];

            HistoryRecord historyRecord = new HistoryRecord
            {
                Date           = DateTime.Now,
                Remarks        = remarks,
                MedicalPlaceID = medicalPlaceID,
                CitizenID      = Convert.ToInt64(form["Id"]),
                SpecialistID   = User.Identity.GetUserId <long>()
            };

            // assign symptoms to history record
            for (int i = 0; i < symptoms.Length; i++)
            {
                symptoms[i] = symptoms[i].Trim();
                if (!symptoms[i].Equals(""))
                {
                    historyRecord.Symptoms.Add(new Symptom {
                        Name = symptoms[i]
                    });
                }
            }

            // assign diseases to history record
            for (int i = 0; i < diseases.Length; i++)
            {
                diseases[i] = diseases[i].Trim();
                if (!diseases[i].Equals(""))
                {
                    historyRecord.Diseases.Add(new Disease {
                        Name = diseases[i], IsGenetic = false
                    });
                }
            }

            // assign genetic diseases
            List <Disease> historyRecordDiseases = historyRecord.Diseases.ToList();

            for (int i = 0; genticDiseases != null && i < Math.Min(genticDiseases.Length, diseases.Length); i++)
            {
                if (diseases[Convert.ToInt32(genticDiseases[i]) - 1] == "")
                {
                    continue;
                }

                historyRecordDiseases[Convert.ToInt32(genticDiseases[i]) - 1].IsGenetic = true;
            }

            // get selected medicines alternatives from form
            for (int i = 0; i < medicines.Length; i++)
            {
                if (form.GetValues("medicineAlternativeFor" + i) == null)
                {
                    medicinesAlternatives.Add(new List <string>());
                    continue;
                }

                medicinesAlternatives.Add(form.GetValues("medicineAlternativeFor" + i).ToList());
            }

            // save history record to database
            Bitmap bitmap = MedicalHistoryBusinessLayer.SavePrescription(historyRecord,
                                                                         medicines, doses, medicinesAlternatives, prescriptionFilePath, (userId, diseaseName) => NotificationsHub.NotifyPrognosis(userId, diseaseName));

            // don't save prescription if null
            if (bitmap != null)
            {
                bitmap.Save(Server.MapPath(prescriptionFilePath), ImageFormat.Jpeg);
            }
            else
            {
                return(null);
            }

            return(Path.GetFileName(prescriptionFilePath));
        }