EmrSidebar.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div style="width: 215px">
  3. <el-input v-model="filterText" placeholder="节点过滤"
  4. style="width: 100%"
  5. @input="filterChange" clearable/>
  6. <el-radio-group v-model="templateType" @change="typeChange">
  7. <el-radio-button :disabled="!editor" :label="0">全院模板</el-radio-button>
  8. <el-radio-button :disabled="!editor" :label="1">科室模板</el-radio-button>
  9. <el-radio-button :label="2">患者数据</el-radio-button>
  10. </el-radio-group>
  11. <div :style="{maxHeight : maxHeight - 100 + 'px'}"
  12. style="overflow: auto; "
  13. class="down-tree">
  14. <el-tree :data="treeData"
  15. :props="defaultProps"
  16. @node-click="handleNodeClick"
  17. node-key="_id"
  18. ref="treeRef"
  19. highlight-current
  20. :filter-node-method="filterNode"
  21. default-expand-all>
  22. <template #default="{ node, data }">
  23. <el-icon v-if="data.submit">
  24. <Lock/>
  25. </el-icon>
  26. <el-icon v-else>
  27. <Folder v-if="data.children"/>
  28. <Document v-else/>
  29. </el-icon>
  30. <span :title="fileName(data)">
  31. {{ fileName(data) }}
  32. </span>
  33. </template>
  34. </el-tree>
  35. </div>
  36. </div>
  37. </template>
  38. <script setup name='EmrSidebar'>
  39. import {
  40. getEmrTree,
  41. getPatientDataTree,
  42. queryWhetherThePatientHasASpecifiedMedicalRecord
  43. } from "@/api/zhu-yuan-yi-sheng/emr-patient";
  44. import {BizException, ExceptionEnum} from "@/utils/BizException";
  45. import {emrConfig} from '@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-init'
  46. import {getWardsApi} from "@/api/login";
  47. import {stringIsBlank} from "@/utils/blank-utils";
  48. const props = defineProps({
  49. maxHeight: {
  50. type: Number
  51. },
  52. huanZheXinXi: {
  53. type: Object
  54. }
  55. })
  56. let editor = emrConfig.value.editor
  57. const emit = defineEmits(['nodeClick', 'typeChange', 'patientMedicalRecord'])
  58. let returnData = $ref({
  59. emrTree: [],
  60. patientTree: []
  61. })
  62. let filterText = $ref('')
  63. let treeRef = $ref('')
  64. let key = ''
  65. let wardList = []
  66. const defaultProps = {
  67. children: 'children',
  68. label: 'name',
  69. }
  70. let templateType = $ref(0)
  71. const treeData = computed(() => {
  72. switch (templateType) {
  73. case 0 :
  74. return returnData.emrTree;
  75. case 1:
  76. return [];
  77. case 2:
  78. return returnData.patientTree;
  79. }
  80. })
  81. const handleNodeClick = async (val, property, event) => {
  82. let temp = {}
  83. if (templateType === 0) {
  84. temp = {
  85. documentId: null,
  86. categoryCode: val.code,
  87. categoryId: val._id,
  88. patientId: null,
  89. name: val.name,
  90. createId: null
  91. }
  92. if (!wardList.includes(props.huanZheXinXi.ward)) {
  93. BizException(ExceptionEnum.LOGICAL_ERROR, "无法创建病历,患者不属于您的科室")
  94. }
  95. } else if (templateType === 2) {
  96. temp = {
  97. documentId: val.emrDocumentId,
  98. categoryCode: val.emrCategoryCode,
  99. categoryId: null,
  100. patientId: null,
  101. name: val.name ? val.name : val.emrName,
  102. createId: val.createId
  103. }
  104. }
  105. let str = JSON.stringify(val)
  106. if (val.children) {
  107. return
  108. }
  109. if (val.labels) {
  110. // 根据 这个编码来限制是不是唯一一个
  111. if (val.labels.includes('唯一') && templateType !== 2) {
  112. let flag = await queryWhetherThePatientHasASpecifiedMedicalRecord({
  113. patNo: props.huanZheXinXi.inpatientNo,
  114. times: props.huanZheXinXi.admissTimes,
  115. emrCategoryCode: val.code
  116. })
  117. if (flag) {
  118. BizException(ExceptionEnum.LOGICAL_ERROR, '此病历只能创建一次。')
  119. }
  120. }
  121. }
  122. if (val.jump) {
  123. temp.code = val.code
  124. temp.value = val.value
  125. emit('nodeClick', temp, true, templateType);
  126. key = str
  127. } else {
  128. if (key !== str) {
  129. key = str
  130. emit('nodeClick', temp, false, templateType);
  131. }
  132. }
  133. }
  134. const typeChange = (val) => {
  135. emit("typeChange", val)
  136. }
  137. const queryHistory = async (times) => {
  138. templateType = 2
  139. returnData.patientTree = await getPatientDataTree(props.huanZheXinXi.inpatientNo, times)
  140. }
  141. const filterChange = (val) => {
  142. treeRef.filter(val)
  143. }
  144. const filterNode = (value, data) => {
  145. if (!value) return true
  146. return data.name.includes(value)
  147. }
  148. const changeTemplateType = (val) => {
  149. templateType = val
  150. typeChange(val)
  151. }
  152. const deleteTheSpecifiedNode = (id) => {
  153. for (let i = 0, len = returnData.patientTree.length; i < len; i++) {
  154. let item = returnData.patientTree[i]
  155. if (item.emrDocumentId === id) {
  156. returnData.patientTree.splice(i, 1)
  157. return
  158. }
  159. if (item.children) {
  160. for (let j = 0; j < item.children.length; j++) {
  161. let child = item.children[j]
  162. if (child.emrDocumentId === id) {
  163. item.children.splice(i, 1)
  164. return
  165. }
  166. }
  167. }
  168. }
  169. }
  170. let findNode = false
  171. const diseaseDurationRecordTime = (id, list) => {
  172. findNode = false
  173. findMedicalRecordById(id, list, returnData.patientTree)
  174. }
  175. const findMedicalRecordById = (id, roundTimes, list) => {
  176. for (let i = 0, len = list.length; i < len; i++) {
  177. if (findNode) return;
  178. let item = list[i]
  179. if (item.emrDocumentId === id) {
  180. findNode = true
  181. item.children = roundTimes
  182. return
  183. }
  184. if (item.children) {
  185. findMedicalRecordById(id, roundTimes, item.children)
  186. }
  187. }
  188. }
  189. const queryData = () => {
  190. getPatientDataTree(props.huanZheXinXi.inpatientNo, props.huanZheXinXi.admissTimes).then((res) => {
  191. if (res?.length > 0) {
  192. templateType = 2
  193. emit('patientMedicalRecord')
  194. }
  195. returnData.patientTree = res
  196. })
  197. }
  198. const fileName = (val) => {
  199. if (templateType === 2) {
  200. return val.name + nullToEmpty(val.createName) + nullToEmpty(val.createDate)
  201. } else {
  202. return val.name
  203. }
  204. }
  205. const nullToEmpty = (val) => {
  206. return stringIsBlank(val) ? '' : ' \\ ' + val
  207. }
  208. onMounted(() => {
  209. queryData()
  210. if (editor) {
  211. getWardsApi().then((res) => {
  212. if (res.length > 0) {
  213. for (let i = 0, len = res.length; i < len; i++) {
  214. wardList.push(res[i].code)
  215. }
  216. }
  217. })
  218. getEmrTree().then((res) => {
  219. returnData.emrTree = res
  220. })
  221. } else {
  222. templateType = 2
  223. }
  224. })
  225. defineExpose({
  226. queryHistory,
  227. changeTemplateType,
  228. deleteTheSpecifiedNode,
  229. diseaseDurationRecordTime,
  230. queryData
  231. })
  232. </script>
  233. <style scoped lang="scss">
  234. .down-tree {
  235. :deep(.el-tree-node.is-expanded > .el-tree-node__children) {
  236. display: inline;
  237. }
  238. }
  239. </style>