소스 검색

Merge branch 'dev' of chenweida/patient-co-management into dev

chenweida 7 년 전
부모
커밋
b1553d3aed

+ 1 - 7
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/AgeConvert.java

@ -28,15 +28,9 @@ public class AgeConvert implements Convert {
        List<DataModel> result = new ArrayList<>();
        for(DataModel one:oneList) {
            try {
                Object value = DataModel.class.getMethod("get" + temp.getKey()).invoke(one);
                Object value = one.getIdcard();
                Integer age= IdCardUtil.getAgeForIdcard(String.valueOf(value));
                String key = getAgeCode(age);
//                if("63".equals(temp.getQuotaCode())){
//
//                    if(tempMap.containsKey(String.valueOf(value))){
//                        continue;
//                    }
//                }
                tempMap.put(String.valueOf(value),one);
                DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(one, key);
//                result.add(one);

+ 0 - 111
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/DiseaseConvert.java

@ -1,111 +0,0 @@
package com.yihu.wlyy.statistics.etl.convert.wlyy;
import com.yihu.wlyy.entity.dimension.WlyyDimensionQuota;
import com.yihu.wlyy.statistics.etl.convert.Convert;
import com.yihu.wlyy.statistics.etl.convert.wlyy.model.HealthLable;
import com.yihu.wlyy.statistics.etl.convert.wlyy.model.PrescriptionDisease;
import com.yihu.wlyy.statistics.vo.DataModel;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 长处方疾病
 * Created by zhangdan on 2017/10/26.
 */
public class DiseaseConvert implements Convert {
    @Override
    public List<DataModel> convert(JdbcTemplate jdbcTemplate, List<DataModel> oneList, String slaveLevel, WlyyDimensionQuota temp) {
        List<DataModel> returnList = new ArrayList<>();
        //初始化标签Map
//        Map<String, Object> map = initHealthLabesMap(jdbcTemplate, temp);
        Map<String,Object> tempMap = new HashMap<>();
        //把标签Map设置到对应的维度里面
        List<String> keyList = null;
        for(DataModel one:oneList){
            try {
                if("63".equals(temp.getQuotaCode())){
                    DataModel dataModelTemp = new DataModel();
                    BeanUtils.copyProperties(one, dataModelTemp);
                    DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, one.getHealthProblem());
                    returnList.add(dataModelTemp);
                }else{
                    keyList = initHealthLabesMap(jdbcTemplate, temp, one);
                    for(String key:keyList){
                        DataModel dataModelTemp = new DataModel();
                        BeanUtils.copyProperties(one, dataModelTemp);
                        DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, key);
                        returnList.add(dataModelTemp);
                    }
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
//            List<String> healthProblems = prescriptionDiseaseMap.get(dataModel.getPrescriptionCode());
//            if (healthProblems != null && healthProblems.size() > 0) {
//                healthProblems.stream().forEach(str -> {
//                    try {
//                        DataModel dataModelTemp = new DataModel();
//                        BeanUtils.copyProperties(dataModel, dataModelTemp);
//                        DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, str);
//                        returnList.add(dataModelTemp);
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                });
//            }
        }
        return returnList;
    }
    private List<String> initHealthLabesMap(JdbcTemplate jdbcTemplate, WlyyDimensionQuota temp,DataModel dataModel) {
//        //得到长处方的疾病标签(只要高血压 糖尿病)
//        String sql = "SELECT " +
//                "  health_problem ," +
//                "  prescription_code " +
//                "FROM " +
//                "  wlyy_prescription_diagnosis " +
//                "WHERE " +
//                "  health_problem = 'HP0047' " +
//                "OR health_problem = 'HP0093' ";
//        List<PrescriptionDisease> prescriptionDiseases = jdbcTemplate.query(sql, new BeanPropertyRowMapper(PrescriptionDisease.class));
//        prescriptionDiseases.stream().forEach(one -> {
//            List<String> labels = prescriptionDiseaseMap.get(one.getPrescriptionCode());
//            if (labels == null) {
//                labels = new ArrayList<String>();
//            }
//            labels.add(one.getHealthProblem());
//            prescriptionDiseaseMap.put(one.getPrescriptionCode(), labels);
//        });
        List<String> key = new ArrayList<>();
        String sql = "SELECT " +
                "  health_problem AS healthProblem ," +
                "  prescription_code AS prescriptionCode " +
                "  FROM " +
                "  wlyy_prescription_diagnosis " +
                "  WHERE " +
                "  prescription_code = '"+dataModel.getPrescriptionCode() +"'";
        List<Map<String, Object>>  diagnosisList =jdbcTemplate.queryForList(sql);
//        List<Map<String, Object>> dictList = jdbcTemplate.queryForList(temp.getDictSql());
        for (Map<String, Object> map:diagnosisList){
//            String diagnosis = map.get("healthProblem")+"";
//            for(Map<String, Object> dict:dictList){
//                if(diagnosis.equals(dict.get("code"))){
//                    key.add()
//                }
//            }
            key.add(map.get("healthProblem").toString());
        }
        return key;
    }
}

+ 1 - 2
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionAgeConvert.java

@ -27,11 +27,10 @@ public class PrescriptionAgeConvert implements Convert {
        List<DataModel> result = new ArrayList<>();
        for(DataModel one:oneList) {
            try {
                Object value = DataModel.class.getMethod("get" + temp.getKey()).invoke(one);
                Object value = one.getIdcard();
                Integer age= IdCardUtil.getAgeForIdcard(String.valueOf(value));
                String key = getAgeCode(age);
                if("63".equals(temp.getQuotaCode())){
                    if(tempMap.containsKey(String.valueOf(value))){
                        continue;
                    }

+ 65 - 0
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionDiseaseConvert.java

@ -0,0 +1,65 @@
package com.yihu.wlyy.statistics.etl.convert.wlyy;
import com.yihu.wlyy.entity.dimension.WlyyDimensionQuota;
import com.yihu.wlyy.statistics.etl.convert.Convert;
import com.yihu.wlyy.statistics.etl.convert.wlyy.model.HealthLable;
import com.yihu.wlyy.statistics.etl.convert.wlyy.model.PrescriptionDisease;
import com.yihu.wlyy.statistics.vo.DataModel;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 长处方疾病
 * Created by zhangdan on 2017/10/26.
 */
public class PrescriptionDiseaseConvert implements Convert {
    @Override
    public List<DataModel> convert(JdbcTemplate jdbcTemplate, List<DataModel> oneList, String slaveLevel, WlyyDimensionQuota temp) {
        List<DataModel> returnList = new ArrayList<>();
        //初始化标签Map
        //把标签Map设置到对应的维度里面
        List<String> keyList = null;
        Map<String,List<String>>  returnMap=initHealthLabesMap(jdbcTemplate, temp);
        for (DataModel one : oneList) {
            try {
                keyList = returnMap.get(one.getPrescriptionCode());
                for (String key : keyList) {
                    DataModel dataModelTemp = new DataModel();
                    BeanUtils.copyProperties(one, dataModelTemp);
                    DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, key);
                    returnList.add(dataModelTemp);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }
    private  Map<String,List<String>> initHealthLabesMap(JdbcTemplate jdbcTemplate, WlyyDimensionQuota temp) {
//        //得到长处方的疾病标签(只要高血压 糖尿病)
       Map<String,List<String>>  returnMap = new HashMap<>();
        String sql = "SELECT " +
                "  health_problem AS healthProblem ," +
                "  prescription_code AS prescriptionCode " +
                "  FROM " +
                "  wlyy_prescription_diagnosis " ;
        List<Map<String, Object>> diagnosisList = jdbcTemplate.queryForList(sql);
        for (Map<String, Object> map : diagnosisList) {
            String key= (String) map.get("prescriptionCode");
            List<String> healthProblemList=returnMap.get(key);
            if(healthProblemList==null){
                healthProblemList=new ArrayList<>();
            }
            healthProblemList.add((String) map.get("healthProblem"));
            returnMap.put(key,healthProblemList);
        }
        return returnMap;
    }
}

+ 65 - 0
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionPatientDiseaseConvert.java

@ -0,0 +1,65 @@
package com.yihu.wlyy.statistics.etl.convert.wlyy;
import com.yihu.wlyy.entity.dimension.WlyyDimensionQuota;
import com.yihu.wlyy.statistics.etl.convert.Convert;
import com.yihu.wlyy.statistics.vo.DataModel;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 长处方疾病
 * Created by zhangdan on 2017/10/26.
 */
public class PrescriptionPatientDiseaseConvert implements Convert {
    @Override
    public List<DataModel> convert(JdbcTemplate jdbcTemplate, List<DataModel> oneList, String slaveLevel, WlyyDimensionQuota temp) {
        List<DataModel> returnList = new ArrayList<>();
        //初始化标签Map
        //把标签Map设置到对应的维度里面
        List<String> keyList = null;
        Map<String,List<String>>  returnMap=initHealthLabesMap(jdbcTemplate, temp);
        for (DataModel one : oneList) {
            try {
                keyList = returnMap.get(one.getPatient());
                for (String key : keyList) {
                    DataModel dataModelTemp = new DataModel();
                    BeanUtils.copyProperties(one, dataModelTemp);
                    DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(dataModelTemp, key);
                    returnList.add(dataModelTemp);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }
    private  Map<String,List<String>> initHealthLabesMap(JdbcTemplate jdbcTemplate, WlyyDimensionQuota temp) {
//        //得到长处方的疾病标签(只要高血压 糖尿病)
        Map<String,List<String>>  returnMap = new HashMap<>();
        String sql = "SELECT distinct " +
                "  d.health_problem AS healthProblem, " +
                "  p.patient AS patient " +
                "FROM " +
                "  wlyy_prescription p, " +
                "  wlyy_prescription_diagnosis d " +
                "WHERE " +
                "p.`code`=d.prescription_code" ;
        List<Map<String, Object>> diagnosisList = jdbcTemplate.queryForList(sql);
        for (Map<String, Object> map : diagnosisList) {
            String key= (String) map.get("patient");
            List<String> healthProblemList=returnMap.get(key);
            if(healthProblemList==null){
                healthProblemList=new ArrayList<>();
            }
            healthProblemList.add((String) map.get("healthProblem"));
            returnMap.put(key,healthProblemList);
        }
        return returnMap;
    }
}

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

@ -3286,6 +3286,20 @@ public class StatisticsESService {
            }
        }
        rs.add(map);
        Collections.sort(rs, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer map1value = Integer.valueOf(String.valueOf(o1.get("val")));
                Integer map2value = Integer.valueOf(String.valueOf(o2.get("val")));
                if (map1value - map2value > 0) {
                    return -1;
                } else if (map1value - map2value < 0) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });
        return rs;
    }
@ -3509,6 +3523,20 @@ public class StatisticsESService {
            rs.add(map);
        }
        Collections.sort(rs, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer map1value = Integer.valueOf(String.valueOf(o1.get("val")));
                Integer map2value = Integer.valueOf(String.valueOf(o2.get("val")));
                if (map1value - map2value > 0) {
                    return -1;
                } else if (map1value - map2value < 0) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });
        return rs;
    }
@ -3785,12 +3813,8 @@ public class StatisticsESService {
    public List<Map<String, Object>> getPrescriptionCostLowLevel(String level, String lowlevel, String area, String disease, String type) throws Exception {
        String index61 = "61";//统计长处方费用总数疾病维度
        String index66 = "66";//费用的指标code
        String index63 = "63";//统计长处方年龄疾病人数(按照患者去重)
        String index68 = "68";//统计长处方年龄人数(按照患者去重)
        String quotaDate = elasticsearchUtil.getQuotaTime();
        List<SaveModel> costList = null;
        Map<String, SaveModel> costMap = new HashedMap();
        List<SaveModel> numList = null;
        //获取费用
        if (org.springframework.util.StringUtils.isEmpty(disease)) {
            costList = elasticsearchUtil.findListDateQuotaLevel0(quotaDate, area, Integer.parseInt(level), index66, SaveModel.timeLevel_DDL, lowlevel);
@ -3818,52 +3842,49 @@ public class StatisticsESService {
        } else {
            //2.平均值
            //费用list转map
            for (SaveModel one : costList) {
                if (SaveModel.townLevel.equals(lowlevel)) {
                    costMap.put(one.getTown(), one);
                } else if (SaveModel.OrgLevel.equals(lowlevel)) {
                    costMap.put(one.getHospital(), one);
                } else if (SaveModel.teamLevel.equals(lowlevel)) {
                    costMap.put(one.getTeam(), one);
                }
            }
            //获取人数
            if (org.springframework.util.StringUtils.isEmpty(disease)) {
                numList = elasticsearchUtil.findListDateQuotaLevel1NoSlaveKey1(quotaDate, area, Integer.parseInt(level), index68, SaveModel.timeLevel_DDL, lowlevel);
            } else {
                numList = elasticsearchUtil.findListDateQuotaLevel2NoSlaveKey1(quotaDate, area, Integer.parseInt(level), index63, SaveModel.timeLevel_DDL, lowlevel, disease);
            }
            for (SaveModel one : numList) {
                String avg = "0.0";
                map = new HashMap<>();
                if (SaveModel.townLevel.equals(lowlevel)) {
                    map.put("code", one.getTown());
                    map.put("name", one.getTownName());
                    SaveModel costOne = costMap.get(one.getTown());
                    if (costOne != null) {
                        avg = decimalFormat.format(costOne.getResult1() / one.getResult1());
                    if (one != null&&one.getResult2()>0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
                    }
                    map.put("val", avg);
                } else if (SaveModel.OrgLevel.equals(lowlevel)) {
                    map.put("code", one.getHospital());
                    map.put("name", one.getHospitalName());
                    SaveModel costOne = costMap.get(one.getHospital());
                    if (costOne != null) {
                        avg = decimalFormat.format(costOne.getResult1() / one.getResult1());
                    if (one != null&&one.getResult2()>0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
                    }
                    map.put("val", avg);
                } else if (SaveModel.teamLevel.equals(lowlevel)) {
                    map.put("code", one.getTeam());
                    map.put("name", one.getTeamName());
                    SaveModel costOne = costMap.get(one.getTeam());
                    if (costOne != null) {
                        avg = decimalFormat.format(costOne.getResult1() / one.getResult1());
                    if (one != null&&one.getResult2()>0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
                    }
                    map.put("val", avg);
                }
                countList.add(map);
            }
        }
        Collections.sort(countList, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Double map1value = Double.valueOf(String.valueOf(o1.get("val")));
                Double map2value = Double.valueOf(String.valueOf(o2.get("val")));
                if (map1value - map2value > 0) {
                    return -1;
                } else if (map1value - map2value < 0) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });
        return countList;
    }
@ -3880,13 +3901,8 @@ public class StatisticsESService {
    public List<Map<String, Object>> getPrescriptionCostAvgLine(String level, String area, String disease, String startDate, String endDate, String type) throws Exception {
        String index61 = "61";//统计长处方费用总数疾病维度
        String index66 = "66";//费用的指标code
        String index63 = "63";//统计长处方年龄疾病人数(按照患者去重)
        String index68 = "68";//统计长处方年龄人数(按照患者去重)
        List<SaveModel> costList = null;
        Map<String, SaveModel> costMap = new HashedMap();
        List<SaveModel> numList = null;
        startDate = elasticsearchUtil.changeTime(startDate += " 00:00:00");
        endDate = elasticsearchUtil.changeTime(endDate += " 23:59:59");
@ -3896,27 +3912,9 @@ public class StatisticsESService {
        } else {
            costList = elasticsearchUtil.findLineChartDateQuotaLevel1(startDate, endDate, area, Integer.parseInt(level), index61, SaveModel.timeLevel_ZL, type, disease);
        }
        //获取人数
        if (org.springframework.util.StringUtils.isEmpty(disease)) {
            numList = elasticsearchUtil.findLineChartDateQuotaLevel1NoSlaveKey1(startDate, endDate, area, Integer.parseInt(level), index68, SaveModel.timeLevel_ZL, type);
        } else {
            numList = elasticsearchUtil.findLineChartDateQuotaLevel2NoSlaveKey1(startDate, endDate, area, Integer.parseInt(level), index63, SaveModel.timeLevel_ZL, type, disease);
        }
        //费用list转map
        for (SaveModel one : costList) {
            String key = null;
            if (SaveModel.interval_day.equals(type)) {
                key = dateFormat.format(one.getQuotaDate());
            } else if (SaveModel.interval_week.equals(type)) {
                key = dateFormat.format(one.getQuotaDate());
            } else {
                key = DateUtil.getMonth(dateFormat.format(one.getQuotaDate()));
            }
            costMap.put(key, one);
        }
        List<Map<String, Object>> countList = new ArrayList<>(); //map date avg
        for (SaveModel one : numList) {
        for (SaveModel one : costList) {
            Map<String, Object> map = new HashMap<>();
            //获取key
            String key = null;
@ -3927,10 +3925,9 @@ public class StatisticsESService {
            } else {
                key = DateUtil.getMonth(dateFormat.format(one.getQuotaDate()));
            }
            SaveModel costOne = costMap.get(key);
            String avg = "0.0";
            if (costOne != null) {
                avg = decimalFormat.format(one.getResult1() / costOne.getResult1());
            if (one.getResult2()!=0) {
                avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
            }
            map.put("val", avg);
            map.put("date", key);
@ -3942,33 +3939,23 @@ public class StatisticsESService {
    public Map<String, Object> getPrescriptionCost(String level, String area, String disease) throws Exception {
        SaveModel costSaveModel = null;
        SaveModel numSaveModel = null;
        String index61 = "61";//统计长处方费用总数疾病维度
        String index66 = "66";//费用的指标code
        String index63 = "63";//统计长处方年龄疾病人数(按照患者去重)
        String index68 = "68";//统计长处方年龄人数(按照患者去重)
        String quotaDate = elasticsearchUtil.getQuotaTime();
        if (StringUtils.isNotEmpty(disease)) {
            costSaveModel = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, Integer.parseInt(level), index61, "2", disease);
        } else {
            costSaveModel = elasticsearchUtil.findOneDateQuotaLevel0(quotaDate, area, Integer.parseInt(level), index66, "2");
        }
        //获取人数
        if (StringUtils.isNotEmpty(disease)) {
            numSaveModel = elasticsearchUtil.findOneDateQuotaLevel2NoSlaveKey1(quotaDate, area, Integer.parseInt(level), index63, "2", disease);
        } else {
            numSaveModel = elasticsearchUtil.findOneDateQuotaLevel1NoSlaveKey1(quotaDate, area, Integer.parseInt(level), index68, "2");
        }
        Long num = numSaveModel.getResult1().longValue();
        Map<String, Object> rs = new HashedMap();
        BigDecimal s = BigDecimal.valueOf(costSaveModel.getResult1());
        BigDecimal a = null;
        if (num == 0) {
        if (costSaveModel.getResult2() == 0.0D) {
            a = BigDecimal.valueOf(0.0);
        } else {
            a = BigDecimal.valueOf(costSaveModel.getResult1().longValue() / num);
            a = BigDecimal.valueOf(costSaveModel.getResult1().longValue() / costSaveModel.getResult2().longValue());
        }
        rs.put("sum", s.divide(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP));//费用总计  单位是分 所以除以100四舍五入
        rs.put("avg", a.divide((new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_UP));//人均费用  单位是分 所以除以100四舍五入