|
@ -1,13 +1,21 @@
|
|
|
package com.yihu.wlyy.service.app.sign;
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.*;
|
|
|
|
|
|
import com.yihu.wlyy.entity.doctor.profile.Doctor;
|
|
|
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.entity.patient.SignFamily;
|
|
|
import com.yihu.wlyy.repository.patient.SignFamilyDao;
|
|
|
import com.yihu.wlyy.service.app.team.AdminTeamService;
|
|
|
import com.yihu.wlyy.service.common.account.DoctorService;
|
|
|
import com.yihu.wlyy.service.common.account.PatientService;
|
|
|
import com.yihu.wlyy.service.system.SystemDictService;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
@ -37,6 +45,14 @@ public class SignWebService extends BaseService {
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
@Autowired
|
|
|
private PatientService patientService;
|
|
|
@Autowired
|
|
|
private DoctorService doctorService;
|
|
|
@Autowired
|
|
|
private AdminTeamService adminTeamService;
|
|
|
@Autowired
|
|
|
private SystemDictService systemDictService;
|
|
|
|
|
|
/**
|
|
|
* 根据医生代码及签约状态编码 获取该医生签约患者的信息列表
|
|
@ -338,4 +354,284 @@ public class SignWebService extends BaseService {
|
|
|
public List<SignFamily> getSignInfoByIdcard(String idcard) {
|
|
|
return signFamilyDao.findAllByIdcard(idcard);
|
|
|
}
|
|
|
|
|
|
public JSONArray getSigns(String patient){
|
|
|
List<SignFamily> signFamilys = signFamilyDao.findAllActiveSignByPatient(patient);
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for(SignFamily signFamily: signFamilys){
|
|
|
AdminTeam adminTeam = adminTeamService.getTeam(signFamily.getAdminTeamId());
|
|
|
Doctor doctor = doctorService.findDoctorByCode(adminTeam.getLeaderCode());
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("hospitalName",signFamily.getHospitalName());
|
|
|
jsonObject.put("hospital",signFamily.getHospital());
|
|
|
jsonObject.put("code",signFamily.getCode());
|
|
|
jsonObject.put("teamCode",signFamily.getTeamCode());
|
|
|
jsonObject.put("begin",signFamily.getBegin());
|
|
|
jsonObject.put("end",signFamily.getEnd());
|
|
|
jsonObject.put("status",signFamily.getStatus());
|
|
|
jsonObject.put("leader",adminTeam.getLeaderCode());
|
|
|
jsonObject.put("leaderName",doctor.getName());
|
|
|
jsonObject.put("doctor",signFamily.getDoctor());
|
|
|
jsonObject.put("doctorHealth",signFamily.getDoctorHealth());
|
|
|
jsonObject.put("doctorName",signFamily.getDoctorName());
|
|
|
jsonObject.put("doctorHealthName",signFamily.getDoctorHealthName());
|
|
|
jsonObject.put("expensesStatus",signFamily.getExpensesStatus());
|
|
|
jsonObject.put("applyDate",signFamily.getApplyDate());
|
|
|
jsonObject.put("type",signFamily.getType());
|
|
|
jsonObject.put("typeName",signFamily.getType()==1?"三师签约":"家庭签约");
|
|
|
String statusName = "";
|
|
|
switch (jsonObject.getInt("status")){
|
|
|
case -4 : statusName = "已到期";break;
|
|
|
case -3 : statusName ="已解约";break;
|
|
|
case 0 : statusName ="待签约";break;
|
|
|
case 1 : if(jsonObject.getInt("expensesStatus")==1){statusName ="已签约";}else{statusName ="待缴费";} break;
|
|
|
case 2 : statusName ="患者申请取消签约";break;
|
|
|
case 3 : statusName ="医生申请取消签约";break;
|
|
|
}
|
|
|
jsonObject.put("statusName",statusName);
|
|
|
jsonArray.put(jsonObject);
|
|
|
}
|
|
|
return jsonArray;
|
|
|
}
|
|
|
|
|
|
public JSONObject getSignInfo(String teamCode){
|
|
|
SignFamily signFamily = signFamilyDao.findByTeamCode(teamCode);
|
|
|
if(signFamily==null){
|
|
|
throw new RuntimeException("找不到签约关系!");
|
|
|
}
|
|
|
Patient p = patientService.findByCode(signFamily.getPatient());
|
|
|
String patient = p.getCode();
|
|
|
JSONObject resultObject = new JSONObject();
|
|
|
|
|
|
AdminTeam adminTeam = adminTeamService.getTeam(signFamily.getAdminTeamId());
|
|
|
//查找到团队领导
|
|
|
Doctor leader = doctorService.findDoctorByCode(adminTeam.getLeaderCode());
|
|
|
JSONObject leaderObj = this.doctorParse(leader);
|
|
|
resultObject.put("leader",leaderObj);
|
|
|
String doctorHealth = signFamily.getDoctorHealth();
|
|
|
String doctor = signFamily.getDoctor();
|
|
|
//签约团队的健管师
|
|
|
if(StringUtils.isNotBlank(doctorHealth)){
|
|
|
Doctor health = doctorService.findDoctorByCode(doctorHealth);
|
|
|
JSONObject healthObj = this.doctorParse(health);
|
|
|
resultObject.put("doctorHealth",healthObj);
|
|
|
}
|
|
|
//签约团队的全科医生
|
|
|
if(StringUtils.isNotBlank(doctor)){
|
|
|
Doctor qk = doctorService.findDoctorByCode(doctor);
|
|
|
JSONObject qkObj = this.doctorParse(qk);
|
|
|
resultObject.put("doctor",qkObj);
|
|
|
}
|
|
|
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));
|
|
|
int year = calendar.get(Calendar.YEAR);
|
|
|
//统计当年咨询数量
|
|
|
String consult_sql = "select count(1) as count from wlyy_consult_team w where w.doctor = ? and w.patient =? and YEAR(w.czrq) = ? ";
|
|
|
//统计随访数量
|
|
|
String followup_sql = "select count(1) as count from wlyy_followup w where (w.doctor_code = ? or w.doctor_code =?) and w.patient_code =? and YEAR(w.create_time) = ? ";
|
|
|
//统计待预约数量
|
|
|
String reservation_sql = "select count(1) as count from wlyy_patient_reservation w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
|
|
|
//统计健康教育数量
|
|
|
String article_sql = "select count(1) as count from wlyy_health_edu_article_patient w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
|
|
|
//统计健康指导数量
|
|
|
String guidance_sql = "select count(1) as count from wlyy_patient_health_guidance w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
|
|
|
|
|
|
StringBuffer countSql = new StringBuffer();
|
|
|
countSql.append(consult_sql).append(" union all ").append(followup_sql).append(" union all ").append(reservation_sql).append(" union all ").append(article_sql).append(" union all ").append(guidance_sql);
|
|
|
List<Map<String, Object>> resultCount = jdbcTemplate.queryForList(countSql.toString(), new Object[]{doctorHealth, patient, year,doctorHealth,doctor,patient,year,doctorHealth,doctor,patient,year,doctorHealth,doctor,patient,year,doctorHealth,doctor,patient,year});
|
|
|
resultObject.put("consultNum",resultCount.get(0).get("count"));
|
|
|
resultObject.put("followupNum",resultCount.get(1).get("count"));
|
|
|
resultObject.put("reservationNum",resultCount.get(2).get("count"));
|
|
|
resultObject.put("articleNum",resultCount.get(3).get("count"));
|
|
|
resultObject.put("guidanceNum",resultCount.get(4).get("count"));
|
|
|
return resultObject;
|
|
|
}
|
|
|
|
|
|
private JSONObject doctorParse(Doctor doctor){
|
|
|
JSONObject object = new JSONObject();
|
|
|
object.put("code",doctor.getCode());
|
|
|
object.put("jobName",doctor.getJobName());
|
|
|
object.put("name",doctor.getName());
|
|
|
object.put("photo",doctor.getPhoto());
|
|
|
object.put("sex",doctor.getSex());
|
|
|
object.put("hospitalName",doctor.getHospitalName());
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
public JSONObject getSignServiceInfo(String teamCode){
|
|
|
SignFamily signFamily = signFamilyDao.findByTeamCode(teamCode);
|
|
|
if(signFamily==null){
|
|
|
throw new RuntimeException("找不到签约关系!");
|
|
|
}
|
|
|
Patient p = patientService.findByCode(signFamily.getPatient());
|
|
|
String patient = p.getCode();
|
|
|
//获取咨询
|
|
|
String consult_sql = "select w.consult,w.symptoms,w.czrq,w.status,1 as type from wlyy_consult_team w where w.doctor = ? and w.patient =? and YEAR(w.czrq) = ? ";
|
|
|
//获取随访
|
|
|
String followup_sql = "select w.id,w.followup_type,w.followup_class,w.followup_date as czrq,w.followup_manager_status,2 as type from wlyy_followup w where (w.doctor_code = ? or w.doctor_code =?) and w.patient_code =? and YEAR(w.create_time) = ? ";
|
|
|
//获取待预约
|
|
|
String reservation_sql = "select w.code,w.id, w.doctor_name,w.doctor_code,w.doctor_job,w.doctor,w.dname,w.status,w.start_time as czrq,3 as type from wlyy_patient_reservation w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
|
|
|
//获取健康教育
|
|
|
String article_sql = "select w.id,w2.title,w2.summary,w.czrq,w.doctor,w.doctor_name,w.is_read,4 as type from wlyy_health_edu_article_patient w,wlyy_health_edu_article w2 where w.article = w2.code and (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
|
|
|
//获取健康指导
|
|
|
String guidance_sql = "select w.id,w.doctor,w.content,w.czrq,w.read_status,5 as type from wlyy_patient_health_guidance w where (w.doctor = ? or w.doctor =?) and w.patient =? and YEAR(w.czrq) = ? ";
|
|
|
|
|
|
String doctorHealth = signFamily.getDoctorHealth();
|
|
|
String doctor = signFamily.getDoctor();
|
|
|
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));
|
|
|
int year = calendar.get(Calendar.YEAR);
|
|
|
//咨询量
|
|
|
List<Map<String, Object>> consultResult = jdbcTemplate.queryForList(consult_sql, new Object[]{doctorHealth, patient, year});
|
|
|
//随访量
|
|
|
List<Map<String, Object>> followupResult = jdbcTemplate.queryForList(followup_sql, new Object[]{doctorHealth,doctor, patient, year});
|
|
|
//待预约量
|
|
|
List<Map<String, Object>> reservationResult = jdbcTemplate.queryForList(reservation_sql, new Object[]{doctorHealth,doctor, patient, year});
|
|
|
//健康教育量
|
|
|
List<Map<String, Object>> articleResult = jdbcTemplate.queryForList(article_sql, new Object[]{doctorHealth,doctor, patient, year});
|
|
|
//健康指导量
|
|
|
List<Map<String, Object>> guidanceResult = jdbcTemplate.queryForList(guidance_sql, new Object[]{doctorHealth,doctor, patient, year});
|
|
|
List<JSONObject> objects = new ArrayList<>();
|
|
|
int amount = consultResult.size()+followupResult.size()+reservationResult.size()+articleResult.size()+guidanceResult.size();
|
|
|
int activeAmount = 0;
|
|
|
objects.addAll(convertResult(consultResult));
|
|
|
objects.addAll(convertResult(followupResult));
|
|
|
objects.addAll(convertResult(reservationResult));
|
|
|
objects.addAll(convertResult(articleResult));
|
|
|
objects.addAll(convertResult(guidanceResult));
|
|
|
for(JSONObject object: objects){
|
|
|
switch (object.get("type").toString()){
|
|
|
case "1":activeAmount += ("1".equals(object.get("status"))?1:0);break;
|
|
|
case "2":activeAmount += ("1".equals(object.get("followup_manager_status"))?1:0);break;
|
|
|
case "3":activeAmount += ("1".equals(object.get("status"))?1:0);break;
|
|
|
case "4":activeAmount += ("1".equals(object.get("is_read"))?1:0);break;
|
|
|
case "5":activeAmount += ("1".equals(object.get("read_status"))?1:0);break;
|
|
|
}
|
|
|
}
|
|
|
objects.sort(new Comparator<JSONObject>() {
|
|
|
@Override
|
|
|
public int compare(JSONObject o1, JSONObject o2) {
|
|
|
Date begin = DateUtil.strToDateLong(o1.get("czrq").toString());
|
|
|
Date end = DateUtil.strToDateLong(o2.get("czrq").toString());
|
|
|
|
|
|
if(begin!=null&&end !=null&&begin.before(end)){
|
|
|
return 1;
|
|
|
}else{
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
JSONObject object = new JSONObject();
|
|
|
object.put("list",objects);
|
|
|
object.put("amount",amount);
|
|
|
object.put("activeAmount",activeAmount);
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
private List<JSONObject> convertResult(List<Map<String, Object>> dataList){
|
|
|
List<JSONObject> objects = new ArrayList<>();
|
|
|
JSONObject resultObject = new JSONObject();
|
|
|
for(Map<String, Object> map: dataList){
|
|
|
switch (map.get("type").toString()){
|
|
|
case "1":resultObject = convertConsult(map);break;
|
|
|
case "2":resultObject = convertFollowup(map);break;
|
|
|
case "3":resultObject = convertReservation(map);break;
|
|
|
case "4":resultObject = convertArticle(map);break;
|
|
|
case "5":resultObject = convertGuidance(map);break;
|
|
|
}
|
|
|
objects.add(resultObject);
|
|
|
}
|
|
|
return objects;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 返回值装换
|
|
|
* @param map
|
|
|
* @return
|
|
|
*/
|
|
|
private JSONObject convertConsult(Map<String, Object> map){
|
|
|
JSONObject resultObject = new JSONObject();
|
|
|
for(String key :map.keySet()){
|
|
|
String value = map.get(key)+"";
|
|
|
if("status".equals(key)){
|
|
|
if("1".equals(value)){
|
|
|
resultObject.put("status_name","已完成");
|
|
|
}else{
|
|
|
resultObject.put("status_name","进行中");
|
|
|
}
|
|
|
}
|
|
|
resultObject.put(key,value);
|
|
|
}
|
|
|
return resultObject;
|
|
|
}
|
|
|
|
|
|
private JSONObject convertFollowup(Map<String, Object> map){
|
|
|
JSONObject resultObject = new JSONObject();
|
|
|
if(map.get("followup_manager_status")==null){
|
|
|
map.put("followup_manager_status","0");
|
|
|
}
|
|
|
for(String key :map.keySet()){
|
|
|
if("followup_type".equals(key)){
|
|
|
String followupTypeName = systemDictService.getDictValue("FOLLOWUP_WAY_DICT", map.get(key)+"");
|
|
|
resultObject.put("followup_type_name",followupTypeName);
|
|
|
}
|
|
|
if("followup_class".equals(key)){
|
|
|
String followupClassName = systemDictService.getDictValue("FOLLOWUP_CLASS_DICT",map.get(key)+"");
|
|
|
resultObject.put("followup_class_name",followupClassName);
|
|
|
}
|
|
|
if("followup_manager_status".equals(map.get(key))){
|
|
|
String followupManagerStatusName = systemDictService.getDictValue("FOLLOWUP_MANAGER_STATUS",map.get(key)+"");
|
|
|
resultObject.put("followup_manager_status_name",followupManagerStatusName);
|
|
|
}
|
|
|
resultObject.put(key,map.get(key));
|
|
|
}
|
|
|
return resultObject;
|
|
|
}
|
|
|
|
|
|
private JSONObject convertReservation(Map<String, Object> map){
|
|
|
JSONObject resultObject = new JSONObject();
|
|
|
for(String key :map.keySet()){
|
|
|
String value = map.get(key)+"";
|
|
|
if("status".equals(key)){
|
|
|
if("1".equals(value)){
|
|
|
resultObject.put("status_name","已完成");
|
|
|
}else{
|
|
|
resultObject.put("status_name","已取消");
|
|
|
}
|
|
|
}
|
|
|
resultObject.put(key,value);
|
|
|
}
|
|
|
return resultObject;
|
|
|
}
|
|
|
|
|
|
private JSONObject convertArticle(Map<String, Object> map){
|
|
|
JSONObject resultObject = new JSONObject();
|
|
|
for(String key :map.keySet()){
|
|
|
String value = map.get(key)+"";
|
|
|
if("is_read".equals(key)){
|
|
|
if("1".equals(value)){
|
|
|
resultObject.put("status_name","已完成");
|
|
|
}else{
|
|
|
resultObject.put("status_name","进行中");
|
|
|
}
|
|
|
}
|
|
|
resultObject.put(key,value);
|
|
|
}
|
|
|
return resultObject;
|
|
|
}
|
|
|
|
|
|
private JSONObject convertGuidance(Map<String, Object> map){
|
|
|
JSONObject resultObject = new JSONObject();
|
|
|
for(String key :map.keySet()){
|
|
|
String value = map.get(key)+"";
|
|
|
if("read_status".equals(key)){
|
|
|
if("1".equals(value)){
|
|
|
resultObject.put("status_name","已完成");
|
|
|
}else{
|
|
|
resultObject.put("status_name","进行中");
|
|
|
}
|
|
|
}
|
|
|
resultObject.put(key,value);
|
|
|
}
|
|
|
return resultObject;
|
|
|
}
|
|
|
|
|
|
}
|