Browse Source

Merge branch 'dev' of huangzhanpeng/wlyy_management into dev

chenweida 8 years ago
parent
commit
f94444da78

+ 659 - 84
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/record/EhrService.java

@ -1,25 +1,18 @@
package com.yihu.wlyy.service.app.record;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.SystemConf;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.apache.xpath.operations.Bool;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -36,47 +29,63 @@ public class EhrService extends BaseService {
    @Autowired
    ObjectMapper  objectMapper;
    private String ehrUrl = SystemConf.getInstance().getEhrServices();
    private String ehrUrl = SystemConf.getInstance().getEhrServices();   //EHR档案服务地址
    private String ehrBaseUrl = SystemConf.getInstance().getEhrServicesBase(); //EHR底层服务地址
    /**
     * 是否包含该类档案数据
     * 获取档案包含相关细表
     * @param profileId
     * @return
     */
    private Boolean contain(String profileId,String catalogCode)
    private List<String> containTables(String profileId)
    {
        Boolean re = false;
        try {
            String url = "";
            if (catalogCode.equals("0102"))     //门诊费用明细
            {
                re = false; //没数据
            }
            else if (catalogCode.equals("0131"))    //门诊检查报告单
            {
                url = ehrUrl + "/null/examination?profile_id=" + profileId;
            }
            else if (catalogCode.equals("0121"))    //门诊检验报告单
            {
                url = ehrUrl + "/null/laboratory?profile_id=" + profileId;
            }
            else if (catalogCode.equals("0141"))    //门诊用药记录
            {
                re = false; //业务不合
            }
            else if (catalogCode.equals("0116"))    //门诊手术记录
        List<String>  re = new ArrayList<>();
        String params = "{\"profile_id\":\""+profileId+"\"}";
        String response = HttpClientUtil.get(ehrBaseUrl + "resources/query/sub_data?queryParams="+URLEncoder.encode(params), "UTF-8");
        JSONObject obj = new JSONObject(response);
        if(obj.has("detailModelList") && obj.getInt("totalCount")>0)
        {
            JSONArray array = obj.getJSONArray("detailModelList");
            if(array!=null && array.length()>0)
            {
                re = false;
               for(int i=0;i<array.length();i++)
               {
                   JSONObject item = array.getJSONObject(i);
                   String rowkey = item.getString("rowkey");
                   String table = rowkey.substring(rowkey.indexOf("$")+1);
                   table =  table.substring(0,table.indexOf("$"));
                   if(!re.contains(table))
                   {
                       re.add(table);
                   }
               }
            }
        }
        return re;
    }
            if(StringUtils.isEmpty(url))
    /**
     * 事件基本信息 (主表)
     */
    private JSONObject getEventBaseInfo(String profileId){
        JSONObject re = null;
        try {
            String params = "{\"q\":\"rowkey:"+profileId+"\"}";
            String url = ehrBaseUrl + "resources/query/master_data?queryParams="+URLEncoder.encode(params);
            String response = HttpClientUtil.get(url, "UTF-8");
            JSONObject obj = new JSONObject(response);
            if(obj.has("detailModelList") && obj.getInt("totalCount")>0)    //obj.getBoolean("successFlg") &&
            {
                String response = HttpClientUtil.get(url, "UTF-8");
                JSONObject obj = new JSONObject(response);
                if(obj.getBoolean("successFlg") && obj.getInt("totalCount")>0)
                JSONArray array = obj.getJSONArray("detailModelList");
                if(array!=null && array.length()>0)
                {
                    re = true;
                    re = array.getJSONObject(0);
                }
            }
        }
        catch (Exception ex)
        {
@ -86,7 +95,7 @@ public class EhrService extends BaseService {
        return re;
    }
    /*****************************************************************************************************************/
    /**
     * 获取门诊记录
     */
@ -102,35 +111,38 @@ public class EhrService extends BaseService {
            for (int i=0; i<jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                JSONObject item = new JSONObject();
                item.put("END_TIME",jsonObject.has("EHR_000065")?jsonObject.get("EHR_000065"):jsonObject.get("event_date")); //就诊时间
                item.put("ORG_NAME",jsonObject.get("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.get("org_code")); //机构代码
                item.put("END_TIME",jsonObject.has("EHR_000065")?jsonObject.optString("EHR_000065"):jsonObject.optString("event_date")); //就诊时间
                item.put("ORG_NAME",jsonObject.optString("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.optString("org_code")); //机构代码
                item.put("UNIONSSID",strSSID); //社保卡号
                item.put("NAME",jsonObject.get("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.get("event_no")); //事件号
                item.put("NAME",jsonObject.optString("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.optString("event_no")); //事件号
                String profileId = jsonObject.getString("rowkey");
                item.put("SERIAL",profileId); //rowkey
                //包含模板
                JSONObject catalog = new JSONObject();
                catalog.put("0101","门诊基本诊疗信息");
                List<String> tables = containTables(profileId);
                //判断是否有费用
                if(contain(profileId,"0102")){
                if(tables.contains("HDSC01_07")){
                    catalog.put("0102","门诊费用明细");
                }
                //判断是否有检查报告
                if(contain(profileId,"0131")){
                if(tables.contains("HDSD01_01")){
                    catalog.put("0131","门诊检查报告单");
                }
                //判断是否有检验报告
                if(contain(profileId,"0121")){
                if(tables.contains("HDSD02_01")){
                    catalog.put("0121","门诊检验报告单");
                }
                //判断是否有检验报告
                if(contain(profileId,"0141")){
                //判断是否有门诊用药记录
                if(tables.contains("HDSC01_09")){
                    catalog.put("0141","门诊用药记录");
                }
                if(contain(profileId,"0116")){
                if(tables.contains("HDSD02_05")){
                    catalog.put("0116","门诊手术记录");
                }
@ -161,55 +173,55 @@ public class EhrService extends BaseService {
            for (int i=0; i<jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                JSONObject item = new JSONObject();
                item.put("END_TIME",jsonObject.has("EHR_000230")?jsonObject.get("EHR_000230"):jsonObject.get("event_date")); //入院时间
                item.put("ORG_NAME",jsonObject.get("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.get("org_code")); //机构代码
                item.put("END_TIME",jsonObject.has("EHR_000230")?jsonObject.optString("EHR_000230"):jsonObject.optString("event_date")); //入院时间
                item.put("ORG_NAME",jsonObject.optString("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.optString("org_code")); //机构代码
                item.put("UNIONSSID",strSSID); //社保卡号
                item.put("NAME",jsonObject.get("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.get("event_no")); //事件号
                String profileId = jsonObject.getString("rowkey");
                item.put("NAME",jsonObject.optString("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.optString("event_no")); //事件号
                String profileId = jsonObject.optString("rowkey");
                item.put("SERIAL",profileId); //rowkey
                //包含模板
                JSONObject catalog = new JSONObject();
                catalog.put("0201","住院诊疗基本信息");
                //catalog.put("0212","入院病历记录");
                if(contain(profileId,"0202")){
                    catalog.put("0202","住院费用明细");
                }
                List<String> tables = containTables(profileId);
                if(contain(profileId,"0211")){
                    catalog.put("0211","住院病案首页");
                }
                if(contain(profileId,"0212")){
                    catalog.put("0212","入院病历记录");
                if(tables.contains("HDSC02_04")){
                    catalog.put("0202","住院费用明细");
                }
                if(contain(profileId,"0213")){
                if(tables.contains("HDSC02_14")){
                    catalog.put("0213","出院小结");
                }
                if(contain(profileId,"0215")){
                if(tables.contains("HDSC02_12")){
                    catalog.put("0214","长期医嘱");
                }
                if(tables.contains("HDSC02_11")){
                    catalog.put("0215","临时医嘱");
                }
                if(contain(profileId,"0216")){
                if(tables.contains("HDSD02_05")){
                    catalog.put("0216","住院手术记录");
                }
                if(contain(profileId,"0217")){
                if(tables.contains("HDSC02_15")){
                    catalog.put("0217","死亡记录");
                }
                if(contain(profileId,"0221")){
                if(tables.contains("HDSD02_01")){
                    catalog.put("0221","住院检验报告");
                }
                if(contain(profileId,"0231")){
                if(tables.contains("HDSD01_01")){
                    catalog.put("0231","住院检查报告");
                }
                if(contain(profileId,"0241")){
                if(tables.contains("HDSC01_09")){
                    catalog.put("0241","住院用药记录");
                }
@ -225,26 +237,72 @@ public class EhrService extends BaseService {
        }
    }
    /**
     * 获取检查报告
     * 获取检查检验列表
     */
    public List<Map<String,String>> examination(String idcard) {
        List<Map<String,String>> list = null;
        try {
            String url = ehrUrl + idcard + "/examination?demographic_id=" + idcard;
    public String getInspectionAndChecking(String strSSID)
    {
        //通过ssid获取身份证
        Patient patient = patientDao.findBySsc(strSSID);
        if(patient!=null) {
            String url = ehrUrl + patient.getIdcard() +"/profile/medical_events?demographic_id=" + patient.getIdcard();
            String response = HttpClientUtil.get(url, "UTF-8");
            Map<String, Object> map = objectMapper.readValue(response, Map.class);
            JSONArray jsonArray = new JSONArray(response);
            JSONArray resultArray = new JSONArray();
            for (int i=0; i<jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
            list = (List<Map<String,String>>)map.get("detailModelList");
                JSONObject item = new JSONObject();
                item.put("END_TIME",jsonObject.has("EHR_000230")?jsonObject.optString("EHR_000230"):jsonObject.optString("event_date")); //入院时间
                item.put("ORG_NAME",jsonObject.optString("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.optString("org_code")); //机构代码
                item.put("UNIONSSID",strSSID); //社保卡号
                item.put("NAME",jsonObject.optString("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.optString("event_no")); //事件号
                String profileId = jsonObject.optString("rowkey");
                item.put("SERIAL",profileId); //rowkey
                //包含模板
                JSONObject catalog = new JSONObject();
                List<String> tables = containTables(profileId);
                //0门诊 1住院
                String eventType =  jsonObject.optString("event_type");
                if(eventType.equals("0"))
                {
                    //判断是否有检查报告
                    if(tables.contains("HDSD01_01")){
                        catalog.put("0131","门诊检查报告单");
                    }
                    //判断是否有检验报告
                    if(tables.contains("HDSD02_01")){
                        catalog.put("0121","门诊检验报告单");
                    }
                }
                else if(eventType.equals("1")){
                    if(tables.contains("HDSD02_01")){
                        catalog.put("0221","住院检验报告");
                    }
                    if(tables.contains("HDSD01_01")){
                        catalog.put("0231","住院检查报告");
                    }
                }
                if(catalog.length()>0) {
                    item.put("CATALOG", catalog); //档案类别
                    resultArray.put(item);
                }
            }
            return resultArray.toString();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        else{
            return "[]";
        }
        return list;
    }
    /**
     * 检验报告单
     */
@ -268,8 +326,525 @@ public class EhrService extends BaseService {
    /**
     * 用药记录
     */
    public String getInspectionAndChecking(String idcard) {
    public String getDrugsList(String idcard) {
        String url = ehrUrl + idcard +"/laboratory?demographic_id="+idcard;
        return HttpClientUtil.get(url, "UTF-8");
    }
    /**
     * 获取档案数据
     * @return
     */
    public String getHealthData(String strSSID,String strEvent,String strCatalog,String strSerial)
    {
        String re = "";
        try {
            /******************************** 主表数据 ********************************************************/
            if (strCatalog.equals("0101")) {     //门诊基本诊疗信息
                return get0101(strSSID,strSerial);
            }
            else if (strCatalog.equals("0201")) {   //住院诊疗基本信息
                return get0201(strSSID,strSerial);
            }
            /******************************** 细表数据 ********************************************************/
            else if (strCatalog.equals("0102")) {   //门诊费用明细
            }
            else if (strCatalog.equals("0131")) {   //门诊检查报告单
                return getExamination(strSSID,strSerial,"0131");
            }
            else if (strCatalog.equals("0121")) {   //门诊检验报告单
                return get0201(strSSID,strSerial);
            }
            else if (strCatalog.equals("0141")) {   //门诊用药记录
            }
            else if (strCatalog.equals("0116")) {   //门诊手术记录
            }
            else if (strCatalog.equals("0202")) {   //住院费用明细
            }
            else if (strCatalog.equals("0213")) {   //出院小结
            }
            else if (strCatalog.equals("0214")) {   //长期医嘱
            }
            else if (strCatalog.equals("0215")) {   //临时医嘱
            }
            else if (strCatalog.equals("0216")) {   //住院手术记录
            }
            else if (strCatalog.equals("0217")) {   //死亡记录
            }
            else if (strCatalog.equals("0221")) {   //住院检验报告
            }
            else if (strCatalog.equals("0231")) {   //住院检查报告
                return getExamination(strSSID,strSerial,"0131");
            }
            else if (strCatalog.equals("0241")) {   //住院用药记录
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        return re;
    }
    //门诊基本诊疗信息
    public String get0101(String ssid,String profileId)
    {
        //事件主要信息
        JSONObject info = getEventBaseInfo(profileId);
        if(info!=null) {
            //门诊症状
            String symptomUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/outpatient/symptom?profile_id=" + profileId;
            String symptomResponse = HttpClientUtil.get(symptomUrl, "UTF-8");
            JSONObject symptomObj = new JSONObject(symptomResponse);
            String symptomString = "";
            if (symptomObj.getBoolean("successFlg") && symptomObj.getInt("totalCount") > 0) {
                JSONArray array = symptomObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        symptomString += "<item code=\"" + item.optString("EHR_001204") + "\" codeSystem=\"CV5101.27\">" + item.optString("EHR_001204_VALUE")+ "</item>\n";
                    }
                }
            }
            //门诊诊断
            String diagnosisUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/outpatient/diagnosis?profile_id=" + profileId;
            String diagnosisResponse = HttpClientUtil.get(diagnosisUrl, "UTF-8");
            JSONObject diagnosisObj = new JSONObject(diagnosisResponse);
            String diagnosisString = "";
            if (diagnosisObj.getBoolean("successFlg") && diagnosisObj.getInt("totalCount") > 0) {
                JSONArray array = diagnosisObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        diagnosisString += "<item>\n" +
                                "            <icd code=\"诊断icd10(字典STD_ICD)\" codeSystem=\"ICD-10\">疾病诊断名称</icd>\n" +
                                "            <result code=\"" + item.optString("EHR_000110") + "\" codeSystem=\"CV5501.11\">诊疗结果</result>\n" +
                                "            <prop code=\"" + item.optString("EHR_000111") + "\" codeSystem=\"STD_DIAGNOSIS_PROP\">诊断性质</prop>\n" +
                                "</item>\n";
                    }
                }
            }
            String re = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<ClinicalDocument>\n" +
                    "  <version code=\"2.0.0.0\" date=\"2009-12-01\">根据卫生部标准第一次修订</version>\n" +
                    "  <ehr code=\"0101\" codeSystem=\"STD_EHR\">门诊基本诊疗信息</ehr>\n" +
                    "  <title>门诊基本诊疗信息</title>\n" +
                    "  <org code=\"" + info.optString("org_code") + "\" codeSystem=\"STD_HEALTH_ORG\">"+info.optString("org_name")+"</org>\n" +
                    "  <id extension=\"" + profileId + "\" eventno=\"" + info.optString("event_no") + "\"></id>\n" +
                    "  <effectiveTime value=\"" + info.optString("create_date") + "\"/>\n" +
                    "  <recordTarget>\n" +
                    "    <patient>\n" +
                    "      <id extension=\"" + ssid + "\"></id>\n" +
                    "      <name>" + info.optString("EHR_000004") + "</name>\n" +
                    "      <sex code=\"" + info.optString("EHR_000019") + "\" codeSystem=\"GB/T2261.1-2003\">" + info.optString("EHR_000019_VALUE")  + "</sex>\n" +
                    "      <birthDate>" + info.optString("EHR_000007") + "</birthDate>\n" +
                    "      <marriage code=\"" + info.optString("EHR_000014") + "\" codeSystem=\"GB/T 2261.2-2003\">" + info.optString("EHR_000014_VALUE")+ "</marriage>\n" +
                    "    </patient>\n" +
                    "  </recordTarget>\n" +
                    "  <component>\n" +
                    "    <section>\n" +
                    "      <code code=\"common\" codeSystem=\"\"  displayName=\"门诊基本诊疗信息\"/>\n" +
                    "      <entry>\n" +
                    "        <onsetTime>" + info.optString("EHR_000065") + "</onsetTime>\n" +
                    "        <treatTime>" + info.optString("EHR_000065") + "</treatTime>\n" +
                    "        <diagnosisDate>" + info.optString("EHR_000065") + "</diagnosisDate>\n" +
                    "        <reg>\n" +
                    "          <value>" + info.optString("EHR_000068") + "</value>\n" +
                    "          <type code=\"【挂号类别代码(字典STD_REG_TYPE)】\" codeSystem=\"STD_REG_TYPE\">【挂号类别名称】</type>\n" +
                    "        </reg>\n" +
                    "        <sec>\n" +
                    "          <value>保险号</value>\n" +
                    "          <type code=\"【保险类别代码(字典STD_SEC_TYPE)】\" codeSystem=\"STD_SEC_TYPE\">【保险类别名称】</type>\n" +
                    "        </sec>\n" +
                    "        <dept code=\"" + info.optString("EHR_000081") + "\" codeSystem=\"GB/T 17538-1998\">" + info.optString("EHR_000082") + "</dept>\n" +
                    "        <doctor>\n" +
                    "          <id extension=\"" + info.optString("EHR_000080") + "\"/>\n" +
                    "          <name>" + info.optString("EHR_000079") + "</name>\n" +
                    "          <title code=\"【职称代码(字典STD_TECH_TITLE)】\" codeSystem=\"GB/T 8561-1988\">【职称名称】</title>\n" +
                    "        </doctor>\n" +
                    "        <symptom>\n" +
                    symptomString +
                    "        </symptom>\n" +
                    "        <diagnosis>\n" +
                    diagnosisString +
                    "        </diagnosis>\n" +
                    "      </entry>\n" +
                    "    </section>\n" +
                    "  </component>\n" +
                    "</ClinicalDocument>";
            return re;
        }
        else{
            return "";
        }
    }
    //住院诊疗基本信息
    public String get0201(String ssid,String profileId)
    {
        //事件主要信息
        JSONObject info = getEventBaseInfo(profileId);
        if(info!=null) {
            //住院症状
            String symptomUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/hospitalized/symptom?profile_id=" + profileId;
            String symptomResponse = HttpClientUtil.get(symptomUrl, "UTF-8");
            JSONObject symptomObj = new JSONObject(symptomResponse);
            String symptomString = "";
            if (symptomObj.getBoolean("successFlg") && symptomObj.getInt("totalCount") > 0) {
                JSONArray array = symptomObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        symptomString += "<item code=\"" + item.optString("EHR_000301") + "\" codeSystem=\"CV5101.27\">" + item.optString("EHR_000302") + "</item>\n";
                    }
                }
            }
            //住院诊断
            String diagnosisUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/hospitalized/diagnosis?profile_id=" + profileId;
            String diagnosisResponse = HttpClientUtil.get(diagnosisUrl, "UTF-8");
            JSONObject diagnosisObj = new JSONObject(diagnosisResponse);
            String diagnosisString = "";
            if (diagnosisObj.getBoolean("successFlg") && diagnosisObj.getInt("totalCount") > 0) {
                JSONArray array = diagnosisObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        diagnosisString +="<item>\n" +
                                        "      <icd code=\""+item.optString("EHR_000293")+"\" codeSystem=\"ICD-10\">"+item.optString("EHR_000295")+"</icd>\n" +
                                        "</item>\n";
                    }
                }
            }
            String re = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<ClinicalDocument>\n" +
                    "  <version code=\"2.0.0.1\" date=\"2011-06-01\">根据卫生部标准第2次修订</version>\n" +
                    "  <ehr code=\"0201\" codeSystem=\"STD_EHR\">住院诊疗基本信息</ehr>\n" +
                    "  <title>住院诊疗基本信息</title>\n" +
                    "  <org code=\""+info.optString("org_code") +"\" codeSystem=\"STD_HEALTH_ORG\">"+info.optString("org_name") +"</org>\n" +
                    "  <id extension=\"" + profileId + "\" eventno=\"" + info.optString("event_no") + "\"></id>\n" +
                    "  <effectiveTime value=\"" + info.optString("create_date") + "\"/>\n" +
                    "  <recordTarget>\n" +
                    "    <patient>\n" +
                    "      <id extension=\""+ssid+"\"></id>\n" +
                    "      <name>"+info.optString("EHR_000004")+"</name>\n" +
                    "      <sex code=\"" + info.optString("EHR_000019") + "\" codeSystem=\"GB/T2261.1-2003\">" + info.optString("EHR_000019_VALUE") + "</sex>\n" +
                    "      <birthDate>" + info.optString("EHR_000007") + "</birthDate>\n" +
                    "      <marriage code=\"" + info.optString("EHR_000014") + "\" codeSystem=\"GB/T 2261.2-2003\">" + info.optString("EHR_000014_VALUE") + "</marriage>\n" +
                    "    </patient>\n" +
                    "  </recordTarget>\n" +
                    "  <component>\n" +
                    "    <section>\n" +
                    "      <code code=\"common\" codeSystem=\"\" displayName=\"住院诊疗基本信息\"/>\n" +
                    "      <entry>\n" +
                    "        <residence>\n" +
                    "          <serial>"+info.optString("EHR_000234") +"</serial>\n" +
                    "          <code>"+info.optString("EHR_000236")+"</code>\n" +
                    "        </residence>\n" +
                    "        <sec>\n" +
                    "          <type code=\"【保险类别(字典STD_SEC_TYPE)】\" codeSystem=\"STD_SEC_TYPE\">【保险类别名称】</type>\n" +
                    "          <value>"+info.optString("EHR_000232")+"</value>\n" +
                    "        </sec>\n" +
                    "        <in>\n" +
                    "          <time>"+info.optString("EHR_000230")+"</time>\n" +
                    "          <dept code=\""+info.optString("EHR_000228")+"\" codeSystem=\"GB/T 17538-1998\">"+info.optString("EHR_000229")+"</dept>\n" +
                    "          <bed>"+info.optString("EHR_000227")+"</bed>\n" +
                    "        </in>\n" +
                    "        <move>\n" +
                    //EHR转诊业务有问题
                    /*"          <item>\n" +
                    "            <time>转科时间</time>\n" +
                    "            <dept code=\"转科科室代码(字典STD_DEPT)\" codeSystem=\"GB/T 17538-1998\">转科后科室名称</dept>\n" +
                    "            <bed>转科后床号</bed>\n" +
                    "          </item>\n" +*/
                    "        </move>\n" +
                    "        <out>\n" +
                    "          <time>"+info.optString("EHR_000224")+"</time>\n" +
                    "          <dept code=\""+info.optString("EHR_000222")+"\" codeSystem=\"GB/T 17538-1998\">"+info.optString("EHR_000223")+"</dept>\n" +
                    "          <bed>"+info.optString("EHR_000221")+"</bed>\n" +
                    "        </out>\n" +
                    "        <onsetTime>"+info.optString("EHR_000230")+"</onsetTime>\n" +
                    "        <diagnosisDate>"+info.optString("EHR_000230")+"</diagnosisDate>\n" +
                    "        <cause code=\""+info.optString("EHR_000237")+"\" codeSystem=\"CV5401.04\">"+info.optString("EHR_000237_VALUE")+"</cause>\n" +
                    "       <symptom>\n" +
                    symptomString +
                    "        </symptom>\n" +
                    "        <illStatus code=\""+info.optString("EHR_000239")+"\" codeSystem=\"CV5502.18\">"+info.optString("EHR_000239_VALUE")+"</illStatus>\n" +
                    "        <infectiousStatus code=\""+info.optString("EHR_000238")+"\" codeSystem=\"STD_JUDGE\">"+info.optString("EHR_000238_VALUE")+"</infectiousStatus>\n" +
                    "        <inDiagnosis>\n" +
                    diagnosisString+
                    "        </inDiagnosis>\n" +
                    "        <outDiagnosis>\n" +
                    "          <item>\n" +
                    "            <icd code=\""+info.optString("EHR_000158")+"\" codeSystem=\"ICD-10\">"+info.optString("EHR_000159")+"</icd>\n" +
                    "            <result code=\""+info.optString("EHR_000166")+"\" codeSystem=\"CV5501.11\">"+info.optString("EHR_000166_VALUE")+"</result>\n" +
                    "            <prop code=\"【诊断性质代码(字典STD_DIAGNOSIS_PROP)】\" codeSystem=\"STD_DIAGNOSIS_PROP\">【诊断性质名称】</prop>\n" +
                    "          </item>\n" +
                    "        </outDiagnosis>\n" +
                    "        <deathTime>"+info.optString("EHR_000255")+"</deathTime>\n" +
                    "        <causeOfDeath code=\""+info.optString("EHR_000258")+"\" codeSystem=\"ICD-10\">"+info.optString("EHR_000258_VALUE")+"</causeOfDeath>\n" +
                    "      </entry>\n" +
                    "    </section>\n" +
                    "  </component>\n" +
                    "</ClinicalDocument>";
            return re;
        }
        else{
            return "";
        }
    }
    //检查报告单(取第一条)
    public String getExamination(String ssid,String profileId,String catalog)
    {
        String re = "";
        //事件主要信息
        JSONObject info = getEventBaseInfo(profileId);
        String catalogName = "";
        if(catalog.equals("0131"))
        {
            catalogName = "门诊检查报告单";
        }
        else if(catalog.equals("0231"))
        {
            catalogName = "住院检查报告";
        }
        if(info!=null) {
            //获取检查报告
            String url = ehrUrl + URLEncoder.encode("{demographic_id}")+"/examination?profile_id=" + profileId;
            String response = HttpClientUtil.get(url, "UTF-8");
            JSONObject json = new JSONObject(response);
            if (json.getBoolean("successFlg") && json.getInt("totalCount") > 0) {
                JSONArray array = json.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    JSONObject obj = array.getJSONObject(0);
                    re = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                            "<ClinicalDocument>\n" +
                            "  <version code=\"2.0.0.0\" date=\"2009-12-01\">根据卫生部标准第一次修订</version>\n" +
                            "  <ehr code=\""+catalog+"\" codeSystem=\"STD_EHR\">"+catalogName+"</ehr>\n" +
                            "  <title>"+catalogName+"</title>\n" +
                            "  <org code=\""+info.optString("org_code") +"\" codeSystem=\"STD_HEALTH_ORG\">"+info.optString("org_name") +"</org>\n" +
                            "  <id extension=\"" + profileId + "\" eventno=\"" + info.optString("event_no") + "\"></id>\n" +
                            "  <effectiveTime value=\"" + info.optString("create_date") + "\"/>\n" +
                            "  <recordTarget>\n" +
                            "    <patient>\n" +
                            "      <id extension=\""+ssid+"\"></id>\n" +
                            "      <name>"+info.optString("EHR_000004")+"</name>\n" +
                            "      <sex code=\"" + info.optString("EHR_000019") + "\" codeSystem=\"GB/T2261.1-2003\">" + info.optString("EHR_000019_VALUE") + "</sex>\n" +
                            "      <birthDate>" + info.optString("EHR_000007") + "</birthDate>\n" +
                            "      <marriage code=\"" + info.optString("EHR_000014") + "\" codeSystem=\"GB/T 2261.2-2003\">" + info.optString("EHR_000014_VALUE") + "</marriage>\n" +
                            "    </patient>\n" +
                            "  </recordTarget>\n" +
                            "  <author>\n" +
                            "    <time>"+obj.optString("EHR_000318")+"</time>\n" +
                            "    <id extension=\""+obj.optString("EHR_000345")+"\"/>\n" +
                            "    <name>【报告者:姓名】</name>\n" +
                            "  </author>\n" +
                            "  <authenticator>\n" +
                            "    <time>"+obj.optString("EHR_000341")+"</time>\n" +
                            "    <id extension=\""+obj.optString("EHR_000340")+"\"/>\n" +
                            "    <name>"+obj.optString("EHR_000342")+"</name>\n" +
                            "  </authenticator>\n" +
                            "  <participant>\n" +
                            "    <time>"+obj.optString("EHR_000338")+"</time>\n" +
                            "    <id extension=\""+obj.optString("EHR_000337")+"\"/>\n" +
                            "    <name>"+obj.optString("EHR_000339")+"</name>\n" +
                            "    <dept>"+obj.optString("EHR_000336")+"</dept>\n" +
                            "  </participant>\n" +
                            "  <inFulfillmentOf>\n" +
                            "    <order>\n" +
                            "      <id>"+obj.optString("EHR_000323")+"</id>\n" +
                            "      <priority code=\""+obj.optString("EHR_000324")+"\" codeSystem=\"HL7 27\">"+obj.optString("EHR_000324_VALUE")+"</priority>\n" +
                            "    </order>\n" +
                            "  </inFulfillmentOf>\n" +
                            "  <component>\n" +
                            "    <section>\n" +
                            "      <code code=\""+obj.optString("EHR_000330")+"\" displayName=\""+obj.optString("EHR_000330_VALUE")+"\" bodyPartCode=\""+obj.optString("EHR_000326")+"\" bodyPartName=\""+obj.optString("EHR_000326_VALUE")+"\" examCode=\""+obj.optString("EHR_000333")+"\" examName=\""+obj.optString("EHR_000333_VALUE")+"\"/>\n" +
                            "      <recognition code=\""+obj.optString("EHR_000334")+"\" codesystem=\"STD_LAB_EXAM_RECOGNITION\"/>\n" +
                            "      <entry>\n" +
                            "        <performer>\n" +
                            "          <assignedEntity>"+obj.optString("EHR_000327")+"</assignedEntity>\n" +
                            "          <name>"+obj.optString("EHR_000329")+"</name>\n" +
                            "          <time>"+obj.optString("EHR_000328")+"</time>\n" +
                            "        </performer>\n" +
                            "        <playingDevice>\n" +
                            "          <name>【检查设备名称】</name>\n" +
                            "        </playingDevice>\n" +
                            "        <clinicDiagnosis>"+obj.optString("EHR_000335")+"</clinicDiagnosis>\n" +
                            "        <patientCondition>"+obj.optString("EHR_000319")+"</patientCondition>\n" +
                            "        <examCause>"+obj.optString("EHR_000331")+"</examCause>\n" +
                            "        <description>"+obj.optString("EHR_000348")+"</description>\n" +
                            "        <isAbnormal code=\""+obj.optString("EHR_000344")+"\" codeSystem=\"\">"+(obj.optString("EHR_000344").equals("Y")?"Y":"N")+"</isAbnormal>\n" +
                            "      </entry>\n" +
                            "    </section>\n" +
                            "  </component>\n" +
                            "</ClinicalDocument>";
                }
            }
        }
        return re;
    }
    //检验报告单(取第一条)
    public String getLaboratory(String ssid,String profileId,String catalog)
    {
        String re = "";
        //事件主要信息
        JSONObject info = getEventBaseInfo(profileId);
        String catalogName = "";
        if(catalog.equals("0121"))
        {
            catalogName = "门诊检验报告单";
        }
        else if(catalog.equals("0221"))
        {
            catalogName = "住院检验报告";
        }
        if(info!=null) {
            //获取检查报告
            String url = ehrUrl + URLEncoder.encode("{demographic_id}")+"/laboratory?profile_id=" + profileId;
            String response = HttpClientUtil.get(url, "UTF-8");
            JSONObject json = new JSONObject(response);
            if (json.getBoolean("successFlg") && json.getInt("totalCount") > 0) {
                JSONArray array = json.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    JSONObject obj = array.getJSONObject(0);
                    //检验报告项目
                    String observationUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/laboratory/project?profile_id=" + profileId;
                    String observationResponse = HttpClientUtil.get(observationUrl, "UTF-8");
                    JSONObject observationJson = new JSONObject(observationResponse);
                    String observationString  = "";
                    if (observationJson.getBoolean("successFlg") && observationJson.getInt("totalCount") > 0) {
                        JSONArray observationArray = observationJson.getJSONArray("detailModelList");
                        if (observationArray != null && observationArray.length() > 0) {
                            for (int i = 0; i < observationArray.length(); i++) {
                                JSONObject item = observationArray.getJSONObject(i);
                                observationString +="<observation>\n" +
                                        "          <code code=\""+item.optString("EHR_000392")+"\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\""+item.optString("EHR_000392_VALUE")+"\"/>\n" +
                                        "          <recognition code=\""+item.optString("EHR_000389")+"\" codesystem=\"STD_LAB_EXAM_RECOGNITION\"/>\n" +
                                        "          <type code=\""+item.optString("EHR_000386")+"\" codeSystem=\"STD_OBSERVATION_TYPE\">"+item.optString("EHR_000386_VALUE")+"</type>\n" +
                                        "          <value>"+item.optString("EHR_000387")+"</value>\n" +
                                        "          <unit>"+item.optString("EHR_000383")+"</unit>\n" +
                                        "          <referenceRange>\n" +
                                        "            <observationRange>\n" +
                                        "              <notes>"+item.optString("EHR_000382")+"</notes>\n" +
                                        "              <low>\n" +
                                        "                <value>"+item.optString("EHR_000391")+"</value>\n" +
                                        "                <unit>"+item.optString("EHR_000383")+"</unit>\n" +
                                        "              </low>\n" +
                                        "              <high>\n" +
                                        "                <value>"+item.optString("EHR_000390")+"</value>\n" +
                                        "                <unit>"+item.optString("EHR_000383")+"</unit>\n" +
                                        "              </high>\n" +
                                        "            </observationRange>\n" +
                                        "          </referenceRange>\n" +
                                        "          <effectiveTime>"+item.optString("EHR_000384")+"</effectiveTime>\n" +
                                        "          <interpretationCode code=\""+item.optString("EHR_000388")+"\" codeSystem=\"2.16.840.1.113883.5.83\">"+item.optString("EHR_000388_VALUE")+"</interpretationCode>\n" +
                                        "        </observation>\n" ;
                            }
                        }
                    }
                    re = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                            "<ClinicalDocument>\n" +
                            "  <version code=\"2.0.0.0\" date=\"2009-12-01\">根据卫生部标准第一次修订</version>\n" +
                            "  <ehr code=\""+catalog+"\" codeSystem=\"STD_EHR\">"+catalogName+"</ehr>\n" +
                            "  <title>"+catalogName+"</title>\n" +
                            "  <org code=\""+info.optString("org_code") +"\" codeSystem=\"STD_HEALTH_ORG\">"+info.optString("org_name") +"</org>\n" +
                            "  <id extension=\"" + profileId + "\" eventno=\"" + info.optString("event_no") + "\"></id>\n" +
                            "  <effectiveTime value=\"" + info.optString("create_date") + "\"/>\n" +
                            "  <recordTarget>\n" +
                            "    <patient>\n" +
                            "      <id extension=\""+ssid+"\"></id>\n" +
                            "      <name>"+info.optString("EHR_000004")+"</name>\n" +
                            "      <sex code=\"" + info.optString("EHR_000019") + "\" codeSystem=\"GB/T2261.1-2003\">" + info.optString("EHR_000019_VALUE") + "</sex>\n" +
                            "      <birthDate>" + info.optString("EHR_000007") + "</birthDate>\n" +
                            "      <marriage code=\"" + info.optString("EHR_000014") + "\" codeSystem=\"GB/T 2261.2-2003\">" + info.optString("EHR_000014_VALUE") + "</marriage>\n" +
                            "    </patient>\n" +
                            "  </recordTarget>\n" +
                            "  <author>\n" +
                            "    <time>" + obj.optString("EHR_000379") + "</time>\n" +
                            "    <id extension=\""+ obj.optString("EHR_000377") + "\"/>\n" +
                            "    <name>"+ obj.optString("EHR_000378") +"</name>\n" +
                            "  </author>\n" +
                            "  <authenticator>\n" +
                            "    <time>"+ obj.optString("EHR_000375") +"</time>\n" +
                            "    <id extension=\""+ obj.optString("EHR_000374") +"\"/>\n" +
                            "    <name>"+ obj.optString("EHR_000376") +"</name>\n" +
                            "  </authenticator>\n" +
                            "  <participant>\n" +
                            "    <time>"+ obj.optString("EHR_000372") +"</time>\n" +
                            "    <id extension=\""+ obj.optString("EHR_000370") +"\"/>\n" +
                            "    <name>"+ obj.optString("EHR_000373") +"</name>\n" +
                            "    <dept>"+ obj.optString("EHR_000371") +"</dept>\n" +
                            "  </participant>\n" +
                            "  <inFulfillmentOf>\n" +
                            "    <order>\n" +
                            "      <id>"+ obj.optString("EHR_000360") +"</id>\n" +
                            "      <priority code=\""+ obj.optString("EHR_000361") +"\" codeSystem=\"HL7 27\">"+ obj.optString("EHR_000361_VALUE") +"</priority>\n" +
                            "    </order>\n" +
                            "  </inFulfillmentOf> \n" +
                            "  <component>\n" +
                            "    <section>\n" +
                            "      <code code=\"【检验的专业类型编码(字典STD_LAB_EXAM_TYPE)】\" codeSystem=\"2.16.840.1.113883.6.1\"  displayName=\"【检验的专业类型名称】\"/>\n" +
                            "      <entry>\n" +
                            "        <id>"+ obj.optString("EHR_000354") +"</id>\n" +
                            "        <performer>\n" +
                            "          <assignedEntity>"+ obj.optString("EHR_000365") +"</assignedEntity>\n" +
                            "          <name>"+ obj.optString("EHR_000367") +"</name>\n" +
                            "          <time>"+ obj.optString("EHR_000366") +"</time>\n" +
                            "        </performer>\n" +
                            "        <classCode>"+ obj.optString("EHR_000357") +"</classCode>\n" +
                            "        <specimenDeterminer code=\""+ obj.optString("EHR_000355") +"\" codeSystem=\"HL7 0163\">"+ obj.optString("EHR_000355_VALUE") +"</specimenDeterminer>\n" +
                            "        <risk code=\""+ obj.optString("EHR_000358") +"\" codeSystem=\"HL7 0489\">"+ obj.optString("EHR_000358_VALUE") +"</risk>\n" +
                            "        <quantity code=\""+ obj.optString("EHR_000359") +"\" codeSystem=\"HL7 0491\">"+ obj.optString("EHR_000359_VALUE") +"</quantity>\n" +
                            "        <rejectReason code=\""+ obj.optString("EHR_000356") +"\" codeSystem=\"HL7 0490\">"+ obj.optString("EHR_000356_VALUE") +"</rejectReason>\n" +
                            "        <playingDevice>\n" +
                            "          <name>【检验设备名称】</name>\n" +
                            "        </playingDevice>\n" +
                            observationString +
                            "      </entry>\n" +
                            "    </section>\n" +
                            "  </component>\n" +
                            "</ClinicalDocument>";
                }
            }
        }
        return re;
    }
}

+ 31 - 22
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/record/HealthDataService.java

@ -23,37 +23,46 @@ public class HealthDataService extends BaseService {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    EhrService ehrService;
    /**
     * 获取健康档案信息
     */
    public String getHealthData(String strSSID, String strEvent, String strCatalog, String strSerial) throws Exception {
        String url = SystemConf.getInstance().getSystemProperties().getProperty("sign_check_upload");
        url = url + "/third/smjk/HealthData";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("strSSID", strSSID));
        params.add(new BasicNameValuePair("strEvent", strEvent));
        params.add(new BasicNameValuePair("strCatalog", strCatalog));
        params.add(new BasicNameValuePair("strSerial", strSerial));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        String result = "";
        if (!StringUtils.isEmpty(response)){
            JSONObject jsonObject = new JSONObject(response);
            int status = jsonObject.getInt("status");
            if (status == 200){
                result = jsonObject.getString("data");
                result = result.replaceAll("<\\?xml version=\"1.0\" encoding=\"utf-8\"\\?>","");
                if (result.startsWith("error")) {
                    return result;
                }
        if(SystemConf.getInstance().getEhrUsed())     //演示环境
        {
            return ehrService.getHealthData(strSSID,strEvent,strCatalog,strSerial);
        }
        else {
            String url = SystemConf.getInstance().getSystemProperties().getProperty("sign_check_upload");
            url = url + "/third/smjk/HealthData";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("strEvent", strEvent));
            params.add(new BasicNameValuePair("strCatalog", strCatalog));
            params.add(new BasicNameValuePair("strSerial", strSerial));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String result = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    result = jsonObject.getString("data");
                    result = result.replaceAll("<\\?xml version=\"1.0\" encoding=\"utf-8\"\\?>", "");
                    if (result.startsWith("error")) {
                        return result;
                    }
//                if (!StringUtils.isEmpty(xmlData)){
//                    String xmlJson = XMLUtil.xml2json(xmlData);
//                    result = objectMapper.readValue(xmlJson, Map.class);
//                }
                }
            }
        }
        return result;
            return result;
        }
    }
}

+ 39 - 30
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/record/InspectionService.java

@ -31,6 +31,9 @@ public class InspectionService extends BaseService {
    @Autowired
    SystemDictService systemDictService;
    @Autowired
    EhrService ehrService;
    /**
     * 获取检查报告信息
     */
@ -56,41 +59,47 @@ public class InspectionService extends BaseService {
     * @throws Exception
     */
    public String getInspectionAndChecking(String strSSID, String startNum, String endNum) throws Exception {
        JSONArray total = new JSONArray();
        JSONArray check = getChecking(strSSID, startNum, endNum);
        if (!check.isNull(0)) {
            JSONObject jsonObject = check.getJSONObject(0);
            if (jsonObject.has("error")) {
                return jsonObject.get("error").toString();
            }
        if(SystemConf.getInstance().getEhrUsed())     //演示环境
        {
            return ehrService.getInspectionAndChecking(strSSID);
        }
        JSONArray inspect = getInspection(strSSID, startNum, endNum);
        if (!inspect.isNull(0)) {
            JSONObject jsonObject = inspect.getJSONObject(0);
            if (jsonObject.has("error")) {
                return jsonObject.get("error").toString();
        else {
            JSONArray total = new JSONArray();
            JSONArray check = getChecking(strSSID, startNum, endNum);
            if (!check.isNull(0)) {
                JSONObject jsonObject = check.getJSONObject(0);
                if (jsonObject.has("error")) {
                    return jsonObject.get("error").toString();
                }
            }
        }
        //TODO 检查检验数据合并
        for (int i = 0; i < check.length(); i++) {
            total.put(check.getJSONObject(i));
        }
        for (int i = 0; i < inspect.length(); i++) {
            total.put(inspect.getJSONObject(i));
        }
        JSONObject temp;
        for (int i = 0; i < total.length(); i++) {
            for (int j = i+1; j < total.length(); j++) {
                String endTimeNew = total.getJSONObject(j).get("END_TIME").toString();
                String endTimeOld = total.getJSONObject(i).get("END_TIME").toString();
                if (endTimeNew.compareTo(endTimeOld) > 0) {
                    temp = total.getJSONObject(i);
                    total.put(i, total.getJSONObject(j));
                    total.put(j, temp);  // 两个数交换位置
            JSONArray inspect = getInspection(strSSID, startNum, endNum);
            if (!inspect.isNull(0)) {
                JSONObject jsonObject = inspect.getJSONObject(0);
                if (jsonObject.has("error")) {
                    return jsonObject.get("error").toString();
                }
            }
            //TODO 检查检验数据合并
            for (int i = 0; i < check.length(); i++) {
                total.put(check.getJSONObject(i));
            }
            for (int i = 0; i < inspect.length(); i++) {
                total.put(inspect.getJSONObject(i));
            }
            JSONObject temp;
            for (int i = 0; i < total.length(); i++) {
                for (int j = i + 1; j < total.length(); j++) {
                    String endTimeNew = total.getJSONObject(j).get("END_TIME").toString();
                    String endTimeOld = total.getJSONObject(i).get("END_TIME").toString();
                    if (endTimeNew.compareTo(endTimeOld) > 0) {
                        temp = total.getJSONObject(i);
                        total.put(i, total.getJSONObject(j));
                        total.put(j, temp);  // 两个数交换位置
                    }
                }
            }
            return total.toString();
        }
        return total.toString();
    }

+ 1 - 1
patient-co-wlyy/src/main/resources/system.properties

@ -184,5 +184,5 @@ guahao_namespace = http://www.zysoft.com.cn/
#EHRµµ°¸·þÎñµØÖ·
ehr_used = false
ehr_services = http://localhost:9009/api/v1.0/
ehr_services_base = http://localhost:9009/api/v1.0/
ehr_services_base = http://localhost:10220/api/v1.0/