Skip to content

Commit 6494635

Browse files
authored
Merge pull request #335 from ansforge/chore/converter-clean-code
chore(converter): nettoyage du code & enrichissement des tests
2 parents f4135da + 74f1cca commit 6494635

File tree

16 files changed

+557
-149
lines changed

16 files changed

+557
-149
lines changed

converter/converter/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ def extract_message_content(edxl_json) -> Dict:
2929

3030

3131
def extract_message_type_from_message_content(
32-
message_content,
33-
unwanted_keys=["messageId", "sender", "sentAt", "kind", "status", "recipient"],
32+
message_content: Dict[str, Any],
3433
) -> str:
34+
unwanted_keys = ["messageId", "sender", "sentAt", "kind", "status", "recipient"]
35+
3536
filtered_keys = list(
3637
filter(lambda key: key not in unwanted_keys, message_content.keys())
3738
)

converter/converter/versions/create_case_health/create_case_health_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
)
1010
from converter.versions.base_message_converter import BaseMessageConverter
1111
from converter.versions.create_case_health.v1_v2.constants import V1V2Constants
12+
from converter.versions.create_case_health.v1_v2.utils import validate_diagnosis_code
1213
from converter.versions.create_case_health.v2_v3.constants import V2V3Constants
1314
from converter.versions.utils import (
1415
reverse_map_to_new_value,
1516
switch_field_name,
16-
validate_diagnosis_code,
1717
)
1818

1919

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import re
2+
from typing import Any, Dict
3+
4+
from converter.utils import (
5+
add_to_medical_notes,
6+
delete_paths,
7+
get_field_value,
8+
)
9+
from converter.versions.create_case_health.v1_v2.constants import V1V2Constants
10+
11+
12+
def validate_diagnosis_code(
13+
json_data: Dict[str, Any], patient_data: Dict[str, Any], diagnosis_type: str
14+
):
15+
diagnosis = get_field_value(patient_data, f"$.hypothesis.{diagnosis_type}")
16+
diagnosis_valid_codes = []
17+
18+
pattern = re.compile(V1V2Constants.DIAGNOSIS_CODE_VALIDATION_REGEX)
19+
20+
if diagnosis is None:
21+
return
22+
23+
code_label = (
24+
"Diagnostique(s) secondaire(s) : "
25+
if diagnosis_type == "otherDiagnosis"
26+
else "Diagnostique principal : "
27+
)
28+
29+
if type(diagnosis) is list:
30+
for index, diag in enumerate(diagnosis):
31+
code = get_field_value(diag, "$.code")
32+
if code is not None:
33+
is_correct_format = pattern.match(code)
34+
if not is_correct_format:
35+
add_to_medical_notes(
36+
json_data,
37+
patient_data,
38+
[
39+
{
40+
"path": f"hypothesis.{diagnosis_type}[{index}]",
41+
"label": code_label,
42+
}
43+
],
44+
)
45+
else:
46+
diagnosis_valid_codes.append(diag)
47+
48+
if len(diagnosis_valid_codes) == 0: # no code matches the pattern
49+
delete_paths(patient_data, [f"hypothesis.{diagnosis_type}"])
50+
else:
51+
patient_data["hypothesis"]["otherDiagnosis"] = diagnosis_valid_codes
52+
53+
else:
54+
code = get_field_value(diagnosis, "$.code")
55+
if code is not None:
56+
is_correct_format = pattern.match(code)
57+
if not is_correct_format:
58+
add_to_medical_notes(
59+
json_data,
60+
patient_data,
61+
[{"path": f"hypothesis.{diagnosis_type}", "label": code_label}],
62+
)
63+
delete_paths(patient_data, [f"hypothesis.{diagnosis_type}"])

converter/converter/versions/create_case_health/v2_v3/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ class V2V3Constants:
9393

9494
V2_PATHS_TO_DELETE = [
9595
"patient[].healthMotive",
96-
"patient[].administrativeFile.externalId.source",
97-
"patient[].administrativeFile.externalId.value",
9896
]
9997

10098
V3_PATHS_TO_DELETE = [

converter/converter/versions/utils.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import re
21
from typing import Any, Dict, Optional
32

43
from converter.utils import (
5-
add_to_medical_notes,
6-
delete_paths,
74
get_field_value,
85
is_field_completed,
96
update_json_value,
@@ -36,61 +33,6 @@ def switch_field_name(
3633
json_data[new_field_name] = json_data[previous_field_name]
3734

3835

39-
def validate_diagnosis_code(
40-
json_data: Dict[str, Any], patient_data: Dict[str, Any], diagnosis_type: str
41-
):
42-
DIAGNOSIS_CODE_VALIDATION_REGEX = "^[A-Z]\\d{2}(\\.[\\d\\+\\-]{1,3})?$"
43-
diagnosis = get_field_value(patient_data, f"$.hypothesis.{diagnosis_type}")
44-
diagnosis_valid_codes = []
45-
46-
pattern = re.compile(DIAGNOSIS_CODE_VALIDATION_REGEX)
47-
48-
if diagnosis is None:
49-
return
50-
51-
code_label = (
52-
"Diagnostique(s) secondaire(s) : "
53-
if diagnosis_type == "otherDiagnosis"
54-
else "Diagnostique principal : "
55-
)
56-
57-
if type(diagnosis) is list:
58-
for index, diag in enumerate(diagnosis):
59-
code = get_field_value(diag, "$.code")
60-
if code is not None:
61-
is_correct_format = pattern.match(code)
62-
if not is_correct_format:
63-
add_to_medical_notes(
64-
json_data,
65-
patient_data,
66-
[
67-
{
68-
"path": f"hypothesis.{diagnosis_type}[{index}]",
69-
"label": code_label,
70-
}
71-
],
72-
)
73-
else:
74-
diagnosis_valid_codes.append(diag)
75-
76-
if len(diagnosis_valid_codes) == 0: # no code matches the pattern
77-
delete_paths(patient_data, [f"hypothesis.{diagnosis_type}"])
78-
else:
79-
patient_data["hypothesis"]["otherDiagnosis"] = diagnosis_valid_codes
80-
81-
else:
82-
code = get_field_value(diagnosis, "$.code")
83-
if code is not None:
84-
is_correct_format = pattern.match(code)
85-
if not is_correct_format:
86-
add_to_medical_notes(
87-
json_data,
88-
patient_data,
89-
[{"path": f"hypothesis.{diagnosis_type}", "label": code_label}],
90-
)
91-
delete_paths(patient_data, [f"hypothesis.{diagnosis_type}"])
92-
93-
9436
def convert_to_float(value: Optional[str]) -> Optional[float]:
9537
if value is None:
9638
return None

converter/tests/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ class TestConstants:
1919
GEO_REQ_TAG = "GEO-REQ"
2020
GEO_RES_TAG = "GEO-RES"
2121
RC_EDA_TAG = "RC-EDA"
22+
RC_REF_TAG = "RC-REF"
2223
RC_RI_TAG = "RC-RI"
2324
RS_BPV_TAG = "RS-BPV"
2425
RS_DR_TAG = "RS-DR"
2526
RS_EDA_TAG = "RS-EDA"
2627
RS_EDA_MAJ_TAG = "RS-EDA-MAJ"
2728
RS_ER_TAG = "RS-ER"
29+
RS_ERROR_TAG = "RS-ERROR"
2830
RS_RI_TAG = "RS-RI"
2931
RS_RPIS_TAG = "RS-RPIS"
3032
RS_RR_TAG = "RS-RR"

converter/tests/conversion_strategy/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)