Backup local changes before resolving remote repository issue
This commit is contained in:
312
openhis-ui-vue3/src/router/json
Normal file
312
openhis-ui-vue3/src/router/json
Normal file
@@ -0,0 +1,312 @@
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "操作成功",
|
||||
"data": {
|
||||
"records": [
|
||||
{
|
||||
"encounterId": "1992766613237190657",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202511240001",
|
||||
"inHospitalTime": "2025-11-26 13:28:14",
|
||||
"outHospitalTime": "2026-01-19 07:00:41",
|
||||
"patientId": "1979081512436203522",
|
||||
"patientName": "随子赫",
|
||||
"genderEnum": 0,
|
||||
"genderEnum_enumText": "男性",
|
||||
"birthDate": "2013-06-23 00:00:00",
|
||||
"age": "13岁",
|
||||
"wardName": null,
|
||||
"houseName": null,
|
||||
"bedName": null,
|
||||
"inOrgTime": null,
|
||||
"inHospitalDays": 55,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "2",
|
||||
"contractName": "居民基本医疗保险",
|
||||
"regDiagnosisName": "持久的心境[情感]障碍,其他的",
|
||||
"accountId": "1993552505086300162",
|
||||
"advanceAmount": null,
|
||||
"totalAmount": null,
|
||||
"balanceAmount": null,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
},
|
||||
{
|
||||
"encounterId": "2012842506781417473",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202601180004",
|
||||
"inHospitalTime": "2026-01-19 15:30:37",
|
||||
"outHospitalTime": "2026-01-20 03:43:47",
|
||||
"patientId": "1980816965970288641",
|
||||
"patientName": "刘潇凡",
|
||||
"genderEnum": 0,
|
||||
"genderEnum_enumText": "男性",
|
||||
"birthDate": "2007-04-29 00:00:00",
|
||||
"age": "19岁",
|
||||
"wardName": null,
|
||||
"houseName": "101号房",
|
||||
"bedName": null,
|
||||
"inOrgTime": null,
|
||||
"inHospitalDays": 1,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "7",
|
||||
"contractName": "城乡居民医疗保险",
|
||||
"regDiagnosisName": "童年情绪障碍",
|
||||
"accountId": "2013131047918845954",
|
||||
"advanceAmount": 500.000000,
|
||||
"totalAmount": 0,
|
||||
"balanceAmount": 500.000000,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
},
|
||||
{
|
||||
"encounterId": "2012842506781417473",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202601180004",
|
||||
"inHospitalTime": "2026-01-19 15:30:37",
|
||||
"outHospitalTime": "2026-01-20 03:43:47",
|
||||
"patientId": "1980816965970288641",
|
||||
"patientName": "刘潇凡",
|
||||
"genderEnum": 0,
|
||||
"genderEnum_enumText": "男性",
|
||||
"birthDate": "2007-04-29 00:00:00",
|
||||
"age": "19岁",
|
||||
"wardName": null,
|
||||
"houseName": "101号房",
|
||||
"bedName": null,
|
||||
"inOrgTime": null,
|
||||
"inHospitalDays": 1,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "7",
|
||||
"contractName": "城乡居民医疗保险",
|
||||
"regDiagnosisName": "童年情绪障碍",
|
||||
"accountId": "2013131047918845954",
|
||||
"advanceAmount": 500.000000,
|
||||
"totalAmount": 0,
|
||||
"balanceAmount": 500.000000,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
},
|
||||
{
|
||||
"encounterId": "2013142728942239745",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202601190002",
|
||||
"inHospitalTime": "2026-01-19 14:54:09",
|
||||
"outHospitalTime": "2026-01-19 00:00:00",
|
||||
"patientId": "1980816965970288641",
|
||||
"patientName": "刘潇凡",
|
||||
"genderEnum": 0,
|
||||
"genderEnum_enumText": "男性",
|
||||
"birthDate": "2007-04-29 00:00:00",
|
||||
"age": "19岁",
|
||||
"wardName": "儿童青少年心理病区",
|
||||
"houseName": "101号房",
|
||||
"bedName": null,
|
||||
"inOrgTime": null,
|
||||
"inHospitalDays": 1,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "2",
|
||||
"contractName": "居民基本医疗保险",
|
||||
"regDiagnosisName": "抑郁状态",
|
||||
"accountId": "2013143088062742529",
|
||||
"advanceAmount": 1000.000000,
|
||||
"totalAmount": 0,
|
||||
"balanceAmount": 1000.000000,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
},
|
||||
{
|
||||
"encounterId": "2013219287040495617",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202601190003",
|
||||
"inHospitalTime": "2026-01-19 19:57:30",
|
||||
"outHospitalTime": "2026-01-20 07:12:47",
|
||||
"patientId": "1989707705648041985",
|
||||
"patientName": "豆包",
|
||||
"genderEnum": 1,
|
||||
"genderEnum_enumText": "女性",
|
||||
"birthDate": "2006-07-30 08:00:00",
|
||||
"age": "20岁",
|
||||
"wardName": "儿童青少年心理病区",
|
||||
"houseName": "101号房",
|
||||
"bedName": "02号床",
|
||||
"inOrgTime": "2026-01-20 03:58:24",
|
||||
"inHospitalDays": 1,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "2",
|
||||
"contractName": "居民基本医疗保险",
|
||||
"regDiagnosisName": "抑郁状态",
|
||||
"accountId": "2013219416401219585",
|
||||
"advanceAmount": 1000.000000,
|
||||
"totalAmount": 0,
|
||||
"balanceAmount": 1000.000000,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
},
|
||||
{
|
||||
"encounterId": "2013219287040495617",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202601190003",
|
||||
"inHospitalTime": "2026-01-19 19:57:30",
|
||||
"outHospitalTime": "2026-01-20 07:12:47",
|
||||
"patientId": "1989707705648041985",
|
||||
"patientName": "豆包",
|
||||
"genderEnum": 1,
|
||||
"genderEnum_enumText": "女性",
|
||||
"birthDate": "2006-07-30 08:00:00",
|
||||
"age": "20岁",
|
||||
"wardName": "儿童青少年心理病区",
|
||||
"houseName": "101号房",
|
||||
"bedName": "02号床",
|
||||
"inOrgTime": "2026-01-20 03:58:24",
|
||||
"inHospitalDays": 1,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "2",
|
||||
"contractName": "居民基本医疗保险",
|
||||
"regDiagnosisName": "抑郁状态",
|
||||
"accountId": "2013219416401219585",
|
||||
"advanceAmount": 1000.000000,
|
||||
"totalAmount": 0,
|
||||
"balanceAmount": 1000.000000,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
},
|
||||
{
|
||||
"encounterId": "2013219287040495617",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202601190003",
|
||||
"inHospitalTime": "2026-01-19 19:57:30",
|
||||
"outHospitalTime": "2026-01-20 07:12:47",
|
||||
"patientId": "1989707705648041985",
|
||||
"patientName": "豆包",
|
||||
"genderEnum": 1,
|
||||
"genderEnum_enumText": "女性",
|
||||
"birthDate": "2006-07-30 08:00:00",
|
||||
"age": "20岁",
|
||||
"wardName": "儿童青少年心理病区",
|
||||
"houseName": "101号房",
|
||||
"bedName": "02号床",
|
||||
"inOrgTime": "2026-01-20 03:58:24",
|
||||
"inHospitalDays": 1,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "2",
|
||||
"contractName": "居民基本医疗保险",
|
||||
"regDiagnosisName": "抑郁状态",
|
||||
"accountId": "2013219416401219585",
|
||||
"advanceAmount": 1000.000000,
|
||||
"totalAmount": 0,
|
||||
"balanceAmount": 1000.000000,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
},
|
||||
{
|
||||
"encounterId": "2013219287040495617",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202601190003",
|
||||
"inHospitalTime": "2026-01-19 19:57:30",
|
||||
"outHospitalTime": "2026-01-20 07:12:47",
|
||||
"patientId": "1989707705648041985",
|
||||
"patientName": "豆包",
|
||||
"genderEnum": 1,
|
||||
"genderEnum_enumText": "女性",
|
||||
"birthDate": "2006-07-30 08:00:00",
|
||||
"age": "20岁",
|
||||
"wardName": "儿童青少年心理病区",
|
||||
"houseName": "101号房",
|
||||
"bedName": "02号床",
|
||||
"inOrgTime": "2026-01-20 03:58:24",
|
||||
"inHospitalDays": 1,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "2",
|
||||
"contractName": "居民基本医疗保险",
|
||||
"regDiagnosisName": "抑郁状态",
|
||||
"accountId": "2013219416401219585",
|
||||
"advanceAmount": 1000.000000,
|
||||
"totalAmount": 0,
|
||||
"balanceAmount": 1000.000000,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
},
|
||||
{
|
||||
"encounterId": "2013219287040495617",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202601190003",
|
||||
"inHospitalTime": "2026-01-19 19:57:30",
|
||||
"outHospitalTime": "2026-01-20 07:12:47",
|
||||
"patientId": "1989707705648041985",
|
||||
"patientName": "豆包",
|
||||
"genderEnum": 1,
|
||||
"genderEnum_enumText": "女性",
|
||||
"birthDate": "2006-07-30 08:00:00",
|
||||
"age": "20岁",
|
||||
"wardName": "儿童青少年心理病区",
|
||||
"houseName": "101号房",
|
||||
"bedName": "02号床",
|
||||
"inOrgTime": "2026-01-20 03:58:24",
|
||||
"inHospitalDays": 1,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "2",
|
||||
"contractName": "居民基本医疗保险",
|
||||
"regDiagnosisName": "抑郁状态",
|
||||
"accountId": "2013219416401219585",
|
||||
"advanceAmount": 1000.000000,
|
||||
"totalAmount": 0,
|
||||
"balanceAmount": 1000.000000,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
},
|
||||
{
|
||||
"encounterId": "2013219287040495617",
|
||||
"statusEnum": 5,
|
||||
"statusEnum_enumText": "已入院",
|
||||
"busNo": "ZY202601190003",
|
||||
"inHospitalTime": "2026-01-19 19:57:30",
|
||||
"outHospitalTime": "2026-01-20 07:12:47",
|
||||
"patientId": "1989707705648041985",
|
||||
"patientName": "豆包",
|
||||
"genderEnum": 1,
|
||||
"genderEnum_enumText": "女性",
|
||||
"birthDate": "2006-07-30 08:00:00",
|
||||
"age": "20岁",
|
||||
"wardName": "儿童青少年心理病区",
|
||||
"houseName": "101号房",
|
||||
"bedName": "02号床",
|
||||
"inOrgTime": "2026-01-20 03:58:24",
|
||||
"inHospitalDays": 1,
|
||||
"inHospitalOrgId": "1989706423340257282",
|
||||
"inHospitalOrgName": "临床心理科",
|
||||
"contractNo": "2",
|
||||
"contractName": "居民基本医疗保险",
|
||||
"regDiagnosisName": "抑郁状态",
|
||||
"accountId": "2013219416401219585",
|
||||
"advanceAmount": 1000.000000,
|
||||
"totalAmount": 0,
|
||||
"balanceAmount": 1000.000000,
|
||||
"insutype": null,
|
||||
"insutype_dictText": null
|
||||
}
|
||||
],
|
||||
"total": 10,
|
||||
"size": 10,
|
||||
"current": 1,
|
||||
"pages": 1
|
||||
}
|
||||
}
|
||||
197
openhis-ui-vue3/src/utils/apiRequestManager.js
Normal file
197
openhis-ui-vue3/src/utils/apiRequestManager.js
Normal file
@@ -0,0 +1,197 @@
|
||||
import globalRequestController from './globalRequestController.js';
|
||||
|
||||
/**
|
||||
* API请求管理器 - 用于合并相同参数的请求,避免重复请求
|
||||
* 在医院信息系统中特别重要,因为医疗数据的频繁请求可能影响系统性能
|
||||
*/
|
||||
|
||||
class ApiRequestManager {
|
||||
constructor() {
|
||||
// 存储正在进行的请求
|
||||
this.pendingRequests = new Map();
|
||||
// 缓存成功的响应结果
|
||||
this.responseCache = new Map();
|
||||
// 缓存过期时间(毫秒)
|
||||
this.cacheTimeout = 10000; // 10秒,医疗系统中数据更新可能较频繁
|
||||
|
||||
// 添加调试模式
|
||||
this.debugMode = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求的唯一键值
|
||||
* @param {string} url - 请求URL
|
||||
* @param {object} params - 请求参数
|
||||
* @returns {string} 唯一键值
|
||||
*/
|
||||
generateRequestKey(url, params = {}) {
|
||||
// 对参数进行排序以确保相同参数产生相同键值
|
||||
const sortedParams = Object.keys(params)
|
||||
.sort()
|
||||
.reduce((acc, key) => {
|
||||
acc[key] = params[key];
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const key = `${url}?${JSON.stringify(sortedParams)}`;
|
||||
|
||||
if (this.debugMode) {
|
||||
console.log(`Generated request key: ${key}`);
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否存在相同的进行中请求
|
||||
* @param {string} requestKey - 请求键值
|
||||
* @returns {Promise|undefined} 如果存在则返回Promise,否则返回undefined
|
||||
*/
|
||||
getPendingRequest(requestKey) {
|
||||
return this.pendingRequests.get(requestKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加进行中的请求
|
||||
* @param {string} requestKey - 请求键值
|
||||
* @param {Promise} promise - 请求Promise
|
||||
*/
|
||||
addPendingRequest(requestKey, promise) {
|
||||
this.pendingRequests.set(requestKey, promise);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除进行中的请求
|
||||
* @param {string} requestKey - 请求键值
|
||||
*/
|
||||
removePendingRequest(requestKey) {
|
||||
this.pendingRequests.delete(requestKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否存在缓存的响应
|
||||
* @param {string} requestKey - 请求键值
|
||||
* @returns {object|undefined} 如果存在则返回缓存的响应,否则返回undefined
|
||||
*/
|
||||
getCachedResponse(requestKey) {
|
||||
const cached = this.responseCache.get(requestKey);
|
||||
if (cached && Date.now() < cached.expiry) {
|
||||
return cached.data;
|
||||
}
|
||||
// 如果缓存已过期,删除它
|
||||
if (cached) {
|
||||
this.responseCache.delete(requestKey);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加缓存的响应
|
||||
* @param {string} requestKey - 请求键值
|
||||
* @param {object} data - 响应数据
|
||||
*/
|
||||
addCachedResponse(requestKey, data) {
|
||||
this.responseCache.set(requestKey, {
|
||||
data,
|
||||
expiry: Date.now() + this.cacheTimeout
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定的缓存
|
||||
* @param {string} requestKey - 请求键值
|
||||
*/
|
||||
clearCache(requestKey) {
|
||||
this.responseCache.delete(requestKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有缓存
|
||||
*/
|
||||
clearAllCache() {
|
||||
this.responseCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有进行中的请求
|
||||
*/
|
||||
clearAllPending() {
|
||||
this.pendingRequests.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行API请求(带去重和缓存)
|
||||
* @param {Function} apiFunction - API函数
|
||||
* @param {string} url - 请求URL
|
||||
* @param {object} params - 请求参数
|
||||
* @returns {Promise} API响应Promise
|
||||
*/
|
||||
async execute(apiFunction, url, params = {}) {
|
||||
const requestKey = this.generateRequestKey(url, params);
|
||||
|
||||
if (this.debugMode) {
|
||||
console.log(`Executing request with key: ${requestKey}`);
|
||||
console.log(`Pending requests count: ${this.pendingRequests.size}`);
|
||||
console.log(`Cached responses count: ${this.responseCache.size}`);
|
||||
}
|
||||
|
||||
// 检查是否有缓存的响应
|
||||
const cachedResponse = this.getCachedResponse(requestKey);
|
||||
if (cachedResponse) {
|
||||
if (this.debugMode) {
|
||||
console.log(`Returning cached response for: ${requestKey}`);
|
||||
}
|
||||
return Promise.resolve(cachedResponse);
|
||||
}
|
||||
|
||||
// 使用全局请求控制器来确保唯一性
|
||||
const requestPromise = globalRequestController.execute(apiFunction, url, params)
|
||||
.then(response => {
|
||||
if (this.debugMode) {
|
||||
console.log(`Request completed for: ${requestKey}`, response);
|
||||
}
|
||||
// 请求成功后,添加到缓存
|
||||
this.addCachedResponse(requestKey, response);
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
if (this.debugMode) {
|
||||
console.error(`Request failed for: ${requestKey}`, error);
|
||||
}
|
||||
throw error; // 不在这里处理错误,让调用方处理
|
||||
});
|
||||
|
||||
return requestPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行POST请求(带去重和缓存)
|
||||
* @param {Function} apiFunction - API函数
|
||||
* @param {string} url - 请求URL
|
||||
* @param {object} data - 请求数据
|
||||
* @returns {Promise} API响应Promise
|
||||
*/
|
||||
async executePost(apiFunction, url, data = {}) {
|
||||
const requestKey = this.generateRequestKey(url, data);
|
||||
|
||||
// POST请求通常不缓存,但仍然可以去重
|
||||
const pendingRequest = this.getPendingRequest(requestKey);
|
||||
if (pendingRequest) {
|
||||
return pendingRequest;
|
||||
}
|
||||
|
||||
const requestPromise = apiFunction(data)
|
||||
.finally(() => {
|
||||
this.removePendingRequest(requestKey);
|
||||
});
|
||||
|
||||
this.addPendingRequest(requestKey, requestPromise);
|
||||
|
||||
return requestPromise;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建全局实例
|
||||
const apiRequestManager = new ApiRequestManager();
|
||||
|
||||
export default apiRequestManager;
|
||||
94
openhis-ui-vue3/src/utils/globalRequestController.js
Normal file
94
openhis-ui-vue3/src/utils/globalRequestController.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 全局请求控制器 - 用于在整个应用范围内控制重复请求
|
||||
* 特别针对医院信息系统中的病历数据访问进行优化
|
||||
*/
|
||||
class GlobalRequestController {
|
||||
constructor() {
|
||||
// 存储正在进行的请求
|
||||
this.activeRequests = new Map();
|
||||
// 请求计数器,用于调试
|
||||
this.requestCounter = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求的唯一标识符
|
||||
* @param {string} url - 请求URL
|
||||
* @param {object} params - 请求参数
|
||||
* @returns {string} 唯一标识符
|
||||
*/
|
||||
generateRequestId(url, params = {}) {
|
||||
// 标准化参数以确保一致性
|
||||
const normalizedParams = this.normalizeParams(params);
|
||||
const paramString = JSON.stringify(normalizedParams);
|
||||
return `${url}|${paramString}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标准化参数对象
|
||||
* @param {object} params - 原始参数
|
||||
* @returns {object} 标准化后的参数
|
||||
*/
|
||||
normalizeParams(params) {
|
||||
const normalized = {};
|
||||
// 按字母顺序排序参数键
|
||||
Object.keys(params).sort().forEach(key => {
|
||||
normalized[key] = params[key];
|
||||
});
|
||||
return normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否已有相同请求在进行中
|
||||
* @param {string} requestId - 请求ID
|
||||
* @returns {Promise|undefined} 如果存在则返回Promise,否则返回undefined
|
||||
*/
|
||||
hasActiveRequest(requestId) {
|
||||
return this.activeRequests.get(requestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册一个新请求
|
||||
* @param {string} requestId - 请求ID
|
||||
* @param {Promise} requestPromise - 请求Promise
|
||||
*/
|
||||
registerRequest(requestId, requestPromise) {
|
||||
this.requestCounter++;
|
||||
console.log(`[GlobalRequestController] Registering request #${this.requestCounter}: ${requestId}`);
|
||||
this.activeRequests.set(requestId, requestPromise);
|
||||
|
||||
// 当请求完成时,从活动请求中移除
|
||||
requestPromise.finally(() => {
|
||||
console.log(`[GlobalRequestController] Removing completed request: ${requestId}`);
|
||||
this.activeRequests.delete(requestId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行请求(确保相同参数的请求只执行一次)
|
||||
* @param {Function} apiFunction - API函数
|
||||
* @param {string} url - 请求URL
|
||||
* @param {object} params - 请求参数
|
||||
* @returns {Promise} 请求结果Promise
|
||||
*/
|
||||
async execute(apiFunction, url, params = {}) {
|
||||
const requestId = this.generateRequestId(url, params);
|
||||
|
||||
// 检查是否已有相同请求在进行中
|
||||
const existingRequest = this.hasActiveRequest(requestId);
|
||||
if (existingRequest) {
|
||||
console.log(`[GlobalRequestController] Returning existing request for: ${requestId}`);
|
||||
return existingRequest;
|
||||
}
|
||||
|
||||
// 创建新请求
|
||||
const requestPromise = apiFunction(params);
|
||||
this.registerRequest(requestId, requestPromise);
|
||||
|
||||
return requestPromise;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建全局实例
|
||||
const globalRequestController = new GlobalRequestController();
|
||||
|
||||
export default globalRequestController;
|
||||
@@ -42,6 +42,7 @@ import {defineEmits, ref, unref} from 'vue';
|
||||
import {deleteRecord, getRecordByEncounterIdList} from '../api';
|
||||
import {ElMessage} from 'element-plus';
|
||||
import {patientInfo} from '../../store/patient.js';
|
||||
import apiRequestManager from '@/utils/apiRequestManager.js';
|
||||
|
||||
const emits = defineEmits(['historyClick']);
|
||||
const props = defineProps({
|
||||
@@ -67,15 +68,30 @@ const queryParams = ref({
|
||||
isPage: 0,
|
||||
});
|
||||
const historyData = ref([]);
|
||||
// 防止重复加载的标志
|
||||
let isLoadingHistory = false;
|
||||
|
||||
const queryList = async () => {
|
||||
// 防止重复加载
|
||||
if (isLoadingHistory) {
|
||||
console.log('History data is already loading, skipping duplicate call');
|
||||
return;
|
||||
}
|
||||
|
||||
isLoadingHistory = true;
|
||||
|
||||
try {
|
||||
if (patientInfo.value.encounterId && unref(definitionId) && unref(definitionId) !== '') {
|
||||
const res = await getRecordByEncounterIdList({
|
||||
...queryParams.value,
|
||||
encounterId: patientInfo.value.encounterId,
|
||||
patientId: patientInfo.value.patientId,
|
||||
definitionId: unref(definitionId),
|
||||
});
|
||||
const res = await apiRequestManager.execute(
|
||||
getRecordByEncounterIdList,
|
||||
'/document/record/getRecordByEncounterIdList',
|
||||
{
|
||||
isPage: 0, // 确保参数一致,便于去重
|
||||
encounterId: patientInfo.value.encounterId,
|
||||
patientId: patientInfo.value.patientId,
|
||||
definitionId: unref(definitionId),
|
||||
}
|
||||
);
|
||||
historyData.value = res.data || [];
|
||||
} else {
|
||||
historyData.value = [];
|
||||
@@ -83,6 +99,8 @@ const queryList = async () => {
|
||||
} catch (error) {
|
||||
// ElMessage.error(' 获取模板树失败 ');
|
||||
historyData.value = [];
|
||||
} finally {
|
||||
isLoadingHistory = false; // 重置加载标志
|
||||
}
|
||||
};
|
||||
const handleNodeClick = (data) => {
|
||||
|
||||
@@ -103,6 +103,7 @@ import dayjs from 'dayjs';
|
||||
// 打印工具
|
||||
import {PRINT_TEMPLATE, simplePrint} from '@/utils/printUtils.js';
|
||||
import {getEncounterDiagnosis} from '../api';
|
||||
import apiRequestManager from '@/utils/apiRequestManager.js';
|
||||
import History from './components/history';
|
||||
import Template from './components/template';
|
||||
import TemplateEdit from './components/templateEdit.vue';
|
||||
@@ -205,7 +206,7 @@ const handleNodeClick = (data, node) => {
|
||||
|
||||
// 选择任何病历模板后,都加载该病历类型的最新历史记录
|
||||
if (node.isLeaf && props.patientInfo && props.patientInfo.patientId) {
|
||||
loadLatestMedicalRecord();
|
||||
debouncedLoadLatestMedicalRecord();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
@@ -279,7 +280,7 @@ const handleSubmitOk = async (data) => {
|
||||
|
||||
// 等待历史记录列表更新后,重新加载最新病历并更新选中状态
|
||||
setTimeout(() => {
|
||||
loadLatestMedicalRecord();
|
||||
debouncedLoadLatestMedicalRecord();
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
ElMessage.error('提交失败');
|
||||
@@ -410,7 +411,7 @@ const selectOutpatientMedicalRecordTemplate = async () => {
|
||||
// 等待模板加载完成,然后获取并回显最新病历数据
|
||||
setTimeout(() => {
|
||||
historyRef.value?.queryList();
|
||||
loadLatestMedicalRecord();
|
||||
debouncedLoadLatestMedicalRecord();
|
||||
}, 500);
|
||||
});
|
||||
} else {
|
||||
@@ -421,19 +422,36 @@ const selectOutpatientMedicalRecordTemplate = async () => {
|
||||
// 当前选中的历史病历ID,用于在History组件中高亮显示
|
||||
const selectedHistoryRecordId = ref('');
|
||||
|
||||
import { debounce } from 'lodash-es';
|
||||
|
||||
// 防止重复加载的标志
|
||||
let isLoadingLatestRecord = false;
|
||||
|
||||
// 加载最新的病历数据并回显
|
||||
const loadLatestMedicalRecord = async () => {
|
||||
if (!patientInfo.value.encounterId || !currentSelectTemplate.value.id) return;
|
||||
|
||||
// 防止重复加载
|
||||
if (isLoadingLatestRecord) {
|
||||
console.log('Latest medical record is already loading, skipping duplicate call');
|
||||
return;
|
||||
}
|
||||
|
||||
isLoadingLatestRecord = true;
|
||||
loading.value = true;
|
||||
|
||||
try {
|
||||
// 获取患者的历史病历记录
|
||||
const res = await getRecordByEncounterIdList({
|
||||
isPage: 0,
|
||||
encounterId: patientInfo.value.encounterId,
|
||||
patientId: patientInfo.value.patientId,
|
||||
definitionId: currentSelectTemplate.value.id,
|
||||
});
|
||||
const res = await apiRequestManager.execute(
|
||||
getRecordByEncounterIdList,
|
||||
'/document/record/getRecordByEncounterIdList',
|
||||
{
|
||||
isPage: 0,
|
||||
encounterId: patientInfo.value.encounterId,
|
||||
patientId: patientInfo.value.patientId,
|
||||
definitionId: currentSelectTemplate.value.id,
|
||||
}
|
||||
);
|
||||
|
||||
const historyRecords = res.data || [];
|
||||
if (historyRecords.length > 0) {
|
||||
@@ -519,8 +537,12 @@ const loadLatestMedicalRecord = async () => {
|
||||
});
|
||||
} finally {
|
||||
loading.value = false;
|
||||
isLoadingLatestRecord = false; // 重置加载标志
|
||||
}
|
||||
};
|
||||
|
||||
// 防抖版本的加载最新病历数据函数
|
||||
const debouncedLoadLatestMedicalRecord = debounce(loadLatestMedicalRecord, 300);
|
||||
const templateRef = ref(null);
|
||||
|
||||
const handleTemplateClick = (data) => {
|
||||
@@ -750,7 +772,7 @@ const selectDefaultTemplate = () => {
|
||||
|
||||
// 直接加载最新病历数据,不再使用额外的setTimeout延迟
|
||||
// 因为handleNodeClick中已经有nextTick和setTimeout处理组件渲染
|
||||
loadLatestMedicalRecord();
|
||||
debouncedLoadLatestMedicalRecord();
|
||||
});
|
||||
} else {
|
||||
console.log('未找到门诊病历模板');
|
||||
|
||||
@@ -209,6 +209,7 @@ import useUserStore from '@/store/modules/user';
|
||||
import { nextTick } from 'vue';
|
||||
import { updatePatientInfo } from './components/store/patient.js';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { debounce } from 'lodash-es';
|
||||
|
||||
// // 监听路由离开事件
|
||||
// onBeforeRouteLeave((to, from, next) => {
|
||||
@@ -487,7 +488,8 @@ function handleOpen() {
|
||||
patientDrawerRef.value.refreshList();
|
||||
}
|
||||
|
||||
function handleCardClick(item, index) {
|
||||
// 原始的handleCardClick函数
|
||||
function handleCardClickOriginal(item, index) {
|
||||
console.log('handleCardClick 被调用');
|
||||
console.log('点击的患者项目:', item);
|
||||
console.log('患者项目中的encounterId:', item.encounterId);
|
||||
@@ -544,6 +546,9 @@ function handleCardClick(item, index) {
|
||||
});
|
||||
}
|
||||
|
||||
// 使用防抖的handleCardClick函数,防止短时间内多次点击
|
||||
const handleCardClick = debounce(handleCardClickOriginal, 500);
|
||||
|
||||
function handleLeave(encounterId) {
|
||||
leaveEncounter(encounterId).then((res) => {
|
||||
if (res.code == 200) {
|
||||
@@ -589,7 +594,7 @@ function handleHospitalizationClick() {
|
||||
|
||||
// 接诊回调
|
||||
function handleReceive(row) {
|
||||
handleCardClick(row);
|
||||
handleCardClickOriginal(row);
|
||||
currentEncounterId.value = row.encounterId;
|
||||
drawer.value = false;
|
||||
getPatientList();
|
||||
@@ -776,7 +781,7 @@ const markSeen = async () => {
|
||||
currentCallPatient.value = {};
|
||||
};
|
||||
const callThis = (row) => {
|
||||
handleCardClick(row);
|
||||
handleCardClickOriginal(row);
|
||||
currentCallPatient.value = row;
|
||||
dialogVisible.value = false;
|
||||
// 刷新患者列表和候诊列表
|
||||
|
||||
@@ -525,19 +525,33 @@ function getList() {
|
||||
function refresh() {
|
||||
getListInfo(false);
|
||||
}
|
||||
// 防止重复请求的标志
|
||||
let listInfoRequestPromise = null;
|
||||
|
||||
// 获取列表信息
|
||||
function getListInfo(addNewRow) {
|
||||
// 如果已经有正在进行的请求,则返回该请求的Promise
|
||||
if (listInfoRequestPromise) {
|
||||
return listInfoRequestPromise;
|
||||
}
|
||||
|
||||
loadingInstance = ElLoading.service({ fullscreen: true });
|
||||
setTimeout(() => {
|
||||
loadingInstance.close();
|
||||
if (loadingInstance) {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}, 180);
|
||||
isAdding.value = false;
|
||||
expandOrder.value = [];
|
||||
getPrescriptionList(patientInfo.value.encounterId).then((res) => {
|
||||
console.log('getListInfo==========>', JSON.stringify(res.data));
|
||||
|
||||
loadingInstance.close();
|
||||
prescriptionList.value = res.data
|
||||
// 并行请求两个API并将结果合并处理
|
||||
listInfoRequestPromise = Promise.all([
|
||||
getPrescriptionList(patientInfo.value.encounterId),
|
||||
getContract({ encounterId: patientInfo.value.encounterId })
|
||||
])
|
||||
.then(([prescriptionRes, contractRes]) => {
|
||||
// 处理处方列表
|
||||
prescriptionList.value = prescriptionRes.data
|
||||
.map((item) => {
|
||||
return {
|
||||
...JSON.parse(item.contentJson),
|
||||
@@ -549,15 +563,35 @@ function getListInfo(addNewRow) {
|
||||
.sort((a, b) => {
|
||||
return new Date(b.requestTime) - new Date(a.requestTime);
|
||||
});
|
||||
getGroupMarkers(); // 更新标记
|
||||
|
||||
// 处理合同列表
|
||||
contractList.value = contractRes.data;
|
||||
|
||||
// 更新账户ID
|
||||
accountId.value = patientInfo.value.accountId;
|
||||
|
||||
// 更新标记
|
||||
getGroupMarkers();
|
||||
|
||||
if (props.activeTab == 'prescription' && addNewRow) {
|
||||
handleAddPrescription();
|
||||
}
|
||||
|
||||
console.log('getListInfo==========>', JSON.stringify(prescriptionRes.data));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取列表信息失败:', error);
|
||||
ElMessage.error('获取列表信息失败');
|
||||
})
|
||||
.finally(() => {
|
||||
if (loadingInstance) {
|
||||
loadingInstance.close();
|
||||
}
|
||||
// 请求完成后清除Promise引用
|
||||
listInfoRequestPromise = null;
|
||||
});
|
||||
getContract({ encounterId: patientInfo.value.encounterId }).then((res) => {
|
||||
contractList.value = res.data;
|
||||
});
|
||||
accountId.value = patientInfo.value.accountId;
|
||||
|
||||
return listInfoRequestPromise;
|
||||
}
|
||||
// 数据过滤
|
||||
const filterPrescriptionList = computed(() => {
|
||||
@@ -571,18 +605,37 @@ const filterPrescriptionList = computed(() => {
|
||||
return pList;
|
||||
});
|
||||
|
||||
// 防止诊断信息重复请求的标志
|
||||
let diagnosisInfoRequestPromise = null;
|
||||
|
||||
function getDiagnosisInfo() {
|
||||
getEncounterDiagnosis(patientInfo.value.encounterId).then((res) => {
|
||||
diagnosisList.value = res.data;
|
||||
let diagnosisInfo = diagnosisList.value.filter((item) => {
|
||||
return item.maindiseFlag == 1;
|
||||
// 如果已经有正在进行的请求,则返回该请求的Promise
|
||||
if (diagnosisInfoRequestPromise) {
|
||||
return diagnosisInfoRequestPromise;
|
||||
}
|
||||
|
||||
diagnosisInfoRequestPromise = getEncounterDiagnosis(patientInfo.value.encounterId)
|
||||
.then((res) => {
|
||||
diagnosisList.value = res.data;
|
||||
let diagnosisInfo = diagnosisList.value.filter((item) => {
|
||||
return item.maindiseFlag == 1;
|
||||
});
|
||||
diagnosisInfo.value = diagnosisInfo[0];
|
||||
conditionDefinitionId.value = diagnosisInfo[0].definitionId;
|
||||
conditionId.value = diagnosisInfo[0].conditionId;
|
||||
encounterDiagnosisId.value = diagnosisInfo[0].encounterDiagnosisId;
|
||||
diagnosisName.value = diagnosisInfo[0].name;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取诊断信息失败:', error);
|
||||
ElMessage.error('获取诊断信息失败');
|
||||
})
|
||||
.finally(() => {
|
||||
// 请求完成后清除Promise引用
|
||||
diagnosisInfoRequestPromise = null;
|
||||
});
|
||||
diagnosisInfo.value = diagnosisInfo[0];
|
||||
conditionDefinitionId.value = diagnosisInfo[0].definitionId;
|
||||
conditionId.value = diagnosisInfo[0].conditionId;
|
||||
encounterDiagnosisId.value = diagnosisInfo[0].encounterDiagnosisId;
|
||||
diagnosisName.value = diagnosisInfo[0].name;
|
||||
});
|
||||
|
||||
return diagnosisInfoRequestPromise;
|
||||
}
|
||||
|
||||
function getRowDisabled(row) {
|
||||
|
||||
@@ -65,22 +65,40 @@ const queryParams = ref({
|
||||
isPage: 0,
|
||||
});
|
||||
const historyData = ref([]);
|
||||
// 防止重复请求的标志
|
||||
let queryListPromise = null;
|
||||
|
||||
const queryList = async () => {
|
||||
// 如果已经有正在进行的请求,则返回该请求的Promise
|
||||
if (queryListPromise) {
|
||||
return queryListPromise;
|
||||
}
|
||||
|
||||
try {
|
||||
if (patientInfo.value.encounterId && unref(definitionId) && unref(definitionId) !== '') {
|
||||
const res = await getRecordByEncounterIdList({
|
||||
queryListPromise = getRecordByEncounterIdList({
|
||||
...queryParams.value,
|
||||
encounterId: patientInfo.value.encounterId,
|
||||
patientId: patientInfo.value.patientId,
|
||||
definitionId: unref(definitionId),
|
||||
})
|
||||
.then(res => {
|
||||
historyData.value = res.data || [];
|
||||
})
|
||||
.finally(() => {
|
||||
// 请求完成后清除Promise引用
|
||||
queryListPromise = null;
|
||||
});
|
||||
historyData.value = res.data || [];
|
||||
|
||||
return queryListPromise;
|
||||
} else {
|
||||
historyData.value = [];
|
||||
}
|
||||
} catch (error) {
|
||||
// 不显示错误消息,避免干扰用户体验
|
||||
historyData.value = [];
|
||||
// 请求完成后清除Promise引用
|
||||
queryListPromise = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -305,9 +305,10 @@ const handleSubmitOk = async (data) => {
|
||||
// templateRef.value?.queryList();
|
||||
|
||||
// 等待历史记录列表更新后,重新加载最新病历并更新选中状态
|
||||
// 增加延迟时间以确保数据库更新完成
|
||||
setTimeout(() => {
|
||||
loadLatestMedicalRecord();
|
||||
}, 100);
|
||||
}, 300);
|
||||
ElMessage.success('保存成功');
|
||||
} catch (error) {
|
||||
ElMessage.error('提交失败');
|
||||
@@ -553,54 +554,94 @@ const selectOutpatientMedicalRecordTemplate = async () => {
|
||||
selectDefaultTemplate();
|
||||
};
|
||||
|
||||
// 防止重复请求的标志
|
||||
let loadLatestMedicalRecordPromise = null;
|
||||
|
||||
// 加载最新的病历数据并回显
|
||||
const loadLatestMedicalRecord = async () => {
|
||||
// 如果已经有正在进行的请求,则返回该请求的Promise
|
||||
if (loadLatestMedicalRecordPromise) {
|
||||
return loadLatestMedicalRecordPromise;
|
||||
}
|
||||
|
||||
if (!patientInfo.value?.encounterId || !currentSelectTemplate.value.id) return;
|
||||
editForm.value.id = '';
|
||||
loading.value = true;
|
||||
try {
|
||||
// 获取患者的历史病历记录
|
||||
const res = await getRecordByEncounterIdList({
|
||||
isPage: 0,
|
||||
encounterId: patientInfo.value.encounterId,
|
||||
patientId: patientInfo.value.patientId,
|
||||
definitionId: currentSelectTemplate.value.id,
|
||||
});
|
||||
|
||||
const historyRecords = res.data || [];
|
||||
if (historyRecords.length > 0) {
|
||||
// 按时间排序,获取最新的病历记录
|
||||
historyRecords.sort((a, b) => new Date(b.recordTime) - new Date(a.recordTime));
|
||||
const latestRecord = historyRecords[0];
|
||||
// 创建一个新的Promise来处理请求
|
||||
loadLatestMedicalRecordPromise = new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
// 获取患者的历史病历记录
|
||||
const res = await getRecordByEncounterIdList({
|
||||
isPage: 0,
|
||||
encounterId: patientInfo.value.encounterId,
|
||||
patientId: patientInfo.value.patientId,
|
||||
definitionId: currentSelectTemplate.value.id,
|
||||
});
|
||||
|
||||
// 保存最新病历ID,用于在History组件中高亮显示
|
||||
selectedHistoryRecordId.value = latestRecord.id;
|
||||
// 自动回显最新病历数据到模板
|
||||
editForm.value = latestRecord;
|
||||
nextTick(() => {
|
||||
if (emrComponentRef.value && latestRecord.contentJson) {
|
||||
try {
|
||||
const parsedData = JSON.parse(latestRecord.contentJson);
|
||||
emrComponentRef.value.setFormData(parsedData);
|
||||
} catch (parseError) {
|
||||
console.error('解析病历数据失败:', parseError);
|
||||
// 解析失败时仍然尝试设置空数据以清空之前的残留数据
|
||||
const historyRecords = res.data || [];
|
||||
if (historyRecords.length > 0) {
|
||||
// 按时间排序,获取最新的病历记录
|
||||
historyRecords.sort((a, b) => new Date(b.recordTime) - new Date(a.recordTime));
|
||||
const latestRecord = historyRecords[0];
|
||||
|
||||
// 保存最新病历ID,用于在History组件中高亮显示
|
||||
selectedHistoryRecordId.value = latestRecord.id;
|
||||
// 自动回显最新病历数据到模板
|
||||
editForm.value = latestRecord;
|
||||
nextTick(() => {
|
||||
if (emrComponentRef.value && latestRecord.contentJson) {
|
||||
try {
|
||||
const parsedData = JSON.parse(latestRecord.contentJson);
|
||||
emrComponentRef.value.setFormData(parsedData);
|
||||
} catch (parseError) {
|
||||
console.error('解析病历数据失败:', parseError);
|
||||
// 解析失败时仍然尝试设置空数据以清空之前的残留数据
|
||||
emrComponentRef.value.setFormData({});
|
||||
}
|
||||
} else {
|
||||
// 如果没有内容数据,也要清空组件中的数据
|
||||
emrComponentRef.value.setFormData({});
|
||||
}
|
||||
} else {
|
||||
// 如果没有内容数据,也要清空组件中的数据
|
||||
emrComponentRef.value.setFormData({});
|
||||
}
|
||||
|
||||
// 通知History组件更新选中状态
|
||||
if (historyRef.value && typeof historyRef.value.updateSelectedRecord === 'function') {
|
||||
historyRef.value.updateSelectedRecord(latestRecord.id);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 清空选中状态
|
||||
// 通知History组件更新选中状态
|
||||
if (historyRef.value && typeof historyRef.value.updateSelectedRecord === 'function') {
|
||||
historyRef.value.updateSelectedRecord(latestRecord.id);
|
||||
}
|
||||
|
||||
resolve(); // 成功完成
|
||||
});
|
||||
} else {
|
||||
// 清空选中状态
|
||||
selectedHistoryRecordId.value = '';
|
||||
// 当没有历史记录时,也要清空当前表单数据,避免显示之前患者的数据
|
||||
editForm.value = {
|
||||
id: '',
|
||||
definitionId: '',
|
||||
definitionBusNo: '',
|
||||
contentJson: '',
|
||||
statusEnum: 1,
|
||||
organizationId: 0,
|
||||
encounterId: '',
|
||||
patientId: '',
|
||||
recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
createBy: '',
|
||||
source: '',
|
||||
};
|
||||
|
||||
nextTick(() => {
|
||||
if (emrComponentRef.value) {
|
||||
emrComponentRef.value.setFormData({});
|
||||
}
|
||||
resolve(); // 成功完成
|
||||
});
|
||||
loading.value = false;
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error('加载最新病历数据失败=====>', error);
|
||||
// 出错时也清空选中状态
|
||||
selectedHistoryRecordId.value = '';
|
||||
// 当没有历史记录时,也要清空当前表单数据,避免显示之前患者的数据
|
||||
// 出错时也要清空表单数据,避免显示之前患者的数据
|
||||
editForm.value = {
|
||||
id: '',
|
||||
definitionId: '',
|
||||
@@ -619,37 +660,17 @@ const loadLatestMedicalRecord = async () => {
|
||||
if (emrComponentRef.value) {
|
||||
emrComponentRef.value.setFormData({});
|
||||
}
|
||||
reject(error); // 错误完成
|
||||
});
|
||||
loading.value = false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
// 请求完成后清除Promise引用
|
||||
loadLatestMedicalRecordPromise = null;
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error('加载最新病历数据失败=====>', error);
|
||||
// 出错时也清空选中状态
|
||||
selectedHistoryRecordId.value = '';
|
||||
// 出错时也要清空表单数据,避免显示之前患者的数据
|
||||
editForm.value = {
|
||||
id: '',
|
||||
definitionId: '',
|
||||
definitionBusNo: '',
|
||||
contentJson: '',
|
||||
statusEnum: 1,
|
||||
organizationId: 0,
|
||||
encounterId: '',
|
||||
patientId: '',
|
||||
recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
createBy: '',
|
||||
source: '',
|
||||
};
|
||||
});
|
||||
|
||||
nextTick(() => {
|
||||
if (emrComponentRef.value) {
|
||||
emrComponentRef.value.setFormData({});
|
||||
}
|
||||
});
|
||||
loading.value = false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
return loadLatestMedicalRecordPromise;
|
||||
};
|
||||
|
||||
// 选择默认模板 - 获取住院病历分类下的第一个模板
|
||||
@@ -835,6 +856,41 @@ watch(
|
||||
{ deep: true, immediate: true }
|
||||
);
|
||||
|
||||
// 合并两个监听器,避免重复触发
|
||||
let patientChangeProcessing = false; // 防止重复处理
|
||||
|
||||
watch(
|
||||
() => [patientInfo.value?.encounterId, currentSelectTemplate.value?.id],
|
||||
([newEncounterId, newTemplateId]) => {
|
||||
// 当患者就诊ID或模板ID变化时,加载最新病历数据
|
||||
if (newEncounterId && newTemplateId && !patientChangeProcessing) {
|
||||
patientChangeProcessing = true;
|
||||
|
||||
// 添加延迟以确保模板数据已更新
|
||||
nextTick(() => {
|
||||
loadLatestMedicalRecord().finally(() => {
|
||||
// 重置处理标志
|
||||
patientChangeProcessing = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// 监听模板选择变化,当模板选择变化时加载最新病历数据
|
||||
watch(
|
||||
() => currentSelectTemplate.value.id,
|
||||
(newTemplateId) => {
|
||||
// 当模板选择变化时,加载该模板的最新病历数据
|
||||
if (newTemplateId) {
|
||||
// 只要有模板ID,就尝试加载数据,不管之前是否有患者信息
|
||||
// 因为可能是在切换患者后才选择模板
|
||||
loadLatestMedicalRecord();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
// 移除日志
|
||||
await queryTemplateTree();
|
||||
|
||||
@@ -109,16 +109,25 @@ const getList = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// 标记是否已经手动选择过患者,防止后续自动选择
|
||||
const hasManuallySelectedPatient = ref(false);
|
||||
|
||||
// 添加一个变量来跟踪当前期望的患者ID
|
||||
let expectedPatientId = null;
|
||||
|
||||
watch(
|
||||
() => filteredCardData.value,
|
||||
(newData) => {
|
||||
// 如果有数据且当前没有选中患者,且是首次加载,默认选择第一条
|
||||
// 只有在从未手动选择过患者的情况下才自动选择
|
||||
// 并且确保当前没有正在处理的患者切换操作
|
||||
if (
|
||||
newData &&
|
||||
newData.length > 0 &&
|
||||
!cardId.value &&
|
||||
isFirstLoad.value &&
|
||||
!patientInfo.value?.encounterId
|
||||
!patientInfo.value?.encounterId &&
|
||||
!hasManuallySelectedPatient.value
|
||||
) {
|
||||
const firstPatient = newData[0];
|
||||
if (firstPatient?.encounterId) {
|
||||
@@ -130,34 +139,81 @@ watch(
|
||||
debounceTimer = setTimeout(() => {
|
||||
handleItemClick(firstPatient);
|
||||
isFirstLoad.value = false;
|
||||
hasManuallySelectedPatient.value = true; // 标记已手动选择过
|
||||
}, 100);
|
||||
}
|
||||
} else if (expectedPatientId && cardId.value && cardId.value !== expectedPatientId) {
|
||||
// 如果当前cardId与期望的不一致,且不是初始状态,这可能意味着发生了意外的重置
|
||||
// 这种情况下,我们不希望自动选择第一个患者
|
||||
console.debug(`期望的患者ID: ${expectedPatientId}, 当前cardId: ${cardId.value}`);
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// 防抖函数,防止快速点击导致状态冲突
|
||||
let debounceTimer = null;
|
||||
// 更新handleItemClick函数,设置期望的患者ID
|
||||
const handleItemClick = (node) => {
|
||||
// 设置期望的患者ID
|
||||
expectedPatientId = node.encounterId;
|
||||
|
||||
// 清除之前的计时器
|
||||
if (debounceTimer) {
|
||||
clearTimeout(debounceTimer);
|
||||
}
|
||||
|
||||
// 取消之前未完成的患者加载操作
|
||||
if (currentPatientPromise) {
|
||||
// 注意:这里无法真正取消Promise,但我们可以标记当前操作已过期
|
||||
currentPatientPromise.cancelled = true;
|
||||
}
|
||||
|
||||
// 设置新的计时器
|
||||
debounceTimer = setTimeout(() => {
|
||||
debounceTimer = setTimeout(async () => {
|
||||
// 检查是否已被取消
|
||||
if (currentPatientPromise?.cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
cardId.value = node.encounterId;
|
||||
// 同时更新本地和全局状态,确保模块内组件和跨模块组件都能正确响应
|
||||
updatePatientInfo(node);
|
||||
updateLocalPatientInfo(node);
|
||||
|
||||
diagnosisRef.value?.getList();
|
||||
adviceRef.value?.getListInfo();
|
||||
adviceRef.value?.getDiagnosisInfo();
|
||||
// 标记已手动选择患者,防止自动选择第一条
|
||||
hasManuallySelectedPatient.value = true;
|
||||
|
||||
// 创建一个新的Promise来追踪这次加载操作
|
||||
currentPatientPromise = Promise.all([
|
||||
// 并行调用医嘱相关的API,避免重复请求
|
||||
adviceRef.value?.getListInfo().catch(error => {
|
||||
console.error('获取医嘱信息失败:', error);
|
||||
return null;
|
||||
}),
|
||||
adviceRef.value?.getDiagnosisInfo().catch(error => {
|
||||
console.error('获取诊断信息失败:', error);
|
||||
return null;
|
||||
}),
|
||||
// 获取诊断信息
|
||||
diagnosisRef.value?.getList?.().catch(error => {
|
||||
console.error('获取诊断信息失败:', error);
|
||||
return null;
|
||||
})
|
||||
]);
|
||||
|
||||
try {
|
||||
await currentPatientPromise;
|
||||
// 检查在此期间是否选择了其他患者
|
||||
if (currentPatientPromise?.cancelled) {
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载患者信息时出错:', error);
|
||||
}
|
||||
}, 100); // 100ms 防抖延迟
|
||||
};
|
||||
|
||||
// 防抖函数,防止快速点击导致状态冲突
|
||||
|
||||
const handleSearch = (keyword) => {
|
||||
searchData.keyword = keyword;
|
||||
getList();
|
||||
|
||||
Reference in New Issue
Block a user