Parcourir la source

Merge branch '2.0' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into 2.0

LAPTOP-KB9HII50\70708 il y a 1 an
Parent
commit
192f5da92e
19 fichiers modifiés avec 2927 ajouts et 330 suppressions
  1. 47 0
      common/common-entity/src/main/java/com/yihu/jw/entity/patient/PatientRestTime.java
  2. 97 72
      common/common-entity/src/main/java/com/yihu/jw/entity/util/TransforSqlUtl.java
  3. 21 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/web/endpoint/EnvelopRestEndpoint.java
  4. 19 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/patient/dao/PatientRestTimeDao.java
  5. 58 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/patient/service/PatientRestTimeService.java
  6. 2 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/controller/DoctorRehabilitaionInfoController.java
  7. 746 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/controller/PatientRehabilitationManageController.java
  8. 121 168
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/controller/RehabilitationManageController.java
  9. 13 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/controller/RehabilitationPlanController.java
  10. 15 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/dao/RehabilitationGuidanceDao.java
  11. 17 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/dao/RehabilitationGuidancePatientDao.java
  12. 387 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/service/RehabilitationGuidanceService.java
  13. 49 28
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/service/RehabilitationInfoService.java
  14. 1061 36
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/service/RehabilitationManageService.java
  15. 11 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/service/RehabilitationPlanService.java
  16. 166 0
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/specialist/controller/PatientSpecialistController.java
  17. 14 3
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/specialist/controller/SpecialistController.java
  18. 34 19
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/specialist/controller/SpecialistScreenResultController.java
  19. 49 4
      svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/specialist/service/SpecialistService.java

+ 47 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/patient/PatientRestTime.java

@ -0,0 +1,47 @@
package com.yihu.jw.entity.patient;
import com.yihu.jw.entity.IdEntityWithCreateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by yeshijie on 2023/3/22.
 */
@Entity
@Table(name = "wlyy_patient_rest_time")
public class PatientRestTime extends IdEntityWithCreateTime {
    private String patient;//居民code
    private String type;//类型 1早餐时间 2午餐时间 3晚餐时间 4入睡时间
    private String restTime;//作息时间
    @Column(name = "patient")
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name = "type")
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    @Column(name = "rest_time")
    public String getRestTime() {
        return restTime;
    }
    public void setRestTime(String restTime) {
        this.restTime = restTime;
    }
}

Fichier diff supprimé car celui-ci est trop grand
+ 97 - 72
common/common-entity/src/main/java/com/yihu/jw/entity/util/TransforSqlUtl.java


+ 21 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/web/endpoint/EnvelopRestEndpoint.java

