Kaynağa Gözat

代码修改

LAPTOP-KB9HII50\70708 1 yıl önce
ebeveyn
işleme
8e078e0db8
36 değiştirilmiş dosya ile 0 ekleme ve 8107 silme
  1. 0 12
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/PatientHospitalRecordDao.java
  2. 0 16
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistEvaluateDao.java
  3. 0 15
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistEvaluateLabelDao.java
  4. 0 15
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistEvaluateScoreDao.java
  5. 0 22
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistHospitalServiceItemDao.java
  6. 0 41
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistPatientRelationDao.java
  7. 0 27
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistServiceItemDao.java
  8. 0 17
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistServiceItemOperateLogDao.java
  9. 0 15
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/GuidanceMessageLogDao.java
  10. 0 17
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/PatientDiagnosisInformationDao.java
  11. 0 58
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/PatientRehabilitationPlanDao.java
  12. 0 11
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/PatientRehabilitationPlanLogDao.java
  13. 0 13
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/RehabilitationDetailAppointmentDao.java
  14. 0 94
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/RehabilitationDetailDao.java
  15. 0 38
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/RehabilitationOperateRecordsDao.java
  16. 0 16
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/RehabilitationServiceItemDao.java
  17. 0 12
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/TemplateJsonDao.java
  18. 0 558
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistController.java
  19. 0 126
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistEvaluateController.java
  20. 0 247
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistHospitalServiceItemController.java
  21. 0 83
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistScreenResultController.java
  22. 0 237
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistServiceItemController.java
  23. 0 63
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistServiceItemOperateLogController.java
  24. 0 78
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/rehabilitation/DiagnosisInformationController.java
  25. 0 511
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/rehabilitation/RehabilitationManageController.java
  26. 0 653
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/rehabilitation/RehabilitationPlanController.java
  27. 0 17
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/FileUploadService.java
  28. 0 414
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistEvaluateService.java
  29. 0 418
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistHospitalServiceItemService.java
  30. 0 261
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistScreenResultService.java
  31. 0 1448
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistService.java
  32. 0 66
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistServiceItemOperateLogService.java
  33. 0 223
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistServiceItemService.java
  34. 0 62
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/rehabilitation/DiagnosisInformationService.java
  35. 0 1595
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/rehabilitation/RehabilitationManageService.java
  36. 0 608
      svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/rehabilitation/RehabilitationPlanService.java

+ 0 - 12
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/PatientHospitalRecordDao.java

@ -1,12 +0,0 @@
package com.yihu.jw.base.dao.specialist;
import com.yihu.jw.entity.specialist.PatientHospitalRecordDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2018/4/25.
 */
public interface PatientHospitalRecordDao extends PagingAndSortingRepository<PatientHospitalRecordDO, String>,
        JpaSpecificationExecutor<PatientHospitalRecordDO> {
}

+ 0 - 16
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistEvaluateDao.java

@ -1,16 +0,0 @@
package com.yihu.jw.base.dao.specialist;/**
 * Created by nature of king on 2018/8/21.
 */
import com.yihu.jw.entity.specialist.SpecialistEvaluateDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author wangzhinan
 * @create 2018-08-21 16:41
 * @desc 评论表
 **/
public interface SpecialistEvaluateDao extends PagingAndSortingRepository<SpecialistEvaluateDO, String>, JpaSpecificationExecutor<SpecialistEvaluateDO> {
}

+ 0 - 15
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistEvaluateLabelDao.java

@ -1,15 +0,0 @@
package com.yihu.jw.base.dao.specialist;/**
 * Created by nature of king on 2018/8/22.
 */
import com.yihu.jw.entity.specialist.SpecialistEvaluateLabelDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author wangzhinan
 * @create 2018-08-22 9:38
 * @desc 评论标签
 **/
public interface SpecialistEvaluateLabelDao extends PagingAndSortingRepository<SpecialistEvaluateLabelDO, String>, JpaSpecificationExecutor<SpecialistEvaluateLabelDO> {
}

+ 0 - 15
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistEvaluateScoreDao.java

@ -1,15 +0,0 @@
package com.yihu.jw.base.dao.specialist;/**
 * Created by nature of king on 2018/8/22.
 */
import com.yihu.jw.entity.specialist.SpecialistEvaluateScoreDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author wangzhinan
 * @create 2018-08-22 9:39
 * @desc 评论得分
 **/
public interface SpecialistEvaluateScoreDao extends PagingAndSortingRepository<SpecialistEvaluateScoreDO, String>, JpaSpecificationExecutor<SpecialistEvaluateScoreDO> {
}

+ 0 - 22
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistHospitalServiceItemDao.java

@ -1,22 +0,0 @@
package com.yihu.jw.base.dao.specialist;/**
 * Created by nature of king on 2018/8/28.
 */
import com.yihu.jw.entity.specialist.HospitalServiceItemDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-08-28 19:54
 * @desc 机构服务项目
 **/
public interface SpecialistHospitalServiceItemDao extends PagingAndSortingRepository<HospitalServiceItemDO, String>,
        JpaSpecificationExecutor<HospitalServiceItemDO> {
    @Query("select p from HospitalServiceItemDO  p where p.hospital =?1 and p.serviceItemId =?2")
    public List<HospitalServiceItemDO> findByHospitalAndServiceItemId(String hospital, String serviceItemId);
}

+ 0 - 41
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistPatientRelationDao.java

@ -1,41 +0,0 @@
package com.yihu.jw.base.dao.specialist;
import com.yihu.jw.entity.specialist.SpecialistPatientRelationDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Trick on 2018/4/25.
 */
public interface SpecialistPatientRelationDao extends PagingAndSortingRepository<SpecialistPatientRelationDO, String>,
        JpaSpecificationExecutor<SpecialistPatientRelationDO> {
    public List<SpecialistPatientRelationDO> findByDoctorAndStatus(String doctor, String status);
    @Query("select p from SpecialistPatientRelationDO p where p.doctor=?1 and p.patient =?2  and p.status>=0 and p.signStatus=1")
    public SpecialistPatientRelationDO findByDoctorAndPatient(String doctor, String patient);
    @Query("select p from SpecialistPatientRelationDO p where p.doctor=?1 and (p.patient=?2 or p.healthAssistant=?2) and p.signStatus='1' and p.status>=0 ")
    SpecialistPatientRelationDO findByPatientAndDoctor(String doctor, String patient);
    List<SpecialistPatientRelationDO> findAllBySignStatus(String signStatus);
    @Modifying
    @Query("update SpecialistPatientRelationDO p set p.doctor = ?2, p.doctorName=?3 where p.patient=?1 and p.signStatus='1' and p.status>=0 ")
    void updateSpecialistByPatient(String patient, String doctor, String doctorName);
    @Query("select p from SpecialistPatientRelationDO p where p.teamCode=?1 and p.patient =?2 and p.status>=0 and p.signStatus=1")
    public SpecialistPatientRelationDO findByTeamCodeAndPatient(Integer teamCode, String patient);
    @Query("select p from SpecialistPatientRelationDO p where p.doctor=?1 and p.patient =?2 and p.teamCode =?3 and p.status>=0 and p.signStatus=1")
    public SpecialistPatientRelationDO findByDoctorAndPatientAndTeamCode(String doctor, String patient, Integer teamCode);
    @Query("select p from SpecialistPatientRelationDO p where p.teamCode=?1 and p.patient=?2 and p.doctor=?3 and p.status>=0 and p.status >=0 and p.signStatus=1")
    List<SpecialistPatientRelationDO> findListByTeamCodeAndPatientAndDoctor(Integer teamCode, String patient, String doctor);
    @Query("select p from SpecialistPatientRelationDO p where p.teamCode=?1 and p.patient=?2 and p.status>=0 and p.status >=0 and p.signStatus=1")
    List<SpecialistPatientRelationDO> findListByTeamAndPatient(Integer teamCode, String patient);
}

+ 0 - 27
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistServiceItemDao.java

@ -1,27 +0,0 @@
package com.yihu.jw.base.dao.specialist;/**
 * Created by nature of king on 2018/8/16.
 */
import com.yihu.jw.entity.specialist.SpecialistServiceItemDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-08-16 10:58
 * @desc 服务项目Dao
 **/
public interface SpecialistServiceItemDao extends PagingAndSortingRepository<SpecialistServiceItemDO, String>,
        JpaSpecificationExecutor<SpecialistServiceItemDO> {
    @Query("select p from SpecialistServiceItemDO p where p.title =?1")
    public List<SpecialistServiceItemDO> findByTitle(String title);
    @Query("select p from SpecialistServiceItemDO p where p.title =?1 and p.content=?2")
    public List<SpecialistServiceItemDO> findByTitleAndContent(String title, String content);
}

+ 0 - 17
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/SpecialistServiceItemOperateLogDao.java

@ -1,17 +0,0 @@
package com.yihu.jw.base.dao.specialist;/**
 * Created by nature of king on 2018/8/16.
 */
import com.yihu.jw.entity.specialist.SpecialistServiceItemOperateLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author wangzhinan
 * @create 2018-08-16 11:04
 * @desc 服务项目操作日志
 **/
public interface SpecialistServiceItemOperateLogDao  extends PagingAndSortingRepository<SpecialistServiceItemOperateLogDO, String>,
        JpaSpecificationExecutor<SpecialistServiceItemOperateLogDO> {
}

+ 0 - 15
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/GuidanceMessageLogDao.java

@ -1,15 +0,0 @@
package com.yihu.jw.base.dao.specialist.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.GuidanceMessageLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by 刘文彬 on 2018/8/23.
 */
public interface GuidanceMessageLogDao extends PagingAndSortingRepository<GuidanceMessageLogDO, Long>, JpaSpecificationExecutor<GuidanceMessageLogDO> {
    List<GuidanceMessageLogDO> findByPlanDetailId(String planDetailId);
}

+ 0 - 17
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/PatientDiagnosisInformationDao.java

@ -1,17 +0,0 @@
package com.yihu.jw.base.dao.specialist.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.PatientDiagnosisInformationDO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface PatientDiagnosisInformationDao extends PagingAndSortingRepository<PatientDiagnosisInformationDO, Long>,
        JpaSpecificationExecutor<PatientDiagnosisInformationDO> {
    PatientDiagnosisInformationDO findByPlanId(String planId);
    @Query("select d from PatientDiagnosisInformationDO d where d.patient = ?1 order by d.dischargeTime,d.createTime desc")
    Page<PatientDiagnosisInformationDO> findByPatient(String patient, Pageable pageRequest);
}

+ 0 - 58
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/PatientRehabilitationPlanDao.java

@ -1,58 +0,0 @@
package com.yihu.jw.base.dao.specialist.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
/**
 * Created by 刘文彬 on 2018/8/16.
 */
public interface PatientRehabilitationPlanDao extends PagingAndSortingRepository<PatientRehabilitationPlanDO, String>, JpaSpecificationExecutor<PatientRehabilitationPlanDO> {
//    PatientRehabilitationPlanDO findById(String id);
    @Query(" select p from PatientRehabilitationPlanDO p where p.patient=?1 and p.createUser=?2 order by p.createTime desc ")
    List<PatientRehabilitationPlanDO> findByPatientAndCreateUser(String patient, String doctor);
    @Query(" select p from PatientRehabilitationPlanDO p where p.patient=?1 and p.createUser=?2 and p.teamCode=?3 order by p.createTime desc ")
    List<PatientRehabilitationPlanDO> findByPatientAndCreateUserAndTeamCode(String patient, String doctor, Integer teamCode);
    @Query(" select p from PatientRehabilitationPlanDO p where p.patient=?1 order by p.createTime desc ")
    List<PatientRehabilitationPlanDO> findByPatients(String patientCode);
    @Query("update PatientRehabilitationPlanDO a set a.status=?1 where a.id =?2 ")
    @Modifying
    int updateStatusById(Integer status, String id);
    //插入服务包id
    @Modifying
    @Query("update PatientRehabilitationPlanDO p set p.servicePackageId = ?2 where p.id = ?1")
    void updateServicePackageId(String planId, String servicePackageId);
    @Query("select count(distinct p.patient) from PatientRehabilitationPlanDO p where p.createUser=?1  and p.status>0 ")
    Integer patientCount(String doctorCode);
    @Query("select count(distinct p.patient) from PatientRehabilitationPlanDO p where p.createUser=?1  and p.status=2 ")
    Integer getFinishPatientCount(String doctorCode);
//    @Query("update PatientRehabilitationPlanDO a set a.status=0,a.abortReason=?1,a.abortTime=?3 where a.id =?2 ")
//    @Modifying
//    int abortPlanById(String abortReason, String id, Date abortTime);
    @Query("select p from PatientRehabilitationPlanDO p where p.disease =?1 and p.status=1 and p.patient=?2")
    List<PatientRehabilitationPlanDO> selectByDiseaseAndPatient(String disease, String patient);
    @Modifying
    @Query("update PatientRehabilitationPlanDO t set t.patientImg = ?2 where t.id=?1 ")
    int updatePatientImgById(String planId, String patientImg);
    @Query("update PatientRehabilitationPlanDO a set a.status=?1,a.abortTime= ?3 where a.id =?2 ")
    @Modifying
    int updateStatusAndTimeById(Integer status, String id, Date date);
}

+ 0 - 11
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/PatientRehabilitationPlanLogDao.java

@ -1,11 +0,0 @@
package com.yihu.jw.base.dao.specialist.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by liub on 2021/1/12.
 */
public interface PatientRehabilitationPlanLogDao extends PagingAndSortingRepository<PatientRehabilitationPlanLogDO,Long>, JpaSpecificationExecutor<PatientRehabilitationPlanLogDO> {
}

+ 0 - 13
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/RehabilitationDetailAppointmentDao.java

@ -1,13 +0,0 @@
package com.yihu.jw.base.dao.specialist.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailAppointmentDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by ysj on 2020/7/10.
 */
public interface RehabilitationDetailAppointmentDao extends PagingAndSortingRepository<RehabilitationDetailAppointmentDO, String>, JpaSpecificationExecutor<RehabilitationDetailAppointmentDO> {
}

+ 0 - 94
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/RehabilitationDetailDao.java

@ -1,94 +0,0 @@
package com.yihu.jw.base.dao.specialist.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created by 刘文彬 on 2018/8/20.
 */
public interface RehabilitationDetailDao extends PagingAndSortingRepository<RehabilitationDetailDO, Long>, JpaSpecificationExecutor<RehabilitationDetailDO> {
    @Query("select count(1) from RehabilitationDetailDO where status=?1 and planId=?2 ")
    Integer findByStatusAndPlanId(Integer status, String planId);
    @Query("select count(1) from RehabilitationDetailDO where planId=?1 ")
    Integer findAllByPlanId(String planId);
    @Query("select count(1) from RehabilitationDetailDO where planId=?1 and executeTime>=?2 and executeTime<=?3 ")
    Integer todayBacklogCount(String programId, Date executeStartTime, Date executeEndTime);
    @Query("select count(1) from RehabilitationDetailDO where status =?1 and planId=?2 and executeTime>=?3 and executeTime<=?4 ")
    Integer completenessCount(Integer status, String planId, Date executeStartTime, Date executeEndTime);
    @Query("select d from RehabilitationDetailDO d where d.planId=?1 order by d.executeTime desc")
    List<RehabilitationDetailDO> getAllRehabilitationDetail(String programId);
    @Query("select d from RehabilitationDetailDO d where d.executeTime<=?1 and d.executeTime>=?2 and d.planId=?3")
    List<RehabilitationDetailDO> findByPlanId(Date executeStartTime, Date executeEndTime, String planId);
    @Query(value ="select count(DISTINCT d.plan_id,d.hospital_service_item_id) from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.doctor=?1 and p.patient=?2  and d.status!=?3",nativeQuery = true)
    Integer unfinishItemByDoctor(String doctor, String patient, Integer status);
    @Query(value ="select count(DISTINCT d.plan_id,d.hospital_service_item_id) from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.doctor in (?1,?2) and p.patient=?3  and d.status!=?4",nativeQuery = true)
    Integer unfinishItemByDoctor(String generalDoctor, String healthDoctor, String patient, Integer status);
    @Query(value ="select count(DISTINCT d.plan_id,d.hospital_service_item_id) from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.doctor=?1 and p.patient=?2",nativeQuery = true)
    Integer findItemByDoctor(String doctor, String patient);
    @Query(value ="select count(DISTINCT d.plan_id,d.hospital_service_item_id) from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.doctor in (?1,?2) and p.patient=?3",nativeQuery = true)
    Integer findItemByDoctor(String generalDoctor, String healthDoctor, String patient);
//    @Query("select count(distinct serviceItemId) from RehabilitationDetailDO d left join PatientRehabilitationPlanDO p on d.planId=p.id where doctor=?1 and p.patient=?2 ")
//    Integer finishItemByDoctor(String doctor,String patient);
//
    @Query(value ="select count(1) from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where doctor=?1 and p.patient=?2  and d.status=?3",nativeQuery = true)
    Integer completeServiceByDoctor(String doctor, String patient, Integer status);
    @Query(value ="select count(1) from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where doctor in (?1,?2) and p.patient=?3  and d.status=?4",nativeQuery = true)
    Integer completeServiceByDoctor(String generalDoctor, String healthDoctor, String patient, Integer status);
    RehabilitationDetailDO findById(String planDetailId);
    @Query(value ="select d.doctor,p.patient,count(1) as num from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.status!=1 and d.execute_time>=?1 and d.execute_time<=?2 GROUP BY d.doctor,p.patient",nativeQuery = true)
    List<Map> dailyJob(String startTime, String endTime);
    @Query(value = "select d.id from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.status!=1 and d.execute_time>=?1 and d.execute_time<=?2 and d.doctor=?3 and p.patient=?4",nativeQuery = true)
    List<String> findByPatientAndDoctor(String startTime, String endTime, String doctorCode, String patientCode);
    @Modifying
    @Query("update RehabilitationDetailDO t set t.status = ?1 where t.id=?2 ")
    int updateStatusById(Integer status, String id);
    @Modifying
    @Query("update RehabilitationDetailDO t set t.status = ?1,t.relationCode=?3 where t.id=?2 ")
    int updateStatusAndRelationCodeById(Integer status, String id, String relationCode);
    @Query(value ="select p.patient from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.id=?1",nativeQuery = true)
    List<String> findPatientById(String planDetailId);
    @Query
    List<RehabilitationDetailDO> findByPlanIdAndStatus(String planId, int status);
    @Modifying
    @Query("update RehabilitationDetailDO t set t.executeTime = ?1 where t.id=?2 ")
    int updateExecuteTime(Date executeTime, String id);
    @Modifying
    @Query("delete from RehabilitationDetailDO t where t.planId = ?1 and t.hospitalServiceItemId = ?2 and (t.executeTime > ?3 OR t.executeTime is null OR t.executeTime<>'')  and t.status <> 1 ")
    void deleteDetailByPlanIdAndHospitalServiceItemId(String planId, String hospitalServiceItemId, Date dateShort);
    @Modifying
    @Query("delete from RehabilitationDetailDO t where t.planId = ?1 and (t.executeTime > ?2 OR t.executeTime is null OR t.executeTime<>'')  and t.status <> 1 ")
    void deleteDetailByPlanId(String planId, Date dateShort);
    @Query("select d from RehabilitationDetailDO d where d.planId = ?1 and d.type=?2 and d.doctor=?3 and d.status<>?4 ")
    List<RehabilitationDetailDO> findByPlanIdAndTypeAndDoctorAndStatusNot(String planId, Integer type, String doctor, Integer status);
}

+ 0 - 38
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/RehabilitationOperateRecordsDao.java

@ -1,38 +0,0 @@
package com.yihu.jw.base.dao.specialist.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationOperateRecordsDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by 刘文彬 on 2018/8/29.
 */
public interface RehabilitationOperateRecordsDao extends PagingAndSortingRepository<RehabilitationOperateRecordsDO, Long>, JpaSpecificationExecutor<RehabilitationOperateRecordsDO> {
    List<RehabilitationOperateRecordsDO> findByRehabilitationDetailId(String rehabilitationDetailId);
    List<RehabilitationOperateRecordsDO> findByRehabilitationDetailIdAndId(String rehabilitationDetailId, String id);
    @Modifying
    @Query("update RehabilitationOperateRecordsDO a set a.status=?1 where a.rehabilitationDetailId =?2 ")
    int updateStatus(Integer status, String rehabilitationDetailId);
    @Modifying
    @Query("update RehabilitationOperateRecordsDO a set a.node=?1,a.relationRecordImg=?2,a.status=1 where a.rehabilitationDetailId =?3 ")
    int updateNodeAndRelationRecordImg(String node, String rehabilitationRecordImg, String rehabilitataioDetailId);
    @Modifying
    @Query("update RehabilitationOperateRecordsDO a set a.node=?1,a.status=1 where a.rehabilitationDetailId =?2 ")
    int updateNodeByPlanDetailId(String node, String rehabilitataioDetailId);
    @Modifying
    @Query("update RehabilitationOperateRecordsDO a set a.relationRecordImg=?1,a.status=1 where a.rehabilitationDetailId =?2 ")
    int updateImagByPlanDetailId(String image, String rehabilitataioDetailId);
    @Query("select a from RehabilitationOperateRecordsDO a where a.rehabilitationDetailId=?1 and a.doctorCode=?2 and a.status<>?3")
    List<RehabilitationOperateRecordsDO> findByRehabilitationDetailIdAndDoctorCodeAndStatusNot(String rehabilitationDetailId, String doctorCode, Integer status);
}

+ 0 - 16
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/RehabilitationServiceItemDao.java

@ -1,16 +0,0 @@
package com.yihu.jw.base.dao.specialist.rehabilitation;
import com.yihu.jw.entity.specialist.RehabilitationServiceItemDO;
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 RehabilitationServiceItemDao extends PagingAndSortingRepository<RehabilitationServiceItemDO, Long>, JpaSpecificationExecutor<RehabilitationServiceItemDO> {
    RehabilitationServiceItemDO findByCode(String itemId);
    @Query("SELECT a FROM RehabilitationServiceItemDO a ")
    List<RehabilitationServiceItemDO> findList();
}

+ 0 - 12
svr/svr-base/src/main/java/com/yihu/jw/base/dao/specialist/rehabilitation/TemplateJsonDao.java

@ -1,12 +0,0 @@
package com.yihu.jw.base.dao.specialist.rehabilitation;
import com.yihu.jw.entity.specialist.rehabilitation.TemplateJson;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface TemplateJsonDao extends PagingAndSortingRepository<TemplateJson, String>,
        JpaSpecificationExecutor<TemplateJson> {
}

+ 0 - 558
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistController.java

