|
|
@@ -1,30 +1,38 @@
|
|
|
package thyyxxk.webserver.service.ca;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.IdcardUtil;
|
|
|
+import cn.hutool.core.util.URLUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.dtflys.forest.Forest;
|
|
|
import com.dtflys.forest.http.ForestRequest;
|
|
|
-import lombok.Data;
|
|
|
-import lombok.EqualsAndHashCode;
|
|
|
+import com.dtflys.forest.utils.ForestDataType;
|
|
|
+import lombok.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import thyyxxk.webserver.config.exception.BizException;
|
|
|
import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
import thyyxxk.webserver.constants.YesOrNo;
|
|
|
+import thyyxxk.webserver.dao.his.zhuyuanyisheng.emr.EmrPatientDao;
|
|
|
import thyyxxk.webserver.entity.ResultVo;
|
|
|
import thyyxxk.webserver.entity.ca.CaData;
|
|
|
import thyyxxk.webserver.entity.ca.CaReturn;
|
|
|
import thyyxxk.webserver.entity.ca.CaSendParams;
|
|
|
import thyyxxk.webserver.entity.ca.CaSingBizSnReturnData;
|
|
|
+import thyyxxk.webserver.entity.inpatient.patient.Patient;
|
|
|
import thyyxxk.webserver.entity.login.UserInfo;
|
|
|
import thyyxxk.webserver.service.redislike.RedisLikeService;
|
|
|
+import thyyxxk.webserver.service.zhuyuanyisheng.emr.EmrServer;
|
|
|
+import thyyxxk.webserver.utils.DateUtil;
|
|
|
import thyyxxk.webserver.utils.ResultVoUtil;
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -35,10 +43,14 @@ public class CaServer {
|
|
|
private final CaData caData;
|
|
|
private final String SUCCRSS = "success";
|
|
|
private final RedisLikeService redisLikeService;
|
|
|
+ private final EmrServer emrServer;
|
|
|
+ private final EmrPatientDao dao;
|
|
|
|
|
|
- public CaServer(CaData caData, RedisLikeService redisLikeService) {
|
|
|
+ public CaServer(CaData caData, RedisLikeService redisLikeService, EmrServer emrServer, EmrPatientDao dao) {
|
|
|
this.caData = caData;
|
|
|
this.redisLikeService = redisLikeService;
|
|
|
+ this.emrServer = emrServer;
|
|
|
+ this.dao = dao;
|
|
|
}
|
|
|
|
|
|
@EqualsAndHashCode(callSuper = true)
|
|
|
@@ -81,7 +93,7 @@ public class CaServer {
|
|
|
CaReturn caReturn;
|
|
|
try {
|
|
|
CaData.MobileApp app = caData.getMobileApp();
|
|
|
- ForestRequest<?> post = Forest.post(app.getUrl() + "/v1/push/sign");
|
|
|
+ ForestRequest<?> post = Forest.post(app.getUrl() + "/v1/push/sign").bodyType(ForestDataType.JSON);
|
|
|
send.setAppId(app.getAppId());
|
|
|
send.setMsg(CaUtils.GetSHA256FormString(send.getMsg()));
|
|
|
send.setMsgWrapper("0");
|
|
|
@@ -187,7 +199,7 @@ public class CaServer {
|
|
|
|
|
|
public ResultVo<CaSingBizSnReturnData> getSignInfoByBizSn(String bizSn) {
|
|
|
CaData.MobileApp app = caData.getMobileApp();
|
|
|
- ForestRequest<?> post = Forest.post(app.getUrl() + "/v1/sign/info/" + bizSn);
|
|
|
+ ForestRequest<?> post = Forest.post(app.getUrl() + "/v1/sign/info/" + bizSn).bodyType(ForestDataType.JSON);
|
|
|
CaSendParams send = new CaSendParams();
|
|
|
send.setAppId(app.getAppId());
|
|
|
|
|
|
@@ -213,4 +225,196 @@ public class CaServer {
|
|
|
return ResultVoUtil.success(ExceptionEnum.LOGICAL_ERROR, execute.getMsg());
|
|
|
}
|
|
|
|
|
|
+ @Data
|
|
|
+ public static class MoreEventSignData {
|
|
|
+ private String content;
|
|
|
+ /**
|
|
|
+ * 签署人身份类型。例如患者本人、亲属、朋友
|
|
|
+ * 、伴侣。进行 URLEncode 编码的数据,并且中
|
|
|
+ * 文长度不得大于 8
|
|
|
+ */
|
|
|
+ private String signType;
|
|
|
+ /**
|
|
|
+ * 签署人身份:
|
|
|
+ * 1:患者本人
|
|
|
+ * 2:亲属
|
|
|
+ * 3:朋友
|
|
|
+ * 4:伴侣
|
|
|
+ */
|
|
|
+ private Integer relation;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public static class MoreEventSign {
|
|
|
+ private String documentId;
|
|
|
+ private String codeRs;
|
|
|
+ private String code;
|
|
|
+ private List<MoreEventSignData> data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送签名到移动平板
|
|
|
+ * 这个接口没什么屌用
|
|
|
+ *
|
|
|
+ * @param moreEventSign 数据
|
|
|
+ * @return 暂无
|
|
|
+ */
|
|
|
+ public ResultVo<JSONObject> sendMoreEventSign(MoreEventSign moreEventSign) {
|
|
|
+ JSONObject data = getMoreEventSignData(moreEventSign);
|
|
|
+ String execute = Forest.post(caData.getHBoardSign().getUrl() + "/mobile/hBoardSign").addBody(data).bodyType(ForestDataType.JSON).execute(String.class);
|
|
|
+ JSONObject rst = JSONUtil.parseObj(execute);
|
|
|
+ String msg = rst.getByPath("ret_msg", String.class);
|
|
|
+ String decode = URLUtil.decode(msg);
|
|
|
+ log.info("入参:{}\n返回值:{},\n错误信息:{}", data, execute, decode);
|
|
|
+ return ResultVoUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject getMoreEventSignData(MoreEventSign moreEventSign) {
|
|
|
+ JSONObject ret = new JSONObject();
|
|
|
+ CaData.HBoardSign app = caData.getHBoardSign();
|
|
|
+ ret.set("api_key", app.getApiKey());
|
|
|
+ ret.set("api_secret", app.getApiSecret());
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.set("document_no", IdUtil.simpleUUID());
|
|
|
+ data.set("pdf", emrServer.getPdfBase(moreEventSign.getDocumentId()));
|
|
|
+ Patient patient = dao.getPatientInfoByDocumentId(moreEventSign.getDocumentId());
|
|
|
+ JSONArray signature = new JSONArray();
|
|
|
+
|
|
|
+ moreEventSign.getData().forEach(item -> {
|
|
|
+ JSONObject entries = new JSONObject();
|
|
|
+ entries.set("type", "keyword");
|
|
|
+ entries.set("sign_type", URLUtil.encode(item.getSignType()));
|
|
|
+ entries.set("keyword", new JSONObject() {{
|
|
|
+ set("page", "0");
|
|
|
+ set("content", URLUtil.encode(item.getContent()));
|
|
|
+ }});
|
|
|
+ JSONObject user_info = new JSONObject() {{
|
|
|
+ set("name", patient.getName());
|
|
|
+ set("idno", patient.getSocialNo());
|
|
|
+ set("age", IdcardUtil.getAgeByIdCard(patient.getSocialNo()));
|
|
|
+ }};
|
|
|
+ user_info.set("relation", item.getRelation());
|
|
|
+ entries.set("user_info", user_info);
|
|
|
+ signature.put(entries);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 签署信息
|
|
|
+ data.set("signature", signature);
|
|
|
+ data.set("doctor_info", new JSONObject() {{
|
|
|
+ set("doctor_no", moreEventSign.getCodeRs());
|
|
|
+ }});
|
|
|
+
|
|
|
+ data.set("pic_size", new JSONObject() {{
|
|
|
+ set("width", "120");
|
|
|
+ set("height", "30");
|
|
|
+ }});
|
|
|
+
|
|
|
+ ret.set("data", data);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public static class H5EventSign {
|
|
|
+ private String documentId;
|
|
|
+ private String content;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ @Builder
|
|
|
+ @AllArgsConstructor
|
|
|
+ @NoArgsConstructor
|
|
|
+ public static class H5Return {
|
|
|
+ private String id;
|
|
|
+ private String result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * h5 签名返回一个http连接
|
|
|
+ *
|
|
|
+ * @param value
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultVo<H5Return> h5EventSign(H5EventSign value) {
|
|
|
+ JSONObject ret = new JSONObject();
|
|
|
+ String uuid = IdUtil.simpleUUID();
|
|
|
+ CaData.HBoardSign app = caData.getHBoardSign();
|
|
|
+ ret.set("api_key", app.getApiKey());
|
|
|
+ ret.set("api_secret", app.getApiSecret());
|
|
|
+ ret.set("data", new JSONObject() {{
|
|
|
+ set("document_no", uuid);
|
|
|
+ set("pdf", emrServer.getPdfBase(value.getDocumentId()));
|
|
|
+ set("type", "keyword");
|
|
|
+ set("keyword", new JSONObject() {{
|
|
|
+ set("page", "0");
|
|
|
+ set("content", URLUtil.encode(value.getContent()));
|
|
|
+ }});
|
|
|
+ }});
|
|
|
+ String execute = Forest
|
|
|
+ .post(caData.getHBoardSign().getUrl() + "/seal/h5EventSign")
|
|
|
+ .addBody(ret)
|
|
|
+ .bodyType(ForestDataType.JSON)
|
|
|
+ .execute(String.class);
|
|
|
+
|
|
|
+ return getStringResultVo(execute, uuid);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<H5Return> hBoardSignV2(H5EventSign value) {
|
|
|
+ JSONObject ret = new JSONObject();
|
|
|
+ String uuid = IdUtil.simpleUUID();
|
|
|
+ ret.set("api_key", caData.getHBoardSign().getApiKey());
|
|
|
+ ret.set("api_secret", caData.getHBoardSign().getApiSecret());
|
|
|
+ ret.set("data", new JSONObject() {{
|
|
|
+ set("document_no", uuid);
|
|
|
+ set("pdf", emrServer.getPdfBase(value.getDocumentId()));
|
|
|
+ set("sign_way", "qrcode,face,hand_sign");
|
|
|
+ set("keyword", new JSONObject() {{
|
|
|
+ set("page", "0");
|
|
|
+ set("content", URLUtil.encode(value.getContent()));
|
|
|
+ }});
|
|
|
+ set("collection_source", "face_photos,hand_sign");
|
|
|
+ }});
|
|
|
+ String execute = Forest
|
|
|
+ .post(caData.getHBoardSign().getUrl() + "/v2/seal/hBoardSign")
|
|
|
+ .addBody(ret)
|
|
|
+ .bodyType(ForestDataType.JSON)
|
|
|
+ .execute(String.class);
|
|
|
+ return getStringResultVo(execute, uuid);
|
|
|
+ }
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private ResultVo<H5Return> getStringResultVo(String execute, String id) {
|
|
|
+ JSONObject rst = JSONUtil.parseObj(URLUtil.decode(execute));
|
|
|
+ String msg = rst.getByPath("ret_msg", String.class);
|
|
|
+
|
|
|
+ if (0 == rst.getByPath("ret_code", Integer.class)) {
|
|
|
+ H5Return build = H5Return.builder()
|
|
|
+ .result(rst.getByPath("sign_url", String.class))
|
|
|
+ .id(id)
|
|
|
+ .build();
|
|
|
+ return ResultVoUtil.success(build);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "签名失败" + msg);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public ResultVo<JSONObject> downloadSealV2(String documentId) {
|
|
|
+ JSONObject ret = new JSONObject();
|
|
|
+ ret.set("api_key", caData.getHBoardSign().getApiKey());
|
|
|
+ ret.set("api_secret", caData.getHBoardSign().getApiSecret());
|
|
|
+ ret.set("data", new JSONObject() {{
|
|
|
+ set("document_no", documentId);
|
|
|
+ }});
|
|
|
+ String execute = Forest
|
|
|
+ .post(caData.getHBoardSign().getUrl() + "/v2/seal/download")
|
|
|
+ .addBody(ret)
|
|
|
+ .bodyType(ForestDataType.JSON)
|
|
|
+ .execute(String.class);
|
|
|
+ JSONObject rst = JSONUtil.parseObj(execute);
|
|
|
+ String msg = URLUtil.decode(rst.getByPath("ret_msg", String.class));
|
|
|
+ if (0 == rst.getByPath("ret_code", Integer.class)) {
|
|
|
+ return ResultVoUtil.success(rst);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, msg);
|
|
|
+ }
|
|
|
+
|
|
|
}
|