|
@ -2308,214 +2308,6 @@ public class RehabilitationManageService {
|
|
|
return medicalRecordsRehabilitationDao.findByPatient(patient);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param doctorType 1专科2家医
|
|
|
* @param level 1市2区3社区
|
|
|
* @param turnDownState 下转状态 0全部;1已下转;2已接受;3未下转
|
|
|
* @param area
|
|
|
* @param doctor
|
|
|
* @return
|
|
|
*/
|
|
|
public org.json.JSONObject selectBySpecialistDoctor(String level, String area, String doctor, String disease, Integer page, Integer pageSize, String doctorType, String patientInfo, String filterPlan, String turnDownState) {
|
|
|
Integer turnDownStateTotal_0 = 0;//全部
|
|
|
Integer turnDownStateTotal_1 = 0;//已下转
|
|
|
Integer turnDownStateTotal_2 = 0;//已接受
|
|
|
Integer turnDownStateTotal_3 = 0;//未下转
|
|
|
org.json.JSONObject resultObj = new org.json.JSONObject();
|
|
|
BaseDoctorDO doctorObj = doctorDao.findById(doctor).orElse(null);
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
String sqlCount = "SELECT count(distinct pr.id) total,count(distinct pr.id,IF(pr.is_manage=1,pr.is_manage,null) ) 'manageTotal' FROM" +
|
|
|
" wlyy_doctor doc,`wlyy_specialist_patient_relation` pr" +
|
|
|
" LEFT JOIN wlyy_patient p ON p.`code` = pr.patient ";
|
|
|
String sql = "SELECT DISTINCT pr.id,p.`name`, p.`code`, p.idcard,p.photo, YEAR (now()) - YEAR (substring(p.idcard, 7, 8)) as age," +
|
|
|
"p.sex,pr.doctor AS specialist,pr.doctor_name AS specialistName,doc.hospital AS specialHospital,doc.hospital_name AS specialHospitalName,pr.disease_code,sf.doctor_name ," +
|
|
|
"sf.doctor, sf.doctor_health, sf.doctor_health_name, sf.hospital, sf.hospital_name,pr.is_manage,pr.manage_user,pr.manage_time FROM" +
|
|
|
" wlyy_doctor doc,`wlyy_specialist_patient_relation` pr" +
|
|
|
" LEFT JOIN wlyy_patient p ON p.`code` = pr.patient ";
|
|
|
//关联居民计划表
|
|
|
if ("1".equals(filterPlan)) {
|
|
|
sql = sql + " INNER JOIN `wlyy_patient_rehabilitation_plan` plan on plan.patient = pr.patient ";
|
|
|
sqlCount = sqlCount + " INNER JOIN `wlyy_patient_rehabilitation_plan` plan on plan.patient = pr.patient ";
|
|
|
}
|
|
|
sql = sql + " LEFT JOIN wlyy_sign_family sf ON sf.patient=pr.patient AND sf.`status`=1 AND sf.type =2" +
|
|
|
" WHERE doc.`code` = pr.doctor AND pr.sign_status > 0 AND pr.`status` = 1 ";
|
|
|
sqlCount = sqlCount + " LEFT JOIN wlyy_sign_family sf ON sf.patient=pr.patient AND sf.`status`=1 AND sf.type =2" +
|
|
|
" WHERE doc.`code` = pr.doctor AND pr.sign_status > 0 AND pr.`status` = 1 ";
|
|
|
|
|
|
String sqlCondition = "";
|
|
|
if (doctorType.equalsIgnoreCase("1")) {
|
|
|
sqlCondition += " AND pr.doctor = '" + doctor + "'";
|
|
|
} else {
|
|
|
// todo 这个后面在改20231116
|
|
|
// if (doctorObj.getHospital().equals("ac02a9b87a3611e69f7c005056850d66")) {
|
|
|
// //测试医院
|
|
|
// sqlCondition += " AND (sf.doctor = '" + doctor + "' or sf.doctor_health = '" + doctor + "')";
|
|
|
// } else {
|
|
|
// //排除测试医院的数据
|
|
|
// sqlCondition += " AND (sf.doctor = '" + doctor + "' or sf.doctor_health = '" + doctor + "') AND doc.hospital <>'ac02a9b87a3611e69f7c005056850d66'";
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNoneBlank(patientInfo)) {
|
|
|
sqlCondition += " AND (p.idcard like '%" + patientInfo + "%' OR p.`name`like '%" + patientInfo + "%') ";
|
|
|
}
|
|
|
if ("1".equalsIgnoreCase(level)) {
|
|
|
// sqlCondition +=" and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.city='"+area+"' and dh.del=1 )";
|
|
|
} else if ("2".equalsIgnoreCase(level)) {
|
|
|
sqlCondition += " and sf.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.town='" + area + "' and dh.del=1 )";
|
|
|
} else if ("3".equalsIgnoreCase(level)) {
|
|
|
sqlCondition += " and sf.hospital = '" + area + "' ";
|
|
|
}
|
|
|
if (StringUtils.isNoneBlank(disease)) {
|
|
|
sqlCondition += " and pr.id IN (SELECT pds.specialist_relation_code FROM wlyy_patient_disease_server pds WHERE pds.del=1 and pds.disease ='" + disease + "')";
|
|
|
}
|
|
|
|
|
|
sqlCount += sqlCondition;
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sqlCount);
|
|
|
Map<String, Object> tmp = list.get(0);
|
|
|
turnDownStateTotal_0 = Integer.valueOf(tmp.get("total").toString());
|
|
|
turnDownStateTotal_2 += Integer.valueOf(tmp.get("manageTotal").toString());
|
|
|
turnDownStateTotal_1 = turnDownStateTotal_0 - turnDownStateTotal_2;
|
|
|
|
|
|
if ("1".equals(filterPlan)) {
|
|
|
sqlCondition += " ORDER BY pr.create_time DESC,plan.create_time desc limit " + (page - 1) * pageSize + "," + pageSize + " ";
|
|
|
} else {
|
|
|
sqlCondition += " ORDER BY pr.create_time DESC limit " + (page - 1) * pageSize + "," + pageSize + " ";
|
|
|
}
|
|
|
sql += sqlCondition;
|
|
|
|
|
|
//字典翻译
|
|
|
Map<String, String> changeStatusMap = systemDictService.getDictMap("changeStatusName");
|
|
|
|
|
|
sql = TransforSqlUtl.wlyySpecialistPatientRelationPatientName(sql, "pr.doctor_name");
|
|
|
Map<String, Integer> countMap = new HashMap<>();
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String, Object> map : mapList) {
|
|
|
String patient = map.get("code").toString();
|
|
|
BasePatientDO patientDo = patientDao.findById(patient).orElse(null);
|
|
|
Integer age = IdCardUtil.getAgeByIdcardOrBirthday(patientDo.getIdcard(), patientDo.getBirthday());
|
|
|
map.put("age", age);
|
|
|
String specialistRelationCode = map.get("id").toString();
|
|
|
String relationManageState = map.get("is_manage") == null ? "0" : map.get("is_manage").toString();//管理状态
|
|
|
List<PatientDiseaseServer> diseaseServers = patientDiseaseServerDao.findBySpecialistRelationCodeAndDel(specialistRelationCode, "1");
|
|
|
StringBuffer diseaseName = new StringBuffer();
|
|
|
for (int i = 0; i < diseaseServers.size(); i++) {
|
|
|
diseaseName.append(diseaseServers.get(i).getDiseaseName() + ",");
|
|
|
}
|
|
|
if (StringUtils.isNoneBlank(diseaseName)) {
|
|
|
diseaseName.deleteCharAt(diseaseName.length() - 1);
|
|
|
}
|
|
|
map.put("disease_name", diseaseName);
|
|
|
|
|
|
if (countMap.containsKey(patient)) {
|
|
|
map.put("unCompleteCount", countMap.get(patient));
|
|
|
} else {
|
|
|
//计算待完成任务数
|
|
|
String unCompleteCountSql = "SELECT COUNT(*) from ( SELECT COUNT(pd.id) AS total,pd.hospital_service_item_id,p.id , COUNT( IF(pd.`status` = 1,1,null)) AS compeletTotal" +
|
|
|
" FROM wlyy_patient_rehabilitation_plan p,wlyy_rehabilitation_plan_detail pd WHERE p.status=1 and " +
|
|
|
" p.patient = '" + patient + "' and pd.plan_id = p.id AND pd.frequency_code <> '' and pd.doctor='" + doctor + "' and pd.execute_time<'" + DateUtil.getStringDateShort() + " 23:59:59' " +
|
|
|
" GROUP BY pd.hospital_service_item_id,p.id HAVING total>compeletTotal) a";
|
|
|
Integer unCompleteCount = jdbcTemplate.queryForObject(unCompleteCountSql, Integer.class);
|
|
|
map.put("unCompleteCount", unCompleteCount);
|
|
|
countMap.put(patient, unCompleteCount);
|
|
|
}
|
|
|
|
|
|
//新增特殊标识-获取最近一条记录的特殊标识
|
|
|
String changeStatus = findLastPlanChangeStatus(patient);
|
|
|
map.put("changeStatus", changeStatus);
|
|
|
map.put("changeStatusName", changeStatusMap.get(changeStatus));
|
|
|
if (StringUtils.isBlank(relationManageState) || !relationManageState.equals("1")) {//未进行管理
|
|
|
map.put("turnDownState", 1);//已下转
|
|
|
if ("1".equals(turnDownState) || "0".equals(turnDownState)) {
|
|
|
result.add(map);
|
|
|
}
|
|
|
} else {
|
|
|
map.put("turnDownState", 2);//已管理
|
|
|
if (turnDownState.equals("2") || turnDownState.equals("0")) {
|
|
|
result.add(map);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//家医端未下转(签约居民,但是还未下转的居民) 专科医生端未下转(与未下转列表同-去除未家签)
|
|
|
if ("1".equalsIgnoreCase(doctorType)) {//专科
|
|
|
sql = "select null as id,p.`name`,p.`code`,p.idcard,p.photo,YEAR (now()) - YEAR (substring(p.idcard, 7, 8)) AS age, p.sex,d.create_user AS specialist,d.create_user_name AS specialistName,\n" +
|
|
|
"doc.hospital AS specialHospital,doc.hospital_name AS specialHospitalName,s.doctor_name,s.doctor,s.doctor_health,s.doctor_health_name, s.hospital,s.hospital_name,null as is_manage,null as manage_user,null as manage_time \n" +
|
|
|
"from wlyy_patient_discharge d LEFT JOIN ( SELECT distinct i.patient FROM wlyy_patient_rehabilitation_plan i,wlyy_sign_family s,wlyy_patient p " +
|
|
|
"WHERE i.create_user='" + doctor + "' AND i. STATUS != 0 AND i.patient = s.patient AND p. CODE = i.patient AND s. STATUS = 1 AND s.type =2 AND s.expenses_status = 1 )A on d.patient =A.patient " +
|
|
|
" ,wlyy_sign_family s,wlyy_patient p ,wlyy_doctor doc where doc.`code` = d.create_user AND d.create_user='" + doctor + "' ";
|
|
|
sqlCount = "select count(distinct d.patient) " +
|
|
|
"from wlyy_patient_discharge d LEFT JOIN ( SELECT distinct i.patient FROM wlyy_patient_rehabilitation_plan i,wlyy_sign_family s,wlyy_patient p " +
|
|
|
"WHERE i.create_user='" + doctor + "' AND i. STATUS != 0 AND i.patient = s.patient AND p. CODE = i.patient AND s. STATUS = 1 AND s.type =2 AND s.expenses_status = 1 )A on d.patient =A.patient " +
|
|
|
" ,wlyy_sign_family s,wlyy_patient p ,wlyy_doctor doc where doc.`code` = d.create_user AND d.create_user='" + doctor + "' ";
|
|
|
} else {//家庭
|
|
|
sql = "select null as id,p.`name`,p.`code`,p.idcard,p.photo,YEAR (now()) - YEAR (substring(p.idcard, 7, 8)) AS age, p.sex,d.create_user AS specialist,d.create_user_name AS specialistName,\n" +
|
|
|
"doc.hospital AS specialHospital,doc.hospital_name AS specialHospitalName,s.doctor_name,s.doctor,s.doctor_health,s.doctor_health_name, s.hospital,s.hospital_name,null as is_manage,null as manage_user,null as manage_time \n" +
|
|
|
"from wlyy_patient_discharge d LEFT JOIN ( SELECT distinct i.patient FROM wlyy_patient_rehabilitation_plan i,wlyy_sign_family s,wlyy_patient p " +
|
|
|
"WHERE s.doctor='" + doctor + "' AND i. STATUS != 0 AND i.patient = s.patient AND p. CODE = i.patient AND s. STATUS = 1 AND s.type =2 AND s.expenses_status = 1 )A on d.patient =A.patient " +
|
|
|
",wlyy_sign_family s,wlyy_patient p ,wlyy_doctor doc where doc.`code` = d.create_user AND s.doctor='" + doctor + "' ";
|
|
|
sqlCount = "select count(distinct d.patient) " +
|
|
|
"from wlyy_patient_discharge d LEFT JOIN ( SELECT distinct i.patient FROM wlyy_patient_rehabilitation_plan i,wlyy_sign_family s,wlyy_patient p " +
|
|
|
"WHERE s.doctor='" + doctor + "' AND i. STATUS != 0 AND i.patient = s.patient AND p. CODE = i.patient AND s. STATUS = 1 AND s.type =2 AND s.expenses_status = 1 )A on d.patient =A.patient " +
|
|
|
",wlyy_sign_family s,wlyy_patient p ,wlyy_doctor doc where doc.`code` = d.create_user AND s.doctor='" + doctor + "' ";
|
|
|
}
|
|
|
sqlCondition = "";
|
|
|
|
|
|
if (StringUtils.isNoneBlank(patientInfo)) {
|
|
|
sqlCondition += " AND (p.idcard like '%" + patientInfo + "%' OR p.`name`like '%" + patientInfo + "%') ";
|
|
|
}
|
|
|
if ("1".equalsIgnoreCase(level)) {
|
|
|
// sqlCondition +=" and s.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.city='"+area+"' and dh.del=1 )";
|
|
|
} else if ("2".equalsIgnoreCase(level)) {
|
|
|
sqlCondition += " and s.hospital IN ( SELECT dh.`code` FROM `dm_hospital` dh where dh.town='" + area + "' and dh.del=1 )";
|
|
|
} else if ("3".equalsIgnoreCase(level)) {
|
|
|
sqlCondition += " and s.hospital = '" + area + "' ";
|
|
|
}
|
|
|
|
|
|
// if (!doctorObj.getHospital().equals("ac02a9b87a3611e69f7c005056850d66")) {//测试医院数据排除
|
|
|
// sqlCondition += " AND doc.hospital <>'ac02a9b87a3611e69f7c005056850d66'";
|
|
|
// }
|
|
|
if (StringUtils.isNoneBlank(disease)) {
|
|
|
sqlCondition += " AND s.patient in (select patient from wlyy_patient_disease_server pds where pds.del=1 and pds.disease ='" + disease + "') ";
|
|
|
}
|
|
|
|
|
|
sql = sql + sqlCondition;
|
|
|
sql = sql + "and ( ISNULL(d.type) or d.type=2) \n" +
|
|
|
"and d.sign_status=1 AND d.patient = s.patient AND p. CODE = d.patient AND s. STATUS = 1 AND s.expenses_status = 1\n" +
|
|
|
"AND A.patient is null GROUP BY d.patient ORDER BY d.create_time DESC limit " + (page - 1) * pageSize + "," + pageSize + " ";
|
|
|
sqlCount = sqlCount + sqlCondition;
|
|
|
sqlCount = sqlCount + "and ( ISNULL(d.type) or d.type=2) \n" +
|
|
|
"and d.sign_status=1 AND d.patient = s.patient AND p. CODE = d.patient AND s. STATUS = 1 AND s.expenses_status = 1\n" +
|
|
|
"AND A.patient is null ";
|
|
|
|
|
|
turnDownStateTotal_3 = jdbcTemplate.queryForObject(sqlCount, Integer.class);
|
|
|
turnDownStateTotal_0 += turnDownStateTotal_3;
|
|
|
List<Map<String, Object>> mapList12 = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String, Object> map : mapList12) {
|
|
|
String patient = map.get("code").toString();
|
|
|
BasePatientDO patientDo = patientDao.findById(patient).orElse(null);
|
|
|
Integer age = IdCardUtil.getAgeByIdcardOrBirthday(patientDo.getIdcard(), patientDo.getBirthday());
|
|
|
map.put("age", age);
|
|
|
map.put("disease_name", "暂无");
|
|
|
map.put("turnDownState", 3);//未下
|
|
|
//新增特殊标识-获取最近一条记录的特殊标识
|
|
|
String changeStatus = findLastPlanChangeStatus(patient);
|
|
|
map.put("changeStatus", changeStatus);
|
|
|
if ("3".equals(turnDownState) || "0".equals(turnDownState)) {
|
|
|
result.add(map);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//计算各数量
|
|
|
org.json.JSONObject turnDownStateObj = new org.json.JSONObject();
|
|
|
turnDownStateObj.put("stateAll", turnDownStateTotal_0);//全部
|
|
|
turnDownStateObj.put("stateDown", turnDownStateTotal_1);//已下转
|
|
|
turnDownStateObj.put("stateReceive", turnDownStateTotal_2);//已接受
|
|
|
turnDownStateObj.put("stateNotDown", turnDownStateTotal_3);//未下转
|
|
|
resultObj.put("showList", result);
|
|
|
resultObj.put("turnDownState", turnDownStateObj);
|
|
|
return resultObj;
|
|
|
}
|
|
|
|
|
|
//获取最近一条康复计划记录的特殊标识
|
|
|
public String findLastPlanChangeStatus(String patient) {
|