陈昶聿
昨天 0dffefa0ba7f38d54852b3c3f97158df236bfe34
smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
@@ -1,7 +1,10 @@
package com.smartor.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.SysUserDept;
@@ -11,12 +14,14 @@
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.smartor.domain.*;
import com.smartor.domain.entity.ServiceSubtaskEntity;
import com.smartor.mapper.*;
import com.smartor.service.IPatMedOuthospService;
import com.smartor.service.IServiceExternalService;
import lombok.extern.slf4j.Slf4j;
import netscape.javascript.JSObject;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -430,18 +435,23 @@
        Map yeWuXX = (Map) dataMap.get("YeWuXX");
        Map<String, Object> BingRenXX = ObjectUtils.isNotEmpty(yeWuXX) ? (Map<String, Object>) yeWuXX.get("BingRenXX") : null;
        Map<String, Object> RuKeXX = ObjectUtils.isNotEmpty(yeWuXX) ? (Map<String, Object>) yeWuXX.get("RuKeXX") : null;
        Map<String, Object> JiuZhenXX = ObjectUtils.isNotEmpty(yeWuXX) ? (Map<String, Object>) yeWuXX.get("JiuZhenXX") : null;
        List<HashMap<String, Object>> epai = ObjectUtils.isNotEmpty(yeWuXX) ? (List<HashMap<String, Object>>) BingRenXX.get("DiZhiXXList") : null;
        ExternalInHospPatientInfo externalInHospPatientInfo = BeanUtil.mapToBean(BingRenXX, ExternalInHospPatientInfo.class, true);
        ExternalInDeptPatientInfo externalInDeptPatientInfo = BeanUtil.mapToBean(RuKeXX, ExternalInDeptPatientInfo.class, true);
        ExternalInDeptPatientInfo externalJZInfo = BeanUtil.mapToBean(JiuZhenXX, ExternalInDeptPatientInfo.class, true);
        if(ObjectUtils.isNotEmpty(externalJZInfo)){
            externalInHospPatientInfo.setJingGuanYSID(externalJZInfo.getJingGuanYSID());
            externalInHospPatientInfo.setJingGuanYSXM(externalJZInfo.getJingGuanYSXM());
        }
        externalInHospPatientInfo.setZeRenHSID(externalInDeptPatientInfo.getZeRenHSID());
        externalInHospPatientInfo.setZeRenHSXM(externalInDeptPatientInfo.getZeRenHSXM());
        externalInHospPatientInfo.setZhuZhiYSID(externalInDeptPatientInfo.getZhuZhiYSID());
        externalInHospPatientInfo.setZhuZhiYSXM(externalInDeptPatientInfo.getZhuZhiYSXM());
        externalInHospPatientInfo.setRuYuanSJ(externalInDeptPatientInfo.getRuYuanSJ());
        externalInHospPatientInfo.setJingGuanYSID(externalInDeptPatientInfo.getJingGuanYSID());
        externalInHospPatientInfo.setJingGuanYSXM(externalInDeptPatientInfo.getJingGuanYSXM());
        externalInHospPatientInfo.setLianXiDH(ObjectUtils.isNotEmpty(BingRenXX.get("LianXiDH")) ? BingRenXX.get("LianXiDH").toString() : null);
        externalInHospPatientInfo.setDangQianCWID(ObjectUtils.isNotEmpty(BingRenXX.get("DangQianCWID")) ? BingRenXX.get("DangQianCWID").toString() : null);
        externalInHospPatientInfo.setDangQianCWMC(ObjectUtils.isNotEmpty(BingRenXX.get("DangQianCWMC")) ? BingRenXX.get("DangQianCWMC").toString() : null);
