Download scripts/verify_live_sample.py from gitmodelmujtaba/medical-guidelines-kg: direct link, hf CLI and curl.
- Browser
- Download file 3.05 kB
-
https://huggingface.co/spaces/gitmodelmujtaba/medical-guidelines-kg/resolve/main/scripts/verify_live_sample.py
- Command line
-
hf download hf://spaces/gitmodelmujtaba/medical-guidelines-kg/scripts/verify_live_sample.py
-
curl -L -o verify_live_sample.py https://huggingface.co/spaces/gitmodelmujtaba/medical-guidelines-kg/resolve/main/scripts/verify_live_sample.py
3.05 kB
| import json | |
| import time | |
| import urllib.request | |
| import urllib.error | |
| verified_candidates = [ | |
| ("200148007", "User's query (Elective repeat caesarean section)"), | |
| ("177141003", "Elective cesarean section"), | |
| ("274130007", "Emergency cesarean section"), | |
| ("11466000", "Cesarean section"), | |
| ("458441000124101", "Trial of labor after cesarean delivery"), | |
| ("18946005", "Epidural anesthesia"), | |
| ("408817009", "Amniotomy at delivery"), | |
| ("236958009", "Induction of labor"), | |
| ("237001001", "Augmentation of labor"), | |
| ("34430009", "Rupture of uterus"), | |
| ("36813001", "Placenta previa"), | |
| ("70129008", "Placenta accreta"), | |
| ("237296008", "Placenta accreta spectrum"), | |
| ("34842007", "Antepartum hemorrhage"), | |
| ("10588007", "Perinatal death"), | |
| ("46775006", "Neonatal respiratory distress syndrome"), | |
| ("31821006", "Uterine scar from previous surgery affecting pregnancy"), | |
| ("1290152008", "Singleton pregnancy"), | |
| ("70028003", "Vertex presentation"), | |
| ("73368009", "Foley catheter"), | |
| ("236962003", "Cervical ripening with Foley catheter"), | |
| ] | |
| headers = { | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ClinicalGuidelineKG/1.0', | |
| 'Accept': 'application/fhir+json, application/json' | |
| } | |
| print(f"Verifying {len(verified_candidates)} sample concepts via Live Snowstorm FHIR API...") | |
| print("=" * 80) | |
| results = [] | |
| for code, label in verified_candidates: | |
| url = f"https://snowstorm.ihtsdotools.org/fhir/CodeSystem/$lookup?system=http://snomed.info/sct&code={code}" | |
| time.sleep(0.5) # respectful rate limit | |
| try: | |
| req = urllib.request.Request(url, headers=headers) | |
| with urllib.request.urlopen(req, timeout=10) as resp: | |
| raw = resp.read().decode('utf-8') | |
| data = json.loads(raw) | |
| display = "" | |
| for p in data.get("parameter", []): | |
| if p.get("name") == "display": | |
| display = p.get("valueString") | |
| print(f"✓ SCTID {code:16} | LIVE SNOMED: '{display:42}' | Expected: '{label}'") | |
| results.append({"code": code, "status": "VALID", "live_display": display, "expected": label}) | |
| except urllib.error.HTTPError as he: | |
| if he.code == 404: | |
| print(f"✗ SCTID {code:16} | [404 NOT FOUND - INVALID / OBSOLETE SCTID] | Expected: '{label}'") | |
| results.append({"code": code, "status": "NOT_FOUND_404", "live_display": None, "expected": label}) | |
| else: | |
| print(f"! SCTID {code:16} | HTTP {he.code} | Expected: '{label}'") | |
| results.append({"code": code, "status": f"HTTP_{he.code}", "live_display": None, "expected": label}) | |
| except Exception as e: | |
| print(f"! SCTID {code:16} | ERROR: {e} | Expected: '{label}'") | |
| results.append({"code": code, "status": f"ERROR_{e}", "live_display": None, "expected": label}) | |
| with open("data/live_api_verification_results.json", "w", encoding="utf-8") as f: | |
| json.dump(results, f, indent=2) | |
| print("\nVerification summary saved to data/live_api_verification_results.json") | |