Parcourir la source

清洗数据;智能设备分析中绑定人的发放量

zd_123 il y a 7 ans
Parent
commit
12eea8f3c0

+ 8 - 7
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java

@ -5452,7 +5452,7 @@ public class StatisticsESService {
                bindingSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "hemopiezometer");
                allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d where device_name like '%血压%' " + areaCondition;
//                useCountSql = "SELECT COUNT(DISTINCT p.device_sn)  FROM device.wlyy_patient_health_index p LEFT JOIN device.wlyy_devices d on d.device_code=p.device_sn WHERE p.type IN (1, 2) and p.del=1 and p.type=1 and p.czrq>= '"+mondayTime+"' AND p.czrq < '"+currentTime+"' "+areaCondition ;
                useSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(mondayTime,DateUtil.getSundayOfThisDate(new Date()), area, level, index_96, SaveModel.timeLevel_ZL, "1");
                useSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(DateUtil.getSundayOfThisDate(new Date()), area, level, index_96, SaveModel.timeLevel_ZL, "1");
//                startUseSaveModel = elasticsearchUtil.findDateQuotaLevel1(mondayTime, mondayTime, area, level, index_87, SaveModel.timeLevel_DDL, "hemopiezometer", null, null);
//                endUseSaveModel = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_87, SaveModel.timeLevel_DDL, "hemopiezometer", null, null);
                anomalySaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_88, SaveModel.timeLevel_DDL, "hemopiezometer");
@ -5467,7 +5467,7 @@ public class StatisticsESService {
                bindingSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "glucometer");
                allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d where device_name like '%血糖%' " + areaCondition;
//                useCountSql = "SELECT COUNT(DISTINCT p.device_sn)  FROM device.wlyy_patient_health_index p LEFT JOIN device.wlyy_devices d on d.device_code=p.device_sn WHERE p.type IN (1, 2) and p.del=1 and p.type=2 and p.czrq>= '"+mondayTime+"' AND p.czrq < '"+currentTime+"' "+areaCondition ;
                useSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(mondayTime,DateUtil.getSundayOfThisDate(new Date()), area, level, index_96, SaveModel.timeLevel_ZL, "2");
                useSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(DateUtil.getSundayOfThisDate(new Date()), area, level, index_96, SaveModel.timeLevel_ZL, "2");
//                startUseSaveModel = elasticsearchUtil.findDateQuotaLevel1(mondayTime, mondayTime, area, level, index_87, SaveModel.timeLevel_DDL, "glucometer", null, null);
//                endUseSaveModel = elasticsearchUtil.findDateQuotaLevel1(timeKey, timeKey, area, level, index_87, SaveModel.timeLevel_DDL, "glucometer", null, null);
                anomalySaveModel = elasticsearchUtil.findOneDateQuotaLevel1(timeKey, area, level, index_88, SaveModel.timeLevel_DDL, "glucometer");
@ -5483,7 +5483,7 @@ public class StatisticsESService {
                anomalySaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey, area, level, index_88, SaveModel.timeLevel_DDL);
                allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d where 1=1 " + areaCondition;
//                useCountSql = "SELECT COUNT(DISTINCT p.device_sn)  FROM device.wlyy_patient_health_index p LEFT JOIN device.wlyy_devices d on d.device_code=p.device_sn WHERE p.type IN (1, 2) and p.del=1  and p.czrq>= '"+mondayTime+"' AND p.czrq < '"+currentTime+"' "+areaCondition ;
                useSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(mondayTime,DateUtil.getSundayOfThisDate(new Date()), area, level, index_96, SaveModel.timeLevel_ZL);
                useSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(DateUtil.getSundayOfThisDate(new Date()), area, level, index_96, SaveModel.timeLevel_ZL);
                anomalyCountSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(timeKey, area, level, index_97, SaveModel.timeLevel_DDL);
