/// <summary>
        /// Add medication to patient
        /// </summary>
        /// <returns></returns>
        public JsonResult AddMedicationToPatient()
        {
            try
            {
                PatientRepository repo = new PatientRepository();
                Patient patient = repo.Get(int.Parse(Request.Form["patientID"]));
                PatientMedicationRepositiry pmr = new PatientMedicationRepositiry();
                MedicationRepository medRepo = new MedicationRepository();

                PatientMedication pMed = new PatientMedication();
                pMed.Medication = medRepo.Get(int.Parse(Request.Form["name"]));
                pMed.Instruction = Request.Form["instructions"];
                pMed.StartDate = DateTime.Now;
                pMed.ExpDate = DateTime.Parse(Request.Form["expDate"]);
                pMed.Administration = (MedicationRouteOfAdministrationType)Enum.Parse(typeof(MedicationRouteOfAdministrationType), Request.Form["route"]);
                pMed.Dose = Request.Form["dose"];
                pMed.Frequency = Request.Form["frequency"];
                pMed.Patient = patient;

                pmr.Add(pMed);

                return Json(new
                                {
                                    error = "false",
                                    id = pMed.Medication.Id,
                                    name = pMed.Medication.Name,
                                    dose = pMed.Dose,
                                    frequency = pMed.Frequency,
                                    route = Enum.GetName(typeof(OpenEhs.Domain.MedicationRouteOfAdministrationType), pMed.Administration),
                                    instructions = pMed.Instruction,
                                    startDate = pMed.StartDate.ToString("dd/MM/yyyy"),
                                    expDate = pMed.ExpDate.ToString("dd/MM/yyyy")
                                });

            }
            catch (Exception e)
            {
                return Json(new
                                {
                                    error = "true",
                                    status = "Unable to add medication to patient",
                                    errorMessage = e.Message
                                });
            }
        }
Esempio n. 2
0
        public JsonResult EditMedication()
        {
            try
            {
                MedicationRepository medicationRepo = new MedicationRepository();
                Medication medication = medicationRepo.Get(int.Parse(Request.Form["Medication"]));
                medication.Name = Request.Form["EditMedication"];

                return Json(new
                {
                    error = "false"
                });
            }
            catch
            {
                return Json(new
                {
                    error = "true"
                });
            }
        }
        /// <summary>
        /// Create new medication
        /// </summary>
        /// <returns></returns>
        public JsonResult CreateNewMedication()
        {
            try
            {
                Medication pMed = new Medication();

                pMed.Name = Request.Form["MedicationName"];
                pMed.Description = Request.Form["MedicationDescription"];
                pMed.IsActive = true;

                MedicationRepository medicationRepo = new MedicationRepository();

                medicationRepo.Add(pMed);

                return Json(new
                                {
                                    error = "false",
                                    Name = pMed.Name,
                                    Id = pMed.Id
                                });

            }
            catch (Exception e)
            {
                return Json(new
                                {
                                    error = "true",
                                    status = "Unable to add new medication successfully",
                                    errorMessage = e.Message
                                });
            }
        }
Esempio n. 4
0
        public JsonResult DeleteMedication()
        {
            try
            {
                MedicationRepository medicationRepo = new MedicationRepository();
                medicationRepo.Remove(medicationRepo.Get(int.Parse(Request.Form["Medication"])));

                return Json(new
                {
                    error = "false"
                });
            }
            catch
            {
                return Json(new
                {
                    error = "true"
                });
            }
        }