index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div class="p-2">
  3. <div v-show="type === 'list'">
  4. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  5. <div v-show="showSearch" class="mb-[10px]">
  6. <el-card shadow="hover">
  7. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  8. <el-form-item>
  9. <el-date-picker v-model="queryParams.dateRange" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
  10. </el-form-item>
  11. <el-form-item label="看诊类型">
  12. <el-select v-model="queryParams.type" class="spec-unit-select">
  13. <el-option v-for="dict in treatment_user_type" :key="dict.value" :label="dict.label" :value="dict.value" />
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item>
  17. <el-input v-model="queryParams.searchValue" placeholder="医生姓名/门诊号/住院号" style="width: 240px; " clearable />
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  21. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </el-card>
  25. </div>
  26. </transition>
  27. <el-card shadow="never">
  28. <template #header>
  29. <el-row :gutter="10" class="mb8">
  30. <el-col :span="1.5">
  31. <el-button type="primary" @click="handleAdd">新增营养诊断</el-button>
  32. </el-col>
  33. <el-col :span="1.5">
  34. <el-button disabled>打印已选病历</el-button>
  35. </el-col>
  36. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  37. </el-row>
  38. </template>
  39. <el-table v-loading="loading" border :data="diagnosisList" @selection-change="handleSelectionChange">
  40. <el-table-column type="selection" width="55" align="center" />
  41. <el-table-column label="时间" align="center" prop="createTime" />
  42. <el-table-column label="诊断依据" align="center" prop="diagnosisBasis">
  43. <template #default="scope">
  44. <span>{{getDictLabel(treatment_user_type ,scope.row.diagnosisBasis )|| '--' }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="看诊类型" align="center" prop="type">
  48. <template #default="scope">
  49. <span>{{getDictLabel(treatment_user_type ,scope.row.type )|| '--' }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="门诊/住院号" align="center" prop="outpatientNo" />
  53. <el-table-column label="营养诊断" align="center" prop="diagnosisLabelStr" width="350"/>
  54. <el-table-column label="诊断医生" align="center" prop="createByUser" />
  55. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  56. <template #default="scope">
  57. <el-tooltip content="详情" placement="top">
  58. <el-button link type="primary" icon="Edit" @click="handleDetail(scope.row)">详情</el-button>
  59. </el-tooltip>
  60. <el-tooltip content="删除" placement="top">
  61. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
  62. </el-tooltip>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  67. </el-card>
  68. </div>
  69. <div v-show="type === 'addForm'">
  70. <el-form ref="diagnosisFormRef" :model="form" :rules="rules" label-width="120px">
  71. <el-form-item label="营养诊断:" prop="diagnosisLableId">
  72. <el-select v-model="form.labelList" multiple placeholder="请选择" style="width: 100%;" :disabled="true" @click="labelDialogVisible = true" class="custom-label-select">
  73. <el-option v-for="item in labelOptions" :key="item.labelId" :label="item.labelName" :value="item.labelId">
  74. <el-tag type="info" size="small">{{ item.labelName }}</el-tag>
  75. </el-option>
  76. </el-select>
  77. </el-form-item>
  78. <el-form-item label="营养诊断依据:" prop="diagnosisBasisId">
  79. <el-input v-model="form.diagnosisBasisId" placeholder="请输入营养筛查/评估结果" clearable />
  80. </el-form-item>
  81. <el-form-item label="营养会诊结论:">
  82. <div class="consultation-toolbar">
  83. <el-button type="danger" plain @click="clearContent">清空记录</el-button>
  84. <el-button @click="showTemplateDialog = true">导入模板</el-button>
  85. </div>
  86. </el-form-item>
  87. <el-form-item>
  88. <Editor v-model="form.consultantResult" placeholder="请输入内容..." style="min-height: 200px; width: 100%;" />
  89. </el-form-item>
  90. <el-form-item label="营养医嘱:" prop="medicalOrder">
  91. <el-input v-model="form.medicalOrder" placeholder="请输入" clearable />
  92. </el-form-item>
  93. </el-form>
  94. <LabelDialog v-model="labelDialogVisible" :initial-selected-labels="labelOptions || []" @confirm="onLabelConfirm" />
  95. <ConsultantTemplateDialog v-model:visible="showTemplateDialog" @select="onTemplateSelect" />
  96. <div class="dialog-footer" style="text-align: center; margin-top: 100px">
  97. <el-button @click="handleCancel">取 消</el-button>
  98. <el-button :loading="buttonLoading" type="primary" @click="submitForm">提 交</el-button>
  99. </div>
  100. </div>
  101. <!-- 详情弹窗始终挂载在最外层div内 -->
  102. <detail-dialog v-model="showDetailDialog" :detail="currentDetail" />
  103. </div>
  104. </template>
  105. <script setup name="Diagnosis" lang="ts">
  106. import { listDiagnosis, getDiagnosis, delDiagnosis, addDiagnosis, updateDiagnosis } from '@/api/patients/diagnosis';
  107. import { DiagnosisVO, DiagnosisQuery, DiagnosisForm } from '@/api/patients/diagnosis/types';
  108. import { getTreatmentUser as fetchTreatmentUser } from '@/api/workbench/treatmentUser';
  109. import LabelDialog from '@/views/warehouse/nutriProduct/labelDialog.vue';
  110. import { getDiseaseLabel } from '@/api/system/diseaseLabel'; // 新增: 导入获取标签详情API
  111. import { log } from 'console';
  112. import DetailDialog from './detailDialog.vue';
  113. import { watch } from 'vue';
  114. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  115. const ConsultantTemplateDialog = defineAsyncComponent(() => import('./consultantTemplateDialog.vue'));
  116. const { treatment_user_type } = toRefs < any > (proxy ?.useDict('treatment_user_type'));
  117. const diagnosisList = ref < DiagnosisVO[] > ([]);
  118. const buttonLoading = ref(false);
  119. const loading = ref(true);
  120. const showSearch = ref(true);
  121. const ids = ref < Array < string | number >> ([]);
  122. const single = ref(true);
  123. const multiple = ref(true);
  124. const total = ref(0);
  125. const type = ref('list');
  126. const labelDialogVisible = ref(false);
  127. const labelOptions = ref < any[] > ([]); // 新增: 用于存储可选标签对象
  128. const showDetailDialog = ref(false);
  129. const currentDetail = ref({});
  130. const queryFormRef = ref < ElFormInstance > ();
  131. const diagnosisFormRef = ref < ElFormInstance > ();
  132. const showTemplateDialog = ref(false);
  133. const dialog = reactive < DialogOption > ({
  134. visible: false,
  135. title: ''
  136. });
  137. // 声明接收的 props
  138. const props = defineProps({
  139. patientInfo: {
  140. type: Object,
  141. required: true,
  142. default: () => ({
  143. id: '',
  144. name: '',
  145. age: '',
  146. gender: ''
  147. })
  148. }
  149. });
  150. const initFormData: DiagnosisForm = {
  151. id: undefined,
  152. labelList: [],
  153. treatmentUserId: props.patientInfo ?.id,
  154. consultantTemplateId: undefined,
  155. diagnosisLableId: undefined,
  156. diagnosisBasisId: undefined,
  157. medicalOrder: undefined,
  158. consultantResult: undefined,
  159. consultantResultStr: undefined,
  160. }
  161. const data = reactive < PageData < DiagnosisForm,
  162. DiagnosisQuery >> ({
  163. form: { ...initFormData },
  164. queryParams: {
  165. pageNum: 1,
  166. pageSize: 10,
  167. visitType: undefined,
  168. treatmentUserId: props.patientInfo ?.id,
  169. dateRange: undefined,
  170. searchValue: undefined,
  171. params: {}
  172. },
  173. rules: {
  174. diagnosisLableId: [
  175. { required: false, message: "营养诊断不能为空", trigger: ['blur', 'change'] }
  176. ],
  177. medicalOrder: [
  178. { required: true, message: "医嘱不能为空", trigger: "blur" }
  179. ],
  180. }
  181. });
  182. const { queryParams, form, rules } = toRefs(data);
  183. // 监听患者ID变化,自动同步到表单和查询参数
  184. watch(
  185. () => props.patientInfo.id,
  186. (newId) => {
  187. form.value.treatmentUserId = newId;
  188. queryParams.value.treatmentUserId = newId;
  189. },
  190. { immediate: true }
  191. );
  192. /** 查询营养诊断列表 */
  193. const getList = async () => {
  194. loading.value = true;
  195. const res = await listDiagnosis(queryParams.value);
  196. diagnosisList.value = res.rows;
  197. total.value = res.total;
  198. loading.value = false;
  199. }
  200. /** 取消按钮 */
  201. const cancel = () => {
  202. reset();
  203. dialog.visible = false;
  204. }
  205. // 标签确认回调
  206. function onLabelConfirm(selectedLabels: Array < { labelId: string | number;labelName: string } > ) {
  207. form.value.labelList = selectedLabels.map(l => l.labelId); // 只存labelId
  208. labelOptions.value = selectedLabels; // 用于el-option展示labelName
  209. }
  210. const onTemplateSelect = async (data) => {
  211. form.value.consultantTemplateId = data.id;
  212. let templateContent = data.template;
  213. console.log(JSON.stringify(data));
  214. if (!templateContent) return;
  215. try {
  216. // 获取患者详细信息
  217. const res = await fetchTreatmentUser(props.patientInfo ?.id);
  218. const patientDetail = res.data || {};
  219. form.value.consultantTemplateId = data.id;
  220. // 替换模板中的占位符
  221. let processedContent = templateContent;
  222. // 定义替换规则(根据实际字段进行调整)
  223. const replacements = {
  224. 'purpose': patientDetail.type == 1 ? '住院' : '门诊' || '',
  225. 'height': patientDetail.height || '',
  226. 'weight': patientDetail.weight || '',
  227. 'bmi': patientDetail.bmi || '',
  228. 'alb': patientDetail.alb || '',
  229. 'hgb': patientDetail.hgb || '',
  230. 'nrs2002Score': patientDetail.nrs2002Score || '',
  231. 'nrs2002Conclusion': patientDetail.nrs2002Conclusion || '',
  232. 'beforeAlb': patientDetail.beforeAlb || '',
  233. 'way': patientDetail.way || '',
  234. 'glimResult': patientDetail.glimResult || '',
  235. 'lossWeight': patientDetail.lossWeight || '',
  236. 'totalCalories': patientDetail.totalCalories || '',
  237. 'totalProtein': patientDetail.totalProtein || '',
  238. 'lossWeightRate': patientDetail.lossWeightRate || '',
  239. 'totalFood24retrospectProtein': patientDetail.totalFood24retrospectProtein || '',
  240. 'totalFood24retrospectCalories': patientDetail.totalFood24retrospectCalories || '',
  241. // 可以根据需要添加更多替换规则
  242. };
  243. // 执行替换
  244. for (const [key, value] of Object.entries(replacements)) {
  245. const placeholder = '${' + key + '}';
  246. console.log(`Replacing ${placeholder} with ${value}`);
  247. processedContent = processedContent.split(placeholder).join(value);
  248. }
  249. // 将处理后的内容赋值给表单
  250. form.value.consultantResult = processedContent;
  251. } catch (error) {
  252. console.error('获取患者详情失败:', error);
  253. proxy ?.$modal.msgError('获取患者详情失败');
  254. // 如果获取详情失败,仍然使用原始模板
  255. form.value.consultantResult = templateContent;
  256. }
  257. };
  258. /** 表单重置 */
  259. const reset = () => {
  260. form.value = {
  261. ...initFormData,
  262. treatmentUserId: props.patientInfo ?.id // 用最新id
  263. };
  264. diagnosisFormRef.value ?.resetFields();
  265. }
  266. /** 搜索按钮操作 */
  267. const handleQuery = () => {
  268. queryParams.value.pageNum = 1;
  269. getList();
  270. }
  271. /** 重置按钮操作 */
  272. const resetQuery = () => {
  273. queryFormRef.value ?.resetFields();
  274. queryParams.value.dateRange = undefined;
  275. queryParams.value.type = undefined;
  276. queryParams.value.searchValue = undefined;
  277. queryParams.value.pageNum = 1;
  278. queryParams.value.pageSize = 10;
  279. handleQuery();
  280. }
  281. // 字典label工具
  282. function getDictLabel(dictList: any[], value: string) {
  283. if (!dictList || !Array.isArray(dictList)) return value || '--';
  284. const found = dictList.find(item => item.value === value);
  285. return found ? found.label : value || '--';
  286. }
  287. /** 多选框选中数据 */
  288. const handleSelectionChange = (selection: DiagnosisVO[]) => {
  289. ids.value = selection.map(item => item.id);
  290. single.value = selection.length != 1;
  291. multiple.value = !selection.length;
  292. }
  293. /** 新增按钮操作 */
  294. const handleAdd = () => {
  295. reset();
  296. type.value = 'addForm';
  297. form.value.treatmentUserId = props.patientInfo ?.id;
  298. }
  299. const handleCancel = () => {
  300. type.value = 'list';
  301. };
  302. const clearContent = () => {
  303. form.value.consultantResult = '';
  304. }
  305. /** 修改按钮操作 */
  306. const handleUpdate = async (row ? : DiagnosisVO) => {
  307. reset();
  308. const _id = row ?.id || ids.value[0]
  309. const res = await getDiagnosis(_id);
  310. Object.assign(form.value, res.data);
  311. // 适配labelList为labelId数组时,需获取完整标签对象
  312. if (Array.isArray(form.value.labelList) && form.value.labelList.length > 0 && typeof form.value.labelList[0] !== 'object') {
  313. // 批量获取标签详情
  314. const labelIds = form.value.labelList;
  315. const labelDetailPromises = labelIds.map(id => getDiseaseLabel(id).then(r => r.data));
  316. labelOptions.value = await Promise.all(labelDetailPromises);
  317. } else {
  318. labelOptions.value = form.value.labelList || [];
  319. }
  320. dialog.visible = true;
  321. dialog.title = "修改营养诊断";
  322. }
  323. /** 提交按钮 */
  324. const submitForm = () => {
  325. diagnosisFormRef.value ?.validate(async (valid: boolean) => {
  326. if (valid) {
  327. buttonLoading.value = true;
  328. if (form.value.id) {
  329. form.value.consultantResultStr = window.btoa(encodeURIComponent(form.value.consultantResult))
  330. await updateDiagnosis(form.value).finally(() => buttonLoading.value = false);
  331. } else {
  332. console.log('addForm', JSON.stringify(form.value));
  333. form.value.consultantResultStr = window.btoa(encodeURIComponent(form.value.consultantResult))
  334. await addDiagnosis(form.value).finally(() => buttonLoading.value = false);
  335. }
  336. proxy ?.$modal.msgSuccess("操作成功");
  337. dialog.visible = false;
  338. await getList();
  339. type.value = 'list';
  340. }
  341. });
  342. }
  343. /** 删除按钮操作 */
  344. const handleDelete = async (row ? : DiagnosisVO) => {
  345. const _ids = row ?.id || ids.value;
  346. await proxy ?.$modal.confirm('是否确认删除营养诊断编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
  347. await delDiagnosis(_ids);
  348. proxy ?.$modal.msgSuccess("删除成功");
  349. await getList();
  350. }
  351. const handleDetail = (row: any) => {
  352. currentDetail.value = row;
  353. currentDetail.value.consultantResult= stripHtml(currentDetail.value.consultantResult);
  354. showDetailDialog.value = true;
  355. };
  356. function stripHtml(html) {
  357. const div = document.createElement('div');
  358. div.innerHTML = html;
  359. return div.textContent || div.innerText || '';
  360. }
  361. onMounted(() => {
  362. getList();
  363. });
  364. </script>