You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
216 lines
8.7 KiB
Java
216 lines
8.7 KiB
Java
4 years ago
|
package com.docus.bgts.handler;
|
||
|
|
||
|
|
||
|
import com.alibaba.fastjson.JSON;
|
||
|
import com.docus.bgts.entity.ReportDownDto;
|
||
|
import com.docus.bgts.entity.ReportDownPatientDto;
|
||
|
import com.docus.bgts.entity.ReportDownScanFileDto;
|
||
|
import com.docus.bgts.enums.Codes;
|
||
|
import com.docus.bgts.facade.IAfCollectTaskService;
|
||
|
import com.docus.bgts.facade.IMrReportErrorService;
|
||
|
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.logging.log4j.LogManager;
|
||
|
import org.apache.logging.log4j.Logger;
|
||
|
import org.dom4j.Document;
|
||
|
import org.dom4j.DocumentException;
|
||
|
import org.dom4j.Element;
|
||
|
import org.dom4j.io.SAXReader;
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
||
|
import javax.jws.WebService;
|
||
|
import java.io.ByteArrayInputStream;
|
||
|
import java.io.StringReader;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
|
||
|
@WebService
|
||
|
public class TBasicWebService implements ITBasicWebService {
|
||
|
|
||
|
@Autowired
|
||
|
IAfCollectTaskService afCollectTaskService;
|
||
|
|
||
|
@Autowired
|
||
|
IMrReportErrorService mrReportErrorService;
|
||
|
|
||
|
private Logger logger = LogManager.getLogger(TBasicWebService.class);
|
||
|
|
||
|
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) {
|
||
|
try {
|
||
|
logger.info("报告推送入参:" + xml);
|
||
|
// 1、创建document对象
|
||
|
// Document document = DocumentHelper.createDocument();
|
||
|
// Element rootElement = getElementFromString(xml);
|
||
|
// document.setRootElement(rootElement);
|
||
|
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + xml;
|
||
|
//解析XML
|
||
|
XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(xml.getBytes("UTF-8")));
|
||
|
// 获取患者主索引号
|
||
|
String empId = String.valueOf(FileUtils.getJsonByName(Codes.EMP_ID.getMessage()));
|
||
|
Map<String, Object> headMap = new HashMap<>();
|
||
|
headMap.put("Content-Type", "application/json");
|
||
|
ReportDownDto reportDownDto;
|
||
|
//获取数据存在的节点节点
|
||
|
Element elementRoot = xmlUtils.getMsgElement();
|
||
|
//key
|
||
|
String serialnmnKey = String.valueOf(FileUtils.getJsonByName("serialnum"));
|
||
|
// String empId = String.valueOf(FileUtils.getJsonByName("indexFlag"));
|
||
|
String filetitleKey = String.valueOf(FileUtils.getJsonByName("filetitle"));
|
||
|
String downurlKey = String.valueOf(FileUtils.getJsonByName("downurl"));
|
||
|
|
||
|
ReportDownScanFileDto reportDownScanFileDto;
|
||
|
ReportDownPatientDto reportDownPatientDto;
|
||
|
//临时资料存储
|
||
|
String serialnum;
|
||
|
String filetitle;
|
||
|
String downurl;
|
||
|
String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid"));
|
||
|
// String collectorid = getCollectorid(elementList.get(0));
|
||
|
// String assortid = String.valueOf(FileUtils.getJsonByName("assortid"));
|
||
|
String assortid = getAssortid(elementRoot);
|
||
|
reportDownDto = new ReportDownDto();
|
||
|
reportDownDto.setCollectorid(collectorid);
|
||
|
reportDownDto.setAssortid(assortid);
|
||
|
//获取基本数据信息
|
||
|
List<ReportDownScanFileDto> reportDownDtoArr = new ArrayList<>();
|
||
|
reportDownPatientDto = new ReportDownPatientDto();
|
||
|
// String empIdText = elementList.get(0).element(empId).getText();
|
||
|
//获取jzh
|
||
|
String empIdText = getElementText(elementRoot, empId.split(","));
|
||
|
//获取采集流水号
|
||
|
serialnum = getElementText(elementRoot, serialnmnKey.split(","));
|
||
|
reportDownPatientDto.setJzh(empIdText);
|
||
|
logger.info("患者主索引号:" + empIdText);
|
||
|
reportDownDto.setPatient(reportDownPatientDto);
|
||
|
List<Element> elementList = xmlUtils.getJsonByName(elementRoot);
|
||
|
|
||
|
for (Element element : elementList) {
|
||
|
// serialnum = element.element(serialnmnKey).getText();
|
||
|
// filetitle = element.element(filetitleKey).getText();
|
||
|
filetitle = getElementText(element, filetitleKey.split(","));
|
||
|
// downurl = element.element(downurlKey).getText();
|
||
|
downurl = getElementText(element, downurlKey.split(","));
|
||
|
reportDownScanFileDto = new ReportDownScanFileDto();
|
||
|
reportDownScanFileDto.setDownurl(downurl);
|
||
|
reportDownScanFileDto.setFiletitle(filetitle);
|
||
|
reportDownScanFileDto.setSerialnum(serialnum);
|
||
|
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);
|
||
|
}
|
||
|
//插入文件af_collect_task表数据
|
||
|
afCollectTaskService.insert(reportDownDto);
|
||
|
String post = "";
|
||
|
logger.info("--------执行上传功能----------");
|
||
|
Map params = JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class);
|
||
|
logger.info("上传参数:" + params);
|
||
|
post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, params);
|
||
|
// 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);
|
||
|
if (String.valueOf(resMap.get("code")).equals("500")) {
|
||
|
throw new RuntimeException(String.valueOf(resMap.get("msg")));
|
||
|
} else {
|
||
|
return ResultUtils.success().asXML();
|
||
|
}
|
||
|
} catch (RuntimeException e) {
|
||
|
e.printStackTrace();
|
||
|
mrReportErrorService.insert(xml);
|
||
|
return ResultUtils.fail(e.getMessage());
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
mrReportErrorService.insert(xml);
|
||
|
return ResultUtils.fail(e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String EmrDocumentArchive(String xml) {
|
||
|
return pushSurveyReport(xml);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取key内容
|
||
|
*
|
||
|
* @param element
|
||
|
* @param args
|
||
|
* @return
|
||
|
*/
|
||
|
private String getElementText(Element element, String[] args) {
|
||
|
String resText = "";
|
||
|
Element byElement = (Element) element.clone();
|
||
|
String[] split;
|
||
|
for (String arg : args) {
|
||
|
split = arg.split("&");
|
||
|
if (split.length > 1) {
|
||
|
for (String spi : split) {
|
||
|
byElement = byElement.element(spi);
|
||
|
if (byElement != null) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
byElement = byElement.element(arg);
|
||
|
}
|
||
|
if (byElement != null) {
|
||
|
resText = byElement.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();
|
||
|
}
|
||
|
}
|
||
|
return assortId;
|
||
|
}
|
||
|
}
|