Skip to content

Commit

Permalink
material template + material and personnel having own thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
anonym-HPI committed Jul 1, 2022
1 parent fd9f459 commit e3d6f47
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 96 deletions.
22 changes: 22 additions & 0 deletions shared/src/data/default-state/material-templates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CanCaterFor } from '../../models/utils';
import { MaterialTemplate } from '../../models/material-template';
import type { MaterialType } from '../../models/utils/material-type';

const defaultMaterialTemplate = MaterialTemplate.create(
'default',
{
url: '/assets/material.svg',
height: 40,
aspectRatio: 1,
},
CanCaterFor.create(2, 2, 2, 'or'),
0.5,
5,
false
);

export const materialTemplateMap: {
[key in MaterialType]: MaterialTemplate;
} = {
default: defaultMaterialTemplate,
};
10 changes: 10 additions & 0 deletions shared/src/data/default-state/personnel-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const sanPersonnelTemplate = PersonnelTemplate.create(
aspectRatio: 1,
},
CanCaterFor.create(0, 0, 5, 'or'),
0.5,
5,
false
);

Expand All @@ -21,6 +23,8 @@ const rettSanPersonnelTemplate = PersonnelTemplate.create(
aspectRatio: 1,
},
CanCaterFor.create(1, 2, 0, 'and'),
0.5,
5,
false
);

Expand All @@ -32,6 +36,8 @@ const notSanPersonnelTemplate = PersonnelTemplate.create(
aspectRatio: 1,
},
CanCaterFor.create(2, 1, 0, 'and'),
0.5,
5,
false
);

Expand All @@ -44,6 +50,8 @@ const notarztPersonnelTemplate = PersonnelTemplate.create(
},
// TODO: give notarzt aura
CanCaterFor.create(2, 2, 2, 'and'),
20,
0,
true
);

Expand All @@ -55,6 +63,8 @@ const gfPersonnelTemplate = PersonnelTemplate.create(
aspectRatio: 1,
},
CanCaterFor.create(0, 0, 0, 'or'),
0,
0,
false
);

Expand Down
92 changes: 12 additions & 80 deletions shared/src/data/default-state/vehicle-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,7 @@ const rtwVehicleTemplate = VehicleTemplate.create(
rtwImage,
2,
['notSan', 'rettSan'],
[
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
]
['default']
);

