病理检验报告接受推送

docus_webservice_1.1
lzy 4 years ago
parent 727df755f0
commit 6430824e5d

@ -2,7 +2,6 @@ package com.docus.webservice.handler;
import com.alibaba.fastjson.JSON;
import com.docus.webservice.dto.SelectColumn;
import com.docus.webservice.entity.MrReportError;
import com.docus.webservice.entity.TBasic;
@ -15,7 +14,6 @@ import com.docus.webservice.utils.XmlUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import javax.jws.WebService;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -146,6 +144,7 @@ public class TBasicWebService implements ITBasicWebService {
return ResultUtils.fail(selectColumn.getQualityColumn() + " 字段不能为空值");
} else {
continue;
}
} else {
if (selectColumn.getTableName().equals("t_basic")) {
@ -181,6 +180,4 @@ public class TBasicWebService implements ITBasicWebService {
}
return ResultUtils.success().asXML();
}
}

@ -1,21 +0,0 @@
package com.docus.webservice.run;
import com.docus.webservice.enums.Codes;
import com.docus.webservice.handler.TBasicWebService;
import org.springframework.stereotype.Component;
import javax.xml.ws.Endpoint;
/**
*
*/
public class RunServer {
public void run() {
String address = "http://localhost:" + Codes.EXTERNAL.getCode()+"/" + Codes.EXTERNAL.getMessage();
Endpoint.publish(address, new TBasicWebService());
System.out.println("publish success...");
System.out.println(address);
}
}

@ -0,0 +1,27 @@
{
//,
"directory":["Msg","PatInfo"],
//
"indexFlag":"jzh",
//
"serialnum":"PATHOLOGY_ONLY_NO",
//
"filetitle":"EXAM_ITEM_NAME",
//
"downurl":"IMAGE_URL",
//id
"assortid":"批复文件",
//id
"collectorid":"121212",
//( 1:2)
"filesource":0,
//(1:2ftp3)
"filestoragetype":0,
//
"uploadConnector":"http://192.168.1.107:9291/api/downplatform/report",
//
"basicDirectory":["Msg","PatInfo"],
//
"doubleBasic":["TestItemInfo","BioTestInfo"],
}

@ -73,6 +73,21 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.4</version>
</dependency>
</dependencies>
<build>

@ -0,0 +1,21 @@
package com.docus.bgts.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class ReportDownDto {
@ApiModelProperty(value = "采集器id")
private String collectorid;
@ApiModelProperty(value = "采集器ip")
private String ip;
@ApiModelProperty(value = "文件信息")
private List<ReportDownScanFileDto> scanfiles;
private ReportDownPatientDto patient;
}

@ -0,0 +1,10 @@
package com.docus.bgts.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ReportDownPatientDto {
@ApiModelProperty(value = "记帐号")
private String jzh;
}

@ -0,0 +1,23 @@
package com.docus.bgts.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ReportDownScanFileDto {
@ApiModelProperty(value = "分类id")
private String assortid;
@ApiModelProperty(value = "文件标题")
private String filetitle;
@ApiModelProperty(value = "采集类型(文件来源 1:采集器2扫描生产软件)")
private int filesource;
@ApiModelProperty(value = "下载类型(1:服务器本地2ftp服务器3共享文件夹)")
private int filestoragetype;
@ApiModelProperty(value = "下载地址")
private String downurl;
@ApiModelProperty(value = "档案信息")
private String recordid;
@ApiModelProperty("采集流水号")
private String serialnum;
}

