Browse Source

代码修改

LAPTOP-KB9HII50\70708 1 month ago
parent
commit
ac4c047898

+ 97 - 5
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/DsyyPrescriptionService.java

@ -34,7 +34,9 @@ import com.yihu.jw.restmodel.hospital.prescription.WlyyOutpatientVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionDiagnosisVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionInfoVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.encrypt.MD5;
import com.yihu.jw.util.entity.ServiceException;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.util.network.HttpResponse;
@ -48,10 +50,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
@Transactional
@ -120,6 +119,74 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
    public WlyyOutpatientVO selectOutpatientInfo(String patient,String conNo) throws Exception {
        return dsyyEntranceService.selectOutpatientInfo(patient,conNo);
    }
    //获取患者卡列表
    public JSONArray findCardNo(String idcard) throws Exception{
        return dsyyEntranceService.findCardNo(idcard);
    }
    /**
     * 根据身份证添加居民
     *
     * @param idcard
     * @return
     */
    public BasePatientDO addPaitentByIdcard(String idcard,String name) {
        try {
            JSONArray jsonArray = findCardNo(idcard);
            if(jsonArray==null||jsonArray.size()==0){
                return null;
            }
            String cardType = "";
            Integer sex = 3;
            String ssc = "";
            String mobile = null;
            for (int i=0;i<jsonArray.size();i++){
                JSONObject json = jsonArray.getJSONObject(i);
                String CARD_TYPE = json.getString("CARD_TYPE");
                if("".equals(CARD_TYPE)){
                    ssc = json.getString("CARD_NO");
                }
                sex = Integer.parseInt(json.getString("XB"));
            }
//            "\tPAT_NO AS \"PAT_NO\",\n" +
//                    "\tSICK_ID AS \"SICK_ID\",\n" +
//                    "\tCARD_NO AS \"CARD_NO\",\n" +
//                    "\tCARD_STAT AS \"CARD_STAT\",\n" +
//                    "\tOP_DATE AS \"OP_DATE\",\n" +
//                    "\tCARD_TYPE AS \"CARD_TYPE\",\n" +
//                    "\tXM AS \"XM\",\n" +
//                    "\tXB AS \"XB\",\n" +
//                    "\tLXDH AS \"LXDH\",\n" +
//                    "\tZJHM AS \"ZJHM\",\n" +
//                    "\tZHYE AS \"ZHYE\" \n" +
            BasePatientDO patient = new BasePatientDO();
            String salt = UUID.randomUUID().toString().substring(0,5);
            String pw = idcard.substring(idcard.length()-6);
            patient.setIdcard(idcard);
            patient.setCardType("01");
            patient.setName(name);
            patient.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
            patient.setSalt(salt);
            patient.setMobile(mobile);
            patient.setDel("1");
            patient.setEnabled(1);
            patient.setLocked(0);
            patient.setCreateTime(new Date());
            patient.setUpdateTime(new Date());
            patient.setSsc(ssc);
            patient.setBirthday(IdCardUtil.getBirthdayForIdcard(idcard));
            patient.setSex(sex);
            patient = patientDao.save(patient);
            return patient;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public String isEmty(String str){
        if (!StringUtils.isNoneBlank(str)){
            return null;
@ -131,7 +198,7 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
    /**
     * 获取门诊下所有处方信息
     * @param registerSn 流水号
     * @param patNo 居民id
     * @param patient 居民id
     * @param admNo 住院唯一号
     * @param realOrder 处方号
     * @return
@ -1360,6 +1427,31 @@ public class DsyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
        return object;
    }
    /**
     * 查询出院小结、门诊病历
     * serverCode 门诊病历 :JHIDS-USD-HLWMZBL-014  出院小结:JHIDS-USD-HLWCYXJ-013
     * @return
     */
    public String selectReportInfo(String serverCode,String patientId,String visitNo,int page,int size) throws Exception {
        String url = entranceUrl +"selectReportInfo";
        String object = "";
        Map<String,Object> params = new HashedMap();
        params.put("serverCode",serverCode);
        params.put("patientId",patientId);
        params.put("visitNo",visitNo);
        params.put("page",page);
        params.put("size",size);
        HttpResponse response = HttpUtils.doPost(url,params);
        String content = response.getContent();
        logger.info("response:"+content);
        JSONObject rs = JSON.parseObject(content);
        Integer status = rs.getInteger("status");
        if (status==200){
            object = rs.getString("detailModelList");
        }
        return object;
    }
    //=====================合理用药内网调用接口=======================

+ 3 - 0
business/base-service/src/main/java/com/yihu/jw/patient/dao/BasePatientDao.java

@ -62,4 +62,7 @@ public interface BasePatientDao extends JpaRepository<BasePatientDO, String>, Jp
    @Query("select p from BasePatientDO p where (p.idcard = ?1 or p.ssc = ?1 )  and p.del = '1'")
    List<BasePatientDO> getPatientByIdcardOrSsc(String patientInfo);
    @Query("select p from BasePatientDO p where p.idcard = ?1 and p.del = '1'")
    List<BasePatientDO> getPatientByIdcard(String idcard);
}

+ 9 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/patient/BasePatientDischargeRecord.java

@ -20,6 +20,7 @@ public class BasePatientDischargeRecord extends UuidIdentityEntity {
    private String idcard;
    private String content;
    private String status;//状态 空值待处理 1完成 ,2下转数据错误,3居民新增失败,4无出院小结或者门诊病历 5未找到满足条件的专病配置
    // 创建时间
    private Date createTime;
@ -48,4 +49,12 @@ public class BasePatientDischargeRecord extends UuidIdentityEntity {
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
}

+ 1 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/BaseDiseaseHospitalDO.java

@ -47,7 +47,7 @@ public class BaseDiseaseHospitalDO extends UuidIdentityEntityWithOperator {
    private String rehabilitationDownType;//康复下转 0自动 1手动
    private String rehabilitationTemplateId;//康复计划模板id
    private String turnDownRange;//下转范围 1出院患者 2门诊患者 3出院+门诊患者
    private String distributionType;//分配方式 1手动分配 2自动分配
    private String distributionType;//分配方式 1手动分配 2自动分配(分配康复计划项的执行医生)
    private String distributionTo;//分配对象 1主管医生 2主治医生
    public String getRehabilitationType() {

+ 9 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationPatientInfoDO.java

@ -74,6 +74,7 @@ public class RehabilitationPatientInfoDO extends IdEntity {
    private Integer signStatus;//签约状态(1已家签 0 待家签)
    private String createUser;//创建code
    private String createUserName;//创建者
    private String dischargeRecordId;//base_patient_discharge_record 表的id(医院下推id)
    public String getPatient() {
        return patient;
@ -432,4 +433,12 @@ public class RehabilitationPatientInfoDO extends IdEntity {
    public void setFromSource(Integer fromSource) {
        this.fromSource = fromSource;
    }
    public String getDischargeRecordId() {
        return dischargeRecordId;
    }
    public void setDischargeRecordId(String dischargeRecordId) {
        this.dischargeRecordId = dischargeRecordId;
    }
}

+ 18 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/rehabilitation/RehabilitationPlanTemplateDO.java

@ -61,6 +61,8 @@ public class RehabilitationPlanTemplateDO extends UuidIdentityEntityWithOperator
    //非数据库字段
    private Integer isFamily;//是否关联三师共管专病(1是0否)
    private String familyRelation;//关联专病code
    private String distributionType;//分配方式 1手动分配 2自动分配(分配康复计划项的执行医生)
    private String distributionTo;//分配对象 1主管医生 2主治医生
    private List<RehabilitationTemplateDetailDO> detailDOList;
    public String getType() {
@ -205,4 +207,20 @@ public class RehabilitationPlanTemplateDO extends UuidIdentityEntityWithOperator
    public void setDetailDOList(List<RehabilitationTemplateDetailDO> detailDOList) {
        this.detailDOList = detailDOList;
    }
    @Transient
    public String getDistributionType() {
        return distributionType;
    }
    public void setDistributionType(String distributionType) {
        this.distributionType = distributionType;
    }
    @Transient
    public String getDistributionTo() {
        return distributionTo;
    }
    public void setDistributionTo(String distributionTo) {
        this.distributionTo = distributionTo;
    }
}

+ 250 - 119
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/service/SynchronizePatientService.java

@ -1,5 +1,6 @@
package com.yihu.jw.hospital.module.rehabilitation.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -7,13 +8,17 @@ import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.door.SignPatientLabelInfo;
import com.yihu.jw.entity.patient.BasePatientDischargeRecord;
import com.yihu.jw.entity.specialist.rehabilitation.*;
import com.yihu.jw.hospital.module.rehabilitation.dao.PatientRehabilitationPlanDao;
import com.yihu.jw.hospital.module.rehabilitation.dao.RehabilitationDetailDao;
import com.yihu.jw.hospital.module.rehabilitation.dao.RehabilitationPatientInfoDao;
import com.yihu.jw.hospital.prescription.service.DsyyPrescriptionService;
import com.yihu.jw.hospital.team.dao.SignPatientLabelInfoDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientDischargeRecordDao;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.wlyy.service.WlyyBusinessService;
import org.apache.commons.lang3.StringUtils;
@ -27,10 +32,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
 * Created by liub on 2020/9/29.
@ -69,6 +71,10 @@ public class SynchronizePatientService  {
    private WlyyBusinessService businessService;
    @Autowired
    private RehabilitationManageService rehabilitationManageService;
    @Autowired
    private BasePatientDischargeRecordDao basePatientDischargeRecordDao;
    @Autowired
    private DsyyPrescriptionService dsyyPrescriptionService;
    //手动重新下转
@ -268,9 +274,22 @@ public class SynchronizePatientService  {
    //获取三院专病配置
    public RehabilitationPlanTemplateDO findPlanTemplate(String dept,String diagnosis){
        String sql = "SELECT t.*,d.is_family isFamily,d.id diseaseId,d.name diseaseName,d.family_relation familyRelation " +
                "FROM base_disease_hospital d,wlyy_rehabilitation_plan_template t " +
                "WHERE d.rehabilitation_template_id=t.id and d.`status`='1' and d.rehabilitation_down_type='0' and d.rehabilitation_type='1'" +
                "and d.dept like '%"+dept+"%' and d.diagnosis like '%"+diagnosis+"%' LIMIT 1";
                " FROM base_disease_hospital d,wlyy_rehabilitation_plan_template t " +
                " WHERE d.rehabilitation_template_id=t.id and d.`status`='1' and d.rehabilitation_down_type='0' and d.rehabilitation_type='1'" +
                " and d.dept like '%"+dept+"%' and d.diagnosis like '%"+diagnosis+"%' LIMIT 1";
        List<RehabilitationPlanTemplateDO> diseaseList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(RehabilitationPlanTemplateDO.class));
        if(diseaseList.size()==0){
            return null;
        }
        return diseaseList.get(0);
    }
    //获取三院专病配置
    public RehabilitationPlanTemplateDO findPlanTemplate(String dept,String diagnosis,String turnDownRange){
        String sql = "SELECT t.*,d.is_family isFamily,d.id diseaseId,d.name diseaseName,d.family_relation familyRelation " +
                ",d.distribution_type distributionType,d.distribution_to distributionTo FROM base_disease_hospital d,wlyy_rehabilitation_plan_template t " +
                " WHERE d.rehabilitation_template_id=t.id and d.`status`='1' and d.rehabilitation_down_type='0' and d.rehabilitation_type='1'" +
                " and d.turn_down_range in('"+turnDownRange+"','3') and d.dept like '%"+dept+"%' and d.diagnosis like '%"+diagnosis+"%' LIMIT 1";
        List<RehabilitationPlanTemplateDO> diseaseList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(RehabilitationPlanTemplateDO.class));
        if(diseaseList.size()==0){
            return null;
@ -529,71 +548,151 @@ public class SynchronizePatientService  {
    //康复管理自动下转
    public StringBuilder synchronizePation(String type) throws Exception {
        StringBuilder results = new StringBuilder("居民下转\n");
        JSONArray successSync = new JSONArray();//存储下转信息
        List<RehabilitationPatientInfoDO> rehabilitationPatientInfoDOs;
        Date nowDate = new Date();
        Date preTime = DateUtil.getPreDays(nowDate,-30);
        String preTimeStr = DateUtil.dateToStrShort(DateUtil.getPreDays(nowDate,-30));
        String sql = "";
        if (StringUtils.isBlank(type)){//为空
            results.append("未分配居民下转type:"+type+"\n");
            rehabilitationPatientInfoDOs = rehabilitationPatientInfoDao.findUnDispation(preTime);
        }
        else{
            Integer typeInt = Integer.parseInt(type);
            sql = " select * from base_patient_discharge_record where status is null and create_time>'"+preTimeStr+"'  order by create_time limit 30";
        }else{
            results.append("指定状态居民下转type:"+type+"\n");
            rehabilitationPatientInfoDOs = rehabilitationPatientInfoDao.findUnDispationByStatus(typeInt,preTime);
            sql = " select * from base_patient_discharge_record where status='"+type+"' and create_time>'"+preTimeStr+"'  order by create_time limit 30";
        }
        logger.info("康复计划自动下转————需要下转的居民人数" + rehabilitationPatientInfoDOs.size());
        results.append("需要下转的居民人数" + rehabilitationPatientInfoDOs.size() + "\n");
        List<RehabilitationPatientInfoDO> modifyList = new ArrayList<>();
        for (RehabilitationPatientInfoDO re : rehabilitationPatientInfoDOs) {
            List<RehabilitationPatientInfoDO> tmpList = getPatientInfoList(re.getIdcard(),DateUtil.dateToStrShort(re.getCreateTime()));
            Date diagnoseTime = re.getDiagnoseTime();
            //诊断时间为空或超过一个月 也不做下转
            if (diagnoseTime==null){
                infoUpdate(tmpList,4,modifyList,null);
        List<BasePatientDischargeRecord> patientDischargeRecords = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BasePatientDischargeRecord.class));
        logger.info("康复计划自动下转————需要下转的居民人数" + patientDischargeRecords.size());
        results.append("需要下转的居民人数" + patientDischargeRecords.size() + "\n");
        List<BasePatientDischargeRecord> modifyList = new ArrayList<>();
        for (BasePatientDischargeRecord re : patientDischargeRecords) {
            String idcard = re.getIdcard();
            if(StringUtils.isBlank(idcard)){
                re.setStatus("2");
                basePatientDischargeRecordDao.equals(re);
                continue;
            }
            if (DateUtil.getDays(nowDate,diagnoseTime)>30){
                infoUpdate(tmpList,4,modifyList,null);
                continue;
            String content = re.getContent();
            JSONObject json = null;
            try {
                json = JSON.parseObject(content);
            }catch (Exception e){
                e.printStackTrace();
            }
            //去除智业获取的厦心患者,智业获取到的一定有problemCode
            if(StringUtils.isNoneBlank(re.getProblemCode())){
                infoUpdate(tmpList,2,modifyList,null);
            if(json==null){
                re.setStatus("2");
                basePatientDischargeRecordDao.equals(re);
                continue;
            }
//            List<BasePatientDischargeRecord> tmpList = getPatientInfoList(re.getIdcard(),DateUtil.dateToStrShort(re.getCreateTime()));
//            Date diagnoseTime = re.getDiagnoseTime();
//            //诊断时间为空或超过一个月 也不做下转
//            if (diagnoseTime==null){
//                dischargeUpdate(tmpList,"4",modifyList);
//                continue;
//            }
//            if (DateUtil.getDays(nowDate,diagnoseTime)>30){
//                dischargeUpdate(tmpList,"4",modifyList);
//                continue;
//            }
//            //去除智业获取的厦心患者,智业获取到的一定有problemCode
//            if(StringUtils.isNoneBlank(re.getProblemCode())){
//                dischargeUpdate(tmpList,"2",modifyList);
//                continue;
//            }
            //"idcard":"510722201908261751","patientName":"龚嘉乐","cardNo":"510722201908261751" "conNo":"9","visitNo":"1727810009"}
            String name = json.getString("patientName");
            String cardNo = json.getString("cardNo");
            String conNo = json.getString("conNo");//就诊次数
            String visitNo = json.getString("visitNo");//就诊号
            BasePatientDO patient = null;
            if(StringUtils.isBlank(re.getIdcard())){
                infoUpdate(tmpList,5,modifyList,null);
                saveModifyList(modifyList);
                results.append("下转数据错误,身份证号不存在\n");
                continue;
            List<BasePatientDO> patientList = patientDao.getPatientByIdcard(re.getIdcard());//获取患者信息
            if (patientList.size() == 0) {
                //未找到居民,从his视图添加居民
                patient = dsyyPrescriptionService.addPaitentByIdcard(re.getIdcard(),name);
                if (patient == null) {
                    re.setStatus("3");
                    basePatientDischargeRecordDao.equals(re);
                    results.append("居民信息不存在\n");
                    continue;
                } else {
                    patientList = patientDao.getPatientByIdcardOrSsc(re.getIdcard());//重新获取该患者信息
                    patient = patientList.get(0);
                }
            }
            if(StringUtils.isBlank(re.getPatient())){
                List<BasePatientDO> patientList = patientDao.getPatientByIdcardOrSsc(re.getIdcard());//获取患者信息
                if (patientList.size() == 0) {
                    //未找到居民,从健康档案添加居民
                    patient = patientService.addPaitentByIdcard(re.getIdcard(),re.getName(),re.getSsc(),re.getMobile(),re.getSex());
                    if (patient == null) {
                        infoUpdate(tmpList,5,modifyList,null);
                        saveModifyList(modifyList);
                        results.append("居民信息不存在\n");
                        continue;
                    } else {
                        patientList = patientDao.getPatientByIdcardOrSsc(re.getIdcard());//重新获取该患者信息
                        patient = patientList.get(0);
                    }
            JSONArray jaMzbl = new JSONArray();
            JSONArray jaCy = new JSONArray();
            String eventType = "";//1门诊 2住院
            try {
                //门诊病历
                String mzbl = dsyyPrescriptionService.selectReportInfo("JHIDS-USD-HLWMZBL-014","",conNo,1,1);
                if(StringUtils.isNotBlank(mzbl)){
                    jaMzbl = JSONArray.parseArray(mzbl);
                }
                infoUpdate4(tmpList,patient.getId(),modifyList);
            }else {
                patient = patientDao.findByIdAndDel(re.getPatient(),"1");
                //出院小结
                String cyxj = dsyyPrescriptionService.selectReportInfo("JHIDS-USD-HLWCYXJ-013","",conNo,1,1);
                if(StringUtils.isNotBlank(cyxj)){
                    jaCy = JSONArray.parseArray(cyxj);
                }
            }catch (Exception e){
                e.printStackTrace();
            }
            String dept = re.getDept();
            String diagnosis = re.getDiagnosis();
            if(StringUtils.isBlank(eventType)){
                re.setStatus("4");
                basePatientDischargeRecordDao.equals(re);
                continue;
            }
            //同步病历 //如果同步病历失败,不做下转
            String result = "";
            if (demoFlag) {//测试线获取病历模板
                result = patientRecordService.getJosnFileResullt("event2");
            } else {
//                try {
//                    JSONObject jsonEvent = new JSONObject();
//                    List<Map<String, String>> resultMap = patientRecordService.getAllEvent_new(patient.getId(), "2", "1", "1", "2010-10-10 00:00:00", hos.getCode());
//                    jsonEvent.put("data", JSON.parseArray(JSON.toJSONString(resultMap)));
//                    result = jsonEvent.toString();
//                }catch (Exception e){
//                    infoUpdate(tmpList,3,modifyList,null);
//                    results.append("同步患者病历:" + re.getIdcard() + "----无住院病历信息\n");
//                    logger.info("康复计划自动下转————" + "同步患者病历:" + re.getIdcard() + "----无住院病历信息");
//                    continue;
//                }
            }
            com.alibaba.fastjson.JSONObject rejson = com.alibaba.fastjson.JSONObject.parseObject(result);
            JSONArray temlist = rejson.getJSONArray("data");
            if (0 == temlist.size()) {
                results.append("同步患者病历:" + re.getIdcard() + "----无住院病历信息\n");
                logger.info("康复计划自动下转————" + "同步患者病历:" + re.getIdcard() + "----无住院病历信息");
                continue;
            }
            com.alibaba.fastjson.JSONObject tem = temlist.getJSONObject(0);
            //创建下转记录表
            RehabilitationPatientInfoDO infoDO = new RehabilitationPatientInfoDO();
            infoDO.setPatient(patient.getId());
            infoDO.setStatus(0);
            infoDO.setIdcard(patient.getIdcard());
            infoDO.setAge(IdCardUtil.getAgeByBirthdayOrIdcard(patient.getIdcard(), patient.getBirthday()));
            infoDO.setSsc(patient.getSsc());
            infoDO.setAddress(patient.getAddress());
            infoDO.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
            infoDO.setCreateTime(new Date());
            infoDO.setName(patient.getName());
            infoDO.setSex(patient.getSex());
            infoDO.setMobile(patient.getMobile());
            infoDO.setFromSource(2);
            infoDO.setSignStatus(0);
            infoDO.setDischargeRecordId(re.getId());
            rehabilitationPatientInfoDao.save(infoDO);
            String dept = "科室";
//            String dept = re.getDept();
//            String diagnosis = re.getDiagnosis();
            String diagnosis = "诊断";
            //三院专病配置
            RehabilitationPlanTemplateDO planTemplateDO = findPlanTemplate(dept,diagnosis);
            RehabilitationPlanTemplateDO planTemplateDO = findPlanTemplate(dept,diagnosis,eventType);
            if(planTemplateDO==null){
                re.setStatus("5");
                basePatientDischargeRecordDao.equals(re);
                results.append("未找到满足条件的专病配置\n");
                continue;
            }
@ -601,21 +700,27 @@ public class SynchronizePatientService  {
                //判断签约的才推送i健康
                JSONObject isSign = businessService.isSign(re.getIdcard());
                if(isSign==null){
                    re.setStatus("6");
                    basePatientDischargeRecordDao.equals(re);
                    results.append("推送i健康失败\n");
                    continue;
                }
                infoDO.setSignStatus(1);
                rehabilitationPatientInfoDao.save(infoDO);
                if(isSign.getJSONObject("obj")!=null) {
                    //推送i健康数据
                    infoUpdate2(tmpList,planTemplateDO.getFamilyRelation(),modifyList);
                    saveModifyList(modifyList);
                    com.alibaba.fastjson.JSONObject jsonObject = businessService.pushPatientInfos(re);
                    com.alibaba.fastjson.JSONObject jsonObject = businessService.pushPatientInfos(infoDO);
                    if(jsonObject==null||jsonObject.getInteger("status")==-1){
                        re.setStatus("6");
                        basePatientDischargeRecordDao.equals(re);
                        results.append("推送i健康失败\n");
                        continue;
                    }
                    Long ijkId = jsonObject.getLong("data");
                    infoUpdate3(tmpList,3,ijkId,modifyList,null);
                    saveModifyList(modifyList);
                    infoDO.setIjkId(ijkId);
                    rehabilitationPatientInfoDao.save(infoDO);
                    re.setStatus("7");
                    basePatientDischargeRecordDao.equals(re);
                    results.append("推送i健康成功\n");
                    continue;
                }
@ -623,45 +728,26 @@ public class SynchronizePatientService  {
            String diseaseId = planTemplateDO.getDiseaseId();
            String diseaseName = planTemplateDO.getDiseaseName();
            String planTemplateId = planTemplateDO.getId();
            String planDoctorId = planTemplateDO.getPlanDoctor();//计划负责人
            BaseDoctorDO planDoctor = doctorDao.findByIdAndDel(planDoctorId);
            String planDoctorType = planTemplateDO.getPlanDoctorType();//计划负责人 1手动获取,2自动获取
            String planDoctorId = planTemplateDO.getPlanDoctor();//类型=1康复计划负责人,类型2  1主管医生 2主治医生
            String distributionType = planTemplateDO.getDistributionType();//分配方式 1手动分配 2自动分配(分配康复计划项的执行医生)
            String distributionTo = planTemplateDO.getDistributionTo();//分配对象 1主管医生 2主治医生
            BaseDoctorDO planDoctor = null;
            BaseDoctorDO zgDoctor = null;//主管医生
            BaseDoctorDO zzDoctor = null;//主治医生
            if("1".equals(planDoctorType)){
                planDoctor = doctorDao.findByIdAndDel(planDoctorId);
            }else {
                if("1".equals(planDoctorId)){
                    //1主管医生
            //同步病历 //如果同步病历失败,不做下转
            String result = "";
            if (demoFlag) {//测试线获取病历模板
                result = patientRecordService.getJosnFileResullt("event" + "2");
            } else {
//                try {
//                    JSONObject jsonEvent = new JSONObject();
//                    List<Map<String, String>> resultMap = patientRecordService.getAllEvent_new(patient.getId(), "2", "1", "1", "2010-10-10 00:00:00", hos.getCode());
//                    jsonEvent.put("data", JSON.parseArray(JSON.toJSONString(resultMap)));
//                    result = jsonEvent.toString();
//                }catch (Exception e){
//                    infoUpdate(tmpList,3,modifyList,null);
//                    results.append("同步患者病历:" + re.getIdcard() + "----无住院病历信息\n");
//                    logger.info("康复计划自动下转————" + "同步患者病历:" + re.getIdcard() + "----无住院病历信息");
//                    continue;
//                }
            }
            com.alibaba.fastjson.JSONObject rejson = com.alibaba.fastjson.JSONObject.parseObject(result);
            JSONArray temlist = rejson.getJSONArray("data");
            if (0 == temlist.size()) {
                results.append("同步患者病历:" + re.getIdcard() + "----无住院病历信息\n");
                logger.info("康复计划自动下转————" + "同步患者病历:" + re.getIdcard() + "----无住院病历信息");
                infoUpdate(tmpList,3,modifyList,null);
//                if(!isPatientExist){//患者不存在与医生原有的康复列表中,添加推送消息
//                    successSync = addSyncPatientInfo(successSync, doctor.getId(), doctor.getName(), teamId, adminTeam.getName(), hos.getCode(), hos.getName(), patient.getId(),0);
//                }
                continue;
                }else {
                    //2主治医生
                }
            }
//            if (!needCreateRehabilitationPlan(hos.getCode())) {//仅厦心进行自动下转至已下转 //厦心不推送消息
//                if(!isPatientExist){//患者不存在与医生原有的康复列表中,添加推送消息
//                    successSync = addSyncPatientInfo(successSync, doctor.getId(), doctor.getName(), teamId, adminTeam.getName(), hos.getCode(), hos.getName(), patient.getId(),0);
//                }
//                continue;
//            }
            com.alibaba.fastjson.JSONObject tem = temlist.getJSONObject(0);
            /**
             * {
             "orgName": "厦门大学附属心血管病医院",
@ -681,11 +767,11 @@ public class SynchronizePatientService  {
            if (demoFlag) {//测试获取为病历模板 hospitalcode获取为自己的code
//                pmr.setHospital(hos.getCode());
            }
            pmr.setDischargeDiagnosis(re.getDiagnosis());
            pmr.setDischargeDiagnosisName(re.getDiagnosisName());
            pmr.setAdmittingDiagnosis(re.getDiagnosis());
//            pmr.setDischargeDiagnosis(re.getDiagnosis());
//            pmr.setDischargeDiagnosisName(re.getDiagnosisName());
//            pmr.setAdmittingDiagnosis(re.getDiagnosis());
            pmr.setJwpatient(tem.getString("patient"));
            pmr.setAdmittingDiagnosisName(re.getDiagnosisName());
//            pmr.setAdmittingDiagnosisName(re.getDiagnosisName());
            pmr.setEvent(tem.getString("id"));
            pmr.setDataFrom(tem.getString("dataFrom"));
            pmr.setAdvice("出院继续观察");
@ -708,10 +794,6 @@ public class SynchronizePatientService  {
            if (patientMedicalRecordsDO1 == null) {
                results.append("创建病历请求:" + re.getIdcard() + "----创建病历失败\n");
                logger.info("康复计划自动下转————" + "创建病历请求:" + re.getIdcard() + "----创建病历失败");
                infoUpdate(tmpList,2,modifyList,null);
//                if(!isPatientExist){//患者不存在与医生原有的康复列表中,添加推送消息
//                    successSync = addSyncPatientInfo(successSync, doctor.getId(), doctor.getName(), teamId, adminTeam.getName(), hos.getCode(), hos.getName(), patient.getId(),0);
//                }
                continue;
            } else {//
                // ↓创建康复计划。创建完成即为已下转
@ -727,22 +809,17 @@ public class SynchronizePatientService  {
                planDO.setMedicalRecordsCode(patientMedicalRecordsDO1.getCode());//居民住院病历code
                planDO.setPlanDoctor(planDoctorId);
                planDO.setPlanDoctorName(planDoctor.getName());
                planDO.setPatientInfoCode(re.getCode());
                planDO.setPatientInfoCode(infoDO.getCode());
                planDO.setCreateTime(new Date());
                planDO.setUpdateTime(new Date());
                planDO.setDisease(diseaseId);
                planDO.setDiseaseName(diseaseName);
//            planDO.setTotalExpense();
                //目前默认为冠心病
                //创建康复计划
                planDO = createRehabilitationPlanJson(planDO,planTemplateId,results,re);
                planDO = createRehabilitationPlanJson(planDO,planTemplateId,results,infoDO);
                if (planDO == null) {//创建康复计划不成功,无法下转
                    results.append("创建康复计划请求:" + re.getIdcard() + "----创建康复计划请求失败\n");
                    logger.info("康复计划自动下转————" + "创建康复计划请求:" + re.getIdcard() + "----创建康复计划请求失败");
                    infoUpdate(tmpList,2,modifyList,null);
//                    if(!isPatientExist){//患者不存在与医生原有的康复列表中,添加推送消息
//                        successSync = addSyncPatientInfo(successSync, doctor.getId(), doctor.getName(), teamId, adminTeam.getName(), hos.getCode(), hos.getName(), patient.getId(),0);
//                    }
                    continue;
                } else {//创建康复计划成功
                    String planId = planDO.getId();
@ -763,18 +840,16 @@ public class SynchronizePatientService  {
                    signPatientLabelInfo.setStatus(1);
                    signPatientLabelInfo.setCzrq(new Date());
                    signPatientLabelInfoDao.save(signPatientLabelInfo);
                    infoUpdate(tmpList,1,modifyList,planDoctor);
                    infoDO.setStatus(1);
                    rehabilitationPatientInfoDao.save(infoDO);
                    re.setStatus("1");
                    basePatientDischargeRecordDao.equals(re);
                    results.append("下转结束:" + re.getIdcard() + "----下转成功");
                    logger.info("康复计划自动下转————" +"下转结束:" + re.getIdcard() + "----下转成功");
                    //给服务医生群组发送下转消息
//                    if (StringUtils.isNoneBlank(planId)){
//                        asynService.sendMsg(planId,signFamily,patient,doctor,patientMedicalRecordsDO1,re);
//                    }
//                    messageService.addSpecialistDynamicMessages(patient,doctor,familyDoctor,"下转成功",diseaseObj.getString("disease"),"1",null);
                }
            }
        }
        rehabilitationPatientInfoDao.saveAll(modifyList);
        return results;
    }
@ -811,6 +886,53 @@ public class SynchronizePatientService  {
        return planDO;
    }
    /**
     * 创建康复计划json
     */
    public PatientRehabilitationPlanDO createRehabilitationPlanJson(PatientRehabilitationPlanDO planDO, String planTemplateId,StringBuilder results
            , RehabilitationPatientInfoDO re,String distributionType,String distributionTo,BaseDoctorDO zgDoctor,BaseDoctorDO zzDoctor) throws Exception{
        String sql = "select * from wlyy_rehabilitation_template_detail where template_id = '" + planTemplateId + "'";
        List<RehabilitationTemplateDetailDO> templateDetail = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(RehabilitationTemplateDetailDO.class));
        if (templateDetail.size() == 0) {
            results.append("系统默认的康复模板请求:" + re.getIdcard() + "----系统默认的康复模板为空,请手动进行下转\n");
            return null;
        }
        planDO = patientRehabilitationPlanDao.save(planDO);
        List<RehabilitationDetailDO> detailDOList = new ArrayList<>();
        for(RehabilitationTemplateDetailDO detailDO : templateDetail) {
            String frequency_code = detailDO.getFrequencyCode();//频次
            RehabilitationDetailDO detail = new RehabilitationDetailDO();
            detail.setHospitalServiceItemId(detailDO.getHospitalServiceItemId());
            detail.setCreateTime(new Date());
            detail.setStatus(0);
            detail.setType(1);
            detail.setUpdateTime(new Date());
            detail.setPlanId(planDO.getId());
            detail.setFrequencyCode(frequency_code);
            if("2".equals(distributionType)){
                if("1".equals(distributionTo)){
                    //1主管医生
//                    detail.setDept();
//                    detail.setDeptName();
                    detail.setDoctor(zgDoctor.getId());
                    detail.setDoctorName(zgDoctor.getName());
                }else {
                    //2主治医生
//                    detail.setDept();
//                    detail.setDeptName();
                    detail.setDoctor(zzDoctor.getId());
                    detail.setDoctorName(zzDoctor.getName());
                }
            }
            detailDOList.add(detail);
        }
        rehabilitationDetailDao.saveAll(detailDOList);
        rehabilitationManageService.addPlanLog(planDO.getId(),planDO.getPlanDoctor(),planDO.getPlanDoctorName());
        planDO.setDetailDOList(detailDOList);
        return planDO;
    }
    @Transactional(propagation= Propagation.NOT_SUPPORTED)
    public void runSqlNow(String sql){
@ -857,6 +979,15 @@ public class SynchronizePatientService  {
        }
    }
    //更新患者下转状态
    public void dischargeUpdate(List<BasePatientDischargeRecord> lists,String status,List<BasePatientDischargeRecord> modifyList){
        for (BasePatientDischargeRecord re:lists){
            re.setStatus(status);
            modifyList.remove(re);
            modifyList.add(re);
        }
    }
    public void infoUpdate2(List<RehabilitationPatientInfoDO> lists,String problemCode,List<RehabilitationPatientInfoDO> modifyList){
        for (RehabilitationPatientInfoDO re:lists){
            re.setProblemCode(problemCode);