ConsultTeamService.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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,"{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 ="";
  423. if(ct.getType()==1||ct.getType()==2){
  424. content = "发病时间:" + (StringUtils.isEmpty(ct.getWhen()) ? "无" : ct.getWhen());
  425. content += "<br>主要症状:" + (StringUtils.isEmpty(ct.getSymptoms()) ? "无" : ct.getSymptoms());
  426. }else if(ct.getType()==6){
  427. content = "咨询问题:";
  428. content += "<br>主要症状:" + (StringUtils.isEmpty(ct.getSymptoms()) ? "无" : ct.getSymptoms());
  429. }
  430. // 生成提问日志,并推送相关消息
  431. ConsultTeamLog infoLog = new ConsultTeamLog();
  432. infoLog.setConsult(ct.getConsult());
  433. infoLog.setContent(content);
  434. infoLog.setDel("1");
  435. infoLog.setType(0);
  436. infoLog.setChatType(1);
  437. infoLog.setCzrq(new Date());
  438. logs.add(infoLog);
  439. // 图片日志
  440. if (StringUtils.isNotEmpty(ct.getImages())) {
  441. String[] images = ct.getImages().split(",");
  442. for (String image : images) {
  443. if (StringUtils.isNoneEmpty(image)) {
  444. ConsultTeamLog imgLog = new ConsultTeamLog();
  445. // 设置咨询标识
  446. imgLog.setConsult(ct.getConsult());
  447. // 设置图片URL
  448. imgLog.setContent(image);
  449. imgLog.setDel("1");
  450. infoLog.setType(0);
  451. imgLog.setCzrq(new Date());
  452. // 图片类型
  453. imgLog.setChatType(2);
  454. // 添加到待保存队列
  455. logs.add(imgLog);
  456. }
  457. }
  458. }
  459. // 语音日志
  460. if (StringUtils.isNotEmpty(ct.getVoice())) {
  461. ConsultTeamLog voiceLog = new ConsultTeamLog();
  462. // 设置咨询标识
  463. voiceLog.setConsult(ct.getConsult());
  464. // 设置语音URL
  465. voiceLog.setContent(ct.getVoice());
  466. voiceLog.setDel("1");
  467. infoLog.setType(0);
  468. // 语音类型
  469. voiceLog.setChatType(3);
  470. voiceLog.setCzrq(new Date());
  471. // 添加到待保存队列
  472. logs.add(voiceLog);
  473. }
  474. if (!logs.isEmpty()) {
  475. Iterable<ConsultTeamLog> iterable = consultTeamLogDao.save(logs);
  476. if (iterable == null || iterable.iterator() == null || !iterable.iterator().hasNext()) {
  477. // 日志保存失败
  478. throw new Exception("consult team log save failed!");
  479. }
  480. }
  481. // 患者提问或追问,给医生发消息
  482. // sendMessage(ct.getDoctor(), ct.getPatient(), "三师咨询", "您有新的三师咨询消息", ct.getConsult(), 116, 1, 0, 0);
  483. }
  484. /**
  485. * 查询咨询列表
  486. * @param patientCode 患者标志
  487. * @param status 咨询状态(0未结束,1已结束,-1 已取消)
  488. * @param pageSize 页数
  489. * @return
  490. */
  491. public Page<ConsultTeam> findByPatient(String patientCode, int status, long id, int pageSize) {
  492. if (id < 0) {
  493. id = 0;
  494. }
  495. if (pageSize <= 0) {
  496. pageSize = 10;
  497. }
  498. // 排序
  499. Sort sort = new Sort(Direction.DESC, "id");
  500. // 分页信息
  501. PageRequest pageRequest = new PageRequest(0, pageSize, sort);
  502. Page<ConsultTeam> list = null;
  503. switch (status) {
  504. case 0:
  505. // 未结束
  506. if (id > 0) {
  507. list = consultTeamDao.findNotFinishedBypatient(patientCode, id, pageRequest);
  508. } else {
  509. list = consultTeamDao.findNotFinishedBypatient(patientCode, pageRequest);
  510. }
  511. break;
  512. case 1:
  513. // 已结束
  514. if (id > 0) {
  515. list = consultTeamDao.findFinishedBypatient(patientCode, id, pageRequest);
  516. } else {
  517. list = consultTeamDao.findFinishedBypatient(patientCode, pageRequest);
  518. }
  519. break;
  520. case -1:
  521. // 已取消
  522. if (id > 0) {
  523. list = consultTeamDao.findCancelBypatient(patientCode, id, pageRequest);
  524. } else {
  525. list = consultTeamDao.findCancelBypatient(patientCode, pageRequest);
  526. }
  527. break;
  528. }
  529. return list;
  530. }
  531. /**
  532. * 医生关闭三师咨询
  533. * @param consult 三师咨询标识
  534. * @return
  535. */
  536. public int finish(String consult) {
  537. return consultTeamDao.updateStatusByConsult(consult);
  538. }
  539. /**
  540. * 设置咨询已读
  541. *
  542. * @param consult
  543. * @return
  544. */
  545. public int readMessage(String consult){
  546. return consultTeamDao.updateReadedByConsult(consult);
  547. }
  548. /**
  549. * 取消三师咨询
  550. * @param consult
  551. * @return
  552. */
  553. public int cancel(String consult) {
  554. return consultTeamDao.cancel(consult);
  555. }
  556. public ConsultTeam findByCode(String code) {
  557. return consultTeamDao.findByConsult(code);
  558. }
  559. /**
  560. * 三师咨询转接医生
  561. * @param from 转出医生标识
  562. * @param to 转入医生标识
  563. * @param consult 三师咨询标识
  564. * @return
  565. */
  566. public void transfer(String from, String to, String consult) {
  567. // 检查是否存在
  568. if (consultTeamDoctorDao.isExist(consult, to) == 0) {
  569. // 查询医生信息
  570. Doctor d = doctorDao.findByCode(from);
  571. // 再保存
  572. ConsultTeamDoctor cd = new ConsultTeamDoctor();
  573. cd.setConsult(consult);
  574. cd.setDel("1");
  575. cd.setCzrq(new Date());
  576. cd.setFrom(d.getCode());
  577. cd.setFromName(d.getName());
  578. cd.setTo(to);
  579. consultTeamDoctorDao.save(cd);
  580. }
  581. }
  582. /**
  583. * 查询患者视频和三师咨询记录
  584. * @param patient 患者标识
  585. * @param id
  586. * @param pagesize
  587. * @return
  588. */
  589. public Page<Consult> findConsultRecordByPatientType(String patient, long id, int pagesize) {
  590. if (pagesize <= 0) {
  591. pagesize = 10;
  592. }
  593. // 排序
  594. Sort sort = new Sort(Direction.DESC, "id");
  595. // 分页信息
  596. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  597. // 设置查询条件
  598. Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
  599. filters.put("patient", new SearchFilter("patient", Operator.EQ, patient));
  600. filters.put("type", new SearchFilter("type", Operator.LT, 3));
  601. if (id > 0) {
  602. filters.put("id", new SearchFilter("id", Operator.LT, id));
  603. }
  604. // 未作废
  605. filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
  606. Specification<Consult> spec = DynamicSpecifications.bySearchFilter(filters.values(), Consult.class);
  607. return consultDao.findAll(spec, pageRequest);
  608. }
  609. /**
  610. * 清空医生未读数量
  611. * @param consult
  612. */
  613. public void clearDoctorRead(String consult) {
  614. consultTeamDao.clearDoctorRead(consult);
  615. }
  616. /**
  617. * 清空患者未读数量
  618. * @param consult
  619. */
  620. public void clearPatientRead(String consult) {
  621. consultTeamDao.clearPatientRead(consult);
  622. }
  623. /**
  624. * 查询医生的咨询统计
  625. *
  626. * @param doctorCode
  627. * @return
  628. */
  629. public Map<String,Long> getAllCount(String doctorCode) {
  630. Map<String,Long> result = new HashMap<>();
  631. //根据医生code查询总咨询数
  632. long allCount=consultTeamDoctorDao.getAllCountByDoctorCode(doctorCode);
  633. //根据医生code查询今日咨询数
  634. long todayCount=consultTeamDoctorDao.getTodayCountByDoctorCode(doctorCode);
  635. result.put("all",allCount);
  636. result.put("today",todayCount);
  637. return result;
  638. }
  639. /**
  640. * 查找未完成咨询
  641. *
  642. * @param patient
  643. * @return
  644. */
  645. public List<ConsultTeam> getUnfinishedConsult(String patient){
  646. return consultTeamDao.findUnfinishedConsult(patient);
  647. }
  648. /**
  649. * 查询患者全部的咨询数目
  650. * @param patientCode
  651. * @return
  652. */
  653. public Integer findByDoctorSize(String patientCode,String doctorCode) {
  654. return consultDao.findByPatient(patientCode,doctorCode);
  655. }
  656. public List<Map<String,Object>> getConsultSign(String[] consults){
  657. String params = "";
  658. List<String> paramList = new ArrayList<>();
  659. for(int i = 0; i < consults.length ; i++){
  660. params += (i == 0?"?":",?");
  661. }
  662. paramList.addAll(Arrays.asList(consults));
  663. paramList.addAll(Arrays.asList(consults));
  664. 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'";
  665. 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'";
  666. String sqlQu = "select * from wlyy_quota_result where qkdoctor_code in (" + sqlgpm+ ") and quato_code = '1' and level1_type = '1'";
  667. 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 ";
  668. return jdbcTemplate.queryForList(sqlQuSum,paramList.toArray());
  669. }
  670. public ConsultTeamLog oneLog(Long logId) {
  671. return consultTeamLogDao.findOne(logId);
  672. }
  673. public boolean isExistFamousConsult(String uid) {
  674. ConsultTeam consultTeam= consultTeamDao.findFamousConsultByPatient(uid);
  675. if(consultTeam!=null){
  676. return true;
  677. }else{
  678. return false;
  679. }
  680. }
  681. public void addFamousTeamConsult(ConsultTeam ct, String uid) throws Exception{
  682. // 设置患者信息
  683. ct.setPatient(uid);
  684. // 查询患者信息
  685. Patient tempPatient = patientDao.findByCode(uid);
  686. // 设置患者姓名
  687. ct.setName(tempPatient.getName());
  688. // 设置患者生日
  689. ct.setBirthday(tempPatient.getBirthday());
  690. //新增性别
  691. ct.setSex(tempPatient.getSex());
  692. // 设置患者头像
  693. ct.setPhoto(tempPatient.getPhoto());
  694. // 设置操作日期
  695. ct.setCzrq(new Date());
  696. ct.setDel("1");
  697. ct.setStatus(0);
  698. // 医生未读数量为1
  699. ct.setDoctorRead(1);
  700. // 患者未读数量为0
  701. ct.setPatientRead(0);
  702. // 添加咨询记录
  703. Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType());
  704. // 设置咨询标识
  705. ct.setConsult(consult.getCode());
  706. // 保存医生咨询信息
  707. if (consultTeamDao.save(ct) == null) {
  708. throw new Exception("保存失败!");
  709. }
  710. // 添加咨询转发记录
  711. ConsultTeamDoctor cd = new ConsultTeamDoctor();
  712. cd.setConsult(consult.getCode());
  713. cd.setDel("1");
  714. cd.setCzrq(new Date());
  715. cd.setTo(ct.getDoctor());
  716. consultTeamDoctorDao.save(cd);
  717. // 添加医生咨询日志
  718. addLogs(ct);
  719. }
  720. /**
  721. * 根据健康管理师和患者 找到正在进行中的咨询
  722. * @param patientCode
  723. * @param doctor
  724. */
  725. public ConsultTeam getConsultByPatientAndDoctor(String patientCode, String doctor) {
  726. ConsultTeam consultTeam= consultTeamDao.findByParientCodeAndSignTypeAndDoctor(patientCode,doctor,2);
  727. return consultTeam;
  728. }
  729. public void transfers(String uid, String doctor, String consult) {
  730. String[] doctors=doctor.split(",");
  731. for(int i=0;i<doctors.length;i++){
  732. transfer(uid,doctors[i],consult);
  733. }
  734. }
  735. }