Repository navigation
Expand file tree
/
Copy pathscoutable.ts
More file actions
70 lines (64 loc) · 2.35 KB
/
Copy pathscoutable.ts
File metadata and controls
70 lines (64 loc) · 2.35 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
import * as z from 'zod';
import type { Immutable } from 'immer';
import { uuid, uuidSchema } from '../utils/uuid.js';
import { type Patient, patientSchema } from './patient.js';
import { mapImageSchema } from './map-image.js';
import {
newUserGeneratedContent,
userGeneratedContentSchema,
} from './user-generated-content.js';
export const scoutableSchema = z.strictObject({
id: uuidSchema,
type: z.literal('scoutable'),
name: z.string(),
userGeneratedContent: userGeneratedContentSchema,
isVisibleForParticipants: z.boolean(),
viewedByParticipants: z.boolean(),
});
export type Scoutable = Immutable<Immutable<z.infer<typeof scoutableSchema>>>;
/* When adding a new ElementType (refered to as it) to become a functioning Scoutable element, do the following:
1) add the scoutableId attribute to its class;
2) add its ElementSchema to scoutableElementSchema;
3) add its type string to scoutableElemntKeys for the indicators
4) modify its popup component to include the scoutable nav tab.
You might want the scoutable indicator to navigate to the scoutble nav directly,
so refer to the mapImages popup component for a simple implemtation.
*/
export const scoutableElementSchema = z.discriminatedUnion('type', [
mapImageSchema,
patientSchema,
]);
export type ScoutableElement = Immutable<
z.infer<typeof scoutableElementSchema>
>;
export const scoutableElementTypes = [
'patient',
'mapImage',
] satisfies ScoutableElement['type'][];
export const scoutableElementTypeSchema = z.literal(scoutableElementTypes);
export function newScoutable(): Scoutable {
return {
id: uuid(),
type: 'scoutable',
name: '',
userGeneratedContent: newUserGeneratedContent(),
isVisibleForParticipants: true,
viewedByParticipants: false,
};
}
export const scoutableImages = {
unviewed: {
generic: '/assets/scoutable-generic.png',
patient: '/assets/scoutable-patient.png',
},
viewed: {
generic: '/assets/scoutable-generic-viewed.png',
patient: '/assets/scoutable-patient-viewed.png',
},
} as const;
export function isPatientBystander(patient: Patient) {
return patient.patientStatusCode.firstField.colorCode === 'B';
}
export function isElementGenericScoutable(element: ScoutableElement) {
return element.image.url.endsWith(scoutableImages.unviewed.generic);
}