Skip to content

Commit 9c0d152

Browse files
authored
Merge pull request #391 from ansforge/feat/converter/empty-list-on-no-cisu-compatible-resource
Feat/converter : Ne pas envoyer d'erreur si aucune ressource CISU-compatible après filtrage
2 parents 8956e91 + 92339c5 commit 9c0d152

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

converter/converter/cisu/resources_info/resources_info_cisu_converter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ def from_cisu_to_rs(cls, edxl_json: Dict[str, Any]) -> List[Dict[str, Any]]:
201201
return messages
202202

203203
@classmethod
204-
def from_rs_to_cisu(cls, edxl_json: Dict[str, Any]) -> Dict[str, Any]:
204+
def from_rs_to_cisu(
205+
cls, edxl_json: Dict[str, Any]
206+
) -> Dict[str, Any] | list[Dict[str, Any]]:
205207
logger.info("Converting from RS to CISU format for Resources Info message.")
206208
logger.debug(f"Message content: {edxl_json}")
207209
output_json = cls.copy_rs_input_content(edxl_json)
@@ -214,10 +216,10 @@ def from_rs_to_cisu(cls, edxl_json: Dict[str, Any]) -> Dict[str, Any]:
214216
converted_resources = cls.convert_resources_to_cisu(resources)
215217

216218
if len(converted_resources) < 1:
217-
raise ValueError(
218-
"Could not map resources to CISU. "
219-
"At least one resource must have a CISU compatible vehicleType. "
219+
logger.info(
220+
"No CISU-compatible resources remain after filtering — returning empty list."
220221
)
222+
return []
221223

222224
set_value(
223225
output_use_case_json,

converter/tests/cisu/test_resources_info_converter.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,14 @@
3232

3333
# Dictionnaire des cas d'erreur : file_name -> message attendu
3434
ERROR_CASES = {
35-
**{
36-
name: "No states found in resource, mandatory for CISU conversion."
37-
for name in usecase_files_with_empty_state
38-
},
39-
**{
40-
name: "At least one resource must have a CISU compatible vehicleType."
41-
for name in usecase_files_with_unsupported_vehicle_type
42-
},
35+
name: "No states found in resource, mandatory for CISU conversion."
36+
for name in usecase_files_with_empty_state
4337
}
4438

4539
TEST_CASES = [
4640
(name, ValueError, ERROR_CASES[name]) if name in ERROR_CASES else (name, None, None)
4741
for name in all_file_names
42+
if name not in usecase_files_with_unsupported_vehicle_type
4843
]
4944

5045

@@ -85,6 +80,21 @@ def test_rs_to_cisu(file_name, expected_exception, expected_message):
8580
ResourcesInfoCISUConverter.from_rs_to_cisu(edxl_json)
8681

8782

83+
@pytest.mark.parametrize(
84+
"file_name",
85+
usecase_files_with_unsupported_vehicle_type,
86+
)
87+
def test_rs_to_cisu_returns_empty_list_when_no_cisu_compatible_resource(file_name):
88+
"""Quand toutes les ressources ont un vehicleType non supporté, from_rs_to_cisu
89+
doit retourner [] au lieu de lever une erreur."""
90+
usecase_file = next(f for f in all_usecase_files if f["name"] == file_name)
91+
edxl_json = TestHelper.create_edxl_json_from_sample(
92+
TestConstants.EDXL_HEALTH_TO_FIRE_ENVELOPE_PATH, usecase_file["path"]
93+
)
94+
result = ResourcesInfoCISUConverter.from_rs_to_cisu(edxl_json)
95+
assert result == []
96+
97+
8898
def test_rs_to_cisu_should_delete_patient_id():
8999
rs_raw_message = TestHelper.create_edxl_json_from_sample(
90100
TestConstants.EDXL_HEALTH_TO_FIRE_ENVELOPE_PATH,

0 commit comments

Comments
 (0)