1.批量查询已选项目的默认数据后提交保存
fetchDefaultDataAndSave(selected) {
const patientData = Cache.get('patientData');
const userData = Cache.get('userData');
const { admID } = patientData;
const { userID, locID, hospID } = userData;
const { date, time } = this.formatDateTime();
// 构造 03050020 的 orders 入参
const queryOrders = selected.map((item) => ({
medID: item.medID,
ordSetID: ''
}));
$http.post('urlDeault', this, {
code: '03050020',
data: {
params: [
{
admID: admID || '',
orders: queryOrders
}
]
},
success: (res) => {
if (res.errorCode === '0') {
const dataList = res.data || [];
// medID -> defaultData 映射,便于按选中顺序构造 orders
const defaultMap = {};
dataList.forEach((d) => {
if (d && d.defaultData && d.defaultData.medID) {
defaultMap[d.defaultData.medID] = d.defaultData;
}
});
const orders = selected.map((item, index) => {
const def = defaultMap[item.medID] || {};
// 仅检查(mainCode='E')需要 bodyPart 三层结构:
// orders.ordbodyPart=[null] -> appMessage.bodyPart[].bodyPart[].bodyPart=[]。
const isExamination = (item.mainCode || '').toUpperCase() === 'E';
const order = {
ordMedItemDesc: item.medDesc,
medID: item.medID,
ordPrice: def.ordPrice || 0,
ordQty: (item.mainCode === 'O') ? (item.qty || 1) : (def.ordQty || 1),
ordDose: def.ordDose || 1,
ordDate: date,
ordTime: time,
ordStartDate: date,
ordStartTime: time,
ordSpecID: def.ordSpecID || '',
ordEMFlag: def.ordEMFlag || '',
ordPriorityID: def.ordPriorityID || '10',
ordAdmReasonID: def.ordAdmReasonID || '1',
// 保持原有规则:每个选中项目按其顺序分配 tabIndex。
tabIndex: index + 1,
ordRecLocID: def.ordRecLocID || locID || '',
ordQtyUomID: def.ordQtyUomID || '',
ordSeqNo: index,
// 03050098 接口返参 appOrderID,传入 03050001 的 orders 中
appOrderID: item.appOrderID || '',
// 内部字段:保存时区分检验/检查,提交给后端前会被剔除
_mainCode: item.mainCode || '',
extvalue: [
{
code: 'Diag',
value: (this.diagData && this.diagData.id) || '',
refDescripts: (this.diagData && this.diagData.diagCode) || ''
},
{ code: 'RegDate', value: '', refDescripts: '预约执行日期' }
]
};
if (isExamination) {
// 后端允许最内层 bodyPart 为空,但该字段不能缺失。
order.ordbodyPart = [null];
}
return order;
});
this.submitOrders(orders, admID, locID, userID, hospID);
} else {
this.setData({ saving: false });
Dialog.alert({
title: '提示',
message: res.errorMessage || '获取医嘱默认数据失败',
context: this
});
}
},
fail: (err) => {
this.setData({ saving: false });
Dialog.alert({
title: '提示',
message: (err && err.errorMessage) || '获取医嘱默认数据失败',
context: this
});
}
});
},
2.调用 03050001 提交 orders
submitOrders(orders, admID, locID, userID, hospID) {
// 依据每个 order 所属类型(_mainCode)区分检验(L)与检查(E):
// - 检查(E):按 tabIndex 分组生成 appMessage.bodyPart 数组,每项 { bodyPart:[...], tabIndex }
// 内层 bodyPart 数组由该 tab 下各 order 的 ordbodyPart 元素映射而来,
// null(未选部位) 映射为空数组 [],非空则取部位本身
// - 检验(L):不传 bodyPart,不参与分组
const bodyPartGroup = {};
orders.forEach((order) => {
// L=检验,E=检查
const isInspection = (order._mainCode || '').toUpperCase() === 'E';
if (!isInspection) {
return;
}
const tabIndex = order.tabIndex;
if (!bodyPartGroup[tabIndex]) {
bodyPartGroup[tabIndex] = [];
}
(order.ordbodyPart || []).forEach((part) => {
bodyPartGroup[tabIndex].push({ bodyPart: part == null ? [] : part });
});
});
const bodyPartArr = Object.keys(bodyPartGroup).map((tabIndex) => ({
bodyPart: bodyPartGroup[tabIndex],
tabIndex: Number(tabIndex)
}));
// 剔除内部字段 _mainCode,避免提交给后端
const cleanOrders = orders.map((order) => {
const { _mainCode, ...rest } = order;
return rest;
});
const appMessage = {
appPurpose: '',
HPIllness: '',
sign: '',
chiefComplaint: '',
// 检验项目不参与 bodyPart 分组;全是检验时传空数组。
bodyPart: bodyPartArr.length > 0 ? bodyPartArr : [],
};
$http.post('urlDeault', this, {
code: '03050001',
data: {
params: [
{
admID: admID || '',
locID: locID || '',
docID: userID || '',
userID: userID || '',
hospID: hospID || '',
medType: 'WM',
orders: cleanOrders,
appMessage: appMessage
}
]
},
success: (res) => {
if (res.errorCode == 0) {
// 设置标记,供 prescription.vue 的 handlePageShow 检测并刷新已确认数据
try {
Cache.set('inspectionExamineSaved', true);
} catch (e) {}
Toast({ type: 'success', message: '保存成功', context: this });
setTimeout(() => {
this.setData({ saving: false });
uni.navigateBack({ delta: 1 });
}, 800);
} else {
this.setData({ saving: false });
Dialog.alert({
title: '提示',
message: res.errorMessage || '保存失败',
context: this
});
}
},
fail: (res) => {
this.setData({ saving: false });
Dialog.alert({
title: '提示',
message: (res && res.errorMessage) || '保存失败',
context: this
});
}
});
}
},