|
|
|
@ -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<TBasic> 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<TBasic> 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<ReportDto> collectLisReport(TBasic tBasic) {
|
|
|
|
|
List<ReportDto> reportDtoList = getLisReportList(tBasic);
|
|
|
|
|
if (reportDtoList.isEmpty()) {
|
|
|
|
@ -209,7 +128,6 @@ public class ReportJob {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void queryLisReport(List<TBasic> basicList) {
|
|
|
|
|
for (TBasic tBasic : basicList) {
|
|
|
|
|
List<ReportDto> reportDtoList = getLisReportList(tBasic);
|
|
|
|
@ -236,8 +154,6 @@ public class ReportJob {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Lock inspectReportLock = new ReentrantLock();
|
|
|
|
|
|
|
|
|
|
private List<ReportDto> getInspectReportList(TBasic tBasic) {
|
|
|
|
|
// 根据基础信息查顺德报告业务系统索引,查 交叉索引
|
|
|
|
|
List<String> sdRyReportPatientIds = getSdRyReportPatientIds(tBasic.getPatientId());
|
|
|
|
@ -248,33 +164,54 @@ public class ReportJob {
|
|
|
|
|
List<ReportDto> reportDtoList = new ArrayList<>();
|
|
|
|
|
// 根据交叉索引查询报告
|
|
|
|
|
for (String sdRyReportPatientId : sdRyReportPatientIds) {
|
|
|
|
|
List<ReportDto> reportDtoList2 = getInspectReportDtoListBySdRyReportPatientId(sdRyReportPatientId, tBasic);
|
|
|
|
|
List<ReportDto> reportDtoList2 = getInspectReportBySdRyJxId(sdRyReportPatientId, tBasic);
|
|
|
|
|
reportDtoList.addAll(reportDtoList2);
|
|
|
|
|
}
|
|
|
|
|
return reportDtoList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<ReportDto> getInspectReportDtoListBySdRyReportPatientId(String sdRyReportPatientId, TBasic tBasic) {
|
|
|
|
|
private List<ReportDto> getInspectReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) {
|
|
|
|
|
List<ReportDto> list = new ArrayList<>();
|
|
|
|
|
List<ReportDto> mzInspectReportBySdRyJxId = getMzInspectReportBySdRyJxId(sdRyReportPatientId, tBasic);
|
|
|
|
|
List<ReportDto> zyInspectReportBySdRyJxId = getZyInspectReportBySdRyJxId(sdRyReportPatientId, tBasic);
|
|
|
|
|
list.addAll(mzInspectReportBySdRyJxId);
|
|
|
|
|
list.addAll(zyInspectReportBySdRyJxId);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<ReportDto> getMzInspectReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) {
|
|
|
|
|
try {
|
|
|
|
|
List<ReportDto> 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<ReportDto> 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<ReportDto> getZyInspectReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) {
|
|
|
|
|
try {
|
|
|
|
|
List<ReportDto> 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<ReportDto> 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<Object, Object> 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<ReportDto> 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<ReportDto> reportDtoList = new ArrayList<>();
|
|
|
|
|
// 根据交叉索引查询报告
|
|
|
|
|
for (String sdRyReportPatientId : sdRyReportPatientIds) {
|
|
|
|
|
List<ReportDto> reportDtoList2 = getLisReportDtoListBySdRyReportPatientId(sdRyReportPatientId, tBasic);
|
|
|
|
|
List<ReportDto> reportDtoList2 = getLisReportBySdRyJxId(sdRyReportPatientId, tBasic);
|
|
|
|
|
reportDtoList.addAll(reportDtoList2);
|
|
|
|
|
}
|
|
|
|
|
return reportDtoList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Lock lisReportLock = new ReentrantLock();
|
|
|
|
|
|
|
|
|
|
private List<ReportDto> getLisReportDtoListBySdRyReportPatientId(String sdRyReportPatientId, TBasic tBasic) {
|
|
|
|
|
private List<ReportDto> getLisReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) {
|
|
|
|
|
List<ReportDto> list = new ArrayList<>();
|
|
|
|
|
List<ReportDto> zyLisReportBySdRyJxId = getZyLisReportBySdRyJxId(sdRyReportPatientId, tBasic);
|
|
|
|
|
List<ReportDto> mzLisReportBySdRyJxId = getMzLisReportBySdRyJxId(sdRyReportPatientId, tBasic);
|
|
|
|
|
list.addAll(mzLisReportBySdRyJxId);
|
|
|
|
|
list.addAll(zyLisReportBySdRyJxId);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取住院的检验报告
|
|
|
|
|
*/
|
|
|
|
|
private List<ReportDto> getZyLisReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) {
|
|
|
|
|
try {
|
|
|
|
|
List<ReportDto> 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<ReportDto> 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<ReportDto> getMzLisReportBySdRyJxId(String sdRyReportPatientId, TBasic tBasic) {
|
|
|
|
|
try {
|
|
|
|
|
List<ReportDto> 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<ReportDto> 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<Object, Object> 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());
|
|
|
|
|