Created
December 28, 2020 20:35
-
-
Save caodac/b6d48420af8f1435fda8b05e5732242d to your computer and use it in GitHub Desktop.
Get list of U.S. approved drugs from https://drugs.ncats.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def get_additional_data(id): | |
r = requests.get('https://drugs.ncats.io/api/v1/substances(%s)/@additional' % id) | |
if 200 == r.status_code: | |
return r.json() | |
return None | |
# experiment with the filters at https://drugs.ncats.io | |
params = { | |
'facet': ['Substance Form/Principal Form', | |
'Development Status/US Approved Rx', | |
'Development Status/US Approved OTC'], | |
'skip': 0, | |
'top': 100 | |
} | |
print('UNII\tName\tYear\tConditions\tStatus\tSource') | |
total = 0 | |
while True: | |
r = requests.get('https://drugs.ncats.io/api/v1/substances/search', params) | |
if 200 != r.status_code: | |
print('%s returns status code %d!' % (r.url, r.status_code)) | |
break | |
json = r.json() | |
count = json['count'] | |
total = total + count | |
#print('fetched %d/%d' % (total, json['total'])) | |
for r in json['content']: | |
#print('...%s' % r['uuid']) | |
data = get_additional_data(r['uuid']) | |
if data != None: | |
status = None | |
year = None | |
conds = [] | |
for d in data: | |
if (d['name'] == 'Highest Development Event' | |
or (d['name'] == 'Earliest Approved Event' and status == None)): | |
status = d['value'] | |
elif d['name'] == 'Approval Year': | |
year = d['value'] | |
elif d['name'] == 'Conditions': | |
conds.append(d['value']['label']) | |
if status != None and not status['withdrawn']: | |
print('%s\t%s\t%s\t%s\t%s\t%s' % ( | |
r['approvalID'], r['_name'], year, ';'.join(conds), status['status'], status['sourceURL'])) | |
if count < json['top']: | |
# we're done | |
break | |
params['skip'] = total | |
#print('%d records processed!' % total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment