|
@ -46,7 +46,9 @@ import java.time.ZonedDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.TextStyle;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
* Created by wangzhinan on 2019/12/3.
|
|
@ -6172,9 +6174,9 @@ public class StatisticsEsService {
|
|
|
//开方 【处方量】
|
|
|
int kf_total = countListTotal(cf_model01);
|
|
|
int kf_period = countListTotal(cf_model02);
|
|
|
;//上个周期
|
|
|
//上个周期
|
|
|
int kf_periodYear = countListTotal(cf_model03);
|
|
|
;//去年同周期
|
|
|
//去年同周期
|
|
|
result.put("kf_total", kf_total);//开方量
|
|
|
result.put("kf_kfl", getRange(kf_total, patientVolume, 0));//【处方率】= 处方量 ÷ 接诊量 ×100%
|
|
|
result.put("kf_hb", getRange((kf_total - kf_period), kf_period, 0));//环比
|
|
@ -6980,10 +6982,10 @@ public class StatisticsEsService {
|
|
|
JSONObject result = new JSONObject();
|
|
|
String sql = " SELECT dict_code \"functionCode\",dict_value \"functionName\",img_url \"img\" FROM wlyy_hospital_sys_dict WHERE dict_name='FUNCTION_SETTING' ORDER BY sort ";
|
|
|
List<Map<String, Object>> functionList = jdbcTemplate.queryForList(sql);
|
|
|
List<String[]> list = new ArrayList<>();
|
|
|
List<String[]> list = new ArrayList<>();
|
|
|
for (Map<String, Object> map : functionList) {
|
|
|
String[] strings = {String.valueOf(map.get("functionCode")), String.valueOf(map.get("functionName")), String.valueOf(map.get("img"))};
|
|
|
list.add(strings);
|
|
|
String[] strings = {String.valueOf(map.get("functionCode")), String.valueOf(map.get("functionName")), String.valueOf(map.get("img"))};
|
|
|
list.add(strings);
|
|
|
}
|
|
|
result.put("list", list);
|
|
|
return result;
|
|
@ -6994,12 +6996,12 @@ public class StatisticsEsService {
|
|
|
String functionSql = " SELECT dict_code \"functionCode\",dict_value \"functionName\",py_code \"img\" FROM wlyy_hospital_sys_dict WHERE dict_name='FUNCTION_SETTING' ORDER BY sort ";
|
|
|
List<Map<String, Object>> functionList = jdbcTemplate.queryForList(functionSql);
|
|
|
//医生信息
|
|
|
String sql = " SELECT function_setting \"functionCode\" FROM base.base_doctor WHERE id='"+doctorCode+"'";
|
|
|
String sql = " SELECT function_setting \"functionCode\" FROM base.base_doctor WHERE id='" + doctorCode + "'";
|
|
|
List<Map<String, Object>> doctorList = jdbcTemplate.queryForList(sql);
|
|
|
if (doctorList.isEmpty()){
|
|
|
if (doctorList.isEmpty()) {
|
|
|
return null;
|
|
|
}else {
|
|
|
String functionCodeList =(String) doctorList.get(0).get("functionCode");
|
|
|
} else {
|
|
|
String functionCodeList = (String) doctorList.get(0).get("functionCode");
|
|
|
// List<String> list = Arrays.asList(functionCodeList.split(","));
|
|
|
// List<Map<String, Object>> collect = functionList.stream()
|
|
|
// .filter(map -> map.keySet().containsAll(list))
|
|
@ -7007,21 +7009,21 @@ public class StatisticsEsService {
|
|
|
List<String[]> list = new ArrayList<>();
|
|
|
for (String code : functionCodeList.split(",")) {
|
|
|
for (Map<String, Object> map : functionList) {
|
|
|
if (code.equals(map.get("functionCode"))){
|
|
|
if (code.equals(map.get("functionCode"))) {
|
|
|
String[] strings = {String.valueOf(map.get("functionCode")), String.valueOf(map.get("functionName")), String.valueOf(map.get("img"))};
|
|
|
list.add(strings);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("list",list);
|
|
|
result.put("list", list);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public int updateDoctorSetting(String doctorCode,String functionCodeList) {
|
|
|
String sql=" UPDATE base.base_doctor SET function_setting='"+functionCodeList+"' WHERE id='"+doctorCode+"'" ;
|
|
|
public int updateDoctorSetting(String doctorCode, String functionCodeList) {
|
|
|
String sql = " UPDATE base.base_doctor SET function_setting='" + functionCodeList + "' WHERE id='" + doctorCode + "'";
|
|
|
int update = jdbcTemplate.update(sql);
|
|
|
|
|
|
return update;
|
|
@ -7043,4 +7045,310 @@ public class StatisticsEsService {
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public static ExecutorService execute = Executors.newFixedThreadPool(20);
|
|
|
|
|
|
/**
|
|
|
* 总人数:200人
|
|
|
* <p>
|
|
|
* 总次数:500次
|
|
|
* 今日新增 +10
|
|
|
* 本月新增 +10
|
|
|
*/
|
|
|
public HashMap<String, Object> getConsultationCount(ScreenQvo qvo) throws Exception {
|
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
|
//获取第一天、最后一天
|
|
|
String[] dateList = getFirstAndEndDay(qvo.getEndDate());
|
|
|
//今日新增量
|
|
|
String todaySql = "SELECT count(*) as count from wlyy_consult_outpatient_info o where 1=1 AND o.create_time >='" + qvo.getEndDate() + "' and o.create_time <='" + qvo.getEndDate() + " 23:59:59' ";
|
|
|
//查询本月量
|
|
|
String monthSql = "SELECT count(*) as count from wlyy_consult_outpatient_info o where 1=1 AND o.create_time >='" + dateList[0] + "' and o.create_time <='" + dateList[1] + " 23:59:59' ";
|
|
|
//查询人数
|
|
|
String patientCountSql = "SELECT count(DISTINCT p.patient) 'count' FROM wlyy_outpatient p WHERE `p`.`pay_status` in (1,2) AND p.`create_time`>='" + qvo.getStartDate() + "' AND p.`create_time`<='" + qvo.getEndDate() + " 23:59:59' ";
|
|
|
|
|
|
CompletableFuture<Void> future01 = CompletableFuture.runAsync(() -> {
|
|
|
try {
|
|
|
//全部问诊量
|
|
|
SaveModel saveModel = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), qvo.getIndex(), SaveModel.timeLevel_DDL);
|
|
|
if (saveModel != null) {
|
|
|
map.put("allConsultCount", saveModel.getResult2().longValue());
|
|
|
} else {
|
|
|
map.put("allConsultCount", 0);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}, execute);
|
|
|
CompletableFuture<Void> future02 = CompletableFuture.runAsync(() -> {
|
|
|
//今日问诊量
|
|
|
Integer count = jdbcTemplate.queryForObject(todaySql, Integer.class);
|
|
|
map.put("todayConsultCount", count);
|
|
|
}, execute);
|
|
|
CompletableFuture<Void> future03 = CompletableFuture.runAsync(() -> {
|
|
|
//本月
|
|
|
Integer count = jdbcTemplate.queryForObject(monthSql, Integer.class);
|
|
|
map.put("monthConsultCount", count);
|
|
|
}, execute);
|
|
|
CompletableFuture<Void> future04 = CompletableFuture.runAsync(() -> {
|
|
|
//问诊人数
|
|
|
Integer count = jdbcTemplate.queryForObject(patientCountSql, Integer.class);
|
|
|
map.put("consultPaitentCount", count);
|
|
|
}, execute);
|
|
|
System.out.println("111");
|
|
|
CompletableFuture<Void> allOf = CompletableFuture.allOf(future01, future02, future03, future04);
|
|
|
allOf.get();
|
|
|
System.out.println("222");
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取男女就诊次数
|
|
|
* 1男2女3其他
|
|
|
*/
|
|
|
public HashMap<String, Object> getConsultGroupBySex(ScreenQvo qvo) {
|
|
|
HashMap<String, Object> resultMap = new HashMap<>();
|
|
|
String sql = "SELECT b.sex,count(a.id) 'count' \n" +
|
|
|
" FROM wlyy_outpatient a INNER JOIN base_patient b ON a.patient=b.id \n" +
|
|
|
" WHERE 1=1 " +
|
|
|
" AND a.`pay_status` in (1,2) " +
|
|
|
" AND a.`create_time`>='" + qvo.getStartDate() + "' AND a.`create_time`<='" + qvo.getEndDate() + "' \n" +
|
|
|
" GROUP BY b.sex";
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
int otherCount = 0;
|
|
|
for (Map<String, Object> map : list) {
|
|
|
if (!Objects.isNull(map.get("sex")) && "1".equals(map.get("sex").toString())) {
|
|
|
resultMap.put("1", map.get("count"));
|
|
|
} else if (!Objects.isNull(map.get("sex")) && "2".equals(map.get("sex").toString())) {
|
|
|
resultMap.put("2", map.get("count"));
|
|
|
} else {
|
|
|
otherCount += Integer.parseInt(map.get("count").toString());
|
|
|
}
|
|
|
}
|
|
|
resultMap.put("3", otherCount);
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取第一天和最后一天
|
|
|
*/
|
|
|
public String[] getFirstAndEndDay(String dateStr) throws ParseException {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date date = sdf.parse(dateStr);
|
|
|
// 获取 Calendar 实例并设置到指定的 Date
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.setTime(date);
|
|
|
// 设置 Calendar 到月初
|
|
|
cal.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
String startOfMonth = sdf.format(cal.getTime());
|
|
|
System.out.println("本月第一天: " + startOfMonth);
|
|
|
// 获取本月最大天数并设置到 Calendar
|
|
|
int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
|
|
cal.set(Calendar.DAY_OF_MONTH, maxDay);
|
|
|
String endOfMonth = sdf.format(cal.getTime());
|
|
|
System.out.println("本月最后一天: " + endOfMonth);
|
|
|
// 返回包含本月第一天和最后一天的字符串数组
|
|
|
String[] dates = {startOfMonth, endOfMonth};
|
|
|
return dates;
|
|
|
}
|
|
|
|
|
|
|
|
|
public HashMap<String, Object> getConsultGroupByAge(ScreenQvo qvo) {
|
|
|
String sql = "SELECT\n" +
|
|
|
" q.*,\n" +
|
|
|
" (\n" +
|
|
|
" SELECT\n" +
|
|
|
" count(1)\n" +
|
|
|
" FROM\n" +
|
|
|
" base_patient a\n" +
|
|
|
" INNER JOIN wlyy_outpatient b ON a.id = b.patient\n" +
|
|
|
" WHERE 1=1 AND a.birthday IS NOT NULL\n" +
|
|
|
" AND TIMESTAMPDIFF(YEAR, a.birthday, b.create_time) >=q.start_age\n" +
|
|
|
" AND TIMESTAMPDIFF(YEAR, a.birthday, b.create_time) <=q.end_age\n" +
|
|
|
" AND b.`pay_status` in (1,2)\n" +
|
|
|
" AND b.`create_time`>='" + qvo.getStartDate() + "' AND b.create_time<='" + qvo.getEndDate() + " 23:59:59'\n" +
|
|
|
" )'count'\n" +
|
|
|
"FROM\n" +
|
|
|
" age_table q ORDER BY q.sort ";
|
|
|
HashMap<String, Object> resultMap = new HashMap<>();
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
int allCount = 0;
|
|
|
for (Map<String, Object> map : list) {
|
|
|
allCount += Integer.parseInt(map.get("count").toString());
|
|
|
}
|
|
|
resultMap.put("ageList", list);
|
|
|
resultMap.put("allCount", allCount);
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 接诊量 job=12,14,16
|
|
|
* 处方量 job=2
|
|
|
* 【接诊率】= 接诊量 ÷ 问诊量 ×100%
|
|
|
* 服务评价
|
|
|
*/
|
|
|
public HashMap<String, Object> getConsultDetailCount(ScreenQvo qvo) throws Exception {
|
|
|
HashMap<String, Object> resultMap = new HashMap<>();
|
|
|
// 服务评分
|
|
|
String scoreSql = "SELECT ROUND(AVG(score),2) 'score' FROM base_evaluate_score ";
|
|
|
|
|
|
|
|
|
CompletableFuture<Void> future01 = CompletableFuture.runAsync(() -> {
|
|
|
//开方量
|
|
|
try {
|
|
|
SaveModel model = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "2", SaveModel.timeLevel_DDL);
|
|
|
if (model != null) {
|
|
|
resultMap.put("kfl", model.getResult2().longValue());//赋值开发量
|
|
|
} else {
|
|
|
resultMap.put("kfl", 0);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}, execute);
|
|
|
|
|
|
|
|
|
CompletableFuture<List<SaveModel>> future02 = CompletableFuture.supplyAsync(() -> {
|
|
|
//接诊量
|
|
|
List<SaveModel> model = null;
|
|
|
try {
|
|
|
model = elasticsearchUtil.findListDateQuotaLevel2(qvo.getStartDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "12,14,16", SaveModel.timeLevel_ZL, null, "9,16,12,1,17", "1");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return model;
|
|
|
}, execute);
|
|
|
|
|
|
|
|
|
CompletableFuture<SaveModel> future03 = CompletableFuture.supplyAsync(() -> {
|
|
|
SaveModel model = null;
|
|
|
try {
|
|
|
//接诊量
|
|
|
model = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "5", SaveModel.timeLevel_DDL);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return model;
|
|
|
}, execute);
|
|
|
|
|
|
CompletableFuture<Void> future04 = CompletableFuture.runAsync(() -> {
|
|
|
String score = jdbcTemplate.queryForObject(scoreSql, String.class);
|
|
|
resultMap.put("score", score);//赋值评分
|
|
|
}, execute);
|
|
|
CompletableFuture.allOf(future01, future02, future03, future04).get();
|
|
|
List<SaveModel> jzModelList = future02.get();
|
|
|
SaveModel model = future03.get();
|
|
|
|
|
|
int patientVolume = countListTotal(jzModelList);
|
|
|
int allConsultCount = 0;
|
|
|
if (model != null) {
|
|
|
allConsultCount = model.getResult2().intValue();
|
|
|
}
|
|
|
|
|
|
resultMap.put("jzCount", patientVolume);//赋值接诊量
|
|
|
resultMap.put("wzAllCount", allConsultCount);//赋值问诊量
|
|
|
//接诊率= 接诊量 ÷ 问诊量 ×100%
|
|
|
resultMap.put("jzl", getRange(patientVolume, allConsultCount, 0));//赋值接诊率
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 【总收入】= 诊查费(21) + 处方费(3)
|
|
|
* 查询诊查费、药品费、平均门诊费用 、总收入
|
|
|
* 今日新增、本月新增
|
|
|
*/
|
|
|
public HashMap<String, Object> getFreeDetailCount(ScreenQvo qvo) throws Exception {
|
|
|
HashMap<String, Object> resultMap = new HashMap<>();
|
|
|
String[] dateList = getFirstAndEndDay(qvo.getEndDate());
|
|
|
//今天的
|
|
|
String sql = "SELECT SUM(q.total)'todayFree' FROM(\n" +
|
|
|
" SELECT\n" +
|
|
|
" IF(SUM(p.drug_fee) IS NULL,0,SUM(p.drug_fee)) AS total \n" +
|
|
|
" FROM\n" +
|
|
|
" wlyy_prescription p\n" +
|
|
|
" INNER JOIN wlyy_outpatient o ON p.outpatient_id = o.id \n" +
|
|
|
" WHERE\n" +
|
|
|
" 1 = 1 \n" +
|
|
|
" AND p.STATUS >= 30\n" +
|
|
|
" AND p.create_time >='" + qvo.getEndDate() + "' AND p.create_time <='" + qvo.getEndDate() + " 23:59:59' \n" +
|
|
|
" UNION ALL\n" +
|
|
|
" SELECT\n" +
|
|
|
" COALESCE(ROUND(SUM(bop.pay_price),2), 0) AS total\n" +
|
|
|
" FROM\n" +
|
|
|
" wlyy_outpatient o\n" +
|
|
|
" LEFT JOIN base_business_order_pay bop ON o.id = bop.relation_code \n" +
|
|
|
" WHERE\n" +
|
|
|
" o.pay_status = 1 \n" +
|
|
|
" AND o.`status` IN ( 1, 2, 3 )\n" +
|
|
|
" AND bop.pay_price IS NOT NULL AND bop.pay_price>0\n" +
|
|
|
" AND o.create_time >='" + qvo.getEndDate() + "' AND o.create_time <='" + qvo.getEndDate() + " 23:59:59' \n" +
|
|
|
") q ";
|
|
|
CompletableFuture<SaveModel> future01 = CompletableFuture.supplyAsync(() -> {
|
|
|
SaveModel model = null;
|
|
|
try {
|
|
|
//处方费
|
|
|
model = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "3", SaveModel.timeLevel_DDL);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return model;
|
|
|
}, execute);
|
|
|
CompletableFuture<SaveModel> future02 = CompletableFuture.supplyAsync(() -> {
|
|
|
SaveModel model = null;
|
|
|
try {
|
|
|
//检查费
|
|
|
model = elasticsearchUtil.findOneDateQuotaLevel0(qvo.getEndDate(), qvo.getEndDate(), qvo.getArea(), qvo.getLevel(), "21", SaveModel.timeLevel_DDL);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return model;
|
|
|
}, execute);
|
|
|
CompletableFuture<SaveModel> future03 = CompletableFuture.supplyAsync(() -> {
|
|
|
SaveModel model = null;
|
|
|
try {
|
|
|
//本月新增[处方费+检查费]
|
|
|
model = elasticsearchUtil.findOneDateQuotaLevel0(dateList[0], dateList[1], qvo.getArea(), qvo.getLevel(), "3,21", SaveModel.timeLevel_ZL);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return model;
|
|
|
}, execute);
|
|
|
CompletableFuture<String> future04 = CompletableFuture.supplyAsync(() -> {
|
|
|
String todayFree = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
return todayFree;
|
|
|
}, execute);
|
|
|
CompletableFuture.allOf(future01, future02, future03, future04).get();
|
|
|
SaveModel model01 = future01.get();
|
|
|
SaveModel model02 = future02.get();
|
|
|
SaveModel monthModel = future03.get();
|
|
|
String todayFree = future04.get();
|
|
|
long checkFree = 0;
|
|
|
long prescriptionFee = 0;
|
|
|
long allCount;
|
|
|
if (model01 != null) {
|
|
|
prescriptionFee = model01.getResult2().longValue();
|
|
|
}
|
|
|
if (model02 != null) {
|
|
|
checkFree = model02.getResult2().longValue();
|
|
|
}
|
|
|
allCount = prescriptionFee + checkFree;
|
|
|
|
|
|
resultMap.put("checkFree", checkFree);//处方费
|
|
|
resultMap.put("prescriptionFee", prescriptionFee);//检查费
|
|
|
resultMap.put("allCount", allCount);//总费用
|
|
|
if (allCount == 0) {
|
|
|
resultMap.put("avgFree", 0);
|
|
|
} else {
|
|
|
resultMap.put("avgFree", allCount / 2.0);//平均费用
|
|
|
}
|
|
|
if (monthModel != null) {
|
|
|
resultMap.put("monthFree", monthModel.getResult2().longValue());//本月新增
|
|
|
} else {
|
|
|
resultMap.put("monthFree", 0);
|
|
|
}
|
|
|
resultMap.put("todayFree", todayFree);//今日新增
|
|
|
return resultMap;
|
|
|
}
|
|
|
}
|