|
@ -184,18 +184,37 @@ public class BirthdayWishesService {
|
|
|
//获取当天0点
|
|
|
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
|
|
String now = f.format(new Date());
|
|
|
String sql = "SELECT DISTINCT p.id patient, p.`name`, " +
|
|
|
"CASE p.sex WHEN 1 THEN '男' WHEN 2 THEN '女' END sex," +
|
|
|
"p.idcard, p.photo," +
|
|
|
" CASE LENGTH(p.idcard) WHEN 18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END date " +
|
|
|
"from wlyy_archive a,base_patient p WHERE a.patient = p.id and a.sign_status = 1 and p.del=1 and EXISTS( " +
|
|
|
"SELECT DISTINCT sr.patient from base_service_package_sign_record sr,base_service_package_record r,base_service_package pack, " +
|
|
|
"base_team_member m " +
|
|
|
"WHERE sr.id = r.sign_id and sr.patient = a.patient and r.service_package_id = pack.id " +
|
|
|
"and m.team_code = r.team_code and m.doctor_code = '"+doctor+"' ) "+
|
|
|
" and (p.archive_status<>2 or p.archive_status is null) " +
|
|
|
"AND CASE LENGTH(p.idcard) WHEN 18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END = '" + dateString + "' " ;
|
|
|
List<Map<String, Object>> patientInfos = jdbcTemplate.queryForList(sql);
|
|
|
BaseDoctorDO baseDoctorDO = doctorDao.findById(doctor);
|
|
|
|
|
|
if(null==baseDoctorDO){
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
List<Map<String, Object>> patientInfos = new ArrayList<>();
|
|
|
if (2==baseDoctorDO.getLevel()){
|
|
|
String sql = "SELECT DISTINCT p.id patient, p.`name`, " +
|
|
|
"CASE p.sex WHEN 1 THEN '男' WHEN 2 THEN '女' END sex," +
|
|
|
"p.idcard, p.photo," +
|
|
|
" CASE LENGTH(p.idcard) WHEN 18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END date " +
|
|
|
"from wlyy_archive a,base_patient p WHERE a.patient = p.id and a.sign_status = 1 and p.del=1 and EXISTS( " +
|
|
|
"SELECT DISTINCT sr.patient from base_service_package_sign_record sr,base_service_package_record r,base_service_package pack, " +
|
|
|
"base_team_member m " +
|
|
|
"WHERE sr.id = r.sign_id and sr.patient = a.patient and r.service_package_id = pack.id " +
|
|
|
"and m.team_code = r.team_code and m.doctor_code = '"+doctor+"' ) "+
|
|
|
" and (p.archive_status<>2 or p.archive_status is null) " +
|
|
|
"AND CASE LENGTH(p.idcard) WHEN 18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END = '" + dateString + "' " ;
|
|
|
patientInfos = jdbcTemplate.queryForList(sql);
|
|
|
}
|
|
|
if (4==baseDoctorDO.getLevel()){
|
|
|
String sql = "SELECT DISTINCT p.id patient, p.`name`, " +
|
|
|
"CASE p.sex WHEN 1 THEN '男' WHEN 2 THEN '女' END sex," +
|
|
|
"p.idcard, p.photo," +
|
|
|
" CASE LENGTH(p.idcard) WHEN 18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END date " +
|
|
|
" from base_patient p INNER JOIN base_patient_helper ph on p.id = ph.patient and ph.del=1 " +
|
|
|
" WHERE ph.doctor='"+doctor+"' " +
|
|
|
" AND CASE LENGTH(p.idcard) WHEN 18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END = '"+dateString+"'";
|
|
|
patientInfos = jdbcTemplate.queryForList(sql);
|
|
|
}
|
|
|
|
|
|
//整理未发送居民信息
|
|
|
Iterator<Map<String, Object>> iterator = patientInfos.iterator();
|
|
|
while (iterator.hasNext()){
|
|
@ -233,15 +252,29 @@ public class BirthdayWishesService {
|
|
|
//获取当天0点
|
|
|
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
|
|
String now = f.format(new Date());
|
|
|
String sql = "SELECT DISTINCT p.id " +
|
|
|
"from wlyy_archive a,base_patient p WHERE a.patient = p.id and p.del=1 and a.sign_status = 1 and EXISTS( " +
|
|
|
"SELECT DISTINCT sr.patient from base_service_package_sign_record sr,base_service_package_record r, " +
|
|
|
"base_team_member m " +
|
|
|
"WHERE sr.id = r.sign_id and sr.patient = a.patient and sr.id = r.sign_id " +
|
|
|
"and m.team_code = r.team_code and m.doctor_code = '"+doctor+"' ) "+
|
|
|
" and (p.archive_status<>2 or p.archive_status is null) " +
|
|
|
"AND CASE LENGTH(p.idcard) WHEN 18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END = '" + dateString + "' " ;
|
|
|
List<String> patientInfos = jdbcTemplate.queryForList(sql,String.class);
|
|
|
BaseDoctorDO baseDoctorDO = doctorDao.findById(doctor);
|
|
|
if(null==baseDoctorDO){
|
|
|
return 0;
|
|
|
}
|
|
|
String sql="";
|
|
|
List<String> patientInfos = new ArrayList<>();
|
|
|
if (2==baseDoctorDO.getLevel()){
|
|
|
sql = "SELECT DISTINCT p.id " +
|
|
|
"from wlyy_archive a,base_patient p WHERE a.patient = p.id and p.del=1 and a.sign_status = 1 and EXISTS( " +
|
|
|
"SELECT DISTINCT sr.patient from base_service_package_sign_record sr,base_service_package_record r, " +
|
|
|
"base_team_member m " +
|
|
|
"WHERE sr.id = r.sign_id and sr.patient = a.patient and sr.id = r.sign_id " +
|
|
|
"and m.team_code = r.team_code and m.doctor_code = '"+doctor+"' ) "+
|
|
|
" and (p.archive_status<>2 or p.archive_status is null) " +
|
|
|
"AND CASE LENGTH(p.idcard) WHEN 18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END = '" + dateString + "' " ;
|
|
|
patientInfos = jdbcTemplate.queryForList(sql,String.class);
|
|
|
}
|
|
|
if (4==baseDoctorDO.getLevel()) {
|
|
|
sql = "SELECT DISTINCT p.id from base_patient p INNER JOIN base_patient_helper ph on p.id = ph.patient and ph.del=1 " +
|
|
|
" WHERE ph.doctor='"+doctor+"' " +
|
|
|
"AND CASE LENGTH(p.idcard) WHEN 18 then SUBSTR(p.idcard,11,4) when 15 then SUBSTR(p.idcard, 9,4) END = '" + dateString + "' " ;
|
|
|
patientInfos = jdbcTemplate.queryForList(sql,String.class);
|
|
|
}
|
|
|
Integer count=0;
|
|
|
for (String tmp:patientInfos){
|
|
|
if (null == sendPatients){
|
|
@ -394,6 +427,7 @@ public class BirthdayWishesService {
|
|
|
List<BirthDayWishesToPatient> list = new ArrayList<>();
|
|
|
List<BirthDayWishesToPatient> birthdayWishesList = new ArrayList<>();
|
|
|
String p = json.get("patient") + "";
|
|
|
p = "'"+p.replace(",","','")+"'";
|
|
|
String doctorCode = json.get("doctorCode") + "";
|
|
|
Integer sendType = (Integer) json.get("sendType");
|
|
|
String currentUserRole = json.has("currentUserRole")?json.get("currentUserRole") + "":null;
|
|
@ -421,7 +455,7 @@ public class BirthdayWishesService {
|
|
|
Set<String> openidSet = new HashSet<>();
|
|
|
BaseDoctorDO doctor = doctorDao.findById(doctorCode);
|
|
|
|
|
|
String sql = " select * from ( select p.id as patient,p.name,we.openid from base_patient p Left join base_patient_wechat we on p.id = we.patient_id where p.id in ( "+p.toString()+") " +
|
|
|
String sql = " select * from ( select p.id as patient,p.name,we.openid from base_patient p Left join base_patient_wechat we on p.id = we.patient_id where p.id in ( "+p+") " +
|
|
|
" order by we.create_time desc )A group by A.patient ";
|
|
|
|
|
|
List<Map<String, Object>> patientInfos = jdbcTemplate.queryForList(sql);
|
|
@ -565,4 +599,131 @@ public class BirthdayWishesService {
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
|
|
|
/*****************************************助老员部分********************************************************************/
|
|
|
/**
|
|
|
* 获取医生生日列表
|
|
|
*/
|
|
|
public Map<String, Object> helperGetBirthdayPatientList(String doctorCode, String patientName, Integer signYear, String startDate, String endDate, Integer status, String currentUserRole, String currentUserRoleLevel,
|
|
|
Integer roleType, Integer page, Integer pageSize) throws Exception {
|
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
List<Map<String, Object>> resultList = new ArrayList();
|
|
|
Long allCount = 0l;
|
|
|
//判断是否筛选推送条件,若未筛选则从数据库直接查生日居民,再进行匹配是否推送,若选择已推送则从推送记录查,若未发送则从未推送表查
|
|
|
//社工签约患者
|
|
|
String sql = " SELECT Distinct p.id patient,p.idcard,p.mobile,p.name,p.sex,p.id,p.photo," +
|
|
|
"CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END birthday " ;
|
|
|
String sqlCount = "SELECT count(distinct p.idcard) ";
|
|
|
|
|
|
String whereSql = " from base_patient p INNER JOIN base_patient_helper ph on p.id = ph.patient and ph.del=1 ";
|
|
|
|
|
|
//根据权限获取生日居民列表
|
|
|
if (roleType == 1) {
|
|
|
whereSql += " WHERE ph.doctor='"+doctorCode+"' ";
|
|
|
} else {//管理员
|
|
|
switch (currentUserRoleLevel) {
|
|
|
case "1": {//省
|
|
|
whereSql += " INNER JOIN base_doctor_hospital dh on ph.doctor = dh.doctor_code and dh.del=1 INNER JOIN base_org org on dh.org_code = org.code and org.del=1\n" +
|
|
|
" where org.province_code='"+currentUserRole+"' ";
|
|
|
break;
|
|
|
}
|
|
|
case "2": {//市
|
|
|
whereSql += " INNER JOIN base_doctor_hospital dh on ph.doctor = dh.doctor_code and dh.del=1 INNER JOIN base_org org on dh.org_code = org.code and org.del=1\n" +
|
|
|
" where org.city_code='"+currentUserRole+"' ";
|
|
|
break;
|
|
|
}
|
|
|
case "3": {//区
|
|
|
whereSql += " INNER JOIN base_doctor_hospital dh on ph.doctor = dh.doctor_code and dh.del=1 INNER JOIN base_org org on dh.org_code = org.code and org.del=1\n" +
|
|
|
" where org.town_code='"+currentUserRole+"' ";
|
|
|
break;
|
|
|
}
|
|
|
case "4": {//社区机构
|
|
|
whereSql += " INNER JOIN base_doctor_hospital dh on ph.doctor = dh.doctor_code and dh.del=1 INNER JOIN base_org org on dh.org_code = org.code and org.del=1\n" +
|
|
|
" where org.code='"+currentUserRole+"' ";
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(patientName)) {
|
|
|
whereSql += " and p.name like '%" + patientName + "%' ";
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
|
|
|
String start = startDate.substring(4).replace("-", "");
|
|
|
String end = endDate.substring(4).replace("-", "");
|
|
|
Integer birStart = Integer.parseInt(start);
|
|
|
Integer birEnd = Integer.parseInt(end);
|
|
|
//判断生日日期
|
|
|
if(birEnd > birStart) {
|
|
|
whereSql += " AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END >= '" + start + "' " +
|
|
|
" AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END <= '" + end + "' ";
|
|
|
}else if(birEnd < birStart){
|
|
|
whereSql += " AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END >= '" + end + "' " +
|
|
|
" AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END <= '" + start + "' ";
|
|
|
}else {
|
|
|
whereSql += " AND CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END = '" + end + "' ";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
whereSql += "and DATE_FORMAT(ph.create_time,'%m%d')< CASE LENGTH(p.idcard) WHEN 18 THEN SUBSTR(p.idcard, 11, 4) WHEN 15 THEN SUBSTR(p.idcard, 9, 4) END ";
|
|
|
sql = sql + whereSql + " order by birthday limit "+(page-1)*pageSize + "," + pageSize;
|
|
|
sqlCount = sqlCount + whereSql ;
|
|
|
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
allCount = jdbcTemplate.queryForObject(sqlCount, Long.class);
|
|
|
resultMap.put("total", allCount);
|
|
|
//获取生日居民code
|
|
|
String patientString = "";
|
|
|
for (Map<String, Object> map : list) {
|
|
|
patientString += "'"+ map.get("patient") + "',";
|
|
|
}
|
|
|
if(patientString.length() > 0) {
|
|
|
//查询该居民是否有推送过
|
|
|
String es = "SELECT patient_code patientCode,doctor_name doctorName,content,birthday,create_time createTime FROM birthday_wishes_to_patient where patient_code in (" + patientString.substring(0, patientString.length() - 1) + ") and user_type =1 and create_time > '" + startDate + " 00:00:00' and create_time < '" + endDate + " 23:59:59'";
|
|
|
List<Map<String, Object>> sendPatientList = jdbcTemplate.queryForList(es);
|
|
|
Set<String> patientSet = new HashSet<>();
|
|
|
for (Map<String, Object> map : list) {
|
|
|
String patientCode = map.get("patient") + "";
|
|
|
//判断是否在推送记录里
|
|
|
if( null == status || 1 == status ) {
|
|
|
for (Map<String, Object> esMap : sendPatientList) {
|
|
|
if (patientCode.equals(esMap.get("patientCode") + "")) {
|
|
|
map.put("birthday", esMap.get("birthday") + "");
|
|
|
map.put("doctorName", esMap.get("doctorName") + "");
|
|
|
map.put("content", esMap.get("content") + "");
|
|
|
map.put("createTimeStr", (esMap.get("createTime") + "").replace("T", " ").replace("+0800", ""));
|
|
|
Date dateTmp = DateUtil.strToDate(esMap.get("createTime") + "");
|
|
|
map.put("createTime", (DateUtil.dateToChineseDate(dateTmp)));
|
|
|
map.put("status", "已发送");
|
|
|
BasePatientDO patientDO = patientDao.findById(map.get("patient") + "");
|
|
|
map.put("patientBirthday", IdCardUtil.getBirthdayForIdcardStr(patientDO.getIdcard()));
|
|
|
patientSet.add(patientCode);
|
|
|
resultList.add(map);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(null == status || 2 == status) {
|
|
|
//存取未发送居民
|
|
|
for (Map<String, Object> map : list) {
|
|
|
String patientCode = map.get("patient") + "";
|
|
|
if (!patientSet.contains(patientCode)) {
|
|
|
String birthday = map.get("birthday")+"日";
|
|
|
StringBuilder bir = new StringBuilder(birthday);
|
|
|
bir.insert(2, "月");
|
|
|
map.put("birthday", bir.toString());
|
|
|
map.put("status", "未发送");
|
|
|
BasePatientDO patientDO = patientDao.findById(map.get("patient") + "");
|
|
|
map.put("patientBirthday", IdCardUtil.getBirthdayForIdcardStr(patientDO.getIdcard()));
|
|
|
resultList.add(map);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
resultMap.put("detailModelList", resultList);
|
|
|
resultMap.put("total", allCount);
|
|
|
resultMap.put("pageCount", allCount%pageSize == 0 ?allCount/pageSize : allCount/pageSize +1);
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
}
|