diff --git a/apps/web-antd/src/views/business/chat/components/PrescriptionModal.vue b/apps/web-antd/src/views/business/chat/components/PrescriptionModal.vue index 67d2e88f..11b2a80f 100644 --- a/apps/web-antd/src/views/business/chat/components/PrescriptionModal.vue +++ b/apps/web-antd/src/views/business/chat/components/PrescriptionModal.vue @@ -332,15 +332,15 @@ function openCommonPrescriptionModal() { /** * 处理选择常用方 * @param data 常用方数据,包含prescription和recipes - * @param type 类型:1-中药,2-西药,3-颗粒药 + * @param type 类型:1-西药,2-中药,3-颗粒药 * @description 选择常用方后,将药品列表填充到当前处方中 */ -function handleSelectCommonPrescription(data: any, type: number) { +async function handleSelectCommonPrescription(data: any, type: number) { const { prescription, recipes } = data; // 根据类型处理不同的药品数据 - if (type === 2) { - // 西药(中成药)处方 + if (type === 1) { + // 西药处方 recipes.forEach((recipe: any) => { const newProduct = { index_id: recipe.drug_id || recipe.id, @@ -389,13 +389,34 @@ function handleSelectCommonPrescription(data: any, type: number) { prescriptionStore.currentDrugs.push(newProduct); } }); + + // 写入规则类型和剂量信息(中药)- 使用 ?? 运算符提供默认值 + prescriptionStore.ruleType = prescription.rule_type ?? 1; + prescriptionStore.dosage = prescription.dosage ?? 7; + prescriptionStore.dayDosage = prescription.day_dosage ?? 2; + prescriptionStore.packageMethodId = prescription.package_method_id ?? 2; + + // 如果是委托调剂,写入完整加工规则配置 - 只有有效值才写入(大于0),级联加载 + if (prescription.process_rule_id && prescription.process_rule_id > 0) { + prescriptionStore.processRuleId = prescription.process_rule_id; + // 加载煎法选项 + await prescriptionStore.getProcessRuleListData(prescription.process_rule_id, 0); + } + if (prescription.child_process_rule_id && prescription.child_process_rule_id > 0) { + prescriptionStore.childProcessRuleId = prescription.child_process_rule_id; + // 加载备注选项 + await prescriptionStore.getProcessRuleListData(0, prescription.child_process_rule_id); + } + if (prescription.process_rule_note_id && prescription.process_rule_note_id > 0) { + prescriptionStore.processRuleNoteId = prescription.process_rule_note_id; + } } - // 更新诊断和医嘱 - if (prescription.clinical_diagnose) { + // 更新诊断和医嘱 - 允许空字符串覆盖 + if (prescription.clinical_diagnose !== undefined && prescription.clinical_diagnose !== null) { prescriptionStore.diagnosis = prescription.clinical_diagnose; } - if (prescription.doctor_order) { + if (prescription.doctor_order !== undefined && prescription.doctor_order !== null) { prescriptionStore.medicalAdvice = prescription.doctor_order; } diff --git a/apps/web-antd/src/views/doctor/doctor-reception/components/CommonPrescriptionModal.vue b/apps/web-antd/src/views/doctor/doctor-reception/components/CommonPrescriptionModal.vue index add67cb5..89f63f90 100644 --- a/apps/web-antd/src/views/doctor/doctor-reception/components/CommonPrescriptionModal.vue +++ b/apps/web-antd/src/views/doctor/doctor-reception/components/CommonPrescriptionModal.vue @@ -288,6 +288,18 @@ function getDrugCount(recipes: any[]): number { 医嘱: {{ item.doctor_order }}

+

+ 调配方式: + {{ item.rule_type === 1 ? '自制剂' : '委托调剂' }} + 剂量:{{ item.dosage || 7 }}天/剂 + 频次:{{ item.day_dosage || 2 }}次/天 +

+

+ 委托调剂: + 制剂:{{ item.process_rule_name }} + 煎法:{{ item.child_process_rule_name }} + 备注:{{ item.process_rule_note_name }} +

药品: {{ diff --git a/apps/web-antd/src/views/doctor/doctor-reception/index.vue b/apps/web-antd/src/views/doctor/doctor-reception/index.vue index 43fbfecf..40bc1f21 100644 --- a/apps/web-antd/src/views/doctor/doctor-reception/index.vue +++ b/apps/web-antd/src/views/doctor/doctor-reception/index.vue @@ -8,6 +8,7 @@ import { DeleteTwoTone, MinusOutlined, PlusOutlined, + SaveOutlined, } from '@ant-design/icons-vue'; import { Button, @@ -17,6 +18,7 @@ import { Empty, Image, ImagePreviewGroup, + Input, InputNumber, message, RadioButton, @@ -24,7 +26,7 @@ import { Row, Select, SelectOption, - Modal, + Modal as AntModal, Tag, Textarea, Timeline, @@ -54,6 +56,11 @@ import RefusalOfTreatmentModal from "#/views/doctor/doctor-reception/components/RefusalOfTreatmentModal.vue"; // 常用方选择弹窗组件 import CommonPrescriptionModal from './components/CommonPrescriptionModal.vue'; +// 保存常用方API +import { + saveChineseCommonPrescriptionApi, + saveWestCommonPrescriptionApi, +} from '#/views/doctor/settings/api'; interface Patient { id: number; @@ -171,6 +178,14 @@ const ruleType = ref(1); const prescriptionList = ref([]); const drugList = ref([]); +// ==================== 保存常用方相关状态 ==================== +/** 保存常用方弹窗是否显示 */ +const showSaveCommonPrescriptionModal = ref(false); +/** 常用方名称输入 */ +const commonPrescriptionName = ref(''); +/** 是否正在保存常用方 */ +const isSavingCommonPrescription = ref(false); + /** * 获取药品使用方式列表 */ @@ -680,7 +695,7 @@ function openCommonPrescriptionModal() { * @param type 类型:1-西药,2-中药,3-颗粒药 * @description 选择常用方后,将药品列表填充到当前处方中 */ -function handleSelectCommonPrescription(data: any, type: number) { +async function handleSelectCommonPrescription(data: any, type: number) { const { prescription, recipes } = data; // 根据类型处理不同的药品数据 @@ -735,19 +750,150 @@ function handleSelectCommonPrescription(data: any, type: number) { currentDrugs.value.push(newProduct); } }); + + // 写入规则类型和剂量信息(中药)- 使用 ?? 运算符提供默认值 + ruleType.value = prescription.rule_type ?? 1; + dosage.value = prescription.dosage ?? 7; + dayDosage.value = prescription.day_dosage ?? 2; + packageMethodId.value = prescription.package_method_id ?? 2; + + // 如果是委托调剂,写入完整加工规则配置 - 只有有效值才写入(大于0),级联加载 + if (prescription.process_rule_id && prescription.process_rule_id > 0) { + processRuleId.value = prescription.process_rule_id; + // 加载煎法选项 + await loadProcessRuleData(prescription.process_rule_id, 0); + } + if (prescription.child_process_rule_id && prescription.child_process_rule_id > 0) { + childProcessRuleId.value = prescription.child_process_rule_id; + // 加载备注选项 + await loadProcessRuleData(0, prescription.child_process_rule_id); + } + if (prescription.process_rule_note_id && prescription.process_rule_note_id > 0) { + processRuleNoteId.value = prescription.process_rule_note_id; + } } - // 更新诊断和医嘱 - if (prescription.clinical_diagnose) { + // 更新诊断和医嘱 - 允许空字符串覆盖 + if (prescription.clinical_diagnose !== undefined && prescription.clinical_diagnose !== null) { diagnosis.value = prescription.clinical_diagnose; } - if (prescription.doctor_order) { + if (prescription.doctor_order !== undefined && prescription.doctor_order !== null) { medicalAdvice.value = prescription.doctor_order; } // 保存到本地存储 updateLocalStorage(); } + +// ==================== 保存常用方相关方法 ==================== + +/** + * 打开保存常用方弹窗 + * @description 检查是否有药品可保存,然后打开弹窗 + */ +const openSaveCommonPrescriptionModal = () => { + // 检查是否有药品 + if (currentDrugs.value.length === 0) { + message.warning('请先添加药品后再保存为常用方'); + return; + } + // 清空输入框 + commonPrescriptionName.value = ''; + // 打开弹窗 + showSaveCommonPrescriptionModal.value = true; +}; + +/** + * 保存当前处方为常用方 + * @description 根据当前药品类型(中药/西药)调用不同的保存接口 + */ +const saveAsCommonPrescription = async () => { + // 验证名称 + if (!commonPrescriptionName.value.trim()) { + message.warning('请输入常用方名称'); + return; + } + + // 验证是否有药品 + if (currentDrugs.value.length === 0) { + message.warning('没有可保存的药品'); + return; + } + + isSavingCommonPrescription.value = true; + + try { + // 根据处方类型选择不同的保存接口 + if (activeCategory.value === 1) { + // 中药处方 - 构建药品详细信息数组 + const drugs = currentDrugs.value.map((drug) => ({ + drug_id: drug.id, + drug_name: drug.drug_name, + number: drug.number || 1, + price: drug.price || 0, + way_id: drug.way_id || 0, + })); + + await saveChineseCommonPrescriptionApi({ + name: commonPrescriptionName.value.trim(), + drugs, + store_id: myStoreId.value, + clinical_diagnose: diagnosis.value || '', + doctor_order: medicalAdvice.value || '', + category: String(category.value), + dosage: dosage.value, + day_dosage: dayDosage.value, + rule_type: ruleType.value, + package_method_id: ruleType.value === 1 ? packageMethodId.value : undefined, + process_rule_id: ruleType.value === 2 ? (processRuleId.value || undefined) : undefined, + child_process_rule_id: ruleType.value === 2 ? (childProcessRuleId.value || undefined) : undefined, + process_rule_note_id: ruleType.value === 2 ? (processRuleNoteId.value || undefined) : undefined, + }); + } else { + // 西药处方 - 构建药品详细信息数组 + const drugs = currentDrugs.value.map((drug) => ({ + drug_id: drug.id, + drug_name: drug.drug_name, + number: drug.number || 1, + price: drug.price || 0, + image: drug.image || '', + instruction: drug.instruction || '', + use_type_id: drug.use_type?.id || 0, + use_frequency_id: drug.use_frequency?.id || 0, + use_time_id: drug.use_num?.id || 0, + unit_id: drug.unit?.id || 0, + select_number: drug.select_number || 1, + })); + + await saveWestCommonPrescriptionApi({ + name: commonPrescriptionName.value.trim(), + drugs, + store_id: myStoreId.value, + clinical_diagnose: diagnosis.value || '', + doctor_order: medicalAdvice.value || '', + category: String(category.value), + }); + } + + message.success('常用方保存成功'); + showSaveCommonPrescriptionModal.value = false; + commonPrescriptionName.value = ''; + } catch (error) { + console.error('保存常用方失败:', error); + message.error('保存常用方失败,请稍后重试'); + } finally { + isSavingCommonPrescription.value = false; + } +}; + +/** + * 取消保存常用方 + */ +const cancelSaveCommonPrescription = () => { + showSaveCommonPrescriptionModal.value = false; + commonPrescriptionName.value = ''; +}; + const openWesternModal = () => { // 打开西药处方模态框逻辑 WesternDrugModalApi.setData({ @@ -863,28 +1009,19 @@ const processRuleId = ref(); const processRuleNoteId = ref(); const childProcessRuleId = ref(); -function getProcessRuleListByDoctor(pid = 0, ruleId = 0) { - let data = {}; - data = - ruleId === 0 - ? { - pid, - } - : { - rule_id: ruleId, - }; - getProcessRuleList(data).then((value) => { - if (ruleId !== 0) { - processRuleNoteList.value = value; - } else if (pid === 0) { - processRuleList.value = value; - } else { - childProcessRuleList.value = value; - } - }); +async function loadProcessRuleData(pid = 0, ruleId = 0) { + const data = ruleId === 0 ? { pid } : { rule_id: ruleId }; + const value = await getProcessRuleList(data); + if (ruleId !== 0) { + processRuleNoteList.value = value; + } else if (pid === 0) { + processRuleList.value = value; + } else { + childProcessRuleList.value = value; + } } -getProcessRuleListByDoctor(); +loadProcessRuleData(); /** * 选择煎法 @@ -1556,6 +1693,14 @@ watch( > 选择常用方 + 要把【{{ newDrugInfo.name }}】添加到清单吗? - +

有毒:

【{{ item }}】

十八反:
@@ -2168,7 +2313,34 @@ watch(
十九畏:

【{{ item }}】

如需继续开方需要二次签名,确认要二次签名吗?

- + + + + +
+

+ 将当前处方({{ currentDrugs.length }}种药品)保存为常用方模板 +

+
+ 常用方名称: + +
+

+ 类型:{{ activeCategory === 1 ? '中药' : '西药(中成药)' }} +

+
+
diff --git a/apps/web-antd/src/views/doctor/settings/api/index.ts b/apps/web-antd/src/views/doctor/settings/api/index.ts index b2523c45..411048e1 100644 --- a/apps/web-antd/src/views/doctor/settings/api/index.ts +++ b/apps/web-antd/src/views/doctor/settings/api/index.ts @@ -161,6 +161,16 @@ export async function saveChineseCommonPrescriptionApi(data: { dosage?: number; /** 每日次数(可选,默认2) */ day_dosage?: number; + /** 规则类型 1=自制剂,2=委托调剂(可选,默认1) */ + rule_type?: number; + /** 加工规则ID(制剂,可选) */ + process_rule_id?: number; + /** 子加工规则ID(煎法,可选) */ + child_process_rule_id?: number; + /** 加工规则备注ID(备注,可选) */ + process_rule_note_id?: number; + /** 包装方式ID(可选,默认2) */ + package_method_id?: number; }) { return requestClient.post( `${commonPrescriptionPrefix}save-chinese`, @@ -245,6 +255,16 @@ export interface UpdateChineseCommonPrescriptionParams extends UpdateCommonPresc dosage?: number; /** 每日次数(可选) */ day_dosage?: number; + /** 规则类型 1=自制剂,2=委托调剂(可选) */ + rule_type?: number; + /** 加工规则ID(制剂,可选) */ + process_rule_id?: number; + /** 子加工规则ID(煎法,可选) */ + child_process_rule_id?: number; + /** 加工规则备注ID(备注,可选) */ + process_rule_note_id?: number; + /** 包装方式ID(可选) */ + package_method_id?: number; } /** diff --git a/apps/web-antd/src/views/doctor/settings/components/AddCommonPrescriptionModal.vue b/apps/web-antd/src/views/doctor/settings/components/AddCommonPrescriptionModal.vue index a48a0876..e9487e97 100644 --- a/apps/web-antd/src/views/doctor/settings/components/AddCommonPrescriptionModal.vue +++ b/apps/web-antd/src/views/doctor/settings/components/AddCommonPrescriptionModal.vue @@ -51,6 +51,7 @@ import { import { getDrugUseList, getProductListDoctorReception, + getProcessRuleList, } from '#/views/doctor/doctor-reception/api'; // 引入诊断和医嘱选择弹窗组件 @@ -131,6 +132,38 @@ const dosage = ref(7); */ const dayDosage = ref(2); +/** + * 规则类型:1=自制剂,2=委托调剂 + */ +const ruleType = ref(1); + +/** + * 包装方式ID(自制剂时使用) + */ +const packageMethodId = ref(2); + +/** + * 加工规则ID(委托调剂时使用) + */ +const processRuleId = ref(null); + +/** + * 子加工规则ID(委托调剂时使用) + */ +const childProcessRuleId = ref(null); + +/** + * 加工规则备注ID(委托调剂时使用) + */ +const processRuleNoteId = ref(null); + +/** + * 委托调剂选项列表 + */ +const processRuleList = ref([]); +const childProcessRuleList = ref([]); +const processRuleNoteList = ref([]); + /** * 保存成功后的回调函数 */ @@ -206,11 +239,18 @@ const [Modal, modalApi] = useVbenModal({ drugList.value = []; dosage.value = 7; dayDosage.value = 2; + ruleType.value = 1; + packageMethodId.value = 2; + processRuleId.value = null; + childProcessRuleId.value = null; + processRuleNoteId.value = null; onSaveCallback = data?.onSave || null; // 加载药品使用方式数据 loadDrugUseData(); + // 加载委托调剂选项(第一级:制剂) + loadProcessRuleData(0, 0); } }, }); @@ -236,6 +276,49 @@ async function loadDrugUseData() { } } +/** + * 加载委托调剂选项数据 + */ +async function loadProcessRuleData(pid = 0, ruleId = 0) { + try { + const data = ruleId === 0 ? { pid } : { rule_id: ruleId }; + const res = await getProcessRuleList(data); + if (ruleId !== 0) { + processRuleNoteList.value = res; + } else if (pid === 0) { + processRuleList.value = res; + } else { + childProcessRuleList.value = res; + } + } catch (error) { + console.error('加载委托调剂选项失败:', error); + } +} + +/** + * 制剂选择变化 + */ +function handleProcessRuleChange(id: number) { + childProcessRuleId.value = null; + processRuleNoteId.value = null; + childProcessRuleList.value = []; + processRuleNoteList.value = []; + if (id) { + loadProcessRuleData(id, 0); + } +} + +/** + * 煎法选择变化 + */ +function handleChildProcessRuleChange(id: number) { + processRuleNoteId.value = null; + processRuleNoteList.value = []; + if (id) { + loadProcessRuleData(0, id); + } +} + /** * 切换常用方类型 */ @@ -597,6 +680,11 @@ async function handleSave() { category: '1', dosage: dosage.value, day_dosage: dayDosage.value, + rule_type: ruleType.value, + package_method_id: ruleType.value === 1 ? packageMethodId.value : undefined, + process_rule_id: ruleType.value === 2 ? (processRuleId.value || undefined) : undefined, + child_process_rule_id: ruleType.value === 2 ? (childProcessRuleId.value || undefined) : undefined, + process_rule_note_id: ruleType.value === 2 ? (processRuleNoteId.value || undefined) : undefined, }); break; } @@ -726,6 +814,87 @@ async function handleSave() { + + + + + + 自制剂 + 委托调剂 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (null); + +/** + * 子加工规则ID(委托调剂时使用) + */ +const childProcessRuleId = ref(null); + +/** + * 加工规则备注ID(委托调剂时使用) + */ +const processRuleNoteId = ref(null); + +/** + * 委托调剂选项列表 + */ +const processRuleList = ref([]); +const childProcessRuleList = ref([]); +const processRuleNoteList = ref([]); + /** * 保存成功后的回调函数 */ @@ -205,7 +238,7 @@ const [Modal, modalApi] = useVbenModal({ async onConfirm() { await handleSave(); }, - onOpenChange(isOpen: boolean) { + async onOpenChange(isOpen: boolean) { if (isOpen) { // 获取传入的参数 const data = modalApi.getData<{ @@ -231,10 +264,31 @@ const [Modal, modalApi] = useVbenModal({ _key: Date.now() + index, // 添加唯一标识 })); + // 初始化规则类型相关数据(中药) + if (data.type === 'chinese') { + dosage.value = data.prescription.dosage || 7; + dayDosage.value = data.prescription.day_dosage || 2; + ruleType.value = data.prescription.rule_type || 1; + packageMethodId.value = data.prescription.package_method_id || 2; + processRuleId.value = data.prescription.process_rule_id || null; + childProcessRuleId.value = data.prescription.child_process_rule_id || null; + processRuleNoteId.value = data.prescription.process_rule_note_id || null; + } + onSaveCallback = data.onSave || null; // 加载药品使用方式数据 loadDrugUseData(); + // 加载委托调剂选项(第一级:制剂) + await loadProcessRuleData(0, 0); + + // 如果有已保存的委托调剂配置,需要级联加载(顺序执行) + if (processRuleId.value) { + await loadProcessRuleData(processRuleId.value, 0); + } + if (childProcessRuleId.value) { + await loadProcessRuleData(0, childProcessRuleId.value); + } } } }, @@ -261,6 +315,49 @@ async function loadDrugUseData() { } } +/** + * 加载委托调剂选项数据 + */ +async function loadProcessRuleData(pid = 0, ruleId = 0) { + try { + const data = ruleId === 0 ? { pid } : { rule_id: ruleId }; + const res = await getProcessRuleList(data); + if (ruleId !== 0) { + processRuleNoteList.value = res; + } else if (pid === 0) { + processRuleList.value = res; + } else { + childProcessRuleList.value = res; + } + } catch (error) { + console.error('加载委托调剂选项失败:', error); + } +} + +/** + * 制剂选择变化 + */ +function handleProcessRuleChange(id: number) { + childProcessRuleId.value = null; + processRuleNoteId.value = null; + childProcessRuleList.value = []; + processRuleNoteList.value = []; + if (id) { + loadProcessRuleData(id, 0); + } +} + +/** + * 煎法选择变化 + */ +function handleChildProcessRuleChange(id: number) { + processRuleNoteId.value = null; + processRuleNoteList.value = []; + if (id) { + loadProcessRuleData(0, id); + } +} + /** * 打开诊断选择弹窗 */ @@ -610,6 +707,11 @@ async function handleSave() { drugs, dosage: dosage.value, day_dosage: dayDosage.value, + rule_type: ruleType.value, + package_method_id: ruleType.value === 1 ? packageMethodId.value : undefined, + process_rule_id: ruleType.value === 2 ? (processRuleId.value || undefined) : undefined, + child_process_rule_id: ruleType.value === 2 ? (childProcessRuleId.value || undefined) : undefined, + process_rule_note_id: ruleType.value === 2 ? (processRuleNoteId.value || undefined) : undefined, }); break; } @@ -730,6 +832,87 @@ async function handleSave() { + + + + + + 自制剂 + 委托调剂 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {

医嘱:{{ item.doctor_order }}

+

+ 调配方式: + {{ item.rule_type === 1 ? '自制剂' : '委托调剂' }} + 剂量:{{ item.dosage || 7 }}天/剂 + 频次:{{ item.day_dosage || 2 }}次/天 +

+

+ 委托调剂配置: + 制剂:{{ item.process_rule_name }} + 煎法:{{ item.child_process_rule_name }} + 备注:{{ item.process_rule_note_name }} +

药品: - {{ getDrugNames(commonPrescriptionData.chinese[index], 'name') }} + {{ getDrugNames(commonPrescriptionData.chinese[index], 'drug_name') }}