Browse Source

Merge branch 'dev' of linzhuo/patient-co-management into dev

linzhuo 8 years ago
parent
commit
99a8a89adc

+ 8 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -336,6 +336,14 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    @Query("select a from SignFamily a where a.patient = ?1 and a.status >= 0")
    List<SignFamily> findAllSignByPatient(String patient);
    /**
     * 获取所有有效的签约信息(不包含-1 -2)
     * @param patient
     * @return
     */
    @Query("select a from SignFamily a where a.patient = ?1 and a.status <> -1 and a.status <> -2")
    List<SignFamily> findAllActiveSignByPatient(String patient);
    @Query("select a.patient from SignFamily a where a.doctor = ?1 and a.type = 2 and a.status > 0 and a.doctorHealth is null")
    List<String> findNohealthByDoctor(String doctor);

+ 2 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -1009,7 +1009,7 @@ public class FamilyContractService extends BaseService {
            if(sessionObj.getInt("status")==-1){
                throw  new RuntimeException(sessionObj.getString("message"));
            }
            ImUtill.sendImMsg(doc.getCode(),doc.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2,"0","家庭医生代理签约成功!","1");
        }
        BusinessLogs.info(BusinessLogs.BusinessType.sign, signDoctorCode, sf.getPatient(), new JSONObject(sf));
        return temp;
@ -1261,6 +1261,7 @@ public class FamilyContractService extends BaseService {
            if(sessionObj.getInt("status")==-1){
                throw  new RuntimeException(sessionObj.getString("message"));
            }
            ImUtill.sendImMsg(doc.getCode(),doc.getName(),patient.getCode()+"_"+sf.getTeamCode()+"_"+2,"0","家庭医生签约成功!","1");
        }
        result.put("status", 1);
        BusinessLogs.info(BusinessLogs.BusinessType.sign, caller, sf.getPatient(), new JSONObject(sf));

+ 300 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java

@ -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;
    }
}

+ 16 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ImUtill.java

@ -170,6 +170,22 @@ public class ImUtill {
    }
    public static JSONObject getSessionMessage(String sessionId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
        String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                + "api/v2/sessions/"+sessionId+"/messages?session_id="+sessionId+"&user="+uid+"&start_message_id="+startMsgId+"&end_message_id="+endMsgId+"&page="+page+"&pagesize"+pagesize;
        try{
            String ret = HttpClientUtil.get(url, "UTF-8");
            JSONObject obj = new JSONObject(ret);
            if(obj.getInt("status")==-1){
                throw new RuntimeException(obj.getString("message"));
            }else{
                return  obj.getJSONObject("data");
            }
        }catch (Exception e){
            return null;
        }
    }
    /**
     * 删除对应的成员信息在MUC模式中
     * @param userId

+ 19 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.web.patient.consult;
import java.util.*;
import com.thoughtworks.xstream.mapper.Mapper;
import com.yihu.wlyy.entity.consult.Consult;
import com.yihu.wlyy.entity.consult.ConsultTeam;
import com.yihu.wlyy.entity.consult.ConsultTeamLog;
@ -703,6 +704,24 @@ public class ConsultController extends WeixinBaseController {
        }
    }
    /**
     * 网络咨询咨询日志查询
     *
     * @param pagesize 每页显示数,默认为10
     * @return
     */
    @RequestMapping(value = "logs")
    @ResponseBody
    public String logs(@RequestParam String sessionId,@RequestParam(required = false) String startMsgId,@RequestParam(required = false) String endMsgId, @RequestParam int page, @RequestParam int pagesize) {
        try {
            JSONObject messageObj = ImUtill.getSessionMessage(sessionId, startMsgId, endMsgId, page, pagesize, getUID());
            return write(200, "查询成功", "list", messageObj);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
    /**
     * 查找单个咨询记录
     *

+ 31 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/sign/PatientSignController.java

@ -4,6 +4,8 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@ -30,9 +32,7 @@ public class PatientSignController extends BaseController {
	/**
	 * 个人医生签约
	 * @param patient 患者标识
	 * @param doctor 医生标识
	 * @param status 签约状态(0待签约,1已拒绝,2已签约,3患者申请取消签约,4医生申请取消签约,5已解约)
	 * @param startTime 签约开始时间
	 * @param endTime 到期时间
	 * @return 申请结果
@ -185,7 +185,6 @@ public class PatientSignController extends BaseController {
	/**
	 * 获取签约医生信息  状态未传查全部签约信息
	 * @param status 签约状态 (0待签约,1已拒绝,2已签约,3患者申请取消签约,4医生申请取消签约,5已解约)
	 * @param query 查询条件 (医生姓名)
	 * @return
	 */
	@RequestMapping("/sign_info")
@ -251,4 +250,33 @@ public class PatientSignController extends BaseController {
			return error(-1, "系统错误,请联系管理员!");
		}
	}
	@RequestMapping("/sign_doctor_info")
	public String getSignDoctorInfo(@RequestParam(required = true,value = "team")String teamCode) {
		try {
			JSONObject resultObj = signWebService.getSignInfo(teamCode);
			return write(200, "查询成功!", "data", resultObj);
		} catch (Exception ex) {
			return error(-1, "系统错误,请联系管理员!");
		}
	}
	@RequestMapping("/sign_service_info")
	public String getSignServiceInfo(@RequestParam(required = true,value = "team")String teamCode) {
		try {
			JSONObject resultObj = signWebService.getSignServiceInfo(teamCode);
			return write(200, "查询成功!", "data", resultObj);
		} catch (Exception ex) {
			return error(-1, "系统错误,请联系管理员!");
		}
	}
	@RequestMapping("/signs")
	public String getSigns() {
		try {
			JSONArray jsonArray  = signWebService.getSigns(getUID());
			return write(200, "查询成功!", "data", jsonArray);
		} catch (Exception ex) {
			return error(-1, "系统错误,请联系管理员!");
		}
	}
}