// GET: Prints public ActionResult Index() { var result_set = db.Results.Where(x => x.Value != null && x.Value.Trim() != "").GroupBy(x => x.PatientID).SelectMany(x => x.Select(s => s.PatientID)).Distinct(); var patient_set = db.PatientInfo.Where(x => result_set.Contains(x.PatientID)); if (patient_set.Count() == 0) { ViewBag.message = "No test results are entered. Click to Add Result"; return(View()); } IEnumerable <PatientInfo> SomePatientList; if (!string.IsNullOrEmpty(Request.Unvalidated["searchItem"])) { string searchItem = Request.Unvalidated["searchItem"]; int Labno = -1; if (int.TryParse(searchItem, out Labno)) //searchItem is lab no { //Returns records of the "month" in which last record was entered. if (patient_set.Where(x => x.LabNo == Labno).FirstOrDefault() != null) { SomePatientList = patient_set.Where(x => x.LabNo == Labno); SomePatientList = SomePatientList.OrderByDescending(x => x.CreatedOn.Date).ThenByDescending(x => x.CreatedOn.TimeOfDay); return(View(SomePatientList)); } else { ViewBag.message = "No records found. Click to Add Result"; return(View()); } } else if (searchItem.All(c => Char.IsLetter(c) || c == ' ')) //searchItem is name { SomePatientList = patient_set.Where(x => x.Name.Contains(searchItem)); SomePatientList = SomePatientList.OrderByDescending(x => x.CreatedOn.Date).ThenByDescending(x => x.CreatedOn.TimeOfDay); if (SomePatientList.Count() != 0) { return(View(SomePatientList)); } else { ViewBag.message = "No records found. Click to Add Result"; return(View()); } } else //searchItem is bad { ViewBag.message = "No records found. Click to Add Result"; return(View()); } } //IEnumerable<PatientInfo> Pt = patient_set; //Pt = Pt.OrderByDescending(x => x.CreatedOn.Date).ThenBy(x => x.CreatedOn.TimeOfDay); return(View()); }
// GET: Results public ActionResult Index() { //var patient_set = db.PatientInfo.GroupJoin(db.Results.Where(x => x.Value == null || x.Value.Trim() == ""), x => x.PatientID, y => y.PatientID, (x, y) => new //{ // x //}); var result_set = db.Results.Where(x => x.Value == null || x.Value.Trim() == "").GroupBy(x => x.PatientID).SelectMany(x => x.Select(s => s.PatientID)); var patient_set = db.PatientInfo.Where(x => result_set.Contains(x.PatientID)); if (patient_set.Count() == 0) { ViewBag.message = "No test results require entry. Click to Add Patient"; return(View()); } //---------------------------------------- IEnumerable <PatientInfo> SomePatientList; if (!string.IsNullOrEmpty(Request.Unvalidated["searchItem"])) { //int LastRecordDateMonth = LastRecordDate.Month; string searchItem = Request.Unvalidated["searchItem"]; int Labno = -1; if (int.TryParse(searchItem, out Labno)) //searchItem is lab no { //Returns records of the "month" in which last record was entered. if (patient_set.Where(x => x.LabNo == Labno).FirstOrDefault() != null) { SomePatientList = patient_set.Where(x => x.LabNo == Labno); SomePatientList = SomePatientList.OrderByDescending(x => x.CreatedOn.Date).ThenByDescending(x => x.CreatedOn.TimeOfDay); return(View(SomePatientList)); } else { ViewBag.message = "All test results are entered. Click to Add Patient"; return(View()); } } else if (searchItem.All(c => Char.IsLetter(c) || c == ' ')) //searchItem is name { SomePatientList = patient_set.Where(x => x.Name.Contains(searchItem)); SomePatientList = SomePatientList.OrderByDescending(x => x.CreatedOn.Date).ThenByDescending(x => x.CreatedOn.TimeOfDay); if (SomePatientList.Count() != 0) { return(View(SomePatientList)); } else { ViewBag.message = "All test results are entered. Click to Add Patient"; return(View()); } } else //searchItem is bad { ViewBag.message = "All test results are entered. Click to Add Patient"; return(View()); } } //var patients = new List<PatientInfo>(); //foreach (var item in patient_set) //{ // patients.Add(item.x); //} //foreach (var item in patient_set) //{ // patients.Add(new PatientInfo(){Age = item.x.Age,LabNo = item.x.LabNo,ReceiptNo = item.x.ReceiptNo,Name = item.x.Name,Guardian = item.x.Guardian,Sex = item.x.Sex,OutdoorNo = item.x.OutdoorNo}); //} //return View(patients.OrderByDescending(x=>x.CreatedOn)); IEnumerable <PatientInfo> Pt = patient_set; Pt = Pt.OrderByDescending(x => x.CreatedOn.Date).ThenBy(x => x.CreatedOn.TimeOfDay); return(View(Pt)); }