|
| 1 | +/* |
| 2 | + * Copyright (c) 2023. Smart Operating Block |
| 3 | + * |
| 4 | + * Use of this source code is governed by an MIT-style |
| 5 | + * license that can be found in the LICENSE file or at |
| 6 | + * https://opensource.org/licenses/MIT. |
| 7 | + */ |
| 8 | + |
| 9 | +package infrastructure.digitaltwins.parser |
| 10 | + |
| 11 | +import entities.events.EmptyEvent |
| 12 | +import entities.events.Event |
| 13 | +import entities.events.ProcessEvent |
| 14 | +import entities.events.TrackingEvent |
| 15 | +import entities.process.ProcessData |
| 16 | +import infrastructure.digitaltwins.events.RelationshipEvents |
| 17 | +import infrastructure.digitaltwins.events.TwinProperties.DTModelID.PROCESS_MODEL_ID |
| 18 | +import infrastructure.digitaltwins.events.TwinProperties.DTModelID.HEALTH_PROFESSIONAL_MODEL_ID |
| 19 | + |
| 20 | +/** |
| 21 | + * The parser of Azure Digital Twins Relationship Events. |
| 22 | + */ |
| 23 | +class RelationshipEventParser { |
| 24 | + |
| 25 | + /** |
| 26 | + * Manage the event of creation of a relationship between Digital Twins. |
| 27 | + * @param createdRelationship the relationship. |
| 28 | + *@return the specific [Event]. |
| 29 | + */ |
| 30 | + fun manageCreatedRelationship(createdRelationship: RelationshipEvents.RelationshipEvent): Event<Any> = |
| 31 | + when (createdRelationship.data.sourceModel) { |
| 32 | + HEALTH_PROFESSIONAL_MODEL_ID.id -> { |
| 33 | + when (createdRelationship.data.relationshipName) { |
| 34 | + "rel_is_inside" -> TrackingEvent( |
| 35 | + healthProfessionalId = createdRelationship.data.sourceId, |
| 36 | + roomId = createdRelationship.data.targetId, |
| 37 | + data = true, |
| 38 | + dateTime = createdRelationship.eventDateTime |
| 39 | + ) |
| 40 | + |
| 41 | + else -> EmptyEvent() |
| 42 | + } |
| 43 | + } |
| 44 | + PROCESS_MODEL_ID.id -> { |
| 45 | + when (createdRelationship.data.relationshipName) { |
| 46 | + "rel_use" -> ProcessEvent( |
| 47 | + data = ProcessData.MedicalDeviceUsage( |
| 48 | + createdRelationship.data.targetId, |
| 49 | + createdRelationship.data.sourceId |
| 50 | + ), |
| 51 | + dateTime = createdRelationship.eventDateTime |
| 52 | + ) |
| 53 | + else -> EmptyEvent() |
| 54 | + } |
| 55 | + } |
| 56 | + else -> EmptyEvent() |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Manage the event of delete of a relationship between Digital Twins. |
| 61 | + * @param deletedRelationship the relationship. |
| 62 | + *@return the specific [Event] |
| 63 | + */ |
| 64 | + fun manageDeletedRelationship(deletedRelationship: RelationshipEvents.RelationshipEvent): Event<Any> = |
| 65 | + when (deletedRelationship.data.relationshipName) { |
| 66 | + "rel_is_inside" -> TrackingEvent( |
| 67 | + healthProfessionalId = deletedRelationship.data.sourceId, |
| 68 | + roomId = deletedRelationship.data.targetId, |
| 69 | + data = false, |
| 70 | + dateTime = deletedRelationship.eventDateTime |
| 71 | + ) |
| 72 | + else -> EmptyEvent() |
| 73 | + } |
| 74 | +} |
0 commit comments