@@ -146,8 +146,8 @@ def _check_query_input(self):
146146 return self ._valid_query , self ._invalid_query_response
147147
148148 # Check the structure of the query graph. Should have 2 nodes and 1 edge (one-hop query)
149- nodes = query_graph .get ('nodes' )
150- edges = query_graph .get ('edges' )
149+ nodes = list ( query_graph .get ('nodes' ). values () )
150+ edges = list ( query_graph .get ('edges' ). values () )
151151 if nodes is None or len (nodes ) != 2 or edges is None or len (edges ) != 1 :
152152 self ._valid_query = False
153153 msg = 'Unsupported query. Only one-hop queries supported.'
@@ -156,6 +156,55 @@ def _check_query_input(self):
156156 self ._invalid_query_response = response , 200
157157 return self ._valid_query , self ._invalid_query_response
158158
159+ # If client provided non-empty QNode constraints, respond with error code
160+ if nodes [0 ].get ('constraints' ) or nodes [1 ].get ('constraints' ):
161+ self ._valid_query = False
162+ description = f'{ CohdTrapi ._SERVICE_NAME } does not support QNode constraints'
163+ self .log (description , TrapiStatusCode .UNSUPPORTED_CONSTRAINT , logging .ERROR )
164+ response = self ._trapi_mini_response (TrapiStatusCode .UNSUPPORTED_CONSTRAINT , description )
165+ self ._invalid_query_response = response , 200
166+ return self ._valid_query , self ._invalid_query_response
167+ if edges [0 ].get ("attribute_constraints" ):
168+ self ._valid_query = False
169+ description = f'{ CohdTrapi ._SERVICE_NAME } does not support QEdge attribute constraints'
170+ self .log (description , TrapiStatusCode .UNSUPPORTED_ATTR_CONSTRAINT , logging .ERROR )
171+ response = self ._trapi_mini_response (TrapiStatusCode .UNSUPPORTED_ATTR_CONSTRAINT , description )
172+ self ._invalid_query_response = response , 200
173+ return self ._valid_query , self ._invalid_query_response
174+ if edges [0 ].get ("qualifier_constraints" ):
175+ self ._valid_query = False
176+ description = f'{ CohdTrapi ._SERVICE_NAME } does not support QEdge qualifier constraints'
177+ self .log (description , TrapiStatusCode .UNSUPPORTED_QUAL_CONSTRAINT , logging .ERROR )
178+ response = self ._trapi_mini_response (TrapiStatusCode .UNSUPPORTED_QUAL_CONSTRAINT , description )
179+ self ._invalid_query_response = response , 200
180+ return self ._valid_query , self ._invalid_query_response
181+
182+ # If client specifies unsupported set_interpretation (ALL or MANY), respond with error code
183+ if nodes [0 ].get ('set_interpretation' ) in CohdTrapi150 .unsupported_set_interpretation or \
184+ nodes [1 ].get ('set_interpretation' ) in CohdTrapi150 .unsupported_set_interpretation :
185+ self ._valid_query = False
186+ description = f'{ CohdTrapi ._SERVICE_NAME } only supports QNode set_interpretation of { CohdTrapi150 .supported_set_interpretation } '
187+ self .log (description , TrapiStatusCode .UNSUPPORTED_SET_INTERPRETATION , logging .ERROR )
188+ response = self ._trapi_mini_response (TrapiStatusCode .UNSUPPORTED_SET_INTERPRETATION , description )
189+ self ._invalid_query_response = response , 200
190+ return self ._valid_query , self ._invalid_query_response
191+
192+ # Check to see if cohd doesn't recognize any properties
193+ qnode_properties = {'ids' ,'categories' , 'set_interpretation' , 'constraints' }
194+ unrec_properties = (set (nodes [0 ].keys ()) | (set (nodes [1 ].keys ()))) - qnode_properties
195+ if unrec_properties :
196+ description = f'{ CohdTrapi ._SERVICE_NAME } does not recognize the following node properties: ' \
197+ f'{ ", " .join (unrec_properties )} . { CohdTrapi ._SERVICE_NAME } will ignore these properties.'
198+ self .log (description , level = logging .WARNING )
199+
200+ qedge_properties = {'knowledge_type' , 'predicates' , 'subject' , 'object' , 'attribute_constraints' ,
201+ 'qualifier_constraints' }
202+ unrec_properties = set (edges [0 ].keys ()) - qedge_properties
203+ if unrec_properties :
204+ description = f'{ CohdTrapi ._SERVICE_NAME } does not recognize the following edge properties: ' \
205+ f'{ ", " .join (unrec_properties )} . { CohdTrapi ._SERVICE_NAME } will ignore these properties.'
206+ self .log (description , level = logging .WARNING )
207+
159208 # Check the workflow. Should be at most a single lookup operation
160209 workflow = self ._json_data .get ('workflow' )
161210 if workflow and type (workflow ) is list :
@@ -227,7 +276,7 @@ def _interpret_query(self):
227276 True if input is valid, otherwise (False, message)
228277 """
229278 # Log that TRAPI 1.4 was called because there's no clear indication otherwise
230- logging .debug ('Query issued against TRAPI 1.4 ' )
279+ logging .debug (f 'Query issued against TRAPI { CohdTrapi150 . schema_version } ' )
231280
232281 try :
233282 self ._json_data = self ._request .get_json ()
@@ -552,62 +601,6 @@ def _interpret_query(self):
552601 self .log (f'The following categories were not recognized in Biolink { bm_version } : { unrecognized_cats } ' ,
553602 level = logging .WARNING )
554603
555- # If client provided non-empty QNode constraints, respond with error code
556- if concept_1_qnode .get ('constraints' ) or concept_2_qnode .get ('constraints' ):
557- self ._valid_query = False
558- description = f'{ CohdTrapi ._SERVICE_NAME } does not support QNode constraints'
559- self .log (description , TrapiStatusCode .UNSUPPORTED_CONSTRAINT , logging .ERROR )
560- response = self ._trapi_mini_response (TrapiStatusCode .UNSUPPORTED_CONSTRAINT , description )
561- self ._invalid_query_response = response , 200
562- return self ._valid_query , self ._invalid_query_response
563- if self ._query_edge .get ("attribute_constraints" ):
564- self ._valid_query = False
565- description = f'{ CohdTrapi ._SERVICE_NAME } does not support QEdge attribute constraints'
566- self .log (description , TrapiStatusCode .UNSUPPORTED_ATTR_CONSTRAINT , logging .ERROR )
567- response = self ._trapi_mini_response (TrapiStatusCode .UNSUPPORTED_ATTR_CONSTRAINT , description )
568- self ._invalid_query_response = response , 200
569- return self ._valid_query , self ._invalid_query_response
570- if self ._query_edge .get ("qualifier_constraints" ):
571- self ._valid_query = False
572- description = f'{ CohdTrapi ._SERVICE_NAME } does not support QEdge qualifier constraints'
573- self .log (description , TrapiStatusCode .UNSUPPORTED_QUAL_CONSTRAINT , logging .ERROR )
574- response = self ._trapi_mini_response (TrapiStatusCode .UNSUPPORTED_QUAL_CONSTRAINT , description )
575- self ._invalid_query_response = response , 200
576- return self ._valid_query , self ._invalid_query_response
577-
578- # If client specifies unsupported set_interpretation (ALL or MANY), respond with error code
579- if concept_1_qnode .get ('set_interpretation' ) in CohdTrapi150 .unsupported_set_interpretation or \
580- concept_2_qnode .get ('set_interpretation' ) in CohdTrapi150 .unsupported_set_interpretation :
581- self ._valid_query = False
582- description = f'{ CohdTrapi ._SERVICE_NAME } only supports QNode set_interpretation of { CohdTrapi150 .supported_set_interpretation } '
583- self .log (description , TrapiStatusCode .UNSUPPORTED_SET_INTERPRETATION , logging .ERROR )
584- response = self ._trapi_mini_response (TrapiStatusCode .UNSUPPORTED_SET_INTERPRETATION , description )
585- self ._invalid_query_response = response , 200
586- return self ._valid_query , self ._invalid_query_response
587-
588- # Check to see if cohd doesn't recognize any properties
589- qnode_properties = {'ids' ,'categories' , 'set_interpretation' , 'constraints' }
590- qedge_properties = {'knowledge_type' , 'predicates' , 'subject' , 'object' , 'attribute_constraints' ,
591- 'qualifier_constraints' }
592- sep = ', '
593- unrec_properties = set (concept_1_qnode .keys ()) - qnode_properties
594- if unrec_properties :
595- description = f'{ CohdTrapi ._SERVICE_NAME } does not recognize the following properties: ' \
596- f'{ sep .join (unrec_properties )} . { CohdTrapi ._SERVICE_NAME } will ignore these properties.'
597- self .log (description , level = logging .WARNING )
598-
599- unrec_properties = set (concept_2_qnode .keys ()) - qnode_properties
600- if unrec_properties :
601- description = f'{ CohdTrapi ._SERVICE_NAME } does not recognize the following properties: ' \
602- f'{ sep .join (unrec_properties )} . { CohdTrapi ._SERVICE_NAME } will ignore these properties.'
603- self .log (description , level = logging .WARNING )
604-
605- unrec_properties = set (self ._query_edge .keys ()) - qedge_properties
606- if unrec_properties :
607- description = f'{ CohdTrapi ._SERVICE_NAME } does not recognize the following properties: ' \
608- f'{ sep .join (unrec_properties )} . { CohdTrapi ._SERVICE_NAME } will ignore these properties.'
609- self .log (description , level = logging .WARNING )
610-
611604 # Get concept_id_1. QNode IDs is a list.
612605 self ._concept_1_omop_ids = list ()
613606 found = False
0 commit comments