liusheng
2025-03-20 db13d846510525ddd4d5c48ee0c549c62cf93efa
smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
@@ -1,7 +1,5 @@
package com.smartor.service.impl;
import java.lang.reflect.Field;
import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
@@ -9,21 +7,22 @@
import com.smartor.domain.*;
import com.smartor.mapper.*;
import com.smartor.service.IServiceExternalService;
import com.smartor.service.IServiceSubtaskRecordService;
import com.smartor.service.IServiceSubtaskService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Value;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.security.auth.login.CredentialNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -46,11 +45,16 @@
    @Autowired
    private PatMedInhospMapper patMedInhospMapper;
    @Autowired
    private Icd10AssociationMapper icd10AssociationMapper;
    private PatMedOperationMapper patMedOperationMapper;
    @Autowired
    private IServiceSubtaskService iServiceSubtaskService;
    private PatMedOperationItemMapper patMedOperationItemMapper;
    @Autowired
    private Icd10Mapper icd10Mapper;
    @Autowired
    private PatMedOuthospMapper patMedOuthospMapper;
    @Value("${defaultPwd}")
    private String defaultPwd;
    public Boolean generalInterface(Map dataMap) {
        Map XiaoXiTou = (Map) dataMap.get("XiaoXiTou");
@@ -111,11 +115,15 @@
        ExternalUserInfo externalUserInfo = BeanUtil.mapToBean(yongHuXX, ExternalUserInfo.class, true);
        SysUser sysUser = new SysUser();
        sysUser.setGuid(externalUserInfo.getZuZhiJGID());
        sysUser.setUserName(externalUserInfo.getYongHuID());
        sysUser.setUserName(externalUserInfo.getYongHuDLM());
        sysUser.setNickName(externalUserInfo.getYongHuXM());
        sysUser.setUserType("");
        sysUser.setDeptId(null);
        sysUser.setTitle(null);
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        sysUser.setPassword(passwordEncoder.encode(defaultPwd));
        sysUser.setHisUserId(externalUserInfo.getYongHuID());
        sysUser.setPhonenumber(externalUserInfo.getLianXiDH());
        sysUser.setJobPhone(externalUserInfo.getGongZuoDH());
@@ -257,40 +265,100 @@
        log.error("ServiceExternalServiceImpl---addOutHospInfo的新增的值为:{}", dataMap);
        Map yeWuXX = (Map) dataMap.get("YeWuXX");
        Map<String, Object> BingRenXX = (Map<String, Object>) yeWuXX.get("BingRenXX");
        List<HashMap<String, Object>> epai = (List<HashMap<String, Object>>) BingRenXX.get("DiZhiXXList");
        List<HashMap<String, Object>> epli = (List<HashMap<String, Object>>) yeWuXX.get("LianXiRList");
        ExternalInHospPatientInfo externalInHospPatientInfo = BeanUtil.mapToBean(BingRenXX, ExternalInHospPatientInfo.class, true);
        ExternalInHospPatientAddrInfo externalInHospPatientAddrInfo = null;
        ExternalInHospPatientLiaisonInfo externalInHospPatientLiaisonInfo = null;
        List<ExternalInHospPatientAddrInfo> epai2 = null;
        if (CollectionUtils.isNotEmpty(epai)) {
            epai2 = epai.stream().map(map -> {
                ExternalInHospPatientAddrInfo info = new ExternalInHospPatientAddrInfo();
                info.setDiZhiLX((String) map.get("DiZhiLX")); // 假设字段类型是 Integer
                info.setDiZhiXX((String) map.get("DiZhiXX"));
                info.setShengFenDM((String) map.get("ShengFenDM"));
                info.setShengFenMC((String) map.get("ShengFenMC"));
                info.setShiDiQDM((String) map.get("ShiDiQDM"));
                info.setShiDiQMC((String) map.get("ShiDiQMC"));
                info.setXianQuDM((String) map.get("XianQuDM"));
                info.setXianQuMC((String) map.get("XianQuMC"));
                info.setXiangZhenDM((String) map.get("XiangZhenDM"));
                info.setXiangZhenMC((String) map.get("XiangZhenMC"));
                info.setCunJiDM((String) map.get("CunJiDM"));
                info.setQiTaXX((String) map.get("QiTaXX"));
                info.setYouBian((String) map.get("YouBian"));
                return info;
            }).collect(Collectors.toList());
        }
        List<ExternalInHospPatientLiaisonInfo> epli2 = null;
        if (CollectionUtils.isNotEmpty(epli)) {
            epli2 = epli.stream().map(map -> {
                ExternalInHospPatientLiaisonInfo info = new ExternalInHospPatientLiaisonInfo();
                info.setLianXiRXM((String) map.get("LianXiRXM"));
                info.setLianXiRDH((String) map.get("LianXiRDH"));
                info.setGuanXiDM((String) map.get("GuanXiDM"));
                info.setGuanXiMC((String) map.get("GuanXiMC"));
                return info;
            }).collect(Collectors.toList());
        }
        if (CollectionUtils.isNotEmpty(epai)) externalInHospPatientAddrInfo = epai2.get(0);
        if (CollectionUtils.isNotEmpty(epli)) externalInHospPatientLiaisonInfo = epli2.get(0);
        //新增患者基本信息新增或修改
        PatArchive patArchive = addPatArchive(externalInHospPatientInfo, externalInHospPatientAddrInfo, externalInHospPatientLiaisonInfo);
        PatMedInhosp patMedInhosp = new PatMedInhosp();
        patMedInhosp.setInhospno(externalInHospPatientInfo.getZhuYuanHao());
        List<PatMedInhosp> patMedInhospList = patMedInhospMapper.selectPatMedInhospList(patMedInhosp);
        Map<String, Object> JiuZhenXX = (Map<String, Object>) yeWuXX.get("JiuZhenXX");
        PatMedInhosp patMedInhosp1 = new PatMedInhosp();
        if (CollectionUtils.isNotEmpty(patMedInhospList)) patMedInhosp1 = patMedInhospList.get(0);
        patMedInhosp1.setSchemestatus(2L);
        try {
            patMedInhosp1.setEndtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(JiuZhenXX.get("ChuYuanSJ").toString()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        patMedInhosp1.setOperator(JiuZhenXX.get("CaoZuoRXM").toString());
        patMedInhosp1.setOperatorId(JiuZhenXX.get("CaoZuoRID").toString());
        patMedInhosp1.setUpdateTime(new Date());
        patMedInhosp1.setTelcode(patArchive.getTelcode());
        patMedInhosp1.setLeavehospitaldistrictcode(externalInHospPatientInfo.getDangQianBQID());
        patMedInhosp1.setLeavehospitaldistrictname(externalInHospPatientInfo.getDangQianBQMC());
        patMedInhosp1.setLeaveldeptname(externalInHospPatientInfo.getDangQianKSMC());
        patMedInhosp1.setDeptname(externalInHospPatientInfo.getDangQianKSMC());
        patMedInhosp1.setLeaveldeptcode(externalInHospPatientInfo.getDangQianKSID());
        patMedInhosp1.setDeptcode(externalInHospPatientInfo.getDangQianKSID());
        List<HashMap<String, Object>> zhenDuanList = (List<HashMap<String, Object>>) yeWuXX.get("ZhenDuanList");
        List<ExternalInHospPatientDiagnoseInfo> hospPatientDiagnoseInfos2 = zhenDuanList.stream().map(map -> {
            ExternalInHospPatientDiagnoseInfo info = new ExternalInHospPatientDiagnoseInfo();
            info.setZhenDuanID((String) map.get("ZhenDuanID"));
            info.setZhenDuanMC((String) map.get("ZhenDuanMC"));
            return info;
        }).collect(Collectors.toList());
        patMedInhosp1.setLeaveicd10code(StringUtils.isNotEmpty(patMedInhosp1.getLeaveicd10code()) ? patMedInhosp1.getLeaveicd10code() + "," + hospPatientDiagnoseInfos2.get(0).getZhenDuanID() : hospPatientDiagnoseInfos2.get(0).getZhenDuanID());
        patMedInhosp1.setLeavediagname(StringUtils.isNotEmpty(patMedInhosp1.getLeavediagname()) ? patMedInhosp1.getLeavediagname() + "," + hospPatientDiagnoseInfos2.get(0).getZhenDuanMC() : hospPatientDiagnoseInfos2.get(0).getZhenDuanMC());
        patMedInhosp1.setDiagname(StringUtils.isNotEmpty(patMedInhosp1.getLeavediagname()) ? patMedInhosp1.getLeavediagname() + "," + hospPatientDiagnoseInfos2.get(0).getZhenDuanMC() : hospPatientDiagnoseInfos2.get(0).getZhenDuanMC());
        patMedInhosp1.setIcd10code(StringUtils.isNotEmpty(patMedInhosp1.getLeavediagname()) ? patMedInhosp1.getLeavediagname() + "," + hospPatientDiagnoseInfos2.get(0).getZhenDuanMC() : hospPatientDiagnoseInfos2.get(0).getZhenDuanMC());
        patMedInhosp1.setInhospstate("1");
        if (CollectionUtils.isNotEmpty(patMedInhospList)) {
            Map<String, Object> JiuZhenXX = (Map<String, Object>) yeWuXX.get("JiuZhenXX");
            PatMedInhosp patMedInhosp1 = patMedInhospList.get(0);
            patMedInhosp1.setSchemestatus(2L);
            try {
                patMedInhosp1.setEndtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(JiuZhenXX.get("ChuYuanSJ").toString()));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            patMedInhosp1.setOperator(JiuZhenXX.get("CaoZuoRXM").toString());
            patMedInhosp1.setOperatorId(JiuZhenXX.get("CaoZuoRID").toString());
            patMedInhosp1.setUpdateTime(new Date());
            patMedInhosp1.setUpdateTime(new Date());
            patMedInhosp1.setLeavehospitaldistrictcode(externalInHospPatientInfo.getDangQianBQID());
            patMedInhosp1.setLeavehospitaldistrictname(externalInHospPatientInfo.getDangQianBQMC());
            patMedInhosp1.setLeaveldeptname(externalInHospPatientInfo.getDangQianKSMC());
            patMedInhosp1.setLeaveldeptcode(externalInHospPatientInfo.getDangQianKSID());
            List<HashMap<String, Object>> zhenDuanList = (List<HashMap<String, Object>>) yeWuXX.get("ZhenDuanList");
            List<ExternalInHospPatientDiagnoseInfo> hospPatientDiagnoseInfos2 = zhenDuanList.stream().map(map -> {
                ExternalInHospPatientDiagnoseInfo info = new ExternalInHospPatientDiagnoseInfo();
                info.setZhenDuanID((String) map.get("ZhenDuanID"));
                info.setZhenDuanMC((String) map.get("ZhenDuanMC"));
                return info;
            }).collect(Collectors.toList());
            patMedInhosp1.setLeaveicd10code(StringUtils.isNotEmpty(patMedInhosp1.getLeaveicd10code()) ? patMedInhosp1.getLeaveicd10code() + "," + hospPatientDiagnoseInfos2.get(0).getZhenDuanID() : hospPatientDiagnoseInfos2.get(0).getZhenDuanID());
            patMedInhosp1.setLeavediagname(StringUtils.isNotEmpty(patMedInhosp1.getLeavediagname()) ? patMedInhosp1.getLeavediagname() + "," + hospPatientDiagnoseInfos2.get(0).getZhenDuanMC() : hospPatientDiagnoseInfos2.get(0).getZhenDuanMC());
            patMedInhosp1.setOrgid(BingRenXX.get("ZuZhiJGID").toString());
            int i = patMedInhospMapper.updatePatMedInhosp(patMedInhosp1);
            if (i != 1) return false;
        } else {
            patMedInhosp1.setHospitalname(BingRenXX.get("ZuZhiJGMC").toString());
            patMedInhosp1.setHospitalcode(BingRenXX.get("ZuZhiJGID").toString());
            patMedInhosp1.setLeavehospitaldistrictname(BingRenXX.get("DangQianBQMC").toString());
            patMedInhosp1.setLeavehospitaldistrictcode(BingRenXX.get("DangQianBQID").toString());
            patMedInhosp1.setPatid(patArchive.getId());
            patMedInhosp1.setPatname(patArchive.getName());
            patMedInhosp1.setOrgid(BingRenXX.get("ZuZhiJGID").toString());
            patMedInhosp1.setPatno(BingRenXX.get("BingRenID").toString());
            patMedInhosp1.setInhospno(BingRenXX.get("ZhuYuanHao").toString());
            patMedInhosp1.setSerialnum(BingRenXX.get("BingAnHao").toString());
            patMedInhosp1.setCreateTime(new Date());
            int i = patMedInhospMapper.insertPatMedInhosp(patMedInhosp1);
            if (i != 1) return false;
        }
        return true;
@@ -320,31 +388,104 @@
    @Override
    public Boolean addFinshJZInfo(Map dataMap) {
        //这个先等等
        log.error("ServiceExternalServiceImpl---addFinshJZInfo的新增的值为:{}", dataMap);
        Map yeWuXX = (Map) dataMap.get("YeWuXX");
        Map XiaoXiTou = (Map) dataMap.get("XiaoXiTou");
        String FaSongJGID = ObjectUtils.isNotEmpty(XiaoXiTou.get("FaSongJGID")) ? XiaoXiTou.get("FaSongJGID").toString() : null;
        return null;
        Map<String, Object> BingRenXX = (Map<String, Object>) yeWuXX.get("BingRenXX");
        Map<String, Object> JiuZhenXX = (Map<String, Object>) yeWuXX.get("JiuZhenXX");
        List<HashMap<String, Object>> ZhenDuanList = (List<HashMap<String, Object>>) yeWuXX.get("ZhenDuanList");
        List<HashMap<String, Object>> externalWZInfos = (List<HashMap<String, Object>>) yeWuXX.get("WenZhenList");
        ExternalInHospPatientInfo externalInHospPatientInfo = BeanUtil.mapToBean(BingRenXX, ExternalInHospPatientInfo.class, true);
        //病人信息里没有组织机构ID
        externalInHospPatientInfo.setZuZhiJGID(FaSongJGID);
        ExternalJZInfo externalJZInfo = BeanUtil.mapToBean(JiuZhenXX, ExternalJZInfo.class, true);
        List<ExternalDiagnosisInfo> externalDiagnosisInfoList = ZhenDuanList.stream().map(map -> {
            ExternalDiagnosisInfo info = new ExternalDiagnosisInfo();
            info.setZhenDuanYSID((String) map.get("ZhenDuanYSID"));
            info.setZhenDuanYSXM((String) map.get("ZhenDuanYSXM"));
            info.setZhenDuanID((String) map.get("ZhenDuanID"));
            info.setZhenDuanMC((String) map.get("ZhenDuanMC"));
            info.setZhenDuanLBDM((String) map.get("ZhenDuanLBDM"));
            info.setZhenDuanLBMC((String) map.get("ZhenDuanLBMC"));
            return info;
        }).collect(Collectors.toList());
        List<ExternalWZInfo> ExternalWZInfoList = externalWZInfos.stream().map(map -> {
            ExternalWZInfo info = new ExternalWZInfo();
            info.setWenZhenLXMC((String) map.get("WenZhenLXMC"));
            info.setNeiRong((String) map.get("NeiRong"));
            return info;
        }).collect(Collectors.toList());
        PatArchive patArchive = addPatArchive(externalInHospPatientInfo, null, null);
        PatMedOuthosp patMedOuthosp = new PatMedOuthosp();
        patMedOuthosp.setOuthospno(externalInHospPatientInfo.getBingAnHao());
        patMedOuthosp.setSerialnum(externalInHospPatientInfo.getBingAnHao());
        patMedOuthosp.setPatid(patArchive.getId());
        patMedOuthosp.setPatname(externalInHospPatientInfo.getXingMing());
        patMedOuthosp.setHospitalname(externalInHospPatientInfo.getZuZhiJGMC());
        patMedOuthosp.setHospitalcode(externalInHospPatientInfo.getZuZhiJGID());
        patMedOuthosp.setDeptname(externalJZInfo.getJiuZhenKSMC());
        patMedOuthosp.setDeptcode(externalJZInfo.getJiuZhenKSID());
        patMedOuthosp.setAdmitdate(externalJZInfo.getJiuZhenRQ());
        patMedOuthosp.setOrgid(FaSongJGID);
        for (ExternalDiagnosisInfo externalDiagnosisInfo : externalDiagnosisInfoList) {
            if (externalDiagnosisInfo.getZhenDuanLBMC().equals("主诊断")) {
                patMedOuthosp.setDiagname(externalDiagnosisInfo.getZhenDuanMC());
                patMedOuthosp.setIcd10code(externalDiagnosisInfo.getZhenDuanID());
                patMedOuthosp.setDrcode(externalDiagnosisInfo.getZhenDuanYSID());
                patMedOuthosp.setDrname(externalDiagnosisInfo.getZhenDuanYSXM());
                patMedOuthosp.setIcd10code(externalDiagnosisInfo.getIcd10());
            }
        }
        for (ExternalWZInfo externalWZInfo : ExternalWZInfoList) {
            if (externalWZInfo.getWenZhenLXMC().equals("现病史")) {
                patMedOuthosp.setHpi(externalWZInfo.getNeiRong());
            }
            if (externalWZInfo.getWenZhenLXMC().equals("主诉")) {
                patMedOuthosp.setMainsuit(externalWZInfo.getNeiRong());
            }
        }
        int i = patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp);
        if (i > 0) {
            return true;
        }
        return false;
    }
    @Override
    public Boolean addDiseaseInfo(Map dataMap) {
        log.error("ServiceExternalServiceImpl---addDiseaseInfo的新增的值为:{}", dataMap);
        Map yeWuXX = (Map) dataMap.get("YeWuXX");
        Map<String, Object> JiBing = (Map<String, Object>) yeWuXX.get("JiBing");
        Map<String, Object> JiBing = (Map<String, Object>) yeWuXX.get("JiBingMLXX");
        ExternalDiseaseInfo externalDiseaseInfo = BeanUtil.mapToBean(JiBing, ExternalDiseaseInfo.class, true);
        Icd10Association icd10Association = new Icd10Association();
        icd10Association.setIcd10code(externalDiseaseInfo.getJiBingID());
        icd10Association.setIcd10name(externalDiseaseInfo.getJiBingMC());
        icd10Association.setGuid(externalDiseaseInfo.getZuZhiJGID());
        icd10Association.setOrgid(externalDiseaseInfo.getZuZhiJGID());
        icd10Association.setPid(externalDiseaseInfo.getFUJIBID());
        icd10Association.setIcd10AssortCode(externalDiseaseInfo.getJiBingFLDM());
        icd10Association.setIcd10AssortName(externalDiseaseInfo.getJiBingFLMC());
        icd10Association.setChineseMedicineDiagnoseSign(externalDiseaseInfo.getZhongYiZDBZ());
        icd10Association.setChineseMedicineDiagnoseAssortCode(externalDiseaseInfo.getZhongYiZDFLDM());
        icd10Association.setChineseMedicineDiagnoseAssortName(externalDiseaseInfo.getZhongYiZDFLMC());
        icd10Association.setOutpatientUseAssort(externalDiseaseInfo.getMenZhenSYBZ());
        icd10Association.setInpatientUseAssort(externalDiseaseInfo.getZhuYuanSYBZ());
        icd10AssociationMapper.insertIcd10Association(icd10Association);
        Map XiaoXiTou = (Map) dataMap.get("XiaoXiTou");
        String FaSongJGID = XiaoXiTou.get("FaSongJGID").toString();
        Icd10 icd10 = new Icd10();
        icd10.setIcdcode(externalDiseaseInfo.getIcD10());
        icd10.setDelFlag("0");
        icd10.setOrgid(FaSongJGID);
        //通过icdCode查询一下,是否存在
        List<Icd10> icd10s = icd10Mapper.selectIcd10List(icd10);
        icd10.setHisIcdid(externalDiseaseInfo.getJiBingID());
        icd10.setIcdname(externalDiseaseInfo.getJiBingMC());
        icd10.setGuid(externalDiseaseInfo.getZuZhiJGID());
        icd10.setLastflag(externalDiseaseInfo.getMOJIBZ());
        icd10.setChimedflag("" + externalDiseaseInfo.getZhongYiZDBZ());
        if (CollectionUtils.isNotEmpty(icd10s)) {
            icd10.setUpdateTime(new Date());
            icd10.setIcdid(icd10s.get(0).getIcdid());
            icd10Mapper.updateIcd10(icd10);
        } else {
            icd10.setCreateTime(new Date());
            icd10Mapper.insertIcd10(icd10);
        }
        return true;
    }
@@ -381,12 +522,142 @@
        return true;
    }
    @Override
    public Boolean addOperationInfo(Map dataMap) {
        log.error("ServiceExternalServiceImpl---addOperationInfo的新增的值为:{}", dataMap);
        Map yeWuXX = (Map) dataMap.get("YeWuXX");
        Map<String, Object> BingRenXX = (Map<String, Object>) yeWuXX.get("BingRenXX");
        ExternalInHospPatientInfo externalInHospPatientInfo = BeanUtil.mapToBean(BingRenXX, ExternalInHospPatientInfo.class, true);
        PatArchive patArchive = addPatArchive(externalInHospPatientInfo, null, null);
        //手术信息新增
        Map<String, Object> ssxx = (Map<String, Object>) yeWuXX.get("ShouShuSQ");
        //手术更新
        Map<String, Object> ssgx = (Map<String, Object>) yeWuXX.get("ShouShuGX");
        //手术撤销
        Map<String, Object> sscx = (Map<String, Object>) yeWuXX.get("ShouShuCX");
        ExternalOperationInfo externalOperationInfo = null;
        if (ObjectUtils.isNotEmpty(ssxx))
            externalOperationInfo = BeanUtil.mapToBean(ssxx, ExternalOperationInfo.class, true);
        else if (ObjectUtils.isNotEmpty(ssgx))
            externalOperationInfo = BeanUtil.mapToBean(ssgx, ExternalOperationInfo.class, true);
        else if (ObjectUtils.isNotEmpty(sscx))
            externalOperationInfo = BeanUtil.mapToBean(sscx, ExternalOperationInfo.class, true);
        PatMedOperation patMedOperation = new PatMedOperation();
        patMedOperation.setPatid(patArchive.getId());
        patMedOperation.setPatcode(externalInHospPatientInfo.getBingRenID());
        patMedOperation.setPaname(externalInHospPatientInfo.getXingMing());
//        patMedOperation.setOpreqid(externalOperationInfo.getShenQingDID());
        patMedOperation.setOpreqcode(externalOperationInfo.getShenQingDID());
        //查询一下,该患者是否已经有这些数据
        List<PatMedOperation> patMedOperations = patMedOperationMapper.selectPatMedOperationList(patMedOperation);
        patMedOperation.setOpsstatus(null);
        patMedOperation.setOptypecode(externalOperationInfo.getShouShuLBDM());
        patMedOperation.setOptypename(externalOperationInfo.getShouShuLBMC());
        patMedOperation.setOperatortime(externalOperationInfo.getYaoQiuSJ());
        patMedOperation.setOpreqtime(externalOperationInfo.getShenQingSJ());
        patMedOperation.setReqdoccode(externalOperationInfo.getShenQingYSID());
        patMedOperation.setReqdocname(externalOperationInfo.getShenQingYSXM());
        patMedOperation.setReqdeptcode(externalOperationInfo.getShenQingKSID());
        patMedOperation.setReqdeptname(externalOperationInfo.getShenQingKSMC());
        patMedOperation.setReqloccode(externalOperationInfo.getShouShuKSID());
        patMedOperation.setReqlocname(externalOperationInfo.getShouShuKSMC());
        patMedOperation.setSurgeoncode(externalOperationInfo.getZhuDaoYSID());
        patMedOperation.setSurgeonname(externalOperationInfo.getSanZhuYSXM());
        patMedOperation.setFirasscode(externalOperationInfo.getYiZhuID());
        patMedOperation.setFirassname(externalOperationInfo.getYiZhuMC());
        patMedOperation.setSecasscode(externalOperationInfo.getErZhuYSID());
        patMedOperation.setSecassname(externalOperationInfo.getErZhuYSXM());
        patMedOperation.setThrasscode(externalOperationInfo.getSanZhuYSID());
        patMedOperation.setThrassname(externalOperationInfo.getSanZhuYSXM());
        patMedOperation.setCanceltime(null);
        patMedOperation.setCancelreason(null);
        patMedOperation.setCancelcode(null);
        patMedOperation.setCancelname(null);
        patMedOperation.setVisittype(null);
        patMedOperation.setStatus(null);
        patMedOperation.setSchemetime(null);
        patMedOperation.setSchemestatus(null);
        patMedOperation.setDelFlag("0");
        patMedOperation.setIsupload(null);
        patMedOperation.setUploadTime(null);
        patMedOperation.setOrgid(externalInHospPatientInfo.getZuZhiJGID());
        patMedOperation.setInhospstate(null);
        patMedOperation.setPatno(externalInHospPatientInfo.getBingRenID());
        patMedOperation.setPatname(externalInHospPatientInfo.getXingMing());
        patMedOperation.setVisitid(null);
        patMedOperation.setSerialnum(externalInHospPatientInfo.getZhuYuanHao());
        patMedOperation.setInhospno(externalInHospPatientInfo.getZhuYuanHao());
        patMedOperation.setHospitalname(externalInHospPatientInfo.getZuZhiJGMC());
        patMedOperation.setHospitalcode(externalInHospPatientInfo.getZuZhiJGID());
        patMedOperation.setDeptid(externalOperationInfo.getShouShuKSID());
        patMedOperation.setDeptcode(externalOperationInfo.getShouShuKSID());
        patMedOperation.setDeptname(externalOperationInfo.getShouShuKSMC());
        patMedOperation.setHospitaldistrictcode(null);
        patMedOperation.setHospitaldistrictname(null);
        patMedOperation.setRoomno(null);
        patMedOperation.setBedNo(null);
        patMedOperation.setDrcode(externalOperationInfo.getZhuDaoYSID());
        patMedOperation.setDrname(externalOperationInfo.getZhuDaoYSXM());
        patMedOperation.setNurseId(null);
        patMedOperation.setNurseName(null);
        if (CollectionUtils.isNotEmpty(patMedOperations)) {
            Long id = patMedOperations.get(0).getId();
            patMedOperation.setId(id);
            patMedOperation.setCheckFlag(patMedOperations.get(0).getCheckFlag());
            //如果手术撤销,直接删除该条手术信息
            if (ObjectUtils.isNotEmpty(sscx)) {
                patMedOperation.setDelFlag("1");
                //同时去查询,是否在subtask中生成任务,如果生成出得立马删除
            }
            patMedOperationMapper.updatePatMedOperation(patMedOperation);
        } else patMedOperationMapper.insertPatMedOperation(patMedOperation);
        log.error("-----patMedOperation的主键id为:{}", patMedOperation.getId());
        if (ObjectUtils.isNotEmpty(ssxx)) {
            Map<String, Object> ShouShuMXList = (Map<String, Object>) ssxx.get("ShouShuMXList");
            List<ExternalOperationDetail> externalOperationDetails = BeanUtil.mapToBean(ShouShuMXList, List.class, true);
            //addMianTableFalg是否需要将主手术的信息放到PatMedOperation表中(只有第一个主手术信息需要放,后面的都不需要放了,也就是说,第一个放完后,就要把这个flag改成false)
            Boolean addMianTableFalg = true;
            for (ExternalOperationDetail externalOperationDetail : externalOperationDetails) {
                PatMedOperationItem patMedOperationItem = new PatMedOperationItem();
                patMedOperationItem.setOpid(patMedOperation.getId());
                patMedOperationItem.setOpcode(externalOperationDetail.getShouShuMCID());
                patMedOperationItem.setOpdesc(externalOperationDetail.getShouShuMC());
                patMedOperationItem.setMainFlag(externalOperationDetail.getZhuShouSBZ());
                patMedOperationItem.setIncitypecode(externalOperationDetail.getQieKouLBDM());
                patMedOperationItem.setIncitypedesc(externalOperationDetail.getQieKouLBMC());
                patMedOperationItem.setOplevelcode(externalOperationDetail.getShouShuJBDM());
                patMedOperationItem.setOpleveldesc(externalOperationDetail.getShouShuJBMC());
                patMedOperationItem.setOpposition(externalOperationDetail.getShouShuBW());
                patMedOperationItem.setDelFlag("0");
                patMedOperationItem.setOrgid(patMedOperation.getOrgid());
                if (externalOperationDetail.getZhuShouSBZ().equals("1") && addMianTableFalg == true) {
                    patMedOperation.setOpcode(externalOperationDetail.getShouShuMCID());
                    patMedOperation.setOpdesc(externalOperationDetail.getShouShuMC());
//                    patMedOperation.setOpid(externalOperationDetail.getShouShuJBDM());
                    patMedOperationMapper.updatePatMedOperation(patMedOperation);
                    addMianTableFalg = false;
                }
                patMedOperationItemMapper.insertPatMedOperationItem(patMedOperationItem);
            }
        }
        return true;
    }
    //新增患者基本信息
    private PatArchive addPatArchive(ExternalInHospPatientInfo externalInHospPatientInfo, ExternalInHospPatientAddrInfo externalInHospPatientAddrInfo, ExternalInHospPatientLiaisonInfo externalInHospPatientLiaisonInfo) {
        PatArchive patArchive = new PatArchive();
        patArchive.setIdcardno(externalInHospPatientInfo.getZhengJianHM());
        patArchive.setOrgid(externalInHospPatientInfo.getZuZhiJGID());
        List<PatArchive> patArchives = patArchiveMapper.selectPatArchiveList(patArchive);
        patArchive.setPatientno(externalInHospPatientInfo.getJiuZhenKH());
        patArchive.setBirthdate(externalInHospPatientInfo.getChuShengRQ());
        patArchive.setPatidHis(externalInHospPatientInfo.getBingRenID());
        patArchive.setSourcefrom(1);
        patArchive.setPattype("2");
@@ -396,25 +667,33 @@
        patArchive.setNation(externalInHospPatientInfo.getMinZuMC());
        patArchive.setNativePlace(externalInHospPatientInfo.getGuoJiMC());
        if (ObjectUtils.isNotEmpty(externalInHospPatientAddrInfo)) {
            patArchive.setPlaceOfResidence(externalInHospPatientAddrInfo.getShengFenMC() + externalInHospPatientAddrInfo.getShiDiQMC() + externalInHospPatientAddrInfo.getXianQuMC() + externalInHospPatientAddrInfo.getXiangZhenMC() + externalInHospPatientAddrInfo.getCunJiMC() + externalInHospPatientAddrInfo.getQiTaXX());
            patArchive.setBirthplace(externalInHospPatientAddrInfo.getShengFenMC() + externalInHospPatientAddrInfo.getShiDiQMC() + externalInHospPatientAddrInfo.getXianQuMC() + externalInHospPatientAddrInfo.getXiangZhenMC() + externalInHospPatientAddrInfo.getCunJiMC() + externalInHospPatientAddrInfo.getQiTaXX());
            String por = null;
            if (StringUtils.isNotEmpty(externalInHospPatientAddrInfo.getDiZhiXX())) {
                por = externalInHospPatientAddrInfo.getDiZhiXX();
            } else {
                por = externalInHospPatientAddrInfo.getShengFenMC() + externalInHospPatientAddrInfo.getShiDiQMC() + externalInHospPatientAddrInfo.getXianQuMC() + externalInHospPatientAddrInfo.getXiangZhenMC() + externalInHospPatientAddrInfo.getCunJiMC() + externalInHospPatientAddrInfo.getQiTaXX();
            }
            patArchive.setPlaceOfResidence(por.replace("null", ""));
            patArchive.setBirthplace(por.replace("null", ""));
        }
        patArchive.setBirthdate(externalInHospPatientInfo.getChuShengRQ());
        patArchive.setAge(externalInHospPatientInfo.getNianLing());
        patArchive.setAgeUnit(externalInHospPatientInfo.getNianLingDW());
        patArchive.setTelcode(externalInHospPatientInfo.getLianXiDH());
        if (StringUtils.isEmpty(externalInHospPatientInfo.getLianXiDH()))
            patArchive.setTelcode(externalInHospPatientInfo.getLianXiRDH());
        patArchive.setRelativetelcode(externalInHospPatientInfo.getLianXiRDH());
        patArchive.setGuid(externalInHospPatientInfo.getZuZhiJGID());
        if (ObjectUtils.isNotEmpty(externalInHospPatientLiaisonInfo))
            patArchive.setRelativetelcode(externalInHospPatientLiaisonInfo.getLianXiRDH());
        patArchive.setInhospno(externalInHospPatientInfo.getZhuYuanHao());
        patArchive.setCreateTime(new Date());
        patArchive.setIdcardtype(externalInHospPatientInfo.getZhengJianLXMC());
        if (CollectionUtils.isNotEmpty(patArchives)) {
            //如果不为空,直接将查询出来的对象返回
            PatArchive patArchive1 = patArchives.get(0);
            String orgid = patArchive1.getOrgid();
            if (StringUtils.isNotEmpty(orgid)) {
                orgid = orgid + "," + externalInHospPatientInfo.getZuZhiJGID();
                patArchive.setOrgid(orgid);
                patArchive.setId(patArchive1.getId());
                patArchiveMapper.updatePatArchive(patArchive);
                return patArchive;
@@ -434,7 +713,9 @@
            patMedInhosp.setHospitalcode(externalInHospPatientInfo.getZuZhiJGID());
            patMedInhosp.setStarttime(externalInHospPatientInfo.getRuYuanSJ());
            patMedInhosp.setDeptcode(externalInHospPatientInfo.getDangQianKSID());
            patMedInhosp.setLeaveldeptcode(externalInHospPatientInfo.getDangQianKSID());
            patMedInhosp.setDeptname(externalInHospPatientInfo.getDangQianKSMC());
            patMedInhosp.setLeaveldeptname(externalInHospPatientInfo.getDangQianKSMC());
            patMedInhosp.setBedNo(externalInHospPatientInfo.getDangQianCWID());
            patMedInhosp.setOrgid(externalInHospPatientInfo.getZuZhiJGID());
            patMedInhosp.setHospitaldistrictid(externalInHospPatientInfo.getDangQianBQID());
@@ -443,7 +724,11 @@
            patMedInhosp.setOperator(externalInHospPatientInfo.getCaoZuoRXM());
            patMedInhosp.setOperatorId(externalInHospPatientInfo.getCaoZuoRID());
            patMedInhosp.setHospitaldistrictcode(externalInHospPatientInfo.getDangQianBQID());
            patMedInhosp.setLeavehospitaldistrictcode(externalInHospPatientInfo.getDangQianBQID());
            patMedInhosp.setHospitaldistrictname(externalInHospPatientInfo.getDangQianBQMC());
            patMedInhosp.setLeavehospitaldistrictname(externalInHospPatientInfo.getDangQianBQMC());
            patMedInhosp.setTelcode(patArchive.getTelcode());
            patMedInhosp.setDrname("");
        }
        if (ObjectUtils.isNotEmpty(externalInHospPatientDiagnoseInfo)) {
            patMedInhosp.setIcd10code(StringUtils.isNotEmpty(patMedInhosp.getIcd10code()) ? patMedInhosp.getIcd10code() + "," + externalInHospPatientDiagnoseInfo.getZhenDuanID() : externalInHospPatientDiagnoseInfo.getZhenDuanID());
@@ -454,7 +739,7 @@
            patMedInhosp.setPatid(patArchive.getId());
            patMedInhosp.setPatno(patArchive.getPatientno());
            patMedInhosp.setPatname(patArchive.getName());
            patMedInhosp.setDrname("");
            patMedInhosp.setSchemestatus(1L);
            patMedInhosp.setCreateTime(new Date());
        }
@@ -540,6 +825,7 @@
                return true;
            case "SM_SQ_ShenQing":
                log.error("手术申请入参类型为:{}", type);
                addOperationInfo(dataMap);
                return true;
            case "TJ_YW_BaoGaoXX":
                log.error("体检报告入参类型为:{}", type);