|
|
@@ -1,26 +1,68 @@
|
|
|
package com.fs.his.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fs.common.BeanCopyUtils;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.enums.ImTypeEnum;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
-import com.fs.course.param.FsInquiryPatientInfoUParam;
|
|
|
+import com.fs.common.utils.HsCryptoUtil;
|
|
|
+import com.fs.common.utils.StringToMapUtil;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.common.utils.spring.SpringUtils;
|
|
|
+import com.fs.core.utils.OrderCodeUtils;
|
|
|
+import com.fs.course.param.*;
|
|
|
import com.fs.course.vo.FsInquiryPatientInfoListUVO;
|
|
|
-import com.fs.his.domain.FsInquiryPatientInfo;
|
|
|
-import com.fs.his.mapper.FsInquiryOrderMapper;
|
|
|
-import com.fs.his.mapper.FsInquiryPatientInfoMapper;
|
|
|
+import com.fs.his.domain.*;
|
|
|
+import com.fs.his.dto.FsInquiryOrderPatientDTO;
|
|
|
+import com.fs.his.dto.PayloadDTO;
|
|
|
+import com.fs.his.mapper.*;
|
|
|
import com.fs.his.param.FsInquiryPatientParam;
|
|
|
-import com.fs.his.service.IFsInquiryPatientInfoService;
|
|
|
+import com.fs.his.service.*;
|
|
|
+import com.fs.his.utils.PhoneUtil;
|
|
|
import com.fs.his.vo.DoctorAdviceVO;
|
|
|
import com.fs.his.vo.FsInquiryPatientVO;
|
|
|
-import org.checkerframework.checker.units.qual.A;
|
|
|
+import com.fs.hisStore.domain.HsPrescribScrm;
|
|
|
+import com.fs.hisStore.domain.PrescriptionInfoDetails;
|
|
|
+import com.fs.im.config.ImTypeConfig;
|
|
|
+import com.fs.im.dto.OpenImMsgDTO;
|
|
|
+import com.fs.im.dto.OpenImResponseDTO;
|
|
|
+import com.fs.im.service.OpenIMService;
|
|
|
+import org.apache.hc.client5.http.classic.methods.HttpGet;
|
|
|
+import org.apache.hc.client5.http.classic.methods.HttpPost;
|
|
|
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
|
|
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
|
|
+import org.apache.hc.client5.http.impl.classic.HttpClients;
|
|
|
+import org.apache.hc.core5.http.ParseException;
|
|
|
+import org.apache.hc.core5.http.io.entity.EntityUtils;
|
|
|
+import org.apache.hc.core5.http.io.entity.StringEntity;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 问诊患者信息Service业务层处理
|
|
|
@@ -34,6 +76,71 @@ public class FsInquiryPatientInfoServiceImpl implements IFsInquiryPatientInfoSer
|
|
|
|
|
|
@Autowired
|
|
|
private FsInquiryOrderMapper inquiryOrderMapper;
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
+ @Autowired
|
|
|
+ private FsPatientMapper fsPatientMapper;
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+ @Autowired
|
|
|
+ private IFsDoctorPrescribeService doctorPrescribeService;
|
|
|
+ @Autowired
|
|
|
+ private IFsDoctorPrescribeDrugService doctorPrescribeDrugService;
|
|
|
+ @Autowired
|
|
|
+ private IFsDoctorService doctorService;
|
|
|
+ @Autowired
|
|
|
+ private IFsPrescribeService prescribeService;
|
|
|
+ @Autowired
|
|
|
+ private IFsPrescribeDrugService prescribeDrugService;
|
|
|
+ @Autowired
|
|
|
+ private OpenIMService openIMService;
|
|
|
+
|
|
|
+ //咨询问诊域名
|
|
|
+ private final String hsInquiryOrderUrl = "https://dev.om.yfttech.cn";
|
|
|
+ //咨询问诊url
|
|
|
+ private final String hsInquiryOrderInquiryUrl = "/open_platform/hospital/suppliers/v2/book_order";
|
|
|
+ //购药问诊url
|
|
|
+ private final String hsInquiryOrderMedicineUrl = "/open_platform/hospital/suppliers/v1/book_order";
|
|
|
+
|
|
|
+ //应用秘钥
|
|
|
+ private final String appSecret = "ExbfudweIeSCFLtp";
|
|
|
+ // 红杉平台RSA公钥(加密AES密钥用)
|
|
|
+ private final String platformPublicKey = "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlHZk1BMEdDU3FHU0liM0RRRUJBUVVBQTRHTkFEQ0JpUUtCZ1FDL2dEZXlQMENzTmI4Vzc3aWVxU0poTlpHeQo3bGpLOVFKZ1kwcHR1cDJ3NUJHZFR1TGpJRFU5ZzFHMkIxNlgrdXZWa0gwYWY5SWpBdGs3ZWRBQnRpK05OUjI0CmlBUDdDa2MrRk9NQjEyYUFXVHA3R0VPS0pZQS9ESkJEdWsrc1pMa2dRUDFubXJuL28xNGJLQk1SQVhMKzltcFAKWERkNUNENUhPUWNJT1JkeVl3SURBUUFCCi0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQo";
|
|
|
+ // 三方平台RSA私钥(解密响应密钥用)
|
|
|
+ private final String thirdPrivateKey = "LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUNkd0lCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQW1Fd2dnSmRBZ0VBQW9HQkFMWmxsblI4SE5Qb0N2WFkKVFBCTmtLdFArejc0NVA4ZzlzZUVHVDZUbysxdmp4Sk9jc2VRNWpFNnR4Rm5IQlJsc3psam5sUHdYT25HYStFLwo3Q2phbElIZjdTZ2p0SzlKSCtpckd5eW1yaVN6cEYyMFpKT2wxQXhsams2UUVFdGRRS0VqYWI2NjFGVHN2clRDCjhaRzAzS05NOVVjM2F6SGY2bVRRUXJtRWp1WjlBZ01CQUFFQ2dZRUF0Zjc5dG5OVkRIaWYzeGthQkRsUkhpOHIKWW5WVmdlRHhmTGtwdTAvMEpPbkkxNXBoV3hJUkxwUUlzUnV5WUFQdVpsZ3BWbFlqVDd5R1RuYksvU1RGUW5YVwpGS05pUEtjQ1pXdXhBdkNhRFFCZ0ZHdXZpMjB6bjBBZ2hEU0tycEIrYU9NL1VGdjhFZWx0cE42WDA0Vis1RlY2CitwWGFsdkZjUlhUWEVHMXBTUUVDUVFEbnVFT2VmcUxKb1pDK3lwMlovMTFFRm0yaWxOL2VKOFBpdzRFUm5WdTkKRU5TWm9OdURIUjFSeVFlYWVzeXU3WlFadzV2d0VvZkFlL1MzV2ZhVlFBM0JBa0VBeVlKRVJEcmdLSHF3YzYyOQpkLys4RGNVOEtZei9hQ3ZqVm9kUGRmMVMwbXZpdUlUS2txYVZhdDFCTis2MjZMcFU2c1BsNVVHeWZ5aXlVc3FTCnpmSi92UUpBRDhGUGw2ODBrbEVSN21jSVlEZ2t0MFJ2SCtiUGNlTnlSakRVemNYTlB3V3Q3dVFwQ0xrcURTMkYKL3RMcXA5b3ZmN0QxSVZXaE5VMDRUbDhuak81V0FRSkJBS01wS0M5NjRJL0dMK09xbFJSNTdJSFY1dzNaemVCQwpVUlI2QVZ3UEh5V2tGM0xDaXVmTm5JUm4zR3YyalFIS0JnSUZWcnVYdzNqMHNkY1prVjdTY0owQ1FGVGJJTnRCCi9OcW5laWI3U3d4ZCt5NHZ4UkRHZVRxZUFjNXE5ZU5RNy8vbUFOWlZyUTZKSEJnZ1NjT3h6ZFhFZFZ5UTk5Z1AKYmQ3c2Z2Mlk2WGdhd3FFPQotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg";
|
|
|
+ //appid唯一标识
|
|
|
+ private final String appId = "TpmBATELpdeMbjtjdaVIGbznlJDRjLDw";
|
|
|
+ private final String localUrl = "192.168.31.1:8113/app/inquiryPatient";
|
|
|
+ //红杉已开具处方
|
|
|
+ private final String prescriptionHsEnd = "prescription_pdf_end";
|
|
|
+ /*获取红杉诊室url*/
|
|
|
+ private final String hsConsultingRoomUrl = "/open_platform/hospital/suppliers/v2/book_order/group";
|
|
|
+ /*红杉跳转小程序版本 develop 开发版, trial 体验版, release 正式版*/
|
|
|
+ private final String hsEnvVersion = "trial";
|
|
|
+ /*银川互联网医院处方查询url*/
|
|
|
+ private final String hsPrescriptionUrl = "/open_platform/hospital/suppliers/v1/book_order/prescription";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 向红杉发起问诊申请
|
|
|
+ */
|
|
|
+ public static final String LOCK_KEY_Inquiry_HS = "inquiry:hs:lock:%d";
|
|
|
+ // /**
|
|
|
+// * 向红杉发起问诊申请后返回的bookNo
|
|
|
+// */
|
|
|
+// public static final String CACHE_BOOK_NO_HS = "cache:hs:book:no:%d";
|
|
|
+ /*红杉医生排班缓存key*/
|
|
|
+ private final String CACHE_HS_DOCTOR_SCHEDULE_LIST = "cache:doctor:schedule:hs:list";
|
|
|
+ private final String CACHE_HS_DOCTOR_SCHEDULE_HASH = "cache:doctor:schedule:hs:hash";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserMapper fsUserMapper;
|
|
|
+ @Autowired
|
|
|
+ private SpringUtils springUtils;
|
|
|
+ @Autowired
|
|
|
+ private FsStoreProductMapper fsStoreProductMapper;
|
|
|
+ @Qualifier("redisTemplate")
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public int insertFsInquiryPatientInfo(FsInquiryPatientParam param) {
|
|
|
FsInquiryPatientInfo fsInquiryPatientInfo = new FsInquiryPatientInfo();
|
|
|
@@ -75,4 +182,809 @@ public class FsInquiryPatientInfoServiceImpl implements IFsInquiryPatientInfoSer
|
|
|
public FsInquiryPatientInfoListUVO getInfo(Long id) {
|
|
|
return fsInquiryPatientInfoMapper.getInfo(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R sendInquiryToHS(SendInquiryParam param) throws Exception {
|
|
|
+ //参数校验
|
|
|
+ if (param.getPatientId() == null || param.getInquiryOrderId() == null || param.getUserId() == null) {
|
|
|
+ throw new RuntimeException("参数错误");
|
|
|
+ }
|
|
|
+ FsInquiryOrder fsInquiryOrder = inquiryOrderMapper.selectFsInquiryOrderByOrderId(param.getInquiryOrderId());
|
|
|
+ if (fsInquiryOrder == null) {
|
|
|
+ return R.error("未查询到该问诊单");
|
|
|
+ }
|
|
|
+ FsPatient fsPatient = fsPatientMapper.selectFsPatientByPatientId(param.getPatientId());
|
|
|
+ if (fsPatient == null) {
|
|
|
+ return R.error("未查询到该患者");
|
|
|
+ }
|
|
|
+ RLock lock = redissonClient.getLock(String.format(LOCK_KEY_Inquiry_HS, param.getInquiryOrderId()));
|
|
|
+ try {
|
|
|
+ boolean locked = lock.tryLock(100, 30000, TimeUnit.MILLISECONDS);
|
|
|
+
|
|
|
+ if (!locked) {
|
|
|
+ logger.warn("问诊单正在处理中,获取锁失败, 订单号: {}", param.getInquiryOrderId());
|
|
|
+ return R.error("订单正在处理中,请勿重复提交");
|
|
|
+ }
|
|
|
+
|
|
|
+ SendInquiryToHSParam hsParam = getHsParam(param.getUserId(), fsInquiryOrder, fsPatient, param.getAppId(), param.getInquiryType(), param.getDoctor(), param.getVisitRange(), param.getBranch());
|
|
|
+ // 使用ObjectMapper转换,会自动处理@JsonProperty注解
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ Map<String, Object> map = mapper.convertValue(hsParam, Map.class);
|
|
|
+ JSONObject jsonObject = new JSONObject(map);
|
|
|
+ String request = JSONUtil.toJsonStr(encryptRequest(jsonObject));
|
|
|
+ String urlWithParams = hsInquiryOrderUrl + (param.getInquiryType() == 1 ? hsInquiryOrderInquiryUrl : hsInquiryOrderMedicineUrl);
|
|
|
+ String responseBody = "";
|
|
|
+ try {
|
|
|
+ responseBody = sendPostRequest(request, urlWithParams,"POST");
|
|
|
+ } catch (Exception e) {
|
|
|
+ redisTemplate.delete(CACHE_HS_DOCTOR_SCHEDULE_LIST);
|
|
|
+ redisTemplate.delete(CACHE_HS_DOCTOR_SCHEDULE_HASH);
|
|
|
+ logger.error("请求失败:{}", e.getMessage());
|
|
|
+ return R.error("向红杉发起咨询问诊失败");
|
|
|
+ }
|
|
|
+ Map<String, Object> stringObjectMap = decryptResponse(responseBody);
|
|
|
+ Map<String, Object> data = (Map) stringObjectMap.get("data");
|
|
|
+ if (data.get("book_no") == null) {
|
|
|
+ redisTemplate.delete(CACHE_HS_DOCTOR_SCHEDULE_LIST);
|
|
|
+ redisTemplate.delete(CACHE_HS_DOCTOR_SCHEDULE_HASH);
|
|
|
+ return R.error("咨询问诊单在红衫异常,请联系管理员");
|
|
|
+ }
|
|
|
+ //把红杉响应数据存数据库,方便扯皮
|
|
|
+ inquiryOrderMapper.insertHsLog(responseBody, param.getInquiryOrderId(), param.getPatientId(), param.getUserId(), 1, stringObjectMap.toString(), (String) data.get("book_no"));
|
|
|
+
|
|
|
+ R.ok(String.valueOf(param.getInquiryOrderId()));
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ logger.error("问诊申请的过程被中断, 问诊单号: {}", param.getInquiryOrderId(), e);
|
|
|
+ return R.error("问诊申请被中断,请稍后重试");
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("问诊申请过程中发生异常, 问诊单号: {}", param.getInquiryOrderId(), e);
|
|
|
+ return R.error("问诊申请过程中发生异常,请稍后重试");
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread()) {
|
|
|
+ lock.unlock();
|
|
|
+ logger.debug("问诊申请锁已释放, 问诊单号: {}", param.getInquiryOrderId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R receiveInquiryFromHsCallbackNotification(HttpServletRequest param) throws Exception {
|
|
|
+// 解析请求
|
|
|
+// 1. 读取请求体内容
|
|
|
+ StringBuilder requestBody = new StringBuilder();
|
|
|
+ try (BufferedReader reader = param.getReader()) {
|
|
|
+ String line;
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ requestBody.append(line);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+// 2. 解析JSON
|
|
|
+ Map<String, Object> jsonMap = new ObjectMapper().readValue(
|
|
|
+ requestBody.toString(), Map.class
|
|
|
+ );
|
|
|
+ //判断行为是否为已开处方
|
|
|
+ String action = (String) jsonMap.get("action");
|
|
|
+ String bookNo = null;
|
|
|
+ if (action.equals(prescriptionHsEnd)) {
|
|
|
+ Map<String, Object> map = decryptResponse(String.valueOf(requestBody));
|
|
|
+ if (map != null && !map.isEmpty() && map.containsKey("book_info")) {
|
|
|
+ if (map.get("book_info") != null && map.get("book_info") instanceof Map) {
|
|
|
+ Object o = map.get("book_info");
|
|
|
+ if (ObjectUtil.isNotEmpty(o) && o instanceof Map) {
|
|
|
+ if (((Map<?, ?>) o).containsKey("book_no")) {
|
|
|
+ bookNo = ((Map<?, ?>) o).get("book_no").toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bookNo == null) {
|
|
|
+ logger.error("银川互联网医院通知回调处方开具异常,订单号为空");
|
|
|
+ return R.error("银川互联网医院通知回调处方开具异常,订单号为空");
|
|
|
+ }
|
|
|
+ /*根据bookNo查hslog*/
|
|
|
+ InquiryOrderHsLog hsLog = inquiryOrderMapper.selectHsLogByBookNo(bookNo);
|
|
|
+ /*插入hsLog*/
|
|
|
+ inquiryOrderMapper.insertHsLog(requestBody.toString(), hsLog.getInquiryOrderId(), hsLog.getPatientId(),
|
|
|
+ String.valueOf(hsLog.getUserId()), 2, map.toString(), bookNo);
|
|
|
+ /*用orderid和bookno拼参发起处方查询*/
|
|
|
+
|
|
|
+ HashMap<String, Object> objectObjectHashMap = MapUtil.newHashMap();
|
|
|
+ objectObjectHashMap.put("union_code", hsLog.getInquiryOrderId());
|
|
|
+ objectObjectHashMap.put("book_no", bookNo);
|
|
|
+ JSONObject jsonObject = new JSONObject(objectObjectHashMap);
|
|
|
+ String request = JSONUtil.toJsonStr(encryptRequest(jsonObject));
|
|
|
+ String urlWithParams = hsInquiryOrderUrl + hsPrescriptionUrl;
|
|
|
+ String responseBody = "";
|
|
|
+ try {
|
|
|
+ responseBody = sendPostRequest(request, urlWithParams, "GET");
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("请求失败:{}", e.getMessage());
|
|
|
+ return R.error("请求失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ Map<String, Object> stringObjectMap = decryptResponse(responseBody);
|
|
|
+ if (stringObjectMap.isEmpty()) {
|
|
|
+ logger.error("处方查询响应异常");
|
|
|
+ return R.error("处方查询响应异常");
|
|
|
+ }
|
|
|
+ Map<String, Object> data = (Map) stringObjectMap.get("data");
|
|
|
+ HsPrescribScrm hsPrescribScrm = BeanUtil.toBean(data, HsPrescribScrm.class);
|
|
|
+ //todo 新增处方和药单
|
|
|
+ /*走doctorapp.PrescribeController#createPrescribe*/
|
|
|
+ /*拼医生处方,注释掉的是未在红杉找到对应数据的*/
|
|
|
+ FsDoctorPrescribe doctorPrescribe = new FsDoctorPrescribe();
|
|
|
+// doctorPrescribe.setPrescribeType();
|
|
|
+ doctorPrescribe.setDiagnose(hsPrescribScrm.getMedicalRecord().getDiagnose().toString());
|
|
|
+// doctorPrescribe.setDoctorId();
|
|
|
+// doctorPrescribe.setStoreId();
|
|
|
+ doctorPrescribe.setUsageJson(hsPrescribScrm.getPrescriptionInfo().getDetails().toString());
|
|
|
+// doctorPrescribe.setRecipeType();
|
|
|
+ doctorPrescribe.setCycle(hsPrescribScrm.getPrescriptionInfo().getDetails().get(0).getTotal());//用的总数,未知响应数据
|
|
|
+ doctorPrescribeService.insertFsDoctorPrescribe(doctorPrescribe);
|
|
|
+
|
|
|
+ for (PrescriptionInfoDetails hsDrug : hsPrescribScrm.getPrescriptionInfo().getDetails()
|
|
|
+ ) {
|
|
|
+ FsStoreProduct fsStoreProduct = fsStoreProductMapper.selectFsStoreProductByBarCode(hsDrug.getBarCode());
|
|
|
+
|
|
|
+ FsDoctorPrescribeDrug drug = new FsDoctorPrescribeDrug();
|
|
|
+ drug.setPrescribeId(doctorPrescribe.getPrescribeId());
|
|
|
+ drug.setDrugName(hsDrug.getName());
|
|
|
+ drug.setDrugSpec(hsDrug.getFormat());
|
|
|
+ drug.setUsageMethod(hsDrug.getUsage());
|
|
|
+ drug.setUsageFrequencyUnit(hsDrug.getFrequency());
|
|
|
+ drug.setUsagePerUseCount(hsDrug.getDose());
|
|
|
+ drug.setUsagePerUseUnit(hsDrug.getUnit());
|
|
|
+// drug.setUsageDays();
|
|
|
+ drug.setDrugPrice(fsStoreProduct.getPrice());
|
|
|
+ drug.setDrugNum(hsDrug.getTotal().longValue());
|
|
|
+ drug.setDrugUnit(hsDrug.getUnit());
|
|
|
+ drug.setInstructions(hsDrug.getRequirements());
|
|
|
+ /*fs_store_product为药品表,甲方自己维护,双方系统互通*/
|
|
|
+ drug.setProductId(fsStoreProduct.getProductId());
|
|
|
+ drug.setDrugImgUrl(fsStoreProduct.getImgUrl());
|
|
|
+ drug.setProductAttrValueId(fsStoreProduct.getSpecType().longValue());
|
|
|
+ drug.setRemark(hsDrug.getLog().toString());
|
|
|
+ drug.setDrugType(fsStoreProduct.getProductType());
|
|
|
+ drug.setIsDrug(fsStoreProduct.getIsDrug());
|
|
|
+ doctorPrescribeDrugService.insertFsDoctorPrescribeDrug(drug);
|
|
|
+ }
|
|
|
+
|
|
|
+ //订单生成
|
|
|
+ FsDoctorPrescribeDrug drugMap=new FsDoctorPrescribeDrug();
|
|
|
+ drugMap.setPrescribeId(doctorPrescribe.getPrescribeId());
|
|
|
+ FsInquiryOrder inquiryOrder=inquiryOrderMapper.selectFsInquiryOrderByOrderId(hsLog.getInquiryOrderId());
|
|
|
+ List<FsDoctorPrescribeDrug> doctorPrescribeDrugs=doctorPrescribeDrugService.selectFsDoctorPrescribeDrugList(drugMap);
|
|
|
+
|
|
|
+ String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
+ if (StringUtils.isEmpty(orderSn)) {
|
|
|
+ return R.error("订单生成失败,请重试");
|
|
|
+ }
|
|
|
+ FsPrescribe prescribe = new FsPrescribe();
|
|
|
+ BeanUtils.copyProperties(doctorPrescribe, prescribe);
|
|
|
+ prescribe.setInquiryOrderId(inquiryOrder.getOrderId());
|
|
|
+ prescribe.setUserId(inquiryOrder.getUserId());
|
|
|
+ prescribe.setPatientId(inquiryOrder.getPatientId());
|
|
|
+ prescribe.setPrescribeCode(orderSn);
|
|
|
+ prescribe.setIcdCode(doctorPrescribe.getIcdCode());
|
|
|
+ FsInquiryOrderPatientDTO patientDTO = JSONUtil.toBean(inquiryOrder.getPatientJson(), FsInquiryOrderPatientDTO.class);
|
|
|
+ prescribe.setPatientAge(patientDTO.getAge());
|
|
|
+ prescribe.setPatientName(patientDTO.getPatientName());
|
|
|
+ prescribe.setPatientAge(patientDTO.getAge());
|
|
|
+ prescribe.setPatientDescs(patientDTO.getTitle());
|
|
|
+ prescribe.setPatientTel(patientDTO.getMobile());
|
|
|
+ prescribe.setPatientGender(patientDTO.getSex().toString());
|
|
|
+ prescribe.setPatientBirthday(patientDTO.getBirthday());
|
|
|
+ prescribe.setRecordPic(inquiryOrder.getImgs());
|
|
|
+ prescribe.setDiagnose(prescribe.getDiagnose());
|
|
|
+ prescribe.setDoctorId(inquiryOrder.getDoctorId());
|
|
|
+ prescribe.setStatus(0);
|
|
|
+ prescribe.setUsageJson(prescribe.getUsageJson());
|
|
|
+ prescribe.setCycle(doctorPrescribe.getCycle());
|
|
|
+ prescribe.setRemark(prescribe.getRemark());
|
|
|
+ if (inquiryOrder.getSource() != null) {
|
|
|
+ prescribe.setSource(inquiryOrder.getSource());
|
|
|
+ }
|
|
|
+
|
|
|
+ FsDoctor doctor = doctorService.selectFsDoctorByDoctorId(1L);//hs医生排班接口获取
|
|
|
+ if (doctor != null && StringUtils.isNotEmpty(doctor.getSignUrl())) {
|
|
|
+ prescribe.setDoctorSignUrl(doctor.getSignUrl());
|
|
|
+ }
|
|
|
+ if (doctor != null && doctor.getIsPrescribeDoctor() != null && doctor.getIsPrescribeDoctor() == 1) {
|
|
|
+ prescribe.setPrescribeDoctorId(doctor.getDoctorId());
|
|
|
+ prescribe.setPrescribeDoctorSignUrl(doctor.getSignUrl());
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (doctor.getPrescribeDoctorId() != null) {
|
|
|
+ FsDoctor prescribeDoctor = doctorService.selectFsDoctorByDoctorId(doctor.getPrescribeDoctorId());
|
|
|
+ if (prescribeDoctor != null) {
|
|
|
+ prescribe.setPrescribeDoctorId(prescribeDoctor.getDoctorId());
|
|
|
+ prescribe.setPrescribeDoctorSignUrl(prescribeDoctor.getSignUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (prescribeService.insertFsPrescribe(prescribe) > 0) {
|
|
|
+ //写入药品
|
|
|
+ for (FsDoctorPrescribeDrug drug : doctorPrescribeDrugs) {
|
|
|
+ FsPrescribeDrug prescribeDrug = new FsPrescribeDrug();
|
|
|
+ BeanUtils.copyProperties(drug, prescribeDrug);
|
|
|
+ prescribeDrug.setProductAttrValueId(drug.getProductAttrValueId());
|
|
|
+ prescribeDrug.setPrescribeId(prescribe.getPrescribeId());
|
|
|
+ prescribeDrugService.insertFsPrescribeDrug(prescribeDrug);
|
|
|
+ }
|
|
|
+ if (ImTypeConfig.IMTYPE == ImTypeEnum.OPENIM) {
|
|
|
+ logger.info("拼接消息体");
|
|
|
+ //部署到正式环境以后下面这段代码要注释,使用定时任务执行auditPrescribe审核处方以后发送消息
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ OpenImMsgDTO openImMsgDTO = new OpenImMsgDTO();
|
|
|
+ openImMsgDTO.setSendID("D" + inquiryOrder.getDoctorId());
|
|
|
+ openImMsgDTO.setRecvID("U" + inquiryOrder.getUserId());
|
|
|
+ openImMsgDTO.setContentType(110);
|
|
|
+ openImMsgDTO.setSenderPlatformID(5);
|
|
|
+ openImMsgDTO.setSessionType(1);
|
|
|
+ OpenImMsgDTO.Content content = new OpenImMsgDTO.Content();
|
|
|
+ //content.setContent(ext);
|
|
|
+ PayloadDTO payload = new PayloadDTO();
|
|
|
+ payload.setData("prescribe");
|
|
|
+ PayloadDTO.Extension extension = new PayloadDTO.Extension();
|
|
|
+ extension.setDiagnose(inquiryOrder.getTitle());
|
|
|
+ extension.setPrescribeId(prescribe.getPrescribeId().toString());
|
|
|
+ payload.setExtension(extension);
|
|
|
+ extension.setStatus(prescribe.getStatus());
|
|
|
+ OpenImMsgDTO.ImData imData = new OpenImMsgDTO.ImData();
|
|
|
+
|
|
|
+ imData.setPayload(payload);
|
|
|
+
|
|
|
+ String imJson = objectMapper.writeValueAsString(imData);
|
|
|
+ content.setData(imJson);
|
|
|
+ openImMsgDTO.setContent(content);
|
|
|
+
|
|
|
+ JSONObject jsonObjectNew = new JSONObject(openImMsgDTO);
|
|
|
+ logger.info("开始发送消息");
|
|
|
+ OpenImMsgDTO.OfflinePushInfo offlinePushInfo = new OpenImMsgDTO.OfflinePushInfo();
|
|
|
+ offlinePushInfo.setDesc("处方单");
|
|
|
+ offlinePushInfo.setTitle(doctor.getDoctorName());
|
|
|
+ offlinePushInfo.setIOSBadgeCount(true);
|
|
|
+ offlinePushInfo.setIOSPushSound("");
|
|
|
+ openImMsgDTO.setOfflinePushInfo(offlinePushInfo);
|
|
|
+ OpenImResponseDTO openImResponseDTO = openIMService.openIMSendMsg(openImMsgDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<HsDoctorSchedule> getDoctorScheduleFromHs() throws Exception {
|
|
|
+ ArrayList<HsDoctorSchedule> hsDoctorSchedules = new ArrayList<>();
|
|
|
+ List range = redisTemplate.opsForList().range(CACHE_HS_DOCTOR_SCHEDULE_LIST, 0, -1);
|
|
|
+ if (range != null && !range.isEmpty()){
|
|
|
+ ArrayList<Integer> doctorIdList = new ArrayList<>(range);
|
|
|
+ doctorIdList.forEach(i -> {
|
|
|
+ Object o = redisTemplate.opsForHash().get(CACHE_HS_DOCTOR_SCHEDULE_HASH, i + "");
|
|
|
+ if (o != null) {
|
|
|
+ hsDoctorSchedules.add(JSONUtil.toBean(o.toString(), HsDoctorSchedule.class));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /*要做一次筛选,存入我们doctor表*/
|
|
|
+ return hsDoctorSchedules;
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ String todayFormat = today.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LocalDate tomorrow = today.plusDays(1);
|
|
|
+ String tomorrowFormat = tomorrow.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ map.put("start_date", todayFormat);
|
|
|
+ map.put("end_date", tomorrowFormat);
|
|
|
+ map.put("symptom", Arrays.asList(""));
|
|
|
+ JSONObject jsonObject = new JSONObject(map);
|
|
|
+
|
|
|
+ Map<String, String> stringStringMap = encryptRequest(jsonObject);
|
|
|
+// stringStringMap.put("_method", "GET");//按他们要求填参异常
|
|
|
+ String requestBody = JSONUtil.toJsonStr(stringStringMap);
|
|
|
+ String responseBody = null;
|
|
|
+
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
+ // 构建URL
|
|
|
+ HttpGet httpGet = new HttpGet(hsInquiryOrderUrl + "/open_platform/hospital/suppliers/v1/hsadmin/schedule");
|
|
|
+
|
|
|
+ // 设置请求头
|
|
|
+ httpGet.setHeader("appid", appId);
|
|
|
+ httpGet.setHeader("Accept", "application/json");
|
|
|
+ httpGet.setHeader("Content-Type", "application/json");
|
|
|
+ httpGet.setHeader("User-Agent", "Mozilla/5.0");
|
|
|
+
|
|
|
+ // 设置请求体
|
|
|
+ StringEntity entity = new StringEntity(requestBody, StandardCharsets.UTF_8);
|
|
|
+ httpGet.setEntity(entity);
|
|
|
+
|
|
|
+ // 执行请求
|
|
|
+ try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
|
|
+ int statusCode = response.getCode();
|
|
|
+ System.out.println("响应码: " + statusCode);
|
|
|
+ responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("向红杉发起请求失败: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ Map<String, Object> stringObjectMap = decryptResponse(responseBody);
|
|
|
+ if (ObjectUtil.isNotEmpty(stringObjectMap) && stringObjectMap.get("data") != null) {
|
|
|
+ List<Map<String, Object>> rawDataList = (List<Map<String, Object>>) stringObjectMap.get("data");
|
|
|
+ rawDataList.forEach(o -> {
|
|
|
+ HsDoctorSchedule item = JSONUtil.toBean(JSONUtil.toJsonStr(o), HsDoctorSchedule.class);
|
|
|
+ Object scheduleObj = o.get("schedule");
|
|
|
+ if (scheduleObj != null) {
|
|
|
+ if (scheduleObj instanceof String) {
|
|
|
+ // 如果是字符串,则解析为 Map
|
|
|
+ try {
|
|
|
+ JSONObject jsonObj = JSONUtil.parseObj((String) scheduleObj);
|
|
|
+ Map<String, Integer> scheduleMap = new HashMap<>();
|
|
|
+ for (Map.Entry<String, Object> entry : jsonObj.entrySet()) {
|
|
|
+ if (entry.getValue() instanceof Number) {
|
|
|
+ scheduleMap.put(entry.getKey(), ((Number) entry.getValue()).intValue());
|
|
|
+ } else if (entry.getValue() instanceof String) {
|
|
|
+ try {
|
|
|
+ scheduleMap.put(entry.getKey(), Integer.parseInt((String) entry.getValue()));
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ scheduleMap.put(entry.getKey(), 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.setSchedule(scheduleMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.warn("解析 schedule 字符串失败: {}", scheduleObj, e);
|
|
|
+ }
|
|
|
+ } else if (scheduleObj instanceof Map) {
|
|
|
+ // 如果已经是 Map,则直接转换类型
|
|
|
+ try {
|
|
|
+ Map<String, Integer> scheduleMap = new HashMap<>();
|
|
|
+ Map<?, ?> rawMap = (Map<?, ?>) scheduleObj;
|
|
|
+ for (Map.Entry<?, ?> entry : rawMap.entrySet()) {
|
|
|
+ if (entry.getKey() instanceof String && entry.getValue() instanceof Number) {
|
|
|
+ scheduleMap.put((String) entry.getKey(), ((Number) entry.getValue()).intValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.setSchedule(scheduleMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.warn("转换 schedule Map 失败: {}", scheduleObj, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.getSchedule() != null) {
|
|
|
+ String currentTimeSlot = getCurrentValidTimeSlot(item.getSchedule());
|
|
|
+ if (currentTimeSlot != null) {
|
|
|
+ hsDoctorSchedules.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!hsDoctorSchedules.isEmpty()){
|
|
|
+ /*直接把排班数据的医生存入fs_doctor*/
|
|
|
+// FsDoctorServiceImpl
|
|
|
+ }
|
|
|
+ List<Integer> collect = hsDoctorSchedules.stream().map(o -> o.getDoctor()).collect(Collectors.toList());
|
|
|
+ try {
|
|
|
+ // 先清除旧的缓存数据
|
|
|
+ redisTemplate.delete(CACHE_HS_DOCTOR_SCHEDULE_LIST);
|
|
|
+ redisTemplate.delete(CACHE_HS_DOCTOR_SCHEDULE_HASH);
|
|
|
+ // 存储医生ID列表
|
|
|
+ Long listResult = redisTemplate.opsForList().leftPushAll(CACHE_HS_DOCTOR_SCHEDULE_LIST, collect);
|
|
|
+ if (listResult > 0) {
|
|
|
+ // 存储每个医生的详细排班信息到hash中
|
|
|
+ for (HsDoctorSchedule schedule : hsDoctorSchedules) {
|
|
|
+ redisTemplate.opsForHash().put(
|
|
|
+ CACHE_HS_DOCTOR_SCHEDULE_HASH,
|
|
|
+ schedule.getDoctor().toString(),
|
|
|
+ JSONUtil.toJsonStr(schedule)
|
|
|
+ );
|
|
|
+ }
|
|
|
+// long expireSeconds = Duration.between(LocalDateTime.now(),
|
|
|
+// LocalDateTime.of(LocalDate.now().plusDays(1), LocalTime.MIDNIGHT)).getSeconds();
|
|
|
+ // 为缓存设置过期时间每天00点过期
|
|
|
+ redisTemplate.expire(CACHE_HS_DOCTOR_SCHEDULE_LIST, 1, TimeUnit.MINUTES);
|
|
|
+ redisTemplate.expire(CACHE_HS_DOCTOR_SCHEDULE_HASH, 1, TimeUnit.MINUTES);
|
|
|
+ logger.info("医生排班缓存更新成功,共{}个医生", listResult);
|
|
|
+ } else {
|
|
|
+ logger.error("添加医生缓存失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("Redis缓存操作异常", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return hsDoctorSchedules;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修复常见的JSON格式问题
|
|
|
+ */
|
|
|
+ private String fixJsonString(String json) {
|
|
|
+ if (json == null) return null;
|
|
|
+ // 移除可能的BOM标记和其他非法字符
|
|
|
+ return json.trim()
|
|
|
+ .replaceAll("^\uFEFF", "") // 移除BOM
|
|
|
+ .replaceAll("[\\x00-\\x1F&&[^\\r\\n\\t]]", ""); // 移除控制字符
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map redirectToHs(String inquiryOrderId) throws Exception {
|
|
|
+ InquiryOrderHsLog inquiryOrderHsLog = inquiryOrderMapper.selectHsLog(inquiryOrderId);
|
|
|
+ if (ObjectUtil.isEmpty(inquiryOrderHsLog)) {
|
|
|
+ throw new RuntimeException("未找到对应的问诊单");
|
|
|
+ }
|
|
|
+ HashMap<String, Object> data = new HashMap<>();
|
|
|
+ String jsonString = inquiryOrderHsLog.getDecodeJson();
|
|
|
+ if (jsonString != null && !jsonString.trim().isEmpty()) {
|
|
|
+ HashMap<String, Object> map = (HashMap<String, Object>) StringToMapUtil.toMap(jsonString);
|
|
|
+ data = (HashMap<String, Object>) map.get("data");
|
|
|
+// HashMap hashMap = JSONUtil.toBean(jsonString, HashMap.class);
|
|
|
+// if (hashMap != null && hashMap.get("data") != null)
|
|
|
+// data = (HashMap<String, Object>) hashMap.get("data");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Map<String, Object> finalMap = MapUtil.newHashMap();
|
|
|
+ Map<String, Object> stringObjectMap1 = MapUtil.newHashMap();
|
|
|
+ //需要创建诊室
|
|
|
+ if (data.get("user_sign_token") != null && data.get("book_no") != null) {
|
|
|
+ //响应存在token和bookno就调用创建诊室接口
|
|
|
+ HashMap<String, String> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("user_sign_token", data.get("user_sign_token").toString());
|
|
|
+ requestMap.put("book_no", data.get("book_no").toString());
|
|
|
+ Map<String, String> stringStringMap = encryptRequest(new JSONObject(requestMap));
|
|
|
+ String s = "";
|
|
|
+ try {
|
|
|
+ s = sendPostRequest(JSONUtil.toJsonStr(stringStringMap), hsInquiryOrderUrl + hsConsultingRoomUrl,"POST");
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("请求失败:{}", e.getMessage());
|
|
|
+ return R.error("向红杉发起诊室获取失败");
|
|
|
+ }
|
|
|
+ stringObjectMap1 = decryptResponse(s);
|
|
|
+ Map<String, Object> map1 = (Map) stringObjectMap1.get("data");
|
|
|
+ if (map1.get("book_no") != null && map1.get("user_sign_token") != null) {
|
|
|
+ Map extraData = new HashMap<String, String>();
|
|
|
+ extraData.put("book_no", map1.get("book_no").toString());
|
|
|
+ extraData.put("user_sign_token", map1.get("user_sign_token").toString());
|
|
|
+ finalMap.put("extraData", extraData);
|
|
|
+ /*测试环境tempAppid*/
|
|
|
+ finalMap.put("appId", "wx4093138269dbaf41");
|
|
|
+ Map map2 = (Map) data.get("jump_param");
|
|
|
+ if (map2 != null && map2.get("jump_uri") != null)
|
|
|
+ finalMap.put("path", map2.get("jump_uri"));
|
|
|
+ finalMap.put("envVersion", hsEnvVersion);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (MapUtil.isEmpty(finalMap)) return R.error("向红杉发起咨询问诊失败-诊室信息为空");
|
|
|
+ /*创建诊室的响应解密*/
|
|
|
+ inquiryOrderMapper.updateHsLog(Long.valueOf(inquiryOrderId), JSONUtil.toJsonStr(stringObjectMap1));
|
|
|
+ return R.ok(finalMap);
|
|
|
+
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ logger.error("问诊申请的过程被中断, 问诊单号: {}", inquiryOrderId, e);
|
|
|
+ return R.error("问诊申请被中断,请稍后重试");
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("问诊申请过程中发生异常, 问诊单号: {}", inquiryOrderId, e);
|
|
|
+ return R.error("问诊申请过程中发生异常,请稍后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R cancelInquiryToHs(String inquiryOrderId) {
|
|
|
+ InquiryOrderHsLog inquiryOrderHsLog = inquiryOrderMapper.selectHsLog(inquiryOrderId);
|
|
|
+ if (ObjectUtil.isEmpty(inquiryOrderHsLog)) {
|
|
|
+ return R.error("未找到对应的问诊单");
|
|
|
+ }
|
|
|
+ inquiryOrderHsLog.getBookNo();//第三方接口不通,需要对接组长是否做这个功能
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前时间所在的时间段(value >= 1)
|
|
|
+ *
|
|
|
+ * @param schedule 时间段映射
|
|
|
+ * @return 当前时间段的key,如果没有找到则返回null
|
|
|
+ */
|
|
|
+ public static String getCurrentValidTimeSlot(Map<String, Integer> schedule) {
|
|
|
+ LocalTime now = LocalTime.now();
|
|
|
+
|
|
|
+ for (Map.Entry<String, Integer> entry : schedule.entrySet()) {
|
|
|
+ String timeSlot = entry.getKey();
|
|
|
+ Integer value = entry.getValue();
|
|
|
+
|
|
|
+ // 只考虑value大于等于1的时间段
|
|
|
+ if (value >= 1) {
|
|
|
+ // 解析时间段,例如"08:00-08:30"
|
|
|
+ String[] times = timeSlot.split("-");
|
|
|
+ if (times.length == 2) {
|
|
|
+ try {
|
|
|
+ LocalTime startTime = LocalTime.parse(times[0]);
|
|
|
+ LocalTime endTime = LocalTime.parse(times[1]);
|
|
|
+ // 判断当前时间是否在这个时间段内
|
|
|
+ if (!now.isBefore(startTime) && now.isBefore(endTime)) {
|
|
|
+ return timeSlot;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 忽略解析错误的时间格式
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null; // 没有找到合适的时间段
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public void updateFsInquiryPatientInfoFromHsRedirect(HttpServletRequest param) throws JsonProcessingException {
|
|
|
+//解析请求
|
|
|
+// 1. 读取请求体内容
|
|
|
+// StringBuilder requestBody = new StringBuilder();
|
|
|
+// try (BufferedReader reader = param.getReader()) {
|
|
|
+// String line;
|
|
|
+// while ((line = reader.readLine()) != null) {
|
|
|
+// requestBody.append(line);
|
|
|
+// }
|
|
|
+// } catch (IOException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+// 2. 解析JSON
|
|
|
+// Map<String, Object> jsonMap = new ObjectMapper().readValue(
|
|
|
+// requestBody.toString(),Map.class
|
|
|
+// );
|
|
|
+
|
|
|
+//发送失败存数据库
|
|
|
+// fsInquiryPatientInfoMapper.updateFsInquiryPatientInfoFromHsRedirect();
|
|
|
+//失败消息发给用户
|
|
|
+
|
|
|
+//todo 暂时不用处理,用户前端可以直接看到问诊失败
|
|
|
+// }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public void recieveInquiryFromHsDispensary(HttpServletRequest param) throws JsonProcessingException {
|
|
|
+//// 1. 读取请求体内容
|
|
|
+// StringBuilder requestBody = new StringBuilder();
|
|
|
+// try (BufferedReader reader = param.getReader()) {
|
|
|
+// String line;
|
|
|
+// while ((line = reader.readLine()) != null) {
|
|
|
+// requestBody.append(line);
|
|
|
+// }
|
|
|
+// } catch (IOException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+//// 2. 解析JSON
|
|
|
+// Map<String, Object> jsonMap = new ObjectMapper().readValue(
|
|
|
+// requestBody.toString(),Map.class
|
|
|
+// );
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 银川互联网医院要求,都用post,请求体加“_method”标识请求方法
|
|
|
+ * @param request 请求体
|
|
|
+ * @param urlWithParams 跳转的url
|
|
|
+ * @param method 跳转的方法
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ * @throws ParseException
|
|
|
+ */
|
|
|
+
|
|
|
+ private String sendPostRequest(String request, String urlWithParams,String method) throws IOException, ParseException {
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
+ // 构建URL
|
|
|
+ HttpPost httpPost = new HttpPost(urlWithParams);
|
|
|
+
|
|
|
+ // 设置请求头
|
|
|
+ httpPost.setHeader("appid", appId);
|
|
|
+ httpPost.setHeader("Accept", "application/json");
|
|
|
+ httpPost.setHeader("Content-Type", "application/json");
|
|
|
+ httpPost.setHeader("User-Agent", "Mozilla/5.0");
|
|
|
+
|
|
|
+ // 设置请求体
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(request);
|
|
|
+ // 添加_method参数
|
|
|
+ jsonObject.put("_method", method);
|
|
|
+ // 重新生成请求体字符串
|
|
|
+ String requestBody = JSONUtil.toJsonStr(jsonObject);
|
|
|
+ StringEntity entity = new StringEntity(requestBody, StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+
|
|
|
+ // 执行请求
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ int statusCode = response.getCode();
|
|
|
+ System.out.println("响应码: " + statusCode);
|
|
|
+ String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
|
|
+ return responseBody;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> encryptRequest(JSONObject hsParam) throws Exception {
|
|
|
+ Map<String, String> encrypt = HsCryptoUtil.encrypt(hsParam, appSecret, platformPublicKey);
|
|
|
+ return encrypt;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> decryptResponse(String response) throws Exception {
|
|
|
+ JsonNode jsonNode = new ObjectMapper().readTree(response);
|
|
|
+ JsonNode data = jsonNode.get("data");
|
|
|
+ if (data == null) {
|
|
|
+ throw new RuntimeException("未收到响应的结果");
|
|
|
+ }
|
|
|
+ Map<String, Object> decrypt = HsCryptoUtil.decrypt(data, appSecret, thirdPrivateKey);
|
|
|
+
|
|
|
+ return decrypt;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<HashMap<String, String>> getHistroyAllergic(String historyAllergic) {
|
|
|
+ /*过敏史*/
|
|
|
+ List<HashMap<String, String>> histroyAllergic = new ArrayList<>();
|
|
|
+ if (!historyAllergic.equals("") && historyAllergic != null) {
|
|
|
+ String[] split = historyAllergic.split(",");
|
|
|
+ Map<String, String> allergy = new HashMap<String, String>() {{
|
|
|
+ put("无", "1");
|
|
|
+ put("青霉素", "2");
|
|
|
+ put("磺胺", "3");
|
|
|
+ put("链霉素", "4");
|
|
|
+ }};
|
|
|
+ for (String s : split
|
|
|
+ ) {
|
|
|
+ s = s.trim();
|
|
|
+ HashMap<String, String> stringStringHashMap = new HashMap<>();
|
|
|
+ stringStringHashMap.put("code", allergy.get(s) != null ? allergy.get(s) : "99");
|
|
|
+ stringStringHashMap.put("name", s);
|
|
|
+ histroyAllergic.add(stringStringHashMap);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ histroyAllergic.add(new HashMap<String, String>() {{
|
|
|
+ put("1", "无");
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ return histroyAllergic;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<HashMap<String, String>> getIllnessHistroy(String selfMedHistory) {
|
|
|
+ /*疾病(现病)史*/
|
|
|
+ List<HashMap<String, String>> illnessHistroy = new ArrayList<>();
|
|
|
+ if (!selfMedHistory.equals("") && selfMedHistory != null) {
|
|
|
+ String[] split = selfMedHistory.split(",");
|
|
|
+ Map<String, String> illnessMap = new HashMap<String, String>() {{
|
|
|
+ put("无", "1");
|
|
|
+ put("骨质疏松", "16");
|
|
|
+ put("心肌病", "17");
|
|
|
+ put("脉管炎", "18");
|
|
|
+ put("肺结核", "19");
|
|
|
+ put("消化道出血", "20");
|
|
|
+ put("胃溃疡", "21");
|
|
|
+ put("肾功能不全", "22");
|
|
|
+ put("泌尿系结石", "23");
|
|
|
+ put("前列腺炎", "24");
|
|
|
+ put("甲状腺病(甲亢、甲减、甲状腺炎、结节)", "25");
|
|
|
+ put("痛风", "26");
|
|
|
+ put("关节炎", "27");
|
|
|
+ put("红斑狼疮", "28");
|
|
|
+ put("贫血", "29");
|
|
|
+ put("脑出血", "30");
|
|
|
+ put("脑梗塞", "31");
|
|
|
+ put("帕金森氏综合症", "32");
|
|
|
+ put("重症肌无力", "33");
|
|
|
+ put("癫痫", "34");
|
|
|
+ put("结肠炎", "35");
|
|
|
+ put("胆囊炎", "36");
|
|
|
+ put("胆结石", "37");
|
|
|
+ put("肝硬化", "38");
|
|
|
+ put("肾炎", "39");
|
|
|
+ put("美尼尔氏综合征", "40");
|
|
|
+ put("老年性痴呆", "41");
|
|
|
+ put("抑郁症", "42");
|
|
|
+ put("焦虑症", "43");
|
|
|
+ put("肿瘤", "44");
|
|
|
+ put("白内障", "45");
|
|
|
+ put("青光眼", "46");
|
|
|
+ put("皮肤病", "47");
|
|
|
+ put("慢性支气管炎", "48");
|
|
|
+ put("肺气肿", "49");
|
|
|
+ put("肺源性心脏病", "50");
|
|
|
+ put("支气管哮喘、扩张", "51");
|
|
|
+ put("气胸", "52");
|
|
|
+ put("慢性心衰", "53");
|
|
|
+ put("心律失常", "54");
|
|
|
+ put("心脏瓣膜病", "55");
|
|
|
+ put("认知障碍", "56");
|
|
|
+ put("其他", "99");
|
|
|
+ }};
|
|
|
+
|
|
|
+ for (String s : split
|
|
|
+ ) {
|
|
|
+ s = s.trim();
|
|
|
+ HashMap<String, String> stringStringHashMap = new HashMap<>();
|
|
|
+ stringStringHashMap.put("code", illnessMap.get(s) != null ? illnessMap.get(s) : "99");
|
|
|
+ stringStringHashMap.put("name", s);
|
|
|
+ illnessHistroy.add(stringStringHashMap);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ illnessHistroy.add(new HashMap<String, String>() {{
|
|
|
+ put("1", "无");
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ return illnessHistroy;
|
|
|
+ }
|
|
|
+
|
|
|
+ private SendInquiryToHSParam getHsParam(String userId, FsInquiryOrder fsInquiryOrder, FsPatient fsPatient, String appId, Integer inquiryType, Integer doctor, String visitRange, Integer branch) {
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserByUserId(Long.valueOf(userId));
|
|
|
+ //没有appid,暂时随便填一个
|
|
|
+ if (appId == null) appId = "wx4115995705bbtest";
|
|
|
+ List<HashMap<String, String>> histroyAllergic = getHistroyAllergic(fsPatient.getHistoryAllergic());
|
|
|
+ List<HashMap<String, String>> illnessHistroy = getIllnessHistroy(fsPatient.getSelfMedHistory());
|
|
|
+ List<HashMap<String, String>> familyHistory = getIllnessHistroy(fsPatient.getFamilyMedHistory());
|
|
|
+ /*测试暂时取了个测试环境的医生信息,正式环境需要高频调医生排班接口*/
|
|
|
+ HsBookDoctorInfoParam hsBookDoctorInfoParam = new HsBookDoctorInfoParam();
|
|
|
+ if (doctor == null) {
|
|
|
+ hsBookDoctorInfoParam
|
|
|
+ .setDoctorId(16405)
|
|
|
+ .setVisitDate("2025-12-22")
|
|
|
+ .setVisitRange("16:00-16:30")
|
|
|
+ .setBranch(1377);
|
|
|
+ } else {
|
|
|
+ hsBookDoctorInfoParam.setDoctorId(doctor)
|
|
|
+ .setVisitDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
|
|
+ .setVisitRange(visitRange)
|
|
|
+ .setBranch(branch);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*跳转信息*/
|
|
|
+ HsRedirectParam hsRedirectParam = new HsRedirectParam();
|
|
|
+ hsRedirectParam.setFromType(1).setFromTag("1").setBackType(1).setBackTag("1").setJumpType(1).setBackUri(localUrl);
|
|
|
+
|
|
|
+ SendInquiryToHSParam sendInquiryToHSParam = new SendInquiryToHSParam()
|
|
|
+ .setPrescriptionType(1)//todo 需要咨询处方分类这个业务
|
|
|
+ .setUnionCode(String.valueOf(fsInquiryOrder.getOrderId()))
|
|
|
+ .setRegisterType(ObjectUtil.isNotNull(fsInquiryOrder) ? fsInquiryOrder.getOrderType() == 1 ? "picture" : fsInquiryOrder.getOrderType() == 2 ? "video" : "" : "")
|
|
|
+ .setUserInfo(new HsUserInfoParam()
|
|
|
+ //微信小程序
|
|
|
+ .setAccType("11")
|
|
|
+ .setUserMp(fsUser.getPhone().length() > 11 ? PhoneUtil.decryptPhone(fsUser.getPhone()) : fsUser.getPhone())
|
|
|
+ .setAccOpenid(fsUser.getMaOpenId())
|
|
|
+ .setAccAppid(appId)
|
|
|
+ )
|
|
|
+ .setUserMember(new HsUserMember().setRealName(fsPatient.getPatientName())
|
|
|
+ .setMp(fsPatient.getMobile().length() > 11 ? PhoneUtil.decryptPhone(fsPatient.getMobile()) : fsPatient.getMobile())
|
|
|
+ .setCertCode(fsPatient.getIdCard()).setAge(fsPatient.getAge()).setAgeUnit("1")
|
|
|
+ .setRelation("0").setSex(fsPatient.getSex().toString()))
|
|
|
+ .setHealthyCondition(new HsHealthyCondition()
|
|
|
+ .setLiverKidneyNormal(fsPatient.getLiverUnusual().equals("正常") && fsPatient.getRenalUnusual().equals("正常") ? 1 : 0)
|
|
|
+ .setAllergy(histroyAllergic)
|
|
|
+ .setIllnessHistory(illnessHistroy)
|
|
|
+ .setFamilyHistory(familyHistory)
|
|
|
+ .setPregnancy(fsPatient.getSex() == 1 ? 9 : 0))
|
|
|
+// .setDrug(Arrays.asList())//todo 购药问诊需要
|
|
|
+ .setBookDescription(fsInquiryOrder.getTitle())
|
|
|
+ .setSubsequentFile(Arrays.asList())
|
|
|
+ .setNotifyUri(localUrl + "")//todo 处方开具后流转通知
|
|
|
+ .setRedirectUri(localUrl + "/recieveInquiryFromHsRedirect")//todo 鉴权失败或进入诊室失败返回地址
|
|
|
+ .setDispensaryUri(localUrl + "")//todo 去取药的跳转地址,一般提供三方小程序购药订单或支付处方
|
|
|
+ .setCallbackNotification(localUrl + "/receiveInquiryFromHsCallbackNotification")//todo 问诊生命周期回调通知
|
|
|
+ .setBookDoctorInfo(hsBookDoctorInfoParam)
|
|
|
+ .setRedirectParam(hsRedirectParam);
|
|
|
+// if (inquiryType==2){
|
|
|
+// sendInquiryToHSParam.setDrug(Arrays.asList(new HsDrug()));
|
|
|
+// } //todo 暂时未知我们系统的药品表
|
|
|
+
|
|
|
+ return sendInquiryToHSParam;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|