def get_calls(): f = open( '../../../../../smart_server/smart/document_processing/schema/smart.owl' ).read() rdf_ontology.parse_ontology(f) out = [] for t in rdf_ontology.api_calls: path = str(t.path) method = str(t.method) target = str(t.target).replace("http://smartplatforms.org/terms#", "") category = str(t.category) by_internal_id = True if str(t.by_internal_id) == "true" else False if path not in [ "/apps/{descriptor}/manifest", "/records/search?given_name={given_name}&family_name={family_name}&zipcode={zipcode}&birthday={birthday}&gender={gender}&medical_record_number={medical_record_number}", "/users/search?given_name={given_name}&family_name={family_name}" ]: out.append({ "path": path, "method": method, "category": category, "target": target, "by_internal_id": by_internal_id }) return out
def get_calls(): f = open('../../../../../smart_server/smart/document_processing/schema/smart.owl').read() rdf_ontology.parse_ontology(f) out = [] for t in rdf_ontology.api_calls: path = str(t.path) method = str(t.method) target = str(t.target).replace("http://smartplatforms.org/terms#","") category = str(t.category) by_internal_id = True if str(t.by_internal_id) == "true" else False if path not in ["/apps/{descriptor}/manifest", "/records/search?given_name={given_name}&family_name={family_name}&zipcode={zipcode}&birthday={birthday}&gender={gender}&medical_record_number={medical_record_number}", "/users/search?given_name={given_name}&family_name={family_name}"]: out.append({"path": path, "method": method, "category": category, "target": target, "by_internal_id": by_internal_id}) return out
def GET(self): '''Returns the available python client calls based on the ontology''' # Load the local copy of the ontology via the SMART client try: sc = get_smart_client(APP_PATH + '/data/smart.owl') except: # When the oauth credentials are bad or another execption occurs, # perform a manual ontology parsing routine which blocks any # consequent SMART client instantiations rdf_ontology.parse_ontology(open(APP_PATH + '/data/smart.owl').read()) # Initialize the output dictionary out = {} # Iterate over the ontology calls for t in rdf_ontology.api_calls: # Fetch the metadata of the api call path = str(t.path) method = str(t.method) target = str(t.target) category = str(t.category) # Process only GET calls of "record_items" category plus a few specific # exceptions by adding them to the dictionary if method == "GET" and (category == "record_items" or path == "/ontology" or path == "/apps/manifests/" or path == "/capabilities/"): # Build the generic python client call name and use it in the dictionary out[target] = {"call_py": get_call(target)} # Return the dictionary serialized as "pretty" JSON return json.dumps(out, sort_keys=True, indent=4)
def get_model(call): '''Returns the name of the target SMART data model corresponding to the SMART python client convenience method Expects a valid SMART python client convenience method name ''' # Local class needed by the call_name method class API_Call(): def __init__ (self, path, method): self.path = path self.method = method # We may have to load the ontology if it is not available yet if not rdf_ontology.api_types: rdf_ontology.parse_ontology(open(APP_PATH + '/data/smart.owl').read()) # Get all the API calls from the ontology r = rdf_ontology.get_api_calls() # Look through the api calls array until a call with matching convenience method name is found for target in r.keys(): if call == call_name(API_Call(r[target], "GET")): return target.replace("http://smartplatforms.org/terms#","")
'''Returns a list of test sparql queries for the given model''' queries = [] generate_queries (data, queries, str(NS['sp'][model])) return queries # Query builder state variables main_types = [] data = {} loaded = False # Initialize the namespace manager object namespace_manager = NamespaceManager(Graph()) # Import the namespaces into the namespace manager for ns in NS.keys(): namespace_manager.bind(ns, NS[ns], override=False) # Parse the ontology when necessary if not rdf_ontology.api_types: rdf_ontology.parse_ontology(open(APP_PATH + '/data/smart.owl').read()) # Build a list of data types that need to be added to the data definitions for t in rdf_ontology.api_types: if t.is_statement or len(t.calls) > 0 or rdf_ontology.sp.Component in [x.uri for x in t.parents]: main_types.append(t) # Build the data definitions object with each data type for t in main_types: generate_data_for_type(t, data)
queries = [] generate_queries(data, queries, str(NS['sp'][model])) return queries # Query builder state variables main_types = [] data = {} loaded = False # Initialize the namespace manager object namespace_manager = NamespaceManager(Graph()) # Import the namespaces into the namespace manager for ns in NS.keys(): namespace_manager.bind(ns, NS[ns], override=False) # Parse the ontology when necessary if not rdf_ontology.api_types: rdf_ontology.parse_ontology(open(APP_PATH + '/data/smart.owl').read()) # Build a list of data types that need to be added to the data definitions for t in rdf_ontology.api_types: if t.is_statement or len(t.calls) > 0 or rdf_ontology.sp.Component in [ x.uri for x in t.parents ]: main_types.append(t) # Build the data definitions object with each data type for t in main_types: generate_data_for_type(t, data)