1818 get_sender ,
1919 is_field_completed ,
2020 translate_key_words ,
21+ set_value ,
2122)
2223from converter .cisu .base_cisu_converter import BaseCISUConverter
2324import logging
@@ -51,40 +52,60 @@ def from_cisu_to_rs(cls, input_json: Dict[str, Any]) -> Dict[str, Any]:
5152
5253 def set_default_location_freetext (json_data : Dict [str , Any ]):
5354 logger .debug ("Setting default location freetext" )
54- if not is_field_completed (json_data , "$.location.freetext" ):
55- json_data [ "location" ][ "freetext" ] = (
56- "" # need at least empty value to pass validation
57- )
55+ if not is_field_completed (
56+ json_data , CreateCaseCISUConstants . LOCATION_FREETEXT_PATH
57+ ):
58+ set_value ( json_data , CreateCaseCISUConstants . LOCATION_FREETEXT_PATH , "" )
5859
5960 def add_location_detail (json_data : Dict [str , Any ]):
6061 logger .debug ("Adding location detail to freetext" )
61- if is_field_completed (json_data , "$.location.city.detail" ):
62- set_default_location_freetext (json_data )
63- json_data ["location" ]["freetext" ] += (
64- "\n Détails de commune : " + json_data ["location" ]["city" ]["detail" ]
65- )
62+ location_city_detail = get_field_value (
63+ json_data , CreateCaseCISUConstants .LOCATION_CITY_DETAIL_PATH
64+ )
65+ if not location_city_detail :
66+ return
67+
68+ current_location_freetext = get_field_value (
69+ json_data , CreateCaseCISUConstants .LOCATION_FREETEXT_PATH
70+ )
71+ updated_location_freetext = current_location_freetext + (
72+ "\n Détails de commune : " + location_city_detail
73+ )
74+ set_value (
75+ json_data ,
76+ CreateCaseCISUConstants .LOCATION_FREETEXT_PATH ,
77+ updated_location_freetext ,
78+ )
6679
6780 def add_case_priority (json_data : Dict [str , Any ]):
6881 logger .debug ("Adding case priority" )
69- if is_field_completed (json_data , "$.initialAlert.reporting" ):
70- if not is_field_completed (json_data , "$.qualification.details" ):
71- json_data ["qualification" ]["details" ] = {}
72- json_data ["qualification" ]["details" ]["priority" ] = (
73- "P0"
74- if get_field_value (json_data , "$.initialAlert.reporting" )
75- == "ATTENTION"
76- else "P2"
77- )
82+ initial_alert_reporting = get_field_value (
83+ json_data , CreateCaseCISUConstants .INITIAL_ALERT_REPORTING_PATH
84+ )
85+ if not initial_alert_reporting :
86+ return
87+
88+ new_priority_value = (
89+ "P0" if initial_alert_reporting == "ATTENTION" else "P2"
90+ )
91+ set_value (
92+ json_data ,
93+ CreateCaseCISUConstants .QUALIFICATION_DETAILS_PRIORITY_PATH ,
94+ new_priority_value ,
95+ )
7896
7997 def merge_notes_freetext (json_data : Dict [str , Any ]):
8098 logger .debug ("Merging freetext notes" )
81- if not is_field_completed (json_data , "$.initialAlert.notes" ):
99+ initial_alert_notes = get_field_value (
100+ json_data , CreateCaseCISUConstants .INITIAL_ALERT_NOTES_PATH
101+ )
102+ if not initial_alert_notes :
82103 return json_data
83104
84105 merged_texts = []
85106 other_notes = []
86107
87- for note in json_data [ "initialAlert" ][ "notes" ] :
108+ for note in initial_alert_notes :
88109 if "freetext" in note :
89110 merged_texts .append (note ["freetext" ])
90111 else :
@@ -94,7 +115,11 @@ def merge_notes_freetext(json_data: Dict[str, Any]):
94115
95116 result_notes = [merged_note ] if merged_note else []
96117 result_notes .extend (other_notes )
97- json_data ["initialAlert" ]["notes" ] = result_notes
118+ set_value (
119+ json_data ,
120+ CreateCaseCISUConstants .INITIAL_ALERT_NOTES_PATH ,
121+ result_notes ,
122+ )
98123
99124 return json_data
100125
@@ -104,20 +129,18 @@ def add_victims_to_medical_notes(json_data: Dict[str, Any], sender_id: str):
104129
105130 if field_value is None :
106131 return
107- else :
108- formatted_field_value = dump (field_value , allow_unicode = True )
109- translated_text = translate_key_words (
110- formatted_field_value ,
111- CreateCaseCISUConstants .MEDICAL_NOTE_KEY_TRANSLATIONS ,
112- )
113- add_object_to_medical_notes (json_data , translated_text , sender_id )
132+
133+ formatted_field_value = dump (field_value , allow_unicode = True )
134+ translated_text = translate_key_words (
135+ formatted_field_value ,
136+ CreateCaseCISUConstants .MEDICAL_NOTE_KEY_TRANSLATIONS ,
137+ )
138+ add_object_to_medical_notes (json_data , translated_text , sender_id )
114139
115140 def add_object_to_medical_notes (
116141 json_data : Dict [str , Any ], note_text : str , sender_id : str
117142 ):
118143 logger .debug ("Adding object to medical notes" )
119- if not is_field_completed (json_data , "$.medicalNote" ):
120- json_data ["medicalNote" ] = []
121144
122145 random_str = "" .join (
123146 random .choices (
@@ -133,7 +156,14 @@ def add_object_to_medical_notes(
133156 "operator" : {"role" : "AUTRE" },
134157 }
135158
136- json_data ["medicalNote" ].append (new_note )
159+ medical_notes = (
160+ get_field_value (json_data , CreateCaseCISUConstants .MEDICAL_NOTE_PATH )
161+ or []
162+ )
163+ medical_notes .append (new_note )
164+ set_value (
165+ json_data , CreateCaseCISUConstants .MEDICAL_NOTE_PATH , medical_notes
166+ )
137167
138168 # Create independent envelope copy without usecase for output
139169 output_json = cls .copy_cisu_input_content (input_json )
@@ -143,18 +173,21 @@ def add_object_to_medical_notes(
143173 output_use_case_json = cls .copy_cisu_input_use_case_content (input_json )
144174
145175 # - Updates
146- output_use_case_json ["owner" ] = get_recipient (input_json )
176+ set_value (
177+ output_use_case_json ,
178+ CreateCaseCISUConstants .OWNER_PATH ,
179+ get_recipient (input_json ),
180+ )
147181
148182 set_default_location_freetext (output_use_case_json )
149183 add_location_detail (output_use_case_json )
150184
151- if is_field_completed (output_use_case_json , "$.initialAlert" ):
152- add_case_priority (output_use_case_json )
153- add_to_initial_alert_notes (
154- output_use_case_json ,
155- CreateCaseCISUConstants .CISU_PATHS_TO_ADD_TO_INITIAL_ALERT_NOTES ,
156- )
157- merge_notes_freetext (output_use_case_json )
185+ add_case_priority (output_use_case_json )
186+ add_to_initial_alert_notes (
187+ output_use_case_json ,
188+ CreateCaseCISUConstants .CISU_PATHS_TO_ADD_TO_INITIAL_ALERT_NOTES ,
189+ )
190+ merge_notes_freetext (output_use_case_json )
158191
159192 add_victims_to_medical_notes (output_use_case_json , sender_id )
160193
@@ -197,10 +230,10 @@ def from_rs_to_cisu(cls, input_json: Dict[str, Any]) -> Dict[str, Any]:
197230
198231 def add_victim_information (json_data : Dict [str , Any ]):
199232 logger .debug ("Adding victim information" )
200- if not is_field_completed ( json_data , "$.qualification" ):
201- json_data [ "qualification" ] = {}
202- json_data [ "qualification" ][ "victims" ] = cls . get_victim_count (
203- cls , input_usecase_json
233+ set_value (
234+ json_data ,
235+ CreateCaseCISUConstants . QUALIFICATION_VICTIMS_PATH ,
236+ cls . get_victim_count ( cls , input_usecase_json ),
204237 )
205238
206239 def get_call_taker_information (json_data : Dict [str , Any ]):
@@ -216,11 +249,20 @@ def get_call_taker_information(json_data: Dict[str, Any]):
216249
217250 def add_default_external_info_type (json_data : Dict [str , Any ]):
218251 logger .debug ("Adding default external info type" )
219- external_info = get_field_value (json_data , "$.location.externalInfo" )
220- if external_info is not None :
221- for info in external_info :
222- if not is_field_completed (info , "$.type" ):
223- info ["type" ] = "AUTRE"
252+ external_info = get_field_value (
253+ json_data , CreateCaseCISUConstants .LOCATION_EXTERNAL_INFO_PATH
254+ )
255+ if external_info is None :
256+ return
257+ for info in external_info :
258+ if not is_field_completed (
259+ info , CreateCaseCISUConstants .LOCATION_EXTERNAL_INFO_TYPE_PATH
260+ ):
261+ set_value (
262+ info ,
263+ CreateCaseCISUConstants .LOCATION_EXTERNAL_INFO_TYPE_PATH ,
264+ CreateCaseCISUConstants .DEFAULT_LOCATION_EXTERNAL_INFO_TYPE ,
265+ )
224266
225267 # Create independent envelope copy without usecase for output
226268 output_json = cls .copy_rs_input_content (input_json )
@@ -237,19 +279,30 @@ def add_default_external_info_type(json_data: Dict[str, Any]):
237279
238280 # - Updates
239281 # ToDo: pass this by ConfigMap and based on the version of the model
240- output_usecase_json ["referenceVersion" ] = "2.0"
282+ set_value (
283+ output_usecase_json , CreateCaseCISUConstants .REFERENCE_VERSION_PATH , "2.0"
284+ )
241285 add_victim_information (output_usecase_json )
242286
243- if not is_field_completed (output_usecase_json , "$.location" ):
244- output_usecase_json ["location" ] = {}
245-
246- output_usecase_json ["location" ]["locID" ] = f"LOC-{ timestamp } -{ random_str } "
287+ set_value (
288+ output_usecase_json ,
289+ CreateCaseCISUConstants .LOCATION_LOC_ID_PATH ,
290+ f"LOC-{ timestamp } -{ random_str } " ,
291+ )
247292 # ToDo: get country from INSEE code | Ref.: https://www.insee.fr/fr/information/7766585#titre-bloc-25
248- output_usecase_json ["location" ]["country" ] = "FR" # Default value
293+ set_value (
294+ output_usecase_json ,
295+ CreateCaseCISUConstants .LOCATION_COUNTRY_PATH ,
296+ CreateCaseCISUConstants .DEFAULT_LOCATION_COUNTRY ,
297+ )
249298
250- if not is_field_completed (output_usecase_json , "$.qualification.whatsHappen" ):
251- output_usecase_json ["qualification" ]["whatsHappen" ] = (
252- CreateCaseCISUConstants .DEFAULT_WHATS_HAPPEN
299+ if not is_field_completed (
300+ output_usecase_json , CreateCaseCISUConstants .QUALIFICATION_WHATS_HAPPEN_PATH
301+ ):
302+ set_value (
303+ output_usecase_json ,
304+ CreateCaseCISUConstants .QUALIFICATION_WHATS_HAPPEN_PATH ,
305+ CreateCaseCISUConstants .DEFAULT_WHATS_HAPPEN ,
253306 )
254307
255308 add_default_external_info_type (output_usecase_json )
@@ -260,27 +313,57 @@ def add_default_external_info_type(json_data: Dict[str, Any]):
260313 output_usecase_json , CreateCaseCISUConstants .HEALTH_PATHS_TO_DELETE
261314 )
262315
263- if is_field_completed (input_usecase_json , "$.initialAlert" ):
264- output_usecase_json ["initialAlert" ]["id" ] = f"INAL-{ timestamp } -{ random_str } "
265- output_usecase_json ["initialAlert" ]["callTaker" ] = (
266- get_call_taker_information (input_json )
316+ if is_field_completed (
317+ input_usecase_json , CreateCaseCISUConstants .INITIAL_ALERT_PATH
318+ ):
319+ set_value (
320+ output_usecase_json ,
321+ CreateCaseCISUConstants .INITIAL_ALERT_ID_PATH ,
322+ f"INAL-{ timestamp } -{ random_str } " ,
267323 )
268- output_usecase_json ["initialAlert" ]["reception" ] = get_field_value (
269- input_usecase_json , "$.creation"
324+
325+ set_value (
326+ output_usecase_json ,
327+ CreateCaseCISUConstants .INITIAL_ALERT_CALL_TAKER_PATH ,
328+ get_call_taker_information (input_json ),
329+ )
330+
331+ set_value (
332+ output_usecase_json ,
333+ CreateCaseCISUConstants .INITIAL_ALERT_RECEPTION_PATH ,
334+ get_field_value (
335+ input_usecase_json , CreateCaseCISUConstants .CREATION_PATH
336+ ),
270337 )
271- output_usecase_json ["initialAlert" ]["reporting" ] = (
338+
339+ new_initial_alert_reporting = (
272340 "ATTENTION"
273341 if get_field_value (
274342 input_usecase_json , "$.qualification.details.priority"
275343 )
276344 in ["P0" , "P1" ]
277345 else "STANDARD"
278346 )
279- output_usecase_json ["initialAlert" ]["qualification" ] = copy .deepcopy (
280- get_field_value (output_usecase_json , "$.qualification" )
347+ set_value (
348+ output_usecase_json ,
349+ CreateCaseCISUConstants .INITIAL_ALERT_REPORTING_PATH ,
350+ new_initial_alert_reporting ,
351+ )
352+
353+ set_value (
354+ output_usecase_json ,
355+ CreateCaseCISUConstants .INITIAL_ALERT_QUALIFICATION_PATH ,
356+ get_field_value (
357+ output_usecase_json , CreateCaseCISUConstants .QUALIFICATION_PATH
358+ ),
281359 )
282- output_usecase_json ["initialAlert" ]["location" ] = copy .deepcopy (
283- get_field_value (output_usecase_json , "$.location" )
360+
361+ set_value (
362+ output_usecase_json ,
363+ CreateCaseCISUConstants .INITIAL_ALERT_LOCATION_PATH ,
364+ get_field_value (
365+ output_usecase_json , CreateCaseCISUConstants .LOCATION_PATH
366+ ),
284367 )
285368
286369 return cls .format_cisu_output_json (output_json , output_usecase_json )
0 commit comments