Example #1
0
    def attach_statements_to_record(self, g, new_uris, var_bindings):
        # Attach each data element (med, problem, lab, etc), to the
        # base record URI with the sp:Statement predicate.
        recordURI = URIRef(
            smart_path("/records/%s" % var_bindings['record_id']))
        for n in new_uris:
            node_type = get_property(g, n, rdf.type)

            # Filter for top-level medical record "Statement" types
            t = ontology[node_type]
            if (not t.is_statement):
                continue
            if (not t.base_path.startswith("/records")):
                continue
            if (n == recordURI):
                continue  # don't assert that the record has itself as an element

            # There's no need to include belongsTo in a POSTed graph.
            # ... but if belongsTo is present, it must be identical
            # to the current recordURI
            existing_record = list(g.triples((n, sp.belongsTo, None)))
            if len(existing_record) > 1:
                raise Exception("Can't have multiple belongsTo statements")
            if len(existing_record) > 0 \
                and existing_record[0][2] != recordURI:
                    raise Exception("Conflicting belongsTo statements")

            g.add((n, sp.belongsTo, recordURI))
            g.add((recordURI, sp.hasStatement, n))
            g.add((recordURI, rdf.type, sp.MedicalRecord))
 def attach_statements_to_record(self, g, new_uris, var_bindings):
     # Attach each data element (med, problem, lab, etc), to the 
     # base record URI with the sp:Statement predicate.
     recordURI = URIRef(smart_path("/records/%s"%var_bindings['record_id']))
     for n in new_uris:
         node_type = get_property(g, n, rdf.type)
         
         # Filter for top-level medical record "Statement" types
         t = ontology[node_type]
         if (not t.is_statement): continue
         if (not t.base_path.startswith("/records")): continue
         if (n == recordURI): continue # don't assert that the record has itself as an element
         
         g.add((n, sp.belongsTo, recordURI))
         g.add((recordURI, sp.hasStatement, n))
         g.add((recordURI, rdf.type, sp.MedicalRecord))