Skip to content

Commit 114e00a

Browse files
giacomoaccursiandrea-acampora
authored andcommitted
chore: add methods to get ImplantabelMedicalDevice and MedicalDevices from the dto
1 parent 3273fa5 commit 114e00a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/main/kotlin/application/presenter/serialization/MedicalDeviceSerializer.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import application.presenter.api.report.medicaldevice.ImplantableMedicalDeviceAp
1313
import application.presenter.api.report.medicaldevice.MedicalTechnologyApiDto
1414
import application.presenter.api.report.medicaldevice.MedicalTechnologyApiDtoType
1515
import entity.surgeryreport.medicaldevice.ImplantableMedicalDevice
16+
import entity.surgeryreport.medicaldevice.ImplantableMedicalDeviceID
1617
import entity.surgeryreport.medicaldevice.ImplantableMedicalDeviceType
1718
import entity.surgeryreport.medicaldevice.MedicalTechnology
19+
import entity.surgeryreport.medicaldevice.MedicalTechnologyID
1820
import entity.surgeryreport.medicaldevice.MedicalTechnologyType
1921

2022
/**
@@ -29,11 +31,26 @@ object MedicalDeviceSerializer {
2931
type = this.type.toApiDtoType(),
3032
)
3133

34+
/**
35+
* Extension method to obtain the an implantable medical device from dto.
36+
*/
37+
fun ImplantableMedicalDeviceApiDto.toImplantableMedicalDevice(): ImplantableMedicalDevice =
38+
ImplantableMedicalDevice(
39+
id = ImplantableMedicalDeviceID(this.id),
40+
type = this.type.toImplantableMedicalDevice(),
41+
)
42+
3243
private fun ImplantableMedicalDeviceType.toApiDtoType(): ImplantableMedicalDeviceApiDtoType = when (this) {
3344
ImplantableMedicalDeviceType.CATHETER -> ImplantableMedicalDeviceApiDtoType.CATHETER
3445
ImplantableMedicalDeviceType.PACEMAKER -> ImplantableMedicalDeviceApiDtoType.PACEMAKER
3546
}
3647

48+
private fun ImplantableMedicalDeviceApiDtoType.toImplantableMedicalDevice(): ImplantableMedicalDeviceType =
49+
when (this) {
50+
ImplantableMedicalDeviceApiDtoType.CATHETER -> ImplantableMedicalDeviceType.CATHETER
51+
ImplantableMedicalDeviceApiDtoType.PACEMAKER -> ImplantableMedicalDeviceType.PACEMAKER
52+
}
53+
3754
/**
3855
* Extension method to obtain the api dto of a medical technology.
3956
*/
@@ -45,8 +62,24 @@ object MedicalDeviceSerializer {
4562
inUse = this.inUse,
4663
)
4764

65+
/**
66+
* Extension method to obtain a medical technology from dto.
67+
*/
68+
fun MedicalTechnologyApiDto.toMedicalTechnology(): MedicalTechnology = MedicalTechnology(
69+
id = MedicalTechnologyID(this.id),
70+
name = this.name,
71+
description = this.description,
72+
type = this.type.toMedicalTechnologyType(),
73+
inUse = this.inUse,
74+
)
75+
4876
private fun MedicalTechnologyType.toApiDtoType(): MedicalTechnologyApiDtoType = when (this) {
4977
MedicalTechnologyType.ENDOSCOPE -> MedicalTechnologyApiDtoType.ENDOSCOPE
5078
MedicalTechnologyType.XRAY -> MedicalTechnologyApiDtoType.XRAY
5179
}
80+
81+
private fun MedicalTechnologyApiDtoType.toMedicalTechnologyType(): MedicalTechnologyType = when (this) {
82+
MedicalTechnologyApiDtoType.ENDOSCOPE -> MedicalTechnologyType.ENDOSCOPE
83+
MedicalTechnologyApiDtoType.XRAY -> MedicalTechnologyType.XRAY
84+
}
5285
}

0 commit comments

Comments
 (0)