Quellcode durchsuchen

Merge branch 'dev' of huangwenjie/wlyy2.0 into dev

huangwenjie vor 5 Jahren
Ursprung
Commit
36eb9f6ddc

+ 680 - 864
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -162,8 +162,6 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    private HibenateUtils hibenateUtils;
    @Autowired
    private BaseDoctorPatientFollowDao baseOrgPatientDao;
    @Autowired
    private WlyyHospitalWorkRuleDao wlyyHospitalWorkRuleDao;
    @Value("${demo.flag}")
@ -672,7 +670,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    }
    public Boolean cancelPrescription(String prescriptionId) {
    public Boolean cancelPrescription(String prescriptionId){
        WlyyPrescriptionDO prescriptionDO = prescriptionDao.findOne(prescriptionId);
        prescriptionDO.setStatus(-2);
        return true;
@ -680,18 +678,18 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * @param admNo     门诊唯一号
     *@param admNo 门诊唯一号
     * @param realOrder 处方号
     * @param status    处方状态 1审方失败,2审核完成,3结算完成
     *  @param status 处方状态 1审方失败,2审核完成,3结算完成
     * @return
     */
    public Map<String, Object> updatePrescriptionByHisStatu(String admNo, String realOrder, String status) throws Exception {
        Map<String, Object> rs = new HashedMap();
    public Map<String,Object> updatePrescriptionByHisStatu(String admNo,String realOrder,String status)throws Exception {
        Map<String,Object> rs = new HashedMap();
        String sql = "";
        //status 处方流程状态 ,13  开方失败/调整中,20 诊断完成/开方成功/待支付,已完成:100 已完成
        //pay_status`:处方结算状态,0为未结算,1为结算成功,默认为0',
        String outPatientSql = "";
        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 + "' ";
            WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findByRealOrder(realOrder);
@ -701,7 +699,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            //开方成功时候,先用处方号获取本地处方状态是否为开方失败,如果是则需要更新本地的处方
            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 + "'";
            outPatientSql="UPDATE base.wlyy_outpatient p SET p.`status`='2' WHERE p.adm_no='" + admNo + "'";
            jdbcTemplate.execute(outPatientSql);
            jdbcTemplate.execute(sql);
@ -715,7 +713,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                wlyyPrescriptionDO.setPayStatus(1);
                wlyyPrescriptionDO.setStatus(100);
                prescriptionLogService.addPrescriptionLog(wlyyPrescriptionDO.getId(), 100, 2, outpatientDO.getDoctor(), outpatientDO.getDoctorName(), "", new Date());
                prescriptionLogService.addPrescriptionLog(wlyyPrescriptionDO.getId(),100,2,outpatientDO.getDoctor(),outpatientDO.getDoctorName(),"",new Date());
                prescriptionDao.save(wlyyPrescriptionDO);
            } else {
@ -723,30 +721,30 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                wlyyPrescriptionDO.setPayStatus(1);
                wlyyPrescriptionDO.setStatus(32);
                try {
                    WlyyPrescriptionVO vo = findOriginPrescription(outpatientDO.getRegisterNo(), outpatientDO.getPatient(), admNo, realOrder, demoFlag);
                try{
                    WlyyPrescriptionVO vo = findOriginPrescription(outpatientDO.getRegisterNo(),outpatientDO.getPatient(),admNo,realOrder,demoFlag);
                    wlyyPrescriptionDO.setDispUser(vo.getDispUser());
                    wlyyPrescriptionDO.setDispUserName(vo.getDispUserName());
                    wlyyPrescriptionDO.setDispDate(new Date());
                    prescriptionLogService.addPrescriptionLog(wlyyPrescriptionDO.getId(), 32, 2, vo.getDispUser(), vo.getDispUserName(), "", new Date());
                } catch (Exception e) {
                    logger.error("获取处方信息异常" + e.toString());
                    prescriptionLogService.addPrescriptionLog(wlyyPrescriptionDO.getId(),32,2,vo.getDispUser(),vo.getDispUserName(),"",new Date());
                }catch (Exception e){
                    logger.error("获取处方信息异常"+e.toString());
                }
                prescriptionDao.save(wlyyPrescriptionDO);
            }
            //发送取药系统消息
            SystemMessageDO systemMessageDO = sendPatientGetDrugMes(outpatientDO, wlyyPrescriptionDO);
            SystemMessageDO systemMessageDO = sendPatientGetDrugMes(outpatientDO,wlyyPrescriptionDO);
            rs.put("mes", systemMessageDO);
            rs.put("mes",systemMessageDO);
        }
        rs.put("flag", true);
        rs.put("flag",true);
        return rs;
    }
    public SystemMessageDO sendPatientGetDrugMes(WlyyOutpatientDO outpatient, WlyyPrescriptionDO prescriptionDO) {
    public SystemMessageDO sendPatientGetDrugMes(WlyyOutpatientDO outpatient,WlyyPrescriptionDO prescriptionDO){
        SystemMessageDO systemMessageDO = new SystemMessageDO();
        try {
        try{
            systemMessageDO.setTitle("患者取药");
            systemMessageDO.setType("7");
@ -758,38 +756,37 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            systemMessageDO.setRelationCode(outpatient.getId());
            JSONObject data = new JSONObject();
            data.put("name", outpatient.getPatientName());
            data.put("age", IdCardUtil.getAgeForIdcard(outpatient.getIdcard()));
            data.put("gender", IdCardUtil.getSexForIdcard_new(outpatient.getIdcard()));
            data.put("recipeType", prescriptionDO.getDispensaryType());
            data.put("message", "患者已完成取药");
            data.put("name",outpatient.getPatientName());
            data.put("age",IdCardUtil.getAgeForIdcard(outpatient.getIdcard()));
            data.put("gender",IdCardUtil.getSexForIdcard_new(outpatient.getIdcard()));
            data.put("recipeType",prescriptionDO.getDispensaryType());
            data.put("message","患者已完成取药");
            systemMessageDO.setData(data.toString());
            systemMessageService.saveMessage(systemMessageDO);
        } catch (Exception e) {
            logger.error("sendPatientGetDrugMes :" + e.toString());
        }catch (Exception e){
            logger.error("sendPatientGetDrugMes :"+e.toString());
        }
        return systemMessageDO;
    }
    /**
     * 获取卡记录
     *
     * @param patient
     * @return
     * @throws Exception
     */
    public JSONArray findPatientCard(String patient) throws Exception {
    public JSONArray findPatientCard(String patient)throws Exception{
        BasePatientDO patientDO = basePatientDao.findById(patient);
        JSONArray res = entranceService.BS15018(patientDO.getIdcard(), null, demoFlag);
        JSONArray res = entranceService.BS15018(patientDO.getIdcard(),null,demoFlag);
        JSONArray rs = new JSONArray();
        if (res != null) {
            for (int i = 0; i < res.size(); i++) {
        if(res !=null){
            for (int i =0;i<res.size();i++){
                JSONObject card = res.getJSONObject(i);
                String cardStat = card.getString("CARD_STAT");
                if ("激活".equals(cardStat)) {
                if("激活".equals(cardStat)){
                    rs.add(card);
                }
            }
@ -798,54 +795,53 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    }
    public Map<String, Object> checkOutpatient(String patient) throws Exception {
    public Map<String,Object> checkOutpatient(String patient)throws Exception{
        //-1卡余额不足,,-2 存在未结束的诊断热 1成功
        Map<String, Object> rs = new HashedMap();
        Map<String,Object> rs = new HashedMap();
        //1.余额判断改到前端判断
        //net.sf.json.JSONObject json = entranceService.qutpatientBalance(cardNo,demoFlag);
        //2.判断是否有未结束的
        List<WlyyOutpatientDO> list = outpatientDao.findByPatientList(patient);
        if (list != null && list.size() > 0) {
            rs.put("outpatient", list.get(0));
            rs.put("code", -2);
            rs.put("mes", "存在未结束的诊断");
        if(list!=null&&list.size()>0){
            rs.put("outpatient",list.get(0));
            rs.put("code",-2);
            rs.put("mes","存在未结束的诊断");
            return rs;
        }
        rs.put("code", 1);
        rs.put("mes", "验证通过");
        rs.put("code",1);
        rs.put("mes","验证通过");
        return rs;
    }
    /**
     * 获取所有医院列表
     *
     * @return
     */
    public List<BaseOrgVO> findAllHospital(Integer level, String keyWord) {
    public List<BaseOrgVO> findAllHospital(Integer level,String keyWord){
    
        if (StringUtils.isNoneEmpty(keyWord)) {
            keyWord = "%" + keyWord + "%";
            if (level != null) {
                List<BaseOrgDO> list = baseOrgDao.findByLevelAndName(level, "1", keyWord);
    
            if(level!=null){
                List<BaseOrgDO> list = baseOrgDao.findByLevelAndName(level,"1",keyWord);
                List<BaseOrgVO> rs = new ArrayList<>();
                return convertToModels(list, rs, BaseOrgVO.class);
            } else {
                List<BaseOrgDO> list = baseOrgDao.findByDelAndName("1", keyWord);
                return convertToModels(list,rs,BaseOrgVO.class);
            }else {
                List<BaseOrgDO> list = baseOrgDao.findByDelAndName("1",keyWord);
                List<BaseOrgVO> rs = new ArrayList<>();
                return convertToModels(list, rs, BaseOrgVO.class);
                return convertToModels(list,rs,BaseOrgVO.class);
            }
        } else {
            if (level != null) {
                List<BaseOrgDO> list = baseOrgDao.findByLevelAndDel(level, "1");
        }else{
    
            if(level!=null){
                List<BaseOrgDO> list = baseOrgDao.findByLevelAndDel(level,"1");
                List<BaseOrgVO> rs = new ArrayList<>();
                return convertToModels(list, rs, BaseOrgVO.class);
            } else {
                return convertToModels(list,rs,BaseOrgVO.class);
            }else {
                List<BaseOrgDO> list = baseOrgDao.findByDel("1");
                List<BaseOrgVO> rs = new ArrayList<>();
                return convertToModels(list, rs, BaseOrgVO.class);
                return convertToModels(list,rs,BaseOrgVO.class);
            }
        }
@ -853,25 +849,24 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 获取机构下部门信息
     *
     * @param orgCode
     * @return
     */
    public List<DictHospitalDeptVO> findDeptByHospital(String orgCode, String dept, String consultDeptFlag) {
    public List<DictHospitalDeptVO> findDeptByHospital(String orgCode,String dept,String consultDeptFlag){
        List<DictHospitalDeptDO> list;
        if (StringUtils.isNotBlank(consultDeptFlag) && "1".equals(consultDeptFlag)) {
            list = dictHospitalDeptDao.findByOrgCodeAndConsultDeptFlag(orgCode, consultDeptFlag);
        } else {
            list = dictHospitalDeptDao.findByOrgCodeIn(orgCode);
        if(StringUtils.isNotBlank(consultDeptFlag)&&"1".equals(consultDeptFlag)){
            list = dictHospitalDeptDao.findByOrgCodeAndConsultDeptFlag(orgCode,consultDeptFlag);
        }else {
            list =  dictHospitalDeptDao.findByOrgCodeIn(orgCode);
        }
        List<DictHospitalDeptVO> rs = new ArrayList<>();
        convertToModels(list, rs, DictHospitalDeptVO.class);
        if (rs != null && rs.size() > 0 && StringUtils.isNotBlank(dept)) {
        convertToModels(list,rs,DictHospitalDeptVO.class);
        if(rs!=null&&rs.size()>0&&StringUtils.isNotBlank(dept)){
            //排序
            for (int i = 0; i < rs.size(); i++) {
            for(int i=0;i<rs.size();i++){
                String id = rs.get(i).getCode();
                if (dept.equals(id)) {
                    Collections.swap(rs, 0, i);
                if(dept.equals(id)){
                    Collections.swap(rs,0,i);
                }
            }
        }
@ -880,13 +875,12 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 获取医生列表.
     *
     * @param orgCode
     * @param dept
     * @return
     */
    public List<Map<String, Object>> findDoctorByHospitalAndDept(String orgCode, String dept, String chargeType, String doctorCode, String outpatientType, String startDate, String endDate, String key, String consultStatus) {
        String sql = "SELECT " +
    public List<Map<String,Object>> findDoctorByHospitalAndDept(String orgCode,String dept,String chargeType,String doctorCode,String outpatientType,String startDate,String endDate,String key,String consultStatus){
        String sql ="SELECT " +
                " d.id, " +
                " d.photo, " +
                " d.`name`, " +
@ -902,59 +896,59 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " WHERE  " +
                " 1=1";
        if (StringUtils.isNotBlank(dept)) {
            sql += " AND h.dept_code = '" + dept + "'";
        if(StringUtils.isNotBlank(dept)){
            sql+= " AND h.dept_code = '"+dept+"'";
        }
        if (StringUtils.isNotBlank(orgCode)) {
            sql += " AND h.org_code = '" + orgCode + "'";
        if(StringUtils.isNotBlank(orgCode)){
            sql+= " AND h.org_code = '"+orgCode+"'";
        }
        if (StringUtils.isNotBlank(chargeType)) {
            if ("all".equals(chargeType)) {
        if(StringUtils.isNotBlank(chargeType)){
            if("all".equals(chargeType)){
                //查询全部号源
            } else {
                sql += " AND d.charge_type ='" + chargeType + "'";
            }else{
                sql+=" AND d.charge_type ='"+chargeType+"'";
            }
        } else {
            sql += " AND d.charge_type is not null ";
        }else{
            sql+=" AND d.charge_type is not null ";
        }
        if (StringUtils.isNotBlank(outpatientType)) {
            if ("all".equals(outpatientType)) {
        if(StringUtils.isNotBlank(outpatientType)){
            if("all".equals(outpatientType)){
                //查询全部权限
            } else {
                sql += " AND d.outpatient_type like'%" + outpatientType + "%'";
            }else{
                sql+=" AND d.outpatient_type like'%"+outpatientType+"%'";
            }
        } else {
            sql += " AND d.outpatient_type is not null ";
        }else{
            sql+=" AND d.outpatient_type is not null ";
        }
        if (StringUtils.isNotBlank(key)) {
            sql += " AND (h.dept_name like '%" + key + "%' OR d.name like '%" + key + "%' OR d.expertise like '%" + key + "%') ";
        if(StringUtils.isNotBlank(key)){
            sql+=" AND (h.dept_name like '%"+key+"%' OR d.name like '%"+key+"%' OR d.expertise like '%"+key+"%') ";
        }
        if (StringUtils.isNotBlank(consultStatus)) {
            sql += " AND d.consult_status = '" + consultStatus + "'";
        if(StringUtils.isNotBlank(consultStatus)){
            sql+=" AND d.consult_status = '"+consultStatus+"'";
        }
        if (StringUtils.isNotBlank(endDate) && StringUtils.isNotBlank(startDate)) {
            sql += " AND EXISTS ( " +
        if(StringUtils.isNotBlank(endDate)&&StringUtils.isNotBlank(startDate)){
            sql+=" AND EXISTS ( " +
                    " SELECT " +
                    "  1 " +
                    " FROM " +
                    "  wlyy_doctor_work_time t " +
                    " WHERE " +
                    "  t.doctor = d.id " +
                    " AND t.start_time >='" + startDate + "'" +
                    " AND t.start_time <='" + endDate + "'" +
                    " AND t.start_time >='" +startDate+"'" +
                    " AND t.start_time <='"+endDate+"'"+
                    " )";
        }
        logger.info("findDoctorByHospitalAndDept sql:" + sql);
        logger.info("findDoctorByHospitalAndDept sql:"+sql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        if (list != null && list.size() > 0 && StringUtils.isNotBlank(doctorCode)) {
        if(list!=null&&list.size()>0&&StringUtils.isNotBlank(doctorCode)){
            //排序
            for (int i = 0; i < list.size(); i++) {
                String id = (String) list.get(i).get("id");
                if (doctorCode.equals(id)) {
                    Collections.swap(list, 0, i);
            for(int i=0;i<list.size();i++){
                String id = (String)list.get(i).get("id");
                if(doctorCode.equals(id)){
                    Collections.swap(list,0,i);
                }
            }
        }
@ -964,65 +958,64 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 获取医生列表带排班
     *
     * @param orgCode
     * @param dept
     * @return
     */
    public MixEnvelop findDoctorWithWork(String orgCode, String dept, String chargeType, String doctorCode, String outpatientType, String startDate, String endDate, String key, String consultStatus, Integer page, Integer size) {
    public MixEnvelop findDoctorWithWork(String orgCode,String dept,String chargeType,String doctorCode,String outpatientType,String startDate,String endDate,String key,String consultStatus,Integer page,Integer size){
        String totalSql = "SELECT " +
        String totalSql ="SELECT " +
                " count(1) AS total " +
                " FROM " +
                " base_doctor d " +
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " WHERE  " +
                " 1=1 ";
        if (StringUtils.isNotBlank(dept)) {
            totalSql += " AND h.dept_code = '" + dept + "'";
        if(StringUtils.isNotBlank(dept)){
            totalSql+= " AND h.dept_code = '"+dept+"'";
        }
        if (StringUtils.isNotBlank(orgCode)) {
            totalSql += " AND h.org_code = '" + orgCode + "'";
        if(StringUtils.isNotBlank(orgCode)){
            totalSql+= " AND h.org_code = '"+orgCode+"'";
        }
        if (StringUtils.isNotBlank(chargeType)) {
            totalSql += " AND d.charge_type ='" + chargeType + "'";
        } else {
            totalSql += " AND d.charge_type is not null ";
        if(StringUtils.isNotBlank(chargeType)){
            totalSql+= " AND d.charge_type ='"+chargeType+"'";
        }else{
            totalSql+= " AND d.charge_type is not null ";
        }
        if (StringUtils.isNotBlank(outpatientType)) {
            if (outpatientType.contains("or")) {
        if(StringUtils.isNotBlank(outpatientType)){
            if(outpatientType.contains("or")){
                String[] outpatientTypeArray = outpatientType.split("or");
                totalSql += " AND ( ";
                totalSql+= " AND ( ";
    
                for (int i = 0; i < outpatientTypeArray.length; i++) {
                    totalSql += " d.outpatient_type like'%" + outpatientTypeArray[i] + "%'";
                    if (i != outpatientTypeArray.length - 1) {
                    totalSql +=" d.outpatient_type like'%"+outpatientTypeArray[i]+"%'";
                    if(i != outpatientTypeArray.length -1){
                        totalSql += " or ";
                    }
                }
                totalSql += "  ) ";
            } else {
                totalSql += " AND d.outpatient_type like'%" + outpatientType + "%'";
                totalSql+= "  ) ";
            }else{
                totalSql+= " AND d.outpatient_type like'%"+outpatientType+"%'";
            }
        } else {
            totalSql += " AND d.outpatient_type is not null ";
        }else{
            totalSql+=" AND d.outpatient_type is not null ";
        }
        if (StringUtils.isNotBlank(key)) {
            totalSql += " AND (h.dept_name like '%" + key + "%' OR d.name like '%" + key + "%' OR d.expertise like '%" + key + "%') ";
        if(StringUtils.isNotBlank(key)){
            totalSql+=" AND (h.dept_name like '%"+key+"%' OR d.name like '%"+key+"%' OR d.expertise like '%"+key+"%') ";
        }
        if (StringUtils.isNotBlank(consultStatus)) {
            totalSql += " AND d.consult_status = '" + consultStatus + "'";
        if(StringUtils.isNotBlank(consultStatus)){
            totalSql+=" AND d.consult_status = '"+consultStatus+"'";
        }
        if (StringUtils.isNotBlank(endDate) && StringUtils.isNotBlank(startDate)) {
            totalSql += " AND EXISTS ( " +
        if(StringUtils.isNotBlank(endDate)&&StringUtils.isNotBlank(startDate)){
            totalSql+=" AND EXISTS ( " +
                    " SELECT " +
                    "  1 " +
                    " FROM " +
                    "  wlyy_doctor_work_time t " +
                    " WHERE " +
                    "  t.doctor = d.id " +
                    " AND t.start_time >='" + startDate + "'" +
                    " AND t.start_time <='" + endDate + "'" +
                    " AND t.start_time >='" +startDate+"'" +
                    " AND t.start_time <='"+endDate+"'"+
                    " )";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -1032,7 +1025,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            count = (Long) rstotal.get(0).get("total");
        }
        String sql = "SELECT " +
        String sql ="SELECT " +
                " d.id, " +
                " d.photo, " +
                " d.`name`, " +
@ -1049,72 +1042,72 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " base_doctor d " +
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " WHERE " +
                " 1=1";
        if (StringUtils.isNotBlank(dept)) {
            sql += " AND h.dept_code = '" + dept + "'";
                " 1=1" ;
        if(StringUtils.isNotBlank(dept)){
            sql+= " AND h.dept_code = '"+dept+"'";
        }
        if (StringUtils.isNotBlank(orgCode)) {
            sql += " AND h.org_code = '" + orgCode + "'";
        if(StringUtils.isNotBlank(orgCode)){
            sql+= " AND h.org_code = '"+orgCode+"'";
        }
        if (StringUtils.isNotBlank(chargeType)) {
            sql += " AND d.charge_type ='" + chargeType + "'";
        } else {
            sql += " AND d.charge_type is not null";
    
        if(StringUtils.isNotBlank(chargeType)){
            sql+= " AND d.charge_type ='"+chargeType+"'";
        }else{
            sql+= " AND d.charge_type is not null";
        }
        if (StringUtils.isNotBlank(outpatientType)) {
            if (outpatientType.contains("or")) {
        
        if(StringUtils.isNotBlank(outpatientType)){
            if(outpatientType.contains("or")){
                String[] outpatientTypeArray = outpatientType.split("or");
                sql += " AND ( ";
                sql+= " AND ( ";
            
                for (int i = 0; i < outpatientTypeArray.length; i++) {
                    sql += " d.outpatient_type like'%" + outpatientTypeArray[i] + "%'";
                    if (i != outpatientTypeArray.length - 1) {
                    sql +=" d.outpatient_type like'%"+outpatientTypeArray[i]+"%'";
                    if(i != outpatientTypeArray.length -1){
                        sql += " or ";
                    }
                }
                sql += " ) ";
            } else {
                sql += " AND d.outpatient_type like'%" + outpatientType + "%'";
                sql+= " ) ";
            }else{
                sql+= " AND d.outpatient_type like'%"+outpatientType+"%'";
            }
        } else {
            sql += " AND d.outpatient_type is not null ";
        }else{
            sql+=" AND d.outpatient_type is not null ";
        }
        if (StringUtils.isNotBlank(key)) {
            sql += " AND (h.dept_name like '%" + key + "%' OR d.name like '%" + key + "%' OR d.expertise like '%" + key + "%') ";
        
        if(StringUtils.isNotBlank(key)){
            sql+=" AND (h.dept_name like '%"+key+"%' OR d.name like '%"+key+"%' OR d.expertise like '%"+key+"%') ";
        }
        if (StringUtils.isNotBlank(consultStatus)) {
            sql += " AND d.consult_status = '" + consultStatus + "'";
        if(StringUtils.isNotBlank(consultStatus)){
            sql+=" AND d.consult_status = '"+consultStatus+"'";
        }
        if (StringUtils.isNotBlank(endDate) && StringUtils.isNotBlank(startDate)) {
            sql += " AND EXISTS ( " +
        if(StringUtils.isNotBlank(endDate)&&StringUtils.isNotBlank(startDate)){
            sql+=" AND EXISTS ( " +
                    " SELECT " +
                    "  1 " +
                    " FROM " +
                    "  wlyy_doctor_work_time t " +
                    " WHERE " +
                    "  t.doctor = d.id " +
                    " AND t.start_time >='" + startDate + "'" +
                    " AND t.start_time <='" + endDate + "'" +
                    " AND t.start_time >='" +startDate+"'" +
                    " AND t.start_time <='"+endDate+"'"+
                    " )";
        }
        sql += " AND d.del='1' AND d.outpatient_type is not null LIMIT " + (page - 1) * size + "," + size + "";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        if (list != null && list.size() > 0) {
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        if(list!=null&&list.size()>0){
            //获取排班
            for (Map<String, Object> doctor : list) {
                String id = (String) doctor.get("id");
                List<WlyyDoctorWorkTimeVO> times = findDoctorWorkTime(id, orgCode);
                doctor.put("workTime", times);
            for(Map<String,Object> doctor :list){
                String id = (String)doctor.get("id");
                List<WlyyDoctorWorkTimeVO> times = findDoctorWorkTime(id);
                doctor.put("workTime",times);
            }
            if (StringUtils.isNotBlank(doctorCode)) {
            if(StringUtils.isNotBlank(doctorCode)){
                //排序
                for (int i = 0; i < list.size(); i++) {
                    String id = (String) list.get(i).get("id");
                    if (doctorCode.equals(id)) {
                        Collections.swap(list, 0, i);
                for(int i=0;i<list.size();i++){
                    String id = (String)list.get(i).get("id");
                    if(doctorCode.equals(id)){
                        Collections.swap(list,0,i);
                    }
                }
            }
@ -1122,44 +1115,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
    }
    public List<WlyyDoctorWorkTimeVO> findDoctorWorkTime(String doctor, String hospital) {
        List<WlyyHospitalWorkRuleDO> list = wlyyHospitalWorkRuleDao.findByHospital(hospital);
        if (list != null && list.size() > 0) {
            WlyyHospitalWorkRuleDO rule = list.get(0);
            String openTimeString = DateUtil.dateToStr(new Date(), "yyyy-MM-dd")+ " " + rule.getMaxDayOpenTime() + ":00";
            logger.info("today openTimeString :"+openTimeString);
            Date openTime = DateUtil.strToDate(openTimeString, "yyyy-MM-dd HH:mm:ss");
            Integer openDay = rule.getMaxDay();
            if (openTime.before(new Date())) {
                openDay = openDay - 1;
            }
            Date preDate =  DateUtil.getPreDays(new Date(), openDay);
            String maxDateString = DateUtil.dateToStr(preDate,"yyyy-MM-dd")+" 23:59:59";
            logger.info("maxDateString :"+maxDateString);
            Date endDate = DateUtil.stringToDate(maxDateString, "yyyy-MM-dd HH:mm:ss");
            List<WlyyDoctorWorkTimeVO> timeVOs = new ArrayList<>();
            List<WlyyDoctorWorkTimeDO> timeDOs = doctorWorkTimeDao.findDoctorWorkTime(doctor, new Date(), endDate);
            convertToModels(timeDOs, timeVOs, WlyyDoctorWorkTimeVO.class);
            if (timeVOs != null && timeVOs.size() > 0) {
                for (WlyyDoctorWorkTimeVO timeVO : timeVOs) {
                    timeVO.setCount(findWorkTimeInfoCout(timeVO.getId()));
                }
            }
            return timeVOs;
        }
        return null;
    }
    /**
     * 查询医生列表带月份排班状态
     *
     * @param orgCode
     * @param dept
     * @param chargeType
@ -1168,33 +1125,33 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @param size
     * @return
     */
    public MixEnvelop findDoctorWithMouthWork(String orgCode, String dept, String chargeType, String date, String nameKey, Integer page, Integer size) {
    public MixEnvelop findDoctorWithMouthWork(String orgCode,String dept,String chargeType,String date,String nameKey,Integer page,Integer size){
        String totalSql = "SELECT " +
        String totalSql ="SELECT " +
                " count(1) AS total " +
                " FROM " +
                " base_doctor d " +
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " JOIN base_doctor_role r ON r.doctor_code = d.id " +
                " WHERE  " +
                " h.org_code = '" + orgCode + "'" +
                " h.org_code = '"+orgCode+"'" +
                " AND r.role_code ='specialist'";
        if (StringUtils.isNotBlank(chargeType)) {
            if ("all".equals(chargeType)) {
        if(StringUtils.isNotBlank(chargeType)){
            if("all".equals(chargeType)){
                //不过滤号别
            } else {
                totalSql += " AND d.charge_type ='" + chargeType + "'";
            }else{
                totalSql+=" AND d.charge_type ='"+chargeType+"'";
            }
        } else {
        }else{
            //不传号别过滤不为为空
            totalSql += " AND d.charge_type is not null ";
            totalSql+=" AND d.charge_type is not null ";
        }
        if (StringUtils.isNotBlank(dept)) {
            totalSql += " AND h.dept_code = '" + dept + "' ";
        if(StringUtils.isNotBlank(dept)){
            totalSql+= " AND h.dept_code = '"+dept+"' " ;
        }
        if (StringUtils.isNotBlank(nameKey)) {
            totalSql += " AND d.name like '%" + nameKey + "%' ";
        if(StringUtils.isNotBlank(nameKey)){
            totalSql+= " AND d.name like '%"+nameKey+"%' " ;
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -1203,7 +1160,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            count = (Long) rstotal.get(0).get("total");
        }
        String sql = "SELECT " +
        String sql ="SELECT " +
                " d.id, " +
                " d.photo, " +
                " d.`name`, " +
@ -1219,72 +1176,72 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " JOIN base_doctor_role r ON r.doctor_code = d.id " +
                " WHERE  " +
                " h.org_code = '" + orgCode + "'" +
                " h.org_code = '"+orgCode+"'"+
                " AND r.role_code ='specialist'";
        if (StringUtils.isNotBlank(chargeType)) {
            if ("all".equals(chargeType)) {
        if(StringUtils.isNotBlank(chargeType)){
            if("all".equals(chargeType)){
                //不过滤号别
            } else {
                sql += " AND d.charge_type ='" + chargeType + "'";
            }else{
                sql+=" AND d.charge_type ='"+chargeType+"'";
            }
        } else {
        }else{
            //不传号别过滤不为为空
            sql += " AND d.charge_type is not null ";
            sql+=" AND d.charge_type is not null ";
        }
        if (StringUtils.isNotBlank(dept)) {
            sql += " AND h.dept_code = '" + dept + "' ";
        if(StringUtils.isNotBlank(dept)){
            sql+= " AND h.dept_code = '"+dept+"' " ;
        }
        if (StringUtils.isNotBlank(nameKey)) {
            sql += " AND d.name like '%" + nameKey + "%' ";
        if(StringUtils.isNotBlank(nameKey)){
            sql+= " AND d.name like '%"+nameKey+"%' " ;
        }
        sql += " LIMIT " + (page - 1) * size + "," + size + "";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        if (list != null && list.size() > 0) {
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        if(list!=null&&list.size()>0){
            //获取排班
            for (Map<String, Object> doctor : list) {
                String id = (String) doctor.get("id");
                List<WlyyDoctorWorkTimeDO> workTimeDOs = doctorWorkTimeDao.findDoctorWorkTimeByMonth(id, "%" + date + "%");
                if (workTimeDOs != null && workTimeDOs.size() > 0) {
                    doctor.put("isScheduling", true);
                } else {
                    doctor.put("isScheduling", false);
            for(Map<String,Object> doctor :list){
                String id = (String)doctor.get("id");
                List<WlyyDoctorWorkTimeDO> workTimeDOs = doctorWorkTimeDao.findDoctorWorkTimeByMonth(id,"%"+date+"%");
                if(workTimeDOs!=null&&workTimeDOs.size()>0){
                    doctor.put("isScheduling",true);
                }else{
                    doctor.put("isScheduling",false);
                }
            }
        }
        logger.info("findDoctorWithMouthWork :" + sql);
        logger.info("findDoctorWithMouthWork :"+sql);
        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
    }
    /**
     * 挂号
     *
     * @return
     */
    public net.sf.json.JSONObject registerOutPatient(String outPatientId, String doctor) throws Exception {
    public net.sf.json.JSONObject registerOutPatient(String outPatientId,String doctor)throws Exception{
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outPatientId);
        
        
        DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(doctor, outpatientDO.getHospital());
        if (doctorMappingDO == null) {
        DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(doctor,outpatientDO.getHospital());
        if(doctorMappingDO==null){
            throw new RuntimeException("未找到医生映射信息");
        }
        
        BasePatientDO basePatientDO = basePatientDao.findById(outpatientDO.getPatient());
    
        Integer manageType = 1;//处理类型(1-新增 2-修改 3-删除) 必填
        //查找居民当天挂号记录
        String date = DateUtil.dateToStr(new Date(), "yyyy-MM-dd");
        List<WlyyPatientRegisterDO> patientRegisterDOs = patientRegisterDao.findByPatientAndDateAndDoctor(outpatientDO.getPatient(), date, doctor);
        if (patientRegisterDOs != null && patientRegisterDOs.size() > 0) {
        String date = DateUtil.dateToStr(new Date(),"yyyy-MM-dd");
        List<WlyyPatientRegisterDO>  patientRegisterDOs = patientRegisterDao.findByPatientAndDateAndDoctor(outpatientDO.getPatient(),date,doctor);
        if(patientRegisterDOs!=null&&patientRegisterDOs.size()>0){
            WlyyPatientRegisterDO registerDO = patientRegisterDOs.get(0);
            //判断是否已经挂号,如果已经挂号
            if (StringUtils.isNotBlank(registerDO.getConNo()) && StringUtils.isNotBlank(registerDO.getRegisterNo())) {
            if(StringUtils.isNotBlank(registerDO.getConNo())&&StringUtils.isNotBlank(registerDO.getRegisterNo())){
                net.sf.json.JSONObject res = new JSONObject();
                res.put("@RESULT", "0");
                logger.info("已经挂号 res: " + res.toString());
                res.put("@RESULT","0");
                logger.info("已经挂号 res: " +res.toString());
                //更新挂号流水号
                outpatientDO.setConNo(registerDO.getConNo());
@ -1292,27 +1249,27 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                outpatientDO.setAdmDate(registerDO.getCreateTime());
                outpatientDao.save(outpatientDO);
                //调用电子病历注册
                manageType = 2;
                registDianziBingli(outpatientDO, basePatientDO, manageType, registerDO.getRegisterNo(), registerDO.getConNo());
                manageType =2;
                registDianziBingli(outpatientDO,basePatientDO,manageType,registerDO.getRegisterNo(),registerDO.getConNo());
                return res;
            }
        }
        net.sf.json.JSONObject rs = entranceService.BS10111(outpatientDO.getCardNo(), doctorMappingDO.getMappingCode(), outpatientDO.getDept(), null, outpatientDO.getWinNo(), demoFlag);
        net.sf.json.JSONObject rs = entranceService.BS10111(outpatientDO.getCardNo(),doctorMappingDO.getMappingCode(),outpatientDO.getDept(),null,outpatientDO.getWinNo(),demoFlag);
        net.sf.json.JSONObject res = rs.getJSONObject("resquest");
        logger.info("挂号结果 res: " + res.toString());
        logger.info("挂号结果 res: " +res.toString());
        String rsCode = res.getString("@RESULT");
        if ("0".equals(rsCode)) {
        
        if("0".equals(rsCode)){
            //存储挂号号
            // {"resquest":{"@RESULT":"0","@MSG":"完成","@serial_no":"47770476","@times":"28"}}
            String serialNo = (String) res.get("@serial_no");
            String serialNo = (String)res.get("@serial_no");
            outpatientDO.setRegisterNo(serialNo);
            String conNo = (String) res.get("@times");
            String conNo = (String)res.get("@times");
            outpatientDO.setConNo(conNo);
            outpatientDO.setAdmDate(new Date());
            logger.info("挂号流水 @serial_no: " + serialNo + " @times: " + conNo);
            logger.info("挂号流水 @serial_no: " +serialNo+" @times: "+conNo);
            outpatientDao.save(outpatientDO);
            //存储就诊记录
@ -1329,21 +1286,21 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            registerDO.setRegisterNo(serialNo);
            registerDO.setConNo(conNo);
            registerDO.setCreateTime(new Date());
            registerDO.setDate(DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
            registerDO.setDate(DateUtil.dateToStr(new Date(),"yyyy-MM-dd"));
            patientRegisterDao.save(registerDO);
    
            //调用电子病历注册
            manageType = 1;//处理类型(1-新增 2-修改 3-删除) 必填
            registDianziBingli(outpatientDO, basePatientDO, manageType, registerDO.getRegisterNo(), registerDO.getConNo());
        } else if ("-2".equals(rsCode)) {
            registDianziBingli(outpatientDO,basePatientDO,manageType,registerDO.getRegisterNo(),registerDO.getConNo());
            
        }else if("-2".equals(rsCode)){
            String serialNo = (String) res.get("@serial_no");
            String serialNo = (String)res.get("@serial_no");
            outpatientDO.setRegisterNo(serialNo);
            String conNo = (String) res.get("@times");
            String conNo = (String)res.get("@times");
            outpatientDO.setConNo(conNo);
            outpatientDO.setAdmDate(new Date());
            logger.info("挂号流水 @serial_no: " + serialNo + " @times: " + conNo);
            logger.info("挂号流水 @serial_no: " +serialNo+" @times: "+conNo);
            outpatientDao.save(outpatientDO);
            //存储就诊记录
@ -1359,111 +1316,112 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            registerDO.setRegisterNo(serialNo);
            registerDO.setConNo(conNo);
            registerDO.setCreateTime(new Date());
            registerDO.setDate(DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
            registerDO.setDate(DateUtil.dateToStr(new Date(),"yyyy-MM-dd"));
            patientRegisterDao.save(registerDO);
    
            //调用电子病历注册
            manageType = 1;//处理类型(1-新增 2-修改 3-删除) 必填
            registDianziBingli(outpatientDO, basePatientDO, manageType, registerDO.getRegisterNo(), registerDO.getConNo());
            registDianziBingli(outpatientDO,basePatientDO,manageType,registerDO.getRegisterNo(),registerDO.getConNo());
        }
    
        //保存日志
        
            //保存日志
        WlyyHttpLogDO log = new WlyyHttpLogDO();
        log.setCode("registerOutPatient");
        log.setName("挂号");
        log.setPatient(outpatientDO.getPatient());
        log.setDoctor(doctor);
        log.setResponse(rs.toString());
        log.setRequest("outPatientId=" + outPatientId + "&doctor=" + doctor);
        log.setRequest("outPatientId="+outPatientId+"&doctor="+doctor);
        log.setStatus(rsCode);
        log.setCreateTime(new Date());
        wlyyHttpLogDao.save(log);
        return res;
    }
    public String registDianziBingli(WlyyOutpatientDO outpatientDO, BasePatientDO basePatientDO, Integer manageType, String RegisterSN, String registerCon) throws Exception {
    
    public String registDianziBingli(WlyyOutpatientDO outpatientDO,BasePatientDO basePatientDO,Integer manageType,String RegisterSN,String registerCon) throws Exception {
    
        //调用电子病历接口注册居民信息
        String patientMappingCode = patientMappingService.findHisPatNoByIdCard(basePatientDO.getIdcard());
        DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(outpatientDO.getDoctor(), outpatientDO.getHospital());
        Map<String, String> params = new HashedMap();
        params.put("type", "PatientInfo");
        String _xmlStr = "<?xml version='1.0' encoding='UTF-8'?>" +
                "<HtRequest>" +
                "<OutRegister>" +
                "<RecordFlow>" + outpatientDO.getId() + "</RecordFlow>" +
                "<RegisterSN>" + RegisterSN + "</RegisterSN>" +
                "<TreatDate>" + DateUtil.getStringDate("yyyyMMdd") + "</TreatDate>" +
                "<RegisterDeptCode>" + outpatientDO.getDept() + "</RegisterDeptCode>" +
                "<RegisterDeptName>" + outpatientDO.getDeptName() + "</RegisterDeptName>" +
                "<RegisterDoctorID>" + doctorMappingDO.getMappingCode() + "</RegisterDoctorID>" +
                "<RegisterDoctorName>" + doctorMappingDO.getDoctorName() + "</RegisterDoctorName>" +
                "<DutyID></DutyID>" +
                "<DutyName></DutyName>" +
                "<OutPatientTime></OutPatientTime>" +
                "<NumClassCode></NumClassCode>" +
                "<NumClassName></NumClassName>" +
                "<JoinGroupCode></JoinGroupCode>" +
                "<JoinGroupName></JoinGroupName>" +
                "<NumClassNO></NumClassNO>" +
                "<AppointmentDateTime></AppointmentDateTime>" +
                "<AppointSN></AppointSN>" +
                "<Pid>" + patientMappingCode + "</Pid>" +
                "<CardNO>" + outpatientDO.getCardNo() + "</CardNO>\n" +
                "<PatientName>" + basePatientDO.getName() + "</PatientName>" +
                "<SexCode>" + basePatientDO.getSex() + "</SexCode>";
        if (1 == basePatientDO.getSex()) {
            _xmlStr = _xmlStr + "<Sex>男</Sex>";
        } else {
            _xmlStr = _xmlStr + "<Sex>女</Sex>";
        }
        _xmlStr = _xmlStr + "<Age>" + IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard()) + "</Age>" +
                "<AgeDesc>" + IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard()) + "岁</AgeDesc>" +
                "<PatientClass></PatientClass>" +
                "<FeeTypeCode></FeeTypeCode>" +
                "<FeeTypeName></FeeTypeName>" +
                "<MedicalInsuranceType></MedicalInsuranceType>" +
                "<IsFirst>N</IsFirst>" +
                "<RegisterDateTime>20200121</RegisterDateTime>" +
                "<RegisterUserID>" + patientMappingCode + "</RegisterUserID>" +
                "<RegisterUserName></RegisterUserName>" +
                "<OutStatus>20</OutStatus>" +
                "<ModifierID></ModifierID>" +
                "<Modifier></Modifier>" +
                "<ModifyTime></ModifyTime>" +
                "<RetreatDateTime></RetreatDateTime>" +
                "<RetreatUserID></RetreatUserID>" +
                "<RetreatUserName></RetreatUserName>" +
                "<PaymentMethodCode></PaymentMethodCode>" +
                "<PaymentMethod></PaymentMethod>" +
                "<RegisterFee></RegisterFee>" +
                "<MedicalFee></MedicalFee>" +
                "<OtherFee></OtherFee>" +
                "<TotalFee></TotalFee>" +
                "<MedicalFloor>N</MedicalFloor>" +
                "<MedicalAddress></MedicalAddress>" +
                "<LastDeptCode></LastDeptCode>" +
                "<LastDeptName></LastDeptName>" +
                "<LastDoctorID></LastDoctorID>" +
                "<LastDoctorName></LastDoctorName>" +
                "<LastTreatDateTime></LastTreatDateTime>" +
                "<LastOpid></LastOpid>" +
                "<NumTypeCode>0</NumTypeCode>" +
                "<NumTypeName></NumTypeName>" +
                "<RegisterSource>1</RegisterSource>" +
                "<AcctNO></AcctNO>" +
                "<IsAcct>N</IsAcct>" +
                "<ManageType>" + manageType + "</ManageType>" +
                "<Times>" + registerCon + "</Times>" +
                "</OutRegister>" +
                "<PatientInfo>" +
                "<RecordFlow>" + outpatientDO.getId() + "</RecordFlow>" +
                "<PID>" + patientMappingCode + "</PID></PatientInfo></HtRequest>";
            String patientMappingCode =  patientMappingService.findHisPatNoByIdCard(basePatientDO.getIdcard());
            DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(outpatientDO.getDoctor(),outpatientDO.getHospital());
            Map<String,String> params = new HashedMap();
            params.put("type","PatientInfo");
            
            String _xmlStr="<?xml version='1.0' encoding='UTF-8'?>" +
                    "<HtRequest>" +
                    "<OutRegister>" +
                    "<RecordFlow>"+outpatientDO.getId()+"</RecordFlow>" +
                    "<RegisterSN>"+RegisterSN+"</RegisterSN>" +
                    "<TreatDate>"+DateUtil.getStringDate("yyyyMMdd")+"</TreatDate>" +
                    "<RegisterDeptCode>"+outpatientDO.getDept()+"</RegisterDeptCode>" +
                    "<RegisterDeptName>"+outpatientDO.getDeptName()+"</RegisterDeptName>" +
                    "<RegisterDoctorID>"+doctorMappingDO.getMappingCode()+"</RegisterDoctorID>" +
                    "<RegisterDoctorName>"+doctorMappingDO.getDoctorName()+"</RegisterDoctorName>" +
                    "<DutyID></DutyID>" +
                    "<DutyName></DutyName>" +
                    "<OutPatientTime></OutPatientTime>" +
                    "<NumClassCode></NumClassCode>" +
                    "<NumClassName></NumClassName>" +
                    "<JoinGroupCode></JoinGroupCode>" +
                    "<JoinGroupName></JoinGroupName>" +
                    "<NumClassNO></NumClassNO>" +
                    "<AppointmentDateTime></AppointmentDateTime>" +
                    "<AppointSN></AppointSN>" +
                    "<Pid>"+patientMappingCode+"</Pid>" +
                    "<CardNO>"+outpatientDO.getCardNo()+"</CardNO>\n" +
                    "<PatientName>"+basePatientDO.getName()+"</PatientName>"+
                    "<SexCode>"+basePatientDO.getSex()+"</SexCode>";
                    if(1 == basePatientDO.getSex()){
                        _xmlStr = _xmlStr + "<Sex>男</Sex>";
                    }else{
                        _xmlStr = _xmlStr +  "<Sex>女</Sex>";
                    }
                    _xmlStr = _xmlStr + "<Age>"+IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard())+"</Age>" +
                    "<AgeDesc>"+IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard())+"岁</AgeDesc>" +
                    "<PatientClass></PatientClass>" +
                    "<FeeTypeCode></FeeTypeCode>" +
                    "<FeeTypeName></FeeTypeName>" +
                    "<MedicalInsuranceType></MedicalInsuranceType>" +
                    "<IsFirst>N</IsFirst>" +
                    "<RegisterDateTime>20200121</RegisterDateTime>" +
                    "<RegisterUserID>"+patientMappingCode+"</RegisterUserID>" +
                    "<RegisterUserName></RegisterUserName>" +
                    "<OutStatus>20</OutStatus>" +
                    "<ModifierID></ModifierID>" +
                    "<Modifier></Modifier>" +
                    "<ModifyTime></ModifyTime>" +
                    "<RetreatDateTime></RetreatDateTime>" +
                    "<RetreatUserID></RetreatUserID>" +
                    "<RetreatUserName></RetreatUserName>" +
                    "<PaymentMethodCode></PaymentMethodCode>" +
                    "<PaymentMethod></PaymentMethod>" +
                    "<RegisterFee></RegisterFee>" +
                    "<MedicalFee></MedicalFee>" +
                    "<OtherFee></OtherFee>" +
                    "<TotalFee></TotalFee>" +
                    "<MedicalFloor>N</MedicalFloor>" +
                    "<MedicalAddress></MedicalAddress>" +
                    "<LastDeptCode></LastDeptCode>" +
                    "<LastDeptName></LastDeptName>" +
                    "<LastDoctorID></LastDoctorID>" +
                    "<LastDoctorName></LastDoctorName>" +
                    "<LastTreatDateTime></LastTreatDateTime>" +
                    "<LastOpid></LastOpid>" +
                    "<NumTypeCode>0</NumTypeCode>" +
                    "<NumTypeName></NumTypeName>" +
                    "<RegisterSource>1</RegisterSource>" +
                    "<AcctNO></AcctNO>" +
                    "<IsAcct>N</IsAcct>" +
                    "<ManageType>"+manageType+"</ManageType>" +
                    "<Times>"+registerCon+"</Times>" +
                    "</OutRegister>" +
                    "<PatientInfo>" +
                    "<RecordFlow>"+outpatientDO.getId()+"</RecordFlow>" +
                    "<PID>"+patientMappingCode+"</PID></PatientInfo></HtRequest>";
            
            
//            String xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
//                    "<HtRequest >" +
//                    "<PatientInfo>" +
@ -1543,142 +1501,134 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
//                    "<RhBloodType></RhBloodType>" +
//                    "</PatientInfo>" +
//                    "</HtRequest>";
        String returnValue = "";
        params.put("xmlStr", _xmlStr);
        returnValue = WebserviceUtil.post("http://192.10.33.34:9080/HtMzWebService/services/Manage",
                "http://business.htemr.haitaiinc.com",
                "manageAdt",
                params);
        logger.info("调用电子病历注册接口请求成功,返回值xmlstr:" + returnValue);
        return returnValue;
            String returnValue = "";
            params.put("xmlStr",_xmlStr);
        
            returnValue = WebserviceUtil.post("http://192.10.33.34:9080/HtMzWebService/services/Manage",
                    "http://business.htemr.haitaiinc.com",
                    "manageAdt",
                    params);
        
            logger.info("调用电子病历注册接口请求成功,返回值xmlstr:"+returnValue);
            
            return returnValue;
    }
    /**
     * 获取诊断
     *
     * @param pyKey
     * @return
     * @throws Exception
     */
    public JSONArray getICD10(String pyKey) throws Exception {
        return entranceService.MS25001(pyKey, demoFlag);
    public JSONArray getICD10(String pyKey)throws Exception{
        return entranceService.MS25001(pyKey,demoFlag);
    }
    /**
     * 获取药品
     *
     * @return
     */
    public JSONArray getDrugDictionary(String chargeCode, String pyKey, String winNo, String groupNo) throws Exception {
        return entranceService.MS53001(chargeCode, pyKey, "0", winNo, "0", groupNo, demoFlag);
    public JSONArray getDrugDictionary(String chargeCode,String pyKey,String winNo,String groupNo)throws Exception{
        return entranceService.MS53001(chargeCode,pyKey,"0",winNo,"0",groupNo,demoFlag);
    }
    /**
     * 获取药品用法
     */
    public JSONArray getDrugUse(String drugNo, String pyKey) throws Exception {
        return entranceService.BS10110(drugNo, pyKey, demoFlag);
    public JSONArray getDrugUse(String drugNo,String pyKey)throws Exception{
        return entranceService.BS10110(drugNo,pyKey,demoFlag);
    }
    /**
     * 医院频次
     *
     * @return
     */
    public JSONArray getDrugFrequency() throws Exception {
    public JSONArray getDrugFrequency()throws Exception{
        return entranceService.MS30012(demoFlag);
    }
    /**
     * 检查模板选择接口
     *
     * @param bz_code
     * @param flag
     * @return
     * @throws Exception
     */
    public JSONArray getJcmb(String bz_code, String tc_no, String flag) throws Exception {
        return entranceService.BS25033(bz_code, tc_no, flag, demoFlag);
    public JSONArray getJcmb(String bz_code,String tc_no,String flag)throws Exception{
        return entranceService.BS25033(bz_code,tc_no,flag,demoFlag);
    }
    /**
     * 检验选择接口
     *
     * @param bz_code
     * @param flag
     * @return
     * @throws Exception
     */
    public JSONArray getJymb(String bz_code, String tc_no, String flag) throws Exception {
        return entranceService.BS20030(bz_code, tc_no, flag, demoFlag);
    public JSONArray getJymb(String bz_code,String tc_no,String flag)throws Exception{
        return entranceService.BS20030(bz_code,tc_no,flag,demoFlag);
    }
    /**
     * 套餐选择接口
     *
     * @param bz_code
     * @param flag
     * @return
     * @throws Exception
     */
    public JSONArray getTcxz(String bz_code, String tc_no, String flag) throws Exception {
        return entranceService.MS02017(bz_code, tc_no, flag, demoFlag);
    public JSONArray getTcxz(String bz_code,String tc_no,String flag)throws Exception{
        return entranceService.MS02017(bz_code,tc_no,flag,demoFlag);
    }
    /**
     * 套餐子项目接口
     *
     * @param parent_code 检查检验项目的charge_code
     * @return
     * @throws Exception
     */
    public JSONArray getTcChild(String parent_code) throws Exception {
        return entranceService.MS02015(parent_code, demoFlag);
    public JSONArray getTcChild(String parent_code)throws Exception{
        return entranceService.MS02015(parent_code,demoFlag);
    }
    /**
     * 项目子项目接口
     *
     * @param zd_charge_code
     * @return
     * @throws Exception
     */
    public JSONArray getInsChild(String zd_charge_code) throws Exception {
        return entranceService.MS02016(zd_charge_code, demoFlag);
    public JSONArray getInsChild(String zd_charge_code)throws Exception{
        return entranceService.MS02016(zd_charge_code,demoFlag);
    }
    /**
     * 获取检查检验
     *
     * @return
     */
    public JSONArray getInspectionDictionary(String pyKey, String codes, String winNo) throws Exception {
        JSONArray rs = entranceService.MS25002(pyKey, codes, winNo, demoFlag);
        if (rs != null && rs.size() > 0) {
    public JSONArray getInspectionDictionary(String pyKey,String codes,String winNo)throws Exception{
        JSONArray rs = entranceService.MS25002(pyKey,codes,winNo,demoFlag);
        if(rs!=null&&rs.size()>0){
            //设置科室翻译名称字典,减少循环层级降低循环次数
            List<DictHospitalDeptDO> depts = dictHospitalDeptDao.findByOrgCode("350211A1002");
            Map<String, String> deptDictMap = new HashedMap();
            for (DictHospitalDeptDO dp : depts) {
                deptDictMap.put(dp.getCode(), dp.getName());
            List<DictHospitalDeptDO> depts =dictHospitalDeptDao.findByOrgCode("350211A1002");
            Map<String,String> deptDictMap = new HashedMap();
            for(DictHospitalDeptDO dp:depts){
                deptDictMap.put(dp.getCode(),dp.getName());
            }
            //翻译执行科室
            for (int i = 0; i < rs.size(); i++) {
                JSONObject dict = (JSONObject) rs.get(i);
            for(int i=0;i<rs.size();i++){
                JSONObject dict = (JSONObject)rs.get(i);
                String dept = dict.getString("exec_unit");
                if (StringUtils.isNotBlank(dept)) {
                if(StringUtils.isNotBlank(dept)){
                    String deptName = deptDictMap.get(dept);
                    if (StringUtils.isNotBlank(deptName)) {
                        dict.put("exec_unit_name", deptName);
                    } else {
                        dict.put("exec_unit_name", "");
                    if(StringUtils.isNotBlank(deptName)){
                        dict.put("exec_unit_name",deptName);
                    }else{
                        dict.put("exec_unit_name","");
                    }
                }
            }
@ -1688,17 +1638,16 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 下诊断,线上开方
     *
     * @param outPatientId
     * @param advice
     * @param type          1带处方,2不带处方
     * @param type 1带处方,2不带处方
     * @param infoJsons
     * @param diagnosisJson
     * @return
     */
    public Map<String, Object> makeDiagnosis(String outPatientId, String advice, String type, String infoJsons, String diagnosisJson, String inspectionJson) throws Exception {
    public Map<String,Object> makeDiagnosis(String outPatientId,String advice,String type,String infoJsons,String diagnosisJson,String inspectionJson)throws Exception{
        Map<String, Object> result = new HashedMap();
        Map<String,Object> result = new HashedMap();
        //获取门诊记录
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outPatientId);
@ -1709,9 +1658,9 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        //创建处方记录
        List<WlyyPrescriptionDO> prescriptionDOs = prescriptionDao.findByOutpatientId(outPatientId);
        WlyyPrescriptionDO prescriptionDO = null;
        if (prescriptionDOs != null && prescriptionDOs.size() > 0) {
        if(prescriptionDOs!=null&&prescriptionDOs.size()>0){
            prescriptionDO = prescriptionDOs.get(0);
        } else {
        }else{
            prescriptionDO = new WlyyPrescriptionDO();
            prescriptionDO.setOutpatientId(outPatientId);
        }
@ -1726,44 +1675,44 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        //========================处方操作结束=============================================================
        //加入处方状态变更流水日志
        prescriptionLogService.addPrescriptionLog(prescription.getId(), 10, 2, outpatientDO.getDoctor(), outpatientDO.getDoctorName(), "", new Date());
        prescriptionLogService.addPrescriptionLog(prescription.getId(),10,2,outpatientDO.getDoctor(),outpatientDO.getDoctorName(),"",new Date());
        //============================下诊断==============================================================
        //删除之前诊断
        List<WlyyPrescriptionDiagnosisDO> ds = prescriptionDiagnosisDao.findByPrescriptionId(prescription.getId());
        if (ds != null && ds.size() > 0) {
        if(ds!=null&&ds.size()>0){
            prescriptionDiagnosisDao.delete(ds);
        }
        List<WlyyPrescriptionDiagnosisDO> diagnosisDOs = (List<WlyyPrescriptionDiagnosisDO>) com.alibaba.fastjson.JSONArray.parseArray(diagnosisJson, WlyyPrescriptionDiagnosisDO.class);
        String Icd10 = "";
        String Icd10Name = "";
        for (WlyyPrescriptionDiagnosisDO diagnosisDO : diagnosisDOs) {
            if ("1".equals(diagnosisDO.getType())) {
                Icd10 = diagnosisDO.getCode() + "," + Icd10;
                Icd10Name += diagnosisDO.getName() + "," + Icd10Name;
            } else {
                Icd10 += diagnosisDO.getCode() + ",";
                Icd10Name += diagnosisDO.getName() + ",";
        for(WlyyPrescriptionDiagnosisDO diagnosisDO:diagnosisDOs){
            if("1".equals(diagnosisDO.getType())){
                Icd10 = diagnosisDO.getCode()+","+Icd10;
                Icd10Name+=diagnosisDO.getName()+","+Icd10Name;
            }else {
                Icd10+=diagnosisDO.getCode()+",";
                Icd10Name+=diagnosisDO.getName()+",";
            }
            diagnosisDO.setPrescriptionId(prescription.getId());
        }
        prescriptionDiagnosisDao.save(diagnosisDOs);
        //存储icd10
        Icd10 = Icd10.substring(0, Icd10.length() - 1);
        Icd10Name = Icd10Name.substring(0, Icd10Name.length() - 1);
        Icd10 = Icd10.substring(0,Icd10.length()-1);
        Icd10Name = Icd10Name.substring(0,Icd10Name.length()-1);
        outpatientDO.setIcd10(Icd10);
        outpatientDO.setIcd10Name(Icd10Name);
        outpatientDao.save(outpatientDO);
        //============================下诊断end==============================================================
        //判断是否有检查检验或药品开方
        if ("1".equals(type)) {
        if("1".equals(type)){
            //doctor转换为his医生
            DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(outpatientDO.getDoctor(), outpatientDO.getHospital());
            if (doctorMappingDO == null) {
            DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(outpatientDO.getDoctor(),outpatientDO.getHospital());
            if(doctorMappingDO==null){
                throw new RuntimeException("未找到医生映射信息");
            }
@ -1773,22 +1722,22 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            //===================药品操作======================================================
            // 删除原有药品信息
            List<WlyyPrescriptionInfoDO> oldInfos = prescriptionInfoDao.findByPrescriptionId(prescription.getId());
            if (oldInfos != null && oldInfos.size() > 0) {
            if(oldInfos!=null&&oldInfos.size()>0){
                prescriptionInfoDao.delete(oldInfos);
            }
            //存储药品,构建his开方入参
            if (StringUtils.isNotBlank(infoJsons)) {
            if(StringUtils.isNotBlank(infoJsons)){
                //药品
                List<WlyyPrescriptionInfoDO> infoDOs = (List<WlyyPrescriptionInfoDO>) com.alibaba.fastjson.JSONArray.parseArray(infoJsons, WlyyPrescriptionInfoDO.class);
                for (WlyyPrescriptionInfoDO info : infoDOs) {
                for(WlyyPrescriptionInfoDO info:infoDOs){
                    info.setDel(1);
                    info.setPrescriptionId(prescription.getId());
                    //设置his药品查询条件
                    setInfoJsonParam(jsonData, doctorMappingDO, outpatientDO, prescriptionDO, info, Icd10);
                    setInfoJsonParam(jsonData,doctorMappingDO,outpatientDO,prescriptionDO,info,Icd10);
                }
                //保存药品信息
                prescriptionInfoDao.save(infoDOs);
@ -1803,20 +1752,20 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            //存储检查检验,构建his开方入参
            //删除之前检查检验
            List<WlyyInspectionDO> inspectionDels = wlyyInspectionDao.findByOutpatientId(outPatientId);
            if (inspectionDels != null && inspectionDels.size() > 0) {
            if(inspectionDels!=null&&inspectionDels.size()>0){
                wlyyInspectionDao.delete(inspectionDels);
            }
            if (StringUtils.isNotBlank(inspectionJson)) {
            if(StringUtils.isNotBlank(inspectionJson)){
                List<WlyyInspectionDO> inspections = (List<WlyyInspectionDO>) com.alibaba.fastjson.JSONArray.parseArray(inspectionJson, WlyyInspectionDO.class);
                for (WlyyInspectionDO ins : inspections) {
                for(WlyyInspectionDO ins:inspections){
                    ins.setCreateTime(new Date());
                    ins.setPrescriptionId(prescription.getId());
                    ins.setOutpatientId(outPatientId);
                    //设置his药品查询条件
                    setInspectionParam(jsonData, doctorMappingDO, outpatientDO, prescriptionDO, ins, Icd10);
                    setInspectionParam(jsonData,doctorMappingDO,outpatientDO,prescriptionDO,ins,Icd10);
                }
                //保存检查检验。
                wlyyInspectionDao.save(inspections);
@ -1832,14 +1781,14 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            prescriptionDao.save(prescription);
            //上传his开方
            return sendHisDiagnosis(jsonData, outpatientDO, prescription);
            return sendHisDiagnosis(jsonData,outpatientDO,prescription);
        } else {
        }else{
            outpatientDO.setStatus("2");
            outpatientDao.save(outpatientDO);
            result.put("code", 1);
            result.put("mes", "诊断完成");
            result.put("code",1);
            result.put("mes","诊断完成");
            return result;
        }
@ -1847,60 +1796,57 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 计算药品费用
     *
     * @param infoDOs
     * @return
     */
    public Double getInfoFee(List<WlyyPrescriptionInfoDO> infoDOs) {
    public Double getInfoFee(List<WlyyPrescriptionInfoDO> infoDOs){
        Double fee = 0D;
        try {
            if (infoDOs != null && infoDOs.size() > 0) {
                for (WlyyPrescriptionInfoDO info : infoDOs) {
            if(infoDOs!=null&&infoDOs.size()>0){
                for(WlyyPrescriptionInfoDO info:infoDOs){
                    Integer quantity = Integer.parseInt(info.getQuantity());
                    fee += info.getPackRetprice() * quantity;
                    fee += info.getPackRetprice()*quantity;
                }
            }
        } catch (Exception e) {
            logger.error("getInfoFee:" + e.toString());
        }catch (Exception e){
            logger.error("getInfoFee:"+e.toString());
        }
        return fee;
    }
    /**
     * 计算检查检验费用
     *
     * @param inspections
     * @return
     */
    public Double getInsFee(List<WlyyInspectionDO> inspections) {
    public Double getInsFee(List<WlyyInspectionDO> inspections){
        Double fee = 0D;
        try {
            if (inspections != null && inspections.size() > 0) {
                for (WlyyInspectionDO ins : inspections) {
            if(inspections!=null&&inspections.size()>0){
                for(WlyyInspectionDO ins:inspections){
                    Double chargeAmount = Double.parseDouble(ins.getChargeAmount());
                    fee += chargeAmount * ins.getQuantity();
                    fee += chargeAmount*ins.getQuantity();
                }
            }
        } catch (Exception e) {
            logger.error("getInsFee:" + e.toString());
        }catch (Exception e){
            logger.error("getInsFee:"+e.toString());
        }
        return fee;
    }
    /**
     * 计算挂号费用
     *
     * @param doctor
     * @return
     */
    public Double getChargeFee(String doctor) {
    public Double getChargeFee(String doctor){
        Double fee = 0D;
        try {
        try{
            BaseDoctorDO doctorDO = baseDoctorDao.findById(doctor);
            WlyyChargeDictDO chargeDictDO = wlyyChargeDictDao.findByChargeTypeAndDeptTypeCode(doctorDO.getChargeType(), "6");
            WlyyChargeDictDO chargeDictDO = wlyyChargeDictDao.findByChargeTypeAndDeptTypeCode(doctorDO.getChargeType(),"6");
            return chargeDictDO.getReqFee();
        } catch (Exception e) {
            logger.error("getChargeFee:" + e.toString());
        }catch (Exception e){
            logger.error("getChargeFee:"+e.toString());
        }
        return fee;
@ -1908,19 +1854,18 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 上传his开方
     *
     * @param jsonData
     * @param outpatientDO
     * @param prescription
     * @return
     * @throws Exception
     */
    public Map<String, Object> sendHisDiagnosis(com.alibaba.fastjson.JSONArray jsonData, WlyyOutpatientDO outpatientDO, WlyyPrescriptionDO prescription) throws Exception {
        Map<String, Object> result = new HashedMap();
    public Map<String,Object> sendHisDiagnosis(com.alibaba.fastjson.JSONArray jsonData,WlyyOutpatientDO outpatientDO,WlyyPrescriptionDO prescription)throws Exception{
        Map<String,Object> result = new HashedMap();
        //调用his开方接口
        net.sf.json.JSONObject jsonObject = entranceService.BS10112(jsonData.toJSONString(), demoFlag);
        net.sf.json.JSONObject jsonObject = entranceService.BS10112(jsonData.toJSONString(),demoFlag);
        //如果无法解析his系统报文,his系统报错
        if (jsonObject == null) {
        if(jsonObject==null){
            //记录http日志
            WlyyHttpLogDO log = new WlyyHttpLogDO();
            log.setCode("makeDiagnosis");
@ -1937,15 +1882,15 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            prescription.setStatus(13);
            prescriptionDao.save(prescription);
            //记录开发失败日志
            prescriptionLogService.addPrescriptionLog(prescription.getId(), 13, 2, outpatientDO.getDoctor(), outpatientDO.getDoctorName(), "", new Date());
            prescriptionLogService.addPrescriptionLog(prescription.getId(),13,2,outpatientDO.getDoctor(),outpatientDO.getDoctorName(),"",new Date());
            //开方失败返回值
            result.put("code", -1);
            result.put("mes", "开方失败,his系统异常");
            result.put("code",-1);
            result.put("mes","开方失败,his系统异常");
            return result;
        }
        logger.info("调用his开方接口: " + jsonObject.toString());
        logger.info("调用his开方接口: "+jsonObject.toString());
        //判断返回结果
        String rs = jsonObject.getString("@RESULT");
        //保存日志
@ -1960,7 +1905,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        log.setCreateTime(new Date());
        wlyyHttpLogDao.save(log);
        if ("0".equals(rs)) {
        if("0".equals(rs)){
            String admNo = jsonObject.getString("@ADM_NO");
            String realOrder = jsonObject.getString("@real_order");
@ -1970,19 +1915,19 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            outpatientDO.setAdmNo(admNo);
            outpatientDao.save(outpatientDO);
            result.put("code", 1);
            result.put("mes", "开方提交成功");
            result.put("code",1);
            result.put("mes","开方提交成功");
            return result;
        } else {
        }else{
            //开方失败
            result.put("code", -1);
            result.put("mes", jsonObject.getString("@MSG"));
            result.put("code",-1);
            result.put("mes",jsonObject.getString("@MSG"));
            //更新处方状态
            prescription.setStatus(13);
            prescriptionDao.save(prescription);
            //记录开发失败日志
            prescriptionLogService.addPrescriptionLog(prescription.getId(), 13, 2, outpatientDO.getDoctor(), outpatientDO.getDoctorName(), "", new Date());
            prescriptionLogService.addPrescriptionLog(prescription.getId(),13,2,outpatientDO.getDoctor(),outpatientDO.getDoctorName(),"",new Date());
            return result;
        }
@ -1990,135 +1935,132 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 设置检查检验his入参
     *
     * @param jsonData
     * @param doctorMappingDO
     * @param outpatientDO
     * @param inspectionDO
     * @param Icd10
     */
    public void setInspectionParam(com.alibaba.fastjson.JSONArray jsonData, DoctorMappingDO doctorMappingDO, WlyyOutpatientDO outpatientDO, WlyyPrescriptionDO prescriptionDO, WlyyInspectionDO inspectionDO, String Icd10) {
    public void setInspectionParam(com.alibaba.fastjson.JSONArray jsonData,DoctorMappingDO doctorMappingDO,WlyyOutpatientDO outpatientDO,WlyyPrescriptionDO prescriptionDO,WlyyInspectionDO inspectionDO,String Icd10){
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        if (StringUtils.isNotBlank(prescriptionDO.getRealOrder())) {
            json.put("realOrder", prescriptionDO.getRealOrder());
        if(StringUtils.isNotBlank(prescriptionDO.getRealOrder())){
            json.put("realOrder",prescriptionDO.getRealOrder());
        }
        json.put("cardNo", outpatientDO.getCardNo());
        json.put("doctor", doctorMappingDO.getMappingCode());
        json.put("dept", outpatientDO.getDept());
        json.put("cardNo",outpatientDO.getCardNo());
        json.put("doctor",doctorMappingDO.getMappingCode());
        json.put("dept",outpatientDO.getDept());
        json.put("frequency", inspectionDO.getFrequency()); //组号
        json.put("quantity", inspectionDO.getQuantity()); //数量
        json.put("serialNo", outpatientDO.getRegisterNo()); //挂号流水号-必输
        json.put("groupNo", "00"); //-库房号
        json.put("serial", "00"); //药品序列号-必输
        json.put("frequency",inspectionDO.getFrequency()); //组号
        json.put("quantity",inspectionDO.getQuantity()); //数量
        json.put("serialNo",outpatientDO.getRegisterNo()); //挂号流水号-必输
        json.put("groupNo","00"); //-库房号
        json.put("serial","00"); //药品序列号-必输
        json.put("winNo", outpatientDO.getWinNo());
        json.put("chargeFlag", 2); //项目类别-必输  1-药品 2检验检查
        json.put("winNo",outpatientDO.getWinNo());
        json.put("chargeFlag",2); //项目类别-必输  1-药品 2检验检查
        /**
         *  code;//项目编码',
         *  name;//(检查方法)',
         *  information;//病史与体征',
         *  checkEquip;//类别',
         *  checkPart;//部位',
         *  adresult;//辅助检查治疗',
         *  goal;//检查目的',
         *  opview;//手术所见-病理申请单必填',
         *  specimenName;//标本名称-病理申请单必填',
         *  specimenNum;//标本数量-病理申请单必填',
         *  ywjcResult;//以往检查结果-病理申请单选填',
         *  ywjcDate;//以往检查时间-病理申请单选填 格式:yyyy-mm-dd',
         *  blzd;//病理诊断-病理申请单选填',
         *  fixationfluid;//固定液
          *  code;//项目编码',
          *  name;//(检查方法)',
          *  information;//病史与体征',
          *  checkEquip;//类别',
          *  checkPart;//部位',
          *  adresult;//辅助检查治疗',
          *  goal;//检查目的',
          *  opview;//手术所见-病理申请单必填',
          *  specimenName;//标本名称-病理申请单必填',
          *  specimenNum;//标本数量-病理申请单必填',
          *  ywjcResult;//以往检查结果-病理申请单选填',
          *  ywjcDate;//以往检查时间-病理申请单选填 格式:yyyy-mm-dd',
          *  blzd;//病理诊断-病理申请单选填',
          *  fixationfluid;//固定液
         */
        json.put("parentCode", inspectionDO.getParentCode()); //父节点
        json.put("chargeCode", inspectionDO.getCode()); //项目编码
        json.put("name", inspectionDO.getName()); //挂号流水号-必输
        json.put("information", inspectionDO.getInformation());//库房号-必输
        json.put("checkEquip", inspectionDO.getCheckEquip()); //药品序列号-必输
        json.put("checkPart", inspectionDO.getCheckPart());
        json.put("adresult", inspectionDO.getAdresult());
        json.put("goal", inspectionDO.getGoal());
        json.put("opview", inspectionDO.getOpview());
        json.put("specimenName", inspectionDO.getSpecimenName());
        json.put("specimenNum", inspectionDO.getSpecimenNum());
        json.put("ywjcResult", inspectionDO.getYwjcResult());
        json.put("ywjcDate", inspectionDO.getYwjcDate());
        json.put("blzd", inspectionDO.getBlzd());
        json.put("fixationfluid", inspectionDO.getFixationfluid());
        json.put("parentCode",inspectionDO.getParentCode()); //父节点
        json.put("chargeCode",inspectionDO.getCode()); //项目编码
        json.put("name",inspectionDO.getName()); //挂号流水号-必输
        json.put("information",inspectionDO.getInformation());//库房号-必输
        json.put("checkEquip",inspectionDO.getCheckEquip()); //药品序列号-必输
        json.put("checkPart",inspectionDO.getCheckPart());
        json.put("adresult",inspectionDO.getAdresult());
        json.put("goal",inspectionDO.getGoal());
        json.put("opview",inspectionDO.getOpview());
        json.put("specimenName",inspectionDO.getSpecimenName());
        json.put("specimenNum",inspectionDO.getSpecimenNum());
        json.put("ywjcResult",inspectionDO.getYwjcResult());
        json.put("ywjcDate",inspectionDO.getYwjcDate());
        json.put("blzd",inspectionDO.getBlzd());
        json.put("fixationfluid",inspectionDO.getFixationfluid());
        //设置诊断
        setIcd10(json, Icd10);
        setIcd10(json,Icd10);
        jsonData.add(json);
        logger.info("json:" + json.toString());
        logger.info("json:" +json.toString());
    }
    /**
     * 设置药品his入参
     *
     * @param jsonData
     * @param doctorMappingDO
     * @param outpatientDO
     * @param info
     * @param Icd10
     */
    public void setInfoJsonParam(com.alibaba.fastjson.JSONArray jsonData, DoctorMappingDO doctorMappingDO, WlyyOutpatientDO outpatientDO, WlyyPrescriptionDO prescriptionDO, WlyyPrescriptionInfoDO info, String Icd10) {
    public void setInfoJsonParam(com.alibaba.fastjson.JSONArray jsonData,DoctorMappingDO doctorMappingDO,WlyyOutpatientDO outpatientDO,WlyyPrescriptionDO prescriptionDO,WlyyPrescriptionInfoDO info,String Icd10){
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        if (StringUtils.isNotBlank(prescriptionDO.getRealOrder())) {
            json.put("realOrder", prescriptionDO.getRealOrder());
        }
        json.put("cardNo", outpatientDO.getCardNo());
        json.put("doctor", doctorMappingDO.getMappingCode());
        json.put("dept", outpatientDO.getDept());
        json.put("chargeCode", info.getDrugNo());
        json.put("winNo", outpatientDO.getWinNo());
        json.put("chargeFlag", 1); //项目类别-必输  1-药品 2检验检查
        json.put("quantity", info.getQuantity()); //数量-必输
        json.put("serialNo", outpatientDO.getRegisterNo()); //挂号流水号-必输
        json.put("groupNo", info.getGroupNo());//库房号-必输
        json.put("serial", info.getSerial()); //药品序列号-必输
        json.put("dosage", info.getDosage());
        json.put("unit", info.getUnit());
        json.put("usage", info.getUsageCode());
        json.put("supplyCode", info.getSupplyCode());
        if (StringUtils.isNotBlank(info.getDays())) {
            json.put("days", info.getDays());
        } else {
        if(StringUtils.isNotBlank(prescriptionDO.getRealOrder())){
            json.put("realOrder",prescriptionDO.getRealOrder());
        }
        json.put("cardNo",outpatientDO.getCardNo());
        json.put("doctor",doctorMappingDO.getMappingCode());
        json.put("dept",outpatientDO.getDept());
        json.put("chargeCode",info.getDrugNo());
        json.put("winNo",outpatientDO.getWinNo());
        json.put("chargeFlag",1); //项目类别-必输  1-药品 2检验检查
        json.put("quantity",info.getQuantity()); //数量-必输
        json.put("serialNo",outpatientDO.getRegisterNo()); //挂号流水号-必输
        json.put("groupNo",info.getGroupNo());//库房号-必输
        json.put("serial",info.getSerial()); //药品序列号-必输
        json.put("dosage",info.getDosage());
        json.put("unit",info.getUnit());
        json.put("usage",info.getUsageCode());
        json.put("supplyCode",info.getSupplyCode());
        if(StringUtils.isNotBlank(info.getDays())){
            json.put("days",info.getDays());
        }else{
            //如果是中草药,贴数为天数,没有默认1天
            json.put("days", StringUtils.isNotBlank(info.getPostCount()) ? info.getPostCount() : "1");
            json.put("days",StringUtils.isNotBlank(info.getPostCount())?info.getPostCount():"1");
        }
        json.put("frequency", info.getFrequency());
        json.put("comm", info.getComm());
        json.put("frequency",info.getFrequency());
        json.put("comm",info.getComm());
        //设置诊断
        setIcd10(json, Icd10);
        setIcd10(json,Icd10);
        jsonData.add(json);
        logger.info("json:" + json.toString());
        logger.info("json:" +json.toString());
    }
    public void setIcd10(com.alibaba.fastjson.JSONObject json, String Icd10) {
    public void setIcd10(com.alibaba.fastjson.JSONObject json,String Icd10){
        String Icd10s[] = Icd10.split(",");
        for (int i = 0; i < Icd10s.length; i++) {
            if (i == 0) {
                json.put("icdCode", Icd10s[i]);
            } else if (i == 1) {
                json.put("diagTwo", Icd10s[i]);
            } else if (i == 2) {
                json.put("diagThree", Icd10s[i]);
            } else if (i == 3) {
                json.put("diagFour", Icd10s[i]);
            } else if (i == 4) {
                json.put("diagFive", Icd10s[i]);
        for(int i=0;i<Icd10s.length;i++){
            if(i==0){
                json.put("icdCode",Icd10s[i]);
            }else if(i==1){
                json.put("diagTwo",Icd10s[i]);
            }else if(i==2){
                json.put("diagThree",Icd10s[i]);
            }else if(i==3){
                json.put("diagFour",Icd10s[i]);
            }else if(i==4){
                json.put("diagFive",Icd10s[i]);
            }
        }
    }
    /**
     * 订单查询
     *
     * @param status
     * @param oneselfPickupFlg
     * @param nameKey
@ -2128,8 +2070,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @param size
     * @return
     */
    public MixEnvelop findExpressageList(String status, String oneselfPickupFlg, String nameKey, String startTime, String endTime, Integer page, Integer size) {
        String totalSql = "SELECT " +
    public MixEnvelop findExpressageList(String status,String oneselfPickupFlg,String nameKey,String startTime,String endTime,Integer page,Integer size){
        String totalSql="SELECT " +
                " COUNT(1) AS total " +
                " FROM " +
                " wlyy_outpatient o " +
@ -2137,20 +2079,20 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " JOIN wlyy_prescription_expressage e ON e.outpatient_id = o.id" +
                " WHERE" +
                " 1=1";
        if (StringUtils.isNotBlank(status)) {
            totalSql += " AND p.status in(" + status + ")";
        if(StringUtils.isNotBlank(status)){
            totalSql+=" AND p.status in("+status+")";
        }
        if (StringUtils.isNotBlank(oneselfPickupFlg)) {
            totalSql += " AND e.oneself_pickup_flg =" + oneselfPickupFlg;
        if(StringUtils.isNotBlank(oneselfPickupFlg)){
            totalSql+=" AND e.oneself_pickup_flg ="+oneselfPickupFlg;
        }
        if (StringUtils.isNotBlank(nameKey)) {
            totalSql += " AND e.name like '%" + nameKey + "%'";
        if(StringUtils.isNotBlank(nameKey)){
            totalSql+=" AND e.name like '%"+nameKey+"%'";
        }
        if (StringUtils.isNotBlank(startTime)) {
            totalSql += " AND e.create_time >='" + startTime + " 00:00:00'";
        if(StringUtils.isNotBlank(startTime)){
            totalSql+=" AND e.create_time >='"+startTime+" 00:00:00'";
        }
        if (StringUtils.isNotBlank(endTime)) {
            totalSql += " AND e.create_time <='" + endTime + " 23:59:59'";
        if(StringUtils.isNotBlank(endTime)){
            totalSql+=" AND e.create_time <='"+endTime+" 23:59:59'";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -2158,7 +2100,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        if (rstotal != null && rstotal.size() > 0) {
            count = (Long) rstotal.get(0).get("total");
        }
        String sql = "SELECT " +
        String sql ="SELECT " +
                " e.create_time AS createTime, " +
                " e.`name`, " +
                " e.oneself_pickup_flg AS oneselfPickupFlg, " +
@ -2173,44 +2115,44 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " JOIN wlyy_prescription_expressage e ON e.outpatient_id = o.id " +
                " WHERE" +
                " 1=1";
        if (StringUtils.isNotBlank(status)) {
            sql += " AND p.status in(" + status + ")";
        if(StringUtils.isNotBlank(status)){
            sql+=" AND p.status in("+status+")";
        }
        if (StringUtils.isNotBlank(oneselfPickupFlg)) {
            sql += " AND e.oneself_pickup_flg =" + oneselfPickupFlg;
        if(StringUtils.isNotBlank(oneselfPickupFlg)){
            sql+=" AND e.oneself_pickup_flg ="+oneselfPickupFlg;
        }
        if (StringUtils.isNotBlank(nameKey)) {
            sql += " AND e.name like '%" + nameKey + "%'";
        if(StringUtils.isNotBlank(nameKey)){
            sql+=" AND e.name like '%"+nameKey+"%'";
        }
        if (StringUtils.isNotBlank(startTime)) {
            sql += " AND e.create_time >='" + startTime + " 00:00:00'";
        if(StringUtils.isNotBlank(startTime)){
            sql+=" AND e.create_time >='"+startTime+" 00:00:00'";
        }
        if (StringUtils.isNotBlank(endTime)) {
            sql += " AND e.create_time <='" + endTime + " 23:59:59'";
        if(StringUtils.isNotBlank(endTime)){
            sql+=" AND e.create_time <='"+endTime+" 23:59:59'";
        }
        sql += " LIMIT " + (page - 1) * size + "," + size + "";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
    }
    public Boolean setMailno(String mailno, String expressageId) {
        WlyyPrescriptionExpressageDO expressageDO = prescriptionExpressageDao.findOne(expressageId);
    public Boolean setMailno(String mailno, String expressageId){
        WlyyPrescriptionExpressageDO expressageDO =  prescriptionExpressageDao.findOne(expressageId);
        expressageDO.setMailno(mailno);
        prescriptionExpressageDao.save(expressageDO);
        return true;
    }
    public void pushListWrite(OutputStream os, List<Map<String, Object>> ls) throws Exception {
    public void pushListWrite(OutputStream os, List<Map<String,Object>> ls) throws Exception{
        WritableWorkbook wwb = jxl.Workbook.createWorkbook(os);
        try {
            WritableSheet ws;
            ws = wwb.createSheet("sheet", 1);
            ws = wwb.createSheet("sheet",1);
            String[] header = {"订单日期", "收货人", "诊断结果", "配送方式", "订单状态"};
            String[] header = {"订单日期","收货人","诊断结果","配送方式", "订单状态"};
            int k = 0;
            for (String h : header) {
                addCell(ws, 0, k, h);//表名,行,列,header
@ -2218,12 +2160,12 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            }
            int i = 1;
            for (Map<String, Object> m : ls) {
                addCell(ws, i, 0, DateUtil.dateToStr((Date) m.get("createTime"), "yyyy-MM-dd HH:mm:ss"), "");
                addCell(ws, i, 1, (String) m.get("name"), "");
                addCell(ws, i, 2, (String) m.get("icd10Name"), "");
                addCell(ws, i, 3, getOneselfPickupFlgString((Integer) m.get("oneselfPickupFlg")), "");
                addCell(ws, i, 4, getStatusName((Integer) m.get("status")), "");
            for (Map<String,Object> m : ls) {
                addCell(ws, i, 0, DateUtil.dateToStr((Date)m.get("createTime"),"yyyy-MM-dd HH:mm:ss"),"");
                addCell(ws, i, 1, (String)m.get("name"),"");
                addCell(ws, i, 2, (String)m.get("icd10Name"),"");
                addCell(ws, i, 3, getOneselfPickupFlgString((Integer)m.get("oneselfPickupFlg")),"");
                addCell(ws, i, 4, getStatusName((Integer)m.get("status")),"");
                i++;
            }
            wwb.write();
@ -2236,44 +2178,45 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    }
    /**
     *
     * @return
     */
    public String getOneselfPickupFlgString(Integer oneselfPickupFlg) {
        if (1 == oneselfPickupFlg) {
    public String getOneselfPickupFlgString(Integer oneselfPickupFlg){
        if(1 == oneselfPickupFlg){
            return "自取";
        } else if (0 == oneselfPickupFlg) {
        }else if(0 == oneselfPickupFlg){
            return "快递";
        } else {
        }else{
            return "其他";
        }
    }
    /**
     *
     * @param status
     * @return
     */
    public String getStatusName(Integer status) {
        if (31 == status) {
    public String getStatusName(Integer status){
        if(31==status){
            return "待配送";
        } else if (32 == status) {
        }else if(32==status){
            return "配送中";
        } else if (100 == status) {
        }else if(100==status){
            return "已完成";
        } else {
        }else{
            return "其他";
        }
    }
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column, String data) throws WriteException {
        Label label = new Label(column, row, data);
    public void addCell(WritableSheet ws, int row, int column,  String data) throws WriteException {
        Label label = new Label(column ,row, data);
        ws.addCell(label);
    }
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column, String data, String memo) throws WriteException {
        Label label = new Label(column, row, data);
        if (!org.springframework.util.StringUtils.isEmpty(memo)) {
        Label label = new Label(column ,row, data);
        if(!org.springframework.util.StringUtils.isEmpty(memo)){
            WritableCellFeatures cellFeatures = new WritableCellFeatures();
            cellFeatures.setComment(memo);
            label.setCellFeatures(cellFeatures);
@ -2281,270 +2224,147 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        ws.addCell(label);
    }
    public List<WlyyChargeDictVO> findByDeptTypeCode(String deptTypeCode) {
    public List<WlyyChargeDictVO> findByDeptTypeCode(String deptTypeCode){
        List<WlyyChargeDictDO> dictDOs = wlyyChargeDictDao.findByDeptTypeCode(deptTypeCode);
        List<WlyyChargeDictVO> dictVOs = new ArrayList<>();
        return convertToModels(dictDOs, dictVOs, WlyyChargeDictVO.class);
        return convertToModels(dictDOs,dictVOs,WlyyChargeDictVO.class);
    }
//      过时
//    public List<WlyyDoctorWorkTimeVO> findDoctorWorkTime(String doctor) {
//        //获取医生排班规则
//        List<WlyyHospitalSysDictDO> list = sysDictDao.findByDictName("Scheduling");
//
//        Calendar ncTime = Calendar.getInstance();
//        ncTime.setTime(new Date());
//
//        Calendar scTime = Calendar.getInstance();
//        scTime.setTime(new Date());
//
//        Calendar ecTime = Calendar.getInstance();
//        ecTime.setTime(new Date());
//
//        //设置几天号源,及最后天号源的开放时间
//        int days = Integer.parseInt(findHospitalSysDictValue(list, "OpenDays"));
//        String closeTime = findHospitalSysDictValue(list, "CloseTime");
//
//        //比较当前时间是否超过开放时间
//        if (DateUtil.strToDate(DateUtil.getTimeShort(), DateUtil.HH_MM_SS).after(DateUtil.strToDate(closeTime, DateUtil.HH_MM))) {
//            //当前时间超过开放时间,可以预约最后一天全部号源
//            ecTime.add(Calendar.DAY_OF_MONTH, days);
//            ecTime.set(ecTime.get(Calendar.YEAR), ecTime.get(Calendar.MONTH), ecTime.get(Calendar.DATE), 23, 59, 59);
//        } else {
//            //当前时间没超过开放时间,可以预约最后一天前一天全部号源
//            ecTime.add(Calendar.DAY_OF_MONTH, days > 1 ? days - 1 : 0);
//            ecTime.set(ecTime.get(Calendar.YEAR), ecTime.get(Calendar.MONTH), ecTime.get(Calendar.DATE), 23, 59, 59);
//        }
//
//
//        List<WlyyDoctorWorkTimeDO> times = doctorWorkTimeDao.findDoctorWorkTime(doctor, scTime.getTime(), ecTime.getTime());
//
//        workTimeFilter(list, times);
//
//        List<WlyyDoctorWorkTimeVO> timeVOs = new ArrayList<>();
//
//        convertToModels(times, timeVOs, WlyyDoctorWorkTimeVO.class);
//
//        if (timeVOs != null && timeVOs.size() > 0) {
//            for (WlyyDoctorWorkTimeVO timeVO : timeVOs) {
//                timeVO.setCount(findWorkTimeCount(timeVO.getId()));
//            }
//        }
//        return timeVOs;
//    }
    public List<WlyyDoctorWorkTimeVO> findDoctorWorkTime(String doctor){
        //获取医生排班规则
        List<WlyyHospitalSysDictDO> list = sysDictDao.findByDictName("Scheduling");
//    public List<WlyyDoctorWorkTimeDO> workTimeFilter(List<WlyyHospitalSysDictDO> sys, List<WlyyDoctorWorkTimeDO> times) {
//
//        if (times != null && times.size() > 0) {
//            //上午号源开放的最早天数
//            int AMCloseDays = Integer.parseInt(findHospitalSysDictValue(sys, "AMCloseDays"));
//            //每一天上午的最早预约的过号时间
//            String AMCloseTime = findHospitalSysDictValue(sys, "AMCloseTime");
//            //下午号源开放的最早天数
//            int PMCloseDays = Integer.parseInt(findHospitalSysDictValue(sys, "PMCloseDays"));
//            //每一天下午的最早预约的过号时间
//            String PMCloseTime = findHospitalSysDictValue(sys, "PMCloseTime");
//
//            Iterator it = times.iterator();
//            while (it.hasNext()) {
//                //设置上午过号时间
//                Calendar scAMTime = Calendar.getInstance();
//                scAMTime.setTime(new Date());
//                scAMTime.add(Calendar.DAY_OF_MONTH, AMCloseDays);
//
//                //设置下午午过号时间
//                Calendar scPMTime = Calendar.getInstance();
//                scPMTime.setTime(new Date());
//                scPMTime.add(Calendar.DAY_OF_MONTH, PMCloseDays);
//
//                WlyyDoctorWorkTimeDO time = (WlyyDoctorWorkTimeDO) it.next();
//
//                Boolean filter = true;
//
//                //1.【上午的排班中】 且 【排班结束时间】如果在【开放时间】前,则移除
//                if (filter && "1".equals(time.getTimeType()) && time.getEndTime().before(scAMTime.getTime())) {
//                    it.remove();
//                    filter = false;
//                }
//
//                //2.【下午午的排班中】 且 【排班结束时间】如果在【开放时间】前,则移除该排班
//                if (filter && "2".equals(time.getTimeType()) && time.getEndTime().before(scPMTime.getTime())) {
//                    it.remove();
//                    filter = false;
//                }
//
//                //3.如果【当前时间】过了【上午放号时间】,则移除所有上午的排班
//                if (filter && "1".equals(time.getTimeType()) &&
//                        DateUtil.strToDate(DateUtil.getTimeShort(), DateUtil.HH_MM_SS).after(DateUtil.strToDate(AMCloseTime, DateUtil.HH_MM))) {
//                    scAMTime.set(scAMTime.get(Calendar.YEAR), scAMTime.get(Calendar.MONTH), scAMTime.get(Calendar.DATE), 12, 00, 00);
//
//                    if (time.getEndTime().before(scAMTime.getTime())) {
//                        it.remove();
//                        filter = false;
//                    }
//                }
//                //4.如果【当前时间】过了【下午午放号时间】,则移除所有下午的排班
//                if (filter && "2".equals(time.getTimeType()) &&
//                        DateUtil.strToDate(DateUtil.getTimeShort(), DateUtil.HH_MM_SS).after(DateUtil.strToDate(PMCloseTime, DateUtil.HH_MM))) {
//                    scPMTime.set(scAMTime.get(Calendar.YEAR), scAMTime.get(Calendar.MONTH), scAMTime.get(Calendar.DATE), 12, 00, 00);
//
//                    if (time.getEndTime().before(scPMTime.getTime())) {
//                        it.remove();
//                    }
//                }
//            }
//        }
//        return times;
//    }
        Calendar ncTime = Calendar.getInstance();
        ncTime.setTime(new Date());
        Calendar scTime = Calendar.getInstance();
        scTime.setTime(new Date());
    public String findHospitalSysDictValue(List<WlyyHospitalSysDictDO> list, String dictCode) {
        Calendar ecTime = Calendar.getInstance();
        ecTime.setTime(new Date());
        if (list != null && list.size() > 0) {
            for (WlyyHospitalSysDictDO sysDictDO : list) {
                if (dictCode.equals(sysDictDO.getDictCode())) {
                    return sysDictDO.getDictValue();
                }
            }
        //设置几天号源,及最后天号源的开放时间
        int days =Integer.parseInt(findHospitalSysDictValue(list,"OpenDays"));
        String closeTime = findHospitalSysDictValue(list,"CloseTime");
        //比较当前时间是否超过开放时间
        if(DateUtil.strToDate(DateUtil.getTimeShort(),DateUtil.HH_MM_SS).after(DateUtil.strToDate(closeTime,DateUtil.HH_MM))){
            //当前时间超过开放时间,可以预约最后一天全部号源
            ecTime.add(Calendar.DAY_OF_MONTH,days);
            ecTime.set(ecTime.get(Calendar.YEAR),ecTime.get(Calendar.MONTH),ecTime.get(Calendar.DATE),23,59,59);
        }else{
            //当前时间没超过开放时间,可以预约最后一天前一天全部号源
            ecTime.add(Calendar.DAY_OF_MONTH,days>1?days-1:0);
            ecTime.set(ecTime.get(Calendar.YEAR),ecTime.get(Calendar.MONTH),ecTime.get(Calendar.DATE),23,59,59);
        }
        return "";
    }
    /**
     * 获取卡信息
     *
     * @param cardNo
     * @param demoFlag
     * @return
     * @throws Exception
     */
    public net.sf.json.JSONObject getCardInfo(String cardNo, boolean demoFlag) throws Exception {
        return entranceService.qutpatientBalance(cardNo, demoFlag);
    }
    /**
     * 新排班号源详情
     * @param id
     * @return
     */
    public List<Map<String,Object>> findWorkTimeInfo(String id){
        WlyyDoctorWorkTimeDO timeDO = doctorWorkTimeDao.findOne(id);
        List<WlyyDoctorWorkTimeDO> times =  doctorWorkTimeDao.findDoctorWorkTime(doctor,scTime.getTime(),ecTime.getTime());
        Long ss = timeDO.getEndTime().getTime()-timeDO.getStartTime().getTime();
        Long s = ss/timeDO.getSourceNumber();
        workTimeFilter(list,times);
        Calendar sc = Calendar.getInstance();
        sc.setTime(timeDO.getStartTime());
        List<WlyyDoctorWorkTimeVO> timeVOs = new ArrayList<>();
        List<Map<String,Object>> rs = new ArrayList<>();
        convertToModels(times,timeVOs,WlyyDoctorWorkTimeVO.class);
        //1.根据当前时间,去取已过时间的号源
        while (sc.getTime().before(timeDO.getEndTime())){
            if(new Date().before(sc.getTime())){
                break;
        if(timeVOs!=null&&timeVOs.size()>0){
            for(WlyyDoctorWorkTimeVO timeVO : timeVOs){
                timeVO.setCount(findWorkTimeCount(timeVO.getId()));
            }
            //加上时间间隔
            Date temp =new Date();
            temp.setTime(sc.getTime().getTime()+s);
            sc.setTime(temp);
        }
        return timeVOs;
    }
        List<WlyyPatientRegisterTimeDO> registerTimeDOs = patientRegisterTimeDao.findByDoctorAndWorkId(timeDO.getDoctor(),id);
    public List<WlyyDoctorWorkTimeDO> workTimeFilter(List<WlyyHospitalSysDictDO> sys,List<WlyyDoctorWorkTimeDO> times){
        if(times!=null&&times.size()>0){
            //上午号源开放的最早天数
            int AMCloseDays =Integer.parseInt(findHospitalSysDictValue(sys,"AMCloseDays"));
            //每一天上午的最早预约的过号时间
            String AMCloseTime = findHospitalSysDictValue(sys,"AMCloseTime");
            //下午号源开放的最早天数
            int PMCloseDays =Integer.parseInt(findHospitalSysDictValue(sys,"PMCloseDays"));
            //每一天下午的最早预约的过号时间
            String PMCloseTime = findHospitalSysDictValue(sys,"PMCloseTime");
            Iterator it = times.iterator();
            while (it.hasNext()){
                //设置上午过号时间
                Calendar scAMTime = Calendar.getInstance();
                scAMTime.setTime(new Date());
                scAMTime.add(Calendar.DAY_OF_MONTH,AMCloseDays);
                //设置下午午过号时间
                Calendar scPMTime = Calendar.getInstance();
                scPMTime.setTime(new Date());
                scPMTime.add(Calendar.DAY_OF_MONTH,PMCloseDays);
                WlyyDoctorWorkTimeDO time = (WlyyDoctorWorkTimeDO)it.next();
                Boolean filter = true;
                //1.【上午的排班中】 且 【排班结束时间】如果在【开放时间】前,则移除
                if(filter&&"1".equals(time.getTimeType())&&time.getEndTime().before(scAMTime.getTime())){
                    it.remove();
                    filter=false;
                }
        //2.根据时间间隔拆分号源
        while (sc.getTime().before(timeDO.getEndTime())){
                //2.【下午午的排班中】 且 【排班结束时间】如果在【开放时间】前,则移除该排班
                if(filter&&"2".equals(time.getTimeType())&&time.getEndTime().before(scPMTime.getTime())){
                    it.remove();
                    filter=false;
                }
            Map<String,Object> t = new HashedMap();
            t.put("startTime",DateUtil.dateToStr(sc.getTime(),"yyyy-MM-dd HH:mm:ss"));
            //加上时间间隔
            Date temp =new Date();
            temp.setTime(sc.getTime().getTime()+s);
            sc.setTime(temp);
            //如果结束时间大于排班时间则不再拆分号源
            if(sc.getTime().after(timeDO.getEndTime())){
                break;
            }
            t.put("endTime",DateUtil.dateToStr(sc.getTime(),"yyyy-MM-dd HH:mm:ss"));
                //3.如果【当前时间】过了【上午放号时间】,则移除所有上午的排班
                if(filter&&"1".equals(time.getTimeType())&&
                        DateUtil.strToDate(DateUtil.getTimeShort(),DateUtil.HH_MM_SS).after(DateUtil.strToDate(AMCloseTime,DateUtil.HH_MM))){
                    scAMTime.set(scAMTime.get(Calendar.YEAR),scAMTime.get(Calendar.MONTH),scAMTime.get(Calendar.DATE),12,00,00);
            //如果号源被预约了,标记为true
            Boolean registered = false;
            if(registerTimeDOs!=null&&registerTimeDOs.size()>0){
                for(WlyyPatientRegisterTimeDO registerTimeDO : registerTimeDOs){
                    if(t.get("startTime").equals(DateUtil.dateToStr(registerTimeDO.getStartTime(),"yyyy-MM-dd HH:mm:ss"))){
                        registered = true;
                    if(time.getEndTime().before(scAMTime.getTime())){
                        it.remove();
                        filter=false;
                    }
                }
            }
            t.put("registered",registered);
            rs.add(t);
        }
        return rs;
    }
    /**
     * 计算号源数目
     * @param id
     * @return
     */
    public Integer findWorkTimeInfoCout(String id){
        WlyyDoctorWorkTimeDO timeDO = doctorWorkTimeDao.findOne(id);
        Long ss = timeDO.getEndTime().getTime()-timeDO.getStartTime().getTime();
        Long s = ss/timeDO.getSourceNumber();
                //4.如果【当前时间】过了【下午午放号时间】,则移除所有下午的排班
                if(filter&&"2".equals(time.getTimeType())&&
                        DateUtil.strToDate(DateUtil.getTimeShort(),DateUtil.HH_MM_SS).after(DateUtil.strToDate(PMCloseTime,DateUtil.HH_MM))){
                    scPMTime.set(scAMTime.get(Calendar.YEAR),scAMTime.get(Calendar.MONTH),scAMTime.get(Calendar.DATE),12,00,00);
        Calendar sc = Calendar.getInstance();
        sc.setTime(timeDO.getStartTime());
        List<Map<String,Object>> rs = new ArrayList<>();
        //1.根据当前时间,去取已过时间的号源
        while (sc.getTime().before(timeDO.getEndTime())){
            if(new Date().before(sc.getTime())){
                break;
                    if(time.getEndTime().before(scPMTime.getTime())){
                        it.remove();
                    }
                }
            }
            //加上时间间隔
            Date temp =new Date();
            temp.setTime(sc.getTime().getTime()+s);
            sc.setTime(temp);
        }
        return times;
    }
        List<WlyyPatientRegisterTimeDO> registerTimeDOs = patientRegisterTimeDao.findByDoctorAndWorkId(timeDO.getDoctor(),id);
        //2.根据时间间隔拆分号源
        while (sc.getTime().before(timeDO.getEndTime())){
    public String findHospitalSysDictValue(List<WlyyHospitalSysDictDO> list,String dictCode){
            Map<String,Object> t = new HashedMap();
            t.put("startTime",DateUtil.dateToStr(sc.getTime(),"yyyy-MM-dd HH:mm:ss"));
            //加上时间间隔
            Date temp =new Date();
            temp.setTime(sc.getTime().getTime()+s);
            sc.setTime(temp);
            //如果结束时间大于排班时间则不再拆分号源
            if(sc.getTime().after(timeDO.getEndTime())){
                break;
            }
            t.put("endTime",DateUtil.dateToStr(sc.getTime(),"yyyy-MM-dd HH:mm:ss"));
            //如果号源被预约了,标记为true
            Boolean registered = false;
            if(registerTimeDOs!=null&&registerTimeDOs.size()>0){
                for(WlyyPatientRegisterTimeDO registerTimeDO : registerTimeDOs){
                    if(t.get("startTime").equals(DateUtil.dateToStr(registerTimeDO.getStartTime(),"yyyy-MM-dd HH:mm:ss"))){
                        registered = true;
                    }
        if(list!=null&&list.size()>0){
            for(WlyyHospitalSysDictDO sysDictDO : list){
                if(dictCode.equals(sysDictDO.getDictCode())){
                    return sysDictDO.getDictValue();
                }
            }
            if(!registered){
                rs.add(t);
            }
        }
        return rs.size();
        return "";
    }
    @Deprecated
    public List<Map<String,Object>> findWorkTimeInfoOld(String id){
    /**
     * 获取卡信息
     * @param cardNo
     * @param demoFlag
     * @return
     * @throws Exception
     */
    public net.sf.json.JSONObject getCardInfo(String cardNo, boolean demoFlag) throws Exception {
        return entranceService.qutpatientBalance(cardNo,demoFlag);
    }
    public List<Map<String,Object>> findWorkTimeInfo(String id){
        WlyyDoctorWorkTimeDO timeDO = doctorWorkTimeDao.findOne(id);
        Calendar sc = Calendar.getInstance();
        sc.setTime(timeDO.getStartTime());
@ -2671,17 +2491,11 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
               rs.put("winNo",org.getWinNo());
               rs.put("deptName",hospitalDOs.get(0).getDeptName());
               rs.put("dept",hospitalDOs.get(0).getDeptCode());
               if(StringUtils.isNotBlank(withWork)&&"1".equals(withWork)){
                  List<WlyyDoctorWorkTimeVO> times = findDoctorWorkTime(doctor,hospitalDOs.get(0).getOrgCode());
                  rs.put("workTime",times);
               }
            }else{
               rs.put("hospital",null);
               rs.put("winNo",null);
               rs.put("deptName",null);
               rs.put("dept",null);
                rs.put("workTime",null);
            }
@ -2709,18 +2523,21 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                rs.put("registerCount",0);
            }
            //医生问诊量
            List<WlyyOutpatientDO> wlyyOutpatientDOs = outpatientDao.findByDoctorAndStatus(doctor,"2");
            if(wlyyOutpatientDOs!=null&&wlyyOutpatientDOs.size()>0){
                rs.put("outpatientCount",wlyyOutpatientDOs.size());
            }else{
                rs.put("outpatientCount",0);
            }
//            List<WlyyOutpatientDO> wlyyOutpatientDOs = outpatientDao.findByDoctorAndStatus(doctor,"2");
//            if(wlyyOutpatientDOs!=null&&wlyyOutpatientDOs.size()>0){
//                rs.put("outpatientCount",wlyyOutpatientDOs.size());
//            }else{
//                rs.put("outpatientCount",0);
//            }
            //协同门诊量
            Integer coordinationCout = outpatientDao.countByDoctorAndStatusAndOutpatientType(doctor,"2","2");
            rs.put("coordinationCout",coordinationCout);
//            Integer coordinationCout = outpatientDao.countByDoctorAndStatusAndOutpatientType(doctor,"2","2");
//            rs.put("coordinationCout",coordinationCout);
//            if(StringUtils.isNotBlank(withWork)&&"1".equals(withWork)){
//                List<WlyyDoctorWorkTimeVO> times = findDoctorWorkTime(doctor);
//                rs.put("workTime",times);
//            }
    
            //专家咨询
            String zjCountsql = "SELECT id FROM wlyy_consult_team WHERE doctor='"+doctor+"' AND (type=1 OR type=15)";
@ -3529,7 +3346,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            List<Map<String,Object>> doctors = jdbcTemplate.queryForList(sql);
            List<WlyyDoctorWorkTimeDO> workTimeDOs =makeDoctorWorkTimeDOList(doctors,wlyyDoctorWorkTimeDOs);
            saveDoctorWorkTime(workTimeDOs,date,doctors);
        //科室
            //科室
        }else if("2".equals(type)){
            String sql ="SELECT " +
@ -3598,7 +3415,6 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                    t.setEndTime(time.getEndTime());
                    t.setDate(time.getDate());
                    t.setTimeInterval(time.getTimeInterval());
                    t.setSourceNumber(time.getSourceNumber());
                    rs.add(t);
                }
                logger.info(rs.size()+"");

+ 1 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/rehabilitation/RehabilitationManageService.java

@ -1077,6 +1077,7 @@ public class RehabilitationManageService {
        guidanceMessageLogDO.setAdminTeamName(adminTeamName);
        guidanceMessageLogDO.setDoctorName(doctorName);
        guidanceMessageLogDO.setCreateTime(new Date());
        guidanceMessageLogDO.setUpdateTime(new Date());
        guidanceMessageLogDao.save(guidanceMessageLogDO);
        return Envelop.getSuccess(SpecialistMapping.api_success);
    }