Skip to content

Commit

Permalink
rm vod
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma committed Sep 12, 2023
1 parent 9f59e1e commit 6c7cc58
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
23 changes: 11 additions & 12 deletions disease/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,14 @@ def _add_merged_meta(self, response: Dict) -> Dict:
response["source_meta_"] = sources_meta
return response

def _add_vod(
self, response: Dict, record: Dict, query: str, match_type: MatchType
def _add_disease(
self, response: Dict, record: Dict, match_type: MatchType
) -> NormalizationService:
"""Format received DB record as VOD and update response object.
"""Format received DB record as core Disease object and update response object.
:param Dict response: in-progress response object
:param Dict record: record as stored in DB
:param str query: query string from user request
:param MatchType match_type: type of match achieved
:param response: in-progress response object
:param record: record as stored in DB
:param match_type: type of match achieved
:return: completed normalized response object ready to return to user
"""
disease_obj = core_models.Disease(
Expand Down Expand Up @@ -415,7 +414,7 @@ def normalize(self, query: str) -> NormalizationService:
# check merged concept ID match
record = self.db.get_record_by_id(query_str, case_sensitive=False, merge=True)
if record:
return self._add_vod(response, record, query, MatchType.CONCEPT_ID)
return self._add_disease(response, record, MatchType.CONCEPT_ID)

non_merged_match = None

Expand All @@ -429,7 +428,7 @@ def normalize(self, query: str) -> NormalizationService:
if merge is None:
return self._handle_failed_merge_ref(record, response, query_str)
else:
return self._add_vod(response, merge, query, MatchType.CONCEPT_ID)
return self._add_disease(response, merge, MatchType.CONCEPT_ID)
else:
non_merged_match = (record, "concept_id")

Expand Down Expand Up @@ -457,8 +456,8 @@ def normalize(self, query: str) -> NormalizationService:
record, response, query_str
)
else:
return self._add_vod(
response, merge, query, MatchType[match_type.upper()]
return self._add_disease(
response, merge, MatchType[match_type.upper()]
)
else:
if not non_merged_match:
Expand All @@ -467,6 +466,6 @@ def normalize(self, query: str) -> NormalizationService:
# if no successful match, try available non-merged match
if non_merged_match:
match_type = MatchType[non_merged_match[1].upper()]
return self._add_vod(response, non_merged_match[0], query, match_type)
return self._add_disease(response, non_merged_match[0], match_type)

return NormalizationService(**response)
12 changes: 6 additions & 6 deletions tests/unit/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def mafd2():
)


def compare_vod(actual, fixture):
def compare_disease(actual, fixture):
"""Verify correctness of returned Disease core object against test fixture."""
actual = actual.disease
actual_keys = actual.model_dump(exclude_none=True).keys()
Expand Down Expand Up @@ -253,7 +253,7 @@ def test_normalize_query(query_handler, neuroblastoma, mafd2):
response = query_handler.normalize("Neuroblastoma")
assert response.match_type == MatchType.LABEL
assert response.warnings is None
compare_vod(response, neuroblastoma)
compare_disease(response, neuroblastoma)
assert len(response.source_meta_) == 4
assert SourceName.NCIT in response.source_meta_
assert SourceName.DO in response.source_meta_
Expand All @@ -263,7 +263,7 @@ def test_normalize_query(query_handler, neuroblastoma, mafd2):
response = query_handler.normalize("MAFD2")
assert response.match_type == MatchType.ALIAS
assert response.warnings is None
compare_vod(response, mafd2)
compare_disease(response, mafd2)
assert len(response.source_meta_) == 2
assert SourceName.MONDO in response.source_meta_

Expand All @@ -273,19 +273,19 @@ def test_normalize_non_mondo(query_handler, skin_myo, neuroblastoma):
response = query_handler.normalize("Skin Myoepithelioma")
assert response.match_type == MatchType.LABEL
assert len(response.source_meta_) == 1
compare_vod(response, skin_myo)
compare_disease(response, skin_myo)
assert SourceName.NCIT in response.source_meta_

response = query_handler.normalize("Cutaneous Myoepithelioma")
assert response.match_type == MatchType.ALIAS
assert len(response.source_meta_) == 1
compare_vod(response, skin_myo)
compare_disease(response, skin_myo)
assert SourceName.NCIT in response.source_meta_

response = query_handler.normalize("orphanet:635")
assert response.match_type == MatchType.XREF
assert len(response.source_meta_) == 4
compare_vod(response, neuroblastoma)
compare_disease(response, neuroblastoma)
assert SourceName.NCIT in response.source_meta_
assert SourceName.DO in response.source_meta_
assert SourceName.MONDO in response.source_meta_
Expand Down

0 comments on commit 6c7cc58

Please sign in to comment.