From 4f336268430b69e4c1e4b8f26b639351e99afb9d Mon Sep 17 00:00:00 2001 From: wyb <1977763549@qq.com> Date: Wed, 15 Nov 2023 12:24:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E6=8F=8F=E6=96=87=E4=BB=B6=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docus/PatScanFileSyncByScanDateJobQuery.json | 1 + .../com/docus/server/CollectApplication.java | 43 +---- .../controller/PatientScanController.java | 10 +- .../converter/FileReportConverter.java | 25 +++ .../docus/server/collect/dto/TBasicQrDto.java | 12 +- .../server/collect/entity/CollectTask.java | 112 ++++++++++++ .../docus/server/collect/entity/TBasic.java | 13 -- .../infrastructure/dao/CollectTaskDao.java | 26 +++ .../infrastructure/dao/DownloadTaskDao.java | 11 +- .../dao/impl/CollectTaskDaoImpl.java | 70 ++++++++ .../dao/impl/DownloadTaskDaoImpl.java | 5 - .../mapper/CollectTaskMapper.java | 4 +- .../mapper/DownloadTaskMapper.java | 28 --- .../mapper/PatientBasicMapper.java | 12 ++ .../mapper/PatientScanMapper.java | 9 +- .../collect/job/PatScanFileSyncJob.java | 167 ++++++++++++++++++ .../collect/service/PatientScanService.java | 28 ++- .../service/dto/ReportFileInfoDTO.java | 9 - .../service/impl/FileReportServiceImpl.java | 45 ++++- .../service/impl/PatientScanServiceImpl.java | 23 ++- src/main/resources/bootstrap.yml | 3 + .../resources/mapper/DownloadTaskMapper.xml | 29 +++ .../resources/mapper/PatientBasicMapper.xml | 53 ++++++ .../resources/mapper/PatientScanMapper.xml | 20 ++- src/main/resources/mapper/TBasicMapper.xml | 123 ------------- 25 files changed, 623 insertions(+), 258 deletions(-) create mode 100644 docus/PatScanFileSyncByScanDateJobQuery.json create mode 100644 src/main/java/com/docus/server/collect/entity/CollectTask.java create mode 100644 src/main/java/com/docus/server/collect/infrastructure/dao/CollectTaskDao.java create mode 100644 src/main/java/com/docus/server/collect/infrastructure/dao/impl/CollectTaskDaoImpl.java create mode 100644 src/main/java/com/docus/server/collect/job/PatScanFileSyncJob.java create mode 100644 src/main/resources/mapper/DownloadTaskMapper.xml create mode 100644 src/main/resources/mapper/PatientBasicMapper.xml delete mode 100644 src/main/resources/mapper/TBasicMapper.xml diff --git a/docus/PatScanFileSyncByScanDateJobQuery.json b/docus/PatScanFileSyncByScanDateJobQuery.json new file mode 100644 index 0000000..a27ded9 --- /dev/null +++ b/docus/PatScanFileSyncByScanDateJobQuery.json @@ -0,0 +1 @@ +{"lastExecuteDate":"2023-11-15"} \ No newline at end of file diff --git a/src/main/java/com/docus/server/CollectApplication.java b/src/main/java/com/docus/server/CollectApplication.java index 82c5ac7..2ac9593 100644 --- a/src/main/java/com/docus/server/CollectApplication.java +++ b/src/main/java/com/docus/server/CollectApplication.java @@ -1,17 +1,13 @@ package com.docus.server; -import com.docus.core.util.SpringUtils; -import com.docus.server.collect.enums.DownWayEnum; -import com.docus.server.collect.service.FileReportService; -import com.docus.server.collect.service.dto.ReportFileInfoDTO; +import com.docus.infrastructure.core.utils.SpringUtil; +import com.docus.server.collect.job.PatScanFileSyncJob; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.scheduling.annotation.EnableAsync; -import java.io.BufferedReader; -import java.io.FileReader; import java.util.Properties; /** @@ -31,39 +27,16 @@ public class CollectApplication { props.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); SpringApplication.run(CollectApplication.class, args); -// testBase64Report(); + testCollectJob(); - } - private static void testBase64Report() { - try { - String url=getBase64(); - ReportFileInfoDTO dto = new ReportFileInfoDTO(); - dto.setPatientId("20001099999"); - dto.setSysFlag("icu"); - dto.setSerialNum("0002353348_1229183645"); - dto.setFileTitle("szy服务"); - dto.setTaskId(2023060815440200002L); - dto.setDownUrl(url); - dto.setDownWayEnum(DownWayEnum.BASE64); - dto.setIp("szy-lis"); - dto.setUserName("lis"); - dto.setReportUserFullName("lis"); - dto.setAssortId("list-assort"); - FileReportService reportService = SpringUtils.getBean(FileReportService.class); - reportService.saveDownloadTaskAndReport(dto); - }catch (Exception ex){ - ex.printStackTrace(); - } } - private static String getBase64() throws Exception { - FileReader reader = new FileReader("C:\\Users\\WYBDEV\\Desktop\\sb.txt"); - BufferedReader bufferedReader = new BufferedReader(reader); - String base64 = bufferedReader.readLine(); - bufferedReader.close(); - reader.close(); - return base64; + private static void testCollectJob() { + PatScanFileSyncJob bean = SpringUtil.getApplicationContext().getBean(PatScanFileSyncJob.class); + bean.patScanFileSyncByScanDateJob(); } + + } diff --git a/src/main/java/com/docus/server/collect/controller/PatientScanController.java b/src/main/java/com/docus/server/collect/controller/PatientScanController.java index 0e682a9..de11c1b 100644 --- a/src/main/java/com/docus/server/collect/controller/PatientScanController.java +++ b/src/main/java/com/docus/server/collect/controller/PatientScanController.java @@ -3,6 +3,7 @@ package com.docus.server.collect.controller; import com.docus.core.util.Func; import com.docus.infrastructure.web.api.CommonResult; import com.docus.server.collect.dto.PatientScanConditionDTO; +import com.docus.server.collect.entity.PatientScan; import com.docus.server.collect.service.PatientScanService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -27,13 +28,12 @@ public class PatientScanController { private PatientScanService patientScanService; - @PostMapping("/collect/byInpatientNoAndTimes") - @ApiOperation("根据住院号和住院次数,进行患者电子病历扫描数据采集!") - public CommonResult collectByInpatientNoAndTimes(@RequestBody List patientScanConditionDTOList) { + @PostMapping("/get/byInpatientNoAndTimes") + @ApiOperation("根据住院号和住院次数,进行患者电子病历扫描数据采集,返回采集数据!") + public CommonResult> collectByInpatientNoAndTimes(@RequestBody List patientScanConditionDTOList) { if (Func.isEmpty(patientScanConditionDTOList)) { return CommonResult.failed("请输入正确的请求参数!"); } - patientScanService.collectByInpatientNoAndTimes(patientScanConditionDTOList); - return CommonResult.success("采集成功!"); + return CommonResult.success(patientScanService.getScanDataByInpatientNoAndTimes(patientScanConditionDTOList)); } } diff --git a/src/main/java/com/docus/server/collect/converter/FileReportConverter.java b/src/main/java/com/docus/server/collect/converter/FileReportConverter.java index 0642bf7..5df9625 100644 --- a/src/main/java/com/docus/server/collect/converter/FileReportConverter.java +++ b/src/main/java/com/docus/server/collect/converter/FileReportConverter.java @@ -1,6 +1,9 @@ package com.docus.server.collect.converter; import com.docus.server.collect.entity.DownloadTask; +import com.docus.server.collect.entity.PatientScan; +import com.docus.server.collect.entity.TBasic; +import com.docus.server.collect.enums.DownWayEnum; import com.docus.server.collect.enums.DownloadStateEnum; import com.docus.server.collect.infrastructure.client.dto.ReportDownDto; import com.docus.server.collect.infrastructure.client.dto.ReportDownPatientDto; @@ -20,6 +23,28 @@ import java.util.List; @Slf4j public class FileReportConverter { + /** + * 电子病历扫描视图对象,转换为上报文件信息对象,没有任务id和采集来源 + * @param tBasic 患者信息 + * @param patientScan 患者扫描文件信息 + * @return + */ + public ReportFileInfoDTO convertReportFileInfoDTO(TBasic tBasic, PatientScan patientScan) { + ReportFileInfoDTO fileInfoDTO = new ReportFileInfoDTO(); + fileInfoDTO.setPatientId(tBasic.getPatientId()); + fileInfoDTO.setInpatientNo(tBasic.getInpatientNo()); + fileInfoDTO.setAdmisstimes(tBasic.getAdmissTimes()); + fileInfoDTO.setJzh(tBasic.getJzh()); + fileInfoDTO.setIp("gdszy-patsm-sync"); + fileInfoDTO.setUserName("admin"); + fileInfoDTO.setReportUserFullName("pat-sm"); + fileInfoDTO.setSerialNum(patientScan.getId()+patientScan.getZdAssortName()+patientScan.getFileName()); + fileInfoDTO.setAssortId(patientScan.getZdAssortId()); + fileInfoDTO.setFileTitle(patientScan.getFileName().substring(0,patientScan.getFileName().indexOf("."))); + fileInfoDTO.setDownUrl(patientScan.getImagePath()+"/"+patientScan.getFileName()); + fileInfoDTO.setDownWayEnum(DownWayEnum.SMB); + return fileInfoDTO; + } /** * 转换病案文件上报信息,得到下载任务对象 diff --git a/src/main/java/com/docus/server/collect/dto/TBasicQrDto.java b/src/main/java/com/docus/server/collect/dto/TBasicQrDto.java index 53265f1..b31dd64 100644 --- a/src/main/java/com/docus/server/collect/dto/TBasicQrDto.java +++ b/src/main/java/com/docus/server/collect/dto/TBasicQrDto.java @@ -1,6 +1,5 @@ package com.docus.server.collect.dto; -import com.docus.server.collect.service.dto.ReportFileInfoDTO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -32,14 +31,11 @@ public class TBasicQrDto { @ApiModelProperty(value = "省中医患者主索引号") private String empId; + @ApiModelProperty(value = "是否忽略ph字段,为1 则添加条件 ph is null") + private int ignorePh; + public TBasicQrDto() { } - public TBasicQrDto(ReportFileInfoDTO fileInfoDTO) { - this.jzh = fileInfoDTO.getJzh(); - this.patientId = fileInfoDTO.getPatientId(); - this.inpatientNo = fileInfoDTO.getInpatientNo(); - this.admissTimes = fileInfoDTO.getAdmisstimes(); - ; - } + } diff --git a/src/main/java/com/docus/server/collect/entity/CollectTask.java b/src/main/java/com/docus/server/collect/entity/CollectTask.java new file mode 100644 index 0000000..5c7a909 --- /dev/null +++ b/src/main/java/com/docus/server/collect/entity/CollectTask.java @@ -0,0 +1,112 @@ +package com.docus.server.collect.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 文件采集任务 + * + * @author wyb + **/ +@ApiModel(value = "DownloadTask对象", description = "文件生成下载任务") +@Data +@TableName("af_collect_task") +public class CollectTask implements Serializable { + + + @TableField("id") + @ApiModelProperty(value = "id 雪花算法") + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + @TableField("patient_id") + @ApiModelProperty(value = "病案主键") + private String patientId; + + + @TableField("sysflag") + @ApiModelProperty(value = "来源 1护理文书,2 (HIS)电子病历,3 Pacs检查,4心电系统,5手麻系统,6 Lis检验,7临床首页,8长期医嘱, 9临时医嘱,10 省病案统计系统首页,11 扫描首页;") + private String sysflag; + + @TableField("start_time") + @ApiModelProperty(value = "开始时间") + private Date startTime; + + @TableField("end_time") + @ApiModelProperty(value = "结束时间") + private Date endTime; + + @TableField("state") + @ApiModelProperty(value = "任务状态 0:未开始,1:正在采集,2:采集错误,3采集完成") + private String state; + + + @TableField("sync_time") + @ApiModelProperty(value = "同步时间") + private Date syncTime; + + @TableField("recollect_time") + @ApiModelProperty(value = "最新重新采集时间") + private Date recollectTime; + + @TableField("recollect_name") + @ApiModelProperty(value = "最新重新采集人") + private String recollectName; + + @TableField("remark") + @ApiModelProperty(value = "备注") + private String remark; + + @TableField("presult") + @ApiModelProperty(value = "presult") + private String presult; + + @TableField("C1") + @ApiModelProperty(value = "报告唯一单号") + private String c1; + + @TableField("C2") + @ApiModelProperty(value = "文件名称") + private String c2; + + @TableField("C3") + @ApiModelProperty(value = "记账号") + private String c3; + + @TableField("C4") + @ApiModelProperty(value = "c4") + private String c4; + + @TableField("C5") + @ApiModelProperty(value = "c5") + private String c5; + + @TableField("C6") + @ApiModelProperty(value = "c6") + private String c6; + + @TableField("C7") + @ApiModelProperty(value = "c7") + private String c7; + + @TableField("C8") + @ApiModelProperty(value = "c8") + private String c8; + + @TableField("C9") + @ApiModelProperty(value = "c9") + private String c9; + + @TableField("C10") + @ApiModelProperty(value = "c10") + private String c10; +} diff --git a/src/main/java/com/docus/server/collect/entity/TBasic.java b/src/main/java/com/docus/server/collect/entity/TBasic.java index babe70e..ca74dc7 100644 --- a/src/main/java/com/docus/server/collect/entity/TBasic.java +++ b/src/main/java/com/docus/server/collect/entity/TBasic.java @@ -1,6 +1,5 @@ package com.docus.server.collect.entity; -import com.docus.server.collect.service.dto.ReportFileInfoDTO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -35,17 +34,5 @@ public class TBasic { private String admissId; @ApiModelProperty(value = "省中医患者主索引号") private String empId; -// @ApiModelProperty(value = "省中医患者记账号") -// private String accountRegistration; - public TBasic() { - } - - public TBasic(ReportFileInfoDTO fileInfoDTO) { - this.jzh = fileInfoDTO.getJzh(); - this.patientId = fileInfoDTO.getPatientId(); - this.inpatientNo = fileInfoDTO.getInpatientNo(); - this.admissTimes = fileInfoDTO.getAdmisstimes(); - ; - } } diff --git a/src/main/java/com/docus/server/collect/infrastructure/dao/CollectTaskDao.java b/src/main/java/com/docus/server/collect/infrastructure/dao/CollectTaskDao.java new file mode 100644 index 0000000..7cdd230 --- /dev/null +++ b/src/main/java/com/docus/server/collect/infrastructure/dao/CollectTaskDao.java @@ -0,0 +1,26 @@ +package com.docus.server.collect.infrastructure.dao; + +import com.docus.infrastructure.core.db.dao.IBaseDao; +import com.docus.server.collect.entity.CollectTask; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; + +/** + * 采集任务dao层接口 + * @author wyb + */ +public interface CollectTaskDao extends IBaseDao { + /** + * 根据上报文件信息,保存采集任务并且返回任务id + * @param reportFileInfoDTO 上报文件信息 + * @return 采集任务id + */ + Long saveTask(ReportFileInfoDTO reportFileInfoDTO); + + /** + * 等同 saveTask,但是加了锁防止并发环境重复任务 + * @param reportFileInfoDTO 上报文件信息 + * @return 采集任务id + * @throws InterruptedException 异常 + */ + Long saveTaskUseLock(ReportFileInfoDTO reportFileInfoDTO) throws InterruptedException; +} diff --git a/src/main/java/com/docus/server/collect/infrastructure/dao/DownloadTaskDao.java b/src/main/java/com/docus/server/collect/infrastructure/dao/DownloadTaskDao.java index 5f16418..9322c2d 100644 --- a/src/main/java/com/docus/server/collect/infrastructure/dao/DownloadTaskDao.java +++ b/src/main/java/com/docus/server/collect/infrastructure/dao/DownloadTaskDao.java @@ -2,9 +2,6 @@ package com.docus.server.collect.infrastructure.dao; import com.docus.infrastructure.core.db.dao.IBaseDao; import com.docus.server.collect.entity.DownloadTask; -import com.docus.server.collect.entity.TBasic; - -import java.util.List; /** * 下载任务表-数据访问接口 @@ -12,13 +9,7 @@ import java.util.List; * @author wyb */ public interface DownloadTaskDao extends IBaseDao { - /** - * 根据患者信息,查询患者基础数据 - * - * @param tBasic 患者基础信息 - * @return 患者基础数据 - */ - List getBasicInfo(TBasic tBasic); + /** diff --git a/src/main/java/com/docus/server/collect/infrastructure/dao/impl/CollectTaskDaoImpl.java b/src/main/java/com/docus/server/collect/infrastructure/dao/impl/CollectTaskDaoImpl.java new file mode 100644 index 0000000..b2f3bc9 --- /dev/null +++ b/src/main/java/com/docus/server/collect/infrastructure/dao/impl/CollectTaskDaoImpl.java @@ -0,0 +1,70 @@ +package com.docus.server.collect.infrastructure.dao.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.docus.infrastructure.core.db.dao.impl.BaseDaoImpl; +import com.docus.infrastructure.redis.service.IdService; +import com.docus.infrastructure.redis.service.RedisLock; +import com.docus.server.collect.entity.CollectTask; +import com.docus.server.collect.infrastructure.dao.CollectTaskDao; +import com.docus.server.collect.infrastructure.mapper.CollectTaskMapper; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; +import org.springframework.stereotype.Repository; + +import javax.annotation.Resource; +import java.util.Date; + +/** + * 采集任务表dao层实现 + * + * @author wyb + */ +@Repository +public class CollectTaskDaoImpl extends BaseDaoImpl implements CollectTaskDao { + + @Resource + private IdService idService; + @Resource + private RedisLock redisLock; + + @Override + public Long saveTask(ReportFileInfoDTO reportFileInfoDTO) { + Date now = new Date(); + LambdaQueryWrapper queryCollectTaskWrapper = new LambdaQueryWrapper<>(); + queryCollectTaskWrapper.eq(CollectTask::getC1, reportFileInfoDTO.getSerialNum()); + queryCollectTaskWrapper.eq(CollectTask::getSysflag, reportFileInfoDTO.getSysFlag()); + queryCollectTaskWrapper.eq(CollectTask::getPatientId, reportFileInfoDTO.getPatientId()); + CollectTask collectTask = baseMapper.selectOne(queryCollectTaskWrapper); + // 更新或者新增 + if (collectTask != null) { + collectTask.setState("0"); + collectTask.setSyncTime(now); + collectTask.setC2(reportFileInfoDTO.getFileTitle()); + baseMapper.updateById(collectTask); + } else { + collectTask = new CollectTask(); + collectTask.setId(idService.getDateSeq()); + collectTask.setPatientId(reportFileInfoDTO.getPatientId()); + collectTask.setSysflag(reportFileInfoDTO.getSysFlag()); + collectTask.setState("0"); + collectTask.setSyncTime(now); + collectTask.setC1(reportFileInfoDTO.getSerialNum()); + collectTask.setC2(reportFileInfoDTO.getFileTitle()); + collectTask.setC3(reportFileInfoDTO.getJzh()); + baseMapper.insert(collectTask); + } + return collectTask.getId(); + + } + + @Override + public Long saveTaskUseLock(ReportFileInfoDTO reportFileInfoDTO) throws InterruptedException { + + String lockFlag = "docus:gdszy:downloadplatform:report:" + reportFileInfoDTO.getPatientId() + ":" + reportFileInfoDTO.getSysFlag(); + try { + redisLock.tryLock(lockFlag, 10 * 1000, 10 * 1000); + return saveTask(reportFileInfoDTO); + } finally { + redisLock.unLock(lockFlag); + } + } +} diff --git a/src/main/java/com/docus/server/collect/infrastructure/dao/impl/DownloadTaskDaoImpl.java b/src/main/java/com/docus/server/collect/infrastructure/dao/impl/DownloadTaskDaoImpl.java index 0f09a61..931c5b1 100644 --- a/src/main/java/com/docus/server/collect/infrastructure/dao/impl/DownloadTaskDaoImpl.java +++ b/src/main/java/com/docus/server/collect/infrastructure/dao/impl/DownloadTaskDaoImpl.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.docus.core.util.Func; import com.docus.infrastructure.core.db.dao.impl.BaseDaoImpl; import com.docus.server.collect.entity.DownloadTask; -import com.docus.server.collect.entity.TBasic; import com.docus.server.collect.infrastructure.dao.DownloadTaskDao; import com.docus.server.collect.infrastructure.mapper.DownloadTaskMapper; import org.springframework.stereotype.Repository; @@ -18,10 +17,6 @@ import java.util.List; */ @Repository public class DownloadTaskDaoImpl extends BaseDaoImpl implements DownloadTaskDao { - @Override - public List getBasicInfo(TBasic basic) { - return baseMapper.getBasicInfo(basic); - } @Override public Long getDownloadTaskIdFromDownloadTask(DownloadTask downloadTask) { diff --git a/src/main/java/com/docus/server/collect/infrastructure/mapper/CollectTaskMapper.java b/src/main/java/com/docus/server/collect/infrastructure/mapper/CollectTaskMapper.java index 8a634e6..f422139 100644 --- a/src/main/java/com/docus/server/collect/infrastructure/mapper/CollectTaskMapper.java +++ b/src/main/java/com/docus/server/collect/infrastructure/mapper/CollectTaskMapper.java @@ -1,6 +1,8 @@ package com.docus.server.collect.infrastructure.mapper; import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.docus.server.collect.entity.CollectTask; import org.apache.ibatis.annotations.Mapper; /** @@ -8,5 +10,5 @@ import org.apache.ibatis.annotations.Mapper; */ @DS("archive-mysql") @Mapper -public interface CollectTaskMapper { +public interface CollectTaskMapper extends BaseMapper { } diff --git a/src/main/java/com/docus/server/collect/infrastructure/mapper/DownloadTaskMapper.java b/src/main/java/com/docus/server/collect/infrastructure/mapper/DownloadTaskMapper.java index d2a1b42..b3b6bd7 100644 --- a/src/main/java/com/docus/server/collect/infrastructure/mapper/DownloadTaskMapper.java +++ b/src/main/java/com/docus/server/collect/infrastructure/mapper/DownloadTaskMapper.java @@ -2,41 +2,13 @@ package com.docus.server.collect.infrastructure.mapper; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.docus.server.collect.dto.TBasicQrDto; import com.docus.server.collect.entity.DownloadTask; -import com.docus.server.collect.entity.TBasic; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import java.util.List; - @DS("archive-mysql") @Mapper public interface DownloadTaskMapper extends BaseMapper { - /** - * 根据患者信息获取基础病案信息 from `docus_medicalrecord`.`t_basic` - * - * @param tBasic 患者基础信息 - * @return 病案基础信息 - */ - List getBasicInfo(@Param("basic") TBasic tBasic); - - /** - * 根据病案查询条件,查询病案数量 - * @param qrDto 查询条件 - * @return 病案数量 - */ - int countBasicInfo(@Param("dto") TBasicQrDto qrDto); - - /** - * 根据条件,分页查询病案 - * @param qrDto 查询条件 - * @param offset 分页参数从第几条开始 - * @param size 每页显示条数 - * @return 病案基础信息 - */ - List pageBasicInfo(@Param("dto") TBasicQrDto qrDto,@Param("offset") long offset,@Param("size") long size); - /** * 根据病案的来源,病案文件的唯一标识,从文件表得到文件下载任务id(也是文件id) * @param patientId 病案主键 diff --git a/src/main/java/com/docus/server/collect/infrastructure/mapper/PatientBasicMapper.java b/src/main/java/com/docus/server/collect/infrastructure/mapper/PatientBasicMapper.java index f23aece..de1f98c 100644 --- a/src/main/java/com/docus/server/collect/infrastructure/mapper/PatientBasicMapper.java +++ b/src/main/java/com/docus/server/collect/infrastructure/mapper/PatientBasicMapper.java @@ -1,7 +1,12 @@ package com.docus.server.collect.infrastructure.mapper; import com.baomidou.dynamic.datasource.annotation.DS; +import com.docus.server.collect.dto.TBasicQrDto; +import com.docus.server.collect.entity.TBasic; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * @author wyb @@ -9,4 +14,11 @@ import org.apache.ibatis.annotations.Mapper; @DS("archive-mysql") @Mapper public interface PatientBasicMapper { + /** + * 根据患者信息条件获取基础病案信息 from `docus_medicalrecord`.`t_basic` + * + * @param dto 患者基础信息条件 + * @return 病案基础信息 + */ + List getBasicInfo(@Param("dto") TBasicQrDto dto); } diff --git a/src/main/java/com/docus/server/collect/infrastructure/mapper/PatientScanMapper.java b/src/main/java/com/docus/server/collect/infrastructure/mapper/PatientScanMapper.java index 1089bc5..b4e9cf6 100644 --- a/src/main/java/com/docus/server/collect/infrastructure/mapper/PatientScanMapper.java +++ b/src/main/java/com/docus/server/collect/infrastructure/mapper/PatientScanMapper.java @@ -30,7 +30,14 @@ public interface PatientScanMapper { * @param scanEndTime 扫描时间结束时间 * @return 住院号和住院次数条件 */ - List getScanPatientCondition(@Param("start")String scanStartTime,@Param("end") String scanEndTime); + List getScanPatientConditionByScanDate(@Param("start")String scanStartTime, @Param("end") String scanEndTime); + /** + * 根据出院时间,查询住院号和住院次数条件 + * @param scanStartTime 扫描时间开始时间 + * @param scanEndTime 扫描时间结束时间 + * @return 住院号和住院次数条件 + */ + List getScanPatientConditionByDisDate(@Param("start")String scanStartTime, @Param("end") String scanEndTime); } diff --git a/src/main/java/com/docus/server/collect/job/PatScanFileSyncJob.java b/src/main/java/com/docus/server/collect/job/PatScanFileSyncJob.java new file mode 100644 index 0000000..6229c86 --- /dev/null +++ b/src/main/java/com/docus/server/collect/job/PatScanFileSyncJob.java @@ -0,0 +1,167 @@ +package com.docus.server.collect.job; + +import com.docus.core.util.Func; +import com.docus.infrastructure.core.utils.TableJsonRead; +import com.docus.server.collect.converter.FileReportConverter; +import com.docus.server.collect.dto.PatientScanConditionDTO; +import com.docus.server.collect.dto.TBasicQrDto; +import com.docus.server.collect.entity.PatientScan; +import com.docus.server.collect.entity.TBasic; +import com.docus.server.collect.infrastructure.dao.CollectTaskDao; +import com.docus.server.collect.infrastructure.mapper.PatientBasicMapper; +import com.docus.server.collect.service.FileReportService; +import com.docus.server.collect.service.PatientScanService; +import com.docus.server.collect.service.dto.ReportFileInfoDTO; +import com.xxl.job.core.context.XxlJobHelper; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +/** + * 患者扫描文件同步任务 + * + * @author wyb + */ +@Component +@Slf4j +public class PatScanFileSyncJob { + @Resource + private PatientScanService patientScanService; + @Resource + private PatientBasicMapper patientBasicMapper; + @Resource + private FileReportService fileReportService; + @Resource + private CollectTaskDao collectTaskDao; + @Resource + private FileReportConverter fileReportConverter; + + @Value("${docus.sync.patsmGSys}") + private String patmGSys; + + @XxlJob("PatScanFileSyncByScanDateJob") + public void patScanFileSyncByScanDateJob() { + final String taskName = "电子病历扫描视图同步,根据扫描时间同步Job"; + log.info("============================= {}采集开始!=============================", taskName); + try { + patScanFileSyncByScanDate(); + } catch (Exception ex) { + log.error(taskName + "============================= 采集出现错误!============================= ", ex); + } + log.info("============================= {}采集结束!=============================", taskName); + } + + private void patScanFileSyncByScanDate() { + + String delayDayParam = XxlJobHelper.getJobParam(); + int delayDay = 1; + try { + if (Func.isNotBlank(delayDayParam)) { + delayDay = Integer.parseInt(delayDayParam); + } + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + LocalDate jobStartDate = LocalDate.now(); + + QueryConfig config = QueryConfig.getQueryConfig(); + LocalDate dateStartCondition; + if (config == null) { + config = new QueryConfig(); + dateStartCondition = jobStartDate.plusDays(-delayDay); + + } else { + dateStartCondition = LocalDate.parse(config.getLastExecuteDate()).plusDays(-delayDay); + } + config.setLastExecuteDate(dateStartCondition.toString()); + + LocalDate lastExecuteDate = dateStartCondition; + // 一天一天的执行,查询一天的住院号和住院次数,单个患者进行采集上传 + // 执行的时间如果大于job的当天,则结束 + do { + if (lastExecuteDate.isAfter(jobStartDate)) { + break; + } + String startTime = lastExecuteDate + " 00:00:00"; + String endTime = lastExecuteDate + " 23:59:59"; + List inpatientNoAndTimesByScanDate = patientScanService.getInpatientNoAndTimesByScanDate(startTime, endTime); + inpatientNoAndTimesByScanDate = Optional.ofNullable(inpatientNoAndTimesByScanDate).orElse(new ArrayList<>()); + for (PatientScanConditionDTO patientScanConditionDTO : inpatientNoAndTimesByScanDate) { + List basicList = getBasicInfo(patientScanConditionDTO); + if (Objects.isNull(basicList) || basicList.size() != 1) { + log.warn("{},住院号:{},住院次数:{} 查询基础数据没有数据或者有多条数据,请检查!", "电子病历扫描视图同步,根据扫描时间同步Job", patientScanConditionDTO.getInpatientNo(), patientScanConditionDTO.getAdmissTimes()); + continue; + } + List patientScanList = patientScanService.getScanDataByInpatientNoAndTimes(patientScanConditionDTO); + log.warn("{},住院号:{},住院次数:{} 采集视图数据:{} 条!,数据为:{}", "电子病历扫描视图同步,根据扫描时间同步Job", patientScanConditionDTO.getInpatientNo(), patientScanConditionDTO.getAdmissTimes(), patientScanList.size(), patientScanList); + saveCollectTaskAndReport(basicList.get(0), patientScanList); + log.warn("{},住院号:{},住院次数:{} 采集视图数据:{} 条,执行成功!", "电子病历扫描视图同步,根据扫描时间同步Job", patientScanConditionDTO.getInpatientNo(), patientScanConditionDTO.getAdmissTimes(), patientScanList); + } + lastExecuteDate = lastExecuteDate.plusDays(1); + } while (!lastExecuteDate.isAfter(jobStartDate)); + config.setLastExecuteDate(jobStartDate.toString()); + config.refresh(); + } + + private void saveCollectTaskAndReport(TBasic tBasic, List patientScanList) { + for (PatientScan patientScan : patientScanList) { + // 转换后的对象缺失的补充 + ReportFileInfoDTO reportFileInfoDTO = fileReportConverter.convertReportFileInfoDTO(tBasic, patientScan); + reportFileInfoDTO.setSysFlag(patmGSys); + Long taskId = collectTaskDao.saveTask(reportFileInfoDTO); + reportFileInfoDTO.setTaskId(taskId); + fileReportService.saveDownloadTaskAndReport(reportFileInfoDTO); + } + } + + private List getBasicInfo(PatientScanConditionDTO patientScanConditionDTO) { + TBasicQrDto basicQrDto = new TBasicQrDto(); + basicQrDto.setInpatientNo(patientScanConditionDTO.getInpatientNo()); + basicQrDto.setAdmissTimes(Integer.parseInt(patientScanConditionDTO.getAdmissTimes())); + basicQrDto.setIgnorePh(1); + return patientBasicMapper.getBasicInfo(basicQrDto); + } + + + public static void main(String[] args) { + QueryConfig config = QueryConfig.getQueryConfig(); + if (config == null) { + config = new QueryConfig(); + } + config.setLastExecuteDate(LocalDate.now().toString()); + config.refresh(); + } + + + public static class QueryConfig { + private String lastExecuteDate; + + public String getLastExecuteDate() { + return lastExecuteDate; + } + + public void setLastExecuteDate(String lastExecuteDate) { + this.lastExecuteDate = lastExecuteDate; + } + + public static QueryConfig getQueryConfig() { + TableJsonRead tableJsonRead = new TableJsonRead(); + return tableJsonRead.Read("docus", "PatScanFileSyncByScanDateJobQuery.json", QueryConfig.class); + } + + public void refresh() { + TableJsonRead tableJsonRead = new TableJsonRead(); + tableJsonRead.Save("docus", "PatScanFileSyncByScanDateJobQuery.json", Func.toJson(this)); + } + + } + +} diff --git a/src/main/java/com/docus/server/collect/service/PatientScanService.java b/src/main/java/com/docus/server/collect/service/PatientScanService.java index 87b9a86..75f9bd2 100644 --- a/src/main/java/com/docus/server/collect/service/PatientScanService.java +++ b/src/main/java/com/docus/server/collect/service/PatientScanService.java @@ -10,14 +10,34 @@ import java.util.List; */ public interface PatientScanService { /** - * 根据患者住院号和住院次数采集-批量 + * 根据患者住院号和住院次数采集-批量,返回采集数据 * @param patientScanConditionDTOList 患者扫描条件传输对象集合 + * @return 采集数据 */ - void collectByInpatientNoAndTimes(List patientScanConditionDTOList); + List getScanDataByInpatientNoAndTimes(List patientScanConditionDTOList); /** - * 根据患者住院号和住院次数采集-单个 + * 根据患者住院号和住院次数采集-单个,返回采集数据 * @param patientScanConditionDto 患者扫描条件传输对象 + * @return 采集数据 */ - List collectByInpatientNoAndTimes(PatientScanConditionDTO patientScanConditionDto); + List getScanDataByInpatientNoAndTimes(PatientScanConditionDTO patientScanConditionDto); + + + /** + * 根据扫描时间查询条件,获取住院号和住院次数 + * @param startTime 区间开始 不为空 + * @param endTime 区间结束 不为空 + * @return 病案号和住院次数 + */ + List getInpatientNoAndTimesByScanDate(String startTime,String endTime); + + /** + * 根据出院时间查询条件,获取住院号和住院次数 + * @param startTime 出院时间区间开始 不为空 + * @param endTime 出院时间区间结束 不为空 + * @return 病案号和住院次数 + */ + List getInpatientNoAndTimesByDisDate(String startTime,String endTime); + } diff --git a/src/main/java/com/docus/server/collect/service/dto/ReportFileInfoDTO.java b/src/main/java/com/docus/server/collect/service/dto/ReportFileInfoDTO.java index cbe31ae..8426459 100644 --- a/src/main/java/com/docus/server/collect/service/dto/ReportFileInfoDTO.java +++ b/src/main/java/com/docus/server/collect/service/dto/ReportFileInfoDTO.java @@ -5,9 +5,6 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; - /** * 上报的文件信息 * 住院号,记账号,住院次数,患者病案主键 必须有一组组合能查出患者基础信息且唯一,不能多传参数,防止查不出来 @@ -42,39 +39,33 @@ public class ReportFileInfoDTO { * 采集来源系统 */ @ApiModelProperty("采集来源系统") - @NotBlank private String sysFlag; /** * 下载地址 */ @ApiModelProperty("下载地址") - @NotBlank private String downUrl; /** * 下载地址 */ @ApiModelProperty("下载地址类型") - @NotNull private DownWayEnum downWayEnum; /** * 文件名 */ @ApiModelProperty("文件名") - @NotBlank private String fileTitle; /** * 采集流水号/文件唯一id */ @ApiModelProperty("采集流水号/文件唯一id") - @NotBlank private String serialNum; /** * 文件分类id */ @ApiModelProperty("文件分类id") - @NotBlank private String assortId; diff --git a/src/main/java/com/docus/server/collect/service/impl/FileReportServiceImpl.java b/src/main/java/com/docus/server/collect/service/impl/FileReportServiceImpl.java index d7cd289..b7d9a7b 100644 --- a/src/main/java/com/docus/server/collect/service/impl/FileReportServiceImpl.java +++ b/src/main/java/com/docus/server/collect/service/impl/FileReportServiceImpl.java @@ -4,11 +4,16 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.docus.core.util.Func; import com.docus.infrastructure.redis.service.IdService; +import com.docus.infrastructure.web.api.CommonResult; +import com.docus.infrastructure.web.api.ResultCode; import com.docus.server.collect.converter.FileReportConverter; +import com.docus.server.collect.dto.TBasicQrDto; import com.docus.server.collect.entity.DownloadTask; import com.docus.server.collect.entity.TBasic; import com.docus.server.collect.infrastructure.client.DownloadPlatformService; +import com.docus.server.collect.infrastructure.client.dto.ReportDownDto; import com.docus.server.collect.infrastructure.dao.DownloadTaskDao; +import com.docus.server.collect.infrastructure.mapper.PatientBasicMapper; import com.docus.server.collect.service.FileReportService; import com.docus.server.collect.service.dto.ReportFileInfoDTO; import lombok.extern.slf4j.Slf4j; @@ -32,6 +37,8 @@ public class FileReportServiceImpl implements FileReportService { @Autowired private DownloadTaskDao downloadTaskDao; @Autowired + private PatientBasicMapper patientBasicMapper; + @Autowired private FileReportConverter fileReportConverter; @Autowired @@ -42,9 +49,10 @@ public class FileReportServiceImpl implements FileReportService { @Override public void saveDownloadTaskAndReport(ReportFileInfoDTO fileInfoDTO) { - TBasic basic = new TBasic(fileInfoDTO); + + TBasicQrDto basicQrDto = convertTbasicQrDto(fileInfoDTO); // 查询基础数据,更新新的病案信息 - List tBasics = downloadTaskDao.getBasicInfo(basic); + List tBasics = patientBasicMapper.getBasicInfo(basicQrDto); // 如果找到患者基础数据,并且刚好为1条 if (CollUtil.isNotEmpty(tBasics) && tBasics.size() == 1) { TBasic tBasic = tBasics.get(0); @@ -62,19 +70,34 @@ public class FileReportServiceImpl implements FileReportService { report(downloadTask); } + private TBasicQrDto convertTbasicQrDto(ReportFileInfoDTO fileInfoDTO) { + String patientId = fileInfoDTO.getPatientId(); + String jzh = fileInfoDTO.getJzh(); + String inpatientNo = fileInfoDTO.getInpatientNo(); + Integer admisstimes = fileInfoDTO.getAdmisstimes(); + + TBasicQrDto dto = new TBasicQrDto(); + dto.setPatientId(patientId); + dto.setJzh(jzh); + dto.setInpatientNo(inpatientNo); + dto.setAdmissTimes(admisstimes); + + return dto; + } + @Override public Long getDownloadTaskId(DownloadTask downloadTask) { String patientId = downloadTask.getPatientId(); - if(StrUtil.isNotBlank(patientId)){ + if (StrUtil.isNotBlank(patientId)) { String serialNum = downloadTask.getFileSerialNum(); String source = downloadTask.getSource(); // 从文件表获取 - Long downloadTaskId = downloadTaskDao.getDownloadTaskIdFromSanAssort(patientId,source,serialNum); + Long downloadTaskId = downloadTaskDao.getDownloadTaskIdFromSanAssort(patientId, source, serialNum); if (Func.isNotEmpty(downloadTaskId)) { return downloadTaskId; } // 从下载记录表获取 - downloadTaskId = downloadTaskDao.getDownloadTaskIdFromDownFile(patientId,source,serialNum); + downloadTaskId = downloadTaskDao.getDownloadTaskIdFromDownFile(patientId, source, serialNum); if (Func.isNotEmpty(downloadTaskId)) { return downloadTaskId; } @@ -91,7 +114,17 @@ public class FileReportServiceImpl implements FileReportService { private void report(DownloadTask downloadTask) { threadPoolExecutor.execute(() -> { if (downloadTask.getBasicDataType().equals(0)) { - downloadPlatformService.report(fileReportConverter.convertDownloadPlatformParam(downloadTask)); + ReportDownDto reportDownDto = fileReportConverter.convertDownloadPlatformParam(downloadTask); + try { + CommonResult commonResult = downloadPlatformService.report(reportDownDto); + if (commonResult.getCode().equals(ResultCode.SUCCESS.getCode())) { + log.info("{},文件上报成功!返回信息:{}", Func.toJson(reportDownDto.getPatient()), Func.toJson(commonResult)); + } else { + log.error("文件上报失败!返回信息:{},上报信息:{}", Func.toJson(commonResult), Func.toJson(reportDownDto)); + } + } catch (Exception ex) { + log.error("文件上报下载服务出错啦!数据为:" + Func.toJson(reportDownDto), ex); + } } }); } diff --git a/src/main/java/com/docus/server/collect/service/impl/PatientScanServiceImpl.java b/src/main/java/com/docus/server/collect/service/impl/PatientScanServiceImpl.java index a9203d9..10fee6b 100644 --- a/src/main/java/com/docus/server/collect/service/impl/PatientScanServiceImpl.java +++ b/src/main/java/com/docus/server/collect/service/impl/PatientScanServiceImpl.java @@ -2,7 +2,6 @@ package com.docus.server.collect.service.impl; import com.docus.server.collect.dto.PatientScanConditionDTO; import com.docus.server.collect.entity.PatientScan; -import com.docus.server.collect.infrastructure.mapper.DownloadTaskMapper; import com.docus.server.collect.infrastructure.mapper.PatientScanMapper; import com.docus.server.collect.service.PatientScanService; import groovy.util.logging.Slf4j; @@ -22,18 +21,32 @@ import java.util.Map; public class PatientScanServiceImpl implements PatientScanService { @Resource private PatientScanMapper patientScanMapper; + @Override - public void collectByInpatientNoAndTimes(List patientScanConditionDTOList) { + public List getScanDataByInpatientNoAndTimes(List patientScanConditionDTOList) { List distinctPatientScanConditionDTOList = distinctForInpatientNoAndTimes(patientScanConditionDTOList); + List list = new LinkedList<>(); for (PatientScanConditionDTO patientScanConditionDTO : distinctPatientScanConditionDTOList) { - collectByInpatientNoAndTimes(patientScanConditionDTO); + List patientScanList = getScanDataByInpatientNoAndTimes(patientScanConditionDTO); + list.addAll(patientScanList); } + return list; + } + + + @Override + public List getScanDataByInpatientNoAndTimes(PatientScanConditionDTO patientScanConditionDto) { + return patientScanMapper.getScanData(patientScanConditionDto); } + @Override + public List getInpatientNoAndTimesByScanDate(String startTime, String endTime) { + return patientScanMapper.getScanPatientConditionByScanDate(startTime,endTime); + } @Override - public List collectByInpatientNoAndTimes(PatientScanConditionDTO patientScanConditionDto) { - return patientScanMapper.getScanData(patientScanConditionDto); + public List getInpatientNoAndTimesByDisDate(String startTime, String endTime) { + return patientScanMapper.getScanPatientConditionByScanDate(startTime,endTime); } /** diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml index a39bb6d..82668e7 100644 --- a/src/main/resources/bootstrap.yml +++ b/src/main/resources/bootstrap.yml @@ -78,6 +78,9 @@ docus: url: # 下载平台服务地址 downloadPlatform: http://192.168.16.85:9291 + sync: + # 电子病历视图扫描文件同步采集器id定义 + patsmGSys: 25 mybatis-plus: configuration: diff --git a/src/main/resources/mapper/DownloadTaskMapper.xml b/src/main/resources/mapper/DownloadTaskMapper.xml new file mode 100644 index 0000000..f99f79d --- /dev/null +++ b/src/main/resources/mapper/DownloadTaskMapper.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/src/main/resources/mapper/PatientBasicMapper.xml b/src/main/resources/mapper/PatientBasicMapper.xml new file mode 100644 index 0000000..5945a02 --- /dev/null +++ b/src/main/resources/mapper/PatientBasicMapper.xml @@ -0,0 +1,53 @@ + + + + + patient_id + as patientId, + admiss_times as admissTimes, + inpatient_no as inpatientNo, + admiss_id as admissId, + admiss_date as admissDate, + dis_date as disDate, + admiss_dept_name as admissDeptName, + dis_dept_name as disDeptName , + jzh, + name, + emp_id as empId + + + + + + diff --git a/src/main/resources/mapper/PatientScanMapper.xml b/src/main/resources/mapper/PatientScanMapper.xml index 99ff6f8..a584c07 100644 --- a/src/main/resources/mapper/PatientScanMapper.xml +++ b/src/main/resources/mapper/PatientScanMapper.xml @@ -3,9 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - + select + from pat_sm where 住院号=#{dto.inpatientNo} and 次数=#{dto.admissTimes} and 扫描盘号 like 'G%' - select 住院号 as inpatientNo, 次数 as admissTimes from pat_sm @@ -32,5 +35,12 @@ group by 住院号, 次数 - + diff --git a/src/main/resources/mapper/TBasicMapper.xml b/src/main/resources/mapper/TBasicMapper.xml deleted file mode 100644 index 4c15ea5..0000000 --- a/src/main/resources/mapper/TBasicMapper.xml +++ /dev/null @@ -1,123 +0,0 @@ - - - - - patient_id as patientId, - admiss_times as admissTimes, - inpatient_no as inpatientNo, - admiss_id as admissId, - admiss_date as admissDate, - dis_date as disDate, - admiss_dept_name as admissDeptName, - dis_dept_name as disDeptName , - jzh, - name, - emp_id as empId - - - - - - - - - - -