Skip to content

Commit e3d4411

Browse files
authored
Merge pull request #434 from ansforge/revert-424-converter/vectuer-samu-conversion-handling
Revert "Converter: VECTEUR_SAMU conversion handling"
2 parents 4b15207 + 99f7316 commit e3d4411

5 files changed

Lines changed: 35 additions & 68 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_VECTEUR_SANTE = "VECTEUR_SANTE"
14+
VEHICLE_TYPE_SMUR = "SMUR"

converter/converter/cisu/resources_info/resources_info_cisu_converter.py

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ 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-
8280
return cls.format_rs_output_json(output_json, output_use_case_json)
8381

8482
@classmethod
@@ -160,34 +158,6 @@ def _has_resources_been_updated(
160158
modified_status_resources=modified_status_resources,
161159
)
162160

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-
191161
@classmethod
192162
def from_cisu_to_rs(cls, edxl_json: Dict[str, Any]) -> List[Dict[str, Any]]:
193163
"""RC-RI → RS: on first reception RS-RI + one RS-SR per resource;
@@ -376,31 +346,33 @@ def _remove_patient_id(cls, resource):
376346

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

381351
vehicle_type = get_field_value(
382352
resource, ResourcesInfoCISUConstants.VEHICLE_TYPE_PATH
383353
)
384-
resourceId = get_field_value(
385-
resource, ResourcesInfoCISUConstants.RESOURCE_ID_KEY
386-
)
387354

388355
if vehicle_type is None:
389356
raise ConversionError(
390-
f"No vehicle found in RS resource for resource: {resourceId}."
357+
f"No vehicle found in RS resource for resource: {resource.get('resourceId')}."
391358
)
392359

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-
)
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+
)
404376

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

converter/tests/cisu/test_resources_info_converter.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
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).
3129
usecase_files_returning_no_converted_messages = [
3230
"RS-RI_Secondaire_RobertVermande.03.json",
3331
"RS-RI_partageRessources_LolaHalimi.03c.json",
32+
"RS-RI_partageRessources_MonsieurX.03.json",
3433
]
3534

3635
all_usecase_files = TestHelper.get_json_files(
@@ -162,14 +161,10 @@ def test_cisu_to_rs_breaking_changes():
162161
@pytest.mark.parametrize(
163162
"rs_vehicule_type,expected",
164163
[
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-
),
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"),
173168
],
174169
)
175170
def test_translate_vehicule_type_to_cisu(rs_vehicule_type, expected):
@@ -179,17 +174,17 @@ def test_translate_vehicule_type_to_cisu(rs_vehicule_type, expected):
179174

180175

181176
@pytest.mark.parametrize(
182-
"rs_vehicule_type,expected",
177+
"rs_vehicule_type",
183178
[
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"),
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"),
187182
],
188183
)
189-
def test_translate_vehicule_type_to_samu(rs_vehicule_type, expected):
184+
def test_translate_vehicule_type_to_cisu_raises_on_unmappable(rs_vehicule_type):
190185
resource = {"vehicleType": rs_vehicule_type}
191-
ResourcesInfoCISUConverter._translate_to_samu_vehicle_type(resource)
192-
assert resource["vehicleType"] == expected
186+
with pytest.raises(ConversionError):
187+
ResourcesInfoCISUConverter._translate_to_cisu_vehicle_type(resource)
193188

194189

195190
# ---------------------------------------------------------------------------
@@ -500,8 +495,8 @@ def test_from_rs_to_cisu_no_persisted_rs_sr():
500495

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

506501

507502
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": "VECTEUR_SANTE",
20+
"vehicleType": "SMUR",
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": "VECTEUR_SANTE",
8+
"vehicleType": "SMUR",
99
"name": "VLM 800-1",
1010
"state": {
1111
"datetime": "2024-08-01T16:42:00+02:00",

0 commit comments

Comments
 (0)