medcat.model_creation.preprocess_snomed
Classes:
-
BundleDescriptor– -
ExtensionDescription– -
FileFormatDescriptor– -
RefSetFileType– -
Snomed–Pre-process SNOMED CT release files.
-
SupportedBundles– -
SupportedExtension– -
UnkownSnomedReleaseException–
Functions:
-
get_all_children–Retrieves all the children of a given SNOMED CT ID (SCTID) from a given
-
get_direct_refset_mapping–This method uses the output from Snomed.map_snomed2icd10 or
-
match_partials_with_folders– -
parse_file–
Attributes:
PER_FILE_TYPE_PATHS
module-attribute
PER_FILE_TYPE_PATHS = {concept: join('Snapshot', 'Terminology'), description: join('Snapshot', 'Terminology'), relationship: join('Snapshot', 'Terminology'), refset: join('Snapshot', 'Refset', 'Map')}
SNOMED_FOLDER_NAME_PATTERN
module-attribute
SNOMED_FOLDER_NAME_PATTERN = compile('^SnomedCT_([A-Za-z0-9]+)_([A-Za-z0-9]+)_(\\d{8}T\\d{6}Z$)')
BundleDescriptor
dataclass
BundleDescriptor(extensions: list[SupportedExtension], ignores: dict[RefSetFileType, list[SupportedExtension]] = dict())
Methods:
Attributes:
ignores
class-attribute
instance-attribute
ignores: dict[RefSetFileType, list[SupportedExtension]] = field(default_factory=dict)
has_invalid
has_invalid(ext: SupportedExtension, file_types: tuple[RefSetFileType]) -> bool
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
196 197 198 199 200 201 202 203 204 | |
ExtensionDescription
dataclass
ExtensionDescription(exp_name_in_folder: str, exp_files: FileFormatDescriptor, exp_2nd_part_in_folder: Optional[str] = None)
Attributes:
-
exp_2nd_part_in_folder(Optional[str]) – -
exp_files(FileFormatDescriptor) – -
exp_name_in_folder(str) –
exp_2nd_part_in_folder
class-attribute
instance-attribute
FileFormatDescriptor
dataclass
FileFormatDescriptor(concept: str, description: str, relationship: str, refset: str, common_prefix: str = 'sct2_')
Methods:
Attributes:
-
common_prefix(str) – -
concept(str) – -
description(str) – -
refset(str) – -
relationship(str) –
get_concept
get_concept() -> str
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
105 106 | |
get_description
get_description() -> str
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
108 109 | |
get_file_per_type
get_file_per_type(file_type: RefSetFileType) -> str
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
96 97 98 99 100 | |
get_refset
get_refset() -> str
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
114 115 | |
get_relationship
get_relationship() -> str
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
111 112 | |
ignore_all
classmethod
ignore_all() -> FileFormatDescriptor
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
91 92 93 94 | |
RefSetFileType
Snomed
Snomed(data_path)
Pre-process SNOMED CT release files.
This class is used to create a SNOMED CT concept DataFrame ready for MedCAT CDB creation.
Attributes:
-
data_path(str) –Path to the unzipped SNOMED CT folder.
-
release(str) –Release of SNOMED CT folder.
-
uk_ext(bool) –Specifies whether the version is a SNOMED UK extension released after 2021. Defaults to False.
-
uk_drug_ext(bool) –Specifies whether the version is a SNOMED UK drug extension. Defaults to False.
-
au_ext(bool) –Specifies whether the version is a AU release. Defaults to False.
Methods:
-
list_all_relationships–List all SNOMED CT relationships.
-
map_snomed2icd10–This function maps SNOMED CT concepts to ICD-10 codes using the refset
-
map_snomed2opcs4–This function maps SNOMED CT concepts to OPCS-4 codes using the refset
-
relationship2json–Convert a single relationship map structure to JSON file.
-
to_concept_df–Create a SNOMED CT concept DataFrame.
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
265 266 267 268 269 | |
NO_VERSION_DETECTED
class-attribute
instance-attribute
NO_VERSION_DETECTED = 'N/A'
bundle
instance-attribute
bundle = _determine_bundle(data_path)
data_path
instance-attribute
data_path = data_path
list_all_relationships
list_all_relationships()
List all SNOMED CT relationships.
SNOMED CT provides a rich set of inter-relationships between concepts.
Returns:
-
list–List of all SNOMED CT relationships.
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
map_snomed2icd10
map_snomed2icd10()
This function maps SNOMED CT concepts to ICD-10 codes using the refset mappings provided in the SNOMED CT release package.
Returns:
-
dict–A dictionary containing the SNOMED CT to ICD-10 mappings including metadata.
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
521 522 523 524 525 526 527 528 529 530 531 | |
map_snomed2opcs4
map_snomed2opcs4() -> dict
This function maps SNOMED CT concepts to OPCS-4 codes using the refset mappings provided in the SNOMED CT release package.
Then it calls the internal function _map_snomed2refset() to get the DataFrame containing the OPCS-4 mappings. The function then converts the DataFrame to a dictionary using the internal function _refset_df2dict()
Raises:
-
AttributeError–If OPCS-4 mappings aren't available.
Returns:
-
dict(dict) –A dictionary containing the SNOMED CT to OPCS-4 mappings including metadata.
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | |
relationship2json
relationship2json(relationshipcode, output_jsonfile)
Convert a single relationship map structure to JSON file.
Parameters:
-
(relationshipcodestr) –A single SCTID or unique concept identifier of the relationship type.
-
(output_jsonfilestr) –Name of JSON file output.
Returns:
-
file–JSON file of relationship mapping.
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
to_concept_df
to_concept_df()
Create a SNOMED CT concept DataFrame.
Creates a SNOMED CT concept DataFrame ready for MEDCAT CDB creation.
Checks if the version is a UK extension release and sets the correct
file names for the concept and description snapshots accordingly.
Additionally, handles the divergent release format of the UK Drug
Extension >v2021 with the uk_drug_ext variable.
Returns:
-
–
pandas.DataFrame: SNOMED CT concept DataFrame.
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
SupportedBundles
Bases: Enum
Attributes:
-
UK_CLIN– -
UK_DRUG_EXT–
UK_CLIN
class-attribute
instance-attribute
UK_CLIN = BundleDescriptor(extensions=[INTERNATIONAL, UK_CLINICAL, UK_CLINICAL_REFSET, UK_EDITION], ignores={refset: [INTERNATIONAL]})
UK_DRUG_EXT
class-attribute
instance-attribute
UK_DRUG_EXT = BundleDescriptor(extensions=[UK_DRUG, UK_EDITION])
SupportedExtension
Bases: Enum
Attributes:
-
AU– -
INTERNATIONAL– -
UK_CLINICAL– -
UK_CLINICAL_REFSET– -
UK_DRUG– -
UK_EDITION–
AU
class-attribute
instance-attribute
AU = ExtensionDescription(exp_name_in_folder='Release', exp_2nd_part_in_folder='AU1000036', exp_files=FileFormatDescriptor(concept='Concept_Snapshot', description='Description_Snapshot-en-AU', relationship='Relationship_Snapshot', refset=_IGNORE_TAG))
INTERNATIONAL
class-attribute
instance-attribute
INTERNATIONAL = ExtensionDescription(exp_name_in_folder='InternationalRF2', exp_files=FileFormatDescriptor(concept='Concept_Snapshot', description='Description_Snapshot-en', relationship='Relationship_Snapshot', refset='der2_iisssccRefset_ExtendedMapSnapshot'))
UK_CLINICAL
class-attribute
instance-attribute
UK_CLINICAL = ExtensionDescription(exp_name_in_folder='UKClinicalRF2', exp_files=FileFormatDescriptor(concept='Concept_UKCLSnapshot', description='Description_UKCLSnapshot-en', relationship='Relationship_UKCLSnapshot', refset='der2_iisssciRefset_ExtendedMapUKCLSnapshot'))
UK_CLINICAL_REFSET
class-attribute
instance-attribute
UK_CLINICAL_REFSET = ExtensionDescription(exp_name_in_folder='UKClinicalRefsetsRF2', exp_files=ignore_all())
UK_DRUG
class-attribute
instance-attribute
UK_DRUG = ExtensionDescription(exp_name_in_folder='UKDrugRF2', exp_files=FileFormatDescriptor(concept='Concept_UKDGSnapshot', description='Description_UKDGSnapshot-en', relationship='Relationship_UKDGSnapshot', refset='der2_iisssciRefset_ExtendedMapUKDGSnapshot'))
UK_EDITION
class-attribute
instance-attribute
UK_EDITION = ExtensionDescription(exp_name_in_folder='UKEditionRF2', exp_files=FileFormatDescriptor(concept='Concept_UKEDSnapshot', description='Description_UKEDSnapshot-en', relationship='Relationship_UKEDSnapshot', refset='der2_iisssciRefset_ExtendedMapUKEDSnapshot'))
UnkownSnomedReleaseException
UnkownSnomedReleaseException(*args)
Bases: ValueError
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
675 676 | |
get_all_children
Retrieves all the children of a given SNOMED CT ID (SCTID) from a given parent-to-child mapping (pt2ch) via the "IS A" relationship. pt2ch can be found in a MedCAT model in the additional info via the call: cat.cdb.addl_info['pt2ch']
Parameters:
-
(sctidint) –The SCTID whose children need to be retrieved.
-
(pt2chdict) –A dictionary containing the parent-to-child elationships in the form {parent_sctid: [list of child sctids]}.
Returns:
-
list–A list of unique SCTIDs that are children of the given SCTID.
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
get_direct_refset_mapping
This method uses the output from Snomed.map_snomed2icd10 or Snomed.map_snomed2opcs4 and removes the metadata and maps each SNOMED CUI to the prioritised list of the target ontology CUIs.
The input dict is expected to be in the following format: - Keys are SnomedCT CUIs - The values are lists of dictionaries, each list item (at least) - Has a key 'code' that specifies the target onotlogy CUI - Has a key 'mapPriority' that specifies the priority
Parameters:
-
(in_dictdict) –The input dict.
Returns:
-
dict(dict) –The map from Snomed CUI to list of priorities list of target ontology CUIs.
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
match_partials_with_folders
match_partials_with_folders(exp_names: list[tuple[str, Optional[str]]], folder_names: list[str], _group_nr1: int = 1, _group_nr2: int = 2) -> bool
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
parse_file
parse_file(filename, first_row_header=True, columns=None)
Source code in medcat-v2/medcat/model_creation/preprocess_snomed.py
11 12 13 14 15 | |