Skip to content

Commit 37b961c

Browse files
author
Issam Kadar
committed
feat/converter : validate RS-SR resource exists in RS-RI before conversion
1 parent 9c0d152 commit 37b961c

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

converter/converter/cisu/resources_info/resources_info_cisu_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class ResourcesInfoCISUConstants:
44
VEHICLE_TYPE_PATH = "$.vehicleType"
55

66
CASE_ID_FIELD = "caseId"
7+
RESOURCE_ID_KEY = "resourceId"
78
PATIENT_ID_KEY = "patientId"
89
POSITION_KEY = "position"
910

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class ResourcesStatusConstants:
22
RESOURCE_STATUS_PATH = "$.resourceStatus"
33
CASE_ID = "$.caseId"
4+
RESOURCE_ID = "$.resourceId"

converter/converter/cisu/resources_status/resources_status_converter.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,25 @@ def from_rs_to_cisu(
4141
if persisted_rs_ri is None: # No RS-RI persisted yet, we return an empty list
4242
return []
4343

44-
persisted_rs_sr_list = get_last_rs_sr_per_resource_by_case_id(case_id)
45-
44+
resource_id = get_field_value(content, ResourcesStatusConstants.RESOURCE_ID)
4645
rs_ri = persisted_rs_ri.payload
4746
rs_ri_content = ResourcesInfoCISUConverter.copy_rs_input_use_case_content(rs_ri)
47+
resources = get_field_value(rs_ri_content, ResourcesInfoCISUConstants.RESOURCE_PATH) or []
48+
resource_ids_in_rs_ri = {r.get(ResourcesInfoCISUConstants.RESOURCE_ID_KEY) for r in resources}
49+
50+
if resource_id not in resource_ids_in_rs_ri:
51+
raise ValueError(
52+
f"Resource '{resource_id}' from RS-SR not found in RS-RI for caseId '{case_id}'"
53+
)
54+
55+
persisted_rs_sr_list = get_last_rs_sr_per_resource_by_case_id(case_id)
56+
4857
rs_sr_content_list = [
4958
cls.copy_rs_input_use_case_content(msg.payload)
5059
for msg in persisted_rs_sr_list
5160
]
5261

5362
# merge RS-SRs in RS-RI
54-
resources = get_field_value(
55-
rs_ri_content, ResourcesInfoCISUConstants.RESOURCE_PATH
56-
)
57-
5863
merged_resources = merge_info_and_resources(resources, rs_sr_content_list)
5964

6065
set_value(

0 commit comments

Comments
 (0)