|
@ -3,6 +3,7 @@ package com.yihu.jw.care.service.patient;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.care.aop.RedisLockAOP;
|
|
|
import com.yihu.jw.care.dao.family.PatientFamilyMemberDao;
|
|
@ -294,11 +295,13 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
|
|
|
if (patientDO.getMarriage()!=null){
|
|
|
patientDO.setMarriageName(dictService.fingByNameAndCode(ConstantUtil.DICT_MARRIAGE_STATUS,String.valueOf(patientDO.getMarriage())));
|
|
|
}
|
|
|
|
|
|
String deviceSql = "select COUNT(*) from wlyy_patient_device a where a.`user` = '"+patientId+"'";
|
|
|
Integer deviceFlag = jdbcTemplate.queryForObject(deviceSql, Integer.class);
|
|
|
patientDO.setDeviceFlag(deviceFlag);
|
|
|
res.put("patient",patientDO);
|
|
|
|
|
|
Map<String, Object> patientInfo = JSONObject.parseObject(JSON.toJSONString(patientDO,SerializerFeature.WriteMapNullValue), Map.class);
|
|
|
patientInfo.put("birthday",DateUtil.dateToStrShort(patientDO.getBirthday()));
|
|
|
res.put("patient",patientInfo);
|
|
|
|
|
|
String sql = "select * from base_service_package_sign_record where patient = '"+patientId+"' and status = 1 ";
|
|
|
List<ServicePackageSignRecordDO> signRecordDOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(ServicePackageSignRecordDO.class));
|
|
@ -593,7 +596,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param type 类型:1幼儿,2老人,3社工,4医生。5家属 不传返回四个类型的数据
|
|
|
* @param type 类型:1幼儿,2签约老人,3社工,4医生,5老人家属 6助老员,7社区老人(未签约) 不传返回四个类型的数据
|
|
|
* @param name 姓名
|
|
|
* @param area 查询区域 目前仅支持查询老人、社工、家属
|
|
|
* @param level 区域等级 2市3区4机构5团队6医生
|
|
@ -665,6 +668,34 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
|
|
|
re.put("oldFamily",list);
|
|
|
re.put("oldFamilyCount",findOlderFamilyTotal(name,area,level,filter));
|
|
|
}
|
|
|
if("6".equals(type)||StringUtils.isBlank(type)){//助老员
|
|
|
filter = "";
|
|
|
String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_org' ";
|
|
|
List<Map<String,Object>> listtmp = jdbcTemplate.queryForList(sqltmp);
|
|
|
if(listtmp.size()>0){
|
|
|
String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
|
|
|
orgCodes = orgCodes.replaceAll(",","','");
|
|
|
filter = " and h.org_code not in ('"+orgCodes+"')";
|
|
|
}
|
|
|
|
|
|
List<Map<String,Object>> list = findHelper4(name,area,level,limit,filter);
|
|
|
re.put("helper4",list);
|
|
|
re.put("helper4Total",findHelper4Total(name,area,level,filter));
|
|
|
}
|
|
|
if("7".equals(type)||StringUtils.isBlank(type)){//社区老人
|
|
|
filter = "";
|
|
|
String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_older' ";
|
|
|
List<Map<String,Object>> listtmp = jdbcTemplate.queryForList(sqltmp);
|
|
|
if(listtmp.size()>0){
|
|
|
String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
|
|
|
orgCodes = orgCodes.replaceAll(",","','");
|
|
|
filter = " and a.id not in ('"+orgCodes+"')";
|
|
|
}
|
|
|
|
|
|
List<Map<String,Object>> list = findUnSignOld(name,residentialArea,area,level,limit,filter);
|
|
|
re.put("unSignOld",list);
|
|
|
re.put("unSignOldCount",findUnSignOldTotal(name,residentialArea,area,level,filter));
|
|
|
}
|
|
|
return re;
|
|
|
}
|
|
|
|
|
@ -716,7 +747,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查找老人
|
|
|
* 查找签约老人
|
|
|
* @param name
|
|
|
* @param residentialArea
|
|
|
* @param limit
|
|
@ -725,7 +756,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
|
|
|
public List<Map<String,Object>> findOld(String name,String residentialArea,String area,Integer level,String limit,String filter1){
|
|
|
String sql = "SELECT a.id,a.name,a.photo,a.idcard,CAST(IFNULL(a.birthday,'') AS char ) birthday,a.residential_area residentialArea,a.sex " +
|
|
|
",a.ykt_id yktId, case 1 WHEN openid is not null then 1 WHEN a.on_line = '1' then 1 ELSE 0 end as online,IFNULL(sign_status,0) signStatus from base_patient a " +
|
|
|
" WHERE a.archive_type = 1 and a.del = '1' ";
|
|
|
" WHERE a.archive_type = 1 and a.del = '1' and a.sign_status=1 ";
|
|
|
|
|
|
//case 1 WHEN openid is not null then 1 WHEN a.on_line = '1' then 1 ELSE 0 end as online
|
|
|
//if(openid is null,0,1) onlineWx,IFNULL(a.on_line,0) onlinePad
|
|
@ -788,7 +819,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
|
|
|
}
|
|
|
|
|
|
public Integer findOldTotal(String name,String residentialArea,String area,Integer level,String filter){
|
|
|
String sql = "SELECT count(a.id) from base_patient a WHERE a.archive_type = 1 and a.del = '1' ";
|
|
|
String sql = "SELECT count(a.id) from base_patient a WHERE a.archive_type = 1 and a.del = '1' and a.sign_status=1 ";
|
|
|
if(!StringUtil.isBlank(name)){
|
|
|
sql+= " and name like '%"+name+"%' ";
|
|
|
}
|
|
@ -805,6 +836,88 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
|
|
|
return jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查找签约老人
|
|
|
* @param name
|
|
|
* @param residentialArea
|
|
|
* @param limit
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String,Object>> findUnSignOld(String name,String residentialArea,String area,Integer level,String limit,String filter1){
|
|
|
String sql = "SELECT a.id,a.name,a.photo,a.idcard,CAST(IFNULL(a.birthday,'') AS char ) birthday,a.residential_area residentialArea,a.sex " +
|
|
|
",a.ykt_id yktId, case 1 WHEN openid is not null then 1 WHEN a.on_line = '1' then 1 ELSE 0 end as online,IFNULL(sign_status,0) signStatus from base_patient a " +
|
|
|
" WHERE a.archive_type = 1 and a.del = '1' and a.sign_status=0 ";
|
|
|
|
|
|
if(!StringUtil.isBlank(name)){
|
|
|
sql+= " and name like '%"+name+"%' ";
|
|
|
}
|
|
|
if(!StringUtil.isBlank(residentialArea)){
|
|
|
sql+= " and residential_area = '"+residentialArea+"' ";
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(area)&&5==level){
|
|
|
return null;
|
|
|
}
|
|
|
sql += filter1;
|
|
|
sql += " GROUP BY a.id,a.name,a.photo,a.idcard,a.birthday,a.residential_area,a.sex,a.ykt_id,online,signStatus ";
|
|
|
sql += " ORDER BY online desc,a.ykt_id desc,signStatus desc";
|
|
|
sql += limit;
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
String sqlLife= "SELECT COUNT(*) from base_life_care_order ";
|
|
|
String sqlEmergency= "SELECT COUNT(*) from base_emergency_assistance_order ";
|
|
|
String sqlSecurity= "SELECT COUNT(*) from base_security_monitoring_order ";
|
|
|
String sqlDevice = "SELECT pd.category_code deviceFlag, IFNULL(d.contact_status,0) status from wlyy_patient_device pd,wlyy_devices d";
|
|
|
for (Map<String,Object> map:list){
|
|
|
String paientId = map.get("id").toString();
|
|
|
String filterDevice = " WHERE pd.device_sn = d.device_code and pd.user = '"+paientId+"' ORDER BY deviceFlag,status desc";
|
|
|
String idcardNo = map.get("idcard") + "";
|
|
|
Date birthday = DateUtil.strToDate(map.get("birthday").toString());
|
|
|
Integer age = IdCardUtil.getAgeByIdcardOrBirthday(idcardNo,birthday);
|
|
|
map.put("age",age);
|
|
|
String filter = " where patient = '"+paientId+"'";
|
|
|
Integer lifeCare = jdbcTemplate.queryForObject(sqlLife+filter,Integer.class);
|
|
|
Integer emergency = jdbcTemplate.queryForObject(sqlEmergency+filter,Integer.class);
|
|
|
Integer security = jdbcTemplate.queryForObject(sqlSecurity+filter,Integer.class);
|
|
|
List<Map<String,Object>> deviceList = jdbcTemplate.queryForList(sqlDevice+filterDevice);
|
|
|
Iterator it = deviceList.listIterator();
|
|
|
Map<Object,Object> deviceMap = new HashedMap();
|
|
|
while (it.hasNext()){
|
|
|
Map<String,Object> tmp = (Map<String,Object>)it.next();
|
|
|
if(deviceMap.containsKey(tmp.get("deviceFlag"))){
|
|
|
it.remove();
|
|
|
}else{
|
|
|
deviceMap.put(tmp.get("deviceFlag"),tmp.get("deviceFlag"));
|
|
|
}
|
|
|
}
|
|
|
map.put("lifeCare",lifeCare);
|
|
|
map.put("emergency",emergency);
|
|
|
map.put("security",security);
|
|
|
map.put("devices",deviceList);
|
|
|
sql = " select sum(total) from ( " +
|
|
|
"select count(id) total from base_emergency_assistance_order o where o.patient ='"+paientId+"' and o.`status`=1 " +
|
|
|
"UNION All " +
|
|
|
"select count(id) total from base_security_monitoring_order o where o.patient ='"+paientId+"' and o.`status`=1 " +
|
|
|
")A ";
|
|
|
Integer warnTotal = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
map.put("warnFlag",warnTotal>0?true:false);
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
public Integer findUnSignOldTotal(String name,String residentialArea,String area,Integer level,String filter){
|
|
|
String sql = "SELECT count(a.id) from base_patient a WHERE a.archive_type = 1 and a.del = '1' and a.sign_status=0 ";
|
|
|
if(!StringUtil.isBlank(name)){
|
|
|
sql+= " and name like '%"+name+"%' ";
|
|
|
}
|
|
|
if(!StringUtil.isBlank(residentialArea)){
|
|
|
sql+= " and residential_area = '"+residentialArea+"' ";
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(area)&&5==level){
|
|
|
return 0;
|
|
|
}
|
|
|
sql += filter;
|
|
|
return jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查找社工
|
|
|
* @param name
|
|
@ -827,7 +940,7 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
String sqlLife= "SELECT COUNT(*) from base_life_care_order where `status` = 2";
|
|
|
String sqlEmergency= "SELECT COUNT(*) from base_emergency_assistance_order where `status` = 0";
|
|
|
String sqlSecurity= "SELECT COUNT(*) from base_security_monitoring_order where `status` = 7 ";
|
|
|
String sqlSecurity= "SELECT COUNT(*) from base_security_monitoring_order where `status` = 0 ";
|
|
|
for (Map<String,Object> map:list){
|
|
|
String doctorId = map.get("id").toString();
|
|
|
List<BaseDoctorHospitalDO> hospitalDOS = doctorHospitalDao.findByDoctorCode(doctorId);
|
|
@ -863,6 +976,74 @@ public class CarePatientService extends BaseJpaService<BasePatientDO, BasePatien
|
|
|
return jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查找助老员
|
|
|
* @param name
|
|
|
* @param limit
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String,Object>> findHelper4(String name,String area,Integer level,String limit,String fileter){
|
|
|
String sql = "SELECT a.id,a.name,a.photo,a.sex,IFNULL(a.on_line,0) online from base_doctor a,base_doctor_hospital h" +
|
|
|
" WHERE a.id=h.doctor_code and a.doctor_level = 4 and a.del = '1' and h.del = '1' ";
|
|
|
if(!StringUtil.isBlank(name)){
|
|
|
sql+= " and a.name like '%"+name+"%' ";
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(area)&&5==level){
|
|
|
sql += " and EXISTS ( select 1 from base_patient_helper ph,base_service_package_sign_record sr, " +
|
|
|
" base_service_package_record r, base_service_package_item i,base_service_package pack " +
|
|
|
" where ph.del=1 and ph.doctor = a.id and sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id " +
|
|
|
" and r.service_package_id = pack.id and i.del = 1 and sr.`status`=1 and CONVERT(sr.patient USING utf8) = ph.patient " +
|
|
|
" and r.team_code='"+area+"') ";
|
|
|
}
|
|
|
sql += fileter;
|
|
|
sql += " ORDER BY online desc";
|
|
|
sql+=limit;
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
String sqlLife= " SELECT COUNT(distinct ord.id) from base_life_care_order ord,base_doctor_hospital h where ord.`status` = 2 " +
|
|
|
" and ord.hospital = h.org_code and h.del='1' ";
|
|
|
String sqlEmergency= " SELECT COUNT(distinct ord.id) from base_emergency_assistance_order ord,base_patient_helper h where ord.`status` = 0 " +
|
|
|
" and ord.patient = h.patient and h.del=1 ";
|
|
|
String sqlSecurity= " SELECT COUNT(distinct ord.id) from base_security_monitoring_order ord,base_patient_helper h where ord.`status` = 0 " +
|
|
|
" and ord.patient = h.patient and h.del=1 ";
|
|
|
for (Map<String,Object> map:list){
|
|
|
String doctorId = map.get("id").toString();
|
|
|
List<BaseDoctorHospitalDO> hospitalDOS = doctorHospitalDao.findByDoctorCode(doctorId);
|
|
|
if (hospitalDOS.size()>0){
|
|
|
map.put("residentialArea",hospitalDOS.get(0).getOrgName());
|
|
|
map.put("org_code",hospitalDOS.get(0).getOrgCode());
|
|
|
}else {
|
|
|
map.put("residentialArea",null);
|
|
|
map.put("org_code",null);
|
|
|
}
|
|
|
|
|
|
String filter = " and h.doctor_code = '"+doctorId+"'";
|
|
|
Integer lifeCare = jdbcTemplate.queryForObject(sqlLife+filter,Integer.class);
|
|
|
filter = " and h.doctor = '"+doctorId+"'";
|
|
|
Integer emergency = jdbcTemplate.queryForObject(sqlEmergency+filter,Integer.class);
|
|
|
Integer security = jdbcTemplate.queryForObject(sqlSecurity+filter,Integer.class);
|
|
|
map.put("lifeCare",lifeCare);
|
|
|
map.put("emergency",emergency);
|
|
|
map.put("security",security);
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
public Integer findHelper4Total(String name,String area,Integer level,String filter){
|
|
|
String sql = "SELECT count(a.id) from base_doctor a,base_doctor_hospital h WHERE a.id=h.doctor_code and a.doctor_level = 4 and a.del = '1' and h.del = '1' ";
|
|
|
if(!StringUtil.isBlank(name)){
|
|
|
sql+= " and name like '%"+name+"%' ";
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(area)&&5==level){
|
|
|
sql += " and EXISTS ( select 1 from base_patient_helper ph,base_service_package_sign_record sr, " +
|
|
|
" base_service_package_record r, base_service_package_item i,base_service_package pack " +
|
|
|
" where ph.del=1 and ph.doctor = a.id and sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id " +
|
|
|
" and r.service_package_id = pack.id and i.del = 1 and sr.`status`=1 and CONVERT(sr.patient USING utf8) = ph.patient " +
|
|
|
" and r.team_code='"+area+"') ";
|
|
|
}
|
|
|
sql += filter;
|
|
|
return jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
}
|
|
|
|
|
|
public List<Map<String,Object>> findOlderFamily(String name,String limit,String area,Integer level,String fileter){
|
|
|
String sql = "select t2.id,t2.name,t2.sex,t2.mobile,t2.idcard,if(t2.openid is null,0,1) online,t2.photo,t1.family_relation,t1.patient older,t3.name olderName " +
|
|
|
"from base_patient t2 left JOIN base_patient_family_member t1 on t1.family_member = t2.id " +
|