SignFamilyDao.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*******************************************************************************
  2. * Copyright (c) 2005, 2014 springside.github.io
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. *******************************************************************************/
  6. package com.yihu.wlyy.repository.patient;
  7. import java.util.List;
  8. import org.springframework.data.domain.Page;
  9. import org.springframework.data.domain.Pageable;
  10. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  11. import org.springframework.data.jpa.repository.Modifying;
  12. import org.springframework.data.jpa.repository.Query;
  13. import org.springframework.data.repository.PagingAndSortingRepository;
  14. import com.yihu.wlyy.entity.patient.SignFamily;
  15. public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Long>, JpaSpecificationExecutor<SignFamily> {
  16. @Query("select count(1) from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status >= 0")
  17. int hasSingStatus(String idcard);
  18. @Query("select a from SignFamily a where a.idcard = ?1 and status = ?2 and a.type = 2")
  19. SignFamily findByPatientStatus(String idcard, int status);
  20. @Query("select a from SignFamily a where a.patient = ?1 and status = ?2 and a.type = 2")
  21. SignFamily findByPatientCodeStatus(String patient, int status);
  22. @Query("select a from SignFamily a where a.patient = ?1 and a.type = ?2 and a.status >= 1")
  23. SignFamily findByPatientAndType(String patient,int type);
  24. SignFamily findByCode(String code);
  25. SignFamily findByCodeAndType(String code,Integer type);
  26. SignFamily findByFamilyCode(String familyCode);
  27. @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.type = 2 and a.status >= 0")
  28. SignFamily findByDoctorPatient(String doctor, String patient);
  29. @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.type = 1 and a.status > 0")
  30. SignFamily findSsSignByDoctorPatient(String doctor, String patient);
  31. @Query("select a from SignFamily a,DoctorTeamMember w where a.teamCode = w.team and w.del = '1' and w.memberCode = ?1 and a.patient = ?2 and a.status > 0")
  32. List<SignFamily> findByDoctorAndPatient(String doctor,String patient);
  33. @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.status = 1 and a.type = 2")
  34. SignFamily findByFamilyDoctorAndPatient(String doctor,String patient);
  35. @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.status = 1 and a.type = 1")
  36. SignFamily findBySanshiDoctorAndPatient(String doctor,String patient);
  37. @Query("select a from SignFamily a where a.doctor = ?1 and a.openid = ?2 and a.type = 2 and a.status >= 0")
  38. SignFamily findByDoctorOpenid(String doctor, String openid);
  39. @Query("select a from SignFamily a where a.doctor = ?1 and a.idcard = ?2 and a.type = 2 and a.status >= 0")
  40. SignFamily findByDoctorIdcard(String doctor, String idcard);
  41. @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status >= 0")
  42. SignFamily findByIdcard(String idcard);
  43. @Query("select a from SignFamily a where a.idcard = ?1 and a.type =1 and a.status >= 0")
  44. SignFamily findSSByIdcard(String idcard);
  45. @Query("select a from SignFamily a where a.idcard = ?1 ")
  46. List<SignFamily> findAllByIdcard(String idcard);
  47. @Query("select a from SignFamily a where a.idcard = ?1 and a.status >= 0")
  48. List<SignFamily> findSSandJTByIdcard(String idcard);
  49. @Query("select a from SignFamily a where a.openid = ?1 and a.type = 2 and a.status >= 0")
  50. SignFamily findByOpenid(String openid);
  51. // 取消签约申请
  52. @Modifying
  53. @Query("update SignFamily a set a.status = -1 where a.patient = ?1 and a.doctor = ?2 and a.type = 2 and a.status = 0")
  54. void unsignByPatient(String patient, String doctor);
  55. // 取消签约申请
  56. @Modifying
  57. @Query("update SignFamily a set a.status = -1 where a.openid = ?1 and a.doctor = ?2 and a.type = 2 and a.status = 0")
  58. void unsignByOpenid(String openid, String doctor);
  59. // 查询医生的签约数量
  60. @Query("select count(1) from SignFamily a where a.doctor = ?1")
  61. int countByDoctor(String doctor);
  62. // 查询医生的签约数量
  63. @Query("select count(1) from SignFamily a")
  64. int countByDoctor();
  65. // 更新状态为待解约
  66. @Modifying
  67. @Query("update SignFamily a set a.status = 2 where a.patient = ?1 and a.doctor = ?2 and a.status = 1 and a.type = 2")
  68. int surrender(String patient, String doctor);
  69. // 更新待签约状态为拒绝或同意状态
  70. @Modifying
  71. @Query("update SignFamily a set a.status = ?1 where a.patient = ?2 and a.status = 0 and a.type = 2")
  72. int handleSign(int status, String patient);
  73. // 更新已签约状态为解约
  74. @Modifying
  75. @Query("update SignFamily a set a.status = -3, a.reason = ?1 where a.patient = ?2 and a.status = 2 and a.type = 2")
  76. int handleSurrender(String reason, String patient);
  77. // 拒绝解约
  78. @Modifying
  79. @Query("update SignFamily a set a.status = 1 where a.patient = ?1 and a.status = 2 and a.type = 2")
  80. int refuseSurrender(String patient);
  81. // 查询患者已生效的家庭签约
  82. @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status > 0")
  83. SignFamily findSignByPatient(String patient);
  84. @Modifying
  85. @Query("update SignFamily a set a.openid = ?1 where patient = ?2")
  86. int updateOpenidByPatient(String openid, String patient);
  87. // 查询已签约的总数
  88. @Query("select count(1) from SignFamily a where a.doctor = ?1 and (a.status = 1 or a.status = 2) and a.type = 2")
  89. int countAmountSignedByDoctor(String doctor);
  90. // 查询待签约总数
  91. @Query("select count(1) from SignFamily a where a.doctor = ?1 and a.status = 0 and a.type = 2")
  92. int countAmountUnsignByDoctor(String doctor);
  93. // 查询团队中的健康管理师 sf.doctorHealth,sf.doctorHealthName,
  94. //select sf.doctorHealth,sf.doctorHealthName,count(*) totalContract from SignFamily sf where sf.healthDoctor = ?1
  95. @Query("select sf.doctorHealth,sf.doctorHealthName,count(sf) from SignFamily sf where sf.doctorHealth = ?1")
  96. List<Object> findTeamHealthDoctors(String healthDoctor);
  97. // 查询团队中的全科医生 sf.doctor,sf.doctorName,d.hosptialName,
  98. //select sf.doctor,sf.doctorName,d.hosptialName,count(*) totalContract from SignFamily sf left join Doctor d on sf.doctor = d.code where sf.doctor = ?1
  99. @Query("select sf.doctor,sf.doctorName,d.hosptialName,count(sf) from SignFamily sf, Doctor d where ( sf.doctor is null or sf.doctor = d.code) and sf.doctor = ?1")
  100. List<Object> findTeamQkDoctors(String doctor);
  101. // 待签约 待解决 已签约
  102. @Query("select a.code,a.doctor,b.code,b.name,b.provinceName,b.cityName,b.townName,b.address,b.photo,a.status,a.id,a.applyDate,a.reason,b.streetName,b.sex from SignFamily a,Patient b,DoctorTeam t,DoctorTeamMember td where a.patient=b.code and a.teamCode=t.code and t.code=td.team and td.memberCode=?1 and td.type=?2 and a.status=?3 order by a.begin desc")
  103. Page<Object> findToBeSignSignWebByDoctor(String doctor, int doctorType,int status, Pageable pageRequest);
  104. /**
  105. * 查询全科医生签约患者
  106. *
  107. * @param doctor
  108. * @param status
  109. * @param pageRequest
  110. * @return
  111. */
  112. @Query("select a.code,a.doctor,b.code,b.name,b.provinceName,b.cityName,b.townName,b.address,b.photo,a.status,a.id,a.applyDate,a.reason,b.streetName,b.sex from SignFamily a,Patient b where a.patient=b.code and a.doctor = ?1 and a.status=?2 order by a.begin desc")
  113. Page<Object> findSignedPatientByQkDoctor(String doctor,int status, Pageable pageRequest);
  114. /**
  115. * 查询健康管理师签约患者
  116. *
  117. * @param doctor
  118. * @param status
  119. * @param pageRequest
  120. * @return
  121. */
  122. @Query("select a.code,a.doctor,b.code,b.name,b.provinceName,b.cityName,b.townName,b.address,b.photo,a.status,a.id,a.applyDate,a.reason,b.streetName,b.sex from SignFamily a,Patient b where a.patient=b.code and a.doctorHealth = ?1 and a.status=?2 order by a.begin desc")
  123. Page<Object> findSignedPatientByJkDoctor(String doctor,int status, Pageable pageRequest);
  124. /**
  125. * 查询全科医生已解约患者
  126. *
  127. * @param doctor
  128. * @param pageRequest
  129. * @return
  130. */
  131. @Query("select a.code,a.doctor,b.code,b.name,b.provinceName,b.cityName,b.townName,b.address,b.photo,a.status,a.id,a.applyDate,a.reason,b.streetName,b.sex from SignFamily a,Patient b where a.patient=b.code and a.doctor = ?1 and (a.status=-3 or a.status=-4) order by a.begin desc")
  132. Page<Object> findUnSignedPatientByQkDoctor(String doctor,Pageable pageRequest);
  133. /**
  134. * 查询健康管理师已解约患者
  135. *
  136. * @param doctor
  137. * @param pageRequest
  138. * @return
  139. */
  140. @Query("select a.code,a.doctor,b.code,b.name,b.provinceName,b.cityName,b.townName,b.address,b.photo,a.status,a.id,a.applyDate,a.reason,b.streetName,b.sex from SignFamily a,Patient b where a.patient=b.code and a.doctorHealth = ?1 and (a.status=-3 or a.status=-4) order by a.begin desc")
  141. Page<Object> findUnSignedPatientByJkDoctor(String doctor,Pageable pageRequest);
  142. //已经解约
  143. @Query("select a.code,a.doctor,b.code,b.name,b.provinceName,b.cityName,b.townName,b.address,b.photo,a.status,a.id,a.applyDate,a.reason,b.streetName,b.sex from SignFamily a,Patient b,DoctorTeam t,DoctorTeamMember td where a.patient=b.code and a.teamCode=t.code and t.code=td.team and td.memberCode=?1 and td.type=?2 and(a.status=-3 or a.status=-4 ) order by a.begin desc")
  144. Page<Object> findToBeSignSignWebByDoctor_34(String doctor, int doctorType, Pageable pageRequest);
  145. @Query("select a from SignFamily a where a.mobile = ?1 and a.type = 2 and a.status >= 0")
  146. SignFamily findByMobile(String mobile);
  147. @Query("select a.code,a.doctor,b.code,b.name,b.provinceName,b.cityName,b.townName,b.address,b.photo,a.status,a.id,a.applyDate,a.reason,b.streetName,b.sex from SignFamily a,Patient b where a.patient=b.code and a.doctor=?1 and a.status=?2 order by a.begin desc")
  148. Page<Object> findToBeSignSignWebByDoctor_0(String doctor, int i, Pageable pageRequest);
  149. @Query("select count(1) from SignFamily a where a.doctorHealth = ?1 and (a.status = 1 or a.status = 2) and a.type = 2")
  150. int countAmountSignedByHeather(String uid);
  151. @Query("select a from SignFamily a where a.patient = ?1 and a.type =1 and a.status >= 1")
  152. SignFamily findBySanshiPatient(String code);
  153. @Query("select a from SignFamily a where a.patient = ?1 and a.type =1 and a.status >= 0")
  154. SignFamily findBySsPatient(String code);
  155. @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >= 1")
  156. SignFamily findByjiatingPatient(String code);
  157. @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status = 1")
  158. SignFamily findByjiatingPatientYes(String code);
  159. @Query("select a from SignFamily a where a.patient = ?1 and a.type =1 and a.status = 1")
  160. SignFamily findBySanshiPatientYes(String id);
  161. @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 1 and a.status in (0,1,2,3)")
  162. SignFamily findByPatientSanshiSignInfo(String idCard);
  163. @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status in (0,1,2,3)")
  164. SignFamily findByPatientFamilySignInfo(String idCard);
  165. @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >=0")
  166. SignFamily findByjiatingPatientStatus0(String patient);
  167. //查找昨天的家庭签约数据
  168. @Query(" from SignFamily a where a.type =2 and a.status = 1 and unix_timestamp(a.applyDate)>=unix_timestamp(?1) and unix_timestamp(a.applyDate)<unix_timestamp(?2) ")
  169. List<SignFamily> findByJiatingSignYesterday(String yesterday,String today);
  170. //查找昨天的家庭解约数据
  171. @Query(" from SignFamily a where a.type =2 and a.status in (-3,-4) and unix_timestamp(a.applyUnsignDate)>=unix_timestamp(?1) and unix_timestamp(a.applyUnsignDate)<unix_timestamp(?2) ")
  172. List<SignFamily> findByJiatingUnSignYesterday(String yesterday,String today);
  173. //查找昨天的家庭待数据
  174. @Query(" from SignFamily a where a.type =2 and a.status =0 and unix_timestamp(a.patientApplyDate)>=unix_timestamp(?1) and unix_timestamp(a.patientApplyDate)<unix_timestamp(?2)")
  175. List<SignFamily> findByJiatingWaitSignYesterday(String yesterday,String today);
  176. //查找昨天的家庭待改签
  177. @Query(" from SignFamily a where a.type =2 and a.status =100 and unix_timestamp(a.patientApplyDate)>=unix_timestamp(?1) and unix_timestamp(a.patientApplyDate)<unix_timestamp(?2) ")
  178. List<SignFamily> findByJiatingChaangeSignYesterday(String yesterday, String now);
  179. @Query("select a from SignFamily a where a.patient = ?1 and a.type = 1 and a.status in (0,1,2)")
  180. SignFamily findSanshiSignByPatient(String patientCode);
  181. @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status in (0,1,2)")
  182. SignFamily findFamilySignByPatient(String patientCode);
  183. @Query("select p.code, p.name, p.photo, p.birthday, p.sex, p.diseaseCondition, p.disease, p.recordAmount,a.type,a.applyDate,p.idcard from SignFamily a,Patient p where (a.doctor = ?1 or a.doctorHealth = ?1) and a.patient = p.code and a.status in (1,2,3)")
  184. List<Object> findDoctorSignPatients(String doctor);
  185. @Query("select p.code, p.name, p.photo, p.birthday, p.sex, p.diseaseCondition, p.disease, p.recordAmount,a.type,a.applyDate,p.idcard from SignFamily a,Patient p where (a.doctor = ?1 or a.doctorHealth = ?1) and p.name like ?2 and a.patient = p.code and a.status in (1,2,3)")
  186. List<Object> findDoctorSignPatientsLikeName(String doctor,String name);
  187. @Query("select p.code, p.name, p.photo, p.birthday, p.sex, p.diseaseCondition, p.disease, p.recordAmount,a.type,a.applyDate,p.idcard from SignFamily a,Patient p where (a.doctor = ?1 or a.doctorHealth = ?1) and a.type = ?2 and a.patient = p.code and a.status in (1,2,3)")
  188. List<Object> findDoctorSignPatientsBySignType(String doctor,int type);
  189. @Query("select p.code, p.name, p.photo, p.birthday, p.sex, p.diseaseCondition, p.disease, p.recordAmount,a.type,a.applyDate,p.idcard from SignFamily a,Patient p where (a.doctor = ?1 or a.doctorHealth = ?1) and a.type = ?2 and p.name like ?3 and a.patient = p.code and a.status in (1,2,3)")
  190. List<Object> findDoctorSignPatientsByTypeName(String doctor,int type,String name);
  191. @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >= 0")
  192. SignFamily findByPatient(String patient);
  193. @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 1 and a.status >= 0")
  194. SignFamily findBySanshiIdcard(String idcard);
  195. @Query("select a from SignFamily a where a.patient = ?1 and a.type = ?2 and a.status > 0")
  196. SignFamily findSignByPatient(String patient,int type);
  197. @Query(" from SignFamily a where a.patient = ?1 and a.type = ?2 and (a.status=-3 or a.status=-4) order by a.id desc")
  198. List<SignFamily> findLastJySignByPatient(String patient,int type);
  199. @Query(" from SignFamily a where a.type =1 and unix_timestamp(a.czrq)=unix_timestamp( ?1 ) ")
  200. List<SignFamily> findByDate(String s);
  201. @Modifying
  202. @Query("update SignFamily set expenses_type = ?1 where patient = ?2 and status > 0 and type = 2")
  203. int updateExpensesType(String expensesType,String patient);
  204. @Query("select count(*) from SignFamily where patient = ?1 and status > 0 and type = 1")
  205. int countPatientSsSign(String patient);
  206. @Query("select count(*) from SignFamily where patient = ?1 and status > 0 and type = 2")
  207. int countPatientJtSign(String patient);
  208. // 查询患者已生效的家庭签约
  209. @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status = 0")
  210. SignFamily findSigningByPatient(String patient);
  211. //找出家庭签约中 团队是空的值
  212. @Query("select a from SignFamily a where a.type = 2 and a.status = 1 and a.adminTeamId is null")
  213. List<SignFamily> findBySignTypeAndTeamCode();
  214. }