|
@ -1,19 +1,20 @@
|
|
package com.yihu.quota.service.medicalInsurance;
|
|
package com.yihu.quota.service.medicalInsurance;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.yihu.ehr.elasticsearch.ElasticSearchUtil;
|
|
import com.yihu.ehr.hbase.HBaseDao;
|
|
import com.yihu.ehr.hbase.HBaseDao;
|
|
import com.yihu.ehr.profile.core.ResourceCore;
|
|
import com.yihu.ehr.profile.core.ResourceCore;
|
|
import com.yihu.ehr.solr.SolrUtil;
|
|
import com.yihu.ehr.solr.SolrUtil;
|
|
import com.yihu.ehr.util.datetime.DateUtil;
|
|
import com.yihu.ehr.util.datetime.DateUtil;
|
|
import com.yihu.ehr.util.rest.Envelop;
|
|
import com.yihu.ehr.util.rest.Envelop;
|
|
import com.yihu.quota.controller.QuotaReportController;
|
|
import com.yihu.quota.controller.QuotaReportController;
|
|
import com.yihu.quota.service.quota.BaseStatistsService;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
import org.apache.solr.client.solrj.response.PivotField;
|
|
import org.apache.solr.client.solrj.response.PivotField;
|
|
import org.apache.solr.common.SolrDocument;
|
|
import org.apache.solr.common.SolrDocument;
|
|
import org.apache.solr.common.SolrDocumentList;
|
|
import org.apache.solr.common.SolrDocumentList;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@ -36,9 +37,9 @@ public class MedicalInsuranceService {
|
|
@Autowired
|
|
@Autowired
|
|
private QuotaReportController quotaReportController;
|
|
private QuotaReportController quotaReportController;
|
|
@Autowired
|
|
@Autowired
|
|
private BaseStatistsService baseStatistsService;
|
|
|
|
@Autowired
|
|
|
|
private HBaseDao hBaseDao;
|
|
private HBaseDao hBaseDao;
|
|
|
|
@Autowired
|
|
|
|
private ElasticSearchUtil elasticSearchUtil;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@ -160,14 +161,10 @@ public class MedicalInsuranceService {
|
|
*/
|
|
*/
|
|
public Envelop oftenIll(String time, int size, int page) throws Exception {
|
|
public Envelop oftenIll(String time, int size, int page) throws Exception {
|
|
Envelop envelop = new Envelop();
|
|
Envelop envelop = new Envelop();
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd'T'23:59:59'Z'");
|
|
SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd'T'23:59:59'Z'");
|
|
// idCardList用来存放最近7天就诊次数大于等于3的用户身份证号码
|
|
|
|
HashSet<String> idCardList = new HashSet<>();
|
|
|
|
|
|
|
|
// 时间
|
|
// 时间
|
|
Date dateTime = DateUtil.strToDate(time);
|
|
Date dateTime = DateUtil.strToDate(time);
|
|
Calendar calendar = new GregorianCalendar();
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
calendar.setTime(dateTime);
|
|
calendar.setTime(dateTime);
|
|
// 设置成本月第一天
|
|
// 设置成本月第一天
|
|
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
@ -175,74 +172,20 @@ public class MedicalInsuranceService {
|
|
// 设置成本月最后一天
|
|
// 设置成本月最后一天
|
|
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
String endDate = dfs.format(calendar.getTime());
|
|
String endDate = dfs.format(calendar.getTime());
|
|
|
|
|
|
String demographicId = "demographic_id";
|
|
|
|
String[] fields = {"rowkey","patient_name","patient_age","patient_sex","demographic_id","EHR_001211","event_date"};
|
|
|
|
|
|
|
|
// 设置成本月第一天
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
|
|
|
|
|
|
// 遍历一个月
|
|
|
|
while (belongCalendar(calendar, startDate, endDate)) {
|
|
|
|
Calendar innerCalendar = Calendar.getInstance();
|
|
|
|
innerCalendar.setTime(calendar.getTime());
|
|
|
|
// 获取该月份下每天前后3天的就诊记录, 共7天
|
|
|
|
innerCalendar.add(Calendar.DATE, -3);
|
|
|
|
String preDate = DateUtil.utcToDate(innerCalendar.getTime());
|
|
|
|
innerCalendar.add(Calendar.DATE, 6);
|
|
|
|
String sufDate = dfs.format(innerCalendar.getTime());
|
|
|
|
String fq = new StringBuffer().append("event_date:[").append(preDate).append(" TO ").append(sufDate).append("]").toString();
|
|
|
|
|
|
|
|
Map<String, Long> groupMap = solrUtil.groupCountLte(ResourceCore.MasterTable, null, fq, demographicId, 0, -1, 3);
|
|
|
|
for (String key : groupMap.keySet()) {
|
|
|
|
idCardList.add(key);
|
|
|
|
}
|
|
|
|
calendar.add(Calendar.DATE, 1);
|
|
|
|
|
|
String filters = "type=1";
|
|
|
|
if (!StringUtils.isEmpty(startDate)) {
|
|
|
|
filters = "eventDate>=" + startDate;
|
|
}
|
|
}
|
|
// 设置查询的时间段
|
|
|
|
calendar.add(Calendar.DATE, 2);
|
|
|
|
String end = dfs.format(calendar.getTime());
|
|
|
|
calendar.add(Calendar.DATE, -3);
|
|
|
|
// 设置成本月第一天
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
|
|
calendar.add(Calendar.DATE, -3);
|
|
|
|
String start = DateUtil.utcToDate(calendar.getTime());
|
|
|
|
String fqAll = new StringBuffer().append("event_date:[").append(start).append(" TO ").append(end).append("]").toString();
|
|
|
|
|
|
|
|
Map<String, Long> groupMap = solrUtil.groupCountLte(ResourceCore.MasterTable, null, fqAll, demographicId, 0, -1, 3);
|
|
|
|
for (String idCard : idCardList) {
|
|
|
|
Map<String, Object> mapInfo = new HashMap();
|
|
|
|
SolrDocumentList query = solrUtil.query(ResourceCore.MasterTable, "demographic_id:\"" + idCard + "\"", fqAll, null, 0, 1, fields);
|
|
|
|
if (null != query && query.size() > 0) {
|
|
|
|
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", idCard);
|
|
|
|
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", null != groupMap.get(idCard) ? groupMap.get(idCard) : 3);
|
|
|
|
mapInfo.put("address", null != query.get(0).get("EHR_001211") ? query.get(0).get("EHR_001211") : "");
|
|
|
|
list.add(mapInfo);
|
|
|
|
}
|
|
|
|
|
|
if (!StringUtils.isEmpty(endDate)) {
|
|
|
|
filters += ";eventDate<=" + endDate;
|
|
}
|
|
}
|
|
// 获取总记录数
|
|
|
|
int totalCount = list.size();
|
|
|
|
// 根据就诊次数排序
|
|
|
|
list = baseStatistsService.sortResultList(list, null);
|
|
|
|
|
|
|
|
list = list.subList((page - 1) * size, ((page - 1) * size + size) > list.size() ? list.size() : (page - 1) * size + size);
|
|
|
|
|
|
Page<Map<String, Object>> pages = elasticSearchUtil.pageBySort("medical_insurance_index", "medical_insurance", filters, "-result", page, size);
|
|
|
|
|
|
|
|
envelop.setDetailModelList(pages.getContent());
|
|
|
|
envelop.setTotalCount((int) pages.getTotalElements());
|
|
envelop.setCurrPage(page);
|
|
envelop.setCurrPage(page);
|
|
envelop.setPageSize(size);
|
|
envelop.setPageSize(size);
|
|
envelop.setTotalCount(totalCount);
|
|
|
|
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);
|
|
envelop.setSuccessFlg(true);
|
|
return envelop;
|
|
return envelop;
|
|
}
|
|
}
|