Browse Source

频繁就医接口

wangxingwang 6 years ago
parent
commit
d6e297adc7

+ 3 - 1
src/main/java/com/yihu/quota/controller/MedicalInsuranceController.java

@ -28,11 +28,13 @@ public class MedicalInsuranceController extends BaseController {
    @RequestMapping(value = ServiceApi.TJ.GetOftenIllList, method = RequestMethod.GET)
    @ApiOperation(value = "频繁就医")
    public Envelop oftenIll(
            @ApiParam(name = "time", value = "过滤时间",required = true)
            @RequestParam(value = "time") String time,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page) throws Exception{
        Envelop envelop = new Envelop();
        Envelop envelop = medicalInsuranceService.oftenIll(time, size, page);
        return envelop;
    }

+ 108 - 5
src/main/java/com/yihu/quota/service/medicalInsurance/MedicalInsuranceService.java

@ -1,23 +1,22 @@
package com.yihu.quota.service.medicalInsurance;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.hbase.HBaseDao;
import com.yihu.ehr.profile.core.ResourceCore;
import com.yihu.ehr.solr.SolrUtil;
import com.yihu.ehr.util.datetime.DateUtil;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.quota.controller.QuotaReportController;
import io.swagger.annotations.ApiParam;
import com.yihu.quota.service.quota.BaseStatistsService;
import org.apache.commons.lang.StringUtils;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * @Author: zhengwei
@ -34,6 +33,11 @@ public class MedicalInsuranceService {
    private ObjectMapper objectMapper;
    @Autowired
    private QuotaReportController quotaReportController;
    @Autowired
    private BaseStatistsService baseStatistsService;
    @Autowired
    private HBaseDao hBaseDao;
    /**
     * 超高费用
     * @param month
@ -120,6 +124,74 @@ public class MedicalInsuranceService {
        return result;
    }
    /**
     * 频繁就医
     * @param time
     * @param size
     * @param page
     * @return
     * @throws Exception
     */
    public Envelop oftenIll(String time, int size, int page) throws Exception {
        Envelop envelop = new Envelop();
        List<Map<String, Object>> list = new ArrayList<>();
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd'T'23:59:59'Z'");
        // 时间
        Date dateTime = DateUtil.strToDate(time);
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(dateTime);
        String endDate = DateUtil.utcToDate(calendar.getTime());
        calendar.add(Calendar.DATE, -6);
        String startDate = dfs.format(calendar.getTime());
        String fq = new StringBuffer().append("event_date:[").append(startDate).append(" TO ").append(endDate).append("]").toString();
        String demographicId = "demographic_id";
        String[] fields = {"rowkey","patient_name","patient_age","patient_sex","demographic_id","EHR_001211","event_date"};
        Map<String, Long> groupMap = solrUtil.groupCountLte(ResourceCore.MasterTable, null, fq, demographicId, 0, -1);
        for (String key : groupMap.keySet()) {
            Map<String, Object> mapInfo = new HashMap();
            SolrDocumentList query = solrUtil.query(ResourceCore.MasterTable, "demographic_id:" + key, fq, null, 0, 1, fields);
            String rowKey = null != query.get(0).get("rowkey") ? query.get(0).get("rowkey") + "" : "";
            String sex = null != query.get(0).get("patient_sex") ? query.get(0).get("patient_sex") + "" : "";
            mapInfo.put("rowkey", rowKey);
            mapInfo.put("demographic_id", key);
            mapInfo.put("patient_name", null != query.get(0).get("patient_name") ? query.get(0).get("patient_name") : "");
            mapInfo.put("patient_age", null != query.get(0).get("patient_age") ? query.get(0).get("patient_age") : "");
            mapInfo.put("patient_sex", sexExchangeByCode(sex));
            mapInfo.put("result", groupMap.get(key));
            mapInfo.put("address", null != query.get(0).get("EHR_001211") ? query.get(0).get("EHR_001211") : "");
            list.add(mapInfo);
        }
        // 根据就诊次数排序
        list = baseStatistsService.sortResultList(list, null);
        list = list.subList((page - 1) * size, ((page - 1) * size + size) > list.size() ? list.size() : (page - 1) * size + size);
        // 判断solr中获取的家庭地址是否有值,没有的话到hbase中查询
        list.forEach(one -> {
            Object address = one.get("EHR_001211");
            if (null == address) {
                Map<String, Object> resultMap = hBaseDao.getResultMap(ResourceCore.MasterTable, one.get("rowkey") + "");
                one.put("address", null != resultMap.get("EHR_001211") ? resultMap.get("EHR_001211") + "" : "");
            }
        });
        envelop.setCurrPage(page);
        envelop.setPageSize(size);
        envelop.setTotalCount(groupMap.size());
        envelop.setDetailModelList(list);
        // 设置总页码数
        if (envelop.getTotalCount() % envelop.getPageSize() > 0) {
            envelop.setTotalPage(envelop.getTotalCount() / envelop.getPageSize() + 1);
        } else {
            envelop.setTotalPage(envelop.getTotalCount() / envelop.getPageSize());
        }
        envelop.setSuccessFlg(true);
        return envelop;
    }
    private String getOrgCode(String hosLevel, String hosHierarchy){
        String orgCode="";
        StringBuffer sql = new StringBuffer();
@ -140,4 +212,35 @@ public class MedicalInsuranceService {
        return orgCode;
    }
    /**
     * 性别字典转换
     * @param code
     * @return
     */
    private String sexExchangeByCode(String code) {
        String sex = "";
        switch (code) {
            case "0" : {
                sex = "未知的性别";
                break;
            }
            case "1" : {
                sex = "男性";
                break;
            }
            case "2" : {
                sex = "女性";
                break;
            }
            case "9" : {
                sex = "未说明的性别";
                break;
            }
            default : {
                break;
            }
        }
        return sex;
    }
}