PatientInfoDjFacade.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. package com.diagbot.facade;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.diagbot.dto.GetTopPatientInfoDjDTO;
  5. import com.diagbot.dto.RegisterInfoDTO;
  6. import com.diagbot.dto.SignInDTO;
  7. import com.diagbot.entity.DoctorInfo;
  8. import com.diagbot.entity.HospitalDept;
  9. import com.diagbot.entity.HospitalInfo;
  10. import com.diagbot.entity.PatientInfo;
  11. import com.diagbot.entity.SysSet;
  12. import com.diagbot.enums.SysTypeEnum;
  13. import com.diagbot.enums.VisibleIdTypeEnum;
  14. import com.diagbot.exception.CommonException;
  15. import com.diagbot.exception.ServiceErrorCode;
  16. import com.diagbot.idc.VisibleIdCreater;
  17. import com.diagbot.service.DoctorInfoService;
  18. import com.diagbot.service.HospitalDeptService;
  19. import com.diagbot.service.impl.PatientInfoServiceImpl;
  20. import com.diagbot.util.BeanUtil;
  21. import com.diagbot.util.DateUtil;
  22. import com.diagbot.util.IdCard;
  23. import com.diagbot.util.ListUtil;
  24. import com.diagbot.util.StringUtil;
  25. import com.diagbot.vo.GetTopPatientInfoDjVO;
  26. import com.diagbot.vo.InquiryQuoteVO;
  27. import com.diagbot.vo.SignInVO;
  28. import com.google.common.collect.Lists;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.beans.factory.annotation.Qualifier;
  31. import org.springframework.stereotype.Component;
  32. import java.util.Date;
  33. import java.util.List;
  34. import java.util.Map;
  35. import java.util.stream.Collectors;
  36. /**
  37. * @Description: 对接-患者业务逻辑
  38. * @author: wangyu
  39. * @time: 2018/11/19 13:19
  40. */
  41. @Component
  42. public class PatientInfoDjFacade extends PatientInfoServiceImpl {
  43. @Autowired
  44. private HospitalInfoFacade hospitalInfoFacade;
  45. @Autowired
  46. private HospitalDeptFacade hospitalDeptFacade;
  47. @Autowired
  48. @Qualifier("hospitalDeptServiceImpl")
  49. private HospitalDeptService hospitalDeptService;
  50. @Autowired
  51. private DoctorInfoFacade doctorInfoFacade;
  52. @Autowired
  53. @Qualifier("doctorInfoServiceImpl")
  54. private DoctorInfoService doctorInfoService;
  55. @Autowired
  56. private SysSetFacade sysSetFacade;
  57. @Autowired
  58. private VisibleIdCreater visibleIdCreater;
  59. /**
  60. * 对接-页面顶部病人医生科室信息——查询
  61. *
  62. * @param getTopPatientInfoDjVO
  63. * @return
  64. */
  65. public GetTopPatientInfoDjDTO getTopPatientInfoDj(GetTopPatientInfoDjVO getTopPatientInfoDjVO) {
  66. GetTopPatientInfoDjDTO getTopPatientInfoDjDTO = this.baseMapper.getTopPatientInfoDj(getTopPatientInfoDjVO);
  67. getTopPatientInfoDjDTO.setSystemTime(DateUtil.now());
  68. getTopPatientInfoDjDTO.setRecordId(getTopPatientInfoDjVO.getRecordId());
  69. getTopPatientInfoDjDTO.setPatientAge(DateUtil.yearCompare(getTopPatientInfoDjDTO.getBirthday(), DateUtil.now()));
  70. List<String> hospitalCodeList = Lists.newArrayList();
  71. hospitalCodeList.add(getTopPatientInfoDjVO.getHospitalCode());
  72. if (StringUtil.isNotBlank(getTopPatientInfoDjVO.getSonHospitalCode())) {
  73. hospitalCodeList.add(getTopPatientInfoDjVO.getSonHospitalCode());
  74. }
  75. QueryWrapper<HospitalInfo> hospitalInfoQe = new QueryWrapper<>();
  76. hospitalInfoQe.in("code", hospitalCodeList);
  77. Map<String, HospitalInfo> hospitalInfoMap = hospitalInfoFacade.list(hospitalInfoQe)
  78. .stream().collect(Collectors.toMap(HospitalInfo::getCode, i -> i));
  79. HospitalInfo hospitalInfo = hospitalInfoMap.get(getTopPatientInfoDjVO.getHospitalCode());
  80. HospitalInfo sonHospitalInfo = hospitalInfoMap.get(getTopPatientInfoDjVO.getSonHospitalCode());
  81. getTopPatientInfoDjDTO.setHospitalId(hospitalInfo.getId());
  82. getTopPatientInfoDjDTO.setHospitalCode(hospitalInfo.getCode());
  83. getTopPatientInfoDjDTO.setHospitalName(hospitalInfo.getName());
  84. if (sonHospitalInfo != null) {
  85. getTopPatientInfoDjDTO.setSonHospitalId(sonHospitalInfo.getId());
  86. getTopPatientInfoDjDTO.setSonHospitalCode(sonHospitalInfo.getCode());
  87. getTopPatientInfoDjDTO.setSonHospitalName(sonHospitalInfo.getName());
  88. }
  89. QueryWrapper<HospitalDept> hospitalDeptQe = new QueryWrapper<>();
  90. hospitalDeptQe.eq("hospital_code",
  91. StringUtil.isBlank(getTopPatientInfoDjVO.getSonHospitalCode())
  92. ? getTopPatientInfoDjVO.getHospitalCode()
  93. : getTopPatientInfoDjVO.getSonHospitalCode());
  94. hospitalDeptQe.eq("code", getTopPatientInfoDjVO.getHospitalDeptCode());
  95. HospitalDept hospitalDept = hospitalDeptFacade.getOne(hospitalDeptQe, false);
  96. if (hospitalDept != null) {
  97. getTopPatientInfoDjDTO.setHospitalDeptId(hospitalDept.getId());
  98. getTopPatientInfoDjDTO.setHospitalDeptCode(hospitalDept.getCode());
  99. getTopPatientInfoDjDTO.setHospitalDeptName(hospitalDept.getName());
  100. getTopPatientInfoDjDTO.setSelfDeptName(hospitalDept.getConceptDeptName());
  101. }
  102. return getTopPatientInfoDjDTO;
  103. }
  104. /**
  105. * 患者登录
  106. *
  107. * @param signInVO
  108. * @return
  109. */
  110. public List<SignInDTO> signIn(SignInVO signInVO) {
  111. List<SignInDTO> retList = null;
  112. List<RegisterInfoDTO> rifList = getRegisterInfo(signInVO);
  113. if (ListUtil.isNotEmpty(rifList)) {
  114. generateByRif(rifList);
  115. retList = rifConverSin(rifList);
  116. } else {
  117. retList = autoGenePatinfo(signInVO);
  118. }
  119. if (retList == null) {
  120. throw new CommonException(ServiceErrorCode.IQC_NOT_FOUND);
  121. }
  122. return retList;
  123. }
  124. /**
  125. * 自动生成患者信息
  126. *
  127. * @param signInVO
  128. * @return
  129. */
  130. private List<SignInDTO> autoGenePatinfo(SignInVO signInVO) {
  131. QueryWrapper<SysSet> sysSetQe = new QueryWrapper<>();
  132. sysSetQe.eq("sys_type", SysTypeEnum.PREC_SERVICE.getKey());
  133. sysSetQe.and(qe1 -> qe1
  134. .and(qe2 -> qe2
  135. .eq("hospital_code", signInVO.getHospitalCode())
  136. .eq("code", "patientinfo"))
  137. .or(qe3 -> qe3
  138. .eq("hospital_code",
  139. StringUtil.isBlank(signInVO.getSonHospitalCode()) ? signInVO.getHospitalCode()
  140. : signInVO.getSonHospitalCode())
  141. .eq("code", "default_dept")));
  142. Map<String, String> sysSetCodeValue = sysSetFacade.list(sysSetQe).stream()
  143. .collect(Collectors.toMap(SysSet::getCode, i -> i.getValue()));
  144. if (StringUtil.isBlank(sysSetCodeValue.get("patientinfo"))
  145. || !sysSetCodeValue.get("patientinfo").equals("1")) {
  146. return null;
  147. }
  148. if (!signInVO.getPatientInfoType().equals("101")) {
  149. throw new CommonException(ServiceErrorCode.IDCARD_LOGIN);
  150. }
  151. List<SignInDTO> retList = Lists.newArrayList();
  152. SignInDTO signInDTO = new SignInDTO();
  153. signInDTO.setHospitalCode(signInVO.getHospitalCode());
  154. signInDTO.setHospitalName(signInVO.getHospitalName());
  155. signInDTO.setSonHospitalCode(signInVO.getSonHospitalCode());
  156. signInDTO.setSonHospitalName(signInVO.getSonHospitalName());
  157. String hospitalDeptCode = sysSetCodeValue.get("default_dept");
  158. signInDTO.setHospitalDeptCode(hospitalDeptCode);
  159. QueryWrapper<HospitalDept> hospitalDeptQe = new QueryWrapper<>();
  160. hospitalDeptQe.eq("hospital_code",
  161. StringUtil.isBlank(signInVO.getSonHospitalCode()) ? signInVO.getHospitalCode() : signInVO.getSonHospitalCode());
  162. hospitalDeptQe.eq("code", hospitalDeptCode);
  163. signInDTO.setHospitalDeptName(hospitalDeptFacade.getOne(hospitalDeptQe, false).getName());
  164. QueryWrapper<PatientInfo> patientInfoQe = new QueryWrapper<>();
  165. patientInfoQe.eq("id_no", signInVO.getPatientInfo());
  166. patientInfoQe.eq("name", signInVO.getPatientName());
  167. PatientInfo patientInfo = getOne(patientInfoQe, false);
  168. if (patientInfo == null) {
  169. patientInfo = new PatientInfo();
  170. patientInfo.setGmtCreate(DateUtil.now());
  171. patientInfo.setHospitalCode(signInVO.getHospitalCode());
  172. patientInfo.setIdNo(signInVO.getPatientInfo());
  173. patientInfo.setIdentityNum(signInVO.getPatientInfo());
  174. patientInfo.setName(signInVO.getPatientName());
  175. patientInfo.setSex(IdCard.getGenderByIdCard(signInVO.getPatientInfo()));
  176. patientInfo.setBirthday(DateUtil.parseDate(IdCard.getBirthByIdCard(signInVO.getPatientInfo()), "yyyyMMdd"));
  177. patientInfo.setCode("" + visibleIdCreater.getNextShortId(VisibleIdTypeEnum.PATIENT_NO.getKey()));
  178. patientInfo.setRemark("1");//自动生成标志
  179. save(patientInfo);
  180. }
  181. signInDTO.setPatientCode(patientInfo.getCode());
  182. signInDTO.setPatientName(patientInfo.getName());
  183. retList.add(signInDTO);
  184. return retList;
  185. }
  186. /**
  187. * his返回的挂号信息转化给前端
  188. *
  189. * @param rifList
  190. * @return
  191. */
  192. private List<SignInDTO> rifConverSin(List<RegisterInfoDTO> rifList) {
  193. List<SignInDTO> retList = Lists.newArrayList();
  194. rifList.forEach(rif -> {
  195. rif.getDetail().forEach(i -> {
  196. SignInDTO signInDTO = new SignInDTO(
  197. rif.getHospitalCode(),
  198. rif.getHospitalName(),
  199. rif.getSonHospitalCode(),
  200. rif.getSonHospitalName(),
  201. i.getHospitalDeptCode(),
  202. i.getHospitalDeptName(),
  203. i.getDoctorInfo().getCode(),
  204. i.getDoctorInfo().getName(),
  205. rif.getPatientInfo().getCode(),
  206. rif.getPatientInfo().getName(),
  207. i.getRecordTime(),
  208. i.getRecordId(),
  209. i.getRegisterNum()
  210. );
  211. retList.add(signInDTO);
  212. });
  213. });
  214. return retList;
  215. }
  216. /**
  217. * 由挂号信息检查病人科室医生信息,有更新,无插入
  218. *
  219. * @param rifList
  220. */
  221. private void generateByRif(List<RegisterInfoDTO> rifList) {
  222. rifList.forEach(rif -> {
  223. String hospitalCode = rif.getHospitalCode();
  224. String hospitalName = rif.getHospitalName();
  225. String sonHospitalCode = rif.getSonHospitalCode();
  226. String sonHospitalName = rif.getSonHospitalName();
  227. PatientInfo patientInfo = rif.getPatientInfo();
  228. QueryWrapper<PatientInfo> patientInfoQe = new QueryWrapper<>();
  229. patientInfoQe.eq("hospital_code", hospitalCode);
  230. patientInfoQe.eq("code", patientInfo.getCode());
  231. PatientInfo patientInfoQuery = getOne(patientInfoQe, false);
  232. PatientInfo saveOrUpat = new PatientInfo();
  233. Long patId = null;
  234. if (patientInfoQuery != null) {
  235. patId = patientInfoQuery.getId();
  236. }
  237. BeanUtil.copyProperties(patientInfoQuery, saveOrUpat);
  238. BeanUtil.copyProperties(patientInfo, saveOrUpat);
  239. patientInfo.setId(patId);
  240. patientInfo.setHospitalCode(hospitalCode);
  241. saveOrUpdate(saveOrUpat);
  242. List<String> deptCodeList = rif.getDetail().stream()
  243. .filter(i -> StringUtil.isNotBlank(i.getHospitalDeptCode()) && StringUtil.isNotBlank(i.getHospitalDeptName()))
  244. .map(i -> i.getHospitalDeptCode())
  245. .collect(Collectors.toList());
  246. QueryWrapper<HospitalDept> hospitalDeptQe = new QueryWrapper<>();
  247. hospitalDeptQe.eq("hospital_code", StringUtil.isBlank(sonHospitalCode) ? hospitalCode : sonHospitalCode);
  248. hospitalDeptQe.in("code", deptCodeList);
  249. Map<String, HospitalDept> deptMap = hospitalDeptFacade.list(hospitalDeptQe)
  250. .stream()
  251. .collect(Collectors.toMap(HospitalDept::getCode, i -> i));
  252. List<HospitalDept> deptSaveOrUpdateList = Lists.newArrayList();
  253. rif.getDetail().stream()
  254. .filter(i -> StringUtil.isNotBlank(i.getHospitalDeptCode()) && StringUtil.isNotBlank(i.getHospitalDeptName()))
  255. .forEach(i -> {
  256. HospitalDept hospitalDeptQuery = deptMap.get(i.getHospitalDeptCode());
  257. if (hospitalDeptQuery == null) {
  258. HospitalDept hospitalDept = new HospitalDept();
  259. hospitalDept.setHospitalCode(StringUtil.isNotBlank(sonHospitalCode) ? sonHospitalCode : hospitalCode);
  260. hospitalDept.setHospitalName(StringUtil.isNotBlank(sonHospitalCode) ? sonHospitalName : hospitalName);
  261. hospitalDept.setCode(i.getHospitalDeptCode());
  262. hospitalDept.setName(i.getHospitalDeptName());
  263. hospitalDept.setconceptDeptName("全科");
  264. deptSaveOrUpdateList.add(hospitalDept);
  265. } else {
  266. hospitalDeptQuery.setName(i.getHospitalDeptName());
  267. deptSaveOrUpdateList.add(hospitalDeptQuery);
  268. }
  269. });
  270. if (ListUtil.isNotEmpty(deptSaveOrUpdateList)) {
  271. hospitalDeptService.saveOrUpdateBatch(deptSaveOrUpdateList);
  272. }
  273. List<String> doctorCodeList = rif.getDetail().stream()
  274. .filter(i -> i.getDoctorInfo() != null).map(i -> i.getDoctorInfo())
  275. .filter(i -> StringUtil.isNotBlank(i.getCode()) && StringUtil.isNotBlank(i.getName()))
  276. .map(i -> i.getCode()).collect(Collectors.toList());
  277. QueryWrapper<DoctorInfo> doctorInfoQe = new QueryWrapper<>();
  278. doctorInfoQe.eq("hospital_code", hospitalCode);
  279. doctorInfoQe.in("code", doctorCodeList);
  280. Map<String, DoctorInfo> doctorMap = doctorInfoFacade.list(doctorInfoQe)
  281. .stream().collect(Collectors.toMap(DoctorInfo::getCode, i -> i));
  282. List<DoctorInfo> doctorSaveOrUpdateList = Lists.newArrayList();
  283. rif.getDetail().stream()
  284. .filter(i -> i.getDoctorInfo() != null).map(i -> i.getDoctorInfo())
  285. .filter(i -> StringUtil.isNotBlank(i.getCode()) && StringUtil.isNotBlank(i.getName()))
  286. .forEach(i -> {
  287. DoctorInfo doctorInfo = new DoctorInfo();
  288. DoctorInfo doctorInfoQuery = doctorMap.get(i.getCode());
  289. Long docId = null;
  290. if (doctorInfoQuery != null) {
  291. BeanUtil.copyProperties(doctorInfoQuery, doctorInfo);
  292. docId = doctorInfoQuery.getId();
  293. }
  294. BeanUtil.copyProperties(i, doctorInfo);
  295. doctorInfo.setHospitalCode(hospitalCode);
  296. doctorInfo.setId(docId);
  297. if (!doctorSaveOrUpdateList.stream()
  298. .map(doc -> doc.getCode()).distinct()
  299. .collect(Collectors.toList()).contains(doctorInfo.getCode())) {
  300. doctorSaveOrUpdateList.add(doctorInfo);
  301. }
  302. });
  303. if (ListUtil.isNotEmpty(doctorSaveOrUpdateList)) {
  304. doctorInfoService.saveOrUpdateBatch(doctorSaveOrUpdateList);
  305. }
  306. });
  307. }
  308. /**
  309. * 对接---获取挂号信息
  310. * 某一时刻患者只可能在一家医院,所以获取到的挂号信息只能是当前医院的,当出现江干的大小医院情况时可采用2种:
  311. * 1、预问诊必须选择小医院,对方接口小医院要求必传;2、his返回时间最近的一家医院挂号信息(可能不准确)。
  312. * 大小医院信息使用his返回来的(未选择小医院时有用)
  313. *
  314. * @param signInVO
  315. * @return
  316. */
  317. private List<RegisterInfoDTO> getRegisterInfo(SignInVO signInVO) {
  318. if (!signInVO.getHospitalCode().equals("33010400")){
  319. return null;
  320. }
  321. String retJson = " [{"
  322. + "\"hospitalCode\": \"33010400\","
  323. + "\"hospitalName\": \"江干区卫计局\","
  324. + "\"sonHospitalCode\": \"33010480\","
  325. + "\"sonHospitalName\": \"四季青街道社区卫生服务中心\","
  326. + "\"patientInfo\": {"
  327. + " \"birthday\": \"1984-10-08 10:20:23\","
  328. + "\"code\": \"1747\","
  329. + "\"idNo\": \"330104198410083034\","
  330. + " \"hospitalCode\": \"33010400\","
  331. + " \"sex\": 1,"
  332. + " \"identityNum\": \"330104198410083034\","
  333. + " \"name\": \"沈利峰\""
  334. + "},"
  335. + "\"detail\": [{"
  336. + " \"hospitalDeptCode\": \"2127\","
  337. + " \"hospitalDeptName\": \"中医科\","
  338. + " \"doctorInfo\": {"
  339. + " \"code\": \"000\","
  340. + " \"hospitalCode\": \"33010400\","
  341. + " \"name\": \"普通\""
  342. + "},"
  343. + " \"recordId\": \"9043516\","
  344. + " \"recordTime\": \"2019-12-05 12:29:55\","
  345. + " \"registerNum\": \"1\""
  346. + "},{"
  347. + "\"hospitalDeptCode\": \"2533\","
  348. + " \"hospitalDeptName\": \"机神全科\","
  349. + " \"doctorInfo\": {"
  350. + "\"code\": \"000\","
  351. + " \"hospitalCode\": \"33010400\","
  352. + "\"name\": \"普通\""
  353. + "},"
  354. + " \"recordId\": \"9043512\","
  355. + " \"recordTime\": \"2019-12-05 12:23:09\","
  356. + " \"registerNum\": \"1\""
  357. + "}]"
  358. + "},"
  359. + "{"
  360. + " \"hospitalCode\": \"33010400\","
  361. + "\"hospitalName\": \"江干区卫计局\","
  362. + " \"sonHospitalCode\": \"33010490\","
  363. + " \"sonHospitalName\": \"闸弄口街道社区卫生服务中心\","
  364. + "\"patientInfo\": {"
  365. + " \"birthday\": \"1984-10-08 10:20:23\","
  366. + "\"code\": \"1747\","
  367. + " \"idNo\": \"330104198410083034\","
  368. + " \"hospitalCode\": \"33010400\","
  369. + " \"sex\": 1,"
  370. + " \"identityNum\": \"330104198410083034\","
  371. + " \"name\": \"沈利峰\""
  372. + "},"
  373. + " \"detail\": [{"
  374. + " \"hospitalDeptCode\": \"2127\","
  375. + "\"hospitalDeptName\": \"中医科\","
  376. + " \"doctorInfo\": {"
  377. + " \"code\": \"000\","
  378. + " \"hospitalCode\": \"33010400\","
  379. + " \"name\": \"普通\""
  380. + "},"
  381. + " \"recordId\": \"9043516\","
  382. + " \"recordTime\": \"2019-12-05 12:29:55\","
  383. + " \"registerNum\": \"1\""
  384. + "},{"
  385. + " \"hospitalDeptCode\": \"2533\","
  386. + " \"hospitalDeptName\": \"机神全科\","
  387. + " \"doctorInfo\": {"
  388. + " \"code\": \"000\","
  389. + " \"hospitalCode\": \"33010400\","
  390. + " \"name\": \"普通\""
  391. + "},"
  392. + "\"recordId\": \"9043512\","
  393. + " \"recordTime\": \"2019-12-05 12:23:09\","
  394. + " \"registerNum\": \"1\""
  395. + "}]"
  396. + "}"
  397. + "]";
  398. // List<RegisterInfoDTO> rifList = GsonUtil.toList(retJson, RegisterInfoDTO.class);
  399. List<RegisterInfoDTO> rifList = JSON.parseArray(retJson, RegisterInfoDTO.class);
  400. System.out.println(rifList);
  401. return rifList;
  402. }
  403. /**
  404. * 病历引用时,更新患者医生科室信息
  405. *
  406. * @param inquiryQuoteVO
  407. * @return
  408. */
  409. public InquiryQuoteVO inquiryQuote(InquiryQuoteVO inquiryQuoteVO) {
  410. List<String> hospitalCodeList = Lists.newArrayList();
  411. hospitalCodeList.add(inquiryQuoteVO.getHospitalCode());
  412. String hospitalCode = inquiryQuoteVO.getHospitalCode();
  413. String hospitalName = inquiryQuoteVO.getHospitalName();
  414. if (StringUtil.isNotBlank(inquiryQuoteVO.getSonHospitalCode())) {
  415. hospitalCodeList.add(inquiryQuoteVO.getSonHospitalCode());
  416. hospitalCode = inquiryQuoteVO.getSonHospitalCode();
  417. hospitalName = inquiryQuoteVO.getSonHospitalName();
  418. }
  419. QueryWrapper<HospitalInfo> hospitalInfoQe = new QueryWrapper<>();
  420. hospitalInfoQe.in("code", hospitalCodeList);
  421. Map<String, Long> hospitalInfoIdMap = hospitalInfoFacade.list(hospitalInfoQe)
  422. .stream().collect(Collectors.toMap(HospitalInfo::getCode, i -> i.getId()));
  423. inquiryQuoteVO.setHospitalId(hospitalInfoIdMap.get(inquiryQuoteVO.getHospitalCode()));
  424. if (StringUtil.isNotBlank(inquiryQuoteVO.getSonHospitalCode())) {
  425. inquiryQuoteVO.setSonHospitalId(hospitalInfoIdMap.get(inquiryQuoteVO.getSonHospitalCode()));
  426. }
  427. Date now = DateUtil.now();
  428. if (inquiryQuoteVO.getDeptInfo() != null) {
  429. QueryWrapper<HospitalDept> hospitalDeptQe = new QueryWrapper<>();
  430. hospitalDeptQe.eq("hospital_code", hospitalCode);
  431. hospitalDeptQe.eq("code", inquiryQuoteVO.getDeptInfo().getCode());
  432. HospitalDept hospitalDept = hospitalDeptFacade.getOne(hospitalDeptQe, false);
  433. Long deptId = null;
  434. if (hospitalDept == null) {
  435. hospitalDept = new HospitalDept();
  436. hospitalDept.setGmtCreate(now);
  437. hospitalDept.setHospitalCode(hospitalCode);
  438. hospitalDept.setHospitalName(hospitalName);
  439. hospitalDept.setconceptDeptName("全科");
  440. } else {
  441. deptId = hospitalDept.getId().longValue();
  442. }
  443. BeanUtil.copyProperties(inquiryQuoteVO.getDeptInfo(), hospitalDept);
  444. hospitalDept.setGmtModified(now);
  445. hospitalDept.setId(deptId);
  446. hospitalDeptFacade.saveOrUpdate(hospitalDept);
  447. inquiryQuoteVO.getDeptInfo().setId(hospitalDept.getId());
  448. }
  449. if (inquiryQuoteVO.getDoctorInfo() != null) {
  450. QueryWrapper<DoctorInfo> doctorInfoQe = new QueryWrapper<>();
  451. doctorInfoQe.eq("hospital_code", inquiryQuoteVO.getHospitalCode());
  452. doctorInfoQe.eq("code", inquiryQuoteVO.getDoctorInfo().getCode());
  453. DoctorInfo doctorInfo = doctorInfoFacade.getOne(doctorInfoQe, false);
  454. Long doctorId = null;
  455. if (doctorInfo == null) {
  456. doctorInfo = new DoctorInfo();
  457. doctorInfo.setGmtCreate(now);
  458. doctorInfo.setHospitalCode(inquiryQuoteVO.getHospitalCode());
  459. } else {
  460. doctorId = doctorInfo.getId().longValue();
  461. }
  462. BeanUtil.copyProperties(inquiryQuoteVO.getDoctorInfo(), doctorInfo);
  463. doctorInfo.setGmtModified(now);
  464. doctorInfo.setId(doctorId);
  465. doctorInfoFacade.saveOrUpdate(doctorInfo);
  466. inquiryQuoteVO.getDoctorInfo().setId(doctorInfo.getId());
  467. }
  468. QueryWrapper<PatientInfo> patientInfoQe = new QueryWrapper<>();
  469. patientInfoQe.eq("hospital_code", inquiryQuoteVO.getHospitalCode());
  470. patientInfoQe.eq("code", inquiryQuoteVO.getPatientInfo().getCode());
  471. PatientInfo patientInfo = getOne(patientInfoQe, false);
  472. Long patientId = null;
  473. if (patientInfo == null) {
  474. patientInfo = new PatientInfo();
  475. patientInfo.setGmtCreate(now);
  476. patientInfo.setHospitalCode(inquiryQuoteVO.getHospitalCode());
  477. } else {
  478. patientId = patientInfo.getId().longValue();
  479. }
  480. BeanUtil.copyProperties(inquiryQuoteVO.getPatientInfo(), patientInfo);
  481. patientInfo.setGmtModified(now);
  482. patientInfo.setId(patientId);
  483. saveOrUpdate(patientInfo);
  484. inquiryQuoteVO.getPatientInfo().setId(patientInfo.getId());
  485. return inquiryQuoteVO;
  486. }
  487. }