OBO Graph to FHIR Converter

class oaklib.converters.obo_graph_to_fhir_converter.OboGraphToFHIRConverter(curie_converter: Converter | None = None, labeler: Callable[[str], str | None] | None = None, enforce_canonical_ordering: bool | None = None)[source]

Converts from OboGraph to FHIR.

  • An ontology is mapped to a FHIR CodeSystem.

  • Each node in the OboGraph is converted to a _FHIR Concept_.

  • Each CURIE/URI in the OboGraph is treated as a CURIE when it becomes a packages (e.g. “HP:0000001”)

  • Each edge in the OboGraph is converted to a _FHIR ConceptProperty_ if the include_all_predicates param is True. Otherwise, will only convert edges if the predicate is in the DIRECT_PREDICATE_MAP.

  • Each synonym in the OboGraph is converted to a _FHIR ConceptDesignation_.

    • The synonym predicate is mapped to a _FHIR Coding_, using the SCOPE_MAP.

To run on the command line:

runoak –prefix my_prefix=my_expansion -i obograph:my-ont.json dump -O fhirjson -o my-ont.fhir.json

Here the input is an OboGraph JSON file. You can also specify:

  • OWL as sqlite

  • OBO Format

dump(source: GraphDocument, target: str | None = None, **kwargs) None[source]

Dump an OBO Graph Document to a FHIR CodeSystem.

Parameters:
  • source – Source serialization.

  • target – Target serialization.

  • kwargs – Additional keyword arguments passed to convert.

convert(source: GraphDocument, target: CodeSystem | None = None, code_system_id: str | None = None, code_system_url: str | None = None, include_all_predicates: bool = True, native_uri_stems: List[str] | None = None, use_curies_native_concepts: bool = False, use_curies_foreign_concepts: bool = True, predicate_period_replacement: bool = False, **kwargs) CodeSystem[source]

Convert an OBO Graph Document to a FHIR CodingSystem

To use:

>>> from oaklib.converters.obo_graph_to_fhir_converter import OboGraphToFHIRConverter
>>> from oaklib.datamodels.obograph import GraphDocument
>>> from linkml_runtime.dumpers import json_dumper
>>> from linkml_runtime.loaders import json_loader
>>> converter = OboGraphToFHIRConverter()
>>> graph = json_loader.load("tests/input/hp_test.json", target_class=GraphDocument)
>>> code_system = converter.convert(graph)
>>> print(json_dumper.dumps(code_system))

...
 "concept": [
    {
    "code": "HP:0012639",
    "display": "Abnormal nervous system morphology",
    "definition": "A structural anomaly of the nervous system.",
    "designation": [
 ...
Parameters:
  • code_system_id – The packages system ID to use for identification on the server uploaded to. See: https://hl7.org/fhir/resource-definitions.html#Resource.id

  • code_system_url – Canonical URL for the packages system. See: https://hl7.org/fhir/codesystem-definitions.html#CodeSystem.url

  • native_uri_stems – A list of URI stems that will be used to determine whether a concept is native to the CodeSystem. (not implemented) For example, for OMIM, the following URI stems are native: https://omim.org/entry/, https://omim.org/phenotypicSeries/PS

  • include_all_predicates – Include the maximal amount of predicates. Changes the default behavior from only exporting: IS_A (rdfs:subClassOf)

  • use_curies_native_concepts – FHIR conventionally uses codes for references to concepts that are native to a given CodeSystem. With this option, references will be CURIEs instead. (not implemented)

  • use_curies_foreign_concepts – Typical FHIR CodeSystems do not contain any concepts that are not native to that CodeSystem. In cases where they do appear, this converter defaults to URIs for references, unless this flag is present, in which case the converter will attempt to construct CURIEs. (not implemented)

  • predicate_period_replacement – Predicates URIs populated into CodeSystem.concept.property.packages and CodeSystem.concept.property.packages, but the HAPI FHIR server has a bug in which periods ‘.’ cause errors. If this flag is present, periods will be replaced with underscores ‘_’.

Returns:

FHIR CodeSystem object

code(uri: str) str[source]

Convert a packages.

This is a wrapper onto curie_converter.compress

Parameters:

uri – URI or CURIE to convert

Returns:

CURIE