| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import { createEntityListSlices } from '../../../list_template/createListSlices';
- import {
- createFetchThunk,
- createDeleteThunk,
- } from '../../../list_template/thunk.factory';
- import { work, workAnimal } from '../types/worklist';
- import { WorkFilter } from '../types/workfilter';
- import { createAsyncThunk, Draft, PayloadAction } from '@reduxjs/toolkit';
- import {
- setId,
- setName,
- setAccNo,
- setStartTime,
- setEndTime,
- setStatus,
- setPage,
- setPageSize,
- } from '../slices/searchSlice';
- // Define the fetch thunk
- import {
- deleteStudies,
- fetchTaskList,
- lockStudy,
- } from '../../../../API/patient/workActions';
- import { editTaskThunk } from '../../edit/editFormSlice';
- import store from '@/states/store';
- import { EntitiesState } from '@/states/list_template/type.model';
- export const fetchWorkThunk = createFetchThunk<WorkFilter, work>(
- 'historylist',
- async ({ page, pageSize, filters }) => {
- // const filtersEx: WorkFilter = { ...filters, status: 'Arrived' }
- const { items, total } = await fetchTaskList(page, pageSize, filters);
- return { data: items, total };
- }
- );
- // Define the delete thunk
- export const deleteWorkThunk = createDeleteThunk(
- 'historylist',
- async (ids: string[]) => {
- await deleteStudies(ids);
- store.dispatch(selectionSlice.actions.clearSelection());
- }
- );
- const extraReducersForFilter = (builder) => {
- builder.addCase(
- setId.type,
- (state: WorkFilter, action: PayloadAction<string>) => {
- state.patient_id = action.payload;
- }
- );
- builder.addCase(
- setName.type,
- (state: WorkFilter, action: PayloadAction<string>) => {
- state.patient_name = action.payload;
- }
- );
- builder.addCase(
- setAccNo.type,
- (state: WorkFilter, action: PayloadAction<string>) => {
- state.access_number = action.payload;
- }
- );
- builder.addCase(
- setStartTime.type,
- (state: WorkFilter, action: PayloadAction<string>) => {
- state.start_time = action.payload;
- }
- );
- builder.addCase(
- setEndTime.type,
- (state: WorkFilter, action: PayloadAction<string>) => {
- state.end_time = action.payload;
- }
- );
- builder.addCase(
- setStatus.type,
- (state: WorkFilter, action: PayloadAction<string>) => {
- state.status = action.payload;
- }
- );
- builder.addCase(
- setPage.type,
- (state: WorkFilter, action: PayloadAction<number>) => {
- state.page = action.payload;
- }
- );
- builder.addCase(
- setPageSize.type,
- (state: WorkFilter, action: PayloadAction<number>) => {
- state.page_size = action.payload;
- }
- );
- };
- // 锁定/解锁研究的 thunk
- export const lockWorkInhistorylistThunk = createAsyncThunk(
- 'historylist/lock',
- async ({ studyId, lock }: { studyId: string; lock: 'Locked' | 'Unlocked' }) => {
- console.log(`锁定,从thunk调用api,目标 studyid是 ${studyId},新状态是 ${lock}`);
- const result = await lockStudy(studyId, lock);
- return { studyId, lock, result };
- }
- );
- // 创建锁定操作的 handlers
- const createLockHandlers = () => ({
- fulfilled: (
- state: Draft<EntitiesState<work | workAnimal>>,
- action: PayloadAction<{ studyId: string; lock: 'Locked' | 'Unlocked'; result: any }>
- ) => {
- const { studyId, lock } = action.payload;
- console.log(`锁定,thunk fulfilled,目标 studyid是 ${studyId},新状态是 ${lock}`);
- const item = state.data.find((item) => item.StudyID === studyId);
- if (item) {
- item.StudyLock = lock;
- }
- },
- });
- // Create the worklist slices
- const {
- entitiesSlice,
- filtersSlice,
- paginationSlice,
- selectionSlice,
- uiSlice,
- } = createEntityListSlices<work, WorkFilter>(
- 'historylist',
- fetchWorkThunk,
- deleteWorkThunk,
- 'StudyID',
- extraReducersForFilter,
- {
- patient_id: '',
- patient_name: '',
- start_time: '',
- end_time: '',
- access_number: '',
- status: 'Completed',
- page: 1,
- page_size: 10,
- } satisfies WorkFilter,
- {
- lock: {
- thunk: lockWorkInhistorylistThunk,
- handlers: createLockHandlers(),
- },
- // 监听 editFormSlice 的编辑 thunk
- editFromEditForm: {
- thunk: editTaskThunk,
- handlers: {
- fulfilled: (
- state: Draft<EntitiesState<work | workAnimal>>,
- action: PayloadAction<any>
- ) => {
- const { studyId, result } = action.payload;
- console.log(`historylist 监听到编辑成功,更新列表数据,studyId: ${studyId}`);
- const item = state.data.find((item) => item.StudyID === studyId);
- if (item && result.code === '0x000000') {
- // 更新列表中的项目数据
- const updatedData = result.data;
- item.PatientName = updatedData.patient_name;
- item.PatientID = updatedData.patient_id;
- item.PatientSex = updatedData.patient_sex;
- item.PatientAge = updatedData.patient_age;
- item.PatientSize = updatedData.patient_size;
- item.AccessionNumber = updatedData.accession_number;
- item.OperatorID = updatedData.operator_name;
- // 根据产品类型更新特定字段
- if ('owner_name' in item) {
- (item as any).owner_name = (updatedData as any).owner_name;
- (item as any).chip_number = (updatedData as any).chip_number;
- (item as any).variety = (updatedData as any).variety;
- (item as any).is_anaesthesia = (updatedData as any).is_anaesthesia;
- (item as any).is_sedation = (updatedData as any).is_sedation;
- }
- }
- },
- },
- },
- }
- );
- export const historyEntitiesSlice = entitiesSlice;
- export const historyFiltersSlice = filtersSlice;
- export const historyPaginationSlice = paginationSlice;
- export const historySelectionSlice = selectionSlice;
- export const historyUISlice = uiSlice;
|