Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate SSSOM for ICD11 to ICD11 codes #286

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/pyobo/sources/icd11.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
logger = logging.getLogger(__name__)

PREFIX = "icd11"
CODE_PREFIX = "icd11.code"

CODE_PROP = TypeDef(reference=default_reference(PREFIX, "icd_mms_code"), is_metadata_tag=True)

Expand All @@ -49,8 +50,13 @@ def iterate_icd11() -> Iterable[Term]:
res = get_icd(ICD11_TOP_LEVEL_URL)
res_json = res.json()
version = res_json["releaseId"]
mms_directory = prefix_directory_join(PREFIX, "mms", version=version)

# Get all terms from the ICD foundation API
terms = list(iterate_icd11_helper(res_json, version))

# prepare a directory for enriching from MMS
mms_directory = prefix_directory_join(PREFIX, "mms", version=version)

# this takes a bit more than 2 hours
for term in tqdm(terms, desc="Getting MMS", unit_scale=True):
path = mms_directory.joinpath(term.identifier).with_suffix(".json")
Expand All @@ -63,12 +69,10 @@ def iterate_icd11() -> Iterable[Term]:
# writing this isn't necessary since not all terms have MMS entries
# tqdm.write(str(e))
mms_data = {}
else:
path.write_text(json.dumps(mms_data))
path.write_text(json.dumps(mms_data))

if code := mms_data.get("code"):
# TODO decide on ICD code prefix, then append this as a mapping
term.annotate_literal(CODE_PROP, code)
term.append_exact_match(Reference(prefix=CODE_PREFIX, identifier=code))

yield term

Expand Down
Loading