Working with SNOMED, LOINC, and Other Ontologies

Bunsen supports querying data with arbitrary code systems, but includes specialized support for importing SNOMED and LOINC since they are prevalent in a number of FHIR-related use cases.

Users must load the reference data in order to use queries aware of LOINC, SNOMED, or other terminologies. Users are responsible for ensuring they have the appropriate licenses to use this content and downloading it from the given sources.

Obtaining LOINC

The LOINC Multiaxial Hierarchy is published at https://loinc.org/download/loinc-multiaxial-hierarchy/. It can be downloaded and extracted into the mappings root with the following structure. Bunsen can ingest the multiaxial hierarchy from the CSV file available in that download, such as:

/path/to/mappings/loinc_hierarchy/2.56/LOINC_2.56_MULTI-AXIAL_HIERARCHY.CSV

Obtaining SNOMED

SNOMED RF2 Files are published at https://www.nlm.nih.gov/healthit/snomedct/international.html. It can be downloaded and extracted into the mappings root with the following structure. Bunsen can ingest the relationship snapshot, such as:

/path/to/mappings/snomedct_rf2/20160901/Snapshot/Terminology/sct2_Relationship_Snapshot_US1000124_20160901.txt

Loading the Ontologies

Once the content is downloaded, users can import it with the following commands. See the with_loinc_hierarchy() and with_relationships() functions for details.

>>> from bunsen.stu3.codes import create_hierarchies
>>> from bunsen.codes.loinc import with_loinc_hierarchy
>>> from bunsen.codes.snomed import with_relationships
>>>
>>> # Add SNOMED to the value sets
>>> snomed_hierarchy= with_relationships(
>>>       spark,
>>>       create_hierarchies(spark),
>>>       '/path/to/mappings/snomedct_rf2/20160901/Snapshot/Terminology/sct2_Relationship_Snapshot_US1000124_20160901.txt',
>>>       '20160901')
>>>
>>> # Add LOINC to the value sets
>>> loinc_hierarchy= with_loinc_hierarchy(
>>>        spark,
>>>        snomed_hierarchy,
>>>        '/path/to/mappings/loinc_hierarchy/2.56/LOINC_2.56_MULTI-AXIAL_HIERARCHY.CSV',
>>>        '2.56')
>>>
>>> # Write the SNOMED and LOINC data to the ontologies database, where it is visible
>>> # in Bunsen's valueset functions.
>>> hierarchies.write_to_database('ontologies')

SNOMED and LOINC Import APIs

Support for importing the LOINC Hierarchy into Bunsen.

bunsen.codes.loinc.with_loinc_hierarchy(sparkSession, hierarchies, loinc_hierarchy_path, loinc_version)

Returns a hierarchies instance that includes the LOINC hierarchy read from the given location.

Parameters:
  • sparkSession – the spark session
  • hierarchies – the bunsen.codes.Hierarchies class to which the LOINC hierarchy should be added.
  • loinc_hierarchy_path – the path of the LOINC hierarchy to load. This can be any path compatible with Hadoop’s FileSystem API.
  • loinc_version – the version of LOINC that is being loaded
Returns:

a bunsen.codes.Hierarchies with the added content.

Support for importing SNOMED relationship files into Bunsen.

bunsen.codes.snomed.with_relationships(sparkSession, hierarchies, snomed_relationship_path, snomed_version)

Returns a hierarchies instance that includes the SNOMED relationships read from the given location.

Parameters:
  • sparkSession – the spark session
  • hierarchies – the bunsen.codes.Hierarchies class to which the SNOMED hierarchy should be added.
  • snomed_relationship_path – the path of the SNOMED file to load. This can be any path compatible with Hadoop’s FileSystem API.
  • snomed_version – the version of SNOMED that is being loaded
Returns:

a bunsen.codes.Hierarchies with the added content.