Skip to content

Commit 4e41b1b

Browse files
authored
Merge pull request #424 from ansforge/converter/vectuer-samu-conversion-handling
Converter: VECTEUR_SAMU conversion handling
2 parents 997f003 + d4cd8ac commit 4e41b1b

5 files changed

Lines changed: 68 additions & 35 deletions

File tree

converter/converter/cisu/resources_info/resources_info_cisu_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class ResourcesInfoCISUConstants:
1111
POSITION_KEY = "position"
1212

1313
VEHICLE_TYPE_SIS = "SIS"
14-
VEHICLE_TYPE_SMUR = "SMUR"
14+
VEHICLE_TYPE_VECTEUR_SANTE = "VECTEUR_SANTE"

converter/converter/cisu/resources_info/resources_info_cisu_converter.py

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def _build_rs_ri_from_cisu(cls, edxl_json: Dict[str, Any]) -> Dict[str, Any]:
7777
ResourcesInfoCISUConstants.MISSION_ID_PATH,
7878
)
7979

80+
cls._translate_to_samu_vehicle_type(resource)
81+
8082
return cls.format_rs_output_json(output_json, output_use_case_json)
8183

8284
@classmethod
@@ -158,6 +160,34 @@ def _has_resources_been_updated(
158160
modified_status_resources=modified_status_resources,
159161
)
160162

