HIS医保
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package com.dpkj.modules.chs.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.file.FileReader;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dpkj.common.config.ChsConfig;
|
||||
@@ -12,6 +13,7 @@ import com.dpkj.common.config.HisConfig;
|
||||
import com.dpkj.common.utils.IDGenerator;
|
||||
import com.dpkj.modules.chs.dll.HispayDll;
|
||||
import com.dpkj.modules.chs.service.IHispayService;
|
||||
import com.dpkj.modules.chs.vo.OutpatientBudgetModel;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
@@ -19,13 +21,11 @@ import com.jacob.com.Variant;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -42,82 +42,13 @@ public class HispayServiceImpl implements IHispayService {
|
||||
private final HisConfig hisConfig;
|
||||
private final ChsConfig chsConfig;
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject getPatientInfo(String type, String content) {
|
||||
Dispatch dispatch = instanceActive();
|
||||
|
||||
/**
|
||||
* 1、删除保存HIS读卡内容的文件 避免读取到错误信息
|
||||
*/
|
||||
// 获取HIS-CHS医保库路径
|
||||
String chsPath = System.getProperty("java.library.path");
|
||||
String filePath = chsPath + "/" + chsConfig.getFileName();
|
||||
// 删除文件
|
||||
FileUtil.del(FileUtil.file(filePath));
|
||||
|
||||
/**
|
||||
* 2、组装参数
|
||||
*/
|
||||
String soleid = IDGenerator.getSnowflakeIdToStr();
|
||||
JSONObject req = new JSONObject() {{
|
||||
put("timestamp", DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss")); // 请求发送时间
|
||||
put("requestid", soleid); // 唯一请求id
|
||||
put("operid", hisConfig.getOperationId()); // 调用者代码
|
||||
put("password", content); // 密码
|
||||
put("params", new JSONObject() {{
|
||||
put("cardtype", type); // 1.就诊卡,2.医保卡,5.门诊号,6.患者姓名和电话号码,8.电子健康码/卡,9.医保电子凭证
|
||||
put("cardno", ""); // 患者就诊卡号
|
||||
put("sfzh", ""); // 身份证号
|
||||
put("hzxm", ""); // 患者姓名
|
||||
put("phone", ""); // 患者电话号码
|
||||
}});
|
||||
}};
|
||||
Document document = XmlUtil.mapToXml(req, "request");
|
||||
String params = XmlUtil.toStr(document, "UTF-8", false, true);
|
||||
log.info("[HispayServiceImpl][getPatientInfo][医保读卡] 接口入参:{}", params);
|
||||
|
||||
/**
|
||||
* 3、调用COM函数
|
||||
*/
|
||||
Variant rest = new Variant();
|
||||
Variant call = Dispatch.call(dispatch, "fRun", "BMZXX010", params, rest);
|
||||
log.info("[HispayServiceImpl][getPatientInfo][医保读卡] call返回值:{}", call);
|
||||
|
||||
// 释放资源
|
||||
releaseActive();
|
||||
|
||||
/**
|
||||
* 4、处理读卡结果
|
||||
*/
|
||||
// COM函数调用之后会生成新的文件 需要判断
|
||||
File file = FileUtil.file(filePath);
|
||||
if (!file.exists()) {
|
||||
throw new RuntimeException("读卡失败:数据未读取");
|
||||
}
|
||||
|
||||
// 获取读卡结果
|
||||
FileReader fileReader = new FileReader(file, "GBK");
|
||||
String data = fileReader.readString();
|
||||
|
||||
JSONObject result;
|
||||
try {
|
||||
result = JSONObject.parseObject(data);
|
||||
log.info("[HispayServiceImpl][getPatientInfo][医保读卡] 读卡值:{}", result);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("读卡失败:" + data);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取HIS医保实例
|
||||
*
|
||||
* @return com.jacob.activeX.ActiveXComponent
|
||||
* @author 萧道子 2025/5/21
|
||||
*/
|
||||
private Dispatch instanceActive() {
|
||||
private ActiveXComponent instanceActive() {
|
||||
try {
|
||||
// 初始化
|
||||
ComThread.InitSTA();
|
||||
@@ -142,5 +73,227 @@ public class HispayServiceImpl implements IHispayService {
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理参数
|
||||
*
|
||||
* @param params : 请求参数
|
||||
* @param password : 密码
|
||||
* @return java.lang.String
|
||||
* @author 萧道子 2025/5/27
|
||||
*/
|
||||
private String processParameters(JSONObject params, String password) {
|
||||
JSONObject req = new JSONObject() {{
|
||||
put("timestamp", DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss")); // 请求发送时间
|
||||
put("requestid", IDGenerator.getSnowflakeIdToStr()); // 唯一请求id
|
||||
put("operid", hisConfig.getOperationId()); // 调用者代码
|
||||
put("password", password); // 密码
|
||||
put("params", params);
|
||||
}};
|
||||
Document document = XmlUtil.mapToXml(req, "request");
|
||||
return XmlUtil.toStr(document, "UTF-8", false, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验结果
|
||||
*
|
||||
* @param resStr :
|
||||
* @return com.alibaba.fastjson.JSONObject
|
||||
* @author 萧道子 2025/5/28
|
||||
*/
|
||||
private JSONObject verifyResult(String resStr) {
|
||||
|
||||
if (StrUtil.isBlank(resStr)) {
|
||||
throw new RuntimeException("信息获取失败");
|
||||
}
|
||||
|
||||
Map<String, Object> resMap = XmlUtil.xmlToMap(resStr);
|
||||
JSONObject resJson = new JSONObject(resMap);
|
||||
|
||||
if (StrUtil.equals(resJson.getString("resultCode"), "1")) {
|
||||
throw new RuntimeException(resJson.getString("resultMessage"));
|
||||
}
|
||||
|
||||
if (!resJson.containsKey("result")) {
|
||||
throw new RuntimeException("result数据为空");
|
||||
}
|
||||
|
||||
return resJson.getJSONObject("result");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject readCode() {
|
||||
// 加载资源
|
||||
Dispatch dispatch = instanceActive();
|
||||
|
||||
/** 1、组装参数 */
|
||||
JSONObject val = new JSONObject()
|
||||
.fluentPut("cardtype", "9") // 1.就诊卡,2.医保卡,5.门诊号,6.患者姓名和电话号码,8.电子健康码/卡,9.医保电子凭证
|
||||
.fluentPut("cardno", "") // 患者就诊卡号
|
||||
.fluentPut("sfzh", "") // 身份证号
|
||||
.fluentPut("hzxm", "") // 患者姓名
|
||||
.fluentPut("phone", ""); // 患者电话号码
|
||||
String params = processParameters(val, null);
|
||||
log.info("[HispayServiceImpl][readCode][医保读卡-电子凭证] 接口入参:{}", params);
|
||||
|
||||
/** 2、调用COM函数 */
|
||||
Variant vres = new Variant("", true);
|
||||
Variant call = Dispatch.call(dispatch, "fRun", "BMZXX010", params, vres);
|
||||
|
||||
String resStr = vres.getStringRef();
|
||||
log.info("[HispayServiceImpl][readCode][医保读卡-电子凭证] call返回值:{} 结果:{}", call, resStr);
|
||||
|
||||
// 释放资源
|
||||
releaseActive();
|
||||
|
||||
/** 3、处理读卡结果 */
|
||||
JSONObject result = verifyResult(resStr);
|
||||
if (!result.containsKey("item")) {
|
||||
throw new RuntimeException("item数据为空");
|
||||
}
|
||||
|
||||
return result.getJSONObject("item");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject readCard(String password) {
|
||||
// 加载资源
|
||||
Dispatch dispatch = instanceActive();
|
||||
|
||||
/** 1、组装参数 */
|
||||
JSONObject val = new JSONObject()
|
||||
.fluentPut("cardtype", "2") // 1.就诊卡,2.医保卡,5.门诊号,6.患者姓名和电话号码,8.电子健康码/卡,9.医保电子凭证
|
||||
.fluentPut("cardno", "") // 患者就诊卡号
|
||||
.fluentPut("sfzh", "") // 身份证号
|
||||
.fluentPut("hzxm", "") // 患者姓名
|
||||
.fluentPut("phone", ""); // 患者电话号码
|
||||
String params = processParameters(val, password);
|
||||
log.info("[HispayServiceImpl][readCard][医保读卡-医保卡] 接口入参:{}", params);
|
||||
|
||||
/** 2、调用COM函数 */
|
||||
Variant vres = new Variant("", true);
|
||||
Variant call = Dispatch.call(dispatch, "fRun", "BMZXX010", params, vres);
|
||||
|
||||
String resStr = vres.getStringRef();
|
||||
log.info("[HispayServiceImpl][readCard][医保读卡-医保卡] call返回值:{} 结果:{}", call, resStr);
|
||||
|
||||
// 释放资源
|
||||
releaseActive();
|
||||
|
||||
/** 3、处理读卡结果 */
|
||||
JSONObject result = verifyResult(resStr);
|
||||
if (!result.containsKey("item")) {
|
||||
throw new RuntimeException("item数据为空");
|
||||
}
|
||||
|
||||
return result.getJSONObject("item");
|
||||
}
|
||||
|
||||
|
||||
// public JSONObject getPatientInfo_old(String type, String content) {
|
||||
// Dispatch dispatch = instanceActive();
|
||||
//
|
||||
// /**
|
||||
// * 1、删除保存HIS读卡内容的文件 避免读取到错误信息
|
||||
// */
|
||||
// // 获取HIS-CHS医保库路径
|
||||
// String chsPath = System.getProperty("java.library.path");
|
||||
// String filePath = chsPath + "/" + chsConfig.getFileName();
|
||||
// // 删除文件
|
||||
// FileUtil.del(FileUtil.file(filePath));
|
||||
//
|
||||
// /**
|
||||
// * 2、组装参数
|
||||
// */
|
||||
// JSONObject val = new JSONObject()
|
||||
// .fluentPut("cardtype", type) // 1.就诊卡,2.医保卡,5.门诊号,6.患者姓名和电话号码,8.电子健康码/卡,9.医保电子凭证
|
||||
// .fluentPut("cardno", "") // 患者就诊卡号
|
||||
// .fluentPut("sfzh", "") // 身份证号
|
||||
// .fluentPut("hzxm", "") // 患者姓名
|
||||
// .fluentPut("phone", ""); // 患者电话号码
|
||||
// String params = processParameters(val, content);
|
||||
// log.info("[HispayServiceImpl][getPatientInfo][医保读卡] 接口入参:{}", params);
|
||||
//
|
||||
// /**
|
||||
// * 3、调用COM函数
|
||||
// */
|
||||
// Variant rest = new Variant();
|
||||
// Variant call = Dispatch.call(dispatch, "fRun", "BMZXX010", params, rest);
|
||||
// log.info("[HispayServiceImpl][getPatientInfo][医保读卡] call返回值:{}", call);
|
||||
//
|
||||
// // 释放资源
|
||||
// releaseActive();
|
||||
//
|
||||
// /**
|
||||
// * 4、处理读卡结果
|
||||
// */
|
||||
// // COM函数调用之后会生成新的文件 需要判断
|
||||
// File file = FileUtil.file(filePath);
|
||||
// if (!file.exists()) {
|
||||
// throw new RuntimeException("读卡失败:数据未读取");
|
||||
// }
|
||||
//
|
||||
// // 获取读卡结果
|
||||
// FileReader fileReader = new FileReader(file, "GBK");
|
||||
// String data = fileReader.readString();
|
||||
//
|
||||
// JSONObject result;
|
||||
// try {
|
||||
// result = JSONObject.parseObject(data);
|
||||
// log.info("[HispayServiceImpl][getPatientInfo][医保读卡] 读卡值:{}", result);
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException("读卡失败:" + data);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
|
||||
private JSONObject outpatientBudget(OutpatientBudgetModel data) {
|
||||
// 加载资源
|
||||
ActiveXComponent dispatch = instanceActive();
|
||||
|
||||
/** 1、组装参数 */
|
||||
JSONObject val = new JSONObject()
|
||||
.fluentPut("patid", data.getPatientId()) // 病人ID
|
||||
.fluentPut("cfxhhj", data.getPrescriptionNo()) // 划价单据,格式:单据1,单据2,单据3
|
||||
.fluentPut("czksfbz", "0") // 是否扣院内账户,0不使用院内账户,1使用院内账户(默认不使用院内账户)
|
||||
.fluentPut("zfjsbz", "0") // 是否自费结算,0根据医保代码缴费,1自费结算(默认自费结算)
|
||||
.fluentPut("ybrc", ""); // 医保入参,xml节点
|
||||
String params = processParameters(val, data.getPassword());
|
||||
log.info("[HispayServiceImpl][outpatientBudget][门诊缴费-预算] 接口入参:{}", params);
|
||||
|
||||
/** 2、调用COM函数 */
|
||||
Variant resVariant = new Variant("", true);
|
||||
Variant call = Dispatch.call(dispatch, "fRun", "BMZJF001", params, resVariant);
|
||||
|
||||
String resStr = resVariant.getStringRef();
|
||||
log.info("[HispayServiceImpl][outpatientBudget][门诊缴费-预算] call返回值:{} 结果:{}", call, resStr);
|
||||
|
||||
// 释放资源
|
||||
releaseActive();
|
||||
|
||||
/** 3、处理结果 */
|
||||
return verifyResult(resStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject outpatientBudgetByCode(OutpatientBudgetModel data) {
|
||||
JSONObject userInfo = readCode();
|
||||
|
||||
String patientId = userInfo.getString("patid");
|
||||
data.setPatientId(patientId);
|
||||
JSONObject result = outpatientBudget(data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject outpatientBudgetByCard(OutpatientBudgetModel data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user