Browse Source

处方状态变更job

zdm 5 years ago
parent
commit
587b49a8c5

+ 2 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/OutpatientDao.java

@ -19,4 +19,6 @@ public interface OutpatientDao extends PagingAndSortingRepository<WlyyOutpatient
    List<WlyyOutpatientDO> findByDoctorAndStatus(String doctor,String status);
    
    List<WlyyOutpatientDO> findByDoctor(String doctor);
    WlyyOutpatientDO findById(String id);
}

+ 3 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/PrescriptionDao.java

@ -28,4 +28,7 @@ public interface PrescriptionDao extends PagingAndSortingRepository<WlyyPrescrip
    List<WlyyPrescriptionDO> findByOutpatientId(String outpatientId);
    List<WlyyPrescriptionDO> findById(String id);
    WlyyPrescriptionDO findByRealOrder(String realOrder);
}

+ 53 - 22
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/EntranceService.java

@ -12,9 +12,11 @@ import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.hospital.dict.WlyyChargeDictDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.hospital.dict.WlyyChargeDictDao;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.prescription.service.entrance.util.ConvertUtil;
import com.yihu.jw.hospital.prescription.service.entrance.util.MqSdkUtil;
import com.yihu.jw.hospital.prescription.service.entrance.util.WebserviceUtil;
@ -78,6 +80,7 @@ public class EntranceService {
    private static String MS02013="MS02013";
    //医院频次字典表
    private static String MS30012="MS30012";
    private String orgCode="350211A1002";
    @Value("${hospital.mqUser}")
    private String mqUser;
    @Value("${hospital.mqPwd}")
@ -102,6 +105,8 @@ public class EntranceService {
    private BaseDoctorHospitalDao baseDoctorHospitalDao;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private PrescriptionDao prescriptionDao;
    /**
     * 获取本地示例返参
@ -380,57 +385,82 @@ public class EntranceService {
     * @param realOrder
     * @return
     */
    public WlyyPrescriptionVO initWlyyPrescriptionVo(WlyyPrescriptionVO wlyyPrescriptionVO , net.sf.json.JSONObject jsonObjectBody,String realOrder){
    public WlyyPrescriptionVO initWlyyPrescriptionVo(WlyyPrescriptionVO wlyyPrescriptionVO , net.sf.json.JSONObject jsonObjectBody,String realOrder) {
        wlyyPrescriptionVO.setAdmNo(null != jsonObjectBody.get("ADM_NO") ? jsonObjectBody.get("ADM_NO").toString() : "");
        wlyyPrescriptionVO.setRealOrder(realOrder);
        wlyyPrescriptionVO.setSerialNo(null != jsonObjectBody.get("REGISTER_SN") ? jsonObjectBody.get("REGISTER_SN").toString() : "");
        wlyyPrescriptionVO.setType(1);
        String patNo=null != jsonObjectBody.get("PAT_NO") ? jsonObjectBody.get("PAT_NO").toString() : "";
        String patientName=null != jsonObjectBody.get("UOM") ? jsonObjectBody.get("UOM").toString() : "";
        PatientMappingDO patientMappingDo=new PatientMappingDO();
        if(StringUtils.isNotBlank(patNo)){
            patientMappingDo=  patientMappingDao.findByMappingCodeAndSource(patNo.trim(),"1");
            patNo=null==patientMappingDo?null:patientMappingDo.getPatient();
            patientName=null==patientMappingDo?null:patientMappingDo.getPatientName();
        String patNo = null != jsonObjectBody.get("PAT_NO") ? jsonObjectBody.get("PAT_NO").toString() : "";
        String patientName = null != jsonObjectBody.get("UOM") ? jsonObjectBody.get("UOM").toString() : "";
        PatientMappingDO patientMappingDo = new PatientMappingDO();
        if (StringUtils.isNotBlank(patNo)) {
            patientMappingDo = patientMappingDao.findByMappingCodeAndSource(patNo.trim(), "1");
            patNo = null == patientMappingDo ? null : patientMappingDo.getPatient();
            patientName = null == patientMappingDo ? null : patientMappingDo.getPatientName();
        }
        wlyyPrescriptionVO.setPatientCode(patNo);
        wlyyPrescriptionVO.setPatientName(patientName);
        wlyyPrescriptionVO.setIdcard(null == patientMappingDo ? null : patientMappingDo.getIdcard());
        //TODO 社保卡号
        wlyyPrescriptionVO.setSsc("");
        wlyyPrescriptionVO.setHisDoctorCode(null != jsonObjectBody.get("PRESC_DOC") ? jsonObjectBody.get("PRESC_DOC").toString() : "");
        wlyyPrescriptionVO.setHisDeptCode(null != jsonObjectBody.get("PRESC_SPEC") ? jsonObjectBody.get("PRESC_SPEC").toString() : "");
        //中山医院处方状态
        String status = null != jsonObjectBody.get("PAY_MARK") ? jsonObjectBody.get("PAY_MARK").toString() : "";
        /**互联网医院处方状态字典:
             续方取消:-3 支付过期取消,-2 患者自己取消 ,-1 医生取消
             候诊中:0 候诊中
             就诊中:10 诊断中,11 药师审核失败 / 调整中,12  药师审核完成,13  开方失败/调整中
             开方成功:20 诊断完成/开方成功/待支付,21 支付失败/待支付中
             待取药:30 支付成功/等待配药,31 配药成功/等待取药,32 配送中
             已完成:100 已完成
         续方取消:-3 支付过期取消,-2 患者自己取消 ,-1 医生取消
         候诊中:0 候诊中
         就诊中:10 诊断中,11 药师审核失败 / 调整中,12  药师审核完成,13  开方失败/调整中
         开方成功:20 诊断完成/开方成功/待支付,21 支付失败/待支付中
         待取药:30 支付成功/等待配药,31 配药成功/等待取药,32 配送中
         已完成:100 已完成
         中山医院处方状态字典:0-正常已收费 1-退费 5-正常未收费 a-皮试后用药 c-作废处方
         */
        //互联网医院处方状态
        Integer hlwyyStatus=10;
        switch (status){
        Integer hlwyyStatus = 10;
        switch (status) {
            case "0":
                hlwyyStatus=30;
                hlwyyStatus = 30;
                break;
            case "1":
                hlwyyStatus=13;
                hlwyyStatus = 13;
                break;
            case "5":
                hlwyyStatus=20;
                hlwyyStatus = 20;
                break;
            case "a":
                hlwyyStatus=100;
                hlwyyStatus = 100;
                break;
            case "c":
                hlwyyStatus=13;
                hlwyyStatus = 13;
                break;
        }
        //发药时间
        String dispDate = null != jsonObjectBody.get("DISP_DATE") ? jsonObjectBody.get("DISP_DATE").toString() : "";
        if(StringUtils.isNotBlank(dispDate)){
            //根据处方号获取处方
            WlyyPrescriptionDO wlyyPrescriptionDO=prescriptionDao.findByRealOrder(realOrder);
            if(null!=wlyyPrescriptionDO&&1==wlyyPrescriptionDO.getDispensaryType()){
                //自取
                hlwyyStatus=31;
            }else {
                //快递配送
                hlwyyStatus=32;
            }
            //发药医生编码-中山医院
            String dispUser = null != jsonObjectBody.get("DISP_USER") ? jsonObjectBody.get("DISP_USER").toString() : "";
            wlyyPrescriptionVO.setDispDate(DateUtil.strToDate(dispDate));
            //转换为本地医生编码
            List<DoctorMappingDO> mappingDOs = doctorMappingDao.findByOrgCodeAndMappingCode(orgCode, dispUser);
            String dispUserName = "";
            if (mappingDOs != null && mappingDOs.size() > 0) {
                dispUser = mappingDOs.get(0).getDoctor();
                dispUserName = mappingDOs.get(0).getDoctorName();
            }
            wlyyPrescriptionVO.setDispUser(dispUser);
            wlyyPrescriptionVO.setDispUserName(dispUserName);
        }
        wlyyPrescriptionVO.setStatus(hlwyyStatus);
        return wlyyPrescriptionVO;
    }
@ -450,6 +480,7 @@ public class EntranceService {
        wlyyPrescriptionDiagnosisVO.setName(icdName);
        wlyyPrescriptionDiagnosisVO.setCreateTime(new Date());
        wlyyPrescriptionDiagnosisVO.setType(type);
       return wlyyPrescriptionDiagnosisVO;
    }

+ 120 - 32
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/service/channel/PrescriptionStatusUpdateService.java

@ -2,6 +2,13 @@ package com.yihu.jw.service.channel;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDiagnosisDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
import com.yihu.jw.hospital.prescription.dao.*;
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.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.status.EnvelopStatus;
@ -17,9 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * 处方状态更新job
@ -38,6 +43,14 @@ public class PrescriptionStatusUpdateService {
    private JdbcTemplate jdbcTemplate;
    @Value("${hlwyyEntrance.url}")
    private String hlwyyEntranceUrl;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
    @Autowired
    private PrescriptionInfoDao prescriptionInfoDao;
    @Autowired
    private OutpatientDao outpatientDao;
    public void autoPush() throws Exception{
        //获取所有就诊中已挂号、已下临时处方、并且未结束的处方
@ -55,6 +68,10 @@ public class PrescriptionStatusUpdateService {
            String conNo=String.valueOf(map.get("con_no"));
            //处方原状态
            String status=String.valueOf(map.get("status"));
            //处方Id
            String preId=String.valueOf(map.get("preId"));
            //门诊记录Id
            String outPatientId=String.valueOf(map.get("id"));
            //根据处方号获取处方状态
            Map<String, Object> params =new HashMap<>();
@ -71,15 +88,108 @@ public class PrescriptionStatusUpdateService {
                params.remove("realOrder");
                wlyyPrescriptionVOS= getWlyyPrescriptionVO(params);
            }
            //根据处方id获取处方详情
            WlyyPrescriptionDO wlyyPrescriptionDO=prescriptionDao.findOne(preId);
            //根据门诊id获取门诊记录:如果处方状态为已完成,需要将门诊状态改为已诊
            WlyyOutpatientDO wlyyOutpatientDO=outpatientDao.findById(outPatientId);
            if(null!=wlyyPrescriptionVOS){
                //如果状态为100,门诊记录需要变更为结束
                //如果状态为13 则需要保存处方状态
                //如果原来状态为13,则需要将处方重新获取
                //
                WlyyPrescriptionVO wlyyPrescriptionVO=wlyyPrescriptionVOS.get(0);
                wlyyPrescriptionDO.setStatus(wlyyPrescriptionVO.getStatus());
                //用处方号获取不到处方时,重新更新处方到本地
                if(!preExistFlag){
                    //删除原有药品信息
                    List<WlyyPrescriptionInfoDO> oldInfos = prescriptionInfoDao.findByPrescriptionId(preId);
                    if(oldInfos!=null&&oldInfos.size()>0){
                        prescriptionInfoDao.delete(oldInfos);
                    }
                    //删除之前诊断
                    List<WlyyPrescriptionDiagnosisDO> ds = prescriptionDiagnosisDao.findByPrescriptionId(preId);
                    if(ds!=null&&ds.size()>0){
                        prescriptionDiagnosisDao.delete(ds);
                    }
                    String Icd10 = "";
                    String Icd10Name = "";
                    List<WlyyPrescriptionDiagnosisDO> wlyyPrescriptionDiagnosisDOS=new ArrayList<>();
                    for(WlyyPrescriptionDiagnosisVO diagnosisVO:wlyyPrescriptionVO.getDiagnosisVOs()){
                        WlyyPrescriptionDiagnosisDO diagnosisDO=new WlyyPrescriptionDiagnosisDO();
                        //将诊断拼接放到门诊记录中
                        if("1".equals(diagnosisVO.getType())){
                            Icd10 = diagnosisVO.getCode()+","+Icd10;
                            Icd10Name+=diagnosisVO.getName()+","+Icd10Name;
                        }else {
                            Icd10+=diagnosisVO.getCode()+",";
                            Icd10Name+=diagnosisVO.getName()+",";
                        }
                        diagnosisDO.setCode(diagnosisVO.getCode());
                        diagnosisDO.setName(diagnosisVO.getName());
                        diagnosisDO.setType(diagnosisVO.getType());
                        diagnosisDO.setPrescriptionId(preId);
                        diagnosisDO.setCreateTime(new Date());
                        wlyyPrescriptionDiagnosisDOS.add(diagnosisDO);
                    }
                    //重新保存诊断
                    prescriptionDiagnosisDao.save(wlyyPrescriptionDiagnosisDOS);
                    //药品更新
                    List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS=new ArrayList<>();
                    for(WlyyPrescriptionInfoVO infoVO:wlyyPrescriptionVO.getInfoVOs()){
                        WlyyPrescriptionInfoDO infoDO=new WlyyPrescriptionInfoDO();
                        //处方code 关联表wlyy_prescription code
                        infoDO.setPrescriptionId(preId);
                        //药品编号
                        infoDO.setDrugNo(infoVO.getDrugNo());
                        //药品名称
                        infoDO.setDrugName(infoVO.getDrugName());
                        //库房号
                        infoDO.setDispDeposite(infoVO.getDispDeposite());
                        // 药量
                        infoDO.setDosage(infoVO.getDosage());
                        //数量
                        infoDO.setQuantity(infoVO.getQuantity());
                        //单位
                        infoDO.setUnit(infoVO.getUnit());
                        //單位名稱
                        infoDO.setUnitName(infoVO.getUnitName());
                        //包装单位
                        infoDO.setPackUnit(infoVO.getPackUnit());
                        //包装单位名称
                        infoDO.setPackUnitName(infoVO.getPackUnitName());
                        // 用法
                        infoDO.setSupplyCode(infoVO.getSupplyCode());
                        //用法名稱
                        infoDO.setSupplyName(infoVO.getSupplyName());
                        //天数
                        infoDO.setDays(infoVO.getDays());
                        //组号
                        infoDO.setFrequency(infoVO.getFrequency());
                        //药品收费码
                        infoDO.setSerial(infoVO.getSerial());
                        //库房号
                        infoDO.setGroupNo(infoVO.getGroupNo());
                        //规格
                        infoDO.setSpecification(infoVO.getSpecification());
                        // 1可用 0删除
                        infoDO.setDel(1);
                        //频率
                        infoDO.setUsageCode(infoVO.getUsageCode());
                        //頻率名稱
                        infoDO.setUsageName(infoVO.getUsageName());
                        //包装价格
                        infoDO.setPackRetprice(infoVO.getPackRetprice());
                        wlyyPrescriptionInfoDOS.add(infoDO);
                    }
                    prescriptionInfoDao.save(wlyyPrescriptionInfoDOS);
                    Icd10 = Icd10.substring(0,Icd10.length()-1);
                    Icd10Name = Icd10Name.substring(0,Icd10Name.length()-1);
                    wlyyOutpatientDO.setIcd10(Icd10);
                    wlyyOutpatientDO.setIcd10Name(Icd10Name);
                }
                if(100==wlyyPrescriptionVO.getStatus()){
                    wlyyOutpatientDO.setStatus("2");
                }
                outpatientDao.save(wlyyOutpatientDO);
                prescriptionDao.save(wlyyPrescriptionDO);
            }
            }
        }
@ -103,26 +213,4 @@ public class PrescriptionStatusUpdateService {
            return null;
        }
    public void updatePrescriptionStatusByAdmNo(String admNo,String realOrder,String status)throws Exception{
        String  sql="";
        String outPatientSql="";
        if ("1".equals(status)) {
            sql = "UPDATE base.wlyy_prescription p SET p.`status`='13' WHERE p.adm_no='" + admNo + "' AND p.real_order='" + realOrder + "' ";
        } else if ("2".equals(status)) {
            //开方成功时候,先用处方号获取本地处方状态是否为开方失败,如果是则需要更新本地的处方
            sql = "UPDATE base.wlyy_prescription p SET p.`status`='20' WHERE p.adm_no='" + admNo + "' AND p.real_order='" + realOrder + "' ";
            //变更门诊状态
            outPatientSql="UPDATE base.wlyy_outpatient p SET p.`status`='2' WHERE p.adm_no='" + admNo + "'";
            jdbcTemplate.execute(outPatientSql);
        } else if ("3".equals(status)) {
            //自取处方结束
            sql = "UPDATE base.wlyy_prescription p SET p.`status`='100',p.pay_status='1' WHERE p.adm_no='" + admNo + "' AND p.real_order='" + realOrder + "' ";
        }
        jdbcTemplate.execute(sql);
    }
}