Skip to content

Commit

Permalink
fix: manage unhandled process interruption
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-acampora committed Jun 5, 2023
1 parent e82a9a4 commit 4f228d4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
30 changes: 29 additions & 1 deletion src/main/kotlin/application/handler/ProcessEventHandlers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package application.handler

import application.controller.manager.EventProducer
import application.handler.ProcessEventHandlers.cast
import application.presenter.event.model.Event
import application.presenter.event.model.ProcessEvent
import application.presenter.event.model.SurgeryReportEvent
Expand Down Expand Up @@ -366,6 +365,9 @@ object ProcessEventHandlers {
*/
class ProcessManualEventHandler(
private val surgicalProcessRepository: SurgicalProcessRepository,
private val surgeryBookingRepository: BookingRepository,
private val patientRepository: PatientRepository,
private val medicalDeviceRepository: MedicalDeviceRepository,
) : EventHandler {

override fun canHandle(event: Event<*>): Boolean = event.cast<ProcessEvent<*>> {
Expand Down Expand Up @@ -399,6 +401,32 @@ object ProcessEventHandlers {
ProcessData.ProcessState.valueOf(this.data.manualEvent),
surgicalProcessRepository,
).execute()
SurgicalProcessServices.DeleteSurgicalProcess(
surgicalProcess.id,
surgicalProcessRepository,
).execute()
SurgeryBookingServices.GetSurgeryBookingByPatient(
PatientData.PatientId(surgicalProcess.patientId.id),
surgeryBookingRepository,
).execute()?.let { booking ->
SurgeryBookingServices.DeleteSurgeryBooking(
booking.id,
surgeryBookingRepository,
).execute()
PatientDataServices.DeletePatient(
surgicalProcess.patientId,
patientRepository,
).execute()
MedicalDeviceServices.GetMedicalDeviceUsageByProcessId(
surgicalProcess.id,
medicalDeviceRepository,
).execute().forEach { device ->
MedicalDeviceServices.DeleteImplantableMedicalDevice(
device,
medicalDeviceRepository,
).execute()
}
}
}
else -> {}
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/infrastructure/event/KafkaClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ class KafkaClient(private val provider: ManagerProvider) : EventProducer {
this,
),
ProcessEventHandlers.EmergencySurgeryEventHandler(surgicalProcessController, patientDataController),
ProcessEventHandlers.ProcessManualEventHandler(surgicalProcessController),
ProcessEventHandlers.ProcessManualEventHandler(
surgicalProcessController,
surgeryBookingController,
patientDataController,
medicalDeviceController,
),
)
}

Expand Down

0 comments on commit 4f228d4

Please sign in to comment.