public async Task AdvancedSearchTest(string userID, string site, string role) { var criteria = new WorklistSearchCriteriaDto { PatientName = "*001*", Pagination = new PaginationDto { PageIndex = 1, PageSize = 5 } }; var result = await _worklistService.SearchWorklist(criteria, userID, site, role); Assert.AreEqual(0, result.OrderItems.Count()); criteria.PatientName = "*LocalName1*"; result = await _worklistService.SearchWorklist(criteria, userID, site, role); Assert.AreEqual(2, result.OrderItems.Count()); criteria.AccNo = "*00000*"; result = await _worklistService.SearchWorklist(criteria, userID, site, role); Assert.AreEqual(2, result.OrderItems.Count()); criteria.AccNo = "*000001*"; result = await _worklistService.SearchWorklist(criteria, userID, site, role); Assert.AreEqual(1, result.OrderItems.Count()); criteria.AccNo = "*000002*"; result = await _worklistService.SearchWorklist(criteria, userID, site, role); Assert.AreEqual(1, result.OrderItems.Count()); criteria.PatientTypes = new List <string>() { "住院病人" }; result = await _worklistService.SearchWorklist(criteria, userID, site, role); Assert.AreEqual(0, result.OrderItems.Count()); criteria.PatientTypes.Add("急诊病人"); result = await _worklistService.SearchWorklist(criteria, userID, site, role); Assert.AreEqual(1, result.OrderItems.Count()); }
public async Task <IHttpActionResult> AdvancedSearch([FromUri] string query) { var criteria = JsonConvert.DeserializeObject <WorklistSearchCriteriaDto>(query); if (criteria == null) { criteria = new WorklistSearchCriteriaDto { Pagination = new PaginationDto { PageIndex = 1, PageSize = Int32.MaxValue } }; } var user = base.CurrentUser(); var result = await _worklistService.SearchWorklist(criteria, user.UniqueID, user.Site, user.RoleName); return(Ok <WorklistSearchResultDto>(result)); }
public async Task <IHttpActionResult> GetWorkList([FromUri] string query) { var microsoftDateFormatSettings = new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Local }; var criteria = JsonConvert.DeserializeObject <WorklistSearchCriteriaDto>(query, microsoftDateFormatSettings); if (criteria == null) { criteria = new WorklistSearchCriteriaDto { Pagination = new PaginationDto { PageIndex = 1, PageSize = Int32.MaxValue } }; } var user = base.CurrentUser(); var result = await _worklistService.GetWorklist(criteria, user.UniqueID, user.Site, user.RoleName); return(Ok(result)); }
public async Task <PaginationResult> GetWorklist(WorklistSearchCriteriaDto criteria, string userID, string site, string role) { if (criteria == null || criteria.Pagination == null) { return(null); } if (criteria.AccessSites.Count < 1)//搜索条件无站点条件 { //获取用户可操作站点 criteria.AccessSites = await GetAccessSites(userID, site, role); } // prepare date range by criteria var createStartDay = criteria.CreateStartDate.HasValue ? (DateTime?)criteria.CreateStartDate.Value : null; var createEndDay = criteria.CreateEndDate.HasValue ? (DateTime?)criteria.CreateEndDate.Value : null; var examineStartDay = criteria.ExamineStartDate.HasValue ? (DateTime?)criteria.ExamineStartDate.Value : null; var examineEndDay = criteria.ExamineEndDate.HasValue ? (DateTime?)criteria.ExamineEndDate.Value : null; // filter result by all criteria except time ranges var orderQuery = from o in _dbContext.Set <Order>() join p in _dbContext.Set <Patient>() on o.PatientID equals p.UniqueID join pro in _dbContext.Set <Procedure>() on o.UniqueID equals pro.OrderID where (criteria.AccessSites.Count == 0 || criteria.AccessSites.Contains(o.CurrentSite) || criteria.AccessSites.Contains(o.Assign2Site)) && pro.Status > 0 select new WorklistSearchQueryResult { o = o, p = p, pro = pro }; #region Build Query var isFuzzySearch = false; if (!String.IsNullOrEmpty(criteria.PatientNo)) { string actualSearchValue = criteria.PatientNo; var searchingType = SearchingUtil.ProcessSearchValue(criteria.PatientNo, out actualSearchValue); if (searchingType == SearchingType.Exact) { orderQuery = orderQuery.Where(q => q.p.PatientNo.Equals(actualSearchValue)); } else { isFuzzySearch = true; orderQuery = orderQuery.Where(q => q.p.PatientNo.Contains(actualSearchValue)); } } if (!String.IsNullOrEmpty(criteria.PatientName)) { string actualSearchValue = criteria.PatientName; var searchingType = SearchingUtil.ProcessSearchValue(criteria.PatientName, out actualSearchValue); if (searchingType == SearchingType.Exact) { orderQuery = orderQuery.Where(q => q.p.LocalName.Equals(actualSearchValue)); } else { isFuzzySearch = true; orderQuery = orderQuery.Where(q => q.p.LocalName.Contains(actualSearchValue)); } } if (!String.IsNullOrEmpty(criteria.AccNo)) { string actualSearchValue = criteria.AccNo; var searchingType = SearchingUtil.ProcessSearchValue(criteria.AccNo, out actualSearchValue); if (searchingType == SearchingType.Exact) { orderQuery = orderQuery.Where(q => q.o.AccNo.Equals(actualSearchValue)); } else { isFuzzySearch = true; orderQuery = orderQuery.Where(q => q.o.AccNo.Contains(actualSearchValue)); } } if (criteria.AccessSites.Count > 0) { orderQuery = orderQuery.Where(q => criteria.AccessSites.Contains(q.o.CurrentSite)); } if (criteria.PatientTypes.Count > 0) { orderQuery = orderQuery.Where(q => criteria.PatientTypes.Contains(q.o.PatientType)); } if (criteria.Statuses.Count > 0) { orderQuery = orderQuery.Where(q => criteria.Statuses.Contains(q.pro.Status)); } if (criteria.ModalityTypes.Count > 0) { orderQuery = orderQuery.Where(q => criteria.ModalityTypes.Contains(q.pro.ModalityType)); } if (criteria.Modalities.Count > 0) { orderQuery = orderQuery.Where(q => criteria.Modalities.Contains(q.pro.Modality)); } // limit to search one month data for fuzzy search // Case 1: start(N), end(N) // Case 2: start(Y), end(N) // Case 3: strat(Y), end(Y) -> Case 3.1: end - start > 30 days, Case 3.2: end - start <= 30 days // Case 4: start(N), end(Y) if (createStartDay.HasValue) { orderQuery = orderQuery.Where(q => q.o.CreateTime.HasValue && q.o.CreateTime.Value >= createStartDay.Value); // limit to search one month data for fuzzy search if (isFuzzySearch) { if (!createEndDay.HasValue || (createEndDay.Value - createStartDay) > TimeSpan.FromDays(30)) { createEndDay = createStartDay.Value.AddDays(30); } } } else { // limit to search one month data for fuzzy search if (isFuzzySearch) { DateTime startDate = DateTime.Today.AddDays(-30); if (createEndDay.HasValue) { startDate = createEndDay.Value.AddDays(-30); } orderQuery = orderQuery.Where(q => q.o.CreateTime > startDate); } } if (createEndDay.HasValue) { orderQuery = orderQuery.Where(q => q.o.CreateTime.HasValue && q.o.CreateTime.Value < createEndDay.Value); } if (examineStartDay.HasValue) { orderQuery = orderQuery.Where(q => q.pro.ExamineTime.HasValue && q.pro.ExamineTime.Value >= examineStartDay.Value); } if (examineEndDay.HasValue) { orderQuery = orderQuery.Where(q => q.pro.ExamineTime.HasValue && q.pro.ExamineTime.Value < examineEndDay.Value); } // filter create time ranges if (criteria.CreateTimeRanges != null && criteria.CreateTimeRanges.Count > 0) { var predicate = BuildWithInOrderCreateTimeRangesPredicate(criteria.CreateTimeRanges); orderQuery = orderQuery.AsExpandable().Where(predicate); } // filter examine time ranges if (criteria.ExamineTimeRanges != null && criteria.ExamineTimeRanges.Count > 0) { var predicate = BuildWithInExamineTimeRangesPredicate(criteria.ExamineTimeRanges); orderQuery = orderQuery.AsExpandable().Where(predicate); } #endregion // theoretically, the result should be distinct by order and patient info var finalQuery = orderQuery.Select(q => new { PatientID = q.p.UniqueID, q.p.Birthday, q.p.LocalName, q.p.PatientNo, OrderID = q.o.UniqueID, q.o.AccNo, q.o.PatientType, q.o.CurrentSite, q.o.ExamSite, q.o.CreateTime, q.o.CurrentAge, q.o.AgeInDays, q.o.IsScan, q.o.ReferralID, q.o.StudyInstanceUID //q.pro.ExamineTime//检查时间不同 ,每个检查部位 都有一个检查时间?列表 是否多个? }).Distinct().AsNoTracking(); // pagination orders by create time // get two pages items every time, to see if there is items in next page var getTwoPagesItemsTask = !criteria.Pagination.NeedNoPagination ? finalQuery.OrderByDescending(q => q.CreateTime).Skip(criteria.Pagination.PageSize * (criteria.Pagination.PageIndex - 1)).Take(criteria.Pagination.PageSize * 2).ToListAsync() : finalQuery.OrderByDescending(q => q.CreateTime).ToListAsync(); var twoPagesItems = await getTwoPagesItemsTask; var firstPageItems = twoPagesItems.Take(criteria.Pagination.PageSize); // assemble result with no procedure info var result = new PaginationResult { Total = finalQuery.Count(), Data = firstPageItems.Select(item => new OrderItemDto { PatientID = item.PatientID, Birthday = item.Birthday, PatientName = item.LocalName, PatientNo = item.PatientNo, OrderID = item.OrderID, AccNo = item.AccNo, PatientType = item.PatientType, CurrentSite = item.CurrentSite, ExamSite = item.ExamSite, CreatedTime = item.CreateTime.HasValue ? item.CreateTime.Value : DateTime.MinValue, CurrentAge = item.CurrentAge, AgeInDays = item.AgeInDays, IsScan = item.IsScan.HasValue ? item.IsScan.Value.Equals(1) : false, ReferralID = item.ReferralID, StudyInstanceUID = item.StudyInstanceUID //ExamineTime = item.ExamineTime }).ToList(), }; var orderIDs = firstPageItems.Select(i => i.OrderID).ToList(); // fetch all procedures associated with those orders await GetProceduresByOrderIDsTwo(orderIDs, result); return(result); }
public async Task <PaginationResult> SearchQualityScoringList(WorklistSearchCriteriaDto criteria, string site) { if (criteria.Pagination == null) { criteria.Pagination = new PaginationDto { PageIndex = 0, PageSize = 20 }; } else { if (criteria.Pagination.PageIndex > 0) { criteria.Pagination.PageIndex = criteria.Pagination.PageIndex - 1; } } string sql = "EXEC SP_QualityScoringListWeb @PageIndex=@PageIndex,@PageSize = @PageSize,@Where=@SqlWhere,@TotalCount = @TotalCount output,@RandomNum = 0 "; StringBuilder sqlwhere = new StringBuilder(" and 1 = 1 "); sqlwhere.Append(string.Format(" and (tbregorder.examsite='{0}')", site)); if (!string.IsNullOrEmpty(criteria.PatientNo)) { sqlwhere.Append(string.Format(" and tbRegPatient.PatientID like '{0}'", "%" + criteria.PatientNo + "%")); } if (!string.IsNullOrEmpty(criteria.PatientName)) { sqlwhere.Append(string.Format(" and tbRegPatient.LocalName like '{0}'", "%" + criteria.PatientName + "%")); } //放射编号 if (!string.IsNullOrEmpty(criteria.AccNo)) { sqlwhere.Append(string.Format(" and tbRegPatient.AccNo like '{0}'", "%" + criteria.AccNo + "%")); } // 高级查询 //(tbProcedureCode.CheckingItem in (''CT踝关节平扫'')) //CreateTimeRanges = new List<TimeRangeDto>(); //ExamineTimeRanges = new List<TimeRangeDto>(); //病人类型 if (criteria.PatientTypes.Count > 0) { var patientTypes = string.Join("','", criteria.PatientTypes); sqlwhere.Append(string.Format(" tbRegOrder.PatientType in {0}", "('" + patientTypes + "')")); } //设备类型 if (criteria.ModalityTypes.Count > 0) { var modalityTypes = string.Join("','", criteria.PatientTypes); sqlwhere.Append(string.Format(" tbProcedureCode.ModalityType in {0}", "('" + modalityTypes + "')")); } //评分 if (criteria.Results.Count > 0) { var results = string.Join("','", criteria.Results); sqlwhere.Append(string.Format(" tbQualityScoring.Result in {0}", "('" + results + "')")); } //状态 if (criteria.Statuses.Count > 0) { var statuses = string.Join(",", criteria.Results); sqlwhere.Append(string.Format(" tbProcedureCode.Status in {0}", "(" + statuses + ")")); } criteria.Pagination.TotalCount = 0; var param = new List <Object>(); param.Add(new SqlParameter("@PageIndex", criteria.Pagination.PageIndex)); param.Add(new SqlParameter("@PageSize", criteria.Pagination.PageSize)); param.Add(new SqlParameter("@SqlWhere", sqlwhere.ToString())); var parcount = new SqlParameter { ParameterName = "@TotalCount", Value = criteria.Pagination.TotalCount, Direction = ParameterDirection.Output }; param.Add(parcount); var query = _dbContext.SqlQuery <QualityScoreDto>(sql, param.ToArray()); var data = await query.ToListAsync(); var result = new PaginationResult { Data = data, Total = (int)parcount.Value }; return(result); }