ConsultTeamService.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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.service.app.consult;
  7. import java.util.*;
  8. import com.yihu.wlyy.entity.consult.Consult;
  9. import com.yihu.wlyy.entity.consult.ConsultTeam;
  10. import com.yihu.wlyy.entity.consult.ConsultTeamDoctor;
  11. import com.yihu.wlyy.entity.consult.ConsultTeamLog;
  12. import com.yihu.wlyy.entity.doctor.profile.Doctor;
  13. import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam;
  14. import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeamMember;
  15. import com.yihu.wlyy.entity.patient.Patient;
  16. import com.yihu.wlyy.entity.patient.SignFamily;
  17. import com.yihu.wlyy.repository.consult.ConsultTeamDao;
  18. import com.yihu.wlyy.repository.consult.ConsultTeamDoctorDao;
  19. import com.yihu.wlyy.repository.consult.ConsultTeamLogDao;
  20. import com.yihu.wlyy.repository.doctor.DoctorPatientDao;
  21. import com.yihu.wlyy.repository.doctor.DoctorTeamDao;
  22. import com.yihu.wlyy.repository.doctor.DoctorTeamMemberDao;
  23. import com.yihu.wlyy.repository.patient.SignFamilyDao;
  24. import com.yihu.wlyy.util.HttpUtil;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.data.domain.Page;
  28. import org.springframework.data.domain.PageImpl;
  29. import org.springframework.data.domain.PageRequest;
  30. import org.springframework.data.domain.Sort;
  31. import org.springframework.data.domain.Sort.Direction;
  32. import org.springframework.data.jpa.domain.Specification;
  33. import org.springframework.jdbc.core.JdbcTemplate;
  34. import org.springframework.stereotype.Component;
  35. import org.springframework.transaction.annotation.Transactional;
  36. import org.springside.modules.persistence.DynamicSpecifications;
  37. import org.springside.modules.persistence.SearchFilter;
  38. import org.springside.modules.persistence.SearchFilter.Operator;
  39. import org.springside.modules.utils.Clock;
  40. import com.yihu.wlyy.task.PushMsgTask;
  41. import com.yihu.wlyy.util.MessageType;
  42. /**
  43. * 網絡諮詢类.
  44. *
  45. * @author George
  46. */
  47. // Spring Service Bean的标识.
  48. @Component
  49. @Transactional(rollbackFor = Exception.class)
  50. public class ConsultTeamService extends ConsultService {
  51. private Clock clock = Clock.DEFAULT;
  52. // 咨询详细记录
  53. @Autowired
  54. private ConsultTeamLogDao consultTeamLogDao;
  55. @Autowired
  56. private ConsultTeamDoctorDao consultTeamDoctorDao;
  57. @Autowired
  58. private SignFamilyDao signFamilyDao;
  59. @Autowired
  60. private DoctorPatientDao doctorPatientDao;
  61. @Autowired
  62. private DoctorTeamDao doctorTeamDao;
  63. @Autowired
  64. private ConsultTeamDao consultTeamDao;
  65. @Autowired
  66. private DoctorTeamMemberDao doctorTeamDoctor;
  67. @Autowired
  68. private JdbcTemplate jdbcTemplate;
  69. /**
  70. * 查询患者是否还有未结束的三师咨询
  71. * @param patient
  72. * @return
  73. */
  74. public boolean exist(String patient,Integer type) {
  75. int count = consultTeamDao.countByPatient(patient, type);
  76. return count > 0;
  77. }
  78. /**
  79. * 查詢醫生網絡諮詢列表
  80. * @param type 咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的 5 名医咨询 全部 6 名医咨询 进行中 7 名医咨询 已结束
  81. * @param id
  82. * @param pagesize 每页显示数,默认为10
  83. * @return
  84. */
  85. public Page<ConsultTeam> findByDoctor(String uid, int type, long id, int pagesize,String title) {
  86. if (id < 0) {
  87. id = 0;
  88. }
  89. if (pagesize <= 0) {
  90. pagesize = 10;
  91. }
  92. switch (type) {
  93. case 0:
  94. // 全部
  95. return findByDoctorType0(uid, id, pagesize);
  96. case 1:
  97. // 咨询我的
  98. return findByDoctorType1(uid, type, id, pagesize);
  99. case 2:
  100. // 我感兴趣的
  101. return findByDoctorType2(uid, type, id, pagesize);
  102. case 3:
  103. // 我回复的
  104. return findByDoctorType3(uid, id, pagesize);
  105. case 4:
  106. // 已完成的
  107. return findByDoctorType4(uid, id, pagesize);
  108. case 5:
  109. // 5 名医咨询 全部
  110. return findByDoctorType5(uid, id, pagesize,title);
  111. case 6:
  112. //6 名医咨询 进行中
  113. return findByDoctorType6(uid, 0, id, pagesize,title);
  114. case 7:
  115. //7 名医咨询 已结束
  116. return findByDoctorType6(uid, 1, id, pagesize,title);
  117. }
  118. return null;
  119. }
  120. private Page<ConsultTeam> findByDoctorType5(String uid, long id, int pagesize,String title) {
  121. Sort sort = new Sort(Direction.DESC, "id");
  122. // 分页信息
  123. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  124. if(StringUtils.isNoneEmpty(title)){
  125. title="%"+title+"%";
  126. if (id > 0) {
  127. return consultTeamDao.findFamousDoctorAllList(uid, id,title, pageRequest);
  128. } else {
  129. return consultTeamDao.findFamousDoctorAllList(uid,title, pageRequest);
  130. }
  131. }else{
  132. if (id > 0) {
  133. return consultTeamDao.findFamousDoctorAllList(uid, id, pageRequest);
  134. } else {
  135. return consultTeamDao.findFamousDoctorAllList(uid, pageRequest);
  136. }
  137. }
  138. }
  139. private Page<ConsultTeam> findByDoctorType6(String uid, int type, long id, int pagesize,String title) {
  140. // 排序
  141. Sort sort = new Sort(Direction.DESC, "id");
  142. // 分页信息
  143. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  144. if(StringUtils.isNoneEmpty(title)){
  145. title="%"+title+"%";
  146. if (id > 0) {
  147. return consultTeamDao.findFamousDoctorDoingList(uid, id,title,type, pageRequest);
  148. } else {
  149. return consultTeamDao.findFamousDoctorDoingList(uid, title,type,pageRequest);
  150. }
  151. }else{
  152. if (id > 0) {
  153. return consultTeamDao.findFamousDoctorDoingList(uid, id,type, pageRequest);
  154. } else {
  155. return consultTeamDao.findFamousDoctorDoingList(uid,type, pageRequest);
  156. }
  157. }
  158. }
  159. /**
  160. * 查询全部咨询记录
  161. * @param uid
  162. * @param id
  163. * @param pagesize
  164. * @return
  165. */
  166. public Page<ConsultTeam> findByDoctorType0(String uid, long id, int pagesize) {
  167. // 排序
  168. Sort sort = new Sort(Direction.DESC, "id");
  169. // 分页信息
  170. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  171. if (id > 0) {
  172. return consultTeamDao.findDoctorList(uid, id, pageRequest);
  173. } else {
  174. return consultTeamDao.findDoctorList(uid, pageRequest);
  175. }
  176. }
  177. /**
  178. * 指定医生三师咨询列表查询
  179. * @param uid 医生标识
  180. * @param type 咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的
  181. * @param pagesize
  182. * @return
  183. */
  184. public Page<ConsultTeam> findByDoctorType1(String uid, int type, long id, int pagesize) {
  185. // 排序
  186. Sort sort = new Sort(Direction.DESC, "id");
  187. // 分页信息
  188. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  189. if (id > 0) {
  190. return consultTeamDao.findDoctorPointList(uid, id, pageRequest);
  191. } else {
  192. return consultTeamDao.findDoctorPointList(uid, pageRequest);
  193. }
  194. }
  195. /**
  196. * 公共三师咨询列表查询
  197. * @param uid 医生标识
  198. * @param type 咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的
  199. * @param pagesize
  200. * @return
  201. */
  202. public Page<ConsultTeam> findByDoctorType2(String uid, int type, long id, int pagesize) {
  203. // 排序
  204. Sort sort = new Sort(Direction.DESC, "id");
  205. // 分页信息
  206. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  207. // 设置查询条件
  208. Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
  209. // 未指定医生
  210. filters.put("type", new SearchFilter("type", Operator.EQ, 0));
  211. if (id > 0) {
  212. filters.put("id", new SearchFilter("id", Operator.LT, id));
  213. }
  214. // 未回复
  215. filters.put("status", new SearchFilter("status", Operator.EQ, 0));
  216. // 未作废
  217. filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
  218. Specification<ConsultTeam> spec = DynamicSpecifications.bySearchFilter(filters.values(), ConsultTeam.class);
  219. return consultTeamDao.findAll(spec, pageRequest);
  220. }
  221. /**
  222. * 医生参与过的未结束的三师咨询列表查询
  223. * @param uid
  224. * @param pagesize
  225. * @return
  226. */
  227. public Page<ConsultTeam> findByDoctorType3(String uid, long id, int pagesize) {
  228. // 排序
  229. Sort sort = new Sort(Direction.DESC, "id");
  230. // 分页信息
  231. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  232. if (id > 0) {
  233. return consultTeamDao.findDoctorJoinList(uid, id, pageRequest);
  234. } else {
  235. return consultTeamDao.findDoctorJoinList(uid, pageRequest);
  236. }
  237. }
  238. /**
  239. * 医生参与过的已结束的三师咨询列表查询
  240. * @param uid
  241. * @param pagesize
  242. * @return
  243. */
  244. public Page<ConsultTeam> findByDoctorType4(String uid, long id, int pagesize) {
  245. // 排序
  246. Sort sort = new Sort(Direction.DESC, "id");
  247. // 分页信息
  248. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  249. if (id > 0) {
  250. return consultTeamDao.findDoctorFinishList(uid, id, pageRequest);
  251. } else {
  252. return consultTeamDao.findDoctorFinishList(uid, pageRequest);
  253. }
  254. }
  255. /**
  256. * 网络咨询咨询日志查询
  257. * @param consult 咨询标识
  258. * @param pagesize 每页显示数,默认为10
  259. * @return
  260. */
  261. public Page<ConsultTeamLog> findLogByConsult(String consult, long id, int pagesize) {
  262. if (id < 0) {
  263. id = 0;
  264. }
  265. // 设置查询条件
  266. Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
  267. filters.put("consult", new SearchFilter("consult", Operator.EQ, consult));
  268. if (id > 0) {
  269. if(pagesize>0)
  270. filters.put("id", new SearchFilter("id", Operator.LT, id));
  271. else
  272. filters.put("id", new SearchFilter("id", Operator.GT, id));
  273. }
  274. filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
  275. Specification<ConsultTeamLog> spec = DynamicSpecifications.bySearchFilter(filters.values(), ConsultTeamLog.class);
  276. if(pagesize <= 0){
  277. Page<ConsultTeamLog> p = new PageImpl<>(consultTeamLogDao.findAll(spec));
  278. return p;
  279. }
  280. // 排序
  281. Sort sort = new Sort(Direction.DESC, "id");
  282. // 分页信息
  283. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  284. return consultTeamLogDao.findAll(spec, pageRequest);
  285. }
  286. /**
  287. * 批量回复
  288. * @param logs
  289. * @return
  290. */
  291. public void reply(List<ConsultTeamLog> logs, String patient) {
  292. for (ConsultTeamLog log : logs) {
  293. reply(log, patient, null, log.getType());
  294. }
  295. }
  296. /**
  297. * 添加咨询记录
  298. * @param log 日志对象
  299. * @param type 类型,0问,1回复,2追问,3评价
  300. * @return
  301. */
  302. public ConsultTeamLog reply(ConsultTeamLog log, String patient, String teamOrDoctor, int type) {
  303. log.setCzrq(clock.getCurrentDate());
  304. // 保存咨询记录
  305. ConsultTeamLog temp = consultTeamLogDao.save(log);
  306. if (temp != null) {
  307. // 发送消息
  308. if (type == 1) {
  309. // 医生回复,给患者发消息
  310. // sendMessage(patient, teamOrDoctor, "三师咨询", log.getDoctorName() + "回复了您的咨询", log.getConsult(), 214, 1, 0, 0);
  311. // 患者未读数量+1
  312. consultTeamDao.increasePatientRead(log.getConsult());
  313. // 医生有回复
  314. consultTeamDoctorDao.updateReply(log.getConsult(), teamOrDoctor);
  315. //shenzaixin v1.2.0 推送消息给患者
  316. HttpUtil.sendWeixinWebsocketMsg(patient,"data={busiType:'qianyuezixun',msgid:'"+log.getId()+"'}");
  317. } else if (type == 0 || type == 2) {
  318. // 查询相关联的医生
  319. Iterable<ConsultTeamDoctor> iterable = consultTeamDoctorDao.findByConsult(log.getConsult());
  320. if (iterable != null && iterable.iterator() != null && iterable.iterator().hasNext()) {
  321. Iterator<ConsultTeamDoctor> iterator = iterable.iterator();
  322. while (iterator.hasNext()) {
  323. // 患者提问或追问,给医生发消息
  324. ConsultTeamDoctor ctd = iterator.next();
  325. if (ctd == null) {
  326. continue;
  327. }
  328. // 推送消息给医生
  329. PushMsgTask.getInstance().put(ctd.getTo(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM_REPLY.D_CT_02.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM_REPLY.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM_REPLY.您有新的消息.name(), temp.getConsult());
  330. }
  331. }
  332. // 医生未读数量+1
  333. consultTeamDao.increaseDoctorRead(log.getConsult());
  334. }
  335. }
  336. return temp;
  337. }
  338. /**
  339. * 添加三师咨询
  340. * @param ct 三师咨询对象
  341. * @param patient 患者标识
  342. * @return
  343. * @throws Exception
  344. */
  345. public int addTeamConsult(ConsultTeam ct, String patient) throws Exception {
  346. // 咨询三师
  347. if (ct.getType() == 1) {
  348. // 查询三师签约信息
  349. SignFamily sc = signFamilyDao.findBySanshiPatientYes(patient);
  350. if (sc == null) {
  351. // 不存在三师签约
  352. return -2;
  353. }
  354. ct.setTeam(sc.getTeamCode());
  355. // 设置健康管理师,三师咨询默认给健康管理师处理
  356. //查找病人所在的团队
  357. DoctorTeam doctorTeam=doctorTeamDao.findBySanshiParientCode(patient);
  358. //得到团队的健康管理师
  359. DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(),3);
  360. // 设置家庭医生
  361. ct.setDoctor( doctorTeamMember.getMemberCode());
  362. } else if (ct.getType() == 2) {
  363. // 咨询家庭医生
  364. SignFamily sf = signFamilyDao.findByjiatingPatient(patient);
  365. if (sf == null) {
  366. // 不存在家庭签约
  367. return -1;
  368. }
  369. // 设置健康管理师,家庭医生咨询默认给健康管理师处理
  370. //查找病人所在的团队
  371. DoctorTeam doctorTeam=doctorTeamDao.findByParientCode(patient);
  372. //得到团队的健康管理师
  373. DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(),3);
  374. // 设置家庭医生
  375. ct.setDoctor( doctorTeamMember.getMemberCode());
  376. }
  377. // 设置患者信息
  378. ct.setPatient(patient);
  379. // 查询患者信息
  380. Patient tempPatient = patientDao.findByCode(patient);
  381. // 设置患者姓名
  382. ct.setName(tempPatient.getName());
  383. // 设置患者生日
  384. ct.setBirthday(tempPatient.getBirthday());
  385. //新增性别
  386. ct.setSex(tempPatient.getSex());
  387. // 设置患者头像
  388. ct.setPhoto(tempPatient.getPhoto());
  389. // 设置操作日期
  390. ct.setCzrq(new Date());
  391. ct.setDel("1");
  392. ct.setStatus(0);
  393. // 医生未读数量为1
  394. ct.setDoctorRead(1);
  395. // 添加咨询记录
  396. Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType());
  397. // 设置咨询标识
  398. ct.setConsult(consult.getCode());
  399. // 保存医生咨询信息
  400. if (consultTeamDao.save(ct) == null) {
  401. throw new Exception("保存失败!");
  402. }
  403. // 添加咨询转发记录
  404. ConsultTeamDoctor cd = new ConsultTeamDoctor();
  405. cd.setConsult(consult.getCode());
  406. cd.setDel("1");
  407. cd.setCzrq(new Date());
  408. cd.setTo(ct.getDoctor());
  409. consultTeamDoctorDao.save(cd);
  410. // 添加医生咨询日志
  411. addLogs(ct);
  412. return 1;
  413. }
  414. /**
  415. * 添加三师咨询日志
  416. * @param ct
  417. * @throws Exception
  418. */
  419. private void addLogs(ConsultTeam ct) throws Exception {
  420. List<ConsultTeamLog> logs = new ArrayList<ConsultTeamLog>();
  421. // 添加问题咨询日志
  422. String content = "发病时间:" + (StringUtils.isEmpty(ct.getWhen()) ? "无" : ct.getWhen());
  423. content += "<br>主要症状:" + (StringUtils.isEmpty(ct.getSymptoms()) ? "无" : ct.getSymptoms());
  424. // 生成提问日志,并推送相关消息
  425. ConsultTeamLog infoLog = new ConsultTeamLog();
  426. infoLog.setConsult(ct.getConsult());
  427. infoLog.setContent(content);
  428. infoLog.setDel("1");
  429. infoLog.setType(0);
  430. infoLog.setChatType(1);
  431. infoLog.setCzrq(new Date());
  432. logs.add(infoLog);
  433. // 图片日志
  434. if (StringUtils.isNotEmpty(ct.getImages())) {
  435. String[] images = ct.getImages().split(",");
  436. for (String image : images) {
  437. if (StringUtils.isNoneEmpty(image)) {
  438. ConsultTeamLog imgLog = new ConsultTeamLog();
  439. // 设置咨询标识
  440. imgLog.setConsult(ct.getConsult());
  441. // 设置图片URL
  442. imgLog.setContent(image);
  443. imgLog.setDel("1");
  444. infoLog.setType(0);
  445. imgLog.setCzrq(new Date());
  446. // 图片类型
  447. imgLog.setChatType(2);
  448. // 添加到待保存队列
  449. logs.add(imgLog);
  450. }
  451. }
  452. }
  453. // 语音日志
  454. if (StringUtils.isNotEmpty(ct.getVoice())) {
  455. ConsultTeamLog voiceLog = new ConsultTeamLog();
  456. // 设置咨询标识
  457. voiceLog.setConsult(ct.getConsult());
  458. // 设置语音URL
  459. voiceLog.setContent(ct.getVoice());
  460. voiceLog.setDel("1");
  461. infoLog.setType(0);
  462. // 语音类型
  463. voiceLog.setChatType(3);
  464. voiceLog.setCzrq(new Date());
  465. // 添加到待保存队列
  466. logs.add(voiceLog);
  467. }
  468. if (!logs.isEmpty()) {
  469. Iterable<ConsultTeamLog> iterable = consultTeamLogDao.save(logs);
  470. if (iterable == null || iterable.iterator() == null || !iterable.iterator().hasNext()) {
  471. // 日志保存失败
  472. throw new Exception("consult team log save failed!");
  473. }
  474. }
  475. // 患者提问或追问,给医生发消息
  476. // sendMessage(ct.getDoctor(), ct.getPatient(), "三师咨询", "您有新的三师咨询消息", ct.getConsult(), 116, 1, 0, 0);
  477. }
  478. /**
  479. * 查询咨询列表
  480. * @param patientCode 患者标志
  481. * @param status 咨询状态(0未结束,1已结束,-1 已取消)
  482. * @param pageSize 页数
  483. * @return
  484. */
  485. public Page<ConsultTeam> findByPatient(String patientCode, int status, long id, int pageSize) {
  486. if (id < 0) {
  487. id = 0;
  488. }
  489. if (pageSize <= 0) {
  490. pageSize = 10;
  491. }
  492. // 排序
  493. Sort sort = new Sort(Direction.DESC, "id");
  494. // 分页信息
  495. PageRequest pageRequest = new PageRequest(0, pageSize, sort);
  496. Page<ConsultTeam> list = null;
  497. switch (status) {
  498. case 0:
  499. // 未结束
  500. if (id > 0) {
  501. list = consultTeamDao.findNotFinishedBypatient(patientCode, id, pageRequest);
  502. } else {
  503. list = consultTeamDao.findNotFinishedBypatient(patientCode, pageRequest);
  504. }
  505. break;
  506. case 1:
  507. // 已结束
  508. if (id > 0) {
  509. list = consultTeamDao.findFinishedBypatient(patientCode, id, pageRequest);
  510. } else {
  511. list = consultTeamDao.findFinishedBypatient(patientCode, pageRequest);
  512. }
  513. break;
  514. case -1:
  515. // 已取消
  516. if (id > 0) {
  517. list = consultTeamDao.findCancelBypatient(patientCode, id, pageRequest);
  518. } else {
  519. list = consultTeamDao.findCancelBypatient(patientCode, pageRequest);
  520. }
  521. break;
  522. }
  523. return list;
  524. }
  525. /**
  526. * 医生关闭三师咨询
  527. * @param consult 三师咨询标识
  528. * @return
  529. */
  530. public int finish(String consult) {
  531. return consultTeamDao.updateStatusByConsult(consult);
  532. }
  533. /**
  534. * 设置咨询已读
  535. *
  536. * @param consult
  537. * @return
  538. */
  539. public int readMessage(String consult){
  540. return consultTeamDao.updateReadedByConsult(consult);
  541. }
  542. /**
  543. * 取消三师咨询
  544. * @param consult
  545. * @return
  546. */
  547. public int cancel(String consult) {
  548. return consultTeamDao.cancel(consult);
  549. }
  550. public ConsultTeam findByCode(String code) {
  551. return consultTeamDao.findByConsult(code);
  552. }
  553. /**
  554. * 三师咨询转接医生
  555. * @param from 转出医生标识
  556. * @param to 转入医生标识
  557. * @param consult 三师咨询标识
  558. * @return
  559. */
  560. public void transfer(String from, String to, String consult) {
  561. // 检查是否存在
  562. if (consultTeamDoctorDao.isExist(consult, to) == 0) {
  563. // 查询医生信息
  564. Doctor d = doctorDao.findByCode(from);
  565. // 再保存
  566. ConsultTeamDoctor cd = new ConsultTeamDoctor();
  567. cd.setConsult(consult);
  568. cd.setDel("1");
  569. cd.setCzrq(new Date());
  570. cd.setFrom(d.getCode());
  571. cd.setFromName(d.getName());
  572. cd.setTo(to);
  573. consultTeamDoctorDao.save(cd);
  574. }
  575. }
  576. /**
  577. * 查询患者视频和三师咨询记录
  578. * @param patient 患者标识
  579. * @param id
  580. * @param pagesize
  581. * @return
  582. */
  583. public Page<Consult> findConsultRecordByPatientType(String patient, long id, int pagesize) {
  584. if (pagesize <= 0) {
  585. pagesize = 10;
  586. }
  587. // 排序
  588. Sort sort = new Sort(Direction.DESC, "id");
  589. // 分页信息
  590. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  591. // 设置查询条件
  592. Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
  593. filters.put("patient", new SearchFilter("patient", Operator.EQ, patient));
  594. filters.put("type", new SearchFilter("type", Operator.LT, 3));
  595. if (id > 0) {
  596. filters.put("id", new SearchFilter("id", Operator.LT, id));
  597. }
  598. // 未作废
  599. filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
  600. Specification<Consult> spec = DynamicSpecifications.bySearchFilter(filters.values(), Consult.class);
  601. return consultDao.findAll(spec, pageRequest);
  602. }
  603. /**
  604. * 清空医生未读数量
  605. * @param consult
  606. */
  607. public void clearDoctorRead(String consult) {
  608. consultTeamDao.clearDoctorRead(consult);
  609. }
  610. /**
  611. * 清空患者未读数量
  612. * @param consult
  613. */
  614. public void clearPatientRead(String consult) {
  615. consultTeamDao.clearPatientRead(consult);
  616. }
  617. /**
  618. * 查询医生的咨询统计
  619. *
  620. * @param doctorCode
  621. * @return
  622. */
  623. public Map<String,Long> getAllCount(String doctorCode) {
  624. Map<String,Long> result = new HashMap<>();
  625. //根据医生code查询总咨询数
  626. long allCount=consultTeamDoctorDao.getAllCountByDoctorCode(doctorCode);
  627. //根据医生code查询今日咨询数
  628. long todayCount=consultTeamDoctorDao.getTodayCountByDoctorCode(doctorCode);
  629. result.put("all",allCount);
  630. result.put("today",todayCount);
  631. return result;
  632. }
  633. /**
  634. * 查找未完成咨询
  635. *
  636. * @param patient
  637. * @return
  638. */
  639. public List<ConsultTeam> getUnfinishedConsult(String patient){
  640. return consultTeamDao.findUnfinishedConsult(patient);
  641. }
  642. /**
  643. * 查询患者全部的咨询数目
  644. * @param patientCode
  645. * @return
  646. */
  647. public Integer findByDoctorSize(String patientCode,String doctorCode) {
  648. return consultDao.findByPatient(patientCode,doctorCode);
  649. }
  650. public List<Map<String,Object>> getConsultSign(String[] consults){
  651. String params = "";
  652. List<String> paramList = new ArrayList<>();
  653. for(int i = 0; i < consults.length ; i++){
  654. params += (i == 0?"?":",?");
  655. }
  656. paramList.addAll(Arrays.asList(consults));
  657. paramList.addAll(Arrays.asList(consults));
  658. String sqlgp = "select DISTINCT consult,to_doctor from wlyy_consult_team_doctor ctd,wlyy_doctor d where ctd.to_doctor = d.code and d.level = 2 and ctd.consult in (" + params + ") and ctd.del = '1'";
  659. String sqlgpm = "select DISTINCT to_doctor from wlyy_consult_team_doctor ctd,wlyy_doctor d where ctd.to_doctor = d.code and d.level = 2 and ctd.consult in (" + params + ") and ctd.del = '1'";
  660. String sqlQu = "select * from wlyy_quota_result where qkdoctor_code in (" + sqlgpm+ ") and quato_code = '1' and level1_type = '1'";
  661. String sqlQuSum = "select a.consult,sum(ifnull(b.result,0)) sign from ("+ sqlgp +") a left join (" + sqlQu+ ") b on a.to_doctor = b.qkdoctor_code group by a.consult ";
  662. return jdbcTemplate.queryForList(sqlQuSum,paramList.toArray());
  663. }
  664. public ConsultTeamLog oneLog(Long logId) {
  665. return consultTeamLogDao.findOne(logId);
  666. }
  667. public boolean isExistFamousConsult(String uid) {
  668. ConsultTeam consultTeam= consultTeamDao.findFamousConsultByPatient(uid);
  669. if(consultTeam!=null){
  670. return true;
  671. }else{
  672. return false;
  673. }
  674. }
  675. public void addFamousTeamConsult(ConsultTeam ct, String uid) throws Exception{
  676. // 设置患者信息
  677. ct.setPatient(uid);
  678. // 查询患者信息
  679. Patient tempPatient = patientDao.findByCode(uid);
  680. // 设置患者姓名
  681. ct.setName(tempPatient.getName());
  682. // 设置患者生日
  683. ct.setBirthday(tempPatient.getBirthday());
  684. //新增性别
  685. ct.setSex(tempPatient.getSex());
  686. // 设置患者头像
  687. ct.setPhoto(tempPatient.getPhoto());
  688. // 设置操作日期
  689. ct.setCzrq(new Date());
  690. ct.setDel("1");
  691. ct.setStatus(0);
  692. // 医生未读数量为1
  693. ct.setDoctorRead(1);
  694. // 患者未读数量为0
  695. ct.setPatientRead(0);
  696. // 添加咨询记录
  697. Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType());
  698. // 设置咨询标识
  699. ct.setConsult(consult.getCode());
  700. // 保存医生咨询信息
  701. if (consultTeamDao.save(ct) == null) {
  702. throw new Exception("保存失败!");
  703. }
  704. // 添加咨询转发记录
  705. ConsultTeamDoctor cd = new ConsultTeamDoctor();
  706. cd.setConsult(consult.getCode());
  707. cd.setDel("1");
  708. cd.setCzrq(new Date());
  709. cd.setTo(ct.getDoctor());
  710. consultTeamDoctorDao.save(cd);
  711. // 添加医生咨询日志
  712. addLogs(ct);
  713. }
  714. }