Skip to content

Commit 4030eb5

Browse files
feat: add patient tracking event
1 parent 292adfe commit 4030eb5

File tree

5 files changed

+78
-9
lines changed

5 files changed

+78
-9
lines changed

src/main/kotlin/entities/events/EventProperties.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ object EventProperties {
2727
PATIENT_SATURATION_UPDATE_EVENT("process-events"),
2828
PATIENT_HEARTBEAT_UPDATE_EVENT("process-events"),
2929
EMPTY_EVENT(""),
30+
PATIENT_TRACKED_EVENT("process-events"),
3031
TRACKING_EVENT("tracking-events"),
3132
SURGERY_BOOKINGS_EVENT("surgery-bookings-events")
3233
}

src/main/kotlin/entities/process/ProcessData.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,23 @@ object ProcessData {
3232
* @param inUse true if the medical technology is in use, false otherwise.
3333
*/
3434
data class MedicalTechnologyUsage(val medicalTechnologyID: String, val inUse: Boolean)
35+
36+
/**
37+
* The event of patient tracking inside the operating block.
38+
* @param patientId the id of the patient.
39+
* @param roomId the id of the room.
40+
* @param entered true if is entered in the room, false otherwise.
41+
* @param roomType the type of the room.
42+
*/
43+
data class PatientTracked(
44+
val patientId: String,
45+
val roomId: String,
46+
val entered: Boolean,
47+
val roomType: RoomType
48+
)
49+
50+
/** The type of the room where the patient is tracked. **/
51+
enum class RoomType {
52+
PRE_OPERATING_ROOM, OPERATING_ROOM
53+
}
3554
}

src/main/kotlin/infrastructure/digitaltwins/events/RelationshipEvents.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ object RelationshipEvents {
4141
/**
4242
* The model of the relationship source.
4343
*/
44-
val sourceModel: String
44+
val sourceModel: String,
45+
46+
/**
47+
* The model of the relationship target.
48+
*/
49+
val targetModel: String
4550
)
4651

4752
/**

src/main/kotlin/infrastructure/digitaltwins/parser/RelationshipEventParser.kt

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ import entities.events.EventProperties.EventKey
1414
import entities.events.ProcessEvent
1515
import entities.events.TrackingEvent
1616
import entities.process.ProcessData
17+
import entities.process.ProcessData.RoomType.OPERATING_ROOM
18+
import entities.process.ProcessData.RoomType.PRE_OPERATING_ROOM
1719
import infrastructure.digitaltwins.events.RelationshipEvents
1820
import infrastructure.digitaltwins.events.TwinProperties.DTModelID.HEALTH_PROFESSIONAL_MODEL_ID
21+
import infrastructure.digitaltwins.events.TwinProperties.DTModelID.PATIENT_MODEL_ID
22+
import infrastructure.digitaltwins.events.TwinProperties.DTModelID.PRE_OPERATING_ROOM_MODEL_ID
1923
import infrastructure.digitaltwins.events.TwinProperties.DTModelID.PROCESS_MODEL_ID
2024

2125
/**
@@ -38,7 +42,24 @@ class RelationshipEventParser {
3842
data = true,
3943
dateTime = createdRelationship.eventDateTime
4044
)
41-
45+
else -> EmptyEvent()
46+
}
47+
}
48+
PATIENT_MODEL_ID.id -> {
49+
when (createdRelationship.data.relationshipName) {
50+
"rel_is_inside" -> ProcessEvent(
51+
key = EventKey.PATIENT_TRACKED_EVENT,
52+
data = ProcessData.PatientTracked(
53+
patientId = createdRelationship.data.sourceId,
54+
roomId = createdRelationship.data.targetId,
55+
entered = true,
56+
roomType =
57+
if (createdRelationship.data.targetModel == PRE_OPERATING_ROOM_MODEL_ID.id)
58+
PRE_OPERATING_ROOM
59+
else OPERATING_ROOM
60+
),
61+
dateTime = createdRelationship.eventDateTime
62+
)
4263
else -> EmptyEvent()
4364
}
4465
}
@@ -65,12 +86,34 @@ class RelationshipEventParser {
6586
*/
6687
fun manageDeletedRelationship(deletedRelationship: RelationshipEvents.RelationshipEvent): Event<Any> =
6788
when (deletedRelationship.data.relationshipName) {
68-
"rel_is_inside" -> TrackingEvent(
69-
healthProfessionalId = deletedRelationship.data.sourceId,
70-
roomId = deletedRelationship.data.targetId,
71-
data = false,
72-
dateTime = deletedRelationship.eventDateTime
73-
)
89+
"rel_is_inside" -> {
90+
when (deletedRelationship.data.sourceModel) {
91+
HEALTH_PROFESSIONAL_MODEL_ID.id -> {
92+
TrackingEvent(
93+
healthProfessionalId = deletedRelationship.data.sourceId,
94+
roomId = deletedRelationship.data.targetId,
95+
data = false,
96+
dateTime = deletedRelationship.eventDateTime
97+
)
98+
}
99+
PATIENT_MODEL_ID.id -> {
100+
ProcessEvent(
101+
key = EventKey.PATIENT_TRACKED_EVENT,
102+
data = ProcessData.PatientTracked(
103+
patientId = deletedRelationship.data.sourceId,
104+
roomId = deletedRelationship.data.targetId,
105+
entered = false,
106+
roomType =
107+
if (deletedRelationship.data.targetModel == PRE_OPERATING_ROOM_MODEL_ID.id)
108+
PRE_OPERATING_ROOM
109+
else OPERATING_ROOM
110+
),
111+
dateTime = deletedRelationship.eventDateTime
112+
)
113+
}
114+
else -> EmptyEvent()
115+
}
116+
}
74117
else -> EmptyEvent()
75118
}
76119
}

src/test/resources/SampleTrackingEvent.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"$sourceId":"health1",
66
"$relationshipName":"rel_is_inside",
77
"$targetId":"ProvaOperatingRoom",
8-
"$sourceModel":"dtmi:io:github:smartoperatingblock:HealthProfessional;1"
8+
"$sourceModel":"dtmi:io:github:smartoperatingblock:HealthProfessional;1",
9+
"$targetModel":"dtmi:io:github:smartoperatingblock:OperatingRoom;1"
910
},
1011
"contenttype":"application/json",
1112
"traceparent":"00-acc18931bfbcdac4cd520dc3b08fc871-53281297c87d648b-01",

0 commit comments

Comments
 (0)