Skip to content

Commit

Permalink
merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Apr 13, 2021
2 parents 4c347be + b9e023b commit 4632d9c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
22 changes: 18 additions & 4 deletions tests/unit/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def phenobarbital():
"type": "TherapyDescriptor",
"value": {
"type": "Therapy",
"therapy_id": "rxcui:8134"
"id": "rxcui:8134"
},
"label": "Phenobarbital",
"xrefs": [
Expand Down Expand Up @@ -127,7 +127,7 @@ def cisplatin():
"type": "TherapyDescriptor",
"value": {
"type": "Therapy",
"therapy_id": "rxcui:2555",
"id": "rxcui:2555",
},
"label": "cisplatin",
"xrefs": [
Expand Down Expand Up @@ -195,7 +195,7 @@ def spiramycin():
"type": "TherapyDescriptor",
"value": {
"type": "Therapy",
"therapy_id": "ncit:C839"
"id": "ncit:C839"
},
"label": "Spiramycin",
"xrefs": [
Expand Down Expand Up @@ -231,7 +231,7 @@ def timolol():
"type": "TherapyDescriptor",
"value": {
"type": "Therapy",
"therapy_id": "rxcui:10600"
"id": "rxcui:10600"
},
"label": "timolol",
"alternate_labels": [
Expand Down Expand Up @@ -506,6 +506,20 @@ def test_query_merged(merge_query_handler, phenobarbital, cisplatin,
assert 'record' not in response
assert response['match_type'] == MatchType.NO_MATCH

test_query = "APRD00818"
response = merge_query_handler.search_groups(test_query)
assert response['query'] == test_query
assert response['warnings'] is None
assert 'record' not in response
assert response['match_type'] == MatchType.NO_MATCH

test_query = "chembl:CHEMBL1200368"
response = merge_query_handler.search_groups(test_query)
assert response['query'] == test_query
assert response['warnings'] is None
assert 'record' not in response
assert response['match_type'] == MatchType.NO_MATCH


def test_merged_meta(merge_query_handler):
"""Test population of source and resource metadata in merged querying."""
Expand Down
14 changes: 7 additions & 7 deletions therapy/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _add_merged_meta(self, response: Dict) -> Dict:
"""
sources_meta = {}
vod = response['value_object_descriptor']
ids = [vod['value']['therapy_id']] + vod.get('xrefs', [])
ids = [vod['value']['id']] + vod.get('xrefs', [])
for concept_id in ids:
prefix = concept_id.split(':')[0]
src_name = PREFIX_LOOKUP[prefix.lower()]
Expand Down Expand Up @@ -375,7 +375,7 @@ def _add_vod(self, response: Dict, record: Dict, query: str,
'type': 'TherapyDescriptor',
'value': {
'type': 'Therapy',
'therapy_id': record['concept_id']
'id': record['concept_id']
},
'label': record['label'],
'extensions': [],
Expand Down Expand Up @@ -447,7 +447,7 @@ def search_groups(self, query: str) -> Dict:

# check concept ID match
record = self.db.get_record_by_id(query_str, case_sensitive=False)
if record:
if record and record['src_name'].lower() not in PROHIBITED_SOURCES:
merge = self.db.get_record_by_id(record['merge_ref'],
case_sensitive=False,
merge=True)
Expand All @@ -462,10 +462,10 @@ def search_groups(self, query: str) -> Dict:
for match_type in ['label', 'trade_name', 'alias', 'other_id']:
# get matches list for match tier
matching_refs = self.db.get_records_by_type(query_str, match_type)
matching_records = [self.db.get_record_by_id(m['concept_id'],
False)
for m in matching_refs
if m['src_name'] not in PROHIBITED_SOURCES]
matching_records = \
[self.db.get_record_by_id(m['concept_id'], False)
for m in matching_refs
if m['src_name'].lower() not in PROHIBITED_SOURCES]
matching_records.sort(key=self._record_order)

# attempt merge ref resolution until successful
Expand Down
2 changes: 1 addition & 1 deletion therapy/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def schema_extra(schema: Dict[str, Any],
"type": "TherapyDescriptor",
"value": {
"type": "Therapy",
"therapy_id": "rxcui:2555"
"id": "rxcui:2555"
},
"label": "cisplatin",
"xrefs": [
Expand Down

0 comments on commit 4632d9c

Please sign in to comment.