@@ -512,13 +522,20 @@
        Map yeWuXX = (Map) dataMap.get("YeWuXX");
        Map<String, Object> BingRenXX = ObjectUtils.isNotEmpty(yeWuXX) ? (Map<String, Object>) yeWuXX.get("BingRenXX") : null;
        Map<String, Object> ChuYuanJL = ObjectUtils.isNotEmpty(yeWuXX) ? (Map<String, Object>) yeWuXX.get("ChuYuanJL") : null;
        Map<String, Object> JiuZhenXX = ObjectUtils.isNotEmpty(yeWuXX) ? (Map<String, Object>) yeWuXX.get("JiuZhenXX") : null;
        List<HashMap<String, Object>> epai = ObjectUtils.isNotEmpty(BingRenXX) ? (List<HashMap<String, Object>>) BingRenXX.get("DiZhiXXList") : null;
        List<HashMap<String, Object>> epli = ObjectUtils.isNotEmpty(yeWuXX) ? (List<HashMap<String, Object>>) yeWuXX.get("LianXiRList") : null;
        Map<String, Object> SuiFangJH = ObjectUtils.isNotEmpty(ChuYuanJL) ? (Map<String, Object>) ChuYuanJL.get("SuiFangJH") : null;
        ExternalInHospPatientInfo externalInHospPatientInfo = BeanUtil.mapToBean(BingRenXX, ExternalInHospPatientInfo.class, true);
        ExternalInHospPatientAddrInfo externalInHospPatientAddrInfo = null;
        ExternalInHospPatientLiaisonInfo externalInHospPatientLiaisonInfo = null;
        //就诊信息
        ExternalInDeptPatientInfo externalJZInfo = BeanUtil.mapToBean(JiuZhenXX, ExternalInDeptPatientInfo.class, true);
        if(ObjectUtils.isNotEmpty(externalJZInfo)){
            externalInHospPatientInfo.setJingGuanYSID(externalJZInfo.getJingGuanYSID());
            externalInHospPatientInfo.setJingGuanYSXM(externalJZInfo.getJingGuanYSXM());
        }
        List<ExternalInHospPatientAddrInfo> epai2 = null;
        //死亡标记
        Boolean deathFlag = false;
@@ -577,7 +594,6 @@
            String tagname = patMedInhospMapper.getTagnameBypatid(patMedInhosp1.getPatid());
            patMedInhosp1.setTagname(tagname);
        }
        Map<String, Object> JiuZhenXX = ObjectUtils.isNotEmpty(yeWuXX) ? (Map<String, Object>) yeWuXX.get("JiuZhenXX") : null;
        PatMedInhosp patMedInhosp1 = new PatMedInhosp();
        if (CollectionUtils.isNotEmpty(patMedInhospList)) patMedInhosp1 = patMedInhospList.get(0);
        patMedInhosp1.setSchemestatus(2L);
@@ -594,6 +610,9 @@
            patMedInhosp1.setNurseName(ObjectUtils.isNotEmpty(JiuZhenXX.get("ZeRenHSXM")) ? JiuZhenXX.get("ZeRenHSXM").toString() : null);
            patMedInhosp1.setNurseId(ObjectUtils.isNotEmpty(JiuZhenXX.get("ZeRenHSID")) ? JiuZhenXX.get("ZeRenHSID").toString() : null);
            patMedInhosp1.setBedNo(ObjectUtils.isNotEmpty(JiuZhenXX.get("DangQianCWMC")) ? JiuZhenXX.get("DangQianCWMC").toString() : null);
            patMedInhosp1.setManagementDoctorCode(ObjectUtils.isNotEmpty(JiuZhenXX.get("JingGuanYSID")) ? JiuZhenXX.get("JingGuanYSID").toString() : null);
            patMedInhosp1.setManagementDoctor(ObjectUtils.isNotEmpty(JiuZhenXX.get("JingGuanYSXM")) ? JiuZhenXX.get("JingGuanYSXM").toString() : null);
            //离院方式代码 1-医瞩离院 2-医嘱转院 3-医嘱转社区卫生服务机构/乡镇卫生院
            // 4-非医嘱离院 5-死亡 9-其他 10-介入室 20-手术室
