workActions.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. import { Series } from '@/domain/series';
  2. import axiosInstance from '../interceptor';
  3. import { Task } from '@/domain/work';
  4. import { dview } from '@/domain/dview';
  5. import { XImage } from '@/domain/xImage';
  6. interface View {
  7. view_id: string;
  8. procedure_id: string;
  9. }
  10. export interface RegisterInfo {
  11. accession_number: string;
  12. patient_id: string;
  13. patient_name: string;
  14. patient_size: string;
  15. patient_age: string;
  16. patient_dob: string;
  17. patient_sex: string;
  18. sex_neutered: string;
  19. pregnancy_status: string;
  20. chip_number: string;
  21. variety: string;
  22. patient_type: string;
  23. ref_physician: string;
  24. operator_id: string;
  25. modality: string;
  26. weight: number;
  27. thickness: number;
  28. length: number;
  29. study_type: 'Normal' | 'Emergency';
  30. comment: string;
  31. views: View[];
  32. }
  33. export interface RegisterWorkResponseData {
  34. study_instance_uid: string;
  35. study_id: string;
  36. public_study_id: string;
  37. specific_character_set: string;
  38. accession_number: string;
  39. ref_physician: string;
  40. patient_id: string;
  41. patient_name: string;
  42. patient_size: string;
  43. other_patient_ids: string;
  44. other_patient_names: string;
  45. owner_name: string;
  46. patient_age: string;
  47. patient_dob: string;
  48. patient_sex: string;
  49. patient_state: string;
  50. admitting_time: string | null;
  51. priority: string;
  52. reg_source: string;
  53. study_status: string;
  54. study_description: string;
  55. study_start_datetime: string | null;
  56. study_end_datetime: string | null;
  57. scheduled_procedure_step_start_date: string | null;
  58. performed_physician: string;
  59. study_lock: string;
  60. folder_path: string;
  61. operator_name: string;
  62. modality: string;
  63. weight: number;
  64. thickness: number;
  65. length: number;
  66. patient_type: string;
  67. study_type: string;
  68. mwl: string;
  69. is_exported: boolean;
  70. is_edited: boolean;
  71. is_appended: boolean;
  72. department: string;
  73. mapped_status: boolean;
  74. qc_result: boolean;
  75. comment: string;
  76. sort: number;
  77. product: string;
  78. series: Series[];
  79. }
  80. export interface RegisterWorkResponse {
  81. code: string;
  82. description: string;
  83. solution: string;
  84. data: RegisterWorkResponseData;
  85. }
  86. export interface AcquisitionContext {
  87. WorkStationID: number;
  88. PatientSize: string;
  89. KVP: number;
  90. MA: number;
  91. MAS: number;
  92. MS: number;
  93. TechMode: number;
  94. AECDensity: number;
  95. AECField: number;
  96. AECFilm: number;
  97. DAP: number;
  98. DOSE: number;
  99. FocalSpot: string;
  100. SID: number;
  101. TOD: number;
  102. TubeLoad: string;
  103. GridType: string;
  104. FilterType: string;
  105. EXI: number;
  106. DI: number;
  107. PositionNumber: string;
  108. CollimatorFilter: string;
  109. CollimatorLength: string;
  110. CollimatorWidth: string;
  111. CollimatorCenter: string;
  112. FpdAcquisitionMode: string;
  113. FrameRate: number;
  114. EntranceDoseInmGy: number;
  115. }
  116. export interface ImageFunctionParameter {
  117. Name: string;
  118. Min: number;
  119. Max: number;
  120. Step: number;
  121. Value: number;
  122. ValueType: string;
  123. IsEnabled: boolean;
  124. }
  125. export interface ImageFunction {
  126. FunctionName: string;
  127. ImageStyle: string;
  128. Parameters: ImageFunctionParameter[];
  129. CurveType: ImageFunctionParameter;
  130. WindowLevelGradeParameters: ImageFunctionParameter[];
  131. }
  132. export interface ImageProcessingContext {
  133. ImageFunction: ImageFunction;
  134. }
  135. export interface CopyPositionResponseData {
  136. series_instance_uid: string;
  137. study_instance_uid: string;
  138. study_id: string;
  139. procedure_id: string;
  140. body_part: string;
  141. performed_datetime: string | null;
  142. performed_protocol_code_meaning: string;
  143. performed_protocol_code_value: string;
  144. sort: number;
  145. product: string;
  146. is_pre_install: boolean;
  147. images: {
  148. sop_instance_id: string;
  149. series_instance_uid: string;
  150. study_instance_uid: string;
  151. secondary_sop_uid: string;
  152. study_id: string;
  153. view_id: string;
  154. view_description: string;
  155. image_status: string;
  156. image_file_path: string;
  157. acquisition_mode: string;
  158. acquisition_context: AcquisitionContext | null;
  159. img_proc_context: ImageProcessingContext | null;
  160. sort: number;
  161. product: string;
  162. is_pre_install: boolean;
  163. }[];
  164. }
  165. export interface CopyPositionResponse {
  166. code: string;
  167. description: string;
  168. solution: string;
  169. data: CopyPositionResponseData;
  170. }
  171. // 充当列表框架的filter
  172. export interface TaskListQuery {
  173. patient_id?: string;
  174. patient_name?: string;
  175. start_time?: string;
  176. end_time?: string;
  177. access_number?: string;
  178. status?: string;
  179. page?: number;
  180. page_size?: number;
  181. }
  182. const registerWork = async (
  183. work: RegisterInfo
  184. ): Promise<RegisterWorkResponse> => {
  185. console.log('Work object:', JSON.stringify(work, null, 2));
  186. try {
  187. const response = await axiosInstance.post('/auth/study', work);
  188. // response.data.code
  189. console.log(`0000${JSON.stringify(response)}`);
  190. return response.data;
  191. } catch (error) {
  192. console.warn(`注册出错:${error}`);
  193. throw error;
  194. }
  195. };
  196. const mapToTask = (study: RegisterWorkResponseData): Task => ({
  197. StudyInstanceUID: study.study_instance_uid,
  198. StudyID: study.study_id,
  199. SpecificCharacterSet: study.specific_character_set,
  200. AccessionNumber: study.accession_number,
  201. PatientID: study.patient_id,
  202. PatientName: study.patient_name,
  203. DisplayPatientName: study.patient_name,
  204. PatientSize: study.patient_size,
  205. PatientAge: study.patient_age,
  206. PatientSex: study.patient_sex,
  207. AdmittingTime: study.admitting_time ?? '',
  208. RegSource: study.reg_source,
  209. StudyStatus: study.study_status,
  210. RequestedProcedureID: '',
  211. PerformedProtocolCodeValue: '',
  212. PerformedProtocolCodeMeaning: '',
  213. PerformedProcedureStepID: '',
  214. StudyDescription: study.study_description,
  215. StudyStartDatetime: study.study_start_datetime ?? '',
  216. ScheduledProcedureStepStartDate:
  217. study.scheduled_procedure_step_start_date ?? '',
  218. StudyLock: study.study_lock,
  219. OperatorID: study.operator_name,
  220. Modality: study.modality,
  221. Views: [],
  222. Thickness: study.thickness,
  223. PatientType: study.patient_type,
  224. StudyType: study.study_type,
  225. QRCode: '',
  226. IsExported: study.is_exported,
  227. IsEdited: study.is_edited,
  228. WorkRef: '',
  229. IsAppended: study.is_appended,
  230. CreationTime: '',
  231. MappedStatus: study.mapped_status,
  232. IsDelete: false,
  233. });
  234. const fetchTaskList = async (
  235. page,
  236. pageSize,
  237. filter: TaskListQuery
  238. ): Promise<{ items: Task[]; total: number }> => {
  239. console.log(
  240. `Fetching task list with page: ${page}, pageSize: ${pageSize}, filter: ${JSON.stringify(filter)}`
  241. );
  242. const response = await axiosInstance.get('/auth/study', {
  243. params: {
  244. page: page,
  245. page_size: pageSize,
  246. id: filter.patient_id ?? '',
  247. name: filter.patient_name ?? '',
  248. start_time: filter.start_time,
  249. end_time: filter.end_time,
  250. acc_no: filter.access_number,
  251. status: filter.status,
  252. },
  253. });
  254. const { studies } = response.data.data;
  255. const tasks = studies.map(mapToTask);
  256. return { items: tasks, total: tasks.length };
  257. };
  258. export { registerWork, fetchTaskList };
  259. const fetchTaskDetails = async (
  260. studyId: string
  261. ): Promise<RegisterWorkResponseData> => {
  262. try {
  263. const response = await axiosInstance.get(`/auth/study/${studyId}`);
  264. return response.data.data;
  265. } catch (error) {
  266. console.error('Error fetching task details:', error);
  267. throw error;
  268. }
  269. };
  270. const copyImage = async (instanceUid: string): Promise<dview[]> => {
  271. try {
  272. const response = await axiosInstance.post('/auth/image/copy', {
  273. instance_uid: instanceUid,
  274. });
  275. const dviews: dview[] = response.data.series.flatMap((series: Series) =>
  276. series.images.map((image: XImage) => ({
  277. view_id: image.view_id,
  278. series_instance_uid: image.series_instance_uid,
  279. study_instance_uid: image.study_instance_uid,
  280. study_id: image.study_id,
  281. procedure_id: series.procedure_id,
  282. view_description: image.view_description,
  283. view_type: image.view_id, // Assuming view_type is the same as view_id
  284. }))
  285. );
  286. return dviews;
  287. } catch (error) {
  288. console.error('Error copying image:', error);
  289. throw error;
  290. }
  291. };
  292. export { copyImage, fetchTaskDetails };
  293. export interface DeleteStudiesResponse {
  294. code: string;
  295. description: string;
  296. solution: string;
  297. data: {
  298. total: number;
  299. exposed: number;
  300. };
  301. }
  302. const deleteStudies = async (
  303. studyIds: string[]
  304. ): Promise<DeleteStudiesResponse> => {
  305. try {
  306. const response = await axiosInstance.delete('/auth/study', {
  307. data: studyIds,
  308. });
  309. return response.data;
  310. } catch (error) {
  311. console.error('Error deleting studies:', error);
  312. throw error;
  313. }
  314. };
  315. export { deleteStudies };
  316. // eslint-disable-next-line
  317. const suspendOrCompleteStudy = async (studyId: string, studyStatus: 'InProgress' | 'Completed'): Promise<{ code: string; description: string; solution: string; data: {} }> => {
  318. try {
  319. const response = await axiosInstance.post('/auth/task/inspection/leave', {
  320. study_id: studyId,
  321. study_status: studyStatus,
  322. });
  323. return response.data;
  324. } catch (error) {
  325. console.error('Error suspending or completing study:', error);
  326. throw error;
  327. }
  328. };
  329. export { suspendOrCompleteStudy };