@ -1,558 +0,0 @@
package com.yihu.jw.base.endpoint.specialist;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.dao.specialist.SpecialistPatientRelationDao;
import com.yihu.jw.base.service.specialist.SpecialistService;
import com.yihu.jw.entity.specialist.SpecialistPatientRelationDO;
import com.yihu.jw.restmodel.specialist.*;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by Trick on 2018/4/25.
 */
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "专科医生相关操作", description = "专科医生相关操作")
public class SpecialistController extends EnvelopRestEndpoint {
    @Autowired
    private SpecialistService specialistService;
//    @Autowired
//    private Tracer tracer;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private SpecialistPatientRelationDao specialistPatientRelationDao;
    @PostMapping(value = SpecialistMapping.specialist.createSpecialistRelation)
    @ApiOperation(value = "创建专科医生与患者匹配关系")
    public MixEnvelop<Boolean, Boolean> createSpecialistPatientRelation(@ApiParam(name = "specialistPatientRelation", value = "实体JSON")
                                                                @RequestParam(value = "specialistPatientRelation", required = false)String specialistPatientRelation){
        try {
            SpecialistPatientRelationDO ps = toEntity(specialistPatientRelation, SpecialistPatientRelationDO.class);
            return specialistService.createSpecialistsPatientRelation(ps);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.findSpecialistPatientRelation)
    @ApiOperation(value = "获取专科医生关系列表")
    public MixEnvelop<SpecialistPatientRelationVO, SpecialistPatientRelationVO> findSpecialistPatientRelation(@ApiParam(name = "doctor", value = "专科医生ID")
                                                                                  @RequestParam(value = "doctor", required = false)String doctor,
                                                                                                              @ApiParam(name = "page", value = "第几页,从1开始")
                                                                              @RequestParam(value = "page", required = false)Integer page,
                                                                                                              @ApiParam(name = "size", value = ",每页分页大小")
                                                                                  @RequestParam(value = "size", required = false)Integer size){
        try {
            return specialistService.findSpecialistPatientRelation(doctor,page,size);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.findSpecialistPatientRelationCout)
    @ApiOperation(value = "获取专科医生下未分配标签居民数目")
    public MixEnvelop<Long, Long> findSpecialistPatientRelationCout(@ApiParam(name = "doctor", value = "医生") @RequestParam(required = true)String doctor){
        try {
            return specialistService.findSpecialistPatientRelationCout(doctor);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.findNoLabelPatientRelation)
    @ApiOperation(value = "获取专科医生下未分配标签居民")
    public MixEnvelop<PatientRelationVO, PatientRelationVO> findNoLabelPatientRelation(@ApiParam(name = "doctor", value = "医生") @RequestParam(required = true)String doctor){
        try {
            return specialistService.findNoLabelPatientRelation(doctor);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.specialist.saveHealthAssistant)
    @ApiOperation(value = "保存配置居民计管师居民")
    public MixEnvelop<Boolean, Boolean> saveHealthAssistant(@ApiParam(name = "json", value = "计管师居民实体") @RequestParam(required = true)String json){
        try {
            List<SpecialistPatientRelationDO> info = (List<SpecialistPatientRelationDO>) JSONArray.parseArray(json, SpecialistPatientRelationDO.class);
            return specialistService.saveHealthAssistant(info);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.findPatientRelatioByAssistant)
    @ApiOperation(value = "根据计管师获取居民信息")
    public MixEnvelop<PatientRelationVO, PatientRelationVO> findPatientRelatioByAssistant(@ApiParam(name = "doctor", value = "医生") @RequestParam(required = true)String doctor,
                                                                                          @ApiParam(name = "assistant", value = "计管师") @RequestParam(required = true)String assistant,
                                                                                          @ApiParam(name = "page", value = "第几页,1开始") @RequestParam(required = true)Integer page,
                                                                                          @ApiParam(name = "size", value = "每页大小") @RequestParam(required = true)Integer size) {
        try {
            return specialistService.findPatientRelatioByAssistant(doctor,assistant,page,size);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.getPatientByLabel)
    @ApiOperation(value = "根据标签获取居民信息")
    public MixEnvelop<PatientLabelVO, PatientLabelVO> getPatientByLabel(@ApiParam(name = "doctor", value = "医生") @RequestParam(required = true)String doctor,
                                                                        @ApiParam(name = "labelType", value = "标签类型") @RequestParam(required = true)String labelType,
                                                                        @ApiParam(name = "teamCode", value = "医生当前所在团队") @RequestParam(required = true) String teamCode,
                                                                        @ApiParam(name = "labelCode", value = "标签code") @RequestParam(required = true)String labelCode,
                                                                        @ApiParam(name = "page", value = "第几页,1开始") @RequestParam(required = true)Integer page,
                                                                        @ApiParam(name = "size", value = "每页大小") @RequestParam(required = true)Integer size,
                                                                        @ApiParam(name = "shareDoctor", value = "共管医生") @RequestParam(required = false)String shareDoctor
                                                                        ){
        try {
            return specialistService.getPatientByLabel(doctor,labelType,teamCode,labelCode,page,size,shareDoctor);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.getLabelpatientCount)
    @ApiOperation(value = "根据标签获取居民数量")
    public MixEnvelop<Long, Long> getLabelpatientCount(@ApiParam(name = "doctor", value = "医生") @RequestParam(required = true)String doctor,
                                                       @ApiParam(name = "labelType", value = "标签类型") @RequestParam(required = true)String labelType,
                                                       @ApiParam(name = "teamCode", value = "医生团队") @RequestParam(required = true)Long teamCode,
                                                       @ApiParam(name = "labelCode", value = "标签code") @RequestParam(required = true)String labelCode,
                                                       @ApiParam(name = "shareDoctor", value = "共管医生CODE") @RequestParam(required = false)String shareDoctor) {
        try {
            return specialistService.getLabelpatientCount(doctor,labelType,labelCode,teamCode,shareDoctor);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.getAssistantPatientCount)
    @ApiOperation(value = "根据计管获取居民数量")
    public MixEnvelop<Long, Long> getAssistantPatientCount(@ApiParam(name = "doctor", value = "医生") @RequestParam(required = true)String doctor,
                                                           @ApiParam(name = "assistant", value = "计管师医生") @RequestParam(required = true)String assistant) {
        try {
            return specialistService.getAssistantPatientCount(doctor,assistant);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.getDoctorPatientByName)
    @ApiOperation(value = "搜索专科医生居民")
    public MixEnvelop<PatientRelationVO, PatientRelationVO> getDoctorPatientByName(@ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true)String doctor,
                                                                                   @ApiParam(name = "nameKey", value = "居民姓名模糊") @RequestParam(required = false)String nameKey,
                                                                                   @ApiParam(name = "teamCode", value = "医生当前所在团队") @RequestParam(required = true) String teamCode,
                                                                                   @ApiParam(name = "page", value = "第几页,1开始") @RequestParam(required = true)Integer page,
                                                                                   @ApiParam(name = "size", value = "每页大小") @RequestParam(required = true)Integer size) {
        try {
            return specialistService.getDoctorPatientByName(doctor,nameKey,teamCode,page,size);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.getDoctorPatientByNameOrIdCard)
    @ApiOperation(value = "根据姓名或身份证号搜索专科医生居民")
    public MixEnvelop<PatientRelationVO, PatientRelationVO> getDoctorPatientByNameOrIdCard(@ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true)String doctor,
                                                                                           @ApiParam(name = "filter", value = "居民姓名模糊") @RequestParam(required = false)String filter,
                                                                                           @ApiParam(name = "teamCode", value = "医生当前所在团队") @RequestParam(required = true) String teamCode,
                                                                                           @ApiParam(name = "page", value = "第几页,1开始") @RequestParam(required = true)Integer page,
                                                                                           @ApiParam(name = "size", value = "每页大小") @RequestParam(required = true)Integer size) {
        try {
            return specialistService.getDoctorPatientByNameOrIdCard(doctor,filter,teamCode,page,size);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.findPatientNoAssistant)
    @ApiOperation(value = "获取未分配计管师居民列表")
    public MixEnvelop<PatientRelationVO, PatientRelationVO> findPatientNoAssistant(@ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true)String doctor,
                                                                                   @ApiParam(name = "page", value = "第几页,1开始") @RequestParam(required = true)Integer page,
                                                                                   @ApiParam(name = "size", value = "每页大小") @RequestParam(required = true)Integer size){
        try {
            return specialistService.findPatientNoAssistant(doctor,page,size);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.specialist.signSpecialistTeam)
    @ApiOperation(value = "提交专科医生签约")
    public MixEnvelop<SpecialistTeamVO, SpecialistTeamVO> signSpecialistTeam(@ApiParam(name = "patient", value = "居民code") @RequestParam(required = true)String patient,
                                                                             @ApiParam(name = "patientName", value = "居民姓名") @RequestParam(required = true)String patientName,
                                                                             @ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true)String doctor,
                                                                             @ApiParam(name = "doctorName", value = "医生姓名") @RequestParam(required = true)String doctorName,
                                                                             @ApiParam(name = "teamCode", value = "团队code") @RequestParam(required = true)Long teamCode) {
        try {
            return specialistService.signSpecialistTeam( patient,  patientName,  doctor,  doctorName,  teamCode);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.specialist.agreeSpecialistTeam)
    @ApiOperation(value = "专科医生审核")
    public MixEnvelop<Boolean, Boolean> agreeSpecialistTeam(@ApiParam(name = "state", value = "状态0为拒绝,1为同意") @RequestParam(required = true)String state,
                                                            @ApiParam(name = "relationCode", value = "关联code") @RequestParam(required = true)String relationCode,
                                                            @ApiParam(name = "remark", value = "审核失败原因") @RequestParam(required = false)String remark,
                                                            @ApiParam(name = "health_assistant", value = "计管医生CODE") @RequestParam(required = false)String health_assistant,
                                                            @ApiParam(name = "health_assistant_name", value = "计管医生名称") @RequestParam(required = false)String health_assistant_name) {
        try {
            return specialistService.agreeSpecialistTeam(state,relationCode,remark,health_assistant,health_assistant_name);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.findPatientSigninfo)
    @ApiOperation(value = "获取签约信息")
    public MixEnvelop<PatientSignInfoVO, PatientSignInfoVO> findPatientSigninfo(String code){
        try {
            return specialistService.findPatientSigninfo(code);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.findPatientTeamList)
    @ApiOperation(value = "获取居民所有有效签约团队信息")
    public MixEnvelop<SpecialistTeamVO, SpecialistTeamVO> findPatientTeamList(@ApiParam(name = "patient", value = "居民code") @RequestParam(required = true)String patient){
        try {
            return specialistService.findPatientTeamList(patient);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.findPatientSignSpecialist)
    @ApiOperation(value = "获取居民所有有效签约医生信息")
    public MixEnvelop findPatientSignSpecialist(@ApiParam(name = "patient", value = "居民code") @RequestParam(required = true)String patient){
        try {
            return specialistService.findPatientSignSpecialist(patient);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.findPatientSignSpecialistInfo)
    @ApiOperation(value = "获取居民与当前专科医生有效签约信息")
    public MixEnvelop findPatientSignSpecialistInfo(@ApiParam(name = "patient", value = "居民code") @RequestParam(required = true)String patient,
                                                    @ApiParam(name = "doctor", value = "专科医生code") @RequestParam(required = true)String doctor) {
        try {
            return specialistService.findPatientSignSpecialistInfo(patient,doctor);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    
    @GetMapping(value = SpecialistMapping.specialist.findDoctorAndDoctorHealthBySpecialDoctor)
    @ApiOperation(value = "获取当前专科医生有关联的家庭医生和健管师列表")
    public MixEnvelop findDoctorAndDoctorHealthBySpecialDoctor(
            @ApiParam(name = "doctor", value = "专科医生code") @RequestParam(required = true)String doctor,
            @ApiParam(name = "name", value = "家庭医生姓名") @RequestParam(required = false)String name){
        try {
            return specialistService.findDoctorAndDoctorHealthBySpecialDoctor(doctor,name);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    
    @GetMapping(value = SpecialistMapping.specialist.findSpecialistSignFamilyPatientCout)
    @ApiOperation(value = "获取专科医生家庭医生共管居民数目")
    public MixEnvelop<Long, Long> findSpecialistSignFamilyPatientCout(
            @ApiParam(name = "specialdoctor", value = "专科医生") @RequestParam(required = true)String specialdoctor,
            @ApiParam(name = "familydoctor", value = "家庭医生") @RequestParam(required = true)String familydoctor
    ){
        try {
            return specialistService.findSpecialistSignFamilyPatientCout(specialdoctor,familydoctor);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    
    @GetMapping(value = SpecialistMapping.specialist.getSpecialistSignFamilyPatientByName)
    @ApiOperation(value = "搜索专科医生家庭医生共管居民")
    public MixEnvelop<PatientRelationVO, PatientRelationVO> getSpecialistSignFamilyPatientByName(
            @ApiParam(name = "specialdoctor", value = "专科医生") @RequestParam(required = true)String specialdoctor,
            @ApiParam(name = "familydoctor", value = "家庭医生") @RequestParam(required = true)String familydoctor,
            @ApiParam(name = "nameKey", value = "居民姓名模糊") @RequestParam(required = false)String nameKey,
            @ApiParam(name = "page", value = "第几页,1开始") @RequestParam(required = true)Integer page,
            @ApiParam(name = "size", value = "每页大小") @RequestParam(required = true)Integer size) {
        try {
            return specialistService.getSpecialistSignFamilyPatientByName(specialdoctor,familydoctor,nameKey,page,size);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.getPatientAndDiseaseByDoctor)
    @ApiOperation(value = "根据医生code获取签约居民信息及签约疾病类型")
    public MixEnvelop getPatientAndDiseaseByDoctor(
            @ApiParam(name = "doctor", value = "医生code") @RequestParam(required = true)String doctor,
            @ApiParam(name = "patientInfo", value = "居民信息") @RequestParam(required = false)String patientInfo,
            @ApiParam(name = "disease", value = "疾病类型") @RequestParam(required = false)String disease,
            @ApiParam(name = "page", value = "第几页,1开始") @RequestParam(required = true)Integer page,
            @ApiParam(name = "size", value = "每页大小") @RequestParam(required = true)Integer size){
        try {
            return specialistService.getPatientAndDiseaseByDoctor(doctor, patientInfo, disease, page, size);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
//    @PostMapping(value = SpecialistMapping.specialist.createArticle)
//    @ApiOperation(value = "创建专科医生健康文章")
//    public Envelop<Boolean> createSpecialistArticle(@ApiParam(name = "specialistArticle", value = "专科医生健康文章JSON")
//                                                    @RequestParam(value = "specialistArticle", required = false)String specialistArticle){
//        try {
//            SpecialistArticleDO ps = toEntity(specialistArticle, SpecialistArticleDO.class);
//            return specialistService.createSpecialistArticle(ps);
//        }catch (Exception e){
//            e.printStackTrace();
//            // tracer.getCurrentSpan().logEvent(e.getMessage())
//            return Envelop.getError(e.getMessage());
//        }
//    }
//    @PostMapping(value = SpecialistMapping.specialist.createConsult)
//    @ApiOperation(value = "创建专科医生咨询")
//    public Envelop<Boolean> createSpscialistConsult(@ApiParam(name = "specialistConsult", value = "专科医生咨询实体JSON")
//                                                    @RequestParam(value = "specialistConsult", required = false)String specialistConsult){
//        try {
//            SpecialistConsultDO ps = toEntity(specialistConsult, SpecialistConsultDO.class);
//            return specialistService.createSpscialistConsult(ps);
//        }catch (Exception e){
//            e.printStackTrace();
//            // tracer.getCurrentSpan().logEvent(e.getMessage())
//            return Envelop.getError(e.getMessage());
//        }
//    }
//    @PostMapping(value = SpecialistMapping.specialist.createSpecialists)
//    @ApiOperation(value = "创建专科医生")
//    public Envelop<Boolean> createSpecialists(@ApiParam(name = "specialists", value = "专科医生实体")
//                                              @RequestParam(value = "code", required = false)String specialists){
//        try {
//            List<SpecialistDO> infos = new ObjectMapper().readValue(specialists, new TypeReference<List<SpecialistDO>>(){});
//            return specialistService.createSpecialists(infos);
//        }catch (Exception e){
//            e.printStackTrace();
//            // tracer.getCurrentSpan().logEvent(e.getMessage())
//            return Envelop.getError(e.getMessage());
//        }
//    }
    @GetMapping(value = SpecialistMapping.specialist.searchPatientInSpecialist)
    @ApiOperation(value = "搜索注册居民")
    public MixEnvelop searchPatientInSpecialist(
            @ApiParam(name = "doctorCode", value = "医生code",required = true) @RequestParam(required = true)String doctorCode,
            @ApiParam(name = "keywords", value = "居民姓名,手机号,身份证") @RequestParam(required = false)String keywords,
            @ApiParam(name = "page", value = "第几页,1开始",defaultValue = "1") @RequestParam(required = true,defaultValue = "1")Integer page,
            @ApiParam(name = "pageSize", value = "每页大小",defaultValue = "5") @RequestParam(required = true,defaultValue = "5")Integer pageSize){
        try {
            return specialistService.searchPatientInSpecialistNew(doctorCode,keywords,page,pageSize);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.searchPatientInSpeciaInfo)
    @ApiOperation(value = "根据病人和医生id病人的家签信息、专科开通信息")
    public ObjEnvelop<Object> searchPatientInSpecialist(
            @ApiParam(name = "doctorCode", value = "医生code",required = true)
            @RequestParam(value = "doctorCode",required = true)String doctorCode,
            @ApiParam(name = "signStatus", value = "签约状态,待审核:0;未签约:-1",required = true)
            @RequestParam(value = "signStatus",required = true)String signStatus,
            @ApiParam(name = "patientCode", value = "居民id",required = true)
            @RequestParam(value = "patientCode",required = true)String patientCode){
        try {
            JSONObject object=specialistService.doctorForSpecialistInfoNew(signStatus,doctorCode,patientCode);
            return  success(object);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.specialist.createPatientInSpeciaRelation)
    @ApiOperation(value = "专科医生发起签约")
    public ObjEnvelop<SpecialistPatientRelationDO> createPatientInSpeciaRelation(
            @ApiParam(name = "jsonData", value = "签约关系json")
            @RequestParam(value = "jsonData") String jsonData) {
        try {
            SpecialistPatientRelationDO specialistPatientRelationDO=toEntity(jsonData, SpecialistPatientRelationDO.class);
            if(StringUtils.isBlank(specialistPatientRelationDO.getPatient())){
                return failed("病人编码不能为空!", ObjEnvelop.class);
            }
            if(StringUtils.isBlank(specialistPatientRelationDO.getPatientName())){
                return failed("病人姓名不能为空!", ObjEnvelop.class);
            }
//            if(StringUtils.isBlank(specialistPatientRelationDO.getDoctor())){
//                return failed("医生编码不能为空!",ObjEnvelop.class);
//            }
//            if(StringUtils.isBlank(specialistPatientRelationDO.getDoctorName())){
//                return failed("医生姓名不能为空!",ObjEnvelop.class);
//            }
            if(null==specialistPatientRelationDO.getTeamCode()){
                return failed("医生团队不能为空!", ObjEnvelop.class);
            }
//            specialistPatientRelationDO.setDoctor(getUID());
//            specialistPatientRelationDO.setDoctorName(getUNAME());
            List<SpecialistPatientRelationDO> list = specialistPatientRelationDao.findListByTeamAndPatient(specialistPatientRelationDO.getTeamCode(),specialistPatientRelationDO.getPatient());
            if (list.size()>0){
                return ObjEnvelop.getSuccess("success", list.get(0));
            }
            return specialistService.createPatientInSpeciaRelation(specialistPatientRelationDO);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = "/redisFindPatientTeamList")
    @ApiOperation(value = "text-redis获取居民所有有效签约团队信息")
    public ObjEnvelop<Boolean> redisFindPatientTeamList(@ApiParam(name = "patient", value = "居民code") @RequestParam(required = true)String patient){
        try {
            String key = "specialist_patient_relation:" +patient +"_"+ ":text";
            return success(redisTemplate.opsForValue().get(key)==null?false:true);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return failed(e.getMessage(), ObjEnvelop.class);
        }
    }
    @GetMapping(value = SpecialistMapping.specialist.updateRedisFindPatientTeamList)
    @ApiOperation(value = "更新-redis获取居民所有有效签约团队信息")
    public ObjEnvelop<Integer> updateRedisFindPatientTeamList(){
        try {
            return success(specialistService.updateRedisFindPatientTeamList());
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return failed(e.getMessage(), ObjEnvelop.class);
        }
    }
    /**
     * 根据共管医生和居民code查询专科签约信息
     * @param patient
     * @param doctor
     * @return
     */
    @GetMapping(value = SpecialistMapping.specialist.selectByAssistant)
    @ApiOperation(value = "根据共管医生和居民code查询专科签约信息")
    public MixEnvelop<SpecialistPatientRelationDO, SpecialistPatientRelationDO> selectByAssistant(
            @ApiParam(name = "patient", value = "居民code") @RequestParam(required = true)String patient,
            @ApiParam(name = "doctor", value = "共管医生code") @RequestParam(required = true)String doctor){
        try {
            MixEnvelop envelop = new MixEnvelop();
            envelop.setDetailModelList(specialistService.selectByAssistant(patient,doctor));
            return envelop;
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = SpecialistMapping.specialist.updatePatientSignSpecialistInfo)
    @ApiOperation(value = "更新居民专科医生有效签约信息")
    public Envelop updatePatientSignSpecialistInfo(@ApiParam(name = "patient", value = "居民code") @RequestParam(required = true)String patient,
                                                   @ApiParam(name = "doctor", value = "专科医生code") @RequestParam(required = true)String doctor,
                                                   @ApiParam(name = "doctorName", value = "专科医生姓名") @RequestParam(required = true)String doctorName) {
        try {
            return specialistService.updatePatientSignSpecialistInfo(patient,doctor, doctorName);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value="/transferPatients")
    @ApiOperation(value = "专科端转移居民")
    public Envelop transferPatients(@ApiParam(name="teamCode",value = "医生所在团队",required = true)@RequestParam(value = "teamCode",required = true) String teamCode,
                                    @ApiParam(name="toTeamCode",value = "转移医生医生所在所在团队,跨团队时必传",required = true)@RequestParam(value = "toTeamCode",required = false) String toTeamCode,
                                    @ApiParam(name="doctorCode",value = "当前医生code",required = true)@RequestParam(value = "doctorCode",required = true)String doctorCode,
                                    @ApiParam(name="toDoctorCode",value = "接收患者医生code",required = true)@RequestParam(value = "toDoctorCode",required = true)String toDoctorCode,
                                    @ApiParam(name="patients",value = "患者JsonArray列表(包含code)",required = true)@RequestParam(value = "patients",required = true)String patients){
        try {
            return MixEnvelop.getSuccess(SpecialistMapping.api_success,specialistService.transferPatients(teamCode,toTeamCode,doctorCode, toDoctorCode, patients));
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return Envelop.getError(e.getMessage());
        }
    }
}

+ 0 - 126
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistEvaluateController.java

@ -1,126 +0,0 @@
package com.yihu.jw.base.endpoint.specialist;/**
 * Created by nature of king on 2018/8/27.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.service.specialist.SpecialistEvaluateService;
import com.yihu.jw.entity.specialist.SpecialistEvaluateDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.specialist.SpecialistMapping;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-08-27 14:17
 * @desc 评论
 **/
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "评价相关操作", description = "评价相关操作")
public class SpecialistEvaluateController extends EnvelopRestEndpoint {
//    @Autowired
//    private Tracer tracer;
    @Autowired
    private SpecialistEvaluateService specialistEvaluateService;
    /**
     * 添加评价
     *
     * @param evaluate
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.createEvaluate)
    @ApiOperation(value = "添加评论")
    public MixEnvelop<SpecialistEvaluateDO, SpecialistEvaluateDO> create(@ApiParam(name = "evaluate", value = "评价")
                                                                           @RequestParam(value = "evaluate")String evaluate){
        try {
            JSONObject object = JSONObject.parseObject(evaluate);
            return specialistEvaluateService.createEvaluate(object);
        }catch (Exception e){
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 获取评论
     *
     * @param evaluate
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.getEvaluate)
    @ApiOperation(value = "获取评论")
    public MixEnvelop<JSONObject,JSONObject> select(@ApiParam(name = "evaluate", value = "评价")
                                                                        @RequestParam(value = "evaluate")String evaluate){
        try {
            SpecialistEvaluateDO specialistEvaluateDO = toEntity(evaluate, SpecialistEvaluateDO.class);
            return specialistEvaluateService.selectByCondition(specialistEvaluateDO);
        }catch (Exception e){
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 更新评价
     *
     * @param evaluate
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.updateEvaluate)
    @ApiOperation(value = "更新评价")
    public MixEnvelop<Boolean,Boolean> update(@ApiParam(name = "evaluate", value = "评价")
                                                                        @RequestParam(value = "evaluate")String evaluate){
        try {
            JSONArray array = JSONArray.parseArray(evaluate);
            List<SpecialistEvaluateDO> specialistEvaluateDOS = new ArrayList<>();
            for (int i = 0;i<array.size();i++){
                SpecialistEvaluateDO specialistEvaluateDO = toEntity(array.getString(i), SpecialistEvaluateDO.class);
                specialistEvaluateDOS.add(specialistEvaluateDO);
            }
            return specialistEvaluateService.update(specialistEvaluateDOS);
        }catch (Exception e){
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 医生获取评分
     *
     * @param doctor
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.selectByDoctor)
    @ApiOperation(value = "医生获取评分")
    public MixEnvelop<JSONObject,JSONObject> selectByDoctor(@ApiParam(name = "doctor", value = "评价")
                                                    @RequestParam(value = "doctor")String doctor){
        try {
            return specialistEvaluateService.selectByDoctor(doctor);
        }catch (Exception e){
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 0 - 247
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistHospitalServiceItemController.java

@ -1,247 +0,0 @@
package com.yihu.jw.base.endpoint.specialist;/**
 * Created by nature of king on 2018/8/29.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.service.specialist.SpecialistHospitalServiceItemService;
import com.yihu.jw.entity.specialist.HospitalServiceItemDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.util.common.DataUtils;
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.*;
import java.util.ArrayList;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-08-29 0:56
 * @desc
 **/
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "机构服务项目相关操作", description = "机构服务项目相关操作")
public class SpecialistHospitalServiceItemController extends EnvelopRestEndpoint {
//    @Autowired
//    private Tracer tracer;
    @Autowired
    private SpecialistHospitalServiceItemService specialistHospitalServiceItemService;
    /**
     * 添加机构服务项目
     * @param hospitalServiceItem
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.createHospitalServiceItem)
    @ApiOperation(value = "添加机构服务项目")
    public MixEnvelop<HospitalServiceItemDO, HospitalServiceItemDO> create(@ApiParam(name = "hospitalServiceItem", value = "机构服务项目")
                                                                        @RequestParam(value = "hospitalServiceItem")String hospitalServiceItem){
        try {
            JSONArray array = JSONArray.parseArray(hospitalServiceItem);
            List<HospitalServiceItemDO> hospitalServiceItemDOS = new ArrayList<>();
            for (int i =0 ; i<array.size();i++){
                JSONObject object = array.getJSONObject(i);
                object.replace("expense", DataUtils.doubleToInt(object.getDouble("expense")));
                HospitalServiceItemDO hospitalServiceItemDO = toEntity(object.toJSONString(), HospitalServiceItemDO.class);
                hospitalServiceItemDOS.add(hospitalServiceItemDO);
            }
            return specialistHospitalServiceItemService.insert(hospitalServiceItemDOS);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 根据医院Code查找机构服务项目
     *
     * @param hospitals
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.selectByHospital)
    @ApiOperation(value = "根据医院Code查找机构服务项目")
    public MixEnvelop<HospitalServiceItemDO, HospitalServiceItemDO> selectByHospital(@ApiParam(name = "hospitals", value = "医院code集合")
                                                                          @RequestParam(value = "hospitals",required = false)String hospitals){
        try {
            JSONArray array = JSONArray.parseArray(hospitals);
            List<String> hospitalList = new ArrayList<>();
            if (array != null || array.size()!=0){
                for (int i =0 ;i<array.size();i++){
                    hospitalList.add(array.getString(i));
                }
            }
            MixEnvelop envelop = specialistHospitalServiceItemService.selectByHospital(hospitalList);
            List<HospitalServiceItemDO> hospitalServiceItemDOList = envelop.getDetailModelList();
            JSONArray array1 = new JSONArray();
            if (hospitalServiceItemDOList != null && hospitalServiceItemDOList.size()!=0){
                for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOList){
                    JSONObject object = (JSONObject) JSONObject.toJSON(hospitalServiceItemDO);
                    object.replace("expense", DataUtils.integerTransferDouble(hospitalServiceItemDO.getExpense()));
                    JSONObject jsonObject = object.getJSONObject("specialistServiceItemDO");
                    jsonObject.replace("threeHospitals", DataUtils.integerTransferDouble(hospitalServiceItemDO.getSpecialistServiceItemDO().getThreeHospitals()));
                    jsonObject.replace("twoHospitals",DataUtils.integerTransferDouble(hospitalServiceItemDO.getSpecialistServiceItemDO().getTwoHospitals()));
                    jsonObject.replace("oneHospitals",DataUtils.integerTransferDouble(hospitalServiceItemDO.getSpecialistServiceItemDO().getOneHospitals()));
                    array1.add(object);
                }
            }
            envelop.setDetailModelList(array1);
            return envelop;
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 根据id查找机构服务项目
     *
     * @param ids
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.selectById)
    @ApiOperation(value = "根据id查找机构服务项目")
    public MixEnvelop<HospitalServiceItemDO, HospitalServiceItemDO> selectById(@ApiParam(name = "ids", value = "机构服务项目集合")
                                                                                    @RequestParam(value = "ids")String ids){
        try {
            JSONArray array = JSONArray.parseArray(ids);
            List<String> idList = new ArrayList<>();
            for (int i =0 ;i<array.size();i++){
                idList.add(array.getString(i));
            }
            MixEnvelop envelop = specialistHospitalServiceItemService.selectById(idList);
            List<HospitalServiceItemDO> hospitalServiceItemDOList = envelop.getDetailModelList();
            JSONArray array1 = new JSONArray();
            if (hospitalServiceItemDOList != null && hospitalServiceItemDOList.size()!=0){
                for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOList){
                    JSONObject object = (JSONObject) JSONObject.toJSON(hospitalServiceItemDO);
                    object.replace("expense", DataUtils.integerTransferDouble(hospitalServiceItemDO.getExpense()));
                    JSONObject jsonObject = object.getJSONObject("specialistServiceItemDO");
                    jsonObject.replace("threeHospitals", DataUtils.integerTransferDouble(hospitalServiceItemDO.getSpecialistServiceItemDO().getThreeHospitals()));
                    jsonObject.replace("twoHospitals",DataUtils.integerTransferDouble(hospitalServiceItemDO.getSpecialistServiceItemDO().getTwoHospitals()));
                    jsonObject.replace("oneHospitals",DataUtils.integerTransferDouble(hospitalServiceItemDO.getSpecialistServiceItemDO().getOneHospitals()));
                    array1.add(object);
                }
            }
            envelop.setDetailModelList(array1);
            return envelop;
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     *
     * @param serviceItemName
     * @param hospitals
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.selectByCondition)
    @ApiOperation(value = "根据条件查找机构服务项目")
    public MixEnvelop<JSONArray,JSONArray> selectByCondition(@ApiParam(name = "serviceItemName", value = "服务项目名称")
                                                                                    @RequestParam(value = "serviceItemName",required = false)String serviceItemName,
                                                             @ApiParam(name = "hospitals",value = "医院集合")
                                                                                     @RequestParam(value = "hospitals",required = false)String hospitals){
        try {
            JSONArray array = JSONArray.parseArray(hospitals);
            List<String> hospitalList = new ArrayList<>();
            for (int i =0 ;i<array.size();i++){
                hospitalList.add(array.getString(i));
            }
            return specialistHospitalServiceItemService.selectByCondition(serviceItemName,hospitalList);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     *
     * @param hospital
     * @param serviceItem
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.deleteHospitalItem)
    @ApiOperation(value = "删除机构服务项目")
    public MixEnvelop<Boolean,Boolean> delete(@ApiParam(name = "hospital", value = "医院code")
                                              @RequestParam(name = "hospital",required = false)String hospital,
                                              @ApiParam(name = "serviceItem", value = "服务项目code")
                                              @RequestParam(name = "serviceItem",required = false)String serviceItem,
                                              @ApiParam(name = "id", value = "机构服务项目id")
                                                  @RequestParam(name = "id",required = false)String id){
        try {
            return specialistHospitalServiceItemService.delete(hospital,serviceItem,id);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     *
     * @param hospital
     * @param docHospital
     * @param serviceItemName
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.selectByHospital1)
    @ApiOperation(value = "查询服务项目")
    public MixEnvelop<JSONArray,JSONArray> selectByHospital1(@ApiParam(name = "hospital", value ="社区code")
                                              @RequestParam(name = "hospital",required = false)String hospital,
                                                             @ApiParam(name = "docHospital", value = "医院code")
                                              @RequestParam(name = "docHospital")String docHospital,
                                                             @ApiParam(name = "serviceItemName", value = "服务项目名称")
                                              @RequestParam(name = "serviceItemName",required = false)String serviceItemName){
        try {
            return  specialistHospitalServiceItemService.selectByHospital1(hospital,docHospital,serviceItemName);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 机构服务项目导数据
     *
     * @param hospitalItems
     * @return
     */
    @RequestMapping(value = SpecialistMapping.serviceItem.importData2)
    @ResponseBody
    public MixEnvelop<Boolean,Boolean> importData(@ApiParam(name = "hospitalItems", value = "机构服务项目集合")
                                                  @RequestParam(value = "hospitalItems")String hospitalItems) {
        try {
            JSONArray array = JSONArray.parseArray(hospitalItems);
            List<HospitalServiceItemDO> hospitalServiceItemDOList = new ArrayList<>();
            for (int i = 0;i<array.size();i++){
                JSONObject object = array.getJSONObject(i);
                object.replace("expense", DataUtils.doubleToInt(object.getDouble("expense")));
                HospitalServiceItemDO hospitalServiceItemDO = toEntity(object.toJSONString(), HospitalServiceItemDO.class);
                hospitalServiceItemDOList.add(hospitalServiceItemDO);
            }
            return specialistHospitalServiceItemService.importData(hospitalServiceItemDOList);
        } catch (Exception e) {
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 0 - 83
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistScreenResultController.java

@ -1,83 +0,0 @@
package com.yihu.jw.base.endpoint.specialist;
import com.yihu.jw.base.service.specialist.SpecialistScreenResultService;
import com.yihu.jw.base.service.specialist.SpecialistService;
import com.yihu.jw.restmodel.specialist.SurveyScreenResultVo;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.specialist.SpecialistMapping;
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 java.util.Map;
/**
 * Created by zhangdan on 2018/7/6.
 */
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "专科医生疾病筛查相关操作", description = "专科医生疾病筛查相关操作")
public class SpecialistScreenResultController extends EnvelopRestEndpoint {
    @Autowired
    private SpecialistService specialistService;
//    @Autowired
//    private Tracer tracer;
    @Autowired
    private SpecialistScreenResultService specialistScreenResultService;
    @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,
                                                                                                  @ApiParam(value = "搜索居民的姓名或身份证") @RequestParam(value = "patientName", required = false) String patientName,
                                                                                                  @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){
        try {
            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());
        }
    }
    @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){
        try {
            return specialistScreenResultService.getResultCount(doctor);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.screen.getScreenResultDetail)
    @ApiOperation(value = "查看筛查结果记录详情.")
    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){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 0 - 237
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistServiceItemController.java

@ -1,237 +0,0 @@
package com.yihu.jw.base.endpoint.specialist;/**
 * Created by nature of king on 2018/8/17.
 */
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.service.specialist.SpecialistServiceItemService;
import com.yihu.jw.entity.specialist.SpecialistEvaluateDO;
import com.yihu.jw.entity.specialist.SpecialistServiceItemDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.util.common.DataUtils;
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.*;
import java.util.ArrayList;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-08-17 9:33
 * @desc 服务项目
 **/
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "服务项目相关操作", description = "服务项目相关操作")
public class SpecialistServiceItemController extends EnvelopRestEndpoint {
//    @Autowired
//    private Tracer tracer;
    @Autowired
    private SpecialistServiceItemService specialistServiceItemService;
    /**
     * 服务项目列表查询
     *
     * @param serviceItem
     * @param page
     * @param pageSize
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.getServiceItem)
    @ApiOperation(value = "服务项目列表查询")
    public MixEnvelop<SpecialistServiceItemDO, SpecialistEvaluateDO> select(@ApiParam(name = "serviceItem", value = "服务项目JSON")
                                                       @RequestParam(value = "serviceItem")String serviceItem,
                                                                            @ApiParam(value = "当前页",name = "page")
                                                   @RequestParam(value = "page",defaultValue = "1") Integer page,
                                                                            @ApiParam(value = "显示记录数",name = "pageSize",defaultValue = "10")
                                                       @RequestParam(value = "pageSize") Integer pageSize){
        try {
            SpecialistServiceItemDO serviceItemDO = toEntity(serviceItem, SpecialistServiceItemDO.class);
            MixEnvelop envelop = specialistServiceItemService.select(serviceItemDO,page,pageSize);
            JSONArray array = new JSONArray();
            List<SpecialistServiceItemDO> specialistServiceItemDOS =  envelop.getDetailModelList();
            if (specialistServiceItemDOS != null && specialistServiceItemDOS.size()!=0){
                for (SpecialistServiceItemDO specialistServiceItemDO:specialistServiceItemDOS){
                    JSONObject jsonObject = (JSONObject)JSONObject.toJSON(specialistServiceItemDO);
                    jsonObject.replace("threeHospitals", DataUtils.integerTransferDouble(specialistServiceItemDO.getThreeHospitals()));
                    jsonObject.replace("twoHospitals",DataUtils.integerTransferDouble(specialistServiceItemDO.getTwoHospitals()));
                    jsonObject.replace("oneHospitals",DataUtils.integerTransferDouble(specialistServiceItemDO.getOneHospitals()));
                    array.add(jsonObject);
                }
            }
            envelop.setDetailModelList(array);
            return envelop;
        }catch (Exception e){
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 服务项目添加
     *
     * @param serviceItem
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.createServiceItem)
    @ApiOperation(value = "服务项目添加")
    public MixEnvelop<Boolean,Boolean> insert(@ApiParam(name = "serviceItem", value = "服务项目JSON")
                                                       @RequestParam(value = "serviceItem")String serviceItem){
        try {
            JSONObject object = JSON.parseObject(serviceItem);
            if (object.getDouble("threeHospitals")!=null){
                object.replace("threeHospitals", DataUtils.doubleToInt(object.getDouble("threeHospitals")));
            }
            if (object.getDouble("twoHospitals")!=null){
                object.replace("twoHospitals",DataUtils.doubleToInt(object.getDouble("twoHospitals")));
            }
            if (object.getDouble("oneHospitals")!=null){
                object.replace("oneHospitals",DataUtils.doubleToInt(object.getDouble("oneHospitals")));
            }
            SpecialistServiceItemDO serviceItemDO = toEntity(object.toJSONString(), SpecialistServiceItemDO.class);
            return specialistServiceItemService.insert(serviceItemDO);
        }catch (Exception e){
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 批量删除服务项目
     * @param ids
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.batchDelete)
    @ApiOperation(value = "批量删除服务项目")
    public MixEnvelop<Boolean,Boolean> batchDelete(@ApiParam(name="ids",value = "id集合")
                                        @RequestParam(value = "ids",required = false)String ids){
        try{
            MixEnvelop<Boolean,Boolean> envelop = new MixEnvelop<>();
            JSONArray array = JSONArray.parseArray(ids);
            List<String> itemIds = new ArrayList<>();
            for (int i = 0;i<array.size();i++){
                itemIds.add(array.getString(i));
            }
            specialistServiceItemService.batchDelete(itemIds);
            envelop.setObj(true);
            return envelop;
        }catch (Exception e){
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 更新服务项目
     *
     * @param serviceItem
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.updateServiceItem)
    @ApiOperation(value = "服务项目更新")
    public MixEnvelop<Boolean,Boolean> udpate(@ApiParam(name = "serviceItem", value = "服务项目JSON")
                                              @RequestParam(value = "serviceItem")String serviceItem){
        try {
            JSONObject object = JSON.parseObject(serviceItem);
            if (object.getDouble("threeHospitals")!=null){
                object.replace("threeHospitals", DataUtils.doubleToInt(object.getDouble("threeHospitals")));
            }
            if (object.getDouble("twoHospitals")!=null){
                object.replace("twoHospitals",DataUtils.doubleToInt(object.getDouble("twoHospitals")));
            }
            if (object.getDouble("oneHospitals")!=null){
                object.replace("oneHospitals",DataUtils.doubleToInt(object.getDouble("oneHospitals")));
            }
            SpecialistServiceItemDO serviceItemDO = toEntity(object.toJSONString(), SpecialistServiceItemDO.class);
            return specialistServiceItemService.update(serviceItemDO);
        }catch (Exception e){
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 根据医院code获取服务项目
     *
     * @param hospital
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.selectItemByHospital)
    @ApiOperation(value = "根据医院code获取服务项目")
    public MixEnvelop selectByHospital(@ApiParam(name = "hospital", value = "医院code")
                                              @RequestParam(value = "hospital")String hospital){
        try {
            MixEnvelop envelop = specialistServiceItemService.selectByHospital(hospital);
            JSONArray array = new JSONArray();
            List<SpecialistServiceItemDO> specialistServiceItemDOS =  envelop.getDetailModelList();
            if (specialistServiceItemDOS != null && specialistServiceItemDOS.size()!=0){
                for (SpecialistServiceItemDO specialistServiceItemDO:specialistServiceItemDOS){
                    JSONObject jsonObject = (JSONObject)JSONObject.toJSON(specialistServiceItemDO);
                    jsonObject.replace("threeHospitals", DataUtils.integerTransferDouble(specialistServiceItemDO.getThreeHospitals()));
                    jsonObject.replace("twoHospitals",DataUtils.integerTransferDouble(specialistServiceItemDO.getTwoHospitals()));
                    jsonObject.replace("oneHospitals",DataUtils.integerTransferDouble(specialistServiceItemDO.getOneHospitals()));
                    array.add(jsonObject);
                }
            }
            envelop.setDetailModelList(array);
            return envelop;
        }catch (Exception e){
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 导数据
     *
     * @return
     */
    @RequestMapping(value = "importData1")
    @ResponseBody
    public MixEnvelop<Boolean,Boolean> importData(@ApiParam(name = "serviceItems", value = "服务项目集合")
                                                      @RequestParam(value = "serviceItems")String serviceItems) {
        try {
            JSONArray array = JSONArray.parseArray(serviceItems);
            List<SpecialistServiceItemDO> specialistServiceItemDOS = new ArrayList<>();
            for (int i = 0;i<array.size();i++){
                JSONObject object = array.getJSONObject(i);
                if (object.getDouble("threeHospitals")!=null){
                    object.replace("threeHospitals", DataUtils.doubleToInt(object.getDouble("threeHospitals")));
                }
                if (object.getDouble("twoHospitals")!=null){
                    object.replace("twoHospitals",DataUtils.doubleToInt(object.getDouble("twoHospitals")));
                }
                if (object.getDouble("oneHospitals")!=null){
                    object.replace("oneHospitals",DataUtils.doubleToInt(object.getDouble("oneHospitals")));
                }
                SpecialistServiceItemDO specialistServiceItemDO = toEntity(object.toJSONString(), SpecialistServiceItemDO.class);
                specialistServiceItemDOS.add(specialistServiceItemDO);
            }
            return specialistServiceItemService.importData(specialistServiceItemDOS);
        } catch (Exception e) {
            e.printStackTrace();
           // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 0 - 63
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/SpecialistServiceItemOperateLogController.java

@ -1,63 +0,0 @@
package com.yihu.jw.base.endpoint.specialist;/**
 * Created by nature of king on 2018/9/1.
 */
import com.yihu.jw.base.service.specialist.SpecialistServiceItemOperateLogService;
import com.yihu.jw.entity.specialist.SpecialistServiceItemOperateLogDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.specialist.SpecialistMapping;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author wangzhinan
 * @create 2018-09-01 15:15
 * @desc 操作记录
 **/
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "服务项目操作记录相关操作", description = "服务项目操作记录相关操作")
public class SpecialistServiceItemOperateLogController extends EnvelopRestEndpoint {
//    @Autowired
//    private Tracer tracer;
    @Autowired
    private SpecialistServiceItemOperateLogService specialistServiceItemOperateLogService;
    /**
     * 查找服务项目操作记录
     *
     * @param operateLog
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.selectByOperate)
    @ApiOperation(value = "服务项目操作记录查询")
    public MixEnvelop<SpecialistServiceItemOperateLogDO, SpecialistServiceItemOperateLogDO> select(@ApiParam(name = "operateLog", value = "操作记录JSON")
                                                                           @RequestParam(value = "operateLog")String operateLog,
                                                                                                   @ApiParam(value = "当前页",name = "page")
                                                                           @RequestParam(value = "page",defaultValue = "1") Integer page,
                                                                                                   @ApiParam(value = "显示记录数",name = "size",defaultValue = "10")
                                                                           @RequestParam(value = "size") Integer size){
        try {
            SpecialistServiceItemOperateLogDO specialistServiceItemOperateLogDO = toEntity(operateLog, SpecialistServiceItemOperateLogDO.class);
            return specialistServiceItemOperateLogService.select(specialistServiceItemOperateLogDO,page,size);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 0 - 78
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/rehabilitation/DiagnosisInformationController.java

@ -1,78 +0,0 @@
package com.yihu.jw.base.endpoint.specialist.rehabilitation;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.service.specialist.rehabilitation.DiagnosisInformationService;
import com.yihu.jw.entity.specialist.rehabilitation.PatientDiagnosisInformationDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.specialist.SpecialistMapping;
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.*;
import java.text.SimpleDateFormat;
/**
 * Created by humingfen on 2019/2/11.
 */
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "诊疗信息管理相关操作", description = "诊疗信息相关操作")
public class DiagnosisInformationController extends EnvelopRestEndpoint {
    @Autowired
    private DiagnosisInformationService diagnosisInformationService;
//    @Autowired
//    private Tracer tracer;
    @PostMapping(value = SpecialistMapping.diagnosisInformation.createDiagnosisInformation)
    @ApiOperation(value = "诊疗信息创建")
    public Envelop createDiagnosisInformation(@ApiParam(name = "diagnosisInformationJson", value = "实体JSON")
                                                       @RequestParam(value = "diagnosisInformationJson")String diagnosisInformationJson){
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
            PatientDiagnosisInformationDO diagnosisInformationDO = objectMapper.readValue(diagnosisInformationJson, PatientDiagnosisInformationDO.class);
            return diagnosisInformationService.createDiagnosisInformation(diagnosisInformationDO);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.diagnosisInformation.findDiagnosisInformationByPlanId)
    @ApiOperation(value = "根据康复计划id查找诊疗信息")
    public Envelop findDiagnosisInformationByPlanId(@ApiParam(name = "planId", value = "康复计划id")
                                              @RequestParam(value = "planId") String planId){
        try {
            return diagnosisInformationService.findDiagnosisInformationByPlanId(planId);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.diagnosisInformation.findDiagnosisInformationByPatient)
    @ApiOperation(value = "查找居民诊疗信息记录")
    public Envelop findDiagnosisInformationByPatient(@ApiParam(name = "patient", value = "居民code")
                                                    @RequestParam(value = "patient") String patient,
                                                     @ApiParam(name = "page", value = "第几页")
                                                     @RequestParam(value = "page") Integer page,
                                                     @ApiParam(name = "size", value = "行数")
                                                         @RequestParam(value = "size") Integer size){
        try {
            return diagnosisInformationService.findDiagnosisInformationByPatient(patient, page, size);
        }catch (Exception e){
            e.printStackTrace();
            // tracer.getCurrentSpan().logEvent(e.getMessage())
            return ObjEnvelop.getError(e.getMessage());
        }
    }
}

+ 0 - 511
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/rehabilitation/RehabilitationManageController.java

@ -1,511 +0,0 @@
package com.yihu.jw.base.endpoint.specialist.rehabilitation;
import com.yihu.jw.base.dao.specialist.rehabilitation.RehabilitationOperateRecordsDao;
import com.yihu.jw.base.service.specialist.rehabilitation.RehabilitationManageService;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationOperateRecordsDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.util.date.DateUtil;
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.cloud.sleuth.Tracer;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.Map;
/**
 * Created by 刘文彬 on 2018/8/16.
 */
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "康复计划管理相关操作", description = "康复计划管理相关操作")
public class RehabilitationManageController {
    @Autowired
    private RehabilitationManageService rehabilitationManageService;
//    @Autowired
//    private Tracer tracer;
    @Autowired
    private RehabilitationOperateRecordsDao rehabilitationOperateRecordsDao;
    @GetMapping(value = SpecialistMapping.rehabilitation.findRehabilitationPlanList)
    @ApiOperation(value = "康复管理-康复计划列表")
    public MixEnvelop findRehabilitationPlan(@ApiParam(name = "doctorType", value = "医生类型(1、专科医生,2、家庭医生)", required = true)
                                             @RequestParam(value = "doctorType", required = true)Integer doctorType,
                                             @ApiParam(name = "doctorCode", value = "医生code", required = true)
                                             @RequestParam(value = "doctorCode", required = true)String doctorCode,
                                             @ApiParam(name = "patientCondition", value = "居民条件,可以按身份证或者居民名称模糊匹配", required = false)
                                             @RequestParam(value = "patientCondition", required = false)String patientCondition,
                                             @ApiParam(name = "diseaseCode", value = "疾病类型code", required = false)
                                             @RequestParam(value = "diseaseCode", required = false)String diseaseCode,
                                             @ApiParam(name = "planType", value = "安排类型(1康复计划,2转社区医院,3转家庭病床)", required = false)
                                             @RequestParam(value = "planType", required = false)Integer planType,
                                             @ApiParam(name = "todaybacklog", value = "今日待办(1、今日待办,2、全部)", required = false)
                                             @RequestParam(value = "todaybacklog", required = false,defaultValue = "1")Integer todaybacklog,
                                             @ApiParam(name = "page", value = "第几页,从1开始", required = false)
                                             @RequestParam(value = "page", required = false,defaultValue = "1")Integer page,
                                             @ApiParam(name = "pageSize", value = "每页分页大小", required = false)
                                             @RequestParam(value = "pageSize", required = false,defaultValue = "10")Integer pageSize){
        try {
            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());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.findRehabilitationPlanDetailList)
    @ApiOperation(value = "康复管理-康复计划详情列表")
    public ObjEnvelop findRehabilitationPlanDetailList(@ApiParam(name = "doctorCode", value = "医生code", required = true)
                                                       @RequestParam(value = "doctorCode", required = true)String doctorCode,
                                                       @ApiParam(name = "patientCode", value = "居民code", required = true)
                                                       @RequestParam(value = "patientCode", required = true)String patientCode){
        try {
            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){
        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){
        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){
        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){
        try {
            return rehabilitationManageService.serviceItem(planDetailId,doctorCode,recordId);
        }catch (Exception e){
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @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){
        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){
        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());
        }
    }
    @PostMapping(value = SpecialistMapping.rehabilitation.updateStatusRehabilitationOperate)
    @ApiOperation(value = "康复管理-更新康复计划操作完成日志状态")
    public Envelop updateStatusRehabilitationOperate(@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.updateStatusRehabilitationOperate(status,planDetailId);
        }catch (Exception e){
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
    @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){
        try {
            return rehabilitationManageService.patientRehabilitationDetail(patientCode,healthDoctor, healthDoctorName,generalDoctor,generalDoctorName);
        }catch (Exception e){
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
    @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){
        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){
        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){
        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){
        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){
        try {
            return rehabilitationManageService.tomorrowJob(startTime,endTime);
        }catch (Exception e){
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @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){
        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){
        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());
        }
    }
    @PostMapping(value = "planDetailAfterCall")
    @ApiOperation(value = "康复管理-电话关怀拨打后生成记录对应怪坏记录")
    public MixEnvelop<RehabilitationOperateRecordsDO, RehabilitationOperateRecordsDO> planDetailAfterCall(
            @ApiParam(name = "dataJson", value = "实体json",defaultValue = "{\"rehabilitationDetailId\":\"808080eb764ba46b017669712c640012\",\"doctorCode\":\"7e06886207e843948ae65d8f91d6ca97\",\"doctorName\":\"兰冠勇\"}")
            @RequestParam(value = "dataJson", required = true)String dataJson){
        try {
            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){
        try {
            return rehabilitationManageService.updatePlanDetailStatusById(status,planDetailId);
        }catch (Exception e){
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
    @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){
        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());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.planSchedule)
    @ApiOperation(value = "康复管理-计划总进度")
    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());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.planListByPatient)
    @ApiOperation(value = "康复管理-根据居民获取康复计划")
    public ObjEnvelop planListByPatient(@ApiParam(name = "patientCode", value = "居民code", required = true)
                                   @RequestParam(value = "patientCode", required = true)String patientCode){
        try {
            return rehabilitationManageService.planListByPatient(patientCode);
        }catch (Exception e){
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = SpecialistMapping.rehabilitation.patientCount)
    @ApiOperation(value = "医生已计划数,已完成计划数(居民数)")
    public ObjEnvelop patientCount(@ApiParam(name = "doctorCode", value = "医生code", required = true)
                               @RequestParam(value = "doctorCode", required = true)String doctorCode){
        try {
            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){
        try {
            return rehabilitationManageService.dailyJobReserve(startTime,endTime);
        }catch (Exception e){
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 查询康复服务项目
     * @param ids
     * @return
     */
    @PostMapping(value = SpecialistMapping.rehabilitation.selectByIds)
    @ApiOperation(value = "查询康复服务项目")
    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());
        }
    }
    @GetMapping(value = SpecialistMapping.serviceItem.getServiceItemsAfterStop)
    @ApiOperation(value = "康复管理-中止康复计划结算项目清单")
    public ObjEnvelop getServiceItemsAfterStop(@ApiParam(name = "planId", value = "康复计划id", required = true)
                                  @RequestParam(value = "planId", required = true)String planId){
        try {
            return rehabilitationManageService.getServiceItemsAfterStop(planId);
        }catch (Exception e){
            e.printStackTrace();
            //tracer.getCurrentSpan().logEvent(e.getMessage());
            return ObjEnvelop.getError(e.getMessage());
        }
    }
}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 653
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/specialist/rehabilitation/RehabilitationPlanController.java


+ 0 - 17
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/FileUploadService.java

@ -1,17 +0,0 @@
//package com.yihu.jw.base.service.specialist;
//
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Service;
//
///**
// * @author zhangdan on 2018/08/22.
// */
//@Service
//public class FileUploadService{
//
//    @Value("${neiwang.wlyy}")
//    private String neiwangWlyy;  //内网的项目地址
//
//
//
//}

+ 0 - 414
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistEvaluateService.java

@ -1,414 +0,0 @@
package com.yihu.jw.base.service.specialist;/**
 * Created by nature of king on 2018/8/22.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.dao.specialist.SpecialistEvaluateDao;
import com.yihu.jw.base.dao.specialist.SpecialistEvaluateLabelDao;
import com.yihu.jw.base.dao.specialist.SpecialistEvaluateScoreDao;
import com.yihu.jw.base.util.ISqlUtils;
import com.yihu.jw.entity.specialist.SpecialistEvaluateDO;
import com.yihu.jw.entity.specialist.SpecialistEvaluateLabelDO;
import com.yihu.jw.entity.specialist.SpecialistEvaluateScoreDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
/**
 * @author wangzhinan
 * @create 2018-08-22 9:48
 * @desc 评论service
 **/
@Transactional
@Service
public class SpecialistEvaluateService extends EnvelopRestEndpoint {
    @Autowired
    private SpecialistEvaluateDao specialistEvaluateDao;
    @Autowired
    private SpecialistEvaluateLabelDao specialistEvaluateLabelDao;
    @Autowired
    private SpecialistEvaluateScoreDao specialistEvaluateScoreDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 添加评论
     *
     * @param jsonObject
     * @return
     */
    public MixEnvelop<SpecialistEvaluateDO, SpecialistEvaluateDO> createEvaluate(JSONObject jsonObject) throws IOException {
        MixEnvelop<SpecialistEvaluateDO, SpecialistEvaluateDO> envelop = new MixEnvelop<>();
        JSONArray evaluate = jsonObject.getJSONArray("evaluate");
        JSONArray evaluateLabel = jsonObject.getJSONArray("evaluateLabel");
        String patientCode = jsonObject.getString("patient");
        List<SpecialistEvaluateDO> specialistEvaluateDOList = new ArrayList<>();
        List<SpecialistEvaluateLabelDO> specialistEvaluateLabelDOS = new ArrayList<>();
        for (int i = 0;i<evaluate.size();i++){
            SpecialistEvaluateDO specialistEvaluateDO = toEntity(evaluate.getJSONObject(i).toJSONString(), SpecialistEvaluateDO.class);
            specialistEvaluateDOList.add(specialistEvaluateDO);
        }
        for (int i =0;i<evaluateLabel.size();i++){
            SpecialistEvaluateLabelDO specialistEvaluateLabelDO = toEntity(evaluateLabel.getJSONObject(i).toJSONString(), SpecialistEvaluateLabelDO.class);
            specialistEvaluateLabelDOS.add(specialistEvaluateLabelDO);
        }
        String doctor = null;
        String relationCode = null;
        String patient = null;
        Double total = 0d;
        if (specialistEvaluateDOList != null && specialistEvaluateDOList.size() != 0){
            for (SpecialistEvaluateDO specialistEvaluateDO:specialistEvaluateDOList){
                specialistEvaluateDO.setRelationType(1);
                specialistEvaluateDO.setPatient(patientCode);
                specialistEvaluateDO.setCreateTime(new Date());
                specialistEvaluateDO.setUpdateTime(new Date());
                doctor = specialistEvaluateDO.getDoctor();
                relationCode = specialistEvaluateDO.getRelationCode();
                patient = specialistEvaluateDO.getPatient();
                SpecialistEvaluateDO specialistEvaluateDO1 = specialistEvaluateDao.save(specialistEvaluateDO);
                SpecialistEvaluateLabelDO specialistEvaluateLabelDO = new SpecialistEvaluateLabelDO();
                specialistEvaluateLabelDO.setSaasId("dev");
                specialistEvaluateLabelDO.setContent(specialistEvaluateDO.getContent());
                specialistEvaluateLabelDO.setDoctor(specialistEvaluateDO1.getDoctor());
                specialistEvaluateLabelDO.setPatient(specialistEvaluateDO1.getPatient());
                specialistEvaluateLabelDO.setEvaluateType(1);
                specialistEvaluateLabelDO.setRelationCode(specialistEvaluateDO.getRelationCode());
                specialistEvaluateLabelDO.setFlag(specialistEvaluateDO.getFlag());
                specialistEvaluateLabelDO.setCreateTime(new Date());
                specialistEvaluateLabelDO.setUpdateTime(new Date());
                specialistEvaluateLabelDao.save(specialistEvaluateLabelDO);
                total = total + specialistEvaluateDO.getScore();
            }
        }
        if (specialistEvaluateLabelDOS.size()!=0&&specialistEvaluateLabelDOS != null){
            for (SpecialistEvaluateLabelDO specialistEvaluateLabelDO:specialistEvaluateLabelDOS){
                specialistEvaluateLabelDO.setSaasId("dev");
                specialistEvaluateLabelDO.setEvaluateType(1);
                specialistEvaluateLabelDO.setPatient(patientCode);
                specialistEvaluateLabelDao.save(specialistEvaluateLabelDO);
            }
        }
        double score = total/3;
        BigDecimal   b   =   new   BigDecimal(score);
        double   f1   =   b.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
        SpecialistEvaluateScoreDO specialistEvaluateScoreDO = new SpecialistEvaluateScoreDO();
        specialistEvaluateScoreDO.setRelationCode(relationCode);
        specialistEvaluateScoreDO.setEvaluateType(1);
        specialistEvaluateScoreDO.setDoctor(doctor);
        specialistEvaluateScoreDO.setSaasId("dev");
        specialistEvaluateScoreDO.setScore(f1);
        specialistEvaluateScoreDO.setCreateTime(new Date());
        specialistEvaluateScoreDO.setUpdateTime(new Date());
        specialistEvaluateScoreDao.save(specialistEvaluateScoreDO);
        return envelop;
    }
    /**
     * 查询评论
     *
     * @param specialistEvaluateDO
     * @return
     */
    public MixEnvelop<JSONObject,JSONObject> selectByCondition(SpecialistEvaluateDO specialistEvaluateDO){
        MixEnvelop<JSONObject,JSONObject> envelop = new MixEnvelop<>();
        String sql = ISqlUtils.getSql(specialistEvaluateDO,1,100,"*");
        List<SpecialistEvaluateDO> specialistEvaluateDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistEvaluateDO.class));
        String sql1 = "select * from wlyy_specialist_evaluate_label where doctor = '"+specialistEvaluateDO.getDoctor()+"' " +
                "and relation_code = '"+specialistEvaluateDO.getRelationCode()+"' and patient = '"+specialistEvaluateDO.getPatient()+"'";
        List<SpecialistEvaluateLabelDO> specialistEvaluateLabelDOS = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(SpecialistEvaluateLabelDO.class));
        String sql2 = "select * from wlyy_specialist_evaluate_score where doctor = '"+specialistEvaluateDO.getDoctor()+"' " +
                "and relation_code = '"+specialistEvaluateDO.getRelationCode()+"'";
        List<SpecialistEvaluateScoreDO> specialistEvaluateScoreDOS = jdbcTemplate.query(sql2,new BeanPropertyRowMapper(SpecialistEvaluateScoreDO.class));
        JSONObject object = new JSONObject();
        object.put("score",specialistEvaluateScoreDOS);
        object.put("evaluate",specialistEvaluateDOS);
        object.put("evaluateLabel",specialistEvaluateLabelDOS);
        List<JSONObject> array = new ArrayList<>();
        array.add(object);
        envelop.setDetailModelList(array);
        return envelop;
    }
    /**
     * 更新评价
     *
     * @param specialistEvaluateDOList
     * @return
     */
    public MixEnvelop<Boolean,Boolean> update(List<SpecialistEvaluateDO> specialistEvaluateDOList){
        MixEnvelop<Boolean,Boolean> envelop = new MixEnvelop<>();
        String doctor = null;
        String relationCode = null;
        String patient = null;
        Double total = 0d;
        if (specialistEvaluateDOList != null && specialistEvaluateDOList.size() != 0){
            for (SpecialistEvaluateDO specialistEvaluateDO:specialistEvaluateDOList){
                specialistEvaluateDO.setSaasId("dev");
                specialistEvaluateDO.setRelationType(1);
                specialistEvaluateDO.setCreateTime(new Date());
                specialistEvaluateDO.setUpdateTime(new Date());
                doctor = specialistEvaluateDO.getDoctor();
                relationCode = specialistEvaluateDO.getRelationCode();
                patient = specialistEvaluateDO.getPatient();
                SpecialistEvaluateDO specialistEvaluateDO1 = specialistEvaluateDao.save(specialistEvaluateDO);
                SpecialistEvaluateLabelDO specialistEvaluateLabelDO = specialistEvaluateLabelDao.findById(specialistEvaluateDO.getLabelId()).orElse(null);
                specialistEvaluateLabelDO.setSaasId("dev");
                specialistEvaluateLabelDO.setContent(specialistEvaluateDO.getContent());
                specialistEvaluateLabelDO.setDoctor(specialistEvaluateDO1.getDoctor());
                specialistEvaluateLabelDO.setPatient(specialistEvaluateDO1.getPatient());
                specialistEvaluateLabelDO.setEvaluateType(1);
                specialistEvaluateLabelDO.setRelationCode(specialistEvaluateDO.getRelationCode());
                specialistEvaluateLabelDO.setCreateTime(new Date());
                specialistEvaluateLabelDO.setUpdateTime(new Date());
                specialistEvaluateLabelDao.save(specialistEvaluateLabelDO);
                total = total + specialistEvaluateDO.getScore();
            }
        }
        double score = total/3;
        BigDecimal   b   =   new   BigDecimal(score);
        double   f1   =   b.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
        String sql2 = "select * from wlyy_specialist_evaluate_score where doctor = '"+doctor+"' " +
                "and relation_code = '"+relationCode+"'";
        List<SpecialistEvaluateScoreDO> specialistEvaluateScoreDOS = jdbcTemplate.query(sql2,new BeanPropertyRowMapper(SpecialistEvaluateScoreDO.class));
        SpecialistEvaluateScoreDO specialistEvaluateScoreDO = specialistEvaluateScoreDOS.get(0);
        specialistEvaluateScoreDO.setRelationCode(relationCode);
        specialistEvaluateScoreDO.setEvaluateType(1);
        specialistEvaluateScoreDO.setDoctor(doctor);
        specialistEvaluateScoreDO.setSaasId("dev");
        specialistEvaluateScoreDO.setScore(f1);
        specialistEvaluateScoreDO.setCreateTime(new Date());
        specialistEvaluateScoreDO.setUpdateTime(new Date());
        specialistEvaluateScoreDao.save(specialistEvaluateScoreDO);
        return envelop;
    }
    public MixEnvelop<JSONObject,JSONObject> selectByDoctor(String doctor){
        MixEnvelop<JSONObject,JSONObject> envelop = new MixEnvelop<>();
        JSONObject object = new JSONObject();
        String sql = "select AVG(score) AS total from wlyy_specialist_evaluate_score where doctor = '"+doctor+"'";
        String sql1 = "select AVG(score) AS total from wlyy_specialist_evaluate where doctor = '"+doctor+"' AND evaluate_type = 1";
        String sql2 =  "select AVG(score) AS total from wlyy_specialist_evaluate where doctor = '"+doctor+"' AND evaluate_type = 2";
        String sql3 =  "select AVG(score) AS total from wlyy_specialist_evaluate where doctor = '"+doctor+"' AND evaluate_type = 3";
        String sql4 = "select * from wlyy_specialist_evaluate where doctor = '"+doctor+"'";
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
        Double totalScore = 0.0;
        if(rstotal!=null&&rstotal.size()>0){
            Object object1 = rstotal.get(0).get("total");
            if (object1!=null){
                totalScore = Double.parseDouble(object1.toString());
            }
        }
        List<Map<String,Object>> rstotal1 = jdbcTemplate.queryForList(sql1);
        Double totalScore1 = 0.0;
        if(rstotal1!=null&&rstotal1.size()>0){
            Object object1 = rstotal1.get(0).get("total");
            if (object1!=null){
                totalScore1 = Double.parseDouble(object1.toString());
            }
        }
        List<Map<String,Object>> rstotal2 = jdbcTemplate.queryForList(sql2);
        Double totalScore2 = 0.0;
        if(rstotal2!=null&&rstotal2.size()>0){
            Object object1 = rstotal2.get(0).get("total");
            if (object1!=null){
                totalScore2 = Double.parseDouble(object1.toString());
            }
        }
        List<Map<String,Object>> rstotal3 = jdbcTemplate.queryForList(sql3);
        Double totalScore3 = 0.0;
        if(rstotal3!=null&&rstotal3.size()>0){
            Object object1 = rstotal3.get(0).get("total");
            if (object1!=null){
                totalScore3 = Double.parseDouble(object1.toString());
            }
        }
        String sql5 = "select * from wlyy_specialist_evaluate WHERE doctor = '"+doctor+"'";
        String sql6 = "select * from wlyy_specialist_evaluate WHERE doctor IN (select doctor from wlyy_specialist_evaluate_score where score > 71 and doctor = '"+doctor+"')";
        String sql7 = "select * from wlyy_specialist_evaluate WHERE doctor IN (select doctor from wlyy_specialist_evaluate_score where score > 41 and score < 71 and doctor = '"+doctor+"')";
        String sql8 = "select * from wlyy_specialist_evaluate WHERE doctor IN (select doctor from wlyy_specialist_evaluate_score where score < 41 and doctor = '"+doctor+"')";
        List<SpecialistEvaluateDO> specialistEvaluateDOS = jdbcTemplate.query(sql5,new BeanPropertyRowMapper(SpecialistEvaluateDO.class));
        List<SpecialistEvaluateDO> specialistEvaluateDOS1 = jdbcTemplate.query(sql5,new BeanPropertyRowMapper(SpecialistEvaluateDO.class));
        List<SpecialistEvaluateDO> specialistEvaluateDOS3 = jdbcTemplate.query(sql6,new BeanPropertyRowMapper(SpecialistEvaluateDO.class));
        List<SpecialistEvaluateDO> specialistEvaluateDOS4 = jdbcTemplate.query(sql6,new BeanPropertyRowMapper(SpecialistEvaluateDO.class));
        List<SpecialistEvaluateDO> specialistEvaluateDOS5 = jdbcTemplate.query(sql7,new BeanPropertyRowMapper(SpecialistEvaluateDO.class));
        List<SpecialistEvaluateDO> specialistEvaluateDOS6 = jdbcTemplate.query(sql7,new BeanPropertyRowMapper(SpecialistEvaluateDO.class));
        List<SpecialistEvaluateDO> specialistEvaluateDOS7 = jdbcTemplate.query(sql8,new BeanPropertyRowMapper(SpecialistEvaluateDO.class));
        List<SpecialistEvaluateDO> specialistEvaluateDOS8 = jdbcTemplate.query(sql8,new BeanPropertyRowMapper(SpecialistEvaluateDO.class));
        JSONArray array = new JSONArray();
        JSONArray array3 = new JSONArray();
        JSONArray array4 = new JSONArray();
        JSONArray array5 = new JSONArray();
        JSONObject object2 = new JSONObject();
        JSONObject object3 = new JSONObject();
        JSONObject object4 = new JSONObject();
        JSONObject object5 = new JSONObject();
        //全部
        for (int i=0;i<specialistEvaluateDOS.size();i++){
            JSONArray array1 = new JSONArray();
            JSONObject object1 = new JSONObject();
            boolean isTrue = false;
            SpecialistEvaluateDO specialistEvaluateDO = specialistEvaluateDOS.get(i);
            Set<String> set = new HashSet<>();
            Set<Double> scoreSet = new HashSet<>();
            for (int j=0;j<specialistEvaluateDOS1.size();j++){
                SpecialistEvaluateDO specialistEvaluateDO1 = specialistEvaluateDOS1.get(j);
                JSONObject jsonObject = new JSONObject();
                if (specialistEvaluateDO.getRelationCode().equals(specialistEvaluateDO1.getRelationCode())&&specialistEvaluateDO.getPatient().equals(specialistEvaluateDO1.getPatient())&&specialistEvaluateDO.getDoctor().equals(specialistEvaluateDO1.getDoctor())){
                    String scoreSql = "select * from wlyy_specialist_evaluate_score where relation_code = '"+specialistEvaluateDO1.getRelationCode()+"' and patient = '"+specialistEvaluateDO1.getPatient()+"'";
                    List<SpecialistEvaluateScoreDO> specialistEvaluateScoreDOS =jdbcTemplate.query(scoreSql,new BeanPropertyRowMapper(SpecialistEvaluateScoreDO.class));
                    if (specialistEvaluateScoreDOS != null && specialistEvaluateScoreDOS.size()!=0){
                        scoreSet.add(specialistEvaluateScoreDOS.get(0).getScore());
                    }
                    set.add(specialistEvaluateDO1.getPatient());
                    array1.add(specialistEvaluateDO1);
                }
            }
            object1.put("patient",set);
            for (Double value:scoreSet){
                if (value>71){
                    object1.put("flag","好评");
                }else if (value>41&&value<71){
                    object1.put("flag","中评");
                }else if (value<41){
                    object1.put("flag","差评");
                }
            }
            object1.put("score",scoreSet);
            object1.put("evaluate",array1);
            if (array1.size() !=0&&array1 != null){
                specialistEvaluateDOS1.removeAll(array1);
                array.add(object1);
            }
        }
        //好评
        for (int i=0;i<specialistEvaluateDOS3.size();i++){
            JSONArray array1 = new JSONArray();
            JSONObject object1 = new JSONObject();
            boolean isTrue = false;
            SpecialistEvaluateDO specialistEvaluateDO = specialistEvaluateDOS3.get(i);
            Set<String> set = new HashSet<>();
            Set<Double> scoreSet = new HashSet<>();
            for (int j=0;j<specialistEvaluateDOS4.size();j++){
                SpecialistEvaluateDO specialistEvaluateDO1 = specialistEvaluateDOS4.get(j);
                JSONObject jsonObject = new JSONObject();
                if (specialistEvaluateDO.getRelationCode().equals(specialistEvaluateDO1.getRelationCode())&&specialistEvaluateDO.getPatient().equals(specialistEvaluateDO1.getPatient())&&specialistEvaluateDO.getDoctor().equals(specialistEvaluateDO1.getDoctor())){
                    String scoreSql = "select * from wlyy_specialist_evaluate_score where relation_code = '"+specialistEvaluateDO1.getRelationCode()+"' and patient = '"+specialistEvaluateDO1.getPatient()+"'";
                    List<SpecialistEvaluateScoreDO> specialistEvaluateScoreDOS =jdbcTemplate.query(scoreSql,new BeanPropertyRowMapper(SpecialistEvaluateScoreDO.class));
                    if (specialistEvaluateScoreDOS != null && specialistEvaluateScoreDOS.size()!=0){
                        scoreSet.add(specialistEvaluateScoreDOS.get(0).getScore());
                    }
                    set.add(specialistEvaluateDO1.getPatient());
                    array1.add(specialistEvaluateDO1);
                }
            }
            object1.put("patient",set);
            object1.put("flag","好评");
            object1.put("score",scoreSet);
            object1.put("evaluate",array1);
            if (array1.size() !=0&&array1 != null){
                specialistEvaluateDOS4.removeAll(array1);
                array3.add(object1);
            }
        }
        //中评
        for (int i=0;i<specialistEvaluateDOS5.size();i++){
            JSONArray array1 = new JSONArray();
            JSONObject object1 = new JSONObject();
            boolean isTrue = false;
            SpecialistEvaluateDO specialistEvaluateDO = specialistEvaluateDOS5.get(i);
            Set<String> set = new HashSet<>();
            Set<Double> scoreSet = new HashSet<>();
            for (int j=0;j<specialistEvaluateDOS6.size();j++){
                SpecialistEvaluateDO specialistEvaluateDO1 = specialistEvaluateDOS6.get(j);
                JSONObject jsonObject = new JSONObject();
                if (specialistEvaluateDO.getRelationCode().equals(specialistEvaluateDO1.getRelationCode())&&specialistEvaluateDO.getPatient().equals(specialistEvaluateDO1.getPatient())&&specialistEvaluateDO.getDoctor().equals(specialistEvaluateDO1.getDoctor())){
                    String scoreSql = "select * from wlyy_specialist_evaluate_score where relation_code = '"+specialistEvaluateDO1.getRelationCode()+"' and patient = '"+specialistEvaluateDO1.getPatient()+"'";
                    List<SpecialistEvaluateScoreDO> specialistEvaluateScoreDOS =jdbcTemplate.query(scoreSql,new BeanPropertyRowMapper(SpecialistEvaluateScoreDO.class));
                    if (specialistEvaluateScoreDOS != null && specialistEvaluateScoreDOS.size()!=0){
                        scoreSet.add(specialistEvaluateScoreDOS.get(0).getScore());
                    }
                    set.add(specialistEvaluateDO1.getPatient());
                    array1.add(specialistEvaluateDO1);
                }
            }
            object1.put("patient",set);
            object1.put("flag","中评");
            object1.put("score",scoreSet);
            object1.put("evaluate",array1);
            if (array1.size() !=0&&array1 != null){
                specialistEvaluateDOS6.removeAll(array1);
                array4.add(object1);
            }
        }
        //差评
        for (int i=0;i<specialistEvaluateDOS7.size();i++){
            JSONArray array1 = new JSONArray();
            JSONObject object1 = new JSONObject();
            boolean isTrue = false;
            SpecialistEvaluateDO specialistEvaluateDO = specialistEvaluateDOS7.get(i);
            Set<String> set = new HashSet<>();
            Set<Double> scoreSet = new HashSet<>();
            for (int j=0;j<specialistEvaluateDOS8.size();j++){
                SpecialistEvaluateDO specialistEvaluateDO1 = specialistEvaluateDOS8.get(j);
                JSONObject jsonObject = new JSONObject();
                if (specialistEvaluateDO.getRelationCode().equals(specialistEvaluateDO1.getRelationCode())&&specialistEvaluateDO.getPatient().equals(specialistEvaluateDO1.getPatient())&&specialistEvaluateDO.getDoctor().equals(specialistEvaluateDO1.getDoctor())){
                    String scoreSql = "select * from wlyy_specialist_evaluate_score where relation_code = '"+specialistEvaluateDO1.getRelationCode()+"' and patient = '"+specialistEvaluateDO1.getPatient()+"'";
                    List<SpecialistEvaluateScoreDO> specialistEvaluateScoreDOS =jdbcTemplate.query(scoreSql,new BeanPropertyRowMapper(SpecialistEvaluateScoreDO.class));
                    if (specialistEvaluateScoreDOS != null && specialistEvaluateScoreDOS.size()!=0){
                        scoreSet.add(specialistEvaluateScoreDOS.get(0).getScore());
                    }
                    set.add(specialistEvaluateDO1.getPatient());
                    array1.add(specialistEvaluateDO1);
                }
            }
            object1.put("patient",set);
            object1.put("flag","差评");
            object1.put("score",scoreSet);
            object1.put("evaluate",array1);
            if (array1.size() !=0&&array1 != null){
                specialistEvaluateDOS8.removeAll(array1);
                array5.add(object1);
            }
        }
        String lableSql = "select * from wlyy_specialist_evaluate_label where doctor ='"+doctor+"' AND flag IN (2,3)";
        List<SpecialistEvaluateLabelDO> specialistEvaluateLabelDOS = jdbcTemplate.query(lableSql,new BeanPropertyRowMapper(SpecialistEvaluateLabelDO.class));
        Set<String> labelSet = new HashSet<>();
        for (SpecialistEvaluateLabelDO specialistEvaluateLabelDO:specialistEvaluateLabelDOS){
            labelSet.add(specialistEvaluateLabelDO.getContent());
        }
        object2.put("evaluate",array);
        object2.put("total",array.size());
        object3.put("evaluate",array3);
        object3.put("total",array3.size());
        object4.put("evaluate",array4);
        object4.put("total",array4.size());
        object5.put("evaluate",array5);
        object5.put("total",array5.size());
        object.put("label",labelSet);
        object.put("totalScore",totalScore);
        object.put("1",totalScore1);//1、服务效率,
        object.put("2",totalScore2);// 2、服务态度,
        object.put("3",totalScore3);// 3、专业程度
        object.put("4",object2);//全部
        object.put("5",object3);//好评
        object.put("6",object4);//中评
        object.put("7",object5);//差评
        envelop.setObj(object);
        return envelop;
    }
}

+ 0 - 418
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistHospitalServiceItemService.java

@ -1,418 +0,0 @@
package com.yihu.jw.base.service.specialist;/**
 * Created by nature of king on 2018/8/28.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.dao.specialist.SpecialistHospitalServiceItemDao;
import com.yihu.jw.base.dao.specialist.SpecialistServiceItemDao;
import com.yihu.jw.entity.specialist.HospitalServiceItemDO;
import com.yihu.jw.entity.specialist.SpecialistServiceItemDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.util.common.DataUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
 * @author wangzhinan
 * @create 2018-08-28 19:57
 * @desc 机构服务项目
 **/
@Service
@Transactional
public class SpecialistHospitalServiceItemService extends EnvelopRestEndpoint {
    @Autowired
    private SpecialistHospitalServiceItemDao specialistHospitalServiceItemDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SpecialistServiceItemDao specialistServiceItemDao;
    /**
     * 添加机构服务项目
     *
     * @param hospitalServiceItemDOS
     * @return
     */
    public MixEnvelop<HospitalServiceItemDO, HospitalServiceItemDO> insert(List<HospitalServiceItemDO> hospitalServiceItemDOS){
        MixEnvelop<HospitalServiceItemDO, HospitalServiceItemDO> envelop = new MixEnvelop<>();
        if (hospitalServiceItemDOS !=null && hospitalServiceItemDOS.size()!=0){
            for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOS){
                hospitalServiceItemDO.setCreateTime(new Date());
                hospitalServiceItemDO.setUpdateTime(new Date());
                specialistHospitalServiceItemDao.save(hospitalServiceItemDO);
            }
        }
        envelop.setDetailModelList(hospitalServiceItemDOS);
        return envelop;
    }
    /**
     * 根据医院code查找数据
     *
     * @param hospitals
     * @return
     */
    public MixEnvelop<HospitalServiceItemDO, HospitalServiceItemDO> selectByHospital(List<String> hospitals){
        MixEnvelop<HospitalServiceItemDO, HospitalServiceItemDO> envelop = new MixEnvelop<>();
        StringBuffer buffer = new StringBuffer();
        if (hospitals!=null && hospitals.size()!=0){
            buffer.append(" and hospital in (");
            for (int i =0 ;i<hospitals.size();i++){
                buffer.append("'"+hospitals.get(i)+"',");
            }
            buffer.deleteCharAt(buffer.length()-1);
            buffer.append(")");
        }else{
            buffer.append("");
        }
        String sql = "select * from wlyy_hospital_service_item where 1=1 "+buffer;
        List<HospitalServiceItemDO> hospitalServiceItemDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
        for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOS){
            SpecialistServiceItemDO specialistServiceItemDO = specialistServiceItemDao.findById(hospitalServiceItemDO.getServiceItemId()).orElse(null);
            hospitalServiceItemDO.setSpecialistServiceItemDO(specialistServiceItemDO);
        }
        envelop.setDetailModelList(hospitalServiceItemDOS);
        return envelop;
    }
    /**
     *
     * @param hospital
     * @param docHospital
     * @param serviceItemName
     * @return
     */
    public MixEnvelop<JSONArray,JSONArray> selectByHospital1(String hospital, String docHospital, String serviceItemName){
        MixEnvelop<JSONArray,JSONArray> envelop = new MixEnvelop<>();
        String sqlUtil = "";
        if (StringUtils.isNoneBlank(serviceItemName)||serviceItemName != null){
            sqlUtil=" AND service_item_id IN ( SELECT id FROM wlyy_service_item WHERE 1=1 and title LIKE '%"+serviceItemName+"%')";
        }
        List<HospitalServiceItemDO> hospitalServiceItemDOS1 = new ArrayList<>();
        if (StringUtils.isNoneBlank(hospital)&&hospital.equals(docHospital)){
            String sql1 = "select * from wlyy_hospital_service_item where 1=1 AND status = 1 AND imediate=1 AND hospital = '"+docHospital+"'"+sqlUtil;
            List<HospitalServiceItemDO> hospitalServiceItemDOList = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
            for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOList){
                hospitalServiceItemDO.setFlag(3);
                hospitalServiceItemDOS1.add(hospitalServiceItemDO);
            }
        }else if (hospital == null || hospital == ""){
            String sql1 = "select * from wlyy_hospital_service_item where 1=1 AND status = 1 AND imediate=1 AND hospital = '"+docHospital+"'"+sqlUtil;
            List<HospitalServiceItemDO> hospitalServiceItemDOList = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
            for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOList){
                hospitalServiceItemDO.setFlag(2);
                hospitalServiceItemDOS1.add(hospitalServiceItemDO);
            }
        }else{
            String sql = "select * from wlyy_hospital_service_item where 1=1 AND status = 1 AND imediate=1 AND hospital = '"+hospital+"' "+sqlUtil;
            List<HospitalServiceItemDO> hospitalServiceItemDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
            String sql1 = "select * from wlyy_hospital_service_item where 1=1 AND status = 1 AND imediate=1 AND hospital = '"+docHospital+"' "+sqlUtil;
            List<HospitalServiceItemDO> hospitalServiceItemDOList = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
            if (hospitalServiceItemDOList != null && hospitalServiceItemDOList.size()!=0){
                for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOList){
                    boolean flag = false;
                    for (HospitalServiceItemDO hospitalServiceItemDO1 :hospitalServiceItemDOS){
                        boolean isTrue = false;
                        if (hospitalServiceItemDOS1 != null && hospitalServiceItemDOS1.size() != 0){
                            for (HospitalServiceItemDO hospitalServiceItemDO2:hospitalServiceItemDOS1){
                                if (hospitalServiceItemDO1.getServiceItemId().equals(hospitalServiceItemDO2.getServiceItemId())){
                                    if (hospitalServiceItemDO.getServiceItemId().equals(hospitalServiceItemDO1.getServiceItemId())){
                                        hospitalServiceItemDO2.setFlag(3);
                                    }
                                    isTrue = true;
                                }
                            }
                        }
                        if (hospitalServiceItemDO.getServiceItemId().equals(hospitalServiceItemDO1.getServiceItemId())){
                            if (isTrue==false){
                                hospitalServiceItemDO1.setFlag(3);
                                hospitalServiceItemDOS1.add(hospitalServiceItemDO1);
                                flag = true;
                            }
                        }else{
                            if (isTrue == false){
                                hospitalServiceItemDO1.setFlag(1);
                                hospitalServiceItemDOS1.add(hospitalServiceItemDO1);
                            }
                        }
                    }
                    if (flag==false){
                        boolean isTrue1 = false;
                        if (hospitalServiceItemDOS1 != null && hospitalServiceItemDOS1.size() != 0){
                            for (HospitalServiceItemDO hospitalServiceItemDO2:hospitalServiceItemDOS1){
                                if (hospitalServiceItemDO.getServiceItemId().equals(hospitalServiceItemDO2.getServiceItemId())){
                                    isTrue1 = true;
                                }
                            }
                        }
                        if (isTrue1 == false){
                            hospitalServiceItemDO.setFlag(2);
                            hospitalServiceItemDOS1.add(hospitalServiceItemDO);
                        }
                    }
                }
            }else {
                String sql3 = "select * from wlyy_hospital_service_item where 1=1 AND status = 1 AND imediate=1 AND hospital = '"+hospital+"'"+sqlUtil;
                List<HospitalServiceItemDO> hospitalServiceItemDOList1 = jdbcTemplate.query(sql3,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
                for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOList1){
                    hospitalServiceItemDO.setFlag(1);
                    hospitalServiceItemDOS1.add(hospitalServiceItemDO);
                }
            }
        }
        for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOS1){
            SpecialistServiceItemDO specialistServiceItemDO = specialistServiceItemDao.findById(hospitalServiceItemDO.getServiceItemId()).orElse(null);
            hospitalServiceItemDO.setSpecialistServiceItemDO(specialistServiceItemDO);
        }
        JSONArray array = new JSONArray();
        List<Integer> itemType = new ArrayList<>();
        for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOS1){
            SpecialistServiceItemDO specialistServiceItemDO = hospitalServiceItemDO.getSpecialistServiceItemDO();
            if (itemType != null && itemType.size() != 0){
                for (int i=0;i<itemType.size();i++){
                    if (!itemType.contains(specialistServiceItemDO.getItemType())){
                        itemType.add(specialistServiceItemDO.getItemType());
                    }
                }
            }else {
                itemType.add(specialistServiceItemDO.getItemType());
            }
        }
        for (int i =0;i<itemType.size();i++){
            JSONObject object = new JSONObject();
            List<String> type = new ArrayList<>();
            for (int j = 0;j<hospitalServiceItemDOS1.size();j++){
                SpecialistServiceItemDO specialistServiceItemDO = hospitalServiceItemDOS1.get(j).getSpecialistServiceItemDO();
                if (itemType.get(i).equals(specialistServiceItemDO.getItemType())&& !type.contains(specialistServiceItemDO.getDiseaseItem())){
            type.add(specialistServiceItemDO.getDiseaseItem());
                }
            }
        JSONArray itemArray = new JSONArray();
        List<String> serviceItems = new ArrayList<>();
        if (type != null && type.size() != 0){
                for (int z =0 ;z<type.size();z++){
                    List<HospitalServiceItemDO> hospitalServiceItemDOS2 = new ArrayList<>();
                    JSONObject object1 =new JSONObject();
                    for (int j = 0;j<hospitalServiceItemDOS1.size();j++){
                        SpecialistServiceItemDO specialistServiceItemDO = hospitalServiceItemDOS1.get(j).getSpecialistServiceItemDO();
                        if (itemType.get(i).equals(specialistServiceItemDO.getItemType())){
                            if (type.get(z).equals(specialistServiceItemDO.getDiseaseItem())) {
                                hospitalServiceItemDOS2.add(hospitalServiceItemDOS1.get(j));
                            }
                        }
                    }
                    if (serviceItems!=null && serviceItems.size()!=0){
                        if (!serviceItems.contains(type.get(z))){
                            serviceItems.add(type.get(z));
                            object1.put("itemName",type.get(z));
                            object1.put("hospitalServiceItems",hospitalServiceItemDOS2);
                            itemArray.add(object1);
                        }else {
                            object1.put("itemName",type.get(z));
                            object1.put("hospitalServiceItems",hospitalServiceItemDOS2);
                            itemArray.add(object1);
                        }
                    }else {
                        serviceItems.add(type.get(z));
                        object1.put("itemName",type.get(z));
                        object1.put("hospitalServiceItems",hospitalServiceItemDOS2);
                        itemArray.add(object1);
                    }
                }
        }
        if (itemArray !=null && itemArray.size()!=0){
            JSONArray jsonArray = new JSONArray();
            for (int j = 0;j<itemArray.size();j++){
                JSONObject object1 = itemArray.getJSONObject(j);
                JSONObject jsonObject1 = new JSONObject();
                JSONArray array1 = object1.getJSONArray("hospitalServiceItems");
                JSONArray array2 = new JSONArray();
                for (int k=0;k<array1.size();k++){
                    JSONObject jsonObject = array1.getJSONObject(k);
                    jsonObject.replace("expense", DataUtils.integerTransferDouble(jsonObject.getInteger("expense")));
                    array2.add(jsonObject);
                }
                jsonObject1.put("itemName",object1.getString("itemName"));
                jsonObject1.put("hospitalServiceItems",array2);
                jsonArray.add(jsonObject1);
            }
            object.put("item",jsonArray);
        }else {
            object.put("item",itemArray);
        }
        object.put("itemType",itemType.get(i));
        array.add(object);
    }
    List<JSONArray> list = new ArrayList<>();
    list.add(array);
    envelop.setDetailModelList(list);
    return envelop;
    }
    /**
     * 根据id获取服务项目
     *
     * @param hospitalServiceItems
     * @return
     */
    public MixEnvelop<HospitalServiceItemDO, HospitalServiceItemDO> selectById(List<String> hospitalServiceItems){
        MixEnvelop<HospitalServiceItemDO, HospitalServiceItemDO> envelop = new MixEnvelop<>();
        StringBuffer buffer = new StringBuffer();
        if(hospitalServiceItems != null && hospitalServiceItems.size()!=0){
            buffer.append(" and id in (");
            for (int i =0 ;i<hospitalServiceItems.size();i++){
                buffer.append("'"+hospitalServiceItems.get(i)+"',");
            }
            buffer.deleteCharAt(buffer.length()-1);
            buffer.append(")");
        }
        String sql = "select * from wlyy_hospital_service_item where 1=1 "+buffer;
        List<HospitalServiceItemDO> hospitalServiceItemDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
        for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOS){
            SpecialistServiceItemDO specialistServiceItemDO = specialistServiceItemDao.findById(hospitalServiceItemDO.getServiceItemId()).orElse(null);
            hospitalServiceItemDO.setSpecialistServiceItemDO(specialistServiceItemDO);
        }
        envelop.setDetailModelList(hospitalServiceItemDOS);
        return envelop;
    }
    /**
     * 按条件查询机构服务项目
     *
     * @param serviceItemName 服务项目名称
     *
     * @param hospitals 医院code集合
     * @return
     */
    public MixEnvelop<JSONArray,JSONArray> selectByCondition(String serviceItemName, List<String> hospitals){
        MixEnvelop<JSONArray,JSONArray> envelop = new MixEnvelop<>();
        /*if (StringUtils.isNoneBlank(serviceItemName)||serviceItemName != null){
            String sql = "select * from wlyy_hospital_service_item where service_item_name = '"+serviceItemName+"' and status=1";
            List<HospitalServiceItemDO> hospitalServiceItemDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
            for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOS){
                SpecialistServiceItemDO specialistServiceItemDO = specialistServiceItemDao.findOne(hospitalServiceItemDO.getServiceItemId());
                hospitalServiceItemDO.setSpecialistServiceItemDO(specialistServiceItemDO);
            }
            JSONArray array = new JSONArray();
            for (int i =0 ;i<hospitalServiceItemDOS.size();i++){
                SpecialistServiceItemDO specialistServiceItemDO = hospitalServiceItemDOS.get(i).getSpecialistServiceItemDO();
                JSONObject object = new JSONObject();
                object.put("itemName",specialistServiceItemDO.getItemType());
                object.put("hospitalServiceItem",hospitalServiceItemDOS.get(i));
                array.add(object);
            }
            List<JSONArray> list = new ArrayList<>();
            list.add(array);
            envelop.setDetailModelList(list);
        }else {*/
        StringBuffer buffer = new StringBuffer();
        if(hospitals != null && hospitals.size()!=0){
            buffer.append(" and hospital in (");
            for (int i =0 ;i<hospitals.size();i++){
                buffer.append("'"+hospitals.get(i)+"',");
            }
            buffer.deleteCharAt(buffer.length()-1);
            buffer.append(")");
        }
        String sql = "select * from wlyy_hospital_service_item where 1=1 AND status = 1"+buffer;
        List<HospitalServiceItemDO> hospitalServiceItemDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
        for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOS){
            SpecialistServiceItemDO specialistServiceItemDO = specialistServiceItemDao.findById(hospitalServiceItemDO.getServiceItemId()).orElse(null);
            hospitalServiceItemDO.setSpecialistServiceItemDO(specialistServiceItemDO);
        }
        JSONArray array = new JSONArray();
        for (int i =0 ;i<hospitalServiceItemDOS.size();i++){
            SpecialistServiceItemDO specialistServiceItemDO = hospitalServiceItemDOS.get(i).getSpecialistServiceItemDO();
            JSONObject object = new JSONObject();
            object.put("itemName",specialistServiceItemDO.getItemType());
            JSONObject jsonObject = (JSONObject) JSONObject.toJSON(hospitalServiceItemDOS.get(i));
            jsonObject.replace("expense", DataUtils.integerTransferDouble(hospitalServiceItemDOS.get(i).getExpense()));
            JSONObject object1 = jsonObject.getJSONObject("specialistServiceItemDO");
            object1.replace("threeHospitals", DataUtils.integerTransferDouble(hospitalServiceItemDOS.get(i).getSpecialistServiceItemDO().getThreeHospitals()));
            object1.replace("twoHospitals",DataUtils.integerTransferDouble(hospitalServiceItemDOS.get(i).getSpecialistServiceItemDO().getTwoHospitals()));
            object1.replace("oneHospitals",DataUtils.integerTransferDouble(hospitalServiceItemDOS.get(i).getSpecialistServiceItemDO().getOneHospitals()));
            object.put("hospitalServiceItem",jsonObject);
            array.add(object);
        }
        List<JSONArray> list = new ArrayList<>();
        list.add(array);
        envelop.setDetailModelList(list);
        return envelop;
    }
    /**
     * 删除机构服务项目
     *
     * @param hospital 医院code
     *
     * @param serviceItemId 服务项目id
     * @return
     */
    public MixEnvelop<Boolean,Boolean> delete(String hospital, String serviceItemId, String id){
        MixEnvelop<Boolean,Boolean> envelop = new MixEnvelop<>();
        if (StringUtils.isNoneBlank(hospital)){
            String sql = "update wlyy_hospital_service_item set status = 0 where hospital = '"+hospital+"'";
            jdbcTemplate.update(sql);
        }else if (StringUtils.isNoneBlank(serviceItemId)){
            String sql = "update wlyy_hospital_service_item set status = 0 where service_item_id = '"+serviceItemId+"'";
            jdbcTemplate.update(sql);
        }else if (StringUtils.isNoneBlank(id)){
            String sql = "update wlyy_hospital_service_item set status = 0 where id = '"+id+"'";
            jdbcTemplate.update(sql);
        }
        return envelop;
    }
    /**
     * 机构服务项目数据添加
     *
     * @param hospitalServiceItemDOS
     * @return
     */
    public MixEnvelop<Boolean,Boolean> importData(List<HospitalServiceItemDO> hospitalServiceItemDOS) {
        MixEnvelop<Boolean,Boolean> envelop = new MixEnvelop<>();
        if (hospitalServiceItemDOS != null && hospitalServiceItemDOS.size()!=0){
            for (HospitalServiceItemDO hospitalServiceItemDO:hospitalServiceItemDOS){
                List<SpecialistServiceItemDO> specialistServiceItemDOS = specialistServiceItemDao.findByTitleAndContent(hospitalServiceItemDO.getTitle(),hospitalServiceItemDO.getContent());
                if (specialistServiceItemDOS != null && specialistServiceItemDOS.size()!=0){
                    List<HospitalServiceItemDO> hospitalServiceItemDOList = specialistHospitalServiceItemDao.findByHospitalAndServiceItemId(hospitalServiceItemDO.getHospital(),specialistServiceItemDOS.get(0).getId());
                    if (hospitalServiceItemDOList != null && hospitalServiceItemDOList.size() !=0){
                        continue;
                    }else {
                        hospitalServiceItemDO.setStatus(1);
                        hospitalServiceItemDO.setImediate(0);
                        hospitalServiceItemDO.setSaasId("dev");
                        hospitalServiceItemDO.setId(UUID.randomUUID().toString());
                        hospitalServiceItemDO.setServiceItemId(specialistServiceItemDOS.get(0).getId());
                        hospitalServiceItemDO.setServiceItemName(specialistServiceItemDOS.get(0).getDiseaseItem());
                        hospitalServiceItemDO.setCreateTime(new Date());
                        hospitalServiceItemDO.setUpdateTime(new Date());
                        specialistHospitalServiceItemDao.save(hospitalServiceItemDO);
                    }
                }
            }
        }
        envelop.setObj(true);
        return envelop;
    }
}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 261
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistScreenResultService.java


+ 0 - 1448
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistService.java

@ -1,1448 +0,0 @@
package com.yihu.jw.base.service.specialist;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.dao.specialist.PatientHospitalRecordDao;
import com.yihu.jw.base.dao.specialist.SpecialistPatientRelationDao;
import com.yihu.jw.base.dao.specialist.rehabilitation.*;
import com.yihu.jw.entity.specialist.SpecialistPatientRelationDO;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanDO;
import com.yihu.jw.entity.specialist.rehabilitation.PatientRehabilitationPlanLogDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationDetailDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationOperateRecordsDO;
import com.yihu.jw.entity.util.TransforSqlUtl;
import com.yihu.jw.restmodel.specialist.*;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
/**
 * Created by Trick on 2018/4/25.
 */
@Service
@Transactional
public class SpecialistService{
    @Autowired
    private SpecialistPatientRelationDao specialistPatientRelationDao;
    @Autowired
    private PatientHospitalRecordDao patientHospitalRecordDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private String basedb="base";
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PatientRehabilitationPlanDao patientRehabilitationPlanDao;
    @Autowired
    private RehabilitationDetailDao rehabilitationDetailDao;
    @Autowired
    private RehabilitationDetailAppointmentDao rehabilitationDetailAppointmentDao;
    @Autowired
    private PatientRehabilitationPlanLogDao patientRehabilitationPlanLogDao;
    @Autowired
    private RehabilitationOperateRecordsDao rehabilitationOperateRecordsDao;
    public MixEnvelop<Boolean, Boolean> createSpecialistsPatientRelation(SpecialistPatientRelationDO specialistPatientRelationDO){
        specialistPatientRelationDao.save(specialistPatientRelationDO);
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,true);
    }
    public MixEnvelop<SpecialistPatientRelationVO, SpecialistPatientRelationVO> findSpecialistPatientRelation(String doctor, Integer page, Integer size)throws ParseException {
        String sql = "SELECT " +
                " r.id, " +
                " r.doctor ,r.doctor_name AS doctor_name " +
                " ,r.saas_id AS sassId, " +
                " r.patient ,r.patient_name AS patient_name" +
                " ,r.health_doctor AS healthDoctor ,r.health_doctor_name AS healthDoctorName" +
                " ,r.sign_code AS signCode, " +
                " r.sign_year AS signYear, " +
                " r.sign_doctor AS sign_doctor ,r.sign_doctor_name AS signDoctorName" +
                " ,r.create_time AS createTime," +
                " r.status " +
                "FROM " +
                " wlyy_specialist_patient_relation r " +
                "WHERE " +
                " r.doctor = '"+doctor+"' AND r.status >=0  AND r.sign_status >0 ORDER BY r.create_time DESC LIMIT "+(page-1)*size+","+size;
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.doctor_name","r.patient_name","r.health_doctor_name","r.sign_doctor_name");
        List<SpecialistPatientRelationVO> specialistPatientRelationVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistPatientRelationVO.class));
        String sqlcount = "SELECT count(1) AS total " +
                "FROM " +
                " wlyy_specialist_patient_relation r " +
                "WHERE " +
                " r.doctor = '"+doctor+"'  AND r.status >=0  AND r.sign_status >0 ;";
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,specialistPatientRelationVOs,page,size,count);
    }
    public MixEnvelop<Long, Long> findSpecialistPatientRelationCout(String doctor){
        String sql = "SELECT " +
                " count(1) AS total " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " WHERE " +
                " r.doctor ='"+doctor+"'" +
                " AND r.patient " +
                " NOT IN ( " +
                " SELECT " +
                " patient " +
                " FROM " +
                " "+basedb+".wlyy_sign_patient_label_info i " +
                " WHERE " +
                " i.label_type = '7' AND " +
                " i.status = 1" +
                " )" +
                " AND r. STATUS >= 0 " +
                " AND r.sign_status > 0";
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,count);
    }
    public MixEnvelop<PatientRelationVO, PatientRelationVO> findNoLabelPatientRelation(String doctor){
        String sql ="SELECT " +
                " r.patient ,r.patient_name as patientName" +
                " ,IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
                " p.photo, " +
                " rd.create_time AS createTime ," +
                " p.sex " +
                " FROM " +
                " wlyy_specialist_patient_relation r JOIN "+basedb+".wlyy_patient p ON p.code = r.patient  " +
                " LEFT JOIN wlyy_patient_hospital_record rd ON r.discharge_record = rd.id " +
                " WHERE " +
                " r.doctor = '"+doctor+"' AND r.status >=0  AND r.sign_status >0" +
                " AND r.patient " +
                " NOT IN ( " +
                "  SELECT " +
                "   i.patient " +
                "  FROM " +
                "   "+basedb+".wlyy_sign_patient_label_info i " +
                "  WHERE " +
                "   i.label_type = '7' AND " +
                "   i.status = 1 " +
                " )";
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name");
        List<PatientRelationVO> patientRelationVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientRelationVO.class));
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientRelationVOs);
    }
    public MixEnvelop<Boolean, Boolean> saveHealthAssistant(List<SpecialistPatientRelationDO> specialistPatientRelationDOs){
        for(SpecialistPatientRelationDO r : specialistPatientRelationDOs){
            SpecialistPatientRelationDO relationDO = specialistPatientRelationDao.findByDoctorAndPatient(r.getDoctor(),r.getPatient());
            if(relationDO!=null){
                relationDO.setHealthAssistant(r.getHealthAssistant());
                relationDO.setHealthAssistantName(r.getHealthAssistantName());
                specialistPatientRelationDao.save(relationDO);
            }
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,true);
    }
    public MixEnvelop<PatientRelationVO, PatientRelationVO> findPatientRelatioByAssistant(String doctor , String assistant, Integer page, Integer size){
        String sql ="SELECT " +
                " r.patient ,r.patient_name as patientName" +
                " ,IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
                " p.photo ," +
                " p.sex," +
                " h.label_name as health, " +
                " h.label AS healthcode " +
                " FROM " +
                " wlyy_specialist_patient_relation r JOIN "+basedb+".wlyy_patient p ON p.`code` = r.patient " +
                " LEFT JOIN ( " +
                " SELECT " +
                "  t.label, " +
                "  t.label_name, " +
                "  t.patient " +
                " FROM " +
                "  "+basedb+".wlyy_sign_patient_label_info t " +
                " WHERE " +
                "  t.label_type = '8' " +
                " AND t.`status` = '1' " +
                " ) h ON h.patient = r.patient " +
                " WHERE " +
                "  r.doctor = '"+doctor+"' AND r.status >=0  AND r.sign_status >0 "+
                " AND r.health_assistant = '"+assistant+"' LIMIT "+(page-1)*size+","+size;
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name");
        List<PatientRelationVO> patientRelationVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientRelationVO.class));
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientRelationVOs);
    }
    public MixEnvelop<PatientLabelVO, PatientLabelVO> getPatientByLabel(String doctor, String labelType, String teamCode, String labelCode, Integer page, Integer size, String shareDoctor){
        String sql="SELECT " +
                " p. CODE ,s.patient_name as name," +
                " p.sex," +
                " IFNULL( " +
                "  YEAR ( " +
                "   from_days(datediff(now(), p.birthday)) " +
                "  ), " +
                "  '未知' " +
                " ) age, " +
                " lb.labelName, " +
                " lb.labelType, " +
                " lb.label, " +
                " p.photo, " +
                " lb.labelName as health, " +
                " lb.label AS healthcode ," +
                " s.health_assistant AS healthAssistant,s.health_assistant_name as healthAssistantName " +
//                " s.health_assistant_name AS healthAssistantName," +
                " ,s.is_manage AS isManage," +
                " s.id AS specialCode" +
                " FROM " +
                " ( " +
                "  SELECT " +
                "   i.label_type AS labelType, " +
                "   i.label, " +
                "   i.label_name AS labelName, " +
                "   i.patient " +
                "  FROM " +
                "   "+basedb+".wlyy_sign_patient_label_info i " +
                "  WHERE " +
                "   i.label = '"+labelCode+"' " +
                "  AND i.label_type = '"+labelType+"' " +
                "  AND i.`status` = '1' " +
                " ) lb " +
                " JOIN "+basedb+".wlyy_patient p ON p. CODE = lb.patient " +
                " JOIN wlyy_specialist_patient_relation s ON s.patient = lb.patient ";
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"s.patient_name","s.health_assistant_name");
        if(StringUtils.isNotBlank(shareDoctor)){
            sql = sql + " JOIN "+basedb+".wlyy_doctor_special_share sp ON s.id = sp.special_code and sp.doctor = '"+shareDoctor+"' ";
        }
        sql = sql +" WHERE s.team_code ='" +teamCode+"' "+
                " AND s.status >=0  AND s.sign_status >0"+
                " LIMIT "+(page-1)*size+","+size;
        System.out.print("日志:"+sql);
        if("7".equals(labelType)){
            sql = "SELECT " +
                    "c.CODE,a.patient_name as name" +
//                    "c.NAME," +
                    ",c.sex," +
                    "IFNULL(YEAR (from_days(datediff(now(),c.birthday))),'未知') age," +
                    "c.photo,b.disease AS label," +
                    "b.disease_name AS labelName," +
                    "d.label_name AS health," +
                    "d.label AS healthcode," +
                    "a.health_assistant AS healthAssistant,a.health_assistant_name AS healthAssistantName," +
//                    "a.health_assistant_name AS healthAssistantName, " +
                    " a.is_manage AS isManage, " +
                    "a.id AS specialCode " +
                    "FROM wlyy_specialist.wlyy_specialist_patient_relation a " +
                    "JOIN "+basedb+".wlyy_patient_disease_server b ON a.id=b.specialist_relation_code AND b.disease=" +labelCode+" and b.del=1 "+
                    "JOIN "+basedb+".wlyy_patient c ON a.patient=c.CODE ";
            if(StringUtils.isNotBlank(shareDoctor)){
                sql = sql + " JOIN "+basedb+".wlyy_doctor_special_share sp ON a.id = sp.special_code and sp.doctor = '"+shareDoctor+"' ";
            }
            sql = sql +"LEFT JOIN "+basedb+".wlyy_sign_patient_label_info d ON a.patient=d.patient AND d.label_type=8 AND d.`status`=1" +
                    " WHERE a.sign_status> 0 AND a.`status`>=0 " +
//                    "AND a.doctor='"+doctor+"' OR a.health_assistant= '"+doctor+
                    " AND a.team_code ='" +teamCode+"' "+
                    " LIMIT "+(page-1)*size+","+size;
            sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"a.patient_name","a.health_assistant_name");
        }
        
        if("pending".equals(labelType)){
            sql = "SELECT " +
                    "c.CODE, a.patient_name as name" +
//                    "c.NAME," +
                    ",c.sex," +
                    "IFNULL(YEAR (from_days(datediff(now(),c.birthday))),'未知') age," +
                    "c.photo," +
                    "a.health_assistant AS healthAssistant,a.health_assistant_name as healthAssistantName" +
//                    "a.health_assistant_name AS healthAssistantName, " +
                    ",a.is_manage AS isManage " +
                    "FROM wlyy_specialist.wlyy_specialist_patient_relation a " +
                    "JOIN "+basedb+".wlyy_patient c ON a.patient=c.CODE " +
                    " WHERE a.sign_status> 0 AND a.`status`>=0 AND (a.is_manage = 0 or a.is_manage is null)" +
                    " AND a.team_code ='" +teamCode+"' "+
                    " LIMIT "+(page-1)*size+","+size;
            sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"a.patient_name","a.health_assistant_name");
        }
        List<PatientLabelVO> PatientLabelVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientLabelVO.class));
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,PatientLabelVOs);
    }
    public MixEnvelop<Long, Long> getLabelpatientCount(String doctor, String labelType, String label, Long teamCode, String shareDoctor){
        String sql = "SELECT " +
                " COUNT(1) as total " +
                " FROM " +
                "   "+basedb+".wlyy_sign_patient_label_info i " +
                "  WHERE " +
                "   i.label = '"+label+"' "+
                "  AND i.label_type = '"+labelType+"' " +
                "  AND i.`status` = '1' " +
                " AND i.patient in ( " +
                " SELECT " +
                " a.patient AS patient " +
                " FROM " +
                " wlyy_specialist_patient_relation a ";
        if(StringUtils.isNotBlank(shareDoctor)){
            sql = sql + " JOIN wlyy.wlyy_doctor_special_share b ON b.special_code = a.id AND b.doctor = '"+shareDoctor+"' ";
        }
        sql = sql+" WHERE " +
                " a.team_code = '"+teamCode+"' " +
                " AND a.STATUS >= 0 " +
                " AND a.sign_status > 0)";
        System.out.print("日志:"+sql);
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,count);
    }
    public MixEnvelop<Long, Long> getAssistantPatientCount(String doctor, String assistant){
        String sql = "SELECT COUNT(1) AS total FROM wlyy_specialist_patient_relation r WHERE r.doctor ='"+doctor+"'  AND r.health_assistant = '"+assistant+"' AND r.status >=0  AND r.sign_status >0";
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,count);
    }
    public MixEnvelop<PatientRelationVO, PatientRelationVO> getDoctorPatientByName(String doctor, String nameKey, String teamCode, Integer page, Integer size){
        String sql ="SELECT " +
                " p.code AS patient,r.patient_name as patientName  " +
//                " p.`name` AS patientName, " +
                " ,p.photo, " +
                " IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
                " p.sex ," +
                " h.label_name as health, " +
                " h.label AS healthcode " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN "+basedb+".wlyy_patient p ON r.patient = p.`code` " +
                " LEFT JOIN ( " +
                " SELECT " +
                "  t.label, " +
                "  t.label_name, " +
                "  t.patient " +
                " FROM " +
                "  "+basedb+".wlyy_sign_patient_label_info t ";
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name");
        String tmpSql = " WHERE " +
                "  t.label_type = '8' " +
                " AND t.`status` = '1' " +
                " ) h ON h.patient = r.patient " +
                " WHERE " +
                " r.doctor IN ( SELECT m.doctor_code FROM wlyy.wlyy_admin_team_member m WHERE m.team_id ='" +teamCode+
                "' ) " +
                " AND r.status >=0  AND r.sign_status >0 " +
                " AND " + "r.patient_name" + " LIKE '%"+nameKey+"%' "+
                " LIMIT "+(page-1)*size+","+size;
        tmpSql = TransforSqlUtl.wlyySpecialistPatientRelationLike(tmpSql,"r.patient_name");
        sql = sql+tmpSql;
        List<PatientRelationVO> patientRelationVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientRelationVO.class));
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientRelationVOs);
    }
    public MixEnvelop<PatientRelationVO, PatientRelationVO> getDoctorPatientByNameOrIdCard(String doctor, String filter, String teamCode, Integer page, Integer size){
        String sql ="SELECT " +
                " p.code AS code,p.code patient,r.patient_name as patientName, " +
                " p.name AS name " +
                " ,p.photo, " +
                " IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
                " p.sex ," +
                " p.idcard ," +
                " h.label_name as health, " +
                " h.label AS healthcode " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN "+basedb+".wlyy_patient p ON r.patient = p.`code` " +
                " LEFT JOIN ( " +
                " SELECT " +
                "  t.label, " +
                "  t.label_name, " +
                "  t.patient " +
                " FROM " +
                "  "+basedb+".wlyy_sign_patient_label_info t " ;
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name");
        String sqlTmp=  " WHERE " +
                "  t.label_type = '8' " +
                " AND t.`status` = '1' " +
                " ) h ON h.patient = r.patient " +
                " WHERE " +
                " r.doctor IN ( SELECT m.doctor_code FROM wlyy.wlyy_admin_team_member m WHERE m.team_id ='" +teamCode+
                "' ) " +
                " AND r.status >=0  AND r.sign_status >0 " +
                " AND (" +  "r.patient_name"  + " LIKE '%"+filter+"%' OR p.idcard LIKE '%"+filter+"%') "+
                " LIMIT "+(page-1)*size+","+size;
        sqlTmp = TransforSqlUtl.wlyySpecialistPatientRelationLike(sqlTmp,"r.patient_name");
        sql = sql+sqlTmp;
        List<PatientRelationVO> patientRelationVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientRelationVO.class));
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientRelationVOs);
    }
    public MixEnvelop<PatientRelationVO, PatientRelationVO> findPatientNoAssistant(String doctor, Integer page, Integer size){
        String sqlTotal ="SELECT " +
                " COUNT(1) AS total" +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN "+basedb+".wlyy_patient p ON r.patient = p.`code` " +
                " JOIN ( " +
                " SELECT " +
                "  t.label, " +
                "  t.label_name, " +
                "  t.patient " +
                " FROM " +
                "  "+basedb+".wlyy_sign_patient_label_info t " +
                " WHERE " +
                "  t.label_type = '8' " +
                " AND t.`status` = '1' " +
                " ) h ON h.patient = r.patient " +
                " WHERE " +
                " r.doctor='"+doctor+"' " +
                " AND r.status >=0  AND r.sign_status >0" +
                " AND r.health_assistant IS NULL ";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sqlTotal);
        Long total = 0L;
        if(list!=null&&list.size()>0){
            total =  (Long) list.get(0).get("total");
        }
        String sql ="SELECT " +
                " p.code AS patient ,r.patient_name as patientName" +
                //AesEncryptUtils.decryptMysql("r.patient_name","patientName") +
