Repository navigation
Expand file tree
/
Copy pathstate.ts
More file actions
198 lines (172 loc) · 7.51 KB
/
Copy pathstate.ts
File metadata and controls
198 lines (172 loc) · 7.51 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { z } from 'zod';
import type { Immutable } from 'immer';
import {
newSeededRandomState,
randomStateSchema,
} from './simulation/utils/randomness.js';
import { spatialElementTypePluralSchema } from './store/action-reducers/utils/spatial-elements.js';
import { vehicleSchema } from './models/vehicle.js';
import { restrictedZoneSchema } from './models/restricted-zone.js';
import { materialSchema } from './models/material.js';
import { personnelSchema } from './models/personnel.js';
import { type ParticipantKey, participantKeySchema } from './exercise-keys.js';
import { hospitalSchema } from './models/hospital.js';
import { mapImageSchema } from './models/map-image.js';
import { viewportSchema } from './models/viewport.js';
import { transferPointSchema } from './models/transfer-point.js';
import { alarmGroupSchema } from './models/alarm-group.js';
import { clientSchema } from './models/client.js';
import { eocLogEntrySchema } from './models/eoc-log-entry.js';
import { operationalSectionSchema } from './models/operational-section.js';
import {
exerciseConfigurationSchema,
newExerciseConfiguration,
} from './models/exercise-configuration.js';
import { patientSchema } from './models/patient.js';
import { hospitalPatientSchema } from './models/hospital-patient.js';
import { patientCategorySchema } from './models/patient-category.js';
import { getIdMapSchema, uuid, uuidSchema } from './utils/uuid.js';
import { SpatialTree } from './models/utils/spatial-tree.js';
import { logEntrySchema } from './models/log-entry.js';
import {
exerciseStatusSchema,
exerciseTypeSchema,
} from './models/utils/exercise-status.js';
import { simulatedRegionSchema } from './models/simulated-region.js';
import { exerciseRadiogramSchema } from './models/radiogram/exercise-radiogram.js';
import { scoutableSchema } from './models/scoutable.js';
import {
measureSchema,
measureTemplateCategorySchema,
} from './models/measure/measures.js';
import { drawingSchema } from './models/drawing.js';
import { defaultMeasureTemplateCategories } from './data/default-state/measure-templates.js';
import { technicalChallengeSchema } from './models/technical-challenge/technical-challenge.js';
import { taskTypeSchema } from './models/task-type.js';
import { getDefaultTasks } from './data/default-state/tmp-default-technical-challenge.js';
import { resourceDescriptionSchema } from './models/utils/resource-description.js';
import { defaultPatientCategories } from './data/default-state/patient-templates.js';
import {
catchAllHospitalId,
createCatchAllHospital,
} from './data/default-state/catch-all-hospital.js';
import { templateSchema } from './models/template.js';
import { versionedCollectionPartialSchema } from './marketplace/models/versioned-id-schema.js';
import { defaultTechnicalChallengeTemplates } from './data/default-state/technical-challenge-templates.js';
import { technicalChallengeTemplateSchema } from './models/technical-challenge/technical-challenge-template.js';
/**
* **Important**
*
* This number MUST be increased every time a change to any object (that is part of the state or the state itself) is made in a way that there may be states valid before that are no longer valid.
*/
export const currentStateVersion = 65 as const;
export const exerciseStateSchema = z.strictObject({
id: uuidSchema,
/**
* The number of ms since the start of the exercise.
* This time is updated each `tick` by a constant value, is guaranteed to be (a bit) slower than the real time
* (depending on the server load and overhead of the tick).
*
* It is guaranteed that the `ExerciseTickAction` is the only action that modifies this value.
*/
currentTime: z.int().nonnegative(),
type: exerciseTypeSchema,
currentStatus: exerciseStatusSchema,
randomState: randomStateSchema,
selectedCollections: z.array(versionedCollectionPartialSchema),
viewports: getIdMapSchema(viewportSchema),
autojoinViewportId: uuidSchema.nullable(),
simulatedRegions: getIdMapSchema(simulatedRegionSchema),
vehicles: getIdMapSchema(vehicleSchema),
personnel: getIdMapSchema(personnelSchema),
patients: getIdMapSchema(patientSchema),
materials: getIdMapSchema(materialSchema),
restrictedZones: getIdMapSchema(restrictedZoneSchema),
measures: getIdMapSchema(measureSchema),
drawings: getIdMapSchema(drawingSchema),
mapImages: getIdMapSchema(mapImageSchema),
taskTypes: getIdMapSchema(taskTypeSchema),
technicalChallenges: getIdMapSchema(technicalChallengeSchema),
technicalChallengeTemplates: z.record(
uuidSchema,
technicalChallengeTemplateSchema
),
transferPoints: getIdMapSchema(transferPointSchema),
hospitals: getIdMapSchema(hospitalSchema),
hospitalPatients: z.record(uuidSchema, hospitalPatientSchema),
alarmGroups: getIdMapSchema(alarmGroupSchema),
clients: getIdMapSchema(clientSchema),
/** All client names that are currently in the exercise or joined the exercise in the past */
collectedClientNames: z.array(z.string()),
radiograms: getIdMapSchema(exerciseRadiogramSchema),
operationalSections: getIdMapSchema(operationalSectionSchema),
patientCategories: z.array(patientCategorySchema),
measureTemplates: z.record(z.string(), measureTemplateCategorySchema),
scoutables: getIdMapSchema(scoutableSchema),
templates: z.record(uuidSchema, templateSchema),
eocLog: z.array(eocLogEntrySchema),
participantKey: participantKeySchema,
spatialTrees: z.record(spatialElementTypePluralSchema, SpatialTree.schema),
configuration: exerciseConfigurationSchema,
patientCounter: z.int().nonnegative(),
vehicleCounters: resourceDescriptionSchema,
logEntries: z.array(logEntrySchema).optional(),
lastLogEntry: logEntrySchema.optional(),
previousTreatmentAssignment: z
.record(uuidSchema, resourceDescriptionSchema)
.optional(),
});
export type ExerciseState = Immutable<z.infer<typeof exerciseStateSchema>>;
export function newExerciseState(
participantKey: ParticipantKey
): ExerciseState {
return {
id: uuid(),
currentTime: 0,
type: 'standalone',
currentStatus: 'notStarted',
randomState: newSeededRandomState(),
selectedCollections: [],
viewports: {},
autojoinViewportId: null,
simulatedRegions: {},
vehicles: {},
personnel: {},
patients: {},
materials: {},
restrictedZones: {},
measures: {},
drawings: {},
mapImages: {},
taskTypes: getDefaultTasks(),
technicalChallenges: {},
transferPoints: {},
hospitals: {
[catchAllHospitalId]: createCatchAllHospital(),
},
hospitalPatients: {},
alarmGroups: {},
clients: {},
collectedClientNames: [],
radiograms: {},
operationalSections: {},
patientCategories: defaultPatientCategories,
measureTemplates: defaultMeasureTemplateCategories,
technicalChallengeTemplates: defaultTechnicalChallengeTemplates,
scoutables: {},
templates: {},
eocLog: [],
participantKey,
spatialTrees: {
materials: SpatialTree.newSpatialTree(),
patients: SpatialTree.newSpatialTree(),
personnel: SpatialTree.newSpatialTree(),
},
configuration: newExerciseConfiguration(),
patientCounter: 0,
vehicleCounters: {},
logEntries: undefined,
lastLogEntry: undefined,
previousTreatmentAssignment: undefined,
};
}