Skip to content

Commit

Permalink
Update icd11.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Jan 10, 2025
1 parent 90c97ae commit b1e183d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/pyobo/sources/icd11.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
from collections.abc import Iterable, Mapping
from typing import Any

import bioregistry
from tqdm.auto import tqdm

from .icd_utils import (
ICD11_TOP_LEVEL_URL,
ICDError,
get_child_identifiers,
get_icd,
get_icd_11_mms,
visiter,
)
from ..struct import Obo, Reference, Synonym, Term, TypeDef, default_reference
Expand All @@ -31,14 +32,6 @@

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

# This hacks a non-sanctioned prefix into the bioregistry
# for demonstration purposes. Do not merge with this!
bioregistry.manager.synonyms[CODE_PREFIX] = CODE_PREFIX
bioregistry.manager.registry[CODE_PREFIX] = bioregistry.Resource(
prefix=CODE_PREFIX,
name="ICD11 Code",
)


class ICD11Getter(Obo):
"""An ontology representation of ICD-11."""
Expand All @@ -57,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 Down

0 comments on commit b1e183d

Please sign in to comment.