@ -53,6 +53,7 @@ public abstract class EnvelopRestEndpoint extends BaseRestEndPoint {
        return success(message, 200);
    }
    protected Envelop success(String message, int status) {
        Envelop envelop = new Envelop();
        envelop.setMessage(message);
@ -477,6 +478,26 @@ public abstract class EnvelopRestEndpoint extends BaseRestEndPoint {
            return null;
        }
    }
    /**
     * 获取被代理人的code
     * @return
     */
    public String getRepresentedUID() {
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            String userAgent = request.getHeader("userAgent");
            if (org.apache.commons.lang3.StringUtils.isEmpty(userAgent)) {
                userAgent = request.getHeader("User-Agent");
            }
            org.json.JSONObject json = new org.json.JSONObject(userAgent);
            return json.getString("represented");
        } catch (Exception e) {
            return null;
        }
    }
    public String getUID(String patient) {
        try {
            if(StringUtils.isEmpty(patient)){

+ 19 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/patient/dao/PatientRestTimeDao.java

@ -0,0 +1,19 @@
package com.yihu.jw.hospital.module.patient.dao;
import com.yihu.jw.entity.patient.PatientRestTime;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by yeshijie on 2023/3/22.
 */
public interface PatientRestTimeDao extends PagingAndSortingRepository<PatientRestTime, Long>, JpaSpecificationExecutor<PatientRestTime> {
    @Query("select t from PatientRestTime t where t.patient=?1 order by t.type asc ")
    List<PatientRestTime> findByPatient(String patient);
}

+ 58 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/patient/service/PatientRestTimeService.java

@ -0,0 +1,58 @@
package com.yihu.jw.hospital.module.patient.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.patient.PatientRestTime;
import com.yihu.jw.hospital.module.patient.dao.PatientRestTimeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * Created by yeshijie on 2023/3/23.
 */
@Service
public class PatientRestTimeService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PatientRestTimeDao patientRestTimeDao;
    //获取居民作息时间
    public Map<String,String> getPatientRestTimeMap(String patient){
        synchronized (patient.intern()){
            List<PatientRestTime> restTimeList = patientRestTimeDao.findByPatient(patient);
            if(restTimeList.size()==0){
                //按默认的生成
                List<PatientRestTime> systemList = patientRestTimeDao.findByPatient("system");
                systemList.forEach(one->{
                    PatientRestTime restTime = new PatientRestTime();
                    restTime.setPatient(patient);
                    restTime.setCreateTime(new Date());
                    restTime.setRestTime(one.getRestTime());
                    restTime.setType(one.getType());
                    restTimeList.add(restTime);
                });
                patientRestTimeDao.saveAll(restTimeList);
            }
            Map<String,String> map = restTimeList.stream().collect(Collectors.toMap(PatientRestTime::getType,PatientRestTime::getRestTime));
            return map;
        }
    }
    //修改居民作息时间
    public void updRestTime(String patient,String jsonData){
        List<PatientRestTime> restTimeList = patientRestTimeDao.findByPatient(patient);
        JSONObject json = JSON.parseObject(jsonData);
        for (PatientRestTime restTime:restTimeList){
            restTime.setRestTime(json.getString(restTime.getType()));
        }
        patientRestTimeDao.saveAll(restTimeList);
    }
}

+ 2 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/controller/DoctorRehabilitaionInfoController.java

@ -59,6 +59,8 @@ public class DoctorRehabilitaionInfoController extends EnvelopRestEndpoint {
        }
    }
    @RequestMapping(value = "getDeorsumvergenceCount", method = RequestMethod.GET)
    @ApiOperation("康复下转已下转顶头数据")
    public String getDeorsumvergenceCount() {

+ 746 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/controller/PatientRehabilitationManageController.java

@ -0,0 +1,746 @@
package com.yihu.jw.hospital.module.rehabilitation.controller;
/**
 * Created by 刘文彬 on 2018/8/31.
 */
import com.yihu.jw.entity.specialist.rehabilitation.PatientMedicalRecordsDO;
import com.yihu.jw.hospital.module.door.service.WlyyDoorServiceOrderService;
import com.yihu.jw.hospital.module.patient.service.PatientRestTimeService;
import com.yihu.jw.hospital.module.rehabilitation.service.RehabilitationGuidanceService;
import com.yihu.jw.hospital.module.rehabilitation.service.RehabilitationManageService;
import com.yihu.jw.hospital.module.rehabilitation.service.RehabilitationPlanService;
import com.yihu.jw.hospital.prescription.service.DrugsPlanService;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
 * Created by 刘文彬 on 2018/8/30.
 */
@RestController
@RequestMapping(value = "/patient/specialist/rehabilitation", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "居民端-康复管理")
public class PatientRehabilitationManageController extends EnvelopRestEndpoint {
    @Autowired
    private RehabilitationManageService rehabilitationManageService;
    @Autowired
    private ImUtil imUtill;
    @Autowired
    private RehabilitationPlanService rehabilitationPlanService;
    @Autowired
    private RehabilitationGuidanceService rehabilitationGuidanceService;
    @Autowired
    private WlyyDoorServiceOrderService wlyyDoorServiceOrderService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Resource
    private PatientRestTimeService patientRestTimeService;
    @Autowired
    private DrugsPlanService drugsPlanService;
//    @Autowired
//    private GuahaoXMService guahaoXM;//挂号
    @RequestMapping(value = "selectPlanByPatient", method = RequestMethod.GET)
    @ApiOperation("康复管理-根据居民code查找康复计划")
    public String calendarPlanDetailItems(@ApiParam(name = "patient", value = "居民code", required = false)
                                          @RequestParam(value = "patient", required = false) String patient,
                                          @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false)
                                          @RequestParam(value = "status", required = false) Integer status) {
        try {
            List<Map<String, Object>> result = rehabilitationManageService.selectPlanByPatient(patient, status, null, null);
            return write(200, "获取成功", "data", result);
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
    @RequestMapping(value = "calendarPlanDetailItems", method = RequestMethod.GET)
    @ApiOperation("康复管理-康复计划服务项目按列表展示")
    public String calendarPlanDetailItems(
            @ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = false) @RequestParam(value = "executeStartTime", required = false) String executeStartTime,
            @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = false) @RequestParam(value = "executeEndTime", required = false) String executeEndTime,
            @ApiParam(name = "planId", value = "计划id", required = true) @RequestParam(value = "planId", required = true) String planId,
            @ApiParam(name = "searchTask", value = "快速查找任务:(1、我的任务,2、健康教育,3、健康指导,4、随访,5、复诊)", required = false) @RequestParam(value = "searchTask", required = false) Integer searchTask,
            @ApiParam(name = "doctorCode", value = "医生code(专科医生、家庭医生)", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode,
            @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false) @RequestParam(value = "status", required = false) Integer status
    ) {
        try {
            if (!StringUtils.isNotEmpty(doctorCode)) {
                doctorCode = getRepUID();
            }
            List<Map<String, Object>> result = rehabilitationManageService.calendarPlanDetailItems(executeStartTime, executeEndTime, planId, searchTask, status, doctorCode);
            return write(200, "获取成功", "data", result);
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
    @RequestMapping(value = "patientRehabilitationDetail", method = RequestMethod.GET)
    @ApiOperation("康复管理-微信端-居民详情页")
    public String patientRehabilitationDetail(
            @ApiParam(name = "patient", value = "居民", required = true) @RequestParam(value = "patient", required = false) String patient
    ) {
        try {
            if (StringUtils.isNotBlank(patient)) {
                if (StringUtils.isNoneBlank(getRepresentedUID())) {
                    patient = getRepresentedUID();
                } else {
                    patient = getUID();
                }
            }
            JSONObject result = rehabilitationManageService.patientRehabilitationDetail(patient);
            return write(200, "获取成功!", "data", result);
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
    /**
     * doctorCode: 361aef4891de492cb0e6a47cf9fe31f3
     * patientInfo:
     * level: 1
     * area: 350200
     * diseaseCode:
     * turnDownState: 0
     * page: 1
     * pageSize: 10
     * doctorType: 2
     * filterPlan: 1
     */
    @RequestMapping(value = "selectBySpecialistDoctor", method = RequestMethod.GET)
    @ApiOperation("康复管理-获取签约专科居民")
    public String selectBySpecialistDoctor(
            @ApiParam(name = "doctorCode", value = "医生code", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode,
            @ApiParam(name = "doctorType", value = "医生类型(1专科2家医)", required = false) @RequestParam(value = "doctorType", required = false) String doctorType,
            @ApiParam(name = "patientInfo", value = "身份证或者姓名", required = false) @RequestParam(value = "patientInfo", required = false) String patientInfo,
            @ApiParam(name = "diseaseCode", value = "疾病类型code", required = false) @RequestParam(value = "diseaseCode", required = false) String diseaseCode,
            @ApiParam(name = "level", value = "1市2区3社区", required = false) @RequestParam(value = "level", required = false) String level,
            @ApiParam(name = "area", value = "区域", required = false) @RequestParam(value = "area", required = false) String area,
            @ApiParam(name = "page", value = "第几页,从1开始", required = true) @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @ApiParam(name = "pageSize", value = "每页分页大小", required = true) @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @ApiParam(name = "filterPlan", value = "是否过滤康复计划,1过滤,0或者放空不过滤", required = false) @RequestParam(value = "filterPlan", required = false) String filterPlan,
            @ApiParam(name = "turnDownState", value = "下转状态 0全部;1已下转;2已接受;3未下转", required = false) @RequestParam(value = "turnDownState", required = false, defaultValue = "0") String turnDownState
    ) {
        try {
            if (!StringUtils.isNotEmpty(doctorCode)) {
                doctorCode = getRepUID();
            }
            JSONObject result = rehabilitationManageService.selectBySpecialistDoctor(level, area, doctorCode, diseaseCode, page, pageSize, doctorType, patientInfo, filterPlan, turnDownState);
            JSONArray showList = result.getJSONArray("showList");
            JSONObject turnDownStateObj = result.getJSONObject("turnDownState");
            return write(200, "获取成功", "data", showList, "data2", turnDownStateObj);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 获取为某患者创建康复计划的专科医生列表,家庭医生,
     *
     * @param patientCode 患者code
     * @return
     */
    @RequestMapping(value = "getPatientSpecialAndFamilyDoctor", method = RequestMethod.GET)
    @ApiOperation("获取为某患者创建康复计划的医生专科列表、家庭医生")
    public String getConsultDoctorForConsulting(@RequestParam("patientCode") String patientCode) {
        try {
            return write(200, "查询成功", "data", rehabilitationManageService.getPatientSpecialAndFamilyDoctor(patientCode));
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "selectAllCompleteServiceItemsByPatient", method = RequestMethod.GET)
    @ApiOperation("康复计划主页动态")
    public String selectAllCompleteServiceItemsByPatient(@ApiParam(name = "patient", value = "居民Code", required = true)
                                                         @RequestParam(value = "patient", required = true) String patient) {
        try {
            return write(200, "获取成功", "data", rehabilitationManageService.selectAllCompleteServiceItemsByPatient(patient));
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "selectAllPlaneByPatient", method = RequestMethod.GET)
    @ApiOperation("获取居民所有康复计划")
    public String getPatientAllRehabilitationPlan(@ApiParam(name = "patient", value = "居民Code", required = true)
                                                  @RequestParam(value = "patient", required = true) String patient) {
        try {
            return write(200, "获取成功", "data", rehabilitationManageService.getPatientAllRehabilitationPlan(patient, getUID()));
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "calendarPlanDetailListBypatient", method = RequestMethod.GET)
    @ApiOperation("康复管理--某患者的康复计划按列表展示")
    public String calendarPlanDetailListBypatient(
            @ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = false) @RequestParam(value = "executeStartTime", required = false) String executeStartTime,
            @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = false) @RequestParam(value = "executeEndTime", required = false) String executeEndTime,
            @ApiParam(name = "patient", value = "患者code", required = true) @RequestParam(value = "patient", required = true) String patient,
            @ApiParam(name = "searchTask", value = "快速查找任务:(1电话/短信关怀,2康复咨询,3健康监测,4上门服务,5康复指导,6康复随访,7康复复诊)", required = false) @RequestParam(value = "searchTask", required = false) Integer searchTask,
            @ApiParam(name = "doctorCode", value = "医生code(专科医生、家庭医生)", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode,
            @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false) @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(name = "taskExecutor", value = "任务执行人:0全部;1我的任务:2他人任务", required = false) @RequestParam(value = "taskExecutor", required = false, defaultValue = "0") String taskExecutor
    ) {
        try {
            if (!StringUtils.isNotEmpty(doctorCode)) {
                doctorCode = getRepUID();
            }
            JSONArray result = rehabilitationManageService.calendarPlanDetailListBypatient(executeStartTime, executeEndTime, patient, searchTask, status, doctorCode, taskExecutor);
            return write(200, "获取成功", "data", result);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "selectPlanServerDoctor", method = RequestMethod.POST)
    @ApiOperation("康复管理-康复计划的服务医生")
    public String selectPlanServerDoctor(@ApiParam(name = "planId", value = "康复计划ID") @RequestParam(value = "planId", required = true) String planId) {
        try {
            String doctorCode = getRepUID();
            return write(200, "查询成功!", "data", rehabilitationManageService.selectPlanServerDoctor(planId, doctorCode));
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
//    @RequestMapping(value = "getPatientInfo", method = RequestMethod.GET)
//    @ApiOperation("康复管理-获取居民信息")
//    public String getPatientInfo(@ApiParam(name = "patient", value = "居民信息", required = true)
//                                 @RequestParam(value = "patient", required = true) String patient,
//                                 @ApiParam(name = "planId", value = "计划id", required = true)
//                                 @RequestParam(value = "planId", required = true) String planId) {
//        try {
//            return write(200, "获取成功", "data", rehabilitationManageService.getPatientInfo(planId, patient));
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
    @RequestMapping(value = "selectByMedicalCode", method = RequestMethod.GET)
    @ApiOperation("获取医院病历")
    public String selectByMedicalCode(@ApiParam(name = "medical", value = "住院code", required = true)
                                      @RequestParam(value = "medical", required = true) String medical) {
        try {
            List<PatientMedicalRecordsDO> result = rehabilitationManageService.selectByMedicalCode(medical);
            try {
                String sql = "UPDATE `wlyy`.`wlyy_patient_medical_records_rehabilitation` SET `patient_read_status`='1' WHERE (`code`='" + medical + "') ";
                jdbcTemplate.update(sql);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return write(200, "获取成功!", "data", result);
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
    @RequestMapping(value = "selectByPatient", method = RequestMethod.GET)
    @ApiOperation("获取居民医院病历列表")
    public String selectByPatient(@ApiParam(name = "patient", value = "居民code", required = true)
                                  @RequestParam(value = "patient", required = true) String patient) {
        try {
            List<PatientMedicalRecordsDO> result = rehabilitationManageService.findByPatient(patient);
            return write(200, "获取成功!", "data", result);
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
//    @RequestMapping(value = "getPlantCodeByMedicalRecordsCode", method = RequestMethod.GET)
//    @ApiOperation("根据住院病历获取计划CODE")
//    public String getPlantCodeByMedicalRecordsCode(@ApiParam(name = "code", value = "住院病历CODE", required = true)
//                                                   @RequestParam(value = "code", required = true) String code) {
//        try {
//            return write(200, "获取成功!", "data", rehabilitationManageService.getPlantCodeByMedicalRecordsCode(code));
//        } catch (Exception e) {
//
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "calendarPlanDetail", method = RequestMethod.GET)
//    @ApiOperation("康复管理-康复计划按日历展示")
//    public String calendarPlanDetail(
//            @ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "executeStartTime", required = true) String executeStartTime,
//            @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "executeEndTime", required = true) String executeEndTime,
//            @ApiParam(name = "planId", value = "计划id", required = true) @RequestParam(value = "planId", required = true) String planId,
//            @ApiParam(name = "searchTask", value = "快速查找任务:(1、我的任务,2、健康教育,3、复诊,4、随访)", required = false) @RequestParam(value = "searchTask", required = false) Integer searchTask,
//            @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false) @RequestParam(value = "status", required = false) Integer status) {
//        try {
//            ObjEnvelop objEnvelop = rehabilitationManageService.calendarPlanDetail(executeStartTime, executeEndTime, planId, searchTask, status, null);
//            return write(200, "获取成功", "data",objEnvelop );
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "serviceDoctorList", method = RequestMethod.GET)
//    @ApiOperation("康复管理-微信端居民服务医生列表")
//    public String serviceDoctorList() {
//        try {
//            String loginUserCode = getUID();
//            JSONArray result = rehabilitationManageService.serviceDoctorList(loginUserCode);
//            return write(200, "获取成功!", "data", result);
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
    /**
     * w;yy2.0的接口
     */
//    @RequestMapping(value = "calendarPlanDetailList", method = RequestMethod.GET)
//    @ApiOperation("康复管理-康复计划按列表展示-限定频次")
//    public String calendarPlanDetailList(
//            @ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "executeStartTime", required = false)String executeStartTime,
//            @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "executeEndTime", required = false)String executeEndTime,
//            @ApiParam(name = "planId", value = "计划id", required = true) @RequestParam(value = "planId", required = true)String planId,
//            @ApiParam(name = "searchTask", value = "快速查找任务:(1电话/短信关怀,2康复咨询,3健康监测,4上门服务,5康复指导,6康复随访,7康复复诊)", required = false) @RequestParam(value = "searchTask", required = false)Integer searchTask,
//            @ApiParam(name = "doctorCode", value = "医生code(专科医生、家庭医生)", required = false) @RequestParam(value = "doctorCode", required = false)String doctorCode,
//            @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false) @RequestParam(value = "status", required = false)Integer status,
//            @ApiParam(name="taskExecutor",value = "任务执行人:0全部;1我的任务:2他人任务",required = false) @RequestParam(value = "taskExecutor",required = false,defaultValue = "0")String taskExecutor
//    ){
//        try {
//            if(!StringUtils.isNotEmpty(doctorCode)){
//                doctorCode = getRepUID();
//            }
//            JSONArray result = rehabilitationManageService.calendarPlanDetailListWithTaskExecutor(executeStartTime,executeEndTime,planId,searchTask,status,doctorCode,taskExecutor);
//            return write(200, "获取成功", "data", result);
//        }  catch (Exception e) {
//            return error(-1, e.getMessage());
//        }
//    }
    /**
     * i健康接口
     */
    @RequestMapping(value = "calendarPlanDetailList", method = RequestMethod.GET)
    @ApiOperation("康复管理-康复计划按列表展示")
    public String calendarPlanDetailList(
            @ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "executeStartTime", required = true) String executeStartTime,
            @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "executeEndTime", required = true) String executeEndTime,
            @ApiParam(name = "planId", value = "计划id", required = true) @RequestParam(value = "planId", required = true) String planId,
            @ApiParam(name = "searchTask", value = "快速查找任务:(1、我的任务,2、健康教育,3、复诊,4、随访)", required = false) @RequestParam(value = "searchTask", required = false) Integer searchTask,
            @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false) @RequestParam(value = "status", required = false) Integer status
    ) {
        try {
            JSONArray result = rehabilitationManageService.calendarPlanDetailList(executeStartTime, executeEndTime, planId, searchTask, status, null);
            return write(200, "获取成功", "data", result);
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
//    @RequestMapping(value = "calendarPlanDetailItems", method = RequestMethod.GET)
//    @ApiOperation("康复管理-康复计划服务项目按列表展示")
//    public String calendarPlanDetailItems(@ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = false)
//                                          @RequestParam(value = "executeStartTime", required = true) String executeStartTime,
//                                          @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = false)
//                                          @RequestParam(value = "executeEndTime", required = true) String executeEndTime,
//                                          @ApiParam(name = "planId", value = "计划id", required = true)
//                                          @RequestParam(value = "planId", required = true) String planId,
//                                          @ApiParam(name = "searchTask", value = "快速查找任务:(1、我的任务,2、健康教育,3、健康指导,4、随访,5、复诊)", required = false)
//                                          @RequestParam(value = "searchTask", required = false) Integer searchTask,
//                                          @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false)
//                                          @RequestParam(value = "status", required = false) Integer status) {
//        try {
//            List<Map<String, Object>> result = rehabilitationManageService.calendarPlanDetailItems(executeStartTime, executeEndTime, planId, searchTask, status, null);
//            return write(200, "获取成功", "data", result);
//        } catch (Exception e) {
//
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "selectByGuidance", method = RequestMethod.GET)
//    @ApiOperation("康复管理-根据计划查询指导留言")
//    public String selectByGuidance(@ApiParam(name = "planId", value = "计划id", required = false)
//                                   @RequestParam(value = "planId", required = true) String planId,
//                                   @ApiParam(name = "itemCode", value = "服务项目code", required = true)
//                                   @RequestParam(value = "itemCode", required = true) String itemCode) {
//
//        try {
//            List<Map<String, Object>> mapList = rehabilitationManageService.selectByGuidance(planId, itemCode);
//            return write(200, "获取成功", "data", mapList);
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "selectByPlanDetaiId", method = RequestMethod.GET)
//    @ApiOperation("康复管理-获取操作记录")
//    public String selectByPlanDetaiId(
//            @ApiParam(name = "planId", value = "计划id", required = true) @RequestParam(value = "planId", required = true) String planId,
//            @ApiParam(name = "code", value = "服务项目code", required = true) @RequestParam(value = "code", required = true) String code,
//            @ApiParam(name = "page", value = "", required = false) @RequestParam(value = "page", required = false) Integer page,
//            @ApiParam(name = "pagesize", value = "", required = false) @RequestParam(value = "pagesize", required = false) Integer pagesize) {
//        try {
//            return write(200, "获取成功", "data", rehabilitationManageService.selectByPlanDetaiId(null, planId, code, page, pagesize));//patient,
//        } catch (Exception e) {
//
//            return error(-1, "请求失败");
//        }
//    }
//    @GetMapping(value = "getPatientDrugsPlan")
//    @ApiOperation("获取居民用药计划")
//    public String getPatientDrugsPlan(
//            @ApiParam(name = "patient", value = "居民code", required = true) @RequestParam(value = "patient", required = true) String patient,
//            @ApiParam(name = "startTime", value = "开始时间", required = false) @RequestParam(value = "startTime", required = false) String startTime,
//            @ApiParam(name = "endTime", value = "结束时间", required = false) @RequestParam(value = "endTime", required = false) String endTime
//    ) {
//        try {
//            Map<String, List<Map<String, Object>>> result = drugsPlanService.getPatientDrugsPlan(patient, startTime, endTime);
//            return write(200, "获取成功", "data", result);
//        } catch (Exception e) {
//            return error(-1, e.getMessage());
//        }
//    }
    @GetMapping(value = "getPatientRestTime")
    @ApiOperation("获取居民作息时间")
    public String getPatientRestTime(
            @ApiParam(name = "patient", value = "居民code", required = true) @RequestParam(value = "patient", required = true) String patient
    ) {
        try {
            return write(200, "获取成功", "data", patientRestTimeService.getPatientRestTimeMap(patient));
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
    @PostMapping(value = "updRestTime")
    @ApiOperation("修改居民作息时间")
    public String updRestTime(
            @ApiParam(name = "patient", value = "居民code", required = true) @RequestParam(value = "patient", required = true) String patient,
            @ApiParam(name = "jsonData", value = "作息", required = true) @RequestParam(value = "jsonData", required = true) String jsonData) {
        try {
            patientRestTimeService.updRestTime(patient, jsonData);
            return write(200, "修改成功");
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
//    @RequestMapping(value = "getPatientDrugList", method = RequestMethod.GET)
//    @ApiOperation("获取居民出院带药列表")
//    public String getPatientDrugList(@ApiParam(name = "patient", value = "居民Code", required = true)
//                                     @RequestParam(value = "patient", required = true) String patient) {
//        try {
//            return write(200, "获取成功", "data", rehabilitationManageService.getPatientDrugList(patient));
//        } catch (Exception e) {
//            return error(-1,e.getMessage());
//        }
//    }
//    @RequestMapping(value = "sendMessageIm", method = RequestMethod.POST)
//    @ApiOperation("康复管理-扫描二维码发送消息")
//    public String sendMessageIm(@ApiParam(name = "sendId", value = "发送者id") @RequestParam(value = "sendId", required = true) String sendId,
//                                @ApiParam(name = "receiverId", value = "接受者id", required = true) @RequestParam(value = "receiverId", required = true) String receiverId,
//                                @ApiParam(name = "content", value = "内容", required = true) @RequestParam(value = "content", required = true) String content) {
//        try {
//            imUtill.sendMessage(sendId, receiverId, "1", content);
//            rehabilitationManageService.sendMessage(sendId, receiverId, content);//发送康复下转邀请
//            return write(200, "发送成功!");
//        } catch (Exception e) {
//            return error(-1, "发送失败!");
//        }
//    }
//    @RequestMapping(value = "checkAfterQrCode", method = RequestMethod.POST)
//    @ApiOperation("康复管理-居民扫码后验证是否是关联的居民扫码")
//    public String checkAfterQrCode(@ApiParam(name = "planDetailId", value = "康复计划项目明细ID") @RequestParam(value = "planDetailId", required = true) String planDetailId,
//                                   @ApiParam(name = "patientCode", value = "居民端登录的居民code") @RequestParam(value = "patientCode", required = true) String patientCode) {
//        try {
//            JSONObject result = rehabilitationManageService.checkAfterQrCode(planDetailId, patientCode);
//            return write(200, String.valueOf(result.get("message")), "data", result.getJSONObject("obj"));
//        } catch (Exception e) {
//
//            return error(-1, "验证失败");
//        }
//    }
//    @RequestMapping(value = "saveRehabilitationOperateRecord", method = RequestMethod.POST)
//    @ApiOperation("康复管理-新增operateRecord")
//    public String saveRehabilitationOperateRecord(@ApiParam(name = "dataJson", value = "实体json", defaultValue = "{\"rehabilitationDetailId\":\"402803f6657f195301657f4fbd3c0001\",\"patientCode\":\"00\",\"patientName\":\"11\",\"doctorCode\":\"22\",\"doctorName\":\"33\",\"node\":\"jjjjjj\",\"relationRecordType\":\"4\",\"relation_record_code\":\"55\",\"relationRecordImg\":\"666666\",\"status\":\"0\"}") @RequestParam(value = "dataJson", required = true) String dataJson) {
//
//        try {
//            JSONObject result = rehabilitationManageService.saveRehabilitationOperateRecord(dataJson);
//            if (result.getInt("status") == 200) {
//                return write(200, "新增康复计划日志成功!", "data", result.getJSONObject("obj"));
//            } else {
//                return error(-1, result.getString("message"));
//            }
//        } catch (Exception e) {
//
//            return error(-1, "新增康复计划日志失败!");
//        }
//    }
//    @RequestMapping(value = "recentPlanDetailRecord", method = RequestMethod.GET)
//    @ApiOperation("康复管理-近期康复相关记录")
//    public String recentPlanDetailRecord(@ApiParam(name = "patientCode", value = "居民code", required = false)
//                                         @RequestParam(value = "patientCode", required = false) String patientCode,
//                                         @ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = false)
//                                         @RequestParam(value = "startTime", required = false) String startTime,
//                                         @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = false)
//                                         @RequestParam(value = "endTime", required = false) String endTime,
//                                         @ApiParam(name = "page", value = "第几页,从1开始", required = true)
//                                         @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
//                                         @ApiParam(name = "pageSize", value = "每页分页大小", required = true)
//                                         @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
//
//        try {
//            if (!StringUtils.isNotEmpty(patientCode)) {
//                patientCode = getUID();
//            }
//            JSONObject result = rehabilitationManageService.recentPlanDetailRecord(patientCode, startTime, endTime, page, pageSize);
//            return write(200, "获取成功!", "data", result);
//        } catch (Exception e) {
//
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "serviceItemList", method = RequestMethod.GET)
//    @ApiOperation("康复管理-多个康复计划服务项目内容列表")
//    public String serviceItemList(@ApiParam(name = "planDetailIds", value = "康复计划多个服务项目id(多个‘,’分隔)", required = true)
//                                  @RequestParam(value = "planDetailIds", required = true) String planDetailIds) {
//
//        try {
//            JSONArray result = rehabilitationManageService.serviceItemList(planDetailIds, null);
//            return write(200, "获取成功", "data", result);
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "serviceItem", method = RequestMethod.GET)
//    @ApiOperation("康复管理-康复计划服务项目确认详情页")
//    public String serviceItem(@ApiParam(name = "planDetailId", value = "康复计划服务项目id", required = true)
//                              @RequestParam(value = "planDetailId", required = true) String planDetailId,
//                              @ApiParam(name = "recordId", value = "记录id", required = false)
//                              @RequestParam(value = "recordId", required = false) String recordId) {
//
//        try {
//            JSONObject result = rehabilitationManageService.serviceItem(planDetailId, null, recordId);
//            return write(200, "获取成功", "data", result);
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
    @RequestMapping(value = "planSchedule", method = RequestMethod.GET)
    @ApiOperation("康复管理-计划总进度")
    public String planSchedule(@ApiParam(name = "planId", value = "计划id", required = true)
                               @RequestParam(value = "planId", required = true) String planId,
                               @ApiParam(name = "patientCode", value = "居民code", required = false)
                               @RequestParam(value = "patientCode", required = false) String patientCode) {
        try {
            if (!StringUtils.isNotEmpty(patientCode)) {
                patientCode = getRepUID();
            }
            JSONObject result = rehabilitationManageService.planSchedule(planId, patientCode);
            try {
                String sql = "UPDATE `wlyy_specialist`.`wlyy_patient_rehabilitation_plan` SET `patient_read_status`='1' WHERE (`id`='" + planId + "') ";
                jdbcTemplate.update(sql);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return write(200, "获取成功!", "data", result);
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
//    @RequestMapping(value = "updatePatientImgById", method = RequestMethod.POST)
//    @ApiOperation("更新康复计划居民签名照/证件照")
//    public String updatePatientImgById(@ApiParam(name = "planId", value = "康复计划id", required = true)
//                                       @RequestParam(value = "planId") String planId,
//                                       @ApiParam(name = "patientImg", value = "居民签名/证件照地址")
//                                       @RequestParam(value = "patientImg") String patientImg) {
//
//        try {
//            rehabilitationPlanService.updatePatientImgById(planId, patientImg);
//            return write(200, "更新成功!");
//        } catch (Exception e) {
//
//            return error(-1, "更新失败");
//        }
//    }
//    @RequestMapping(value = "getServiceItemsAfterStop", method = RequestMethod.GET)
//    @ApiOperation("康复管理-已执行项目清单")
//    public String getServiceItemsAfterStop(@ApiParam(name = "planId", value = "康复计划id", required = true)
//                                           @RequestParam(value = "planId", required = true) String planId) {
//
//        try {
//            return write(200, "操作成功!", "data", rehabilitationPlanService.getServiceItemsAfterStop(planId));
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "selectByRelationCodeAndGuidance", method = RequestMethod.GET)
//    @ApiOperation("康复管理-根据业务code查找康复指导")
//    public String selectByRelationCodeAndGuidance(@ApiParam(name = "relationCode", value = "业务关联code", required = false)
//                                                  @RequestParam(value = "relationCode", required = false) String relationCode,
//                                                  @ApiParam(name = "patient", value = "居民code", required = false)
//                                                  @RequestParam(value = "patient", required = false) String patient,
//                                                  @ApiParam(name = "doctor", value = "医生code", required = false)
//                                                  @RequestParam(value = "doctor", required = false) String doctor) {
//
//        try {
//            return write(200, "请求成功!", "data", rehabilitationGuidanceService.selectByRelationCode(patient, doctor, relationCode));
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
//    @GetMapping(value = "selectRelationCodeAndDoor")
//    @ResponseBody
//    @ApiOperation("业务关联code--上门服务")
//    public String selectRelationCodeAndDoor(@ApiParam(name = "relationCode", value = "业务关联code", required = true)
//                                            @RequestParam String relationCode) {
//        try {
//            return write(200, "请求成功!", "data", wlyyDoorServiceOrderService.selectRelationCode(relationCode));
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
    @RequestMapping(value = "selectGuidances", method = RequestMethod.GET)
    @ApiOperation("康复管理-查看指导列表")
    public String selectType(
            @ApiParam(name = "type", value = "康复指导类型", required = false) @RequestParam(value = "type", required = false) Integer type,
            @ApiParam(name = "id", value = "康复指导模板id", required = false) @RequestParam(value = "id", required = false) String id,
            @ApiParam(name = "title", value = "康复指导名称", required = false) @RequestParam(value = "title", required = false) String title,
            @ApiParam(name = "planId", value = "计划id", required = false) @RequestParam(value = "planId", required = false) String planId,
            @ApiParam(name = "page", value = "页码", required = false) @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(name = "pagesize", value = "每页大小", required = false) @RequestParam(value = "pagesize", required = false) Integer pagesize
    ) {
        try {
            return write(200, "请求成功!", "data", rehabilitationGuidanceService.select(title, type, id, planId, page, pagesize));
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
//    @RequestMapping(value = "selectPlanDetailByPlanId", method = RequestMethod.GET)
//    @ApiOperation("康复管理-查看其它服务计划")
//    public String selectPlanDetailByPlanId(
//            @ApiParam(name = "planId", value = "计划id", required = true) @RequestParam(value = "planId", required = true) String planId,
//            @ApiParam(name = "planDetailId", value = "计划详情id", required = true) @RequestParam(value = "planDetailId", required = true) String planDetailId,
//            @ApiParam(name = "itemId", value = "服务项目code", required = true) @RequestParam(value = "itemId", required = true) String itemId
//    ) {
//
//        try {
//            return write(200, "请求成功!", "data", rehabilitationManageService.selectPlanDetailByPlan(planId, planDetailId, itemId));
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
    @GetMapping(value = "selectRelationCode")
    @ResponseBody
    @ApiOperation("业务关联code")
    public String selectRelationCode(
            @ApiParam(name = "relationCode", value = "业务关联code", required = true) @RequestParam String relationCode
    ) {
        try {
            return write(200, "请求成功!", "data", wlyyDoorServiceOrderService.selectRelationCode(relationCode));
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
    @RequestMapping(value = "selectByRelationCode", method = RequestMethod.GET)
    @ApiOperation("康复管理-根据业务code查找康复指导")
    public String selectByRelationCode(
            @ApiParam(name = "relationCode", value = "业务关联code", required = false) @RequestParam(value = "relationCode", required = false) String relationCode,
            @ApiParam(name = "patient", value = "居民code", required = false) @RequestParam(value = "patient", required = false) String patient,
            @ApiParam(name = "doctor", value = "医生code", required = false) @RequestParam(value = "doctor", required = false) String doctor
    ) {
        try {
            return write(200, "请求成功!", "data", rehabilitationGuidanceService.selectByRelationCode(patient, doctor, relationCode));
        } catch (Exception e) {
            return error(-1, "请求失败");
        }
    }
//    @RequestMapping(value = "getDiseaseTopicInfo", method = RequestMethod.GET)
//    @ApiOperation("获取居民疾病专题首页相关数据")
//    public String getDiseaseTopicInfo(@ApiParam(name = "patientCode", value = "住院病历CODE", required = true)
//                                      @RequestParam(value = "patientCode", required = true) String patientCode,
//                                      @ApiParam(name = "diseaseType", value = "疾病类型", required = true)
//                                      @RequestParam(value = "diseaseType", required = true) String diseaseType) {
//        try {
//            com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
//            object.put("patientId", getUID());
//            return write(200, "获取成功!", "data", rehabilitationManageService.getDiseaseTopicInfo(object, patientCode, diseaseType));
//        } catch (Exception e) {
//
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "getDiseaseHospital", method = RequestMethod.GET)
//    @ApiOperation("获取入住疾病的医院列表")
//    public String getDiseaseHospital(
//            @ApiParam(name = "diseaseType", value = "疾病类型", required = true) @RequestParam(value = "diseaseType", required = true) String diseaseType,
//            @ApiParam(name = "name", value = "医院名称", required = false) @RequestParam(value = "name", required = false) String name,
//            @ApiParam(name = "page", value = "页码", required = false) @RequestParam(value = "page", required = false) Integer page,
//            @ApiParam(name = "pagesize", value = "每页大小", required = false) @RequestParam(value = "pagesize", required = false) Integer pagesize
//    ) {
//        try {
//            if (page == null) {
//                page = 1;
//            }
//            if (pagesize == null) {
//                pagesize = 15;
//            }
//            return write(200, "获取成功!", "data", rehabilitationManageService.getDiseaseHospital(diseaseType, name, page, pagesize));
//        } catch (Exception e) {
//            return error(-1, "请求失败");
//        }
//    }
}

+ 121 - 168
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/controller/RehabilitationManageController.java

@ -14,6 +14,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -42,8 +43,8 @@ public class RehabilitationManageController {
    @PostMapping(value = "synchronizePationSingle")
    @ApiOperation("手动重新下转")
    public MixEnvelop synchronizePationSingle(@ApiParam(name = "id", value = "id", required = true)
                                              @RequestParam(value = "id", required = true) Long id) {
    public MixEnvelop synchronizePationSingle(
            @ApiParam(name = "id", value = "id", required = true) @RequestParam(value = "id", required = true) Long id) {
        try {
            String res = synchronizePatientService.synchronizePationSingle(id);
            if (StringUtils.isBlank(res)) {
@ -74,7 +75,7 @@ public class RehabilitationManageController {
            return rehabilitationManageService.findRehabilitationPlan(doctorType, doctorCode, diseaseCode, planType, todaybacklog, patientCondition, page, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
@ -89,89 +90,76 @@ public class RehabilitationManageController {
            return rehabilitationManageService.findRehabilitationPlanDetailList(doctorCode, patientCode);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.calendarPlanDetail)
    @ApiOperation(value = "康复管理-康复计划按日历展示")
    public ObjEnvelop calendarPlanDetail(@ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)")
                                         @RequestParam(value = "executeStartTime", required = false) String executeStartTime,
                                         @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)")
                                         @RequestParam(value = "executeEndTime", required = false) String executeEndTime,
                                         @ApiParam(name = "planId", value = "计划id,多个计划逗号隔开", required = true)
                                         @RequestParam(value = "planId", required = true) String planId,
                                         @ApiParam(name = "searchTask", value = "快速查找任务:(1电话/短信关怀,2康复咨询,3健康监测,4上门服务,5康复指导,6康复随访,7康复复诊)", required = false)
                                         @RequestParam(value = "searchTask", required = false) Integer searchTask,
                                         @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false)
                                         @RequestParam(value = "status", required = false) Integer status,
                                         @ApiParam(name = "doctorCode", value = "医生code(专科医生、家庭医生)", required = false)
                                         @RequestParam(value = "doctorCode", required = false) String doctorCode,
                                         @ApiParam(name = "taskExecutor", value = "任务执行人:0全部;1我的任务:2他人任务", required = false)
                                         @RequestParam(value = "taskExecutor", required = false, defaultValue = "0") String taskExecutor) {
    public ObjEnvelop calendarPlanDetail(
            @ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)") @RequestParam(value = "executeStartTime", required = false) String executeStartTime,
            @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)") @RequestParam(value = "executeEndTime", required = false) String executeEndTime,
            @ApiParam(name = "planId", value = "计划id,多个计划逗号隔开", required = true) @RequestParam(value = "planId", required = true) String planId,
            @ApiParam(name = "searchTask", value = "快速查找任务:(1电话/短信关怀,2康复咨询,3健康监测,4上门服务,5康复指导,6康复随访,7康复复诊)", required = false) @RequestParam(value = "searchTask", required = false) Integer searchTask,
            @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false) @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(name = "doctorCode", value = "医生code(专科医生、家庭医生)", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode,
            @ApiParam(name = "taskExecutor", value = "任务执行人:0全部;1我的任务:2他人任务", required = false) @RequestParam(value = "taskExecutor", required = false, defaultValue = "0") String taskExecutor
    ) {
        try {
            return rehabilitationManageService.calendarPlanDetail(executeStartTime, executeEndTime, planId, searchTask, status, doctorCode, taskExecutor);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.calendarPlanDetailList)
    @ApiOperation(value = "康复管理-康复计划按列表展示")
    public ObjEnvelop calendarPlanDetailList(@ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)")
                                             @RequestParam(value = "executeStartTime", required = false) String executeStartTime,
                                             @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)")
                                             @RequestParam(value = "executeEndTime", required = false) String executeEndTime,
                                             @ApiParam(name = "planId", value = "计划id,多个计划逗号隔开", required = true)
                                             @RequestParam(value = "planId", required = true) String planId,
                                             @ApiParam(name = "searchTask", value = "快速查找任务:(1电话/短信关怀,2康复咨询,3健康监测,4上门服务,5康复指导,6康复随访,7康复复诊)")
                                             @RequestParam(value = "searchTask", required = false) Integer searchTask,
                                             @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)")
                                             @RequestParam(value = "status", required = false) Integer status,
                                             @ApiParam(name = "doctorCode", value = "医生code(专科医生、家庭医生)")
                                             @RequestParam(value = "doctorCode", required = false) String doctorCode,
                                             @ApiParam(name = "taskExecutor", value = "任务执行人:0全部;1我的任务:2他人任务", required = false)
                                             @RequestParam(value = "taskExecutor", required = false, defaultValue = "0") String taskExecutor) {
    public ObjEnvelop calendarPlanDetailList(
            @ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)") @RequestParam(value = "executeStartTime", required = false) String executeStartTime,
            @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)") @RequestParam(value = "executeEndTime", required = false) String executeEndTime,
            @ApiParam(name = "planId", value = "计划id,多个计划逗号隔开", required = true) @RequestParam(value = "planId", required = true) String planId,
            @ApiParam(name = "searchTask", value = "快速查找任务:(1电话/短信关怀,2康复咨询,3健康监测,4上门服务,5康复指导,6康复随访,7康复复诊)") @RequestParam(value = "searchTask", required = false) Integer searchTask,
            @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)") @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(name = "doctorCode", value = "医生code(专科医生、家庭医生)") @RequestParam(value = "doctorCode", required = false) String doctorCode,
            @ApiParam(name = "taskExecutor", value = "任务执行人:0全部;1我的任务:2他人任务", required = false) @RequestParam(value = "taskExecutor", required = false, defaultValue = "0") String taskExecutor
    ) {
        try {
            return rehabilitationManageService.calendarPlanDetailList(planId, searchTask, status, doctorCode, executeStartTime, executeEndTime, taskExecutor);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.serviceItemList)
    @ApiOperation(value = "康复管理-多个康复计划服务项目内容信息列表")
    public ObjEnvelop serviceItemList(@ApiParam(name = "planDetailIds", value = "多个服务项目id用‘,’分隔", required = true)
                                      @RequestParam(value = "planDetailIds", required = true) String planDetailIds,
                                      @ApiParam(name = "doctorCode", value = "医生code", required = false)
                                      @RequestParam(value = "doctorCode", required = false) String doctorCode) {
    public ObjEnvelop serviceItemList(
            @ApiParam(name = "planDetailIds", value = "多个服务项目id用‘,’分隔", required = true) @RequestParam(value = "planDetailIds", required = true) String planDetailIds,
            @ApiParam(name = "doctorCode", value = "医生code", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode
    ) {
        try {
            return rehabilitationManageService.serviceItemList(planDetailIds, doctorCode);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.serviceItem)
    @ApiOperation(value = "康复管理-康复计划服务项目确认详情页")
    public ObjEnvelop serviceItem(@ApiParam(name = "planDetailId", value = "服务项目id", required = true)
                                  @RequestParam(value = "planDetailId", required = true) String planDetailId,
                                  @ApiParam(name = "doctorCode", value = "医生code", required = false)
                                  @RequestParam(value = "doctorCode", required = false) String doctorCode,
                                  @ApiParam(name = "recordId", value = "记录id", required = false)
                                  @RequestParam(value = "recordId", required = false) String recordId) {
    public ObjEnvelop serviceItem(
            @ApiParam(name = "planDetailId", value = "服务项目id", required = true) @RequestParam(value = "planDetailId", required = true) String planDetailId,
            @ApiParam(name = "doctorCode", value = "医生code", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode,
            @ApiParam(name = "recordId", value = "记录id", required = false) @RequestParam(value = "recordId", required = false) String recordId
    ) {
        try {
            return rehabilitationManageService.serviceItem(planDetailId, doctorCode, recordId);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
@ -179,50 +167,38 @@ public class RehabilitationManageController {
    @PostMapping(value = "appointmentConsultation")
    @ApiOperation(value = "康复管理-预约协诊")
    public ObjEnvelop appointmentConsultation(
            @ApiParam(name = "patient", value = "居民姓名", required = true)
            @RequestParam(value = "patient", required = true) String patient,
            @ApiParam(name = "doctor", value = "医生code-家医", required = true)
            @RequestParam(value = "doctor", required = true) String doctor,
            @ApiParam(name = "doctorName", value = "医生姓名", required = true)
            @RequestParam(value = "doctorName", required = true) String doctorName,
            @ApiParam(name = "appointmentDoctor", value = "医生code-专科", required = true)
            @RequestParam(value = "appointmentDoctor", required = true) String appointmentDoctor,
            @ApiParam(name = "appointmentDoctorName", value = "医生姓名", required = true)
            @RequestParam(value = "appointmentDoctorName", required = true) String appointmentDoctorName,
            @ApiParam(name = "sendTime", value = "发送时间", required = true)
            @RequestParam(value = "sendTime", required = true) String sendTime,
            @ApiParam(name = "planDetailId", value = "计划明细id", required = true)
            @RequestParam(value = "planDetailId", required = true) String planDetailId) {
            @ApiParam(name = "patient", value = "居民姓名", required = true) @RequestParam(value = "patient", required = true) String patient,
            @ApiParam(name = "doctor", value = "医生code-家医", required = true) @RequestParam(value = "doctor", required = true) String doctor,
            @ApiParam(name = "doctorName", value = "医生姓名", required = true) @RequestParam(value = "doctorName", required = true) String doctorName,
            @ApiParam(name = "appointmentDoctor", value = "医生code-专科", required = true) @RequestParam(value = "appointmentDoctor", required = true) String appointmentDoctor,
            @ApiParam(name = "appointmentDoctorName", value = "医生姓名", required = true) @RequestParam(value = "appointmentDoctorName", required = true) String appointmentDoctorName,
            @ApiParam(name = "sendTime", value = "发送时间", required = true) @RequestParam(value = "sendTime", required = true) String sendTime,
            @ApiParam(name = "planDetailId", value = "计划明细id", required = true) @RequestParam(value = "planDetailId", required = true) String planDetailId
    ) {
        try {
            return rehabilitationManageService.appointmentConsultation(patient, doctor, doctorName, appointmentDoctor, appointmentDoctorName, sendTime, planDetailId);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.rehabilitation.saveGuidanceMessage)
    @ApiOperation(value = "康复管理-保存指导留言")
    public Envelop saveGuidanceMessage(@ApiParam(name = "messageId", value = "消息id", required = true)
                                       @RequestParam(value = "messageId", required = true) String messageId,
//                                       @ApiParam(name = "patientCode", value = "居民code", required = true)
//                                       @RequestParam(value = "patientCode", required = true)String patientCode,
                                       @ApiParam(name = "doctorCode", value = "医生code", required = true)
                                       @RequestParam(value = "doctorCode", required = true) String doctorCode,
                                       @ApiParam(name = "doctorType", value = "医生类型(1、专科医生,2、家庭医生)", required = true)
                                       @RequestParam(value = "doctorType", required = true) Integer doctorType,
                                       @ApiParam(name = "content", value = "聊天内容", required = true)
                                       @RequestParam(value = "content", required = true) String content,
                                       @ApiParam(name = "planDetailId", value = "服务项目id", required = true)
                                       @RequestParam(value = "planDetailId", required = true) String planDetailId,
                                       @ApiParam(name = "contentType", value = "内容类型(1,6,8 - 文本, 2,9- 图片, 3 - 语音, 4-文章, 5,7系统消息。12-语音 18-居民名片, 19-聊天记录)", required = true)
                                       @RequestParam(value = "contentType", required = true) Integer contentType) {
    public Envelop saveGuidanceMessage(
            @ApiParam(name = "messageId", value = "消息id", required = true) @RequestParam(value = "messageId", required = true) String messageId,
            @ApiParam(name = "patientCode", value = "居民code", required = false) @RequestParam(value = "patientCode", required = false) String patientCode,
            @ApiParam(name = "doctorCode", value = "医生code", required = true) @RequestParam(value = "doctorCode", required = true) String doctorCode,
            @ApiParam(name = "doctorType", value = "医生类型(1、专科医生,2、家庭医生)", required = true) @RequestParam(value = "doctorType", required = true) Integer doctorType,
            @ApiParam(name = "content", value = "聊天内容", required = true) @RequestParam(value = "content", required = true) String content,
            @ApiParam(name = "planDetailId", value = "服务项目id", required = true) @RequestParam(value = "planDetailId", required = true) String planDetailId,
            @ApiParam(name = "contentType", value = "内容类型(1,6,8 - 文本, 2,9- 图片, 3 - 语音, 4-文章, 5,7系统消息。12-语音 18-居民名片, 19-聊天记录)", required = true)
            @RequestParam(value = "contentType", required = true) Integer contentType) {
        try {
            return rehabilitationManageService.saveGuidanceMessage(messageId, doctorCode, doctorType, content, planDetailId, contentType);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
@ -237,7 +213,6 @@ public class RehabilitationManageController {
            return rehabilitationManageService.updateStatusRehabilitationOperate(status, planDetailId);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
@ -245,21 +220,17 @@ public class RehabilitationManageController {
    @GetMapping(value = SpecialistMapping.rehabilitation.patientRehabilitationDetail)
    @ApiOperation(value = "康复管理-居民详情页")
    public Envelop patientRehabilitationDetail(@ApiParam(name = "patientCode", value = "居民code", required = true)
                                               @RequestParam(value = "patientCode", required = true) String patientCode,
                                               @ApiParam(name = "healthDoctor", value = "健管师医生code", required = false)
                                               @RequestParam(value = "healthDoctor", required = false) String healthDoctor,
                                               @ApiParam(name = "healthDoctorName", value = "健管师医生名称", required = false)
                                               @RequestParam(value = "healthDoctorName", required = false) String healthDoctorName,
                                               @ApiParam(name = "generalDoctor", value = "全科医生code", required = false)
                                               @RequestParam(value = "generalDoctor", required = false) String generalDoctor,
                                               @ApiParam(name = "generalDoctorName", value = "全科医生名称", required = false)
                                               @RequestParam(value = "generalDoctorName", required = false) String generalDoctorName) {
    public Envelop patientRehabilitationDetail(
            @ApiParam(name = "patientCode", value = "居民code", required = true) @RequestParam(value = "patientCode", required = true) String patientCode,
            @ApiParam(name = "healthDoctor", value = "健管师医生code", required = false) @RequestParam(value = "healthDoctor", required = false) String healthDoctor,
            @ApiParam(name = "healthDoctorName", value = "健管师医生名称", required = false) @RequestParam(value = "healthDoctorName", required = false) String healthDoctorName,
            @ApiParam(name = "generalDoctor", value = "全科医生code", required = false) @RequestParam(value = "generalDoctor", required = false) String generalDoctor,
            @ApiParam(name = "generalDoctorName", value = "全科医生名称", required = false) @RequestParam(value = "generalDoctorName", required = false) String generalDoctorName
    ) {
        try {
            return rehabilitationManageService.patientRehabilitationDetail(patientCode, healthDoctor, healthDoctorName, generalDoctor, generalDoctorName);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
@ -267,93 +238,79 @@ public class RehabilitationManageController {
    @GetMapping(value = SpecialistMapping.rehabilitation.recentPlanDetailRecord)
    @ApiOperation(value = "居民康复计划详情页-近期康复相关记录")
    public Envelop recentPlanDetailRecord(
            @ApiParam(name = "patientCode", value = "居民code", required = true)
            @RequestParam(value = "patientCode", required = true) String patientCode,
            @ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = false)
            @RequestParam(value = "startTime", required = false) String startTime,
            @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = false)
            @RequestParam(value = "endTime", required = false) String endTime,
            @ApiParam(name = "page", value = "第几页,从1开始", required = true)
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @ApiParam(name = "pageSize", value = "每页分页大小", required = true)
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
            @ApiParam(name = "patientCode", value = "居民code", required = true) @RequestParam(value = "patientCode", required = true) String patientCode,
            @ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = false) @RequestParam(value = "startTime", required = false) String startTime,
            @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = false) @RequestParam(value = "endTime", required = false) String endTime,
            @ApiParam(name = "page", value = "第几页,从1开始", required = true) @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @ApiParam(name = "pageSize", value = "每页分页大小", required = true) @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        try {
            return rehabilitationManageService.recentPlanDetailRecord(patientCode, startTime, endTime, page, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.serviceDoctorList)
    @ApiOperation(value = "康复管理-医生端居民详情服务医生列表")
    public Envelop serviceDoctorList(@ApiParam(name = "patientCode", value = "居民code", required = true)
                                     @RequestParam(value = "patientCode", required = true) String patientCode,
                                     @ApiParam(name = "healthDoctor", value = "健管师医生code", required = false)
                                     @RequestParam(value = "healthDoctor", required = false) String healthDoctor,
                                     @ApiParam(name = "healthDoctorName", value = "健管师医生名称", required = false)
                                     @RequestParam(value = "healthDoctorName", required = false) String healthDoctorName,
                                     @ApiParam(name = "generalDoctor", value = "全科医生code", required = false)
                                     @RequestParam(value = "generalDoctor", required = false) String generalDoctor,
                                     @ApiParam(name = "generalDoctorName", value = "全科医生名称", required = false)
                                     @RequestParam(value = "generalDoctorName", required = false) String generalDoctorName) {
    public Envelop serviceDoctorList(
            @ApiParam(name = "patientCode", value = "居民code", required = true) @RequestParam(value = "patientCode", required = true) String patientCode,
            @ApiParam(name = "healthDoctor", value = "健管师医生code", required = false) @RequestParam(value = "healthDoctor", required = false) String healthDoctor,
            @ApiParam(name = "healthDoctorName", value = "健管师医生名称", required = false) @RequestParam(value = "healthDoctorName", required = false) String healthDoctorName,
            @ApiParam(name = "generalDoctor", value = "全科医生code", required = false) @RequestParam(value = "generalDoctor", required = false) String generalDoctor,
            @ApiParam(name = "generalDoctorName", value = "全科医生名称", required = false) @RequestParam(value = "generalDoctorName", required = false) String generalDoctorName
    ) {
        try {
            return rehabilitationManageService.serviceDoctorList(patientCode, healthDoctor, healthDoctorName, generalDoctor, generalDoctorName);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.appCalendarPlanDetailList)
    @ApiOperation(value = "康复管理-app端、微信端计划的服务项目列表")
    public ObjEnvelop appCalendarPlanDetailList(@ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                                @RequestParam(value = "executeStartTime", required = false) String executeStartTime,
                                                @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                                @RequestParam(value = "executeEndTime", required = false) String executeEndTime,
                                                @ApiParam(name = "planId", value = "计划id", required = true)
                                                @RequestParam(value = "planId", required = true) String planId,
                                                @ApiParam(name = "searchTask", value = "快速查找任务:(1、我的任务,2、随访,3、复诊,4、健康教育)", required = false)
                                                @RequestParam(value = "searchTask", required = false) Integer searchTask,
                                                @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false)
                                                @RequestParam(value = "status", required = false) Integer status) {
    public ObjEnvelop appCalendarPlanDetailList(
            @ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "executeStartTime", required = false) String executeStartTime,
            @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "executeEndTime", required = false) String executeEndTime,
            @ApiParam(name = "planId", value = "计划id", required = true) @RequestParam(value = "planId", required = true) String planId,
            @ApiParam(name = "searchTask", value = "快速查找任务:(1、我的任务,2、随访,3、复诊,4、健康教育)", required = false) @RequestParam(value = "searchTask", required = false) Integer searchTask,
            @ApiParam(name = "status", value = "任务状态(0未完成,1已完成,2已预约)", required = false) @RequestParam(value = "status", required = false) Integer status
    ) {
        try {
            return rehabilitationManageService.appCalendarPlanDetailList(planId, searchTask, status, executeStartTime, executeEndTime);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.dailyJob)
    @ApiOperation(value = "每日康复服务通知")
    public ObjEnvelop dailyJob(@ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                               @RequestParam(value = "startTime", required = true) String startTime,
                               @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                               @RequestParam(value = "endTime", required = true) String endTime) {
    public ObjEnvelop dailyJob(
            @ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "startTime", required = true) String startTime,
            @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "endTime", required = true) String endTime
    ) {
        try {
            return rehabilitationManageService.dailyJob(startTime, endTime);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.tomorrowJob)
    @ApiOperation(value = "明日康复服务通知")
    public ObjEnvelop tomorrowJob(@ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                  @RequestParam(value = "startTime", required = true) String startTime,
                                  @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                  @RequestParam(value = "endTime", required = true) String endTime) {
    public ObjEnvelop tomorrowJob(
            @ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "startTime", required = true) String startTime,
            @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "endTime", required = true) String endTime
    ) {
        try {
            return rehabilitationManageService.tomorrowJob(startTime, endTime);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
@ -361,33 +318,33 @@ public class RehabilitationManageController {
    @GetMapping(value = SpecialistMapping.rehabilitation.dailyByJob)
    @ApiOperation(value = "每日康复计划提醒")
    public ObjEnvelop dailyByJob(@ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                 @RequestParam(value = "startTime", required = true) String startTime,
                                 @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                 @RequestParam(value = "endTime", required = true) String endTime) {
    public ObjEnvelop dailyByJob(
            @ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "startTime", required = true) String startTime,
            @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "endTime", required = true) String endTime
    ) {
        try {
            return rehabilitationManageService.dailyByJob(startTime, endTime);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.rehabilitation.updateNoteAndImageRehabilitationOperate)
    @ApiOperation(value = "康复计划完成时更新服务完成笔记和图片接口并且确认完成")
    public ObjEnvelop updateNoteAndImageRehabilitationOperate(@ApiParam(name = "planDetailId", value = "服务项目id", required = true) @RequestParam(value = "planDetailId", required = true) String planDetailId,
                                                              @ApiParam(name = "node", value = "服务完成笔记", required = true) @RequestParam(value = "node", required = false) String node,
                                                              @ApiParam(name = "image", value = "相关记录图片,json格式", required = true) @RequestParam(value = "image", required = false) String image,
                                                              @ApiParam(name = "relationCode", value = "业务code", required = true) @RequestParam(value = "relationCode", required = false) String relationCode,
                                                              @ApiParam(name = "status", value = "是否确认完成 0未确认 1确认", required = true) @RequestParam(value = "status", required = false) String status) {
    public ObjEnvelop updateNoteAndImageRehabilitationOperate(
            @ApiParam(name = "planDetailId", value = "服务项目id", required = true) @RequestParam(value = "planDetailId", required = true) String planDetailId,
            @ApiParam(name = "node", value = "服务完成笔记", required = true) @RequestParam(value = "node", required = false) String node,
            @ApiParam(name = "image", value = "相关记录图片,json格式", required = true) @RequestParam(value = "image", required = false) String image,
            @ApiParam(name = "relationCode", value = "业务code", required = true) @RequestParam(value = "relationCode", required = false) String relationCode,
            @ApiParam(name = "status", value = "是否确认完成 0未确认 1确认", required = true) @RequestParam(value = "status", required = false) String status
    ) {
        try {
            Map<String, Object> map = rehabilitationManageService.updateNodeAndRelationRecordImg(node, image, status, planDetailId, relationCode);
            return ObjEnvelop.getSuccess(SpecialistMapping.api_success, map);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
@ -402,22 +359,22 @@ public class RehabilitationManageController {
            return MixEnvelop.getSuccess(SpecialistMapping.api_success, rehabilitationManageService.planDetailAfterCall(dataJson));
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.rehabilitation.updatePlanDetailStatusById)
    @ApiOperation(value = "康复管理-更新康复计划项目状态")
    public Envelop updatePlanDetailStatusById(@ApiParam(name = "planDetailId", value = "服务项目id", required = true)
                                              @RequestParam(value = "planDetailId", required = true) String planDetailId,
                                              @ApiParam(name = "status", value = "状态", required = true)
                                              @RequestParam(value = "status", required = true) Integer status) {
    public Envelop updatePlanDetailStatusById(
            @ApiParam(name = "planDetailId", value = "服务项目id", required = true) @RequestParam(value = "planDetailId", required = true) String planDetailId,
            @ApiParam(name = "status", value = "状态", required = true) @RequestParam(value = "status", required = true) Integer status
    ) {
        try {
            return rehabilitationManageService.updatePlanDetailStatusById(status, planDetailId);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
@ -425,16 +382,15 @@ public class RehabilitationManageController {
    @PostMapping(value = SpecialistMapping.rehabilitation.updatePlanDetailExecuteTimeById)
    @ApiOperation(value = "康复管理-修改康复计划项目执行时间")
    public Envelop updatePlanDetailExecuteTimeById(@ApiParam(name = "planDetailId", value = "服务项目id", required = true)
                                                   @RequestParam(value = "planDetailId", required = true) String planDetailId,
                                                   @ApiParam(name = "executeTime", value = "状态", required = true)
                                                   @RequestParam(value = "executeTime", required = true) String executeTime) {
    public Envelop updatePlanDetailExecuteTimeById(
            @ApiParam(name = "planDetailId", value = "服务项目id", required = true) @RequestParam(value = "planDetailId", required = true) String planDetailId,
            @ApiParam(name = "executeTime", value = "状态", required = true) @RequestParam(value = "executeTime", required = true) String executeTime
    ) {
        try {
            Date date = DateUtil.strToDateLong(executeTime);
            return rehabilitationManageService.updatePlanDetailExecuteTimeById(date, planDetailId);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
@ -442,13 +398,14 @@ public class RehabilitationManageController {
    @GetMapping(value = SpecialistMapping.rehabilitation.planSchedule)
    @ApiOperation(value = "康复管理-计划总进度")
    public ObjEnvelop planSchedule(@ApiParam(name = "planId", value = "计划id", required = true)
                                   @RequestParam(value = "planId", required = true) String planId) {
    public ObjEnvelop planSchedule(
            @ApiParam(name = "planId", value = "计划id", required = true) @RequestParam(value = "planId", required = true) String planId
    ) {
        try {
            return rehabilitationManageService.planSchedule(planId);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
@ -461,7 +418,6 @@ public class RehabilitationManageController {
            return rehabilitationManageService.planListByPatient(patientCode);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
@ -474,22 +430,20 @@ public class RehabilitationManageController {
            return rehabilitationManageService.patientCount(doctorCode);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.dailyJobReserve)
    @ApiOperation(value = "10天、7天、5天、当天康复服务预约复诊通知")
    public ObjEnvelop dailyJobReserve(@ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                      @RequestParam(value = "startTime", required = true) String startTime,
                                      @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                      @RequestParam(value = "endTime", required = true) String endTime) {
    public ObjEnvelop dailyJobReserve(
            @ApiParam(name = "startTime", value = "开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "startTime", required = true) String startTime,
            @ApiParam(name = "endTime", value = "结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true) @RequestParam(value = "endTime", required = true) String endTime
    ) {
        try {
            return rehabilitationManageService.dailyJobReserve(startTime, endTime);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
@ -503,13 +457,13 @@ public class RehabilitationManageController {
     */
    @PostMapping(value = SpecialistMapping.rehabilitation.selectByIds)
    @ApiOperation(value = "查询康复服务项目")
    public ObjEnvelop selectByIds(@ApiParam(name = "ids", value = "康复服务套餐明细表ids")
                                  @RequestParam(value = "ids", required = true) String ids) {
    public ObjEnvelop selectByIds(
            @ApiParam(name = "ids", value = "康复服务套餐明细表ids") @RequestParam(value = "ids", required = true) String ids
    ) {
        try {
            return rehabilitationManageService.selectByIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
@ -522,7 +476,6 @@ public class RehabilitationManageController {
            return rehabilitationManageService.getServiceItemsAfterStop(planId);
        } catch (Exception e) {
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }

+ 13 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/controller/RehabilitationPlanController.java

@ -47,6 +47,19 @@ public class RehabilitationPlanController extends EnvelopRestEndpoint {
    @Autowired
    private ImUtil imUtill;
    @RequestMapping(value = "getRehabilitationPlanLog", method = RequestMethod.GET)
    @ApiOperation(value = "获取康复计划修改记录")
    public String getRehabilitationPlanLog(
            @ApiParam(name = "planId", value = "康复计划Id", required = true) @RequestParam(value = "planId", required = true) String planId
    ) {
        try {
            return write(200, "获取成功", "data", rehabilitationPlanService.getRehabilitationPlanLog(planId));
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 新增整个模板 /svr-specialist/saveRehabilitationPlanTemplate

+ 15 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/dao/RehabilitationGuidanceDao.java

@ -0,0 +1,15 @@
package com.yihu.jw.hospital.module.rehabilitation.dao;
import com.yihu.jw.entity.rehabilitation.RehabilitationguidanceDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface RehabilitationGuidanceDao extends PagingAndSortingRepository<RehabilitationguidanceDO, Long>, JpaSpecificationExecutor<RehabilitationguidanceDO> {
    @Query("select p from RehabilitationguidanceDO p where p.code = ?1 and p.del=1")
    RehabilitationguidanceDO findByCode(String code);
//    Page<RehabilitationguidanceDO> findByCondition(String sql,PageRequest page);
}

+ 17 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/dao/RehabilitationGuidancePatientDao.java

@ -0,0 +1,17 @@
package com.yihu.jw.hospital.module.rehabilitation.dao;
import com.yihu.jw.entity.rehabilitation.RehabilitationguidancePatientDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface RehabilitationGuidancePatientDao extends PagingAndSortingRepository<RehabilitationguidancePatientDO, Long>, JpaSpecificationExecutor<RehabilitationguidancePatientDO> {
    @Query("select p from RehabilitationguidancePatientDO p where p.patient = ?1 and p.doctor=?2 ")
    List<RehabilitationguidancePatientDO> findByPatientAndDoctor(String patient, String doctor);
    @Query("select p from RehabilitationguidancePatientDO p where  p.relationCode=?1")
    List<RehabilitationguidancePatientDO> findByRelationCode(String relationCode);
}

+ 387 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/service/RehabilitationGuidanceService.java

@ -0,0 +1,387 @@
package com.yihu.jw.hospital.module.rehabilitation.service;
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.rehabilitation.RehabilitationguidanceDO;
import com.yihu.jw.entity.rehabilitation.RehabilitationguidancePatientDO;
import com.yihu.jw.entity.util.TransforSqlUtl;
import com.yihu.jw.hospital.module.rehabilitation.dao.RehabilitationGuidanceDao;
import com.yihu.jw.hospital.module.rehabilitation.dao.RehabilitationGuidancePatientDao;
import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
import com.yihu.jw.hospital.utils.WeiXinOpenIdUtils;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;
import java.util.*;
/**
 * Created by wangzhinan on 2018/8/29.
 */
@Service
@Transactional
public class RehabilitationGuidanceService {
    private Logger logger = LoggerFactory.getLogger(RehabilitationGuidanceService.class);
    @Autowired
    private RehabilitationGuidanceDao rehabilitationGuidanceDao;
    @Autowired
    private RehabilitationGuidancePatientDao rehabilitationGuidancePatientDao;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private BasePatientDao patientDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Autowired
    private WeiXinOpenIdUtils weiXinOpenIdUtils;
    /**
     * 康复指导类型标题
     *
     * @return
     */
    public List<Map<String, Object>> selectType(String planId) {
        String disease = "";
        if (StringUtils.isNoneBlank(planId)) {
            String sql = "select * from wlyy_specialist.wlyy_patient_rehabilitation_plan where id='" + planId + "' ";
            sql = TransforSqlUtl.wlyy_patient_rehabilitation_planAll(sql);
            Map<String, Object> map = jdbcTemplate.queryForMap(sql);
            if (map.get("disease") != null && StringUtils.isNoneBlank(map.get("disease").toString())) {
                disease = map.get("disease").toString();
            }
        }
        StringBuffer sql = new StringBuffer("select g.type,g.type_name as typeName,COUNT(g.id) as number from wlyy_rehabilitation_guidance g where g.del=1 ");
        if (StringUtils.isNoneBlank(disease)) {
            sql.append("and g.type in ( '").append(disease.replace(",", "','")).append("') ");
        }
        sql.append("group by g.type");
        List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql.toString());
        return mapList;
    }
    /**
     * 查询康复指导列表
     *
     * @param type
     * @param code
     * @param page
     * @param pagesize
     * @return
     */
    public Page<RehabilitationguidanceDO> select(String title, Integer type, String code, String planId, Integer page, Integer pagesize) {
        String disease = "";
        if (StringUtils.isNoneBlank(planId)) {
            String sql = "select * from wlyy_specialist.wlyy_patient_rehabilitation_plan where id='" + planId + "' ";
            sql = TransforSqlUtl.wlyy_patient_rehabilitation_planAll(sql);
            Map<String, Object> map = jdbcTemplate.queryForMap(sql);
            if (map.get("disease") != null && StringUtils.isNoneBlank(map.get("disease").toString())) {
                disease = map.get("disease").toString();
            }
        }
        if (page >= 1) {
            page--;
        }
        if (pagesize <= 0) {
            pagesize = 10;
        }
        StringBuffer sql = new StringBuffer("select * from wlyy_rehabilitation_guidance where 1=1 and del =1 ");
        StringBuffer sqlCounts = new StringBuffer("select count(1) from wlyy_rehabilitation_guidance where 1=1 and del =1 ");
        if (StringUtils.isNoneBlank(code)) {
            sql.append("and code='" + code + "' ");
            sqlCounts.append("and code='" + code + "' ");
        }
        if (type != null) {
            sql.append("and type='" + type + "' ");
            sqlCounts.append("and type='" + type + "' ");
        }
        if (StringUtils.isNoneBlank(title)) {
            sql.append("and title like '%" + title + "%' ");
            sqlCounts.append("and title like '%" + title + "%' ");
        }
        if (StringUtils.isNoneBlank(disease)) {
            sql.append("and type in ( '").append(disease.replace(",", "','")).append("') ");
            sqlCounts.append("and type in ( '").append(disease.replace(",", "','")).append("') ");
        }
        sql.append("order by czrq desc limit " + page * pagesize + "," + (page + 1) * pagesize);
        List<RehabilitationguidanceDO> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(RehabilitationguidanceDO.class));
        Long totalCount = jdbcTemplate.queryForObject(sqlCounts.toString(), Long.class);
        for (RehabilitationguidanceDO temp : list) {
            String contents = temp.getContent();
            temp.setContent(StringEscapeUtils.unescapeJava(contents));
        }
        PageRequest pageRequest = PageRequest.of(page, pagesize);
        if (list.size() <= 0) {
            return new PageImpl(new ArrayList<>(), pageRequest, 0);
        }
        return new PageImpl(list, pageRequest, totalCount);
    }
    public Page<RehabilitationguidancePatientDO> selectPatientGuidances(String patient, String doctor, String code, Integer page, Integer pagesize) {
        if (page >= 1) {
            page--;
        }
        if (pagesize <= 0) {
            pagesize = 10;
        }
        // 排序
        Sort sort = Sort.by(Sort.Direction.DESC, "czrq");
        // 分页信息
        PageRequest pageRequest = PageRequest.of(page, pagesize, sort);
        // 设置查询条件
        Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
        // 指定患者
        if (StringUtils.isNoneBlank(code)) {
            filters.put("code", new SearchFilter("code", SearchFilter.Operator.EQ, code));
        }
        if (StringUtils.isNoneBlank(patient)) {
            filters.put("patient", new SearchFilter("patient", SearchFilter.Operator.EQ, patient));
        }
        if (StringUtils.isNoneBlank(doctor)) {
            filters.put("doctor", new SearchFilter("doctor", SearchFilter.Operator.EQ, doctor));
        }
        Specification<RehabilitationguidancePatientDO> spec = DynamicSpecifications.bySearchFilter(filters.values(), RehabilitationguidancePatientDO.class);
        Page<RehabilitationguidancePatientDO> rehabilitationguidancePatientDOS = rehabilitationGuidancePatientDao.findAll(spec, pageRequest);
        for (RehabilitationguidancePatientDO rehabilitationguidancePatientDO : rehabilitationguidancePatientDOS) {
            BasePatientDO patient1 = patientDao.findById(rehabilitationguidancePatientDO.getPatient()).orElse(null);
            rehabilitationguidancePatientDO.setPhoto(patient1.getPhoto());
        }
        return rehabilitationguidancePatientDOS;
    }
    /**
     * 发送康复指导
     *
     * @param rehabilitationguidancePatientDOS
     * @return
     */
    public List<RehabilitationguidancePatientDO> sendGuidanceToPatient(List<RehabilitationguidancePatientDO> rehabilitationguidancePatientDOS, String planId) throws Exception {
        for (RehabilitationguidancePatientDO rehabilitationguidancePatientDO : rehabilitationguidancePatientDOS) {
            RehabilitationguidanceDO rehabilitationguidanceDO = rehabilitationGuidanceDao.findByCode(rehabilitationguidancePatientDO.getArticle());
            rehabilitationguidanceDO.setUseCount(rehabilitationguidanceDO.getUseCount() + 1);
            rehabilitationGuidanceDao.save(rehabilitationguidanceDO);
            BasePatientDO patient = patientDao.findById(rehabilitationguidancePatientDO.getPatient()).orElse(null);
            BaseDoctorDO doctor = doctorDao.findById(rehabilitationguidancePatientDO.getDoctor()).orElse(null);
            rehabilitationguidancePatientDO.setAttachedTitle(rehabilitationguidanceDO.getTitle());
            if (patient != null) {
                rehabilitationguidancePatientDO.setName(patient.getName());
            }
            if (doctor != null) {
                rehabilitationguidancePatientDO.setDoctorName(doctor.getName());
            }
            rehabilitationguidancePatientDO.setAttachedContent(rehabilitationguidanceDO.getContent());
            rehabilitationguidancePatientDO.setCzrq(new Date());
            rehabilitationguidancePatientDO.setIsRead(0);
            rehabilitationguidancePatientDO.setSendStatus(0);
            rehabilitationguidancePatientDO = rehabilitationGuidancePatientDao.save(rehabilitationguidancePatientDO);
            this.sendSpecialistWeixinMessage(rehabilitationguidancePatientDO.getPatient(), rehabilitationguidancePatientDO.getDoctor(), 1, rehabilitationguidancePatientDO.getArticle(), planId, null);
        }
        return rehabilitationguidancePatientDOS;
    }
    /**
     * 查看发送的康复指导
     *
     * @param patient
     * @param doctor
     * @param relationCode
     * @return
     */
    public List<RehabilitationguidancePatientDO> selectByRelationCode(String patient, String doctor, String relationCode) {
        if (StringUtils.isNoneBlank(relationCode)) {
            return rehabilitationGuidancePatientDao.findByRelationCode(relationCode);
        } else {
            return rehabilitationGuidancePatientDao.findByPatientAndDoctor(patient, doctor);
        }
    }
    /**
     * 康复计划-微信模板发送
     *
     * @param patientCode  居民code
     * @param doctorCode   专科医生code
     * @param type         1康复指导2康复下转3复诊提醒4上门服务提醒5家签提醒
     * @param relationCode 业务关联code
     * @param planId       计划id
     * @throws Exception
     */
    public void sendSpecialistWeixinMessage(String patientCode, String doctorCode, Integer type, String relationCode, String planId, String reservationType) throws Exception {
        //康复指导
        BasePatientDO patient = patientDao.findById(patientCode).orElse(null);
        BaseDoctorDO doctor = doctorDao.findById(doctorCode).orElse(null);
//        SignFamily signFamily = signFamilyDao.findByPatient(patientCode);
        String name = "";
        String doctorName = "";
        String familyDoctorName = "";
        org.json.JSONObject json = new org.json.JSONObject();
        if (patient != null) {
            name = patient.getName();
        }
        if (doctor != null) {
            doctorName = doctor.getName();
        }
//        if (signFamily != null) {
//            familyDoctorName = signFamily.getDoctorName();
//        }
        Integer sendType = null;
        if (type == 1) {
            RehabilitationguidanceDO rehabilitationguidanceDO = rehabilitationGuidanceDao.findByCode(relationCode);
            json.put("toUser", patientCode);
            json.put("first", patient.getName() + ",您好!您的家庭医生发来一篇健康文章!");
            json.put("represented", patientCode);//被代理人
            json.put("id", planId);
            json.put("date", DateUtil.getStringDate());
//            json.put("orgName", doctor.getHospitalName());
            json.put("doctorName", doctor.getName());
            json.put("content", "《" + rehabilitationguidanceDO.getTitle() + "》");
            json.put("remark", "请及时阅读");
            json.put("url", "kfgl/html/plan-item-detail.html?planIds=" + planId + "");
            sendType = 36;
        } else if (type == 2) {
            //反馈处理30
            sendType = 30;
            String sql = "SELECT pr.manage_time as manageTime,pr.is_manage as isManage " +
                    "FROM wlyy_specialist.`wlyy_specialist_patient_relation` pr " +
                    "where pr.doctor = '" + doctorCode + "' and pr.patient = '" + patientCode + "' and pr.sign_status=1 and pr.`status`=1";
            List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
            String manageTime = "";
            for (Map<String, Object> map : mapList) {
                manageTime = DateUtil.dateToStrLong((Date) map.get("manageTime"));
            }
            json.put("first", patient.getName() + ",您好!您已成功签约专科医生“" + doctorName + "”," + doctorName + "医生(专科医生)和" + familyDoctorName + "(全科医生)将为您提供康复管理服务");
            json.put("toUser", patientCode);
            json.put("represented", patientCode);//被代理人
            json.put("keyword1", manageTime);
            json.put("keyword2", "康复下转");
            json.put("remark", "请及时阅读");
            json.put("relationCode", 1);
            json.put("url", "kfgl/html/recover_manage.html");
        } else if (type == 3) {
            //复诊提醒3
            //更新复诊类型
            if (StringUtils.isNoneBlank(reservationType)) {
                String updSql = "update wlyy_specialist.wlyy_rehabilitation_plan_detail set reservation_type = " + reservationType + " where id = '" + relationCode + "'";
                jdbcTemplate.execute(updSql);
            }
            sendType = 11;//待办事项
            String sql = "select pd.id,pd.execute_time as executeTime from wlyy_specialist.wlyy_rehabilitation_plan_detail pd " +
                    "where pd.id ='" + relationCode + "' and pd.hospital_service_item_id='7' and pd.status <>1 order by pd.execute_time desc ";
            List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
            String excuteTime = "";
            if (mapList != null && mapList.size() != 0) {
                excuteTime = DateUtil.dateToStrLong((Date) mapList.get(0).get("executeTime"));
            }
            if (StringUtils.isNoneBlank(excuteTime)) {
                json.put("first", patient.getName() + ",您好!您的下次复诊时间是[" + excuteTime + "],请按时安排就诊。您可点击“查看详情”,提前预约就诊");
            } else {
                json.put("first", patient.getName() + ",您好!" + doctor.getName() + "医生提醒您预约复诊。您可点击“查看详情”,提前预约就诊");
            }
            json.put("toUser", patientCode);
            json.put("represented", patientCode);//被代理人
            json.put("keyword1", "复诊预约");
            json.put("keyword2", "" + DateUtil.getStringDate() + "");
            json.put("remark", "请及时阅读");
            json.put("url", "wdyy/html/appointment-register.html");
        } else if (type == 4) {
            //上门服务提醒 4
            sendType = 11;//待办事项
            String sql = "select pd.id,pd.execute_time as executeTime from wlyy_specialist.wlyy_rehabilitation_plan_detail pd " +
                    "where pd.id ='" + relationCode + "' and pd.hospital_service_item_id='4' and pd.status <>1 order by pd.execute_time desc ";
            List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
            String excuteTime = "";
            String detailId = "";
            if (mapList != null && mapList.size() != 0) {
                excuteTime = DateUtil.dateToStrLong((Date) mapList.get(0).get("executeTime"));
            }
            if (StringUtils.isNoneBlank(excuteTime)) {
                json.put("first", patient.getName() + ",您好!您的下次上门诊疗服务时间是[" + excuteTime + "],请按时预约上门诊疗服务。您可点击“查看详情”,提前预约就诊");
            } else {
                json.put("first", patient.getName() + ",您好!" + doctor.getName() + "医生提醒您预约上门服务。您可点击“查看详情”,提前预约就诊");
            }
            json.put("toUser", patientCode);
            json.put("represented", patientCode);//被代理人
            json.put("keyword1", "上门诊疗服务预约");
            json.put("keyword2", DateUtil.getStringDate());
            json.put("remark", "请及时阅读");
            json.put("url", "smfw/html/toAppointment.html?relationCode=" + relationCode + "");
        } else if (type == 5) {
            //家签提醒 5
            sendType = 11;//待办事项
            String sql = "select pd.id,pd.execute_time as executeTime from wlyy_specialist.wlyy_rehabilitation_plan_detail pd " +
                    "where pd.plan_id ='" + planId + "' and pd.hospital_service_item_id='4' and pd.status <>1 order by pd.execute_time desc ";
            List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
            String excuteTime = "";
            if (mapList != null && mapList.size() != 0) {
                excuteTime = DateUtil.dateToStrLong((Date) mapList.get(0).get("executeTime"));
            }
            json.put("first", patient.getName() + ",您好!为方便为您提供康复管理服务,请先选择合适的社区和家庭医生进行签约");
            json.put("toUser", patientCode);
            json.put("represented", patientCode);//被代理人
            json.put("keyword1", "家庭医生签约");
            json.put("keyword2", DateUtil.getStringDate());
            json.put("remark", "请及时阅读");
            json.put("url", "qygl/html/signing-welcome.html");
        }
        logger.info("微信模板入参:" + sendType + "==" + json.toString());
        if (StringUtils.isNotBlank(patient.getOpenid())) {
            pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), sendType, patient.getOpenid(), patient.getName(), json);
        } else {
            //发送代理人
            org.json.JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient.getId(), patient.getOpenid());
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    org.json.JSONObject j = jsonArray.getJSONObject(i);
                    BasePatientDO member = (BasePatientDO) j.get("member");
                    org.json.JSONObject data = json;
                    data.remove("toUser");
                    data.put("toUser", member.getId());
                    data.remove("first");
                    data.put("first", weiXinOpenIdUtils.getTitleMes(patient, j.getInt("relation"), patient.getName()));
                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), sendType, member.getOpenid(), patient.getName(), data);
                }
            }
        }
    }
}

+ 49 - 28
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/service/RehabilitationInfoService.java

@ -653,14 +653,24 @@ public class RehabilitationInfoService {
     * 已下转已接收
     */
    public JSONObject downAndSign(String idcard, String doctorCode, Integer page, Integer pagesize, JSONObject object) {
        String sql2 = "SELECT i.disease_name diseaseName,s.doctor,s.idcard,p.sex, s.patient,CAST(IFNULL(p.birthday,'') AS char ) birthday," +
                " i. STATUS, p. NAME patientName, p.address, CONCAT(s.doctor_name,'(全科医生)' ) AS doctorName, \n" +
                "IFNULL(CONCAT(s.doctor_health_name,'(健管师)'), s.doctor_health_name ) doctorHealthName, s.hospital_name hospitalName, \n" +
                "s.admin_team_code teamCode ,pr.is_manage isManage \n" +
                "FROM wlyy_specialist.wlyy_patient_rehabilitation_plan i, wlyy_sign_family s, wlyy_patient p ,\n" +
                "wlyy_specialist.wlyy_specialist_patient_relation pr \n" +
                "WHERE i.create_user = '" + doctorCode + "' AND i.status != 0 AND i.patient = s.patient AND p.code = i.patient AND s.status = 1 \n" +
                "AND s.expenses_status = 1 AND pr.patient=p.code and pr.team_code = i.team_code and pr.`status`>=0 and pr.sign_status=1 and pr.is_manage=1";
//        String sql2 = "SELECT i.disease_name diseaseName,s.doctor,s.idcard,p.sex, s.patient,CAST(IFNULL(p.birthday,'') AS char ) birthday," +
//                " i. STATUS, p. NAME patientName, p.address, CONCAT(s.doctor_name,'(全科医生)' ) AS doctorName, \n" +
//                "IFNULL(CONCAT(s.doctor_health_name,'(健管师)'), s.doctor_health_name ) doctorHealthName, s.hospital_name hospitalName, \n" +
//                "s.admin_team_code teamCode ,pr.is_manage isManage \n" +
//                "FROM wlyy_specialist.wlyy_patient_rehabilitation_plan i, wlyy_sign_family s, wlyy_patient p ,\n" +
//                "wlyy_specialist.wlyy_specialist_patient_relation pr \n" +
//                "WHERE i.create_user = '" + doctorCode + "' AND i.status != 0 AND i.patient = s.patient AND p.code = i.patient AND s.status = 1 \n" +
//                "AND s.expenses_status = 1 AND pr.patient=p.code and pr.team_code = i.team_code and pr.`status`>=0 and pr.sign_status=1 and pr.is_manage=1";
        String sql2 = "SELECT i.disease_name diseaseName,p.idcard,p.sex, p.id 'patient',\n" +
                " CAST(IFNULL(p.birthday,'') AS char ) birthday, \n" +
                " i.`status`, p.`name` patientName, p.address,pr.is_manage isManage \n" +
                "FROM wlyy_patient_rehabilitation_plan i \n" +
                " INNER JOIN wlyy_rehabilitation_patient_info q ON q.patient=i.id AND q.sign_status='1' AND i.patient_info_code=q.`code` \n" +
                " INNER JOIN base_patient p ON p.id = i.patient \n" +
                " INNER JOIN wlyy_specialist_patient_relation pr ON pr.patient=p.id \n" +
                "WHERE i.create_user = '" + doctorCode + "' AND i.status != 0  AND pr.`status`>=0 and pr.sign_status=1 and pr.is_manage=1 \n";
        if (StringUtils.isNotBlank(idcard)) {
            sql2 += " and  p.idcard like '%" + idcard + "%' ";
        }
@ -691,14 +701,24 @@ public class RehabilitationInfoService {
     * 已下转已接收
     */
    public JSONObject down(String idcard, String doctorCode, Integer page, Integer pagesize, JSONObject object) {
        String sql2 = "SELECT i.disease_name diseaseName,s.doctor,s.idcard,p.sex, s.patient,CAST(IFNULL(p.birthday,'') AS char ) birthday," +
                " i. STATUS, p. NAME patientName, p.address, CONCAT(s.doctor_name,'(全科医生)' ) AS doctorName, \n" +
                "IFNULL(CONCAT(s.doctor_health_name,'(健管师)'), s.doctor_health_name ) doctorHealthName, s.hospital_name hospitalName, \n" +
                "s.admin_team_code teamCode ,pr.is_manage isManage \n" +
                "FROM wlyy_specialist.wlyy_patient_rehabilitation_plan i, wlyy_sign_family s, wlyy_patient p ,\n" +
                "wlyy_specialist.wlyy_specialist_patient_relation pr \n" +
                "WHERE i.create_user = '" + doctorCode + "' AND i.status != 0 AND i.patient = s.patient AND p.code = i.patient AND s.status = 1 \n" +
                "AND s.expenses_status = 1 AND pr.patient=p.code and pr.team_code = i.team_code and pr.`status`>=0 and pr.sign_status=1 ";
//        String sql2 = "SELECT i.disease_name diseaseName,s.doctor,s.idcard,p.sex, s.patient,CAST(IFNULL(p.birthday,'') AS char ) birthday," +
//                " i. STATUS, p. NAME patientName, p.address, CONCAT(s.doctor_name,'(全科医生)' ) AS doctorName, \n" +
//                "IFNULL(CONCAT(s.doctor_health_name,'(健管师)'), s.doctor_health_name ) doctorHealthName, s.hospital_name hospitalName, \n" +
//                "s.admin_team_code teamCode ,pr.is_manage isManage \n" +
//                "FROM wlyy_specialist.wlyy_patient_rehabilitation_plan i, wlyy_sign_family s, wlyy_patient p ,\n" +
//                "wlyy_specialist.wlyy_specialist_patient_relation pr \n" +
//                "WHERE i.create_user = '" + doctorCode + "' AND i.status != 0 AND i.patient = s.patient AND p.code = i.patient AND s.status = 1 \n" +
//                "AND s.expenses_status = 1 AND pr.patient=p.code and pr.team_code = i.team_code and pr.`status`>=0 and pr.sign_status=1 ";
        String sql2="SELECT i.disease_name diseaseName,p.idcard,p.sex, p.id 'patient',\n" +
                " CAST(IFNULL(p.birthday,'') AS char ) birthday, i.`status`, p.`name` patientName, p.address, \n" +
                " pr.is_manage isManage \n" +
                "FROM wlyy_patient_rehabilitation_plan i \n" +
                " INNER JOIN base_patient p ON p.id = i.patient\n" +
                " INNER JOIN wlyy_rehabilitation_patient_info q ON q.patient=i.id AND q.sign_status='1' AND i.patient_info_code=q.`code`\n" +
                " INNER JOIN wlyy_specialist_patient_relation pr ON pr.patient=p.id\n" +
                "WHERE i.create_user = '" + doctorCode + "' AND i.status != 0 \n" +
                " and pr.`status`>=0 and pr.sign_status=1  ";
        if (StringUtils.isNotBlank(idcard)) {
            sql2 += " and  p.idcard like '%" + idcard + "%' ";
@ -965,22 +985,23 @@ public class RehabilitationInfoService {
//        return data;
//    }
    public JSONObject getUnm(String doctor, String patient) {
        String sqlMe = "select d.id,d.plan_id as planId,i.code,i.name,p.patient,d.frequency_code from wlyy_specialist.wlyy_rehabilitation_plan_detail d \n" +
                "LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p ON p.id=d.plan_id\n" +
                "LEFT JOIN wlyy_specialist.wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id  \n" +
                "where d.plan_id IN (SELECT id FROM wlyy_specialist.wlyy_patient_rehabilitation_plan WHERE patient ='" + patient + "') \n" +
        String sqlMe = "select d.id,d.plan_id as planId,i.code,i.name,p.patient,d.frequency_code from wlyy_rehabilitation_plan_detail d \n" +
                "LEFT JOIN wlyy_patient_rehabilitation_plan p ON p.id=d.plan_id\n" +
                "LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id  \n" +
                "where d.plan_id IN (SELECT id FROM wlyy_patient_rehabilitation_plan WHERE patient ='" + patient + "') \n" +
                "AND d.doctor = '" + doctor + "'  ";//我的任务
        List<Map<String, Object>> listMe = jdbcTemplate.queryForList(sqlMe);
        String sqlAll = "select d.id,d.plan_id as planId,i.code,i.name,p.patient,d.frequency_code from wlyy_specialist.wlyy_rehabilitation_plan_detail d \n" +
                "LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p ON p.id=d.plan_id\n" +
                "LEFT JOIN wlyy_specialist.wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id  \n" +
                "where d.plan_id IN (SELECT id FROM wlyy_specialist.wlyy_patient_rehabilitation_plan WHERE patient ='" + patient + "') ";//全部任务
        String sqlAll = "select d.id,d.plan_id as planId,i.code,i.name,p.patient,d.frequency_code from wlyy_rehabilitation_plan_detail d \n" +
                "LEFT JOIN wlyy_patient_rehabilitation_plan p ON p.id=d.plan_id\n" +
                "LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id  \n" +
                "where d.plan_id IN (SELECT id FROM wlyy_patient_rehabilitation_plan WHERE patient ='" + patient + "') ";//全部任务
        List<Map<String, Object>> listAll = jdbcTemplate.queryForList(sqlAll);
        String newDetailSql = "select d.id,d.plan_id as planId,i.code,i.name,p.patient,d.frequency_code,r.complete_time createTime, r.doctor_name doctorName \n" +
                "from wlyy_specialist.wlyy_rehabilitation_plan_detail d INNER JOIN wlyy_specialist.wlyy_rehabilitation_operate_records r ON d.id = r.rehabilitation_detail_id\n" +
                "LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p ON p.id=d.plan_id\n" +
                "LEFT JOIN wlyy_specialist.wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id  \n" +
                "where d.plan_id IN (SELECT id FROM wlyy_specialist.wlyy_patient_rehabilitation_plan WHERE patient ='" + patient + "')\n" +
                "from wlyy_rehabilitation_plan_detail d \n" +
                "INNER JOIN wlyy_rehabilitation_operate_records r ON d.id = r.rehabilitation_detail_id\n" +
                "LEFT JOIN wlyy_patient_rehabilitation_plan p ON p.id=d.plan_id\n" +
                "LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id  \n" +
                "where d.plan_id IN (SELECT id FROM wlyy_patient_rehabilitation_plan WHERE patient ='" + patient + "')\n" +
                " and r.`status`=1 GROUP BY r.complete_time DESC LIMIT 0,1 ";
        newDetailSql = TransforSqlUtl.wlyy_rehabilitation_operate_recordsDoctorName(newDetailSql);
        List<Map<String, Object>> newDetail = jdbcTemplate.queryForList(newDetailSql);

+ 1061 - 36
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/service/RehabilitationManageService.java

@ -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("请求失败!");
    }
}

+ 11 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/rehabilitation/service/RehabilitationPlanService.java

@ -836,4 +836,15 @@ public class RehabilitationPlanService extends BaseJpaService<RehabilitationPlan
        return list;
    }
    /**
     * 获取康复计划修改记录
     * @param planId
     * @return
     */
    public List<Map<String,Object>> getRehabilitationPlanLog(String planId){
        String sql ="select * from wlyy_specialist.wlyy_patient_rehabilitation_plan_log where plan_id = '"+planId+"' ORDER BY create_time DESC";
        sql = TransforSqlUtl.wlyy_patient_rehabilitation_planLogAll(sql);
        List<Map<String,Object>> planLogList = jdbcTemplate.queryForList(sql);
        return planLogList;
    }
}

+ 166 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/specialist/controller/PatientSpecialistController.java

@ -0,0 +1,166 @@
package com.yihu.jw.hospital.module.specialist.controller;
import com.yihu.jw.hospital.appointment.dao.SpecialDiseaseDao;
import com.yihu.jw.hospital.module.specialist.service.SpecialistService;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
/**
 * Created by Trick on 2018/7/3.
 */
@RestController
@RequestMapping(value = "/patient/specialist", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "患者端-专病管理")
public class PatientSpecialistController extends EnvelopRestEndpoint {
    @Autowired
    private SpecialistService specialistService;
    @Autowired
    private SpecialDiseaseDao specialDiseaseDao;
//    @Autowired
//    private ServerPackageService serverPackageService;
    @RequestMapping(value = "/findPatientTeamList", method = RequestMethod.GET)
    @ApiOperation(value = "获取居民所有专科医生签约信息")
    public String findPatientTeamList(@ApiParam(name = "patient", value = "居民code") @RequestParam(required = true) String patient) {
        try {
            return write(200, "获取成功", "data", specialistService.findPatientTeamList(patient));
        } catch (Exception e) {
            error(e);
            return error(-1, "请求失败");
        }
    }
//    @RequestMapping(value = "/findSpecialistTeamInfo", method = RequestMethod.GET)
//    @ApiOperation(value = "获取专科医生所在团队信息")
//    public String findSpecialistTeamInfo(@ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true)String doctor,
//                                         @ApiParam(name = "teamCode", value = "团队code") @RequestParam(required = true)Long teamCode){
//        try {
//            return write(200, "获取成功", "data", specialistService.findSpecialistTeamInfo(doctor,teamCode));
//        } catch (Exception e) {
//            error(e);
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "/findTeamDiseaseRelation", method = RequestMethod.GET)
//    @ApiOperation(value = "获取团队专病服务信息")
//    public String findTeamDiseaseRelation(@ApiParam(name = "teamCode", value = "团队code") @RequestParam(required = true)Long teamCode) {
//        try {
//            return write(200, "获取成功", "data", specialistService.findTeamDiseaseRelation(teamCode));
//        } catch (Exception e) {
//            error(e);
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "/findPatientDiseaseServerList", method = RequestMethod.GET)
//    @ApiOperation(value = "获取居民专病服务信息")
//    public String findPatientDiseaseServerList(@ApiParam(name = "patient", value = "患者code") @RequestParam(required = true)String patient) {
//        try {
//            return write(200, "获取成功", "data", specialistService.findPatientDiseaseServerList(patient));
//        } catch (Exception e) {
//            error(e);
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "/signSpecialist", method = RequestMethod.POST)
//    @ApiOperation(value = "居民提交专科医生团队签约申请")
//    public String signSpecialist(@ApiParam(name = "patient", value = "患者code") @RequestParam(required = true)String patient,
//                                 @ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true)String doctor,
//                                 @ApiParam(name = "disease", value = "疾病code") @RequestParam(required = true)String disease,
//                                 @ApiParam(name = "teamCode", value = "团队code") @RequestParam(required = true)Long teamCode) throws Exception {
//        try {
//            return write(200, "获取成功", "data", specialistService.signSpecialist(patient,doctor,disease,teamCode));
//        } catch (Exception e) {
//            error(e);
//            return error(-1, "请求失败");
//        }
//    }
//    @RequestMapping(value = "/agreeSpecialistTeam", method = RequestMethod.GET)
//    @ApiOperation(value = "医生审核")
//    public String agreeSpecialistTeam(String state,String relationCode,String remark,Long mesId)throws Exception {
//        try {
//            return write(200, "获取成功", "data", specialistService.agreeSpecialistTeam(getAccessToken(),state, relationCode, remark, mesId, labelcode, doctorcode));
//        } catch (Exception e) {
//            error(e);
//            return error(-1, "请求失败");
//        }
//    }
    /**
     * 根据机构code获取本机构服务项目
     * hospital
     */
//    @RequestMapping(value = "selectHospital1", method = RequestMethod.POST)
//    @ResponseBody
//    @ApiOperation(value = "根据机构code获取本机构服务项目")
//    public String selectHospital1(@RequestParam(name = "hospital",required = false) String hospital){
//        try {
//            return write(200, "查询成功", "data",serverPackageService.selectByHospital1(hospital));
//        } catch (Exception ex) {
//            error(ex);
//            return error(-1, "查询失败");
//        }
//    }
    /**
     * 根据机构code获取本机构服务项目-上门服务
     * hospital
     */
//    @RequestMapping(value = "selectServiceByHospital", method = RequestMethod.POST)
//    @ResponseBody
//    @ApiOperation(value = "根据机构code获取本机构服务项目-上门服务")
//    public String selectServiceByHospital(
//            @RequestParam(name = "hospital",required = false) String hospital,
//            @ApiParam(value = "服务项目名称", name = "serverItemName") @RequestParam(value = "serverItemName", required = false) String serverItemName,
//            @ApiParam(value = "类型", name = "type") @RequestParam(value = "type", required = false) String type,
//            @ApiParam(value = "医生", name = "doctor") @RequestParam(value = "doctor", required = false) String doctor
//    ){
//        try {
//            return write(200, "查询成功", "data",serverPackageService.selectServiceByHospital(hospital,serverItemName,type,getRepUID(),doctor));
//        } catch (Exception ex) {
//            error(ex);
//            return error(-1, "查询失败");
//        }
//    }
//    @RequestMapping(value = "selectServiceTypes", method = RequestMethod.POST)
//    @ResponseBody
//    @ApiOperation(value = "获取服务项目类型-上门服务")
//    public String selectServiceTypes(){
//        try {
//            return write(200, "查询成功", "data",serverPackageService.selectTypes());
//        } catch (Exception ex) {
//            error(ex);
//            return error(-1, "查询失败");
//        }
//    }
//    @RequestMapping(value = "getSpecialDisease", method = RequestMethod.GET)
//    @ApiOperation(value = "获取专科疾病类型")
//    @ResponseBody
//    public String getSpecialDisease() {
//        try {
//            return write(200, "查询成功!", "data", specialDiseaseDao.findByDel("1"));
//        } catch (Exception e) {
//            e.printStackTrace();
//            return write(-1, "查询失败!");
//        }
//    }
}

+ 14 - 3
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/specialist/controller/SpecialistController.java

@ -32,13 +32,25 @@ public class SpecialistController extends EnvelopRestEndpoint {
    @Autowired
    private SpecialistService specialistService;
//    @Autowired
//    private Tracer tracer;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private SpecialistPatientRelationDao specialistPatientRelationDao;
    @RequestMapping(value = "getSpecialistTeamList", method = RequestMethod.GET)
    @ApiOperation(value = "获取专科医生所在团队信息列表")
    public String getSpecialistTeamList(@ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true) String doctor) {
        try {
            return write(200, "获取成功", "data", specialistService.getSpecialistTeamList(doctor));
        } catch (Exception e) {
            return error(-1,e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.specialist.createSpecialistRelation)
    @ApiOperation(value = "创建专科医生与患者匹配关系")
    public MixEnvelop<Boolean, Boolean> createSpecialistPatientRelation(@ApiParam(name = "specialistPatientRelation", value = "实体JSON")
@ -48,7 +60,6 @@ public class SpecialistController extends EnvelopRestEndpoint {
            return specialistService.createSpecialistsPatientRelation(ps);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }

+ 34 - 19
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/specialist/controller/SpecialistScreenResultController.java

@ -11,10 +11,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@ -28,25 +25,45 @@ public class SpecialistScreenResultController extends EnvelopRestEndpoint {
    @Autowired
    private SpecialistService specialistService;
//    @Autowired
    //    @Autowired
//    private Tracer tracer;
    @Autowired
    private SpecialistScreenResultService specialistScreenResultService;
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ApiOperation(value = "专科医生获取筛查记录列表")
    public String createSpecialistPatientRelation(@ApiParam(name = "doctor", value = "专科医生ID") @RequestParam(value = "doctor", required = false) String doctor,
                                                  @ApiParam(value = "当前页") @RequestParam(value = "pageNo") int pageNo,
                                                  @ApiParam(value = "显示记录数") @RequestParam(value = "pageSize") int pageSize,
                                                  @ApiParam(value = "处理方式(1已预约 2已跟踪 3已接诊 4待处理),多个用逗号隔开") @RequestParam(value = "type", required = false) Integer type,
                                                  @ApiParam(value = "搜索居民的姓名或身份证") @RequestParam(value = "patientName", required = false) String patientName,
                                                  @ApiParam(value = "是否高危预警(0否 1是)") @RequestParam(value = "isDanger", required = false) String isDanger,
                                                  @ApiParam(value = "疾病类型,多个用逗号隔开") @RequestParam(value = "diseaseType", required = false) String diseaseType,
                                                  @ApiParam(value = "传1则根据类型查一条数据") @RequestParam(value = "filterType", required = false, defaultValue = "0") Integer filterType,
                                                  @ApiParam(value = "居民code") @RequestParam(value = "patientCode", required = false) String patientCode) {
        try {
            return write(200, "获取成功!", "data", specialistScreenResultService.getScreenList(doctor, type, pageNo, pageSize, patientName, isDanger, diseaseType, filterType, patientCode));
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.screen.getScreenResult)
    @ApiOperation(value = "专科医生获取筛查记录列表")
    public MixEnvelop<SurveyScreenResultVo, SurveyScreenResultVo> createSpecialistPatientRelation(@ApiParam(name = "doctor", value = "专科医生ID")@RequestParam(value = "doctor",required = false)String doctor,
                                                                                                  @ApiParam(value = "当前页")@RequestParam(value = "pageNo") int pageNo,
                                                                                                  @ApiParam(value = "显示记录数")@RequestParam(value = "pageSize") int pageSize,
    public MixEnvelop<SurveyScreenResultVo, SurveyScreenResultVo> createSpecialistPatientRelation(@ApiParam(name = "doctor", value = "专科医生ID") @RequestParam(value = "doctor", required = false) String doctor,
                                                                                                  @ApiParam(value = "当前页") @RequestParam(value = "pageNo") int pageNo,
                                                                                                  @ApiParam(value = "显示记录数") @RequestParam(value = "pageSize") int pageSize,
                                                                                                  @ApiParam(value = "搜索居民的姓名或身份证") @RequestParam(value = "patientName", required = false) String patientName,
                                                                                                  @ApiParam(value = "1已跟踪 2已预约 3已接诊 4待处理")@RequestParam(value = "type",required = false) Integer type,
                                                                                                  @ApiParam(value = "1已跟踪 2已预约 3已接诊 4待处理") @RequestParam(value = "type", required = false) Integer type,
                                                                                                  @ApiParam(value = "是否高危预警(0否 1是)") @RequestParam(value = "isDanger", required = false) String isDanger,
                                                                                                  @ApiParam(value = "疾病类型") @RequestParam(value = "diseaseType", required = false) String diseaseType,
                                                                                                  @ApiParam(value = "传1则根据类型查一条数据")@RequestParam(value = "filterType",required = false,defaultValue = "0")Integer filterType,
                                                                                                  @ApiParam(value = "居民code")@RequestParam(required = false)String patientCode){
                                                                                                  @ApiParam(value = "传1则根据类型查一条数据") @RequestParam(value = "filterType", required = false, defaultValue = "0") Integer filterType,
                                                                                                  @ApiParam(value = "居民code") @RequestParam(required = false) String patientCode) {
        try {
            return specialistScreenResultService.getScreenList(doctor,type,pageNo,pageSize,patientName, isDanger, diseaseType,filterType,patientCode);
        }catch (Exception e){
            return specialistScreenResultService.getScreenList(doctor, type, pageNo, pageSize, patientName, isDanger, diseaseType, filterType, patientCode);
        } catch (Exception e) {
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
@ -55,10 +72,10 @@ public class SpecialistScreenResultController extends EnvelopRestEndpoint {
    @GetMapping(value = SpecialistMapping.screen.getScreenCount)
    @ApiOperation(value = "专科医生首页--筛查已跟踪和已预约的数目")
    public MixEnvelop<Map<String,Object>, Map<String,Object>> findSpecialistPatientRelation(@ApiParam(name = "doctor", value = "专科医生ID")@RequestParam(value = "doctor")String doctor){
    public MixEnvelop<Map<String, Object>, Map<String, Object>> findSpecialistPatientRelation(@ApiParam(name = "doctor", value = "专科医生ID") @RequestParam(value = "doctor") String doctor) {
        try {
            return specialistScreenResultService.getResultCount(doctor);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
@ -67,10 +84,10 @@ public class SpecialistScreenResultController extends EnvelopRestEndpoint {
    @GetMapping(value = SpecialistMapping.screen.getScreenResultDetail)
    @ApiOperation(value = "查看筛查结果记录详情.")
    public MixEnvelop<Map<String,Object>, Map<String,Object>> getScreenResultDetail(@ApiParam(value = "筛查结果唯一code")@RequestParam(value = "code") String code) {
    public MixEnvelop<Map<String, Object>, Map<String, Object>> getScreenResultDetail(@ApiParam(value = "筛查结果唯一code") @RequestParam(value = "code") String code) {
        try {
            return specialistScreenResultService.getScreenResultDetail(code);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
@ -78,6 +95,4 @@ public class SpecialistScreenResultController extends EnvelopRestEndpoint {
    }
}

+ 49 - 4
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/specialist/service/SpecialistService.java

@ -626,14 +626,10 @@ public class SpecialistService{
        String sql = "SELECT " +
                " r.id AS relationCode, " +
                " r.patient, r.patient_name as patientName" +
               // AesEncryptUtils.decryptMysql("r.patient_name","patientName") +
//                " r.patient_name AS patientName, " +
                " ,r.team_code,r.sign_date , " +
                " t.`name` AS name," +
                " d.photo," +
                " md.code AS doctor,md.name as doctorName" +
              //  AesEncryptUtils.decryptMysql("md.name","doctorName") +
//                " md.name AS doctorName," +
                ",d.hospital,d.hospital_name " +
                " FROM " +
                " wlyy_specialist_patient_relation r  " +
@ -1447,4 +1443,53 @@ public class SpecialistService{
        result.put("rehabilitationOperateRecords",rehabilitationOperateRecords);
        return  result;
    }
    public List<Map<String, Object>> getSpecialistTeamList(String doctor) {
        String sql = "SELECT " +
                " t.id, " +
                " t.name, " +
                " d.photo, " +
                " t.leader_code, " +
                " d.name as leader_name," +
                " t.special_code, " +
                " t.special_name " +
                " FROM " +
                " wlyy_admin_team t " +
                " JOIN wlyy_admin_team_member m ON t.id = m.team_id " +
                " JOIN wlyy_doctor d ON d.code = t.leader_code " +
                " WHERE " +
                " m.doctor_code = '" + doctor + "' " +
                " AND t.available ='1' " +
                " AND m.available ='1' ";
        List<Map<String, Object>> rs = jdbcTemplate.queryForList(sql);
        if (rs != null && rs.size() > 0) {
            for (Map<String, Object> team : rs) {
                Integer id = (Integer) team.get("id");
                String sqlMember = "SELECT " +
                        " d.name, " +
                        " d.code," +
                        "CASE " +
                        "WHEN(d.sex=1) " +
                        "THEN '男' " +
                        "WHEN(d.sex=2) " +
                        "THEN '女' " +
                        "ELSE 'X' " +
                        "END AS sex, " +
                        " d.photo, " +
                        " d.hospital_name, " +
                        " d.dept_name, " +
                        " d.job_name " +
                        " FROM " +
                        " wlyy_admin_team_member m " +
                        " JOIN wlyy_doctor d ON m.doctor_code = d.`code` " +
                        " WHERE " +
                        " m.team_id =" + id +
                        " AND m.available='1'";
                List<Map<String, Object>> list = jdbcTemplate.queryForList(sqlMember);
                team.put("doctors", list);
            }
            return rs;
        }
        return rs;
    }
}