You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
from dotenv import dotenv_values
|
|
import requests
|
|
import json
|
|
from drugtools.env_setup import ENV,postgres_conn
|
|
from psycopg2 import extras
|
|
|
|
|
|
|
|
class Requestor():
|
|
def __init__(self,api_key):
|
|
self.key = api_key
|
|
|
|
def search(self,search_term,inputType="sourceUi", returnIdType="code", addnl_terms={}):
|
|
query_terms = {
|
|
"apiKey":self.key,
|
|
"sabs":"ICD10",
|
|
"string":search_term,
|
|
"returnIdType":returnIdType,
|
|
"inputType":inputType
|
|
} | addnl_terms
|
|
query = "https://uts-ws.nlm.nih.gov/rest/search/current/"
|
|
|
|
r = requests.get(query,params=query_terms)
|
|
print(r.url)
|
|
return r
|
|
|
|
|
|
r = Requestor(ENV.get("UMLS_API_KEY"))
|
|
print(json.dumps(r.search("leukemia").json(),indent=2))
|
|
|
|
|
|
conditions_link = {}
|
|
|
|
pconn = postgres_conn()
|
|
pcurse = pconn.cursor(cursor_factory=extras.DictCursor)
|
|
sql = """
|
|
select nct_id, downcase_mesh_term
|
|
from ctgov.browse_conditions bc
|
|
where
|
|
mesh_type = 'mesh-list'
|
|
and
|
|
nct_id in (select distinct nct_id from history.trial_snapshots ts)
|
|
order by nct_id
|
|
;
|
|
"""
|
|
pcurse.execute(sql)
|
|
rows = pcurse.fetchall()
|
|
for row in rows:
|
|
nctid = row[0]
|
|
condition = row[1]
|
|
print(nctid,condition)
|
|
|
|
results = r.search(row[1]).json().get('result', Exception("No result entry in json")).get('results',Exception("No results entry in json"))
|
|
for entry in results:
|
|
print("\t", entry["ui"], entry["name"])
|
|
|
|
|
|
|