index.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import { createSlice, PayloadAction } from '@reduxjs/toolkit';
  2. import { setCurrentPatientType } from '../../patientTypeSlice';
  3. import { BodyPart } from '@/API/bodyPart';
  4. import { PatientType } from '@/API/patientType';
  5. import {
  6. SelectionState,
  7. setSelected,
  8. } from '@/states/patient/register/SelectionTypeSlice';
  9. import { setCurrentBodyPart } from '../../bodyPartSlice';
  10. // 体位类型
  11. export interface View {
  12. internal_id: string;
  13. view_id: string;
  14. view_name: string;
  15. view_name_local: string;
  16. view_other_name: string;
  17. view_description: string;
  18. view_position: string;
  19. application: string;
  20. anatomic_region: string;
  21. patient_type: string;
  22. body_part_id: string;
  23. view_icon_name: string;
  24. view_big_icon_name: string;
  25. view_coach_name: string;
  26. modality: string;
  27. // config_object: any;
  28. tech_template: string;
  29. img_proc_template: string;
  30. sort: number;
  31. is_enabled: boolean;
  32. product: string;
  33. is_pre_install: boolean;
  34. }
  35. // 协议类型
  36. export interface Procedure {
  37. ProcedureID: string;
  38. ProcedureCode: string;
  39. ProcedureName: string;
  40. ProcedureOtherName: string;
  41. ProcedureDescription: string;
  42. PatientType: string;
  43. ProcedureGroupID: string;
  44. ProcedureType: string;
  45. FastSearch: boolean;
  46. Enable: boolean;
  47. Order: number;
  48. UserGroupID: string;
  49. ProcedureCategory: string;
  50. Modality: string;
  51. IsImplanted: boolean;
  52. MagFactor: number;
  53. // ProcedureViews: View[];
  54. // ProcedureViewRelations: any[];
  55. ClinicProtocol: boolean;
  56. IsFactoryDefault: boolean;
  57. MinBMI: number;
  58. MaxBMI: number;
  59. AutoDecompression: boolean;
  60. ConfigObjectValue: string;
  61. }
  62. interface ViewSelectionState {
  63. selectedViews: View[]; // 已选择体位列表
  64. availableViews: View[]; // 待选择体位列表
  65. protocols: Procedure[]; // 协议列表(只会出现在待选择列表)
  66. currentBodyPart: BodyPart | null;
  67. currentPatientType: PatientType | null;
  68. currentSelectionType: SelectionState;
  69. }
  70. const initialState: ViewSelectionState = {
  71. selectedViews: [],
  72. availableViews: [
  73. {
  74. internal_id: '1',
  75. view_id: 'AP',
  76. view_name: 'Anteroposterior',
  77. view_name_local: '前后位',
  78. view_other_name: 'AP View',
  79. view_description: '前后体位描述',
  80. view_position: 'Standing',
  81. application: 'General',
  82. anatomic_region: 'Chest',
  83. patient_type: 'Adult',
  84. body_part_id: 'CHEST',
  85. view_icon_name: 'ap_icon.png',
  86. view_big_icon_name: 'ap_big_icon.png',
  87. view_coach_name: 'ap_coach.png',
  88. modality: 'X-Ray',
  89. tech_template: 'default',
  90. img_proc_template: 'default',
  91. sort: 1,
  92. is_enabled: true,
  93. product: 'Standard',
  94. is_pre_install: true,
  95. },
  96. {
  97. internal_id: '2',
  98. view_id: 'LAT',
  99. view_name: 'Lateral',
  100. view_name_local: '侧位',
  101. view_other_name: 'LAT View',
  102. view_description: '侧体位描述',
  103. view_position: 'Standing',
  104. application: 'General',
  105. anatomic_region: 'Chest',
  106. patient_type: 'Adult',
  107. body_part_id: 'CHEST',
  108. view_icon_name: 'lat_icon.png',
  109. view_big_icon_name: 'lat_big_icon.png',
  110. view_coach_name: 'lat_coach.png',
  111. modality: 'X-Ray',
  112. tech_template: 'default',
  113. img_proc_template: 'default',
  114. sort: 2,
  115. is_enabled: true,
  116. product: 'Standard',
  117. is_pre_install: true,
  118. },
  119. ],
  120. protocols: [],
  121. currentBodyPart: null,
  122. currentPatientType: null,
  123. currentSelectionType: { selected: 'protocol' },
  124. };
  125. const viewSelectionSlice = createSlice({
  126. name: 'viewSelection',
  127. initialState,
  128. reducers: {
  129. // 添加体位到已选择体位列表
  130. addSelectedView(state, action: PayloadAction<View>) {
  131. state.selectedViews.push(action.payload);
  132. },
  133. // 添加协议中的所有体位到已选择体位列表
  134. // eslint-disable-next-line
  135. addProtocolViews(state, action: PayloadAction<Procedure>) {
  136. // 假设协议中包含 ProcedureViews 属性,存储体位数组
  137. // todo 这里涉及到基于协议查询其名下的体位,然后再添加
  138. // if (Array.isArray(action.payload.ProcedureViews)) {
  139. // state.selectedViews.push(...action.payload.ProcedureViews);
  140. // }
  141. },
  142. // 可根据需要添加其它 reducer,例如设置 availableViews、Procedures 等
  143. setAvailableViews(state, action: PayloadAction<View[]>) {
  144. state.availableViews = action.payload;
  145. },
  146. setProtocols(state, action: PayloadAction<Procedure[]>) {
  147. state.protocols = action.payload;
  148. },
  149. },
  150. extraReducers: (builder) => {
  151. builder
  152. .addCase(setCurrentPatientType, (state, action) => {
  153. const currentPatientType = action.payload;
  154. if (currentPatientType) {
  155. // console.log(`在view section中感知到 current patient type 变化: ${currentPatientType.patient_type_name}`);
  156. // 基于过滤条件查询协议或者体位
  157. state.currentPatientType = currentPatientType;
  158. }
  159. })
  160. .addCase(setCurrentBodyPart, (state, action) => {
  161. const currentBodyPart = action.payload;
  162. if (currentBodyPart) {
  163. state.currentBodyPart = currentBodyPart;
  164. // console.log(`在view section中感知到 currentBodyPart 变化: ${JSON.stringify(currentBodyPart, null, 2)}`);
  165. }
  166. })
  167. .addCase(setSelected, (state, action) => {
  168. console.log(
  169. `在view section中感知到 currentSelectionType : ${action.payload}`
  170. );
  171. state.currentSelectionType.selected = action.payload;
  172. });
  173. },
  174. });
  175. export const {
  176. addSelectedView,
  177. addProtocolViews,
  178. setAvailableViews,
  179. setProtocols,
  180. } = viewSelectionSlice.actions;
  181. export default viewSelectionSlice.reducer;