SignFamilyDao.java 17 KB

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