Skip to content

Commit b022ea5

Browse files
committed
refactor(converter): extract constants from create case cisu converter
1 parent 53776dd commit b022ea5

File tree

2 files changed

+60
-53
lines changed

2 files changed

+60
-53
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
class CreateCaseCISUConstants:
2+
CISU_PATHS_TO_DELETE = [
3+
"qualification.victims",
4+
"referenceVersion",
5+
"freetext",
6+
"location.geometry.point.coord.heading",
7+
"location.geometry.point.coord.speed",
8+
"location.geometry.sketch",
9+
"location.country",
10+
"location.locID",
11+
"location.locLabel",
12+
"location.city.detail",
13+
"initialAlert.id",
14+
"initialAlert.attachment",
15+
"initialAlert.reporting",
16+
"initialAlert.qualification",
17+
"initialAlert.location",
18+
"initialAlert.callTaker",
19+
"newAlert",
20+
]
21+
22+
HEALTH_PATHS_TO_DELETE = [
23+
"owner",
24+
"patient",
25+
"medicalNote",
26+
"decision",
27+
"perimeter",
28+
"interventionType",
29+
"qualification.origin",
30+
"qualification.details",
31+
"location.detailedAddress.highway",
32+
"location.geometry.point.isAml",
33+
]
34+
35+
CISU_PATHS_TO_ADD_TO_INITIAL_ALERT_NOTES = [
36+
{"path": "$.initialAlert.attachment", "label": "Pièces jointes :"},
37+
{"path": "$.initialAlert.callTaker", "label": "Contact de l'opérateur SIS :"},
38+
{"path": "$.freetext", "label": ""},
39+
{"path": "$.newAlert", "label": "Nouvelles alertes :"},
40+
]
41+
42+
MEDICAL_NOTE_KEY_TRANSLATIONS = {
43+
"freetext:": "Commentaire général :",
44+
"mainVictim:": "Victime principale :",
45+
"count:": "Nombre de victimes :",
46+
}
47+
48+
DEFAULT_WHATS_HAPPEN = {"code": "C11.06.00", "label": "Autre nature de fait"}

converter/converter/cisu/create_case/create_case_cisu_converter.py

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
from yaml import dump
88

9+
from converter.cisu.create_case.create_case_cisu_constants import (
10+
CreateCaseCISUConstants,
11+
)
912
from converter.cisu.utils import add_to_initial_alert_notes
1013
from converter.constants import Constants
1114
from converter.utils import (
@@ -25,54 +28,6 @@
2528
class CreateCaseCISUConverter(BaseCISUConverter):
2629
"""Handles CISU format conversions"""
2730

28-
CISU_PATHS_TO_DELETE = [
29-
"qualification.victims",
30-
"referenceVersion",
31-
"freetext",
32-
"location.geometry.point.coord.heading",
33-
"location.geometry.point.coord.speed",
34-
"location.geometry.sketch",
35-
"location.country",
36-
"location.locID",
37-
"location.locLabel",
38-
"location.city.detail",
39-
"initialAlert.id",
40-
"initialAlert.attachment",
41-
"initialAlert.reporting",
42-
"initialAlert.qualification",
43-
"initialAlert.location",
44-
"initialAlert.callTaker",
45-
"newAlert",
46-
]
47-
48-
HEALTH_PATHS_TO_DELETE = [
49-
"owner",
50-
"patient",
51-
"medicalNote",
52-
"decision",
53-
"perimeter",
54-
"interventionType",
55-
"qualification.origin",
56-
"qualification.details",
57-
"location.detailedAddress.highway",
58-
"location.geometry.point.isAml",
59-
]
60-
61-
CISU_PATHS_TO_ADD_TO_INITIAL_ALERT_NOTES = [
62-
{"path": "$.initialAlert.attachment", "label": "Pièces jointes :"},
63-
{"path": "$.initialAlert.callTaker", "label": "Contact de l'opérateur SIS :"},
64-
{"path": "$.freetext", "label": ""},
65-
{"path": "$.newAlert", "label": "Nouvelles alertes :"},
66-
]
67-
68-
MEDICAL_NOTE_KEY_TRANSLATIONS = {
69-
"freetext:": "Commentaire général :",
70-
"mainVictim:": "Victime principale :",
71-
"count:": "Nombre de victimes :",
72-
}
73-
74-
DEFAULT_WHATS_HAPPEN = {"code": "C11.06.00", "label": "Autre nature de fait"}
75-
7631
@classmethod
7732
def get_rs_message_type(cls) -> str:
7833
return "createCaseHealth"
@@ -152,7 +107,8 @@ def add_victims_to_medical_notes(json_data: Dict[str, Any], sender_id: str):
152107
else:
153108
formatted_field_value = dump(field_value, allow_unicode=True)
154109
translated_text = translate_key_words(
155-
formatted_field_value, cls.MEDICAL_NOTE_KEY_TRANSLATIONS
110+
formatted_field_value,
111+
CreateCaseCISUConstants.MEDICAL_NOTE_KEY_TRANSLATIONS,
156112
)
157113
add_object_to_medical_notes(json_data, translated_text, sender_id)
158114

@@ -195,15 +151,16 @@ def add_object_to_medical_notes(
195151
if is_field_completed(output_use_case_json, "$.initialAlert"):
196152
add_case_priority(output_use_case_json)
197153
add_to_initial_alert_notes(
198-
output_use_case_json, cls.CISU_PATHS_TO_ADD_TO_INITIAL_ALERT_NOTES
154+
output_use_case_json,
155+
CreateCaseCISUConstants.CISU_PATHS_TO_ADD_TO_INITIAL_ALERT_NOTES,
199156
)
200157
merge_notes_freetext(output_use_case_json)
201158

202159
add_victims_to_medical_notes(output_use_case_json, sender_id)
203160

204161
# - Delete paths - /!\ It must be the last step
205162
logger.debug("Removing unnecessary paths")
206-
delete_paths(output_use_case_json, cls.CISU_PATHS_TO_DELETE)
163+
delete_paths(output_use_case_json, CreateCaseCISUConstants.CISU_PATHS_TO_DELETE)
207164

208165
return cls.format_rs_output_json(output_json, output_use_case_json)
209166

@@ -292,14 +249,16 @@ def add_default_external_info_type(json_data: Dict[str, Any]):
292249

293250
if not is_field_completed(output_usecase_json, "$.qualification.whatsHappen"):
294251
output_usecase_json["qualification"]["whatsHappen"] = (
295-
cls.DEFAULT_WHATS_HAPPEN
252+
CreateCaseCISUConstants.DEFAULT_WHATS_HAPPEN
296253
)
297254

298255
add_default_external_info_type(output_usecase_json)
299256

300257
# Deletions - /!\ it must be done before copying qualification and location fields
301258
logger.debug("Removing unnecessary paths")
302-
delete_paths(output_usecase_json, cls.HEALTH_PATHS_TO_DELETE)
259+
delete_paths(
260+
output_usecase_json, CreateCaseCISUConstants.HEALTH_PATHS_TO_DELETE
261+
)
303262

304263
if is_field_completed(input_usecase_json, "$.initialAlert"):
305264
output_usecase_json["initialAlert"]["id"] = f"INAL-{timestamp}-{random_str}"

0 commit comments

Comments
 (0)