|
| 1 | +""" |
| 2 | +Integration tests exercising CreateCaseCISUConverter.from_cisu_to_rs / from_rs_to_cisu |
| 3 | +end-to-end against real nomenclature map entries, for the qualification.whatsHappen, |
| 4 | +qualification.healthMotive, qualification.riskThreat and qualification.locationKind |
| 5 | +fields. Complements the unit tests in tests/nomenclatures/test_utils.py (which cover |
| 6 | +apply_nomenclature_mapping/apply_nomenclature_mapping_to_list in isolation) by proving |
| 7 | +the maps are actually wired into the converter and that real fixture-shaped messages |
| 8 | +produce the expected replace/remove behaviour. |
| 9 | +""" |
| 10 | + |
| 11 | +import copy |
| 12 | + |
| 13 | +from converter.cisu.create_case.create_case_cisu_converter import ( |
| 14 | + CreateCaseCISUConverter, |
| 15 | +) |
| 16 | +from tests.cisu.helpers import get_edxl_message |
| 17 | +from tests.constants import TestConstants |
| 18 | +from tests.test_helpers import TestHelper |
| 19 | + |
| 20 | +RC_EDA_BASE = TestHelper.load_json_file( |
| 21 | + "tests/fixtures/RC-EDA/RC-EDA_required_fields.json" |
| 22 | +) |
| 23 | +RS_EDA_BASE = TestHelper.load_json_file( |
| 24 | + "tests/fixtures/RS-EDA/cisu_case/RS-EDA_required_fields.json" |
| 25 | +) |
| 26 | + |
| 27 | + |
| 28 | +def cisu_to_rs_message(qualification_overrides: dict) -> dict: |
| 29 | + content = copy.deepcopy(RC_EDA_BASE) |
| 30 | + content["createCase"]["qualification"].update(qualification_overrides) |
| 31 | + edxl = TestHelper.combine_edxl_envelope_and_message( |
| 32 | + TestConstants.EDXL_FIRE_TO_HEALTH_ENVELOPE_PATH, content |
| 33 | + ) |
| 34 | + result = CreateCaseCISUConverter.from_cisu_to_rs(edxl) |
| 35 | + return get_edxl_message(result)["createCaseHealth"]["qualification"] |
| 36 | + |
| 37 | + |
| 38 | +def rs_to_cisu_message(qualification_overrides: dict) -> dict: |
| 39 | + content = copy.deepcopy(RS_EDA_BASE) |
| 40 | + content["createCaseHealth"]["qualification"].update(qualification_overrides) |
| 41 | + edxl = TestHelper.combine_edxl_envelope_and_message( |
| 42 | + TestConstants.EDXL_HEALTH_TO_FIRE_ENVELOPE_PATH, content |
| 43 | + ) |
| 44 | + result = CreateCaseCISUConverter.from_rs_to_cisu(edxl) |
| 45 | + return get_edxl_message(result)["createCase"]["qualification"] |
| 46 | + |
| 47 | + |
| 48 | +# --- from_cisu_to_rs: code has no entry in the map -> field untouched --- |
| 49 | + |
| 50 | + |
| 51 | +def test_from_cisu_to_rs_whats_happen_unmapped_code_is_untouched(): |
| 52 | + unmapped = {"code": "C99.99.99", "label": "Code inconnu"} |
| 53 | + qualification = cisu_to_rs_message({"whatsHappen": unmapped}) |
| 54 | + assert qualification["whatsHappen"] == unmapped |
| 55 | + |
| 56 | + |
| 57 | +# --- from_cisu_to_rs: code has a non-None entry -> field replaced --- |
| 58 | + |
| 59 | + |
| 60 | +def test_from_cisu_to_rs_whats_happen_mapped_code_is_replaced(): |
| 61 | + qualification = cisu_to_rs_message( |
| 62 | + {"whatsHappen": {"code": "C02.05.03", "label": "Menace de suicide"}} |
| 63 | + ) |
| 64 | + assert qualification["whatsHappen"] == { |
| 65 | + "code": "C02.18.00", |
| 66 | + "label": "Problème psychiatrique, menace de suicide", |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | +def test_from_cisu_to_rs_health_motive_mapped_code_is_replaced(): |
| 71 | + qualification = cisu_to_rs_message( |
| 72 | + {"healthMotive": {"code": "M20.00", "label": "Inconscience"}} |
| 73 | + ) |
| 74 | + assert qualification["healthMotive"] == { |
| 75 | + "code": "M08.00.00", |
| 76 | + "label": "Personne inconsciente ", |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | +def test_from_cisu_to_rs_location_kind_mapped_code_is_replaced(): |
| 81 | + qualification = cisu_to_rs_message( |
| 82 | + { |
| 83 | + "locationKind": { |
| 84 | + "code": "L02.02.04", |
| 85 | + "label": "Aire de repos sur voie rapide", |
| 86 | + } |
| 87 | + } |
| 88 | + ) |
| 89 | + assert qualification["locationKind"] == { |
| 90 | + "code": "L02.02.03", |
| 91 | + "label": "Aire de repos ou de service sur voie rapide", |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | +# --- from_cisu_to_rs: riskThreat is an array -> per-item behaviour --- |
| 96 | + |
| 97 | + |
| 98 | +def test_from_cisu_to_rs_risk_threat_mapped_to_none_removes_item_and_field(): |
| 99 | + qualification = cisu_to_rs_message( |
| 100 | + {"riskThreat": [{"code": "R36", "label": "Menace"}]} |
| 101 | + ) |
| 102 | + assert "riskThreat" not in qualification |
| 103 | + |
| 104 | + |
| 105 | +def test_from_cisu_to_rs_risk_threat_removes_only_the_none_mapped_item(): |
| 106 | + unmapped = {"code": "R99", "label": "Autre menace"} |
| 107 | + qualification = cisu_to_rs_message( |
| 108 | + {"riskThreat": [{"code": "R36", "label": "Menace"}, unmapped]} |
| 109 | + ) |
| 110 | + assert qualification["riskThreat"] == [unmapped] |
| 111 | + |
| 112 | + |
| 113 | +# --- from_rs_to_cisu: same three cases, using the reverse maps --- |
| 114 | + |
| 115 | + |
| 116 | +def test_from_rs_to_cisu_whats_happen_unmapped_code_is_untouched(): |
| 117 | + unmapped = {"code": "C99.99.99", "label": "Code inconnu"} |
| 118 | + qualification = rs_to_cisu_message({"whatsHappen": unmapped}) |
| 119 | + assert qualification["whatsHappen"] == unmapped |
| 120 | + |
| 121 | + |
| 122 | +def test_from_rs_to_cisu_whats_happen_mapped_code_is_replaced(): |
| 123 | + qualification = rs_to_cisu_message( |
| 124 | + {"whatsHappen": {"code": "C02.17.00", "label": "Mort suspecte/cadavre"}} |
| 125 | + ) |
| 126 | + assert qualification["whatsHappen"] == { |
| 127 | + "code": "C10.02.01", |
| 128 | + "label": "Mort suspecte", |
| 129 | + } |
| 130 | + |
| 131 | + |
| 132 | +def test_from_rs_to_cisu_health_motive_mapped_code_is_replaced(): |
| 133 | + qualification = rs_to_cisu_message( |
| 134 | + {"healthMotive": {"code": "M08.00.00", "label": "Personne inconsciente"}} |
| 135 | + ) |
| 136 | + assert qualification["healthMotive"] == { |
| 137 | + "code": "M22.00", |
| 138 | + "label": "Personne inconsciente", |
| 139 | + } |
| 140 | + |
| 141 | + |
| 142 | +def test_from_rs_to_cisu_location_kind_mapped_code_is_replaced(): |
| 143 | + qualification = rs_to_cisu_message( |
| 144 | + {"locationKind": {"code": "L01.01.05", "label": "Pavillon"}} |
| 145 | + ) |
| 146 | + assert qualification["locationKind"] == { |
| 147 | + "code": "L01.01.00", |
| 148 | + "label": "Maison particulière, pavillon", |
| 149 | + } |
| 150 | + |
| 151 | + |
| 152 | +def test_from_rs_to_cisu_risk_threat_mapped_code_replaces_matching_item_only(): |
| 153 | + unmapped = {"code": "R99", "label": "Autre menace"} |
| 154 | + qualification = rs_to_cisu_message( |
| 155 | + { |
| 156 | + "riskThreat": [ |
| 157 | + {"code": "R17", "label": "Situation instable"}, |
| 158 | + unmapped, |
| 159 | + ] |
| 160 | + } |
| 161 | + ) |
| 162 | + assert qualification["riskThreat"] == [ |
| 163 | + {"code": "R37", "label": "Situation instable/indéterminée"}, |
| 164 | + unmapped, |
| 165 | + ] |
0 commit comments