package com.ynxbd.wx.config; import com.alibaba.fastjson.JSONObject; import com.ynxbd.common.bean.me_technology.BookOrder; import com.ynxbd.common.bean.me_technology.BookedInfo; import com.ynxbd.common.bean.me_technology.NumberSourceDetails; import com.ynxbd.common.bean.me_technology.NumberSourceStatistics; import com.ynxbd.common.helper.ProperHelper; import com.ynxbd.common.helper.common.JsonHelper; import com.ynxbd.common.helper.http.OkHttpHelper; import com.ynxbd.common.result.JsonResult; import com.ynxbd.common.result.JsonResultEnum; import com.ynxbd.common.result.Result; import lombok.extern.slf4j.Slf4j; import okhttp3.MediaType; import okhttp3.RequestBody; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author 李进才 * @ClassName MeTechnologyReConfig * @Description TODO * @date 2024/06/14 09:27:00 */ @Slf4j public class MeTechnologyReConfig { private MeTechnologyReConfig() { } public static final String MEDICAL_TECHNOLOGY_RESERVE_WEBSERVICE_URL; public static final String MEDICAL_TECHNOLOGY_RESERVE_TERMINAL_NO; public static final String MEDICAL_TECHNOLOGY_RESERVE_TEST_PATIENT_ID; public static final String MEDICAL_TECHNOLOGY_RESERVE_JSON_URL; public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); static { ProperHelper config = new ProperHelper().read("medical-technology-reserve.properties"); if (config == null) { MEDICAL_TECHNOLOGY_RESERVE_WEBSERVICE_URL = null; MEDICAL_TECHNOLOGY_RESERVE_TERMINAL_NO = null; MEDICAL_TECHNOLOGY_RESERVE_TEST_PATIENT_ID = null; MEDICAL_TECHNOLOGY_RESERVE_JSON_URL = null; } else { MEDICAL_TECHNOLOGY_RESERVE_WEBSERVICE_URL = config.getString("medical_technology_reserve_webservice_url"); MEDICAL_TECHNOLOGY_RESERVE_TERMINAL_NO = config.getString("medical_technology_reserve_terminal_no"); MEDICAL_TECHNOLOGY_RESERVE_TEST_PATIENT_ID = config.getString("medical_technology_reserve_test_patientId"); MEDICAL_TECHNOLOGY_RESERVE_JSON_URL = config.getString("medical_technology_reserve_json_url"); } } public static void reserveRun(String patientId) { try { if (MEDICAL_TECHNOLOGY_RESERVE_WEBSERVICE_URL == null) { return; } if (MEDICAL_TECHNOLOGY_RESERVE_TEST_PATIENT_ID != null) { if (!patientId.equals(MEDICAL_TECHNOLOGY_RESERVE_TEST_PATIENT_ID)) { log.info("[天助预约平台] 不是测试账号,不允许调用接口 patientId-{}", patientId); return; } } String result = OkHttpHelper.get(MEDICAL_TECHNOLOGY_RESERVE_WEBSERVICE_URL, params -> { params.put("patientID", patientId); params.put("terminalNo", MEDICAL_TECHNOLOGY_RESERVE_TERMINAL_NO); }); JsonResult jsonResult = JsonResult.xmlToBean(result, JsonResultEnum.SYS_RESERVE); if (jsonResult == null) { log.info("[天助预约平台] xml转换出错,result-{}", result); return; } if (jsonResult.success()) { log.info("[天助预约平台] 预约成功 message-{}", jsonResult.getMessage()); // MessagePushConfig.businessPush("天助预约平台",patientId,jsonResult.getMessage(),null); } } catch (Exception e) { log.error("[天助预约平台] 调用医技预约出错,error-{}", e.toString()); } } public static String getToken() { String result = OkHttpHelper.get(MEDICAL_TECHNOLOGY_RESERVE_JSON_URL + "/Tools/Tool/GetToken", params -> { params.put("clientName", "WXAPP"); params.put("clientCode", "wxapp"); }); JSONObject jsonObject = JsonHelper.parseObject(result); if (jsonObject == null) { log.info("[天助预约平台] token获取失败,result-{}", result); return null; } String token = jsonObject.getString("token"); log.info("[天助预约平台] token获取成功,token={}", token); return token; } /** * 预约平台提供,终端调用,主要用来获取患者申请单列表,用于预约改约 * * @return 根据患者身份获得开立检查单情况 */ public static Result getCanBookOrders(String patientId, String startDate, String endDate) { Map params = new HashMap<>(); params.put("PatientId", patientId); params.put("StartDate", startDate); params.put("EndDate", endDate); params.put("TerminalNo", MEDICAL_TECHNOLOGY_RESERVE_TERMINAL_NO); params.put("IsBooked", "2"); RequestBody requestBody = RequestBody.create(JSON, JsonHelper.toJsonString(params)); String result = OkHttpHelper.post(MEDICAL_TECHNOLOGY_RESERVE_JSON_URL + "/BookDetails/BookDetails/GetCanBookOrders", requestBody, headers -> { headers.add("token", getToken()); }); JSONObject jsonObject = JsonHelper.parseObject(result); if (jsonObject == null) { log.info("[天助预约平台] patientId-{},startDate-{},endDate-{} 获取患者申请信息失败,result-{}", patientId, startDate, endDate, result); return Result.error(); } if (!"0".equals(jsonObject.getString("ResultCode"))) { log.info("[天助预约平台] 获取患者申请信息失败,失败原因-{}", jsonObject.getString("ResultContent")); return Result.error(jsonObject.getString("ResultCode")); } return Result.success(jsonObject.getJSONArray("OrderLists").toJavaList(BookOrder.class)); } /** * 根据日期范围获得可使用资源概况 * * @param patientId 患者id * @param startDate 开始时间 * @param endDate 结束时间 * @param docDetailedNo 申请单编号 * @param intervalTimeType 上午或者下午 * @return 日期范围获得可使用资源概况 */ public static Result getNumberSourceStatistics(String patientId, String startDate, String endDate, String docDetailedNo, String intervalTimeType) { Map params = new HashMap<>(); params.put("PatientId", patientId); params.put("StartDate", startDate); params.put("EndDate", endDate); params.put("DocDetailedNo", docDetailedNo); params.put("IntervalTimeType", intervalTimeType); String json = JsonHelper.toJsonString(params); RequestBody requestBody = RequestBody.create(JSON, json); String result = OkHttpHelper.post(MEDICAL_TECHNOLOGY_RESERVE_JSON_URL + "/BookDetails/BookDetails/GetNumberSourceStatistics", requestBody, headers -> { headers.add("token", getToken()); }); JSONObject jsonObject = JsonHelper.parseObject(result); if (jsonObject == null) { log.info("[天助预约平台] patientId-{},startDate-{},endDate-{},docDetailedNo-{},intervalTimeType-{} 根据日期范围获得可使用资源概况失败,result-{}", patientId, startDate, endDate, docDetailedNo, intervalTimeType, result); return Result.error(); } if (!"0".equals(jsonObject.getString("resultCode"))) { log.info("[天助预约平台] 根据日期范围获得可使用资源概况失败,失败原因-{}", jsonObject.getString("resultContent")); return Result.error(jsonObject.getString("resultCode")); } return Result.success(jsonObject.getJSONArray("numberSourceStatisticsApplyDTO").toJavaList(NumberSourceStatistics.class)); } /** * 预约平台提供,终端调用,主要用来获取号池明细信息 * * @param examRoomOrQueue 检查室或队列 * @param startDate 开始时间 * @param endDate 结束时间 * @param appFromID 医嘱申请单号 * @return 号池明细信息 */ public static Result getNumberSourceDetails(String examRoomOrQueue, String startDate, String endDate, String appFromID) { JSONObject jsonParams = new JSONObject(); jsonParams.put("examRoomOrQueue", examRoomOrQueue); jsonParams.put("StartDate", startDate); jsonParams.put("EndDate", endDate); jsonParams.put("appFromID", appFromID); RequestBody requestBody = RequestBody.create(JSON, jsonParams.toJSONString()); String result = OkHttpHelper.post(MEDICAL_TECHNOLOGY_RESERVE_JSON_URL + "/BookDetails/BookDetails/GetNumberSourceDetails", requestBody, headers -> { headers.add("token", getToken()); }); JSONObject jsonObject = JsonHelper.parseObject(result); if (jsonObject == null) { log.info("[天助预约平台] examRoomOrQueue-{},startDate-{},endDate-{},appFromID-{}, 获取号池明细失败,result-{}", examRoomOrQueue, startDate, endDate, appFromID, result); return Result.error(); } if (!"0".equals(jsonObject.getString("resultCode"))) { log.info("[天助预约平台] 获取号池明细失败,失败原因-{}", jsonObject.getString("resultContent")); return Result.error(jsonObject.getString("resultCode")); } return Result.success(jsonObject.getJSONArray("numPoolDetailsDTOList").toJavaList(NumberSourceDetails.class)); } /** * 根据提交时段锁定号池资源 * * @param appFormID 检查室或队列 * @param examRoomOrQueue 检查室或队列 * @param beginDateTime 开始时间 * @param endDateTime 结束时间 * @param lockStatus 锁定状态 * @return 是否锁定成功 */ public static Boolean lockedBookNo(String appFormID, String examRoomOrQueue, String beginDateTime, String endDateTime, Boolean lockStatus) { Map params = new HashMap<>(); params.put("appFormID", appFormID); params.put("examRoomOrQueue", examRoomOrQueue); params.put("beginDateTime", beginDateTime); params.put("endDateTime", endDateTime); params.put("lockStatus", lockStatus); RequestBody requestBody = RequestBody.create(JSON, JsonHelper.toJsonString(params)); String result = OkHttpHelper.post(MEDICAL_TECHNOLOGY_RESERVE_JSON_URL + "/BookDetails/BookDetails/LockedBookNo", requestBody, headers -> { headers.add("token", getToken()); }); JSONObject jsonObject = JsonHelper.parseObject(result); if (jsonObject == null) { log.info("[天助预约平台] examRoomOrQueue-{},beginDateTime-{},endDateTime-{},lockStatus-{}, 根据提交时段锁定号池资源失败,result-{}", examRoomOrQueue, beginDateTime, endDateTime, lockStatus, result); return false; } if (!"0".equals(jsonObject.getString("resultCode"))) { log.info("[天助预约平台] 根据提交时段锁定号池资源失败,失败原因-{}", jsonObject.getString("resultContent")); return false; } return true; } public static Result getBookedDateTime(String appFormID, String examRoomOrQueue, String beginDateTime, String endDateTime, String patientId, String patientName) { Map param = new HashMap<>(); param.put("AppFormID", appFormID); param.put("ExamRoomOrQueue", examRoomOrQueue); param.put("BeginDateTime", beginDateTime); param.put("EndDateTime", endDateTime); List> paramList = new ArrayList<>(); paramList.add(param); Map params = new HashMap<>(); params.put("BookedDateTimeDTOList", paramList); params.put("ScheduleUserId", patientId); params.put("ScheduleUser", patientName); log.info("[天助预约平台] 确定预约json={}", JsonHelper.toProJsonString(params)); RequestBody requestBody = RequestBody.create(JSON, JsonHelper.toProJsonString(params)); String result = OkHttpHelper.post(MEDICAL_TECHNOLOGY_RESERVE_JSON_URL + "/BookDetails/BookDetails/GetBookedDateTime", requestBody, headers -> { headers.add("token", getToken()); }); JSONObject jsonObject = JsonHelper.parseObject(result); if (jsonObject == null) { log.info("[天助预约平台] examRoomOrQueue-{},startDate-{},endDate-{},appFromID-{}, patientId-{},patientName-{}, 提交预约具体时间失败,result-{}", examRoomOrQueue, beginDateTime, endDateTime, appFormID, patientId, patientName, result); return Result.error(); } if (!"0".equals(jsonObject.getString("resultCode"))) { log.info("[天助预约平台] 提交预约具体时间失败,失败原因-{}", jsonObject.getString("resultContent")); return Result.error(jsonObject.getString("resultCode")); } return Result.success(jsonObject.getJSONArray("bookedInfos").toJavaList(BookedInfo.class).get(0)); } }