created base of umls linking script
parent
29644a0ad5
commit
e2edf1eb6b
@ -0,0 +1,58 @@
|
||||
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"])
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue