public ActionResult UpdateNotes(PatientEncounters enc)
 {
     PatientEncounters objNewEquip = (from p in db.PatientEncountersList
                                         where p.EncounterID == enc.EncounterID
                                         select p).FirstOrDefault();
     if (Session["sesuserrole"].ToString() == "Biller")
     objNewEquip.Notes = enc.Notes;
           objNewEquip.StatusID=enc.StatusID;
     db.SaveChanges();
     return Json(new { data = "Success" });
 }
 public ViewResult ViewPatientDetails(int id)
 {
     IEnumerable<PatientEncounters> model = (from p in db.PatientEncountersList
                                             where p.StatusID == 5 && p.PatientID == id
                                             select p).ToList();
     db.PatientEncountersList.Find(id);
     PatientEncounters pat = new PatientEncounters();
     if (model.Count() == 0)
     {
         List<PatientEncounters> patient = new List<PatientEncounters>();
         pat.Equip_Options = pat.Presc_Physician = pat.Delivery_Method = pat.Equip_Inspected_By = pat.Facility_Name = "";
         pat.patnt = db.Patients.Find(id);
         patient.Add(pat);
         return View(patient);
     }
     else
     return View(model);
 }
        public JsonResult GetPatientSingleEncounter(PatientEncounters objPEncounters)
        {
            var objPEncounter = (from p in objDBContext.PatientEncountersList
                                               where p.PatientID == objPEncounters.PatientID
                                               where p.EncounterID == objPEncounters.EncounterID
                                               where p.StatusID != 2
                                               select new
                                               {p.EncounterID,
                                                   p.PatientID,
                                                   p.EquipID,
                                                   p.Date,
                                                   p.Notes,
                                                   p.Equip_Options,
                                                   p.Presc_Physician,
                                                   p.Delivery_Method,
                                                   p.Start_Refill_Date,
                                                   p.Equip_Inspected_By,
                                                   p.Equip_Deliv_Date,
                                                   p.Facility_Name,
                                                   p.Facility_Address,
                                                   p.Diagnosis_Codes,
                                                   p.Est_Treatment_Dur,
                                                   p.Equip_Serial_Num,
                                                   p.Type_Of_Equip,
                                                   p.Drug,
                                                   p.HCPCS_Code,
                                                   p.J_Code,
                                                   p.Po_Patient_Sign,
                                                   p.Po_Patient_Sign_Date,
                                                   p.Po_CompanyRep_Sign,
                                                   p.Po_Company_Rep_Sign_Date,
                                                   p.Po_Equip_Received_Date,
                                                   p.Mcr_Beneficiary_Sign,
                                                   p.Mcr_Beneficiary_Sign_Date,
                                                   p.Mcr_Beneficiary_Name,
                                                   p.Mcr_Notes,
                                                   p.Pdr_Patient_Sign,
                                                   p.Pdr_Patient_Sign_Date,
                                                   p.Pdr_Legalguardian_Sign,
                                                   p.Pdr_Legalguardian_Name,
                                                   p.Pii_Patient_Sign,
                                                   p.Pii_Patient_Sign_Date,
                                                   p.Pii_Legalguardian_Sign,
                                                   p.Pii_Reason_PatientUnsign,
                                                   p.Pii_Guardian_Relation,
                                                   p.Pii_Guardian_Firstname,
                                                   p.Pii_Guardian_Lastname,
                                                   p.Pii_Guardian_Address1,
                                                   p.Pii_Guardian_Address2,
                                                   p.Pii_Guardian_City,
                                                   p.Pii_Guardian_State,
                                                   p.Pii_Guardian_Zip,
                                                   p.Pii_Guardian_Email,
                                                   p.Pii_Guardian_Phone,
                                                   p.Ptn_Physician_Sign,
                                                   p.Ptn_Physician_Sign_Date,
                                                   p.Ptn_Physician_Name,
                                                   p.Ptn_Intravenous_Conti_Times,
                                                   p.Ptn_Intravenous_Conti_Days,
                                                   p.Ptn_Continu_Administrat,
                                                   p.Ptn_Continu_Adminstrat_IFno,
                                                   p.Ptn_Intravenous_Infusion,
                                                   p.Ptn_Presc_Of_Equip,
                                                   p.Dmeif_Supplier_Sign,
                                                   p.Dmeif_Supplier_Sign_Date,
                                                   p.Dmeif_Initial_Date,
                                                   p.Dmeif_Revised_Date,
                                                   p.Dmeif_Recertification_Date,
                                                   p.StatusID
                                               }).FirstOrDefault();

            return Json(objPEncounter, JsonRequestBehavior.AllowGet);
        }
        public JsonResult CopyEncounter(int PatientID, int EncounterID)
        {
            string msg = "";
            try
            {
                PatientEncounters objPEncounters = (from p in objDBContext.PatientEncountersList
                                                     where p.PatientID == PatientID
                                                     where p.EncounterID == EncounterID
                                                     select p).FirstOrDefault();

                PatientEncounters objCpyEncounter = new PatientEncounters
                {
                    //EncounterID =objPEncounters.EncounterID,
                    PatientID = objPEncounters.PatientID,
                    EquipID = objPEncounters.EquipID,
                    Date = objPEncounters.Date,
                    Notes = objPEncounters.Notes,
                    Equip_Options = objPEncounters.Equip_Options,
                    Presc_Physician = objPEncounters.Presc_Physician,
                    Delivery_Method = objPEncounters.Delivery_Method,
                    Start_Refill_Date = objPEncounters.Start_Refill_Date,
                    Equip_Inspected_By = objPEncounters.Equip_Inspected_By,
                    Equip_Deliv_Date = objPEncounters.Equip_Deliv_Date,
                    Facility_Name = objPEncounters.Facility_Name,
                    Facility_Address = objPEncounters.Facility_Address,
                    Diagnosis_Codes = objPEncounters.Diagnosis_Codes,
                    Est_Treatment_Dur = objPEncounters.Est_Treatment_Dur,
                    Equip_Serial_Num = objPEncounters.Equip_Serial_Num,
                    Type_Of_Equip = objPEncounters.Type_Of_Equip,
                    Drug = objPEncounters.Drug,
                    HCPCS_Code = objPEncounters.HCPCS_Code,
                    J_Code = objPEncounters.J_Code,
                    Po_Patient_Sign = objPEncounters.Po_Patient_Sign,
                    Po_Patient_Sign_Date = objPEncounters.Po_Patient_Sign_Date,
                    Po_CompanyRep_Sign = objPEncounters.Po_CompanyRep_Sign,
                    Po_Company_Rep_Sign_Date = objPEncounters.Po_Company_Rep_Sign_Date,
                    Po_Equip_Received_Date = objPEncounters.Po_Equip_Received_Date,
                    Mcr_Beneficiary_Sign = objPEncounters.Mcr_Beneficiary_Sign,
                    Mcr_Beneficiary_Sign_Date = objPEncounters.Mcr_Beneficiary_Sign_Date,
                    Mcr_Beneficiary_Name = objPEncounters.Mcr_Beneficiary_Name,
                    Mcr_Notes = objPEncounters.Mcr_Notes,
                    Pdr_Patient_Sign = objPEncounters.Pdr_Patient_Sign,
                    Pdr_Patient_Sign_Date = objPEncounters.Pdr_Patient_Sign_Date,
                    Pdr_Legalguardian_Sign = objPEncounters.Pdr_Legalguardian_Sign,
                    Pdr_Legalguardian_Name = objPEncounters.Pdr_Legalguardian_Name,
                    Pii_Patient_Sign = objPEncounters.Pii_Patient_Sign,
                    Pii_Patient_Sign_Date = objPEncounters.Pii_Patient_Sign_Date,
                    Pii_Legalguardian_Sign = objPEncounters.Pii_Legalguardian_Sign,
                    Pii_Reason_PatientUnsign = objPEncounters.Pii_Reason_PatientUnsign,
                    Pii_Guardian_Relation = objPEncounters.Pii_Guardian_Relation,
                    Pii_Guardian_Firstname = objPEncounters.Pii_Guardian_Firstname,
                    Pii_Guardian_Lastname = objPEncounters.Pii_Guardian_Lastname,
                    Pii_Guardian_Address1 = objPEncounters.Pii_Guardian_Address1,
                    Pii_Guardian_Address2 = objPEncounters.Pii_Guardian_Address2,
                    Pii_Guardian_City = objPEncounters.Pii_Guardian_City,
                    Pii_Guardian_State = objPEncounters.Pii_Guardian_State,
                    Pii_Guardian_Zip = objPEncounters.Pii_Guardian_Zip,
                    Pii_Guardian_Email = objPEncounters.Pii_Guardian_Email,
                    Pii_Guardian_Phone = objPEncounters.Pii_Guardian_Phone,
                    Ptn_Physician_Sign = objPEncounters.Ptn_Physician_Sign,
                    Ptn_Physician_Sign_Date = objPEncounters.Ptn_Physician_Sign_Date,
                    Ptn_Physician_Name = objPEncounters.Ptn_Physician_Name,
                    Ptn_Intravenous_Conti_Times = objPEncounters.Ptn_Intravenous_Conti_Times,
                    Ptn_Intravenous_Conti_Days = objPEncounters.Ptn_Intravenous_Conti_Days,
                    Ptn_Continu_Administrat = objPEncounters.Ptn_Continu_Administrat,
                    Ptn_Continu_Adminstrat_IFno = objPEncounters.Ptn_Continu_Adminstrat_IFno,
                    Ptn_Intravenous_Infusion = objPEncounters.Ptn_Intravenous_Infusion,
                    Ptn_Presc_Of_Equip = objPEncounters.Ptn_Presc_Of_Equip,
                    Dmeif_Supplier_Sign = objPEncounters.Dmeif_Supplier_Sign,
                    Dmeif_Supplier_Sign_Date = objPEncounters.Dmeif_Supplier_Sign_Date,
                    Dmeif_Initial_Date = objPEncounters.Dmeif_Initial_Date,
                    Dmeif_Revised_Date = objPEncounters.Dmeif_Revised_Date,
                    Dmeif_Recertification_Date = objPEncounters.Dmeif_Recertification_Date,
                    StatusID = 1
                };
                objDBContext.PatientEncountersList.Add(objCpyEncounter);
                objDBContext.SaveChanges();

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

            return Json(new { result = msg }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult EditPatientEncounter(PatientEncounters objPEncounters)
        {
            string msg = "";
            try
            {
                PatientEncounters objNewEncounter = (from p in objDBContext.PatientEncountersList
                                                     where p.PatientID == objPEncounters.PatientID
                                                     where p.EncounterID == objPEncounters.EncounterID
                                                     select p).FirstOrDefault();

                //EncounterID =objPEncounters.EncounterID,
                // objNewEncounter. PatientID = objPEncounters.PatientID;
                objNewEncounter.EquipID = objPEncounters.EquipID;
                objNewEncounter.Date = objPEncounters.Date;
                objNewEncounter.Notes = objPEncounters.Notes;
                objNewEncounter.Equip_Options = objPEncounters.Equip_Options;
                objNewEncounter.Presc_Physician = objPEncounters.Presc_Physician;
                objNewEncounter.Delivery_Method = objPEncounters.Delivery_Method;
                objNewEncounter.Start_Refill_Date = objPEncounters.Start_Refill_Date;
                objNewEncounter.Equip_Inspected_By = objPEncounters.Equip_Inspected_By;
                objNewEncounter.Equip_Deliv_Date = objPEncounters.Equip_Deliv_Date;
                objNewEncounter.Facility_Name = objPEncounters.Facility_Name;
                objNewEncounter.Facility_Address = objPEncounters.Facility_Address;
                objNewEncounter.Diagnosis_Codes = objPEncounters.Diagnosis_Codes;
                objNewEncounter.Est_Treatment_Dur = objPEncounters.Est_Treatment_Dur;
                objNewEncounter.Equip_Serial_Num = objPEncounters.Equip_Serial_Num;
                objNewEncounter.Type_Of_Equip = objPEncounters.Type_Of_Equip;
                objNewEncounter.Drug = objPEncounters.Drug;
                objNewEncounter.HCPCS_Code = objPEncounters.HCPCS_Code;
                objNewEncounter.J_Code = objPEncounters.J_Code;
                objNewEncounter.Po_Patient_Sign = objPEncounters.Po_Patient_Sign;
                objNewEncounter.Po_Patient_Sign_Date = objPEncounters.Po_Patient_Sign_Date;
                objNewEncounter.Po_CompanyRep_Sign = objPEncounters.Po_CompanyRep_Sign;
                objNewEncounter.Po_Company_Rep_Sign_Date = objPEncounters.Po_Company_Rep_Sign_Date;
                objNewEncounter.Po_Equip_Received_Date = objPEncounters.Po_Equip_Received_Date;
                objNewEncounter.Mcr_Beneficiary_Sign = objPEncounters.Mcr_Beneficiary_Sign;
                objNewEncounter.Mcr_Beneficiary_Sign_Date = objPEncounters.Mcr_Beneficiary_Sign_Date;
                objNewEncounter.Mcr_Beneficiary_Name = objPEncounters.Mcr_Beneficiary_Name;
                objNewEncounter.Mcr_Notes = objPEncounters.Mcr_Notes;
                objNewEncounter.Pdr_Patient_Sign = objPEncounters.Pdr_Patient_Sign;
                objNewEncounter.Pdr_Patient_Sign_Date = objPEncounters.Pdr_Patient_Sign_Date;
                objNewEncounter.Pdr_Legalguardian_Sign = objPEncounters.Pdr_Legalguardian_Sign;
                objNewEncounter.Pdr_Legalguardian_Name = objPEncounters.Pdr_Legalguardian_Name;
                objNewEncounter.Pii_Patient_Sign = objPEncounters.Pii_Patient_Sign;
                objNewEncounter.Pii_Patient_Sign_Date = objPEncounters.Pii_Patient_Sign_Date;
                objNewEncounter.Pii_Legalguardian_Sign = objPEncounters.Pii_Legalguardian_Sign;
                objNewEncounter.Pii_Reason_PatientUnsign = objPEncounters.Pii_Reason_PatientUnsign;
                objNewEncounter.Pii_Guardian_Relation = objPEncounters.Pii_Guardian_Relation;
                objNewEncounter.Pii_Guardian_Firstname = objPEncounters.Pii_Guardian_Firstname;
                objNewEncounter.Pii_Guardian_Lastname = objPEncounters.Pii_Guardian_Lastname;
                objNewEncounter.Pii_Guardian_Address1 = objPEncounters.Pii_Guardian_Address1;
                objNewEncounter.Pii_Guardian_Address2 = objPEncounters.Pii_Guardian_Address2;
                objNewEncounter.Pii_Guardian_City = objPEncounters.Pii_Guardian_City;
                objNewEncounter.Pii_Guardian_State = objPEncounters.Pii_Guardian_State;
                objNewEncounter.Pii_Guardian_Zip = objPEncounters.Pii_Guardian_Zip;
                objNewEncounter.Pii_Guardian_Email = objPEncounters.Pii_Guardian_Email;
                objNewEncounter.Pii_Guardian_Phone = objPEncounters.Pii_Guardian_Phone;
                objNewEncounter.Ptn_Physician_Sign = objPEncounters.Ptn_Physician_Sign;
                objNewEncounter.Ptn_Physician_Sign_Date = objPEncounters.Ptn_Physician_Sign_Date;
                objNewEncounter.Ptn_Physician_Name = objPEncounters.Ptn_Physician_Name;
                objNewEncounter.Ptn_Intravenous_Conti_Times = objPEncounters.Ptn_Intravenous_Conti_Times;
                objNewEncounter.Ptn_Intravenous_Conti_Days = objPEncounters.Ptn_Intravenous_Conti_Days;
                objNewEncounter.Ptn_Continu_Administrat = objPEncounters.Ptn_Continu_Administrat;
                objNewEncounter.Ptn_Continu_Adminstrat_IFno = objPEncounters.Ptn_Continu_Adminstrat_IFno;
                objNewEncounter.Ptn_Intravenous_Infusion = objPEncounters.Ptn_Intravenous_Infusion;
                objNewEncounter.Ptn_Presc_Of_Equip = objPEncounters.Ptn_Presc_Of_Equip;
                objNewEncounter.Dmeif_Supplier_Sign = objPEncounters.Dmeif_Supplier_Sign;
                objNewEncounter.Dmeif_Supplier_Sign_Date = objPEncounters.Dmeif_Supplier_Sign_Date;
                objNewEncounter.Dmeif_Initial_Date = objPEncounters.Dmeif_Initial_Date;
                objNewEncounter.Dmeif_Revised_Date = objPEncounters.Dmeif_Revised_Date;
                objNewEncounter.Dmeif_Recertification_Date = objPEncounters.Dmeif_Recertification_Date;
                objNewEncounter.StatusID = 1;
                objDBContext.SaveChanges();
                msg = "Success";
            }
            catch (Exception ex)
            {
                msg = "Failed";
                msg = ex.Message;
            }

            return Json(new { result = msg }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult DeletePatientEncounter(PatientEncounters objPEncounters)
        {
            string msg = "";
            try
            {
                PatientEncounters objPEncounter = (from p in objDBContext.PatientEncountersList
                                                   where p.PatientID == objPEncounters.PatientID
                                                   where p.EncounterID == objPEncounters.EncounterID
                                                   where p.StatusID == 1
                                                   select p).FirstOrDefault();

                objPEncounter.StatusID = 2;
                objDBContext.SaveChanges();
                msg = "Success";
            }
            catch(Exception ex)
            {
                msg = "Failed";
                msg = ex.Message;
            }
            return Json(new { result = msg }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Edit(PatientEncounters patient)
        {
            db.Entry(patient.patnt).State = EntityState.Modified;
            db.SaveChanges();

            return RedirectToAction("Edit/" + patient.patnt.PatientID);
        }
        //public ActionResult Patients(vwSearchPatients vwsearch)
        //{
        //    int PracticeID = Convert.ToInt32(Session["sespracticeid"]);
        //    //IEnumerable<Patient> model = (from p in db.Patients
        //    //                              where p.StatusID != 2 && p.PracticeID == PracticeID
        //    //                              select p).ToList();
        //    ViewBag.ProviderID = from v in db.PracticeUsers
        //                         where v.StatusID != 2 && v.PracticeID == PracticeID && v.PracticeUserType == "Provider"
        //                         select v;
        //    return View(vwsearch);
        //}
        public ActionResult Edit(int id,int flag)
        {
            //var patientID = (from v in db.PatientEncountersList
            //                where v.EncounterID == id
            //                select v.PatientID);
            IEnumerable<PatientEncounters> model = (from p in db.PatientEncountersList
                                                    where p.StatusID != 2 && p.PatientID == id
                                                    select p).ToList();

            db.PatientEncountersList.Find(id);
            int PracticeID = Convert.ToInt32(Session["sespracticeid"]);
            ViewBag.ProviderID = from v in db.PracticeUsers
                                 where v.StatusID != 2 && v.PracticeID == PracticeID && v.PracticeUserType == "Provider"
                                 select v;
            PatientEncounters pat = new PatientEncounters();
            if (model.Count() == 0)
            {
                List<PatientEncounters> patient = new List<PatientEncounters>();
                pat.Equip_Options = pat.Presc_Physician = pat.Delivery_Method = pat.Equip_Inspected_By = pat.Facility_Name = "";
                pat.patnt = db.Patients.Find(id);
                patient.Add(pat);
                return View(patient);
            }
            else
                return View(model);
        }