From 4d537968ac6efb3a5e3d0f8ea5071d5254eb63c3 Mon Sep 17 00:00:00 2001 From: liusheng <337615773@qq.com> Date: 星期二, 29 七月 2025 14:37:17 +0800 Subject: [PATCH] 代码提交 --- smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java | 445 ++++++++++++++++++++++++ ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java | 2 ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java | 452 ++---------------------- smartor/src/main/java/com/smartor/domain/HnDataGatherVO.java | 40 ++ smartor/src/main/java/com/smartor/service/IXHGatherPatArchiveService.java | 27 + smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java | 5 ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java | 38 - smartor/src/main/java/com/smartor/service/IHNGatherPatArchiveService.java | 8 smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java | 27 + 9 files changed, 598 insertions(+), 446 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java index da5b443..3be114b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/HNGatherPatArchiveController.java @@ -9,10 +9,7 @@ import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.utils.poi.ExcelUtil; -import com.smartor.domain.PatMedInhosp; -import com.smartor.domain.PatMedOuthosp; -import com.smartor.domain.PatMedReq; -import com.smartor.domain.PatMedRes; +import com.smartor.domain.*; import com.smartor.service.IHNGatherPatArchiveService; import com.smartor.service.IPatMedOuthospService; import com.smartor.service.impl.HNGatherPatArchiveServiceImpl; @@ -48,35 +45,12 @@ /** * 娌冲崡鏁版嵁閲囬泦 */ - //@PreAuthorize("@ss.hasPermi('smartor:patouthosp:list')") - @PostMapping("/selectGatherList") + @PostMapping("/hnDataGather") @ApiOperation("娌冲崡鏁版嵁閲囬泦") - public Integer selectUserList(@RequestBody PatMedInhosp patMedInhosp) { -// Integer sd = ihnGatherPatArchiveService.selectDeptList(null); -// Integer su = ihnGatherPatArchiveService.selectUserList(null); -// Integer icd = ihnGatherPatArchiveService.selectIcd10List(null); - - log.info("寮�濮嬫寜澶╁悓姝ョ敤鎴锋暟鎹紝鏃堕棿鑼冨洿: {} 鍒� {}", patMedInhosp.getStartOutHospTime(), patMedInhosp.getEndOutHospTime()); - - LocalDate startDate = patMedInhosp.getStartOutHospTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - LocalDate endDate = patMedInhosp.getEndOutHospTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - - Integer po = null; - // 寰幆澶勭悊姣忎竴澶� - for (LocalDate currentDate = startDate; !currentDate.isAfter(endDate); currentDate = currentDate.plusDays(1)) { - PatMedInhosp dailyCondition = new PatMedInhosp(); - LocalDateTime dayStart = currentDate.atStartOfDay(); - LocalDateTime dayEnd = currentDate.atTime(23, 59, 59); - dailyCondition.setStartOutHospTime(Date.from(dayStart.atZone(ZoneId.systemDefault()).toInstant())); - dailyCondition.setEndOutHospTime(Date.from(dayEnd.atZone(ZoneId.systemDefault()).toInstant())); - Integer pi = ihnGatherPatArchiveService.selectPatMedInhospList(dailyCondition); - - PatMedOuthosp patMedOuthosp = new PatMedOuthosp(); - patMedOuthosp.setBeginTime(Date.from(dayStart.atZone(ZoneId.systemDefault()).toInstant())); - patMedOuthosp.setEndTime(Date.from(dayEnd.atZone(ZoneId.systemDefault()).toInstant())); - po = ihnGatherPatArchiveService.selectPatMedOuthospList(patMedOuthosp); - } - return po; + public AjaxResult hnDataGather(@RequestBody HnDataGatherVO hnDataGatherVO) { + log.info("寮�濮嬫寜澶╁悓姝ョ敤鎴锋暟鎹紝鏃堕棿鑼冨洿: {} 鍒� {}", hnDataGatherVO.getStartOutHospTime(), hnDataGatherVO.getEndOutHospTime()); + Boolean aBoolean = ihnGatherPatArchiveService.hnDataGather(hnDataGatherVO); + return AjaxResult.success(aBoolean); } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 93f9f7e..eedaef8 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -2,6 +2,7 @@ import javax.annotation.Resource; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; @@ -33,6 +34,7 @@ * * @author ruoyi */ +@Slf4j @Component public class SysLoginService { @Autowired diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java index 64240b7..771bf63 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java @@ -87,7 +87,7 @@ private IServicePatientTempService iServicePatientTempService; @Autowired - private PlatformTransactionManager transactionManager; + private IHNGatherPatArchiveService ihnGatherPatArchiveService; @Autowired private SysUserImportMapper sysUserImportMapper; @@ -125,8 +125,6 @@ @Autowired IPatArchiveService patArchiveService; - @Autowired - IPatMedInhospService patMedInhospService; @Autowired IPatMedOuthospService patMedOuthospService; @@ -137,14 +135,19 @@ @Autowired IIvrTaskTemplateService iIvrTaskTemplateService; - @Value("${hosp_info_url}") - private String hospInfoUrl; + @Autowired + IXHGatherPatArchiveService ixhGatherPatArchiveService; + @Value("${appid}") private String appid; @Value("${server.port}") private String port; + + + @Value("${spring.profiles.active}") + private String active; public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { System.out.println(StringUtils.format("鎵ц澶氬弬鏂规硶锛� 瀛楃涓茬被鍨媨}锛屽竷灏旂被鍨媨}锛岄暱鏁村瀷{}锛屾诞鐐瑰瀷{}锛屾暣褰}", s, b, l, d, i)); @@ -211,34 +214,42 @@ */ public void dealHisData() { log.info("銆恉ealHisData銆戝紑濮嬫墽琛孒IS鏁版嵁閲囬泦浠诲姟"); - long startTime = System.currentTimeMillis(); + // 鑾峰彇鏄ㄥぉ0鐐瑰埌浠婂ぉ0鐐圭殑鏃堕棿鑼冨洿 + LocalDateTime todayZero = LocalDateTime.now().with(LocalTime.MIN); + LocalDateTime yesterdayZero = todayZero.minusDays(1); + log.info("銆恉ealHisData銆戦噰闆嗘椂闂磋寖鍥达細{} ~ {}", yesterdayZero, todayZero); - try { - // 鑾峰彇鏄ㄥぉ0鐐瑰埌浠婂ぉ0鐐圭殑鏃堕棿鑼冨洿 - LocalDateTime todayZero = LocalDateTime.now().with(LocalTime.MIN); - LocalDateTime yesterdayZero = todayZero.minusDays(1); + if (active.trim().equals("xh")) { + try { + // 閲囬泦鍏ラ櫌鏁版嵁 + log.info("銆恉ealHisData銆戞柊鍗庡紑濮嬮噰闆嗗叆闄㈡暟鎹�"); + ixhGatherPatArchiveService.getInHospDataGather("0", yesterdayZero, todayZero); + log.info("銆恉ealHisData銆戞柊鍗庡叆闄㈡暟鎹噰闆嗗畬鎴�"); - log.info("銆恉ealHisData銆戦噰闆嗘椂闂磋寖鍥达細{} ~ {}", yesterdayZero, todayZero); + // 閲囬泦鍑洪櫌鏁版嵁 + log.info("銆恉ealHisData銆戞柊鍗庡紑濮嬮噰闆嗗嚭闄㈡暟鎹�"); + ixhGatherPatArchiveService.getInHospDataGather("1", yesterdayZero, todayZero); + log.info("銆恉ealHisData銆戞柊鍗庡嚭闄㈡暟鎹噰闆嗗畬鎴�"); - // 閲囬泦鍏ラ櫌鏁版嵁 - log.info("銆恉ealHisData銆戝紑濮嬮噰闆嗗叆闄㈡暟鎹�"); - getInHospInfo("0", yesterdayZero, todayZero); - log.info("銆恉ealHisData銆戝叆闄㈡暟鎹噰闆嗗畬鎴�"); - - // 閲囬泦鍑洪櫌鏁版嵁 - log.info("銆恉ealHisData銆戝紑濮嬮噰闆嗗嚭闄㈡暟鎹�"); - getInHospInfo("1", yesterdayZero, todayZero); - log.info("銆恉ealHisData銆戝嚭闄㈡暟鎹噰闆嗗畬鎴�"); - - long endTime = System.currentTimeMillis(); - log.info("銆恉ealHisData銆慔IS鏁版嵁閲囬泦浠诲姟瀹屾垚锛屾�昏�楁椂锛歿}ms", endTime - startTime); - - } catch (Exception e) { - log.error("銆恉ealHisData銆慔IS鏁版嵁閲囬泦寮傚父", e); - // 杩欓噷鍙互娣诲姞鍛婅閫氱煡閫昏緫锛屾瘮濡傚彂閫侀偖浠舵垨鐭俊 + } catch (Exception e) { + log.error("銆恉ealHisData銆戞柊鍗庢暟鎹噰闆嗗紓甯�", e); + } + } else if (active.trim().equals("hn")) { + try { + // 娌冲崡鏁版嵁閲囬泦 + HnDataGatherVO hnDataGatherVO = new HnDataGatherVO(); + log.info("銆恉ealHisData銆戞渤鍗楀紑濮嬮噰闆嗘暟鎹�"); + ihnGatherPatArchiveService.hnDataGather(hnDataGatherVO); + log.info("銆恉ealHisData銆戞渤鍗楃粨鏉熼噰闆嗘暟鎹�"); + } catch (Exception e) { + log.error("銆恉ealHisData銆戞渤鍗楁暟鎹噰闆嗗紓甯�", e); + } } } + /** + * 杩欎釜鍙槸鏂板崕涓存椂浣跨敤锛屽钩鏃剁敤涓嶅埌 + */ public void dealHisData2() { //灏嗘偅鑰呬俊鎭�佸嚭鍏ラ櫌鏁版嵁鍏ㄩ儴閲囬泦 // 鎸囧畾鐨勫紑濮嬫棩鏈� @@ -251,8 +262,8 @@ // 浠庡紑濮嬫棩鏈熷埌褰撳墠鏃ユ湡閫愬ぉ鎵撳嵃 for (LocalDate date = endDate; !date.isAfter(currentDate); date = date.plusDays(1)) { System.out.println(date.format(formatter)); - getInHospInfo("0", date.minusDays(1).atStartOfDay(), date.atStartOfDay()); - getInHospInfo("1", date.minusDays(1).atStartOfDay(), date.atStartOfDay()); + ixhGatherPatArchiveService.getInHospDataGather("0", date.minusDays(1).atStartOfDay(), date.atStartOfDay()); + ixhGatherPatArchiveService.getInHospDataGather("1", date.minusDays(1).atStartOfDay(), date.atStartOfDay()); } } @@ -639,389 +650,6 @@ } } } - - - /** - * 鑾峰彇鎮h�呭嚭鍏ラ櫌淇℃伅 - * - * @param cry 鍑哄叆闄㈢被鍨嬶細0-鍏ラ櫌锛�1-鍑洪櫌 - * @param startTime 寮�濮嬫椂闂� - * @param endTime 缁撴潫鏃堕棿 - */ - @Transactional - public void getInHospInfo(String cry, LocalDateTime startTime, LocalDateTime endTime) { - String typeName = "0".equals(cry) ? "鍏ラ櫌" : "鍑洪櫌"; - log.info("銆恎etInHospInfo銆戝紑濮嬭幏鍙杮}鎮h�呬俊鎭紝鏃堕棿鑼冨洿锛歿} ~ {}", typeName, startTime, endTime); - long startTimeMillis = System.currentTimeMillis(); - - try { - // 绗竴姝ワ細鏋勫缓璇锋眰鍙傛暟骞惰皟鐢℉IS鎺ュ彛 - List<ThiedInhospInfo> thiedInhospInfoList = fetchHisData(cry, startTime, endTime); - - if (CollectionUtils.isEmpty(thiedInhospInfoList)) { - log.info("銆恎etInHospInfo銆憑}鎮h�呬俊鎭负绌猴紝璺宠繃澶勭悊", typeName); - return; - } - - log.info("銆恎etInHospInfo銆戣幏鍙栧埌{}鏉}鎮h�呬俊鎭�", thiedInhospInfoList.size(), typeName); - - // 绗簩姝ワ細淇濆瓨鍘熷鏁版嵁鍒版枃浠讹紙鐢ㄤ簬澶囦唤锛� - saveRawDataToFile(cry, thiedInhospInfoList); - - // 绗笁姝ワ細澶勭悊鎮h�呮暟鎹� - processPatientData(thiedInhospInfoList, cry); - - long endTimeMillis = System.currentTimeMillis(); - log.info("銆恎etInHospInfo銆憑}鎮h�呬俊鎭鐞嗗畬鎴愶紝鑰楁椂锛歿}ms", typeName, endTimeMillis - startTimeMillis); - - } catch (Exception e) { - log.error("銆恎etInHospInfo銆戣幏鍙杮}鎮h�呬俊鎭紓甯�", typeName, e); - throw new RuntimeException("鑾峰彇" + typeName + "鎮h�呬俊鎭け璐�", e); - } - } - - /** - * 绗竴姝ワ細璋冪敤HIS鎺ュ彛鑾峰彇鏁版嵁 - */ - private List<ThiedInhospInfo> fetchHisData(String cry, LocalDateTime startTime, LocalDateTime endTime) { - try { - // 鏋勫缓璇锋眰鍙傛暟 - Map<String, String> requestParams = buildRequestParams(cry, startTime, endTime); - - // 鏋勫缓璇锋眰澶� - Map<String, String> headers = buildRequestHeaders(startTime); - - // 鍙戦�丠TTP璇锋眰 - String result = HttpUtils.sendPostByHeader(hospInfoUrl, new Gson().toJson(requestParams), headers); - - // 瑙f瀽鍝嶅簲鏁版嵁 - return parseResponseData(result); - - } catch (Exception e) { - log.error("銆恌etchHisData銆戣皟鐢℉IS鎺ュ彛寮傚父", e); - throw e; - } - } - - /** - * 鏋勫缓璇锋眰鍙傛暟 - */ - private Map<String, String> buildRequestParams(String cry, LocalDateTime startTime, LocalDateTime endTime) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); - Map<String, String> req = new HashMap<>(); - - if ("1".equals(cry)) { - // 鍑洪櫌鍙傛暟 - req.put("cashStartDate", startTime.format(formatter)); - req.put("cashEndDate", endTime.format(formatter)); - req.put("currStatus", "4"); - } else { - // 鍏ラ櫌鍙傛暟 - req.put("admissStartDate", startTime.format(formatter)); - req.put("admissEndDate", endTime.format(formatter)); - req.put("currStatus", "2"); - } - - return req; - } - - /** - * 鏋勫缓璇锋眰澶� - */ - private Map<String, String> buildRequestHeaders(LocalDateTime startTime) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); - Map<String, String> header = new HashMap<>(); - header.put("x-hcsb-serviceno", "IS002347"); - header.put("x-hcsb-version", "2.0"); - header.put("x-hcsb-sourcesyscode", "14"); - header.put("x-hcsb-token", "ArGE2JnHtxG/Zx5nrnGY4eOfMUJGGJokAJHigG1BrCY="); - header.put("x-hcsb-msgdate", startTime.format(formatter)); - return header; - } - - /** - * 瑙f瀽鍝嶅簲鏁版嵁 - */ - private List<ThiedInhospInfo> parseResponseData(String result) { - try { - Gson gson = new Gson(); - JsonObject jsonObject = gson.fromJson(result, JsonObject.class); - JsonArray resultArray = jsonObject.getAsJsonObject("data").getAsJsonArray("result"); - Type resultType = new TypeToken<List<ThiedInhospInfo>>() { - }.getType(); - return gson.fromJson(resultArray, resultType); - } catch (Exception e) { - log.error("銆恜arseResponseData銆戣В鏋愬搷搴旀暟鎹紓甯革紝鍘熷鏁版嵁锛歿}", result, e); - throw e; - } - } - - /** - * 绗簩姝ワ細淇濆瓨鍘熷鏁版嵁鍒版枃浠� - */ - private void saveRawDataToFile(String cry, List<ThiedInhospInfo> dataList) { - try { - String typeName = "0".equals(cry) ? "鍏ラ櫌淇℃伅" : "鍑洪櫌淇℃伅"; - String filename = typeName + "_" + System.currentTimeMillis() + ".json"; - String filePath = "D:\\public\\HIS鏁版嵁閲囬泦\\" + filename; - - File file = new File(filePath); - File parentDir = file.getParentFile(); - if (!parentDir.exists()) { - parentDir.mkdirs(); - } - - if (!file.exists()) { - file.createNewFile(); - } - - // 灏嗘暟鎹啓鍏ユ枃浠� - try (FileWriter writer = new FileWriter(file)) { - writer.write(new Gson().toJson(dataList)); - } - - log.info("銆恠aveRawDataToFile銆戝師濮嬫暟鎹凡淇濆瓨鍒版枃浠讹細{}", filePath); - - } catch (Exception e) { - log.error("銆恠aveRawDataToFile銆戜繚瀛樺師濮嬫暟鎹埌鏂囦欢寮傚父", e); - // 鏂囦欢淇濆瓨澶辫触涓嶅奖鍝嶄富娴佺▼锛屽彧璁板綍鏃ュ織 - } - } - - /** - * 绗笁姝ワ細澶勭悊鎮h�呮暟鎹� - */ - private void processPatientData(List<ThiedInhospInfo> thiedInhospInfoList, String cry) { - int successCount = 0; - int skipCount = 0; - int errorCount = 0; - - for (ThiedInhospInfo thiedInhospInfo : thiedInhospInfoList) { - try { - if (processSinglePatient(thiedInhospInfo, cry)) { - successCount++; - } else { - skipCount++; - } - } catch (Exception e) { - errorCount++; - log.error("銆恜rocessPatientData銆戝鐞嗘偅鑰呮暟鎹紓甯革紝鎮h�匢D锛歿}", thiedInhospInfo.getPatiMediaNo(), e); - } - } - - log.info("銆恜rocessPatientData銆戞偅鑰呮暟鎹鐞嗗畬鎴愶紝鎴愬姛锛歿}锛岃烦杩囷細{}锛屽け璐ワ細{}", successCount, skipCount, errorCount); - } - - /** - * 澶勭悊鍗曚釜鎮h�呮暟鎹� - */ - private boolean processSinglePatient(ThiedInhospInfo thiedInhospInfo, String cry) { - // 楠岃瘉韬唤璇佸彿 - if (StringUtils.isEmpty(thiedInhospInfo.getPatiIdCardNo())) { - log.warn("銆恜rocessSinglePatient銆戞偅鑰呰韩浠借瘉鍙蜂负绌猴紝璺宠繃澶勭悊锛屾偅鑰呯紪鍙凤細{}", thiedInhospInfo.getPatiMediaNo()); - return false; - } - - // 澶勭悊鎮h�呮。妗堜俊鎭� - PatArchive patArchive = processPatientArchive(thiedInhospInfo, cry); - - // 澶勭悊鎮h�呬綇闄俊鎭� - processPatientInhospInfo(thiedInhospInfo, patArchive, cry); - - return true; - } - - /** - * 澶勭悊鎮h�呮。妗堜俊鎭� - */ - private PatArchive processPatientArchive(ThiedInhospInfo thiedInhospInfo, String cry) { - // 鏌ヨ鎮h�呮槸鍚﹀凡瀛樺湪 - PatArchive queryArchive = new PatArchive(); - queryArchive.setIdcardno(thiedInhospInfo.getPatiIdCardNo().trim()); - List<PatArchive> existingArchives = patArchiveService.selectPatArchiveList(queryArchive); - - // 鏋勫缓鎮h�呮。妗堜俊鎭� - PatArchive patArchive = buildPatientArchive(thiedInhospInfo, cry); - - // 淇濆瓨鎴栨洿鏂版偅鑰呮。妗� - if (CollectionUtils.isEmpty(existingArchives)) { - patArchiveService.insertPatArchive(patArchive); - log.debug("銆恜rocessPatientArchive銆戞柊澧炴偅鑰呮。妗堬紝鎮h�呯紪鍙凤細{}", patArchive.getPatientno()); - } else { - patArchive.setId(existingArchives.get(0).getId()); - patArchiveService.updateArchive(patArchive); - log.debug("銆恜rocessPatientArchive銆戞洿鏂版偅鑰呮。妗堬紝鎮h�呯紪鍙凤細{}", patArchive.getPatientno()); - } - - return patArchive; - } - - /** - * 鏋勫缓鎮h�呮。妗堜俊鎭� - */ - private PatArchive buildPatientArchive(ThiedInhospInfo thiedInhospInfo, String cry) { - PatArchive patArchive = new PatArchive(); - - // 鍩烘湰淇℃伅 - patArchive.setPatientno(thiedInhospInfo.getPatiMediaNo()); - patArchive.setIdcardno(thiedInhospInfo.getPatiIdCardNo().trim()); - patArchive.setName(thiedInhospInfo.getPatiRecordName()); - patArchive.setSourcefrom(2); - patArchive.setPattype("2"); - - // 鎬у埆 - patArchive.setSex("鐢�".equals(thiedInhospInfo.getPatiRecordGender()) ? 1L : 2L); - - // 姘戞棌鍜岀睄璐� - patArchive.setNation(thiedInhospInfo.getPatiNation()); - patArchive.setNativePlace(thiedInhospInfo.getPatiNationality()); - - // 灞呬綇鍦板潃 - String homeAddr = thiedInhospInfo.getPatiHomeAddr(); - patArchive.setPlaceOfResidence(StringUtils.isNotEmpty(homeAddr) ? homeAddr.replace("null", "") : ""); - - // 鍑虹敓鏃ユ湡 - if (StringUtils.isNotEmpty(thiedInhospInfo.getPatiBirthday())) { - try { - patArchive.setBirthdate(new SimpleDateFormat("yyyy-MM-dd").parse(thiedInhospInfo.getPatiBirthday())); - } catch (ParseException e) { - log.warn("銆恇uildPatientArchive銆戣В鏋愬嚭鐢熸棩鏈熷け璐ワ細{}", thiedInhospInfo.getPatiBirthday(), e); - } - } - - // 骞撮緞 - if (thiedInhospInfo.getTreateAge() != null) { - patArchive.setAge(Long.valueOf(thiedInhospInfo.getTreateAge())); - } - patArchive.setAgeUnit(thiedInhospInfo.getTreatAgeunit()); - - // 鑱旂郴鏂瑰紡 - patArchive.setTelcode(thiedInhospInfo.getCompanyTelNum()); - patArchive.setRelativetelcode(thiedInhospInfo.getContactPersonPhone()); - - // 鍑洪櫌鏂瑰紡澶勭悊锛堟浜$瓑鐗规畩鎯呭喌锛� - if (StringUtils.isNotEmpty(thiedInhospInfo.getOutWayId()) && "4".equals(thiedInhospInfo.getOutWayId())) { - patArchive.setNotrequiredFlag("1"); - patArchive.setNotrequiredreason(thiedInhospInfo.getOutWayName()); - } - if ("1".equals(cry) && StringUtils.isEmpty(thiedInhospInfo.getOutWayId())) { - patArchive.setNotrequiredFlag("1"); - patArchive.setNotrequiredreason("鍑洪櫌鏂瑰紡涓虹┖"); - } - - // 绯荤粺瀛楁 - patArchive.setDelFlag("0"); - patArchive.setCreateTime(new Date()); - patArchive.setUpdateTime(new Date()); - - return patArchive; - } - - /** - * 澶勭悊鎮h�呬綇闄俊鎭� - */ - private void processPatientInhospInfo(ThiedInhospInfo thiedInhospInfo, PatArchive patArchive, String cry) { - // 鏋勫缓浣忛櫌淇℃伅 - PatMedInhosp patMedInhosp = buildPatientInhospInfo(thiedInhospInfo, patArchive, cry); - - // 鏌ヨ鏄惁宸插瓨鍦ㄤ綇闄㈣褰� - PatMedInhosp queryInhosp = new PatMedInhosp(); - queryInhosp.setPatno(patArchive.getPatientno()); - queryInhosp.setSerialnum(patMedInhosp.getSerialnum()); - List<PatMedInhosp> existingInhosps = patMedInhospService.selectPatMedInhospList(queryInhosp); - - // 淇濆瓨鎴栨洿鏂颁綇闄俊鎭� - if (CollectionUtils.isNotEmpty(existingInhosps)) { - patMedInhosp.setInhospid(existingInhosps.get(0).getInhospid()); - patMedInhospService.updatePatMedInhosp(patMedInhosp); - log.debug("銆恜rocessPatientInhospInfo銆戞洿鏂颁綇闄俊鎭紝鎮h�呯紪鍙凤細{}锛屾祦姘村彿锛歿}", patArchive.getPatientno(), patMedInhosp.getSerialnum()); - } else { - patMedInhospService.insertPatMedInhosp(patMedInhosp); - log.debug("銆恜rocessPatientInhospInfo銆戞柊澧炰綇闄俊鎭紝鎮h�呯紪鍙凤細{}锛屾祦姘村彿锛歿}", patArchive.getPatientno(), patMedInhosp.getSerialnum()); - } - } - - /** - * 鏋勫缓鎮h�呬綇闄俊鎭� - */ - private PatMedInhosp buildPatientInhospInfo(ThiedInhospInfo thiedInhospInfo, PatArchive patArchive, String cry) { - PatMedInhosp patMedInhosp = new PatMedInhosp(); - - // 鎮h�呭熀鏈俊鎭� - patMedInhosp.setPatid(patArchive.getId()); - patMedInhosp.setPatno(patArchive.getPatientno()); - patMedInhosp.setPatname(patArchive.getName()); - - // 鎶ょ悊淇℃伅 - patMedInhosp.setNurseId(thiedInhospInfo.getNurseId()); - patMedInhosp.setNurseName(thiedInhospInfo.getNurseName()); - - // 浣忛櫌淇℃伅 - patMedInhosp.setSerialnum(thiedInhospInfo.getInpatientId()); - patMedInhosp.setFuflag("1"); - patMedInhosp.setInhospstate("0".equals(cry) ? "0" : "1"); - - // 鍖婚櫌鍜屽簥浣嶄俊鎭� - patMedInhosp.setHospitalcode(thiedInhospInfo.getAreaId()); - patMedInhosp.setBedNo(thiedInhospInfo.getAdmissBedNo()); - - - // 鏃堕棿淇℃伅 - if (StringUtils.isNotEmpty(thiedInhospInfo.getAdmissDate())) { - try { - patMedInhosp.setStarttime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(thiedInhospInfo.getAdmissDate())); - } catch (ParseException e) { - log.warn("銆恇uildPatientInhospInfo銆戣В鏋愬叆闄㈡椂闂村け璐ワ細{}", thiedInhospInfo.getAdmissDate(), e); - } - } - - if (StringUtils.isNotEmpty(thiedInhospInfo.getOutDate())) { - try { - patMedInhosp.setEndtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(thiedInhospInfo.getOutDate())); - } catch (ParseException e) { - log.warn("銆恇uildPatientInhospInfo銆戣В鏋愬嚭闄㈡椂闂村け璐ワ細{}", thiedInhospInfo.getOutDate(), e); - } - } - - // 鍑洪櫌淇℃伅 - if (cry.equals("1")) { - patMedInhosp.setLeaveldeptcode(thiedInhospInfo.getCurrDeptId()); - patMedInhosp.setLeaveldeptname(thiedInhospInfo.getCurrDeptName()); - patMedInhosp.setLeavediagname(thiedInhospInfo.getDiagName()); - patMedInhosp.setLeaveicd10code(thiedInhospInfo.getDiagIcd10()); - patMedInhosp.setOutWayId(thiedInhospInfo.getOutWayId()); - patMedInhosp.setOutWayName(thiedInhospInfo.getOutWayName()); - // 鐥呭尯淇℃伅 - patMedInhosp.setLeavehospitaldistrictid(thiedInhospInfo.getCurrWardCode()); - patMedInhosp.setLeavehospitaldistrictcode(thiedInhospInfo.getCurrWardId()); - patMedInhosp.setLeavehospitaldistrictname(thiedInhospInfo.getCurrWardName()); - patMedInhosp.setLeaveldeptid(thiedInhospInfo.getCurrDeptCode()); - } else { - //鍏ラ櫌 - patMedInhosp.setDeptcode(thiedInhospInfo.getCurrDeptId()); - patMedInhosp.setDeptname(thiedInhospInfo.getCurrDeptName()); - patMedInhosp.setDiagname(thiedInhospInfo.getDiagName()); - patMedInhosp.setIcd10code(thiedInhospInfo.getDiagIcd10()); - patMedInhosp.setHospitaldistrictid(thiedInhospInfo.getAdmissWardCode()); - patMedInhosp.setHospitaldistrictcode(thiedInhospInfo.getAdmissWardId()); - patMedInhosp.setHospitaldistrictname(thiedInhospInfo.getAdmissWardName()); - } - - // 鍖荤敓淇℃伅 - patMedInhosp.setDrname(thiedInhospInfo.getDoctName()); - patMedInhosp.setDrcode(thiedInhospInfo.getDoctId()); - - - // 鐘舵�佷俊鎭� - patMedInhosp.setSchemestatus("0".equals(cry) ? 1L : 2L); - - // 绯荤粺瀛楁 - patMedInhosp.setDelFlag("0"); - patMedInhosp.setOrgid("1"); - - return patMedInhosp; - } - private String getKey() { Map<String, String> map = new HashMap<>(); diff --git a/smartor/src/main/java/com/smartor/domain/HnDataGatherVO.java b/smartor/src/main/java/com/smartor/domain/HnDataGatherVO.java new file mode 100644 index 0000000..a0acdb0 --- /dev/null +++ b/smartor/src/main/java/com/smartor/domain/HnDataGatherVO.java @@ -0,0 +1,40 @@ +package com.smartor.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; +import java.util.List; + +/** + * 娌冲崡鏁版嵁閲囬泦鍏ュ弬瀵硅薄 + * + * @author smartor + * @date 2023-03-04 + */ +@ApiModel(value = "HnDataGatherVO", description = "娌冲崡鏁版嵁閲囬泦鍏ュ弬瀵硅薄") +@Data +public class HnDataGatherVO extends BaseEntity { + + /** + * 寮�濮嬪嚭闄㈡棩鏈� + */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = " ", width = 30, dateFormat = "yyyy-MM-dd") + @ApiModelProperty(value = "寮�濮嬪嚭闄㈡棩鏈�") + private Date startOutHospTime; + + /** + * 缁撴潫鍑洪櫌鏃ユ湡 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = " ", width = 30, dateFormat = "yyyy-MM-dd") + @ApiModelProperty(value = "缁撴潫鍑洪櫌鏃ユ湡") + private Date endOutHospTime; + + +} diff --git a/smartor/src/main/java/com/smartor/service/IHNGatherPatArchiveService.java b/smartor/src/main/java/com/smartor/service/IHNGatherPatArchiveService.java index 44427b0..40234b9 100644 --- a/smartor/src/main/java/com/smartor/service/IHNGatherPatArchiveService.java +++ b/smartor/src/main/java/com/smartor/service/IHNGatherPatArchiveService.java @@ -32,6 +32,14 @@ public Integer selectPatMedInhospList(PatMedInhosp patMedInhosp); /** + * 娌冲崡鏁版嵁閲囬泦 + * + * @param patMedInhosp + * @return + */ + public Boolean hnDataGather(HnDataGatherVO patMedInhosp); + + /** * 闂ㄦ�ヨ瘖淇℃伅 * * @param id diff --git a/smartor/src/main/java/com/smartor/service/IXHGatherPatArchiveService.java b/smartor/src/main/java/com/smartor/service/IXHGatherPatArchiveService.java new file mode 100644 index 0000000..b5ac057 --- /dev/null +++ b/smartor/src/main/java/com/smartor/service/IXHGatherPatArchiveService.java @@ -0,0 +1,27 @@ +package com.smartor.service; + +import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.smartor.domain.*; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 娌冲崡閲囬泦鎮h�呬俊鎭帴鍙� + * + * @author smartor + * @date 2023-03-04 + */ +public interface IXHGatherPatArchiveService { + + /** + * 娌冲崡鏁版嵁閲囬泦 + * + * @param patMedInhosp + * @return + */ + public void getInHospDataGather(String cry, LocalDateTime startTime, LocalDateTime endTime); + + +} diff --git a/smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java index 2cb62f0..934a87a 100644 --- a/smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java +++ b/smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java @@ -14,6 +14,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Service; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.*; /** @@ -106,6 +109,30 @@ return 0; } + @Override + public Boolean hnDataGather(HnDataGatherVO hnDataGatherVO) { + + LocalDate startDate = hnDataGatherVO.getStartOutHospTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + LocalDate endDate = hnDataGatherVO.getEndOutHospTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + + Integer po = null; + // 寰幆澶勭悊姣忎竴澶� + for (LocalDate currentDate = startDate; !currentDate.isAfter(endDate); currentDate = currentDate.plusDays(1)) { + PatMedInhosp dailyCondition = new PatMedInhosp(); + LocalDateTime dayStart = currentDate.atStartOfDay(); + LocalDateTime dayEnd = currentDate.atTime(23, 59, 59); + dailyCondition.setStartOutHospTime(Date.from(dayStart.atZone(ZoneId.systemDefault()).toInstant())); + dailyCondition.setEndOutHospTime(Date.from(dayEnd.atZone(ZoneId.systemDefault()).toInstant())); + Integer pi = selectPatMedInhospList(dailyCondition); + + PatMedOuthosp patMedOuthosp = new PatMedOuthosp(); + patMedOuthosp.setBeginTime(Date.from(dayStart.atZone(ZoneId.systemDefault()).toInstant())); + patMedOuthosp.setEndTime(Date.from(dayEnd.atZone(ZoneId.systemDefault()).toInstant())); + po = selectPatMedOuthospList(patMedOuthosp); + } + return true; + } + @Override public Integer selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) { diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java index ebc4af6..e4f500d 100644 --- a/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java +++ b/smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java @@ -397,8 +397,6 @@ PatArchive patArchive = addPatArchive(externalInHospPatientInfo, externalInHospPatientAddrInfo, externalInHospPatientLiaisonInfo); - - PatMedInhosp patMedInhosp = new PatMedInhosp(); patMedInhosp.setInhospno(externalInHospPatientInfo.getBingAnHao()); patMedInhosp.setSerialnum(externalInHospPatientInfo.getJiuZhenYWID()); @@ -1201,6 +1199,9 @@ PatArchive patArchive = new PatArchive(); //濡傛灉鏄垰鍑虹敓鐨勫皬瀛╁瓙锛屾槸娌℃湁韬唤璇佺殑锛屾�庝箞澶勭悊锛燂紵锛燂紵锛燂紵锛燂紵 patArchive.setIdcardno(externalInHospPatientInfo.getZhengJianHM()); + //濡傛灉韬唤璇佷负绌虹殑璇濓紝灏辩敤灏辫瘖鍗″彿浠f浛 + if (StringUtils.isEmpty(externalInHospPatientInfo.getZhengJianHM())) + patArchive.setIdcardno(externalInHospPatientInfo.getJiuZhenKH()); patArchive.setOrgid(externalInHospPatientInfo.getZuZhiJGID()); List<PatArchive> patArchives = null; if (ObjectUtils.isNotEmpty(patArchive.getIdcardno())) diff --git a/smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java new file mode 100644 index 0000000..b55a0a5 --- /dev/null +++ b/smartor/src/main/java/com/smartor/service/impl/XHGatherPatArchiveServiceImpl.java @@ -0,0 +1,445 @@ +package com.smartor.service.impl; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.domain.entity.SysUserDept; +import com.ruoyi.common.core.domain.entity.SysUserRole; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.http.HttpUtils; +import com.smartor.domain.*; +import com.smartor.mapper.*; +import com.smartor.service.IHNGatherPatArchiveService; +import com.smartor.service.IPatArchiveService; +import com.smartor.service.IPatMedInhospService; +import com.smartor.service.IXHGatherPatArchiveService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.File; +import java.io.FileWriter; +import java.lang.reflect.Type; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.*; + +/** + * 鏂板崕鏁版嵁閲囬泦澶勭悊 + * + * @author smartor + * @date 2023-03-04 + */ +@Slf4j +@Service +public class XHGatherPatArchiveServiceImpl implements IXHGatherPatArchiveService { + + @Value("${hosp_info_url}") + private String hospInfoUrl; + + + @Autowired + IPatMedInhospService patMedInhospService; + + @Autowired + IPatArchiveService patArchiveService; + + /** + * 鑾峰彇鎮h�呭嚭鍏ラ櫌淇℃伅 + * + * @param cry 鍑哄叆闄㈢被鍨嬶細0-鍏ラ櫌锛�1-鍑洪櫌 + * @param startTime 寮�濮嬫椂闂� + * @param endTime 缁撴潫鏃堕棿 + */ + @Transactional + public void getInHospDataGather(String cry, LocalDateTime startTime, LocalDateTime endTime) { + String typeName = "0".equals(cry) ? "鍏ラ櫌" : "鍑洪櫌"; + log.info("銆恎etInHospInfo銆戝紑濮嬭幏鍙杮}鎮h�呬俊鎭紝鏃堕棿鑼冨洿锛歿} ~ {}", typeName, startTime, endTime); + long startTimeMillis = System.currentTimeMillis(); + + try { + // 绗竴姝ワ細鏋勫缓璇锋眰鍙傛暟骞惰皟鐢℉IS鎺ュ彛 + List<ThiedInhospInfo> thiedInhospInfoList = fetchHisData(cry, startTime, endTime); + + if (CollectionUtils.isEmpty(thiedInhospInfoList)) { + log.info("銆恎etInHospInfo銆憑}鎮h�呬俊鎭负绌猴紝璺宠繃澶勭悊", typeName); + return; + } + + log.info("銆恎etInHospInfo銆戣幏鍙栧埌{}鏉}鎮h�呬俊鎭�", thiedInhospInfoList.size(), typeName); + + // 绗簩姝ワ細淇濆瓨鍘熷鏁版嵁鍒版枃浠讹紙鐢ㄤ簬澶囦唤锛� + saveRawDataToFile(cry, thiedInhospInfoList); + + // 绗笁姝ワ細澶勭悊鎮h�呮暟鎹� + processPatientData(thiedInhospInfoList, cry); + + long endTimeMillis = System.currentTimeMillis(); + log.info("銆恎etInHospInfo銆憑}鎮h�呬俊鎭鐞嗗畬鎴愶紝鑰楁椂锛歿}ms", typeName, endTimeMillis - startTimeMillis); + + } catch (Exception e) { + log.error("銆恎etInHospInfo銆戣幏鍙杮}鎮h�呬俊鎭紓甯�", typeName, e); + throw new RuntimeException("鑾峰彇" + typeName + "鎮h�呬俊鎭け璐�", e); + } + } + + + /** + * 绗竴姝ワ細璋冪敤HIS鎺ュ彛鑾峰彇鏁版嵁 + */ + private List<ThiedInhospInfo> fetchHisData(String cry, LocalDateTime startTime, LocalDateTime endTime) { + try { + // 鏋勫缓璇锋眰鍙傛暟 + Map<String, String> requestParams = buildRequestParams(cry, startTime, endTime); + + // 鏋勫缓璇锋眰澶� + Map<String, String> headers = buildRequestHeaders(startTime); + + // 鍙戦�丠TTP璇锋眰 + String result = HttpUtils.sendPostByHeader(hospInfoUrl, new Gson().toJson(requestParams), headers); + + // 瑙f瀽鍝嶅簲鏁版嵁 + return parseResponseData(result); + + } catch (Exception e) { + log.error("銆恌etchHisData銆戣皟鐢℉IS鎺ュ彛寮傚父", e); + throw e; + } + } + + /** + * 绗簩姝ワ細淇濆瓨鍘熷鏁版嵁鍒版枃浠� + */ + private void saveRawDataToFile(String cry, List<ThiedInhospInfo> dataList) { + try { + String typeName = "0".equals(cry) ? "鍏ラ櫌淇℃伅" : "鍑洪櫌淇℃伅"; + String filename = typeName + "_" + System.currentTimeMillis() + ".json"; + String filePath = "D:\\public\\HIS鏁版嵁閲囬泦\\" + filename; + + File file = new File(filePath); + File parentDir = file.getParentFile(); + if (!parentDir.exists()) { + parentDir.mkdirs(); + } + + if (!file.exists()) { + file.createNewFile(); + } + + // 灏嗘暟鎹啓鍏ユ枃浠� + try (FileWriter writer = new FileWriter(file)) { + writer.write(new Gson().toJson(dataList)); + } + + log.info("銆恠aveRawDataToFile銆戝師濮嬫暟鎹凡淇濆瓨鍒版枃浠讹細{}", filePath); + + } catch (Exception e) { + log.error("銆恠aveRawDataToFile銆戜繚瀛樺師濮嬫暟鎹埌鏂囦欢寮傚父", e); + // 鏂囦欢淇濆瓨澶辫触涓嶅奖鍝嶄富娴佺▼锛屽彧璁板綍鏃ュ織 + } + } + + /** + * 绗笁姝ワ細澶勭悊鎮h�呮暟鎹� + */ + private void processPatientData(List<ThiedInhospInfo> thiedInhospInfoList, String cry) { + int successCount = 0; + int skipCount = 0; + int errorCount = 0; + + for (ThiedInhospInfo thiedInhospInfo : thiedInhospInfoList) { + try { + if (processSinglePatient(thiedInhospInfo, cry)) { + successCount++; + } else { + skipCount++; + } + } catch (Exception e) { + errorCount++; + log.error("銆恜rocessPatientData銆戝鐞嗘偅鑰呮暟鎹紓甯革紝鎮h�匢D锛歿}", thiedInhospInfo.getPatiMediaNo(), e); + } + } + + log.info("銆恜rocessPatientData銆戞偅鑰呮暟鎹鐞嗗畬鎴愶紝鎴愬姛锛歿}锛岃烦杩囷細{}锛屽け璐ワ細{}", successCount, skipCount, errorCount); + } + + /** + * 鏋勫缓璇锋眰澶� + */ + private Map<String, String> buildRequestHeaders(LocalDateTime startTime) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); + Map<String, String> header = new HashMap<>(); + header.put("x-hcsb-serviceno", "IS002347"); + header.put("x-hcsb-version", "2.0"); + header.put("x-hcsb-sourcesyscode", "14"); + header.put("x-hcsb-token", "ArGE2JnHtxG/Zx5nrnGY4eOfMUJGGJokAJHigG1BrCY="); + header.put("x-hcsb-msgdate", startTime.format(formatter)); + return header; + } + + + /** + * 鏋勫缓璇锋眰鍙傛暟 + */ + private Map<String, String> buildRequestParams(String cry, LocalDateTime startTime, LocalDateTime endTime) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); + Map<String, String> req = new HashMap<>(); + + if ("1".equals(cry)) { + // 鍑洪櫌鍙傛暟 + req.put("cashStartDate", startTime.format(formatter)); + req.put("cashEndDate", endTime.format(formatter)); + req.put("currStatus", "4"); + } else { + // 鍏ラ櫌鍙傛暟 + req.put("admissStartDate", startTime.format(formatter)); + req.put("admissEndDate", endTime.format(formatter)); + req.put("currStatus", "2"); + } + + return req; + } + + /** + * 瑙f瀽鍝嶅簲鏁版嵁 + */ + private List<ThiedInhospInfo> parseResponseData(String result) { + try { + Gson gson = new Gson(); + JsonObject jsonObject = gson.fromJson(result, JsonObject.class); + JsonArray resultArray = jsonObject.getAsJsonObject("data").getAsJsonArray("result"); + Type resultType = new TypeToken<List<ThiedInhospInfo>>() { + }.getType(); + return gson.fromJson(resultArray, resultType); + } catch (Exception e) { + log.error("銆恜arseResponseData銆戣В鏋愬搷搴旀暟鎹紓甯革紝鍘熷鏁版嵁锛歿}", result, e); + throw e; + } + } + + + /** + * 澶勭悊鍗曚釜鎮h�呮暟鎹� + */ + private boolean processSinglePatient(ThiedInhospInfo thiedInhospInfo, String cry) { + // 楠岃瘉韬唤璇佸彿 + if (StringUtils.isEmpty(thiedInhospInfo.getPatiIdCardNo())) { + log.warn("銆恜rocessSinglePatient銆戞偅鑰呰韩浠借瘉鍙蜂负绌猴紝璺宠繃澶勭悊锛屾偅鑰呯紪鍙凤細{}", thiedInhospInfo.getPatiMediaNo()); + return false; + } + + // 澶勭悊鎮h�呮。妗堜俊鎭� + PatArchive patArchive = processPatientArchive(thiedInhospInfo, cry); + + // 澶勭悊鎮h�呬綇闄俊鎭� + processPatientInhospInfo(thiedInhospInfo, patArchive, cry); + + return true; + } + + /** + * 澶勭悊鎮h�呮。妗堜俊鎭� + */ + private PatArchive processPatientArchive(ThiedInhospInfo thiedInhospInfo, String cry) { + // 鏌ヨ鎮h�呮槸鍚﹀凡瀛樺湪 + PatArchive queryArchive = new PatArchive(); + queryArchive.setIdcardno(thiedInhospInfo.getPatiIdCardNo().trim()); + List<PatArchive> existingArchives = patArchiveService.selectPatArchiveList(queryArchive); + + // 鏋勫缓鎮h�呮。妗堜俊鎭� + PatArchive patArchive = buildPatientArchive(thiedInhospInfo, cry); + + // 淇濆瓨鎴栨洿鏂版偅鑰呮。妗� + if (CollectionUtils.isEmpty(existingArchives)) { + patArchiveService.insertPatArchive(patArchive); + log.debug("銆恜rocessPatientArchive銆戞柊澧炴偅鑰呮。妗堬紝鎮h�呯紪鍙凤細{}", patArchive.getPatientno()); + } else { + patArchive.setId(existingArchives.get(0).getId()); + patArchiveService.updateArchive(patArchive); + log.debug("銆恜rocessPatientArchive銆戞洿鏂版偅鑰呮。妗堬紝鎮h�呯紪鍙凤細{}", patArchive.getPatientno()); + } + + return patArchive; + } + + /** + * 澶勭悊鎮h�呬綇闄俊鎭� + */ + private void processPatientInhospInfo(ThiedInhospInfo thiedInhospInfo, PatArchive patArchive, String cry) { + // 鏋勫缓浣忛櫌淇℃伅 + PatMedInhosp patMedInhosp = buildPatientInhospInfo(thiedInhospInfo, patArchive, cry); + + // 鏌ヨ鏄惁宸插瓨鍦ㄤ綇闄㈣褰� + PatMedInhosp queryInhosp = new PatMedInhosp(); + queryInhosp.setPatno(patArchive.getPatientno()); + queryInhosp.setSerialnum(patMedInhosp.getSerialnum()); + List<PatMedInhosp> existingInhosps = patMedInhospService.selectPatMedInhospList(queryInhosp); + + // 淇濆瓨鎴栨洿鏂颁綇闄俊鎭� + if (CollectionUtils.isNotEmpty(existingInhosps)) { + patMedInhosp.setInhospid(existingInhosps.get(0).getInhospid()); + patMedInhospService.updatePatMedInhosp(patMedInhosp); + log.debug("銆恜rocessPatientInhospInfo銆戞洿鏂颁綇闄俊鎭紝鎮h�呯紪鍙凤細{}锛屾祦姘村彿锛歿}", patArchive.getPatientno(), patMedInhosp.getSerialnum()); + } else { + patMedInhospService.insertPatMedInhosp(patMedInhosp); + log.debug("銆恜rocessPatientInhospInfo銆戞柊澧炰綇闄俊鎭紝鎮h�呯紪鍙凤細{}锛屾祦姘村彿锛歿}", patArchive.getPatientno(), patMedInhosp.getSerialnum()); + } + } + + + /** + * 鏋勫缓鎮h�呬綇闄俊鎭� + */ + private PatMedInhosp buildPatientInhospInfo(ThiedInhospInfo thiedInhospInfo, PatArchive patArchive, String cry) { + PatMedInhosp patMedInhosp = new PatMedInhosp(); + + // 鎮h�呭熀鏈俊鎭� + patMedInhosp.setPatid(patArchive.getId()); + patMedInhosp.setPatno(patArchive.getPatientno()); + patMedInhosp.setPatname(patArchive.getName()); + + // 鎶ょ悊淇℃伅 + patMedInhosp.setNurseId(thiedInhospInfo.getNurseId()); + patMedInhosp.setNurseName(thiedInhospInfo.getNurseName()); + + // 浣忛櫌淇℃伅 + patMedInhosp.setSerialnum(thiedInhospInfo.getInpatientId()); + patMedInhosp.setFuflag("1"); + patMedInhosp.setInhospstate("0".equals(cry) ? "0" : "1"); + + // 鍖婚櫌鍜屽簥浣嶄俊鎭� + patMedInhosp.setHospitalcode(thiedInhospInfo.getAreaId()); + patMedInhosp.setBedNo(thiedInhospInfo.getAdmissBedNo()); + + + // 鏃堕棿淇℃伅 + if (StringUtils.isNotEmpty(thiedInhospInfo.getAdmissDate())) { + try { + patMedInhosp.setStarttime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(thiedInhospInfo.getAdmissDate())); + } catch (ParseException e) { + log.warn("銆恇uildPatientInhospInfo銆戣В鏋愬叆闄㈡椂闂村け璐ワ細{}", thiedInhospInfo.getAdmissDate(), e); + } + } + + if (StringUtils.isNotEmpty(thiedInhospInfo.getOutDate())) { + try { + patMedInhosp.setEndtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(thiedInhospInfo.getOutDate())); + } catch (ParseException e) { + log.warn("銆恇uildPatientInhospInfo銆戣В鏋愬嚭闄㈡椂闂村け璐ワ細{}", thiedInhospInfo.getOutDate(), e); + } + } + + // 鍑洪櫌淇℃伅 + if (cry.equals("1")) { + patMedInhosp.setLeaveldeptcode(thiedInhospInfo.getCurrDeptId()); + patMedInhosp.setLeaveldeptname(thiedInhospInfo.getCurrDeptName()); + patMedInhosp.setLeavediagname(thiedInhospInfo.getDiagName()); + patMedInhosp.setLeaveicd10code(thiedInhospInfo.getDiagIcd10()); + patMedInhosp.setOutWayId(thiedInhospInfo.getOutWayId()); + patMedInhosp.setOutWayName(thiedInhospInfo.getOutWayName()); + // 鐥呭尯淇℃伅 + patMedInhosp.setLeavehospitaldistrictid(thiedInhospInfo.getCurrWardCode()); + patMedInhosp.setLeavehospitaldistrictcode(thiedInhospInfo.getCurrWardId()); + patMedInhosp.setLeavehospitaldistrictname(thiedInhospInfo.getCurrWardName()); + patMedInhosp.setLeaveldeptid(thiedInhospInfo.getCurrDeptCode()); + } else { + //鍏ラ櫌 + patMedInhosp.setDeptcode(thiedInhospInfo.getCurrDeptId()); + patMedInhosp.setDeptname(thiedInhospInfo.getCurrDeptName()); + patMedInhosp.setDiagname(thiedInhospInfo.getDiagName()); + patMedInhosp.setIcd10code(thiedInhospInfo.getDiagIcd10()); + patMedInhosp.setHospitaldistrictid(thiedInhospInfo.getAdmissWardCode()); + patMedInhosp.setHospitaldistrictcode(thiedInhospInfo.getAdmissWardId()); + patMedInhosp.setHospitaldistrictname(thiedInhospInfo.getAdmissWardName()); + } + + // 鍖荤敓淇℃伅 + patMedInhosp.setDrname(thiedInhospInfo.getDoctName()); + patMedInhosp.setDrcode(thiedInhospInfo.getDoctId()); + + + // 鐘舵�佷俊鎭� + patMedInhosp.setSchemestatus("0".equals(cry) ? 1L : 2L); + + // 绯荤粺瀛楁 + patMedInhosp.setDelFlag("0"); + patMedInhosp.setOrgid("1"); + + return patMedInhosp; + } + + + /** + * 鏋勫缓鎮h�呮。妗堜俊鎭� + */ + private PatArchive buildPatientArchive(ThiedInhospInfo thiedInhospInfo, String cry) { + PatArchive patArchive = new PatArchive(); + + // 鍩烘湰淇℃伅 + patArchive.setPatientno(thiedInhospInfo.getPatiMediaNo()); + patArchive.setIdcardno(thiedInhospInfo.getPatiIdCardNo().trim()); + patArchive.setName(thiedInhospInfo.getPatiRecordName()); + patArchive.setSourcefrom(2); + patArchive.setPattype("2"); + + // 鎬у埆 + patArchive.setSex("鐢�".equals(thiedInhospInfo.getPatiRecordGender()) ? 1L : 2L); + + // 姘戞棌鍜岀睄璐� + patArchive.setNation(thiedInhospInfo.getPatiNation()); + patArchive.setNativePlace(thiedInhospInfo.getPatiNationality()); + + // 灞呬綇鍦板潃 + String homeAddr = thiedInhospInfo.getPatiHomeAddr(); + patArchive.setPlaceOfResidence(StringUtils.isNotEmpty(homeAddr) ? homeAddr.replace("null", "") : ""); + + // 鍑虹敓鏃ユ湡 + if (StringUtils.isNotEmpty(thiedInhospInfo.getPatiBirthday())) { + try { + patArchive.setBirthdate(new SimpleDateFormat("yyyy-MM-dd").parse(thiedInhospInfo.getPatiBirthday())); + } catch (ParseException e) { + log.warn("銆恇uildPatientArchive銆戣В鏋愬嚭鐢熸棩鏈熷け璐ワ細{}", thiedInhospInfo.getPatiBirthday(), e); + } + } + + // 骞撮緞 + if (thiedInhospInfo.getTreateAge() != null) { + patArchive.setAge(Long.valueOf(thiedInhospInfo.getTreateAge())); + } + patArchive.setAgeUnit(thiedInhospInfo.getTreatAgeunit()); + + // 鑱旂郴鏂瑰紡 + patArchive.setTelcode(thiedInhospInfo.getCompanyTelNum()); + patArchive.setRelativetelcode(thiedInhospInfo.getContactPersonPhone()); + + // 鍑洪櫌鏂瑰紡澶勭悊锛堟浜$瓑鐗规畩鎯呭喌锛� + if (StringUtils.isNotEmpty(thiedInhospInfo.getOutWayId()) && "4".equals(thiedInhospInfo.getOutWayId())) { + patArchive.setNotrequiredFlag("1"); + patArchive.setNotrequiredreason(thiedInhospInfo.getOutWayName()); + } + if ("1".equals(cry) && StringUtils.isEmpty(thiedInhospInfo.getOutWayId())) { + patArchive.setNotrequiredFlag("1"); + patArchive.setNotrequiredreason("鍑洪櫌鏂瑰紡涓虹┖"); + } + + // 绯荤粺瀛楁 + patArchive.setDelFlag("0"); + patArchive.setCreateTime(new Date()); + patArchive.setUpdateTime(new Date()); + + return patArchive; + } +} + + -- Gitblit v1.9.3