Skip to content

Commit 3a3d1a5

Browse files
committed
Add handling of QNode set_interpretation. Error when ALL or MANY
1 parent 55dfdfb commit 3a3d1a5

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

cohd/cohd_trapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TrapiStatusCode(Enum):
2626
UNSUPPORTED_CONSTRAINT = 'UnsupportedConstraint'
2727
UNSUPPORTED_ATTR_CONSTRAINT = 'UnsupportedAttributeConstraint'
2828
UNSUPPORTED_QUAL_CONSTRAINT = 'UnsupportedQualifierConstraint'
29+
UNSUPPORTED_SET_INTERPRETATION = 'UnsupportedSetInterpretation'
2930

3031

3132
class CohdTrapi(ABC):

cohd/cohd_trapi_15.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class CohdTrapi150(CohdTrapi):
2929
supported_edge_types = ['biolink:positively_correlated_with', 'biolink:negatively_correlated_with',
3030
'biolink:has_real_world_evidence_of_association_with']
3131

32+
# QNode set_interpretation values that COHD TRAPI does not support
33+
supported_set_interpretation = ['BATCH']
34+
unsupported_set_interpretation = list(set(['BATCH', 'ALL', 'MANY']) - set(supported_set_interpretation))
35+
3236
# Biolink predicates that request positive associations only
3337
edge_types_positive = ['biolink:positively_correlated_with']
3438
default_positive_predicate = edge_types_positive[0]
@@ -568,8 +572,18 @@ def _interpret_query(self):
568572
self._invalid_query_response = response, 200
569573
return self._valid_query, self._invalid_query_response
570574

575+
# If client specifies unsupported set_interpretation (ALL or MANY), respond with error code
576+
if concept_1_qnode.get('set_interpretation') in CohdTrapi150.unsupported_set_interpretation or \
577+
concept_2_qnode.get('set_interpretation') in CohdTrapi150.unsupported_set_interpretation:
578+
self._valid_query = False
579+
description = f'{CohdTrapi._SERVICE_NAME} only supports QNode set_interpretation of {CohdTrapi150.supported_set_interpretation}'
580+
self.log(description, TrapiStatusCode.UNSUPPORTED_SET_INTERPRETATION, logging.ERROR)
581+
response = self._trapi_mini_response(TrapiStatusCode.UNSUPPORTED_SET_INTERPRETATION, description)
582+
self._invalid_query_response = response, 200
583+
return self._valid_query, self._invalid_query_response
584+
571585
# Check to see if cohd doesn't recognize any properties
572-
qnode_properties = {'ids','categories', 'is_set', 'constraints'}
586+
qnode_properties = {'ids','categories', 'set_interpretation', 'constraints'}
573587
qedge_properties = {'knowledge_type', 'predicates', 'subject', 'object', 'attribute_constraints',
574588
'qualifier_constraints'}
575589
sep = ', '

0 commit comments

Comments
 (0)