//                " p.`name` AS patientName, " +
                " ,p.photo, " +
                " IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
                " p.sex, " +
                " h.label_name as health, " +
                " h.label AS healthcode " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN "+basedb+".wlyy_patient p ON r.patient = p.`code` " +
                " JOIN ( " +
                " SELECT " +
                "  t.label, " +
                "  t.label_name, " +
                "  t.patient " +
                " FROM " +
                "  "+basedb+".wlyy_sign_patient_label_info t " +
                " WHERE " +
                "  t.label_type = '8' " +
                " AND t.`status` = '1' " +
                " ) h ON h.patient = r.patient " +
                " WHERE " +
                " r.doctor='"+doctor+"' " +
                " AND r.status >=0  AND r.sign_status >0 " +
                " AND r.health_assistant IS NULL "+
                " LIMIT "+(page-1)*size+","+size;
        sql  = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name");
        List<PatientRelationVO> patientRelationVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientRelationVO.class));
        return MixEnvelop.getSuccessList(SpecialistMapping.api_success,patientRelationVOs,total.intValue());
    }
    public MixEnvelop<SpecialistTeamVO, SpecialistTeamVO> signSpecialistTeam(String patient, String patientName, String doctor, String doctorName, Long teamCode){
        //1.查询该居民是否已经与该专科医生签约
        String checkDoctorSql = "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 AS teamCode, " +
                " t.`name`, " +
                " d.photo ," +
                " d.code AS doctor, r.doctor_name as doctorName" +
               // AesEncryptUtils.decryptMysql("r.doctor_name","doctorName") +
//                " d.name AS doctorName" +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN "+basedb+".wlyy_admin_team t ON t.id = r.team_code " +
                " JOIN "+basedb+".wlyy_doctor d ON d. CODE = r.doctor " +
                " WHERE " +
                " r.patient = '"+patient+"' " +
                " AND r.doctor = '"+doctor+"' " +
                " AND r.`status` >= 0 " +
                " AND r.sign_status >=0 " +
                " AND t.available = '1' ";
        checkDoctorSql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(checkDoctorSql,"r.patient_name","r.doctor_name");
        List<SpecialistTeamVO> specialistTeamVOs = jdbcTemplate.query(checkDoctorSql,new BeanPropertyRowMapper(SpecialistTeamVO.class));
        if(specialistTeamVOs!=null&&specialistTeamVOs.size()>0){
            for(SpecialistTeamVO specialistTeamVO:specialistTeamVOs){
                List<AdminTeamMemberVO> adminTeamMemberVOs = findTeamMember(specialistTeamVO.getTeamCode());
                specialistTeamVO.setMembers(adminTeamMemberVOs);
            }
            return MixEnvelop.getSuccess(SpecialistMapping.doctor_exist,specialistTeamVOs.get(0));
        }
        //验证团队是否已经签约
        String checkTeamSql = "SELECT " +
                " r.id AS relationCode," +
                " r.patient ,r.patient_name as patientName" +
//                " r.patient_name AS patientName, " +
                " ,r.team_code AS teamCode, " +
                " t.`name`, " +
                " d.photo " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN "+basedb+".wlyy_admin_team t ON t.id = r.team_code " +
                " JOIN "+basedb+".wlyy_doctor d ON d. CODE = r.doctor " +
                " WHERE " +
                " r.patient = '"+patient+"' " +
                " AND r.team_code = " +teamCode+
                " AND r.`status` >=0 " +
                " AND r.sign_status >=0 " +
                " AND t.available = '1' ";
        checkTeamSql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(checkTeamSql,"r.patient_name");
        List<SpecialistTeamVO> teamVOs = jdbcTemplate.query(checkTeamSql,new BeanPropertyRowMapper(SpecialistTeamVO.class));
        if(teamVOs!=null&&teamVOs.size()>0){
            for(SpecialistTeamVO specialistTeamVO:teamVOs){
                List<AdminTeamMemberVO> adminTeamMemberVOs = findTeamMember(specialistTeamVO.getTeamCode());
                specialistTeamVO.setMembers(adminTeamMemberVOs);
            }
            return MixEnvelop.getSuccess(SpecialistMapping.team_exist,teamVOs.get(0));
        }
        //存储签约关系
        SpecialistPatientRelationDO relation = new SpecialistPatientRelationDO();
        relation.setDoctor(doctor);
        relation.setDoctorName(doctorName);
        relation.setPatient(patient);
        relation.setPatientName(patientName);
        relation.setTeamCode(teamCode.intValue());
        relation.setStatus("0");
        relation.setSignStatus("0");
        relation.setUpdateTime(new Date());
        relation.setCreateTime(new Date());
        relation.setUpdateTime(new Date());
        SpecialistPatientRelationDO relationDO = specialistPatientRelationDao.save(relation);
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,relationDO.getId());
    }
    public List<AdminTeamMemberVO> findTeamMember(Long teamId){
        String menberSql = "SELECT " +
                " m.doctor_code AS doctorCode ," +
                        " d.`name` AS doctorName " +
                " FROM " +
                " "+basedb+".wlyy_admin_team_member m " +
                " JOIN "+basedb+".wlyy_doctor d ON m.doctor_code = d.`code` " +
                " WHERE  " +
                " m.available='1' " +
                " AND m.team_id="+teamId;
        return jdbcTemplate.query(menberSql,new BeanPropertyRowMapper(AdminTeamMemberVO.class));
    }
    public MixEnvelop<Boolean, Boolean> agreeSpecialistTeam(String state, String relationCode, String remark, String health_assistant, String health_assistant_name){
        SpecialistPatientRelationDO relation = specialistPatientRelationDao.findById(relationCode).orElse(null);
        if("0".equals(state)){
            relation.setSignStatus("-2");
            relation.setStatus("-1");
            relation.setRemark(remark);
            specialistPatientRelationDao.save(relation);
        }else{
            relation.setSignStatus("1");
            relation.setHealthAssistant(health_assistant);
            relation.setHealthAssistantName(health_assistant_name);
            relation.setSignDate(new Date());
            specialistPatientRelationDao.save(relation);
            //签约成功之后,将签约关系保存在redis中
            String key = "specialist_patient_relation:" + relation.getPatient() +"_"+ ":text";
            redisTemplate.opsForValue().set(key,"true");
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,relation);
    }
    public MixEnvelop<PatientSignInfoVO, PatientSignInfoVO> findPatientSigninfo(String code){
        String sql = "SELECT " +
                " r.patient ,r.patient_name as patientName" +
               // AesEncryptUtils.decryptMysql("r.patient_name","patientName") +
//                " r.patient_name AS patientName, " +
                " ,r.doctor ,r.doctor_name as doctorName" +
                //AesEncryptUtils.decryptMysql("r.doctor_name","doctorName") +
//                " r.doctor_name AS doctorName, " +
                " ,d.hospital, " +
                " d.hospital_name AS hospitalName, " +
                " d.photo, " +
                " d.dept, " +
                " d.dept_name AS deptName, " +
                " t.`name` AS teamName, " +
                " t.id As teamCode, " +
                " r.create_time AS createTime," +
                " r.status," +
                " r.sign_status AS signStatus,  " +
                " r.team_code AS teamCode  " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN "+basedb+".wlyy_doctor d ON r.doctor = d.code " +
                " JOIN "+basedb+".wlyy_admin_team t ON t.id = r.team_code " +
                " WHERE " +
                " r.id = '"+code+"'";
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name","r.doctor_name");
        List<PatientSignInfoVO> patientSignInfoVOs = jdbcTemplate.query(sql, new BeanPropertyRowMapper(PatientSignInfoVO.class));
        PatientSignInfoVO patientSignInfoVO = (null != patientSignInfoVOs && patientSignInfoVOs.size() > 0 ? patientSignInfoVOs.get(0) : new PatientSignInfoVO());
        return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientSignInfoVO);
    }
    public MixEnvelop<SpecialistTeamVO, SpecialistTeamVO> findPatientTeamList(String patient){
        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  " +
                " JOIN "+basedb+".wlyy_admin_team t ON t.id = r.team_code " +
                " JOIN "+basedb+".wlyy_doctor d ON t.leader_code = d.`code` " +
                " JOIN "+basedb+".wlyy_doctor md ON md.code = r.doctor " +
                " WHERE " +
                " r.patient = '"+patient+"' " +
                " AND r.`status` >=0  " +
                " AND r.sign_status >0";
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name");
        List<SpecialistTeamVO> specialistTeamVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistTeamVO.class));
        if(specialistTeamVOs!=null&&specialistTeamVOs.size()>0){
            for(SpecialistTeamVO specialistTeamVO:specialistTeamVOs){
                List<AdminTeamMemberVO> adminTeamMemberVOs = findTeamMember(specialistTeamVO.getTeamCode());
                specialistTeamVO.setMembers(adminTeamMemberVOs);
            }
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,specialistTeamVOs);
    }
    public MixEnvelop findPatientSignSpecialist(String patient){
        String sql = "SELECT " +
                " r.id AS relationCode, " +
                " r.patient, " +
                " r.team_code AS teamCode,r.patient_name as patientName" +
               // AesEncryptUtils.decryptMysql("r.patient_name","patientName") +
//                " r.patient_name AS patientName, " +
//                " d.name AS doctorName, " +
                ",d.name as doctorName"+
               // AesEncryptUtils.decryptMysql("d.name","doctorName") +
                " ,d.code AS doctor, " +
                " d.photo, " +
                " d.dept, " +
                " d.dept_name AS deptName, " +
                " d.job_name AS job, " +
                " d.sex AS sex, " +
                " d.hospital, " +
                " d.hospital_name AS hospital_name, " +
                " d.`level` " +
                " FROM " +
                " wlyy_specialist_patient_relation r " +
                " JOIN "+basedb+".wlyy_doctor d ON r.doctor = d.`code` " +
                " WHERE  " +
                " r.patient ='"+patient+"' " +
                " AND r.`status`>=0 " +
                " AND r.sign_status >0";
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name");
        List<PatientSignInfoVO> patientSignInfoVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientSignInfoVO.class));
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientSignInfoVOs);
    }
    public MixEnvelop findPatientSignSpecialistInfo(String patient, String doctor){
        String sql = "SELECT p.idcard, " +
                "p.ssc, " +
                "r.*  FROM " +
                "(SELECT " +
                " r.id AS relationCode," +
                " r.patient, " +
                " r.team_code AS teamCode,r.patient_name as patientName" +
               // AesEncryptUtils.decryptMysql("r.patient_name","patientName") +
                " ,r.health_assistant AS healthAssistant,r.health_assistant_name as healthAssistantName" +
                //AesEncryptUtils.decryptMysql("r.health_assistant_name","healthAssistantName") +
                " ,r.create_time AS createTime," +
//                AesEncryptUtils.decryptMysql("d.name","doctorName") +
                " d.name AS doctorName, " +
                " ,d.code AS doctor, " +
                " d.photo, " +
                " d.dept, " +
                " d.dept_name AS deptName, " +
                " d.hospital, " +
                " d.hospital_name AS hospital_name, " +
                " r.id AS specialCode, " +
                " d.`level` " +
                " FROM " +
                " wlyy_specialist.wlyy_specialist_patient_relation r " +
                " JOIN "+basedb+".wlyy_doctor d ON r.doctor = d.`code` " +
                " WHERE  " +
                " r.patient ='"+patient+"' " +
                " AND r.doctor in" +
                " (SELECT m.doctor_code FROM  wlyy.wlyy_admin_team_member m where m.team_id in  " +
                "  (SELECT dt.id FROM  wlyy.wlyy_admin_team dt LEFT JOIN  wlyy.wlyy_admin_team_member watm ON dt.id=watm.team_id  " +
                "  WHERE dt.available='1' AND watm.available='1' AND watm.doctor_code='"+doctor+"') AND  m.available='1')" +
//                " AND r.`status`>=0 " +
                " AND r.sign_status >0 ) r join "+basedb+".wlyy_patient p on r.patient = p.code order by p.czrq DESC ";
        sql = TransforSqlUtl.wlyySpecialistPatientRelationReplay(sql,"r.patient_name","r.health_assistant_name");
        List<PatientSignInfoVO> patientSignInfoVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientSignInfoVO.class));
        PatientSignInfoVO patientSignInfoVO = (null != patientSignInfoVOs && patientSignInfoVOs.size() > 0 )? patientSignInfoVOs.get(0):null;
        return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientSignInfoVO);
    }
    
    public MixEnvelop findDoctorAndDoctorHealthBySpecialDoctor(String doctor, String name) {
    
        String sql = "";
        
        if(StringUtils.isNotBlank(name)){
            sql = "SELECT " +
                    "doctor.CODE AS CODE" +
//                    AesEncryptUtils.decryptMysql("doctor.name","name") +
                    ",doctor.NAME AS NAME" +
                    ",doctor.sex AS sex," +
                    "doctor.birthday AS birthday," +
                    "doctor.photo AS photo," +
                    "doctor.mobile AS mobile," +
                    "doctor.hospital AS hospital," +
                    "doctor.hospital_name AS hospitalName," +
                    "doctor.dept AS dept," +
                    "doctor.dept_name AS deptName," +
                    "doctor.job AS job," +
                    "doctor.job_name AS jobName," +
                    "doctor.LEVEL AS LEVEL," +
                    "doctor.qrcode AS qrcode," +
                    "doctor.czrq AS czrq," +
                    "doctor.del AS del," +
                    "doctor.idcard AS idcard " +
                    "FROM wlyy.wlyy_doctor doctor JOIN ( " +
                    "SELECT a.doctor AS doctorcode FROM wlyy.wlyy_sign_family a RIGHT JOIN ( " +
                    "SELECT patient FROM wlyy_specialist_patient_relation WHERE sign_status> 0 AND `status`>=0 AND doctor='"+doctor+"') b ON a.patient=b.patient WHERE a.`status`=1 AND a.expenses_status = 1 " +
                    "UNION  " +
                    "SELECT a.doctor_health AS doctorcode FROM wlyy.wlyy_sign_family a RIGHT JOIN ( " +
                    "SELECT patient FROM wlyy_specialist_patient_relation WHERE sign_status> 0 AND `status`>=0 AND doctor='"+doctor+"') b ON a.patient=b.patient WHERE a.`status`=1 AND a.expenses_status = 1 " +
                    ") " +
                    "t ON doctor.CODE=t.doctorcode and doctor.NAME like '%"+name+"%'";
        }else{
            sql = "SELECT " +
                    "doctor.CODE AS CODE" +
//                    AesEncryptUtils.decryptMysql("doctor.name","name") +
                    ",doctor.NAME AS NAME" +
                    ",doctor.sex AS sex," +
                    "doctor.birthday AS birthday," +
                    "doctor.photo AS photo," +
                    "doctor.mobile AS mobile," +
                    "doctor.hospital AS hospital," +
                    "doctor.hospital_name AS hospitalName," +
                    "doctor.dept AS dept," +
                    "doctor.dept_name AS deptName," +
                    "doctor.job AS job," +
                    "doctor.job_name AS jobName," +
                    "doctor.LEVEL AS LEVEL," +
                    "doctor.qrcode AS qrcode," +
                    "doctor.czrq AS czrq," +
                    "doctor.del AS del," +
                    "doctor.idcard AS idcard " +
                    "FROM wlyy.wlyy_doctor doctor JOIN ( " +
                    "SELECT a.doctor AS doctorcode FROM wlyy.wlyy_sign_family a RIGHT JOIN ( " +
                    "SELECT patient FROM wlyy_specialist_patient_relation WHERE sign_status> 0 AND `status`>=0 AND doctor='"+doctor+"') b ON a.patient=b.patient WHERE a.`status`=1 AND a.expenses_status = 1 " +
                    "UNION  " +
                    "SELECT a.doctor_health AS doctorcode FROM wlyy.wlyy_sign_family a RIGHT JOIN ( " +
                    "SELECT patient FROM wlyy_specialist_patient_relation WHERE sign_status> 0 AND `status`>=0 AND doctor='"+doctor+"') b ON a.patient=b.patient WHERE a.`status`=1 AND a.expenses_status = 1 " +
                    ") " +
                    "t ON doctor.CODE=t.doctorcode";
        }
        
        List<SignFamilyDoctorVO> patientSignInfoVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignFamilyDoctorVO.class));
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientSignInfoVOs);
    }
    
    public MixEnvelop<Long,Long> findSpecialistSignFamilyPatientCout(String specialdoctor, String familydoctor) {
    
        String sql = "SELECT count(1) AS total " +
                "FROM wlyy.wlyy_sign_family a WHERE a.`status`=1 AND a.expenses_status=1 " +
                "AND patient IN (" +
                "SELECT patient FROM wlyy_specialist.wlyy_specialist_patient_relation WHERE sign_status> 0 AND `status`>=0 " +
                "AND doctor='"+specialdoctor+"') " +
                "AND (a.doctor='"+familydoctor+"' OR a.doctor_health='"+familydoctor+"') ";
    
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sql);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,count);
    }
    
    public MixEnvelop<PatientRelationVO, PatientRelationVO> getSpecialistSignFamilyPatientByName(String specialdoctor, String familydoctor, String nameKey, Integer page, Integer size) {
        String sql ="SELECT " +
                "p.CODE AS patient" +
//                AesEncryptUtils.decryptMysql("p.name","patientName") +
                ",p.`name` AS patientName" +
                ",p.photo," +
                "IFNULL(YEAR (from_days(datediff(now(),p.birthday))),'未知') age," +
                "p.sex " +
                "FROM wlyy.wlyy_patient p " +
                "JOIN ( " +
                " SELECT a.patient FROM wlyy.wlyy_sign_family a WHERE patient IN (" +
                "  SELECT patient FROM wlyy_specialist_patient_relation WHERE sign_status> 0 AND `status`>=0 " +
                "  AND doctor='"+specialdoctor+"') " +
                "  AND (a.doctor='"+familydoctor+"' OR a.doctor_health='"+familydoctor+"') ";
        if(StringUtils.isNotBlank(nameKey)){
            sql= sql + " AND  a.name LIKE '%"+nameKey+"%' ";
//            sql= sql + " AND " + AesEncryptUtils.decryptMysqlNo("a.name") + " LIKE '%"+nameKey+"%' ";
        }
        sql= sql +" AND a.`status`=1 AND a.expenses_status=1) s ON p.CODE=s.patient" +
                " LIMIT "+(page-1)*size+","+size;
    
        List<PatientRelationVO> patientRelationVOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(PatientRelationVO.class));
    
        return MixEnvelop.getSuccess(SpecialistMapping.api_success,patientRelationVOs);
    }
    public MixEnvelop getPatientAndDiseaseByDoctor(String doctor, String patientInfo, String disease, Integer page, Integer size) {
        String sql = "SELECT s.*, " +
                "p.idcard, " +
                "case p.sex WHEN 1 then '男' ELSE '女' END as sex, " +
                "IFNULL(year( from_days( datediff( now(), p.birthday))),'未知') age, " +
                "p.birthday, " +
                "p.photo " +
//                "FROM (SELECT s.disease,s.disease_name,s.patient" + AesEncryptUtils.decryptMysql("s.patient_name","patient_name") + ",r.team_code from " +
                "FROM (SELECT s.disease,s.disease_name,s.patient s.patient_name,r.team_code from " +
                "(SELECT id, team_code FROM wlyy_specialist_patient_relation WHERE doctor='" + doctor + "' and sign_status > 0 and `status` >= 0) r " +
                "JOIN "+basedb+".wlyy_patient_disease_server s on r.id = s.specialist_relation_code WHERE s.del = 1) s " +
                "JOIN "+basedb+".wlyy_patient p on s.patient = p.`code` where p.`status` >0 ";
        if(StringUtils.isNotBlank(patientInfo)){
            sql += " and p.idcard like '%"+ patientInfo +"%' or patient_name  like '%" + patientInfo + "%'";
        }
        if(StringUtils.isNotBlank(disease)){
            sql = sql.replace("WHERE s.del = 1", "WHERE s.del = 1 and s.disease = '" + disease + "'");
        }
        sql += "ORDER BY p.czrq DESC LIMIT "+(page-1)*size+","+size;
        List<PatientDisseaseInfoVO> patientDisseaseInfoVO = jdbcTemplate.query(sql, new BeanPropertyRowMapper(PatientDisseaseInfoVO.class));
        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success, patientDisseaseInfoVO, page, size, (long) patientDisseaseInfoVO.size());
    }
    /**
     * 专科-模糊搜索注册居民(未与该医生所在团队医生签约的居民)
     * @param doctorCode
     * @param keywords
     */
    public MixEnvelop searchPatientInSpecialist(String doctorCode, String keywords, Integer page, Integer pageSize) throws Exception{
        String sql1 = " select count(1) as num ";
        String sql2 = " select p.name as name,p.idcard,p.code,p.photo ";
        String whereSql ="";
        if(!StringUtils.isEmpty(keywords)){
//            whereSql+=" and (p.name like '%"+keywords+"%' or p.idcard like '%"+keywords+"%' or p.mobile like '%"+keywords+"%') ";
            whereSql+=" and  p.mobile ='"+keywords+"'";
        }
        String centerSql =" from "+basedb+".wlyy_patient p  " +
                " WHERE p.code not in (SELECT r.patient FROM  wlyy_specialist.wlyy_specialist_patient_relation r WHERE r.sign_status = '1' " +
                " AND doctor in (SELECT m.doctor_code FROM  "+basedb+".wlyy_admin_team_member m where m.team_id in " +
                " (SELECT dt.id FROM  "+basedb+".wlyy_admin_team dt LEFT JOIN  "+basedb+".wlyy_admin_team_member watm ON dt.id=watm.team_id " +
                " WHERE dt.available='1' AND watm.available='1' AND watm.doctor_code='"+doctorCode+"') AND  m.available='1'))"
                +" AND p.openid IS NOT NULL "+
               whereSql;
        String countCenterSql =" from "+basedb+".wlyy_patient p " +
                " WHERE p.code not in (SELECT r.patient FROM  wlyy_specialist.wlyy_specialist_patient_relation r WHERE r.sign_status = '1'" +
                " AND doctor in (SELECT m.doctor_code FROM  "+basedb+".wlyy_admin_team_member m where m.team_id in " +
                " (SELECT dt.id FROM  "+basedb+".wlyy_admin_team dt LEFT JOIN  "+basedb+".wlyy_admin_team_member watm ON dt.id=watm.team_id " +
                " WHERE dt.available='1' AND watm.available='1' AND watm.doctor_code='"+doctorCode+"') AND  m.available='1'))"
                +" AND p.openid IS NOT NULL "+
                whereSql;
        String sqlCount=sql1+countCenterSql;
        String sql=sql2+centerSql+" LIMIT "+(page-1)*pageSize+","+pageSize;
        List<Map<String,Object>> map = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>> countMap = jdbcTemplate.queryForList(sqlCount);
        List<Map<String,Object>> resultList = new ArrayList<>();
        Map m = null;
        Integer age = null;
        String sex = null;
        String sexName="";
        for(Map<String,Object> one:map){
            StringBuffer statusSql =new StringBuffer( " select CASE WHEN wsf.status ='-4' THEN '已到期' WHEN wsf.status ='0' THEN '待签约' WHEN wsf.status ='1' THEN '已签约' WHEN wsf.status ='2' THEN '已签约' WHEN wsf.status ='3' THEN '已签约' ELSE '待签约' END  status  ");
            statusSql.append("FROM wlyy.wlyy_sign_family wsf, (SELECT patient,Max(apply_date) applyDate FROM wlyy.wlyy_sign_family WHERE type = '2' AND patient='"+one.get("code")+"' GROUP BY patient) temp WHERE wsf.patient=temp.patient AND wsf.apply_date=temp.applyDate");
            List<Map<String,Object>> strMap= jdbcTemplate.queryForList(statusSql.toString());
            m = new HashMap();
            age = IdCardUtil.getAgeForIdcard(one.get("idcard")+"");
            sex = IdCardUtil.getSexForIdcard_new(one.get("idcard")+"");
            m.put("name",one.get("name"));
            m.put("age",age);
            m.put("sex",sex);
            m.put("status", !(null != strMap && strMap.size() > 0) ? "待签约" : strMap.get(0).get("status"));
            if("1".equals(sex)){
                sexName="男";
            }else if("2".equals(sex)){
                sexName="女";
            }else{
                sexName="未知";
            }
            m.put("sexName",sexName);
            m.put("patientCode",one.get("code"));
            m.put("photo",one.get("photo"));
            resultList.add(m);
        }
        Long co=Long.parseLong("100");
        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,resultList,page,pageSize,countMap.size()>0?Long.valueOf(countMap.get(0).get("num")+""):0);
