From 2102baab001b313174dda2e7fd3edc986a5d3ba2 Mon Sep 17 00:00:00 2001
From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com>
Date: Sat, 20 Apr 2024 22:29:33 +0800
Subject: [PATCH] =?UTF-8?q?lis=E7=94=B3=E8=AF=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
 .../LisRequests/GetLisRequestListDto.cs       | 62 +++++++++++++
 .../LisRequests/LisRequestDto.cs              | 74 +++++++++++++++
 .../LisRequests/LisRequestAppService.cs       | 89 ++++++++++++++++++-
 .../PatientRegisterAppService.cs              | 10 +--
 .../LisRequests/LisRequestManager.cs          | 10 ++-
 5 files changed, 236 insertions(+), 9 deletions(-)
 create mode 100644 src/Shentun.Peis.Application.Contracts/LisRequests/GetLisRequestListDto.cs
 create mode 100644 src/Shentun.Peis.Application.Contracts/LisRequests/LisRequestDto.cs
diff --git a/src/Shentun.Peis.Application.Contracts/LisRequests/GetLisRequestListDto.cs b/src/Shentun.Peis.Application.Contracts/LisRequests/GetLisRequestListDto.cs
new file mode 100644
index 0000000..afa2d17
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/LisRequests/GetLisRequestListDto.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.Peis.LisRequests
+{
+    public class GetLisRequestListDto
+    {
+        /// 
+        /// 单位id
+        /// 
+        public Guid? CustomerOrgId { get; set; }
+
+        public Guid? CustomerOrgRegisterId { get; set; }
+
+        /// 
+        /// 姓名
+        /// 
+        public string? PatientName { get; set; }
+
+        /// 
+        /// 性别
+        /// 
+        public char? SexId { get; set; }
+
+        /// 
+        /// 档案号
+        /// 
+        public string? PatientNo { get; set; }
+
+        /// 
+        /// 条码号
+        /// 
+        public string? PatientRegisterNo { get; set; }
+
+        /// 
+        /// 身份证号
+        /// 
+        public string? IdNo { get; set; }
+
+        /// 
+        /// 开始日期
+        /// 
+        public string? StartDate { get; set; }
+
+        /// 
+        /// 结束日期
+        /// 
+        public string? EndDate { get; set; }
+
+        /// 
+        /// 手机号(支持手机跟座机)
+        /// 
+        public string? Phone { get; set; }
+
+        //public override int MaxResultCount { get; set; } = 50;
+
+        public int MaxResultCount { get; set; } = 50;
+
+        public int SkipCount { get; set; } = 0;
+    }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/LisRequests/LisRequestDto.cs b/src/Shentun.Peis.Application.Contracts/LisRequests/LisRequestDto.cs
new file mode 100644
index 0000000..6fa3dc1
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/LisRequests/LisRequestDto.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.Peis.LisRequests
+{
+    public class LisRequestDto
+    {
+        /// 
+        /// LisRequest的ID
+        /// 
+        public Guid Id { get; set; }
+        /// 
+        /// 姓名
+        /// 
+        public string PatientName { get; set; }
+
+        /// 
+        /// 性别
+        /// 
+        public string? SexName { get; set; }
+
+        /// 
+        /// 年龄
+        /// 
+        public short? Age { get; set; }
+
+        /// 
+        /// 标本类型名称
+        /// 
+        public string SampleTypeName { get; set; }
+        /// 
+        /// 标本容器名称
+        /// 
+        public string SampleContainerName { get; set; }
+        /// 
+        /// 颜色值
+        /// 
+        public int ContainerColor { get; set; }
+
+        /// 
+        /// 标本容器备注
+        /// 
+        public string? SampleContainerRemark { get; set; }
+
+        /// 
+        /// 检验申请单号
+        /// 
+        public string LisRequestNo { get; set; }
+        /// 
+        /// 档案号
+        /// 
+        public string PatientNo { get; set; }
+        /// 
+        /// 登记人员条码号
+        /// 
+        public string PatientRegisterNo { get; set; }
+
+        /// 
+        /// 组合项目简称(多个“,”号隔开)
+        /// 
+        public string AsbitemName { get; set; }
+
+        /// 
+        /// 单位名称
+        /// 
+        public string CustomerOrgName { get; set; }
+
+        /// 
+        /// 部门名称
+        /// 
+        public string DepartmentName { get; set; }
+    }
+}
diff --git a/src/Shentun.Peis.Application/LisRequests/LisRequestAppService.cs b/src/Shentun.Peis.Application/LisRequests/LisRequestAppService.cs
index 8eeab7d..8f3dc3a 100644
--- a/src/Shentun.Peis.Application/LisRequests/LisRequestAppService.cs
+++ b/src/Shentun.Peis.Application/LisRequests/LisRequestAppService.cs
@@ -1,5 +1,8 @@
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Shentun.Peis.CustomerOrgs;
+using Shentun.Peis.Enums;
 using Shentun.Peis.Models;
 using Shentun.Peis.PrintReports;
 using System;
@@ -8,6 +11,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Volo.Abp;
+using Volo.Abp.Application.Dtos;
 using Volo.Abp.Application.Services;
 using Volo.Abp.Domain.Repositories;
 using Volo.Abp.Identity;
@@ -28,13 +32,17 @@ namespace Shentun.Peis.LisRequests
         private readonly ILisRequestReportRepository _lisRequestReportRepository;
         private readonly LisRequestManager _lisRequestManager;
         private readonly CacheService _cacheService;
+        private readonly IRepository _customerOrgRepository;
+        private readonly CustomerOrgManager _customerOrgManager;
         public LisRequestAppService(
              IRepository userRepository,
              IRepository patientRegisterRepository,
              IRepository registerAsbitemRepository,
              ILisRequestReportRepository lisRequestReportRepository,
+             IRepository customerOrgRepository,
             LisRequestManager lisRequestManager,
-            CacheService cacheService
+            CacheService cacheService,
+            CustomerOrgManager customerOrgManager
             )
         {
             this._userRepository = userRepository;
@@ -43,8 +51,75 @@ namespace Shentun.Peis.LisRequests
             this._lisRequestReportRepository = lisRequestReportRepository;
             this._lisRequestManager = lisRequestManager;
             _cacheService = cacheService;
+            _customerOrgRepository = customerOrgRepository;
+            _customerOrgManager = customerOrgManager;
         }
 
+        [HttpPost("api/app/LisRequest/GetListInFilter")]
+        public async Task> GetListInFilterAsync(GetLisRequestListDto input)
+        {
+            var customerOrgList = await _customerOrgRepository.GetListAsync();
+
+            //Stopwatch stopwatch = Stopwatch.StartNew();
+            //stopwatch.Start();
+
+            #region MyRegion
+            var patientRegisterQuery = (await _patientRegisterRepository.GetQueryableAsync()).Include(x => x.Patient).AsQueryable();
+
+            if (!string.IsNullOrEmpty(input.PatientNo))
+                patientRegisterQuery = patientRegisterQuery.Where(m => m.Patient.PatientNo == input.PatientNo);
+
+            if (!string.IsNullOrEmpty(input.IdNo))
+                patientRegisterQuery = patientRegisterQuery.Where(m => m.Patient.IdNo == input.IdNo);
+
+            if (!string.IsNullOrEmpty(input.PatientName))
+                patientRegisterQuery = patientRegisterQuery.Where(m => !string.IsNullOrEmpty(m.PatientName) && m.PatientName.Contains(input.PatientName));
+
+            if (!string.IsNullOrEmpty(input.PatientRegisterNo))
+                patientRegisterQuery = patientRegisterQuery.Where(m => m.PatientRegisterNo == input.PatientRegisterNo);
+
+            if (!string.IsNullOrEmpty(input.Phone))
+                patientRegisterQuery = patientRegisterQuery.Where(m => m.Patient.MobileTelephone == input.Phone || m.Patient.Telephone == input.Phone);
+
+            if (input.SexId != null && input.SexId != ForSexFlag.All)
+                patientRegisterQuery = patientRegisterQuery.Where(m => m.SexId == input.SexId);
+
+            if (!string.IsNullOrEmpty(input.StartDate) && !string.IsNullOrEmpty(input.EndDate))
+                patientRegisterQuery = patientRegisterQuery.Where(m => m.CreationTime >= Convert.ToDateTime(input.StartDate) &&
+                m.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1));
+
+          
+            if (input.CustomerOrgId != null)
+            {
+                var CustomerOrgIds = await _customerOrgManager.GetCustomerOrgChildrenId(input.CustomerOrgId.Value);
+                patientRegisterQuery = patientRegisterQuery.Where(m => CustomerOrgIds.Contains(m.CustomerOrgId));
+            }
+
+            if (input.CustomerOrgRegisterId != null && input.CustomerOrgRegisterId != Guid.Empty)
+            {
+                patientRegisterQuery = patientRegisterQuery.Where(m => m.CustomerOrgRegisterId == input.CustomerOrgRegisterId);
+            }
+            patientRegisterQuery.Where(o => o.CompleteFlag != PatientRegisterCompleteFlag.PreRegistration);
+            #endregion
+
+
+            int totalCount = patientRegisterQuery.Count();
+
+            patientRegisterQuery =  patientRegisterQuery.Skip(input.SkipCount * input.MaxResultCount).Take(input.MaxResultCount);
+            var patientRegisterList = patientRegisterQuery.ToList();
+            if (patientRegisterList.Count > 10000)
+            {
+                throw new UserFriendlyException("选择的人员数不能超过1万条");
+            }
+            //生成LIS申请数据
+            foreach(var patientRegister in patientRegisterList )
+            {
+                var lisRequests = await _lisRequestManager.SetLisRequestAsync(patientRegister.Id);
+            }
+            //返回检索到的数据
+            var result = new PagedResultDto();
+            return result;
+        }
         /// 
         /// 生成检验申请单 首次自动生成
         /// 
