Skip to content

Commit

Permalink
chore: add latest room id in update room method
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-acampora committed May 8, 2023
1 parent 20dcfd4 commit c51ffd1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ class SurgicalProcessController(
this.processDigitalTwinManager.updateSurgicalProcessStep(processId, step) &&
this.processDatabaseManager.updateSurgicalProcessStep(processId, dateTime, step)

override fun updateSurgicalProcessRoom(processId: ProcessData.ProcessId, room: Room): Boolean =
this.processDigitalTwinManager.updateSurgicalProcessRoom(processId, room) &&
this.processDatabaseManager.updateSurgicalProcessRoom(processId, room)
override fun updateSurgicalProcessRoom(
processId: ProcessData.ProcessId,
latestRoomId: String?,
room: Room
): Boolean =
this.processDigitalTwinManager.updateSurgicalProcessRoom(processId, latestRoomId, room) &&
this.processDatabaseManager.updateSurgicalProcessRoom(processId, latestRoomId, room)

override fun getSurgicalProcessStates(
surgicalProcessId: ProcessData.ProcessId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface ProcessDigitalTwinManager {
*/
fun updateSurgicalProcessRoom(
processId: ProcessData.ProcessId,
latestRoomId: String?,
room: Room
): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ object SurgicalProcessServices {
*/
class UpdateSurgicalProcessRoom(
private val surgicalProcessId: ProcessData.ProcessId,
private val latestRoomId: String?,
private val room: Room,
private val surgicalProcessRepository: SurgicalProcessRepository
) : ApplicationService<Boolean> {
override fun execute(): Boolean =
surgicalProcessRepository.updateSurgicalProcessRoom(surgicalProcessId, room)
surgicalProcessRepository.updateSurgicalProcessRoom(surgicalProcessId, latestRoomId, room)
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/infrastructure/database/DatabaseManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ class DatabaseManager(
.wasAcknowledged()
}

override fun updateSurgicalProcessRoom(processId: ProcessData.ProcessId, room: Room): Boolean =
override fun updateSurgicalProcessRoom(
processId: ProcessData.ProcessId,
latestRoomId: String?,
room: Room
): Boolean =
when (room.type) {
RoomData.RoomType.PRE_POST_OPERATING_ROOM -> {
this.surgicalProcessCollection.safeMongoDbWrite(false) {
Expand Down
13 changes: 9 additions & 4 deletions src/main/kotlin/infrastructure/digitaltwin/DigitalTwinManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ class DigitalTwinManager :
),
BasicRelationship::class.java
)
process.preOperatingRoom?.let { room -> updateSurgicalProcessRoom(process.id, room) }
process.operatingRoom?.let { room -> updateSurgicalProcessRoom(process.id, room) }
process.preOperatingRoom?.let { room ->
updateSurgicalProcessRoom(process.id, null, room)
}
}
true
}
Expand All @@ -160,10 +161,14 @@ class DigitalTwinManager :
true
}

override fun updateSurgicalProcessRoom(processId: ProcessData.ProcessId, room: Room): Boolean =
override fun updateSurgicalProcessRoom(
processId: ProcessData.ProcessId,
latestRoomId: String?,
room: Room
): Boolean =
this.dtClient.applySafeDigitalTwinOperation(false) {
this.listRelationships(processId.id, BasicRelationship::class.java).forEach {
if (it.targetId == room.id.id) {
if (it.targetId == latestRoomId) {
this.deleteRelationship(it.sourceId, it.id)
}
}.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ interface SurgicalProcessRepository {
): Boolean

/**
* Update the [room] of a [SurgicalProcess] by its [processId].
* Update the [room] and the previous [latestRoomId] of a [SurgicalProcess] by its [processId].
*/
fun updateSurgicalProcessRoom(
processId: ProcessData.ProcessId,
latestRoomId: String?,
room: Room
): Boolean

Expand Down

0 comments on commit c51ffd1

Please sign in to comment.