|
|
@ -0,0 +1,276 @@
|
|
|
package com.yihu.jw.hospital.endpoint.consult;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
|
|
|
import com.yihu.jw.entity.base.im.ConsultDo;
|
|
|
import com.yihu.jw.entity.base.im.ConsultTeamDo;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
|
|
|
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
|
|
|
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
|
|
|
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
|
|
|
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionEmrDO;
|
|
|
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
|
|
|
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
|
|
|
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
|
|
|
import com.yihu.jw.hospital.prescription.service.HcyyPrescriptionService;
|
|
|
import com.yihu.jw.hospital.prescription.service.PrescriptionService;
|
|
|
import com.yihu.jw.hospital.prescription.service.XzyyPrescriptionService;
|
|
|
import com.yihu.jw.hospital.prescription.service.entrance.EntranceService;
|
|
|
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
|
|
|
import com.yihu.jw.hospital.service.SystemMessage.HospitalSystemMessageService;
|
|
|
import com.yihu.jw.im.dao.ConsultDao;
|
|
|
import com.yihu.jw.im.service.ImService;
|
|
|
import com.yihu.jw.order.pay.ylz.YlzPayService;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.web.Envelop;
|
|
|
import com.yihu.jw.restmodel.web.ListEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.ObjEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
|
|
|
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
|
|
|
import com.yihu.jw.sms.service.ZhongShanSMSService;
|
|
|
import com.yihu.jw.util.common.IdCardUtil;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.util.entity.ServiceException;
|
|
|
import com.yihu.jw.utils.StringUtil;
|
|
|
import com.yihu.jw.wechat.service.WxTemplateService;
|
|
|
import com.yihu.jw.wlyy.service.WlyyBusinessService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/reportConsult/statistics")
|
|
|
public class DoctorConsultStatisticsEndpoint extends EnvelopRestEndpoint {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DoctorConsultStatisticsEndpoint.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ImService imService;
|
|
|
|
|
|
@Autowired
|
|
|
private ZhongShanSMSService smsService;
|
|
|
|
|
|
@Autowired
|
|
|
private PrescriptionService prescriptionService;
|
|
|
|
|
|
@Autowired
|
|
|
private BaseDoctorDao baseDoctorDao;
|
|
|
|
|
|
@Autowired
|
|
|
private OutpatientDao outpatientDao;
|
|
|
|
|
|
@Autowired
|
|
|
private WlyyBusinessService wlyyBusinessService;
|
|
|
|
|
|
@Autowired
|
|
|
private BaseDoctorHospitalDao baseDoctorHospitalDao;
|
|
|
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private HospitalSystemMessageService hospitalSystemMessageService;
|
|
|
@Autowired
|
|
|
public BasePatientDao basePatientDao;
|
|
|
@Autowired
|
|
|
private WxTemplateService wxTemplateService;
|
|
|
@Autowired
|
|
|
private XzyyPrescriptionService xzyyPrescriptionService;
|
|
|
@Autowired
|
|
|
private ConsultDao consultDao;
|
|
|
@Autowired
|
|
|
private YkyyEntranceService ykyyEntranceService;
|
|
|
@Autowired
|
|
|
private YlzPayService ylzPayService;
|
|
|
@Autowired
|
|
|
private PatientMappingDao patientMappingDao;
|
|
|
@Autowired
|
|
|
private PrescriptionDao prescriptionDao;
|
|
|
@Autowired
|
|
|
private EntranceService entranceService;
|
|
|
@Autowired
|
|
|
private HcyyPrescriptionService hcyyPrescriptionService;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Value("${wechat.id}")
|
|
|
private String wxId;
|
|
|
|
|
|
@Value("${demo.flag}")
|
|
|
private String demoFlag;
|
|
|
|
|
|
@GetMapping (value = "/statisticsData")
|
|
|
public Envelop statisticsData(
|
|
|
@ApiParam(name = "mediaType", value = "图文1,视频2")
|
|
|
@RequestParam(value = "mediaType",required = true) Integer mediaType,
|
|
|
@ApiParam(name = "aggField", value = "聚合方式 org dept doctor")
|
|
|
@RequestParam(value = "aggField",required = true) String aggField,
|
|
|
@ApiParam(name = "startTime", value = "开始时间")
|
|
|
@RequestParam(value = "startTime",required = true) String startTime,
|
|
|
@ApiParam(name = "endTime", value = "结束时间")
|
|
|
@RequestParam(value = "endTime",required = true) String endTime,
|
|
|
@ApiParam(name = "relationId", value = "机构id | 科室id")
|
|
|
@RequestParam(value = "relationId",required = false) String relationId,
|
|
|
@ApiParam(name = "pageNum", value = "pageNum")
|
|
|
@RequestParam(value = "pageNum",required = true) Integer pageNum,
|
|
|
@ApiParam(name = "pageSize", value = "pageSize")
|
|
|
@RequestParam(value = "pageSize",required = true) Integer pageSize) {
|
|
|
try {
|
|
|
|
|
|
String selectSql = "SELECT\n" +
|
|
|
"dh.org_code orgCode,dh.org_name orgName, " +
|
|
|
"COUNT(*) 'consultNum', " +
|
|
|
"COUNT(IF(`op`.`status` >= 1,1,null)) 'haveReceiveNum', " +
|
|
|
"COUNT(IF(`op`.`status` <= 0,1,null)) 'noReceiveNum', " +
|
|
|
"COUNT(IF(`op`.`status` = -1,1,null)) 'cancelNum' ";
|
|
|
|
|
|
String filterSql = " WHERE " +
|
|
|
" op.scbgjt IS NOT NULL AND op.create_time BETWEEN '"+startTime+"' AND '"+endTime+"' ";
|
|
|
|
|
|
String groupSql = "GROUP BY " +
|
|
|
" dh.org_code,dh.org_name";
|
|
|
|
|
|
if("org".equals(aggField)) {
|
|
|
selectSql += " FROM " +
|
|
|
" base_doctor_hospital dh LEFT JOIN wlyy_outpatient op ON dh.doctor_code=op.doctor ";
|
|
|
} else if("dept".equals(aggField)) {
|
|
|
selectSql += ",dh.dept_code deptCode,dh.dept_name deptName ";
|
|
|
selectSql += " FROM " +
|
|
|
" base_doctor_hospital dh LEFT JOIN wlyy_outpatient op ON dh.doctor_code=op.doctor ";
|
|
|
if(StringUtils.isBlank(relationId)) {
|
|
|
throw new ServiceException("参数未传");
|
|
|
}
|
|
|
filterSql += " AND dh.org_code = '" + relationId + "' ";
|
|
|
groupSql += " ,dh.dept_code,dh.dept_name ";
|
|
|
} else if("doctor".equals(aggField)) {
|
|
|
selectSql += ",dh.dept_code deptCode,dh.dept_name deptName,op.doctor,op.`doctor_name` doctorName ";
|
|
|
selectSql += " FROM " +
|
|
|
" base_doctor_hospital dh LEFT JOIN wlyy_outpatient op ON dh.doctor_code=op.doctor ";
|
|
|
if(StringUtils.isBlank(relationId)) {
|
|
|
throw new ServiceException("参数未传");
|
|
|
}
|
|
|
filterSql += " AND dh.dept_code='" + relationId + "' ";
|
|
|
groupSql += ",dh.dept_code,dh.dept_name,op.doctor,op.`doctor_name` ";
|
|
|
}
|
|
|
|
|
|
if("1".equals(mediaType)) {
|
|
|
filterSql += " (((`op`.`outpatient_type` = 3) AND (`op`.`type` = 1)) OR ((`op`.`outpatient_type` = 1) AND (`op`.`type` = 1))) ";
|
|
|
}
|
|
|
|
|
|
if("2".equals(mediaType)) {
|
|
|
filterSql += " (((`op`.`outpatient_type` = 1) AND (`op`.`type` = 2)) OR ((`op`.`outpatient_type` = 3) AND (`op`.`type` = 2))) ";
|
|
|
}
|
|
|
|
|
|
selectSql += filterSql;
|
|
|
selectSql += groupSql;
|
|
|
|
|
|
String countSql = " SELECT COUNT(*) FROM ( " + selectSql+" ) t ";
|
|
|
|
|
|
selectSql = selectSql + " limit " + (pageNum-1)*pageSize +","+ pageSize;
|
|
|
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(selectSql);
|
|
|
Integer total = jdbcTemplate.queryForObject(countSql, Integer.class);
|
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("total",total);
|
|
|
result.put("list",list);
|
|
|
return success("请求成功",result);
|
|
|
}catch (Exception e){
|
|
|
return failedListEnvelopException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@GetMapping (value = "/statisticsGraph")
|
|
|
public Envelop statisticsGraph(
|
|
|
@ApiParam(name = "mediaType", value = "图文1,视频2")
|
|
|
@RequestParam(value = "mediaType",required = true) Integer mediaType,
|
|
|
@ApiParam(name = "aggField", value = "聚合方式 org dept doctor")
|
|
|
@RequestParam(value = "aggField",required = true) String aggField,
|
|
|
@ApiParam(name = "startTime", value = "开始时间")
|
|
|
@RequestParam(value = "startTime",required = true) String startTime,
|
|
|
@ApiParam(name = "endTime", value = "结束时间")
|
|
|
@RequestParam(value = "endTime",required = true) String endTime,
|
|
|
@ApiParam(name = "relationId", value = "机构id | 科室id")
|
|
|
@RequestParam(value = "relationId",required = false) String relationId) {
|
|
|
try {
|
|
|
|
|
|
String selectSql = "SELECT " +
|
|
|
"DATE(op.create_time) AS 'statDate',dh.org_code,dh.org_name, " +
|
|
|
"COUNT(*) 'consultNum', " +
|
|
|
"COUNT(IF(`op`.`status` >= 1,1,null)) 'haveReceiveNum', " +
|
|
|
"COUNT(IF(`op`.`status` <= 0,1,null)) 'noReceiveNum', " +
|
|
|
"COUNT(IF(`op`.`status` = -1,1,null)) 'cancelNum' ";
|
|
|
|
|
|
String filterSql = " WHERE " +
|
|
|
" op.scbgjt IS NOT NULL AND op.create_time BETWEEN '"+startTime+"' AND '"+endTime+"' ";
|
|
|
|
|
|
String groupSql = "GROUP BY DATE(op.create_time)," +
|
|
|
" dh.org_code,dh.org_name";
|
|
|
|
|
|
if("org".equals(aggField)) {
|
|
|
selectSql += " FROM " +
|
|
|
" base_doctor_hospital dh LEFT JOIN wlyy_outpatient op ON dh.doctor_code=op.doctor ";
|
|
|
} else if("dept".equals(aggField)) {
|
|
|
String groupField = ",dh.dept_code,dh.dept_name ";
|
|
|
selectSql += groupField;
|
|
|
selectSql += " FROM " +
|
|
|
" base_doctor_hospital dh LEFT JOIN wlyy_outpatient op ON dh.doctor_code=op.doctor ";
|
|
|
if(StringUtils.isBlank(relationId)) {
|
|
|
throw new ServiceException("参数未传");
|
|
|
}
|
|
|
filterSql += " AND dh.org_code = '" + relationId + "' ";
|
|
|
groupSql += groupField;
|
|
|
} else if("doctor".equals(aggField)) {
|
|
|
String groupField = ",dh.dept_code,dh.dept_name,op.doctor,op.`doctor_name` ";
|
|
|
selectSql += groupField;
|
|
|
selectSql += " FROM " +
|
|
|
" base_doctor_hospital dh LEFT JOIN wlyy_outpatient op ON dh.doctor_code=op.doctor ";
|
|
|
if(StringUtils.isBlank(relationId)) {
|
|
|
throw new ServiceException("参数未传");
|
|
|
}
|
|
|
filterSql += " AND dh.dept_code='" + relationId + "' ";
|
|
|
groupSql += groupField;
|
|
|
}
|
|
|
|
|
|
if("1".equals(mediaType)) {
|
|
|
filterSql += " (((`op`.`outpatient_type` = 3) AND (`op`.`type` = 1)) OR ((`op`.`outpatient_type` = 1) AND (`op`.`type` = 1))) ";
|
|
|
}
|
|
|
|
|
|
if("2".equals(mediaType)) {
|
|
|
filterSql += " (((`op`.`outpatient_type` = 1) AND (`op`.`type` = 2)) OR ((`op`.`outpatient_type` = 3) AND (`op`.`type` = 2))) ";
|
|
|
}
|
|
|
|
|
|
selectSql += filterSql;
|
|
|
selectSql += groupSql;
|
|
|
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(selectSql);
|
|
|
|
|
|
return success("请求成功",list);
|
|
|
}catch (Exception e){
|
|
|
return failedListEnvelopException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|