939 lines
28 KiB
JavaScript
939 lines
28 KiB
JavaScript
const dayjs = require("dayjs");
|
||
const { decode } = require('iconv-lite');
|
||
const request = require("../../request");
|
||
|
||
// const baseUrl = "http://115.239.161.48:8089"; //his说 8089可能会关闭,用8083
|
||
const baseUrl = process.env.CONFIG_ZYT_HIS_BASE_URL;
|
||
|
||
const AppWin = {
|
||
line: '线上挂号',
|
||
win: '线下挂号',
|
||
}
|
||
|
||
module.exports = async (item) => {
|
||
switch (item.type) {
|
||
case "getHisCustomer":
|
||
return await getHisCustomer(item);
|
||
case "addHisCustomer":
|
||
return await addHisCustomer(item);
|
||
case "registration":
|
||
return await registration(item);
|
||
case "getPayStatus":
|
||
return await getPayStatus(item);
|
||
case "hlwRefund":
|
||
return await hlwRefund(item);
|
||
case "hlwuploadprescription":
|
||
return await hlwuploadprescription(item);
|
||
case "hlwPrescriptionOrderStatus":
|
||
return await hlwPrescriptionOrderStatus(item);
|
||
case "getHisPrescriptionUploadStatus":
|
||
return await getHisPrescriptionUploadStatus(item);
|
||
case "getHisStoreRegList":
|
||
return await getHisStoreRegList(item);
|
||
case "insurancePreSettle":
|
||
return await insurancePreSettle(item);
|
||
case "insuranceSettle":
|
||
return await insuranceSettle(item);
|
||
case "insuranceRefund":
|
||
return await insuranceRefund(item);
|
||
case "getRecent90daysDrugRecord":
|
||
return await getRecent90daysDrugRecord(item);
|
||
case "uploadMedicinePurchaseRx":
|
||
return await uploadMedicinePurchaseRx(item);
|
||
case "uploadWinePurchaseRx":
|
||
return await uploadWinePurchaseRx(item);
|
||
case "getHisDrugInfo":
|
||
return await getHisDrugInfo(item);
|
||
case "getHisMedicinePurchase":
|
||
return await getHisMedicinePurchase(item);
|
||
case "cancelMedicinePurchase":
|
||
return await cancelMedicinePurchase(item);
|
||
case "refundMedicinePurchase":
|
||
return await refundMedicinePurchase(item);
|
||
case "getHisInvoice":
|
||
return await getHisInvoice(item);
|
||
case "updateMedicinePurchaseDelivery":
|
||
return await updateMedicinePurchaseDelivery(item);
|
||
case 'syncHisChargeStatus':
|
||
return await syncHisChargeStatus(item);
|
||
case "hisTest":
|
||
return await hisTest(item);
|
||
case "getHisEmployeeInfo":
|
||
return await getHisEmployeeInfo(item);
|
||
case "syncHisRefundStatus":
|
||
return await syncHisRefundStatus(item);
|
||
case "getWineDrugStockInfo":
|
||
return await getWineDrugStockInfo(item);
|
||
case "ybReviewPrescription":
|
||
return await ybReviewPrescription(item);
|
||
}
|
||
};
|
||
|
||
async function getHisCustomer(item) {
|
||
const { idCard, anotherIdNo } = item;
|
||
try {
|
||
const params = { type: "01" };
|
||
if (idCard) {
|
||
params.idnumber = idCard;
|
||
} else if (anotherIdNo) {
|
||
const Sm4Util = require('../../utils/sm4-util');
|
||
params.idnumber = Sm4Util.decryptDataForSm3(anotherIdNo);
|
||
}
|
||
if (!params.idnumber) {
|
||
return { success: false, message: '证件号不能为空' }
|
||
}
|
||
const url = `${baseUrl}/his/hlw/patientinfo`;
|
||
const { data, status_code, message } = await request.main(url, params, "POST");
|
||
if (status_code == 200 && !message) {
|
||
return {
|
||
success: true,
|
||
list: data?.patients,
|
||
patient: data?.patients?.[0],
|
||
message: `[his]查询档案:获取his档案成功`,
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: message || "获取失败",
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: err.message || "获取失败",
|
||
};
|
||
}
|
||
}
|
||
/**
|
||
*
|
||
* @param {buildType} 建档类型 1.自费建档 2.电子凭证建档 3.线下医保建档
|
||
* @returns
|
||
*/
|
||
async function addHisCustomer(item) {
|
||
let { idCard, name, mobile, address, psnToken, buildType = '1', mdtrt_cert_type, mdtrt_cert_no, card_sn } = item;
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/patientbulid`;
|
||
const payload = {
|
||
type: buildType,
|
||
name,
|
||
socialno: idCard,
|
||
tel: mobile,
|
||
};
|
||
if (typeof address === "string") {
|
||
payload.address = address;
|
||
}
|
||
// 电子凭证建档 医保插件授权建档
|
||
if (psnToken) {
|
||
payload.psnToken = psnToken;
|
||
payload.type = "2";
|
||
}
|
||
// 线下医保建档
|
||
// mdtrt_cert_type 就诊凭证类型 01 | 03
|
||
// mdtrt_cert_no 就诊凭证号码 mdtrt_cert_type为01 填写电子凭证令牌 | mdtrt_cert_type为03 填写社会保障卡卡号
|
||
if (mdtrt_cert_type) {
|
||
payload.mdtrt_cert_type = mdtrt_cert_type;
|
||
payload.mdtrt_cert_no = mdtrt_cert_no;
|
||
payload.card_sn = card_sn; //就诊凭证类型为“03”时填写社会保障卡内码
|
||
payload.type = "3";
|
||
}
|
||
|
||
const { data, status_code, message } = await request.main(
|
||
url,
|
||
payload,
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && !message) {
|
||
return {
|
||
success: true,
|
||
list: data?.patients,
|
||
message: "获取成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: message || "获取失败",
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: "获取失败",
|
||
};
|
||
}
|
||
}
|
||
|
||
// 预约挂号
|
||
async function registration(item) {
|
||
const { patientId, doctorCode, appwin = 'line', unitCode, registerId, chargecode, reg_fee, shopid, shopname, op_id = '', channel } = item;
|
||
if (AppWin[appwin] == undefined) {
|
||
return {
|
||
success: false,
|
||
message: "appwin参数错误"
|
||
}
|
||
}
|
||
if (AppWin[appwin] == '线下挂号' && (typeof op_id !== 'string' || op_id.trim() === '')) {
|
||
return {
|
||
success: false,
|
||
message: "op_id参数错误"
|
||
}
|
||
}
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/registration`;
|
||
// 根据dayjs 判断是上午 还是下午
|
||
const ampm = dayjs().hour() < 12 ? "a" : "p";
|
||
const requestday = dayjs().format("YYYY-MM-DD HH:mm:ss");
|
||
// registerId 为 H开头 15位随机数
|
||
const payload = {
|
||
patientId,
|
||
doctorCode,
|
||
unitCode,
|
||
requestday,
|
||
ampm,
|
||
registerId,
|
||
chargecode,
|
||
reg_fee,
|
||
shopid,
|
||
shopname,
|
||
chargetype: "普通",
|
||
appwin
|
||
};
|
||
if (AppWin[appwin] == '线下挂号') {
|
||
payload.op_id = op_id;
|
||
}
|
||
if (channel === 1) {
|
||
payload.channel = 1
|
||
}
|
||
const { data, status_code, message } = await request.main(
|
||
url,
|
||
payload,
|
||
"POST"
|
||
);
|
||
if (data && data.register && data.register.medorg_order_no) {
|
||
return {
|
||
success: true,
|
||
data,
|
||
message: message || "挂号成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: message || "挂号失败",
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: err.message || "挂号失败"
|
||
};
|
||
}
|
||
}
|
||
|
||
//订单支付状态查询
|
||
async function getPayStatus(item) {
|
||
const { patientId, registerId, medorgOrderNo } = item;
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/settlement`;
|
||
const { status, status_code, message, ...rest } = await request.main(
|
||
url,
|
||
{
|
||
patientid: patientId,
|
||
registerid: registerId,
|
||
medorg_order_no: medorgOrderNo,
|
||
},
|
||
"POST"
|
||
);
|
||
const settlement =
|
||
rest.data && rest.data.settlement ? rest.data.settlement : null;
|
||
//settlement.status 0 已收费 1 已退费 5 未收费 x 已作废
|
||
if (status_code == 200) {
|
||
return {
|
||
success: true,
|
||
status: settlement ? settlement.status : '',
|
||
settlement,
|
||
message: "订单查询成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: message || "获取失败",
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: "获取失败",
|
||
};
|
||
}
|
||
}
|
||
|
||
//医保患者退费
|
||
async function hlwRefund(item) {
|
||
const { patientId, registerId, medorgOrderNo } = item;
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/refund`;
|
||
const { data, status_code, message, ...rest } = await request.main(
|
||
url,
|
||
{
|
||
patientid: patientId,
|
||
registerid: registerId,
|
||
medorg_order_no: medorgOrderNo,
|
||
},
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && !message) {
|
||
return {
|
||
success: true,
|
||
message: "退费成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: message || "退费失败",
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: "退费失败",
|
||
};
|
||
}
|
||
}
|
||
|
||
// 6.外配处方回写
|
||
/**
|
||
*
|
||
* @param {*} param0
|
||
* @returns
|
||
*/
|
||
async function hlwuploadprescription(item) {
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/ordersave`;
|
||
const { code, status_code, message } = await request.main(
|
||
url,
|
||
item.data,
|
||
"POST"
|
||
);
|
||
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
return {
|
||
success: true,
|
||
message: "[his]处方上传成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: `[his]处方上传失败: ${message || '未知错误'}`,
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: `[his]处方上传错误: ${err.message || '未知错误'}`,
|
||
};
|
||
}
|
||
}
|
||
|
||
// 外配处方状态查询
|
||
async function hlwPrescriptionOrderStatus(item) {
|
||
const { patientId, orderno } = item;
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/orderstatus`;
|
||
const { status_code, message, data } = await request.main(
|
||
url,
|
||
{
|
||
patientid: patientId,
|
||
orderno,
|
||
},
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && data && data.orderstatus) {
|
||
return {
|
||
success: true,
|
||
uploaded: data.orderstatus.status == '1',
|
||
status: data.orderstatus.status,
|
||
message: "查询成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: message || "查询失败",
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: "查询失败",
|
||
};
|
||
}
|
||
}
|
||
|
||
async function getHisPrescriptionUploadStatus(item) {
|
||
const { patientId, orderno, _id } = item;
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/orderstatus`;
|
||
const { status_code, message, data } = await request.main(
|
||
url,
|
||
{
|
||
patientid: patientId,
|
||
orderno,
|
||
},
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && data && data.orderstatus && data.orderstatus.status == 1) {
|
||
return { orderno, hisUploadStatus: 'uploaded', _id }
|
||
}
|
||
if (status_code == 200 && data && data.orderstatus && data.orderstatus.status == -1) {
|
||
return { orderno, hisUploadStatus: 'error', _id }
|
||
}
|
||
if (status_code == 200 && data && data.orderstatus && data.orderstatus.status == 0) {
|
||
return { orderno, hisUploadStatus: 'notUploaded', _id }
|
||
}
|
||
return {
|
||
success: false,
|
||
message: message || "查询失败",
|
||
|
||
};
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: "查询失败",
|
||
};
|
||
}
|
||
|
||
}
|
||
|
||
async function getHisStoreRegList(item) {
|
||
const { storeId: shopid } = item;
|
||
if (typeof shopid !== 'string' || shopid.trim() === '') {
|
||
return {
|
||
success: false,
|
||
message: "店铺id无效",
|
||
};
|
||
}
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/registerquery`;
|
||
const { status_code, message, data } = await request.main(
|
||
url,
|
||
{
|
||
shopid,
|
||
requestday: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||
status: "0",
|
||
starttime: dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
|
||
endtime: dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss'),
|
||
hospid: "108",
|
||
},
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && Array.isArray(data)) {
|
||
return {
|
||
success: true,
|
||
list: data,
|
||
message: "查询成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: message || "查询失败",
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: "查询失败",
|
||
};
|
||
}
|
||
}
|
||
|
||
async function insurancePreSettle(ctx) {
|
||
const {
|
||
medorg_order_no: orderno,
|
||
patientId: patientid,
|
||
mdtrtCertNo: mdtrt_cert_no,
|
||
mdtrtCertType: mdtrt_cert_type,
|
||
cardSn: card_sn,
|
||
operator_code,
|
||
operator_name,
|
||
shopid,
|
||
hospid = "108"
|
||
} = ctx;
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/presettle`;
|
||
const payload = { orderno, patientid, mdtrt_cert_no, mdtrt_cert_type, card_sn, operator_code, operator_name, hospid, shopid };
|
||
const { data, status_code, message } = await request.main(url, payload, "POST");
|
||
|
||
if (status_code == 200 && !message) {
|
||
return { success: true, data, message: '预结算成功' }
|
||
}
|
||
return { success: false, message: message || '预结算失败' }
|
||
} catch (e) {
|
||
return { success: false, message: e.message || '预结算失败' }
|
||
}
|
||
}
|
||
|
||
async function insuranceSettle(ctx) {
|
||
const {
|
||
patientid,
|
||
orderno,
|
||
mdtrt_id,
|
||
mdtrt_cert_no,
|
||
outparm_1101,
|
||
outparm_2206A,
|
||
inparm_2207A,
|
||
outparm_2204,
|
||
totalamount,
|
||
selfpay,
|
||
operator_code,
|
||
operator_name
|
||
} = ctx;
|
||
const payload = {
|
||
patientid,
|
||
orderno,
|
||
settle_method: '7',
|
||
paymethod: '1', // 1: 现金 w: 支付宝 z: 微信
|
||
paysn: '',
|
||
payrequestsn: '',
|
||
mdtrt_id,
|
||
mdtrt_cert_no,
|
||
outparm_1101,
|
||
outparm_2206A,
|
||
inparm_2207A,
|
||
outparm_2204,
|
||
totalamount,
|
||
selfpay,
|
||
operator_code,
|
||
operator_name
|
||
}
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/ybsettle`;
|
||
// const url = `${baseUrl}/his/hlw/presettle`;
|
||
const { data, status_code, message } = await request.main(url, payload, "POST");
|
||
if (status_code == 200 && !message) {
|
||
return { success: true, data, message: '结算成功' }
|
||
}
|
||
return { success: false, message: message || '结算失败' }
|
||
} catch (e) {
|
||
return { success: false, message: e.message || '结算失败' }
|
||
}
|
||
}
|
||
|
||
async function insuranceRefund(ctx) {
|
||
const { type, ...payload } = ctx;
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/ybrefund`;
|
||
// const url = `${baseUrl}/his/hlw/presettle`;
|
||
const { data, status_code, message } = await request.main(url, payload, "POST");
|
||
if (status_code == 200 && !message) {
|
||
return { success: true, data, message: '退费成功' }
|
||
}
|
||
return { success: false, message: message || '退费失败' }
|
||
} catch (e) {
|
||
return { success: false, message: e.message || '退费失败' }
|
||
}
|
||
}
|
||
|
||
async function getRecent90daysDrugRecord(ctx) {
|
||
const patientid = typeof ctx.patientId === 'string' ? ctx.patientId.trim() : '';
|
||
if (patientid === '') {
|
||
return { success: false, message: '患者ID不能为空' }
|
||
}
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/patientzj3100`;
|
||
const payload = { patientid, hospid: "108", doctorCode: '10021' };
|
||
if (typeof ctx.doctorcode === 'string' && ctx.doctorcode.trim() !== '') {
|
||
payload.doctorcode = ctx.doctorcode.trim();
|
||
}
|
||
const { data, status_code, message } = await request.main(url, payload, "POST");
|
||
|
||
|
||
if (status_code == 200 && !message && data && data.outparm_zj3100) {
|
||
// 解析医保用药数据列表
|
||
const decodedBuffer = Buffer.from(data.outparm_zj3100, 'base64');
|
||
const gbkDecodedStr = decode(decodedBuffer, 'gbk');
|
||
const res = JSON.parse(gbkDecodedStr);
|
||
const drugList = res && res.data && Array.isArray(res.data.lists) ? res.data.lists.map(i => ({
|
||
hiListName: i.hiListName,
|
||
insuranceCode: i.hilistCode,
|
||
mdtrtId: i.mdtrtId,
|
||
quantity: i.cnt,
|
||
spec: i.spec && i.spec !== 'null' ? i.spec : '',
|
||
unit: i.unit && i.unit !== 'null' ? i.unit : ''
|
||
})) : [];
|
||
|
||
// 解析医保记录
|
||
const decodedBuffer1 = Buffer.from(data.outparm_zj3101, 'base64');
|
||
const gbkDecodedStr1 = decode(decodedBuffer1, 'gbk');
|
||
const res1 = JSON.parse(gbkDecodedStr1);
|
||
const recordList = res1 && res1.data && Array.isArray(res1.data.lists) ? res1.data.lists.map(i => ({
|
||
mdtrtId: i.mdtrtId,
|
||
date: i.admDate,
|
||
medinsName: i.medinsName,
|
||
})) : [];
|
||
|
||
return { success: true, drugList, message: '查询成功', recordList }
|
||
}
|
||
return { success: false, message: message || '查询失败' }
|
||
} catch (e) {
|
||
return { success: false, message: e.message || '查询失败' }
|
||
}
|
||
}
|
||
|
||
async function getHisDrugInfo(item) {
|
||
try {
|
||
const ignoreAreaCode = typeof item.ignoreAreaCode === 'boolean' ? item.ignoreAreaCode : false;
|
||
if (!ignoreAreaCode && (typeof item.areaCode !== 'string' || item.areaCode.trim() === '')) {
|
||
return { success: false, message: '区域代码不能为空' }
|
||
}
|
||
const showAll = typeof item.showAll === 'boolean' ? item.showAll : false;
|
||
const gjbm = Array.isArray(item.insuranceCodes) ? item.insuranceCodes.filter(i => typeof i === 'string' && i.trim() !== '') : [];
|
||
console.log('gjbm: ', gjbm)
|
||
if (gjbm.length === 0 && !showAll) {
|
||
return { success: false, message: '医保编码不能为空' }
|
||
}
|
||
const url = `${baseUrl}/his/hlw/drug`;
|
||
const payload = {
|
||
hospid: '108',
|
||
drug_type: 'xy',
|
||
area_code: typeof item.areaCode === 'string' ? item.areaCode.trim() : '',
|
||
gjbm: gjbm.join(',')
|
||
}
|
||
const { code, status_code, message, data } = await request.main(
|
||
url,
|
||
payload,
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
return {
|
||
success: true,
|
||
message: "[his]查询药品信息成功",
|
||
data: data && Array.isArray(data.drugs) ? data.drugs : []
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: `[his]查询药品信息传失败: ${message || '未知错误'}`,
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: `[his]查询药品信息传错误: ${err.message || '未知'}`,
|
||
};
|
||
}
|
||
}
|
||
|
||
async function uploadMedicinePurchaseRx(item) {
|
||
try {
|
||
const { data } = item;
|
||
const url = `${baseUrl}/his/hlw/mzordersave`;
|
||
const { code, status_code, message } = await request.main(
|
||
url,
|
||
data,
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
return {
|
||
success: true,
|
||
message: "[his]购药订单处上传成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: `[his]购药订单处方上传失败: ${message || '未知错误'}`,
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: `[his]购药订单处方上传错误: ${err.message || '未知'}`,
|
||
};
|
||
}
|
||
}
|
||
|
||
async function uploadWinePurchaseRx(item) {
|
||
try {
|
||
const { data } = item;
|
||
const url = `${baseUrl}/his/hlw/tcsave`;
|
||
const { code, status_code, message } = await request.main(
|
||
url,
|
||
data,
|
||
"POST"
|
||
);
|
||
console.log('data', code, status_code, message);
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
return {
|
||
success: true,
|
||
message: "[his]浸酒处上传成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: `[his]浸酒处方上传失败: ${message || '未知错误'}`,
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: `[his]浸酒处方上传错误: ${err.message || '未知'}`,
|
||
};
|
||
}
|
||
}
|
||
|
||
// hlwuploadprescription
|
||
async function ybReviewPrescription(item) {
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/ybsh`;
|
||
const { code, data, status_code, message } = await request.main(
|
||
url,
|
||
item.data,
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
const str = Buffer.from(data, 'base64');
|
||
const dataStr = decode(str, 'gbk');
|
||
const strData = JSON.parse(dataStr);
|
||
const result = strData && strData.output && Array.isArray(strData.output.result) ? strData.output.result.filter(Boolean) : [];
|
||
const advices = result.map(i => ({
|
||
name: typeof i.rule_name === 'string' ? i.rule_name.trim() : '',
|
||
text: typeof i.vola_cont === 'string' ? i.vola_cont.trim() : '',
|
||
})).filter(i => i.name || i.text)
|
||
return {
|
||
success: true,
|
||
advices,
|
||
message: "[his]医保审核成功",
|
||
};
|
||
} else {
|
||
return {
|
||
success: false,
|
||
message: `[his]医保审核失败: ${message || '未知错误'}`,
|
||
};
|
||
}
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: `[his]医保审核错误: ${err.message || '未知错误'}`,
|
||
};
|
||
}
|
||
}
|
||
|
||
|
||
async function getHisMedicinePurchase({ patientId, orderNo }) {
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/orderquery`;
|
||
const { code, status_code, message, data } = await request.main(url, { patientid: patientId, orderno: orderNo }, "POST");
|
||
const order = data && Array.isArray(data.orders) ? data.orders[0] : null;
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
if (order) {
|
||
return { success: true, data: order, message: '查询成功' }
|
||
}
|
||
return { success: false, message: `[his]处方订单查询失败: 未找到订单` }
|
||
}
|
||
return {
|
||
success: false,
|
||
message: `[his]处方订单查询失败: ${message || '未知错误'}`,
|
||
};
|
||
} catch (err) {
|
||
return { success: false, message: `[his]处方订单查询错误: ${err.message || '未知错误'}` };
|
||
}
|
||
}
|
||
|
||
async function cancelMedicinePurchase({ patientId: patientid, orderNo: orderno }) {
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/ordercancel`;
|
||
const { code, status_code, message } = await request.main(url, { patientid, orderno }, "POST");
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
return { success: true, message: '[his]取消购药订单处方成功' }
|
||
}
|
||
return { success: false, message: `[his]取消购药订单处方失败: ${message || '未知错误'}` }
|
||
} catch (err) {
|
||
return { success: false, message: `[his]取消购药订单处方错误: ${err.message || '未知错误'}` };
|
||
}
|
||
}
|
||
|
||
async function refundMedicinePurchase({ patientId: patientid, orderNo: orderno }) {
|
||
try {
|
||
const url = `${baseUrl}/his/hlw/orderrefund`;
|
||
const { code, status_code, message } = await request.main(url, { patientid, orderno }, "POST");
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
return { success: true, message: '[his]退费购药订单处方成功' }
|
||
}
|
||
return { success: false, message: `[his]退费购药订单处方失败: ${message || '未知错误'}` }
|
||
} catch (err) {
|
||
return { success: false, message: `[his]退费购药订单处方错误: ${err.message || '未知错误'}` };
|
||
}
|
||
}
|
||
|
||
async function getHisInvoice(item) {
|
||
try {
|
||
const { patientId, orderNo } = item;
|
||
const url = `${baseUrl}/his/hlw/dzfp`;
|
||
let { code, status_code, message, data } = await request.main(url, { patientid: patientId, orderno: orderNo }, "POST");
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
const dzfp = data && Array.isArray(data.dzfp) ? data.dzfp[0] : null;
|
||
return { success: true, data: dzfp && dzfp.dzfp_url ? dzfp.dzfp_url : '', message: '发票查询成功' }
|
||
}
|
||
return { success: false, message: `[his]发票查询失败: ${message || '未知错误'}` }
|
||
} catch (err) {
|
||
return { success: false, message: `[his]发票查询错误: ${err.message || '未知错误'}` };
|
||
}
|
||
}
|
||
|
||
async function updateMedicinePurchaseDelivery(item) {
|
||
try {
|
||
const {
|
||
patientId: patientid,
|
||
orderNo: orderno,
|
||
backFlag: back_flag = 0,
|
||
shippingType: deliv_type,
|
||
shippingNo: deliv_no,
|
||
shippingFee: deliv_fee,
|
||
pickupCode: tracking_no,
|
||
payTime: pay_dt,
|
||
tradeNo: pay_orderno,
|
||
receiveName: shipp_name,
|
||
receivePhone: shipp_tel,
|
||
fullAddress: shipp_addr,
|
||
invoice
|
||
} = item;
|
||
const payload = {
|
||
patientid,
|
||
orderno,
|
||
back_flag, // 0 收取运费 | 1 退还运费
|
||
deliv_type,
|
||
deliv_no,
|
||
deliv_fee,
|
||
pay_dt,
|
||
pay_orderno,
|
||
shipp_name,
|
||
shipp_tel,
|
||
shipp_addr,
|
||
tracking_no,
|
||
invoice
|
||
}
|
||
const url = `${baseUrl}/his/hlw/delivery`;
|
||
let { code, status_code, message, data } = await request.main(url, payload, "POST");
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
return { success: true, data, message: '[his]同步配药订单物流信息成功' }
|
||
}
|
||
return { success: false, message: `[his]同步配药订单物流信息失败: ${message || '未知错误'}` }
|
||
} catch (err) {
|
||
return { success: false, message: `[his]同步配药订单物流信息错误: ${err.message || '未知错误'}` };
|
||
}
|
||
}
|
||
|
||
async function syncHisChargeStatus(ctx) {
|
||
try {
|
||
const payload = {
|
||
patientid: ctx.patientId,
|
||
orderno: ctx.orderNo,
|
||
settle_method: 1,
|
||
paymethod: 'h',
|
||
paysn: ctx.tradeNo,
|
||
payrequestsn: ctx.outTradeNo,
|
||
totalamount: ctx.totalAmount,
|
||
selfpay: ctx.totalAmount,
|
||
operator_code: 'hlw',
|
||
operator_name: '互联网医院'
|
||
}
|
||
const url = `${baseUrl}/his/hlw/ybsettle`;
|
||
let { code, status_code, message, data } = await request.main(url, payload, "POST");
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
return { success: true, data, message: '[his]同步浸酒订单收费成功' }
|
||
}
|
||
return { success: false, message: `[his]同步浸酒订单收费失败: ${message || '未知错误'}` }
|
||
} catch (err) {
|
||
return { success: false, message: `[his]同步浸酒订单收费错误: ${err.message || '未知错误'}` };
|
||
}
|
||
}
|
||
|
||
async function syncHisRefundStatus(ctx) {
|
||
try {
|
||
const payload = {
|
||
patientid: ctx.patientId,
|
||
orderno: ctx.orderNo,
|
||
ptlsh: ctx.refundSerialNo
|
||
}
|
||
const url = `${baseUrl}/his/hlw/orderrefund`;
|
||
let { code, status_code, message, data } = await request.main(url, payload, "POST");
|
||
if (status_code == 200 && code == '1' && !message) {
|
||
return { success: true, data, message: '[his]同步浸酒订单退费成功' }
|
||
}
|
||
return { success: false, message: `[his]同步浸酒订单退费失败: ${message || '未知错误'}` }
|
||
} catch (err) {
|
||
return { success: false, message: `[his]同步浸酒订单退费错误: ${err.message || '未知错误'}` };
|
||
}
|
||
}
|
||
|
||
|
||
async function getHisEmployeeInfo(item) {
|
||
const { code } = item;
|
||
try {
|
||
const testUrl = "http://115.239.161.48:8089";
|
||
const url = `${testUrl}/his/hlw/employeeinfo`;
|
||
const { data, status_code, message } = await request.main(
|
||
url,
|
||
{ type: "01", code: code },
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && !message) {
|
||
return {
|
||
success: true,
|
||
data,
|
||
message: "获取成功",
|
||
}
|
||
}
|
||
} catch (e) {
|
||
return { success: false, message: e?.message }
|
||
}
|
||
}
|
||
|
||
async function getWineDrugStockInfo(item) {
|
||
try {
|
||
if (typeof item.code !== 'string' || item.code.trim() === '') {
|
||
return { success: false, message: '中药饮片代码不能为空' }
|
||
}
|
||
if (!(Number.isInteger(item.num) && item.num > 0)) {
|
||
return { success: false, message: '中药饮片数量必须是整数且大于0' }
|
||
}
|
||
const url = `${baseUrl}/his/hlw/drug`;
|
||
const payload = {
|
||
hospid: '108',
|
||
drug_type: 'zcy',
|
||
tc_code: item.code.trim(),
|
||
tc_number: item.num
|
||
}
|
||
const { code, status_code, message, data } = await request.main(
|
||
url,
|
||
payload,
|
||
"POST"
|
||
);
|
||
if (status_code == 200 && code == '1') {
|
||
return {
|
||
success: true,
|
||
message: "[his]查询药品信息成功",
|
||
data: data
|
||
};
|
||
}
|
||
return {
|
||
success: false,
|
||
message: `中药饮品查询失败: ${message || '未知错误'}`,
|
||
};
|
||
|
||
} catch (err) {
|
||
return {
|
||
success: false,
|
||
message: `中药饮品查询失败错误: ${err.message || '未知'}`,
|
||
};
|
||
}
|
||
}
|
||
|
||
async function hisTest() {
|
||
// const data = {
|
||
// patientId: '10428622',
|
||
// orderNo: 'R260530160013084765664',
|
||
// tradeNo: '3JHR2605301770353161405592',
|
||
// outTradeNo: '3JHR260530160352836640789',
|
||
// totalAmount: 78
|
||
// }
|
||
// const data = { "patientid": "30015424", "registerid": "h202501070833145550001", "orderno": "h202501070833145550001", "doctorcode": "10010", "unitcode": "1005000", "visit_time": "2025-12-04 13:15", "area_code": "330602", "hospid": "108", "icds": [{ "icd_code ": "R51.x00", "icd_name": "头痛", "sort": 1 }], "details": [{ "drug_type": "xy", "drug_groupno": "7X", "drug_group": "", "drug_id": "00110", "drug_serial": "01", "drug_name": "富马酸替诺福韦二吡呋酯片", "drug_spec": "300mg×30片/盒", "drug_pric": "329.41", "drug_cnt": "1", "drug_sumamt": "329.41", "supple_code": "1", "supple_name": "口服", "medc_days": "3", "drug_times": "1", "drug_comm": "", "drug_ma": "", "remark": "", "limit_flag": "0", "usage": "11", "usage_name": "每天一次(qd)", "sin_doscnt": "2.00", "sin_dosunt": "片", "unit": "盒" }] }
|
||
// return await syncHisChargeStatus(data);
|
||
} |