Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def from_cisu_to_rs(cls, edxl_json: Dict[str, Any]) -> List[Dict[str, Any]]:
return messages

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

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

set_value(
output_use_case_json,
Expand Down
26 changes: 18 additions & 8 deletions converter/tests/cisu/test_resources_info_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,14 @@

# Dictionnaire des cas d'erreur : file_name -> message attendu
ERROR_CASES = {
**{
name: "No states found in resource, mandatory for CISU conversion."
for name in usecase_files_with_empty_state
},
**{
name: "At least one resource must have a CISU compatible vehicleType."
for name in usecase_files_with_unsupported_vehicle_type
},
name: "No states found in resource, mandatory for CISU conversion."
for name in usecase_files_with_empty_state
}

TEST_CASES = [
(name, ValueError, ERROR_CASES[name]) if name in ERROR_CASES else (name, None, None)
for name in all_file_names
if name not in usecase_files_with_unsupported_vehicle_type
]


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


@pytest.mark.parametrize(
"file_name",
usecase_files_with_unsupported_vehicle_type,
)
def test_rs_to_cisu_returns_empty_list_when_no_cisu_compatible_resource(file_name):
"""Quand toutes les ressources ont un vehicleType non supporté, from_rs_to_cisu
doit retourner [] au lieu de lever une erreur."""
usecase_file = next(f for f in all_usecase_files if f["name"] == file_name)
edxl_json = TestHelper.create_edxl_json_from_sample(
TestConstants.EDXL_HEALTH_TO_FIRE_ENVELOPE_PATH, usecase_file["path"]
)
result = ResourcesInfoCISUConverter.from_rs_to_cisu(edxl_json)
assert result == []


def test_rs_to_cisu_should_delete_patient_id():
rs_raw_message = TestHelper.create_edxl_json_from_sample(
TestConstants.EDXL_HEALTH_TO_FIRE_ENVELOPE_PATH,
Expand Down
Loading