import json import urllib.request import urllib.error import sys codes_to_test = [ "200148007", # user googled this "11466000", # Cesarean section "177141003", # Elective / Emergency? "34430009", # Rupture of uterus "73368009", # Foley catheter "237296008", # Placenta accreta spectrum "70129008", # Placenta accreta "10588007", # Perinatal death "408817009", # Amniotomy at delivery "31821006", # Uterine scar "441097003", # Initial code for VBAC "398909004", # Initial code for placenta praevia "18949003", # Initial code for epidural "276505004", # Initial code for perinatal death "274127005", # Initial code for classical scar "A-1014", # Initial code for foley catheter ] headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'Accept': 'application/json' } for code in codes_to_test: url = f"https://snowstorm.ihtsdotools.org/fhir/CodeSystem/$lookup?system=http://snomed.info/sct&code={code}" try: req = urllib.request.Request(url, headers=headers) with urllib.request.urlopen(req, timeout=8) as resp: data = json.loads(resp.read().decode('utf-8')) display = None params = data.get("parameter", []) for p in params: if p.get("name") == "display": display = p.get("valueString") elif p.get("name") == "property": # designations pass print(f"[ONLINE FOUND] Code: {code} -> Display: '{display}'") except urllib.error.HTTPError as he: if he.code == 404: print(f"[ONLINE NOT FOUND - 404] Code: {code} does not exist in SNOMED International!") else: print(f"[ONLINE ERROR] Code: {code} -> HTTP {he.code}") except Exception as e: print(f"[ONLINE ERROR] Code: {code} -> {e}")