@@ -977,6 +996,9 @@
            patMedInhosp1.setNurseName(ObjectUtils.isNotEmpty(JiuZhenXX.get("ZeRenHSXM")) ? JiuZhenXX.get("ZeRenHSXM").toString() : null);
            patMedInhosp1.setNurseId(ObjectUtils.isNotEmpty(JiuZhenXX.get("ZeRenHSID")) ? JiuZhenXX.get("ZeRenHSID").toString() : null);
            patMedInhosp1.setBedNo(ObjectUtils.isNotEmpty(JiuZhenXX.get("DangQianCWMC")) ? JiuZhenXX.get("DangQianCWMC").toString() : null);
            patMedInhosp1.setManagementDoctorCode(ObjectUtils.isNotEmpty(JiuZhenXX.get("JingGuanYSID")) ? JiuZhenXX.get("JingGuanYSID").toString() : null);
            patMedInhosp1.setManagementDoctor(ObjectUtils.isNotEmpty(JiuZhenXX.get("JingGuanYSXM")) ? JiuZhenXX.get("JingGuanYSXM").toString() : null);
        }
        patMedInhosp1.setUpdateTime(new Date());
        patMedInhosp1.setTelcode(patArchive.getTelcode());
@@ -1045,6 +1067,13 @@
            int i = patMedInhospMapper.insertPatMedInhosp(patMedInhosp1);
            if (i != 1) return false;
        }
        //离院方式代码 1-医瞩离院 2-医嘱转院 3-医嘱转社区卫生服务机构/乡镇卫生院
        // 4-非医嘱离院 5-死亡 9-其他 10-介入室 20-手术室
        String liYuanQxdm = ObjectUtils.isNotEmpty(JiuZhenXX.get("LiYuanQXDM")) ? JiuZhenXX.get("LiYuanQXDM").toString() : null;
        if (ObjectUtils.isNotEmpty(liYuanQxdm) && ("5").equals(liYuanQxdm)) {
            deathPatProcess(liYuanQxdm,patMedInhosp1);
        }
        return true;
    }
