统计查询。

This commit is contained in:
haown 2024-11-08 09:32:48 +08:00
parent 760af62433
commit e5fbec5fed
7 changed files with 119 additions and 41 deletions

View File

@ -19,14 +19,14 @@ public class FollowUpRateDto {
* 开始月份 * 开始月份
*/ */
@ApiModelProperty("开始月份") @ApiModelProperty("开始月份")
@DateTimeFormat(pattern = "yyyy-MM") @DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate; private LocalDate startDate;
/** /**
* 结束月份 * 结束月份
*/ */
@ApiModelProperty("结束月份") @ApiModelProperty("结束月份")
@DateTimeFormat(pattern = "yyyy-MM") @DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate endDate; private LocalDate endDate;
/** /**

View File

@ -128,6 +128,7 @@ public class StatisticsServiceImpl implements IStatisticsService {
rateTrendVo.setCommonPatientSuccessRate(monthObj.getCommonPatientSuccessRate()); rateTrendVo.setCommonPatientSuccessRate(monthObj.getCommonPatientSuccessRate());
rateTrendVoList.add(rateTrendVo); rateTrendVoList.add(rateTrendVo);
numTrendVo.setFollowUpMonth(month);
numTrendVo.setAiPatientNum(monthObj.getAiPatientNum()); numTrendVo.setAiPatientNum(monthObj.getAiPatientNum());
numTrendVo.setCommonPatientNum(monthObj.getCommonPatientNum()); numTrendVo.setCommonPatientNum(monthObj.getCommonPatientNum());
@ -153,26 +154,34 @@ public class StatisticsServiceImpl implements IStatisticsService {
*/ */
@Override @Override
public List<FollowUpDetailVo> getFollowUpDetail(FollowUpRateDto queryDto) { public List<FollowUpDetailVo> getFollowUpDetail(FollowUpRateDto queryDto) {
if (queryDto.getStartDate() == null) {
queryDto.setStartDate(LocalDate.now().withDayOfYear(1));
}
if (queryDto.getEndDate() == null) {
queryDto.setEndDate(LocalDate.now());
}
List<FollowUpDetailVo> retList = new ArrayList<>(); List<FollowUpDetailVo> retList = new ArrayList<>();
FollowUpDetailVo followUpDetailVo = new FollowUpDetailVo();
// 总计行预留位置
retList.set(0, followUpDetailVo);
// 就诊患者列表查询 // 就诊患者列表查询
List<PatientVisitRecordStatisticVo> patientVisitList = patientVisitRecordMapper.getVisitPatientList(queryDto); List<PatientVisitRecordStatisticVo> patientVisitList = patientVisitRecordMapper.getVisitPatientList(queryDto);
// 随访计划列表查询 // 随访计划列表查询
List<PatientFollowUpPlanVo> planList = signPatientManageRouteNodeMapper.getFollowUpPlan(queryDto); List<PatientFollowUpPlanVo> planList = signPatientManageRouteNodeMapper.getFollowUpPlan(queryDto);
if (StringUtils.equals(queryDto.getType(), "dept")) { if (StringUtils.equals(queryDto.getType(), "dept")) {
FollowUpDetailVo firstRow = new FollowUpDetailVo();
firstRow.setRowName("总计");
// 总计行预留位置
retList.add(0, firstRow);
// 就诊患者列表按照科室分组 // 就诊患者列表按照科室分组
Map<Long, List<PatientVisitRecordStatisticVo>> groupByDept = new HashMap<>(); Map<Long, List<PatientVisitRecordStatisticVo>> groupByDept = new HashMap<>();
if (CollectionUtils.isNotEmpty(patientVisitList)) { if (CollectionUtils.isNotEmpty(patientVisitList)) {
groupByDept = patientVisitList.stream().collect(Collectors.groupingBy(PatientVisitRecordStatisticVo::getDepartmentId)); groupByDept = patientVisitList.stream().filter(item -> item.getDepartmentId() != null).collect(Collectors.groupingBy(PatientVisitRecordStatisticVo::getDepartmentId));
} }
Map<Long, List<PatientFollowUpPlanVo>> planGroupByDept = new HashMap<>(); Map<Long, List<PatientFollowUpPlanVo>> planGroupByDept = new HashMap<>();
if (CollectionUtils.isNotEmpty(planList)) { if (CollectionUtils.isNotEmpty(planList)) {
// 随访计划列表按照科室分组 // 随访计划列表按照科室分组
planGroupByDept = planList.stream().collect(Collectors.groupingBy(PatientFollowUpPlanVo::getDepartmentId)); planGroupByDept = planList.stream().filter(item-> item.getDepartmentId() != null).collect(Collectors.groupingBy(PatientFollowUpPlanVo::getDepartmentId));
} }
// 查询机构科室医生列表 // 查询机构科室医生列表
Agency agencyQuery = new Agency(); Agency agencyQuery = new Agency();
@ -185,6 +194,7 @@ public class StatisticsServiceImpl implements IStatisticsService {
deptQuery.setNodeType(NodeTypeEnum.DEPARTMENT.getInfo()); deptQuery.setNodeType(NodeTypeEnum.DEPARTMENT.getInfo());
List<Department> deptList = departmentService.selectDepartmentList(deptQuery); List<Department> deptList = departmentService.selectDepartmentList(deptQuery);
for (Department dept : deptList) { for (Department dept : deptList) {
FollowUpDetailVo followUpDetailVo = new FollowUpDetailVo();
followUpDetailVo.setRowName(dept.getDepartmentName()); followUpDetailVo.setRowName(dept.getDepartmentName());
// 就诊人数 // 就诊人数
List<PatientVisitRecordStatisticVo> deptVisitList = groupByDept.get(dept.getId()); List<PatientVisitRecordStatisticVo> deptVisitList = groupByDept.get(dept.getId());
@ -201,27 +211,43 @@ public class StatisticsServiceImpl implements IStatisticsService {
List<SysUser> userList = userService.selectUserList(userQuery); List<SysUser> userList = userService.selectUserList(userQuery);
List<FollowUpDetailVo> childrenList = new ArrayList<>(); List<FollowUpDetailVo> childrenList = new ArrayList<>();
Map<Long, List<PatientVisitRecordStatisticVo>> patientGroupByDoctor = deptVisitList.stream().collect(Collectors.groupingBy(PatientVisitRecordStatisticVo::getAttendingPhysicianId)); Map<Long, List<PatientVisitRecordStatisticVo>> patientGroupByDoctor = new HashMap<>();
Map<Long, List<PatientFollowUpPlanVo>> planGroupByDoctor = deptPlanList.stream().collect(Collectors.groupingBy(PatientFollowUpPlanVo::getAttendingPhysicianId)); Map<Long, List<PatientFollowUpPlanVo>> planGroupByDoctor = new HashMap<>();
if (CollectionUtils.isNotEmpty(deptVisitList)) {
patientGroupByDoctor = deptVisitList.stream().filter(item-> item.getAttendingPhysicianId() != null).collect(Collectors.groupingBy(PatientVisitRecordStatisticVo::getAttendingPhysicianId));
}
if (CollectionUtils.isNotEmpty(deptPlanList)) {
planGroupByDoctor = deptPlanList.stream().filter(item-> item.getAttendingPhysicianId() != null).collect(Collectors.groupingBy(PatientFollowUpPlanVo::getAttendingPhysicianId));
}
for (SysUser user : userList) { for (SysUser user : userList) {
FollowUpDetailVo childRow = new FollowUpDetailVo(); FollowUpDetailVo childRow = new FollowUpDetailVo();
childRow.setRowName(user.getNickName()); childRow.setRowName(user.getNickName());
List<PatientVisitRecordStatisticVo> doctorPatientList = patientGroupByDoctor.get(user.getUserId());
if (CollectionUtils.isEmpty(doctorPatientList)) {
childRow.setPatientNum(0);
} else {
Map<Long, List<PatientVisitRecordStatisticVo>> doctorGroupByPatient = doctorPatientList.stream().collect(Collectors.groupingBy(PatientVisitRecordStatisticVo::getPatientId));
// 医生就诊人数 // 医生就诊人数
childRow.setPatientNum(CollectionUtils.isEmpty(patientGroupByDoctor.get(user.getUserId())) ? 0 : planGroupByDoctor.get(user.getUserId()).size()); childRow.setPatientNum(CollectionUtils.isEmpty(doctorPatientList) ? 0 : doctorGroupByPatient.keySet().size());
}
// 医生统计随访计划人数随访覆盖率随访成功人数随访成功率 // 医生统计随访计划人数随访覆盖率随访成功人数随访成功率
List<PatientFollowUpPlanVo> doctorPlanList = planGroupByDoctor.get(dept.getId()); List<PatientFollowUpPlanVo> doctorPlanList = planGroupByDoctor.get(user.getUserId());
getFollowUpDetailVo(doctorPlanList, childRow); getFollowUpDetailVo(doctorPlanList, childRow);
childrenList.add(childRow); childrenList.add(childRow);
} }
followUpDetailVo.setChilderenList(childrenList); followUpDetailVo.setChilderenList(childrenList);
retList.add(followUpDetailVo); retList.add(followUpDetailVo);
// 计算总计行
getTotalRow(firstRow, retList);
} }
} }
} else if (StringUtils.equals(queryDto.getType(), "date")){ } else if (StringUtils.equals(queryDto.getType(), "date")) {
// 日期列表 // 日期列表
List<String> months = new ArrayList<>(); List<String> months = new ArrayList<>();
LocalDate startDate = queryDto.getStartDate(); LocalDate startDate = queryDto.getStartDate();
@ -241,12 +267,30 @@ public class StatisticsServiceImpl implements IStatisticsService {
planGroupByExecuteDate = planList.stream().collect(Collectors.groupingBy(PatientFollowUpPlanVo::getExecuteMonthStr)); planGroupByExecuteDate = planList.stream().collect(Collectors.groupingBy(PatientFollowUpPlanVo::getExecuteMonthStr));
} }
for (String month : months) { for (String month : months) {
FollowUpDetailVo followUpDetailVo = new FollowUpDetailVo();
followUpDetailVo.setRowName(month);
// 就诊人数
followUpDetailVo.setPatientNum(groupByVisitDate.getOrDefault(month, new ArrayList<>()).size());
// 有随访计划人数
//followUpDetailVo.setFollowUpNum(planGroupByExecuteDate.getOrDefault(month, new ArrayList<>()).size());
// 随访覆盖率
//followUpDetailVo.setFollowUpCoverRate(new BigDecimal(followUpDetailVo.getFollowUpNum()).divide(new BigDecimal(followUpDetailVo.getPatientNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
// 随访计划人数随访覆盖率随访成功人数随访成功率
getFollowUpDetailVo(planGroupByExecuteDate.getOrDefault(month, new ArrayList<>()), followUpDetailVo);
// 按随访方式统计
List<PhoneDialRecordVo> phoneDialRecordVoList = phoneDialRecordMapper.getPhoneDialStatistic(queryDto);
// 统计AI电话拨打次数AI电话拨打次数成功率人工电话拨打次数人工电话拨打次数成功率
FollowUpRateVo followUpRateVo = getFollowUpRateVo(phoneDialRecordVoList);
followUpDetailVo.setAiNum(followUpRateVo.getAiNum());
followUpDetailVo.setAiSuccessRate(followUpRateVo.getAiSuccessRate());
followUpDetailVo.setCommonNum(followUpRateVo.getCommonNum());
followUpDetailVo.setCommonSuccessRate(followUpRateVo.getCommonSuccessRate());
retList.add(followUpDetailVo);
} }
} }
// 计算总计行
getTotalRow(retList);
return retList; return retList;
} }
@ -281,7 +325,7 @@ public class StatisticsServiceImpl implements IStatisticsService {
// AI拨打人数成功率 // AI拨打人数成功率
if (CollectionUtils.isNotEmpty(aiSuccessList)) { if (CollectionUtils.isNotEmpty(aiSuccessList)) {
Map<Long, List<PhoneDialRecordVo>> aiSuccessGroupByPatient = aiSuccessList.stream().collect(Collectors.groupingBy(PhoneDialRecordVo::getPatientId)); Map<Long, List<PhoneDialRecordVo>> aiSuccessGroupByPatient = aiSuccessList.stream().collect(Collectors.groupingBy(PhoneDialRecordVo::getPatientId));
retObj.setAiSuccessRate(new BigDecimal(aiSuccessGroupByPatient.keySet().size()).divide(new BigDecimal(retObj.getAiPatientNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))); retObj.setAiPatientSuccessRate(new BigDecimal(aiSuccessGroupByPatient.keySet().size()).divide(new BigDecimal(retObj.getAiPatientNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
} }
} }
@ -300,7 +344,7 @@ public class StatisticsServiceImpl implements IStatisticsService {
// 人工拨打人数成功率 // 人工拨打人数成功率
if (CollectionUtils.isNotEmpty(commonSuccessList)) { if (CollectionUtils.isNotEmpty(commonSuccessList)) {
Map<Long, List<PhoneDialRecordVo>> commonSuccessGroupByPatient = commonSuccessList.stream().collect(Collectors.groupingBy(PhoneDialRecordVo::getPatientId)); Map<Long, List<PhoneDialRecordVo>> commonSuccessGroupByPatient = commonSuccessList.stream().collect(Collectors.groupingBy(PhoneDialRecordVo::getPatientId));
retObj.setCommonSuccessRate(new BigDecimal(commonSuccessGroupByPatient.keySet().size()).divide(new BigDecimal(retObj.getCommonPatientNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))); retObj.setCommonPatientSuccessRate(new BigDecimal(commonSuccessGroupByPatient.keySet().size()).divide(new BigDecimal(retObj.getCommonPatientNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
} }
} }
return retObj; return retObj;
@ -314,7 +358,7 @@ public class StatisticsServiceImpl implements IStatisticsService {
* @Date 2024-11-4 11:13 * @Date 2024-11-4 11:13
*/ */
private FollowUpDetailVo getFollowUpDetailVo(List<PatientFollowUpPlanVo> planList, FollowUpDetailVo followUpDetailVo) { private FollowUpDetailVo getFollowUpDetailVo(List<PatientFollowUpPlanVo> planList, FollowUpDetailVo followUpDetailVo) {
if (followUpDetailVo.getPatientNum() == 0) { if (followUpDetailVo.getPatientNum() == 0 || CollectionUtils.isEmpty(planList)) {
followUpDetailVo.setFollowUpNum(0); followUpDetailVo.setFollowUpNum(0);
followUpDetailVo.setFollowUpCoverRate(BigDecimal.ZERO); followUpDetailVo.setFollowUpCoverRate(BigDecimal.ZERO);
followUpDetailVo.setFollowUpSuccessNum(0); followUpDetailVo.setFollowUpSuccessNum(0);
@ -344,21 +388,25 @@ public class StatisticsServiceImpl implements IStatisticsService {
* @Author haown * @Author haown
* @Date 2024-11-4 11:29 * @Date 2024-11-4 11:29
*/ */
private List<FollowUpDetailVo> getTotalRow(List<FollowUpDetailVo> followUpDetailVoList) { private List<FollowUpDetailVo> getTotalRow(FollowUpDetailVo firstRow, List<FollowUpDetailVo> followUpDetailVoList) {
for (FollowUpDetailVo retObj : followUpDetailVoList) { firstRow.setRowName("总计");
retObj.setRowName("总计");
// 就诊人数 // 就诊人数
retObj.setPatientNum(followUpDetailVoList.stream().map(FollowUpDetailVo::getPatientNum).reduce(Integer::sum).get()); firstRow.setPatientNum(followUpDetailVoList.stream().map(FollowUpDetailVo::getPatientNum).reduce(Integer::sum).get());
// 随访计划人数 // 随访计划人数
retObj.setFollowUpNum(followUpDetailVoList.stream().map(FollowUpDetailVo::getFollowUpNum).reduce(Integer::sum).get()); firstRow.setFollowUpNum(followUpDetailVoList.stream().map(FollowUpDetailVo::getFollowUpNum).reduce(Integer::sum).get());
// 随访覆盖率 // 随访覆盖率
retObj.setFollowUpCoverRate(new BigDecimal(retObj.getFollowUpNum()).divide(new BigDecimal(retObj.getPatientNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))); if (firstRow.getPatientNum() != null && firstRow.getPatientNum() > 0) {
// 随访成功人数 firstRow.setFollowUpCoverRate(new BigDecimal(firstRow.getFollowUpNum()).divide(new BigDecimal(firstRow.getPatientNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
retObj.setFollowUpSuccessNum(followUpDetailVoList.stream().map(FollowUpDetailVo::getFollowUpSuccessNum).reduce(Integer::sum).get());
// 随访成功率
retObj.setFollowUpCoverRate(new BigDecimal(retObj.getFollowUpSuccessNum()).divide(new BigDecimal(retObj.getPatientNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
followUpDetailVoList.set(0, retObj);
} }
// 随访成功人数
firstRow.setFollowUpSuccessNum(followUpDetailVoList.stream().map(FollowUpDetailVo::getFollowUpSuccessNum).reduce(Integer::sum).get());
// 随访成功率
if (firstRow.getPatientNum() != null && firstRow.getPatientNum() > 0) {
firstRow.setFollowUpSuccessRate(new BigDecimal(firstRow.getFollowUpSuccessNum()).divide(new BigDecimal(firstRow.getPatientNum()), 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100")));
}
followUpDetailVoList.set(0, firstRow);
return followUpDetailVoList; return followUpDetailVoList;
} }
} }

View File

@ -13,6 +13,12 @@ import lombok.Data;
@Data @Data
public class PatientVisitRecordStatisticVo { public class PatientVisitRecordStatisticVo {
/**
* 患者主键
*/
@ApiModelProperty(value = "患者主键")
private Long patientId;
/** /**
* 所属医院id * 所属医院id
*/ */

View File

@ -22,31 +22,55 @@ public class FollowUpDetailVo {
* 就诊/出院患者人数 * 就诊/出院患者人数
*/ */
@ApiModelProperty("就诊/出院患者人数") @ApiModelProperty("就诊/出院患者人数")
private Integer patientNum; private Integer patientNum = 0;
/** /**
* 有随访计划人数 * 有随访计划人数
*/ */
@ApiModelProperty("有随访计划人数") @ApiModelProperty("有随访计划人数")
private Integer followUpNum; private Integer followUpNum = 0;
/** /**
* 随访覆盖率 * 随访覆盖率
*/ */
@ApiModelProperty("随访覆盖率") @ApiModelProperty("随访覆盖率")
private BigDecimal followUpCoverRate; private BigDecimal followUpCoverRate = BigDecimal.ZERO;
/** /**
* 随访成功人数 * 随访成功人数
*/ */
@ApiModelProperty("随访成功人数") @ApiModelProperty("随访成功人数")
private Integer followUpSuccessNum; private Integer followUpSuccessNum = 0;
/** /**
* 随访成功率 * 随访成功率
*/ */
@ApiModelProperty("随访成功率") @ApiModelProperty("随访成功率")
private BigDecimal followUpSuccessRate; private BigDecimal followUpSuccessRate = BigDecimal.ZERO;
/**
* AI电话拨打次数
*/
@ApiModelProperty("AI电话拨打次数")
private Integer aiNum = 0;
/**
* AI电话拨打成功率
*/
@ApiModelProperty("AI电话拨打成功率")
private BigDecimal aiSuccessRate = BigDecimal.ZERO;
/**
* 人工电话拨打次数
*/
@ApiModelProperty("人工电话拨打次数")
private Integer commonNum = 0;
/**
* 人工电话拨打成功率
*/
@ApiModelProperty("人工电话拨打成功率")
private BigDecimal commonSuccessRate = BigDecimal.ZERO;
/** /**
* 下一级随访明细表 * 下一级随访明细表

View File

@ -502,7 +502,7 @@
</where> </where>
</select> </select>
<select id="getVisitPatientList" resultType="com.xinelu.manage.vo.patientvisitrecord.PatientVisitRecordStatisticVo"> <select id="getVisitPatientList" resultType="com.xinelu.manage.vo.patientvisitrecord.PatientVisitRecordStatisticVo">
select hospital_agency_id, hospital_agency_name, campus_agency_id, campus_agency_name, select patient_id, hospital_agency_id, hospital_agency_name, campus_agency_id, campus_agency_name,
department_id, department_name, ward_id, ward_name, department_id, department_name, ward_id, ward_name,
attending_physician_id,attending_physician_name, attending_physician_id,attending_physician_name,
date_format(discharge_time, '%Y-%m') as dischargeTimeMonthStr date_format(discharge_time, '%Y-%m') as dischargeTimeMonthStr

View File

@ -215,7 +215,7 @@
resultType="com.xinelu.manage.vo.statistics.MessageSendVo"> resultType="com.xinelu.manage.vo.statistics.MessageSendVo">
select select
record.patient_id, record.patient_id,
date_format(record.subscribe_time, '%Y-%m') as sendTimeMonthStr date_format(record.send_time, '%Y-%m') as sendTimeMonthStr
from short_message_send_record record left join patient_info patient on patient.id = record.patient_id from short_message_send_record record left join patient_info patient on patient.id = record.patient_id
<where> <where>
<if test="hospitalAgencyId != null"> <if test="hospitalAgencyId != null">

View File

@ -1027,10 +1027,10 @@
and task.ward_id = #{wardId} and task.ward_id = #{wardId}
</if> </if>
<if test="startDate != null"> <if test="startDate != null">
and task.date_format(execute_date_time,'%y%m') &gt;= date_format(#{startDate},'%y%m') and date_format(task.execute_date_time,'%y%m') &gt;= date_format(#{startDate},'%y%m')
</if> </if>
<if test="endDate != null"> <if test="endDate != null">
and task.date_format(execute_date_time,'%y%m') &lt;= date_format(#{endDate},'%y%m') and date_format(task.execute_date_time,'%y%m') &lt;= date_format(#{endDate},'%y%m')
</if> </if>
</where> </where>
</select> </select>