diff --git a/src/main/java/com/docus/server/report/api/ShunDePeopleService.java b/src/main/java/com/docus/server/report/api/ShunDePeopleService.java index 14fc74e..f8bbe06 100644 --- a/src/main/java/com/docus/server/report/api/ShunDePeopleService.java +++ b/src/main/java/com/docus/server/report/api/ShunDePeopleService.java @@ -1,5 +1,7 @@ package com.docus.server.report.api; +import com.docus.server.report.api.dto.SdJxReportDto; + import java.util.List; /** @@ -14,7 +16,20 @@ public interface ShunDePeopleService { * @param sdRyIndex 顺德人医第三方索引 * @return 报告交叉索引 */ - List getSdRyReportPatientIds(String sdRyIndex); + List getSdRyReportJxIds(String sdRyIndex); + + /** + * 根据顺德人医的报告交叉索引,查询检查报告 + * @param sdJxReportDto 交叉索引和其他信息 + * @return 检查报告 + */ + String getInspectReportByJxId(SdJxReportDto sdJxReportDto); + /** + * 根据顺德人医的报告交叉索引,查询Lis检验报告 + * @param sdJxReportDto 交叉索引和其他信息 + * @return 检查报告 + */ + String getLisReportByJxId(SdJxReportDto sdJxReportDto); /** * 根据检查流水或和报告序列号,指定要获取的报告,PACS将生成PDF格式的报告,并将PDF文件的BASE64编码串返回。 diff --git a/src/main/java/com/docus/server/report/api/dto/SdJxReportDto.java b/src/main/java/com/docus/server/report/api/dto/SdJxReportDto.java new file mode 100644 index 0000000..c872b07 --- /dev/null +++ b/src/main/java/com/docus/server/report/api/dto/SdJxReportDto.java @@ -0,0 +1,28 @@ +package com.docus.server.report.api.dto; + +import lombok.Data; + +@Data +public class SdJxReportDto { + + private boolean isPage=true; + private int pageNo=1; + private int pageSize=5; + private String orgCode="4560886379"; + /** + * 开始时间 + */ + private String startTime; + /** + * 结束时间 + */ + private String endTime; + /** + * 通过webservice查询的交叉索引,不是归档系统的病案主键 + */ + private String patientId; + /** + * 就诊类型 1门诊 3住院 + */ + private String patentTypeCode="1"; +} diff --git a/src/main/java/com/docus/server/report/api/impl/ShunDePeopleServiceImpl.java b/src/main/java/com/docus/server/report/api/impl/ShunDePeopleServiceImpl.java index 21f7c1e..70983a5 100644 --- a/src/main/java/com/docus/server/report/api/impl/ShunDePeopleServiceImpl.java +++ b/src/main/java/com/docus/server/report/api/impl/ShunDePeopleServiceImpl.java @@ -1,8 +1,12 @@ package com.docus.server.report.api.impl; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; import com.docus.core.util.DateUtil; import com.docus.core.util.Func; import com.docus.server.report.api.ShunDePeopleService; +import com.docus.server.report.api.dto.SdJxReportDto; import com.docus.server.report.api.dto.SdPacsServerConfig; import com.docus.server.report.client.JaxWsDynamicClient; import com.docus.server.report.config.SdRyReportQueryConfig; @@ -17,6 +21,7 @@ import org.w3c.dom.NodeList; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; @@ -32,17 +37,53 @@ import java.util.concurrent.locks.ReentrantLock; public class ShunDePeopleServiceImpl implements ShunDePeopleService { private static final Lock INDEX_LOCK = new ReentrantLock(); private static final Lock PACS_PDF_LOCK = new ReentrantLock(); + private static final Lock INSPECT_REPORT_LOCK = new ReentrantLock(); + private static final Lock LIS_REPORT_LOCK = new ReentrantLock(); + @Resource private SdRyReportQueryConfig sdRyReportQueryConfig; - public static void main(String[] args) { - ShunDePeopleServiceImpl shunDePeopleService = new ShunDePeopleServiceImpl(); - String base64PdfFromPacs = shunDePeopleService.getBase64PdfFromPacs("121", "1"); - System.out.println(base64PdfFromPacs); + + @Override + public String getInspectReportByJxId(SdJxReportDto sdJxReportDto) { + String requestParam = organizationQuerySdRyInspectReportParam(sdJxReportDto); + String url = organizationQuerySdRyInspectReportUrl(sdRyReportQueryConfig.getReportQueryInspectUrl()); + log.info("查询检查报告请求地址:{} ,请求body参数:{}", url, requestParam); + INSPECT_REPORT_LOCK.lock(); + try { + String respBody = this.sendPost(url, requestParam); + log.info("查询检查报告请求成功,响应参数:{}", respBody); + TimeUnit.MILLISECONDS.sleep(sdRyReportQueryConfig.getReportQueryInspectInterval()); + return respBody; + } catch (Exception ex) { + log.error("查询检查报告失败:"+ex.getMessage(), ex); + return ""; + } finally { + INSPECT_REPORT_LOCK.unlock(); + } } @Override - public List getSdRyReportPatientIds(String sdRyIndex) { + public String getLisReportByJxId(SdJxReportDto sdJxReportDto) { + String requestParam = organizationQuerySdRyLisReportParam(sdJxReportDto); + String url = organizationQuerySdRyLisReportUrl(sdRyReportQueryConfig.getReportQueryInspectUrl()); + log.info("查询LIS检验报告请求地址:{} ,请求body参数:{}", url, requestParam); + LIS_REPORT_LOCK.lock(); + try { + String respBody = this.sendPost(url, requestParam); + log.info("查询LIS检验报告请求成功,响应参数:{}", respBody); + TimeUnit.MILLISECONDS.sleep(sdRyReportQueryConfig.getReportQueryLisInterval()); + return respBody; + } catch (Exception ex) { + log.error("查询LIS检验报告失败:"+ex.getMessage(), ex); + return ""; + } finally { + LIS_REPORT_LOCK.unlock(); + } + } + + @Override + public List getSdRyReportJxIds(String sdRyIndex) { List indexes = new ArrayList<>(); try { String zyParam = organizationQuerySdRyReportIndexParam(sdRyIndex, 3); @@ -91,6 +132,65 @@ public class ShunDePeopleServiceImpl implements ShunDePeopleService { } } + + private String organizationQuerySdRyInspectReportUrl(String reportQueryLisUrl) { + return reportQueryLisUrl + "/query?uuid=" + IdUtil.standardUUID() + + "&action=" + sdRyReportQueryConfig.getReportQueryInspectAction() + + "&accessKey=" + sdRyReportQueryConfig.getReportQueryInspectAccessKey() + + "&creationTime=" + Func.format(new Date(), DateUtil.PATTERN_DATETIME_MINI); + + } + private String organizationQuerySdRyInspectReportParam(SdJxReportDto dto) { + String patientId = dto.getPatientId(); + if("1".equals(dto.getPatentTypeCode())){ + patientId="m"+patientId; + } + if("3".equals(dto.getPatentTypeCode())){ + patientId="z"+patientId; + } + HashMap map = new HashMap<>(7); + map.put("isPage", dto.isPage()); + map.put("pageNo", dto.getPageNo()); + map.put("pageSize", dto.getPageSize()); + map.put("OrgCode", dto.getOrgCode()); + map.put("StartTime", dto.getStartTime()); + map.put("EndTime", dto.getEndTime()); + map.put("PatientId", patientId); + map.put("PatentTypeCode", dto.getPatentTypeCode()); + return Func.toJson(map); + } + + private String organizationQuerySdRyLisReportUrl(String reportQueryLisUrl) { + return reportQueryLisUrl + "/query?uuid=" + IdUtil.standardUUID() + + "&action=" + sdRyReportQueryConfig.getReportQueryLisAction() + + "&accessKey=" + sdRyReportQueryConfig.getReportQueryLisAccessKey() + + "&creationTime=" + Func.format(new Date(), DateUtil.PATTERN_DATETIME_MINI); + + } + + private String organizationQuerySdRyLisReportParam(SdJxReportDto dto) { + String patientId = dto.getPatientId(); + if("1".equals(dto.getPatentTypeCode())){ + patientId="m"+patientId; + } + if("3".equals(dto.getPatentTypeCode())){ + patientId="z"+patientId; + } + HashMap map = new HashMap<>(7); + map.put("isPage", dto.isPage()); + map.put("pageNo", dto.getPageNo()); + map.put("pageSize", dto.getPageSize()); + map.put("OrgCode", dto.getOrgCode()); + map.put("StartTime", dto.getStartTime()); + map.put("EndTime", dto.getEndTime()); + map.put("PatientId", patientId); + map.put("PatentTypeCode", dto.getPatentTypeCode()); + return Func.toJson(map); + } + + + + private String getPdfReportBase64InputString(String examNo, String reportNo, SdPacsServerConfig config) { return "\n" + "\n" + @@ -205,4 +305,14 @@ public class ShunDePeopleServiceImpl implements ShunDePeopleService { "\t\n" + "\n"; } + + + private String sendPost(String url, String body) { + HttpRequest post = HttpUtil.createPost(url); + post.timeout(60 * 1000); + post.header("Content-Type", "application/json; charset=utf-8"); + post.body(body); + HttpResponse response = post.execute(); + return response.body(); + } } diff --git a/src/main/java/com/docus/server/report/config/ZdAssortConfig.java b/src/main/java/com/docus/server/report/config/ZdAssortConfig.java new file mode 100644 index 0000000..a181465 --- /dev/null +++ b/src/main/java/com/docus/server/report/config/ZdAssortConfig.java @@ -0,0 +1,26 @@ +package com.docus.server.report.config; + +import com.alibaba.fastjson.JSONObject; +import com.docus.server.report.util.TableJsonRead; + +public class ZdAssortConfig { + /** + * 获取配置文件中类型对应的分类id + * @param type 类型 + * @return 分类id + */ + public static String getZdAssortId(String type){ + TableJsonRead jsonRead = new TableJsonRead(); + JSONObject tableTypeJson = jsonRead.Read("data-config", "js-table-type.json", JSONObject.class); + return tableTypeJson.getString(type); + } + + /** + * 获取配置文件中默认其他的分类id + * @return 分类id + */ + public static String getOtherAssortId(){ + return getZdAssortId("other"); + } + +} diff --git a/src/main/java/com/docus/server/report/controller/ReportDownController.java b/src/main/java/com/docus/server/report/controller/ReportDownController.java index bbcd4cc..1ceca15 100644 --- a/src/main/java/com/docus/server/report/controller/ReportDownController.java +++ b/src/main/java/com/docus/server/report/controller/ReportDownController.java @@ -109,19 +109,7 @@ public class ReportDownController { } - @ApiOperation(value = "report lis job 测试", hidden = true) - @PostMapping("/lisreportJobTest") - public CommonResult LisreportJobTest() { - reportJob.sdRyLisReportQueryJob(); - return CommonResult.success("成功"); - } - @ApiOperation(value = "report inspect job 测试", hidden = true) - @PostMapping("/inspectReportJobTest") - public CommonResult inspectReportJobTest() { - reportJob.sdRyInspectReportQueryJob(); - return CommonResult.success("成功"); - } @ApiOperation(value = "inspect检查报告测试地址", hidden = true) diff --git a/src/main/java/com/docus/server/report/job/ReportJob.java b/src/main/java/com/docus/server/report/job/ReportJob.java index bd8779f..ec6a653 100644 --- a/src/main/java/com/docus/server/report/job/ReportJob.java +++ b/src/main/java/com/docus/server/report/job/ReportJob.java @@ -1,10 +1,6 @@ package com.docus.server.report.job; -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpResponse; -import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONObject; -import com.docus.core.util.DateUtil; import com.docus.core.util.Func; import com.docus.infrastructure.core.exception.BaseException; import com.docus.infrastructure.redis.service.IdService; @@ -14,26 +10,32 @@ import com.docus.server.report.api.ShunDePeopleService; import com.docus.server.report.api.TaskDistributeService; import com.docus.server.report.api.dto.ReportDownTwoDto; import com.docus.server.report.api.dto.ReportDto; +import com.docus.server.report.api.dto.SdJxReportDto; import com.docus.server.report.config.SdRyReportQueryConfig; +import com.docus.server.report.config.ZdAssortConfig; import com.docus.server.report.entity.AfJobTime; import com.docus.server.report.entity.AfReportRecord; import com.docus.server.report.mapper.AfJobTimeMapper; import com.docus.server.report.mapper.AfReportRecordMapper; import com.docus.server.report.service.ReportService; -import com.docus.server.report.util.IdUtil; +import com.docus.server.report.util.XmlUtil; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import org.w3c.dom.Node; import javax.annotation.Resource; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.ZoneId; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; import java.util.stream.Collectors; /** @@ -109,89 +111,6 @@ public class ReportJob { } - /** - * Lis 检验报告查询 更换了无视图消费 {@link com.docus.server.report.job.ReportJob#sdRyLisCollectJob } - */ - @XxlJob("SdRyLisReportQueryJob") - @Deprecated - public void sdRyLisReportQueryJob() { - // 顺德人医 Lis 检验报告查询 - final String jobType = "SdRyLisReport"; - LocalDateTime now = LocalDateTime.now(); - // 等待基础数据入库时间 - now = now.plusMinutes(-10); - log.info("LIS检验报告报告查询 任务开始了"); - // 定义查基础数据 根据基础数据的创建时间 - AfJobTime afJobTime = getJobTimeByJobType(jobType); - String queryBasicStartDate = afJobTime.getUpdateTime(); - String queryBasicEndDate = DateUtil.formatDateTime(now); - // 查询基础数据定义 分页 - int offset = 0; - int pageSize = 50; - boolean loopCondition = true; - try { - do { - List basicList = tBasicMapper.selectBasicListByCreateOrUpdateTime(queryBasicStartDate, queryBasicEndDate, offset, pageSize); - if (Func.isEmpty(basicList)) { - break; - } - if (basicList.size() < pageSize) { - loopCondition = false; - } - queryLisReport(basicList); - - offset += pageSize; - } while (loopCondition); - } catch (Exception ex) { - log.error("LIS检验报告报告查询 出错啦!", ex); - } - - afJobTime.setUpdateTime(DateUtil.formatDateTime(now)); - refreshTime(afJobTime); - log.info("LIS检验报告报告查询 任务结束了,本次查询出院时间段 {} - {}", "", ""); - } - - /** - * 检查报告查询,更换了无视图消费 {@link com.docus.server.report.job.ReportJob#SdRyInspectCollectJob } - */ - @XxlJob("SdRyInspectReportQueryJob") - @Deprecated - public void sdRyInspectReportQueryJob() { - // 顺德人医 检查报告查询 - final String jobType = "SdRyInspectReport"; - LocalDateTime now = LocalDateTime.now(); - // 等待基础数据入库时间 - now = now.plusMinutes(-10); - log.info("检查报告报告查询 任务开始了"); - // 定义查基础数据 更新时间 开始结束 - AfJobTime afJobTime = getJobTimeByJobType(jobType); - String queryBasicStartDate = afJobTime.getUpdateTime(); - String queryBasicEndDate = DateUtil.formatDateTime(now); - // 查询基础数据定义 分页 - int offset = 0; - int pageSize = 50; - boolean loopCondition = true; - try { - do { - List basicList = tBasicMapper.selectBasicListByCreateOrUpdateTime(queryBasicStartDate, queryBasicEndDate, offset, pageSize); - if (Func.isEmpty(basicList)) { - break; - } - if (basicList.size() < pageSize) { - loopCondition = false; - } - queryInspectReport(basicList); - offset += pageSize; - } while (loopCondition); - } catch (Exception ex) { - log.error("检查报告报告查询 出错啦!", ex); - } - - afJobTime.setUpdateTime(DateUtil.formatDateTime(now)); - refreshTime(afJobTime); - log.info("检查报告报告查询 任务结束了,本次查询出院时间段 {} - {}", "", ""); - } - public List collectLisReport(TBasic tBasic) { List reportDtoList = getLisReportList(tBasic); if (reportDtoList.isEmpty()) { @@ -209,7 +128,6 @@ public class ReportJob { } - public void queryLisReport(List basicList) { for (TBasic tBasic : basicList) { List reportDtoList = getLisReportList(tBasic); @@ -236,8 +154,6 @@ public class ReportJob { } } - private static Lock inspectReportLock = new ReentrantLock(); - private List getInspectReportList(TBasic tBasic) { // 根据基础信息查顺德报告业务系统索引,查 交叉索引 List sdRyReportPatientIds = getSdRyReportPatientIds(tBasic.getPatientId()); @@ -248,33 +164,54 @@ public class ReportJob { List reportDtoList = new ArrayList<>(); // 根据交叉索引查询报告 for (String sdRyReportPatientId : sdRyReportPatientIds) { - List reportDtoList2 = getInspectReportDtoListBySdRyReportPatientId(sdRyReportPatientId, tBasic); + List reportDtoList2 = getInspectReportBySdRyJxId(sdRyReportPatientId, tBasic); reportDtoList.addAll(reportDtoList2); } return reportDtoList; } - private List getInspectReportDtoListBySdRyReportPatientId(String sdRyReportPatientId, TBasic tBasic) { + private List getInspectReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) { + List list = new ArrayList<>(); + List mzInspectReportBySdRyJxId = getMzInspectReportBySdRyJxId(sdRyReportPatientId, tBasic); + List zyInspectReportBySdRyJxId = getZyInspectReportBySdRyJxId(sdRyReportPatientId, tBasic); + list.addAll(mzInspectReportBySdRyJxId); + list.addAll(zyInspectReportBySdRyJxId); + return list; + } + + private List getMzInspectReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) { try { List reportDtos = new ArrayList<>(); int pageNum = 1; final int pageSize = 5; boolean loopCondition = true; do { - String requestParam = organizationQuerySdRyInspectReportParam(sdRyReportPatientId, tBasic, pageNum, pageSize); - String url = organizationQuerySdRyInspectReportUrl(sdRyReportQueryConfig.getReportQueryInspectUrl()); - log.info("查询检查报告请求地址:{} ,请求body参数:{}", url, requestParam); - String respBody = ""; - inspectReportLock.lock(); - try { - respBody = this.sendPost(url, requestParam); - TimeUnit.MILLISECONDS.sleep(sdRyReportQueryConfig.getReportQueryInspectInterval()); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } finally { - inspectReportLock.unlock(); + Date admissDate = tBasic.getAdmissDate(); + Date disDate = tBasic.getDisDate(); + if (admissDate == null || disDate == null) { + throw new BaseException("patientId:" + tBasic.getPatientId() + "的入院时间为空"); } - log.info("查询检查报告请求成功,响应参数:{}", respBody); + ZoneId zoneId = ZoneId.systemDefault(); + Instant adminssDateInstant = admissDate.toInstant(); + Instant disDateInstant = disDate.toInstant(); + // 开始时间去入院前三天 + LocalDate admissLocalDate = adminssDateInstant.atZone(zoneId).toLocalDate(); + LocalDate startTimeLocalDate = admissLocalDate.plusDays(-3); + LocalDate disLocalDate = disDateInstant.atZone(zoneId).toLocalDate(); + String startTime = startTimeLocalDate.toString() + " 00:00:00"; + String endTime = disLocalDate.toString() + " 23:59:59"; + + SdJxReportDto sdJxReportDto = new SdJxReportDto(); + sdJxReportDto.setPage(true); + sdJxReportDto.setPageNo(pageNum); + sdJxReportDto.setPageSize(pageSize); + sdJxReportDto.setPatientId(sdRyReportPatientId); + sdJxReportDto.setStartTime(startTime); + sdJxReportDto.setEndTime(endTime); + sdJxReportDto.setPatentTypeCode("1"); + sdJxReportDto.setOrgCode("4560886379"); + String respBody = shunDePeopleService.getInspectReportByJxId(sdJxReportDto); + List reportDtoList = parseQuerySdRyInspectReport(respBody, tBasic); if (reportDtoList.isEmpty()) { break; @@ -287,48 +224,59 @@ public class ReportJob { } while (loopCondition); return reportDtos; } catch (Exception ex) { - log.error("查询检查报告出错啦!", ex); + log.error("查询门诊检查报告出错啦!", ex); return new ArrayList<>(); } } - private String organizationQuerySdRyInspectReportUrl(String reportQueryLisUrl) { - return reportQueryLisUrl + "/query?uuid=" + IdUtil.standardUUID() + - "&action=" + sdRyReportQueryConfig.getReportQueryInspectAction() + - "&accessKey=" + sdRyReportQueryConfig.getReportQueryInspectAccessKey() - + "&creationTime=" + Func.format(new Date(), DateUtil.PATTERN_DATETIME_MINI); - - } + private List getZyInspectReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) { + try { + List reportDtos = new ArrayList<>(); + int pageNum = 1; + final int pageSize = 5; + boolean loopCondition = true; + do { + Date admissDate = tBasic.getAdmissDate(); + Date disDate = tBasic.getDisDate(); + if (admissDate == null || disDate == null) { + throw new BaseException("patientId:" + tBasic.getPatientId() + "的入院时间为空"); + } + ZoneId zoneId = ZoneId.systemDefault(); + Instant adminssDateInstant = admissDate.toInstant(); + Instant disDateInstant = disDate.toInstant(); + // 开始时间去入院前三天 + LocalDate admissLocalDate = adminssDateInstant.atZone(zoneId).toLocalDate(); + LocalDate startTimeLocalDate = admissLocalDate.plusDays(-3); + LocalDate disLocalDate = disDateInstant.atZone(zoneId).toLocalDate(); + String startTime = startTimeLocalDate.toString() + " 00:00:00"; + String endTime = disLocalDate.toString() + " 23:59:59"; + + SdJxReportDto sdJxReportDto = new SdJxReportDto(); + sdJxReportDto.setPage(true); + sdJxReportDto.setPageNo(pageNum); + sdJxReportDto.setPageSize(pageSize); + sdJxReportDto.setPatientId(sdRyReportPatientId); + sdJxReportDto.setStartTime(startTime); + sdJxReportDto.setEndTime(endTime); + sdJxReportDto.setPatentTypeCode("3"); + sdJxReportDto.setOrgCode("4560886379"); + String respBody = shunDePeopleService.getInspectReportByJxId(sdJxReportDto); - private String organizationQuerySdRyInspectReportParam(String sdRyReportPatientId, TBasic tBasic, int pageNum, int pageSize) { - boolean isPage = true; - String orgCode = "4560886379"; - Date admissDate = tBasic.getAdmissDate(); - Date disDate = tBasic.getDisDate(); - if (admissDate == null || disDate == null) { - throw new BaseException("patientId:" + tBasic.getPatientId() + "的入院时间为空"); + List reportDtoList = parseQuerySdRyInspectReport(respBody, tBasic); + if (reportDtoList.isEmpty()) { + break; + } + if (reportDtoList.size() < pageSize) { + loopCondition = false; + } + reportDtos.addAll(reportDtoList); + pageNum++; + } while (loopCondition); + return reportDtos; + } catch (Exception ex) { + log.error("查询住院检查报告出错啦!", ex); + return new ArrayList<>(); } - ZoneId zoneId = ZoneId.systemDefault(); - Instant adminssDateInstant = admissDate.toInstant(); - Instant disDateInstant = disDate.toInstant(); - sdRyReportPatientId = "m" + sdRyReportPatientId; - // 开始时间去入院前三天 - LocalDate admissLocalDate = adminssDateInstant.atZone(zoneId).toLocalDate(); - LocalDate startTimeLocalDate = admissLocalDate.plusDays(-3); - LocalDate disLocalDate = disDateInstant.atZone(zoneId).toLocalDate(); - String startTime = startTimeLocalDate.toString() + " 00:00:00"; - String endTime = disLocalDate.toString() + " 23:59:59"; - - HashMap map = new HashMap<>(7); - map.put("isPage", isPage); - map.put("pageNo", pageNum); - map.put("pageSize", pageSize); - map.put("OrgCode", orgCode); - map.put("StartTime", startTime); - map.put("EndTime", endTime); - map.put("PatientId", sdRyReportPatientId); - map.put("PatentTypeCode", "1"); - return Func.toJson(map); } private List parseQuerySdRyInspectReport(String respBody, TBasic tBasic) { @@ -367,8 +315,19 @@ public class ReportJob { // 确定报告唯一 报告单号+申请单号 reportDto.setSerialnum(examReportSn + requestSn); reportDto.setFileTitle(reportName); - reportDto.setDownUrl(pdfUrl); - reportDto.setAssortId(sdRyReportQueryConfig.getReportQueryInspectAssortId()); + // 检查报告需要从Pacs接口获取base64 + String[] split = examReportSn.split("_"); + String fromPacs = shunDePeopleService.getBase64PdfFromPacs(split[0], split[1]); + // 从pacs打印出来 + String base64 = parsePacsGetBase64(fromPacs); + if (Func.isBlank(base64)) { + continue; + } + String url = saveBase64(base64); + reportDto.setDownUrl(url); + reportDto.setDowntype(5); + // 根据系统来分类 + reportDto.setAssortId(ZdAssortConfig.getZdAssortId(updateBy)); reportDto.setSysFlag(updateBy); reportDto.setFileSource("1"); reportDto.setFilestoragetype("1"); @@ -383,34 +342,51 @@ public class ReportJob { } } - private String sendPost(String url, String body) { - HttpRequest post = HttpUtil.createPost(url); - post.timeout(60 * 1000); - post.header("Content-Type", "application/json; charset=utf-8"); - post.body(body); - HttpResponse response = post.execute(); - return response.body(); - } - /** - * 查询job需要的开始时间 - * - * @param jobType job类型 - * @return job需要的开始时间,未查到 默认 1801-01-01 00:00:00 - */ - private AfJobTime getJobTimeByJobType(String jobType) { - AfJobTime afJobTime = afJobTimeMapper.getAfJobTimeByJobType(jobType); - // 定义查基础数据 入院时间 开始结束 - String startTime = "1801-01-01 00:00:00"; - if (afJobTime == null) { - afJobTime = new AfJobTime(); - afJobTime.setJobType(jobType); - afJobTime.setUpdateTime(startTime); + private String saveBase64(String base64) throws IOException { + String dir; + try { + File current = new File("."); + String canonicalPath = current.getCanonicalPath(); + String dirPath = canonicalPath + File.separator + "base64"; + File dirFile = new File(dirPath); + if (!dirFile.exists()) { + dirFile.mkdirs(); + } + dir = dirPath; + } catch (Exception e) { + String temp = "C:\\docus\\base64"; + File file1 = new File(temp); + if (!file1.exists()) { + file1.mkdirs(); + } + dir = temp; } - if (Func.isBlank(afJobTime.getUpdateTime())) { - afJobTime.setUpdateTime(startTime); + String base64File = dir + File.separator + idService.getDateSeq() + ".txt"; + try (FileWriter fileWriter = new FileWriter(base64File); + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) { + bufferedWriter.write(base64); + bufferedWriter.flush(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + return null; + } + return base64File; + } + + private static String parsePacsGetBase64(String xml) { + try { + XmlUtil xmlUtil = XmlUtil.of(xml); + Node codeNode = xmlUtil.getNode("/Result/Code"); + if ("0".equals(codeNode.getTextContent())) { + Node base64Node = xmlUtil.getNode("/Result/Base64"); + return base64Node.getTextContent(); + } + } catch (Exception ex) { + log.error("解析pacs返回的base64信息失败:" + ex.getMessage(), ex); + return null; } - return afJobTime; + return null; } @@ -424,41 +400,111 @@ public class ReportJob { List reportDtoList = new ArrayList<>(); // 根据交叉索引查询报告 for (String sdRyReportPatientId : sdRyReportPatientIds) { - List reportDtoList2 = getLisReportDtoListBySdRyReportPatientId(sdRyReportPatientId, tBasic); + List reportDtoList2 = getLisReportBySdRyJxId(sdRyReportPatientId, tBasic); reportDtoList.addAll(reportDtoList2); } return reportDtoList; } - private static Lock lisReportLock = new ReentrantLock(); - private List getLisReportDtoListBySdRyReportPatientId(String sdRyReportPatientId, TBasic tBasic) { + private List getLisReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) { + List list = new ArrayList<>(); + List zyLisReportBySdRyJxId = getZyLisReportBySdRyJxId(sdRyReportPatientId, tBasic); + List mzLisReportBySdRyJxId = getMzLisReportBySdRyJxId(sdRyReportPatientId, tBasic); + list.addAll(mzLisReportBySdRyJxId); + list.addAll(zyLisReportBySdRyJxId); + return list; + } + + /** + * 获取住院的检验报告 + */ + private List getZyLisReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) { try { List reportDtos = new ArrayList<>(); int pageNum = 1; final int pageSize = 5; boolean loopCondition = true; do { - String requestParam = organizationQuerySdRyLisReportParam(sdRyReportPatientId, tBasic, pageNum, pageSize); - String url = organizationQuerySdRyLisReportUrl(sdRyReportQueryConfig.getReportQueryLisUrl()); - log.info("查询Lis报告请求地址:{} ,请求body参数:{}", url, requestParam); - HttpRequest post = HttpUtil.createPost(url); - post.timeout(60 * 1000); - post.header("Content-Type", "application/json; charset=utf-8"); - post.body(requestParam); - HttpResponse response = post.execute(); - String respBody = ""; - lisReportLock.lock(); - try { - respBody = response.body(); - TimeUnit.MILLISECONDS.sleep(sdRyReportQueryConfig.getReportQueryLisInterval()); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } finally { - lisReportLock.unlock(); + Date admissDate = tBasic.getAdmissDate(); + Date disDate = tBasic.getDisDate(); + if (admissDate == null || disDate == null) { + throw new BaseException("patientId:" + tBasic.getPatientId() + "的入院时间为空"); + } + ZoneId zoneId = ZoneId.systemDefault(); + Instant adminssDateInstant = admissDate.toInstant(); + Instant disDateInstant = disDate.toInstant(); + // 开始时间去入院前三天 + LocalDate admissLocalDate = adminssDateInstant.atZone(zoneId).toLocalDate(); + LocalDate startTimeLocalDate = admissLocalDate.plusDays(-3); + LocalDate disLocalDate = disDateInstant.atZone(zoneId).toLocalDate(); + String startTime = startTimeLocalDate.toString() + " 00:00:00"; + String endTime = disLocalDate.toString() + " 23:59:59"; + + SdJxReportDto sdJxReportDto = new SdJxReportDto(); + sdJxReportDto.setPage(true); + sdJxReportDto.setPageNo(pageNum); + sdJxReportDto.setPageSize(pageSize); + sdJxReportDto.setPatientId(sdRyReportPatientId); + sdJxReportDto.setStartTime(startTime); + sdJxReportDto.setEndTime(endTime); + sdJxReportDto.setPatentTypeCode("3"); + sdJxReportDto.setOrgCode("4560886379"); + + String respBody = shunDePeopleService.getLisReportByJxId(sdJxReportDto); + List reportDtoList = parseQuerySdRyLisReport(respBody, tBasic); + if (reportDtoList.isEmpty()) { + break; + } + if (reportDtoList.size() < pageSize) { + loopCondition = false; } + reportDtos.addAll(reportDtoList); + pageNum++; + } while (loopCondition); + return reportDtos; + } catch (Exception ex) { + log.error("查询Lis报告出错啦!", ex); + return new ArrayList<>(); + } + } - log.info("查询Lis报告请求成功,响应参数:{}", respBody); + /** + * 获取门诊的检验报告 + */ + private List getMzLisReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) { + try { + List reportDtos = new ArrayList<>(); + int pageNum = 1; + final int pageSize = 5; + boolean loopCondition = true; + do { + Date admissDate = tBasic.getAdmissDate(); + Date disDate = tBasic.getDisDate(); + if (admissDate == null || disDate == null) { + throw new BaseException("patientId:" + tBasic.getPatientId() + "的入院时间为空"); + } + ZoneId zoneId = ZoneId.systemDefault(); + Instant adminssDateInstant = admissDate.toInstant(); + Instant disDateInstant = disDate.toInstant(); + // 开始时间去入院前三天 + LocalDate admissLocalDate = adminssDateInstant.atZone(zoneId).toLocalDate(); + LocalDate startTimeLocalDate = admissLocalDate.plusDays(-3); + LocalDate disLocalDate = disDateInstant.atZone(zoneId).toLocalDate(); + String startTime = startTimeLocalDate.toString() + " 00:00:00"; + String endTime = disLocalDate.toString() + " 23:59:59"; + + SdJxReportDto sdJxReportDto = new SdJxReportDto(); + sdJxReportDto.setPage(true); + sdJxReportDto.setPageNo(pageNum); + sdJxReportDto.setPageSize(pageSize); + sdJxReportDto.setPatientId(sdRyReportPatientId); + sdJxReportDto.setStartTime(startTime); + sdJxReportDto.setEndTime(endTime); + sdJxReportDto.setPatentTypeCode("1"); + sdJxReportDto.setOrgCode("4560886379"); + + String respBody = shunDePeopleService.getLisReportByJxId(sdJxReportDto); List reportDtoList = parseQuerySdRyLisReport(respBody, tBasic); if (reportDtoList.isEmpty()) { break; @@ -513,7 +559,8 @@ public class ReportJob { reportDto.setSerialnum(labReportSn + requestSn); reportDto.setFileTitle(reportTypeName); reportDto.setDownUrl(pdfUrl); - reportDto.setAssortId(sdRyReportQueryConfig.getReportQueryLisAssortId()); + // 根据系统来分类 + reportDto.setAssortId(ZdAssortConfig.getZdAssortId(updateBy)); reportDto.setSysFlag(updateBy); reportDto.setFileSource("1"); reportDto.setFilestoragetype("1"); @@ -528,46 +575,6 @@ public class ReportJob { } } - private String organizationQuerySdRyLisReportUrl(String reportQueryLisUrl) { - return reportQueryLisUrl + "/query?uuid=" + IdUtil.standardUUID() + - "&action=" + sdRyReportQueryConfig.getReportQueryLisAction() + - "&accessKey=" + sdRyReportQueryConfig.getReportQueryLisAccessKey() - + "&creationTime=" + Func.format(new Date(), DateUtil.PATTERN_DATETIME_MINI); - - } - - private String organizationQuerySdRyLisReportParam(String sdRyReportPatientId, TBasic tBasic, int pageNum, int pageSize) { - boolean isPage = true; - String orgCode = "4560886379"; - Date admissDate = tBasic.getAdmissDate(); - Date disDate = tBasic.getDisDate(); - if (admissDate == null || disDate == null) { - throw new BaseException("patientId:" + tBasic.getPatientId() + "的入院时间为空"); - } - ZoneId zoneId = ZoneId.systemDefault(); - Instant adminssDateInstant = admissDate.toInstant(); - Instant disDateInstant = disDate.toInstant(); - sdRyReportPatientId = "m" + sdRyReportPatientId; - // 开始时间去入院前三天 - LocalDate admissLocalDate = adminssDateInstant.atZone(zoneId).toLocalDate(); - LocalDate startTimeLocalDate = admissLocalDate.plusDays(-3); - LocalDate disLocalDate = disDateInstant.atZone(zoneId).toLocalDate(); - String startTime = startTimeLocalDate.toString() + " 00:00:00"; - String endTime = disLocalDate.toString() + " 23:59:59"; - - HashMap map = new HashMap<>(7); - map.put("isPage", isPage); - map.put("pageNo", pageNum); - map.put("pageSize", pageSize); - map.put("OrgCode", orgCode); - map.put("StartTime", startTime); - map.put("EndTime", endTime); - map.put("PatientId", sdRyReportPatientId); - map.put("PatentTypeCode", "1"); - return Func.toJson(map); - } - - /** * 根据归档病案主键查询报告交叉索引 @@ -582,7 +589,7 @@ public class ReportJob { log.warn("归档系统 patientId:{} 未关联到第三方索引", patientId); return new ArrayList<>(); } - return shunDePeopleService.getSdRyReportPatientIds(sDryIndex); + return shunDePeopleService.getSdRyReportJxIds(sDryIndex); } catch (Exception ex) { log.error(ex.getMessage(), ex); return new ArrayList<>(); @@ -590,8 +597,6 @@ public class ReportJob { } - - private void refreshTime(AfJobTime afJobTime) { if (afJobTime.getId() == null) { afJobTime.setId(idService.getDateSeq()); diff --git a/src/main/java/com/docus/server/report/webservice/impl/SdryReportServerImpl.java b/src/main/java/com/docus/server/report/webservice/impl/SdryReportServerImpl.java index f3e0ca2..fdb6306 100644 --- a/src/main/java/com/docus/server/report/webservice/impl/SdryReportServerImpl.java +++ b/src/main/java/com/docus/server/report/webservice/impl/SdryReportServerImpl.java @@ -1,10 +1,10 @@ package com.docus.server.report.webservice.impl; -import com.alibaba.fastjson.JSONObject; import com.docus.core.util.DateUtil; import com.docus.core.util.Func; import com.docus.infrastructure.core.exception.BaseException; import com.docus.server.report.api.dto.ReportDto; +import com.docus.server.report.config.ZdAssortConfig; import com.docus.server.report.service.ReportService; import com.docus.server.report.util.IdUtil; import com.docus.server.report.util.JSXMLResult; @@ -60,7 +60,6 @@ public class SdryReportServerImpl implements IReportServer { */ public ReportDto getReportDtoByJSXML(XmlUtil xmlUtil) { TableJsonRead jsonRead = new TableJsonRead(); - JSONObject tableTypeJson = jsonRead.Read("data-config", "js-table-type.json", JSONObject.class); String jsReportConfigXml = jsonRead.ReadContent("data-config", "js-report-config.xml"); XmlUtil configXmlUtil = XmlUtil.of(jsReportConfigXml); @@ -109,10 +108,10 @@ public class SdryReportServerImpl implements IReportServer { if (Func.isEmpty(assortIdValueNode)) { assortId = assortIdValueNode.getNodeValue(); } else { - assortId = tableTypeJson.getString(tableType); + assortId= ZdAssortConfig.getZdAssortId(tableType); } if (Func.isBlank(assortId)) { - assortId = tableTypeJson.getString("other"); + assortId = ZdAssortConfig.getOtherAssortId(); } } else { Node assortIdNode = xmlUtil.getNode(assortIdXpath);