@ -17,11 +17,17 @@ public enum Codes {
//web service返回描述部分
RET_CON("103","RetCon"),
//web service 服务名
EXTERNAL("9201","docus_tBasic_data"),
EXTERNAL("9202","201_P_WS_JYBGTS"),
//静态文件存放位置
JSON_ADDRESS("999","\\dataConfig\\homeQualitySet.json"),
//接收二级节点
MSG("201","Msg"),
//节点根
DIRECTORY("1000","directory"),
//上传接口地址
UPLOAD("0","uploadConnector"),
//患者主索引号
EMP_ID("0","indexFlag"),
//错误日志编号
ERROR_CODE("500","12"),
//接收三级节点

@ -1,10 +1,16 @@
package com.docus.bgts.handler;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface ITBasicWebService {
/**
*
* @return
*/
@WebMethod
String pushSurveyReport(String xml);
}

@ -1,9 +1,95 @@
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.utils.FileUtils;
import com.docus.bgts.utils.HttpUtils;
import com.docus.bgts.utils.ResultUtils;
import com.docus.bgts.utils.XmlUtils;
import org.apache.bcel.classfile.Code;
import org.dom4j.Element;
import javax.jws.WebService;
import java.io.ByteArrayInputStream;
import java.util.*;
@WebService
public class TBasicWebService implements ITBasicWebService {
@Override
public String pushSurveyReport(String xml) {
StringBuffer mesBuffer=new StringBuffer();
try {
//解析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;
//获取根节点
List<Element> elementList = xmlUtils.getJsonByName();
//key
String serialnmnKey=String.valueOf(FileUtils.getJsonByName("serialnum"));
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 assortid=String.valueOf(FileUtils.getJsonByName("assortid"));
reportDownDto = new ReportDownDto();
reportDownDto.setCollectorid(collectorid);
reportDownDto.setIp("string");
//获取基本数据信息
List<ReportDownScanFileDto> reportDownDtoArr=new ArrayList<>();
reportDownPatientDto=new ReportDownPatientDto();
reportDownPatientDto.setJzh(elementList.get(0).element(empId).getText());
reportDownDto.setPatient(reportDownPatientDto);
for (Element element : elementList) {
serialnum=element.element(serialnmnKey).getText();
filetitle=element.element(filetitleKey).getText();
downurl=element.element(downurlKey).getText();
reportDownScanFileDto=new ReportDownScanFileDto();
reportDownScanFileDto.setDownurl(downurl);
reportDownScanFileDto.setFiletitle(filetitle);
reportDownScanFileDto.setSerialnum(serialnum);
reportDownScanFileDto.setAssortid(assortid);
reportDownScanFileDto.setFilesource(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource"))));
reportDownScanFileDto.setFilestoragetype(Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype"))));
reportDownScanFileDto.setRecordid("临时医嘱");
reportDownDtoArr.add(reportDownScanFileDto);
}
if(reportDownDtoArr.size()<=0){
throw new RuntimeException("不存在必要的基本信息");
}else {
reportDownDto.setScanfiles(reportDownDtoArr);
}
String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class));
// String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), map, headMap);
Map resMap = JSON.parseObject(post, Map.class);
System.out.println(resMap);
if (String.valueOf(resMap.get("code")).equals("500")) {
return ResultUtils.fail(String.valueOf(resMap.get("msg")));
} else {
return ResultUtils.success().asXML();
}
}
catch (RuntimeException e){
return ResultUtils.fail(e.getMessage());
}
catch (Exception e) {
e.printStackTrace();
}
return ResultUtils.fail();
}
}

@ -0,0 +1,44 @@
package com.docus.bgts.utils;
import com.alibaba.fastjson.JSON;
import com.docus.bgts.enums.Codes;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class FileUtils {
/**
* jar
*
* @return
*/
public static String currentPath() {
File dir = new File(".");
String currentpath = "";
try {
currentpath = dir.getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
return currentpath;
}
/**
*
* @param name
* @return
*/
public static Object getJsonByName(String name){
//获取目录结构
String path = FileUtils.currentPath();
//解析json映射文件
String json = JsonUtils.readJsonFile(path + Codes.JSON_ADDRESS.getMessage());
Map jsonMap = JSON.parseObject(json, Map.class);
return jsonMap.get(name);
}
}

@ -0,0 +1,211 @@
package com.docus.bgts.utils;
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Map;
public class HttpUtils {
private static PoolingHttpClientConnectionManager cm;
private static String EMPTY_STR = "";
private static String UTF_8 = "UTF-8";
private static void init() {
if (cm == null) {
cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(50);// 整个连接池最大连接数
cm.setDefaultMaxPerRoute(5);// 每路由最大连接数默认值是2
}
}
/**
* HttpClient
*
* @return
*/
private static CloseableHttpClient getHttpClient() {
init();
return HttpClients.custom().setConnectionManager(cm).build();
}
/**
* @param url
* @return
*/
public static String get(String url) {
HttpGet httpGet = new HttpGet(url);
return getResult(httpGet);
}
/**
* @param urlparams
* @return
*/
public static String get(String url, Map<String, String > params) throws URISyntaxException {
URIBuilder ub = new URIBuilder();
ub.setPath(url);
ArrayList<NameValuePair> pairs = covertParams2NVPS(params);
ub.setParameters(pairs);
HttpGet httpGet = new HttpGet(ub.build());
return getResult(httpGet);
}
/**
* @param urlheadersparams
* @return
*/
public static String get(String url, Map<String, Object> headers, Map<String, String> params)
throws URISyntaxException {
URIBuilder ub = new URIBuilder();
ub.setPath(url);
if (params != null) {
ArrayList<NameValuePair> pairs = covertParams2NVPS(params);
ub.setParameters(pairs);
}
HttpGet httpGet = new HttpGet(ub.build());
for (Map.Entry<String, Object> param : headers.entrySet()) {
httpGet.addHeader(param.getKey(), String.valueOf(param.getValue()));
}
return getResult(httpGet);
}
/**
* @param url
* @return
*/
public static String post(String url) {
HttpPost httpPost = new HttpPost(url);
return getResult(httpPost);
}
/**
* @param urlparams
* @return
*/
public static String post(String url, Map<String, String> params) throws UnsupportedEncodingException {
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(covertParams2NVPS(params), "utf-8"));//设置表单提交编码
// httpPost.setEntity(new StringEntity(JSON.toJSONString(params), ContentType.APPLICATION_FORM_URLENCODED));
return getResult(httpPost);
}
public static String post(String url, Object params, Map<String, Object> head) throws UnsupportedEncodingException {
HttpPost httpPost = new HttpPost(url);
System.out.println(params);
httpPost.setEntity(new StringEntity(params.toString()));//设置表单提交编码
if (params != null) {
for (Map.Entry<String, Object> param : head.entrySet()) {
httpPost.addHeader(param.getKey(), String.valueOf(param.getValue()));
}
}
// httpPost.setEntity(new StringEntity(JSON.toJSONString(params), ContentType.APPLICATION_FORM_URLENCODED));
return getResult(httpPost);
}
private static ArrayList<NameValuePair> covertParams2NVPS(Map<String, String> params) {
ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
for (Map.Entry<String, String> param : params.entrySet()) {
if (param.getValue() != null) {
pairs.add(new BasicNameValuePair(param.getKey(), param.getValue()));
}
}
return pairs;
}
/**
* @param urlheadersparams
* @return
*/
public static String post(String url, Map<String, Object> headers, Map<String, Object> params)
throws UnsupportedEncodingException {
HttpPost httpPost = new HttpPost(url);
System.out.println(params);
if (params != null) {
for (Map.Entry<String, Object> param : headers.entrySet()) {
httpPost.addHeader(param.getKey(), String.valueOf(param.getValue()));
}
}
httpPost.setEntity(new StringEntity(JSON.toJSONString(params), ContentType.APPLICATION_JSON));
return getResult(httpPost);
}
/**
* Http
*
* @param request
* @return
*/
private static String getResult(HttpRequestBase request) {
// CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpClient httpClient = getHttpClient();
try {
CloseableHttpResponse response = httpClient.execute(request);
// response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
if (entity != null) {
// long len = entity.getContentLength();// -1 表示长度未知
String result = EntityUtils.toString(entity, UTF_8);
response.close();
// httpClient.close();
return result;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
return EMPTY_STR;
}
/**
* Http
*
* @param requestBuilder
* @return
*/
private static String getResult(RequestBuilder requestBuilder) {
// CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpClient httpClient = getHttpClient();
try {
CloseableHttpResponse response = httpClient.execute(requestBuilder.build());
// response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
if (entity != null) {
// long len = entity.getContentLength();// -1 表示长度未知
String result = EntityUtils.toString(entity, UTF_8);
response.close();
// httpClient.close();
return result;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
return EMPTY_STR;
}
}

@ -1,6 +1,7 @@
package com.docus.bgts.utils;
import com.alibaba.fastjson.JSON;
import com.docus.bgts.enums.Codes;
import org.dom4j.Document;
import org.dom4j.DocumentException;
@ -8,6 +9,9 @@ import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class XmlUtils {
//定义解析器和文档对象
@ -38,6 +42,74 @@ public class XmlUtils {
}
}
/**
*
* @return
*/
public String getElement(String name){
//获取根节点
Element root = document.getRootElement();
Object directory = FileUtils.getJsonByName(Codes.DIRECTORY.getMessage());
Element current=root;
if(directory==null){
throw new RuntimeException("没有定义目录结构");
}
List<String> directoryArr=(List<String>)directory;
for (String dire : directoryArr) {
current=current.element(dire);
}
return current.element(name)==null?"":current.element(name).getText();
}
/**
*
* @return
*/
public Element getElement(List<String> directory){
//获取根节点
Element root = document.getRootElement();
Element current=root;
List<String> directoryArr=directory;
for (String dire : directoryArr) {
current=current.element(dire);
}
if(current==null){
throw new RuntimeException("未找到对应节点");
}
return current;
}
/**
*
*/
public List<Element> getJsonByName(){
//获取目录结构
String path = FileUtils.currentPath();
//解析json映射文件
String json = JsonUtils.readJsonFile(path + Codes.JSON_ADDRESS.getMessage());
Map jsonMap = JSON.parseObject(json, Map.class);
//判断是否多条
List<String> basicArr= (List<String>) jsonMap.get("doubleBasic");
List<String> directory= (List<String>) jsonMap.get("basicDirectory");
List<Element> elements=null;
Element root=this.getElement(directory);
for (String basic : basicArr) {
elements=root.elements(basic);
if(elements!=null&&elements.size()>0){
break;
}
}
if(elements==null||elements.size()==0){
//只有一条
List<String> rootDirectory= (List<String>) jsonMap.get("directory");
root = this.getElement(rootDirectory);
elements=new ArrayList<>();
elements.add(root);
}
return elements;
}
/**
*
*

@ -1,5 +1,5 @@
server:
port: 9797
port: 9301
mybatis-plus:
configuration:

Loading…
Cancel
Save