//        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,resultList,page,pageSize,co);
    }
    /**
     * 病人的家签信息、专科开通信息
     * @param doctorCode 医生code
     * @param patientCode 病人id
     * @param signStatus 签约状态,待审核:0;未签约:-1
     */
    public JSONObject doctorForSpecialistInfo(String signStatus,String doctorCode, String patientCode)  throws Exception{
        JSONObject jsonObject = new JSONObject();
        SpecialistPatientRelationDO specialistPatientRelationDO = new SpecialistPatientRelationDO();
        //待审核
        if ("0".equals(signStatus)) {
            specialistPatientRelationDO = specialistPatientRelationDao.findByDoctorAndPatient(doctorCode, patientCode);
        }
        //1、获取居民基础信息
        String preSql = "SELECT p.name as name, p.photo as photo,p.idcard as idcard,p.mobile as mobile,p.medicare_number as medicareNumber,p.ssc as ssc," +
                " CASE  WHEN wd.name is null THEN '无' ELSE wd.name END as doctorName,CASE  WHEN wd.hospital_name is NULL THEN '无' ELSE wd.hospital_name END as hospitalName,CASE  WHEN wd.mobile is NULL THEN '无' ELSE wd.mobile END as doctorMobole ";
        String patientSql = " from " + basedb + ".wlyy_patient p LEFT JOIN " + basedb + ".wlyy_sign_family wsf " +
                " ON p.code=wsf.patient AND wsf.type='2' AND wsf.status='1' " +
                " LEFT JOIN " + basedb + ".wlyy_doctor wd ON wsf.doctor =wd.code WHERE p.code='" + patientCode + "'";
        //一个居民 生效的家签信息只会有一条
        Map<String, Object> map = jdbcTemplate.queryForMap(preSql + patientSql);
        map.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard")+""));
        String sexCode= IdCardUtil.getSexForIdcard_new(map.get("idcard")+"");
        String sexName="";
        if("1".equals(sexCode)){
            sexName="男";
        }else if("2".equals(sexCode)){
            sexName="女";
        }else{
            sexName="未知";
        }
        map.put("sex",sexName);
        jsonObject.put("patientInfo", map);
        //2、获取医生信息(所属医院、科室、姓名)
        String doctorSql = "SELECT wd.hospital_name as hospitalName,wd.dept_name as deptName,wd.name as name FROM " + basedb + ".wlyy_doctor wd WHERE wd.code='" + doctorCode + "'";
        jsonObject.put("doctorInfo", jdbcTemplate.queryForMap(doctorSql));
        //3、获取该医生所属团队及团队成员信息
        String teamSql = "SELECT at.name teamName, tm.team_id , tm.doctor_code, wd.NAME as doctorName  FROM " + basedb + ".wlyy_doctor wd LEFT JOIN  " + basedb + ".wlyy_admin_team_member tm ON wd. CODE = tm.doctor_code, " + basedb + ".wlyy_admin_team at " +
                "WHERE tm.team_id IN ( SELECT watm.team_id teamId FROM  " + basedb + ".wlyy_admin_team_member watm WHERE watm.doctor_code ='" + doctorCode + "'" + " AND watm.available = '1' ) AND tm.available='1' AND `at`.id=tm.team_id";
        List<Map<String, Object>> teamList = jdbcTemplate.queryForList(teamSql);
        Map<Integer, List<Map<String, Object>>> m = teamList.stream().collect(Collectors.groupingBy(tem -> ((Integer) tem.get("team_id")).intValue(), Collectors.toList()));
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (Integer i : m.keySet()) {
            Map<String, Object> objectMap = new HashMap<>();
            objectMap.put("teamId", i);
            objectMap.put("teamName", m.get(i).get(0).get("teamName"));
            objectMap.put("teamDoctors", m.get(i));
            //获取专科团队疾病标签
           String disSql = "SELECT wtdr.disease_code, wtdr.disease_name from  wlyy.wlyy_team_disease_relation wtdr WHERE wtdr.team_code ='" + i + "'" +"  AND wtdr.del='1'";
            //new BeanPropertyRowMapper(
            List<Map<String, Object>>  stringList = jdbcTemplate.queryForList(disSql);
            String areaSql = "SELECT wpds.disease FROM wlyy.wlyy_patient_disease_server wpds WHERE wpds.patient='" + patientCode + "'" + " AND wpds.del='1'";
            List<String> signDiseaseList = jdbcTemplate.queryForList(areaSql,String.class);
            Set<String> stringSet =new HashSet<>(signDiseaseList);
//            stringSet.addAll(new HashSet<>(signDiseaseList));
            //已签约的疾病状态改成1
            stringList.stream().forEach(item->{
                item.put("status",stringSet.contains( item.get("disease_code"))?1:0) ;
            });
            objectMap.put("teamDisease", stringList);
            mapList.add(objectMap);
        }
        jsonObject.put("teamAndDoctors", mapList);
        //康复情况标签
        String labelSql = "SELECT wspl.label_code,wspl.label_name from  wlyy.wlyy_sign_patient_label wspl WHERE wspl.label_type='8' AND status='1'";
        List<Map<String, Object>> signPatientLabelList = jdbcTemplate.queryForList(labelSql);
        jsonObject.put("signPatientLabels", signPatientLabelList);
        return jsonObject;
    }
    /**
     * 病人的家签信息、专科开通信息
     * @param doctorCode 医生code
     * @param patientCode 病人id
     * @param signStatus 签约状态,待审核:0;未签约:-1
     */
    public JSONObject doctorForSpecialistInfoNew(String signStatus,String doctorCode, String patientCode)  throws Exception{
        JSONObject jsonObject = new JSONObject();
        SpecialistPatientRelationDO specialistPatientRelationDO = new SpecialistPatientRelationDO();
        //待审核
        if ("0".equals(signStatus)) {
            specialistPatientRelationDO = selectByDoctorAndPatient(doctorCode, patientCode);
        }
        jsonObject.put("specialistPatientRelationId", null == specialistPatientRelationDO ? null : specialistPatientRelationDO.getId());
        jsonObject.put("signCertificate", null == specialistPatientRelationDO ? null : specialistPatientRelationDO.getSignCertificate());
        //1、获取居民基础信息
        String preSql = "SELECT p.name as name, p.photo as photo,p.idcard as idcard,p.mobile as mobile,p.medicare_number as medicareNumber,p.ssc as ssc," +
                " CASE  WHEN wd.name is null THEN '无' ELSE wd.name END as doctorName,CASE  WHEN wd.hospital_name is NULL THEN '无' ELSE wd.hospital_name END as hospitalName,CASE  WHEN wd.mobile is NULL THEN '无' ELSE wd.mobile END as doctorMobole ";
        String patientSql = " from " + basedb + ".wlyy_patient p LEFT JOIN " + basedb + ".wlyy_sign_family wsf " +
                " ON p.code=wsf.patient AND wsf.type='2' AND wsf.status='1' " +
                " LEFT JOIN " + basedb + ".wlyy_doctor wd ON wsf.doctor =wd.code WHERE p.code='" + patientCode + "'";
        //一个居民 生效的家签信息只会有一条
        Map<String, Object> map = jdbcTemplate.queryForMap(preSql + patientSql);
        map.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard")+""));
        String sexCode= IdCardUtil.getSexForIdcard_new(map.get("idcard")+"");
        String sexName="";
        if("1".equals(sexCode)){
            sexName="男";
        }else if("2".equals(sexCode)){
            sexName="女";
        }else{
            sexName="未知";
        }
        map.put("sex",sexName);
        jsonObject.put("patientInfo", map);
        //2、获取医生信息(所属医院、科室、姓名)
        String doctorSql = "SELECT wd.hospital_name as hospitalName,wd.dept_name as deptName,wd.name as name FROM " + basedb + ".wlyy_doctor wd WHERE wd.code='" + doctorCode + "'";;
        if("0".equals(signStatus)){
            doctorSql="SELECT wd.hospital_name as hospitalName,wd.dept_name as deptName,wd.name as name FROM " + basedb + ".wlyy_doctor wd WHERE wd.code='" + specialistPatientRelationDO.getDoctor() + "'";
        }
        Map<String,Object> result =jdbcTemplate.queryForMap(doctorSql);
        if ("0".equals(signStatus) && !(doctorCode.equals(specialistPatientRelationDO.getDoctor()))) {
            result.put("buttonShowFlag", false);
        } else {
            result.put("buttonShowFlag",true);
        }
        jsonObject.put("doctorInfo", result);
        //3、获取该医生所属团队及团队成员信息
        String teamSql = "SELECT at.name teamName, tm.team_id , tm.doctor_code, wd.NAME as doctorName  FROM " + basedb + ".wlyy_doctor wd LEFT JOIN  " + basedb + ".wlyy_admin_team_member tm ON wd. CODE = tm.doctor_code, " + basedb + ".wlyy_admin_team at " +
                "WHERE tm.team_id IN ( SELECT watm.team_id teamId FROM  " + basedb + ".wlyy_admin_team_member watm WHERE watm.doctor_code ='" + doctorCode + "'" + " AND watm.available = '1' ) AND tm.available='1' AND `at`.id=tm.team_id";
        List<Map<String, Object>> teamList = jdbcTemplate.queryForList(teamSql);
        Map<Integer, List<Map<String, Object>>> m = teamList.stream().collect(Collectors.groupingBy(tem -> ((Integer) tem.get("team_id")).intValue(), Collectors.toList()));
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (Integer i : m.keySet()) {
            Map<String, Object> objectMap = new HashMap<>();
            if ("0".equals(signStatus) && i.equals(specialistPatientRelationDO.getTeamCode())) {
                objectMap.put("checkFlag", true);
            } else {
                objectMap.put("checkFlag", false);
            }
            objectMap.put("teamId", i);
            objectMap.put("teamName", m.get(i).get(0).get("teamName"));
            objectMap.put("teamDoctors", m.get(i));
            //获取专科团队疾病标签
            String disSql = "SELECT wtdr.disease_code, wtdr.disease_name from  wlyy.wlyy_team_disease_relation wtdr WHERE wtdr.team_code ='" + i + "'" +"  AND wtdr.del='1'";
            //new BeanPropertyRowMapper(
            List<Map<String, Object>>  stringList = jdbcTemplate.queryForList(disSql);
            String areaSql = "SELECT wpds.disease FROM wlyy.wlyy_patient_disease_server wpds WHERE wpds.patient='" + patientCode + "'" + " AND wpds.del='1'";
            List<String> signDiseaseList = jdbcTemplate.queryForList(areaSql,String.class);
            Set<String> stringSet =new HashSet<>(signDiseaseList);
            List<String> speciaSignDiseaseList = new ArrayList<>();
            if("0".equals(signStatus) ){
                String speciaSignSql = "SELECT wpds.disease FROM wlyy.wlyy_patient_disease_server wpds WHERE wpds.patient='" + patientCode + "'" + " AND wpds.del='1' and wpds.specialist_relation_code='" + specialistPatientRelationDO.getId() + "'";
                speciaSignDiseaseList = jdbcTemplate.queryForList(speciaSignSql,String.class);
            }
            Set<String> speciaSignSet =new HashSet<>(speciaSignDiseaseList);
            //已签约的疾病状态改成1
            stringList.stream().forEach(item->{
                int status=0;
                if(stringSet.contains( item.get("disease_code"))){
                    //已签约过的疾病
                    status=1;
                }
                if(null!=speciaSignSet&& speciaSignSet.contains(item.get("disease_code"))){
                    //本次专病签约的疾病
                    status=2;
                }
                item.put("status",status) ;
            });
            objectMap.put("teamDisease", stringList);
            mapList.add(objectMap);
        }
        jsonObject.put("teamAndDoctors", mapList);
        //康复情况标签
        String labelSql = "SELECT wspl.label_code,wspl.label_name from  wlyy.wlyy_sign_patient_label wspl WHERE wspl.label_type='8' AND status='1'";
        List<Map<String, Object>> signPatientLabelList = jdbcTemplate.queryForList(labelSql);
        List<String> patientLabelList = new ArrayList<>();
        if("0".equals(signStatus) ){
            //居民的康复情况
            String patientLabelSql = "SELECT wspl.label from  wlyy.wlyy_sign_patient_label_info wspl WHERE wspl.patient='"+patientCode+"' and  wspl.label_type='8' AND status='1'";
            patientLabelList = jdbcTemplate.queryForList(patientLabelSql,String.class);
        }
        Set<String> patientLabelSet =new HashSet<>(patientLabelList);
        signPatientLabelList.stream().forEach(item->{
            item.put("status",patientLabelSet.contains(item.get("label_code").toString())?1:0) ;
        });
        jsonObject.put("signPatientLabels", signPatientLabelList);
        return jsonObject;
    }
    /**
     * 专科医生发起签约
     * @param specialistPatientRelationDO
     * @return
     * @throws Exception
     */
    public ObjEnvelop<SpecialistPatientRelationDO> createPatientInSpeciaRelation(SpecialistPatientRelationDO specialistPatientRelationDO) throws Exception {
        if(StringUtils.isNotEmpty(specialistPatientRelationDO.getId())){
            //获取专科相关的信息
            Map<String,Object> m=  getMessageByRelationId(specialistPatientRelationDO.getId());
            if(null!=m){
                updateMessageByRelationId(specialistPatientRelationDO.getId());
            }
        }
        specialistPatientRelationDO.setSignStatus("1");
        specialistPatientRelationDO.setSignDate(new Date());
        specialistPatientRelationDO.setCreateTime(new Date());
        specialistPatientRelationDO.setUpdateTime(new Date());
        specialistPatientRelationDO.setCreateUser(specialistPatientRelationDO.getDoctor());
        specialistPatientRelationDO.setCreateUserName(specialistPatientRelationDO.getDoctorName());
        specialistPatientRelationDO.setStatus("1");//计管师分配状态
        specialistPatientRelationDO.setSignYear(String.valueOf(DateUtil.getNowYear()));
        specialistPatientRelationDO.setSignDate(new Date());
        specialistPatientRelationDO = specialistPatientRelationDao.save(specialistPatientRelationDO);
        //签约成功之后,将签约关系保存在redis中
        String key = "specialist_patient_relation:" + specialistPatientRelationDO.getPatient() +"_"+ ":text";
        redisTemplate.opsForValue().set(key,"true");
        return ObjEnvelop.getSuccess("success", specialistPatientRelationDO);
    }
    public Integer updateRedisFindPatientTeamList(){
        List<SpecialistPatientRelationDO> specialistPatientRelationDOList=specialistPatientRelationDao.findAllBySignStatus("1");
        List<SpecialistPatientRelationDO> unique = specialistPatientRelationDOList.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SpecialistPatientRelationDO::getPatient))), ArrayList::new)
        );
        unique.stream().forEach(item->{
            //签约成功之后,将签约关系保存在redis中
            String key = "specialist_patient_relation:" + item.getPatient() +"_"+ ":text";
            redisTemplate.opsForValue().set(key,"true");
        });
        return null==unique?0:unique.size();
    }
    /**
     * 根据共管医生和居民code查询专科签约信息
     *
     * @param patient
     * @param doctor
     * @return
     */
    public List<SpecialistPatientRelationDO> selectByAssistant(String patient, String doctor){
        String sql = "select *" +
                " from wlyy_specialist_patient_relation r where r.health_assistant = '"+doctor+"' and r.patient = '"+patient+"' ";
        sql = TransforSqlUtl.specialistPatientRelationAll(sql);
        List<SpecialistPatientRelationDO> relationDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistPatientRelationDO.class));
        return relationDOS;
    }
    /**
     * 专科-通过手机号码精确搜索注册居民
     * @param keywords
     */
    public MixEnvelop searchPatientInSpecialistNew(String doctorCode, String keywords, Integer page, Integer pageSize) throws Exception{
        String sql1 = " select count(1) as num ";
        String sql2 = " select p.name as name,p.idcard,p.code,p.photo";
        String whereSql ="";
        if(!StringUtils.isEmpty(keywords)){
            whereSql+=" and  p.mobile ='"+keywords+"'";
        }
        //根据手机号码精确查找居民
        String centerSql =" from "+basedb+".wlyy_patient p /*LEFT JOIN wlyy_specialist.wlyy_specialist_patient_relation r ON p.code=r.patient */where  p.openid IS NOT NULL "+whereSql;
        String signSql ="SELECT r.patient,r.sign_status  FROM  wlyy_specialist.wlyy_specialist_patient_relation r WHERE (r.sign_status = '1' or r.sign_status = '0') " +
                " AND doctor in (SELECT m.doctor_code FROM  "+basedb+".wlyy_admin_team_member m where m.team_id in " +
                " (SELECT dt.id FROM  "+basedb+".wlyy_admin_team dt LEFT JOIN  "+basedb+".wlyy_admin_team_member watm ON dt.id=watm.team_id " +
                " WHERE dt.available='1' AND watm.available='1' AND watm.doctor_code='"+doctorCode+"') AND  m.available='1')";
        List<Map<String,Object>> map1=jdbcTemplate.queryForList(signSql);
        String sqlCount=sql1+centerSql;
        String sql=sql2+centerSql+" LIMIT "+(page-1)*pageSize+","+pageSize;
        List<Map<String,Object>> map = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>> countMap = jdbcTemplate.queryForList(sqlCount);
        //根据居民查找专科签约状态
        //已签约专科,获取签约信息
        Map<String,String> patientMap = new HashMap<>();
        if(null!=map1){
            map1.stream().forEach(temp->{
                patientMap.put(temp.get("patient").toString(),temp.get("sign_status").toString()) ;
            });
        }
        //未签约,获取居民信息,及专科医生信息
        List<Map<String,Object>> resultList = new ArrayList<>();
        Map m = null;
        Integer age = null;
        String sex = null;
        String sexName="";
        for(Map<String,Object> one:map){
            m = new HashMap();
            age = IdCardUtil.getAgeForIdcard(one.get("idcard")+"");
            sex = IdCardUtil.getSexForIdcard_new(one.get("idcard")+"");
            String patientCode=null==one.get("code")?"":one.get("code").toString();
            m.put("name",one.get("name"));
            m.put("age",age);
            m.put("sex",sex);
            //1已签约,0待审核,-1未签约或已取消或已拒绝
            if(patientMap.containsKey(patientCode)&&"1".equals(patientMap.get(patientCode))){
                m.put("sign_status", 1);
            }else if(patientMap.containsKey(patientCode)&&"0".equals(patientMap.get(patientCode))){
                m.put("sign_status", 0);
            }else {
                m.put("sign_status", -1);
            }
            if("1".equals(sex)){
                sexName="男";
            }else if("2".equals(sex)){
                sexName="女";
            }else{
                sexName="未知";
            }
            m.put("sexName",sexName);
            m.put("patientCode",one.get("code"));
            m.put("photo",one.get("photo"));
            resultList.add(m);
        }
        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,resultList,page,pageSize,countMap.size()>0?Long.valueOf(countMap.get(0).get("num")+""):0);
    }
    /**
     * 根据医生和居民code查询居民与该医生所在团队的待审核专科签约信息
     *
     * @param patient
     * @param doctor
     * @return
     */
    public SpecialistPatientRelationDO selectByDoctorAndPatient(String doctor, String patient){
        String sql = "select * from wlyy_specialist.wlyy_specialist_patient_relation r where r.doctor in ( " +
                " SELECT m.doctor_code  FROM wlyy.wlyy_admin_team_member m " +
                " WHERE  m.team_id IN ( SELECT dt.id  FROM  wlyy.wlyy_admin_team dt LEFT JOIN wlyy.wlyy_admin_team_member watm ON dt.id = watm.team_id   WHERE " +
                " dt.available = '1' AND watm.available = '1'  AND watm.doctor_code = '"+doctor+"') AND m.available = '1'  ) and r.patient = '"+patient+"' and r.sign_status=0";
        sql  = TransforSqlUtl.specialistPatientRelationAll2(sql);
        List<SpecialistPatientRelationDO> relationDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistPatientRelationDO.class));
        SpecialistPatientRelationDO specialistPatientRelationDO=null!=relationDOS&&relationDOS.size()>0?relationDOS.get(0):new SpecialistPatientRelationDO();
        return specialistPatientRelationDO;
    }
    /**
     * 根据签约关系id获取消息
     * @param relationId
     * @return
     */
    public Map<String,Object> getMessageByRelationId(String relationId){
        String sql = "select w.* from wlyy.wlyy_message w where w.type='16' and  w.relation_code='" + relationId + "' ";
       List<Map<String,Object>> res= jdbcTemplate.queryForList(sql);
       if(null!=res&&res.size()>0){
           return res.get(0);
       }
       return null;
    }
    /**
     * 更新消息
     * @param relationId
     * @return
     */
    public void updateMessageByRelationId(String relationId){
        String sql = "update wlyy.wlyy_message set has_read=0 ,over=0  where relation_code='" + relationId + "' ";
        jdbcTemplate.execute(sql);
    }
    public Envelop updatePatientSignSpecialistInfo(String patient, String doctor, String doctorName) {
        specialistPatientRelationDao.updateSpecialistByPatient(patient, doctor, doctorName);
        return Envelop.getSuccess("更新成功!");
    }
    public JSONObject transferPatients(String teamCode,String toTeamCode,String doctorCode,String toDoctorCode,String patients){
        String[] patient = patients.split(",");
        boolean flag=false;//同团队时 teamCode==toTeamCode
        if (!teamCode.equals(toTeamCode)){//跨团队
            flag=true;
        }
        String sql =" select name from wlyy.wlyy_doctor where code='"+toDoctorCode+"'";
        String toDoctorName = jdbcTemplate.queryForObject(sql,String.class);
//        toDoctorName = AesEncryptUtils.decrypt(toDoctorName);
        sql =" select name from wlyy.wlyy_doctor where code='"+doctorCode+"'";
        String doctorName = jdbcTemplate.queryForObject(sql,String.class);
//        doctorName = AesEncryptUtils.decrypt(doctorName);
        JSONObject result = new JSONObject();
        JSONArray planObject = new JSONArray();
        JSONArray planDetailObject = new JSONArray();
        JSONArray specialistPatientRelation = new JSONArray();
        JSONArray rehabilitationOperateRecords = new JSONArray();
        for (String patientCode:patient){
            sql ="select name from wlyy.wlyy_patient where code='"+patientCode+"' ";
            String patientName = jdbcTemplate.queryForObject(sql,String.class);
            Long admin_team_code = 0L;
            //判断是否签约,如果签约 新增家签团队id
            try{
                String sqltmp = "SELECT a.admin_team_code  from wlyy.wlyy_sign_family a WHERE patient = '"+patientCode+"' and `status`>0 and expenses_status =1 order by id desc limit 1 ";
                List<Map<String,Object>> list =  jdbcTemplate.queryForList(sqltmp);
                if(list!=null&&list.size()>0){
                    admin_team_code = Long.valueOf(list.get(0).get("admin_team_code")+"");
                }
            }catch (Exception e){
                e.printStackTrace();
            }
//            patientName = AesEncryptUtils.decrypt(patientName);
            List<PatientRehabilitationPlanDO> planList  = patientRehabilitationPlanDao.findByPatientAndCreateUserAndTeamCode(patientCode,doctorCode,Integer.parseInt(teamCode));{
                for (PatientRehabilitationPlanDO plan:planList){
                    plan.setCreateUser(toDoctorCode);
                    plan.setCreateUserName(toDoctorName);
                    plan.setUpdateUser(doctorCode);
                    plan.setUpdateUserName(doctorName);
                    plan.setUpdateTime(new Date());
                    if (flag){
                        plan.setTeamCode(Integer.parseInt(toTeamCode));
                    }
                    if(admin_team_code>0){
                        plan.setAdminTeamCode(admin_team_code);
                    }
                    patientRehabilitationPlanDao.save(plan);
                    planObject.add(plan.getId());
                    PatientRehabilitationPlanLogDO planLogDO = new PatientRehabilitationPlanLogDO();
                    planLogDO.setId(UUID.randomUUID().toString().replace("-",""));
                    planLogDO.setPlanId(plan.getId());
                    planLogDO.setCreateTime(new Date());
                    planLogDO.setCreateUser(doctorCode);
                    planLogDO.setCreateUserName(doctorName);
                    patientRehabilitationPlanLogDao.save(planLogDO);
                    List<RehabilitationDetailDO> planDetails  = rehabilitationDetailDao.findByPlanIdAndTypeAndDoctorAndStatusNot(plan.getId(),2,doctorCode,1);//未完成的任务
                    for (RehabilitationDetailDO planDetail:planDetails){
                        planDetail.setCreateUser(toDoctorCode);
                        planDetail.setCreateUserName(toDoctorName);
                        planDetail.setDoctor(toDoctorCode);
                        planDetail.setDoctorName(toDoctorName);
                        planDetail.setUpdateTime(new Date());
                        planDetail.setUpdateUser(doctorCode);
                        planDetail.setUpdateUserName(doctorName);
                        rehabilitationDetailDao.save(planDetail);
                        planDetailObject.add(planDetail.getId());
                        List<RehabilitationOperateRecordsDO> operateList = rehabilitationOperateRecordsDao.findByRehabilitationDetailIdAndDoctorCodeAndStatusNot(planDetail.getId(),doctorCode,1);
                        for (RehabilitationOperateRecordsDO operateRecordsDO:operateList){
                            operateRecordsDO.setDoctorCode(toDoctorCode);
                            operateRecordsDO.setDoctorName(toDoctorName);
                            operateRecordsDO.setUpdateTime(new Date());
                            operateRecordsDO.setUpdateUser(doctorCode);
                            operateRecordsDO.setUpdateUserName(doctorName);
                            rehabilitationOperateRecordsDao.save(operateRecordsDO);
                            rehabilitationOperateRecords.add(operateRecordsDO.getId());
                        }
                    }
                }
            }
            if (flag){
                SpecialistPatientRelationDO relations = specialistPatientRelationDao.findByTeamCodeAndPatient(Integer.parseInt(toTeamCode),patientCode);
                SpecialistPatientRelationDO relationDoBefore = specialistPatientRelationDao.findByTeamCodeAndPatient(Integer.parseInt(teamCode),patientCode);
                if (relations==null){//跨团队时  患者未与目标团队签约
                    SpecialistPatientRelationDO relationDO = new SpecialistPatientRelationDO();
                    relationDO.setId(UUID.randomUUID().toString().replace("-",""));
                    relationDO.setDoctorName(toDoctorCode);
                    relationDO.setDoctorName(toDoctorName);
                    relationDO.setPatient(patientCode);
                    relationDO.setPatientName(patientName);
                    relationDO.setTeamCode(Integer.parseInt(toTeamCode));
                    relationDO.setSignStatus("1");
                    relationDO.setStatus("1");
                    relationDO.setSignYear(DateUtil.getSignYear()+"");
                    relationDO.setSignDate(new Date());
                    relationDO.setCreateTime(new Date());
                    relationDO.setCreateUser(toDoctorCode);
                    relationDO.setCreateUserName(toDoctorName);
                    relationDO.setUpdateTime(new Date());
                    if (StringUtils.isNotBlank(relationDoBefore.getDiseaseCode())){
                        relationDO.setDiseaseCode(relationDoBefore.getDiseaseCode());
                    }
                    if (relationDoBefore.getDiseaseCode()!=null){
                        relationDO.setIsManage(relationDoBefore.getIsManage());
                    }
                    if (StringUtils.isNotBlank(relationDoBefore.getManageUser())){
                        relationDO.setManageUser(relationDoBefore.getManageUser());
                    }
                    if (StringUtils.isNotBlank(relationDoBefore.getManageTime().toString())){
                        relationDO.setManageTime(relationDoBefore.getManageTime());
                    }
                    if (StringUtils.isNotBlank(relationDoBefore.getRemindTime())){
                        relationDO.setRemindTime(relationDoBefore.getRemindTime());
                    }
                    specialistPatientRelationDao.save(relationDO);
                    specialistPatientRelation.add(relationDO.getId());
                    sql = "UPDATE wlyy.wlyy_patient_disease_server set specialist_relation_code='"+relationDO.getId()+"' \n" +
                            "where specialist_relation_code='"+relationDoBefore.getId()+"'";
                    jdbcTemplate.execute(sql);
                }
                else{
                    relations.setCreateUser(toDoctorCode);
                    relations.setCreateUserName(toDoctorName);
                    relations.setDoctor(toDoctorCode);
                    relations.setDoctorName(toDoctorName);
                    relations.setUpdateTime(new Date());
                    relations.setUpdateUser(doctorCode);
                    relations.setUpdateUserName(doctorName);
                    specialistPatientRelationDao.save(relations);
                    specialistPatientRelation.add(relations.getId());
                    sql = "UPDATE wlyy.wlyy_patient_disease_server set specialist_relation_code='"+relations.getId()+"' \n" +
                            "where specialist_relation_code='"+relationDoBefore.getId()+"'";
                    jdbcTemplate.execute(sql);
                }
            }
            else{//
                List<SpecialistPatientRelationDO> relations = specialistPatientRelationDao.findListByTeamCodeAndPatientAndDoctor(Integer.parseInt(teamCode),patientCode,doctorCode);
                for (SpecialistPatientRelationDO relation:relations){
                    relation.setCreateUser(toDoctorCode);
                    relation.setCreateUserName(toDoctorName);
                    relation.setDoctor(toDoctorCode);
                    relation.setDoctorName(toDoctorName);
                    relation.setUpdateTime(new Date());
                    relation.setUpdateUser(doctorCode);
                    relation.setUpdateUserName(doctorName);
                    specialistPatientRelationDao.save(relation);
                    specialistPatientRelation.add(relation.getId());
                }
            }
        }
        result.put("planList",planObject);
        result.put("planDetailList",planDetailObject);
        result.put("relationList",specialistPatientRelation);
        result.put("rehabilitationOperateRecords",rehabilitationOperateRecords);
        return  result;
    }
}

