-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpatient-template.ts
123 lines (111 loc) · 4.21 KB
/
patient-template.ts
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
import { Type } from 'class-transformer';
import { IsUUID, ValidateNested } from 'class-validator';
import { cloneDeepMutable, UUID, uuid, uuidValidationOptions } from '../utils';
import { IsIdMap, IsValue } from '../utils/validators';
import type { PatientStatusCode } from './utils';
import {
BiometricInformation,
getCreate,
getStatus,
HealthPoints,
IsValidHealthPoint,
} from './utils';
import { ImageProperties } from './utils/image-properties';
import { PersonalInformation } from './utils/personal-information';
import { Patient } from './patient';
import type { FunctionParameters } from './patient-health-state';
import { PretriageInformation } from './utils/pretriage-information';
import { PatientHealthState } from './patient-health-state';
import type { Position } from './utils/position/position';
export class PatientTemplate {
@IsUUID(4, uuidValidationOptions)
public readonly id: UUID = uuid();
@IsValue('patientTemplate' as const)
public readonly type = 'patientTemplate';
@ValidateNested()
@Type(() => BiometricInformation)
public readonly biometricInformation: BiometricInformation;
@ValidateNested()
@Type(() => PretriageInformation)
public readonly pretriageInformation: PretriageInformation;
@ValidateNested()
@Type(() => ImageProperties)
public readonly image: ImageProperties;
@IsIdMap(PatientHealthState)
public readonly healthStates: {
readonly [stateId: UUID]: PatientHealthState;
};
@IsUUID(4, uuidValidationOptions)
public readonly startingHealthStateId: UUID;
@IsValidHealthPoint()
public readonly health: HealthPoints;
/**
* @deprecated Use {@link create} instead
*/
constructor(
biometricInformation: BiometricInformation,
pretriageInformation: PretriageInformation,
healthStates: { readonly [stateId: UUID]: PatientHealthState },
image: ImageProperties,
health: HealthPoints,
startingHealthStateId: UUID
) {
this.biometricInformation = biometricInformation;
this.pretriageInformation = pretriageInformation;
this.image = image;
this.healthStates = healthStates;
this.health = health;
this.startingHealthStateId = startingHealthStateId;
}
static readonly create = getCreate(this);
public static generatePatient(
template: PatientTemplate,
patientStatusCode: PatientStatusCode,
position: Position
): Patient {
// Randomize function parameters
const healthStates = Object.fromEntries(
Object.entries(cloneDeepMutable(template.healthStates)).map(
([stateId, state]) => {
const functionParameters = Object.fromEntries(
Object.entries(state.functionParameters).map(
([key, value]) => [
key as keyof FunctionParameters,
randomizeValue(value, 0.2),
]
// The signatures for Object.fromEntries and Object.entries are not made for literals...
) as [keyof FunctionParameters, any][]
) as FunctionParameters;
// The function parameters will randomize by 20%
return [
stateId,
{
...state,
functionParameters,
},
];
}
)
);
const status = getStatus(template.health);
return Patient.create(
PersonalInformation.generatePersonalInformation(
template.biometricInformation.sex
),
template.biometricInformation,
template.pretriageInformation,
patientStatusCode,
'white',
status,
healthStates,
template.startingHealthStateId,
template.image,
template.health,
'',
position
);
}
}
function randomizeValue(value: number, randomizeBy: number): number {
return value + value * (Math.random() - 0.5) * randomizeBy;
}