Repository navigation
Expand file tree
/
Copy pathmaterial.ts
More file actions
61 lines (58 loc) · 2.29 KB
/
Copy pathmaterial.ts
File metadata and controls
61 lines (58 loc) · 2.29 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
import { z } from 'zod';
import type { Immutable } from 'immer';
import { maxTreatmentRange } from '../state-helpers/max-treatment-range.js';
import { uuid, type UUID, uuidSchema } from '../utils/uuid.js';
import { uuidSetSchema } from '../utils/uuid-set.js';
import { versionedElementModelSchema } from '../marketplace/models/versioned-element-model.js';
import type { MaterialTemplate } from './material-template.js';
import { canCaterForSchema } from './utils/cater-for.js';
import { imagePropertiesSchema } from './utils/image-properties.js';
import { type Position, positionSchema } from './utils/position/position.js';
export const materialSchema = z.strictObject({
...versionedElementModelSchema.shape,
id: uuidSchema,
type: z.literal('material'),
templateId: uuidSchema,
typeName: z.string().trim().nonempty(),
vehicleId: uuidSchema,
vehicleName: z.string().trim().nonempty(),
assignedPatientIds: uuidSetSchema,
canCaterFor: canCaterForSchema,
/**
* Patients in this range are preferred over patients farther away (even if they are less injured).
* Guaranteed to be <= {@link maxTreatmentRange}.
* Setting this to `0` means deactivating this range.
*/
overrideTreatmentRange: z.number().min(0).max(maxTreatmentRange),
/**
* Only patients in this range around the material's position can be treated.
* Guaranteed to be <= {@link maxTreatmentRange}.
* Setting this to `0` means deactivating this range.
*/
treatmentRange: z.number().min(0).max(maxTreatmentRange),
position: positionSchema,
image: imagePropertiesSchema,
});
export type Material = Immutable<z.infer<typeof materialSchema>>;
export function newMaterialFromTemplate(
materialTemplate: MaterialTemplate,
vehicleId: UUID,
vehicleName: string,
position: Position,
id?: UUID
): Material {
return {
id: id ?? uuid(),
type: 'material',
templateId: materialTemplate.id,
typeName: materialTemplate.name,
vehicleId,
vehicleName,
assignedPatientIds: {},
image: materialTemplate.image,
canCaterFor: materialTemplate.canCaterFor,
overrideTreatmentRange: materialTemplate.overrideTreatmentRange,
treatmentRange: materialTemplate.treatmentRange,
position,
};
}