Download scripts/test_online_api.py from gitmodelmujtaba/medical-guidelines-kg: direct link, hf CLI and curl.
- Browser
- Download file 2.4 kB
-
https://huggingface.co/spaces/gitmodelmujtaba/medical-guidelines-kg/resolve/main/scripts/test_online_api.py
- Command line
-
hf download hf://spaces/gitmodelmujtaba/medical-guidelines-kg/scripts/test_online_api.py
-
curl -L -o test_online_api.py https://huggingface.co/spaces/gitmodelmujtaba/medical-guidelines-kg/resolve/main/scripts/test_online_api.py
2.4 kB
| import json | |
| import urllib.request | |
| import urllib.parse | |
| # Test NIH NLM Clinical Tables API | |
| # The clinical tables API provides datasets for various clinical terminologies: | |
| # https://clinicaltables.nlm.nih.gov/apidoc/conditions/v3/doc.html | |
| # https://clinicaltables.nlm.nih.gov/apidoc/procedures/v3/doc.html | |
| # https://clinicaltables.nlm.nih.gov/apidoc/icd10cm/v3/doc.html | |
| endpoints = [ | |
| # NIH Clinical Tables Conditions (maps conditions to SNOMED CT / ICD-10) | |
| "https://clinicaltables.nlm.nih.gov/api/conditions/v3/search?terms=caesarean+section&ef=concept_id,code,coding_system", | |
| # NIH Clinical Tables Procedures | |
| "https://clinicaltables.nlm.nih.gov/api/procedures/v3/search?terms=caesarean+section&ef=concept_id,code,coding_system", | |
| # Snowstorm browser public endpoint | |
| "https://snowstorm.ihtsdotools.org/fhir/ValueSet/$expand?url=http://snomed.info/sct?fhir_vs=isa/11466000&count=5", | |
| # Snowstorm FHIR CodeSystem lookup | |
| "https://snowstorm.ihtsdotools.org/fhir/CodeSystem/$lookup?system=http://snomed.info/sct&code=11466000", | |
| # NIH NLM UTS / Clinical tables snomed endpoint check | |
| "https://clinicaltables.nlm.nih.gov/api/conditions/v3/search?terms=rupture+of+uterus&maxList=3", | |
| "https://clinicaltables.nlm.nih.gov/api/conditions/v3/search?terms=placenta+accreta&maxList=3", | |
| ] | |
| headers = { | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', | |
| 'Accept': 'application/json' | |
| } | |
| for url in endpoints: | |
| print(f"\nTesting URL: {url[:70]}...") | |
| try: | |
| req = urllib.request.Request(url, headers=headers) | |
| with urllib.request.urlopen(req, timeout=10) as resp: | |
| data = resp.read().decode('utf-8') | |
| parsed = json.loads(data) | |
| print(f"Status 200 OK! Response preview:") | |
| if isinstance(parsed, list): | |
| print(f"List with {len(parsed)} items: {parsed[:2]}") | |
| elif isinstance(parsed, dict): | |
| # If FHIR | |
| if "parameter" in parsed: | |
| params = {p.get("name"): p.get("valueString") or p.get("valueCode") or p.get("part") for p in parsed.get("parameter", [])} | |
| print(f"FHIR lookup: {params.get('name')}, display: {params.get('display')}") | |
| else: | |
| keys = list(parsed.keys())[:5] | |
| print(f"Dict with keys {keys}") | |
| except Exception as e: | |
| print(f"Error: {e}") | |