|
@@ -14,6 +14,16 @@ let mzHistoryDays = 30 // 门诊历史处方前置天数
|
|
|
let isTyOk = false;
|
|
|
var hospitalName ='沭阳铭和医院';
|
|
|
let yf;
|
|
|
+
|
|
|
+// ================= 新增:追溯码扫描状态跟踪变量 =================
|
|
|
+// 目的:支持智能追溯码匹配功能,记录每个药品的扫描状态和退药数量
|
|
|
+// 修改时间:2025年
|
|
|
+// 修改原因:实现只扫描退药数量对应追溯码的功能,提高工作效率
|
|
|
+// 变量说明:
|
|
|
+// - scannedCodesMap: 记录每个药品已扫描的追溯码数组,格式:{药品编码: [追溯码1, 追溯码2, ...]}
|
|
|
+// - refundQuantityMap: 记录每个药品的退药数量,格式:{药品编码: 退药数量}
|
|
|
+let scannedCodesMap = {}; // 记录每个药品的扫描情况
|
|
|
+let refundQuantityMap = {}; // 记录每个药品的退药数量
|
|
|
$(function () {
|
|
|
getAjaxRequst("/thmz/queryHospitalName",{},true,function (res) {
|
|
|
hospitalName = res.data
|
|
@@ -1889,7 +1899,8 @@ function saveRefundMedicine() {
|
|
|
needRefundItems.push({
|
|
|
chargeItemCode: item.charge_item_code,
|
|
|
serial: item.serial,
|
|
|
- itemNo: item.item_no
|
|
|
+ itemNo: item.item_no,
|
|
|
+ decAmount: item.dec_amount // 添加退药数量字段,用于后续校验
|
|
|
});
|
|
|
}
|
|
|
});
|
|
@@ -1902,6 +1913,49 @@ function saveRefundMedicine() {
|
|
|
console.log('- itemNo:', needRefundItems[0].itemNo);
|
|
|
}
|
|
|
// ========== 调试日志结束 ==========
|
|
|
+
|
|
|
+ // ================= 新增:智能追溯码匹配校验逻辑 =================
|
|
|
+ // 目的:检查是否扫描了足够数量的追溯码,而不是检查是否所有追溯码都已匹配
|
|
|
+ // 修改时间:2025年
|
|
|
+ // 修改原因:提高退药效率,只要求扫描退药数量对应的追溯码
|
|
|
+
|
|
|
+ // 检查每个需要退药的药品是否都已匹配足够数量
|
|
|
+ let allMatched = true;
|
|
|
+ let unmatchedItems = [];
|
|
|
+
|
|
|
+ for (let i = 0; i < tyTable.length; i++) {
|
|
|
+ let item = tyTable[i];
|
|
|
+
|
|
|
+ // 检查这个药品是否需要退药
|
|
|
+ let needRefund = needRefundItems.find(function(refundItem) {
|
|
|
+ return refundItem.chargeItemCode === item.chargeItemCode &&
|
|
|
+ refundItem.serial === item.serial &&
|
|
|
+ refundItem.itemNo === item.itemNo;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (needRefund) {
|
|
|
+ let drugCode = item.chargeItemCode;
|
|
|
+ let requiredCount = needRefund.decAmount;
|
|
|
+ let scannedCount = scannedCodesMap[drugCode] ? scannedCodesMap[drugCode].length : 0;
|
|
|
+
|
|
|
+ // 检查是否扫描了足够的追溯码
|
|
|
+ if (scannedCount < requiredCount) {
|
|
|
+ allMatched = false;
|
|
|
+ unmatchedItems.push(`${item.drugName} (需要${requiredCount}个,已扫描${scannedCount}个)`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!allMatched) {
|
|
|
+ return errorMesageSimaple('还有药品未完成追溯码匹配:' + unmatchedItems.join('、') + ',请完成匹配后再退药!');
|
|
|
+ }
|
|
|
+
|
|
|
+ // ================= 原逻辑(已屏蔽,如需恢复请取消注释) =================
|
|
|
+ /*
|
|
|
+ // 原逻辑:检查是否所有追溯码都已匹配
|
|
|
+ // 屏蔽原因:效率低下,要求扫描所有追溯码而不是退药数量对应的追溯码
|
|
|
+ // 屏蔽时间:2025年
|
|
|
+
|
|
|
// 检查每个需要退药的药品是否都已匹配
|
|
|
let allMatched = true;
|
|
|
let unmatchedItems = [];
|
|
@@ -1927,6 +1981,8 @@ function saveRefundMedicine() {
|
|
|
if (!allMatched) {
|
|
|
return errorMesageSimaple('还有药品未匹配追溯码:' + unmatchedItems.join('、') + ',请完成匹配后再退药!');
|
|
|
}
|
|
|
+ */
|
|
|
+ // ================= 原逻辑结束 =================
|
|
|
}
|
|
|
|
|
|
var row = $("#tb_table").bootstrapTable('getSelections');
|
|
@@ -2033,8 +2089,11 @@ function saveRefundMedicine() {
|
|
|
}
|
|
|
|
|
|
// 退药成功后重置匹配状态和全局数据
|
|
|
- isTyOk = false;
|
|
|
- window.currentRefundData = null;
|
|
|
+ // ================= 新增:使用统一的重置函数 =================
|
|
|
+ // 目的:统一管理追溯码匹配状态的重置
|
|
|
+ // 修改时间:2025年
|
|
|
+ // 修改原因:确保状态重置的完整性和一致性
|
|
|
+ resetTraceabilityState();
|
|
|
initTbTable();
|
|
|
} else {
|
|
|
console.error('退药处理失败:', res.message);
|
|
@@ -2554,6 +2613,23 @@ function matchingDrugCodg(patientId, times, receiptNo, orderNo, realNo){
|
|
|
// 保存当前退药数据到全局变量,供匹配检查使用
|
|
|
window.currentRefundData = $table.bootstrapTable('getData');
|
|
|
|
|
|
+ // ================= 新增:追溯码匹配状态初始化 =================
|
|
|
+ // 目的:初始化扫描状态和退药数量信息,为智能匹配做准备
|
|
|
+ // 修改时间:2025年
|
|
|
+ // 修改原因:支持智能追溯码匹配功能
|
|
|
+
|
|
|
+ // 初始化扫描状态
|
|
|
+ scannedCodesMap = {};
|
|
|
+ refundQuantityMap = {};
|
|
|
+
|
|
|
+ // 预加载退药数量信息
|
|
|
+ let refundData = $table.bootstrapTable('getData');
|
|
|
+ refundData.forEach(function (item, index, arr) {
|
|
|
+ if (item.dec_amount > 0) {
|
|
|
+ refundQuantityMap[item.charge_item_code] = item.dec_amount;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
$('#ty_table_detail').bootstrapTable("destroy");
|
|
|
$('#ty_table_detail').bootstrapTable({
|
|
|
url: '/thmz/getMzDrugTracCodgData', //请求后台的URL(*)
|
|
@@ -2636,6 +2712,14 @@ function matchingDrugCodg(patientId, times, receiptNo, orderNo, realNo){
|
|
|
$("#employeeNameLabelTy").val(re.data[0].employeeName);
|
|
|
$("#warnDeptNameLabelPy").val(re.data[0].warnDeptName);
|
|
|
$("#smMatchTy").val("");
|
|
|
+
|
|
|
+ // ================= 新增:初始化追溯码表格的进度显示 =================
|
|
|
+ // 目的:在追溯码表格加载完成后显示初始进度状态
|
|
|
+ // 修改时间:2025年
|
|
|
+ // 修改原因:提供更好的用户体验,显示每个药品的扫描进度
|
|
|
+ setTimeout(function() {
|
|
|
+ updateTraceabilityProgressDisplay();
|
|
|
+ }, 100);
|
|
|
}
|
|
|
if (re.code === -1) {
|
|
|
if (re.message != null && re.message !== '') {
|
|
@@ -2667,6 +2751,14 @@ function matchingDrugCodg(patientId, times, receiptNo, orderNo, realNo){
|
|
|
}, 100);
|
|
|
});
|
|
|
|
|
|
+ // ================= 新增:弹窗关闭时重置追溯码状态 =================
|
|
|
+ // 目的:确保弹窗关闭时清理所有状态,避免状态残留
|
|
|
+ // 修改时间:2025年
|
|
|
+ // 修改原因:防止状态污染,确保下次打开弹窗时状态正确
|
|
|
+ $("#tyModal").off('hidden.bs.modal').on('hidden.bs.modal', function () {
|
|
|
+ resetTraceabilityState();
|
|
|
+ });
|
|
|
+
|
|
|
// 防抖定时器
|
|
|
let matchDebounceTimer = null;
|
|
|
|
|
@@ -2733,6 +2825,70 @@ function matchDrugCodg(){
|
|
|
|
|
|
for (let i = 0; i < tyTable.length; i++) {
|
|
|
if(tyTable[i].drugTracCodg === code){
|
|
|
+ // ================= 新增:智能追溯码匹配逻辑 =================
|
|
|
+ // 目的:只要求扫描退药数量对应的追溯码,而不是所有追溯码
|
|
|
+ // 修改时间:2025年
|
|
|
+ // 修改原因:解决退药时需要扫描所有追溯码的问题,提高工作效率
|
|
|
+
|
|
|
+ let currentDrugCode = tyTable[i].chargeItemCode;
|
|
|
+
|
|
|
+ // 获取该药品的退药数量
|
|
|
+ if (!refundQuantityMap[currentDrugCode]) {
|
|
|
+ refundQuantityMap[currentDrugCode] = getRefundQuantityForDrug(currentDrugCode);
|
|
|
+ }
|
|
|
+ let maxAllowedCount = refundQuantityMap[currentDrugCode];
|
|
|
+
|
|
|
+ // 获取已扫描数量
|
|
|
+ if (!scannedCodesMap[currentDrugCode]) {
|
|
|
+ scannedCodesMap[currentDrugCode] = [];
|
|
|
+ }
|
|
|
+ let currentScannedCount = scannedCodesMap[currentDrugCode].length;
|
|
|
+
|
|
|
+ // 检查是否超过退药数量
|
|
|
+ if (currentScannedCount >= maxAllowedCount) {
|
|
|
+ warningMesageSimaple(`该药品已扫描${currentScannedCount}个追溯码,退药数量为${maxAllowedCount}个,无需继续扫描!`);
|
|
|
+ $("#smMatchTy").val("").focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否已扫描过此追溯码
|
|
|
+ if (scannedCodesMap[currentDrugCode].includes(code)) {
|
|
|
+ warningMesageSimaple("该追溯码已扫描过,请勿重复扫描!");
|
|
|
+ $("#smMatchTy").val("").focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 记录扫描的追溯码
|
|
|
+ scannedCodesMap[currentDrugCode].push(code);
|
|
|
+
|
|
|
+ // 更新匹配结果显示(带进度显示)
|
|
|
+ let newScannedCount = scannedCodesMap[currentDrugCode].length;
|
|
|
+ let progressText = `${newScannedCount}/${maxAllowedCount}`;
|
|
|
+ let color = newScannedCount >= maxAllowedCount ? 'green' : 'orange';
|
|
|
+
|
|
|
+ $('#ty_table_detail').bootstrapTable('updateCell', {
|
|
|
+ index: i,
|
|
|
+ field: "drugTracCodg",
|
|
|
+ value: '<span style="color: green">' + tyTable[i].drugTracCodg + '</span>'
|
|
|
+ });
|
|
|
+ $('#ty_table_detail').bootstrapTable('updateCell', {
|
|
|
+ index: i,
|
|
|
+ field: "matchOk",
|
|
|
+ value: `<span style="color: ${color}">已匹配 (${progressText})</span>`
|
|
|
+ });
|
|
|
+
|
|
|
+ successMesageSimaple("药品追溯码匹配成功!");
|
|
|
+ matched = true;
|
|
|
+ // 匹配成功后清空输入框,准备扫描下一个
|
|
|
+ $("#smMatchTy").val("").focus();
|
|
|
+ break;
|
|
|
+
|
|
|
+ // ================= 原逻辑(已屏蔽,如需恢复请取消注释) =================
|
|
|
+ /*
|
|
|
+ // 原逻辑:要求扫描所有追溯码
|
|
|
+ // 屏蔽原因:效率低下,需要扫描所有追溯码而不是退药数量对应的追溯码
|
|
|
+ // 屏蔽时间:2025年
|
|
|
+
|
|
|
if(!isEmpty(tyTable[i].matchOk)){
|
|
|
warningMesageSimaple("已匹配,请勿重复扫码!");
|
|
|
// 重复匹配时清空输入框,准备扫描下一个
|
|
@@ -2754,6 +2910,8 @@ function matchDrugCodg(){
|
|
|
// 匹配成功后清空输入框,准备扫描下一个
|
|
|
$("#smMatchTy").val("").focus();
|
|
|
break;
|
|
|
+ */
|
|
|
+ // ================= 原逻辑结束 =================
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2782,11 +2940,54 @@ function matchTp(){
|
|
|
needRefundItems.push({
|
|
|
chargeItemCode: item.charge_item_code,
|
|
|
serial: item.serial,
|
|
|
- itemNo: item.item_no
|
|
|
+ itemNo: item.item_no,
|
|
|
+ decAmount: item.dec_amount
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ // ================= 新增:智能数量校验逻辑 =================
|
|
|
+ // 目的:检查是否扫描了足够数量的追溯码,而不是检查是否所有追溯码都已匹配
|
|
|
+ // 修改时间:2025年
|
|
|
+ // 修改原因:提高退药效率,只要求扫描退药数量对应的追溯码
|
|
|
+
|
|
|
+ // 检查每个需要退药的药品是否都已匹配足够数量
|
|
|
+ let allMatched = true;
|
|
|
+ let unmatchedItems = [];
|
|
|
+
|
|
|
+ for (let i = 0; i < tyTable.length; i++) {
|
|
|
+ let item = tyTable[i];
|
|
|
+
|
|
|
+ // 检查这个药品是否需要退药
|
|
|
+ let needRefund = needRefundItems.find(function(refundItem) {
|
|
|
+ return refundItem.chargeItemCode === item.chargeItemCode &&
|
|
|
+ refundItem.serial === item.serial &&
|
|
|
+ refundItem.itemNo === item.itemNo;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (needRefund) {
|
|
|
+ let drugCode = item.chargeItemCode;
|
|
|
+ let requiredCount = needRefund.decAmount;
|
|
|
+ let scannedCount = scannedCodesMap[drugCode] ? scannedCodesMap[drugCode].length : 0;
|
|
|
+
|
|
|
+ // 检查是否扫描了足够的追溯码
|
|
|
+ if (scannedCount < requiredCount) {
|
|
|
+ allMatched = false;
|
|
|
+ unmatchedItems.push(`${item.drugName} (需要${requiredCount}个,已扫描${scannedCount}个)`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!allMatched) {
|
|
|
+ return errorMesageSimaple('还有药品未完成追溯码匹配:' + unmatchedItems.join('、') + ',请完成匹配后再确认!');
|
|
|
+ }
|
|
|
+
|
|
|
+ // ================= 原逻辑(已屏蔽,如需恢复请取消注释) =================
|
|
|
+ /*
|
|
|
+ // 原逻辑:检查是否所有追溯码都已匹配
|
|
|
+ // 屏蔽原因:效率低下,要求扫描所有追溯码而不是退药数量对应的追溯码
|
|
|
+ // 屏蔽时间:2025年
|
|
|
+
|
|
|
// 检查每个需要退药的药品是否都已匹配
|
|
|
let allMatched = true;
|
|
|
let unmatchedItems = [];
|
|
@@ -2830,6 +3031,8 @@ function matchTp(){
|
|
|
if (!allMatched) {
|
|
|
return errorMesageSimaple('还有药品未匹配追溯码:' + unmatchedItems.join('、') + ',请完成所有匹配后再确认!');
|
|
|
}
|
|
|
+ */
|
|
|
+ // ================= 原逻辑结束 =================
|
|
|
|
|
|
if (!confirm("确定对当前处方所有退药的药品匹配成功?")) {
|
|
|
return;
|
|
@@ -2840,6 +3043,65 @@ function matchTp(){
|
|
|
$("#tyModal").modal('hide');
|
|
|
}
|
|
|
|
|
|
+// ================= 新增:获取指定药品的退药数量 =================
|
|
|
+// 目的:根据药品编码获取该药品的退药数量,用于智能追溯码匹配
|
|
|
+// 修改时间:2025年
|
|
|
+// 修改原因:支持智能追溯码匹配功能,只要求扫描退药数量对应的追溯码
|
|
|
+// 参数:drugCode - 药品编码
|
|
|
+// 返回值:退药数量,如果没有退药则返回0
|
|
|
+function getRefundQuantityForDrug(drugCode) {
|
|
|
+ let refundData = window.currentRefundData || $table.bootstrapTable('getData');
|
|
|
+ for (let item of refundData) {
|
|
|
+ if (item.charge_item_code === drugCode && item.dec_amount > 0) {
|
|
|
+ return item.dec_amount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+// ================= 新增:更新追溯码表格的进度显示 =================
|
|
|
+// 目的:实时更新追溯码表格中每个药品的扫描进度显示
|
|
|
+// 修改时间:2025年
|
|
|
+// 修改原因:提供更好的用户体验,让用户清楚了解每个药品的扫描状态
|
|
|
+// 功能:显示格式为"已匹配 (2/4)"或"未匹配 (0/4)",绿色表示完成,橙色表示进行中
|
|
|
+function updateTraceabilityProgressDisplay() {
|
|
|
+ let tyTable = $('#ty_table_detail').bootstrapTable("getData");
|
|
|
+
|
|
|
+ tyTable.forEach(function(item, index) {
|
|
|
+ let drugCode = item.chargeItemCode;
|
|
|
+ let scannedCount = scannedCodesMap[drugCode] ? scannedCodesMap[drugCode].length : 0;
|
|
|
+ let requiredCount = refundQuantityMap[drugCode] || 0;
|
|
|
+
|
|
|
+ if (requiredCount > 0) {
|
|
|
+ let progressText = `${scannedCount}/${requiredCount}`;
|
|
|
+ let color = scannedCount >= requiredCount ? 'green' : 'orange';
|
|
|
+ let statusText = scannedCount > 0 ? '已匹配' : '未匹配';
|
|
|
+
|
|
|
+ $('#ty_table_detail').bootstrapTable('updateCell', {
|
|
|
+ index: index,
|
|
|
+ field: "matchOk",
|
|
|
+ value: `<span style="color: ${color}">${statusText} (${progressText})</span>`
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+// ================= 新增:重置追溯码扫描状态 =================
|
|
|
+// 目的:统一重置所有追溯码匹配相关的状态变量
|
|
|
+// 修改时间:2025年
|
|
|
+// 修改原因:确保状态管理的一致性,防止状态残留导致的问题
|
|
|
+// 重置内容:
|
|
|
+// - scannedCodesMap: 清空已扫描的追溯码记录
|
|
|
+// - refundQuantityMap: 清空退药数量记录
|
|
|
+// - isTyOk: 重置匹配完成标志
|
|
|
+// - window.currentRefundData: 清空当前退药数据
|
|
|
+function resetTraceabilityState() {
|
|
|
+ scannedCodesMap = {};
|
|
|
+ refundQuantityMap = {};
|
|
|
+ isTyOk = false;
|
|
|
+ window.currentRefundData = null;
|
|
|
+}
|
|
|
+
|
|
|
function printPrescription(patientId, times, orderNo) {
|
|
|
if (mzCfPrintIndex == null || ekCfPrintIndex == null || jzCfPrintIndex == null) {
|
|
|
return errorMesageSimaple('打印机参数未设置,请在发药参数设置中设置');
|
|
@@ -3212,9 +3474,11 @@ function saveCellData(table, index, field, value) {
|
|
|
}
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
- // 初始化全局变量
|
|
|
- window.currentRefundData = null;
|
|
|
- isTyOk = false;
|
|
|
+ // ================= 新增:使用统一的重置函数初始化全局变量 =================
|
|
|
+ // 目的:确保页面加载时追溯码匹配状态正确初始化
|
|
|
+ // 修改时间:2025年
|
|
|
+ // 修改原因:统一状态管理,避免状态不一致
|
|
|
+ resetTraceabilityState();
|
|
|
|
|
|
initTbTable();
|
|
|
});
|