const ktwVehicleTemplate = VehicleTemplate.create(
Expand All @@ -53,14 +46,7 @@ const ktwVehicleTemplate = VehicleTemplate.create(
ktwImage,
2,
['san', 'rettSan'],
[
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
]
['default']
);

const gwSanVehicleTemplate = VehicleTemplate.create(
Expand All @@ -70,54 +56,14 @@ const gwSanVehicleTemplate = VehicleTemplate.create(
0,
['gf', 'rettSan', 'rettSan', 'san', 'san', 'notarzt'],
[
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
'default',
'default',
'default',
'default',
'default',
'default',
'default',
'default',
]
);

Expand All @@ -127,14 +73,7 @@ const nefVehicleTemplate = VehicleTemplate.create(
nefImage,
0,
['notarzt', 'notSan'],
[
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
]
['default']
);

const rthVehicleTemplate = VehicleTemplate.create(
Expand All @@ -143,14 +82,7 @@ const rthVehicleTemplate = VehicleTemplate.create(
rthImage,
1,
['notarzt', 'notSan'],
[
{
logicalOperator: 'and',
green: 0,
yellow: 0,
red: 2,
},
]
['default']
);

export const defaultVehicleTemplates: readonly VehicleTemplate[] = [
Expand Down
55 changes: 55 additions & 0 deletions shared/src/models/material-template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Type } from 'class-transformer';
import {
IsBoolean,
IsNumber,
IsString,
Min,
ValidateNested,
} from 'class-validator';
import { CanCaterFor, ImageProperties, getCreate } from './utils';
import { MaterialType } from './utils/material-type';

export class MaterialTemplate {
@IsString()
public readonly materialType: MaterialType;

@ValidateNested()
@Type(() => CanCaterFor)
public readonly canCaterFor: CanCaterFor;

@IsNumber()
@Min(0)
public readonly specificThreshold: number;

@IsNumber()
@Min(0)
public readonly generalThreshold: number;

@IsBoolean()
public readonly auraMode: boolean;

@ValidateNested()
@Type(() => ImageProperties)
public readonly image: ImageProperties;

/**
* @deprecated Use {@link create} instead
*/
constructor(
materialType: MaterialType,
image: ImageProperties,
canCaterFor: CanCaterFor,
specificThreshold: number,
generalThreshold: number,
auraMode: boolean
) {
this.materialType = materialType;
this.image = image;
this.canCaterFor = canCaterFor;
this.specificThreshold = specificThreshold;
this.generalThreshold = generalThreshold;
this.auraMode = auraMode;
}

static readonly create = getCreate(this);
}
27 changes: 20 additions & 7 deletions shared/src/models/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { Type } from 'class-transformer';
import {
IsBoolean,
IsDefined,
IsNumber,
IsOptional,
IsString,
IsUUID,
Min,
ValidateNested,
} from 'class-validator';
import { materialTemplateMap } from '../data/default-state/material-templates';
import { uuid, UUID, UUIDSet, uuidValidationOptions } from '../utils';
import { CanCaterFor, getCreate, ImageProperties, Position } from './utils';
import type { MaterialType } from './utils/material-type';

export class Material {
@IsUUID(4, uuidValidationOptions)
Expand All @@ -28,6 +32,14 @@ export class Material {
@Type(() => CanCaterFor)
public readonly canCaterFor: CanCaterFor;

@IsNumber()
@Min(0)
public readonly specificThreshold: number;

@IsNumber()
@Min(0)
public readonly generalThreshold: number;

@IsBoolean()
public readonly auraMode: boolean;

Expand All @@ -41,29 +53,30 @@ export class Material {

@ValidateNested()
@Type(() => ImageProperties)
public readonly image: ImageProperties = {
url: './assets/material.svg',
height: 40,
aspectRatio: 1,
};
public readonly image: ImageProperties;

/**
* @deprecated Use {@link create} instead
*/
constructor(
vehicleId: UUID,
vehicleName: string,
canCaterFor: CanCaterFor,
materialType: MaterialType,
assignedPatientIds: UUIDSet,
position?: Position,
auraMode: boolean = false
) {
this.vehicleId = vehicleId;
this.vehicleName = vehicleName;
this.canCaterFor = canCaterFor;
this.assignedPatientIds = assignedPatientIds;
this.position = position;
this.auraMode = auraMode;
this.image = materialTemplateMap[materialType]?.image;
this.canCaterFor = materialTemplateMap[materialType]?.canCaterFor;
this.generalThreshold =
materialTemplateMap[materialType]?.generalThreshold;
this.specificThreshold =
materialTemplateMap[materialType]?.specificThreshold;
}

static readonly create = getCreate(this);
Expand Down
20 changes: 19 additions & 1 deletion shared/src/models/personnel-template.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Type } from 'class-transformer';
import { IsBoolean, IsString, ValidateNested } from 'class-validator';
import {
IsBoolean,
IsNumber,
IsString,
Min,
ValidateNested,
} from 'class-validator';
import {
CanCaterFor,
ImageProperties,
Expand All @@ -15,6 +21,14 @@ export class PersonnelTemplate {
@Type(() => CanCaterFor)
public readonly canCaterFor: CanCaterFor;

@IsNumber()
@Min(0)
public readonly specificThreshold: number;

@IsNumber()
@Min(0)
public readonly generalThreshold: number;

@IsBoolean()
public readonly auraMode: boolean;

Expand All @@ -29,11 +43,15 @@ export class PersonnelTemplate {
personnelType: PersonnelType,
image: ImageProperties,
canCaterFor: CanCaterFor,
specificThreshold: number,
generalThreshold: number,
auraMode: boolean
) {
this.personnelType = personnelType;
this.image = image;
this.canCaterFor = canCaterFor;
this.specificThreshold = specificThreshold;
this.generalThreshold = generalThreshold;
this.auraMode = auraMode;
}

Expand Down
Loading

0 comments on commit e3d6f47

Please sign in to comment.