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 @@ -11,4 +11,4 @@ class ResourcesInfoCISUConstants:
POSITION_KEY = "position"

VEHICLE_TYPE_SIS = "SIS"
VEHICLE_TYPE_SMUR = "SMUR"
VEHICLE_TYPE_VECTEUR_SANTE = "VECTEUR_SANTE"
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def _build_rs_ri_from_cisu(cls, edxl_json: Dict[str, Any]) -> Dict[str, Any]:
ResourcesInfoCISUConstants.MISSION_ID_PATH,
)

cls._translate_to_samu_vehicle_type(resource)

return cls.format_rs_output_json(output_json, output_use_case_json)

@classmethod
Expand Down Expand Up @@ -158,6 +160,34 @@ def _has_resources_been_updated(
modified_status_resources=modified_status_resources,
)

@classmethod
def _translate_to_samu_vehicle_type(cls, resource: Dict[str, Any]) -> None:
"""Translate a CISU vehicle type to its SAMU equivalent. Throws an error if no vehicleType is provided."""

vehicle_type = get_field_value(
resource, ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH
)
resourceId = get_field_value(
resource, ResourcesInfoCISUConstants.RESOURCE_ID_KEY
)

if vehicle_type is None:
raise ConversionError(
f"No vehicle found in CISU resource for resource: {resourceId}."
)

logger.info(
"Replacing vehicleType %s with %s for ressource with id %s",
vehicle_type,
ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS,
resourceId,
)
set_value(
resource,
ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH,
ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS,
)