+ 0 - 66
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistServiceItemOperateLogService.java

@ -1,66 +0,0 @@
package com.yihu.jw.base.service.specialist;/**
 * Created by nature of king on 2018/8/17.
 */
import com.yihu.jw.base.dao.specialist.SpecialistServiceItemOperateLogDao;
import com.yihu.jw.base.util.ISqlUtils;
import com.yihu.jw.entity.specialist.SpecialistServiceItemOperateLogDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
/**
 * @author wangzhinan
 * @create 2018-08-17 8:48
 * @desc 服务项目操作记录
 **/
@Service
@Transactional
public class SpecialistServiceItemOperateLogService {
    @Autowired
    private SpecialistServiceItemOperateLogDao specialistServiceItemOperateLogDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     *
     * @param specialistServiceItemOperateLogDO
     * @return
     */
    public MixEnvelop<Boolean,Boolean> insert(SpecialistServiceItemOperateLogDO specialistServiceItemOperateLogDO){
        MixEnvelop<Boolean,Boolean> envelop = new MixEnvelop<>();
        specialistServiceItemOperateLogDao.save(specialistServiceItemOperateLogDO);
        envelop.setObj(true);
        return envelop;
    }
    /**
     *  查询操作记录
     *
     * @param specialistServiceItemOperateLogDO
     * @param page
     * @param pageSize
     * @return
     */
    public MixEnvelop<SpecialistServiceItemOperateLogDO, SpecialistServiceItemOperateLogDO> select(SpecialistServiceItemOperateLogDO specialistServiceItemOperateLogDO, Integer page, Integer pageSize){
        MixEnvelop<SpecialistServiceItemOperateLogDO, SpecialistServiceItemOperateLogDO> envelop = new MixEnvelop<>();
        String sql = ISqlUtils.getSql(specialistServiceItemOperateLogDO,page,pageSize,"*");
        List<SpecialistServiceItemOperateLogDO> specialistServiceItemOperateLogDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistServiceItemOperateLogDO.class));
        String sqlcount = new ISqlUtils().getSql(specialistServiceItemOperateLogDO,0,0,"count");
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success,specialistServiceItemOperateLogDOS,page,pageSize,count);
    }
}

