예제 #1
0
        //GET: PatientLog
        public ActionResult Index()
        {
            var viewM = new PatientAssignmentIndexViewModel();
            var fromD = new DateTime();
            var toD   = new DateTime();
            Dictionary <string, string> preferences = new Dictionary <string, string>();
            List <string> physicians = new List <string>();
            string        hospitals  = "BRO";
            List <string> services   = new List <string>();

            string[] splitList;

            if (Session["patientAssignmentFromDate"] != null && Session["patientAssignmentToDate"] != null)
            {
                fromD = Convert.ToDateTime(Session["patientAssignmentFromDate"]);
                toD   = Convert.ToDateTime(Session["patientAssignmentToDate"]);
            }
            else
            {
                fromD = DateTime.Now.AddDays(intDayFallback);
                fromD = fromD.Date + new TimeSpan(0, 0, 0);
                toD   = DateTime.Now;
                toD   = toD.Date + new TimeSpan(23, 59, 59);
            }
            if (Session["patientAssignmentSortColumn"] != null)
            {
                //sortColumn = Session["patientLogSortColumn"].ToString();
                //sortDirection = (GridFilter.FilterTypes)Session["patientLogSortDirection"];
                viewM.SortColumn    = Session["patientAssignmentSortColumn"].ToString();
                viewM.SortDirection = (GridFilter.SortDirections)Session["patientAssignmentSortDirection"];
            }

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

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

                if (preferences["Hospital"] != null)
                {
                    hospitals = preferences["Hospital"];
                }

                if (preferences["ServiceType"] != null)
                {
                    splitList = preferences["ServiceType"].Split(new char[] { ',' });
                    services  = splitList.ToList();
                }
            }
            //if (Session["patientAssignmentPhysicians"] != null)
            //{
            //    physicians = (List<string>)Session["patientAssignmentPhysicians"];
            //}
            //if (Session["patientAssignmentHospitals"] != null)
            //{
            //    string hosp = Session["patientAssignmentHospitals"].ToString();
            //    //tempList.Add(hosp);
            //    hospitals = hosp;
            //}
            //else
            //{
            //    //List<string> tempList = new List<string>();
            //    //string usr = HubSecurity.getLoggedInUserID();
            //    ////string hosp = (from u in db.UserDetails
            //    ////              where u.UserID == usr && u.UserType == "AIMSPhy"
            //    ////              select u.DefaultHospital).Single().ToString();
            //    //string hosp = "HFM"; //DEBUG
            //    //tempList.Add(hosp);
            //    hospitals = "BRO";
            //}
            //if (Session["patientAssignmentServices"] != null)
            //{
            //    services = (List<string>)Session["patientAssignmentServices"];
            //}



            Session["patientAssignmentFromDate"]      = fromD;
            Session["patientAssignmentToDate"]        = toD;
            Session["patientAssignmentSortColumn"]    = viewM.SortColumn;
            Session["patientAssignmentSortDirection"] = viewM.SortDirection;
            //Session["patientAssignmentPhysicians"] = physicians;
            //Session["patientAssignmentHospitals"] = hospitals;
            //Session["patientAssignmentServices"] = services;

            IQueryable <PatientLog> query = patientAssignmentQueryGenerator(fromD, toD, physicians, hospitals, services, viewM.SortDirection, viewM.SortColumn);

            viewM.Patients = query.AsEnumerable <PatientLog>();
            //viewM.ToLookupTally = viewM.Patients.ToLookup(p => p.Physician, p => p.ServiceType);
            viewM.ToLookupTally = query.ToLookup(p => p.Physician, p => p.ServiceType).ToDictionary(p => p.Key, p => p.ToArray());
            if (viewM.ToLookupTally.Count == 0)
            {
                viewM.ToLookupTally.Add("No data", new string[] { "" });
            }
            viewM.FromDate           = fromD.ToShortDateString();
            viewM.ToDate             = toD.ToShortDateString();
            viewM.PhysicianList      = DataCollections.getAIMSPhy(db);
            viewM.HospitalList       = DataCollections.getHospital(db);
            viewM.ServiceList        = DataCollections.getServiceType(db);
            viewM.ImportColumns      = DataCollections.getImportColumns(db);
            viewM.SelectedPhysicians = physicians;
            viewM.SelectedHospitals  = hospitals;
            viewM.SelectedServices   = services;

            return(View("Index", viewM));
        }