SignFamilyDao.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 findByFamilyCode(String familyCode);
  26. @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.type = 2 and a.status >= 0")
  27. SignFamily findByDoctorPatient(String doctor, String patient);
  28. @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.type = 1 and a.status > 0")
  29. SignFamily findSsSignByDoctorPatient(String doctor, String patient);
  30. @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")
  31. List<SignFamily> findByDoctorAndPatient(String doctor,String patient);
  32. @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.status = 1 and a.type = 2")
  33. SignFamily findByFamilyDoctorAndPatient(String doctor,String patient);
  34. @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.status = 1 and a.type = 1")
  35. SignFamily findBySanshiDoctorAndPatient(String doctor,String patient);
  36. @Query("select a from SignFamily a where a.doctor = ?1 and a.openid = ?2 and a.type = 2 and a.status >= 0")
  37. SignFamily findByDoctorOpenid(String doctor, String openid);
  38. @Query("select a from SignFamily a where a.doctor = ?1 and a.idcard = ?2 and a.type = 2 and a.status >= 0")
  39. SignFamily findByDoctorIdcard(String doctor, String idcard);
  40. @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status >= 0")
  41. SignFamily findByIdcard(String idcard);
  42. @Query("select a from SignFamily a where a.idcard = ?1 and a.type =1 and a.status >= 0")
  43. SignFamily findSSByIdcard(String idcard);
  44. @Query("select a from SignFamily a where a.idcard = ?1 ")
  45. List<SignFamily> findAllByIdcard(String idcard);
  46. @Query("select a from SignFamily a where a.idcard = ?1 and a.status >= 0")
  47. List<SignFamily> findSSandJTByIdcard(String idcard);
  48. @Query("select a from SignFamily a where a.openid = ?1 and a.type = 2 and a.status >= 0")
  49. SignFamily findByOpenid(String openid);
  50. // 取消签约申请
  51. @Modifying
  52. @Query("update SignFamily a set a.status = -1 where a.patient = ?1 and a.doctor = ?2 and a.type = 2 and a.status = 0")
  53. void unsignByPatient(String patient, String doctor);
  54. // 取消签约申请
  55. @Modifying
  56. @Query("update SignFamily a set a.status = -1 where a.openid = ?1 and a.doctor = ?2 and a.type = 2 and a.status = 0")
  57. void unsignByOpenid(String openid, String doctor);
  58. // 查询医生的签约数量
  59. @Query("select count(1) from SignFamily a where a.doctor = ?1")
  60. int countByDoctor(String doctor);
  61. // 查询医生的签约数量
  62. @Query("select count(1) from SignFamily a")
  63. int countByDoctor();
  64. // 更新状态为待解约
  65. @Modifying
  66. @Query("update SignFamily a set a.status = 2 where a.patient = ?1 and a.doctor = ?2 and a.status = 1 and a.type = 2")
  67. int surrender(String patient, String doctor);
  68. // 更新待签约状态为拒绝或同意状态
  69. @Modifying
  70. @Query("update SignFamily a set a.status = ?1 where a.patient = ?2 and a.status = 0 and a.type = 2")
  71. int handleSign(int status, String patient);
  72. // 更新已签约状态为解约
  73. @Modifying
  74. @Query("update SignFamily a set a.status = -3, a.reason = ?1 where a.patient = ?2 and a.status = 2 and a.type = 2")
  75. int handleSurrender(String reason, String patient);
  76. // 拒绝解约
  77. @Modifying
  78. @Query("update SignFamily a set a.status = 1 where a.patient = ?1 and a.status = 2 and a.type = 2")
  79. int refuseSurrender(String patient);
  80. // 查询患者已生效的家庭签约
  81. @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status > 0")
  82. SignFamily findSignByPatient(String patient);
  83. @Modifying
  84. @Query("update SignFamily a set a.openid = ?1 where patient = ?2")
  85. int updateOpenidByPatient(String openid, String patient);
  86. // 查询已签约的总数
  87. @Query("select count(1) from SignFamily a where a.doctor = ?1 and (a.status = 1 or a.status = 2) and a.type = 2")
  88. int countAmountSignedByDoctor(String doctor);
  89. // 查询待签约总数
  90. @Query("select count(1) from SignFamily a where a.doctor = ?1 and a.status = 0 and a.type = 2")
  91. int countAmountUnsignByDoctor(String doctor);
  92. // 查询团队中的健康管理师 sf.doctorHealth,sf.doctorHealthName,
  93. //select sf.doctorHealth,sf.doctorHealthName,count(*) totalContract from SignFamily sf where sf.healthDoctor = ?1
  94. @Query("select sf.doctorHealth,sf.doctorHealthName,count(sf) from SignFamily sf where sf.doctorHealth = ?1")
  95. List<Object> findTeamHealthDoctors(String healthDoctor);
  96. // 查询团队中的全科医生 sf.doctor,sf.doctorName,d.hosptialName,
  97. //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
  98. @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")
  99. List<Object> findTeamQkDoctors(String doctor);
  100. // 待签约 待解决 已签约
  101. @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")
  102. Page<Object> findToBeSignSignWebByDoctor(String doctor, int doctorType,int status, Pageable pageRequest);
  103. /**
  104. * 查询全科医生签约患者
  105. *
  106. * @param doctor
  107. * @param status
  108. * @param pageRequest
  109. * @return
  110. */
  111. @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")
  112. Page<Object> findSignedPatientByQkDoctor(String doctor,int status, Pageable pageRequest);
  113. /**
  114. * 查询健康管理师签约患者
  115. *
  116. * @param doctor
  117. * @param status
  118. * @param pageRequest
  119. * @return
  120. */
  121. @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")
  122. Page<Object> findSignedPatientByJkDoctor(String doctor,int status, Pageable pageRequest);
  123. /**
  124. * 查询全科医生已解约患者
  125. *
  126. * @param doctor
  127. * @param pageRequest
  128. * @return
  129. */
  130. @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")
  131. Page<Object> findUnSignedPatientByQkDoctor(String doctor,Pageable pageRequest);
  132. /**
  133. * 查询健康管理师已解约患者
  134. *
  135. * @param doctor
  136. * @param pageRequest
  137. * @return
  138. */
  139. @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")
  140. Page<Object> findUnSignedPatientByJkDoctor(String doctor,Pageable pageRequest);
  141. //已经解约
  142. @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")
  143. Page<Object> findToBeSignSignWebByDoctor_34(String doctor, int doctorType, Pageable pageRequest);
  144. @Query("select a from SignFamily a where a.mobile = ?1 and a.type = 2 and a.status >= 0")
  145. SignFamily findByMobile(String mobile);
  146. @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")
  147. Page<Object> findToBeSignSignWebByDoctor_0(String doctor, int i, Pageable pageRequest);
  148. @Query("select count(1) from SignFamily a where a.doctorHealth = ?1 and (a.status = 1 or a.status = 2) and a.type = 2")
  149. int countAmountSignedByHeather(String uid);
  150. @Query("select a from SignFamily a where a.patient = ?1 and a.type =1 and a.status >= 1")
  151. SignFamily findBySanshiPatient(String code);
  152. @Query("select a from SignFamily a where a.patient = ?1 and a.type =1 and a.status >= 0")
  153. SignFamily findBySsPatient(String code);
  154. @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >= 1")
  155. SignFamily findByjiatingPatient(String code);
  156. @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status = 1")
  157. SignFamily findByjiatingPatientYes(String code);
  158. @Query("select a from SignFamily a where a.patient = ?1 and a.type =1 and a.status = 1")
  159. SignFamily findBySanshiPatientYes(String id);
  160. @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 1 and a.status in (0,1,2,3)")
  161. SignFamily findByPatientSanshiSignInfo(String idCard);
  162. @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status in (0,1,2,3)")
  163. SignFamily findByPatientFamilySignInfo(String idCard);
  164. @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >=0")
  165. SignFamily findByjiatingPatientStatus0(String patient);
  166. //查找昨天的家庭签约数据
  167. @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) ")
  168. List<SignFamily> findByJiatingSignYesterday(String yesterday,String today);
  169. //查找昨天的家庭解约数据
  170. @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) ")
  171. List<SignFamily> findByJiatingUnSignYesterday(String yesterday,String today);
  172. //查找昨天的家庭待数据
  173. @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)")
  174. List<SignFamily> findByJiatingWaitSignYesterday(String yesterday,String today);
  175. //查找昨天的家庭待改签
  176. @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) ")
  177. List<SignFamily> findByJiatingChaangeSignYesterday(String yesterday, String now);
  178. @Query("select a from SignFamily a where a.patient = ?1 and a.type = 1 and a.status in (0,1,2)")
  179. SignFamily findSanshiSignByPatient(String patientCode);
  180. @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status in (0,1,2)")
  181. SignFamily findFamilySignByPatient(String patientCode);
  182. @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)")
  183. List<Object> findDoctorSignPatients(String doctor);
  184. @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)")
  185. List<Object> findDoctorSignPatientsLikeName(String doctor,String name);
  186. @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)")
  187. List<Object> findDoctorSignPatientsBySignType(String doctor,int type);
  188. @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)")
  189. List<Object> findDoctorSignPatientsByTypeName(String doctor,int type,String name);
  190. @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >= 0")
  191. SignFamily findByPatient(String patient);
  192. @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 1 and a.status >= 0")
  193. SignFamily findBySanshiIdcard(String idcard);
  194. @Query("select a from SignFamily a where a.patient = ?1 and a.type = ?2 and a.status > 0")
  195. SignFamily findSignByPatient(String patient,int type);
  196. @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")
  197. List<SignFamily> findLastJySignByPatient(String patient,int type);
  198. @Query(" from SignFamily a where a.type =1 and unix_timestamp(a.czrq)=unix_timestamp( ?1 ) ")
  199. List<SignFamily> findByDate(String s);
  200. @Modifying
  201. @Query("update SignFamily set expenses_type = ?1 where patient = ?2 and status > 0 and type = 2")
  202. int updateExpensesType(String expensesType,String patient);
  203. @Query("select count(*) from SignFamily where patient = ?1 and status > 0 and type = 1")
  204. int countPatientSsSign(String patient);
  205. @Query("select count(*) from SignFamily where patient = ?1 and status > 0 and type = 2")
  206. int countPatientJtSign(String patient);
  207. // 查询患者已生效的家庭签约
  208. @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status = 0")
  209. SignFamily findSigningByPatient(String patient);
  210. }