Skip to content
Open
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
16 changes: 13 additions & 3 deletions converter/converter/cisu/cisu_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

from yaml import dump

from .utils import add_to_initial_alert_notes
from converter.constants import Constants

from .utils import add_to_initial_alert_notes, update_health_motive_code
from ..utils import delete_paths, get_field_value, get_recipient, get_sender, is_field_completed, translate_key_words

class CISUConverterV3:
"""Handles CISU format conversions"""
# Todo: revert change when all editors use the new CISU nomenclature or are in V3 or above
def __init__(self, target_version: str):
self.target_version = target_version

CISU_PATHS_TO_DELETE = [
"qualification.victims",
Expand Down Expand Up @@ -62,7 +66,7 @@ class CISUConverterV3:
DEFAULT_WHATS_HAPPEN = {"code": "C11.06.00", "label":"Autre nature de fait"}

@classmethod
def from_cisu(cls, input_json: Dict[str, Any]) -> Dict[str, Any]:
def from_cisu(cls, input_json: Dict[str, Any], target_version: str) -> Dict[str, Any]:
"""
Convert from CISU to Health format

Expand Down Expand Up @@ -143,6 +147,9 @@ def add_object_to_medical_notes(json_data: Dict[str, Any], note_text: str, sende

# - Updates
output_use_case_json['owner'] = get_recipient(input_json)
if target_version != Constants.V3_VERSION:
# /!\ it must be done before copying qualification
update_health_motive_code(output_use_case_json, True)

set_default_location_freetext(output_use_case_json)
add_location_detail(output_use_case_json)
Expand Down Expand Up @@ -240,6 +247,9 @@ def add_default_external_info_type(json_data: Dict[str,Any]):
if not is_field_completed(output_usecase_json,'$.qualification.whatsHappen'):
output_usecase_json['qualification']['whatsHappen'] = cls.DEFAULT_WHATS_HAPPEN

# /!\ it must be done before copying qualification
update_health_motive_code(output_usecase_json, False)

add_default_external_info_type(output_usecase_json)

# Deletions - /!\ it must be done before copying qualification and location fields
Expand Down
6 changes: 6 additions & 0 deletions converter/converter/cisu/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Constants:
MRSM_CISU_UPDATED_NOMENCLATURE_FILE = './mrms_cisu_updated_nomenclature.csv'
MR0_LABEL = "CodeCisuMR0"
MR1_LABEL = "CodeCisuMR1"
OLD_MR_LABEL = "CodeCisu V1.3"
CSV_DELIMITER = ';'
202 changes: 202 additions & 0 deletions converter/converter/cisu/mrms_cisu_updated_nomenclature.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
CodeCisuMR0;CodeCisuMR1;CodeCisu V1.3
M20.00;[Null];M01.00
M22.00;M22.11;M01.01
M22.00;[Null];M01.02
M22.00;M22.21;M01.02
M50.00;M50.35;M01.02
M60.00;M60.03;M01.02
M22.00;M22.01;M01.03
M31.00;M31.01;M01.03
M31.00;M31.02;M01.03
M31.00;M31.03;M01.03
M31.00;M31.13;M01.03
M50.00;M50.33;M01.03
M50.00;M50.53;M01.03
M41.00;[Null];M02.00
M41.00;M41.41;M02.00
M41.00;M41.51;M02.00
M41.00;M41.61;M02.00
M45.00;[Null];M02.00
M24.00;M24.01;M02.02
M46.00;M46.21;M02.03
M46.00;M46.22;M02.03
M46.00;M46.29;M02.03
M46.00;M46.02;M02.04
M46.00;M46.03;M02.04
M46.00;M46.12;M02.04
M46.00;M46.13;M02.04
M46.00;M46.09;M02.05
M46.00;M46.19;M02.05
M24.00;M24.91;M02.06
M24.00;M24.92;M02.06
M41.00;M41.21;M02.06
M41.00;M41.29;M02.06
M41.00;M41.39;M02.06
M41.00;M41.49;M02.06
M41.00;M41.59;M02.06
M41.00;M41.69;M02.06
M45.00;M45.33;M02.06
M24.00;[Null];M02.07
M24.00;M24.11;M02.07
M41.00;M41.22;M02.07
M41.00;M41.31;M02.07
M41.00;M41.42;M02.07
M41.00;M41.52;M02.07
M41.00;M41.53;M02.07
M41.00;M41.54;M02.07
M41.00;M41.55;M02.07
M41.00;M41.62;M02.07
M41.00;M41.64;M02.07
M41.00;M41.65;M02.07
M41.00;M41.66;M02.07
M45.00;M45.02;M02.07
M45.00;M45.03;M02.07
M45.00;M45.05;M02.07
M45.00;M45.06;M02.07
M45.00;M45.07;M02.07
M45.00;M45.31;M02.07
M45.00;M45.32;M02.07
M46.00;[Null];M02.07
M46.00;M46.01;M02.07
M46.00;M46.11;M02.07
M41.00;M41.11;M02.08
M41.00;M41.32;M02.08
M45.00;M45.01;M02.08
M45.00;M45.08;M02.08
M45.00;M45.09;M02.08
M80.00;M80.01;M03.01
M80.00;M80.02;M03.01
M80.00;M80.03;M03.01
M80.00;M80.04;M03.01
M80.00;M80.05;M03.01
M80.00;M80.06;M03.01
M80.00;M80.07;M03.01
M80.00;M80.08;M03.01
M32.00;M32.95;M03.02
M60.00;M60.05;M03.02
M80.00;[Null];M03.02
M80.00;M80.11;M03.02
M80.00;M80.12;M03.02
M80.00;M80.13;M03.02
M80.00;M80.14;M03.02
M80.00;M80.15;M03.02
M80.00;M80.19;M03.02
M60.00;M60.31;M03.06
M60.00;M60.32;M03.06
M60.00;M60.33;M03.06
M60.00;M60.34;M03.06
M60.00;M60.35;M03.06
M60.00;M60.36;M03.06
M60.00;M60.37;M03.06
M60.00;M60.38;M03.06
M60.00;M60.39;M03.06
M60.00;M60.40;M03.06
M60.00;M60.41;M03.06
M60.00;M60.49;M03.06
M32.00;[Null];M03.07
M32.00;M32.91;M03.07
M32.00;M32.99;M03.07
M32.00;M32.01;M03.08
M32.00;M32.02;M03.08
M32.00;M32.03;M03.08
M32.00;M32.04;M03.08
M32.00;M32.05;M03.08
M32.00;M32.51;M03.09
M32.00;M32.57;M03.09
M32.00;M32.31;M03.10
M32.00;M32.32;M03.10
M32.00;M32.34;M03.10
M32.00;M32.35;M03.10
M32.00;M32.39;M03.10
M32.00;M32.52;M03.10
M32.00;M32.54;M03.10
M32.00;M32.55;M03.10
M32.00;M32.92;M03.11
M60.00;M60.01;M03.11
M60.00;M60.08;M03.11
M31.00;[Null];M03.12
M31.00;M31.11;M03.12
M31.00;M31.12;M03.12
M31.00;M31.19;M03.12
M31.00;M31.91;M03.12
M31.00;M31.92;M03.12
M31.00;M31.93;M03.12
M31.00;M31.94;M03.12
M31.00;M31.99;M03.12
M30.00;[Null];M03.13
M30.00;M30.61;M03.13
M30.00;M30.91;M03.13
M30.00;M30.92;M03.13
M30.00;M30.93;M03.13
M30.00;M30.95;M03.13
M30.00;M30.96;M03.13
M60.00;M60.94;M03.14
M90.00;M90.41;M03.14
M90.00;M90.71;M03.14
M90.00;M90.11;M03.15
M90.00;M90.12;M03.15
M90.00;M90.13;M03.15
M90.00;M90.14;M03.15
M90.00;M90.16;M03.15
M90.00;M90.17;M03.15
M90.00;M90.19;M03.15
M90.00;M90.61;M03.16
M90.00;M90.63;M03.17
M24.00;M24.02;M03.18
M24.00;M24.29;M03.18
M24.00;M24.21;M03.19
M24.00;M24.25;M03.19
M24.00;M24.26;M03.19
M24.00;M24.28;M03.19
M60.00;M60.21;M03.20
M60.00;M60.26;M03.20
M90.00;M90.51;M03.21
M90.00;M90.53;M03.21
M90.00;M90.54;M03.21
M90.00;M90.55;M03.21
M90.00;M90.59;M03.21
M32.00;M32.11;M03.23
M32.00;M32.21;M03.23
M32.00;M32.22;M03.23
M32.00;M32.25;M03.23
M32.00;M32.24;M03.23
M50.00;M50.22;M03.23
M50.00;M50.32;M03.23
M50.00;M50.52;M03.23
M24.00;M24.27;M03.24
M90.00;M90.52;M03.24
M60.00;[Null];M03.26
M60.00;M60.51;M03.26
M60.00;M60.53;M03.26
M60.00;M60.59;M03.26
M60.00;M60.91;M03.26
M60.00;M60.96;M03.26
M60.00;M60.92;M03.27
M90.00;M90.01;M03.28
M32.00;M32.36;M03.29
M60.00;M60.93;M03.30
M50.00;[Null];M04.00
M50.00;M50.21;M04.00
M50.00;M50.29;M04.00
M50.00;M50.31;M04.00
M50.00;M50.39;M04.00
M50.00;M50.54;M04.00
M50.00;M50.51;M04.02
M50.00;M50.25;M04.03
M90.00;M90.64;M04.04
M50.00;M50.11;M04.05
M50.00;M50.12;M04.05
M50.00;M50.15;M04.05
M50.00;M50.16;M04.05
M90.00;M90.65;M05.01
M90.00;M90.62;M05.02
M98.00;[Null];M06.01
M98.00;M98.01;M06.01
M98.00;M98.11;M06.01
M98.00;M98.21;M06.01
M98.00;M98.31;M06.01
M90.00;M90.31;M06.02
M41.00;M41.01;M06.03
M30.00;M30.97;M06.04
M90.00;[Null];M06.04
M90.00;M90.21;M06.05
45 changes: 45 additions & 0 deletions converter/converter/cisu/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import Any, Dict, List
import csv
import os

from yaml import dump

from converter.cisu.constants import Constants
from ..utils import concatenate_values, get_field_value, is_field_completed

def add_object_to_initial_alert_notes(json_data: Dict[str, Any], note_text: str):
Expand All @@ -22,3 +26,44 @@ def add_field_to_initial_alert_notes(data: Dict[str, Any], path_and_label: Dict[
def add_to_initial_alert_notes(data: Dict[str, Any], paths: List[Dict[str, str]]):
for path in paths:
add_field_to_initial_alert_notes(data, path)

def find_in_cisu_nomenclature(search_value: str, search_columns: list, return_column: str, filename: str) -> str:
file_path = os.path.join(os.path.dirname(__file__), filename)
with open(file_path, newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile, delimiter=Constants.CSV_DELIMITER)
for row in reader:
for col in search_columns:
if row.get(col, '').strip() == search_value:
return row.get(return_column)
return None

def get_deprecated_code_cisu_from_health_motive(health_motive_code: str) -> str:
return find_in_cisu_nomenclature(
health_motive_code,
[Constants.MR0_LABEL, Constants.MR1_LABEL],
Constants.OLD_MR_LABEL,
Constants.MRSM_CISU_UPDATED_NOMENCLATURE_FILE
)

def get_code_cisu_mr0_from_health_motive(health_motive_code: str) -> str:
return find_in_cisu_nomenclature(
health_motive_code,
[Constants.OLD_MR_LABEL],
Constants.MR0_LABEL,
Constants.MRSM_CISU_UPDATED_NOMENCLATURE_FILE
)

def update_health_motive_code(json_data: Dict[str, Any], isCodeDeprecated: bool):
health_motive_code = get_field_value(json_data, '$.qualification.healthMotive.code')

if health_motive_code is not None:
if isCodeDeprecated:
updated_health_motive_code = get_deprecated_code_cisu_from_health_motive(health_motive_code)
else:
updated_health_motive_code = get_code_cisu_mr0_from_health_motive(health_motive_code)

if updated_health_motive_code is not None:
json_data['qualification']['healthMotive'] = {
'code': updated_health_motive_code,
'label': get_field_value(json_data, '$.qualification.healthMotive.label')
}
4 changes: 4 additions & 0 deletions converter/converter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ class Constants:
V2_GITHUB_TAG="release/2.x-maintenance"
V3_GITHUB_TAG="3.0.0"

V3_VERSION="v3"
V2_VERSION="v2"
V1_VERSION="v1"

EDXL_HEALTH_TO_FIRE_ENVELOPE_PATH="tests/edxl_envelope_health_to_fire.json"
EDXL_FIRE_TO_HEALTH_ENVELOPE_PATH="tests/edxl_envelope_fire_to_health.json"
EDXL_HEALTH_TO_HEALTH_ENVELOPE_PATH="tests/edxl_envelope_health_to_health.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def cisu_conversion_strategy(edxl_json, source_version, target_version):

TO_CISU = "to_CISU"
FROM_CISU = "from_CISU"
MAINTAINED_CISU_VERSION = "v3"
MAINTAINED_CISU_VERSION = Constants.V3_VERSION

# Compute direction based on sender / recipient
sender = get_sender(edxl_json)
Expand All @@ -25,12 +25,12 @@ def cisu_conversion_strategy(edxl_json, source_version, target_version):
raise ValueError(f"Unknown target version {target_version}. Must be: {MAINTAINED_CISU_VERSION}")

rs_json_message = health_conversion_strategy(edxl_json, source_version, MAINTAINED_CISU_VERSION)
return CISUConverterV3.to_cisu(rs_json_message)
return CISUConverterV3(target_version).to_cisu(rs_json_message)
elif direction == FROM_CISU:
if source_version != MAINTAINED_CISU_VERSION:
raise ValueError(f"Unknown source version {source_version}. Must be: {MAINTAINED_CISU_VERSION}")

rc_json_message = CISUConverterV3.from_cisu(edxl_json)
rc_json_message = CISUConverterV3.from_cisu(edxl_json, target_version)
return health_conversion_strategy(rc_json_message, MAINTAINED_CISU_VERSION, target_version)
else:
raise ValueError('Invalid direction parameter')
Loading
Loading