-
Notifications
You must be signed in to change notification settings - Fork 1
/
main-background.py
45 lines (38 loc) · 1.34 KB
/
main-background.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from smart_client_python import oauth
from smart_client_python import smart
from smart_client_python.common import util as smart_util
from xml.etree import ElementTree
import urllib
def get_smart_client(resource_tokens=None):
# instantiate the smart client
smart_client = smart.SmartClient(
{'api_base' : 'http://sandbox-api.smartplatforms.org'},
{'consumer_key' : '[email protected]',
'consumer_secret' : 'smartapp-secret'},
resource_tokens)
return smart_client
QUERY = """
PREFIX dcterms:<http://purl.org/dc/terms/>
PREFIX sp:<http://smartplatforms.org/terms#>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?drugname
WHERE {
?med rdf:type sp:Medication .
?med sp:drugName ?drugname_code .
?drugname_code dcterms:title ?drugname .
}
"""
def print_drugnames():
"""
map a function onto every record
"""
smart_client = get_smart_client()
for record_id in smart_client.loop_over_records():
medications = smart_client.records_X_medications_GET(record_id = record_id)
med_names = medications.query(QUERY)
print "%s: %s" % (record_id, ", ".join([str(m) for m in med_names]))
def run():
print_drugnames()
if __name__ == '__main__':
run()