فهرست منبع

Merge branch 'master' of chenweida/esb into master

esb 9 سال پیش
والد
کامیت
4d77461dd4

+ 5 - 0
Hos-Resource-Mini/pom.xml

@ -60,6 +60,11 @@
            <artifactId>json</artifactId>
            <version>20151123</version>
        </dependency>
        <dependency>
            <groupId>xom</groupId>
            <artifactId>xom</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>

+ 20 - 0
Hos-Resource-Mini/src/main/java/com.yihu.ehr/common/constants/Constants.java

@ -69,4 +69,24 @@ public class Constants {
    public static final String MYSQL = "mysql";
    public static final String ORACLE = "oracle";
    public static final String SQLSERVER = "sqlserver";
    //===========================开放接口参数 start=============================
    /**
     * 获取就诊病人列表(GetPatientQueue)
     */
    public static final String GETPATIENTQUEUE="01001";
    /**
     *获取就诊病人档案数据集(GetPatientDataset)
     */
    public static final String GETPATIENTDATASET="01002";
    /**
     * 上传就诊病人档案数据集(PostPatientDataset)
     */
    public static final String POSTPATIENTDATASET="01003";
    // 09开头的都是系统级别
    public static final String SYSTEM_ERROR="09000";
    public static final String SYSTEM_PARAMS="09001";
    public static final String SYSTEM_PARAMS_MESSAGE="参数错误";
    //===========================开放接口参数 end=============================
}

+ 79 - 0
Hos-Resource-Mini/src/main/java/com.yihu.ehr/controller/DataAcquisitionController.java

@ -0,0 +1,79 @@
package com.yihu.ehr.controller;
import com.yihu.ehr.common.constants.Constants;
import com.yihu.ehr.model.RespResult;
import com.yihu.ehr.service.intf.IDataAcquisitionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
/**
 * Created by chenweida on 2016/3/18.
 */
@Controller
@RequestMapping("/dataAcquisition")
public class DataAcquisitionController {
    @Autowired
    private IDataAcquisitionManager dataAcquisitionManager;
    @RequestMapping(value = "/getData")
    @ResponseBody
    public RespResult getData(HttpServletRequest request) throws Exception {
        RespResult r = new RespResult();
        //得到参数
        try {
            String transactionCode = request.getParameter("transactionCode");
            String page = request.getParameter("page");
            String filter = request.getParameter("filter");
            if (!StringUtils.isEmpty(transactionCode)) {
                r.setData(gate(request, transactionCode, page, filter));
            } else {
                r.setRespCode(Constants.SYSTEM_PARAMS);
                r.setRespMessage(Constants.SYSTEM_PARAMS_MESSAGE);
            }
            //根据参数选择业务函数
            r.setTransactionCode(transactionCode);
        } catch (Exception e) {
            r.setRespCode(Constants.SYSTEM_ERROR);
            r.setRespMessage(e.getMessage());
        }
        return r;
    }
    /**
     * 根据参数选择业务函数
     *
     * @param request
     * @param transactionCode
     * @param page
     * @param filter
     * @return
     */
    private String gate(HttpServletRequest request, String transactionCode, String page, String filter) {
        if (Constants.GETPATIENTQUEUE.equals(transactionCode)) {
            //获取就诊病人列表(GetPatientQueue)]
            String beginDate = request.getParameter("beginDate");
            String endDate = request.getParameter("endDate");
            return dataAcquisitionManager.getPatientQueue(beginDate, endDate, page, filter);
        } else if (Constants.GETPATIENTDATASET.equals(transactionCode)) {
            //获取就诊病人档案数据集(GetPatientDataset)
            String patientId = request.getParameter("patientId");
            String eventNo = request.getParameter("eventNo");
            String datasetCode = request.getParameter("datasetCode");
            return dataAcquisitionManager.getPatientDataset(patientId, eventNo, datasetCode);
        } else if (Constants.POSTPATIENTDATASET.equals(transactionCode)) {
            //上传就诊病人档案数据集(PostPatientDataset)
            String patientId = request.getParameter("patientId");
            String eventNo = request.getParameter("eventNo");
            String dataset = request.getParameter("dataset");
            return dataAcquisitionManager.postPatientDataset(patientId, eventNo, dataset);
        }
        return "";
    }
}

+ 57 - 0
Hos-Resource-Mini/src/main/java/com.yihu.ehr/model/RespResult.java

@ -0,0 +1,57 @@
package com.yihu.ehr.model;
/**
 * Created by chenweida on 2016/3/21.
 * 开放接口返回的实体类
 */
