|
@ -4,14 +4,18 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.door.SignFamily;
|
|
|
import com.yihu.jw.entity.specialist.SpecialistPatientRelationDO;
|
|
|
import com.yihu.jw.entity.specialist.rehabilitation.*;
|
|
|
import com.yihu.jw.entity.util.TransforSqlUtl;
|
|
|
import com.yihu.jw.hospital.module.rehabilitation.dao.*;
|
|
|
import com.yihu.jw.hospital.module.specialist.dao.PatientDiseaseServerDao;
|
|
|
import com.yihu.jw.hospital.module.specialist.dao.PatientMedicalRecordsRehabilitationDao;
|
|
|
import com.yihu.jw.hospital.module.specialist.dao.SpecialistPatientRelationDao;
|
|
|
import com.yihu.jw.hospital.team.dao.WlyySignFamilyDao;
|
|
|
import com.yihu.jw.hospital.module.system.service.SystemDictService;
|
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.web.Envelop;
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.ObjEnvelop;
|
|
@ -29,8 +33,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@ -42,6 +46,9 @@ public class RehabilitationManageService {
|
|
|
|
|
|
@Value("${basedb.name}")
|
|
|
private String basedb;
|
|
|
@Value("${im.data_base_name}")
|
|
|
private String imDBName;
|
|
|
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
@ -61,7 +68,99 @@ public class RehabilitationManageService {
|
|
|
@Autowired
|
|
|
BaseDoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
WlyySignFamilyDao signFamilyDao;
|
|
|
BasePatientDao patientDao;
|
|
|
@Autowired
|
|
|
private PatientMedicalRecordsRehabilitationDao medicalRecordsRehabilitationDao;
|
|
|
|
|
|
@Autowired
|
|
|
PatientDiseaseServerDao patientDiseaseServerDao;
|
|
|
@Autowired
|
|
|
private SystemDictService systemDictService;
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> selectPlanByPatient(String patient, Integer status, String planId, String doctor) {
|
|
|
if (StringUtils.isNoneBlank(planId)) {
|
|
|
String planSql = "select p.patient " +
|
|
|
" FROM wlyy_patient_rehabilitation_plan p where p.id='" + planId + "' ";
|
|
|
List<Map<String, Object>> maps = jdbcTemplate.queryForList(planSql);
|
|
|
if (maps != null && maps.size() != 0) {
|
|
|
Map<String, Object> map = maps.get(0);
|
|
|
patient = map.get("patient").toString();
|
|
|
}
|
|
|
}
|
|
|
String sql = "select d.code as doctor,p.create_time as createTime,p.id,d.photo,p.title,d.idcard,YEAR (now()) - YEAR (substring(d.idcard, 7, 8)) AS age," +
|
|
|
" d.sex,p.name,p.patient,p.disease,d.name as doctorName,d.hospital,d.dept_name as deptName,hospital_name as hospitalName,p.advice_content as adviceContent," +
|
|
|
"p.medical_records_code as medicalRecordsCode,p.create_time as create_time " +
|
|
|
" FROM wlyy_patient_rehabilitation_plan p " +
|
|
|
" LEFT JOIN wlyy_doctor d ON d.code = p.create_user " +
|
|
|
"WHERE p.patient='" + patient + "'";
|
|
|
if (status != null) {
|
|
|
sql += " and p.status =" + status;
|
|
|
}
|
|
|
if (StringUtils.isNoneBlank(doctor)) {
|
|
|
BaseDoctorDO doctor1 = doctorDao.findById(doctor).orElse(null);
|
|
|
if (doctor1 != null && doctor1.getLevel() == 1) {
|
|
|
sql += " and p.create_user ='" + doctor + "'";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
sql += " union ";
|
|
|
|
|
|
sql += " SELECT d.CODE AS doctor," +
|
|
|
"p.create_time AS createTime," +
|
|
|
"p.id," +
|
|
|
"d.photo," +
|
|
|
"p.title," +
|
|
|
"d.idcard,YEAR (now())-YEAR (substring(d.idcard,7,8)) AS age," +
|
|
|
"d.sex,p.name," +
|
|
|
"p.patient,p.disease," +
|
|
|
"d.NAME AS doctorName,d.hospital," +
|
|
|
"d.dept_name AS deptName," +
|
|
|
"hospital_name AS hospitalName," +
|
|
|
"p.advice_content AS adviceContent," +
|
|
|
"p.medical_records_code AS medicalRecordsCode," +
|
|
|
"p.create_time AS create_time " +
|
|
|
"FROM " +
|
|
|
"wlyy_patient_rehabilitation_plan p " +
|
|
|
"LEFT JOIN wlyy.wlyy_doctor d ON d.CODE=p.create_user" +
|
|
|
" LEFT JOIN (" +
|
|
|
"SELECT sr.patient AS patient,sr.team_code AS team_code " +
|
|
|
"FROM wlyy_specialist_patient_relation sr " +
|
|
|
"JOIN wlyy.wlyy_doctor_special_share se ON se.special_code=sr.id " +
|
|
|
"WHERE se.doctor='" + doctor + "' " +
|
|
|
"AND sr.patient='" + patient + "') d " +
|
|
|
"ON d.patient=p.patient WHERE " +
|
|
|
"p.patient='" + patient + "' " +
|
|
|
"AND d.team_code=p.team_code ";
|
|
|
|
|
|
sql += " ORDER BY create_time DESC ";
|
|
|
sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
|
|
|
int i = 0;
|
|
|
for (Map<String, Object> map : mapList) {
|
|
|
|
|
|
String sqlSpecilist = "select * from wlyy_specialist_patient_relation where doctor = '" + map.get("code") + "' and patient ='" + patient + "' and sign_status=1 and status=1";
|
|
|
sql = TransforSqlUtl.specialistPatientRelationAll(sql);
|
|
|
List<Map<String, Object>> maps = jdbcTemplate.queryForList(sqlSpecilist);
|
|
|
map.put("specialist", maps);
|
|
|
|
|
|
// //判断是否展示出院带药模块
|
|
|
// if (i == 0) {
|
|
|
// i++;
|
|
|
// String hospital = map.get("hospital") + "";
|
|
|
// String disease = map.get("disease") + "";
|
|
|
// RehabilitationHospitalDrugSetting drugSetting = drugSettingDao.findByHospital(hospital, disease);
|
|
|
// if (drugSetting == null) {
|
|
|
// map.put("isShowDrug", "0");//不展示
|
|
|
// } else {
|
|
|
// map.put("isShowDrug", "1");//展示
|
|
|
// }
|
|
|
// } else {
|
|
|
// map.put("isShowDrug", "0");//不展示
|
|
|
// }
|
|
|
}
|
|
|
return mapList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 预约协诊
|
|
@ -104,7 +203,7 @@ public class RehabilitationManageService {
|
|
|
public MixEnvelop<Map<String, Object>, Map<String, Object>> findRehabilitationPlan(Integer doctorType, String doctorCode, String diseaseCode, Integer planType, Integer todaybacklog, String patientCondition, Integer page, Integer pageSize) throws Exception {
|
|
|
|
|
|
String sql = " select DISTINCT p.* " +
|
|
|
" from wlyy_specialist.wlyy_rehabilitation_plan_detail a INNER JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p " +
|
|
|
" from wlyy_rehabilitation_plan_detail a INNER JOIN wlyy_patient_rehabilitation_plan p " +
|
|
|
" on a.plan_id = p.id ";
|
|
|
if (doctorType == 2) {//家医是根据签约关系过滤
|
|
|
sql += " INNER JOIN wlyy.wlyy_sign_family f ON f.patient = p.patient \n" +
|
|
@ -213,7 +312,7 @@ public class RehabilitationManageService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public ObjEnvelop findRehabilitationPlanDetailList(String currentDoctorCode, String patientCode) throws Exception {
|
|
|
String sql = " select DISTINCT r.* from wlyy_specialist.wlyy_specialist_patient_relation r join wlyy_patient_rehabilitation_plan p on r.patient=p.patient where r.sign_status ='1' and r.status in('0','1') and r.patient='" + patientCode + "' ";
|
|
|
String sql = " select DISTINCT r.* from wlyy_specialist_patient_relation r join wlyy_patient_rehabilitation_plan p on r.patient=p.patient where r.sign_status ='1' and r.status in('0','1') and r.patient='" + patientCode + "' ";
|
|
|
sql = TransforSqlUtl.specialistPatientRelationAll2(sql);
|
|
|
List<Map<String, Object>> specialistPatientRelationList = jdbcTemplate.queryForList(sql);
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
@ -229,7 +328,7 @@ public class RehabilitationManageService {
|
|
|
resultMap.put("healthyCondition", healthyCondition);
|
|
|
resultMap.put("healthyConditionType", healthyConditionType);
|
|
|
//专科医生
|
|
|
String specialistRelationSql = "select r.*,t.name as teamName,h.name as specialistHospitalName from wlyy_specialist.wlyy_specialist_patient_relation r left join " + basedb + ".wlyy_admin_team t on r.team_code=t.id left join " + basedb + ".dm_hospital h on t.org_code=h.code where r.sign_status ='1' and r.status in('0','1') and r.patient='" + patientCode + "' and r.doctor='" + doctorCode + "'";
|
|
|
String specialistRelationSql = "select r.*,t.name as teamName,h.name as specialistHospitalName from wlyy_specialist_patient_relation r left join " + basedb + ".wlyy_admin_team t on r.team_code=t.id left join " + basedb + ".dm_hospital h on t.org_code=h.code where r.sign_status ='1' and r.status in('0','1') and r.patient='" + patientCode + "' and r.doctor='" + doctorCode + "'";
|
|
|
specialistRelationSql = TransforSqlUtl.specialistPatientRelationAll2(specialistRelationSql);
|
|
|
List<Map<String, Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
|
|
|
Map<String, Object> specialistMap = specialistRelationList.get(0);
|
|
@ -357,7 +456,7 @@ public class RehabilitationManageService {
|
|
|
for (int i = 1; i < planIdlist.length; i++) {
|
|
|
planCondition.append(",'" + planIdlist[i] + "'");
|
|
|
}
|
|
|
String sql = " select d.* from wlyy_specialist.wlyy_rehabilitation_plan_detail d " +
|
|
|
String sql = " select d.* from wlyy_rehabilitation_plan_detail d " +
|
|
|
" LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
|
|
|
" where d.plan_id in (" + planCondition + ") ";
|
|
|
if (StringUtils.isNotBlank(executeStartTime)) {
|
|
@ -385,7 +484,6 @@ public class RehabilitationManageService {
|
|
|
sql += " ORDER BY d.execute_time ";
|
|
|
sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(sql);
|
|
|
List<Map<String, Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
|
|
|
// List<RehabilitationDetailDO> rehabilitationDetailList = rehabilitationDetailDao.findByPlanId(DateUtil.strToDate(executeStartTime),DateUtil.strToDate(executeEndTime),planId);
|
|
|
Map<String, Map<String, Object>> map = new LinkedHashMap<>();
|
|
|
for (Map<String, Object> one : rehabilitationDetailList) {
|
|
|
String executeTime = DateUtil.dateToStr((Date) one.get("execute_time"), DateUtil.YYYY_MM_DD);
|
|
@ -487,6 +585,36 @@ public class RehabilitationManageService {
|
|
|
return ObjEnvelop.getSuccess(SpecialistMapping.api_success, map);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 康复管理-康复计划按列表展示
|
|
|
*
|
|
|
* @param executeStartTime
|
|
|
* @param executeEndTime
|
|
|
* @param planId
|
|
|
* @param searchTask
|
|
|
* @param status
|
|
|
* @param doctorCode
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONArray calendarPlanDetailList(String executeStartTime, String executeEndTime, String planId, Integer searchTask, Integer status, String doctorCode) throws Exception {
|
|
|
Map<String, Object> param = new HashedMap();
|
|
|
param.put("executeStartTime", executeStartTime);
|
|
|
param.put("executeEndTime", executeEndTime);
|
|
|
param.put("planId", planId);
|
|
|
param.put("searchTask", searchTask);
|
|
|
param.put("status", status);
|
|
|
param.put("doctorCode", doctorCode);
|
|
|
ObjEnvelop objEnvelop = calendarPlanDetailList(planId, searchTask, status, doctorCode, executeStartTime, executeEndTime, "0");
|
|
|
org.json.JSONObject result = new org.json.JSONObject(objEnvelop);
|
|
|
if (result.getInt("status") == 200) {
|
|
|
return result.getJSONArray("obj");
|
|
|
}
|
|
|
throw new Exception("请求失败!");
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 日历列表
|
|
|
*
|
|
@ -497,14 +625,13 @@ public class RehabilitationManageService {
|
|
|
* @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
|
|
|
*/
|
|
|
public ObjEnvelop calendarPlanDetailList(String planId, Integer searchTask, Integer status, String doctorCode, String executeStartTime, String executeEndTime, String taskExecutor) {
|
|
|
|
|
|
String[] planIdlist = planId.split(",");
|
|
|
StringBuilder planCondition = new StringBuilder();
|
|
|
planCondition.append("'" + planIdlist[0] + "'");
|
|
|
for (int i = 1; i < planIdlist.length; i++) {
|
|
|
planCondition.append(",'" + planIdlist[i] + "'");
|
|
|
}
|
|
|
String sql = " select d.*,DATE_FORMAT(d.execute_time,'%Y/%m/%d %H:%i') as executeTime ,i.code,IF(d.followup_detail_type=1,'社区随访(厦心)',i.name) name,1 as flag from wlyy_specialist.wlyy_rehabilitation_plan_detail d " +
|
|
|
String sql = " select d.*,DATE_FORMAT(d.execute_time,'%Y/%m/%d %H:%i') as executeTime ,i.code,IF(d.followup_detail_type=1,'社区随访(厦心)',i.name) name,1 as flag from wlyy_rehabilitation_plan_detail d " +
|
|
|
" LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
|
|
|
" where d.plan_id in (" + planCondition + " )AND d.execute_time IS NOT NULL and d.execute_time <>'' ";
|
|
|
if (searchTask != null) {
|
|
@ -535,7 +662,7 @@ public class RehabilitationManageService {
|
|
|
sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(sql);
|
|
|
List<Map<String, Object>> rehabilitationDetailList = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
String planPatientSql = " SELECT p.patient FROM wlyy_specialist.wlyy_patient_rehabilitation_plan p " +
|
|
|
String planPatientSql = " SELECT p.patient FROM wlyy_patient_rehabilitation_plan p " +
|
|
|
"INNER JOIN wlyy.wlyy_sign_family f ON p.patient = f.patient WHERE p.id in (" + planCondition + " ) " +
|
|
|
"AND f.`status` = 1 AND f.expenses_status = 1 AND f.doctor = '" + doctorCode + "' ";
|
|
|
List<Map<String, Object>> patientCodeList = jdbcTemplate.queryForList(planPatientSql);
|
|
@ -559,7 +686,9 @@ public class RehabilitationManageService {
|
|
|
" AND sd.dict_name = 'FOLLOWUP_WAY_DICT' WHERE wf.status !=0 AND wf.patient_code = '" + patient + "' order by wf.followup_plan_date desc ";
|
|
|
list = jdbcTemplate.queryForList(sfSql);
|
|
|
}
|
|
|
if (list != null && list.size() > 0) rehabilitationDetailList.addAll(list);
|
|
|
if (list != null && list.size() > 0) {
|
|
|
rehabilitationDetailList.addAll(list);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return ObjEnvelop.getSuccess(SpecialistMapping.api_success, rehabilitationDetailList);
|
|
@ -581,9 +710,9 @@ public class RehabilitationManageService {
|
|
|
String planDetailResult = StringUtils.isNotEmpty(planDetailList) ? planDetailList.substring(1) : "";
|
|
|
String sql = "select i.name,i.code,i.content,d.execute_time,d.hospital_name,d.id,d.status,d.type as detailType,d.expense,d.doctor as executeDoctor," +
|
|
|
" d.doctor_name as executeDoctorName,p.patient ,p.id AS planId,p.create_user as createDoctor,p.create_user_name as createDoctorName, p.status as planStatus " +
|
|
|
" from wlyy_specialist.wlyy_rehabilitation_plan_detail d " +
|
|
|
" LEFT JOIN wlyy_specialist.wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
|
|
|
" LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
|
|
|
" from wlyy_rehabilitation_plan_detail d " +
|
|
|
" LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
|
|
|
" LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
|
|
|
" where d.id in (" + planDetailResult + ") order BY d.execute_time ASC ";
|
|
|
sql = TransforSqlUtl.wlyy_patient_rehabilitation_planCreateName(sql);
|
|
|
sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName(sql);
|
|
@ -690,10 +819,10 @@ public class RehabilitationManageService {
|
|
|
" d.doctor_name as executeDoctorName,p.patient ,p.name as patientName,p.create_user as createDoctor,p.create_user_name as createDoctorName, p.status as planStatus," +
|
|
|
" p.disease,p.disease_name as diseaseName,p.title as planTitle,d.plan_id as planId,d.relation_code as relationCode,d.frequency_code as frequencyCode,d.remark " +
|
|
|
" ,a.appointment_time appointmentTime,a.appointment_doctor appointmentDoctor,a.appointment_doctor_name appointmentDoctorName,d.reservation_type reservationType,d.followup_detail_type followupDetailType " +
|
|
|
" from wlyy_specialist.wlyy_rehabilitation_plan_detail d " +
|
|
|
" LEFT JOIN wlyy_specialist.wlyy_rehabilitation_service_item h on d.hospital_service_item_id = h.code " +
|
|
|
" LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
|
|
|
" LEFT JOIN wlyy_specialist.wlyy_plan_detail_appointment a on d.id=.a.rehabilitation_plan_detail_id " +
|
|
|
" from wlyy_rehabilitation_plan_detail d " +
|
|
|
" LEFT JOIN wlyy_rehabilitation_service_item h on d.hospital_service_item_id = h.code " +
|
|
|
" LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
|
|
|
" LEFT JOIN wlyy_plan_detail_appointment a on d.id=.a.rehabilitation_plan_detail_id " +
|
|
|
" where d.id = '" + planDetailId + "'";
|
|
|
sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName2(sql);
|
|
|
sql = TransforSqlUtl.wlyy_patient_rehabilitation_planCreateName(sql);
|
|
@ -820,23 +949,101 @@ public class RehabilitationManageService {
|
|
|
return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultMap);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 康复管理居民详情页
|
|
|
* 康复管理-居民详情页
|
|
|
*
|
|
|
* @param patientCode
|
|
|
* @param healthDoctor
|
|
|
* @param healthDoctorName
|
|
|
* @param generalDoctor
|
|
|
* @param generalDoctorName
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public ObjEnvelop patientRehabilitationDetail(String patientCode, String healthDoctor, String healthDoctorName, String generalDoctor, String generalDoctorName) {
|
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
public org.json.JSONObject patientRehabilitationDetail(String patientCode) throws Exception {
|
|
|
//查询居民信息
|
|
|
// List<SignFamily> list = signFamilyDao.findByPatientAndExpensesStatusAndStatus(patientCode, "1", 1);
|
|
|
BasePatientDO patient = patientDao.findById(patientCode).orElse(null);
|
|
|
String healthDoctor = null;
|
|
|
String healthDoctorName = null;
|
|
|
String generalDoctor = null;
|
|
|
String generalDoctorName = null;
|
|
|
String patientName = null;
|
|
|
Integer age = null;
|
|
|
String sex = null;
|
|
|
String signHospitalName = null;
|
|
|
org.json.JSONObject json = new org.json.JSONObject();
|
|
|
String healthyConditionSql = " select label_name,label from wlyy_sign_patient_label_info where status=1 and patient='" + patientCode + "' and label_type=8";
|
|
|
List<Map<String, Object>> healthyConditionList = jdbcTemplate.queryForList(healthyConditionSql);
|
|
|
String healthyCondition = healthyConditionList.size() > 0 ? healthyConditionList.get(0).get("label_name") + "" : "";
|
|
|
String healthyConditionType = healthyConditionList.size() > 0 ? healthyConditionList.get(0).get("label") + "" : "";
|
|
|
|
|
|
if (patient != null) {
|
|
|
|
|
|
healthDoctor = null;
|
|
|
healthDoctorName = null;
|
|
|
generalDoctor = null;
|
|
|
generalDoctorName = null;
|
|
|
// healthDoctor = signFamily.getDoctorHealth();
|
|
|
// healthDoctorName = signFamily.getDoctorHealthName();
|
|
|
// generalDoctor = signFamily.getDoctor();
|
|
|
// generalDoctorName = signFamily.getDoctorName();
|
|
|
patientName = patient.getName();
|
|
|
// signHospitalName = signFamily.getHospitalName();
|
|
|
|
|
|
ObjEnvelop envelop = patientRehabilitationDetail(patientCode, healthDoctor, healthDoctorName, generalDoctor, generalDoctorName);
|
|
|
org.json.JSONObject jsonObject = new org.json.JSONObject((Map<String, Object>) envelop.getObj());
|
|
|
if (envelop.getStatus() == 200) {
|
|
|
json = jsonObject.getJSONObject("patientInfo");
|
|
|
json.put("healthyCondition", healthyCondition);
|
|
|
json.put("healthyConditionType", healthyConditionType);
|
|
|
json.put("patientName", patientName);
|
|
|
// json.put("signHospitalName", signHospitalName);
|
|
|
age = IdCardUtil.getAgeByIdcardOrBirthday(patient.getIdcard(), patient.getBirthday());
|
|
|
sex = IdCardUtil.getSexForIdcard_new(patient.getIdcard());
|
|
|
json.put("patientCode", patientCode);
|
|
|
json.put("patientName", patient.getName());
|
|
|
json.put("age", age);
|
|
|
json.put("sex", sex);
|
|
|
json.put("photo", patient.getPhoto());
|
|
|
json.put("mobile", patient.getMobile());
|
|
|
JSONArray jsonArray = jsonObject.getJSONArray("serviceDoctorList");
|
|
|
String doctorCode = "";
|
|
|
BaseDoctorDO doctor = null;
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
doctorCode = jsonArray.getJSONObject(i).get("doctorCode") + "";
|
|
|
doctor = doctorDao.findById(doctorCode).orElse(null);
|
|
|
jsonArray.getJSONObject(i).put("doctorPhoto", doctor != null ? doctor.getPhoto() : "");
|
|
|
}
|
|
|
return jsonObject.put("patientInfo", json);
|
|
|
}
|
|
|
throw new Exception("查询失败!");
|
|
|
} else {
|
|
|
json = new org.json.JSONObject();
|
|
|
}
|
|
|
json.put("healthyCondition", healthyCondition);
|
|
|
json.put("healthyConditionType", healthyConditionType);
|
|
|
age = IdCardUtil.getAgeByIdcardOrBirthday(patient.getIdcard(), patient.getBirthday());
|
|
|
sex = IdCardUtil.getSexForIdcard_new(patient.getIdcard());
|
|
|
json.put("patientCode", patientCode);
|
|
|
json.put("patientName", patient.getName());
|
|
|
json.put("age", age);
|
|
|
json.put("sex", sex);
|
|
|
json.put("photo", patient.getPhoto());
|
|
|
json.put("mobile", patient.getMobile());
|
|
|
return new org.json.JSONObject().put("patientInfo", json);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 康复管理居民详情页
|
|
|
* patientCode
|
|
|
* healthDoctor
|
|
|
* healthDoctorName
|
|
|
* generalDoctor
|
|
|
* generalDoctorName
|
|
|
*/
|
|
|
public ObjEnvelop patientRehabilitationDetail(String patientCode, String healthDoctor, String healthDoctorName, String generalDoctor, String generalDoctorName) {
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
//个人基础信息(康复机构)
|
|
|
String patientInfoSql = " SELECT DISTINCT hospital_name from wlyy_specialist.wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
|
|
|
String patientInfoSql = " SELECT DISTINCT hospital_name from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
|
|
|
" where p.patient='" + patientCode + "' and p.status=1 ";
|
|
|
List<Map<String, Object>> patientInfoList = jdbcTemplate.queryForList(patientInfoSql);
|
|
|
Map<String, Object> patientInfo = new HashMap<>();
|
|
@ -881,7 +1088,7 @@ public class RehabilitationManageService {
|
|
|
serviceDoctorList.add(generalDoctorMap);
|
|
|
}
|
|
|
|
|
|
String specialistRelationSql = "select DISTINCT d.doctor,d.doctor_name from wlyy_specialist.wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.type=2 and p.patient='" + patientCode + "'";
|
|
|
String specialistRelationSql = "select DISTINCT d.doctor,d.doctor_name from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.type=2 and p.patient='" + patientCode + "'";
|
|
|
specialistRelationSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName2(specialistRelationSql);
|
|
|
List<Map<String, Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
|
|
|
for (Map<String, Object> one : specialistRelationList) {
|
|
@ -988,8 +1195,8 @@ public class RehabilitationManageService {
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
//近期康复相关记录
|
|
|
// String currentTime = DateUtil.getStringDate();
|
|
|
String planDetailSql = " select d.*,h.name,h.code,s.complete_time from wlyy_specialist.wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_rehabilitation_service_item h on d.hospital_service_item_id=h.code" +
|
|
|
" LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p on d.plan_id=p.id" +
|
|
|
String planDetailSql = " select d.*,h.name,h.code,s.complete_time from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_rehabilitation_service_item h on d.hospital_service_item_id=h.code" +
|
|
|
" LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id" +
|
|
|
" left join wlyy_rehabilitation_operate_records s on s.rehabilitation_detail_id=d.id " +
|
|
|
" where d.status=1 and p.patient='" + patientCode + "' and d.frequency_code IS NOT NULL AND d.frequency_code <>'' ";
|
|
|
if (StringUtils.isNotEmpty(startTime)) {
|
|
@ -1037,8 +1244,8 @@ public class RehabilitationManageService {
|
|
|
planDetailList.add(map);
|
|
|
}
|
|
|
resultMap.put("planDetailList", planDetailList);//康复相关记录列表
|
|
|
String planDetailCountSql = " select d.status as num from wlyy_specialist.wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_rehabilitation_service_item h on d.hospital_service_item_id=h.code" +
|
|
|
" LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where p.patient='" + patientCode + "'";
|
|
|
String planDetailCountSql = " select d.status as num from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_rehabilitation_service_item h on d.hospital_service_item_id=h.code" +
|
|
|
" LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where p.patient='" + patientCode + "'";
|
|
|
List<Map<String, Object>> planDetailList2 = jdbcTemplate.queryForList(planDetailCountSql);
|
|
|
Integer planDetailFinish = 0;
|
|
|
Integer planDetailUnfinish = 0;
|
|
@ -1159,7 +1366,7 @@ public class RehabilitationManageService {
|
|
|
serviceDoctorList.add(healthDoctorMap);
|
|
|
}
|
|
|
|
|
|
String specialistRelationSql = "select DISTINCT d.doctor,d.doctor_name from wlyy_specialist.wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.type=2 AND d.doctor IS NOT NULL and d.doctor <> '' and p.patient='" + patientCode + "'";
|
|
|
String specialistRelationSql = "select DISTINCT d.doctor,d.doctor_name from wlyy_rehabilitation_plan_detail d LEFT JOIN wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.type=2 AND d.doctor IS NOT NULL and d.doctor <> '' and p.patient='" + patientCode + "'";
|
|
|
specialistRelationSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName2(specialistRelationSql);
|
|
|
List<Map<String, Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
|
|
|
for (Map<String, Object> one : specialistRelationList) {
|
|
@ -1420,6 +1627,56 @@ public class RehabilitationManageService {
|
|
|
return Envelop.getError("更新失败!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 康复管理-计划总进度
|
|
|
*
|
|
|
* @param planId
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public org.json.JSONObject planSchedule(String planId, String patientCode) throws Exception {
|
|
|
Map<String, Object> param = new HashedMap();
|
|
|
param.put("planId", planId);
|
|
|
ObjEnvelop objEnvelop = planSchedule(planId);
|
|
|
org.json.JSONObject result = new org.json.JSONObject(objEnvelop);
|
|
|
if (result.getInt("status") == 200) {
|
|
|
org.json.JSONObject json = result.getJSONObject("obj");
|
|
|
BasePatientDO p = patientDao.findById(patientCode).orElse(null);
|
|
|
Integer age = IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(), p.getBirthday());
|
|
|
String sex = IdCardUtil.getSexForIdcard_new(p.getIdcard());
|
|
|
json.put("sex", "1".equals(sex) ? "男" : ("2".equals(sex) ? "女" : "未知"));
|
|
|
json.put("age", age);
|
|
|
json.put("patientPhoto", p.getPhoto());
|
|
|
json.put("patientName", p.getName());
|
|
|
json.put("patientCode", p.getId());
|
|
|
String healthyConditionSql = " select label_name,label from wlyy_sign_patient_label_info where status=1 and patient='" + p.getId() + "' and label_type=8";
|
|
|
List<Map<String, Object>> healthyConditionList = jdbcTemplate.queryForList(healthyConditionSql);
|
|
|
String healthyCondition = healthyConditionList.size() > 0 ? healthyConditionList.get(0).get("label_name") + "" : "";
|
|
|
String healthyConditionType = healthyConditionList.size() > 0 ? healthyConditionList.get(0).get("label") + "" : "";
|
|
|
//专科医生、科室、专科医院
|
|
|
String sql = "select create_user from wlyy_specialist.wlyy_patient_rehabilitation_plan where id='" + planId + "'";
|
|
|
String specialDoctorCode = jdbcTemplate.queryForObject(sql, String.class);//专科code
|
|
|
BaseDoctorDO specialDoctor = doctorDao.findById(specialDoctorCode).orElse(null);
|
|
|
json.put("specialDoctorName", specialDoctor.getName());
|
|
|
// todo 后面在改202311116
|
|
|
// json.put("specialDoctorDeptName", specialDoctor.getDeptName());
|
|
|
// json.put("specialDoctorHospitalName", specialDoctor.getHospitalName());
|
|
|
|
|
|
json.put("healthyCondition", healthyCondition);
|
|
|
json.put("healthyConditionType", healthyConditionType);
|
|
|
json.put("idcard", p.getIdcard());
|
|
|
json.put("planId", planId);
|
|
|
|
|
|
//下转特殊标识
|
|
|
Map<String, String> changeStatusMap = systemDictService.getDictMap("changeStatusName");
|
|
|
String changeStatus = findLastPlanChangeStatus2(planId);
|
|
|
json.put("changeStatus", changeStatus);
|
|
|
json.put("changeStatusName", changeStatusMap.get(changeStatus));
|
|
|
|
|
|
return json;
|
|
|
}
|
|
|
throw new Exception("请求微服务失败!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计划总进度
|
|
@ -1458,6 +1715,7 @@ public class RehabilitationManageService {
|
|
|
return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultMap);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 根据居民获取康复计划
|
|
|
*
|
|
@ -1610,7 +1868,7 @@ public class RehabilitationManageService {
|
|
|
|
|
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
|
|
public JSONArray selectPlanServerDoctor(String planId, String doctorCode) throws Exception {
|
|
|
String sql = "SELECT t.patient,t.create_user FROM wlyy_specialist.wlyy_patient_rehabilitation_plan t where t.id='" + planId + "'";//专科
|
|
|
String sql = "SELECT t.patient,t.create_user FROM wlyy_patient_rehabilitation_plan t where t.id='" + planId + "'";//专科
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
|
|
|
JSONArray array = new JSONArray();
|
|
|
String patient = "";
|
|
@ -1635,7 +1893,8 @@ public class RehabilitationManageService {
|
|
|
object.put("idcard", doctor1.getIdcard());
|
|
|
array.put(object);
|
|
|
}
|
|
|
SignFamily signFamily = signFamilyDao.findByPatient(patient);
|
|
|
// SignFamily signFamily = signFamilyDao.findByPatient(patient);
|
|
|
SignFamily signFamily = null;
|
|
|
if (signFamily != null) {
|
|
|
JSONObject object = new JSONObject();
|
|
|
BaseDoctorDO doctor = doctorDao.findById(signFamily.getDoctor()).orElse(null);
|
|
@ -1717,8 +1976,774 @@ public class RehabilitationManageService {
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<PatientMedicalRecordsDO> findByPatient(String patient) {
|
|
|
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) {
|
|
|
try {
|
|
|
String planSql = "SELECT id from wlyy_patient_rehabilitation_plan " +
|
|
|
" WHERE patient = '" + patient + "' ORDER BY create_time desc LIMIT 1";
|
|
|
List<Map<String, Object>> planList = jdbcTemplate.queryForList(planSql);
|
|
|
if (planList.size() > 0) {
|
|
|
String planId = planList.get(0).get("id") + "";
|
|
|
return findLastPlanChangeStatus2(planId);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public String findLastPlanChangeStatus2(String planId) {
|
|
|
try {
|
|
|
String changeSql = "SELECT status from wlyy_plan_sign_change WHERE plan_id = '" + planId + "' and del=1 order by id desc LIMIT 1";
|
|
|
List<Map<String, Object>> changeList = jdbcTemplate.queryForList(changeSql);
|
|
|
if (changeList.size() > 0) {
|
|
|
return changeList.get(0).get("status") + "";
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public org.json.JSONObject getPatientSpecialAndFamilyDoctor(String patientCode) {
|
|
|
org.json.JSONObject result = new org.json.JSONObject();
|
|
|
//专科列表
|
|
|
String sql = "SELECT DISTINCT p.patient, p.name AS patient_name, d.`code` as special_code, d.`name` as special_name, d.photo,d.dept_name,d.hospital_name \n" +
|
|
|
"FROM wlyy_patient_rehabilitation_plan p, wlyy_doctor d\n" +
|
|
|
"WHERE p.patient = '" + patientCode + "' AND d.`code`= p.create_user GROUP BY p.patient, p.create_user";
|
|
|
sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName2(sql);
|
|
|
List<Map<String, Object>> specialList = jdbcTemplate.queryForList(sql);
|
|
|
result.put("specialList", specialList);
|
|
|
//全科 健康管理师列表
|
|
|
sql = "select s.patient,s.`name`,s.doctor,doc.photo as doctor_photo,s.doctor_name,s.doctor_health,s.doctor_health_name \n" +
|
|
|
"\t\tfrom wlyy_sign_family s ,wlyy_doctor doc\n" +
|
|
|
"\t\twhere s.patient ='" + patientCode + "' and doc.`code` =s.doctor and s.type=2 and s.`status`=1;";
|
|
|
Map<String, Object> doctor = jdbcTemplate.queryForMap(sql);
|
|
|
String doctor_health = doctor.get("doctor_health") == null ? "" : doctor.get("doctor_health").toString();
|
|
|
if (StringUtils.isBlank(doctor_health)) {
|
|
|
doctor.put("health_photo", "");
|
|
|
doctor.put("doctor_health", "");
|
|
|
} else {
|
|
|
sql = "select photo from wlyy_doctor where `code`='" + doctor_health + "'";
|
|
|
String health_photo = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
doctor.put("health_photo", health_photo);
|
|
|
}
|
|
|
result.put("doctor", doctor);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取完成随访数-这边接口需要改造
|
|
|
*/
|
|
|
public List<Map<String, Object>> selectAllCompleteServiceItemsByPatient(String patient) {
|
|
|
List<Map<String, Object>> resutList = new ArrayList<>();
|
|
|
String sql = "select A.id 'planId',pdl.id,pdl.frequency_code,A.patient,A.`name`,si.id 'code',si.`name` 'serviceName',opr.complete_time 'czrq' from \n" +
|
|
|
"(select p.team_code as teamCode,d.code as doctor,p.create_time as createTime,p.id,p.patient,p.name " +
|
|
|
"from wlyy_patient_rehabilitation_plan p\n" +
|
|
|
"LEFT JOIN wlyy.wlyy_doctor d ON d.code = p.create_user\n" +
|
|
|
"WHERE p.patient='" + patient + "'\n" +
|
|
|
"union\n" +
|
|
|
"SELECT p.team_code as teamCode,d.CODE AS doctor,p.create_time AS createTime,p.id,p.patient,p.name " +
|
|
|
"from \n" +
|
|
|
"wlyy_patient_rehabilitation_plan p\n" +
|
|
|
"LEFT JOIN wlyy.wlyy_doctor d ON d.CODE=p.create_user\n" +
|
|
|
"LEFT JOIN (\n" +
|
|
|
"SELECT sr.patient AS patient,sr.team_code AS team_code \n" +
|
|
|
"FROM wlyy_specialist_patient_relation sr \n" +
|
|
|
"JOIN wlyy.wlyy_doctor_special_share se ON se.special_code=sr.id \n" +
|
|
|
"WHERE sr.patient='" + patient + "') d \n" +
|
|
|
"ON d.patient=p.patient WHERE \n" +
|
|
|
"p.patient='" + patient + "' \n" +
|
|
|
"AND d.team_code=p.team_code \n" +
|
|
|
"ORDER BY createTime DESC)A \n" +
|
|
|
"INNER JOIN wlyy_rehabilitation_plan_detail pdl ON A.id = pdl.plan_id\n" +
|
|
|
"INNER JOIN wlyy_rehabilitation_service_item si on pdl.hospital_service_item_id = si.id\n" +
|
|
|
"INNER JOIN wlyy_rehabilitation_operate_records opr on opr.rehabilitation_detail_id = pdl.id\n" +
|
|
|
"where pdl.hospital_service_item_id <>2 and opr.`status`=1 order by opr.complete_time desc ";
|
|
|
sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
|
|
|
List<Map<String, Object>> planDetailList = jdbcTemplate.queryForList(sql);
|
|
|
resutList.addAll(planDetailList);
|
|
|
//康复咨询
|
|
|
sql = "select ct.consult,ct.type,ct.patient,ct.name,ct.czrq,ct.symptoms,top.`status`,top.end_time,top.evaluate,top.evaluate_time,top.reply,top.reply_time, '2' as 'serviceId','康复咨询' as 'serviceName'\n" +
|
|
|
"from wlyy_consult_team ct\n" +
|
|
|
"INNER JOIN " + imDBName + ".topics top on top.id = ct.consult \n" +
|
|
|
"where ct.patient='" + patient + "' and ct.type=18 and ct.del=1";
|
|
|
List<Map<String, Object>> kangFuList = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String, Object> map : kangFuList) {
|
|
|
if (map.get("status").toString().equals("0") && map.get("reply").toString().equals("0")) {
|
|
|
map.put("serviceStatus", "未回复");
|
|
|
}
|
|
|
if (map.get("status").toString().equals("0") && map.get("reply").toString().equals("1")) {
|
|
|
map.put("serviceStatus", "未结束");
|
|
|
}
|
|
|
if (map.get("status").toString().equals("10")) {//&&map.get("evaluate").toString().equals("0")
|
|
|
map.put("serviceStatus", "已结束");
|
|
|
}
|
|
|
// if (map.get("status").toString().equals("10")&&map.get("evaluate").toString().equals("1")){
|
|
|
// map.put("serviceStatus","已结束");
|
|
|
// }
|
|
|
}
|
|
|
resutList.addAll(kangFuList);
|
|
|
Collections.sort(resutList, new Comparator<Map<String, Object>>() {
|
|
|
@Override
|
|
|
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
|
|
Timestamp map1value = (Timestamp) o1.get("czrq");
|
|
|
Timestamp map2value = (Timestamp) o2.get("czrq");
|
|
|
int sort = 1;
|
|
|
if (map1value.getTime() - map2value.getTime() > 0) {
|
|
|
return sort == 1 ? -1 : 1;
|
|
|
} else if (map1value.getTime() - map2value.getTime() < 0) {
|
|
|
return sort == 1 ? 1 : -1;
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return resutList;
|
|
|
}
|
|
|
|
|
|
public List<Map<String, Object>> getPatientAllRehabilitationPlan(String patient, String doctor) {
|
|
|
String sql = "select p.team_code as teamCode,d.code as doctor,p.create_time as createTime,p.id,d.photo,p.title,d.idcard," +
|
|
|
"YEAR (now()) - YEAR (substring(d.idcard, 7, 8)) AS age, d.sex,p.name,p.patient,p.disease,p.disease_name,d.name as doctorName," +
|
|
|
"d.dept_name as deptName,d.hospital_name as hospitalName,d.hospital,p.advice_content as adviceContent,p.medical_records_code as medicalRecordsCode," +
|
|
|
"p.create_time as create_time,p.status " +
|
|
|
" FROM wlyy_specialist.wlyy_patient_rehabilitation_plan p " +
|
|
|
" LEFT JOIN wlyy.wlyy_doctor d ON d.code = p.create_user " +
|
|
|
"WHERE p.patient='" + patient + "'";
|
|
|
sql = sql + " union " +
|
|
|
"SELECT p.team_code as teamCode,d.CODE AS doctor," +
|
|
|
"p.create_time AS createTime," +
|
|
|
"p.id," +
|
|
|
"d.photo," +
|
|
|
"p.title," +
|
|
|
"d.idcard,YEAR (now())-YEAR (substring(d.idcard,7,8)) AS age," +
|
|
|
"d.sex,p.name," +
|
|
|
"p.patient,p.disease, " +
|
|
|
"p.disease_name," +
|
|
|
"d.NAME AS doctorName," +
|
|
|
"d.dept_name AS deptName," +
|
|
|
"d.hospital_name AS hospitalName," +
|
|
|
"d.hospital," +
|
|
|
"p.advice_content AS adviceContent," +
|
|
|
"p.medical_records_code AS medicalRecordsCode," +
|
|
|
"p.create_time AS create_time,p.status " +
|
|
|
"FROM " +
|
|
|
"wlyy_specialist.wlyy_patient_rehabilitation_plan p " +
|
|
|
"LEFT JOIN wlyy.wlyy_doctor d ON d.CODE=p.create_user" +
|
|
|
" LEFT JOIN (" +
|
|
|
"SELECT sr.patient AS patient,sr.team_code AS team_code " +
|
|
|
"FROM wlyy_specialist.wlyy_specialist_patient_relation sr " +
|
|
|
"JOIN wlyy.wlyy_doctor_special_share se ON se.special_code=sr.id " +
|
|
|
"WHERE sr.patient='" + patient + "') d " +
|
|
|
"ON d.patient=p.patient WHERE " +
|
|
|
"p.patient='" + patient + "' " +
|
|
|
"AND d.team_code=p.team_code " +
|
|
|
"ORDER BY create_time DESC";
|
|
|
sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
List<Map<String, Object>> hadManage = new ArrayList<>();
|
|
|
int i = 0;
|
|
|
Map<String, String> changeStatusMap = systemDictService.getDictMap("changeStatusName");
|
|
|
for (Map<String, Object> mp : mapList) {//获下转状态
|
|
|
Date createTimeDate = DateUtil.strToDateLong(mp.get("createTime").toString());
|
|
|
mp.put("createTimeDate", DateUtil.dateToStrShort(createTimeDate));
|
|
|
String mpDoctor = mp.get("doctor").toString();
|
|
|
String manageStatus;
|
|
|
//获取最近完成服务
|
|
|
sql = "select si.`code`,si.name,opr.complete_time update_time " +
|
|
|
"from wlyy_specialist.wlyy_rehabilitation_plan_detail pd \n" +
|
|
|
"INNER JOIN wlyy_specialist.wlyy_rehabilitation_service_item si on si.`code` = pd.hospital_service_item_id \n" +
|
|
|
"INNER JOIN wlyy_specialist.wlyy_rehabilitation_operate_records opr on opr.rehabilitation_detail_id = pd.id\n" +
|
|
|
"where plan_id='" + mp.get("id").toString() + "' and opr.`status` =1 ORDER BY opr.complete_time DESC ";
|
|
|
List<Map<String, Object>> serverItems = jdbcTemplate.queryForList(sql);
|
|
|
if (serverItems != null && serverItems.size() != 0) {
|
|
|
mp.put("completeServer", serverItems.get(0));
|
|
|
} else {
|
|
|
mp.put("completeServer", "");
|
|
|
}
|
|
|
if (mp.get("teamCode") != null) {
|
|
|
sql = "select is_manage from wlyy_specialist.wlyy_specialist_patient_relation where patient ='" + patient + "' and team_code='" + mp.get("teamCode").toString() + "' and sign_status>0 and status=1 ORDER BY sign_date desc limit 1";
|
|
|
} else {
|
|
|
sql = "select is_manage from wlyy_specialist.wlyy_specialist_patient_relation where doctor = '" + mpDoctor + "' and patient ='" + patient + "' and sign_status>0 and status=1 ORDER BY sign_date desc limit 1";
|
|
|
}
|
|
|
try {
|
|
|
manageStatus = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
} catch (Exception e) {
|
|
|
manageStatus = "0";
|
|
|
}
|
|
|
if (StringUtils.isBlank(manageStatus) || manageStatus.equals("0")) {//已下转,即未接收
|
|
|
mp.put("turnDownState", 1);
|
|
|
result.add(mp);
|
|
|
} else {//已接受
|
|
|
mp.put("turnDownState", 2);
|
|
|
hadManage.add(mp);
|
|
|
}
|
|
|
//计算待完成任务数
|
|
|
String status = mp.get("status") + "";
|
|
|
Integer unCompleteCount = 0;
|
|
|
if ("1".equals(status)) {
|
|
|
String unCompleteCountSql = "SELECT COUNT(*) from ( SELECT COUNT(pd.id) AS total,pd.hospital_service_item_id , COUNT( IF(pd.`status` = 1,1,null)) AS compeletTotal" +
|
|
|
" FROM wlyy_specialist.wlyy_rehabilitation_plan_detail pd WHERE " +
|
|
|
" pd.plan_id = '" + mp.get("id") + "' AND pd.doctor='" + doctor + "' and pd.execute_time<'" + DateUtil.getStringDateShort() + " 23:59:59' " +
|
|
|
"GROUP BY pd.hospital_service_item_id HAVING total>compeletTotal) a";
|
|
|
unCompleteCount = jdbcTemplate.queryForObject(unCompleteCountSql, Integer.class);
|
|
|
}
|
|
|
mp.put("unCompleteCount", unCompleteCount);
|
|
|
|
|
|
// //判断是否展示出院带药模块
|
|
|
// if (i == 0) {
|
|
|
// i++;
|
|
|
// String hospital = mp.get("hospital") + "";
|
|
|
// String disease = mp.get("disease") + "";
|
|
|
// RehabilitationHospitalDrugSetting drugSetting = drugSettingDao.findByHospital(hospital, disease);
|
|
|
// if (drugSetting == null) {
|
|
|
// mp.put("isShowDrug", "0");//不展示
|
|
|
// } else {
|
|
|
// mp.put("isShowDrug", "1");//展示
|
|
|
// }
|
|
|
// } else {
|
|
|
// mp.put("isShowDrug", "0");//不展示
|
|
|
// }
|
|
|
|
|
|
|
|
|
//下转特殊标识
|
|
|
String changeStatus = findLastPlanChangeStatus2(mp.get("id") + "");
|
|
|
mp.put("changeStatus", changeStatus);
|
|
|
mp.put("changeStatusName", changeStatusMap.get(changeStatus));
|
|
|
}
|
|
|
result.addAll(hadManage);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 患者所有康复计划按列表展示(区分我的任务,他人任务)
|
|
|
*
|
|
|
* @param executeStartTime
|
|
|
* @param executeEndTime
|
|
|
* @param patient
|
|
|
* @param searchTask
|
|
|
* @param status
|
|
|
* @param doctorCode
|
|
|
* @param taskExecutor
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONArray calendarPlanDetailListBypatient(String executeStartTime, String executeEndTime, String patient, Integer searchTask, Integer status, String doctorCode, String taskExecutor) throws Exception {
|
|
|
//居民康复计划
|
|
|
List<Map<String, Object>> planList = getPatientAllRehabilitationPlan(patient, doctorCode);
|
|
|
StringBuilder planIds = new StringBuilder();
|
|
|
planIds.append(planList.get(0).get("id").toString());
|
|
|
for (int i = 1; i < planList.size(); i++) {
|
|
|
planIds.append("," + planList.get(i).get("id").toString());
|
|
|
}
|
|
|
Map<String, Object> param = new HashedMap();
|
|
|
param.put("planId", planIds);
|
|
|
param.put("searchTask", searchTask);
|
|
|
param.put("status", status);
|
|
|
param.put("doctorCode", doctorCode);
|
|
|
param.put("executeStartTime", executeStartTime);
|
|
|
param.put("executeEndTime", executeEndTime);
|
|
|
|
|
|
|
|
|
param.put("taskExecutor", taskExecutor);
|
|
|
ObjEnvelop objEnvelop = calendarPlanDetailList(planIds.toString(), searchTask, status, doctorCode, executeStartTime, executeEndTime, taskExecutor);
|
|
|
|
|
|
org.json.JSONObject result = new org.json.JSONObject(objEnvelop);
|
|
|
if (result.getInt("status") == 200) {
|
|
|
return result.getJSONArray("obj");
|
|
|
}
|
|
|
throw new Exception("查询失败!");
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> calendarPlanDetailItems(String executeStartTime, String executeEndTime, String planId, Integer searchTask, Integer status, String doctorCode) throws Exception {
|
|
|
String sqlCondition = "";
|
|
|
if (searchTask != null) {
|
|
|
if (searchTask == 8) {
|
|
|
sqlCondition += "and d.doctor='" + doctorCode + "' ";
|
|
|
} else {
|
|
|
sqlCondition += " and i.code=" + searchTask + " ";
|
|
|
}
|
|
|
}
|
|
|
if (status != null) {
|
|
|
sqlCondition += "and d.status=" + status;
|
|
|
}//服务项目
|
|
|
String sql = " select d.id,d.plan_id as planId,i.code,i.name,p.patient,d.frequency_code,DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s') as createTime from wlyy_specialist.wlyy_rehabilitation_plan_detail d " +
|
|
|
" LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p ON p.id=d.plan_id " +
|
|
|
" LEFT JOIN wlyy_specialist.wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
|
|
|
" where d.plan_id='" + planId + "' " + sqlCondition + " group by i.code";
|
|
|
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
for (Map<String, Object> map : mapList) {
|
|
|
String sql1 = "SELECT d.frequency_code,d.plan_id as planId ,d.id,DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s') AS createTime " +
|
|
|
"FROM wlyy_specialist.wlyy_rehabilitation_plan_detail d " +
|
|
|
"WHERE d.plan_id = '" + planId + "' and d.hospital_service_item_id='" + map.get("code") + "'ORDER BY d.create_time DESC";
|
|
|
List<Map<String, Object>> mapList1 = jdbcTemplate.queryForList(sql1);
|
|
|
if (mapList1 != null && mapList1.size() != 0) {
|
|
|
Map<String, Object> map1 = mapList1.get(0);
|
|
|
map.put("frequency_code", map1.get("frequency_code"));
|
|
|
map.put("planId", map1.get("planId"));
|
|
|
map.put("id", map1.get("id"));
|
|
|
map.put("createTime", map1.get("createTime"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (Map<String, Object> map : mapList) {
|
|
|
if (!StringUtils.isNoneBlank(map.get("frequency_code").toString())) {
|
|
|
String sqlCount = "SELECT ror.id,MAX(ror.complete_time) as date,count(*) as total FROM wlyy_specialist.`wlyy_rehabilitation_operate_records` ror, " +
|
|
|
"wlyy_specialist.wlyy_rehabilitation_plan_detail pd WHERE pd.id = ror.rehabilitation_detail_id " +
|
|
|
"AND pd.plan_id = '" + planId + "' AND pd.hospital_service_item_id='" + map.get("code") + "' AND ror.`status`=1 ";
|
|
|
List<Map<String, Object>> mapList1 = jdbcTemplate.queryForList(sqlCount);
|
|
|
int count = 0;
|
|
|
if (map.get("code").toString().equalsIgnoreCase("6")) {
|
|
|
/**
|
|
|
* 这边是随访的
|
|
|
* 加入type=‘21’
|
|
|
*/
|
|
|
String allPlanSql = "select wf.id as id,wf.followup_no as followupNo,wf.followup_date as followupDate,wf.followup_plan_date as followupPlanDate,wf.followup_next_date as followupNextDate,\n" +
|
|
|
"wf.followup_type as followupType,wf.followup_class as followupClass,wf.followup_manager_status as followupManagerStatus,wf.doctor_code as doctorCode,wf.doctor_name as doctorName,\n" +
|
|
|
"wf.jwdoctor_code as jwdoctorCode,wf.org_code as orgCode,wf.org_name as orgName,wf.jworg_code as jworgCode,wf.patient_code as patientCode,wf.patient_name as patientName,wf.idcard,\n" +
|
|
|
"wf.data_from as dataFrom,wf.status,wf.followup_content_phone as followupContentPhone,wf.creater,wf.sign_type as signType,wf.admin_team_code as adminTeamCode,wf.sign_code as signCode,\n" +
|
|
|
"wf.prescription_code as prescriptionCode,wf.type from wlyy_followup wf where 1=1 and wf.status !=0\n";
|
|
|
allPlanSql += " and wf.type='21' ";
|
|
|
allPlanSql += "and wf.patient_code = '" + map.get("patient") + "' order by wf.followup_plan_date desc";
|
|
|
List<Map<String, Object>> allPlanList = jdbcTemplate.queryForList(allPlanSql);
|
|
|
count = allPlanList.size();
|
|
|
}
|
|
|
|
|
|
if (map.get("code").toString().equalsIgnoreCase("7")) {
|
|
|
String allPrescrSql = "SELECT p.`name`, TIMESTAMPDIFF(YEAR,p.birthday,SYSDATE()) age, p.sex, p.photo, pr.`status`, pr.`code`, \n" +
|
|
|
"LEFT(pr.create_time,19) AS createTime, pr.doctor, pr.min_drug_day AS minDrugDay, LEFT(pr.pres_create_time,19) AS presCreateTime \n" +
|
|
|
"FROM wlyy_prescription pr LEFT JOIN wlyy_patient p ON pr.patient = p.`code` WHERE 1=1 AND pr.patient = '" + map.get("patient") + "' AND pr.status = 100 GROUP BY pr.`code`;";
|
|
|
List<Map<String, Object>> allPrescrList = jdbcTemplate.queryForList(allPrescrSql);
|
|
|
count = allPrescrList.size();
|
|
|
}
|
|
|
|
|
|
if (mapList1 != null && mapList1.size() != 0) {
|
|
|
Map<String, Object> map1 = mapList1.get(0);
|
|
|
map.put("compeletTotal", new Integer(map1.get("total").toString()) + count);
|
|
|
map.put("firstDate", map1.get("date"));
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
int codeCount = 0;
|
|
|
|
|
|
if (map.get("code").toString().equalsIgnoreCase("6")) { //康复随访
|
|
|
//该居民的所有随访计划,需要同步展示到康复计划-康复随访内
|
|
|
String allPlanSql = "select wf.id as id,wf.followup_no as followupNo,wf.followup_date as followupDate,wf.followup_plan_date as followupPlanDate,wf.followup_next_date as followupNextDate,\n" +
|
|
|
"wf.followup_type as followupType,wf.followup_class as followupClass,wf.followup_manager_status as followupManagerStatus,wf.doctor_code as doctorCode,wf.doctor_name as doctorName,\n" +
|
|
|
"wf.jwdoctor_code as jwdoctorCode,wf.org_code as orgCode,wf.org_name as orgName,wf.jworg_code as jworgCode,wf.patient_code as patientCode,wf.patient_name as patientName,wf.idcard,\n" +
|
|
|
"wf.data_from as dataFrom,wf.status,wf.followup_content_phone as followupContentPhone,wf.creater,wf.sign_type as signType,wf.admin_team_code as adminTeamCode,wf.sign_code as signCode,\n" +
|
|
|
"wf.prescription_code as prescriptionCode,wf.type from wlyy_followup wf where 1=1 and wf.status !=0\n" +
|
|
|
"and wf.patient_code = '" + map.get("patient") + "' order by wf.followup_plan_date desc";
|
|
|
List<Map<String, Object>> allPlanList = jdbcTemplate.queryForList(allPlanSql);
|
|
|
codeCount = allPlanList.size();
|
|
|
map.put("allPlanList", allPlanList);
|
|
|
}
|
|
|
|
|
|
if (map.get("code").toString().equalsIgnoreCase("7")) { //康复复诊
|
|
|
//居民的处方续方,需要同步展示到康复计划-康复复诊内
|
|
|
String allPrescrSql = "SELECT p.`name`, TIMESTAMPDIFF(YEAR,p.birthday,SYSDATE()) age, p.sex, p.photo, pr.`status`, pr.`code`, \n" +
|
|
|
"LEFT(pr.create_time,19) AS createTime, pr.doctor, pr.min_drug_day AS minDrugDay, LEFT(pr.pres_create_time,19) AS presCreateTime \n" +
|
|
|
"FROM wlyy_prescription pr LEFT JOIN wlyy_patient p ON pr.patient = p.`code` WHERE 1=1 AND pr.patient = '" + map.get("patient") + "' AND pr.status = 100 GROUP BY pr.`code`;";
|
|
|
List<Map<String, Object>> allPrescrList = jdbcTemplate.queryForList(allPrescrSql);
|
|
|
codeCount = allPrescrList.size();
|
|
|
map.put("allPrescrList", allPrescrList);
|
|
|
}
|
|
|
|
|
|
String sqlCount = "SELECT\n" +
|
|
|
"\tCOUNT(pd.id) AS total ,\n" +
|
|
|
"\tCOUNT(CASE WHEN pd.`status`=1 THEN 1 ELSE NULL END) AS compeletTotal\n" +
|
|
|
"FROM\n" +
|
|
|
"\twlyy_specialist.wlyy_rehabilitation_plan_detail pd\n" +
|
|
|
"WHERE\n" +
|
|
|
"\t pd.plan_id = '" + planId + "' " +
|
|
|
"AND pd.hospital_service_item_id='" + map.get("code") + "' and (pd.frequency_code IS NOT NULL AND pd.frequency_code<>'')\n";
|
|
|
|
|
|
List<Map<String, Object>> mapList1 = jdbcTemplate.queryForList(sqlCount);
|
|
|
if (mapList1 != null && mapList1.size() != 0) {
|
|
|
//随访
|
|
|
Map<String, Object> map1 = mapList1.get(0);
|
|
|
// map.put("total",new Integer(map1.get("total").toString()) + codeCount);
|
|
|
// map.put("compeletTotal",new Integer(map1.get("compeletTotal").toString()) + codeCount);
|
|
|
map.put("total", new Integer(map1.get("total").toString()));
|
|
|
map.put("compeletTotal", new Integer(map1.get("compeletTotal").toString()));
|
|
|
}
|
|
|
String dateSql = "SELECT MAX(CASE WHEN pd.`status`=1 THEN pd.execute_time ELSE NULL END) AS firstDate FROM wlyy_specialist.wlyy_rehabilitation_plan_detail pd " +
|
|
|
"WHERE pd.plan_id = '" + planId + "' AND pd.hospital_service_item_id='" + map.get("code") + "'";
|
|
|
List<Map<String, Object>> mapList2 = jdbcTemplate.queryForList(dateSql);
|
|
|
if (mapList2 != null && mapList2.size() != 0) {
|
|
|
Map<String, Object> map1 = mapList2.get(0);
|
|
|
map.put("firstDate", map1.get("firstDate"));
|
|
|
String condition = "";
|
|
|
if (map1.get("firstDate") != null && StringUtils.isNoneBlank(map1.get("firstDate").toString())) {
|
|
|
condition = "and pd.execute_time >='" + map1.get("firstDate").toString() + "'";
|
|
|
}
|
|
|
String dateSql1 = "SELECT pd.execute_time as lastDate FROM wlyy_specialist.wlyy_rehabilitation_plan_detail pd " +
|
|
|
"WHERE pd.plan_id = '" + planId + "' AND pd.hospital_service_item_id='" + map.get("code") + "' and pd.status=0 " + condition + " order by pd.execute_time ASC ";
|
|
|
List<Map<String, Object>> mapList3 = jdbcTemplate.queryForList(dateSql1);
|
|
|
if (mapList3 != null && mapList3.size() != 0) {
|
|
|
Map<String, Object> map2 = mapList3.get(0);
|
|
|
map.put("lastDate", map2.get("lastDate"));
|
|
|
} else {
|
|
|
map.put("lastDate", null);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (map.get("code").toString().equalsIgnoreCase("2")) {//康复咨询
|
|
|
String typeSql = " and a.type in (2,18)";
|
|
|
//总康复咨询数量
|
|
|
String sqlTotal = "select count(*)\n" +
|
|
|
"from wlyy_consult a,wlyy_consult_team b where a.code = b.consult and a.patient = '" + map.get("patient") + "' and a.del = '1' " + typeSql + " ";
|
|
|
Integer consultTotal = jdbcTemplate.queryForObject(sqlTotal, Integer.class);
|
|
|
|
|
|
String healthCount = "SELECT * FROM wlyy_patient_reservation WHERE incidental_msg_type = 0 AND source = 4 AND patient = '" + map.get("patient") + "' ORDER BY start_time DESC";
|
|
|
List<Map<String, Object>> healthList = jdbcTemplate.queryForList(healthCount);
|
|
|
map.put("healthList", healthList);
|
|
|
map.put("total", consultTotal + healthList.size());
|
|
|
//完成康复咨询数量
|
|
|
sqlTotal = "select count(*)\n" +
|
|
|
"from wlyy_consult a,wlyy_consult_team b where a.code = b.consult and a.patient = '" + map.get("patient") + "' and a.del = '1' " + typeSql + " and b.`status`=1";
|
|
|
consultTotal = jdbcTemplate.queryForObject(sqlTotal, Integer.class);
|
|
|
map.put("compeletTotal", consultTotal + healthList.size());
|
|
|
//上次发起时间
|
|
|
String sqlTemp = "select a.czrq " +
|
|
|
"from wlyy_consult a,wlyy_consult_team b where a.code = b.consult and a.patient = '" + map.get("patient") + "' and a.del = '1' " + typeSql + " order by a.czrq desc limit 1";
|
|
|
List<Map<String, Object>> czrqMap = jdbcTemplate.queryForList(sqlTemp);
|
|
|
if (czrqMap.size() != 0) {
|
|
|
if (czrqMap.get(0).get("czrq") != null) {
|
|
|
map.put("lastDate", czrqMap.get(0).get("czrq").toString());
|
|
|
}
|
|
|
} else {
|
|
|
map.put("lastDate", null);
|
|
|
}
|
|
|
|
|
|
//未回复康复咨询数量
|
|
|
sqlTotal = "SELECT count(*) FROM wlyy.wlyy_consult_team a WHERE a.type = 18\n" +
|
|
|
"AND EXISTS ( SELECT DISTINCT t.id consultId FROM " + imDBName + ".topics t, " + imDBName + ".participants p, " + imDBName + ".doctors d, " + imDBName + ".sessions s \n" +
|
|
|
"WHERE p.participant_id = d.id AND t.session_id = p.session_id AND t.session_id = s.id\n" +
|
|
|
"AND s.type =18 AND t.`reply` = 0 AND a.consult = t.id\n" +
|
|
|
"and a.id in( select b.id from wlyy_consult a,wlyy_consult_team b \n" +
|
|
|
"where a.code = b.consult and a.patient = '" + map.get("patient") + "' and a.del = '1' " + typeSql + " )\n" +
|
|
|
")";
|
|
|
Integer noReplay = jdbcTemplate.queryForObject(sqlTotal, Integer.class);
|
|
|
map.put("noReplay", noReplay);
|
|
|
}
|
|
|
if (map.get("code").toString().equalsIgnoreCase("3")) {//健康检测,总的体征检测
|
|
|
String createTime = map.get("createTime").toString();
|
|
|
String sqlTotal = "select count(*) as total from device.wlyy_patient_health_index p where p.user ='" + map.get("patient") + "' and p.type IN(1,2) ";//and p.record_date >= '"+createTime+"'
|
|
|
String sqlTemp = "select p.value1,p.value2,p.value3,p.value4,p.value5,p.value6,p.value7,p.type from device.wlyy_patient_health_index p where p.user ='" + map.get("patient") + "' and p.type IN(1,2) order by p.record_date desc limit 0,1 ";
|
|
|
List<Map<String, Object>> maps = jdbcTemplate.queryForList(sqlTemp);
|
|
|
List<Map<String, Object>> mapTotal = jdbcTemplate.queryForList(sqlTotal);
|
|
|
if (mapTotal != null && mapTotal.size() != 0) {
|
|
|
map.put("compeletTotal", mapTotal.get(0).get("total"));
|
|
|
}
|
|
|
if (maps != null && maps.size() != 0) {
|
|
|
Map<String, Object> map1 = maps.get(0);
|
|
|
Map<String, Object> map2 = null;
|
|
|
if (maps.size() != 1) {
|
|
|
map2 = maps.get(1);
|
|
|
}
|
|
|
map.put("value1", map1.get("value1"));
|
|
|
map.put("value2", map1.get("value2"));
|
|
|
if (map2 != null) {
|
|
|
if (Integer.parseInt(map1.get("value1").toString()) > Integer.parseInt(map2.get("value1").toString())) {
|
|
|
map.put("value1Flag", 1);
|
|
|
} else if (Integer.parseInt(map1.get("value1").toString()) == Integer.parseInt(map2.get("value1").toString())) {
|
|
|
map.put("value1Flag", 0);
|
|
|
} else if (Integer.parseInt(map1.get("value1").toString()) < Integer.parseInt(map2.get("value1").toString())) {
|
|
|
map.put("value1Flag", -1);
|
|
|
}
|
|
|
if (map1.get("type").toString().equalsIgnoreCase("2")) {
|
|
|
if (Integer.parseInt(map1.get("value2").toString()) > Integer.parseInt(map2.get("value2").toString())) {
|
|
|
map.put("value2Flag", 1);
|
|
|
} else if (Integer.parseInt(map1.get("value2").toString()) == Integer.parseInt(map2.get("value2").toString())) {
|
|
|
map.put("value2Flag", 0);
|
|
|
} else if (Integer.parseInt(map1.get("value2").toString()) < Integer.parseInt(map2.get("value2").toString())) {
|
|
|
map.put("value2Flag", -1);
|
|
|
}
|
|
|
} else {
|
|
|
map.put("value2Flag", 0);
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
map.put("value1Flag", 0);
|
|
|
map.put("value2Flag", 0);
|
|
|
}
|
|
|
map.put("value3", map1.get("value3"));
|
|
|
map.put("value4", map1.get("value4"));
|
|
|
map.put("value5", map1.get("value5"));
|
|
|
map.put("value6", map1.get("value6"));
|
|
|
map.put("value7", map1.get("value7"));
|
|
|
map.put("type", map1.get("type"));
|
|
|
} else {
|
|
|
map.put("value1", null);
|
|
|
map.put("value2", null);
|
|
|
map.put("type", null);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return mapList;
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<PatientMedicalRecordsDO> selectByMedicalCode(String code) {
|
|
|
String str[] = code.split(",");
|
|
|
List<PatientMedicalRecordsDO> medicalRecordsDOS = new ArrayList<>();
|
|
|
for (int i = 0; i < str.length; i++) {
|
|
|
PatientMedicalRecordsDO medicalRecordsDO = medicalRecordsRehabilitationDao.findByCode(str[i]);
|
|
|
medicalRecordsDOS.add(medicalRecordsDO);
|
|
|
}
|
|
|
return medicalRecordsDOS;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 康复管理-康复计划按列表展示(区分我的任务他人任务)
|
|
|
*
|
|
|
* @param executeStartTime
|
|
|
* @param executeEndTime
|
|
|
* @param planId
|
|
|
* @param searchTask
|
|
|
* @param status
|
|
|
* @param doctorCode
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONArray calendarPlanDetailListWithTaskExecutor(String executeStartTime, String executeEndTime, String planId, Integer searchTask, Integer status, String doctorCode, String taskExecutor) throws Exception {
|
|
|
Map<String, Object> param = new HashedMap();
|
|
|
param.put("executeStartTime", executeStartTime);
|
|
|
param.put("executeEndTime", executeEndTime);
|
|
|
param.put("planId", planId);
|
|
|
param.put("searchTask", searchTask);
|
|
|
param.put("status", status);
|
|
|
param.put("doctorCode", doctorCode);
|
|
|
param.put("taskExecutor", taskExecutor);
|
|
|
ObjEnvelop objEnvelop = calendarPlanDetailList(planId, searchTask, status, doctorCode, executeStartTime, executeEndTime, taskExecutor);
|
|
|
org.json.JSONObject result = new org.json.JSONObject(objEnvelop);
|
|
|
if (result.getInt("status") == 200) {
|
|
|
return result.getJSONArray("obj");
|
|
|
}
|
|
|
throw new Exception("请求失败!");
|
|
|
}
|
|
|
}
|