|
@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@ -42,64 +43,28 @@ public class ServiceStatisticsService extends BaseService {
|
|
|
@Autowired
|
|
|
private ElasticsearchUtil elasticsearchUtil;
|
|
|
|
|
|
public JSONObject getServiceStatistics(String patient, long teamCode, String doctor) throws Exception {
|
|
|
public JSONObject getServiceStatistics(String patient, String doctor) throws Exception {
|
|
|
JSONObject result = new JSONObject();
|
|
|
AdminTeam team = teamService.getTeam(teamCode);
|
|
|
SignFamily signFamily = signFamilyDao.findByPatientAndAdminTeamId(patient, teamCode, 2);
|
|
|
|
|
|
if (signFamily == null) {
|
|
|
signFamily = signFamilyDao.findByPatientAndAdminTeamId(patient, teamCode, 1);
|
|
|
|
|
|
if (signFamily == null) {
|
|
|
throw new Exception("patient and doctor no sign relation");
|
|
|
} else {
|
|
|
if((!doctor.equals(team.getLeaderCode()) && !doctor.equals(signFamily.getDoctor())
|
|
|
&& !doctor.equals(signFamily.getDoctorHealth()))) {
|
|
|
throw new Exception("patient and doctor no sign relation");
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if((!doctor.equals(team.getLeaderCode()) && !doctor.equals(signFamily.getDoctor())
|
|
|
&& !doctor.equals(signFamily.getDoctorHealth()))) {
|
|
|
signFamily = signFamilyDao.findByPatientAndAdminTeamId(patient, teamCode, 1);
|
|
|
|
|
|
if (signFamily == null) {
|
|
|
throw new Exception("patient and doctor no sign relation");
|
|
|
} else {
|
|
|
if((!doctor.equals(team.getLeaderCode()) && !doctor.equals(signFamily.getDoctor())
|
|
|
&& !doctor.equals(signFamily.getDoctorHealth()))) {
|
|
|
throw new Exception("patient and doctor no sign relation");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (signFamily == null) {
|
|
|
signFamily = signFamilyDao.findByPatientAndAdminTeamId(patient, teamCode, 1);
|
|
|
|
|
|
if (signFamily == null) {
|
|
|
throw new Exception("sign info can not find");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Calendar today = Calendar.getInstance();
|
|
|
today.set(Calendar.DATE, 1);
|
|
|
String monthBegin = DateUtil.dateToStrShort(today.getTime()) + " 00:00:00";
|
|
|
String yearBegin = DateUtil.dateToStrShort(signFamily.getBegin()) + " 00:00:00";
|
|
|
String yearEnd = DateUtil.dateToStrShort(signFamily.getEnd()) + " 23:59:59";
|
|
|
JSONObject consult = getConsultStatistics(patient, teamCode, yearBegin, yearEnd, monthBegin);
|
|
|
String yearBegin = "2018-01-01 00:00:00";
|
|
|
String yearEnd = DateUtil.dateToStrShort(new Date()) + " 23:59:59";
|
|
|
JSONObject consult = getConsultStatistics(patient, doctor, yearBegin, yearEnd, monthBegin);
|
|
|
result.put("consult", consult);
|
|
|
|
|
|
JSONObject followup = getFollowupStatistics(patient, teamCode, yearBegin, yearEnd, monthBegin);
|
|
|
JSONObject followup = getFollowupStatistics(patient, doctor, yearBegin, yearEnd, monthBegin);
|
|
|
result.put("followup", followup);
|
|
|
|
|
|
JSONObject reservation = getReservationStatistics(patient, teamCode, yearBegin, yearEnd, monthBegin);
|
|
|
JSONObject reservation = getReservationStatistics(patient, doctor, yearBegin, yearEnd, monthBegin);
|
|
|
result.put("reservation", reservation);
|
|
|
|
|
|
JSONObject guidance = getGuidanceStatistics(patient, teamCode, yearBegin, yearEnd, monthBegin);
|
|
|
JSONObject guidance = getGuidanceStatistics(patient, doctor, yearBegin, yearEnd, monthBegin);
|
|
|
result.put("guidance", guidance);
|
|
|
|
|
|
JSONObject article = getArticleStatistics(patient, teamCode, DateUtil.dateToStrShort(signFamily.getBegin()), DateUtil.dateToStrShort(signFamily.getEnd()), DateUtil.dateToStrShort(today.getTime()));
|
|
|
JSONObject article = getArticleStatistics(patient, doctor, "2018-01-01", DateUtil.dateToStrShort(new Date()), DateUtil.dateToStrShort(today.getTime()));
|
|
|
result.put("article", article);
|
|
|
|
|
|
return result;
|
|
@ -115,21 +80,21 @@ public class ServiceStatisticsService extends BaseService {
|
|
|
* @param monthBegin
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getConsultStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
public JSONObject getConsultStatistics(String patient, String doctor, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("history", 0);
|
|
|
result.put("history", 0);
|
|
|
result.put("history", 0);
|
|
|
String sqlHistory = "select count(1) h from wlyy_consult_team where patient = ? and admin_team_code = ?";
|
|
|
String sqlYear = "select count(1) y from wlyy_consult_team where patient = ? and admin_team_code = ? and czrq >= ? and czrq <= ?";
|
|
|
String sqlMonth = "select count(1) m from wlyy_consult_team where patient = ? and admin_team_code = ? and czrq >= ?";
|
|
|
String sqlHistory = "select count(1) h from wlyy_consult_team where patient = ? and doctor = ?";
|
|
|
String sqlYear = "select count(1) y from wlyy_consult_team where patient = ? and doctor = ? and czrq >= ? and czrq <= ?";
|
|
|
String sqlMonth = "select count(1) m from wlyy_consult_team where patient = ? and doctor = ? and czrq >= ?";
|
|
|
String sql = "select * from " +
|
|
|
"(" + sqlHistory + ") a" +
|
|
|
",(" + sqlYear + ") b" +
|
|
|
",(" + sqlMonth + ") c";
|
|
|
|
|
|
List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, teamCode,
|
|
|
patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin
|
|
|
List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, doctor,
|
|
|
patient, doctor, yearBegin, yearEnd, patient, doctor, monthBegin
|
|
|
});
|
|
|
|
|
|
if (counts != null && counts.size() > 0) {
|
|
@ -145,13 +110,13 @@ public class ServiceStatisticsService extends BaseService {
|
|
|
* 健康教育统计
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param teamCode
|
|
|
* @param doctor
|
|
|
* @param yearBegin
|
|
|
* @param yearEnd
|
|
|
* @param monthBegin
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getArticleStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
public JSONObject getArticleStatistics(String patient, String doctor, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("history", 0);
|
|
|
result.put("year", 0);
|
|
@ -175,9 +140,9 @@ public class ServiceStatisticsService extends BaseService {
|
|
|
}*/
|
|
|
|
|
|
//数据转移至Es
|
|
|
String sqlHistory="select count(*) AS h from " + esType + " where patientCode='" + patient + "' and adminTeamCode = '"+teamCode+"'";
|
|
|
String sqlYear = "select count(*) AS y from "+esType+" where patientCode='" + patient + "' and adminTeamCode = '"+teamCode+"' and createTime >= '"+changeDate(yearBegin)+"' and createTime <= '"+changeDate(yearEnd)+"'";
|
|
|
String sqlMonth = "select count(*) AS m from "+esType+" where patientCode='" + patient + "' and adminTeamCode = '"+teamCode+"' and createTime >= '"+changeDate(monthBegin)+"'";
|
|
|
String sqlHistory="select count(*) AS h from " + esType + " where patientCode='" + patient + "' and doctorCode = '"+doctor+"'";
|
|
|
String sqlYear = "select count(*) AS y from "+esType+" where patientCode='" + patient + "' and doctorCode = '"+doctor+"' and createTime >= '"+changeDate(yearBegin)+"' and createTime <= '"+changeDate(yearEnd)+"'";
|
|
|
String sqlMonth = "select count(*) AS m from "+esType+" where patientCode='" + patient + "' and doctorCode = '"+doctor+"' and createTime >= '"+changeDate(monthBegin)+"'";
|
|
|
|
|
|
result.put("history", elasticsearchUtil.excuteForLong(sqlHistory,esType,esIndex));
|
|
|
result.put("year", elasticsearchUtil.excuteForLong(sqlYear,esType,esIndex));
|
|
@ -195,27 +160,27 @@ public class ServiceStatisticsService extends BaseService {
|
|
|
* 健康指导统计
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param teamCode
|
|
|
* @param doctor
|
|
|
* @param yearBegin
|
|
|
* @param yearEnd
|
|
|
* @param monthBegin
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getGuidanceStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
public JSONObject getGuidanceStatistics(String patient, String doctor, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("history", 0);
|
|
|
result.put("year", 0);
|
|
|
result.put("month", 0);
|
|
|
String sqlHistory = "select count(1) h from wlyy_patient_health_guidance where patient = ? and admin_team_code = ?";
|
|
|
String sqlYear = "select count(1) y from wlyy_patient_health_guidance where patient = ? and admin_team_code = ? and czrq >= ? and czrq <= ?";
|
|
|
String sqlMonth = "select count(1) m from wlyy_patient_health_guidance where patient = ? and admin_team_code = ? and czrq >= ?";
|
|
|
String sqlHistory = "select count(1) h from wlyy_patient_health_guidance where patient = ? and doctor = ?";
|
|
|
String sqlYear = "select count(1) y from wlyy_patient_health_guidance where patient = ? and doctor = ? and czrq >= ? and czrq <= ?";
|
|
|
String sqlMonth = "select count(1) m from wlyy_patient_health_guidance where patient = ? and doctor = ? and czrq >= ?";
|
|
|
String sql = "select * from " +
|
|
|
"(" + sqlHistory + ") a" +
|
|
|
",(" + sqlYear + ") b" +
|
|
|
",(" + sqlMonth + ") c";
|
|
|
|
|
|
List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, teamCode,
|
|
|
patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin
|
|
|
List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, doctor,
|
|
|
patient, doctor, yearBegin, yearEnd, patient, doctor, monthBegin
|
|
|
});
|
|
|
|
|
|
if (counts != null && counts.size() > 0) {
|
|
@ -231,20 +196,19 @@ public class ServiceStatisticsService extends BaseService {
|
|
|
* 随访计划统计
|
|
|
*
|
|
|
* @param patient
|
|
|
* @param teamCode
|
|
|
* @param yearBegin
|
|
|
* @param yearEnd
|
|
|
* @param monthBegin
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getFollowupStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
public JSONObject getFollowupStatistics(String patient, String doctor, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("history", 0);
|
|
|
result.put("year", 0);
|
|
|
result.put("month", 0);
|
|
|
String sqlHistory = "select count(1) h from wlyy_followup where patient_code = ? and admin_team_code = ?";
|
|
|
String sqlYear = "select count(1) y from wlyy_followup where patient_code = ? and admin_team_code = ? and create_time >= ? and create_time <= ?";
|
|
|
String sqlMonth = "select count(1) m from wlyy_followup where patient_code = ? and admin_team_code = ? and create_time >= ?";
|
|
|
String sqlHistory = "select count(1) h from wlyy_followup where patient_code = ? and doctor_code = ?";
|
|
|
String sqlYear = "select count(1) y from wlyy_followup where patient_code = ? and doctor_code = ? and create_time >= ? and create_time <= ?";
|
|
|
String sqlMonth = "select count(1) m from wlyy_followup where patient_code = ? and doctor_code = ? and create_time >= ?";
|
|
|
String sql = "select * from " +
|
|
|
"(" + sqlHistory + " and status > 0" + ") a" +
|
|
|
",(" + sqlYear + " and status > 0" + ") b" +
|
|
@ -253,9 +217,9 @@ public class ServiceStatisticsService extends BaseService {
|
|
|
",(" + sqlYear.replace(" y ", " yy ") + " and status = 1" + ") e" +
|
|
|
",(" + sqlMonth.replace(" m ", " mm ") + " and status = 1" + ") f";
|
|
|
|
|
|
List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, teamCode,
|
|
|
patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin, patient, teamCode,
|
|
|
patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin
|
|
|
List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, doctor,
|
|
|
patient, doctor, yearBegin, yearEnd, patient, doctor, monthBegin, patient, doctor,
|
|
|
patient, doctor, yearBegin, yearEnd, patient, doctor, monthBegin
|
|
|
});
|
|
|
|
|
|
if (counts != null && counts.size() > 0) {
|
|
@ -278,21 +242,21 @@ public class ServiceStatisticsService extends BaseService {
|
|
|
* @param monthBegin
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getReservationStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
public JSONObject getReservationStatistics(String patient, String doctor, String yearBegin, String yearEnd, String monthBegin) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("history", 0);
|
|
|
result.put("year", 0);
|
|
|
result.put("month", 0);
|
|
|
String sqlHistory = "select count(1) h from wlyy_patient_reservation where patient = ? and admin_team_code = ?";
|
|
|
String sqlYear = "select count(1) y from wlyy_patient_reservation where patient = ? and admin_team_code = ? and czrq >= ? and czrq <= ?";
|
|
|
String sqlMonth = "select count(1) m from wlyy_patient_reservation where patient = ? and admin_team_code = ? and czrq >= ?";
|
|
|
String sqlHistory = "select count(1) h from wlyy_patient_reservation where patient = ? and doctor = ?";
|
|
|
String sqlYear = "select count(1) y from wlyy_patient_reservation where patient = ? and doctor = ? and czrq >= ? and czrq <= ?";
|
|
|
String sqlMonth = "select count(1) m from wlyy_patient_reservation where patient = ? and doctor = ? and czrq >= ?";
|
|
|
String sql = "select * from " +
|
|
|
"(" + sqlHistory + ") a" +
|
|
|
",(" + sqlYear + ") b" +
|
|
|
",(" + sqlMonth + ") c";
|
|
|
|
|
|
List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, teamCode,
|
|
|
patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin
|
|
|
List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, doctor,
|
|
|
patient, doctor, yearBegin, yearEnd, patient, doctor, monthBegin
|
|
|
});
|
|
|
|
|
|
if (counts != null && counts.size() > 0) {
|