@@ -144,6 +219,11 @@ namespace Shentun.Peis.LisRequests
         {
             if (input.OperateType == 1)
             {
+                var _patientRegister = await _patientRegisterRepository.GetAsync((Guid)input.PatientRegisterId);
+                if (_patientRegister.CompleteFlag == PatientRegisterCompleteFlag.PreRegistration)
+                {
+                    throw new UserFriendlyException("未正式登记,不能打印");
+                }
                 //按人员登记批量修改
                 var LisRequestIds = (await _registerAsbitemRepository.GetListAsync(m => m.PatientRegisterId == input.PatientRegisterId && m.LisRequestId != null)).Select(s => s.LisRequestId);
                 if (LisRequestIds.Count() > 0)
@@ -164,6 +244,13 @@ namespace Shentun.Peis.LisRequests
                 var oldent = await _lisRequestReportRepository.FirstOrDefaultAsync(m => m.Id == input.LisRequestId);
                 if (oldent != null)
                 {
+                    var registerAsbitem = (await _registerAsbitemRepository.GetListAsync(o => o.LisRequestId == input.LisRequestId)).FirstOrDefault();
+                    var _patientRegister = await _patientRegisterRepository.GetAsync(registerAsbitem.PatientRegisterId);
+                    if (_patientRegister.CompleteFlag == PatientRegisterCompleteFlag.PreRegistration)
+                    {
+                        throw new UserFriendlyException("未正式登记,不能打印");
+                    }
+
                     oldent.IsPrint = 'Y';
 
                     await _lisRequestReportRepository.UpdateAsync(oldent);
diff --git a/src/Shentun.Peis.Application/PatientRegisters/PatientRegisterAppService.cs b/src/Shentun.Peis.Application/PatientRegisters/PatientRegisterAppService.cs
index d727c85..2a53d43 100644
--- a/src/Shentun.Peis.Application/PatientRegisters/PatientRegisterAppService.cs
+++ b/src/Shentun.Peis.Application/PatientRegisters/PatientRegisterAppService.cs
@@ -338,7 +338,7 @@ namespace Shentun.Peis.PatientRegisters
         public async Task> GetListInFilterAsync(GetListInSearchDto input)
         {
 
-            var userList = await _userRepository.GetListAsync();
+            //var userList = await _userRepository.GetListAsync();
             var customerOrgList = await _customerOrgRepository.GetListAsync();
 
             //Stopwatch stopwatch = Stopwatch.StartNew();
@@ -650,13 +650,13 @@ namespace Shentun.Peis.PatientRegisters
                 LastModifierId = ent.LastModifierId,
                 ThirdInfo = ent.ThirdInfo,
                 SummaryDoctorId = ent.SummaryDoctorId,
-                SummaryDate = ent.SummaryDate.ToString(),
+                SummaryDate = DataHelper.ConversionDateToString(ent.SummaryDate),
                 SexId = ent.SexId,
                 SexName = _cacheService.GetSexNameAsync(ent.SexId).Result,
                 Age = ent.Age,
-                AuditDate = ent.AuditDate.ToString(),
+                AuditDate = DataHelper.ConversionDateToString(ent.AuditDate),
                 AuditDoctorId = ent.AuditDoctorId,
-                BirthDate = ent.BirthDate.ToString(),
+                BirthDate = DataHelper.ConversionDateToString(ent.BirthDate),
                 CompleteFlag = ent.CompleteFlag,
                 CustomerOrgGroupId = ent.CustomerOrgGroupId,
                 CustomerOrgId = ent.CustomerOrgId,
@@ -679,7 +679,7 @@ namespace Shentun.Peis.PatientRegisters
                 MedicalCardNo = ent.MedicalCardNo,
                 MedicalConclusionId = ent.MedicalConclusionId,
                 MedicalPackageId = ent.MedicalPackageId,
-                MedicalStartDate = ent.MedicalStartDate.ToString(),
+                MedicalStartDate = DataHelper.ConversionDateToString(ent.MedicalStartDate),
                 MedicalTimes = ent.MedicalTimes,
                 MedicalTypeId = ent.MedicalTypeId,
                 MedicalTypeName = _cacheService.GetMedicalTypeNameAsync(ent.MedicalTypeId).Result,
diff --git a/src/Shentun.Peis.Domain/LisRequests/LisRequestManager.cs b/src/Shentun.Peis.Domain/LisRequests/LisRequestManager.cs
index be731b0..c5fda3f 100644
--- a/src/Shentun.Peis.Domain/LisRequests/LisRequestManager.cs
+++ b/src/Shentun.Peis.Domain/LisRequests/LisRequestManager.cs
@@ -192,7 +192,7 @@ namespace Shentun.Peis.LisRequests
         {
             string LisRequestNo = "";  //条码号
 
-            List spvlist = await _sysParmValueRepository.GetListAsync();
+            //List spvlist = await _sysParmValueRepository.GetListAsync();
 
             //var spv_tjzx = spvlist.Where(m => m.MedicalCenterId == medicalCenterId); //体检中心配置
             //var spv_global = spvlist.Where(m => m.MedicalCenterId == Guid.Empty);  //全局配置
@@ -211,11 +211,15 @@ namespace Shentun.Peis.LisRequests
             {
                 throw new UserFriendlyException("LIS编码尾号长度不能为空");
             }
-            int i_lis_request_no_rule_tail_len = 0;
-            if(!int.TryParse(lis_request_no_rule_tail_len, out i_lis_request_no_rule_tail_len))
+            int tailLen = 0;
+            if(!int.TryParse(lis_request_no_rule_tail_len, out tailLen))
             {
                 throw new UserFriendlyException("LIS编码尾号长度不能为空");
             }
+            if(tailLen < 3)
+            {
+                throw new UserFriendlyException("LIS编码尾号长度至少为3位");
+            }
             if (string.IsNullOrWhiteSpace(lis_request_no_rule_prefix))
             {
                 lis_request_no_rule_prefix = "";