@@ -1086,6 +1115,13 @@
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            //离院方式代码 1-医瞩离院 2-医嘱转院 3-医嘱转社区卫生服务机构/乡镇卫生院
            // 4-非医嘱离院 5-死亡 9-其他 10-介入室 20-手术室
            String liYuanQxdm = ObjectUtils.isNotEmpty(JiuZhenXX.get("LiYuanQXDM")) ? JiuZhenXX.get("LiYuanQXDM").toString() : null;
            if (ObjectUtils.isNotEmpty(liYuanQxdm) && ("5").equals(liYuanQxdm)) {
                deathPatProcess(liYuanQxdm,patMedInhosp1);
            }
            return true;
        } else {
@@ -1418,7 +1454,7 @@
            Boolean addMianTableFalg = true;
            for (ExternalOperationDetail externalOperationDetail : externalOperationDetails) {
                PatMedOperationItem patMedOperationItem = new PatMedOperationItem();
                patMedOperationItem.setOpid(patMedOperation.getId());
                patMedOperationItem.setOpid(patMedOperation.getOpid());
                patMedOperationItem.setOpcode(externalOperationDetail.getShouShuMCID());
                patMedOperationItem.setOpdesc(externalOperationDetail.getShouShuMC());
                patMedOperationItem.setMainFlag(externalOperationDetail.getZhuShouSBZ());
@@ -1860,40 +1896,18 @@
    @Override
    public Map<String, Object> query360PatInfolwl(Long patid, SysUser sysUser) {
        Map<String, Object> result = new HashMap<>();
        PatArchive pa = patArchiveMapper.selectPatArchiveByPatid(patid);
        if (pa.getPatientno() == null) {
            result.put("url", null);
            result.put("error", "患者编号为空");
            return result;
        PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patid);
        Map<String, String> headers = buildRequestHeaders();
        Map<String, Object> requestParams = buildRequestParams(sysUser,patArchive);
        String result = HttpUtils.sendPostByHeader("http://cfdata.nhyfy.cn/kapi/hbos-h360/open/getNoLoginUrl", new Gson().toJson(requestParams), headers);
        log.info("============result的值为:{}",result);
        Gson gson = new Gson();
        Map<String, Object> map = null;
        if (result != null) {
            map = gson.fromJson(result, new TypeToken<Map<String, Object>>() {
            }.getType());
        }
        StringBuffer sbf = new StringBuffer("http://cfdata.nhyfy.cn/cfdata/h360/patient-summary?");
        sbf.append("referer=thirdparty");
        sbf.append("&encode=1");
        sbf.append("&patientMainIndexNum=" + AesUtils.encrypt(pa.getPatientno()));
        sbf.append("&workId=" + AesUtils.encrypt(sysUser.getUserName()));
        sbf.append("&workName=" + AesUtils.encrypt(sysUser.getNickName()));
        sbf.append("&hisOrgCode=" + AesUtils.encrypt("20001001"));
        sbf.append("&hisOrgName=" + AesUtils.encrypt("南华大学附属第一医院"));
        sbf.append("&hisHosCode=" + AesUtils.encrypt("30001002"));
        sbf.append("&hisHosName=" + AesUtils.encrypt("南华大学附属第一医院"));
        String url360 = null;
        try {
            url360 = URLEncoder.encode(sbf.toString(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        StringBuffer stringBuffer = new StringBuffer("http://cfdata.nhyfy.cn/cfdata/login/nologin?");
        //accountNo对接人不给,先空着---------------------------------------------------------------
        stringBuffer.append("accountNo=");
        stringBuffer.append("&source=third");
        stringBuffer.append("&redirectUrl=" + url360);
        result.put("url", stringBuffer.toString());
        result.put("error", null);
        return result;
        return map;
    }
    private Boolean getType(String type, Map dataMap) {
@@ -2072,4 +2086,76 @@
        return ageMap;
    }
    private Map<String, String> buildRequestHeaders() {
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put("app-key", "ak-0p5Qi0J1I4AL67ztEYQL1j9v");
        return headers;
    }
    private Map<String, Object> buildRequestParams(SysUser sysUser,PatArchive patArchive) {
        Map<String, Object> requestParams = new HashMap<>();
        requestParams.put("key",  sysUser.getUserName());
        requestParams.put("windowOpen", false);
        requestParams.put("isShowHeader", false);
        requestParams.put("encode", 1);
        Map<String, Object> params = new HashMap<>();
        //病历号
        params.put("patientMainIndexNum", patArchive.getPatientno());
        params.put("sourceSystem", "pacs");
        params.put("workId", sysUser.getUserName());
        params.put("workName", sysUser.getNickName());
        params.put("hisDepName", sysUser.getDeptName());
        params.put("hisDepCode", sysUser.getDeptCode());
        params.put("hisOrgName", "南华大学附属第一医院");
        params.put("hisOrgCode", "20001001");
        params.put("hisHosName", "南华大学附属第一医院");
        params.put("hisHosCode", "30001002");
        requestParams.put("params", params);
        return requestParams;
    }
    /**
     * 死亡患者处理
     * @param liYuanQxdm
     * @param patMedInhosp
     * @return
     */
    private int deathPatProcess(String liYuanQxdm, PatMedInhosp patMedInhosp){
        //死亡标记
        Boolean deathFlag = false;
        //判断病人是否死亡
        if (ObjectUtils.isNotEmpty(liYuanQxdm) && ("5").equals(liYuanQxdm)) {
            deathFlag = true;
        }
        PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedInhosp.getPatid());
        if(ObjectUtils.isNotEmpty(patArchive)) {
            patMedInhosp.setInhospstate("1");
            if (deathFlag) {
                //病人死亡无须随访
                patMedInhosp.setFuflag("0");
                //更新病人 notrequiredFlag
                patArchive.setNotrequiredFlag("1");
                patArchive.setNotrequiredreason("患者已离世");
                patArchiveMapper.updatePatArchive(patArchive);
                //对已经生成的随访任务进行处理
                ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity();
                serviceSubtaskVO.setPatid(patArchive.getId());
                serviceSubtaskVO.setSendstate(2L);
                List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
                for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
                    serviceSubtask.setSendstate(4L);
                    serviceSubtask.setRemark(serviceSubtask.getRemark() + ";患者已离世,不随访");
                    serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                }
            } else {
                return 0;
            }
        }else {
            return -1;
        }
        return 1;
    }
}