public ActionResult Add(Health.Areas.Prescription.Models.Prescription model)
        {
            PrescriptionContext pc = new PrescriptionContext();
            HealthDB.Model.Prescription p = new HealthDB.Model.Prescription();
            p.DoctorId = model.PrescribedByUserId;
            p.Dosage = model.Strength;
            p.DrugName = model.DrugName;
            if (model.GroupName != null)
                p.GroupName = model.GroupName;
            p.Instruction = model.Direction;
            p.Invoice = DateTime.Today.Year.ToString() + DateTime.Today.Month.ToString() + DateTime.Today.Day.ToString() + "_" + model.PatientUserId + "_" + model.PrescribedByUserId;
            p.PatientId = model.PatientUserId;
            p.PharmacistId = model.PharmacistUserId;
            p.PrescriptionTypeId = model.PrescriptionTypeId;
            p.Quantity = model.Quantity;
            p.PrescriptionStatusId = 1;
            pc.Prescriptions.InsertOnSubmit(p);

            IEnumerable<DrugName> DrugNames = from drugs in pc.DrugNames
                                              where drugs.Name == model.DrugName
                                              select drugs;
            if (DrugNames == null)
            {
                DrugName dn = new DrugName();
                dn.Name = model.DrugName;
                pc.DrugNames.InsertOnSubmit(dn);
            }

            pc.SubmitChanges();
            model = GetPrescription(model.PatientUserId, model.PrescribedByUserId, DateTime.Today.Year.ToString() + DateTime.Today.Month.ToString() + DateTime.Today.Day.ToString() + "_" + model.PatientUserId + "_" + model.PrescribedByUserId, model);

            return View(model);
        }
        public ActionResult Delete (int id, int PatientID, int DoctorID)
        {
            PrescriptionContext pc = new PrescriptionContext();
            HealthDB.Model.Prescription p = (from Prescriptions in pc.Prescriptions
                                            where Prescriptions.Id == id
                                            select Prescriptions).FirstOrDefault();
            pc.Prescriptions.DeleteOnSubmit(p);
            pc.SubmitChanges();
            return RedirectToAction("Add", "Prescription", new { PatientID = PatientID, DoctorID = DoctorID});

        }
        public ActionResult Order(int PatientID, int DoctorID, string InvoiceId)
        {
            PrescriptionContext pc = new PrescriptionContext();
            IEnumerable<HealthDB.Model.Prescription> ps = from Prescriptions in pc.Prescriptions
                                                          where Prescriptions.Invoice == InvoiceId
                                                          select Prescriptions;
            foreach (var p in ps)
            {
                p.PrescriptionStatusId = 2;
            }
            pc.SubmitChanges();
            Models.Prescription model = new Models.Prescription();
            model = GetPrescription(PatientID, DoctorID, InvoiceId, model);

            return View(model);
        }
        private Models.Prescription GetPrescription(int PatientID, int DoctorID, string InvoiceId, Models.Prescription model)
        {
            ListboxHelper g = new ListboxHelper();
            model.getAllPrescriptionTypes = g.GetAllPrescriptionType();
            model.Patient = GetUser(PatientID);
            model.Doctor = GetUser(DoctorID);
            model.PatientUserId = PatientID;
            model.PrescribedByUserId = DoctorID;
            model.InvoiceId = InvoiceId;
            List<Drug> Drugs = new List<Drug>();

            PrescriptionContext pc = new PrescriptionContext();
            IEnumerable<HealthDB.Model.Prescription> ps = from Prescriptions in pc.Prescriptions
                                                          where Prescriptions.Invoice == InvoiceId
                                                          select Prescriptions;

            foreach (var p in ps)
            {
                Drug d = new Drug();
                d.Id = p.Id;
                d.Direction = p.Instruction;
                d.DrugName = p.DrugName;
                d.GroupName = p.GroupName;
                d.PrescriptionType = (from PrescriptionTypes in pc.PrescriptionTypes
                                      where PrescriptionTypes.Id == p.PrescriptionTypeId
                                      select PrescriptionTypes.Name).FirstOrDefault();
                d.Quantity = p.Quantity;
                d.Strength = p.Dosage;
                Drugs.Add(d);
            }
            model.Drugs = Drugs.OrderBy(ds => ds.PrescriptionType + ds.GroupName + ds.DrugName).ToList();
            return model;
        }
        public JsonResult AutoCompleteDrugName(string DrugName)
        {
            List<string> DrugNameList = new List<string>();
            if (DrugName.ToString().Length >= 3)
            {
                PrescriptionContext PrescriptionContext = new PrescriptionContext();
                DrugNameList = (from drugs in PrescriptionContext.DrugNames
                                                  where drugs.Name.Contains(DrugName)
                                                  select drugs.Name).ToList();
            }
            

           return Json(DrugNameList, JsonRequestBehavior.AllowGet);
        }