cuiretrievbegeted

Sort:
GalaxyPen15

#This script will return CUI information for a single search term.
#Optional query parameters are commented out below.

import requests
import argparse
import json

def results_list(input):
parser = argparse.ArgumentParser(description='process user given parameters')
parser.add_argument("-k", "--apikey", required = True, dest = "apikey", help = "enter api key from your UTS Profile")
parser.add_argument("-v", "--version", required = False, dest="version", default = "current", help = "enter version example-2021AA")
parser.add_argument("-s", "--string", required = True, dest="string", help = "enter a search term, using hyphens between words, like diabetic-foot")

#args = parser.parse_args()
apikey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#version = args.version
string = input
uri = "https://uts-ws.nlm.nih.gov"
content_endpoint = "/rest/search/current"
full_url = uri+content_endpoint
page = 1

try:
search = True
while search ==True and page == 1:

query = {'string'nervous.pngtring,'apiKey':apikey, 'pageNumber'tongue.pngage}
#query['includeObsolete'] = 'true'
#query['includeSuppressible'] = 'true'
#query['returnIdType'] = "sourceConcept"
#query['sabs'] = "SNOMEDCT_US"
r = requests.get(full_url,params=query)
r.raise_for_status()
print(r.url)
r.encoding = 'utf-8'
outputs = r.json()

items = (([outputs['result']])[0])['results']

if len(items) == 0:
if page == 1:
print('No results found.'+'\n')
break
else:
break

print("Results for page " + str(page)+"\n")
cui = []
for result in items:
if str(result['rootSource']) == "" or "" or "" or "" or "" and search == True:
if page == 1:
print('UI: ' + result['ui'])
cui.append(result['ui'])
print('URI: ' + result['uri'])
print('Name: ' + result['name'])
print('Source Vocabulary: ' + result['rootSource'])
print('\n')
search = False



print('*********')
return cui

except Exception as except_error:
print(except_error)

print("Eingabe: ")
eingabe = input().capitalize()
CUI = results_list(eingabe)
#url4 = "https://uts-ws.nlm.nih.gov/rest/content/current/CUI/"+ str(CUI) +"/atoms?language=ENG&apiKey=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

namensliste = []

for item in CUI:
url4 = "https://uts-ws.nlm.nih.gov/rest/content/current/CUI/"+ str(item) +"/atoms?language=ENG&apiKey=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

response = requests.get(url4)

# Print the responsess
response_js = response.json()
response_json = json.dumps(response_js)

# parse the JSON data 
parsed_data = json.loads(response_json)

#print (parsed_data)

try:
#for lang["language"] in parsed_data:

name = [result["name"] for result in parsed_data["result"]] 
#print (name)
for item in name:
if not item in namensliste:
namensliste.append(item.capitalize())
except:
print("skipped")

#for item in namensliste:
# item.capitalize()

print(namensliste)