def smart_problems(toc): g=rdflib.Graph() cdautil.rdfinit(g) # Create a namespace object dcterms=Namespace("http://purl.org/dc/terms/") rdf=Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") sp=Namespace("http://smartplatforms.org/terms#") smart=Namespace("http://sandbox-api.smartplatforms.org/records/") snomed=Namespace("http://purl.bioontology.org/ontology/SNOMEDCT/") ccd=Namespace("http://this.ccd.com/") j=toc['problem-count'] for i in range(1,j+1): pdata='problem-'+str(i)+'-data' p=toc[pdata] sub=ccd[pdata] g.add((sub,RDF.type,sp['Problem'])) bto=ccd['problems'] g.add((sub,sp['belongsTo'],bto)) g.add((sub,sp['startDate'],Literal(p['effectiveTime']))) probname=BNode() g.add((sub,sp['problemName'],probname)) g.add((probname,RDF.type,sp['CodedValue'])) g.add((probname,dcterms['title'],Literal(p['displayName']))) g.add((probname,sp['code'],snomed[p['code']])) return g
def smart_medications(toc): g=rdflib.Graph() cdautil.rdfinit(g) # Create a namespace object dcterms=Namespace("http://purl.org/dc/terms/") rdf=Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") sp=Namespace("http://smartplatforms.org/terms#") smart=Namespace("http://sandbox-api.smartplatforms.org/records/") snomed=Namespace("http://purl.bioontology.org/ontology/SNOMEDCT/") rxnorm=Namespace("http://purl.bioontology.org/ontology/RXNORM/") ccd=Namespace("http://this.ccd.com/") j=toc['medication-count'] for i in range(1,j+1): meddata='medication-'+str(i)+'-data' med=toc[meddata] sub=ccd[meddata] g.add((sub,RDF.type,sp['Medication'])) bto=ccd['medications'] g.add((sub,sp['belongsTo'],bto)) g.add((sub,sp['startDate'],Literal(med['effectiveTime']))) medname=BNode() g.add((sub,sp['medicationName'],medname)) g.add((medname,RDF.type,sp['CodedValue'])) g.add((medname,dcterms['title'],Literal(med['displayName']))) g.add((medname,sp['code'],rxnorm[med['code']])) route=med['route'] binstr=BNode() broute=BNode() g.add((medname,sp['instructions'],binstr)) g.add((binstr,sp['route'],broute)) g.add((broute,RDF.type,sp['CodedValue'])) g.add((broute,sp['codeSystemName'],Literal(route['codeSystemName']))) g.add((broute,sp['code'],Literal(route['code']))) g.add((broute,dcterms['title'],Literal(route['displayName']))) # g.add((broute,sp['originalText'],Literal(route['originalText']))) # try rtrans=route['translation'] # brtrans=BNode() # g.add((broute,sp['translation'],brtrans)) # g.add((brtrans,RDF.type,sp['CodedValue'])) # g.add((brtrans,sp['codeSystemName'],Literal(rtrans['codeSystemName']))) # g.add((brtrans,sp['code'],Literal(rtrans['code']))) # g.add((brtrans,dcterms['title'],Literal(rtrans['displayName']))) period=med['period'] bperiod=BNode() dose=med['dose'] bdose=BNode() g.add((medname,sp['quantity'],bdose)) g.add((bdose,sp['unit'],Literal(dose['unit']))) g.add((bdose,sp['value'],Literal(dose['value']))) freq=med['period'] bfreq=BNode() g.add((medname,sp['frequency'],bfreq)) # g.add((bfreq,RDF.type,sp['CodedValue'])) g.add((bfreq,sp['unit'],Literal(freq['unit']))) g.add((bfreq,sp['value'],Literal(freq['value']))) return g