|
@ -18,6 +18,143 @@ public class StatisticsService {
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
/**
|
|
|
* 设备上传次数趋势
|
|
|
*/
|
|
|
public JSONObject uploadAnalysis(String startDate,String endDate) throws Exception{
|
|
|
JSONObject json = new JSONObject();
|
|
|
String useSql = "SELECT COUNT(if(type=1,1,null)) xtBindNum,COUNT(if(type=2,1,null)) xyBindNum,DATE_FORMAT(czrq,'%Y-%m-%d') date" +
|
|
|
" from wlyy_patient_health_index where del=1 ";
|
|
|
if(StringUtils.isNotBlank(startDate)){
|
|
|
useSql += " and czrq>='"+startDate+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(endDate)){
|
|
|
useSql += " and czrq<='"+endDate+" 23:59:59' ";
|
|
|
}
|
|
|
useSql += " GROUP BY date ORDER BY date ";
|
|
|
|
|
|
List<Map<String,Object>> useList = jdbcTemplate.queryForList(useSql);
|
|
|
json.put("useList",useList);
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 绑定次数占比
|
|
|
*/
|
|
|
public JSONObject bindAnalysis(String startDate,String endDate) throws Exception{
|
|
|
JSONObject json = new JSONObject();
|
|
|
String sql = "SELECT COUNT(if(category_code=1,1,null)) xtBindNum,COUNT(if(category_code=2,1,null)) xyBindNum" +
|
|
|
" from wlyy_patient_device where 1=1 ";
|
|
|
if(StringUtils.isNotBlank(startDate)){
|
|
|
sql += " and czrq>='"+startDate+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(endDate)){
|
|
|
sql += " and czrq<='"+endDate+" 23:59:59' ";
|
|
|
}
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
Map<String,Object> map = list.get(0);
|
|
|
int xtBindNum = Integer.parseInt(map.get("xtBindNum")+"");
|
|
|
int xyBindNum = Integer.parseInt(map.get("xyBindNum")+"");
|
|
|
int total = xtBindNum + xyBindNum;
|
|
|
json.put("xtBindNum",xtBindNum);//血糖绑定次数
|
|
|
json.put("xyBindNum",xyBindNum);//血压绑定次数
|
|
|
json.put("total",total);//总绑定次数
|
|
|
json.put("xtRate",getRange(xtBindNum,total));//血糖占比
|
|
|
json.put("xyRate",getRange(xyBindNum,total));//血压占比
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设备分析头部统计
|
|
|
* 1、【设备总数】:展示添加时间为查询时间内的设备总数;
|
|
|
* 2、【血压计数量】:展示添加时间为查询时间内的设备总数;
|
|
|
* 3、【血糖仪数量】:展示添加时间为查询时间内的设备总数;
|
|
|
* 4、【投放科室】:展示添加时间为查询时间内的设备分配给科室的科室数量,需去重;
|
|
|
* 5、【使用科室】:展示查询时间内有数据上传的科室的数量,需要去重;
|
|
|
* 6、【绑定次数】:展示查询时间内,所有设备被绑定的次数;
|
|
|
* 7、【上传次数】:展示查询时间段内所有设备的上传次数,
|
|
|
* 8、【血糖仪上传】:展示查询时间段内所有血糖仪设备的数据上传次数;
|
|
|
* 9、【血压计上传】:展示查询时间段内所有血压计设备的数据上传次数;
|
|
|
*/
|
|
|
public JSONObject deviceAnalysisTop(String startDate,String endDate) throws Exception{
|
|
|
JSONObject json = new JSONObject();
|
|
|
String filterDevice = "";
|
|
|
String filterUpload = "";
|
|
|
String filterDept = "";
|
|
|
String filterDeptUse = "";
|
|
|
if(StringUtils.isNotBlank(startDate)){
|
|
|
filterDevice += " and d.apply_date>='"+startDate+"' ";
|
|
|
filterDept += " and apply_date>='"+startDate+"' ";
|
|
|
filterDeptUse += " and d.apply_date>='"+startDate+"' and i.czrq>='"+startDate+"' ";
|
|
|
filterUpload += " and czrq>='"+startDate+"' ";
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(endDate)){
|
|
|
filterDevice += " and d.apply_date<='"+endDate+" 23:59:59' ";
|
|
|
filterDept += " and apply_date<='"+endDate+" 23:59:59' ";
|
|
|
filterDeptUse += " and d.apply_date<='"+endDate+" 23:59:59' and i.czrq<='"+endDate+" 23:59:59' ";
|
|
|
filterUpload += " and czrq<='"+endDate+" 23:59:59' ";
|
|
|
}
|
|
|
|
|
|
//智能设备总数
|
|
|
int devcieTotal = 0;
|
|
|
int devcieXt = 0;//血糖仪数
|
|
|
int devcieXy = 0;//血压计数
|
|
|
String deviceSql = "SELECT dm.category_code type,COUNT(d.id) num FROM " +
|
|
|
"wlyy_devices d INNER JOIN dm_device dm ON d.category_code = dm.id " +
|
|
|
"where 1=1 " + filterDevice +
|
|
|
"GROUP BY dm.category_code";
|
|
|
List<Map<String,Object>> deviceList = jdbcTemplate.queryForList(deviceSql);
|
|
|
for (Map<String,Object> map:deviceList){
|
|
|
String type = map.get("type")+"";
|
|
|
if("1".equals(type)){
|
|
|
devcieXt = Integer.parseInt(map.get("num")+"");
|
|
|
}
|
|
|
if("2".equals(type)){
|
|
|
devcieXy = Integer.parseInt(map.get("num")+"");
|
|
|
}
|
|
|
}
|
|
|
devcieTotal = devcieXt+devcieXy;
|
|
|
json.put("devcieTotal",devcieTotal);
|
|
|
json.put("devcieXt",devcieXt);
|
|
|
json.put("devcieXy",devcieXy);
|
|
|
//设备上传次数
|
|
|
int uploadTotal = 0;
|
|
|
int uploadXt = 0;//
|
|
|
int uploadXy = 0;//
|
|
|
String uploadSql = "select type,count(id) num from wlyy_patient_health_index where 1=1 "+filterUpload+" group by type";
|
|
|
List<Map<String,Object>> uploadList = jdbcTemplate.queryForList(uploadSql);
|
|
|
for (Map<String,Object> map:uploadList){
|
|
|
String type = map.get("type")+"";
|
|
|
if("1".equals(type)){
|
|
|
uploadXt = Integer.parseInt(map.get("num")+"");
|
|
|
}
|
|
|
if("2".equals(type)){
|
|
|
uploadXy = Integer.parseInt(map.get("num")+"");
|
|
|
}
|
|
|
}
|
|
|
uploadTotal = uploadXt+uploadXy;
|
|
|
json.put("uploadTotal",uploadTotal);
|
|
|
json.put("uploadXt",uploadXt);
|
|
|
json.put("uploadXy",uploadXy);
|
|
|
//投放科室数量
|
|
|
String deptSql = "select count(DISTINCT dept) from wlyy_devices where dept is not null "+filterDept;
|
|
|
String deptUseSql = "SELECT count(DISTINCT d.dept) from wlyy_devices d,wlyy_patient_health_index i " +
|
|
|
"WHERE d.dept is not null and d.device_code=i.device_sn and i.del=1 "+filterDeptUse;
|
|
|
int deptTotal = jdbcTemplate.queryForObject(deptSql,Integer.class);
|
|
|
int deptUse = jdbcTemplate.queryForObject(deptUseSql,Integer.class);
|
|
|
if(deptUse>deptTotal){
|
|
|
deptUse = deptTotal;
|
|
|
}
|
|
|
//绑定次数
|
|
|
String bindSql = "SELECT COUNT(*) num from wlyy_patient_device " +
|
|
|
" where 1=1 "+filterUpload;
|
|
|
int bindNum = jdbcTemplate.queryForObject(bindSql,Integer.class);
|
|
|
json.put("deptTotal",deptTotal);
|
|
|
json.put("deptUse",deptUse);
|
|
|
json.put("bindNum",bindNum);//绑定次数
|
|
|
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 智能设备分析
|