/** * 医疗常量配置 * 从字典动态获取常量值,避免硬编码 * * 使用方式: * import { DIAG_TYPE, RequestStatus } from '@/utils/medicalConstants'; * medTypeCode: DIAG_TYPE.WESTERN_MEDICINE * serviceStatus: RequestStatus.ACTIVE */ import { getDicts } from '@/api/system/dict/data'; // 诊断类型字典缓存 let diagTypeCache = null; /** * 请求状态枚举(与后端 RequestStatus.java 保持一致) * 用于服务申请、医嘱执行等状态管理 */ export const RequestStatus = { /** 待发送 */ DRAFT: 1, /** 已发送/待执行 */ ACTIVE: 2, /** 已完成 */ COMPLETED: 3, /** 暂停 */ ON_HOLD: 4, /** 取消/待退 */ CANCELLED: 5, /** 停嘱 */ STOPPED: 6, /** 不执行 */ ENDED: 7, /** 未知 */ UNKNOWN: 9, }; /** * 请求状态枚举的说明信息 */ export const RequestStatusDescriptions = { 1: '待发送', 2: '已发送/待执行', 3: '已完成', 4: '暂停', 5: '取消/待退', 6: '停嘱', 7: '不执行', 9: '未知', }; /** * 获取请求状态的说明 * @param {number} value - 请求状态值 * @returns {string} - 说明信息 */ export function getRequestStatusDescription(value) { return RequestStatusDescriptions[value] || '未知状态'; } /** * 获取诊断类型字典(异步初始化) */ async function initDiagType() { if (!diagTypeCache) { try { const res = await getDicts('diag_type'); diagTypeCache = res.data || []; } catch (error) { console.error('获取诊断类型字典失败:', error); diagTypeCache = []; } } return diagTypeCache; } /** * 根据标签获取诊断类型的值 * @param {string} label - 诊断类型标签,如 '西医诊断' * @returns {string|null} - 诊断类型的值,如 '1' */ export async function getDiagTypeValue(label) { const dictList = await initDiagType(); const item = dictList.find(d => d.dictLabel === label); return item ? item.dictValue : null; } /** * 根据值获取诊断类型的标签 * @param {string} value - 诊断类型的值,如 '1' * @returns {string|null} - 诊断类型的标签,如 '西医诊断' */ export async function getDiagTypeLabel(value) { const dictList = await initDiagType(); const item = dictList.find(d => d.dictValue === value); return item ? item.dictLabel : null; } /** * 获取完整的诊断类型字典列表 * @returns {Array} - 诊断类型字典列表 */ export async function getDiagTypeList() { return await initDiagType(); } /** * 诊断类型常量(同步使用,需要先初始化字典) * 注意:这些值在字典加载后才有效 */ export const DIAG_TYPE = { /** 西医诊断 */ WESTERN_MEDICINE: '1', /** 中医主病诊断 */ TCM_MAIN_DISEASE: '2', /** 中医主证诊断 */ TCM_MAIN_SYNDROME: '3', /** 初诊诊断 */ INITIAL: '4', /** 修正诊断 */ REVISED: '5', /** 补充诊断 */ SUPPLEMENTARY: '6', }; /** * 诊断类型常量的说明信息 */ export const DIAG_TYPE_DESCRIPTIONS = { '1': '西医诊断', '2': '中医主病诊断', '3': '中医主证诊断', '4': '初诊诊断', '5': '修正诊断', '6': '补充诊断', }; /** * 获取诊断类型的说明 * @param {string} value - 诊断类型的值 * @returns {string} - 说明信息 */ export function getDiagTypeDescription(value) { return DIAG_TYPE_DESCRIPTIONS[value] || '未知类型'; } // 默认导出 export default { DIAG_TYPE, DIAG_TYPE_DESCRIPTIONS, getDiagTypeValue, getDiagTypeLabel, getDiagTypeList, getDiagTypeDescription, };