public class RespResult {
    String transactionCode;
    String respCode="10000";
    String respMessage="成功";
    String page;
    String data;
    public String getTransactionCode() {
        return transactionCode;
    }
    public void setTransactionCode(String transactionCode) {
        this.transactionCode = transactionCode;
    }
    public String getRespCode() {
        return respCode;
    }
    public void setRespCode(String respCode) {
        this.respCode = respCode;
    }
    public String getRespMessage() {
        return respMessage;
    }
    public void setRespMessage(String respMessage) {
        this.respMessage = respMessage;
    }
    public String getPage() {
        return page;
    }
    public void setPage(String page) {
        this.page = page;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
}

+ 41 - 0
Hos-Resource-Mini/src/main/java/com.yihu.ehr/service/DataAcquisitionManager.java

@ -0,0 +1,41 @@
package com.yihu.ehr.service;
import com.yihu.ehr.service.intf.IDataAcquisitionManager;
import com.yihu.ehr.util.json.JSON;
import org.springframework.stereotype.Service;
import java.io.File;
/**
 * Created by chenweida on 2016/3/18.
 */
@Service("dataAcquisitionManager")
public class DataAcquisitionManager implements IDataAcquisitionManager {
    @Override
    /**
     * 格式YYYY-MM-DD HH:mm:ss
     */
    public String getPatientQueue(String beginDate, String endDate, String page, String filter) {
        return null;
    }
    @Override
    public String getPatientDataset(String patientId, String eventNo, String datasetCode) {
        return null;
    }
    @Override
    public String postPatientDataset(String patientId, String eventNo, String dataset) {
        //转文件
        File f = JSON.json2File(patientId, eventNo, dataset);
        //文件上传
        //删除文件
        f.delete();
        return null;
    }
}

+ 12 - 0
Hos-Resource-Mini/src/main/java/com.yihu.ehr/service/intf/IDataAcquisitionManager.java

@ -0,0 +1,12 @@
package com.yihu.ehr.service.intf;
/**
 * Created by chenweida on 2016/3/18.
 */
public interface IDataAcquisitionManager {
    String getPatientQueue(String beginDate, String endDate,String page,String filter);
    String getPatientDataset(String patientId, String eventNo, String datasetCode);
    String postPatientDataset(String patientId, String eventNo, String dataset);
}

+ 58 - 29
Hos-Resource-Mini/src/main/java/com.yihu.ehr/util/file/FileUtil.java

@ -43,7 +43,7 @@ public class FileUtil {
        return true;
    }
    public static boolean writeFile(String filePath,InputStream fis, String encoding) throws IOException {
    public static boolean writeFile(String filePath, InputStream fis, String encoding) throws IOException {
        File file = new File(filePath);
        if (!file.getParentFile().exists()) {
            if (!file.getParentFile().mkdirs()) {
@ -87,13 +87,14 @@ public class FileUtil {
    /**
     * file转string
     *
     * @param file 文件
     * @return string类型流
     */
    public static String convertFileToString(File file) {
        StringBuilder sb = new StringBuilder();
        if(file.isFile()&&file.exists()) {
        if (file.isFile() && file.exists()) {
            InputStreamReader read = null;
            try {
                read = new InputStreamReader(new FileInputStream(file), "UTF-8");
@ -122,20 +123,19 @@ public class FileUtil {
    }
    /**
     * 清空文件内容
     *
     * @param filePath 文件路径
     * @param content 写入内容
     * @param content  写入内容
     */
    public static void clearInfoForFile(String filePath,String content) {
        File file =new File(filePath);
    public static void clearInfoForFile(String filePath, String content) {
        File file = new File(filePath);
        try {
            if(!file.exists()) {
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fileWriter =new FileWriter(file);
            FileWriter fileWriter = new FileWriter(file);
            fileWriter.write(content);
            fileWriter.flush();
            fileWriter.close();
@ -145,36 +145,34 @@ public class FileUtil {
    }
    /**
     * 记录文件最后读取的位置
     * @param readPath  被读取文件路径
     * @param savePath  保存被读取文件的最后位置 的文件路径
     *
     * @param readPath 被读取文件路径
     * @param savePath 保存被读取文件的最后位置 的文件路径
     */
    public static Integer  saveFilePos(String  readPath,  String  savePath)  {
        boolean result=false;
        File readFile=new File(readPath);
        Integer lenth=null;
        try  {
            if(readFile.exists()){
    public static Integer saveFilePos(String readPath, String savePath) {
        boolean result = false;
        File readFile = new File(readPath);
        Integer lenth = null;
        try {
            if (readFile.exists()) {
                InputStream inputStream = new FileInputStream(readPath);
                lenth = inputStream.available();
                clearInfoForFile(savePath,"");//清空内容
                writeFile(savePath,lenth.toString(),"UTF-8");//重新写入标识
                clearInfoForFile(savePath, "");//清空内容
                writeFile(savePath, lenth.toString(), "UTF-8");//重新写入标识
            }
        }
        catch  (Exception  e)  {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lenth;
    }
    public static Integer getFileSize(String path) {
        Integer size=0;
        InputStream inputStream=null;
        File file=new File(path);
        if (file.exists()){
        Integer size = 0;
        InputStream inputStream = null;
        File file = new File(path);
        if (file.exists()) {
            try {
                inputStream = new FileInputStream(path);
                size = inputStream.available();
@ -182,12 +180,13 @@ public class FileUtil {
                e.printStackTrace();
            }
        }
       return size;
        return size;
    }
    /**
     * 读取文本文件内容
     * @param file  文件路径
     *
     * @param file 文件路径
     * @return
     */
    public static String readFileText(File file) {
@ -215,4 +214,34 @@ public class FileUtil {
        return stringBuilder.toString();
    }
    public static File writeFile(String filePathAndName, String fileContent) {
        File f = new File(filePathAndName);
        OutputStreamWriter write =null;
        BufferedWriter writer=null;
        try {
            if (!f.exists()) {
                f.createNewFile();
            }
             write = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
             writer = new BufferedWriter(write);
             writer.write(fileContent);
        } catch (Exception e) {
            System.out.println("写文件内容操作出错");
            e.printStackTrace();
        }finally {
            try {
                if(writer!=null){
                    writer.close();
                }
                if(write!=null){
                    write.close();
                }
            }catch (Exception e){
                e.printStackTrace();;
            }
        }
        return f;
    }
}

+ 31 - 0
Hos-Resource-Mini/src/main/java/com.yihu.ehr/util/json/JSON.java

@ -0,0 +1,31 @@
package com.yihu.ehr.util.json;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.util.file.FileUtil;
import net.sf.json.JSONObject;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * Created by chenweida on 2016/3/24.
 */
public class JSON {
    public static final String[] key = {"data", "event_no", "patient_id"};
    public static File json2File(String patientId, String eventNo, String dataset) {
        //先转json
        String jsonDataSet = XML2JSON.xml2JSON(dataset);
        JSONObject jo = new JSONObject();
        jo.put(key[0], dataset);
        jo.put(key[1], eventNo);
        jo.put(key[2], patientId);
        String jsonString=jo.toString();
        //json转文件
        String home = System.getProperty("catalina.home").replace('\\', '/');
        SimpleDateFormat sd=new SimpleDateFormat("yyyyMMddHHmmss");
        String filePath=home + File.separator +sd.format(new Date());
        return FileUtil.writeFile(filePath,jsonString);
    }
}

+ 37 - 0
Hos-Resource-Mini/src/main/java/com.yihu.ehr/util/json/XML2JSON.java

@ -0,0 +1,37 @@
package com.yihu.ehr.util.json;
import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;
/**
 * Created by chenweida on 2016/3/24.
 */
public class XML2JSON {
    public static String xml2JSON(String xml) {
        return new XMLSerializer().read(xml).toString();
    }
    public static String json2XML(String json) {
        //json
        JSONObject jobj = JSONObject.fromObject(json);
        String xml = new XMLSerializer().write(jobj);
        return xml;
    }
    public static void main(String[] args) {
        System.out.println(xml2JSON("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Data><PATIENT_ID>病人ID</PATIENT_ID>\n" +
                "\t<EVENT_NO>门诊号(挂号号) / 住院号</EVENT_NO>\n" +
                "\t<HDSD00_05_040>检验报告单号</HDSD00_05_040>\n" +
                "\t<JDSD02_03_02>子项序号</JDSD02_03_02>\n" +
                "\t<JDSD02_03_03>子项的LOINC编码</JDSD02_03_03>\n" +
                "\t<JDSD02_03_13>子项目中文名称</JDSD02_03_13>\n" +
                "\t<JDSD02_03_14>子项目英文名称</JDSD02_03_14>\n" +
                "\t<JDSD02_03_04>结果类型</JDSD02_03_04>\n" +
                "\t<JDSD02_03_05>结果值</JDSD02_03_05>\n" +
                "\t<HDSD00_01_547>单位</HDSD00_01_547>\n" +
                "\t<JDSD02_03_06>正常参考值下限</JDSD02_03_06>\n" +
                "\t<JDSD02_03_07>正常参考值上限</JDSD02_03_07>\n" +
                "\t<JDSD02_03_08>参考值备注</JDSD02_03_08>\n" +
                "\t<JDSD02_03_09>结果值的解释</JDSD02_03_09></Data>"));
    }
}

+ 3 - 0
Hos-Resource-Mini/src/main/resources/config/dataAcquisition.properties

@ -0,0 +1,3 @@
service.url=https://172.19.103.73:443/api/v1.0/
service.clientId = kHAbVppx44
service.clientKey = Bd2h8rdYhep6NKOO

+ 1 - 1
Hos-Resource-Mini/src/main/resources/log4j2.xml

@ -26,7 +26,7 @@
                           pattern='%d{yyyy-MM-dd HH:mm:ss}-- %p %t %c - %m%n'/>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="10 MB"/>
                <SizeBasedTriggeringPolicy size="1 MB"/>
            </Policies>
            <DefaultRolloverStrategy fileIndex="max" max="10"/>
        </RollingFile>

+ 4 - 4
Hos-Resource-Mini/src/main/resources/spring/applicationContext.xml

@ -3,18 +3,17 @@
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"
       >
>
    <!--业务Beans, 使用注解方式配置-->
    <context:component-scan base-package="com.yihu">
@ -44,4 +43,5 @@
    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
    <util:properties id="sys" location="classpath:config/dataAcquisition.properties"/>
</beans>