+ 0 - 223
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/SpecialistServiceItemService.java

@ -1,223 +0,0 @@
package com.yihu.jw.base.service.specialist;/**
 * Created by nature of king on 2018/8/17.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.dao.specialist.SpecialistServiceItemDao;
import com.yihu.jw.base.dao.specialist.SpecialistServiceItemOperateLogDao;
import com.yihu.jw.base.util.ISqlUtils;
import com.yihu.jw.entity.specialist.HospitalServiceItemDO;
import com.yihu.jw.entity.specialist.SpecialistEvaluateDO;
import com.yihu.jw.entity.specialist.SpecialistServiceItemDO;
import com.yihu.jw.entity.specialist.SpecialistServiceItemOperateLogDO;
import com.yihu.jw.entity.util.TransforSqlUtl;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.Column;
import javax.persistence.Table;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
/**
 * @author wangzhinan
 * @create 2018-08-17 8:48
 * @desc 服务项目
 **/
@Service
@Transactional
public class SpecialistServiceItemService {
    @Autowired
    private SpecialistServiceItemDao specialistServiceItemDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SpecialistServiceItemOperateLogDao specialistServiceItemOperateLogDao;
    /**
     * 添加服务项目
     *
     * @param specialistServiceItemDO
     * @return
     */
    public MixEnvelop<Boolean,Boolean> insert(SpecialistServiceItemDO specialistServiceItemDO){
        MixEnvelop<Boolean,Boolean> envelop = new MixEnvelop<>();
        specialistServiceItemDO.setCreateTime(new Date());
        specialistServiceItemDO.setUpdateTime(new Date());
        specialistServiceItemDao.save(specialistServiceItemDO);
        envelop.setObj(true);
        return envelop;
    }
    /**
     * 按条件查询
     *
     * @param specialistServiceItemDO
     * @param page
     * @param size
     * @return
     */
    public MixEnvelop<SpecialistServiceItemDO, SpecialistEvaluateDO> select(SpecialistServiceItemDO specialistServiceItemDO, Integer page, Integer size){
        MixEnvelop<SpecialistServiceItemDO, SpecialistServiceItemDO> envelop = new MixEnvelop<>();
        String sql = ISqlUtils.getSql(specialistServiceItemDO,page,size,"*");
        List<SpecialistServiceItemDO> specialistServiceItemDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistServiceItemDO.class));
        String sqlcount = new ISqlUtils().getSql(specialistServiceItemDO,0,0,"count");
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return MixEnvelop.getSuccessListWithPage(HealthBankMapping.api_success,specialistServiceItemDOS,page,size,count);
    }
    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    public MixEnvelop<Boolean,Boolean> batchDelete(List<String> ids){
        MixEnvelop<Boolean,Boolean> envelop = new MixEnvelop<>();
        for (int i =0;i<ids.size();i++){
            SpecialistServiceItemDO specialistServiceItemDO = specialistServiceItemDao.findById(ids.get(i)).orElse(null);
            specialistServiceItemDO.setStatus(0);
            specialistServiceItemDO.setCreateTime(new Date());
            specialistServiceItemDO.setUpdateTime(new Date());
            specialistServiceItemDao.save(specialistServiceItemDO);
        }
        envelop.setObj(true);
        return envelop;
    }
    /**
     * 修改服务项目
     *
     * @param specialistServiceItemDO
     * @return
     */
    public MixEnvelop<Boolean,Boolean> update(SpecialistServiceItemDO specialistServiceItemDO){
        MixEnvelop<Boolean,Boolean> envelop = new MixEnvelop<>();
        SpecialistServiceItemDO specialistServiceItemDO1 = specialistServiceItemDao.findById(specialistServiceItemDO.getId()).orElse(null);
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(specialistServiceItemDO1);
        String sql = ISqlUtils.getUpdateSql(specialistServiceItemDO);
        jdbcTemplate.update(sql);
        Class c = specialistServiceItemDO.getClass();
        Table table = (Table)c.getAnnotation(Table.class);
        String tableName = table.name();
        Field[] fArray = c.getDeclaredFields();
        JSONArray array = new JSONArray();
        for (Field f:fArray){
            String getMethoName = "";
            JSONObject object = new JSONObject();
            boolean isCExist = f.isAnnotationPresent(Column.class);
            if (isCExist){
                Column mc = f.getAnnotation(Column.class);
                String columeName = mc.name();
                String name = f.getName();
                Class a= f.getType();
                Object value= null;
                getMethoName = "get" + name.substring(0,1).toUpperCase()+name.substring(1);
                try {
                    Method m = c.getMethod(getMethoName);
                    value = (Object)m.invoke(specialistServiceItemDO);
                    if (value == null || "".equals(value)){
                        continue;
                    }
                    else if (value instanceof  String || value instanceof Integer){
                        value = "'"+value+"'";
                        object.put(name+"旧",jsonObject.getString(name));
                        object.put(name,value);
                        array.add(object);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
        SpecialistServiceItemOperateLogDO specialistServiceItemOperateLogDO = new SpecialistServiceItemOperateLogDO();
        specialistServiceItemOperateLogDO.setSaasId("dev");
        specialistServiceItemOperateLogDO.setServiceItemId(specialistServiceItemDO.getId());
        specialistServiceItemOperateLogDO.setStatus(1);
        specialistServiceItemOperateLogDO.setOperateLog(array.toJSONString());
        specialistServiceItemOperateLogDO.setCreateTime(new Date());
        specialistServiceItemOperateLogDO.setUpdateTime(new Date());
        specialistServiceItemOperateLogDao.save(specialistServiceItemOperateLogDO);
        envelop.setObj(true);
        return envelop;
    }
    /**
     * 根据医院code获取服务项目
     *
     * @param hospital
     * @return
     */
    public MixEnvelop<SpecialistServiceItemDO, SpecialistServiceItemDO> selectByHospital(String hospital){
        MixEnvelop<SpecialistServiceItemDO, SpecialistServiceItemDO> envelop = new MixEnvelop<>();
        String sql = "select * from wlyy_service_item where status = 1 AND imediate = 1 ";
        sql = TransforSqlUtl.wlyy_service_itemAll(sql);
        List<SpecialistServiceItemDO> specialistServiceItemDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistServiceItemDO.class));
        List<SpecialistServiceItemDO> specialistServiceItemDOList = new ArrayList<>();
        for (int i =0;i<specialistServiceItemDOS.size();i++){
            SpecialistServiceItemDO specialistServiceItemDO = specialistServiceItemDOS.get(i);
            String sqlUtil = "";
            if (StringUtils.isNoneBlank(hospital)) {
                sqlUtil = " and hospital = '" + hospital + "'";
            }
            String sql1 = "select * from wlyy_hospital_service_item where 1=1 AND status = 1 AND service_item_id = '"+specialistServiceItemDO.getId()+"'"+sqlUtil;
            List<HospitalServiceItemDO> hospitalServiceItemDOS = jdbcTemplate.query(sql1,new BeanPropertyRowMapper(HospitalServiceItemDO.class));
            if (StringUtils.isNoneBlank(hospital)){
                if (hospitalServiceItemDOS.size() == 0 || hospitalServiceItemDOS == null){
                    specialistServiceItemDOList.add(specialistServiceItemDO);
                }
            }else {
                    specialistServiceItemDOList.add(specialistServiceItemDO);
            }
        }
        envelop.setDetailModelList(specialistServiceItemDOList);
        return envelop;
    }
    /**
     * 导数据
     *
     * @param specialistServiceItemDOS
     * @return
     */
    public MixEnvelop<Boolean,Boolean> importData(List<SpecialistServiceItemDO> specialistServiceItemDOS) {
        MixEnvelop<Boolean,Boolean> envelop = new MixEnvelop<>();
        if (specialistServiceItemDOS != null && specialistServiceItemDOS.size()!=0){
            for (SpecialistServiceItemDO specialistServiceItemDO:specialistServiceItemDOS){
                List<SpecialistServiceItemDO> specialistServiceItemDOList = specialistServiceItemDao.findByTitle(specialistServiceItemDO.getTitle());
                if (specialistServiceItemDOList == null && specialistServiceItemDOList.size() ==0){
                    continue;
                }else {
                    specialistServiceItemDO.setStatus(1);
                    specialistServiceItemDO.setId(UUID.randomUUID().toString());
                    specialistServiceItemDO.setCreateTime(new Date());
                    specialistServiceItemDO.setUpdateTime(new Date());
                    specialistServiceItemDao.save(specialistServiceItemDO);
                }
            }
        }
        envelop.setObj(true);
        return envelop;
    }
}

+ 0 - 62
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/rehabilitation/DiagnosisInformationService.java

@ -1,62 +0,0 @@
package com.yihu.jw.base.service.specialist.rehabilitation;
import com.yihu.jw.base.dao.specialist.rehabilitation.PatientDiagnosisInformationDao;
import com.yihu.jw.entity.specialist.rehabilitation.PatientDiagnosisInformationDO;
import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
 * Created by humingfen on 2019/1/11.
 */
@Service
@Transactional
public class DiagnosisInformationService extends BaseJpaService<PatientDiagnosisInformationDO, PatientDiagnosisInformationDao> {
    @Autowired
    private PatientDiagnosisInformationDao diagnosisInformationDao;
    /**
     * 保存诊疗信息
     * @param diagnosisInformationDO
     * @return
     */
    public Envelop createDiagnosisInformation(PatientDiagnosisInformationDO diagnosisInformationDO) {
        Date date = new Date();
        diagnosisInformationDO.setCreateTime(date);
        diagnosisInformationDao.save(diagnosisInformationDO);
        return Envelop.getSuccess(SpecialistMapping.api_success);
    }
    /**
     * 根据康复计划查找诊疗信息
     * @param planId
     * @return
     */
    public ObjEnvelop findDiagnosisInformationByPlanId(String planId) {
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, diagnosisInformationDao.findByPlanId(planId));
    }
    /**
     * 获取居民诊疗信息记录
     * @param patient
     * @param page
     * @param size
     * @return
     */
    public PageEnvelop findDiagnosisInformationByPatient(String patient, Integer page, Integer size) {
        PageRequest pageRequest = PageRequest.of(page, size);
        Page<PatientDiagnosisInformationDO> list = diagnosisInformationDao.findByPatient(patient,pageRequest);
        return PageEnvelop.getSuccessListWithPage(SpecialistMapping.api_success, list.getContent(), page, size,list.getTotalElements());
    }
}

+ 0 - 1595
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/rehabilitation/RehabilitationManageService.java

@ -1,1595 +0,0 @@
package com.yihu.jw.base.service.specialist.rehabilitation;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.dao.specialist.SpecialistPatientRelationDao;
import com.yihu.jw.base.dao.specialist.rehabilitation.*;
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.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.DecimalFormat;
import java.util.*;
/**
 * Created by 刘文彬 on 2018/8/16.
 */
