yxh
2026-10-03 d553a4be94d4f6ee162cc353a28b220403909cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { defineStore } from 'pinia'
import { store } from '../index'
// @ts-ignore
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache('sessionStorage')
import {CheckTypeApi} from "@/api/ecg/checktype";
 
export interface CheckTypeSimpleVO {
  value: number
  name: string
  displayBarcode: []
  notes: string
  seqPrefix: string // 序号前缀
  expenseRecognition: number
  /** 是否需要设备领用:0-不需要,1-需要(用于「设备领用」页的校验) */
  needDevReady?: number
}
export interface CheckTypeState {
  checkTypeMap: Map<number, CheckTypeSimpleVO>
  isSetCheckType: boolean
}
 
export const useCheckTypeStore = defineStore('checktype ', {
  state: (): CheckTypeState => ({
    checkTypeMap: new Map<number, CheckTypeSimpleVO>(),
    isSetCheckType: false
  }),
  getters: {
    getCheckTypeMap(): Recordable {
      const checkTypeMap = wsCache.get(CACHE_KEY.CHECKTYPE_CACHE)
      if (checkTypeMap) {
        this.checkTypeMap = checkTypeMap
      }
      return this.checkTypeMap
    },
    getIsSetCheckType(): boolean {
      return this.isSetCheckType
    }
  },
  actions: {
    async setCheckTypeMap() {
      const checkTypeMap = wsCache.get(CACHE_KEY.CHECKTYPE_CACHE)
      if (checkTypeMap) {
        this.checkTypeMap = checkTypeMap
        this.isSetCheckType = true
      } else {
        const res = await CheckTypeApi.getSimpleCheckTypeList()
        // 设置数据
        const checkTypeMap = new Map<number, CheckTypeSimpleVO>()
        res.forEach((simpleVO: CheckTypeSimpleVO) => {
          // 获得 dictType 层级
          const enumValueObj = checkTypeMap[simpleVO.value]
          if (!enumValueObj) {
            checkTypeMap[simpleVO.value] = simpleVO
          }
        })
        this.checkTypeMap = checkTypeMap
        this.isSetCheckType = true
        wsCache.set(CACHE_KEY.CHECKTYPE_CACHE, checkTypeMap, { exp: 60 }) // 60 秒 过期
      }
    },
    getCheckTypeName(type: number) {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return this.checkTypeMap[type]?.name
    },
    getCheckTypeOptions() {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return Object.keys(this.checkTypeMap).map((key) => {
        return {
          value: parseInt(key, 10),
          label: this.checkTypeMap[key].name
        }
      });
    },
    getCheckTypeDispBarCode(type: number) {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return this.checkTypeMap[type]?.displayBarcode
    },
    getCheckTypeNotes(type: number) {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return this.checkTypeMap[type].notes
    },
    getCheckTypeSeqPrefix(type: number) {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return this.checkTypeMap[type]?.seqPrefix || ''
    },
    getExpenseRecognition(type: number) {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return this.checkTypeMap[type]?.expenseRecognition
    },
    /**
     * 该检查项目是否需要「设备领用」。
     *
     * 用于「设备领用」页的守卫:只有需要设备领用的项目(如动态心电、动态血压)
     * 才应进入领用流程;常规心电图等不需要领用的项目若被拉到该页,应拦下并提示,
     * 否则会出现"检查类患者出现在设备领用模块"的混乱。
     */
    getNeedDevReady(type: number) {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return this.checkTypeMap[type]?.needDevReady
    },
    async resetCheckTypeInfo() {
      wsCache.delete(CACHE_KEY.CHECKTYPE_CACHE)
      const res = await CheckTypeApi.getSimpleCheckTypeList()
      // 设置数据
      const checkTypeMap = new Map<number, CheckTypeSimpleVO>()
      res.forEach((simpleVO: CheckTypeSimpleVO) => {
        // 获得 dictType 层级
        const enumValueObj = checkTypeMap[simpleVO.value]
        if (!enumValueObj) {
          checkTypeMap[simpleVO.value] = simpleVO
        }
      })
      this.checkTypeMap = checkTypeMap
      this.isSetCheckType = true
      wsCache.set(CACHE_KEY.CHECKTYPE_CACHE, checkTypeMap, { exp: 60 }) // 60 秒 过期
    }
  }
})
 
export const useCheckTypeStoreWithOut = () => {
  return useCheckTypeStore(store)
}