public ActionResult Index(BillingIndexViewModel viewM)
        {
            BillingIndexViewModel returnM  = new BillingIndexViewModel();
            var           fromD            = new DateTime();
            var           toD              = new DateTime();
            List <string> physicians       = new List <string>();
            List <string> hospitals        = new List <string>();
            List <string> services         = new List <string>();
            List <string> lastnamefilters  = new List <string>();
            bool?         notesCompleted   = null;
            bool?         notesCopied      = null;
            bool?         faceSheetEntered = null;
            bool?         codingCompleted  = null;
            bool?         chargePosted     = null;

            string[] splitList;

            //Manages physician input and builds a List<string> to be used in the query
            if (viewM.hidPhysicians != null && viewM.hidPhysicians != "")
            {
                splitList  = viewM.hidPhysicians.Split(new char[] { ',' });
                physicians = splitList.ToList <string>();
            }
            //Manages physician input and builds a List<string> to be used in the query
            if (viewM.hidHospitals != null && viewM.hidHospitals != "")
            {
                splitList = viewM.hidHospitals.Split(new char[] { ',' });
                hospitals = splitList.ToList <string>();
            }
            if (viewM.hidServices != null && viewM.hidServices != "")
            {
                splitList = viewM.hidServices.Split(new char[] { ',' });
                services  = splitList.ToList <string>();
            }
            if (viewM.hidLastNameFilters != null && viewM.hidLastNameFilters != "")
            {
                splitList       = viewM.hidLastNameFilters.Split(new char[] { ',' });
                lastnamefilters = splitList.ToList <string>();
            }
            if (viewM.hidNotesCompleted != null)
            {
                switch (viewM.hidNotesCompleted)
                {
                case "true":
                    notesCompleted = true;
                    break;

                case "false":
                    notesCompleted = false;
                    break;
                }
            }
            if (viewM.hidNotesCopied != null)
            {
                switch (viewM.hidNotesCopied)
                {
                case "true":
                    notesCopied = true;
                    break;

                case "false":
                    notesCopied = false;
                    break;
                }
            }
            if (viewM.hidFaceSheetEntered != null)
            {
                switch (viewM.hidFaceSheetEntered)
                {
                case "true":
                    faceSheetEntered = true;
                    break;

                case "false":
                    faceSheetEntered = false;
                    break;
                }
            }
            if (viewM.hidCodingCompleted != null)
            {
                switch (viewM.hidCodingCompleted)
                {
                case "true":
                    codingCompleted = true;
                    break;

                case "false":
                    codingCompleted = false;
                    break;
                }
            }
            if (viewM.hidChargePosted != null)
            {
                switch (viewM.hidChargePosted)
                {
                case "true":
                    chargePosted = true;
                    break;

                case "false":
                    chargePosted = false;
                    break;
                }
            }


            fromD = getValidDate(viewM.FromDate, true);
            toD   = getValidDate(viewM.ToDate, false);

            IQueryable <BillingIndexPatient> query = billingIndexQueryGenerator(fromD, toD, physicians, hospitals, services, lastnamefilters, notesCompleted, notesCopied, faceSheetEntered, chargePosted, codingCompleted, viewM.SortDirection, viewM.SortColumn, false);

            Session["billingFromDate"]      = fromD;
            Session["billingToDate"]        = toD;
            Session["billingSortColumn"]    = viewM.SortColumn;
            Session["billingSortDirection"] = viewM.SortDirection;
            //Session["billingPhysicians"] = physicians;
            //Session["billingHospitals"] = hospitals;
            //Session["billingServices"] = services;
            //Session["billingLastNameFilters"] = lastnamefilters;
            //Session["billingNotesCompleted"] = notesCompleted;
            //Session["billingNotesCopied"] = notesCopied;
            //Session["billingFaceSheetEntered"] = faceSheetEntered;
            //Session["billingCodingCompleted"] = codingCompleted;
            //Session["billingChargePosted"] = chargePosted;

            returnM.Patients           = query.AsEnumerable();
            returnM.FromDate           = fromD.ToShortDateString();
            returnM.ToDate             = toD.ToShortDateString();
            returnM.PhysicianList      = DataCollections.getAIMSPhy(db);
            returnM.HospitalList       = DataCollections.getHospital(db);
            returnM.ServiceList        = DataCollections.getServiceType(db);
            returnM.LastNameFilterList = DataCollections.getLastNameFilter();
            returnM.YesNo = DataCollections.getYesNo();
            returnM.SelectedPhysicians       = physicians;
            returnM.SelectedHospitals        = hospitals;
            returnM.SelectedServices         = services;
            returnM.SelectedLastNameFilters  = lastnamefilters;
            returnM.SelectedNotesCompleted   = notesCompleted;
            returnM.SelectedNotesCopied      = notesCopied;
            returnM.SelectedFaceSheetEntered = faceSheetEntered;
            returnM.SelectedCodingCompleted  = codingCompleted;
            returnM.SelectedChargePosted     = chargePosted;
            returnM.SortColumn    = viewM.SortColumn;
            returnM.SortDirection = viewM.SortDirection;
            return(View("Index", returnM));
        }
        // GET: Billing
        public ActionResult Index()
        {
            BillingIndexViewModel viewM             = new BillingIndexViewModel();
            var           fromD                     = new DateTime();
            var           toD                       = new DateTime();
            List <string> physicians                = new List <string>();
            List <string> hospitals                 = new List <string>();
            List <string> services                  = new List <string>();
            List <string> lastnamefilters           = new List <string>();
            Dictionary <string, string> preferences = new Dictionary <string, string>();
            bool?notesCompleted                     = null;
            bool?notesCopied      = null;
            bool?faceSheetEntered = null;
            bool?codingCompleted  = null;
            bool?chargePosted     = null;

            string[] splitList;

            if (Session["billingFromDate"] != null && Session["billingToDate"] != null)
            {
                fromD = Convert.ToDateTime(Session["billingFromDate"]);
                toD   = Convert.ToDateTime(Session["billingToDate"]);
            }
            else
            {
                fromD = getValidDate("", true);
                toD   = getValidDate("", false);
            }
            if (Session["billingSortColumn"] != null)
            {
                viewM.SortColumn    = Session["billingSortColumn"].ToString();
                viewM.SortDirection = (GridFilter.SortDirections)Session["billingSortDirection"];
            }

            //Load user preferences into a dictionary
            preferences = DataCollections.LoadPreferences(db, "Billing", "BillingIndex");

            if (preferences.Count > 0)
            {
                if (preferences["Physician"] != null)
                {
                    splitList  = preferences["Physician"].Split(new char[] { ',' });
                    physicians = splitList.ToList();
                }

                if (preferences["LastNameFilter"] != null)
                {
                    splitList       = preferences["LastNameFilter"].Split(new char[] { ',' });
                    lastnamefilters = splitList.ToList();
                }

                if (preferences["Hospital"] != null)
                {
                    splitList = preferences["Hospital"].Split(new char[] { ',' });
                    hospitals = splitList.ToList();
                }

                if (preferences["ServiceType"] != null)
                {
                    splitList = preferences["ServiceType"].Split(new char[] { ',' });
                    services  = splitList.ToList();
                }
                if (preferences["NotesCompleted"] != null)
                {
                    if (preferences["NotesCompleted"] == "true")
                    {
                        notesCompleted = true;
                    }
                    else
                    {
                        notesCompleted = false;
                    }
                }
                if (preferences["NotesCopied"] != null)
                {
                    if (preferences["NotesCopied"] == "true")
                    {
                        notesCopied = true;
                    }
                    else
                    {
                        notesCopied = false;
                    }
                }
                if (preferences["FaceSheetEntered"] != null)
                {
                    if (preferences["FaceSheetEntered"] == "true")
                    {
                        faceSheetEntered = true;
                    }
                    else
                    {
                        faceSheetEntered = false;
                    }
                }
                if (preferences["CodingCompleted"] != null)
                {
                    if (preferences["CodingCompleted"] == "true")
                    {
                        codingCompleted = true;
                    }
                    else
                    {
                        codingCompleted = false;
                    }
                }
                if (preferences["ChargePosted"] != null)
                {
                    if (preferences["ChargePosted"] == "true")
                    {
                        chargePosted = true;
                    }
                    else
                    {
                        chargePosted = false;
                    }
                }
            }

            //if (Session["billingPhysicians"] != null)
            //{
            //    physicians = (List<string>)Session["billingPhysicians"];
            //}
            //if (Session["billingHospitals"] != null)
            //{
            //    hospitals = (List<string>)Session["billingHospitals"];
            //}
            //if (Session["billingServices"] != null)
            //{
            //    services = (List<string>)Session["billingServices"];
            //}
            //if (Session["billingLastNameFilters"] != null)
            //{
            //    lastnamefilters = (List<string>)Session["billingLastNameFilters"];
            //}

            //if (Session["billingNotesCompleted"] != null)
            //{
            //    notesCompleted = (bool)Session["billingNotesCompleted"];
            //}
            //if (Session["billingNotesCopied"] != null)
            //{
            //    notesCopied = (bool)Session["billingNotesCopied"];
            //}
            //if (Session["billingFaceSheetEntered"] != null)
            //{
            //    faceSheetEntered = (bool)Session["billingFaceSheetEntered"];
            //}
            //if (Session["billingCodingCompleted"] != null)
            //{
            //    codingCompleted = (bool)Session["billingCodingCompleted"];
            //}
            //if (Session["billingChargePosted"] != null)
            //{
            //    chargePosted = (bool)Session["billingChargePosted"];
            //}

            Session["billingFromDate"]      = fromD;
            Session["billingToDate"]        = toD;
            Session["billingSortColumn"]    = viewM.SortColumn;
            Session["billingSortDirection"] = viewM.SortDirection;
            //Session["billingPhysicians"] = physicians;
            //Session["billingHospitals"] = hospitals;
            //Session["billingServices"] = services;
            //Session["billingLastNameFilters"] = lastnamefilters;
            //Session["billingNotesCompleted"] = notesCompleted;
            //Session["billingNotesCopied"] = notesCopied;
            //Session["billingFaceSheetEntered"] = faceSheetEntered;
            //Session["billingCodingCompleted"] = codingCompleted;
            //Session["billingChargePosted"] = chargePosted;

            IQueryable <BillingIndexPatient> query = billingIndexQueryGenerator(fromD, toD, physicians, hospitals, services, lastnamefilters, notesCompleted, notesCopied, faceSheetEntered, chargePosted, codingCompleted, viewM.SortDirection, viewM.SortColumn, false);

            viewM.Patients           = query.AsEnumerable();
            viewM.FromDate           = fromD.ToShortDateString();
            viewM.ToDate             = toD.ToShortDateString();
            viewM.PhysicianList      = DataCollections.getAIMSPhy(db);
            viewM.HospitalList       = DataCollections.getHospital(db);
            viewM.ServiceList        = DataCollections.getServiceType(db);
            viewM.LastNameFilterList = DataCollections.getLastNameFilter();
            viewM.YesNo = DataCollections.getYesNo();
            viewM.SelectedPhysicians       = physicians;
            viewM.SelectedHospitals        = hospitals;
            viewM.SelectedServices         = services;
            viewM.SelectedLastNameFilters  = lastnamefilters;
            viewM.SelectedNotesCompleted   = notesCompleted;
            viewM.SelectedNotesCopied      = notesCopied;
            viewM.SelectedFaceSheetEntered = faceSheetEntered;
            viewM.SelectedCodingCompleted  = codingCompleted;
            viewM.SelectedChargePosted     = chargePosted;
            return(View("Index", viewM));
        }