| | |
| | | import com.google.common.reflect.TypeToken; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonArray; |
| | | import com.google.gson.JsonElement; |
| | | 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.HttpUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | | import com.ruoyi.system.mapper.SysConfigMapper; |
| | | 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 com.smartor.service.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.lang.reflect.Type; |
| | | import java.net.URLEncoder; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | |
| | | |
| | | @Value("${hosp_info_url}") |
| | | private String hospInfoUrl; |
| | | |
| | | |
| | | @Autowired |
| | | IPatMedInhospService patMedInhospService; |
| | | |
| | | @Autowired |
| | | IPatArchiveService patArchiveService; |
| | | @Autowired |
| | | IServiceAppointRecordService iServiceAppointRecordService; |
| | | @Autowired |
| | | private SysConfigMapper sysConfigMapper; |
| | | @Value("${xhsmsPath}") |
| | | private String xhsmsPath; |
| | | // 帐号 |
| | | @Value("${xhsmsAccount}") |
| | | private String xhsmsAccount; |
| | | // 接口密码 |
| | | @Value("${xhsmsPwd}") |
| | | private String xhsmsPwd; |
| | | // 虚拟接入码 |
| | | @Value("${xhsmsjrm}") |
| | | private String xhsmsjrm; |
| | | |
| | | |
| | | /** |
| | | * 获取患者出入院信息 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取预约停诊记录信息 |
| | | * |
| | | * @param cry 出入院类型:0-入院,1-出院 2,预约记录 |
| | | * @param startTime 开始时间 |
| | | * @param endTime 结束时间 |
| | | */ |
| | | public void getAppointRecordInfo(String cry, LocalDateTime startTime, LocalDateTime endTime) { |
| | | log.info("【getAppointRecordInfo】开始获取取预约停诊记录信息,时间范围:{} ~ {}", startTime, endTime); |
| | | long startTimeMillis = System.currentTimeMillis(); |
| | | |
| | | try { |
| | | // 第一步:构建请求参数并调用HIS接口 |
| | | List<ServiceAppointRecord> appointRecordFromHIS = getAppointRecordFromHIS(cry, startTime, endTime); |
| | | |
| | | if (CollectionUtils.isEmpty(appointRecordFromHIS)) { |
| | | log.info("【getAppointRecordInfo】获取预约停诊记录信息为空,跳过处理"); |
| | | return; |
| | | } |
| | | log.info("【getAppointRecordInfo】获取预约停诊记录信息{}条", appointRecordFromHIS.size()); |
| | | SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("yytz.sms.template"); |
| | | if (sysConfig != null) { |
| | | String smsContemt = sysConfig.getConfigValue(); |
| | | // 第二步:处理停诊记录信息 |
| | | for (ServiceAppointRecord serviceAppointRecord : appointRecordFromHIS) { |
| | | String replace = smsContemt.replace("${patFileName}", StringUtils.defaultString(serviceAppointRecord.getPatFileName())).replace("${registTimeRange}", StringUtils.defaultString(serviceAppointRecord.getRegistTimeRange())).replace("${registDeptName}", StringUtils.defaultString(serviceAppointRecord.getRegistDeptName())).replace("${treatDoctName}", StringUtils.defaultString(serviceAppointRecord.getTreatDoctName())); |
| | | Map<String, String> map2 = new HashMap<String, String>(); |
| | | map2.put("action", "send"); |
| | | map2.put("account", xhsmsAccount); |
| | | map2.put("password", xhsmsPwd); |
| | | map2.put("mobile", serviceAppointRecord.getPatTel()); |
| | | map2.put("content", replace); |
| | | map2.put("extno", xhsmsjrm); |
| | | map2.put("rt", "json"); |
| | | StringBuilder encodedParams = new StringBuilder(); |
| | | |
| | | for (Map.Entry<String, String> entry : map2.entrySet()) { |
| | | if (encodedParams.length() > 0) { |
| | | encodedParams.append("&"); |
| | | } |
| | | // 对键和值进行URL编码 |
| | | String encodedKey = URLEncoder.encode(entry.getKey(), "UTF-8"); |
| | | String encodedValue = URLEncoder.encode(entry.getValue(), "UTF-8"); |
| | | encodedParams.append(encodedKey).append("=").append(encodedValue); |
| | | } |
| | | Boolean isSuccess = HttpUtils.sendPost(xhsmsPath, encodedParams.toString()); |
| | | if (isSuccess) { |
| | | log.info("---处理停诊记录信息发送成功,入参为:{}", encodedParams.toString()); |
| | | serviceAppointRecord.setSendTime(new Date()); |
| | | serviceAppointRecord.setSenderName("系统管理员"); |
| | | iServiceAppointRecordService.insertServiceAppointRecord(serviceAppointRecord); |
| | | } else { |
| | | log.info("处理停诊记录信息发送失败"); |
| | | iServiceAppointRecordService.insertServiceAppointRecord(serviceAppointRecord); |
| | | } |
| | | } |
| | | } |
| | | long endTimeMillis = System.currentTimeMillis(); |
| | | log.info("【getAppointRecordInfo】{},预约停诊记录信息处理完成,耗时:{}ms", endTimeMillis - startTimeMillis); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("【getAppointRecordInfo】获取预约停诊记录信息处理异常", e); |
| | | throw new RuntimeException("获取预约停诊记录信息处理异常", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 第一步:调用HIS接口获取数据 |
| | |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | |
| | | private List<ServiceAppointRecord> getAppointRecordFromHIS(String cry, LocalDateTime startTime, LocalDateTime endTime) { |
| | | try { |
| | | // 构建请求参数 |
| | | Map<String, String> requestParams = buildRequestParams(cry, startTime, endTime); |
| | | |
| | | // 构建请求头 |
| | | Map<String, String> headers = buildRequestHeaders(startTime); |
| | | |
| | | // 发送HTTP请求 |
| | | log.info("【getAppointRecordFromHIS】发送HTTP请求,请求参数:{},请求地址:{}", new Gson().toJson(requestParams), hospInfoUrl); |
| | | String result = HttpUtils.sendPostByHeader(hospInfoUrl, new Gson().toJson(requestParams), headers); |
| | | |
| | | // 解析响应数据 |
| | | return parseResponseData2(result); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("【fetchHisData】调用HIS接口异常", e); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 第二步:保存原始数据到文件 |
| | |
| | | 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-serviceno", "IS044056"); |
| | | // 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="); |
| | |
| | | req.put("cashStartDate", startTime.format(formatter)); |
| | | req.put("cashEndDate", endTime.format(formatter)); |
| | | req.put("currStatus", "4"); |
| | | } else { |
| | | } else if ("0".equals(cry)) { |
| | | // 入院参数 |
| | | req.put("admissStartDate", startTime.format(formatter)); |
| | | req.put("admissEndDate", endTime.format(formatter)); |
| | | req.put("currStatus", "2"); |
| | | } else if ("2".equals(cry)) { |
| | | // 预约记录查询 |
| | | req.put("appointRegistDateBegin", startTime.format(formatter)); |
| | | req.put("appointRegistDateEnd", endTime.format(formatter)); |
| | | // 排班停诊 (预约状态标志(0:已预约 1:已挂号 2:已退号 3:已就诊 -1:病人取消 -2:医院取消 -3:排班停诊)) |
| | | req.put("scheduleStatusFlag", "-3"); |
| | | } |
| | | |
| | | return req; |
| | |
| | | try { |
| | | Gson gson = new Gson(); |
| | | JsonObject jsonObject = gson.fromJson(result, JsonObject.class); |
| | | JsonArray resultArray = jsonObject.getAsJsonObject("data").getAsJsonArray("result"); |
| | | |
| | | // 校验data字段是否为JsonObject |
| | | JsonElement dataElement = jsonObject.get("data"); |
| | | if (dataElement == null || !dataElement.isJsonObject()) { |
| | | log.warn("【parseResponseData】响应数据中data字段为空或非对象类型,原始数据:{}", result); |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | JsonObject dataObject = dataElement.getAsJsonObject(); |
| | | JsonElement resultElement = dataObject.get("result"); |
| | | if (resultElement == null || !resultElement.isJsonArray()) { |
| | | log.warn("【parseResponseData】响应数据中result字段为空或非数组类型,原始数据:{}", result); |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | JsonArray resultArray = resultElement.getAsJsonArray(); |
| | | Type resultType = new TypeToken<List<ThiedInhospInfo>>() { |
| | | }.getType(); |
| | | return gson.fromJson(resultArray, resultType); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 解析响应数据 |
| | | */ |
| | | private List<ServiceAppointRecord> parseResponseData2(String result) { |
| | | try { |
| | | Gson gson = new Gson(); |
| | | JsonObject jsonObject = gson.fromJson(result, JsonObject.class); |
| | | |
| | | // 校验data字段是否为JsonObject |
| | | JsonElement dataElement = jsonObject.get("data"); |
| | | if (dataElement == null || !dataElement.isJsonObject()) { |
| | | log.warn("【parseResponseData2】响应数据中data字段为空或非对象类型,原始数据:{}", result); |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | JsonObject dataObject = dataElement.getAsJsonObject(); |
| | | JsonElement resultElement = dataObject.get("result"); |
| | | if (resultElement == null || !resultElement.isJsonArray()) { |
| | | log.warn("【parseResponseData2】响应数据中result字段为空或非数组类型,原始数据:{}", result); |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | JsonArray resultArray = resultElement.getAsJsonArray(); |
| | | Type resultType = new TypeToken<List<ServiceAppointRecord>>() { |
| | | }.getType(); |
| | | return gson.fromJson(resultArray, resultType); |
| | | } catch (Exception e) { |
| | | log.error("【parseResponseData2】解析响应数据异常,原始数据:{}", result, e); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 处理单个患者数据 |