@classmethod
def from_cisu_to_rs(cls, edxl_json: Dict[str, Any]) -> List[Dict[str, Any]]:
"""RC-RI → RS: on first reception RS-RI + one RS-SR per resource;
Expand Down Expand Up @@ -346,33 +376,31 @@ def _remove_patient_id(cls, resource):

@classmethod
def _translate_to_cisu_vehicle_type(cls, resource: Dict[str, Any]) -> None:
"""Translate a RS vehicle type to its CISU equivalent, or None if not mappable."""
"""Translate a RS vehicle type to its CISU equivalent. Throws an error if no vehicleType is provided."""

vehicle_type = get_field_value(
resource, ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH
)
resourceId = get_field_value(
resource, ResourcesInfoCISUConstants.RESOURCE_ID_KEY
)

if vehicle_type is None:
raise ConversionError(
f"No vehicle found in RS resource for resource: {resource.get('resourceId')}."
f"No vehicle found in RS resource for resource: {resourceId}."
)

if vehicle_type.startswith(ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS):
set_value(
resource,
ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH,
ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS,
)
elif vehicle_type.startswith(ResourcesInfoCISUConstants.VEHICLE_TYPE_SMUR):
set_value(
resource,
ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH,
ResourcesInfoCISUConstants.VEHICLE_TYPE_SMUR,
)
else:
raise ConversionError(
f"No valid vehicle found for resource: {resource.get('resourceId')}."
)
logger.info(
"Replacing vehicleType %s with %s for ressource with id %s",
vehicle_type,
ResourcesInfoCISUConstants.VEHICLE_TYPE_VECTEUR_SANTE,
resourceId,
)
set_value(
resource,
ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH,
ResourcesInfoCISUConstants.VEHICLE_TYPE_VECTEUR_SANTE,
)

@classmethod
def _keep_last_state(cls, resource: Dict[str, Any]) -> None:
Expand Down
33 changes: 19 additions & 14 deletions converter/tests/cisu/test_resources_info_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
_PATCH_GET_LAST_RC_RI_BY_CASE_ID = "converter.cisu.resources_info.resources_info_cisu_converter.get_last_rc_ri_by_case_id"
_PATCH_GET_RS_MESSAGES_BY_CASE_ID = "converter.cisu.resources_info.resources_info_cisu_converter.get_rs_messages_by_case_id"

# These usecases does not contain the minimal infomations to trigger
# the traduction of a valid RC-RI (no state on resource).
usecase_files_returning_no_converted_messages = [
"RS-RI_Secondaire_RobertVermande.03.json",
"RS-RI_partageRessources_LolaHalimi.03c.json",
"RS-RI_partageRessources_MonsieurX.03.json",
]

all_usecase_files = TestHelper.get_json_files(
Expand Down Expand Up @@ -161,10 +162,14 @@ def test_cisu_to_rs_breaking_changes():
@pytest.mark.parametrize(
"rs_vehicule_type,expected",
[
pytest.param("SIS", "SIS", id="translates SIS to SIS"),
pytest.param("SIS.DRAGON", "SIS", id="translates SIS.DRAGON to SIS"),
pytest.param("SMUR", "SMUR", id="translates SMUR to SMUR"),
pytest.param("SMUR.VLM", "SMUR", id="translates SMUR.VLM to SMUR"),
pytest.param("SIS", "VECTEUR_SANTE", id="translates SIS to VECTEUR_SANTE"),
pytest.param(
"SIS.DRAGON", "VECTEUR_SANTE", id="translates SIS.DRAGON to VECTEUR_SANTE"
),
pytest.param("SMUR", "VECTEUR_SANTE", id="translates SMUR to VECTEUR_SANTE"),
pytest.param(
"SMUR.VLM", "VECTEUR_SANTE", id="translates SMUR.VLM to VECTEUR_SANTE"
),
],
)
def test_translate_vehicule_type_to_cisu(rs_vehicule_type, expected):
Expand All @@ -174,17 +179,17 @@ def test_translate_vehicule_type_to_cisu(rs_vehicule_type, expected):


@pytest.mark.parametrize(
"rs_vehicule_type",
"rs_vehicule_type,expected",
[
pytest.param("AUTREVEC", id="AUTREVEC is not mappable to CISU"),
pytest.param("FSI.HELIFSI", id="FSI.HELIFSI is not mappable to CISU"),
pytest.param("TSU.VSL", id="TSU.VSL is not mappable to CISU"),
pytest.param("SIS", "SIS", id="translates SIS to SIS"),
pytest.param("VECTEUR_SANTE", "SIS", id="translates VECTEUR_SANTE to SIS"),
pytest.param("unsuported", "SIS", id="translates unsuported to SIS"),
],
)
def test_translate_vehicule_type_to_cisu_raises_on_unmappable(rs_vehicule_type):
def test_translate_vehicule_type_to_samu(rs_vehicule_type, expected):
resource = {"vehicleType": rs_vehicule_type}
with pytest.raises(ConversionError):
ResourcesInfoCISUConverter._translate_to_cisu_vehicle_type(resource)
ResourcesInfoCISUConverter._translate_to_samu_vehicle_type(resource)
assert resource["vehicleType"] == expected


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -495,8 +500,8 @@ def test_from_rs_to_cisu_no_persisted_rs_sr():

rc_ri = get_cisu_content(result)
assert rc_ri["resource"][0]["state"]["status"] == "RET-BASE"
# Two resources present originaly but only one valid vehicle type, so 1 resource expected
assert (len(rc_ri["resource"])) == 1
# Two resources present originaly and both are translated in the destination RC-RI
assert (len(rc_ri["resource"])) == 2


def test_from_rs_to_cisu_no_state_but_persisted_rs_sr():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"datetime": "2024-08-01T16:42:00+02:00",
"resourceId": "fr.health.samu76A.resource.VLM12",
"orgId": "fr.health.samu76A",
"vehicleType": "SMUR",
"vehicleType": "VECTEUR_SANTE",
"name": "VLM 76 - A45"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"resourceId": "fr.health.samu800.resource.VLM1",
"orgId": "fr.health.samu800",
"vehicleType": "SMUR",
"vehicleType": "VECTEUR_SANTE",
"name": "VLM 800-1",
"state": {
"datetime": "2024-08-01T16:42:00+02:00",
Expand Down
Loading