@Service
@Transactional
public class RehabilitationManageService {
    private String basedb="base";
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private RehabilitationDetailDao rehabilitationDetailDao;
    @Autowired
    private PatientRehabilitationPlanDao patientRehabilitationPlanDao;
    @Autowired
    private GuidanceMessageLogDao guidanceMessageLogDao;
    @Autowired
    private SpecialistPatientRelationDao specialistPatientRelationDao;
    @Autowired
    private RehabilitationOperateRecordsDao rehabilitationOperateRecordsDao;
    @Autowired
    private RehabilitationDetailAppointmentDao rehabilitationDetailAppointmentDao;
    /**
     * 预约协诊
     *
     * @param doctor
     * @param doctorName
     * @param sendTime
     * @param planDetailId
     */
    public ObjEnvelop appointmentConsultation(String patient, String doctor, String doctorName,
                                              String appointmentDoctor, String appointmentDoctorName, String sendTime, String planDetailId) {
        RehabilitationDetailAppointmentDO appointment = new RehabilitationDetailAppointmentDO();
        appointment.setAppointmentTime(sendTime + ":00");
        appointment.setCreateTime(new Date());
        appointment.setDoctor(doctor);
        appointment.setDoctorName(doctorName);
        appointment.setAppointmentDoctor(appointmentDoctor);
        appointment.setAppointmentDoctorName(appointmentDoctorName);
        appointment.setIsSend(0);
        appointment.setRehabilitationPlanDetailId(planDetailId);
        appointment.setPatient(patient);
        rehabilitationDetailAppointmentDao.save(appointment);
        return ObjEnvelop.getSuccess("获取成功", appointment);
    }
    /**
     * 康复管理(专科)-- 计划列表
     *
     * @param doctorType   1.专科,2.家医
     * @param doctorCode
     * @param diseaseCode
     * @param planType
     * @param todaybacklog
     * @param page
     * @param pageSize
     * @return
     * @throws Exception
     */
    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 " +
                " on a.plan_id = p.id  ";
        if (doctorType == 2) {//家医是根据签约关系过滤
            sql += " INNER JOIN wlyy.wlyy_sign_family f ON f.patient = p.patient \n" +
                    "\tand f.expenses_status=1\n" +
                    "\tAND f.STATUS >= 1 \n" +
                    "\tAND ( f.doctor = '" + doctorCode + "' OR f.doctor_health = '" + doctorCode + "' )  ";
        }
        sql += " where 1=1 ";
        if (todaybacklog != null && todaybacklog == 1) {
            String todayStart = DateUtil.getStringDateShort() + " " + "00:00:00";
            String todayEnd = DateUtil.getStringDateShort() + " " + "23:59:59";
            sql += " and a.execute_time>='" + todayStart + "' and a.execute_time<='" + todayEnd + "'";
        }
        if (planType != null) {
            sql += " and p.plan_type=" + planType;
        }
        if (StringUtils.isNotEmpty(diseaseCode)) {
            sql += " and p.disease='" + diseaseCode + "'";
        }
        if (StringUtils.isNotEmpty(patientCondition)) {//姓名idcard模糊查询
            sql += " AND EXISTS (select code from wlyy.wlyy_patient where  `code` = p.patient and ( `name` LIKE '%" + patientCondition + "%' or idcard like '%" + patientCondition + "%') )";
        }
        if (doctorType == 1) {
            sql += " AND (p.create_user = '" + doctorCode + "' \n" +
                    "\tOR a.doctor = '" + doctorCode + "' ) ";
        }
        sql = TransforSqlUtl.wlyy_patient_rehabilitation_planAll2(sql);
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(sql);
        int count = 0;
        if (rstotal != null && rstotal.size() > 0 && rstotal.get(0).get("id") != null) {
            count = rstotal.size();
        }
        sql += " ORDER BY p.create_time DESC LIMIT " + (page - 1) * pageSize + "," + pageSize;
        List<Map<String, Object>> patientRehabilitationPlanDOList = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (patientRehabilitationPlanDOList.size() > 0 && patientRehabilitationPlanDOList.get(0).get("id") != null) {
            for (Map<String, Object> one : patientRehabilitationPlanDOList) {
                Map<String, Object> resultMap = new HashMap<>();
//                Integer age = IdCardUtil.getAgeForIdcard(one.get("idcard")+"");
//                String sex = IdCardUtil.getSexForIdcard_new(one.get("idcard")+"");
//                resultMap.put("age",age);
                resultMap.put("hospitalName", one.get("hospital_name"));
//                resultMap.put("sex","1".equals(sex)?"男":("2".equals(sex)?"女":"未知"));
                resultMap.put("patientName", one.get("patientName"));
                resultMap.put("patientCode", one.get("patient"));
                resultMap.put("id", one.get("id"));
                resultMap.put("status", one.get("status"));//康复计划状态
                //健康情况
                String healthyConditionSql = " select  label_name,label from " + basedb + ".wlyy_sign_patient_label_info where status=1 and patient='" + one.get("patient") + "' 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") + "" : "";
                resultMap.put("healthyCondition", healthyCondition);
                resultMap.put("healthyConditionType", healthyConditionType);
                //安排类型
                String planTypeName = null;
                Integer planTypeTemp = (Integer) one.get("plan_type");
                switch (planTypeTemp) {
                    case 1:
                        planTypeName = "康复计划";
                        break;
                    case 2:
                        planTypeName = "(转)社区医院";
                        break;
                    case 3:
                        planTypeName = "(转)转家庭病床";
                        break;
                }
                resultMap.put("planTypeName", planTypeName);
                resultMap.put("planCreateUser", one.get("create_user"));
                //今日待办(即今日全部的项目)
                Date beginTime = DateUtil.strToDateLong(DateUtil.getStringDateShort() + " " + "00:00:00");
                Date endTime = DateUtil.strToDateLong(DateUtil.getStringDateShort() + " " + "23:59:59");
                Integer todayBacklogCount = rehabilitationDetailDao.todayBacklogCount(one.get("id").toString(), beginTime, endTime);
                resultMap.put("todayBacklogCount", todayBacklogCount);//今日待办总数
                //已完成
                Integer finishedCount = rehabilitationDetailDao.completenessCount(1, one.get("id").toString(), beginTime, endTime);
                resultMap.put("finishedCount", finishedCount);//已完成
                //未完成
                Integer notstartedCount = rehabilitationDetailDao.completenessCount(0, one.get("id").toString(), beginTime, endTime);//未开始
                Integer underwayCount = rehabilitationDetailDao.completenessCount(2, one.get("id").toString(), beginTime, endTime);//已预约
                Integer unfinishedCount = notstartedCount + underwayCount;
                resultMap.put("unfinishedCount", unfinishedCount);//未完成
                //完成度(已完成/(已完成+未完成))
                Integer allFinishCount = rehabilitationDetailDao.findByStatusAndPlanId(1, one.get("id").toString());
                Integer allCount = rehabilitationDetailDao.findAllByPlanId(one.get("id").toString());
                resultMap.put("allCount", allCount);//总数
                resultMap.put("allFinishCount", allFinishCount);//全部已完成数
                resultMap.put("createTime", one.get("create_time"));
                resultList.add(resultMap);
            }
        }
        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success, resultList, page, pageSize, Long.valueOf(count));
    }
    /**
     * 康复管理更多计划
     *
     * @param currentDoctorCode
     * @param patientCode
     * @return
     * @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 + "' ";
        sql = TransforSqlUtl.specialistPatientRelationAll2(sql);
        List<Map<String, Object>> specialistPatientRelationList = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (Map<String, Object> temp : specialistPatientRelationList) {
            String doctorCode = temp.get("doctor") + "";
            Map<String, Object> resultMap = new HashMap<>();
            Integer isOperator = 0;
            resultMap.put("patientCode", patientCode);//居民code
            String healthyConditionSql = " select  label_name,label from " + basedb + ".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") + "" : "";
            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 + "'";
            specialistRelationSql = TransforSqlUtl.specialistPatientRelationAll2(specialistRelationSql);
            List<Map<String, Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
            Map<String, Object> specialistMap = specialistRelationList.get(0);
            resultMap.put("specialistAdminTeamName", specialistMap.get("teamName"));
            resultMap.put("specialistHospitalName", specialistMap.get("specialistHospitalName"));//专科医生所在医院
            Integer specialistUnfinishCount1 = rehabilitationDetailDao.unfinishItemByDoctor(doctorCode, patientCode, 1);
            Integer specialistFinishCount1 = rehabilitationDetailDao.findItemByDoctor(doctorCode, patientCode);
            Integer specialistServiceCount1 = rehabilitationDetailDao.completeServiceByDoctor(doctorCode, patientCode, 1);
            Integer specialistUnfinishCount2 = rehabilitationDetailDao.unfinishItemByDoctor(specialistMap.get("health_assistant") + "", patientCode, 1);
            Integer specialistFinishCount2 = rehabilitationDetailDao.findItemByDoctor(specialistMap.get("health_assistant") + "", patientCode);
            Integer specialistServiceCount2 = rehabilitationDetailDao.completeServiceByDoctor(specialistMap.get("health_assistant") + "", patientCode, 1);
            resultMap.put("specialistFinishItemCount", specialistFinishCount1 - specialistUnfinishCount1 + specialistFinishCount2 - specialistUnfinishCount2);//完成项目
            resultMap.put("specialistServiceRecordCount", specialistServiceCount1 + specialistServiceCount2);//服务次数
            //家庭医生(包括全科医生、健管师)
            String signFamilySql = "SELECT f.*,t.name as teamName FROM " + basedb + ".wlyy_sign_family f LEFT JOIN " + basedb + ".wlyy_admin_team t on f.admin_team_code=t.id where f.status =1 and f.expenses_status='1' and f.patient='" + patientCode + "'";
            List<Map<String, Object>> signFamilyList = jdbcTemplate.queryForList(signFamilySql);
            if (signFamilyList != null && signFamilyList.size() > 0) {
                Map<String, Object> signFamilyMap = signFamilyList.get(0);
                resultMap.put("signFamilyAdminTeamName", signFamilyMap.get("teamName"));
                resultMap.put("familyHospitalName", signFamilyMap.get("hospital_name"));//家庭医生所在医院
                Integer familyUnfinishCount1 = rehabilitationDetailDao.unfinishItemByDoctor(signFamilyMap.get("doctor") + "", patientCode, 1);
                Integer familyFinishCount1 = rehabilitationDetailDao.findItemByDoctor(signFamilyMap.get("doctor") + "", patientCode);
                Integer familyServiceCount1 = rehabilitationDetailDao.completeServiceByDoctor(signFamilyMap.get("doctor") + "", patientCode, 1);
                if ((signFamilyMap.get("doctor") + "").equals(signFamilyMap.get("doctor_health") + "")) {
                    resultMap.put("signFamilyFinishItemCount", familyFinishCount1 - familyUnfinishCount1);//完成项目
                    resultMap.put("signFamilyServiceRecordCount", familyServiceCount1);//服务次数
                } else {
                    Integer familyUnfinishCount2 = rehabilitationDetailDao.unfinishItemByDoctor(signFamilyMap.get("doctor_health") + "", patientCode, 1);
                    Integer familyFinishCount2 = rehabilitationDetailDao.findItemByDoctor(signFamilyMap.get("doctor_health") + "", patientCode);
                    Integer familyServiceCount2 = rehabilitationDetailDao.completeServiceByDoctor(signFamilyMap.get("doctor_health") + "", patientCode, 1);
                    resultMap.put("signFamilyFinishItemCount", familyFinishCount1 - familyUnfinishCount1 + familyFinishCount2 - familyUnfinishCount2);//完成项目
                    resultMap.put("signFamilyServiceRecordCount", familyServiceCount1 + familyServiceCount2);//服务次数
                }
                //基础信息
                resultMap.put("hospitalName", signFamilyMap.get("hospital_name"));
                Integer age = IdCardUtil.getAgeForIdcard(signFamilyMap.get("idcard") + "");
                String sex = IdCardUtil.getSexForIdcard_new(signFamilyMap.get("idcard") + "");
                resultMap.put("age", age);
                resultMap.put("sex", "1".equals(sex) ? "男" : ("2".equals(sex) ? "女" : "未知"));
                resultMap.put("patientName", signFamilyMap.get("patientName"));
            }
            //疾病类型
            String diseaseSql = " select s.* from " + basedb + ".wlyy_patient_disease_server s where s.del=1 and s.patient='" + patientCode + "' and s.specialist_relation_code='" + specialistMap.get("id") + "' ";
            List<Map<String, Object>> diseaseList = jdbcTemplate.queryForList(diseaseSql);
            List<String> disease = new ArrayList<>();
            for (Map<String, Object> one2 : diseaseList) {
                disease.add(one2.get("disease_name") + "");
            }
            resultMap.put("diseaseList", disease);
            //计划列表
            List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatientAndCreateUser(patientCode, doctorCode);
            List<Map<String, Object>> rehabilitationPlanList = new ArrayList<>();
            for (PatientRehabilitationPlanDO one : list) {
                Map<String, Object> planMap = new HashMap<>();
                planMap.put("planId", one.getId());
                //安排类型
                String planTypeName = null;
                Integer planTypeTemp = one.getPlanType();
                switch (planTypeTemp) {
                    case 1:
                        planTypeName = "康复计划";
                        break;
                    case 2:
                        planTypeName = "(转)社区医院";
                        break;
                    case 3:
                        planTypeName = "(转)转家庭病床";
                        break;
                }
                planMap.put("planTypeName", planTypeName);
                planMap.put("status", one.getStatus());//0已中止,1进行中,2已完成
                if (currentDoctorCode.equals(doctorCode)) {
                    isOperator = 1;
                }
                planMap.put("isOperator", isOperator);
                //状态(0未完成,1已完成,2已预约)
                //今日待办
                Date beginTime = DateUtil.strToDateLong(DateUtil.getStringDateShort() + " " + "00:00:00");
                Date endTime = DateUtil.strToDateLong(DateUtil.getStringDateShort() + " " + "23:59:59");
                Integer todayBacklogCount = rehabilitationDetailDao.todayBacklogCount(one.getId(), beginTime, endTime);
                planMap.put("todayBacklogCount", todayBacklogCount);
                //已完成
                Integer finishedCount = rehabilitationDetailDao.completenessCount(1, one.getId(), beginTime, endTime);
                planMap.put("finishedCount", finishedCount);//已完成
                //未完成
                Integer notstartedCount = rehabilitationDetailDao.completenessCount(0, one.getId(), beginTime, endTime);//未完成
                Integer underwayCount = rehabilitationDetailDao.completenessCount(2, one.getId(), beginTime, endTime);//已预约
                Integer unfinishedCount = notstartedCount + underwayCount;
                planMap.put("unfinishedCount", unfinishedCount);//未完成
                //完成度(已完成/(已完成+未完成))
                Integer allFinishCount = rehabilitationDetailDao.findByStatusAndPlanId(1, one.getId());
                Integer allCount = rehabilitationDetailDao.findAllByPlanId(one.getId());
                planMap.put("allCount", allCount);//总数
                planMap.put("allFinishCount", allFinishCount);//全部已完成数
                rehabilitationPlanList.add(planMap);
            }
            resultMap.put("rehabilitationPlanList", rehabilitationPlanList);
            resultList.add(resultMap);
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultList);
    }
    /**
     * 日历
     *
     * @param planId       计划id
     * @param searchTask   快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
     * @param status       任务状态(0未完成,1已完成,2已预约)
     * @param doctorCode   登陆医生
     * @param taskExecutor 任务执行者 0全部;1我的任务 2他人任务
     */
    public ObjEnvelop calendarPlanDetail(String executeStartTime, String executeEndTime, String planId, Integer searchTask, Integer status, String doctorCode, String taskExecutor) throws Exception {
        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.* from wlyy_specialist.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)) {
            sql += " and d.execute_time>='" + executeStartTime + "' ";
        }
        if (StringUtils.isNotBlank(executeEndTime)) {
            sql += " and d.execute_time<='" + executeEndTime + "' ";
        }
        if (searchTask != null) {
            if (searchTask == 8) {
                sql += " and d.doctor='" + doctorCode + "' ";
            } else {
                sql += " and i.code=" + searchTask + " ";
            }
        }
        if (taskExecutor.equals("1")) { //我的任务
            sql += "and d.doctor='" + doctorCode + "' ";
        }
        if (taskExecutor.equals("2")) {//他人任务
            sql += "and d.doctor <>'" + doctorCode + "' ";
        }
        if (status != null) {
            sql += " and d.status=" + status;
        }
        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);
            Map<String, Object> m = null;
            if (map.containsKey(executeTime)) {
                m = map.get(executeTime);
                Map<String, Integer> family = null;
                Map<String, Integer> specialist = null;
                if (one.get("type") != null) {
                    if ((Integer) one.get("type") == 1) {//家庭医生
                        if (m.containsKey("family")) {
                            family = (Map<String, Integer>) m.get("family");
                        } else {
                            family = new HashMap<>();
                            family.put("all", 0);
                            family.put("finish", 0);
                        }
                        if ((Integer) one.get("status") == 1) {
                            family.put("finish", family.get("finish") + 1);
                        }
                        family.put("all", family.get("all") + 1);
                        m.put("family", family);
                    } else if ((Integer) one.get("type") == 2) {//专科医生
                        if (m.containsKey("specialist")) {
                            specialist = (Map<String, Integer>) m.get("specialist");
                        } else {
                            specialist = new HashMap<>();
                            specialist.put("all", 0);
                            specialist.put("finish", 0);
                        }
                        if ((Integer) one.get("status") == 1) {
                            specialist.put("finish", (specialist.get("finish")) + 1);
                        }
                        specialist.put("all", (specialist.get("all")) + 1);
                        m.put("specialist", specialist);
                    }
                }
            } else {
                m = new HashMap<>();
//                m.put("specialist",new HashMap<String,Object>());
                if (one.get("type") != null) {
                    if ((Integer) one.get("type") == 1) {//家庭医生
                        Map<String, Integer> family = new HashMap<>();
                        family.put("all", 0);
                        family.put("finish", 0);
                        if ((Integer) one.get("status") == 1) {
                            family.put("finish", family.get("finish") + 1);
                        }
                        family.put("all", family.get("all") + 1);
                        m.put("family", family);
                    } else if ((Integer) one.get("type") == 2) {//专科医生
                        Map<String, Integer> specialist = new HashMap<>();
                        specialist.put("all", 0);
                        specialist.put("finish", 0);
                        if ((Integer) one.get("status") == 1) {
                            specialist.put("finish", specialist.get("finish") + 1);
                        }
                        specialist.put("all", specialist.get("all") + 1);
                        m.put("specialist", specialist);
                    }
                }
            }
            //myTaskFlag,1:有自己任务,0:没有自己任务
            if (StringUtils.isNotEmpty(doctorCode)) {
                if (m.containsKey("myTaskFlag")) {
                    if ((Integer) m.get("myTaskFlag") == 0) {
                        if (doctorCode.equals(one.get("doctor").toString())) {
                            m.put("myTaskFlag", 1);
                        } else {
                            m.put("myTaskFlag", 0);
                        }
                    }
                } else {
                    if (doctorCode.equals(one.get("doctor").toString())) {
                        m.put("myTaskFlag", 1);
                    } else {
                        m.put("myTaskFlag", 0);
                    }
                }
            }
            if (m.containsKey("planDetailIds")) {
                m.put("planDetailIds", m.get("planDetailIds") + "," + one.get("id"));
            } else {
                m.put("planDetailIds", one.get("id") + "");
            }
            map.put(executeTime, m);
        }
        /*List list = new ArrayList();
        for(String key : map.keySet()){
            Map<String,Object> result = map.get(key);
            result.put("executeTime", key);
            list.add(result);
        }*/
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, map);
    }
    /**
     * 日历列表
     *
     * @param planId       计划id
     * @param searchTask   快速查找任务(1、我的任务,2、随访,3、复诊,4、健康教育)
     * @param status       任务状态(0未完成,1已完成,2已预约)
     * @param doctorCode   登陆医生
     * @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 " +
                " 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) {
            if (searchTask == 8) {//
                if (StringUtils.isNotBlank(doctorCode)) {
                    sql += " and d.doctor='" + doctorCode + "' ";
                }
                //sql+=" and i.code="+searchTask+" " ;
            } else {
                sql += " and i.code=" + searchTask + " ";
            }/*else if(searchTask==5){
                sql+=" and i.reserve=1 " ;
            }*/
        }
        if (taskExecutor.equals("1")) { //我的任务
            sql += "and d.doctor='" + doctorCode + "' ";
        }
        if (taskExecutor.equals("2")) {//他人任务
            sql += "and d.doctor <>'" + doctorCode + "' ";
        }
        if (StringUtils.isNoneBlank(executeEndTime) && StringUtils.isNoneBlank(executeStartTime)) {
            sql += "and d.execute_time>='" + executeStartTime + "' and d.execute_time<='" + executeEndTime + "' ";
        }
        if (status != null) {
            sql += "and d.status=" + status;
        }
        sql += "  order by d.execute_time desc ";
        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 " +
                "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);
        List<Map<String, Object>> list = null;
        if (patientCodeList.size() > 0 && null != searchTask) {
            String patient = patientCodeList.get(0).get("patient").toString();
            if (7 == searchTask) { //处方续方 flag 用于判断 1.7.0.5 新增
                String cfxfSql = "SELECT LEFT ( pr.create_time, 19 ) AS executeTime ,LEFT ( pr.pres_create_time, 19 ) AS buildCreateTime , pr.doctor AS doctorCode, pr.doctor_name AS doctorNmae,pr.`status`," +
                        " pr.hospital_name, pr.hospital, p.`name` AS patientName,p.code AS patientCode,pr.`code` AS id,7 as code, 2 as flag " +
                        " FROM  wlyy.wlyy_prescription pr  LEFT JOIN wlyy.wlyy_patient p ON pr.patient = p.`code` WHERE " +
                        "  1 = 1  AND pr.STATUS = '100' AND p.code= '" + patient + "' GROUP BY  pr.CODE ";
                list = jdbcTemplate.queryForList(cfxfSql);
            }
            if (6 == searchTask) { //随访
                String sfSql = "SELECT DISTINCT DATE_FORMAT(wf.followup_date,'%Y/%m/%d %H:%i') followupDate,DATE_FORMAT(wf.followup_plan_date,'%Y/%m/%d %H:%i') executeTime,wf.doctor_code doctorCode,wf.followup_class followupClass, " +
                        " wf.patient_code AS patientCode,wf.patient_name AS patientName,wf.doctor_name doctorName,wf.`status` AS `status`,wf.org_name orgName," +
                        " wf.org_code orgCode,sd.value AS `value`, wf.followup_type  followupType,wf.id AS id, 6 AS code,2 as flag FROM  wlyy.wlyy_followup wf " +
                        " LEFT JOIN wlyy.system_dict sd ON wf.followup_type = sd.CODE " +
                        " 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);
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, rehabilitationDetailList);
    }
    /**
     * 多个康复计划服务项目内容列表
     *
     * @param planDetailIds
     * @return
     * @throws Exception
     */
    public ObjEnvelop serviceItemList(String planDetailIds, String doctorCode) throws Exception {
        String[] s = planDetailIds.split(",");
        String planDetailList = "";
        for (String one : s) {
            planDetailList += ",'" + one + "'";
        }
        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 " +
                " 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);
        List<Map<String, Object>> serviceItemList = jdbcTemplate.queryForList(sql);
//        if(serviceItemList.size()>0){
//            Map<String,Object> serviceItem = serviceItemList.get(0);
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (Map<String, Object> one : serviceItemList) {
            Map<String, Object> resultMap = new HashMap<>();
            Integer isMyTask = 0;
            if (StringUtils.isNotEmpty(doctorCode) && doctorCode.equals(one.get("executeDoctor") + "")) {
                isMyTask = 1;
            }
            resultMap.put("isMyTask", isMyTask);//0不是自己的任务,1是自己的任务
//            if(!(one.get("specialistDoctor")+"").equals((one.get("create_user")+""))){
//                executeDoctorList.add(one.get("create_user_name")+"");
//            }
            List<String> executeDoctorList = new ArrayList<>();
            executeDoctorList.add(one.get("executeDoctorName") + "");
            resultMap.put("executeDoctorList", executeDoctorList);//执行医生名称列表
            resultMap.put("executeDoctorCode", one.get("executeDoctor") + "");//执行医生code
            resultMap.put("executeDoctorName", one.get("executeDoctorName") + "");//执行医生code
            resultMap.put("specialistDoctorCode", one.get("createDoctor") + "");//创建人(专科)医生code
            resultMap.put("specialistDoctorName", one.get("createDoctorName") + "");//创建人(专科)医生名字
            resultMap.put("title", one.get("name"));//项目标题
            resultMap.put("planDetaiId", one.get("id"));//计划服务项目id
            resultMap.put("planId", one.get("planId"));//计划id
            resultMap.put("shortExecuteTime", DateUtil.dateToStr((Date) one.get("execute_time"), DateUtil.HH_MM));//项目标题
            resultMap.put("content", one.get("content"));//项目内容
            resultMap.put("hospitalName", one.get("hospital_name"));//地点
            resultMap.put("executeTime", one.get("execute_time"));//执行时间
            DecimalFormat df = new DecimalFormat("0.00");
            resultMap.put("expense", one.get("expense") != null ? df.format(((Integer) one.get("expense") * 1.00)) : 0);//收费
            resultMap.put("reserve", null);//是否需要预约(1预约、0不预约)
            resultMap.put("planStatus", one.get("planStatus"));//计划的状态
            Integer status = Integer.valueOf(one.get("status").toString());//状态(0未完成,1已完成,2已预约)
            String statusName = "";
            switch (status) {
                case 0: {
                    statusName = "未完成";
                    break;
                }
                case 1: {
                    statusName = "已完成";
                    break;
                }
                case 2: {
                    statusName = "已预约";
                    break;
                }
            }
            resultMap.put("statusName", statusName);//状态
            //指导与汇报
            List<GuidanceMessageLogDO> messageList = guidanceMessageLogDao.findByPlanDetailId(one.get("id").toString());
            List<Map<String, Object>> messageMapList = new ArrayList<>();
            for (GuidanceMessageLogDO one2 : messageList) {
                Map<String, Object> map = new HashMap<>();
                map.put("doctorName", one2.getDoctorName());
                map.put("adminTeamName", one2.getAdminTeamName());
                map.put("content", one2.getContent());
                map.put("contentType", one2.getContentType());
                map.put("createTime", DateUtil.dateToStr(one2.getCreateTime(), "MM-dd HH:mm"));
                messageMapList.add(map);
            }
            /* Integer itemType = (Integer) one.get("itemType");*/
            resultMap.put("messageList", messageMapList);//指导与汇报记录
            resultMap.put("patient", one.get("patient"));
            resultMap.put("itemType", one.get("code"));
            resultMap.put("detaiType", one.get("detaiType"));
            resultMap.put("status", status);//状态
            //是否完成任务
            List<RehabilitationOperateRecordsDO> operateList = rehabilitationOperateRecordsDao.findByRehabilitationDetailId(one.get("id").toString());
            Integer operate = 0;
            if (operateList.size() > 0) {
                operate = 1;
                RehabilitationOperateRecordsDO temp = operateList.get(0);
                operate = 1;
                Date completeTime = temp.getCompleteTime();
                String completeTimeStr = DateUtil.dateToStr(completeTime, DateUtil.YYYY_MM_DD_HH_MM);
                resultMap.put("completeTime", completeTimeStr);//完成时间
                resultMap.put("operatorDoctorName", temp.getDoctorName());//执行医生名称
                resultMap.put("node", temp.getNode());
                resultMap.put("relationRecordImg", (temp.getRelationRecordImg() != null && StringUtils.isNotEmpty(temp.getRelationRecordImg())) ? (new JSONArray(temp.getRelationRecordImg())) : null);//json格式
                resultMap.put("relationRecordCode", temp.getRelationRecordCode());
                resultMap.put("completeTimeShort", DateUtil.dateToStr(completeTime, "yyyy/MM/dd"));
            }
            resultMap.put("operate", operate);//是否完成任务(默认0:未完成,1:已完成)
            resultList.add(resultMap);
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultList);
//        }
//        return MixEnvelop.getError("没有该服务项详情信息!");
    }
    /**
     * 康复计划服务项目确认页
     *
     * @param planDetailId
     * @return
     * @throws Exception
     */
    public ObjEnvelop serviceItem(String planDetailId, String doctorCode, String recordId) throws Exception {
        String sql = "select h.name as title,h.content as content,h.code as itemType,d.id,d.execute_time,d.hospital_name,d.status,d.type,d.expense,d.doctor as executeDoctor, " +
                " 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 " +
                " where d.id = '" + planDetailId + "'";
        sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName2(sql);
        sql = TransforSqlUtl.wlyy_patient_rehabilitation_planCreateName(sql);
        sql = TransforSqlUtl.wlyy_plan_detail_appointmentAppDoctorName(sql);
        sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName(sql);
        List<Map<String, Object>> serviceItemList = jdbcTemplate.queryForList(sql);
        if (serviceItemList.size() == 0) {
            return ObjEnvelop.getSuccess(SpecialistMapping.api_success, new HashMap<>());
        }
        Map<String, Object> one = serviceItemList.get(0);
        Map<String, Object> resultMap = new HashMap<>();
        List<String> executeDoctorList = new ArrayList<>();
        Integer isMyTask = 0;
        //判断登陆者和执行医生是不是同一个人
        if (StringUtils.isNotEmpty(doctorCode) && doctorCode.equals(one.get("executeDoctor") + "")) {
            isMyTask = 1;
        }
        // 协诊预约信息
        resultMap.put("appointmentTime", one.get("appointmentTime"));
        resultMap.put("appointmentDoctor", one.get("appointmentDoctor"));
        resultMap.put("appointmentDoctorName", one.get("appointmentDoctorName"));
        resultMap.put("reservationType", one.get("reservationType"));//复诊类型:1线上,2线下,3远程
        resultMap.put("followupDetailType", one.get("followupDetailType"));
        resultMap.put("frequencyCode", one.get("frequencyCode") + "");
        resultMap.put("isMyTask", isMyTask);//0不是自己的任务,1是自己的任务
//        if(!(one.get("specialistDoctor")+"").equals((one.get("create_user")+""))){
//            executeDoctorList.add(one.get("create_user_name")+"");
//        }
        executeDoctorList.add(one.get("executeDoctorName") + "");//
        resultMap.put("remark", one.get("remark"));//备注
        resultMap.put("executeDoctorList", executeDoctorList);//执行医生名称列表
        resultMap.put("executeDoctorCode", one.get("executeDoctor") + "");//执行医生code
        resultMap.put("executeDoctorName", one.get("executeDoctorName") + "");//执行医生名称
        resultMap.put("specialistDoctorCode", one.get("createDoctor") + "");//创建人(专科)医生code
        resultMap.put("specialistDoctorName", one.get("createDoctorName") + "");//创建人(专科)医生名字
        resultMap.put("title", one.get("title"));//项目标题
        resultMap.put("shortExecuteTime", DateUtil.dateToStr((Date) one.get("execute_time"), DateUtil.HH_MM));//项目标题
        resultMap.put("content", one.get("content"));//项目内容
        resultMap.put("hospitalName", one.get("hospital_name"));//地点
        resultMap.put("executeTime", one.get("execute_time"));//执行时间
        DecimalFormat df = new DecimalFormat("0.00");
        resultMap.put("expense", one.get("expense") != null ? df.format(((Integer) one.get("expense") * 1.00)) : 0);//收费
        resultMap.put("reserve", one.get("reserve"));//是否需要预约(1预约、0不预约)
        resultMap.put("planStatus", one.get("planStatus"));//计划的状态
        resultMap.put("relationCode", one.get("relationCode"));//业务关联code
        Integer status = Integer.valueOf(one.get("status").toString());//状态(0未完成,1已完成,2已预约)
        String statusName = "";
        switch (status) {
            case 0: {
                statusName = "未完成";
                break;
            }
            case 1: {
                statusName = "已完成";
                break;
            }
            case 2: {
                statusName = "已预约";
                break;
            }
            case 3: {
                statusName = "待录入";
                break;
            }
        }
        resultMap.put("statusName", statusName);//状态名称
        resultMap.put("status", status);//状态
        resultMap.put("disease", one.get("disease"));
        resultMap.put("diseaseName", one.get("diseaseName"));
        resultMap.put("planTitle", one.get("planTitle"));
        resultMap.put("planId", one.get("planId"));
        //指导与汇报
        List<GuidanceMessageLogDO> messageList = guidanceMessageLogDao.findByPlanDetailId(one.get("id").toString());
        List<Map<String, Object>> messageMapList = new ArrayList<>();
        for (GuidanceMessageLogDO one2 : messageList) {
            Map<String, Object> map = new HashMap<>();
            map.put("doctorName", one2.getDoctorName());
            map.put("adminTeamName", one2.getAdminTeamName());
            map.put("content", one2.getContent());
            map.put("contentType", one2.getContentType());
            map.put("doctorType", one2.getDoctorType());//医生类型
            map.put("createTime", DateUtil.dateToStr(one2.getCreateTime(), "MM-dd HH:mm"));
            messageMapList.add(map);
        }
        resultMap.put("messageList", messageMapList);//指导与汇报记录
        resultMap.put("patient", one.get("patient"));
        resultMap.put("patientName", one.get("patientName"));
        resultMap.put("type", one.get("itemType"));//1扫码、0上传附件、2、健康教育,3、健康指导,4、随访
        //是否完成任务
        List<RehabilitationOperateRecordsDO> operateList = new ArrayList<>();
        if (StringUtils.isNoneBlank(recordId)) {
            operateList = rehabilitationOperateRecordsDao.findByRehabilitationDetailIdAndId(one.get("id").toString(), recordId);
        } else {
            operateList = rehabilitationOperateRecordsDao.findByRehabilitationDetailId(one.get("id").toString());
        }
        Integer operate = 0;
        if (operateList.size() > 0) {
            RehabilitationOperateRecordsDO temp = operateList.get(0);
            operate = 1;
            Date completeTime = temp.getCompleteTime();
            String completeTimeStr = DateUtil.dateToStr(completeTime, DateUtil.YYYY_MM_DD_HH_MM);
            resultMap.put("completeTime", completeTimeStr);//完成时间
            resultMap.put("operatorDoctorName", temp.getDoctorName());//执行医生名称
            resultMap.put("node", temp.getNode());
            resultMap.put("recordStatus", temp.getStatus());//操作记录
            resultMap.put("recordRelationCode", temp.getRelationCode());
            resultMap.put("recordFlag", temp.getFlag());
            resultMap.put("recordId", temp.getId());
            JSONArray imgs = new JSONArray();
            if (temp.getRelationRecordImg() != null && StringUtils.isNotEmpty(temp.getRelationRecordImg())) {
                resultMap.put("relationRecordImg", (temp.getRelationRecordImg() != null && StringUtils.isNotEmpty(temp.getRelationRecordImg())) ? (new JSONArray(temp.getRelationRecordImg())) : null);//json格式
            } else {
                resultMap.put("relationRecordImg", imgs);
            }
            /*   if(itemType!=1&&itemType!=0){*/
            resultMap.put("relationRecordCode", temp.getRelationRecordCode());
            resultMap.put("completeTimeShort", DateUtil.dateToStr(completeTime, "yyyy/MM/dd"));
            /*          }*/
        }
        resultMap.put("operate", operate);//是否完成任务(默认0:未完成,1:已完成)
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultMap);
    }
    /**
     * 康复管理居民详情页
     *
     * @param patientCode
     * @param healthDoctor
     * @param healthDoctorName
     * @param generalDoctor
     * @param generalDoctorName
     * @return
     */
    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 " +
                " where p.patient='" + patientCode + "' and p.status=1 ";
        List<Map<String, Object>> patientInfoList = jdbcTemplate.queryForList(patientInfoSql);
        Map<String, Object> patientInfo = new HashMap<>();
        String rehabilitationOrg = "";
        for (Map<String, Object> one : patientInfoList) {
            rehabilitationOrg += "," + one.get("hospital_name");
        }
        patientInfo.put("rehabilitationOrg", StringUtils.isNotEmpty(rehabilitationOrg) ? rehabilitationOrg.substring(1) : "");
        resultMap.put("patientInfo", patientInfo);
        //服务医生
        //完成项目=全部的服务项目-未完成的服务项目
        List<Map<String, Object>> serviceDoctorList = new ArrayList<>();
        //全科医生和健管师要是同一个人,就显示全科医生
        /*      if(!generalDoctor.equals(healthDoctor)){
         */
        if (StringUtils.isNotEmpty(healthDoctor)) {
            Map<String, Object> healthDoctorMap = new HashMap<>();
            healthDoctorMap.put("type", "健管师");
            healthDoctorMap.put("doctorName", healthDoctorName);
            healthDoctorMap.put("doctorCode", healthDoctor);
            Integer healthUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(healthDoctor, patientCode, 1);
            Integer healthFinishCount = rehabilitationDetailDao.findItemByDoctor(healthDoctor, patientCode);
            Integer healthServiceCount = rehabilitationDetailDao.completeServiceByDoctor(healthDoctor, patientCode, 1);
            healthDoctorMap.put("finishedItem", healthFinishCount - healthUnfinishCount);
            healthDoctorMap.put("serviceCount", healthServiceCount);
            serviceDoctorList.add(healthDoctorMap);
        }
        /*        }*/
        if (StringUtils.isNotEmpty(generalDoctor)) {
            Map<String, Object> generalDoctorMap = new HashMap<>();
            generalDoctorMap.put("type", "全科医生");
            generalDoctorMap.put("doctorName", generalDoctorName);
            generalDoctorMap.put("doctorCode", generalDoctor);
            Integer generalUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(generalDoctor, patientCode, 1);
            Integer generalFinishCount = rehabilitationDetailDao.findItemByDoctor(generalDoctor, patientCode);
            Integer generalServiceCount = rehabilitationDetailDao.completeServiceByDoctor(generalDoctor, patientCode, 1);
            generalDoctorMap.put("finishedItem", generalFinishCount - generalUnfinishCount);
            generalDoctorMap.put("serviceCount", generalServiceCount);
            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 + "'";
        specialistRelationSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName2(specialistRelationSql);
        List<Map<String, Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
        for (Map<String, Object> one : specialistRelationList) {
            String doctor = one.get("doctor") + "";
            String doctorName = one.get("doctor_name") + "";
            Integer unfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(doctor, patientCode, 1);
            Integer finishCount = rehabilitationDetailDao.findItemByDoctor(doctor, patientCode);
            Integer serviceCount = rehabilitationDetailDao.completeServiceByDoctor(doctor, patientCode, 1);
            Map<String, Object> map = new HashMap<>();
            map.put("finishedItem", finishCount - unfinishCount);
            map.put("serviceCount", serviceCount);
            map.put("doctorName", doctorName);
            map.put("doctorCode", doctor);
            map.put("type", "专科医生");
            serviceDoctorList.add(map);
        }
        resultMap.put("serviceDoctorList", serviceDoctorList);
        //康复计划
        List<Map<String, Object>> planList = new ArrayList<>();
        List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatients(patientCode);
        Integer planUnderway = 0;//进行中
        Integer planFinish = 0;//已完成
        for (PatientRehabilitationPlanDO one : list) {
            if (one.getStatus() == 1) {
                planUnderway += 1;
            } else if (one.getStatus() == 2) {
                planFinish += 1;
            }
            Map<String, Object> map = new HashMap<>();
            //安排类型
            String planTypeName = null;
            Integer planTypeTemp = one.getPlanType();
            switch (planTypeTemp) {
                case 1:
                    planTypeName = "康复计划";
                    break;
                case 2:
                    planTypeName = "(转)社区医院";
                    break;
                case 3:
                    planTypeName = "(转)转家庭病床";
                    break;
            }
            map.put("createUser", one.getCreateUser());
            map.put("createUserName", one.getCreateUserName());
            map.put("planId", one.getId());
            map.put("planTypeName", planTypeName);
            String statusName = "";
            Integer status = one.getStatus();
            switch (status) {
                case 0: {
                    statusName = "已中止";
                    break;
                }
                case 1: {
                    statusName = "进行中";
                    break;
                }
                case 2: {
                    statusName = "已完成";
                    break;
                }
            }
            map.put("planTypeName", planTypeName);//安排类型名称
            map.put("statusName", statusName);//状态名称
            map.put("medicalRecordsCode", one.getMedicalRecordsCode());//住院code
            map.put("adviceContent", one.getAdviceContent());//康复建议
            //已完成
            Integer allFinishCount = rehabilitationDetailDao.findByStatusAndPlanId(1, one.getId());
            map.put("allFinishCount", allFinishCount);//已完成
            //完成度(已完成/(已完成+未完成))
            Integer allCount = rehabilitationDetailDao.findAllByPlanId(one.getId());
            map.put("allCount", allCount);//总数
            List<RehabilitationDetailDO> detailList = rehabilitationDetailDao.getAllRehabilitationDetail(one.getId());
            if (detailList.size() > 0) {
                Date executeTimeStart = detailList.get(0).getExecuteTime();
                Date executeTimeEnd = detailList.get(detailList.size() - 1).getExecuteTime();
                String executeStart = DateUtil.dateToStr(executeTimeStart, "yyyy/MM/dd");
                String executeEnd = DateUtil.dateToStr(executeTimeEnd, "yyyy/MM/dd");
                map.put("time", executeStart + "-" + executeEnd);
            } else {
                map.put("time", "");
            }
            planList.add(map);
        }
        resultMap.put("planList", planList);
        //康复计划-已完成、进行中
        resultMap.put("planUnderway", planUnderway);//进行中
        resultMap.put("planFinish", planFinish);//已完成
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultMap);
    }
    /**
     * 居民康复计划详情页-近期康复相关记录
     *
     * @param patientCode
     * @param startTime
     * @param endTime
     */
    public ObjEnvelop recentPlanDetailRecord(String patientCode, String startTime, String endTime, Integer page, Integer pageSize) throws Exception {
        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" +
                " 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)) {
            planDetailSql += "  and d.execute_Time>='" + startTime + "' ";
        }
        if (StringUtils.isNotEmpty(endTime)) {
            planDetailSql += "  and d.execute_time<='" + endTime + "' ";
        }
        planDetailSql += " ORDER BY s.complete_time DESC LIMIT " + (page - 1) * pageSize + "," + pageSize;
        planDetailSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll2(planDetailSql);
        List<Map<String, Object>> planDetails = jdbcTemplate.queryForList(planDetailSql);
        List<Map<String, Object>> planDetailList = new ArrayList<>();
        for (Map<String, Object> one : planDetails) {
            Date executeTimeDate = (Date) one.get("complete_time");
            String executeTime = DateUtil.dateToStr(executeTimeDate, "yyyy/MM/dd HH:mm");
            String content = one.get("code") + "";
            String title = one.get("name") + "";
            Integer status = (Integer) one.get("status");
            String statusName = "";
            switch (status) {
                case 0: {
                    statusName = "未完成";
                    break;
                }
                case 1: {
                    statusName = "已完成";
                    break;
                }
                case 2: {
                    statusName = "已预约";
                    break;
                }
            }
            String id = one.get("id").toString();
            Map<String, Object> map = new HashMap<>();
            map.put("id", id);//id
//            List<RehabilitationOperateRecordsDO> rehabilitationOperateRecords = rehabilitationOperateRecordsDao.findByRehabilitationDetailId(id);
//            Date completeTime = rehabilitationOperateRecords!=null&&rehabilitationOperateRecords.size()>0?rehabilitationOperateRecords.get(0).getCompleteTime():null;
//            String completeTimeStr =  completeTime!=null?DateUtil.dateToStr(completeTime,"yyyy/MM/dd HH:mm"):"";
            map.put("executeTime", executeTime);//执行时间
            map.put("title", title);//项目标题
            map.put("content", content);//项目内容
            map.put("statusName", statusName);//状态名称
            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 + "'";
        List<Map<String, Object>> planDetailList2 = jdbcTemplate.queryForList(planDetailCountSql);
        Integer planDetailFinish = 0;
        Integer planDetailUnfinish = 0;
        for (Map<String, Object> one : planDetailList2) {
            Integer status = (Integer) one.get("num");
            if (status == 1) {
                planDetailFinish += 1;
            } else {
                planDetailUnfinish += 1;
            }
        }
        resultMap.put("planDetailFinish", planDetailFinish);//已完成
        resultMap.put("planDetailUnfinish", planDetailUnfinish);//未完成
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultMap);
    }
    /**
     * 保存康复管理指导留言信息
     *
     * @param messageId
     * @param doctor
     * @param doctorType 1、专科医生,2、家庭医生
     */
    @Transactional
    public Envelop saveGuidanceMessage(String messageId, String doctor, Integer doctorType, String content, String planDetailId, Integer contentType) throws Exception {
        List<String> patientList = rehabilitationDetailDao.findPatientById(planDetailId);
        String patient = patientList.size() > 0 ? patientList.get(0) : "";
        GuidanceMessageLogDO guidanceMessageLogDO = new GuidanceMessageLogDO();
        guidanceMessageLogDO.setMessageId(messageId);
        guidanceMessageLogDO.setPlanDetailId(planDetailId);
        guidanceMessageLogDO.setContent(content);
        guidanceMessageLogDO.setDoctor(doctor);
        guidanceMessageLogDO.setContentType(contentType);
        guidanceMessageLogDO.setDoctorType(doctorType);
        Integer adminTeamCode = null;
        String doctorName = null;
        if (doctorType == 1) {
            SpecialistPatientRelationDO specialistPatientRelationDO = specialistPatientRelationDao.findByPatientAndDoctor(doctor, patient);
            adminTeamCode = specialistPatientRelationDO.getTeamCode();
            doctorName = specialistPatientRelationDO.getDoctorName();
        } else if (doctorType == 2) {
            String signFamilySql = " select f.* from " + basedb + ".wlyy_sign_family f where f.status=1 and f.expenses_status='1' and f.patient='" + patient + "'";
            List<Map<String, Object>> signFamily = jdbcTemplate.queryForList(signFamilySql);
            adminTeamCode = (Integer) signFamily.get(0).get("admin_team_code");
            doctorName = signFamily.get(0).get("doctor_name").toString();
        }
        String adminTeamSql = " select t.* from " + basedb + ".wlyy_admin_team t where t.available=1 and t.id=" + adminTeamCode;
        List<Map<String, Object>> adminTeam = jdbcTemplate.queryForList(adminTeamSql);
        String adminTeamName = adminTeam.get(0).get("name").toString();
        guidanceMessageLogDO.setAdminTeamCode(adminTeamCode);
        guidanceMessageLogDO.setAdminTeamName(adminTeamName);
        guidanceMessageLogDO.setDoctorName(doctorName);
        guidanceMessageLogDO.setCreateTime(new Date());
        guidanceMessageLogDO.setUpdateTime(new Date());
        guidanceMessageLogDao.save(guidanceMessageLogDO);
        return Envelop.getSuccess(SpecialistMapping.api_success);
    }
    /**
     * 康复管理-更新康复计划操作完成日志状态
     *
     * @param planDetailId
     * @param status
     * @throws Exception
     */
    @Transactional
    public Envelop updateStatusRehabilitationOperate(Integer status, String planDetailId) {
        if (rehabilitationOperateRecordsDao.updateStatus(status, planDetailId) > 0) {
            return Envelop.getSuccess(SpecialistMapping.api_success);
        }
        return Envelop.getError("更新失败!");
    }
    /**
     * app端居民详情服务医生列表
     *
     * @param patientCode
     * @param healthDoctor
     * @param healthDoctorName
     * @param generalDoctor
     * @param generalDoctorName
     * @return
     */
    public ObjEnvelop serviceDoctorList(String patientCode, String healthDoctor, String healthDoctorName, String generalDoctor, String generalDoctorName) {
        //服务医生
        //完成项目=全部的服务项目-未完成的服务项目
        List<Map<String, Object>> serviceDoctorList = new ArrayList<>();
        if (StringUtils.isNotEmpty(generalDoctor)) {
            Map<String, Object> generalDoctorMap = new HashMap<>();
            generalDoctorMap.put("type", "全科医生");
            generalDoctorMap.put("doctorName", generalDoctorName);
            generalDoctorMap.put("doctorCode", generalDoctor);
            Integer generalUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(generalDoctor, patientCode, 1);
            Integer generalFinishCount = rehabilitationDetailDao.findItemByDoctor(generalDoctor, patientCode);
            Integer generalServiceCount = rehabilitationDetailDao.completeServiceByDoctor(generalDoctor, patientCode, 1);
            generalDoctorMap.put("finishedItem", generalFinishCount - generalUnfinishCount);
            generalDoctorMap.put("serviceCount", generalServiceCount);
            serviceDoctorList.add(generalDoctorMap);
        }
        if (StringUtils.isNotEmpty(healthDoctor)) {
            Map<String, Object> healthDoctorMap = new HashMap<>();
            healthDoctorMap.put("type", "健管师");
            healthDoctorMap.put("doctorName", healthDoctorName);
            healthDoctorMap.put("doctorCode", healthDoctor);
            Integer healthUnfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(healthDoctor, patientCode, 1);
            Integer healthFinishCount = rehabilitationDetailDao.findItemByDoctor(healthDoctor, patientCode);
            Integer healthServiceCount = rehabilitationDetailDao.completeServiceByDoctor(healthDoctor, patientCode, 1);
            healthDoctorMap.put("finishedItem", healthFinishCount - healthUnfinishCount);
            healthDoctorMap.put("serviceCount", healthServiceCount);
            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 + "'";
        specialistRelationSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailDoctorName2(specialistRelationSql);
        List<Map<String, Object>> specialistRelationList = jdbcTemplate.queryForList(specialistRelationSql);
        for (Map<String, Object> one : specialistRelationList) {
            String doctor = one.get("doctor") + "";
            String doctorName = one.get("doctor_name") + "";
            Integer unfinishCount = rehabilitationDetailDao.unfinishItemByDoctor(doctor, patientCode, 1);
            Integer finishCount = rehabilitationDetailDao.findItemByDoctor(doctor, patientCode);
            Integer serviceCount = rehabilitationDetailDao.completeServiceByDoctor(doctor, patientCode, 1);
            Map<String, Object> map = new HashMap<>();
            map.put("finishedItem", finishCount - unfinishCount);
            map.put("serviceCount", serviceCount);
            map.put("doctorName", doctorName);
            map.put("doctorCode", doctor);
            map.put("type", "专科医生");
            serviceDoctorList.add(map);
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, serviceDoctorList);
    }
    /**
     * app端、微信端计划的服务项目列表
     *
     * @param planId
     * @param searchTask
     * @param status
     * @param executeStartTime
     * @param executeEndTime
     * @return
     */
    public ObjEnvelop appCalendarPlanDetailList(String planId, Integer searchTask, Integer status, String executeStartTime, String executeEndTime) {
        Map<String, Object> resultMap = new HashMap<>();
        ObjEnvelop objEnvelop = calendarPlanDetailList(planId, searchTask, status, null, executeStartTime, executeEndTime, "0");
        Integer finishCount = rehabilitationDetailDao.findByStatusAndPlanId(1, planId);
        Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);
        resultMap.put("planDetailList", objEnvelop.getObj());
        resultMap.put("finishCount", finishCount);
        resultMap.put("allCount", allCount);
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultMap);
    }
    /**
     * 每日康复服务通知
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public ObjEnvelop dailyJob(String startTime, String endTime) {
        String sql = "select d.doctor,p.patient,count(1) as num from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.status!=1 and p.status=1 and d.execute_time>='" + startTime + "' and d.execute_time<='" + endTime + "' GROUP BY d.doctor,p.patient";
//        List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        String doctorCode = "";
        String patientCode = "";
        List<String> listMap = null;
        for (Map<String, Object> one : list) {
            doctorCode = one.get("doctor") + "";
            patientCode = one.get("patient") + "";
            listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime, endTime, doctorCode, patientCode);
            String ids = "";
            for (String one2 : listMap) {
                ids += "," + one2;
            }
            one.put("planDetailIds", StringUtils.isNotEmpty(ids) ? ids.substring(1) : "");
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, list);
    }
    /**
     * 明日康复计划提醒
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public ObjEnvelop tomorrowJob(String startTime, String endTime) {
        String sql = "select d.doctor,p.patient,count(1) as num,p.id from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id where d.status!=1 and p.status=1 and d.execute_time>='" + startTime + "' and d.execute_time<='" + endTime + "' GROUP BY d.doctor,p.patient";
//        List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        String doctorCode = "";
        String patientCode = "";
        List<String> listMap = null;
        for (Map<String, Object> one : list) {
            doctorCode = one.get("doctor") + "";
            patientCode = one.get("patient") + "";
            listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime, endTime, doctorCode, patientCode);
            String ids = "";
            for (String one2 : listMap) {
                ids += "," + one2;
            }
            one.put("planDetailIds", StringUtils.isNotEmpty(ids) ? ids.substring(1) : "");
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, list);
    }
    /**
     * 每日康复计划提醒
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public ObjEnvelop dailyByJob(String startTime, String endTime) {
        String sql = "select d.doctor,p.patient,h.service_item_name AS serviceItemName,d.time_type AS timeType from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id left join wlyy_hospital_service_item h ON h.id=d.hospital_service_item_id where d.status!=1 and p.status=1 and d.execute_time>='" + startTime + "' and d.execute_time<='" + endTime + "' GROUP BY d.doctor,p.patient,d.execute_time";
//        List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        String doctorCode = "";
        String patientCode = "";
        List<String> listMap = null;
        for (Map<String, Object> one : list) {
            doctorCode = one.get("doctor") + "";
            patientCode = one.get("patient") + "";
            listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime, endTime, doctorCode, patientCode);
            String ids = "";
            for (String one2 : listMap) {
                ids += "," + one2;
            }
            one.put("planDetailIds", StringUtils.isNotEmpty(ids) ? ids.substring(1) : "");
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, list);
    }
    /**
     * 更新康复计划项目操作日志并且确认完成更新status.
     *
     * @param node
     * @param image
     * @param planDeatilId
     * @return
     */
    public Map<String, Object> updateNodeAndRelationRecordImg(String node, String image, String status, String planDeatilId, String relationCode) throws Exception {
        Map<String, Object> resultMap = new HashedMap();
        try {
            RehabilitationDetailDO detailDO = rehabilitationDetailDao.findById(planDeatilId);
            detailDO.setStatus(1);
            if (StringUtils.isNoneBlank(status)) {
                detailDO.setStatus(Integer.parseInt(status));
            }
            detailDO.setUpdateTime(new Date());
            if (StringUtils.isNoneBlank(relationCode)) {
                detailDO.setRelationCode(relationCode);
            }
            rehabilitationDetailDao.save(detailDO);
            if (StringUtils.isNoneBlank(image) && StringUtils.isNoneBlank(node)) {
                int j = rehabilitationOperateRecordsDao.updateNodeAndRelationRecordImg(node, image, planDeatilId);
            } else if (StringUtils.isNoneBlank(node)) {
                int j = rehabilitationOperateRecordsDao.updateNodeByPlanDetailId(node, planDeatilId);
            } else if (StringUtils.isNoneBlank(image)) {//
                int j = rehabilitationOperateRecordsDao.updateImagByPlanDetailId(image, planDeatilId);
            } else {//跟新为已完成
                int j = rehabilitationOperateRecordsDao.updateStatus(1, planDeatilId);
            }
            //如果整个计划的服务项都完成了,整个计划也完成了
            String allSql = "SELECT * FROM wlyy_rehabilitation_plan_detail where plan_id = (SELECT plan_id FROM `wlyy_rehabilitation_plan_detail` WHERE id='" + planDeatilId + "')";
            allSql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll(allSql);
            List<RehabilitationDetailDO> rehabilitationDetailDOList = jdbcTemplate.query(allSql, new BeanPropertyRowMapper<>(RehabilitationDetailDO.class));
            int allCount = 0;
            String planId = "";
            for (RehabilitationDetailDO rehabilitationDetailDO : rehabilitationDetailDOList) {
                if (rehabilitationDetailDO.getStatus() == 1) {
                    allCount++;
                }
            }
            if (rehabilitationDetailDOList.size() > 0 && rehabilitationDetailDOList.size() == allCount) {
                planId = rehabilitationDetailDOList.get(0).getPlanId();
                patientRehabilitationPlanDao.updateStatusAndTimeById(2, planId, new Date());
            }
        } catch (Exception e) {
            throw new Exception("更新服务状态失败!");
        }
        //更新返回数据提供发送消息使用
        String sql = "SELECT" +
                " i.service_item_id," +
                " r.doctor_code," +
                " r.patient_code," +
                " pd.hospital" +
                " FROM" +
                " wlyy_rehabilitation_plan_detail pd" +
                " LEFT JOIN wlyy_hospital_service_item i ON pd.hospital_service_item_id = i.id" +
                " LEFT JOIN wlyy_rehabilitation_operate_records r ON pd.id = r.rehabilitation_detail_id" +
                " WHERE" +
                " pd.id = '" + planDeatilId + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        if (list != null && list.size() > 0) {
            resultMap = list.get(0);
        }
        String itemSql = "SELECT evaluation,title FROM `wlyy_service_item` WHERE id='" + String.valueOf(resultMap.get("service_item_id")) + "'";
        List<Map<String, Object>> itemList = jdbcTemplate.queryForList(itemSql);
        if (itemList != null && itemList.size() > 0) {
            resultMap.put("evaluation", itemList.get(0).get("evaluation"));
            resultMap.put("title", itemList.get(0).get("title"));
        }
        return resultMap;
    }
    /**
     * 电话关怀拨打电话后生成对应记录
     *
     * @param jsonStr
     */
    public RehabilitationOperateRecordsDO planDetailAfterCall(String jsonStr) {
        JSONObject jsonObject = JSON.parseObject(jsonStr);
        /*{
            "rehabilitationDetailId":"808080eb764ba46b017669712c640012",
                "doctorCode":"7e06886207e843948ae65d8f91d6ca97",
                "doctorName":"兰冠勇"
        }*/
        RehabilitationDetailDO rehabilitationDetailDO = rehabilitationDetailDao.findById(jsonObject.getString("rehabilitationDetailId"));
        PatientRehabilitationPlanDO patientRehabilitationPlanDO = patientRehabilitationPlanDao.findById(rehabilitationDetailDO.getPlanId()).orElse(null);
        RehabilitationOperateRecordsDO rehabilitationOperateRecordsDO = new RehabilitationOperateRecordsDO();
        rehabilitationOperateRecordsDO.setId(getCode());
        if (rehabilitationDetailDO.getExecuteTime() != null) {
            rehabilitationOperateRecordsDO.setReserveTime(rehabilitationDetailDO.getExecuteTime());
        }
        rehabilitationOperateRecordsDO.setStatus(3);
        rehabilitationOperateRecordsDO.setRelationRecordImg("[]");
        rehabilitationOperateRecordsDO.setRehabilitationDetailId(rehabilitationDetailDO.getId());
        rehabilitationOperateRecordsDO.setPatientCode(patientRehabilitationPlanDO.getPatient());
        rehabilitationOperateRecordsDO.setPatientName(patientRehabilitationPlanDO.getName());
        rehabilitationOperateRecordsDO.setDoctorCode(jsonObject.getString("doctorCode"));
        rehabilitationOperateRecordsDO.setDoctorName(jsonObject.getString("doctorName"));
        rehabilitationOperateRecordsDO.setRelationRecordType(5);
        rehabilitationOperateRecordsDO.setCompleteTime(new Date());
        rehabilitationOperateRecordsDO.setCreateTime(new Date());
        rehabilitationOperateRecordsDO.setUpdateTime(new Date());
        if (StringUtils.isNoneBlank(rehabilitationDetailDO.getFrequencyCode())) {//限定频次的
            rehabilitationDetailDO.setStatus(3);
            rehabilitationDetailDao.save(rehabilitationDetailDO);
//            rehabilitationOperateRecordsDO.setRelationRecordType(8);
        }
        return rehabilitationOperateRecordsDao.save(rehabilitationOperateRecordsDO);
    }
    /**
     * 更新康复计划项目状态
     *
     * @param status
     * @param planDetailId
     * @return
     */
    public Envelop updatePlanDetailStatusById(Integer status, String planDetailId) throws Exception {
        if (rehabilitationDetailDao.updateStatusById(status, planDetailId) > 0) {
            return Envelop.getSuccess(SpecialistMapping.api_success);
        }
        return Envelop.getError("更新失败!");
    }
    public Envelop updatePlanDetailExecuteTimeById(Date executeTime, String planDetailId) throws Exception {
        if (rehabilitationDetailDao.updateExecuteTime(executeTime, planDetailId) > 0) {
            return Envelop.getSuccess(SpecialistMapping.api_success);
        }
        return Envelop.getError("更新失败!");
    }
    /**
     * 计划总进度
     *
     * @param planId
     * @return
     */
    public ObjEnvelop planSchedule(String planId) {
        Map<String, Object> resultMap = new HashMap<>();
        Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);//计划总服务项目数
        Integer finishedCount = rehabilitationDetailDao.findByStatusAndPlanId(1, planId);
        PatientRehabilitationPlanDO p = patientRehabilitationPlanDao.findById(planId).orElse(null);
        SpecialistPatientRelationDO specialistPatientRelationDO;
        if (p.getTeamCode() != null) {
            specialistPatientRelationDO = specialistPatientRelationDao.findByTeamCodeAndPatient(p.getTeamCode(), p.getPatient());
        } else {
            specialistPatientRelationDO = specialistPatientRelationDao.findByDoctorAndPatient(p.getCreateUser(), p.getPatient());
        }
        resultMap.put("allCount", allCount);
        resultMap.put("finishedCount", finishedCount);
        resultMap.put("specialistPatientRelationDO", specialistPatientRelationDO);
        if (p != null) {
            resultMap.put("disease", p.getDisease());
            resultMap.put("diseaseName", p.getDiseaseName());
            resultMap.put("createUser", p.getCreateUser());
            resultMap.put("planTitle", p.getTitle());
            resultMap.put("status", p.getStatus());
            resultMap.put("patientImg", p.getPatientImg());
            resultMap.put("adviceContent", p.getAdviceContent());
            resultMap.put("createTimeDate", DateUtil.dateToStr(p.getCreateTime(), "yyyy-MM-dd"));
            resultMap.put("createTime", DateUtil.dateToStr(p.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
            resultMap.put("medicalRecordsCode", p.getMedicalRecordsCode());
        }
//        resultMap.put("healthyCondition",healthyCondition);
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, resultMap);
    }
    /**
     * 根据居民获取康复计划
     *
     * @param patient
     * @return
     */
    public ObjEnvelop planListByPatient(String patient) {
        List<PatientRehabilitationPlanDO> list = patientRehabilitationPlanDao.findByPatients(patient);
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, list);
    }
    /**
     * 医生已计划数,已完成计划数(居民数)
     *
     * @param doctorCode
     * @return
     */
    public ObjEnvelop patientCount(String doctorCode) {
        Integer count = patientRehabilitationPlanDao.patientCount(doctorCode);
        Integer finishCount = patientRehabilitationPlanDao.getFinishPatientCount(doctorCode);
        Map<String, Object> map = new HashMap<>();
        map.put("planCount", count);
        map.put("finishedPlanCount", finishCount);
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, map);
    }
    public ObjEnvelop dailyJobReserve(String startTime, String endTime) {
        String sql = "select DISTINCT d.doctor,p.patient,d.hospital from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
                " left join wlyy_hospital_service_item h on d.hospital_service_item_id=h.id " +
                " left join wlyy_service_item i on i.id =h.service_item_id " +
                " where d.status!=1 and d.execute_time>='" + startTime + "' and d.execute_time<='" + endTime + "' and i.reserve=1 and p.status!=0 and d.status=0 ";
//        List<Object> list = rehabilitationDetailDao.dailyJob(startTime,endTime);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        String doctorCode = "";
        String patientCode = "";
//        List<String> listMap  = null;
        for (Map<String, Object> one : list) {
            doctorCode = one.get("doctor") + "";
            patientCode = one.get("patient") + "";
            String sql2 = "select d.id from wlyy_rehabilitation_plan_detail d left join wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
                    " left join wlyy_hospital_service_item h on d.hospital_service_item_id=h.id " +
                    " left join wlyy_service_item i on i.id =h.service_item_id " +
                    " where d.status!=1 and d.execute_time>='" + startTime + "' and d.execute_time<='" + endTime + "' and i.reserve=1 and d.doctor='" + doctorCode + "' and p.patient='" + patientCode + "'";
            List<Map<String, Object>> list2 = jdbcTemplate.queryForList(sql2);
//            listMap = rehabilitationDetailDao.findByPatientAndDoctor(startTime,endTime,doctorCode,patientCode);
            String ids = "";
            for (Map<String, Object> one2 : list2) {
                ids += "," + one2.get("id");
            }
            one.put("planDetailIds", StringUtils.isNotEmpty(ids) ? ids.substring(1) : "");
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, list);
    }
    /**
     * 根据ids获取数据
     *
     * @param ids
     * @return
     */
    public ObjEnvelop selectByIds(String ids) {
        ObjEnvelop envelop = new ObjEnvelop();
        List idList = Arrays.asList(ids.split(","));
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < idList.size(); i++) {
            buffer.append("'" + idList.get(i) + "'").append(",");
        }
        buffer.deleteCharAt(buffer.length() - 1);
        String sql = "select * from wlyy_rehabilitation_plan_detail where id in(" + buffer + ")";
        sql = TransforSqlUtl.wlyy_rehabilitation_plan_detailAll(sql);
        List<RehabilitationDetailDO> rehabilitationDetailDOS = jdbcTemplate.query(sql, new BeanPropertyRowMapper(RehabilitationDetailDO.class));
        envelop.setObj(rehabilitationDetailDOS);
        return envelop;
    }
    public ObjEnvelop getServiceItemsAfterStop(String planId) throws Exception {
        Map<String, Object> reslutMap = new HashMap<>();
        String sql = "SELECT" +
                " p.patient," +
                " p.name," +
                " p.title," +
                " p.disease_name,p.abort_reason,p.abort_time,p.create_time,p.patient_img," +
                " a.*" +
                " FROM" +
                " wlyy_patient_rehabilitation_plan p" +
                " LEFT JOIN (" +
                "  SELECT" +
                "  d.id," +
                "  d.plan_id," +
                "  d.hospital," +
                "  d.hospital_name," +
                "  i.code as service_item_id," +
                "  i.name as service_item_name," +
                "  d.expense," +
                "  r.doctor_code," +
                "  r.doctor_name," +
                "  r.complete_time, " +
                "  i.code as item_type " +
                "  FROM" +
                "  wlyy_rehabilitation_plan_detail d" +
                "  LEFT JOIN wlyy_rehabilitation_service_item i ON d.hospital_service_item_id = i.code  " +
                "  LEFT JOIN wlyy_rehabilitation_operate_records r ON d.id = r.rehabilitation_detail_id" +
                "  WHERE" +
                "  r.`status` = 1" +
                " ) a ON p.id = a.plan_id" +
                " WHERE" +
                " p.id = '" + planId + "'";
        sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
        sql = TransforSqlUtl.wlyy_rehabilitation_operate_recordsDoctorName(sql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);//计划总服务项目数
        Integer finishCount = list.size();//完成服务项目数
        double totalExpense = 0;
        Set<String> hospitalSet = new HashSet();
        Set<String> serviceDoctor = new HashSet();
        DecimalFormat df = new DecimalFormat("0.00");
        for (Map<String, Object> map : list) {
            double expense = 0;
            if (StringUtils.isNotEmpty(String.valueOf(map.get("expense"))) && !"null".equals(String.valueOf(map.get("expense")))) {
                expense = Integer.valueOf(String.valueOf(map.get("expense")));
            }
            totalExpense += expense;
            map.put("expense", df.format(expense / 100));
            //组装机构和服务医生
            if (map.get("hospital") != null) {
                if (map.get("hospital_name") != null && !hospitalSet.contains(("hospital_name") + "")) {
                    hospitalSet.add(map.get("hospital_name") + "");
                }
            }
            if (map.get("doctor_code") != null) {
                if (map.get("doctor_name") != null && !hospitalSet.contains(("doctor_name") + "")) {
                    serviceDoctor.add(map.get("doctor_name") + "");
                }
            }
        }
        reslutMap.put("totalExpense", df.format(totalExpense / 100));
        reslutMap.put("allCount", allCount);
        reslutMap.put("finishCount", finishCount);
        reslutMap.put("serviceList", list);
        reslutMap.put("hospitalAll", hospitalSet.toString().replace("[", "").replace("]", "").replace(",", "、"));
        reslutMap.put("serviceDoctor", serviceDoctor.toString().replace("[", "").replace("]", "").replace(",", "、"));
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, reslutMap);
    }
    public String getCode() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
}

