public ActionResult Index(string dfn, LabResultType labType, bool pregFilter, string page) { // *** Create the model *** LabModel model = new LabModel(); // *** Set the patient *** model.Patient = this.CurrentPatient; // *** Get the page value *** int pageVal = this.GetPage(page); // *** Create date range dates *** DateTime fromDate = DateTime.MinValue; DateTime toDate = DateTime.MinValue; // *** Add the filters to the model *** model.LabTypeFilter = labType.ToString(); PregnancyDetails pregDetails = null; PregnancyResult pregResult = this.DashboardRepository.Pregnancy.GetCurrentOrMostRecentPregnancy(dfn); if (pregResult.Success) { if (pregResult.Pregnancy != null) { pregDetails = pregResult.Pregnancy; } } if (pregDetails != null) { if (pregDetails.RecordType == Data.Models.Pregnancy.PregnancyRecordType.Current) { model.PregnancyFilterDescription = "Current Pregnancy"; } else { model.PregnancyFilterDescription = "Most Recent Pregnancy"; } if (pregFilter) { // *** Set the date range dates *** fromDate = pregDetails.StartDate; toDate = pregDetails.EndDate; // *** Create an approximate date/time for fromDate if needed *** if (fromDate == DateTime.MinValue) { if (toDate != DateTime.MinValue) { fromDate = toDate.AddDays(-280); } } model.FilteredByPregnancy = true; } model.CanFilterByPregnancy = true; } else { model.PregnancyFilterDescription = "Current Pregnancy"; model.CanFilterByPregnancy = false; model.FilteredByPregnancy = false; } // *** Get the list of labs *** LabItemsResult labsResult = this.DashboardRepository.Labs.GetList(dfn, labType, pregFilter, fromDate, toDate, pageVal, LabItemsPerPage); if (!labsResult.Success) { this.Error(labsResult.Message); } else if (labsResult.Labs == null) { model.Items = new List <LabItem>(); } else { // *** Add lab items *** model.Items = labsResult.Labs; // *** Paging *** model.Paging.SetPagingData(LabItemsPerPage, pageVal, labsResult.TotalResults); model.Paging.BaseUrl = Url.Action("Index", new { dfn = dfn, labtype = labType, pregFilter = pregFilter, page = "" }); } return(View(model)); }
/// <summary> /// Gets a list of lab results by patient /// </summary> /// <param name="dfn">Patient's unique DFN</param> /// <param name="labType">Type of lab to return (Any or Prenatal Only)</param> /// <param name="fromDate">Labs must be after or equal to this date if not min date</param> /// <param name="toDate">Labs must be before or equal to this date if not min date</param> /// <param name="page">Page of data to retrieve</param> /// <param name="itemsPerPage">Number of items on each page</param> /// <returns></returns> public LabItemsResult GetList(string dfn, LabResultType labType, bool filterByDate, DateTime fromDate, DateTime toDate, int page, int itemsPerPage) { LabItemsResult result = new LabItemsResult(); // *** Using DSIO VPR to get a list of all labs *** DsioVprGetPatientDataCommand command = new DsioVprGetPatientDataCommand(this.broker); // *** Add the arguments *** command.AddCommandArguments(dfn, Commands.Vpr.VprDataType.Labs); // *** Execute the command *** RpcResponse response = command.Execute(); // *** Add response to return *** result.Success = response.Status == RpcResponseStatus.Success; result.Message = response.InformationalMessage; // *** Check results *** if (result.Success) { if (command.PatientResult != null) { if (command.PatientResult.Labs != null) { if (command.PatientResult.Labs.Count > 0) { // *** If we have labs to work with *** // *** Set up paging *** int curItem = 0; int first = (page - 1) * itemsPerPage + 1; int last = first + itemsPerPage - 1; // *** Go throug all *** foreach (Lab lab in command.PatientResult.Labs) { // *** If matches prenatal filter *** if ((labType == LabResultType.Any) || (this.IsPrenatal(lab))) { // *** If matches date criteria *** if (this.LabMatchesDateCriteria(filterByDate, fromDate, toDate, lab)) { // *** Count the total items that match criteria *** curItem += 1; // *** If belongs in current page *** if ((curItem >= first) && (curItem <= last)) { // *** Get a lab item based on data *** LabItem item = GetLabItem(lab); // *** Create the list if necessary *** if (result.Labs == null) { result.Labs = new List <LabItem>(); } // *** Add to list *** result.Labs.Add(item); } } } } // *** Set total results which match filters *** result.TotalResults = curItem; } } } } return(result); }