-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorph_acode_aggregation_controller.py
More file actions
54 lines (42 loc) · 2.43 KB
/
Copy pathorph_acode_aggregation_controller.py
File metadata and controls
54 lines (42 loc) · 2.43 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
import connexion
from swagger_server.models.error_model import ErrorModel # noqa: E501
from swagger_server.models.orph_acode_aggregation import ORPHAcodeAggregation # noqa: E501
from swagger_server import util
import config
from controllers.query_controller import *
def list_aggregation(lang, orphacode): # noqa: E501
"""Search for a clinical entity's aggregation code by ORPHAcode
The result retrieves the clinical entity's ORPHAcode, its preferred term as well as the ORPHAcode and the preferred term of the aggregation code. # 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: ORPHAcodeAggregation
"""
es = config.elastic_server
index = "rdcode_orphanomenclature"
index = "{}_{}".format(index, lang.lower())
query = "{\"query\": {\"match\": {\"ORPHAcode\": " + str(orphacode) + "}}," \
"\"_source\":[\"Date\", \"AggregationlevelSection\", \"Preferred term\", \"ORPHAcode\"]}"
response = single_res(es, index, query)
# bug when utf8 special char. such "é" etc. commenting the print
# print(response, flush=True)
# Check for error, an error will be returned as text or tuple
if isinstance(response, str) or isinstance(response, tuple):
pass
else:
# If an AggregationLevel is applicable return the ORPHAcode and Preferred term from the Aggregation
if response["AggregationlevelSection"].get("AggregationLevel"):
response = {"Date": response["Date"],
"ORPHAcodeAggregation": response["AggregationlevelSection"]["AggregationLevel"][0]["ORPHAcode"],
"Preferred term": response["AggregationlevelSection"]["AggregationLevel"][0]["Preferred term"],
}
else:
# If an AggregationLevel is NOT applicable return the ORPHAcode and Preferred term from the query
response = {"Date": response["Date"],
"ORPHAcodeAggregation": response["AggregationlevelSection"]["OrphaCodeAggregation"],
"Preferred term": response["AggregationlevelSection"]["PreferredTerm"],
}
# return yaml if needed
response = if_yaml(connexion.request.accept_mimetypes.best, response)
return response