#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Dec 12 10:57:46 2022 @author: saramarceglia """ import requests import json import PySimpleGUI as sg apikey = "XXXXX" #qui ciascuno deve mettere la propria baseURI = "https://uts-ws.nlm.nih.gov/rest" path = "/search/current" pathDefinition = '/content/current/CUI/' #FUNZIONE CHE SERVE PER ESTRARRE IL VALORE SELEZIONATO DAL MENU A TENDINA def callback(var, index, mode): """ For OptionMenu var - tkinter control variable. index - index of var, '' if var is not a list. mode - 'w' for 'write' here. """ window.write_event_value('-CONCEPTLIST-', window['-CONCEPTLIST-'].TKStringVar.get()) #creo layout della finestra conceptList = ['',] layout = [[sg.Text("Inserisci un termine di ricerca")], [sg.Input(key='-INPUT-')], [sg.Button('Search')], [sg.Text('Diagnosi:'),sg.OptionMenu(values=conceptList , key='-CONCEPTLIST-')], [sg.Button('Vedi Definizione')], [sg.Text(key = '-OUTPUT-')], [sg.Button('Quit')]] #creo la finestra window = sg.Window('Insert Diagnosis', layout) #Event Loop di interazione while True: event, values = window.read() if event == 'Quit' or event == sg.WINDOW_CLOSED: break elif event == 'Search': searchTerm = values['-INPUT-'] param = {'apiKey': apikey,'string':searchTerm,'pageNumber':1} results = requests.get(baseURI+path, params= param) resList = results.json()['result']['results'] ConceptList2 = [d['name'] for d in resList] window['-CONCEPTLIST-'].update(values = ConceptList2) window['-CONCEPTLIST-'].TKStringVar.trace("w", callback) elif event == 'Vedi Definizione': name = values['-CONCEPTLIST-'] pos = ConceptList2.index(name) CUI = resList[pos]['ui'] dictDef = {'apiKey':apikey,'sabs':'MSH'} resDef = requests.get(baseURI+pathDefinition+CUI+'/definitions',params = dictDef) if resDef.status_code == 200: window['-OUTPUT-'].update(resDef.json()['result'][0]['value']) else: window['-OUTPUT-'].update('Definizione non trovata') #Chiusura finestra window.close()