Skip to content

Commit

Permalink
Allow specifying a next occupation (#977)
Browse files Browse the repository at this point in the history
* Add successorOccupation to everything

* Use successorOccupation even more
  • Loading branch information
Nils1729 authored May 11, 2023
1 parent ec2d28f commit 9a22fcf
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 15 deletions.
14 changes: 12 additions & 2 deletions shared/src/simulation/activities/load-vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import {
Min,
} from 'class-validator';
import { difference } from 'lodash-es';
import { Type } from 'class-transformer';
import {
ExerciseOccupation,
SimulatedRegionPosition,
VehiclePosition,
getCreate,
isInSpecificSimulatedRegion,
occupationTypeOptions,
} from '../../models/utils';
import {
UUID,
Expand Down Expand Up @@ -84,6 +87,10 @@ export class LoadVehicleActivityState implements SimulationActivityState {
@Min(0)
public readonly startTime: number = 0;

@IsOptional()
@Type(...occupationTypeOptions)
readonly successorOccupation?: ExerciseOccupation;

/**
* @deprecated Use {@link create} instead
*/
Expand All @@ -95,7 +102,8 @@ export class LoadVehicleActivityState implements SimulationActivityState {
patientsToBeLoaded: UUIDSet,
loadTimePerPatient: number,
personnelLoadTime: number,
key?: string
key?: string,
successorOccupation?: ExerciseOccupation
) {
this.id = id;
this.vehicleId = vehicleId;
Expand All @@ -105,6 +113,7 @@ export class LoadVehicleActivityState implements SimulationActivityState {
this.loadTimePerPatient = loadTimePerPatient;
this.personnelLoadTime = personnelLoadTime;
this.key = key;
this.successorOccupation = successorOccupation;
}

static readonly create = getCreate(this);
Expand Down Expand Up @@ -275,7 +284,8 @@ export const loadVehicleActivity: SimulationActivity<LoadVehicleActivityState> =
activityState.vehicleId,
activityState.transferDestinationType,
activityState.transferDestinationId,
activityState.key
activityState.key,
cloneDeepMutable(activityState.successorOccupation)
)
);

Expand Down
19 changes: 16 additions & 3 deletions shared/src/simulation/activities/transfer-vehicle.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { IsOptional, IsString, IsUUID } from 'class-validator';
import { Type } from 'class-transformer';
import {
MissingTransferConnectionRadiogram,
RadiogramUnpublishedStatus,
} from '../../models/radiogram';
import { publishRadiogram } from '../../models/radiogram/radiogram-helpers-mutable';
import {
ExerciseOccupation,
getCreate,
isInSpecificSimulatedRegion,
isInSpecificVehicle,
NoOccupation,
occupationTypeOptions,
TransferStartPoint,
} from '../../models/utils';
import { VehicleResource } from '../../models/utils/rescue-resource';
Expand Down Expand Up @@ -52,6 +55,10 @@ export class TransferVehicleActivityState implements SimulationActivityState {
@IsUUID(4, uuidValidationOptions)
readonly transferDestinationId: UUID;

@IsOptional()
@Type(...occupationTypeOptions)
readonly successorOccupation?: ExerciseOccupation;

@IsOptional()
@IsString()
readonly key?: string;
Expand All @@ -64,14 +71,16 @@ export class TransferVehicleActivityState implements SimulationActivityState {
vehicleId: UUID,
transferDestinationType: TransferDestination,
transferDestinationId: UUID,
key?: string
key?: string,
successorOccupation?: ExerciseOccupation
) {
this.id = id;
this.vehicleId = vehicleId;

this.transferDestinationType = transferDestinationType;
this.transferDestinationId = transferDestinationId;
this.key = key;
this.successorOccupation = successorOccupation;
}

static readonly create = getCreate(this);
Expand Down Expand Up @@ -157,7 +166,9 @@ export const transferVehicleActivity: SimulationActivity<TransferVehicleActivity

// Do transfer and send event

vehicle.occupation = cloneDeepMutable(NoOccupation.create());
vehicle.occupation = cloneDeepMutable(
activityState.successorOccupation ?? NoOccupation.create()
);

TransferActionReducers.addToTransfer.reducer(draftState, {
type: '[Transfer] Add to transfer',
Expand Down Expand Up @@ -207,7 +218,9 @@ export const transferVehicleActivity: SimulationActivity<TransferVehicleActivity

// Do transfer and send event

vehicle.occupation = cloneDeepMutable(NoOccupation.create());
vehicle.occupation = cloneDeepMutable(
activityState.successorOccupation ?? NoOccupation.create()
);

HospitalActionReducers.transportPatientToHospital.reducer(
draftState,
Expand Down
13 changes: 10 additions & 3 deletions shared/src/simulation/behaviors/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ export const transferBehavior: SimulationBehavior<TransferBehaviorState> = {
event.transferDestinationId,
{},
behaviorState.loadTimePerPatient,
behaviorState.personnelLoadTime
behaviorState.personnelLoadTime,
undefined,
event.successorOccupation
)
);
vehicle.occupation = cloneDeepMutable(
Expand Down Expand Up @@ -279,7 +281,11 @@ export const transferBehavior: SimulationBehavior<TransferBehaviorState> = {
event.transferDestinationId,
{},
behaviorState.loadTimePerPatient,
behaviorState.personnelLoadTime
behaviorState.personnelLoadTime,
undefined,
cloneDeepMutable(
event.successorOccupation
)
)
);
loadableVehicles![index]!.occupation =
Expand Down Expand Up @@ -404,7 +410,8 @@ export const transferBehavior: SimulationBehavior<TransferBehaviorState> = {
vehicle.id,
transferEvent!.transferDestinationType,
transferEvent!.transferDestinationId,
transferEvent!.key
transferEvent!.key,
cloneDeepMutable(transferEvent!.successorOccupation)
)
);
}
Expand Down
15 changes: 13 additions & 2 deletions shared/src/simulation/events/start-transfer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { IsOptional, IsString, IsUUID } from 'class-validator';
import { getCreate } from '../../models/utils';
import { Type } from 'class-transformer';
import {
ExerciseOccupation,
getCreate,
occupationTypeOptions,
} from '../../models/utils';
import { UUID, uuidValidationOptions } from '../../utils';
import { IsLiteralUnion, IsValue } from '../../utils/validators';
import {
Expand All @@ -25,19 +30,25 @@ export class StartTransferEvent implements SimulationEvent {
@IsString()
readonly key?: string;

@IsOptional()
@Type(...occupationTypeOptions)
readonly successorOccupation?: ExerciseOccupation;

/**
* @deprecated Use {@link create} instead
*/
constructor(
vehicleId: UUID,
transferDestinationType: TransferDestination,
transferDestinationId: UUID,
key?: string
key?: string,
successorOccupation?: ExerciseOccupation
) {
this.vehicleId = vehicleId;
this.transferDestinationType = transferDestinationType;
this.transferDestinationId = transferDestinationId;
this.key = key;
this.successorOccupation = successorOccupation;
}

static readonly create = getCreate(this);
Expand Down
17 changes: 14 additions & 3 deletions shared/src/simulation/events/transfer-specific-vehicle-request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { IsUUID } from 'class-validator';
import { getCreate } from '../../models/utils';
import { IsOptional, IsUUID } from 'class-validator';
import { Type } from 'class-transformer';
import {
ExerciseOccupation,
getCreate,
occupationTypeOptions,
} from '../../models/utils';
import { UUID, uuidValidationOptions } from '../../utils';
import { IsLiteralUnion, IsValue } from '../../utils/validators';
import {
Expand All @@ -21,17 +26,23 @@ export class TransferSpecificVehicleRequestEvent implements SimulationEvent {
@IsUUID(4, uuidValidationOptions)
readonly transferDestinationId: UUID;

@IsOptional()
@Type(...occupationTypeOptions)
readonly successorOccupation?: ExerciseOccupation;

/**
* @deprecated Use {@link create} instead
*/
constructor(
vehicleId: UUID,
transferDestinationType: TransferDestination,
transferDestinationId: UUID
transferDestinationId: UUID,
successorOccupation?: ExerciseOccupation
) {
this.vehicleId = vehicleId;
this.transferDestinationType = transferDestinationType;
this.transferDestinationId = transferDestinationId;
this.successorOccupation = successorOccupation;
}

static readonly create = getCreate(this);
Expand Down
15 changes: 13 additions & 2 deletions shared/src/simulation/events/transfer-vehicles-request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { IsOptional, IsString, IsUUID } from 'class-validator';
import { getCreate } from '../../models/utils';
import { Type } from 'class-transformer';
import {
ExerciseOccupation,
getCreate,
occupationTypeOptions,
} from '../../models/utils';
import { IsLiteralUnion, IsValue } from '../../utils/validators';
import { ResourceDescription } from '../../models/utils/resource-description';
import { IsResourceDescription } from '../../utils/validators/is-resource-description';
Expand All @@ -23,6 +28,10 @@ export class TransferVehiclesRequestEvent implements SimulationEvent {
@IsUUID(4, uuidValidationOptions)
readonly transferDestinationId: UUID;

@IsOptional()
@Type(...occupationTypeOptions)
readonly successorOccupation?: ExerciseOccupation;

@IsOptional()
@IsString()
readonly key?: string;
Expand All @@ -34,12 +43,14 @@ export class TransferVehiclesRequestEvent implements SimulationEvent {
requestedVehicles: ResourceDescription,
transferDestinationType: TransferDestination,
transferDestinationId: UUID,
key?: string
key?: string,
successorOccupation?: ExerciseOccupation
) {
this.requestedVehicles = requestedVehicles;
this.transferDestinationType = transferDestinationType;
this.transferDestinationId = transferDestinationId;
this.key = key;
this.successorOccupation = successorOccupation;
}

static readonly create = getCreate(this);
Expand Down

0 comments on commit 9a22fcf

Please sign in to comment.