ConsultTeamService.java 24 KB

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