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.
feat: add medical technology controller and create and findBy functio…
…nalities
- Loading branch information
1 parent
f6a7232
commit 3ac5cc2
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/kotlin/application/controller/MedicalTechnologyController.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,51 @@ | ||
/* | ||
* 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.controller | ||
|
||
import application.controller.manager.MedicalTechnologyDatabaseManager | ||
import application.controller.manager.MedicalTechnologyDigitalTwinManager | ||
import application.controller.util.rollback | ||
import entity.medicaltechnology.MedicalTechnology | ||
import entity.medicaltechnology.MedicalTechnologyID | ||
import entity.zone.RoomID | ||
import usecase.repository.MedicalTechnologyRepository | ||
import java.time.Instant | ||
|
||
/** | ||
* Implementation of medical technology repository that handle the application logic | ||
* using both db and digital twin. | ||
* @param[digitalTwinManager] the digital twin manager for medical technologies. | ||
* @param[databaseManager] the database manager for medical technologies. | ||
*/ | ||
class MedicalTechnologyController( | ||
private val digitalTwinManager: MedicalTechnologyDigitalTwinManager, | ||
private val databaseManager: MedicalTechnologyDatabaseManager | ||
) : MedicalTechnologyRepository { | ||
override fun createMedicalTechnology(medicalTechnology: MedicalTechnology): MedicalTechnology? = ( | ||
this.digitalTwinManager.createMedicalTechnologyDigitalTwin(medicalTechnology) && | ||
this.databaseManager.saveMedicalTechnology(medicalTechnology).rollback { | ||
this.digitalTwinManager.deleteMedicalTechnologyDigitalTwin(medicalTechnology.id) | ||
} | ||
).let { if (it) medicalTechnology else null } | ||
|
||
override fun deleteMedicalTechnology(medicalTechnologyId: MedicalTechnologyID): Boolean { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun findBy(medicalTechnologyId: MedicalTechnologyID, dateTime: Instant?): MedicalTechnology? = | ||
if (dateTime == null) { // if the date-time is null, then obtain present information | ||
this.digitalTwinManager.findBy(medicalTechnologyId) | ||
} else { | ||
this.databaseManager.findBy(medicalTechnologyId, dateTime) | ||
} | ||
|
||
override fun mapTechnologyTo(medicalTechnologyId: MedicalTechnologyID, roomId: RoomID): Boolean { | ||
TODO("Not yet implemented") | ||
} | ||
} |