suqinyi преди 1 година
родител
ревизия
dcc913f09d

Файловите разлики са ограничени, защото са твърде много
+ 93 - 75
common/common-entity/src/main/java/com/yihu/jw/entity/util/TransforSqlUtl.java


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

@ -72,6 +72,28 @@ public class PatientRehabilitationManageController extends EnvelopRestEndpoint {
    }
    @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(
@ -92,6 +114,120 @@ public class PatientRehabilitationManageController extends EnvelopRestEndpoint {
        }
    }
    /**
     * 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)
@ -105,25 +241,25 @@ public class PatientRehabilitationManageController extends EnvelopRestEndpoint {
//        }
//    }
//    @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 = "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("获取居民医院病历列表")
@ -180,26 +316,53 @@ public class PatientRehabilitationManageController extends EnvelopRestEndpoint {
//        }
//    }
    /**
     * 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 = 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) {
//    @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 {
//            JSONArray result = rehabilitationManageService.calendarPlanDetailList(executeStartTime, executeEndTime, planId, searchTask, status, null);
//            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, "请求失败");
//        }  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)
@ -401,29 +564,29 @@ public class PatientRehabilitationManageController extends EnvelopRestEndpoint {
//        }
//    }
//    @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 = "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("更新康复计划居民签名照/证件照")

+ 2 - 2
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.*;
@ -113,6 +114,7 @@ public class RehabilitationManageController {
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.calendarPlanDetailList)
    @ApiOperation(value = "康复管理-康复计划按列表展示")
    public ObjEnvelop calendarPlanDetailList(
@ -128,7 +130,6 @@ public class RehabilitationManageController {
            return rehabilitationManageService.calendarPlanDetailList(planId, searchTask, status, doctorCode, executeStartTime, executeEndTime, taskExecutor);
        } catch (Exception e) {
            e.printStackTrace();
            return ObjEnvelop.getError(e.getMessage());
        }
    }
@ -143,7 +144,6 @@ public class RehabilitationManageController {
            return rehabilitationManageService.serviceItemList(planDetailIds, doctorCode);
        } catch (Exception e) {
            e.printStackTrace();
            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

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

@ -10,8 +10,10 @@ 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.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;
@ -31,6 +33,7 @@ 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.util.*;
@ -43,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
@ -66,6 +72,11 @@ public class RehabilitationManageService {
    @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)) {
@ -574,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("请求失败!");
    }
    /**
     * 日历列表
     *
@ -584,7 +625,6 @@ 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] + "'");
@ -1587,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("请求微服务失败!");
    }
    /**
     * 计划总进度
@ -1625,6 +1715,7 @@ public class RehabilitationManageService {
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultMap);
    }
    /**
     * 根据居民获取康复计划
     *
@ -1889,4 +1980,770 @@ public class RehabilitationManageService {
        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;
    }
}

+ 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 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/specialist/service/SpecialistService.java

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