public ActionResult ViewPatientEncounters(int id)
        {
            int PracticeID = Convert.ToInt32(Session["sespracticeid"]);

            ViewBag.StatusID = from v in db.StatusList
                               where v.StatusID == 3 || v.StatusID == 4 || v.StatusID == 5
                               select v;
            IEnumerable<Encounter_Accessories> patientenc = (from p in db.Encounter_AccessoriesList
                                                             where p.EncounterID == id && p.patientenc.equip.PracticeID == PracticeID
                                                             select p).ToList();
            Encounter_Accessories enc = new Encounter_Accessories();
            if (patientenc.Count() == 0)
            {
                List<Encounter_Accessories> patient = new List<Encounter_Accessories>();
                enc.EncAccID = enc.EncounterID = enc.AccessoryID = enc.Quantity = 0;
                enc.patientenc = db.PatientEncountersList.Find(id);
                patient.Add(enc);
                return View(patient);
            }
            else
                return View(patientenc);
        }
        public JsonResult CreateEncounterAccessories(List<Encounter_Accessories> objEncounterAccs)
        {
            string msg = "";
            try {

                foreach (Encounter_Accessories objItem in objEncounterAccs)
                {
                    var objDelEncAcces = (from p in objDBContext.Encounter_AccessoriesList
                                          where p.EncounterID == objItem.EncounterID
                                          select p).FirstOrDefault();

                    objDBContext.Encounter_AccessoriesList.Remove(objDelEncAcces);
                    objDBContext.SaveChanges();
                }

                foreach (Encounter_Accessories objItem in objEncounterAccs)
                {
                    Encounter_Accessories objNewEnAcces = new Encounter_Accessories();
                    objNewEnAcces.EncounterID = objItem.EncounterID;
                    objNewEnAcces.AccessoryID = objItem.AccessoryID;

                    objDBContext.Encounter_AccessoriesList.Add(objNewEnAcces);
                    objDBContext.SaveChanges();
                }

                msg = "Success";
            }
            catch(Exception ex)
            {
                msg = "Failed";
                msg = ex.Message;
            }

            return Json(new { result = msg }, JsonRequestBehavior.AllowGet);
        }
 public ActionResult EditPatientEncounters(Encounter_Accessories encounter, FormCollection frm)
 {
     var EquipID = frm["patientenc.EquipID"];
     string[] k = EquipID.Split(',');
     encounter.patientenc.EquipID = Convert.ToInt32(k[1]);
     var StatusID = frm["patientenc.StatusID"];
     encounter.patientenc.StatusID = Convert.ToInt32(StatusID);
     var Delivery_Method = frm["ddlUserType"];
     encounter.patientenc.Delivery_Method = Delivery_Method;
     var PresEquip = frm["ddlPrescEquip"];
     encounter.patientenc.Ptn_Presc_Of_Equip = PresEquip;
     //var ContAdm =Convert.ToBoolean(frm["patientenc.Ptn_Continu_Administrat"]);
     //encounter.patientenc.Ptn_Continu_Administrat =ContAdm;
     db.Entry(encounter.patientenc).State = EntityState.Modified;
     db.SaveChanges();
     return RedirectToAction("EditPatientEncounters/" + encounter.patientenc.EncounterID);
 }
        public ActionResult EditPatientEncounters(int id)
        {
            int PracticeID = Convert.ToInt32(Session["sespracticeid"]);
            IEnumerable<Encounter_Accessories> patientenc = (from p in db.Encounter_AccessoriesList
                                                             where p.EncounterID == id && p.patientenc.equip.PracticeID == PracticeID
                                                             select p).ToList();
            if (patientenc.Count() > 0)
            {
                if (patientenc.First().patientenc.StatusID == 1)
                    ViewBag.StatusID = from v in db.StatusList
                                       where v.StatusID == 1 || v.StatusID == 5
                                       select v;
                else
                    ViewBag.StatusID = from v in db.StatusList
                                       where v.StatusID == 4 || v.StatusID == 5
                                       select v;
                if (patientenc.First().patientenc.Delivery_Method == "")
                    patientenc.First().patientenc.Delivery_Method = "to nursing facility";
                var list = new SelectList(new[]
                                          {
                                              new {ID="directly to beneficiary",Name="directly to beneficiary"},
                                              new{ID="shipping service",Name="shipping service"},
                                              new{ID="to nursing facility",Name="to nursing facility"},
                                          },
                        "ID", "Name", patientenc.First().patientenc.Delivery_Method);

                ViewData["list"] = list;

                var listPrescEquip = new SelectList(new[]
                                          {
                                              new {ID="Ambit",Name="Ambit"},
                                              new{ID="CADD",Name="CADD"},
                                              new{ID="Walkmed",Name="Walkmed"},
                                                 new{ID="Curlin",Name="Curlin"}
                                          },
                              "ID", "Name", patientenc.First().patientenc.Ptn_Presc_Of_Equip);

                ViewData["listPrescEquip"] = listPrescEquip;

                if (patientenc.First().patientenc.Ptn_Continu_Administrat == null)
                    patientenc.First().patientenc.Ptn_Continu_Administrat = false;
                if (patientenc.First().patientenc.Ptn_Intravenous_Infusion == null)
                    patientenc.First().patientenc.Ptn_Intravenous_Infusion = false;
            }

            ViewBag.EquipID = from v in db.Equipments
                              where v.StatusID != 2 && v.PracticeID == PracticeID
                              select v;

            Encounter_Accessories enc = new Encounter_Accessories();
            if (patientenc.Count() == 0)
            {
                List<Encounter_Accessories> patient = new List<Encounter_Accessories>();
                enc.EncAccID = enc.EncounterID = enc.AccessoryID = enc.Quantity = 0;
                enc.patientenc = db.PatientEncountersList.Find(id);
                patient.Add(enc);
                if (patient.First().patientenc.StatusID == 1)
                    ViewBag.StatusID = from v in db.StatusList
                                       where v.StatusID == 1 || v.StatusID == 5
                                       select v;
                else
                    ViewBag.StatusID = from v in db.StatusList
                                       where v.StatusID == 4 || v.StatusID == 5
                                       select v;
                if (patient.First().patientenc.Delivery_Method == "")
                    patient.First().patientenc.Delivery_Method = "to nursing facility";
                var list = new SelectList(new[]
                                          {
                                              new {ID="directly to beneficiary",Name="directly to beneficiary"},
                                              new{ID="shipping service",Name="shipping service"},
                                              new{ID="to nursing facility",Name="to nursing facility"},
                                          },
                        "ID", "Name", patient.First().patientenc.Delivery_Method);

                ViewData["list"] = list;

                var listPrescEquip = new SelectList(new[]
                                          {
                                              new {ID="Ambit",Name="Ambit"},
                                              new{ID="CADD",Name="CADD"},
                                              new{ID="Walkmed",Name="Walkmed"},
                                                 new{ID="Curlin",Name="Curlin"}
                                          },
                              "ID", "Name", patient.First().patientenc.Ptn_Presc_Of_Equip);

                ViewData["listPrescEquip"] = listPrescEquip;

                if (patient.First().patientenc.Ptn_Continu_Administrat == null)
                    patient.First().patientenc.Ptn_Continu_Administrat = false;
                if (patient.First().patientenc.Ptn_Intravenous_Infusion == null)
                    patient.First().patientenc.Ptn_Intravenous_Infusion = false;

                return View(patient);
            }
            else
                return View(patientenc);
        }