generated from SmartOperatingBlock/kotlin-template-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move patient event handlers to dedicated object
- Loading branch information
1 parent
8bebf08
commit b697871
Showing
3 changed files
with
220 additions
and
189 deletions.
There are no files selected for viewing
204 changes: 204 additions & 0 deletions
204
src/main/kotlin/application/handler/PatientEventHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
/* | ||
* Copyright (c) 2023. Smart Operating Block | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
package application.handler | ||
|
||
import application.handler.ProcessEventHandlers.cast | ||
import application.presenter.event.model.Event | ||
import application.presenter.event.model.ProcessEvent | ||
import application.presenter.event.model.payloads.ProcessEventsPayloads | ||
import application.service.PatientDataServices | ||
import application.service.SurgicalProcessServices | ||
import entity.patient.PatientData | ||
import entity.process.ProcessData | ||
import usecase.repository.PatientRepository | ||
import usecase.repository.SurgicalProcessRepository | ||
import java.time.Instant | ||
|
||
/** | ||
* Module that contains all the handlers for patient events. | ||
*/ | ||
object PatientEventHandlers { | ||
|
||
/** | ||
* The handler for process information events. | ||
*/ | ||
class PatientOnOperatingTableEventHandler( | ||
private val surgicalProcessRepository: SurgicalProcessRepository | ||
) : EventHandler { | ||
|
||
override fun canHandle(event: Event<*>): Boolean = event.cast<ProcessEvent<*>> { | ||
this.data.cast<ProcessEventsPayloads.PatientOnOperatingTable>() | ||
} | ||
|
||
override fun consume(event: Event<*>) { | ||
event.cast<ProcessEvent<ProcessEventsPayloads.PatientOnOperatingTable>> { | ||
SurgicalProcessServices.UpdateSurgicalProcessState( | ||
ProcessData.ProcessId(this.data.processId), | ||
Instant.parse(this.dateTime), | ||
ProcessData.ProcessState.SURGERY, | ||
surgicalProcessRepository | ||
).execute() && | ||
SurgicalProcessServices.UpdateSurgicalProcessStep( | ||
ProcessData.ProcessId(this.data.processId), | ||
Instant.parse(this.dateTime), | ||
ProcessData.ProcessStep.PATIENT_ON_OPERATING_TABLE, | ||
surgicalProcessRepository | ||
).execute() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The handler for Patient Body Temperature update events. | ||
*/ | ||
class BodyTemperatureUpdateEventHandler( | ||
private val patientRepository: PatientRepository | ||
) : EventHandler { | ||
|
||
override fun canHandle(event: Event<*>): Boolean = event.cast<ProcessEvent<*>> { | ||
this.data.cast<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.BodyTemperature>>() | ||
} | ||
|
||
override fun consume(event: Event<*>) { | ||
event.cast<ProcessEvent<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.BodyTemperature>>> { | ||
PatientDataServices.UpdatePatientMedicalData( | ||
PatientData.PatientId(this.data.patientId), | ||
PatientData.MedicalData(bodyTemperature = PatientData.BodyTemperature(this.data.data.temperature)), | ||
Instant.parse(this.dateTime), | ||
patientRepository | ||
).execute() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The handler for Patient Diastolic Pressure update events. | ||
*/ | ||
class DiastolicPressureUpdateEventHandler( | ||
private val patientRepository: PatientRepository | ||
) : EventHandler { | ||
|
||
override fun canHandle(event: Event<*>): Boolean = event.cast<ProcessEvent<*>> { | ||
this.data.cast<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.DiastolicPressure>>() | ||
} | ||
|
||
override fun consume(event: Event<*>) { | ||
event.cast<ProcessEvent<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.DiastolicPressure>>> { | ||
PatientDataServices.UpdatePatientMedicalData( | ||
PatientData.PatientId(this.data.patientId), | ||
PatientData.MedicalData( | ||
diastolicBloodPressure = PatientData.DiastolicBloodPressure(this.data.data.pressure) | ||
), | ||
Instant.parse(this.dateTime), | ||
patientRepository | ||
).execute() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The handler for Patient Systolic Pressure update events. | ||
*/ | ||
class SystolicPressureUpdateEventHandler( | ||
private val patientRepository: PatientRepository | ||
) : EventHandler { | ||
|
||
override fun canHandle(event: Event<*>): Boolean = event.cast<ProcessEvent<*>> { | ||
this.data.cast<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.SystolicPressure>>() | ||
} | ||
|
||
override fun consume(event: Event<*>) { | ||
event.cast<ProcessEvent<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.SystolicPressure>>> { | ||
PatientDataServices.UpdatePatientMedicalData( | ||
PatientData.PatientId(this.data.patientId), | ||
PatientData.MedicalData( | ||
systolicBloodPressure = PatientData.SystolicBloodPressure(this.data.data.pressure) | ||
), | ||
Instant.parse(this.dateTime), | ||
patientRepository | ||
).execute() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The handler for Patient Diastolic Pressure update events. | ||
*/ | ||
class RespiratoryRateUpdateEventHandler( | ||
private val patientRepository: PatientRepository | ||
) : EventHandler { | ||
|
||
override fun canHandle(event: Event<*>): Boolean = event.cast<ProcessEvent<*>> { | ||
this.data.cast<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.RespiratoryRate>>() | ||
} | ||
|
||
override fun consume(event: Event<*>) { | ||
event.cast<ProcessEvent<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.RespiratoryRate>>> { | ||
PatientDataServices.UpdatePatientMedicalData( | ||
PatientData.PatientId(this.data.patientId), | ||
PatientData.MedicalData( | ||
respiratoryRate = PatientData.RespiratoryRate(this.data.data.rate) | ||
), | ||
Instant.parse(this.dateTime), | ||
patientRepository | ||
).execute() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The handler for Patient saturation update events. | ||
*/ | ||
class SaturationUpdateEventHandler( | ||
private val patientRepository: PatientRepository | ||
) : EventHandler { | ||
|
||
override fun canHandle(event: Event<*>): Boolean = event.cast<ProcessEvent<*>> { | ||
this.data.cast<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.Saturation>>() | ||
} | ||
|
||
override fun consume(event: Event<*>) { | ||
event.cast<ProcessEvent<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.Saturation>>> { | ||
PatientDataServices.UpdatePatientMedicalData( | ||
PatientData.PatientId(this.data.patientId), | ||
PatientData.MedicalData( | ||
saturationPercentage = PatientData.SaturationPercentage(this.data.data.saturation) | ||
), | ||
Instant.parse(this.dateTime), | ||
patientRepository | ||
).execute() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The handler for Patient heart beat update events. | ||
*/ | ||
class HeartbeatUpdateEventHandler( | ||
private val patientRepository: PatientRepository | ||
) : EventHandler { | ||
|
||
override fun canHandle(event: Event<*>): Boolean = event.cast<ProcessEvent<*>> { | ||
this.data.cast<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.Heartbeat>>() | ||
} | ||
|
||
override fun consume(event: Event<*>) { | ||
event.cast<ProcessEvent<ProcessEventsPayloads.PatientData<ProcessEventsPayloads.Heartbeat>>> { | ||
PatientDataServices.UpdatePatientMedicalData( | ||
PatientData.PatientId(this.data.patientId), | ||
PatientData.MedicalData( | ||
heartBeat = PatientData.HeartBeat(this.data.data.heartbeat) | ||
), | ||
Instant.parse(this.dateTime), | ||
patientRepository | ||
).execute() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.