+ 0 - 608
svr/svr-base/src/main/java/com/yihu/jw/base/service/specialist/rehabilitation/RehabilitationPlanService.java

@ -1,608 +0,0 @@
package com.yihu.jw.base.service.specialist.rehabilitation;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.base.dao.specialist.rehabilitation.*;
import com.yihu.jw.base.service.specialist.SpecialistHospitalServiceItemService;
import com.yihu.jw.base.service.specialist.SpecialistService;
import com.yihu.jw.base.vo.TemplateDetailVo;
import com.yihu.jw.entity.rehabilitation.RehabilitationPlanningDO;
import com.yihu.jw.entity.specialist.HospitalServiceItemDO;
import com.yihu.jw.entity.specialist.RehabilitationServiceItemDO;
import com.yihu.jw.entity.specialist.rehabilitation.*;
import com.yihu.jw.entity.util.TransforSqlUtl;
import com.yihu.jw.hospital.disease.dao.RehabilitationPlanTemplateDao;
import com.yihu.jw.hospital.disease.dao.RehabilitationTemplateDetailDao;
import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.restmodel.qvo.ParamQvo;
import com.yihu.jw.restmodel.specialist.PatientSignInfoVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;
/**
 * Created by humingfen on 2018/8/17.
 */
@Service
@Transactional
public class RehabilitationPlanService extends BaseJpaService<RehabilitationPlanningDO, RehabilitationPlanTemplateDao> {
    private String baseUrl;
    private String basedb="base";
    @Autowired
    private RehabilitationPlanTemplateDao templateDao;
    @Autowired
    private RehabilitationTemplateDetailDao templateDetailDao;
    @Autowired
    private PatientRehabilitationPlanDao patientRehabilitationPlanDao;
    @Autowired
    RehabilitationPlanService planService;
    @Autowired
    private RehabilitationDetailDao rehabilitationDetailDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private FastDFSUtil fastDFSHelper;
    @Autowired
    protected HttpServletRequest request;
    @Autowired
    private RehabilitationOperateRecordsDao rehabilitationOperateRecordsDao;
    @Autowired
    private SpecialistHospitalServiceItemService hospitalServiceItemService;
    @Autowired
    private SpecialistService specialistService;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private RehabilitationServiceItemDao serviceItemDao;
    @Autowired
    TemplateJsonDao templateJsonDao;
    /**
     * 没有默认创建服务项
     *
     * @param templateDO
     * @return
     */
    public RehabilitationPlanTemplateDO createRehabilitationTemplateNew(RehabilitationPlanTemplateDO templateDO) {
        templateDO.setCreateTime(new Date());
        templateDO.setDel(1);
        templateDO.setUpdateTime(new Date());
        templateDO = templateDao.save(templateDO);
        return templateDO;
    }
    public ObjEnvelop createRehabilitationTemplate(RehabilitationPlanTemplateDO templateDO) {
        templateDO.setCreateTime(new Date());
        templateDO.setDel(1);
        templateDO.setUpdateTime(new Date());
        templateDO = templateDao.save(templateDO);
        String templateId = templateDO.getId();
        String user = templateDO.getCreateUser();
        String userName = templateDO.getCreateUserName();
        //默认新增服务项
        String sql = "SELECT code from wlyy.system_dict WHERE `dict_name` = 'default_service_item_id'";
        List<String> list = jdbcTemplate.queryForList(sql, String.class);
        if (list != null && list.size() > 0) {
            list.stream().forEach(code -> {
                RehabilitationTemplateDetailDO detailDO = new RehabilitationTemplateDetailDO();
                detailDO.setTemplateId(templateId);
                detailDO.setHospitalServiceItemId(code);
                detailDO.setCreateUser(user);
                detailDO.setCreateUserName(userName);
                detailDO.setCreateTime(new Date());
                detailDO.setUpdateTime(new Date());
                templateDetailDao.save(detailDO);
            });
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, templateDO.getId());
    }
    public ObjEnvelop createRehabilitationTemplateDetail(List<RehabilitationTemplateDetailDO> details) {
        for (RehabilitationTemplateDetailDO detail : details) {
            detail.setCreateTime(new Date());
            detail.setUpdateTime(new Date());
            templateDetailDao.save(detail);
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, true);
    }
    public ObjEnvelop createRehabilitationTemplateDetail(List<RehabilitationTemplateDetailDO> details, String templateId) {
        List<RehabilitationTemplateDetailDO> detailDOList = templateDetailDao.findTemplateDetailByTemplateId(templateId);
        List<RehabilitationTemplateDetailDO> delList = new ArrayList<>();
        Map<String,String> map = new HashMap<>();
        for (RehabilitationTemplateDetailDO detail : details) {
            if(StringUtils.isNotBlank(detail.getId())){
                map.put(detail.getId(),"");
            }
            detail.setTemplateId(templateId);
            detail.setCreateTime(new Date());
            detail.setUpdateTime(new Date());
            try {
                templateDetailDao.save(detail);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        for (RehabilitationTemplateDetailDO detailDO:detailDOList){
            if(!map.containsKey(detailDO.getId())){
                delList.add(detailDO);
            }
        }
        if(delList.size()>0){
            templateDetailDao.deleteAll(delList);
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, true);
    }
    public ObjEnvelop updateRehabilitationTemplateDetail(List<RehabilitationTemplateDetailDO> details) {
        String templateId = details.get(0).getTemplateId();
        if (templateId != null && templateId.length() > 0) {
            templateDetailDao.deleteByTemplateId(templateId);
        }
        for (RehabilitationTemplateDetailDO detail : details) {
            detail.setCreateTime(new Date());
            detail.setUpdateTime(new Date());
            templateDetailDao.save(detail);
        }
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, true);
    }
    public MixEnvelop findRehabilitationPlanTemplate(Long adminTeamCode, String doctor, String patient) {
        if (adminTeamCode == null && StringUtils.isNotBlank(doctor) && StringUtils.isNotBlank(patient)) {
            PatientSignInfoVO patientSignSpecialistInfo = (PatientSignInfoVO) specialistService.findPatientSignSpecialistInfo(patient, doctor).getObj();
            adminTeamCode = patientSignSpecialistInfo.getTeamCode();
        }
        List<RehabilitationPlanTemplateDO> list = templateDao.findByAdminTeamCode(adminTeamCode);
        return MixEnvelop.getSuccessList(SpecialistMapping.api_success, list);
    }
    /**
     * 根据模板id修改康复模板删除状态
     *
     * @param id
     * @return
     */
    public ObjEnvelop deleteRehabilitationPlanTemplate(String id) {
        //删除主表
        templateDao.delete(id);
        //detail也删除了
        templateDetailDao.deleteByTemplateId(id);
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, true);
    }
    /**
     * 根据模板id获取机构服务项目id,然后找出具体服务项目内容
     *
     * @param templateId
     * @return
     */
    public ListEnvelop findTemplateDetailByTemplateId(String templateId) {
        List<TemplateDetailVo> resultList = new ArrayList<>();
        List<RehabilitationTemplateDetailDO> list = templateDetailDao.findTemplateDetailByTemplateId(templateId);
        List<RehabilitationServiceItemDO> itemDOList = serviceItemDao.findList();
        Map<String, List<RehabilitationTemplateDetailDO>> map = list.stream().collect(Collectors.groupingBy(RehabilitationTemplateDetailDO::getHospitalServiceItemId));
        for (String code : map.keySet()) {
            TemplateDetailVo detailVo = new TemplateDetailVo();
            detailVo.setCode(code);
            detailVo.setId(code);
            detailVo.setList(map.get(code));
            for (RehabilitationServiceItemDO item : itemDOList) {
                if (code.equals(item.getCode())) {
                    detailVo.setName(item.getName());
                    for (RehabilitationTemplateDetailDO detailDO : detailVo.getList()) {
                        detailDO.setName(item.getName());
                    }
                    break;
                }
            }
            resultList.add(detailVo);
        }
        return ListEnvelop.getSuccess(SpecialistMapping.api_success, resultList);
    }
    public PatientRehabilitationPlanDO createPatientRehabilitationPlan(PatientRehabilitationPlanDO planDO) {
        planDO.setCreateTime(new Date());
        planDO.setStatus(1);
        planDO.setUpdateTime(new Date());
        //判断是否签约,如果签约 新增家签团队id
        try {
            String sql = "SELECT a.admin_team_code  from wlyy.wlyy_sign_family a WHERE patient = '" + planDO.getPatient() + "' and `status`>0 and expenses_status =1 order by id desc limit 1 ";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
            if (list != null && list.size() > 0) {
                planDO.setAdminTeamCode(Long.valueOf(list.get(0).get("admin_team_code") + ""));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return patientRehabilitationPlanDao.save(planDO);
    }
    public List<RehabilitationDetailDO> createRehabilitationDetail(List<RehabilitationDetailDO> details, String planId) {
        for (RehabilitationDetailDO detail : details) {
            /*List<String> list = new ArrayList<>();
            list.add(detail.getHospitalServiceItemId());
            HospitalServiceItemDO hospitalServiceItemDO = hospitalServiceItemService.selectById(list).getDetailModelList().get(0);
            detail.setHospital(hospitalServiceItemDO.getHospital());
            detail.setHospitalName(hospitalServiceItemDO.getHospitalName());
            detail.setExpense(hospitalServiceItemDO.getExpense());*/
            detail.setPlanId(planId);
            detail.setCreateTime(new Date());
            detail.setStatus(0);
            detail.setUpdateTime(new Date());
        }
        return (List<RehabilitationDetailDO>) rehabilitationDetailDao.saveAll(details);
    }
    public MixEnvelop findServiceItemsByHospital(String doctorHospital, String signHospital) {
        JSONArray jsonArray = new JSONArray();
        List<String> list = new ArrayList<>();
        list.add(doctorHospital);
        List<HospitalServiceItemDO> docHospitalServiceItemDO = hospitalServiceItemService.selectByHospital(list).getDetailModelList();
        if (StringUtils.isNotBlank(signHospital)) {
            if (signHospital.equals(doctorHospital)) {
                for (Object object : docHospitalServiceItemDO) {
                    JSONObject json = (JSONObject) JSONObject.toJSON(object);
                    json.put("type", "社区");
                    jsonArray.add(json);
                }
            } else if (!signHospital.equals(doctorHospital)) {
                JSONArray array = new JSONArray();
                List<String> itemIds = new ArrayList<>();
                list.remove(0);
                list.add(signHospital);
                List<HospitalServiceItemDO> signHospitalServiceItemDO = hospitalServiceItemService.selectByHospital(list).getDetailModelList();
                HashSet signSet = new HashSet();
                for (HospitalServiceItemDO h : signHospitalServiceItemDO) {
                    signSet.add(h.getServiceItemId());
                }
                //将服务项目重复的都放入itemIds集合里,并在列表中删除该条数据
                List<HospitalServiceItemDO> temp = new ArrayList<>();
                temp.addAll(docHospitalServiceItemDO);
                for (HospitalServiceItemDO h : docHospitalServiceItemDO) {
                    int size = signSet.size();
                    String itemId = h.getServiceItemId();
                    signSet.add(itemId);
                    if (signSet.size() == size) {
                        itemIds.add(itemId);
                        temp.remove(h);
                    }
                }
                array.addAll(signHospitalServiceItemDO);
                array.addAll(temp);
                for (Object obj : array) {
                    //往实体类插入数据
                    JSONObject json = (JSONObject) JSONObject.toJSON(obj);
                    if (json.get("hospital").equals(signHospital)) {
                        json.put("type", "社区");
                    } else if (json.get("hospital").equals(doctorHospital)) {
                        json.put("type", "医院");
                    }
                    if (itemIds.contains(json.get("serviceItemId"))) {
                        json.put("type", "社区,医院");
                    }
                    jsonArray.add(json);
                }
            }
        } else {
            jsonArray.addAll(docHospitalServiceItemDO);
        }
        return MixEnvelop.getSuccessList(SpecialistMapping.api_success, jsonArray);
    }
    /**
     * 调用服务包创建接口
     *
     * @param planDO
     * @param details
     */
    public String addServicePackage(PatientRehabilitationPlanDO planDO, List<RehabilitationDetailDO> details) {
        JSONObject jsonData = new JSONObject();
        JSONObject servicePackageVO = new JSONObject();
        JSONObject signRecordVO = new JSONObject();
        JSONArray detailsVOList = new JSONArray();
        //服务项目数据
        for (RehabilitationDetailDO detail : details) {
            JSONObject detailsVO = new JSONObject();
            detailsVO.put("executionType", "1");
            detailsVO.put("executionTime", DateUtil.dateToStr(detail.getExecuteTime(), "yyyy-MM-dd hh:mm:ss"));
            List<String> hospitalServiceIds = new ArrayList<>();
            hospitalServiceIds.add(detail.getHospitalServiceItemId());
            HospitalServiceItemDO signHospitalServiceItemDO = hospitalServiceItemService.selectById(hospitalServiceIds).getDetailModelList().get(0);
            detailsVO.put("code", signHospitalServiceItemDO.getServiceItemId());
            detailsVO.put("name", signHospitalServiceItemDO.getSpecialistServiceItemDO().getTitle());
            detailsVOList.add(detailsVO);
        }
        //服务包数据
        servicePackageVO.put("detailsVOList", detailsVOList);
        servicePackageVO.put("num", detailsVOList.size());
        servicePackageVO.put("saasId", "xmihealth");
        servicePackageVO.put("name", planDO.getTitle());
        servicePackageVO.put("introduce", planDO.getTitle());
        servicePackageVO.put("creater", planDO.getCreateUser());
        servicePackageVO.put("type", "1");
        servicePackageVO.put("price", planDO.getTotalExpense());
        //签约记录数据
        signRecordVO.put("servicePackageName", planDO.getTitle());
        signRecordVO.put("patient", planDO.getPatient());
        signRecordVO.put("name", planDO.getName());
        PatientSignInfoVO patientSignInfoVO = (PatientSignInfoVO) specialistService.findPatientSignSpecialistInfo(planDO.getPatient(), planDO.getCreateUser()).getObj();
        signRecordVO.put("idcard", patientSignInfoVO.getIdcard());
        signRecordVO.put("ssc", patientSignInfoVO.getSsc());
        signRecordVO.put("signDoctor", patientSignInfoVO.getDoctor());
        signRecordVO.put("signDoctorName", patientSignInfoVO.getDoctorName());
        signRecordVO.put("hospital", patientSignInfoVO.getHospital());
        signRecordVO.put("hospitalName", patientSignInfoVO.getHospitalName());
        signRecordVO.put("adminTeamCode", patientSignInfoVO.getTeamCode());
        signRecordVO.put("price", planDO.getTotalExpense());
        signRecordVO.put("saasId", "xmihealth");
        jsonData.put("servicePackageVO", servicePackageVO);
        jsonData.put("signRecordVO", signRecordVO);
        String response = null;
        try {
            response = httpClientUtil.postBody(baseUrl + "base_rehabilitation/create", jsonData);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject rs = JSONObject.parseObject(response);
        if ("success".equals(rs.getString("message"))) {
            return rs.getJSONObject("obj").getString("id");
        }
        return null;
    }
    public void updateServicePackageId(String planId, String servicePackageId) {
        patientRehabilitationPlanDao.updateServicePackageId(planId, servicePackageId);
    }
    public MixEnvelop<String, String> createServiceQrCode(String planDetailId, String doctorCode, String imageUrl) {
        //更新到康复计划居民关系表中
        String sql = "update wlyy_rehabilitation_plan_detail set service_qr_code='" + imageUrl + "' where id='" + planDetailId + "'";
        jdbcTemplate.update(sql);
        return MixEnvelop.getSuccess("获取二维码成功!", imageUrl);
    }
    public Map<String, Object> checkAfterQrCode(String planDetailId, String patietCode) throws Exception {
        Map<String, Object> map = new HashedMap();
        int result = 0;
        String name = "";
        String sql = "SELECT p.patient,p.name FROM `wlyy_rehabilitation_plan_detail` pd LEFT JOIN wlyy_patient_rehabilitation_plan p ON pd.plan_id = p.id WHERE pd.id='" + planDetailId + "'";
        sql = TransforSqlUtl.wlyy_patient_rehabilitation_planName(sql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        if (list != null && list.size() > 0) {
            if (String.valueOf(list.get(0).get("patient")).equals(patietCode)) {
                result = 200;
            } else {
                result = -1;
                name = String.valueOf(list.get(0).get("name"));
            }
        } else {
            result = -10000;
        }
        map.put("code", result);
        if (StringUtils.isNotBlank(name)) {
            map.put("name", name);
        }
        return map;
    }
    public RehabilitationOperateRecordsDO saveRehabilitationRecord(RehabilitationOperateRecordsDO rehabilitationOperateRecordsDO) {
        RehabilitationDetailDO rehabilitationDetailDO = rehabilitationDetailDao.findById(rehabilitationOperateRecordsDO.getRehabilitationDetailId());
        if (!StringUtils.isNoneBlank(rehabilitationOperateRecordsDO.getId())) {
            rehabilitationOperateRecordsDO.setId(getCode());
        }
        if (rehabilitationDetailDO.getExecuteTime() != null) {
            rehabilitationOperateRecordsDO.setReserveTime(rehabilitationDetailDO.getExecuteTime());
        }
        rehabilitationOperateRecordsDO.setCompleteTime(new Date());
        rehabilitationOperateRecordsDO.setCreateTime(new Date());
        rehabilitationOperateRecordsDO.setUpdateTime(new Date());
        rehabilitationOperateRecordsDO.setStatus(rehabilitationOperateRecordsDO.getStatus());
        if (StringUtils.isEmpty(rehabilitationOperateRecordsDO.getPatientName())) {
            String sql = "select name from " + basedb + ".wlyy_patient where code='" + rehabilitationOperateRecordsDO.getPatientCode() + "'";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
            if (list != null && list.size() > 0) {
                rehabilitationOperateRecordsDO.setPatientName(String.valueOf(list.get(0).get("name")));
            }
        }
        return rehabilitationOperateRecordsDao.save(rehabilitationOperateRecordsDO);
    }
    /**
     * 更新康复计划项目状态
     *
     * @param status
     * @param planId
     * @return
     */
    public MixEnvelop updatePlanStatusById(Integer status, String planId) throws Exception {
        if (status == 1) {
            if (patientRehabilitationPlanDao.updateStatusById(status, planId) > 0) {
                return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientRehabilitationPlanDao.findById(planId));
            }
        } else if (status == 2) {
            if (patientRehabilitationPlanDao.updateStatusAndTimeById(2, planId, new Date()) > 0) {
                return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientRehabilitationPlanDao.findById(planId));
            }
        }
        return MixEnvelop.getError("更新失败!");
    }
    public MixEnvelop abortPlanById(String planId, String abortReason) {
        PatientRehabilitationPlanDO patientRehabilitationPlanDO = patientRehabilitationPlanDao.findById(planId).orElse(null);
        List<RehabilitationDetailDO> detailDOList = rehabilitationDetailDao.findByPlanIdAndStatus(planId, 0);
        if (null != patientRehabilitationPlanDO) {
            patientRehabilitationPlanDO.setAbortReason(abortReason);
            patientRehabilitationPlanDO.setAbortTime(new Date());
            patientRehabilitationPlanDO.setStatus(0);
            patientRehabilitationPlanDO.setUpdateTime(new Date());
            patientRehabilitationPlanDao.save(patientRehabilitationPlanDO);
            return MixEnvelop.getSuccess(SpecialistMapping.api_success, patientRehabilitationPlanDO, detailDOList);
        }
        return MixEnvelop.getError("更新失败!");
    }
    /**
     * 根据标签和居民code查找康复计划
     *
     * @param patient
     * @param label
     * @return
     */
    public List<PatientRehabilitationPlanDO> selectByLabelAndPatient(String patient, String label) {
        return patientRehabilitationPlanDao.selectByDiseaseAndPatient(label, patient);
    }
    public Envelop updatePatientImgById(String planId, String patientImg) {
        if (patientRehabilitationPlanDao.updatePatientImgById(planId, patientImg) > 0) {
            return Envelop.getSuccess(SpecialistMapping.api_success);
        }
        return Envelop.getError("更新失败!");
    }
    public void deleteDetailByPlanIdAndHospitalServiceItemId(String planId, String hospitalServiceItemId, Date dateShort) {
        rehabilitationDetailDao.deleteDetailByPlanIdAndHospitalServiceItemId(planId, hospitalServiceItemId, dateShort);
    }
    public void deleteDetailByPlanId(String planId, Date dateShort) {
        rehabilitationDetailDao.deleteDetailByPlanId(planId, dateShort);
    }
    public HashMap<String, Object> findRehabilitationPlanTemplatenew(
            String templateId, String templateName, String status, String diseaseId, String type, String pageIf, int page, int pageSize) {
        String countSql = "select count(1) ";
        String detailSql = "SELECT \n" +
                "  (SELECT GROUP_CONCAT(b.`name`) FROM 	wlyy_rehabilitation_template_detail q \n" +
                "	 INNER JOIN wlyy_rehabilitation_service_item b ON q.hospital_service_item_id=b.`code` WHERE q.template_id=a.id) 'itemName',\n" +
                "	a.*\n";
        String sql = " FROM	wlyy_rehabilitation_plan_template a WHERE 1=1\n";
        String pageSql = "";
        if (StringUtils.isNotBlank(templateId)) {
            sql += " AND a.id = '" + templateName + "' ";
        }
        if (StringUtils.isNotBlank(templateName)) {
            sql += " AND a.title LIKE '%" + templateName + "%' ";
        }
        if (StringUtils.isNotBlank(status)) {
            sql += "  AND a.status='" + status + "' ";
        }
        if (StringUtils.isNotBlank(diseaseId)) {
            sql += "  AND a.disease_id='" + diseaseId + "' ";
        }
        if (StringUtils.isNotBlank(type)) {
            sql += "  AND a.type='" + type + "' ";
        }
        if (StringUtils.isNotBlank(pageIf)) {
            pageSql += " LIMIT " + (page - 1) * pageSize + "," + pageSize;
        }
        detailSql += sql + pageSql;
        countSql += sql;
        List<Map<String, Object>> list = jdbcTemplate.queryForList(detailSql);
        Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", count);
        map.put("list", list);
        return map;
    }
    public List<Map<String, Object>> findRehabilitationServiceItem(String itemName) {
        String sql = " SELECT * FROM base.wlyy_rehabilitation_service_item WHERE 1=1 ";
        if (StringUtils.isNotBlank(itemName)) {
            sql += " and `name` LIKE '%" + itemName + "%'";
        }
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    public TemplateJson saveTemplate(String templateName, String templateJson) {
        TemplateJson entity = new TemplateJson();
        entity.setCreateTime(new Date());
        entity.setTemplateName(templateName);
        entity.setTemplateJson(templateJson);
        templateJsonDao.save(entity);
        return entity;
    }
    public List<Map<String, Object>> findDiseaseList() {
        String sql = "SELECT * FROM base_disease_hospital WHERE `status`='1' ORDER BY sort ";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    public List<Map<String, Object>> findSaveTemplate(String templateName) {
        String sql = "select * FROM template_json WHERE 1=1 ";
        if (StringUtils.isNotBlank(templateName)) {
            sql += " and template_name LIKE '%" + templateName + "%'  ";
        }
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    /**
     * 新增整个模板
     *
     * @param templateDO
     * @param details
     * @return
     */
    public ObjEnvelop saveRehabilitationPlanTemplateData(RehabilitationPlanTemplateDO templateDO, List<RehabilitationTemplateDetailDO> details) {
        RehabilitationPlanTemplateDO planTemplateDO = this.createRehabilitationTemplateNew(templateDO);
        this.createRehabilitationTemplateDetail(details, planTemplateDO.getId());
        return ObjEnvelop.getSuccess(SpecialistMapping.api_success, true);
    }
    public RehabilitationPlanTemplateDO changeState(ParamQvo qvo) {
        RehabilitationPlanTemplateDO entity = templateDao.findById(qvo.getId()).orElse(null);
        if (entity != null) {
            entity.setStatus(qvo.getStatus());
            templateDao.save(entity);
            return entity;
        }
        return null;
    }
    public ListEnvelop findFrequencyList() {
//        String sql = " SELECT * FROM `base`.`wlyy_frequency` WHERE del='1' ";
//        List<Frequency> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(Frequency.class));
//        return ListEnvelop.getSuccess(SpecialistMapping.api_success, list);
        String sql = " SELECT dict_code 'code',dict_value 'name' from wlyy_hospital_sys_dict WHERE dict_name = 'plan_frequency' ";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return ListEnvelop.getSuccess(SpecialistMapping.api_success, list);
    }
}