@@ -12,8 +12,14 @@ import application.presenter.api.report.measurements.ValueWithUnit
1212import application.presenter.api.report.room.RoomApiDto
1313import application.presenter.api.report.room.RoomApiDtoType
1414import application.presenter.api.report.room.RoomEnvironmentalDataApiDto
15+ import entity.surgeryreport.measurements.Humidity
16+ import entity.surgeryreport.measurements.Luminosity
17+ import entity.surgeryreport.measurements.Percentage
18+ import entity.surgeryreport.measurements.Presence
19+ import entity.surgeryreport.measurements.Temperature
1520import entity.surgeryreport.room.Room
1621import entity.surgeryreport.room.RoomEnvironmentalData
22+ import entity.surgeryreport.room.RoomID
1723import entity.surgeryreport.room.RoomType
1824
1925/* *
@@ -28,6 +34,14 @@ object RoomSerializer {
2834 type = this .type.toApiDtoType(),
2935 )
3036
37+ /* *
38+ * Extension method to obtain the room from the dto.
39+ */
40+ fun RoomApiDto.toRoom (): Room = Room (
41+ RoomID (this .id),
42+ this .type.toRoomType(),
43+ )
44+
3145 /* *
3246 * Extension method to obtain the api dto type of a room.
3347 */
@@ -36,6 +50,14 @@ object RoomSerializer {
3650 RoomType .PRE_OPERATING_ROOM -> RoomApiDtoType .PRE_OPERATING_ROOM
3751 }
3852
53+ /* *
54+ * Extension method to obtain the room type from the api dto.
55+ */
56+ fun RoomApiDtoType.toRoomType () = when (this ) {
57+ RoomApiDtoType .OPERATING_ROOM -> RoomType .OPERATING_ROOM
58+ RoomApiDtoType .PRE_OPERATING_ROOM -> RoomType .PRE_OPERATING_ROOM
59+ }
60+
3961 /* *
4062 * Extension method to obtain the api dto of room environmental data.
4163 */
@@ -45,4 +67,14 @@ object RoomSerializer {
4567 luminosity = this .luminosity?.let { ValueWithUnit (it.value, it.unit.toString()) },
4668 presence = this .presence?.presenceDetected,
4769 )
70+
71+ /* *
72+ * Extension method to obtain room environmental data from dto.
73+ */
74+ fun RoomEnvironmentalDataApiDto.toRoomEnvironmentalData () = RoomEnvironmentalData (
75+ temperature = this .temperature?.let { Temperature (it.value) },
76+ humidity = this .humidity?.let { Percentage (it) }?.let { Humidity (it) },
77+ luminosity = this .luminosity?.let { Luminosity (it.value) },
78+ presence = this .presence?.let { Presence (it) },
79+ )
4880}
0 commit comments