//                anomalyCountSql = " SELECT COUNT(i.id) FROM device.wlyy_patient_health_index i left join device.wlyy_devices d on i.device_sn=d.device_code where  i.status=1 and i.del=1 " + areaCondition;
//                startUseSaveModel = elasticsearchUtil.findDateQuotaLevel0(mondayTime, mondayTime, area, level, index_87, SaveModel.timeLevel_DDL, null, null);
@ -5634,7 +5634,7 @@ public class StatisticsESService {
                        obj.put("code", one.get("doctorCode"));
                        obj.put("name", one.get("doctorName"));
                        obj.put("amount", one.get("amount"));
                        obj = deviceRateList(obj,hos);
                        obj = deviceRateList(obj,hos,String.valueOf(obj.get("doctorCode")));
                        if("other".equals(one.get("doctorCode")+"")){
                            amount += Integer.valueOf(obj.get("amount")+"");
                            allNum += Integer.valueOf(obj.get("allNum")+"");
@ -5766,13 +5766,14 @@ public class StatisticsESService {
    }
    //按绑定的医生列表展示绑定的设备列表
    public Map<String, Object> deviceRateList(Map<String, Object> reMap,Hospital hos){
    public Map<String, Object> deviceRateList(Map<String, Object> reMap,Hospital hos,String doctor){
//        String sql = " select count(1) as amount from wlyy.wlyy_patient_device p JOIN wlyy.wlyy_doctor r on p.doctor is not null and  p.doctor =r.code  LEFT JOIN device.wlyy_devices d on p.device_sn=d.device_code where  p.doctor is not null and d.grant_org_code ='" + hos.getCode() + "' and p.doctor='"+reMap.get("code")+"'";
        String temp = "other".equals(reMap.get("code"))? " and p.doctor is null ":" and p.doctor='"+reMap.get("code")+"' ";
        String sql = " select count(1) as amount " +
       /* String sql = " select count(1) as amount " +
                " from (select  DISTINCT p.doctor,r.name,p.device_sn FROM wlyy.wlyy_patient_device p left join device.wlyy_devices d on p.device_sn=d.device_code left JOIN wlyy.wlyy_doctor r ON  p.doctor = r. CODE " +
                " where d.is_binding in (1,2) and p.category_code in('1','2') and d.grant_org_code ='" + hos.getCode() + "' "+temp+") a " +
                " GROUP BY a.doctor,a.name";
                " GROUP BY a.doctor,a.name";*/
       String sql ="SELECT count(1) as amount from device.wlyy_devices wd LEFT JOIN dm_device dd ON wd.device_model=dd.model where grant_doctor ='"+doctor+"' AND dd.category_code IN('1','2')";
//        Map<String, Object> map = jdbcTemplate.queryForMap(sql);
        List<Map<String,Object>> result = jdbcTemplate.queryForList(sql);
        Map<String,Object> map = result.get(0);

+ 77 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandingService.java

@ -676,6 +676,7 @@ public class DataHandingService {
    @Transactional(rollbackFor = Exception.class)
    public void updateDeviceGrantDoctor()throws Exception{
        //取出所有符合逻辑的已发放的设备
        String sql ="SELECT" +
                " wd.device_code,s.* FROM device.wlyy_devices wd" +
                " LEFT JOIN (" +
@ -683,15 +684,61 @@ public class DataHandingService {
                " LEFT JOIN wlyy.wlyy_doctor d ON wat.leader_code = d.`code`" +
                " WHERE available = 1" +
                ") s ON wd.grant_admin_team = s.id" +
                " WHERE  wd.is_grant = 1 AND wd.grant_admin_team IN(SELECT id from wlyy.wlyy_admin_team where available=1)";
                " WHERE  wd.is_grant = 1 AND (wd.grant_doctor IS NULL OR wd.grant_doctor ='') AND wd.grant_admin_team IN(SELECT id from wlyy.wlyy_admin_team where available=1)";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        //wlyy_patient_device取出对应的device_sn和doctor
        String patientDeviceSql ="SELECT device_sn,doctor,doctor_name FROM `wlyy_patient_device`  WHERE doctor IS NOT NULL and  doctor = '' and category_code IN('1','2') GROUP BY device_sn";
        List<Map<String,Object>> patientDeviceList = jdbcTemplate.queryForList(patientDeviceSql);
        String patientDeviceLogSql ="SELECT s.* FROM" +
                "(SELECT device_sn, operator doctor, operator_name doctor_name FROM" +
                " wlyy_patient_device_log WHERE device_sn NOT IN (SELECT device_sn FROM wlyy_patient_device WHERE" +
                " category_code IN ('1', '2') AND doctor IS NOT NULL GROUP BY device_sn )" +
                " AND category_code IN ('1', '2')" +
                " AND operate_code = 1" +
                " AND is_del = 1" +
                " AND role = 1" +
                " ORDER BY" +
                " create_time" +
                " ) s" +
                " GROUP BY" +
                " s.device_sn";
        //List<Map<String,Object>> patientDeviceLogList = jdbcTemplate.queryForList(patientDeviceLogSql);
        patientDeviceList.addAll(jdbcTemplate.queryForList(patientDeviceLogSql));
        List<String> sqlList = new ArrayList<>();
        //设备列表和绑定关系列表比对,存入绑定医生的doctor,没有的存团队长
        for (Map<String,Object> map : list){
            String updateSql ="update device.wlyy_devices set grant_doctor='"+String.valueOf(map.get("code"))+"'," +
                    " grant_doctor_name='"+String.valueOf(map.get("name"))+"'"+
                    " where device_code='"+String.valueOf(map.get("device_code"))+"'";
            int count =0;
            String doctor = "";
            String doctorName="";
            String deviceCode = String.valueOf(map.get("device_code"));
            for (Map<String,Object> patientDeviceMap : patientDeviceList){
                if (deviceCode.equals(String.valueOf(patientDeviceMap.get("device_sn")))){
                    count++;
                    doctor=String.valueOf(patientDeviceMap.get("doctor"));
                    doctorName=String.valueOf(patientDeviceMap.get("doctor_name"));
                }
            }
            if (count==0){
                doctor = String.valueOf(map.get("code"));
                doctorName=String.valueOf(map.get("name"));
            }
            if (StringUtils.isEmpty(doctorName) || "null".equals(doctorName)){
                Doctor doctorDo = doctorDao.findByCode(doctor);
                if (doctorDo!=null){
                    doctorName = doctorDo.getName();
                }
            }
            String updateSql ="update device.wlyy_devices set grant_doctor='"+doctor+"'," +
                    " grant_doctor_name='"+doctorName+"'"+
                    " where device_code='"+deviceCode+"'";
            sqlList.add(updateSql);
        }
        String[] sqlStr = new String[sqlList.size()];
        sqlStr = sqlList.toArray(sqlStr);
        jdbcTemplate.batchUpdate(sqlStr);
@ -750,4 +797,30 @@ public class DataHandingService {
        }
        return result;
    }
    @Transactional(rollbackFor = Exception.class)
    public void addPatientDeviceDoctor()throws Exception{
        String patientDeviceSql="SELECT * FROM wlyy_patient_device WHERE doctor IS NULL OR doctor = ''";
        List<PatientDevice> patientDeviceList = jdbcTemplate.query(patientDeviceSql,new BeanPropertyRowMapper<>(PatientDevice.class));
        List<String> sqlList = new ArrayList<>();
        for (PatientDevice patientDevice : patientDeviceList){
            SignFamily signFamily = signFamilyDao.findByPatient(patientDevice.getUser());
            if (signFamily==null && signFamilyDao.findLastJySignByPatient(patientDevice.getUser(),2)!=null && signFamilyDao.findLastJySignByPatient(patientDevice.getUser(),2).size()>0){
                signFamily = signFamilyDao.findLastJySignByPatient(patientDevice.getUser(),2).get(0);
            }
            if (signFamily!=null){
                String doctorSql ="SELECT d.`code`,d.`name` FROM wlyy_admin_team wat LEFT JOIN wlyy_doctor d ON wat.leader_code = d.`code` WHERE wat.id='"+signFamily.getAdminTeamId()+"'";
                List<Map<String,Object>> doctorList = jdbcTemplate.queryForList(doctorSql);
                if (doctorList!=null && doctorList.size()>0){
                    String updateSql ="update wlyy_patient_device set doctor='"+String.valueOf(doctorList.get(0).get("code"))
                            +"',doctor_name='"+String.valueOf(doctorList.get(0).get("name"))+"' where id="+patientDevice.getId();
                    sqlList.add(updateSql);
                }
            }
        }
        String[] sqlStr = new String[sqlList.size()];
        sqlStr = sqlList.toArray(sqlStr);
        jdbcTemplate.batchUpdate(sqlStr);
    }
}

+ 13 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/data/DataHandlingController.java

@ -390,4 +390,17 @@ public class DataHandlingController extends BaseController {
        }
    }
    @RequestMapping(value = "/addPatientDeviceDoctor",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("更新居民设备关系表中绑定医生字段")
    public String addPatientDeviceDoctor(){
        try{
            dataHandingService.addPatientDeviceDoctor();
            return write(200,"清洗数据成功");
        }catch (Exception e){
            System.out.println(e.getMessage());
            e.printStackTrace();
            return write(-1,"清洗数据失败!");
        }
    }
}