|
@@ -3,6 +3,7 @@ import { registerWork } from '../../API/patient/workActions';
|
|
|
import { setSystemMode, SystemMode } from '../../states/systemModeSlice';
|
|
|
import { addWork } from '../../states/exam/examWorksCacheSlice';
|
|
|
import { setBusinessFlow } from '../../states/BusinessFlowSlice';
|
|
|
+import { setUserInfo } from '../../states/user_info';
|
|
|
import mapToTask from './mapToTask';
|
|
|
import store from '@/states/store';
|
|
|
|
|
@@ -10,14 +11,36 @@ const handleEmergencyOperation = async () => {
|
|
|
const dispatch = store.dispatch;
|
|
|
|
|
|
try {
|
|
|
+ // Step 1: Get guest token from product slice
|
|
|
+ const state = store.getState();
|
|
|
+ const guestToken = state.product.guest;
|
|
|
+
|
|
|
+ if (!guestToken) {
|
|
|
+ throw new Error('Guest token not available');
|
|
|
+ }
|
|
|
+
|
|
|
+ // Step 2: Set system mode to Emergency
|
|
|
dispatch(setSystemMode(SystemMode.Emergency));
|
|
|
- // Step 1: Generate Registration Information
|
|
|
+
|
|
|
+ // Step 3: Set temporary user info with guest token
|
|
|
+ // This allows the app to render BasicLayout while using guest token for API calls
|
|
|
+ dispatch(
|
|
|
+ setUserInfo({
|
|
|
+ token: guestToken,
|
|
|
+ expire: Date.now() + 24 * 60 * 60 * 1000, // 24 hours expiry
|
|
|
+ uid: -1, // Special uid to identify emergency mode
|
|
|
+ name: 'Emergency User',
|
|
|
+ avatar: '',
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ // Step 4: Generate Registration Information
|
|
|
const registrationInfo = generateRegistrationInfo();
|
|
|
if (!registrationInfo) {
|
|
|
throw new Error('Failed to generate registration information');
|
|
|
}
|
|
|
|
|
|
- // Step 2: Register Emergency Work
|
|
|
+ // Step 5: Register Emergency Work
|
|
|
const registrationResult = await registerWork(registrationInfo);
|
|
|
if (!registrationResult || registrationResult.code !== '0x000000') {
|
|
|
throw new Error(
|
|
@@ -28,21 +51,17 @@ const handleEmergencyOperation = async () => {
|
|
|
`Emergency registration result: ${JSON.stringify(registrationResult)}`
|
|
|
);
|
|
|
|
|
|
- // Switch system mode back to normal
|
|
|
- // dispatch(setSystemMode(SystemMode.Normal));
|
|
|
-
|
|
|
- // Save registration result to cache
|
|
|
+ // Step 6: Save registration result to cache
|
|
|
const task = mapToTask(registrationResult.data);
|
|
|
dispatch(addWork(task));
|
|
|
|
|
|
- // Step 3: Proceed to Examination
|
|
|
+ // Step 7: Proceed to Examination
|
|
|
dispatch(setBusinessFlow('exam'));
|
|
|
} catch (error) {
|
|
|
- // dispatch(setSystemMode(SystemMode.Normal));
|
|
|
+ // Clean up emergency state on error
|
|
|
+ dispatch(setSystemMode(SystemMode.Unkonwn));
|
|
|
console.error('Error in handleEmergencyOperation:', error);
|
|
|
throw error;
|
|
|
- } finally {
|
|
|
- // dispatch(setSystemMode(SystemMode.Normal));
|
|
|
}
|
|
|
};
|
|
|
|