163+
@classmethod
164+
def _translate_to_samu_vehicle_type(cls, resource: Dict[str, Any]) -> None:
165+
"""Translate a CISU vehicle type to its SAMU equivalent. Throws an error if no vehicleType is provided."""
166+
167+
vehicle_type = get_field_value(
168+
resource, ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH
169+
)
170+
resourceId = get_field_value(
171+
resource, ResourcesInfoCISUConstants.RESOURCE_ID_KEY
172+
)
173+
174+
if vehicle_type is None:
175+
raise ConversionError(
176+
f"No vehicle found in CISU resource for resource: {resourceId}."
177+
)
178+
179+
logger.info(
180+
"Replacing vehicleType %s with %s for ressource with id %s",
181+
vehicle_type,
182+
ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS,
183+
resourceId,
184+
)
185+
set_value(
186+
resource,
187+
ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH,
188+
ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS,
189+
)
190+
161191
@classmethod
162192
def from_cisu_to_rs(cls, edxl_json: Dict[str, Any]) -> List[Dict[str, Any]]:
163193
"""RC-RI → RS: on first reception RS-RI + one RS-SR per resource;
@@ -346,33 +376,31 @@ def _remove_patient_id(cls, resource):
346376

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

351381
vehicle_type = get_field_value(
352382
resource, ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH
353383
)
384+
resourceId = get_field_value(
385+
resource, ResourcesInfoCISUConstants.RESOURCE_ID_KEY
386+
)
354387

355388
if vehicle_type is None:
356389
raise ConversionError(
357-
f"No vehicle found in RS resource for resource: {resource.get('resourceId')}."
390+
f"No vehicle found in RS resource for resource: {resourceId}."
358391
)
359392

360-
if vehicle_type.startswith(ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS):
361-
set_value(
362-
resource,
363-
ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH,
364-
ResourcesInfoCISUConstants.VEHICLE_TYPE_SIS,
365-
)
366-
elif vehicle_type.startswith(ResourcesInfoCISUConstants.VEHICLE_TYPE_SMUR):
367-
set_value(
368-
resource,
369-
ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH,
370-
ResourcesInfoCISUConstants.VEHICLE_TYPE_SMUR,
371-
)
372-
else:
373-
raise ConversionError(
374-
f"No valid vehicle found for resource: {resource.get('resourceId')}."
375-
)
393+
logger.info(
394+
"Replacing vehicleType %s with %s for ressource with id %s",
395+
vehicle_type,
396+
ResourcesInfoCISUConstants.VEHICLE_TYPE_VECTEUR_SANTE,
397+
resourceId,
398+
)
399+
set_value(
400+
resource,
401+
ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH,
402+
ResourcesInfoCISUConstants.VEHICLE_TYPE_VECTEUR_SANTE,
403+
)
376404

377405
@classmethod
378406
def _keep_last_state(cls, resource: Dict[str, Any]) -> None:

converter/tests/cisu/test_resources_info_converter.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
_PATCH_GET_LAST_RC_RI_BY_CASE_ID = "converter.cisu.resources_info.resources_info_cisu_converter.get_last_rc_ri_by_case_id"
2727
_PATCH_GET_RS_MESSAGES_BY_CASE_ID = "converter.cisu.resources_info.resources_info_cisu_converter.get_rs_messages_by_case_id"
2828

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

3536
all_usecase_files = TestHelper.get_json_files(
@@ -161,10 +162,14 @@ def test_cisu_to_rs_breaking_changes():
161162
@pytest.mark.parametrize(
162163
"rs_vehicule_type,expected",
163164
[
164-
pytest.param("SIS", "SIS", id="translates SIS to SIS"),
165-
pytest.param("SIS.DRAGON", "SIS", id="translates SIS.DRAGON to SIS"),
166-
pytest.param("SMUR", "SMUR", id="translates SMUR to SMUR"),
167-
pytest.param("SMUR.VLM", "SMUR", id="translates SMUR.VLM to SMUR"),
165+
pytest.param("SIS", "VECTEUR_SANTE", id="translates SIS to VECTEUR_SANTE"),
166+
pytest.param(
167+
"SIS.DRAGON", "VECTEUR_SANTE", id="translates SIS.DRAGON to VECTEUR_SANTE"
168+
),
169+
pytest.param("SMUR", "VECTEUR_SANTE", id="translates SMUR to VECTEUR_SANTE"),
170+
pytest.param(
171+
"SMUR.VLM", "VECTEUR_SANTE", id="translates SMUR.VLM to VECTEUR_SANTE"
172+
),
168173
],
169174
)
170175
def test_translate_vehicule_type_to_cisu(rs_vehicule_type, expected):
@@ -174,17 +179,17 @@ def test_translate_vehicule_type_to_cisu(rs_vehicule_type, expected):
174179

175180

176181
@pytest.mark.parametrize(
177-
"rs_vehicule_type",
182+
"rs_vehicule_type,expected",
178183
[
179-
pytest.param("AUTREVEC", id="AUTREVEC is not mappable to CISU"),
180-
pytest.param("FSI.HELIFSI", id="FSI.HELIFSI is not mappable to CISU"),
181-
pytest.param("TSU.VSL", id="TSU.VSL is not mappable to CISU"),
184+
pytest.param("SIS", "SIS", id="translates SIS to SIS"),
185+
pytest.param("VECTEUR_SANTE", "SIS", id="translates VECTEUR_SANTE to SIS"),
186+
pytest.param("unsuported", "SIS", id="translates unsuported to SIS"),
182187
],
183188
)
184-
def test_translate_vehicule_type_to_cisu_raises_on_unmappable(rs_vehicule_type):
189+
def test_translate_vehicule_type_to_samu(rs_vehicule_type, expected):
185190
resource = {"vehicleType": rs_vehicule_type}
186-
with pytest.raises(ConversionError):
187-
ResourcesInfoCISUConverter._translate_to_cisu_vehicle_type(resource)
191+
ResourcesInfoCISUConverter._translate_to_samu_vehicle_type(resource)
192+
assert resource["vehicleType"] == expected
188193

189194

190195
# ---------------------------------------------------------------------------
@@ -495,8 +500,8 @@ def test_from_rs_to_cisu_no_persisted_rs_sr():
495500

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

501506

502507
def test_from_rs_to_cisu_no_state_but_persisted_rs_sr():

converter/tests/fixtures/RC-RI/RC-RI_V3.0_exhaustive_fill.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"datetime": "2024-08-01T16:42:00+02:00",
1818
"resourceId": "fr.health.samu76A.resource.VLM12",
1919
"orgId": "fr.health.samu76A",
20-
"vehicleType": "SMUR",
20+
"vehicleType": "VECTEUR_SANTE",
2121
"name": "VLM 76 - A45"
2222
},
2323
{

converter/tests/fixtures/RC-RI/RC-RI_V3.0_with_position.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"resourceId": "fr.health.samu800.resource.VLM1",
77
"orgId": "fr.health.samu800",
8-
"vehicleType": "SMUR",
8+
"vehicleType": "VECTEUR_SANTE",
99
"name": "VLM 800-1",
1010
"state": {
1111
"datetime": "2024-08-01T16:42:00+02:00",

0 commit comments

Comments
 (0)