index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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="form.visitType" 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="id" v-if="true" />
  42. <el-table-column label="时间" align="center" prop="createTime" />
  43. <el-table-column label="诊断依据" align="center" prop="diagnosisBasis" />
  44. <el-table-column label="看诊类型" align="center" prop="diagnosisType" />
  45. <el-table-column label="门诊/住院号" align="center" prop="outpatientNumber" />
  46. <el-table-column label="营养诊断" align="center" prop="nutritionalDiagnosis" />
  47. <el-table-column label="诊断医生" align="center" prop="diagnosisDoctor" />
  48. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  49. <template #default="scope">
  50. <el-tooltip content="修改" placement="top">
  51. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
  52. </el-tooltip>
  53. <el-tooltip content="删除" placement="top">
  54. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
  55. </el-tooltip>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  60. </el-card>
  61. </div>
  62. <div v-show="type === 'addForm'">
  63. <el-form ref="diagnosisFormRef" :model="form" :rules="rules" label-width="120px">
  64. <el-form-item label="营养诊断:" prop="diagnosisLableId">
  65. <el-select v-model="labelList" multiple placeholder="请选择" style="width: 100%;" :disabled="true" @click="labelDialogVisible = true" class="custom-label-select" value-key="labelId">
  66. <el-option v-for="item in labelList" :key="item.labelId" :label="item.labelName" :value="item">
  67. <el-tag type="info" size="small">{{ item.labelName }}</el-tag>
  68. </el-option>
  69. </el-select>
  70. </el-form-item>
  71. <el-form-item label="营养诊断依据:" prop="diagnosisBasisId">
  72. <el-input v-model="form.diagnosisBasisId" placeholder="请输入营养筛查/评估结果" clearable />
  73. </el-form-item>
  74. <el-form-item label="营养会诊结论:">
  75. <div class="consultation-toolbar">
  76. <el-button type="danger" plain @click="clearContent">清空记录</el-button>
  77. <el-button @click="showTemplateDialog = true">导入模板</el-button>
  78. </div>
  79. </el-form-item>
  80. <el-form-item>
  81. <Editor v-model="form.consultationContent" placeholder="请输入内容..." style="min-height: 200px; width: 100%;" />
  82. </el-form-item>
  83. <el-form-item label="营养医嘱:" prop="medicalOrder">
  84. <el-input v-model="form.medicalOrder" placeholder="请输入" clearable />
  85. </el-form-item>
  86. </el-form>
  87. <LabelDialog v-model="labelDialogVisible" :initial-selected-labels="labelList || []" @confirm="onLabelConfirm" />
  88. <ConsultantTemplateDialog v-model:visible="showTemplateDialog" @select="onTemplateSelect" />
  89. <div class="dialog-footer" style="text-align: center; margin-top: 100px">
  90. <el-button @click="handleCancel">取 消</el-button>
  91. <el-button :loading="buttonLoading" type="primary" @click="submitForm">提 交</el-button>
  92. </div>
  93. </div>
  94. </div>
  95. </template>
  96. <script setup name="Diagnosis" lang="ts">
  97. import { listDiagnosis, getDiagnosis, delDiagnosis, addDiagnosis, updateDiagnosis } from '@/api/patients/diagnosis';
  98. import { DiagnosisVO, DiagnosisQuery, DiagnosisForm } from '@/api/patients/diagnosis/types';
  99. import { getTreatmentUser as fetchTreatmentUser } from '@/api/workbench/treatmentUser';
  100. import LabelDialog from '@/views/warehouse/nutriProduct/labelDialog.vue';
  101. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  102. const ConsultantTemplateDialog = defineAsyncComponent(() => import('./consultantTemplateDialog.vue'));
  103. const { treatment_user_type } = toRefs < any > (proxy ?.useDict('treatment_user_type'));
  104. const diagnosisList = ref < DiagnosisVO[] > ([]);
  105. const buttonLoading = ref(false);
  106. const loading = ref(true);
  107. const showSearch = ref(true);
  108. const ids = ref < Array < string | number >> ([]);
  109. const single = ref(true);
  110. const multiple = ref(true);
  111. const total = ref(0);
  112. const type = ref('list');
  113. const labelList = ref([]);
  114. const detailData = ref({});
  115. const labelDialogVisible = ref(false);
  116. const queryFormRef = ref < ElFormInstance > ();
  117. const diagnosisFormRef = ref < ElFormInstance > ();
  118. const showTemplateDialog = ref(false);
  119. const dialog = reactive < DialogOption > ({
  120. visible: false,
  121. title: ''
  122. });
  123. // 声明接收的 props
  124. const props = defineProps({
  125. patientInfo: {
  126. type: Object,
  127. required: true,
  128. default: () => ({
  129. id: '',
  130. name: '',
  131. age: '',
  132. gender: ''
  133. })
  134. }
  135. });
  136. const initFormData: DiagnosisForm = {
  137. id: undefined,
  138. treatmentUserId: props.patientInfo ?.id, // Initialize with patient ID
  139. consultantTemplateId: undefined,
  140. diagnosisLableId: undefined,
  141. diagnosisBasisId: undefined,
  142. medicalOrder: undefined,
  143. consultationContent: undefined,
  144. }
  145. const data = reactive < PageData < DiagnosisForm,
  146. DiagnosisQuery >> ({
  147. form: { ...initFormData },
  148. queryParams: {
  149. pageNum: 1,
  150. pageSize: 10,
  151. visitType: undefined,
  152. dateRange: undefined,
  153. searchValue: undefined,
  154. params: {}
  155. },
  156. rules: {
  157. diagnosisLableId: [
  158. { required: false, message: "营养诊断不能为空", trigger: ['blur', 'change'] }
  159. ],
  160. medicalOrder: [
  161. { required: true, message: "医嘱不能为空", trigger: "blur" }
  162. ],
  163. }
  164. });
  165. const { queryParams, form, rules } = toRefs(data);
  166. /** 查询营养诊断列表 */
  167. const getList = async () => {
  168. loading.value = true;
  169. const res = await listDiagnosis(queryParams.value);
  170. diagnosisList.value = res.rows;
  171. console.log("diagnosisList", JSON.stringify(diagnosisList.value));
  172. total.value = res.total;
  173. loading.value = false;
  174. }
  175. // 详情按钮处理
  176. const getTreatmentUser = async () => {
  177. try {
  178. // 获取患者详细信息
  179. const res = await fetchTreatmentUser(props.patientInfo ?.id);
  180. detailData.value = res.data;
  181. } catch (error) {
  182. }
  183. };
  184. /** 取消按钮 */
  185. const cancel = () => {
  186. reset();
  187. dialog.visible = false;
  188. }
  189. // 标签确认回调
  190. function onLabelConfirm(selectedLabels: Array < { labelId: string | number;labelName: string } > ) {
  191. labelList.value = selectedLabels;
  192. }
  193. const onTemplateSelect = async (templateContent) => {
  194. if (!templateContent) return;
  195. try {
  196. // 获取患者详细信息
  197. const res = await fetchTreatmentUser(props.patientInfo ?.id);
  198. const patientDetail = res.data || {};
  199. console.log('Template content:', templateContent);
  200. console.log('Patient details:', patientDetail);
  201. // 替换模板中的占位符
  202. let processedContent = templateContent;
  203. // 定义替换规则(根据实际字段进行调整)
  204. const replacements = {
  205. 'height': patientDetail.height || '',
  206. 'weight': patientDetail.weight || '',
  207. 'bmi': patientDetail.bmi || '',
  208. 'alb': patientDetail.alb || '',
  209. 'hgb': patientDetail.hgb || '',
  210. 'nrs2002Score': patientDetail.nrs2002Score || '',
  211. 'nrs2002Conclusion': patientDetail.nrs2002Conclusion || '',
  212. 'beforeAlb': patientDetail.beforeAlb || '',
  213. 'way': patientDetail.way || '',
  214. 'glimResult': patientDetail.glimResult || '',
  215. 'purpose': patientDetail.purpose || '',
  216. 'lossWeight': patientDetail.lossWeight || '',
  217. 'totalCalories': patientDetail.totalCalories || '',
  218. 'totalProtein': patientDetail.totalProtein || '',
  219. 'lossWeightRate': patientDetail.lossWeightRate || '',
  220. 'totalFood24retrospectProtein': patientDetail.totalFood24retrospectProtein || '',
  221. 'totalFood24retrospectCalories': patientDetail.totalFood24retrospectCalories || '',
  222. // 可以根据需要添加更多替换规则
  223. };
  224. console.log('Replacements:', replacements);
  225. // 执行替换
  226. for (const [key, value] of Object.entries(replacements)) {
  227. const placeholder = '${' + key + '}';
  228. console.log(`Replacing ${placeholder} with ${value}`);
  229. processedContent = processedContent.split(placeholder).join(value);
  230. }
  231. console.log('Processed content:', processedContent);
  232. // 将处理后的内容赋值给表单
  233. form.value.consultationContent = processedContent;
  234. } catch (error) {
  235. console.error('获取患者详情失败:', error);
  236. proxy ?.$modal.msgError('获取患者详情失败');
  237. // 如果获取详情失败,仍然使用原始模板
  238. form.value.consultationContent = templateContent;
  239. }
  240. };
  241. /** 表单重置 */
  242. const reset = () => {
  243. form.value = { ...initFormData };
  244. diagnosisFormRef.value ?.resetFields();
  245. }
  246. /** 搜索按钮操作 */
  247. const handleQuery = () => {
  248. queryParams.value.pageNum = 1;
  249. getList();
  250. }
  251. /** 重置按钮操作 */
  252. const resetQuery = () => {
  253. queryFormRef.value ?.resetFields();
  254. handleQuery();
  255. }
  256. /** 多选框选中数据 */
  257. const handleSelectionChange = (selection: DiagnosisVO[]) => {
  258. ids.value = selection.map(item => item.id);
  259. single.value = selection.length != 1;
  260. multiple.value = !selection.length;
  261. }
  262. /** 新增按钮操作 */
  263. const handleAdd = () => {
  264. reset();
  265. type.value = 'addForm';
  266. form.value.treatmentUserId = props.patientInfo ?.id;
  267. }
  268. const handleCancel = () => {
  269. type.value = 'list';
  270. };
  271. const clearContent = () => {
  272. form.value.consultationContent = '';
  273. }
  274. /** 修改按钮操作 */
  275. const handleUpdate = async (row ? : DiagnosisVO) => {
  276. reset();
  277. const _id = row ?.id || ids.value[0]
  278. const res = await getDiagnosis(_id);
  279. Object.assign(form.value, res.data);
  280. dialog.visible = true;
  281. dialog.title = "修改营养诊断";
  282. }
  283. /** 提交按钮 */
  284. const submitForm = () => {
  285. diagnosisFormRef.value ?.validate(async (valid: boolean) => {
  286. if (valid) {
  287. buttonLoading.value = true;
  288. if (form.value.id) {
  289. await updateDiagnosis(form.value).finally(() => buttonLoading.value = false);
  290. } else {
  291. await addDiagnosis(form.value).finally(() => buttonLoading.value = false);
  292. }
  293. proxy ?.$modal.msgSuccess("操作成功");
  294. dialog.visible = false;
  295. await getList();
  296. type.value = 'list';
  297. }
  298. });
  299. }
  300. /** 删除按钮操作 */
  301. const handleDelete = async (row ? : DiagnosisVO) => {
  302. const _ids = row ?.id || ids.value;
  303. await proxy ?.$modal.confirm('是否确认删除营养诊断编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
  304. await delDiagnosis(_ids);
  305. proxy ?.$modal.msgSuccess("删除成功");
  306. await getList();
  307. }
  308. onMounted(() => {
  309. getList();
  310. });
  311. </script>