|
@ -21,6 +21,8 @@ import com.yihu.wlyy.util.MapListUtils;
|
|
import com.yihu.wlyy.util.SystemConf;
|
|
import com.yihu.wlyy.util.SystemConf;
|
|
import io.swagger.models.auth.In;
|
|
import io.swagger.models.auth.In;
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
import org.elasticsearch.common.inject.internal.Join;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@ -34,6 +36,7 @@ import org.springframework.jdbc.support.nativejdbc.OracleJdbc4NativeJdbcExtracto
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
@ -4951,6 +4954,410 @@ public class StatisticsService extends BaseService {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String,Object> getPrescriptionCount(String level,String area,String disease){
|
|
|
|
|
|
|
|
//总数
|
|
|
|
String totalSql ="SELECT " +
|
|
|
|
" count(1) total" +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription p ";
|
|
|
|
if(StringUtils.isNotBlank(disease)){
|
|
|
|
totalSql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = p.code WHERE d.health_problem ='"+disease+"' ";
|
|
|
|
}else{
|
|
|
|
totalSql +=" WHERE 1=1 ";
|
|
|
|
}
|
|
|
|
|
|
|
|
//进行中
|
|
|
|
String processingSql="SELECT " +
|
|
|
|
" count(1) processingCount " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription p ";
|
|
|
|
if(StringUtils.isNotBlank(disease)){
|
|
|
|
processingSql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = p.code WHERE d.health_problem ='"+disease+"' ";
|
|
|
|
}else{
|
|
|
|
processingSql +=" WHERE 1=1 ";
|
|
|
|
}
|
|
|
|
processingSql += " AND p.`status` < " + PrescriptionLog.PrescriptionLogStatus.finish.getValue() +
|
|
|
|
" AND p.`status`>= " + PrescriptionLog.PrescriptionLogStatus.revieweding.getValue() ;
|
|
|
|
|
|
|
|
//已完成,已经取消,审核不通过,其他原因取消
|
|
|
|
String stateSql = "SELECT " +
|
|
|
|
" count(1) count" +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription p ";
|
|
|
|
if(StringUtils.isNotBlank(disease)){
|
|
|
|
stateSql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = p.code WHERE d.health_problem ='"+disease+"' ";
|
|
|
|
}else{
|
|
|
|
stateSql +=" WHERE 1=1 ";
|
|
|
|
}
|
|
|
|
stateSql += " AND p.`status` = ? " ;
|
|
|
|
|
|
|
|
//市区
|
|
|
|
if("4".equals(level)){
|
|
|
|
//市区无过滤
|
|
|
|
//区级
|
|
|
|
}else if("3".equals(level)){
|
|
|
|
totalSql += " AND LEFT(p.hospital, 6) = '"+area+"' ";
|
|
|
|
processingSql += " AND LEFT(p.hospital, 6) = '"+area+"' ";
|
|
|
|
stateSql += " AND LEFT(p.hospital, 6) = '"+area+"' ";
|
|
|
|
//机构
|
|
|
|
}else if("2".equals(level)){
|
|
|
|
totalSql += " p.hospital = '"+area+"' ";
|
|
|
|
processingSql += " p.hospital = '"+area+"' ";
|
|
|
|
stateSql += " p.hospital = '"+area+"' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String,Object> rs = new HashedMap();
|
|
|
|
//总数
|
|
|
|
List<Map<String,Object>> total = jdbcTemplate.queryForList(totalSql);
|
|
|
|
if(total!=null&&total.size()>0){
|
|
|
|
rs.put("total",total.get(0).get("total"));
|
|
|
|
}else{
|
|
|
|
rs.put("total",0);
|
|
|
|
}
|
|
|
|
//进行中
|
|
|
|
List<Map<String,Object>> processingCount = jdbcTemplate.queryForList(processingSql);
|
|
|
|
if(total!=null&&total.size()>0){
|
|
|
|
rs.put("processingCount",processingCount.get(0).get("processingCount"));
|
|
|
|
}else{
|
|
|
|
rs.put("processingCount",0);
|
|
|
|
}
|
|
|
|
//已完成
|
|
|
|
List<Map<String,Object>> finishCount = jdbcTemplate.queryForList(stateSql,new Object[]{PrescriptionLog.PrescriptionLogStatus.finish.getValue()});
|
|
|
|
if(total!=null&&total.size()>0){
|
|
|
|
rs.put("finishCount",finishCount.get(0).get("count"));
|
|
|
|
}else{
|
|
|
|
rs.put("finishCount",0);
|
|
|
|
}
|
|
|
|
//已取消
|
|
|
|
List<Map<String,Object>> patientCancelCount = jdbcTemplate.queryForList(stateSql,new Object[]{PrescriptionLog.PrescriptionLogStatus.patient_canel.getValue()});
|
|
|
|
if(total!=null&&total.size()>0){
|
|
|
|
rs.put("patientCancelCount",patientCancelCount.get(0).get("count"));
|
|
|
|
}else{
|
|
|
|
rs.put("patientCancelCount",0);
|
|
|
|
}
|
|
|
|
//审核不通过
|
|
|
|
List<Map<String,Object>> noReviewedCount = jdbcTemplate.queryForList(stateSql,new Object[]{PrescriptionLog.PrescriptionLogStatus.no_reviewed.getValue()});
|
|
|
|
if(total!=null&&total.size()>0){
|
|
|
|
rs.put("noReviewedCount",noReviewedCount.get(0).get("count"));
|
|
|
|
}else{
|
|
|
|
rs.put("noReviewedCount",0);
|
|
|
|
}
|
|
|
|
//其他原因取消
|
|
|
|
List<Map<String,Object>> payOuttimeCount = jdbcTemplate.queryForList(stateSql,new Object[]{PrescriptionLog.PrescriptionLogStatus.pay_outtime.getValue()});
|
|
|
|
if(total!=null&&total.size()>0){
|
|
|
|
rs.put("payOuttimeCount",payOuttimeCount.get(0).get("count"));
|
|
|
|
}else{
|
|
|
|
rs.put("payOuttimeCount",0);
|
|
|
|
}
|
|
|
|
return rs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param level 等级
|
|
|
|
* @param area 等级编码
|
|
|
|
* @param disease 疾病编码
|
|
|
|
* @param type 类型1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<Map<String,Object>> getPrescriptionTotalHistogram(String level,String area,String disease,String type){
|
|
|
|
List<Map<String,Object>> rs = new ArrayList<>();
|
|
|
|
|
|
|
|
Calendar dd = Calendar.getInstance();//定义日期实例
|
|
|
|
Date endDate = new Date();
|
|
|
|
dd.setTime(endDate);
|
|
|
|
|
|
|
|
for(int i=1;i<7;i++){
|
|
|
|
Map<String,Object> mc = new HashedMap();
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
|
|
|
String date = sdf.format(dd.getTime());
|
|
|
|
mc.put("month",date);
|
|
|
|
mc.put("count",0);
|
|
|
|
dd.add(Calendar.MONTH,-1);
|
|
|
|
rs.add(mc);
|
|
|
|
}
|
|
|
|
|
|
|
|
String sql = "SELECT count(1) AS count,LEFT(p.create_time,7) AS month " +
|
|
|
|
" FROM wlyy_prescription p ";
|
|
|
|
if(StringUtils.isNotBlank(disease)){
|
|
|
|
sql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = p.code WHERE d.health_problem ='"+disease+"' ";
|
|
|
|
}else{
|
|
|
|
sql +=" WHERE 1=1 ";
|
|
|
|
}
|
|
|
|
//市区
|
|
|
|
if("4".equals(level)){
|
|
|
|
//市区无过滤
|
|
|
|
//区级
|
|
|
|
}else if("3".equals(level)){
|
|
|
|
sql += " AND LEFT(p.hospital, 6) = '"+area+"' ";
|
|
|
|
//机构
|
|
|
|
}else if("2".equals(level)){
|
|
|
|
sql += " p.hospital = '"+area+"' ";
|
|
|
|
}
|
|
|
|
//类型1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消
|
|
|
|
if("1".equals(type)){
|
|
|
|
//无状态过滤
|
|
|
|
}else if("2".equals(type)){
|
|
|
|
sql +=" AND p.`status` ='"+PrescriptionLog.PrescriptionLogStatus.finish.getValue()+"' ";
|
|
|
|
}else if("3".equals(type)){
|
|
|
|
sql +=" AND p.`status` ='"+PrescriptionLog.PrescriptionLogStatus.patient_canel.getValue()+"' ";
|
|
|
|
}else if("4".equals(type)){
|
|
|
|
sql +=" AND p.`status` ='"+PrescriptionLog.PrescriptionLogStatus.no_reviewed.getValue()+"' ";
|
|
|
|
}else if("5".equals(type)){
|
|
|
|
sql +=" AND p.`status` <'"+PrescriptionLog.PrescriptionLogStatus.finish.getValue()+"' " +
|
|
|
|
" AND p.`status`>='"+PrescriptionLog.PrescriptionLogStatus.revieweding+"'";
|
|
|
|
}else if("6".equals(type)){
|
|
|
|
sql +=" AND p.`status` ='"+PrescriptionLog.PrescriptionLogStatus.pay_outtime.getValue()+"'";
|
|
|
|
}
|
|
|
|
|
|
|
|
sql += " AND p.create_time >='"+DateUtil.dateToStr(dd.getTime(),"YYYY-MM-dd HH:mm:ss")+"' AND p.create_time <='"+ DateUtil.dateToStr(new Date(),"YYYY-MM-dd HH:mm:ss")+"' GROUP BY LEFT(p.create_time,7) ";
|
|
|
|
|
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
|
Iterator iterator = list.iterator();
|
|
|
|
for(Map<String,Object> m:rs){
|
|
|
|
while (iterator.hasNext()){
|
|
|
|
Map<String,Object> ml = ( Map<String,Object>)iterator.next();
|
|
|
|
String monthKey = (String)m.get("month");
|
|
|
|
String monthKeyDb = (String)ml.get("month");
|
|
|
|
if(monthKey.equals(monthKeyDb)){
|
|
|
|
m.put("count",ml.get("count"));
|
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param level
|
|
|
|
* @param lowlevel
|
|
|
|
* @param area
|
|
|
|
* @param disease
|
|
|
|
* @param type
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<Map<String,Object>> getPrescriptionTotalLowLevel(String level,String lowlevel,String area,String disease,String type){
|
|
|
|
|
|
|
|
List<Map<String,Object>> rs ;
|
|
|
|
String sql =null;
|
|
|
|
//市级维度
|
|
|
|
if("4".equals(level)){
|
|
|
|
//默认查找市级维度
|
|
|
|
if("3".equals(lowlevel)){
|
|
|
|
sql = "SELECT " +
|
|
|
|
" t.code, " +
|
|
|
|
" t.name, " +
|
|
|
|
" ifnull(s.count,0) num " +
|
|
|
|
" FROM " +
|
|
|
|
" dm_town t " +
|
|
|
|
" LEFT JOIN ( " +
|
|
|
|
" SELECT " +
|
|
|
|
" count(1) count, " +
|
|
|
|
" LEFT (p.hospital, 6) code " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription p ";
|
|
|
|
sql = setDiseaseTypeSql(disease,type,sql);
|
|
|
|
sql += " GROUP BY " +
|
|
|
|
" LEFT (p.hospital, 6) " +
|
|
|
|
" ) s ON s.code = t.code " +
|
|
|
|
" WHERE " +
|
|
|
|
" t.city='350200' " +
|
|
|
|
" ORDER BY num DESC";
|
|
|
|
}else if("2".equals(lowlevel)){
|
|
|
|
sql = "SELECT " +
|
|
|
|
" t.code, " +
|
|
|
|
" t.name, " +
|
|
|
|
" ifnull(s.count,0) num " +
|
|
|
|
" FROM " +
|
|
|
|
" dm_hospital t " +
|
|
|
|
" LEFT JOIN ( " +
|
|
|
|
" SELECT " +
|
|
|
|
" count(1) count, " +
|
|
|
|
" p.hospital code " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription p ";
|
|
|
|
sql = setDiseaseTypeSql(disease,type,sql);
|
|
|
|
sql += " GROUP BY " +
|
|
|
|
" p.hospital " +
|
|
|
|
" ) s ON s.code = t.code " +
|
|
|
|
" WHERE " +
|
|
|
|
" t.city='350200' " +
|
|
|
|
" AND LENGTH(t.code)=10 " +
|
|
|
|
" ORDER BY num DESC";
|
|
|
|
}else if("1".equals(lowlevel)){
|
|
|
|
sql = " SELECT " +
|
|
|
|
" t.id code, " +
|
|
|
|
" t.name, " +
|
|
|
|
" ifnull(s.count,0) num " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_admin_team t " +
|
|
|
|
" LEFT JOIN ( " +
|
|
|
|
" SELECT " +
|
|
|
|
" count(1) count, " +
|
|
|
|
" p.admin_team_id code " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription p " ;
|
|
|
|
sql = setDiseaseTypeSql(disease,type,sql);
|
|
|
|
sql += " GROUP BY " +
|
|
|
|
" p.admin_team_id " +
|
|
|
|
" ) s ON s.code = t.id " +
|
|
|
|
" ORDER BY num DESC ";
|
|
|
|
}
|
|
|
|
//区级维度
|
|
|
|
}else if("3".equals(level)){
|
|
|
|
if("2".equals(lowlevel)){
|
|
|
|
sql = "SELECT " +
|
|
|
|
" t.code, " +
|
|
|
|
" t.name, " +
|
|
|
|
" ifnull(s.count,0) num " +
|
|
|
|
" FROM " +
|
|
|
|
" dm_hospital t " +
|
|
|
|
" LEFT JOIN ( " +
|
|
|
|
" SELECT " +
|
|
|
|
" count(1) count, " +
|
|
|
|
" p.hospital code " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription p ";
|
|
|
|
sql = setDiseaseTypeSql(disease,type,sql);
|
|
|
|
sql += " GROUP BY " +
|
|
|
|
" p.hospital " +
|
|
|
|
" ) s ON s.code = t.code " +
|
|
|
|
" WHERE " +
|
|
|
|
" t.city='350200' " +
|
|
|
|
" AND LENGTH(t.code)=10 " +
|
|
|
|
" AND t.town ='"+area+"'" +
|
|
|
|
" ORDER BY num DESC";
|
|
|
|
}else if("1".equals(lowlevel)){
|
|
|
|
sql = " SELECT " +
|
|
|
|
" t.id code, " +
|
|
|
|
" t.name, " +
|
|
|
|
" ifnull(s.count,0) num " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_admin_team t " +
|
|
|
|
" LEFT JOIN ( " +
|
|
|
|
" SELECT " +
|
|
|
|
" count(1) count, " +
|
|
|
|
" p.admin_team_id code " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription p " ;
|
|
|
|
sql = setDiseaseTypeSql(disease,type,sql);
|
|
|
|
sql += " GROUP BY " +
|
|
|
|
" p.admin_team_id " +
|
|
|
|
" ) s ON s.code = t.id " +
|
|
|
|
" WHERE LEFT(t.org_code,6) ='"+area+"' " +
|
|
|
|
" ORDER BY num DESC ";
|
|
|
|
}
|
|
|
|
//机构级维度
|
|
|
|
}else if("2".equals(level)){
|
|
|
|
if("1".equals(lowlevel)){
|
|
|
|
sql = " SELECT " +
|
|
|
|
" t.id code, " +
|
|
|
|
" t.name, " +
|
|
|
|
" ifnull(s.count,0) num " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_admin_team t " +
|
|
|
|
" LEFT JOIN ( " +
|
|
|
|
" SELECT " +
|
|
|
|
" count(1) count, " +
|
|
|
|
" p.admin_team_id code " +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription p " ;
|
|
|
|
sql = setDiseaseTypeSql(disease,type,sql);
|
|
|
|
sql += " GROUP BY " +
|
|
|
|
" p.admin_team_id " +
|
|
|
|
" ) s ON s.code = t.id " +
|
|
|
|
" WHERE t.org_code ='"+area+"'" +
|
|
|
|
" ORDER BY num DESC ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rs = jdbcTemplate.queryForList(sql);
|
|
|
|
return rs;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String setDiseaseTypeSql(String disease,String type,String sql){
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(disease)){
|
|
|
|
sql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = p.code WHERE d.health_problem ='"+disease+"' ";
|
|
|
|
}else{
|
|
|
|
sql +=" WHERE 1=1 ";
|
|
|
|
}
|
|
|
|
//类型1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消
|
|
|
|
if("1".equals(type)){
|
|
|
|
//无状态过滤
|
|
|
|
}else if("2".equals(type)){
|
|
|
|
sql +=" AND p.`status` ='"+PrescriptionLog.PrescriptionLogStatus.finish.getValue()+"' ";
|
|
|
|
}else if("3".equals(type)){
|
|
|
|
sql +=" AND p.`status` ='"+PrescriptionLog.PrescriptionLogStatus.patient_canel.getValue()+"' ";
|
|
|
|
}else if("4".equals(type)){
|
|
|
|
sql +=" AND p.`status` ='"+PrescriptionLog.PrescriptionLogStatus.no_reviewed.getValue()+"' ";
|
|
|
|
}else if("5".equals(type)){
|
|
|
|
sql +=" AND p.`status` <'"+PrescriptionLog.PrescriptionLogStatus.finish.getValue()+"' " +
|
|
|
|
" AND p.`status`>='"+PrescriptionLog.PrescriptionLogStatus.revieweding+"'";
|
|
|
|
}else if("6".equals(type)){
|
|
|
|
sql +=" AND p.`status` ='"+PrescriptionLog.PrescriptionLogStatus.pay_outtime.getValue()+"'";
|
|
|
|
}
|
|
|
|
|
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String,Object> getPrescriptionCost(String level,String area,String disease){
|
|
|
|
|
|
|
|
Map<String,Object> rs = new HashedMap();
|
|
|
|
|
|
|
|
String sql = "SELECT " +
|
|
|
|
" IFNULL(SUM(t.total_amount),0) sum" +
|
|
|
|
" FROM " +
|
|
|
|
" wlyy_prescription_pay t ";
|
|
|
|
|
|
|
|
String avgSql = "SELECT" +
|
|
|
|
" IFNULL(AVG(t.total_amount),0) avg" +
|
|
|
|
" FROM" +
|
|
|
|
" wlyy_prescription_pay t " ;
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(disease)){
|
|
|
|
sql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = t.prescription_code ";
|
|
|
|
avgSql += " JOIN wlyy_prescription_diagnosis d ON d.prescription_code = t.prescription_code ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if("4".equals(level)){
|
|
|
|
sql +=" WHERE 1=1 ";
|
|
|
|
avgSql +=" WHERE 1=1 ";
|
|
|
|
}else if("3".equals(level)){
|
|
|
|
sql +=" JOIN wlyy_prescription p ON t.prescription_code = p.code WHERE LEFT(p.hospital,6) ='"+area+"' ";
|
|
|
|
avgSql +=" JOIN wlyy_prescription p ON t.prescription_code = p.code WHERE LEFT(p.hospital,6) ='"+area+"' ";
|
|
|
|
|
|
|
|
}else if("2".equals(level)){
|
|
|
|
sql +=" JOIN wlyy_prescription p ON t.prescription_code = p.code WHERE p.hospital ='"+area+"' ";
|
|
|
|
avgSql +=" JOIN wlyy_prescription p ON t.prescription_code = p.code WHERE p.hospital ='"+area+"' ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(disease)){
|
|
|
|
sql += " AND d.health_problem ='"+disease+"'";
|
|
|
|
avgSql += " AND d.health_problem ='"+disease+"'";
|
|
|
|
}
|
|
|
|
sql +="AND t.trade_status = 1 ";
|
|
|
|
avgSql +="AND t.trade_status = 1 ";
|
|
|
|
|
|
|
|
List<Map<String,Object>> sum = jdbcTemplate.queryForList(sql);
|
|
|
|
if(sum!=null&&sum.size()>0){
|
|
|
|
BigDecimal s = (BigDecimal)sum.get(0).get("sum");
|
|
|
|
rs.put("sum",s.divide(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP));
|
|
|
|
}else{
|
|
|
|
rs.put("sum",0);
|
|
|
|
}
|
|
|
|
List<Map<String,Object>> avg = jdbcTemplate.queryForList(avgSql);
|
|
|
|
if(avg!=null&&avg.size()>0){
|
|
|
|
BigDecimal a = (BigDecimal)avg.get(0).get("avg");
|
|
|
|
rs.put("avg",a.divide((new BigDecimal(100))).setScale(2,BigDecimal.ROUND_HALF_UP));
|
|
|
|
}else{
|
|
|
|
rs.put("avg",0);
|
|
|
|
}
|
|
|
|
return rs;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|