@ -2,31 +2,45 @@ package com.docus.bgts.handler;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
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 com.sun.xml.internal.ws.util.xml.XmlUtil;
import org.apache.commons.lang3.CharEncoding ;
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.Namespace ;
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.jws.WebService ;
import java.io.ByteArrayInputStream ;
import java.io.StringReader ;
import java.io.UnsupportedEncodingException ;
import java.io.* ;
import java.nio.file.Files ;
import java.nio.file.Path ;
import java.nio.file.Paths ;
import java.text.SimpleDateFormat ;
import java.util.* ;
import java.util.concurrent.locks.Lock ;
import java.util.concurrent.locks.ReentrantLock ;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
@WebService
public class TBasicWebService implements ITBasicWebService {
@ -37,6 +51,15 @@ public class TBasicWebService implements ITBasicWebService {
@Autowired
IMrReportErrorService mrReportErrorService ;
@Autowired
TBasicMapper tBasicMapper ;
@Autowired
TBasicExtendMapper tBasicExtendMapper ;
@Autowired
TScanAssortMapper tScanAssortMapper ;
// private Object lock = new Object();
private final Logger logger = LoggerFactory . getLogger ( getClass ( ) ) ;
@ -59,6 +82,7 @@ public class TBasicWebService implements ITBasicWebService {
@Override
public String pushSurveyReport ( String xml ) {
long l6 = System . currentTimeMillis ( ) ;
try {
logger . info ( "报告推送入参:" + xml ) ;
// 1、创建document对象
@ -66,11 +90,18 @@ public class TBasicWebService implements ITBasicWebService {
//解析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 ( ) ) ) ;
//判断是否为撤销
@ -110,8 +141,15 @@ public class TBasicWebService implements ITBasicWebService {
String serialnum ;
String filetitle ;
String downurl ;
String sortingTime ;
String assortid ;
String collectorid = String . valueOf ( FileUtils . getJsonByName ( "collectorid" ) ) ;
String assortid = getAssortid ( elementRoot ) ;
if ( collectorid . equals ( "1" ) ) {
assortid = String . valueOf ( FileUtils . getJsonByName ( "assortid" ) ) ;
} else {
assortid = getAssortid ( elementRoot ) ;
}
reportDownDto = new ReportDownDto ( ) ;
reportDownDto . setCollectorid ( collectorid ) ;
reportDownDto . setAssortid ( assortid ) ;
@ -121,21 +159,77 @@ public class TBasicWebService implements ITBasicWebService {
//获取jzh
String empIdText = getElementText ( elementRoot , empId . split ( "," ) ) ;
//病理没有就诊流水号的根据住院号和检查申请日期时间匹配患者
// 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 ) ;
//downurl = handleDownUrl(downurl);
//添加护理提交时间
// if (filetitle.equals("体温单")||filetitle.equals("护理记录单(通用)")||filetitle.equals("首次护理记录单(通用)")){
// nurseSubmitTime = getElementText(element, nurseSubmitTime.split(","));
// afCollectTaskService.updateNurseSubmitTime(reportDownDto, nurseSubmitTime);
// 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
@ -149,23 +243,59 @@ public class TBasicWebService implements ITBasicWebService {
} 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);
//插入医生提交状态
// afCollectTaskService.insertDoctorState(reportDownDto,doctorSubmitTime);
//插入文件af_collect_task表数据
// synchronized (lock) {
afCollectTaskService . insert ( reportDownDto ) ;
// 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 ( "上传参数:" + 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" ) ) {
throw new RuntimeException ( String . valueOf ( resMap . get ( "msg" ) ) ) ;
} else {
@ -174,13 +304,137 @@ public class TBasicWebService implements ITBasicWebService {
}
} catch ( RuntimeException e ) {
e . printStackTrace ( ) ;
mrReportErrorService . insert ( xml ) ;
// 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 ( ) ;
mrReportErrorService . insert ( xml ) ;
return ResultUtils . fail ( e . getMessage ( ) ) ;
}
}
/ * *
* 肇 庆 门 急 诊 报 告 接 收
* @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 ( ) ) ;
}
}
@ -194,6 +448,7 @@ public class TBasicWebService implements ITBasicWebService {
private String handleDownUrl ( String downurl ) {
String url = "" ;
try {
XmlUtils xmlUtils = new XmlUtils ( new ByteArrayInputStream ( downurl . getBytes ( "UTF-8" ) ) ) ;
if ( null ! = xmlUtils ) {
url = downurl ;
@ -204,40 +459,40 @@ public class TBasicWebService implements ITBasicWebService {
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 ( ) ) ;
}
}
// @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 对 象
@ -316,6 +571,50 @@ public class TBasicWebService implements ITBasicWebService {
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
@ -352,4 +651,43 @@ public class TBasicWebService implements ITBasicWebService {
}
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();
// }
}