-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathicd11_controller.py
More file actions
109 lines (82 loc) · 4.02 KB
/
Copy pathicd11_controller.py
File metadata and controls
109 lines (82 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import operator
import connexion
from swagger_server import config
from swagger_server.controllers.query_controller import *
def list_icd11(lang, orphacode): # noqa: E501
"""Search for a clinical entity's ICD11 code(s) by ORPHAcode
The result retrieves the clinical entity's ORPHAcode and its preferred term as well as annotated ICD-11 code(s), specifying the characterisation of the alignment between the clinical entity and ICD-11 code, and the status of the mapping (validated/not yet validated). # noqa: E501
:param lang: Language
:type lang: str
:param orphacode: A unique and time-stable numerical identifier attributed randomly by the Orphanet database to each clinical entity upon its creation.
:type orphacode: int
:rtype: Icd11
"""
es = config.elastic_server
index = "rdcode_orpha_icd11_mapping"
index = "{}_{}".format(index, lang.lower())
query = '{\"query\": {\"match\": {\"ORPHAcode\": ' + str(orphacode) + '}},' \
'\"_source\":[\"ORPHAcode\", \"Preferred term\", \"OrphanetURL\", \"Code ICD\",\"Date\"]}'
response = single_res(es, index, query)
# Test to return error
if isinstance(response, str) or isinstance(response, tuple):
return response
else:
references = response.pop("Code ICD")
references.sort(key=operator.itemgetter("Code ICD11"))
response["References"] = references
# return yaml if needed
response = if_yaml(connexion.request.accept_mimetypes.best, response)
return response
def list_orpha_by_icd11(lang, icd11): # noqa: E501
"""Search for a clinical entity's ORPHAcode(s) by ICD-11 code
The result retrieves the ICD-11 code as well as annotated ORPHAcode(s) and preferred term, specifying the characterisation of the alignment between the clinical entity and ICD-11 code, and the status of the mapping (validated/not yet validated). # noqa: E501
:param lang: Language
:type lang: str
:param icd11: ICD11 code of entity
:type icd11: str
:rtype: EntityByIcd
"""
es = config.elastic_server
index = "rdcode_orpha_icd11_mapping"
index = "{}_{}".format(index, lang.lower())
query = {
"query": {
"query_string": {
"default_field": "Code ICD.Code ICD11",
"query": str(icd11)
}
}
}
response_icd_to_orpha = multiple_res(es, index, query, 9999)
# Statement condition to return error
if isinstance(response_icd_to_orpha, str) or isinstance(response_icd_to_orpha, tuple):
return response_icd_to_orpha
# If no response (response_icd_to_orpha) is ok, it needs to be formatted
"""
Source data are organized from the perspective of ORPHA concept
1 ORPHAcode => X ICD
response_icd_to_orpha is a list of object containing "Code ICD"
"Code ICD" is also a list of object that need to be filtrated by ICD
"""
response = {}
response["Date"] = response_icd_to_orpha[0]["Date"]
response["Code ICD11"] = icd11
response["References"] = []
for hit in response_icd_to_orpha:
reference = {
"ORPHAcode": int(hit["ORPHAcode"]),
"Preferred term": hit["Preferred term"]
}
for CodeICD in hit["Code ICD"]:
reference["Code ICD11"] = CodeICD["Code ICD11"]
reference["DisorderMappingRelation"] = CodeICD["DisorderMappingRelation"]
reference["DisorderMappingICDRelation"] = CodeICD["DisorderMappingICDRelation"]
reference["DisorderMappingValidationStatus"] = CodeICD["DisorderMappingValidationStatus"]
reference["DisorderMappingICDRefUrl"] = CodeICD["DisorderMappingICDRefUrl"]
reference["DisorderMappingICDRefUri"] = CodeICD["DisorderMappingICDRefUri"]
response["References"].append(reference)
# Sort references by Orphacode
response["References"].sort(key=operator.itemgetter("ORPHAcode"))
# return yaml if needed
response = if_yaml(connexion.request.accept_mimetypes.best, response)
return response