|
|
package com.docus.bgts.handler;
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.docus.bgts.dto.SystemCollectConfig;
|
|
|
import com.docus.bgts.entity.*;
|
|
|
import com.docus.bgts.enums.Codes;
|
|
|
import com.docus.bgts.facade.IAfCollectTaskService;
|
|
|
import com.docus.bgts.facade.IMrReportErrorService;
|
|
|
import com.docus.bgts.mapper.TBasicExtendMapper;
|
|
|
import com.docus.bgts.mapper.TBasicMapper;
|
|
|
import com.docus.bgts.mapper.TScanAssortMapper;
|
|
|
import com.docus.bgts.utils.FileUtils;
|
|
|
import com.docus.bgts.utils.HttpUtils;
|
|
|
import com.docus.bgts.utils.ResultUtils;
|
|
|
import com.docus.bgts.utils.XmlUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentException;
|
|
|
import org.dom4j.Element;
|
|
|
import org.dom4j.io.SAXReader;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import sun.misc.BASE64Decoder;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.jws.WebService;
|
|
|
import java.io.*;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
@WebService
|
|
|
public class TBasicWebService implements ITBasicWebService {
|
|
|
|
|
|
@Autowired
|
|
|
IAfCollectTaskService afCollectTaskService;
|
|
|
|
|
|
@Autowired
|
|
|
IMrReportErrorService mrReportErrorService;
|
|
|
|
|
|
@Autowired
|
|
|
TBasicMapper tBasicMapper;
|
|
|
|
|
|
@Autowired
|
|
|
TBasicExtendMapper tBasicExtendMapper;
|
|
|
|
|
|
@Autowired
|
|
|
TScanAssortMapper tScanAssortMapper;
|
|
|
|
|
|
@Resource
|
|
|
private ThreadPoolExecutor threadPoolExecutor;
|
|
|
|
|
|
// private Object lock = new Object();
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
private Element getElementFromString(String s) {
|
|
|
SAXReader builder = new SAXReader();
|
|
|
Document doc = null;
|
|
|
Element element = null;
|
|
|
try {
|
|
|
doc = builder.read(new StringReader(s));
|
|
|
} catch (DocumentException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (doc != null) {
|
|
|
element = doc.getRootElement();
|
|
|
}
|
|
|
return element;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String pushSurveyReport(String xml) {
|
|
|
long l6 = System.currentTimeMillis();
|
|
|
try {
|
|
|
logger.info("报告推送入参:" + xml);
|
|
|
// 1、创建document对象
|
|
|
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + xml;
|
|
|
//解析XML
|
|
|
XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(xml.getBytes("UTF-8")));
|
|
|
//获取数据存在的节点节点
|
|
|
|
|
|
Element elementRoot = xmlUtils.getMsgElement();
|
|
|
//key
|
|
|
String serialnmnKey = String.valueOf(FileUtils.getJsonByName("serialnum"));
|
|
|
String filetitleKey = String.valueOf(FileUtils.getJsonByName("filetitle"));
|
|
|
String downurlKey = String.valueOf(FileUtils.getJsonByName("downurl"));
|
|
|
String nurseSubmitTime = String.valueOf(FileUtils.getJsonByName("nurseSubmitTime"));
|
|
|
String doctorSubmitTime = String.valueOf(FileUtils.getJsonByName("doctorSubmitTime"));
|
|
|
String examApplyDate = String.valueOf(FileUtils.getJsonByName("examApplyDate"));
|
|
|
String inPatientNo = String.valueOf(FileUtils.getJsonByName("inPatientNo"));
|
|
|
//电子病历排序时间
|
|
|
String sortingTimeKey = String.valueOf(FileUtils.getJsonByName("sortingTime"));
|
|
|
// 获取患者主索引号
|
|
|
String empId = String.valueOf(FileUtils.getJsonByName(Codes.EMP_ID.getMessage()));
|
|
|
//电子病历封存id
|
|
|
String seal = String.valueOf(FileUtils.getJsonByName("sealId"));
|
|
|
//提交人姓名
|
|
|
String submitName = String.valueOf(FileUtils.getJsonByName("submitName"));
|
|
|
|
|
|
//判断是否为撤销
|
|
|
String isJudge = String.valueOf(FileUtils.getJsonByName("isJudge"));
|
|
|
if (StringUtils.isBlank(isJudge) || isJudge.equals("0")) {
|
|
|
|
|
|
} else {
|
|
|
//获取撤回路径
|
|
|
List<String> judgeDirectory = (List<String>) FileUtils.getJsonByName("judgeDirectory");
|
|
|
Element current = xmlUtils.getElement(judgeDirectory);
|
|
|
//获取撤回标签
|
|
|
String judgeIndex = String.valueOf(FileUtils.getJsonByName("judgeIndex"));
|
|
|
Element judgeIndexElement = current.element(judgeIndex);
|
|
|
if (judgeIndexElement == null || StringUtils.isBlank(judgeIndexElement.getText()) || (!judgeIndexElement.getText().equals("1"))) {
|
|
|
logger.info("------新增/修改------");
|
|
|
} else if (judgeIndexElement.getText().equals("1")) {
|
|
|
logger.info("---------撤回--------");
|
|
|
CanlcelDto canlcelDto = new CanlcelDto();
|
|
|
String serialnum = String.valueOf(FileUtils.getJsonByName("serialnum"));
|
|
|
String serialnumElement = getElementText(elementRoot, serialnum.split(","));
|
|
|
canlcelDto.setSerialnum(serialnumElement);
|
|
|
//调用上传服务撤销功能
|
|
|
afCollectTaskService.invokeRepoalFile(canlcelDto);
|
|
|
logger.info("----------当前操作完成--------------");
|
|
|
return ResultUtils.success().asXML();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Map<String, Object> headMap = new HashMap<>();
|
|
|
headMap.put("Content-Type", "application/json");
|
|
|
ReportDownDto reportDownDto;
|
|
|
|
|
|
ReportDownScanFileDto reportDownScanFileDto;
|
|
|
ReportDownPatientDto reportDownPatientDto;
|
|
|
//临时资料存储
|
|
|
String serialnum;
|
|
|
String filetitle;
|
|
|
String downurl;
|
|
|
String sortingTime;
|
|
|
String assortid;
|
|
|
String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid"));
|
|
|
if (collectorid.equals("1")) {
|
|
|
assortid = String.valueOf(FileUtils.getJsonByName("assortid"));
|
|
|
} else {
|
|
|
assortid = getAssortid(elementRoot);
|
|
|
}
|
|
|
|
|
|
reportDownDto = new ReportDownDto();
|
|
|
reportDownDto.setCollectorid(collectorid);
|
|
|
reportDownDto.setAssortid(assortid);
|
|
|
//获取基本数据信息
|
|
|
List<ReportDownScanFileDto> reportDownDtoArr = new ArrayList<>();
|
|
|
reportDownPatientDto = new ReportDownPatientDto();
|
|
|
//获取jzh
|
|
|
String empIdText = getElementText(elementRoot, empId.split(","));
|
|
|
//获取提交人姓名
|
|
|
String submit = getElementText(elementRoot, submitName.split(","));
|
|
|
//获取封存id
|
|
|
String sealId = getElementTextCanBeEmpty(elementRoot, seal.split(","));
|
|
|
if (null != sealId && !"".equals(sealId)) {
|
|
|
reportDownPatientDto.setJzh(empIdText);
|
|
|
reportDownPatientDto.setSealId(sealId);
|
|
|
logger.info("封存患者jzh : " + empIdText);
|
|
|
sealCollect(sealId);
|
|
|
reportDownDto.setPatient(reportDownPatientDto);
|
|
|
List<Element> elementList = xmlUtils.getJsonByName(elementRoot);
|
|
|
doctorSubmitTime = getElementText(elementRoot, doctorSubmitTime.split(","));
|
|
|
for (Element element : elementList) {
|
|
|
filetitle = getElementText(element, filetitleKey.split(","));
|
|
|
downurl = getElementText(element, downurlKey.split(","));
|
|
|
//downurl = handleDownUrl(downurl);
|
|
|
//添加护理提交时间
|
|
|
if (collectorid.equals("1")) {
|
|
|
nurseSubmitTime = getElementText(element, nurseSubmitTime.split(","));
|
|
|
afCollectTaskService.updateNurseSubmitTime(reportDownDto, nurseSubmitTime,submit);
|
|
|
afCollectTaskService.insertNurseState(reportDownDto, nurseSubmitTime);
|
|
|
}
|
|
|
|
|
|
//获取电子病历排序时间
|
|
|
sortingTime = getElementTextCanBeEmpty(element, sortingTimeKey.split(","));
|
|
|
//获取采集流水号
|
|
|
serialnum = getElementText(element, serialnmnKey.split(","));
|
|
|
reportDownScanFileDto = new ReportDownScanFileDto();
|
|
|
reportDownScanFileDto.setDownurl(downurl);
|
|
|
reportDownScanFileDto.setFiletitle(filetitle);
|
|
|
reportDownScanFileDto.setSerialnum(serialnum);
|
|
|
reportDownScanFileDto.setSortdate(sortingTime);
|
|
|
reportDownScanFileDto.setFilesource(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource"))));
|
|
|
reportDownScanFileDto.setFilestoragetype(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype"))));
|
|
|
//判断是否为base64
|
|
|
if (reportDownScanFileDto.getDownurl().length() > 200) {
|
|
|
reportDownScanFileDto.setFiletype(2);
|
|
|
}
|
|
|
reportDownDtoArr.add(reportDownScanFileDto);
|
|
|
}
|
|
|
if (reportDownDtoArr.size() <= 0) {
|
|
|
throw new RuntimeException("不存在必要的基本信息");
|
|
|
} else {
|
|
|
reportDownDto.setScanfiles(reportDownDtoArr);
|
|
|
}
|
|
|
//插入医生提交时间
|
|
|
afCollectTaskService.updateDoctorSubmitTime(reportDownDto, doctorSubmitTime,submit);
|
|
|
//插入医生提交状态
|
|
|
afCollectTaskService.insertDoctorState(reportDownDto, doctorSubmitTime);
|
|
|
afCollectTaskService.insertSeal(reportDownDto);
|
|
|
|
|
|
|
|
|
String post = "";
|
|
|
logger.info("--------执行上传功能----------");
|
|
|
|
|
|
Map params = JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class);
|
|
|
if (reportDownDto.getScanfiles().get(0).getFiletype() == 1) {
|
|
|
logger.info("封存id--"+reportDownDto.getPatient().getSealId()+ ": 上传参数:" + params);
|
|
|
}
|
|
|
long l = System.currentTimeMillis();
|
|
|
post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.SEALUPLOAD.getMessage())), headMap, params);
|
|
|
long l1 = System.currentTimeMillis();
|
|
|
logger.info("封存id--"+reportDownDto.getPatient().getSealId()+"请求下载耗时----------" + (l1 - l));
|
|
|
|
|
|
if (StringUtils.isBlank(post)) {
|
|
|
logger.info("封存id--"+reportDownDto.getPatient().getSealId()+"--------上传时出现错误,可能是文件服务没有启动----------");
|
|
|
throw new RuntimeException("封存id--"+reportDownDto.getPatient().getSealId()+"上传时出现错误,可能是文件服务没有启动");
|
|
|
}
|
|
|
Map resMap = JSON.parseObject(post, Map.class);
|
|
|
long l7 = System.currentTimeMillis();
|
|
|
logger.info("接口总耗时--------" + (l7 - l6));
|
|
|
if (String.valueOf(resMap.get("code")).equals("500")) {
|
|
|
|
|
|
logger.info("封存id--"+reportDownDto.getPatient().getSealId()+ "--------上传失败!" + resMap.get("msg"));
|
|
|
throw new RuntimeException("封存id--"+reportDownDto.getPatient().getSealId()+ "上传失败:" + resMap.get("msg"));
|
|
|
} else {
|
|
|
logger.info("----------执行成功-----------");
|
|
|
return ResultUtils.success().asXML();
|
|
|
}
|
|
|
}else {
|
|
|
//病理没有就诊流水号的根据住院号和检查申请日期时间匹配患者
|
|
|
// String empIdText = getElementTextCanBeEmpty(elementRoot, empId.split(","));
|
|
|
// if (null==empIdText||empIdText.equals("")){
|
|
|
// String examApplyDates = getElementText(elementRoot, examApplyDate.split(","));
|
|
|
// String inPatientNos = getElementText(elementRoot, inPatientNo.split(","));
|
|
|
// empIdText = afCollectTaskService.selectJzh(inPatientNos, examApplyDates);
|
|
|
// if (null==empIdText){
|
|
|
// TBasic tBasic = afCollectTaskService.selectDisDateIsNull(inPatientNos);
|
|
|
// if (null!=tBasic){
|
|
|
// empIdText = tBasic.getJzh();
|
|
|
// }else {
|
|
|
// throw new RuntimeException("住院号未匹配到患者");
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
|
|
|
doctorSubmitTime = getElementText(elementRoot, doctorSubmitTime.split(","));
|
|
|
|
|
|
/**
|
|
|
* 删除电子病历数据
|
|
|
*/
|
|
|
|
|
|
long l2 = System.currentTimeMillis();
|
|
|
String patientId = afCollectTaskService.getpatientIdByEmpId(empIdText);
|
|
|
long l3 = System.currentTimeMillis();
|
|
|
logger.info("查询patient_id耗时" + (l3 - l2));
|
|
|
//删除af_downfile表数据
|
|
|
long l4 = System.currentTimeMillis();
|
|
|
int i = afCollectTaskService.deleteByPatientIdAndCollectorId(patientId, collectorid);
|
|
|
long l5 = System.currentTimeMillis();
|
|
|
logger.info("删除" + empIdText + "af_downfile表" + i + "条数据耗时-----" + (l5 - l4));
|
|
|
//删除t_scan_assort表数据
|
|
|
long l8 = System.currentTimeMillis();
|
|
|
int i1 = afCollectTaskService.deleteByPatientIdAndAssortId(patientId, assortid);
|
|
|
long l11 = System.currentTimeMillis();
|
|
|
logger.info("删除" + empIdText + "t_scan_assort表" + i1 + "条数据耗时-----" + (l11 - l8));
|
|
|
//删除af_collect_task表数据
|
|
|
long l9 = System.currentTimeMillis();
|
|
|
int i2 = afCollectTaskService.deleteByPatientIdAndSysFlag(patientId, collectorid);
|
|
|
long l10 = System.currentTimeMillis();
|
|
|
logger.info("删除" + empIdText + "af_collect_task表" + i2 + "条数据耗时-----" + (l10 - l9));
|
|
|
reportDownPatientDto.setJzh(empIdText);
|
|
|
logger.info("患者主索引号:" + empIdText);
|
|
|
reportDownDto.setPatient(reportDownPatientDto);
|
|
|
List<Element> elementList = xmlUtils.getJsonByName(elementRoot);
|
|
|
for (Element element : elementList) {
|
|
|
filetitle = getElementText(element, filetitleKey.split(","));
|
|
|
downurl = getElementText(element, downurlKey.split(","));
|
|
|
//downurl = handleDownUrl(downurl);
|
|
|
//添加护理提交时间
|
|
|
if (collectorid.equals("1")) {
|
|
|
nurseSubmitTime = getElementText(element, nurseSubmitTime.split(","));
|
|
|
afCollectTaskService.updateNurseSubmitTime(reportDownDto, nurseSubmitTime,submit);
|
|
|
afCollectTaskService.insertNurseState(reportDownDto, nurseSubmitTime);
|
|
|
}
|
|
|
//获取电子病历排序时间
|
|
|
sortingTime = getElementTextCanBeEmpty(element, sortingTimeKey.split(","));
|
|
|
//获取采集流水号
|
|
|
serialnum = getElementText(element, serialnmnKey.split(","));
|
|
|
reportDownScanFileDto = new ReportDownScanFileDto();
|
|
|
reportDownScanFileDto.setDownurl(downurl);
|
|
|
reportDownScanFileDto.setFiletitle(filetitle);
|
|
|
reportDownScanFileDto.setSerialnum(serialnum);
|
|
|
reportDownScanFileDto.setSortdate(sortingTime);
|
|
|
reportDownScanFileDto.setFilesource(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource"))));
|
|
|
reportDownScanFileDto.setFilestoragetype(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype"))));
|
|
|
//判断是否为base64
|
|
|
if (reportDownScanFileDto.getDownurl().length() > 200) {
|
|
|
reportDownScanFileDto.setFiletype(2);
|
|
|
}
|
|
|
reportDownDtoArr.add(reportDownScanFileDto);
|
|
|
}
|
|
|
if (reportDownDtoArr.size() <= 0) {
|
|
|
throw new RuntimeException("不存在必要的基本信息");
|
|
|
} else {
|
|
|
reportDownDto.setScanfiles(reportDownDtoArr);
|
|
|
}
|
|
|
if (collectorid.equals("22")) {
|
|
|
//查询正式住院患者信息
|
|
|
TBasic tBasic = tBasicMapper.selectByjzh(empIdText);
|
|
|
if (null != tBasic) {
|
|
|
//查询预住院患者信息
|
|
|
TBasicExtend tBasicExtend = tBasicExtendMapper.selectByPatientId(tBasic.getPatientId());
|
|
|
if (null != tBasicExtend) {
|
|
|
TBasic tBasicPre = tBasicMapper.selectByjzh(tBasicExtend.getPreJzh());
|
|
|
if (null != tBasicPre) {
|
|
|
int pre = tScanAssortMapper.updateByPatientId(tBasic.getPatientId(), tBasicPre.getPatientId());
|
|
|
if (pre <= 0) {
|
|
|
logger.info("当前预住院没有文件!");
|
|
|
} else {
|
|
|
logger.info("本次预住院合并" + pre + "份报告");
|
|
|
}
|
|
|
} else {
|
|
|
logger.info("未查询到预住院患者信息!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//插入医生提交时间
|
|
|
afCollectTaskService.updateDoctorSubmitTime(reportDownDto, doctorSubmitTime,submit);
|
|
|
//插入医生提交状态
|
|
|
afCollectTaskService.insertDoctorState(reportDownDto, doctorSubmitTime);
|
|
|
//插入文件af_collect_task表数据
|
|
|
// synchronized (lock) {
|
|
|
// System.err.println(reportDownDto);
|
|
|
afCollectTaskService.insert(reportDownDto);
|
|
|
// }
|
|
|
String post = "";
|
|
|
logger.info("--------执行上传功能----------");
|
|
|
Map params = JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class);
|
|
|
if (reportDownDto.getScanfiles().get(0).getFiletype() == 1) {
|
|
|
logger.info(reportDownDto.getPatient().getJzh() + ": 上传参数:" + params);
|
|
|
}
|
|
|
long l = System.currentTimeMillis();
|
|
|
post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, params);
|
|
|
long l1 = System.currentTimeMillis();
|
|
|
logger.info("请求下载耗时----------" + (l1 - l));
|
|
|
// String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), map, headMap);
|
|
|
if (StringUtils.isBlank(post)) {
|
|
|
logger.info("--------上传时出现错误,可能是文件服务没有启动----------");
|
|
|
throw new RuntimeException("上传时出现错误,可能是文件服务没有启动");
|
|
|
}
|
|
|
Map resMap = JSON.parseObject(post, Map.class);
|
|
|
long l7 = System.currentTimeMillis();
|
|
|
logger.info("接口总耗时--------" + (l7 - l6));
|
|
|
if (String.valueOf(resMap.get("code")).equals("500")) {
|
|
|
logger.info(reportDownDto.getPatient().getJzh() + "--------上传失败!" + resMap.get("msg"));
|
|
|
throw new RuntimeException(reportDownDto.getPatient().getJzh() + "上传失败:" + resMap.get("msg"));
|
|
|
} else {
|
|
|
logger.info("----------执行成功-----------");
|
|
|
return ResultUtils.success().asXML();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
e.printStackTrace();
|
|
|
// mrReportErrorService.insert(xml);
|
|
|
logger.error(e.getMessage());
|
|
|
String stackTrace = ExceptionUtils.getStackTrace(e);
|
|
|
logger.info("错误信息----------" + stackTrace);
|
|
|
return ResultUtils.fail(e.getMessage());
|
|
|
} catch (Exception e) {
|
|
|
// mrReportErrorService.insert(xml);
|
|
|
logger.error(e.getMessage());
|
|
|
String stackTrace = ExceptionUtils.getStackTrace(e);
|
|
|
logger.info("错误信息----------" + stackTrace);
|
|
|
e.printStackTrace();
|
|
|
return ResultUtils.fail(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// public static void main(String[] args) {
|
|
|
// TBasicWebService service = new TBasicWebService();
|
|
|
// service.sealCollect("");
|
|
|
// }
|
|
|
private void sealCollect(String sealId) {
|
|
|
final String systemCollectConfigFileName = "dataConfig" + File.separator + "SystemCollectConfig";
|
|
|
List<SystemCollectConfig.CollectConfig> sealCollectConfigs;
|
|
|
try {
|
|
|
String configJson = FileUtils.readJsonFromCurrentProject(systemCollectConfigFileName);
|
|
|
|
|
|
SystemCollectConfig systemCollectConfig = JSON.parseObject(configJson, SystemCollectConfig.class);
|
|
|
String sealCollectClassify = systemCollectConfig.getSealCollectClassify();
|
|
|
if (!SystemCollectConfig.Classify.SEAL_COLLECT.getClassify().equals(sealCollectClassify)) {
|
|
|
throw new RuntimeException("封存病案采集配置未配置!");
|
|
|
}
|
|
|
sealCollectConfigs = systemCollectConfig.getSealCollectConfigs();
|
|
|
for (SystemCollectConfig.CollectConfig config : sealCollectConfigs) {
|
|
|
if (StringUtils.isBlank(config.getDesc()) || StringUtils.isBlank(config.getUrl())) {
|
|
|
throw new RuntimeException("封存病案采集配置中描述和地址不能为空!");
|
|
|
}
|
|
|
}
|
|
|
} catch (RuntimeException runtimeException) {
|
|
|
logger.error(runtimeException.getMessage(), runtimeException);
|
|
|
return;
|
|
|
} catch (Exception ex) {
|
|
|
logger.error("封存病案获取采集配置出现未知错误!", ex);
|
|
|
return;
|
|
|
}
|
|
|
// 添加封存采集任务的容器
|
|
|
List<CompletableFuture<Void>> completableFutureList = new CopyOnWriteArrayList<>();
|
|
|
for (SystemCollectConfig.CollectConfig config : sealCollectConfigs) {
|
|
|
CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
|
|
|
sealCollect(sealId, config);
|
|
|
}, threadPoolExecutor);
|
|
|
completableFutureList.add(completableFuture);
|
|
|
}
|
|
|
// 封存采集任务的容器不为空,阻塞到所有任务完成
|
|
|
if (!completableFutureList.isEmpty()) {
|
|
|
CompletableFuture<Void> allFutures = CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[0]));
|
|
|
try {
|
|
|
allFutures.get();
|
|
|
} catch (Exception ex) {
|
|
|
logger.error(ex.getMessage(), ex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void sealCollect(String sealId, SystemCollectConfig.CollectConfig config) {
|
|
|
String url = config.getUrl() + "?sealId=" + sealId;
|
|
|
String desc = config.getDesc();
|
|
|
try {
|
|
|
logger.info("{},采集地址:{}", desc, url);
|
|
|
String result = HttpUtils.get(url);
|
|
|
logger.info("{},采集地址:{},采集结果:{}", desc, url, result);
|
|
|
} catch (Exception ex) {
|
|
|
logger.error(desc + ",采集地址:" + url + ",采集失败!", ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 肇庆门急诊报告接收
|
|
|
*
|
|
|
* @param xml
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public String outPatient(String xml) {
|
|
|
long l6 = System.currentTimeMillis();
|
|
|
try {
|
|
|
logger.info("报告推送入参:" + xml);
|
|
|
// 1、创建document对象
|
|
|
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + xml;
|
|
|
//解析XML
|
|
|
XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(xml.getBytes("UTF-8")));
|
|
|
//获取数据存在的节点节点
|
|
|
|
|
|
Element elementRoot = xmlUtils.getMsgElement();
|
|
|
//key
|
|
|
String serialnmnKey = String.valueOf(FileUtils.getJsonByName("serialnum"));
|
|
|
String filetitleKey = String.valueOf(FileUtils.getJsonByName("filetitle"));
|
|
|
String downurlKey = String.valueOf(FileUtils.getJsonByName("downurl"));
|
|
|
|
|
|
// 获取患者主索引号
|
|
|
String empId = String.valueOf(FileUtils.getJsonByName(Codes.EMP_ID.getMessage()));
|
|
|
|
|
|
|
|
|
Map<String, Object> headMap = new HashMap<>();
|
|
|
headMap.put("Content-Type", "application/json");
|
|
|
ReportDownDto reportDownDto;
|
|
|
|
|
|
ReportDownScanFileDto reportDownScanFileDto;
|
|
|
ReportDownPatientDto reportDownPatientDto;
|
|
|
//临时资料存储
|
|
|
String serialnum;
|
|
|
String filetitle;
|
|
|
String downurl;
|
|
|
// String sortingTime;
|
|
|
int filetype = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filetype")));
|
|
|
String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid"));
|
|
|
|
|
|
String assortid = getAssortid(elementRoot);
|
|
|
reportDownDto = new ReportDownDto();
|
|
|
reportDownDto.setCollectorid(collectorid);
|
|
|
reportDownDto.setAssortid(assortid);
|
|
|
//获取基本数据信息
|
|
|
List<ReportDownScanFileDto> reportDownDtoArr = new ArrayList<>();
|
|
|
reportDownPatientDto = new ReportDownPatientDto();
|
|
|
//获取jzh
|
|
|
String empIdText = getElementText(elementRoot, empId.split(","));
|
|
|
|
|
|
reportDownPatientDto.setJzh(empIdText);
|
|
|
logger.info("患者主索引号:" + empIdText);
|
|
|
reportDownDto.setPatient(reportDownPatientDto);
|
|
|
List<Element> elementList = xmlUtils.getJsonByName(elementRoot);
|
|
|
for (Element element : elementList) {
|
|
|
filetitle = getElementText(element, filetitleKey.split(","));
|
|
|
downurl = getElementText(element, downurlKey.split(","));
|
|
|
serialnum = getElementText(element, serialnmnKey.split(","));
|
|
|
reportDownScanFileDto = new ReportDownScanFileDto();
|
|
|
reportDownScanFileDto.setDownurl(downurl.substring(1, downurl.length() - 1));
|
|
|
reportDownScanFileDto.setFiletitle(filetitle);
|
|
|
reportDownScanFileDto.setSerialnum(serialnum);
|
|
|
reportDownScanFileDto.setFiletype(filetype);
|
|
|
reportDownScanFileDto.setFilesource(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource"))));
|
|
|
reportDownScanFileDto.setFilestoragetype(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype"))));
|
|
|
//判断是否为base64
|
|
|
if (reportDownScanFileDto.getDownurl().length() > 200) {
|
|
|
reportDownScanFileDto.setFiletype(2);
|
|
|
}
|
|
|
reportDownDtoArr.add(reportDownScanFileDto);
|
|
|
}
|
|
|
if (reportDownDtoArr.size() <= 0) {
|
|
|
throw new RuntimeException("不存在必要的基本信息");
|
|
|
} else {
|
|
|
reportDownDto.setScanfiles(reportDownDtoArr);
|
|
|
}
|
|
|
|
|
|
// System.err.println(reportDownDto);
|
|
|
|
|
|
afCollectTaskService.insertOut(reportDownDto);
|
|
|
|
|
|
|
|
|
String post = "";
|
|
|
logger.info("--------执行上传功能----------");
|
|
|
Map params = JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class);
|
|
|
logger.info("上传参数:" + params);
|
|
|
long l = System.currentTimeMillis();
|
|
|
post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, params);
|
|
|
long l1 = System.currentTimeMillis();
|
|
|
logger.info("请求下载耗时----------" + (l1 - l));
|
|
|
|
|
|
if (StringUtils.isBlank(post)) {
|
|
|
logger.info("--------上传时出现错误,可能是文件服务没有启动----------");
|
|
|
throw new RuntimeException("上传时出现错误,可能是文件服务没有启动");
|
|
|
}
|
|
|
Map resMap = JSON.parseObject(post, Map.class);
|
|
|
long l7 = System.currentTimeMillis();
|
|
|
logger.info("接口总耗时--------" + (l7 - l6));
|
|
|
if (String.valueOf(resMap.get("code")).equals("500")) {
|
|
|
throw new RuntimeException(String.valueOf(resMap.get("msg")));
|
|
|
} else {
|
|
|
logger.info("----------执行成功-----------");
|
|
|
return ResultUtils.success().asXML();
|
|
|
}
|
|
|
} catch (RuntimeException e) {
|
|
|
e.printStackTrace();
|
|
|
logger.error(e.getMessage());
|
|
|
// String stackTrace = ExceptionUtils.getStackTrace(e);
|
|
|
// logger.info("错误信息----------"+stackTrace);
|
|
|
return ResultUtils.fail(e.getMessage());
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage());
|
|
|
// String stackTrace = ExceptionUtils.getStackTrace(e);
|
|
|
// logger.info("错误信息----------"+stackTrace);
|
|
|
e.printStackTrace();
|
|
|
return ResultUtils.fail(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 特殊处理字符
|
|
|
*
|
|
|
* @param downurl
|
|
|
* @return
|
|
|
*/
|
|
|
private String handleDownUrl(String downurl) {
|
|
|
String url = "";
|
|
|
try {
|
|
|
|
|
|
XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(downurl.getBytes("UTF-8")));
|
|
|
if (null != xmlUtils) {
|
|
|
url = downurl;
|
|
|
List<String> urlReplaces = (List<String>) FileUtils.getJsonByName("urlReplace");
|
|
|
for (String urlReplace : urlReplaces) {
|
|
|
url = url.replaceAll(urlReplace, "");
|
|
|
}
|
|
|
return url;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
// @Override
|
|
|
// public String EmrDocumentArchive(String xml) {
|
|
|
// return pushSurveyReport(xml);
|
|
|
// }
|
|
|
//
|
|
|
// @Override
|
|
|
// public String EmrDocumentArchiveCancel(String xml) {
|
|
|
// try {
|
|
|
// logger.info("--------------撤销接收到xml--------------");
|
|
|
// logger.info(xml);
|
|
|
// //解析xml,并提取CanlcelDto对象
|
|
|
// CanlcelDto canlcelDto = getCanlCelDtoByXml(xml);
|
|
|
// //调用上传服务撤销功能
|
|
|
// afCollectTaskService.invokeRepoalFile(canlcelDto);
|
|
|
// logger.info("--------------撤销操作完成-------------");
|
|
|
// return ResultUtils.success().asXML();
|
|
|
// } catch (RuntimeException e) {
|
|
|
// logger.info("发送错误:" + e.getMessage());
|
|
|
// // mrReportErrorService.insert(xml);
|
|
|
// e.printStackTrace();
|
|
|
// return ResultUtils.fail(e.getMessage());
|
|
|
// } catch (Exception e) {
|
|
|
// logger.info("发送错误:" + e.getMessage());
|
|
|
// e.printStackTrace();
|
|
|
// // mrReportErrorService.insert(xml);
|
|
|
// return ResultUtils.fail(e.getMessage());
|
|
|
// }
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 解析xml,返回CanlcelDto对象
|
|
|
*
|
|
|
* @param xml
|
|
|
* @return
|
|
|
*/
|
|
|
private CanlcelDto getCanlCelDtoByXml(String xml) throws UnsupportedEncodingException {
|
|
|
XmlUtils xmlUtils = null;
|
|
|
try {
|
|
|
xmlUtils = new XmlUtils(new ByteArrayInputStream(xml.getBytes("UTF-8")));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
//采集流水号所在位置目录
|
|
|
List<String> repealDirectory = (List<String>) FileUtils.getJsonByName("repealDirectory");
|
|
|
Element element = xmlUtils.getElement(repealDirectory);
|
|
|
String repealSerialnum = String.valueOf(FileUtils.getJsonByName("repealSerialnum"));
|
|
|
Element repealSerialnumElement = element.element(repealSerialnum);
|
|
|
CanlcelDto canlcelDto = new CanlcelDto();
|
|
|
|
|
|
if (null == repealSerialnumElement || StringUtils.isBlank(repealSerialnumElement.getText())) {
|
|
|
throw new RuntimeException(repealSerialnum + "标签必须有值");
|
|
|
} else {
|
|
|
String serialnum = repealSerialnumElement.getText();
|
|
|
logger.info("当前流水号为:" + serialnum);
|
|
|
canlcelDto.setSerialnum(serialnum);
|
|
|
}
|
|
|
return canlcelDto;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取key内容
|
|
|
*
|
|
|
* @param element
|
|
|
* @param args
|
|
|
* @return
|
|
|
*/
|
|
|
private String getElementText(Element element, String[] args) {
|
|
|
String resText = "";
|
|
|
Element byElement = (Element) element.clone();
|
|
|
Element byElement1 = null;
|
|
|
String[] split;
|
|
|
for (String arg : args) {
|
|
|
split = arg.split("&");
|
|
|
if (split.length > 1) {
|
|
|
for (String spi : split) {
|
|
|
if (byElement1 == null) {
|
|
|
byElement1 = byElement.element(spi);
|
|
|
} else {
|
|
|
byElement1 = byElement1.element(spi);
|
|
|
}
|
|
|
|
|
|
if (byElement1 != null && StringUtils.isNotBlank(byElement1.getText())) {
|
|
|
break;
|
|
|
} else {
|
|
|
byElement1 = null;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if (byElement1 == null) {
|
|
|
byElement1 = byElement.element(arg);
|
|
|
} else {
|
|
|
byElement1 = byElement1.element(arg);
|
|
|
}
|
|
|
}
|
|
|
if (byElement1 != null) {
|
|
|
resText = byElement1.getText();
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (StringUtils.isBlank(resText)) {
|
|
|
throw new RuntimeException(args[args.length - 1] + "的值不能为空");
|
|
|
}
|
|
|
return resText;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取key内容
|
|
|
*
|
|
|
* @param element
|
|
|
* @param args
|
|
|
* @return
|
|
|
*/
|
|
|
private String getElementTextCanBeEmpty(Element element, String[] args) {
|
|
|
String resText = "";
|
|
|
Element byElement = (Element) element.clone();
|
|
|
Element byElement1 = null;
|
|
|
String[] split;
|
|
|
for (String arg : args) {
|
|
|
split = arg.split("&");
|
|
|
if (split.length > 1) {
|
|
|
for (String spi : split) {
|
|
|
if (byElement1 == null) {
|
|
|
byElement1 = byElement.element(spi);
|
|
|
} else {
|
|
|
byElement1 = byElement1.element(spi);
|
|
|
}
|
|
|
|
|
|
if (byElement1 != null && StringUtils.isNotBlank(byElement1.getText())) {
|
|
|
break;
|
|
|
} else {
|
|
|
byElement1 = null;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if (byElement1 == null) {
|
|
|
byElement1 = byElement.element(arg);
|
|
|
} else {
|
|
|
byElement1 = byElement1.element(arg);
|
|
|
}
|
|
|
}
|
|
|
if (byElement1 != null) {
|
|
|
resText = byElement1.getText();
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return resText;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取分类id
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
private String getAssortid(Element element) {
|
|
|
|
|
|
String assortId = String.valueOf(FileUtils.getJsonByName("assortid"));
|
|
|
if (StringUtils.isBlank(assortId)) {
|
|
|
String assortIdKey = String.valueOf(FileUtils.getJsonByName("assortidParamKey"));
|
|
|
if (StringUtils.isBlank(assortIdKey)) {
|
|
|
assortId = "";
|
|
|
} else {
|
|
|
assortId = element.element(assortIdKey).getText();
|
|
|
}
|
|
|
String myAssortId = afCollectTaskService.getAssortIdByAssortId(assortId);
|
|
|
if (StringUtils.isBlank(myAssortId)) {
|
|
|
myAssortId = afCollectTaskService.getAssortIdByAssortName(assortId);
|
|
|
if (StringUtils.isBlank(myAssortId)) {
|
|
|
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
ZdAssort zdAssort = new ZdAssort();
|
|
|
zdAssort.setAssortName(assortId);
|
|
|
zdAssort.setAssortId(uuid);
|
|
|
zdAssort.setEffective(1);
|
|
|
afCollectTaskService.insertZdAssort(zdAssort);
|
|
|
assortId = uuid;
|
|
|
} else {
|
|
|
assortId = myAssortId;
|
|
|
}
|
|
|
} else {
|
|
|
assortId = myAssortId;
|
|
|
}
|
|
|
}
|
|
|
return assortId;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static void depdf() {
|
|
|
// 存放pdf的base64
|
|
|
Path path = Paths.get("D:\\pdf.txt");
|
|
|
Stream<String> lines = null;
|
|
|
try {
|
|
|
lines = Files.lines(path);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
// 读取文件转换为String
|
|
|
String collect = lines.collect(Collectors.joining(System.lineSeparator()));
|
|
|
String encodedBytes = collect;
|
|
|
BASE64Decoder decoder = new BASE64Decoder();
|
|
|
byte[] decodedBytes = new byte[0];
|
|
|
try {
|
|
|
decodedBytes = decoder.decodeBuffer(encodedBytes);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
File file = new File("D:\\newfile.pdf");
|
|
|
FileOutputStream fop = null;
|
|
|
try {
|
|
|
fop = new FileOutputStream(file);
|
|
|
fop.write(decodedBytes);
|
|
|
fop.flush();
|
|
|
fop.close();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// public static void main(String[] args) {
|
|
|
// depdf();
|
|
|
// }
|
|
|
|
|
|
|
|
|
}
|