FamilyContractService.java 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. package com.yihu.wlyy.service.app.sign;
  2. import java.util.*;
  3. import com.yihu.wlyy.entity.organization.Hospital;
  4. import com.yihu.wlyy.entity.dict.SystemDict;
  5. import com.yihu.wlyy.entity.doctor.profile.Doctor;
  6. import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
  7. import com.yihu.wlyy.entity.doctor.profile.DoctorService;
  8. import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam;
  9. import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeamMember;
  10. import com.yihu.wlyy.entity.message.Message;
  11. import com.yihu.wlyy.entity.patient.Patient;
  12. import com.yihu.wlyy.entity.patient.SignFamily;
  13. import com.yihu.wlyy.entity.patient.SignFamilyCode;
  14. import com.yihu.wlyy.repository.consult.ConsultTeamDao;
  15. import com.yihu.wlyy.repository.dict.SystemDictDao;
  16. import com.yihu.wlyy.repository.doctor.*;
  17. import com.yihu.wlyy.repository.message.MessageDao;
  18. import com.yihu.wlyy.repository.organization.HospitalDao;
  19. import com.yihu.wlyy.repository.patient.PatientDao;
  20. import com.yihu.wlyy.repository.patient.PatientDiseaseDao;
  21. import com.yihu.wlyy.repository.patient.SignFamilyDao;
  22. import com.yihu.wlyy.repository.patient.SocialSecurityInfoDao;
  23. import com.yihu.wlyy.repository.statistics.WlyySignFamilyCodeDao;
  24. import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.json.JSONArray;
  27. import org.json.JSONObject;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.data.domain.Page;
  30. import org.springframework.data.domain.PageRequest;
  31. import org.springframework.data.domain.Sort;
  32. import org.springframework.data.domain.Sort.Direction;
  33. import org.springframework.data.jpa.domain.Specification;
  34. import org.springframework.data.redis.core.StringRedisTemplate;
  35. import org.springframework.jdbc.core.JdbcTemplate;
  36. import org.springframework.stereotype.Component;
  37. import org.springframework.transaction.annotation.Transactional;
  38. import org.springside.modules.persistence.DynamicSpecifications;
  39. import org.springside.modules.persistence.SearchFilter;
  40. import org.springside.modules.persistence.SearchFilter.Operator;
  41. import com.yihu.wlyy.service.BaseService;
  42. import com.yihu.wlyy.task.PushMsgTask;
  43. import com.yihu.wlyy.util.DateUtil;
  44. import com.yihu.wlyy.util.IdcardInfoExtractor;
  45. import com.yihu.wlyy.util.MessageType;
  46. /**
  47. * 家庭签约业务处理类
  48. *
  49. * @author George
  50. */
  51. @Component
  52. @Transactional
  53. public class FamilyContractService extends BaseService {
  54. @Autowired
  55. private DoctorPatientDao doctorPatientDao;
  56. @Autowired
  57. private SignFamilyDao signFamilyDao;
  58. @Autowired
  59. private DoctorServiceDao doctorServiceDao;
  60. @Autowired
  61. private HospitalDao hospitalDao;
  62. @Autowired
  63. private DoctorDao doctorDao;
  64. @Autowired
  65. private PatientDao patientDao;
  66. @Autowired
  67. private MessageDao messageDao;
  68. @Autowired
  69. private DoctorTeamDao doctorTeamDao;
  70. @Autowired
  71. private DoctorTeamMemberDao doctorTeamDoctor;
  72. @Autowired
  73. private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
  74. @Autowired
  75. private ConsultTeamDao consultTeamDao;
  76. @Autowired
  77. private JdbcTemplate jdbcTemplate;
  78. @Autowired
  79. private WlyySignFamilyCodeDao wlyySignFamilyCodeDao;
  80. @Autowired
  81. private SystemDictDao systemDictDao;
  82. @Autowired
  83. private PatientDiseaseService patientDiseaseService;
  84. @Autowired
  85. private StringRedisTemplate redisTemplate;
  86. @Autowired
  87. private PatientDiseaseDao patientDiseaseDao;
  88. @Autowired
  89. private SocialSecurityInfoDao socialSecurityInfoDao;
  90. @Autowired
  91. private DoctorAdminTeamDao doctorAdminTeamDao;
  92. public SignFamily findByPatientByType(String patient, int type) {
  93. return signFamilyDao.findByPatientAndType(patient, type);
  94. }
  95. public SignFamily findByPatient(String patient) {
  96. return signFamilyDao.findByjiatingPatient(patient);
  97. }
  98. public SignFamily findSignByPatient(String patient) {
  99. return signFamilyDao.findSignByPatient(patient);
  100. }
  101. /**
  102. * 获取患者待签约数据
  103. *
  104. * @param patient
  105. * @return
  106. */
  107. public SignFamily findSigningByPatient(String patient) {
  108. return signFamilyDao.findSigningByPatient(patient);
  109. }
  110. /**
  111. * 查询医院列表
  112. *
  113. * @param type 医院类型:0全部,1大医院,2社区医院
  114. * @param province 省代码
  115. * @param city 城市代码
  116. * @param key 搜索关键字
  117. * @param id
  118. * @param pagesize 分页大小
  119. * @return
  120. */
  121. public Page<Hospital> findHospitals(int type, String province, String city, String town, String key, long id, int pagesize) {
  122. if (pagesize <= 0) {
  123. pagesize = 10;
  124. }
  125. // 排序
  126. Sort sort = new Sort(Direction.ASC, "id");
  127. // 分页信息
  128. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  129. // 设置查询条件
  130. Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
  131. if (type == 1) {
  132. // 查询大医院
  133. filters.put("level", new SearchFilter("level", Operator.EQ, 1));
  134. } else if (type == 2) {
  135. // 查询社区医院
  136. filters.put("level", new SearchFilter("level", Operator.EQ, 2));
  137. }
  138. if (StringUtils.isNotEmpty(province)) {
  139. filters.put("province", new SearchFilter("province", Operator.EQ, province));
  140. }
  141. if (StringUtils.isNotEmpty(city)) {
  142. filters.put("city", new SearchFilter("city", Operator.EQ, city));
  143. }
  144. if (StringUtils.isNotEmpty(town)) {
  145. filters.put("town", new SearchFilter("town", Operator.EQ, town));
  146. }
  147. if (StringUtils.isNotEmpty(key)) {
  148. filters.put("name", new SearchFilter("name", Operator.LIKE, key));
  149. }
  150. if (id > 0) {
  151. filters.put("id", new SearchFilter("id", Operator.GT, id));
  152. }
  153. // 未作废
  154. filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
  155. Specification<Hospital> spec = DynamicSpecifications.bySearchFilter(filters.values(), Hospital.class);
  156. return hospitalDao.findAll(spec, pageRequest);
  157. }
  158. /**
  159. * 查询医院下的医生
  160. *
  161. * @param hospital
  162. * @param level 医生类型:1专科医生,2全科医生,3健康管理师
  163. * @return
  164. */
  165. public Page<Doctor> findDoctors(String hospital, int level, long id, int pagesize) {
  166. if (pagesize <= 0) {
  167. pagesize = 10;
  168. }
  169. // 排序
  170. Sort sort = new Sort(Direction.ASC, "id");
  171. // 分页信息
  172. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  173. // 设置查询条件
  174. Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
  175. if (StringUtils.isNoneEmpty(hospital)) {
  176. filters.put("hospital", new SearchFilter("hospital", Operator.EQ, hospital));
  177. }
  178. if (id > 0) {
  179. filters.put("id", new SearchFilter("id", Operator.GT, id));
  180. }
  181. // 医生类型过滤
  182. if (level > 0) {
  183. filters.put("level", new SearchFilter("level", Operator.EQ, level));
  184. }
  185. // 未作废
  186. filters.put("status", new SearchFilter("status", Operator.EQ, 1));
  187. Specification<Doctor> spec = DynamicSpecifications.bySearchFilter(filters.values(), Doctor.class);
  188. return doctorDao.findAll(spec, pageRequest);
  189. }
  190. /**
  191. * 查询医生主页信息
  192. *
  193. * @param doctor 医生标识
  194. * @param patient 患者标识
  195. * @return
  196. */
  197. public JSONObject findDoctorMainPage(String patient, String doctor) {
  198. JSONObject json = new JSONObject();
  199. // 查询医生基本信息
  200. Doctor d = doctorDao.findByCode(doctor);
  201. json.put("doctor", d.getCode());
  202. json.put("name", d.getName());
  203. json.put("photo", d.getPhoto());
  204. json.put("sex", d.getSex());
  205. json.put("job", d.getJob());
  206. json.put("jobName", d.getJobName());
  207. json.put("hospital", d.getHosptialName());
  208. json.put("dept", d.getDeptName());
  209. json.put("intro", d.getIntroduce());
  210. json.put("expertise", d.getExpertise());
  211. // 查询与当前医生的签约状态
  212. SignFamily sf = signFamilyDao.findByDoctorPatient(doctor, patient);
  213. if (sf == null) {
  214. // 没有签约信息
  215. json.put("sign", -1);
  216. } else {
  217. // 有签约信息
  218. json.put("sign", sf.getStatus());
  219. }
  220. //设置查看病人所在分组
  221. List<DoctorPatientGroupInfo> dctorPatientGroupInfo = doctorPatientGroupInfoDao.findByMorenPatient(patient);
  222. if (dctorPatientGroupInfo != null && dctorPatientGroupInfo.size() > 0) {
  223. json.put("group", dctorPatientGroupInfo.get(0).getGroup());
  224. } else {
  225. json.put("group", "0");
  226. }
  227. // 查询医生服务
  228. List<DoctorService> list = doctorServiceDao.findByDoctor(doctor);
  229. JSONArray services = new JSONArray();
  230. for (DoctorService ds : list) {
  231. if (ds == null) {
  232. continue;
  233. }
  234. JSONObject service = new JSONObject();
  235. service.put("logo", ds.getLogo());
  236. service.put("title", ds.getTitle());
  237. service.put("content", ds.getContent());
  238. service.put("url", ds.getUrl());
  239. services.put(service);
  240. }
  241. json.put("services", services);
  242. return json;
  243. }
  244. /**
  245. * 查询患者与医生的签约信息
  246. *
  247. * @param patient
  248. * @param doctor
  249. * @return
  250. */
  251. public int findSignStatus(String patient, String doctor) {
  252. // 查询与当前医生的签约状态
  253. SignFamily sf = signFamilyDao.findByDoctorPatient(doctor, patient);
  254. if (sf == null) {
  255. // 没有签约信息
  256. return -1;
  257. } else {
  258. // 有签约信息
  259. return sf.getStatus();
  260. }
  261. }
  262. /**
  263. * 校验签约状态
  264. *
  265. * @return
  266. * @throws Exception
  267. */
  268. public JSONObject checkSign(Patient patient) throws Exception {
  269. JSONObject json = new JSONObject();
  270. // 查询是否已存在家庭签约
  271. SignFamily sf = signFamilyDao.findByIdcard(patient.getIdcard());
  272. if (sf != null) {
  273. // 已签约
  274. json.put("sign", 1);
  275. } else {
  276. // 未签约
  277. json.put("sign", 0);
  278. }
  279. return json;
  280. }
  281. /**
  282. * 校验当前openid是否签约家庭医生
  283. *
  284. * @return
  285. */
  286. public String checkPatient(String patient) {
  287. SignFamily sf = signFamilyDao.findByjiatingPatientStatus0(patient);
  288. if (sf != null) {
  289. return sf.getDoctor();
  290. }
  291. return null;
  292. }
  293. /**
  294. * 查询是否存在签约状态
  295. *
  296. * @param idcard
  297. * @return
  298. */
  299. public int hasSingStatus(String idcard) {
  300. return signFamilyDao.hasSingStatus(idcard);
  301. }
  302. /**
  303. * 发起签约申请
  304. *
  305. * @param province 省代码
  306. * @param provinceName 省名称
  307. * @param city 城市代码
  308. * @param cityName 城市名称
  309. * @param town 区县代码
  310. * @param townName 区县名称
  311. * @param address 详细地址
  312. * @param name 患者姓名
  313. * @param doctor 医生标识
  314. * @param openid 微信openid
  315. * @param patient 患者标识
  316. * @param idcard 患者身份证号
  317. * @param ssc 患者社保卡号
  318. * @param mobile 患者手机号
  319. * @param emerMobile 患者紧急联系人
  320. * @return
  321. */
  322. public JSONObject sign(String province,
  323. String provinceName,
  324. String city,
  325. String cityName,
  326. String town,
  327. String townName,
  328. String address,
  329. String name,
  330. String doctor,
  331. String openid,
  332. String patient,
  333. String idcard,
  334. String ssc,
  335. String mobile,
  336. String emerMobile) {
  337. // 查询三师签约
  338. JSONObject json = new JSONObject();
  339. SignFamily sc = signFamilyDao.findByIdcard(idcard);
  340. //判断身份证号是否已经注册
  341. if (sc != null) {
  342. json.put("res", "-3");
  343. return json;
  344. }
  345. Doctor d = doctorDao.findByCode(doctor);
  346. SignFamily sf = new SignFamily();
  347. sf.setCode(getCode());
  348. // 设置两网编码
  349. sf.setLwCode(sc != null ? sc.getCode() : null);
  350. sf.setCzrq(new Date());
  351. sf.setPatientApplyDate(new Date());
  352. sf.setDoctor(doctor);
  353. //设置全科医生的行政团队
  354. sf.setAdminTeamCode(doctorAdminTeamDao.findIdByLeaderCode(doctor));
  355. sf.setMobile(mobile);
  356. sf.setDoctorName(d.getName());
  357. sf.setEmerMobile(emerMobile);
  358. sf.setName(name);
  359. sf.setIdcard(idcard);
  360. sf.setOpenid(openid);
  361. sf.setPatient(patient);
  362. sf.setHospital(d.getHospital());
  363. sf.setHospitalName(d.getHosptialName());
  364. sf.setSsc(ssc);
  365. sf.setStatus(0);//0为初始状态
  366. sf.setType(2);// 设置为家庭签约
  367. sf.setSignType("1");//用户申请
  368. sf.setSignSource("2");//签约来源【1 社区签约 2 移动签约】
  369. //******************扣费接口**********************/
  370. sf.setExpensesStatus("0"); //扣费状态 【0未扣费 1已扣费 2已退费】
  371. // 判断用户表是否存在该身份证号
  372. Patient p = patientDao.findByIdcard(idcard);
  373. if (p == null) {
  374. // 插入患者基本信息
  375. IdcardInfoExtractor ie = new IdcardInfoExtractor(idcard);
  376. p = new Patient();
  377. p.setCode(getCode());
  378. p.setName(name);
  379. p.setProvince(province);
  380. p.setProvinceName(provinceName);
  381. p.setCity(city);
  382. p.setCityName(cityName);
  383. p.setTown(town);
  384. p.setTownName(townName);
  385. p.setAddress(address);
  386. p.setOpenid(openid);
  387. p.setIdcard(idcard);
  388. p.setMobile(mobile);
  389. p.setSsc(ssc);
  390. // 从身份证号中提取生日
  391. p.setBirthday(ie.getBirthday());
  392. // 从身份证号中提取性别
  393. p.setSex(ie.getGender());
  394. p.setCzrq(new Date());
  395. p.setStatus(1);
  396. // 保存新的用户信息
  397. p = patientDao.save(p);
  398. } else {
  399. if (StringUtils.isNotEmpty(patient) && !StringUtils.equals(p.getCode(), patient)) {
  400. // 身份证信息与登录信息不匹配
  401. json.put("res", -1);
  402. return json;
  403. }
  404. if (StringUtils.isNotEmpty(openid) && !StringUtils.equals(p.getOpenid(), openid)) {
  405. // 身份证信息与登录信息不匹配
  406. json.put("res", -1);
  407. return json;
  408. }
  409. if (StringUtils.isNotEmpty(idcard) && !StringUtils.equals(p.getIdcard(), idcard)) {
  410. // 身份证信息与登录信息不匹配
  411. json.put("res", -1);
  412. return json;
  413. }
  414. }
  415. // 更新签约用户信息
  416. patient = p.getCode();
  417. sf.setPatient(patient);
  418. SignFamily temp = signFamilyDao.save(sf);
  419. if (temp != null) {
  420. // 添加签约消息
  421. Message message = new Message();
  422. message.setCzrq(new Date());
  423. message.setContent("您有一条新的家庭签约申请!");
  424. message.setRead(1);//设置未读
  425. message.setReceiver(doctor);//设置接受医生的code
  426. message.setSender(patient);//设置发送的用户
  427. message.setSenderName(p.getName());
  428. message.setCode(getCode());
  429. message.setSenderPhoto(p.getPhoto());
  430. message.setTitle("家庭签约申请");
  431. message.setType(1);//家庭签约信息
  432. message.setReadonly(1);//是否只读消息
  433. message.setSignStatus("1");//新的签约
  434. message.setSex(p.getSex());
  435. message.setOver("1");//未处理
  436. messageDao.save(message);
  437. // 发送消息给医生
  438. PushMsgTask.getInstance().put(doctor, MessageType.MESSAGE_TYPE_DOCTOR_NEW_SIGN_WEB.D_SW_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_SIGN_WEB.家庭签约.name(), "您有一条新的家庭签约申请!", patient);
  439. }
  440. json.put("id", p.getId());
  441. json.put("uid", p.getCode());
  442. json.put("res", 1);
  443. return json;
  444. }
  445. /**
  446. * 取消签约申请
  447. *
  448. * @param patient 患者标识
  449. * @param doctor 医生标识
  450. * @return
  451. */
  452. public int unsign(String patient, String doctor) {
  453. //修改签约标识为无效
  454. SignFamily sf = signFamilyDao.findByDoctorPatient(doctor, patient);
  455. Message message = messageDao.findByPatient(patient, doctor);
  456. if (sf.getStatus() != 0 && sf.getStatus() != 2) {
  457. return -2;
  458. }
  459. if (sf != null) {
  460. sf.setStatus(-1);
  461. } else {
  462. return -2;
  463. }
  464. //修改信息为无效
  465. if (message != null) {
  466. message.setRead(0);
  467. message.setOver("0");
  468. }
  469. return 200;
  470. }
  471. /**
  472. * 申请解约
  473. *
  474. * @param patient 患者标识
  475. * @param doctor 医生标识
  476. * @param openid 微信openid
  477. * @param reason 解约理由
  478. * @return
  479. */
  480. public int surrender(String patient, String patientName, String userPhoto, String doctor, String doctorName, String openid, String reason, int sex) {
  481. // 更新为待解约
  482. int res = signFamilyDao.surrender(patient, doctor);
  483. SignFamily signFamily = signFamilyDao.findByjiatingPatient(patient);
  484. signFamily.setPatientApplyUnsignDate(new Date());
  485. if (res == 0) {
  486. return 0;
  487. }
  488. // 添加签约消息
  489. Message message = new Message();
  490. // 消息时间
  491. message.setCzrq(new Date());
  492. // 消息内容
  493. message.setContent("[" + patientName + "]申请解除与您的签约关系");
  494. // 未读
  495. message.setRead(1);
  496. message.setReceiverName(doctorName);
  497. // 接收人
  498. message.setReceiver(doctor);
  499. message.setCode(getCode());
  500. // 发送人
  501. message.setSender(patient);
  502. message.setSenderName(patientName);
  503. message.setSenderPhoto(userPhoto);
  504. // 标题
  505. message.setTitle("解除家庭签约申请");
  506. message.setType(1);
  507. message.setSignStatus("4");
  508. message.setReadonly(1);
  509. message.setSex(sex);
  510. message.setOver("1");
  511. // 设置解约理由
  512. message.setReason(reason);
  513. messageDao.save(message);
  514. // 发送消息给医生
  515. PushMsgTask.getInstance().put(doctor, MessageType.MESSAGE_TYPE_DOCTOR_SIGN_WEB_RELIEVE.D_SW_02.name(), MessageType.MESSAGE_TYPE_DOCTOR_SIGN_WEB_RELIEVE.家庭签约.name(), patientName + " 申请解除与您的家庭签约!", patient);
  516. return 1;
  517. }
  518. /**
  519. * 查询患者的签约消息
  520. *
  521. * @param id
  522. * @param pagesize
  523. * @return
  524. */
  525. public Page<Message> findMessageByPatient(String patient, long id, int pagesize) {
  526. if (pagesize <= 0) {
  527. pagesize = 10;
  528. }
  529. // 排序
  530. Sort sort = new Sort(Direction.DESC, "id");
  531. // 分页信息
  532. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  533. // 设置查询条件
  534. Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
  535. filters.put("receiver", new SearchFilter("receiver", Operator.EQ, patient));
  536. if (id > 0) {
  537. filters.put("id", new SearchFilter("id", Operator.LT, id));
  538. }
  539. Specification<Message> spec = DynamicSpecifications.bySearchFilter(filters.values(), Message.class);
  540. return messageDao.findAll(spec, pageRequest);
  541. }
  542. /**
  543. * 查询跟医生相关的家庭签约信息
  544. *
  545. * @param type 0全部,1待签约,2已签约,3待解约,4已解约
  546. * @param id
  547. * @param pagesize 分页大小
  548. * @return
  549. */
  550. public Page<SignFamily> findSignByDoctor(int type, long id, int pagesize) {
  551. if (pagesize <= 0) {
  552. pagesize = 10;
  553. }
  554. // 排序
  555. Sort sort = new Sort(Direction.DESC, "id");
  556. // 分页信息
  557. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  558. // 设置查询条件
  559. Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
  560. // 只查家庭签约(网络签约)
  561. filters.put("type", new SearchFilter("type", Operator.EQ, 2));
  562. switch (type) {
  563. case 1:
  564. // 待签约
  565. filters.put("status", new SearchFilter("status", Operator.EQ, 0));
  566. break;
  567. case 2:
  568. // 已签约
  569. filters.put("status", new SearchFilter("status", Operator.EQ, 1));
  570. break;
  571. case 3:
  572. // 待解约
  573. filters.put("status", new SearchFilter("status", Operator.EQ, 2));
  574. break;
  575. case 4:
  576. // 已解约
  577. filters.put("status", new SearchFilter("status", Operator.EQ, -3));
  578. break;
  579. }
  580. if (id > 0) {
  581. filters.put("id", new SearchFilter("id", Operator.LT, id));
  582. }
  583. Specification<SignFamily> spec = DynamicSpecifications.bySearchFilter(filters.values(), SignFamily.class);
  584. return signFamilyDao.findAll(spec, pageRequest);
  585. }
  586. /**
  587. * 代理签约
  588. *
  589. * @param name 患者姓名
  590. * @param doctor 医生标识
  591. * @param doctorName 医生姓名
  592. * @param doctorHealth 健康管理师标识
  593. * @param doctorHealthName 健康管理师姓名
  594. * @param hospital 签约医院标识
  595. * @param hospitalName 签约医院名称
  596. * @param idcard 患者身份证号
  597. * @param ssc 患者社保卡号
  598. * @param mobile 患者手机号
  599. * @param emerMobile 患者紧急联系人
  600. * @param expenses
  601. * @return
  602. * @throws Exception
  603. */
  604. synchronized public SignFamily agent(String access_token, String name,
  605. String doctor, String doctorName,
  606. String doctorHealth, String doctorHealthName,
  607. String majorDoctor,
  608. String majorDoctorName,
  609. String hospital, String hospitalName,
  610. String idcard, String ssc, String mobile,
  611. String emerMobile, String images, String disease, String expenses, String signDoctorCode,
  612. String signDoctorName, String signDoctorLevel, String customGroup) throws Exception {
  613. // 查询是否有家庭签约
  614. SignFamily sc = signFamilyDao.findByIdcard(idcard);
  615. if (sc != null) {
  616. throw new Exception("已签约了家庭医生!");
  617. }
  618. //判断是否有三师签约 并且判断全科医生一致
  619. SignFamily sssignFamily = signFamilyDao.findSSByIdcard(idcard);
  620. if (sssignFamily != null && !doctor.equals(sssignFamily.getDoctor())) {
  621. throw new Exception("全科医生不一致!");
  622. }
  623. List<SystemDict> systemDicts = systemDictDao.findByDictName("SIGN_YEAR");
  624. String signYear = systemDicts.get(0).getCode();
  625. SignFamily sf = new SignFamily();
  626. sf.setSignYear(signYear);//设置签约年度
  627. sf.setBegin(DateUtil.getNowDateShort());
  628. sf.setCode(getCode());
  629. sf.setCzrq(new Date());
  630. //设置全科医生的行政团队
  631. sf.setAdminTeamCode(doctorAdminTeamDao.findIdByLeaderCode(doctor));
  632. sf.setDoctor(doctor);
  633. sf.setDoctorName(doctorName);
  634. sf.setDoctorHealth(doctorHealth);
  635. sf.setExpensesType(expenses);
  636. sf.setFamilyCode(createSignCode(doctor, hospital));
  637. sf.setDoctorHealthName(doctorHealthName);
  638. sf.setEmerMobile(emerMobile);
  639. sf.setEnd(DateUtil.strToDateShort(DateUtil.getNextYear(DateUtil.getNowDateShort(), 1)));
  640. sf.setName(name);
  641. sf.setIdcard(idcard);
  642. sf.setMobile(mobile);
  643. sf.setHospital(hospital);
  644. sf.setHospitalName(hospitalName);
  645. String sscD = "";
  646. if (StringUtils.isNumeric(ssc.trim())) {
  647. //如果是纯数字的医保号换成D开头的
  648. sscD = socialSecurityInfoDao.findBySfzh18Max(idcard).getCardno();
  649. } else {
  650. sscD = ssc;
  651. }
  652. sf.setSsc(sscD);
  653. sf.setStatus(1);// 代理签约,直接生效
  654. sf.setImages(images);
  655. sf.setApplyDate(new Date());
  656. sf.setType(2);// 设置为家庭签约
  657. sf.setSignType("2");//手工带签
  658. sf.setSignDoctorCode(doctor);
  659. sf.setSignDoctorLevel("2");
  660. sf.setSignDoctorName(doctorName);
  661. sf.setAgentDoctorCode(signDoctorCode);
  662. sf.setAgentDoctorLevel(signDoctorLevel);
  663. sf.setAgentDoctorName(signDoctorName);
  664. sf.setSignSource("2");//签约来源【1 社区签约 2 移动签约】
  665. //******************扣费接口**********************/
  666. sf.setExpensesStatus("0"); //扣费状态 【0未扣费 1已扣费 2已退费】
  667. // 查询该患者是否已注册
  668. Patient patient = patientDao.findByIdcard(idcard);
  669. if (patient == null) {
  670. // 插入患者基本信息
  671. IdcardInfoExtractor ie = new IdcardInfoExtractor(idcard);
  672. patient = new Patient();
  673. patient.setCode(getCode());
  674. patient.setName(name);
  675. patient.setIdcard(idcard);
  676. patient.setSsc(sscD);
  677. patient.setBirthday(ie.getBirthday());
  678. patient.setSex(ie.getGender());
  679. patient.setMobile(mobile);
  680. patient.setStatus(1);
  681. patient.setDisease(0);
  682. }
  683. //病人疾病更新
  684. // if (!StringUtils.isEmpty(disease)) {
  685. // patient.setDisease(Integer.valueOf(disease));
  686. // }
  687. // 保存用户信息
  688. patientDao.save(patient);
  689. sf.setOpenid(patient.getOpenid());
  690. sf.setPatient(patient.getCode());
  691. // 改为签约生效
  692. sf.setStatus(1);
  693. // 更新签约日期
  694. sf.setBegin(DateUtil.getNowDateShort());
  695. sf.setEnd(DateUtil.strToDateShort(DateUtil.getNextYear(DateUtil.getNowDateShort(), 1)));
  696. //建立团队
  697. DoctorTeam doctorTeam = new DoctorTeam();
  698. String doctorTeamCode = getCode();
  699. doctorTeam.setCode(doctorTeamCode);
  700. doctorTeam.setCzrq(new Date());
  701. doctorTeam.setName("团队名称:" + name);
  702. doctorTeam.setSignType("2");//家庭签约
  703. doctorTeam.setDel("1");
  704. doctorTeamDao.save(doctorTeam);
  705. sf.setTeamCode(doctorTeamCode);
  706. signFamilyDao.save(sf);
  707. //添加团队成员
  708. //添加健康管理师
  709. DoctorTeamMember wlyyDoctorTeamDoctor = new DoctorTeamMember();
  710. wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
  711. wlyyDoctorTeamDoctor.setMemberCode(doctorHealth);
  712. wlyyDoctorTeamDoctor.setName(doctorHealthName);
  713. wlyyDoctorTeamDoctor.setDel("1");
  714. wlyyDoctorTeamDoctor.setType(3);
  715. wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
  716. wlyyDoctorTeamDoctor.setCode(getCode());
  717. wlyyDoctorTeamDoctor.setCzrq(new Date());
  718. doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
  719. //添加全科医生
  720. wlyyDoctorTeamDoctor = new DoctorTeamMember();
  721. wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
  722. wlyyDoctorTeamDoctor.setMemberCode(doctor);
  723. wlyyDoctorTeamDoctor.setName(doctorName);
  724. wlyyDoctorTeamDoctor.setDel("1");
  725. wlyyDoctorTeamDoctor.setType(2);
  726. wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
  727. wlyyDoctorTeamDoctor.setCode(getCode());
  728. wlyyDoctorTeamDoctor.setCzrq(new Date());
  729. doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
  730. // if (StringUtils.isNotEmpty(disease) && !disease.equals("0")) {
  731. // //如果有选择病种
  732. // //添加专科医生
  733. // wlyyDoctorTeamDoctor = new DoctorTeamMember();
  734. // wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
  735. // wlyyDoctorTeamDoctor.setMemberCode(majorDoctor);
  736. // wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
  737. // wlyyDoctorTeamDoctor.setName(majorDoctorName);
  738. // wlyyDoctorTeamDoctor.setDel("1");
  739. // wlyyDoctorTeamDoctor.setType(1);
  740. // wlyyDoctorTeamDoctor.setCode(getCode());
  741. // wlyyDoctorTeamDoctor.setCzrq(new Date());
  742. //
  743. // doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
  744. // }
  745. //添加患者和团队的关系
  746. DoctorTeamMember wlyyDoctorTeamPatient = new DoctorTeamMember();
  747. wlyyDoctorTeamPatient.setTeam(doctorTeamCode);
  748. wlyyDoctorTeamPatient.setMemberCode(patient.getCode());
  749. wlyyDoctorTeamPatient.setName(patient.getName());
  750. wlyyDoctorTeamPatient.setDel("1");
  751. wlyyDoctorTeamPatient.setSignType("2");//家庭签约
  752. wlyyDoctorTeamPatient.setType(5);
  753. wlyyDoctorTeamPatient.setCode(getCode());
  754. wlyyDoctorTeamPatient.setCzrq(new Date());
  755. doctorTeamDoctor.save(wlyyDoctorTeamPatient);
  756. //病人分组类别
  757. String groupCode = "1";
  758. //判断病人分组
  759. if (!StringUtils.isEmpty(disease)) {
  760. List<String> diseases = Arrays.asList(disease.split(","));
  761. if (diseases.contains("1") || diseases.contains("2")) {
  762. groupCode = "2";
  763. }
  764. } else {
  765. String birth = patient.getIdcard().substring(6, 14);
  766. int year = Integer.valueOf(birth.substring(0, 4));
  767. int month = Integer.valueOf(birth.substring(4, 6));
  768. int day = Integer.valueOf(birth.substring(6));
  769. Calendar cal = Calendar.getInstance();
  770. int age = cal.get(Calendar.YEAR) - year;
  771. //周岁计算
  772. if (cal.get(Calendar.MONTH) > (month - 1) || (cal.get(Calendar.MONTH) == (month - 1) && cal.get(Calendar.DATE) > day)) {
  773. age--;
  774. }
  775. if (age >= 65) {
  776. groupCode = "3";
  777. }
  778. }
  779. //把病人添加到健康管理师的健康分组里
  780. DoctorPatientGroupInfo doctorPatientGroupInfo = new DoctorPatientGroupInfo();
  781. doctorPatientGroupInfo.setCzrq(new Date());
  782. doctorPatientGroupInfo.setDoctor(doctorHealth);
  783. doctorPatientGroupInfo.setStatus(1);
  784. doctorPatientGroupInfo.setPatient(patient.getCode());
  785. doctorPatientGroupInfo.setPname(patient.getName());
  786. doctorPatientGroupInfo.setPartAmount(0);
  787. doctorPatientGroupInfo.setGroup(groupCode);//默认健康分组
  788. doctorPatientGroupInfo.setQyrq(new Date());
  789. doctorPatientGroupInfo.setSignType("2");//家庭签约
  790. doctorPatientGroupInfoDao.save(doctorPatientGroupInfo);
  791. //把病人添加到全科医生的健康分组里
  792. doctorPatientGroupInfo = new DoctorPatientGroupInfo();
  793. doctorPatientGroupInfo.setCzrq(new Date());
  794. doctorPatientGroupInfo.setDoctor(doctor);
  795. doctorPatientGroupInfo.setStatus(1);
  796. doctorPatientGroupInfo.setPatient(patient.getCode());
  797. doctorPatientGroupInfo.setPname(patient.getName());
  798. doctorPatientGroupInfo.setPartAmount(0);
  799. doctorPatientGroupInfo.setGroup(groupCode);//默认健康分组
  800. doctorPatientGroupInfo.setQyrq(new Date());
  801. doctorPatientGroupInfo.setSignType("2");//家庭签约
  802. doctorPatientGroupInfoDao.save(doctorPatientGroupInfo);
  803. if (!StringUtils.isEmpty(customGroup) && !customGroup.equals("0")) {
  804. DoctorPatientGroupInfo customDoctorGroup = new DoctorPatientGroupInfo();
  805. customDoctorGroup.setCzrq(new Date());
  806. customDoctorGroup.setDoctor(signDoctorCode);
  807. customDoctorGroup.setStatus(1);
  808. customDoctorGroup.setPatient(patient.getCode());
  809. customDoctorGroup.setPname(patient.getName());
  810. customDoctorGroup.setPartAmount(0);
  811. customDoctorGroup.setGroup(customGroup);
  812. customDoctorGroup.setQyrq(new Date());
  813. customDoctorGroup.setSignType("2");//家庭签约
  814. doctorPatientGroupInfoDao.save(customDoctorGroup);
  815. SignFamily signFamily = signFamilyDao.findSsSignByDoctorPatient(sf.getDoctor(), sf.getPatient());
  816. if (signFamily != null) {
  817. DoctorPatientGroupInfo ssDoctorGroup = new DoctorPatientGroupInfo();
  818. ssDoctorGroup.setCzrq(new Date());
  819. ssDoctorGroup.setDoctor(signDoctorCode);
  820. ssDoctorGroup.setStatus(1);
  821. ssDoctorGroup.setPatient(patient.getCode());
  822. ssDoctorGroup.setPname(patient.getName());
  823. ssDoctorGroup.setPartAmount(0);
  824. ssDoctorGroup.setGroup(customGroup);
  825. ssDoctorGroup.setQyrq(new Date());
  826. ssDoctorGroup.setSignType("1");//三师签约
  827. doctorPatientGroupInfoDao.save(ssDoctorGroup);
  828. }
  829. }
  830. List<DoctorPatientGroupInfo> groups = doctorPatientGroupInfoDao.findPatientGroups(patient.getCode());
  831. if (groups != null && groups.size() > 0) {
  832. for (DoctorPatientGroupInfo group : groups) {
  833. if (StringUtils.isNotEmpty(group.getSignType()) && group.getSignType().equals("2")) {
  834. continue;
  835. }
  836. if (group.getGroup().equals(customGroup)) {
  837. continue;
  838. }
  839. DoctorPatientGroupInfo patientGroup = new DoctorPatientGroupInfo();
  840. patientGroup.setCzrq(new Date());
  841. patientGroup.setDoctor(group.getDoctor());
  842. patientGroup.setStatus(1);
  843. patientGroup.setPatient(patient.getCode());
  844. patientGroup.setPname(patient.getName());
  845. patientGroup.setPartAmount(0);
  846. patientGroup.setGroup(group.getGroup());
  847. patientGroup.setQyrq(new Date());
  848. patientGroup.setSignType("2");//家庭签约
  849. doctorPatientGroupInfoDao.save(patientGroup);
  850. }
  851. }
  852. if (!StringUtils.isEmpty(disease) && !disease.equals("0")) {
  853. boolean flag = patientDiseaseService.updatePatientDisease(sf.getPatient(), disease);
  854. if (!flag) {
  855. throw new Exception("疾病更新失败");
  856. }
  857. }
  858. SignFamily temp = signFamilyDao.save(sf);
  859. if (temp != null && patient != null) {
  860. Doctor doc = doctorDao.findByCode(sf.getDoctor());
  861. Hospital hos = hospitalDao.findByCode(doc.getHospital());
  862. String content = "祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
  863. "为了给您提供更好的服务,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
  864. (hos != null ? hos.getAddress() : "") + ")缴费。";
  865. JSONObject json = new JSONObject();
  866. json.put("first", "签约成功通知");
  867. json.put("doctor", sf.getDoctor());
  868. json.put("doctorName", sf.getDoctorName());
  869. json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
  870. json.put("content", content);
  871. json.put("remark", ""); //您好,您成功签约家庭医生
  872. // 添加到发送队列
  873. PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
  874. }
  875. return temp;
  876. }
  877. /**
  878. * 处理签约申请
  879. *
  880. * @param healthDoctor 健康管理师标识
  881. * @param healthDoctorName 健康管理师姓名
  882. * @param msgid 消息id
  883. * @param patientCard 患者身份证
  884. * @param type 处理类型:1同意,2拒绝
  885. * @return
  886. */
  887. public int handleSign(String signType,
  888. String access_token,
  889. String healthDoctor,
  890. String healthDoctorName,
  891. long msgid,
  892. String patientCard, int type, String disease, String majorDoctor, String majorhDoctorName, String customGroup, String expenses) throws Exception {
  893. if (type != 1 && type != 2) {
  894. return -1;
  895. }
  896. // 查询患者信息
  897. Patient p = patientDao.findByIdcard(patientCard);
  898. // 更新消息状态为已处理
  899. if (msgid > 0) {
  900. Message message = messageDao.findOne(msgid);
  901. message.setRead(0);//设置已读
  902. message.setOver("0");//设置消息操作结束
  903. message.setCzrq(new Date());
  904. }
  905. // 判断患者有没有家庭签约
  906. SignFamily sf = signFamilyDao.findByPatientStatus(patientCard, 0);
  907. if (sf == null) {
  908. return 0;
  909. }
  910. if (type == 1) {
  911. List<SystemDict> systemDicts = systemDictDao.findByDictName("SIGN_YEAR");
  912. String year = systemDicts.get(0).getCode();
  913. //病人疾病更新
  914. // if (!StringUtils.isEmpty(disease)) {
  915. // p.setDisease(Integer.valueOf(disease));
  916. // }
  917. //签约类型:1三师签约,2家庭签约
  918. // 改为签约生效
  919. sf.setStatus(1);
  920. // 更新签约日期
  921. sf.setBegin(DateUtil.getNowDateShort());
  922. sf.setSignType("1");//患者发起签约
  923. sf.setExpensesType(expenses);//收费类别
  924. sf.setEnd(DateUtil.strToDateShort(DateUtil.getNextYear(DateUtil.getNowDateShort(), 1)));
  925. //设置签约人 患者发起的签约 默认签约人是全科医生
  926. sf.setSignDoctorCode(sf.getDoctor());
  927. sf.setSignDoctorName(sf.getDoctorName());
  928. sf.setSignDoctorLevel("2");
  929. // 更新健康管理师
  930. sf.setDoctorHealth(healthDoctor);
  931. sf.setDoctorHealthName(healthDoctorName);
  932. sf.setCzrq(new Date());
  933. sf.setSignYear(year);//设置签约年度
  934. sf.setApplyDate(new Date());
  935. Doctor doctor = doctorDao.findByCode(sf.getDoctor());
  936. sf.setFamilyCode(createSignCode(sf.getDoctor(), doctor.getHospital()));
  937. //建立团队
  938. DoctorTeam doctorTeam = new DoctorTeam();
  939. String doctorTeamCode = getCode();
  940. doctorTeam.setName("三师签约团队患者:" + p.getName());
  941. doctorTeam.setCode(doctorTeamCode);
  942. doctorTeam.setCzrq(new Date());
  943. doctorTeam.setSignType("2");
  944. doctorTeam.setDel("1");
  945. doctorTeamDao.save(doctorTeam);
  946. sf.setTeamCode(doctorTeamCode);
  947. //添加团队成员
  948. //添加健康管理师
  949. DoctorTeamMember wlyyDoctorTeamDoctor = new DoctorTeamMember();
  950. wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
  951. wlyyDoctorTeamDoctor.setMemberCode(healthDoctor);
  952. wlyyDoctorTeamDoctor.setName(healthDoctorName);
  953. wlyyDoctorTeamDoctor.setDel("1");
  954. wlyyDoctorTeamDoctor.setSignType("2");
  955. wlyyDoctorTeamDoctor.setType(3);
  956. wlyyDoctorTeamDoctor.setCode(getCode());
  957. wlyyDoctorTeamDoctor.setCzrq(new Date());
  958. doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
  959. //添加全科医生
  960. wlyyDoctorTeamDoctor = new DoctorTeamMember();
  961. wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
  962. wlyyDoctorTeamDoctor.setMemberCode(sf.getDoctor());
  963. wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
  964. wlyyDoctorTeamDoctor.setName(sf.getDoctorName());
  965. wlyyDoctorTeamDoctor.setDel("1");
  966. wlyyDoctorTeamDoctor.setType(2);
  967. wlyyDoctorTeamDoctor.setCode(getCode());
  968. wlyyDoctorTeamDoctor.setCzrq(new Date());
  969. doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
  970. //添加患者和团队的关系
  971. DoctorTeamMember wlyyDoctorTeamPatient = new DoctorTeamMember();
  972. wlyyDoctorTeamPatient.setTeam(doctorTeamCode);
  973. wlyyDoctorTeamPatient.setMemberCode(sf.getPatient());
  974. wlyyDoctorTeamPatient.setName(p.getName());
  975. wlyyDoctorTeamPatient.setDel("1");
  976. wlyyDoctorTeamPatient.setSignType("2");//家庭签约
  977. wlyyDoctorTeamPatient.setType(5);//患者
  978. wlyyDoctorTeamPatient.setCode(getCode());
  979. wlyyDoctorTeamPatient.setCzrq(new Date());
  980. doctorTeamDoctor.save(wlyyDoctorTeamPatient);
  981. // if (StringUtils.isNotEmpty(disease) && !disease.equals("0")) {
  982. // //如果有选择病种
  983. // //添加专科医生
  984. // wlyyDoctorTeamDoctor = new DoctorTeamMember();
  985. // wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
  986. // wlyyDoctorTeamDoctor.setMemberCode(majorDoctor);
  987. // wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
  988. // wlyyDoctorTeamDoctor.setName(majorhDoctorName);
  989. // wlyyDoctorTeamDoctor.setDel("1");
  990. // wlyyDoctorTeamDoctor.setType(1);
  991. // wlyyDoctorTeamDoctor.setCode(getCode());
  992. // wlyyDoctorTeamDoctor.setCzrq(new Date());
  993. // doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
  994. // }
  995. } else {
  996. // 医生拒绝
  997. sf.setStatus(-2);
  998. // 拒绝签约
  999. JSONObject json = new JSONObject();
  1000. json.put("first", "签约失败通知");
  1001. json.put("doctor", sf.getDoctor());
  1002. json.put("doctorName", sf.getDoctorName());
  1003. json.put("date", DateUtil.dateToStrShort(new Date()));
  1004. json.put("content", "您与 " + sf.getDoctorName() + " 医生建立家庭医生签约关系失败,请查看!");
  1005. json.put("remark", "您好,签约家庭医生失败通知");
  1006. // 添加到发送队列
  1007. PushMsgTask.getInstance().putWxMsg(access_token, 2, sf.getOpenid(), sf.getName(), json);
  1008. return 2;
  1009. }
  1010. //病人分组类别
  1011. String groupCode = "1";
  1012. //判断病人分组
  1013. if (!StringUtils.isEmpty(disease)) {
  1014. List<String> diseases = Arrays.asList(disease.split(","));
  1015. if (diseases.contains("1") || diseases.contains("2")) {
  1016. groupCode = "2";
  1017. }
  1018. } else {
  1019. String birth = p.getIdcard().substring(6, 14);
  1020. int year = Integer.valueOf(birth.substring(0, 4));
  1021. int month = Integer.valueOf(birth.substring(4, 6));
  1022. int day = Integer.valueOf(birth.substring(6));
  1023. Calendar cal = Calendar.getInstance();
  1024. int age = cal.get(Calendar.YEAR) - year;
  1025. //周岁计算
  1026. if (cal.get(Calendar.MONTH) > (month - 1) || (cal.get(Calendar.MONTH) == (month - 1) && cal.get(Calendar.DATE) > day)) {
  1027. age--;
  1028. }
  1029. if (age >= 65) {
  1030. groupCode = "3";
  1031. }
  1032. }
  1033. //设置签约人到全科管理师和健康管理师的健康人群分组里
  1034. //给病人分组
  1035. //把病人添加到健康管理师的健康分组里
  1036. DoctorPatientGroupInfo doctorPatientGroupInfo = new DoctorPatientGroupInfo();
  1037. doctorPatientGroupInfo.setCzrq(new Date());
  1038. doctorPatientGroupInfo.setDoctor(healthDoctor);
  1039. doctorPatientGroupInfo.setStatus(1);
  1040. doctorPatientGroupInfo.setPatient(p.getCode());
  1041. doctorPatientGroupInfo.setPname(p.getName());
  1042. doctorPatientGroupInfo.setPartAmount(0);
  1043. doctorPatientGroupInfo.setGroup(groupCode);//默认健康分组
  1044. doctorPatientGroupInfo.setQyrq(new Date());
  1045. doctorPatientGroupInfo.setSignType("2");//家庭签约
  1046. doctorPatientGroupInfoDao.save(doctorPatientGroupInfo);
  1047. //把病人添加到全科医生的健康分组里
  1048. doctorPatientGroupInfo = new DoctorPatientGroupInfo();
  1049. doctorPatientGroupInfo.setCzrq(new Date());
  1050. doctorPatientGroupInfo.setDoctor(sf.getDoctor());
  1051. doctorPatientGroupInfo.setStatus(1);
  1052. doctorPatientGroupInfo.setPatient(p.getCode());
  1053. doctorPatientGroupInfo.setPname(p.getName());
  1054. doctorPatientGroupInfo.setPartAmount(0);
  1055. doctorPatientGroupInfo.setGroup(groupCode);//默认健康分组
  1056. doctorPatientGroupInfo.setQyrq(new Date());
  1057. doctorPatientGroupInfo.setSignType("2");//家庭签约
  1058. doctorPatientGroupInfoDao.save(doctorPatientGroupInfo);
  1059. if (!StringUtils.isEmpty(customGroup) && !customGroup.equals("0")) {
  1060. DoctorPatientGroupInfo customDoctorGroup = new DoctorPatientGroupInfo();
  1061. customDoctorGroup.setCzrq(new Date());
  1062. customDoctorGroup.setDoctor(sf.getDoctor());
  1063. customDoctorGroup.setStatus(1);
  1064. customDoctorGroup.setPatient(p.getCode());
  1065. customDoctorGroup.setPname(p.getName());
  1066. customDoctorGroup.setPartAmount(0);
  1067. customDoctorGroup.setGroup(customGroup);
  1068. customDoctorGroup.setQyrq(new Date());
  1069. customDoctorGroup.setSignType("2");//家庭签约
  1070. doctorPatientGroupInfoDao.save(customDoctorGroup);
  1071. SignFamily signFamily = signFamilyDao.findSsSignByDoctorPatient(sf.getDoctor(), sf.getPatient());
  1072. if (signFamily != null) {
  1073. DoctorPatientGroupInfo ssDoctorGroup = new DoctorPatientGroupInfo();
  1074. ssDoctorGroup.setCzrq(new Date());
  1075. ssDoctorGroup.setDoctor(sf.getDoctor());
  1076. ssDoctorGroup.setStatus(1);
  1077. ssDoctorGroup.setPatient(p.getCode());
  1078. ssDoctorGroup.setPname(p.getName());
  1079. ssDoctorGroup.setPartAmount(0);
  1080. ssDoctorGroup.setGroup(customGroup);
  1081. ssDoctorGroup.setQyrq(new Date());
  1082. ssDoctorGroup.setSignType("1");//三师签约
  1083. doctorPatientGroupInfoDao.save(ssDoctorGroup);
  1084. }
  1085. }
  1086. List<DoctorPatientGroupInfo> groups = doctorPatientGroupInfoDao.findPatientGroups(p.getCode());
  1087. if (groups != null && groups.size() > 0) {
  1088. for (DoctorPatientGroupInfo group : groups) {
  1089. if (StringUtils.isNotEmpty(group.getSignType()) && group.getSignType().equals("2")) {
  1090. continue;
  1091. }
  1092. if (group.getGroup().equals(customGroup)) {
  1093. continue;
  1094. }
  1095. DoctorPatientGroupInfo patientGroup = new DoctorPatientGroupInfo();
  1096. patientGroup.setCzrq(new Date());
  1097. patientGroup.setDoctor(group.getDoctor());
  1098. patientGroup.setStatus(1);
  1099. patientGroup.setPatient(p.getCode());
  1100. patientGroup.setPname(p.getName());
  1101. patientGroup.setPartAmount(0);
  1102. patientGroup.setGroup(group.getGroup());
  1103. patientGroup.setQyrq(new Date());
  1104. patientGroup.setSignType("2");//家庭签约
  1105. doctorPatientGroupInfoDao.save(patientGroup);
  1106. }
  1107. }
  1108. if (!StringUtils.isEmpty(disease) && !disease.equals("0")) {
  1109. boolean flag = patientDiseaseService.updatePatientDisease(sf.getPatient(), disease);
  1110. if (!flag) {
  1111. throw new Exception("疾病更新失败");
  1112. }
  1113. }
  1114. // 推送消息消息给微信端
  1115. if (type == 1) {
  1116. Doctor doc = doctorDao.findByCode(sf.getDoctor());
  1117. Hospital hos = hospitalDao.findByCode(doc.getHospital());
  1118. String content = "祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
  1119. "为了给您提供更好的服务,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
  1120. (hos != null ? hos.getAddress() : "") + ")缴费。";
  1121. // 同意签约
  1122. JSONObject json = new JSONObject();
  1123. json.put("first", "签约成功通知");
  1124. json.put("doctor", sf.getDoctor());
  1125. json.put("doctorName", sf.getDoctorName());
  1126. json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
  1127. json.put("content", content);
  1128. json.put("remark", ""); //您好,您成功签约家庭医生
  1129. // 添加到发送队列
  1130. PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
  1131. } else if (type == 2) {
  1132. System.out.println(" ---------- fail send weixin-------------");
  1133. // 拒绝签约
  1134. JSONObject json = new JSONObject();
  1135. json.put("first", "签约失败通知");
  1136. json.put("doctor", sf.getDoctor());
  1137. json.put("doctorName", sf.getDoctorName());
  1138. json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
  1139. json.put("content", "您与 " + sf.getDoctorName() + " 医生建立家庭医生签约关系失败,请查看!");
  1140. json.put("remark", "您好,签约家庭医生失败通知");
  1141. // 添加到发送队列
  1142. PushMsgTask.getInstance().putWxMsg(access_token, 2, sf.getOpenid(), sf.getName(), json);
  1143. }
  1144. return 1;
  1145. }
  1146. /**
  1147. * 处理解约申请
  1148. *
  1149. * @param patient 患者标识
  1150. * @param type 处理类型:1同意,2拒绝
  1151. * @param reason 解约原因
  1152. * @return
  1153. */
  1154. public int handleSurrender(String access_token, long msgid, String patient, int type, String reason) throws Exception {
  1155. if (type != 1 && type != 2) {
  1156. return -1;
  1157. }
  1158. SignFamily sf = signFamilyDao.findByPatientCodeStatus(patient, 2);
  1159. if (sf == null) {
  1160. return 0;
  1161. }
  1162. // 更新消息状态为已处理
  1163. if (msgid > 0) {
  1164. Message message = messageDao.findOne(msgid);
  1165. message.setRead(0);
  1166. message.setOver("0");
  1167. }
  1168. if (type == 1) {
  1169. // 设置家庭签约疾病无效
  1170. if (!patientDiseaseService.updatePatientDisease(patient, "")) {
  1171. throw new Exception("patient's disease update failed");
  1172. }
  1173. // 将签约状态改为已解约
  1174. sf.setReason(reason);
  1175. sf.setStatus(-3);
  1176. sf.setApplyUnsignDate(new Date());
  1177. //signFamilyDao.handleSurrender(reason, patient);
  1178. //设置患者所在团队失效
  1179. doctorTeamDao.deleteTeam(sf.getTeamCode());
  1180. //设置团队成员失效
  1181. doctorTeamDoctor.deleteMember(sf.getTeamCode());
  1182. //把患者移除健康管理师和全科医生的晃患者管理
  1183. doctorPatientGroupInfoDao.deleteByPatient(patient);
  1184. //结束患者家庭签约咨询
  1185. consultTeamDao.updateStatusByPatient(patient);
  1186. // 推送消息消息给微信端
  1187. JSONObject json = new JSONObject();
  1188. json.put("first", "解约申请通知");
  1189. json.put("date", DateUtil.getStringDateShort());
  1190. json.put("doctor", sf.getDoctor());
  1191. json.put("doctorName", sf.getDoctorName());
  1192. json.put("orgName", sf.getHospitalName());
  1193. json.put("remark", "您好,您的签约医生已同意您的解约申请,解约已生效。");
  1194. // 添加到发送队列
  1195. PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
  1196. } else {
  1197. // 更新状态为正常
  1198. signFamilyDao.refuseSurrender(patient);
  1199. // 拒绝解约,推送消息消息给微信端
  1200. JSONObject json = new JSONObject();
  1201. json.put("first", "解约申请通知");
  1202. json.put("date", DateUtil.getStringDateShort());
  1203. json.put("doctor", sf.getDoctor());
  1204. json.put("doctorName", sf.getDoctorName());
  1205. json.put("orgName", sf.getHospitalName());
  1206. json.put("remark", "您好,您的签约医生拒绝您的解约申请,解约失败。");
  1207. // 添加到发送队列
  1208. PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
  1209. }
  1210. return 1;
  1211. }
  1212. /**
  1213. * 查询医生的签约消息
  1214. *
  1215. * @param doctor 医生标识
  1216. * @param id
  1217. * @param pagesize 分页大小
  1218. * @return
  1219. */
  1220. public Page<Message> findMessageByDoctor(String doctor, long id, int pagesize) {
  1221. if (pagesize <= 0) {
  1222. pagesize = 10;
  1223. }
  1224. // 排序
  1225. Sort sort = new Sort(Direction.DESC, "id");
  1226. // 分页信息
  1227. PageRequest pageRequest = new PageRequest(0, pagesize, sort);
  1228. // 设置查询条件
  1229. Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
  1230. filters.put("receiver", new SearchFilter("receiver", Operator.EQ, doctor));
  1231. if (id > 0) {
  1232. filters.put("id", new SearchFilter("id", Operator.LT, id));
  1233. }
  1234. // 只查询未处理的消息
  1235. filters.put("type", new SearchFilter("type", Operator.EQ, 1));
  1236. filters.put("over", new SearchFilter("over", Operator.EQ, 1));
  1237. filters.put("read", new SearchFilter("read", Operator.EQ, 1));
  1238. Specification<Message> spec = DynamicSpecifications.bySearchFilter(filters.values(), Message.class);
  1239. return messageDao.findAll(spec, pageRequest);
  1240. }
  1241. /**
  1242. * 查询已签约总数
  1243. *
  1244. * @param doctor
  1245. * @return
  1246. */
  1247. public int countAmountSigned(String doctor) {
  1248. return signFamilyDao.countAmountSignedByDoctor(doctor);
  1249. }
  1250. /**
  1251. * 查询待签约总数
  1252. *
  1253. * @param doctor
  1254. * @return
  1255. */
  1256. public int countAmountUnsign(String doctor) {
  1257. return signFamilyDao.countAmountUnsignByDoctor(doctor);
  1258. }
  1259. public List<?> amountPatients(String uid) {
  1260. return null;
  1261. }
  1262. public SignFamily getFamilyContractByIdcard(String idCard) {
  1263. return signFamilyDao.findByIdcard(idCard);
  1264. }
  1265. public SignFamily getFamilyContractByMobile(String mobile) {
  1266. return signFamilyDao.findByMobile(mobile);
  1267. }
  1268. /**
  1269. * 生成签约标识
  1270. *
  1271. * @param doctor 医生标识
  1272. * @return
  1273. */
  1274. private String createSignCode(String doctor, String hospital) {
  1275. // 获取当前年份
  1276. String year = DateUtil.getStringDate(DateUtil.YY);
  1277. Hospital hospital1 = hospitalDao.findByCode(hospital);
  1278. Integer amount = 0;
  1279. SignFamilyCode wlyySignFamilyCode = wlyySignFamilyCodeDao.findByOrgCodeAndYear(hospital, year);
  1280. if (wlyySignFamilyCode != null) {
  1281. amount = wlyySignFamilyCode.getSequence() + 1;
  1282. wlyySignFamilyCode.setSequence(amount);
  1283. wlyySignFamilyCode.setModifyTime(new Date());
  1284. } else {
  1285. //创建序列
  1286. amount = 1;
  1287. SignFamilyCode wlyySignFamilyCodeTemp = new SignFamilyCode();
  1288. wlyySignFamilyCodeTemp.setModifyTime(new Date());
  1289. wlyySignFamilyCodeTemp.setOrgCode(hospital1.getCode());
  1290. wlyySignFamilyCodeTemp.setOrgName(hospital1.getName());
  1291. wlyySignFamilyCodeTemp.setYear(year);
  1292. wlyySignFamilyCodeTemp.setSequence(1);
  1293. wlyySignFamilyCodeDao.save(wlyySignFamilyCodeTemp);
  1294. }
  1295. return year + hospital1.getRoadCode() + hospital1.getCenterSite() + "Y" + StringUtils.leftPad(String.valueOf(amount + 1), 5, "0");
  1296. }
  1297. public int countAmountSigned2(String uid) {
  1298. return signFamilyDao.countAmountSignedByHeather(uid);
  1299. }
  1300. public SignFamily findBySanshiPatient(String code) {
  1301. return signFamilyDao.findSanshiSignByPatient(code);
  1302. }
  1303. public SignFamily findByFamilySignPatient(String code) {
  1304. return signFamilyDao.findFamilySignByPatient(code);
  1305. }
  1306. public SignFamily findByJiatingPatient(String code) {
  1307. return signFamilyDao.findByjiatingPatientYes(code);
  1308. }
  1309. /**
  1310. * 查询患者已签约信息
  1311. *
  1312. * @param code
  1313. * @return
  1314. */
  1315. public SignFamily findBySsPatient(String code) {
  1316. return signFamilyDao.findBySsPatient(code);
  1317. }
  1318. public List<Map<String, Object>> getDoctorsByhospitalNoPage(String hospital, String name, Integer type) {
  1319. String sql = "select * from wlyy_doctor where 1=1 and del=1 and iscertified=1 and status=1 ";
  1320. List<Object> params = new ArrayList<Object>();
  1321. if (StringUtils.isNoneEmpty(hospital)) {
  1322. sql += " and hospital =? ";
  1323. params.add(hospital);
  1324. }
  1325. if (StringUtils.isNoneEmpty(name)) {
  1326. sql += " and name like ? ";
  1327. params.add("%" + name + "%");
  1328. }
  1329. if (type != null && type > 0) {
  1330. sql += " and level =? ";
  1331. params.add(type);
  1332. }
  1333. return jdbcTemplate.queryForList(sql, params.toArray());
  1334. }
  1335. public Map<String, Object> getSanshiSignByPatientCode(String patientCode) {
  1336. Map<String, Object> map = new HashMap<>();
  1337. SignFamily signFamily = signFamilyDao.findBySanshiPatient(patientCode);
  1338. //判斷之前有没有三师签约
  1339. if (signFamily != null) {
  1340. map.put("hasSanshi", "true");
  1341. //得到团队的专科医生
  1342. DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findSanshiByTeamAndType(signFamily.getTeamCode(), 1);
  1343. map.put("zkCode", doctorTeamMember.getMemberCode());
  1344. map.put("zkName", doctorTeamMember.getName());
  1345. //得到团队的全科医生
  1346. doctorTeamMember = doctorTeamDoctor.findSanshiByTeamAndType(signFamily.getTeamCode(), 2);
  1347. map.put("qkCode", doctorTeamMember.getMemberCode());
  1348. map.put("qkName", doctorTeamMember.getName());
  1349. //得到团队的健康管理医生
  1350. doctorTeamMember = doctorTeamDoctor.findSanshiByTeamAndType(signFamily.getTeamCode(), 3);
  1351. map.put("glsCode", doctorTeamMember.getMemberCode());
  1352. map.put("glsName", doctorTeamMember.getName());
  1353. //得到之前病人得的病
  1354. Patient pa = patientDao.findByCode(patientCode);
  1355. map.put("disease", pa.getDisease());
  1356. } else {
  1357. map.put("hasSanshi", "false");
  1358. }
  1359. return map;
  1360. }
  1361. public SignFamily findByPatientYes(String id) {
  1362. return signFamilyDao.findByjiatingPatient(id);
  1363. }
  1364. public SignFamily findBySanshiPatientYes(String id) {
  1365. return signFamilyDao.findBySanshiPatientYes(id);
  1366. }
  1367. /**
  1368. * 根据身份证号查找病人的三师签约信息
  1369. *
  1370. * @param idCard
  1371. * @return
  1372. */
  1373. public JSONObject getSanshiSingInfoByPatientIdCard(String idCard) throws Exception {
  1374. JSONObject result = new JSONObject();
  1375. SignFamily sign = signFamilyDao.findByPatientSanshiSignInfo(idCard);
  1376. SignFamily signFamily = signFamilyDao.findByPatientFamilySignInfo(idCard);
  1377. Patient p = patientDao.findByIdcard(idCard);
  1378. if (p == null) {
  1379. result.put("signStatus", "0");
  1380. result.put("msg", "病人未注册");
  1381. return result;
  1382. }
  1383. if (signFamily != null) {
  1384. result.put("signStatus", "2");
  1385. result.put("msg", "病人已申请过家庭签约!");
  1386. return result;
  1387. }
  1388. if (sign != null) {
  1389. List<DoctorTeamMember> members = doctorTeamDoctor.findByTeamAndDel(sign.getTeamCode(), "1");
  1390. if (members == null) {
  1391. throw new Exception("签约团队信息有误!");
  1392. }
  1393. //三师签约医生信息
  1394. for (DoctorTeamMember member : members) {
  1395. if (member.getType() == 1) {
  1396. result.put("majorDoctor", member.getMemberCode());
  1397. result.put("majorDoctorName", member.getName());
  1398. } else if (member.getType() == 2) {
  1399. Doctor doctor = doctorDao.findByCode(member.getMemberCode());
  1400. result.put("hospital", doctor.getHospital());
  1401. result.put("doctor", member.getMemberCode());
  1402. result.put("doctorName", member.getName());
  1403. } else if (member.getType() == 3) {
  1404. result.put("healthDoctor", member.getMemberCode());
  1405. result.put("healthDoctorName", member.getName());
  1406. }
  1407. }
  1408. // 查询患者疾病
  1409. String diseases = redisTemplate.opsForValue().get("disease:" + p.getCode());
  1410. if (!StringUtils.isEmpty(diseases)) {
  1411. JSONArray array = new JSONArray(diseases);
  1412. JSONArray disArray = new JSONArray();
  1413. for (int i = 0; i < array.length(); i++) {
  1414. JSONObject json = array.getJSONObject(i);
  1415. if (json != null && json.get("signType").toString().equals("1")) {
  1416. disArray.put(json);
  1417. }
  1418. }
  1419. result.put("diseases", disArray);
  1420. } else {
  1421. result.put("diseases", "");
  1422. }
  1423. result.put("signStatus", "1");
  1424. } else {
  1425. result.put("signStatus", "3");
  1426. }
  1427. if (p != null) {
  1428. JSONObject pJson = new JSONObject(p);
  1429. result.put("patient", pJson);
  1430. }
  1431. return result;
  1432. }
  1433. public JSONArray getSignDoctorMessage(String patientCode) {
  1434. JSONArray jsonArray = new JSONArray();
  1435. //找出患者的三师签约信息
  1436. SignFamily signFamily = signFamilyDao.findSanshiSignByPatient(patientCode);
  1437. Patient patient = patientDao.findByCode(patientCode);
  1438. if (signFamily != null) {
  1439. //得到三师签约的服务团队
  1440. List<Doctor> doctors = doctorDao.findSanshiDoctorByTeam(signFamily.getTeamCode());
  1441. for (Doctor doctor : doctors) {
  1442. JSONObject jo = new JSONObject();
  1443. jo.put("code", doctor.getCode());//医生code
  1444. jo.put("sex", doctor.getSex());//医生性别 1男,2女)
  1445. jo.put("name", doctor.getName());//医生名称
  1446. jo.put("photo", doctor.getPhoto());//医生头像
  1447. jo.put("hosptialName", doctor.getHosptialName());//所属机构名称
  1448. jo.put("level", doctor.getLevel());//医生等级1专科医生,2全科医生,3健康管理师
  1449. jo.put("signType", "1");//签约类别 1是三师 2是家庭
  1450. jo.put("signStatus", signFamily.getStatus());//签约状态 0待签约,1已签约 2待解约
  1451. jo.put("jobName", doctor.getJobName());//职称
  1452. jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
  1453. if (signFamily.getStatus() == 0) {
  1454. jo.put("sqDate", DateUtil.dateToStrShort(signFamily.getPatientApplyDate()));//申请时间
  1455. } else if (signFamily.getStatus() == 1) {
  1456. jo.put("qyDate", DateUtil.dateToStrShort(signFamily.getApplyDate()));//签约时间
  1457. jo.put("endDate", DateUtil.dateToStrShort(signFamily.getEnd()));//结束时间
  1458. } else if (signFamily.getStatus() == 2) {
  1459. jo.put("qyDate", DateUtil.dateToStrShort(signFamily.getPatientApplyUnsignDate()));//申请解约时间
  1460. jo.put("endDate", DateUtil.dateToStrShort(signFamily.getEnd()));//结束时间
  1461. }
  1462. jsonArray.put(jo);
  1463. }
  1464. }
  1465. //得到家庭签约
  1466. SignFamily jtSignFamily = signFamilyDao.findFamilySignByPatient(patientCode);
  1467. if (jtSignFamily != null) {
  1468. //家庭签约只找全科医生
  1469. Doctor doctor = doctorDao.findByCode(jtSignFamily.getDoctor());
  1470. if (doctor != null) {
  1471. JSONObject jo = new JSONObject();
  1472. jo.put("code", doctor.getCode());
  1473. jo.put("sex", doctor.getSex());
  1474. jo.put("name", doctor.getName());
  1475. jo.put("photo", doctor.getPhoto());
  1476. jo.put("hosptialName", doctor.getHosptialName());
  1477. jo.put("level", doctor.getLevel());
  1478. jo.put("signType", "2");//三师签约
  1479. jo.put("signStatus", jtSignFamily.getStatus());
  1480. jo.put("jobName", doctor.getJobName());
  1481. jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
  1482. if (jtSignFamily.getStatus() == 0) {
  1483. jo.put("sqDate", DateUtil.dateToStrShort(jtSignFamily.getPatientApplyDate()));//申请时间
  1484. } else {
  1485. jo.put("qyDate", DateUtil.dateToStrShort(jtSignFamily.getApplyDate()));//签约时间
  1486. jo.put("endDate", DateUtil.dateToStrShort(jtSignFamily.getEnd()));//结束时间
  1487. }
  1488. jsonArray.put(jo);
  1489. }
  1490. }
  1491. return jsonArray;
  1492. }
  1493. public SignFamily getPatientSign(String patient) {
  1494. return signFamilyDao.findByPatient(patient);
  1495. }
  1496. public SignFamily getssPatientSign(String invitePatientCode) {
  1497. return signFamilyDao.findBySsPatient(invitePatientCode);
  1498. }
  1499. /**
  1500. * 患者家庭签约收费类型更新
  1501. *
  1502. * @param expensesType
  1503. * @param patient
  1504. * @return
  1505. */
  1506. public boolean updateExpensesType(String expensesType, String patient) {
  1507. if (signFamilyDao.updateExpensesType(expensesType, patient) > 0) {
  1508. return true;
  1509. } else {
  1510. return false;
  1511. }
  1512. }
  1513. }