API Reference¶
Full reference for the plugin-rosetta Python API. All public classes and functions are documented here. Source code is shown inline.
Base translator¶
The abstract base class all resource-specific translators extend.
Bases: ABC
Abstract base for per-resource FHIR-to-OMOP translators.
Source code in src/plugin_rosetta/translators/base.py
translate_dict(record)
¶
translate_ndjson(path)
¶
Read a FHIR ndjson file line-by-line and translate each record.
Uses orjson for performance. Lines that fail to parse or that have an unexpected resourceType are skipped with a warning.
Source code in src/plugin_rosetta/translators/base.py
translate_parquet(path)
¶
Read a FHIR Parquet file with Polars and translate each record.
Each Parquet row is converted to a plain Python dict and passed through
translate_record. For complex nested schemas you may need to
override this method.
Source code in src/plugin_rosetta/translators/base.py
translate_record(record)
abstractmethod
¶
Translate one FHIR resource dict to one (flat) OMOP row dict.
Returns an empty dict if the record cannot be translated.
Translators¶
PatientTranslator¶
Bases: FhirToOmopTranslator
Translate a FHIR R4 Patient resource to an OMOP Person row.
Mapping source: PersonMap.fml (HL7 fhir-omop-ig 1.0.0-ballot).
Notes:
- person_id is taken from Patient.id (cast to int if numeric,
else left as None — the ETL must assign a surrogate key).
- Gender concept mapping (FHIR code -> OMOP concept_id) is not resolved
here; gender_concept_id is set to 0 (unknown) and
gender_source_value carries the raw FHIR code.
- Race / ethnicity fields are not present in FHIR Patient R4 in a standard
way and are therefore set to 0 (no matching concept).
Source code in src/plugin_rosetta/translators/fhir_to_omop/patient.py
EncounterTranslator¶
Bases: FhirToOmopTranslator
Translate a FHIR R4 Encounter resource to an OMOP VisitOccurrence row.
Mapping source: EncounterVisit.fml (HL7 fhir-omop-ig 1.0.0-ballot).
Notes:
- visit_concept_id is populated from class.coding[0].code but
requires a concept lookup to resolve to a standard OMOP concept.
Until that lookup is implemented the source code is stored in
visit_source_value and visit_concept_id is set to 0.
- person_id and visit_occurrence_id are set to None; the caller
must assign surrogate keys.
Source code in src/plugin_rosetta/translators/fhir_to_omop/encounter.py
ConditionTranslator¶
Bases: FhirToOmopTranslator
Translate a FHIR R4 Condition resource to an OMOP ConditionOccurrence row.
Mapping source: condition.fml (HL7 fhir-omop-ig 1.0.0-ballot).
Notes:
- condition_concept_id requires a terminology lookup from
code.coding[0].code; set to 0 until resolved.
- Onset and abatement use the dateTime polymorphic variant only.
Other onset types (Period, Age, Range, string) are not handled here.
Source code in src/plugin_rosetta/translators/fhir_to_omop/condition.py
ObservationTranslator¶
Bases: FhirToOmopTranslator
Translate a FHIR R4 Observation to an OMOP Observation row.
Mapping source: Observation.fml (HL7 fhir-omop-ig 1.0.0-ballot).
Notes:
- Records whose category codes are outside OBS_CATEGORIES are skipped
(return empty dict). Those should be routed to a MeasurementTranslator.
- Polymorphic value[x] is handled for Quantity, CodeableConcept, string.
Source code in src/plugin_rosetta/translators/fhir_to_omop/observation.py
ProcedureTranslator¶
Bases: FhirToOmopTranslator
Translate a FHIR R4 Procedure resource to an OMOP ProcedureOccurrence row.
Mapping source: Procedure.fml (HL7 fhir-omop-ig 1.0.0-ballot).
Source code in src/plugin_rosetta/translators/fhir_to_omop/procedure.py
MedicationTranslator¶
Bases: FhirToOmopTranslator
Translate a FHIR R4 MedicationStatement to an OMOP DrugExposure row.
Mapping source: medication.fml (HL7 fhir-omop-ig 1.0.0-ballot).
Source code in src/plugin_rosetta/translators/fhir_to_omop/medication.py
ImmunizationTranslator¶
Bases: FhirToOmopTranslator
Translate a FHIR R4 Immunization resource to an OMOP DrugExposure row.
Mapping source: ImmunizationMap.fml (HL7 fhir-omop-ig 1.0.0-ballot).
Source code in src/plugin_rosetta/translators/fhir_to_omop/immunization.py
AllergyTranslator¶
Bases: FhirToOmopTranslator
Translate a FHIR R4 AllergyIntolerance resource to an OMOP Observation row.
Mapping source: Allergy.fml (HL7 fhir-omop-ig 1.0.0-ballot).
Source code in src/plugin_rosetta/translators/fhir_to_omop/allergy.py
I/O — NDJSON¶
Yield dicts from a FHIR ndjson file, optionally filtered by resourceType.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the |
required |
resource_type
|
str | None
|
If given, only yield records whose |
None
|
Yields:
| Type | Description |
|---|---|
dict
|
Parsed FHIR resource dicts. |
Source code in src/plugin_rosetta/translators/io/ndjson_reader.py
Read all records from a FHIR ndjson file into a list.
Convenience wrapper around :func:iter_ndjson.
Source code in src/plugin_rosetta/translators/io/ndjson_reader.py
I/O — Parquet¶
Reading¶
Container for the result of reading a validated Parquet file.
Source code in src/plugin_rosetta/translators/io/parquet_reader.py
Read a Parquet file and return a Polars DataFrame.
No validation is applied; use :func:read_parquet_validated if you need
schema validation via nyctea.
Source code in src/plugin_rosetta/translators/io/parquet_reader.py
Read a Parquet file and validate it against a nyctea SchemaModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the Parquet file. |
required |
schema_model
|
A nyctea |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
ParquetReadResult
|
class: |
ParquetReadResult
|
validation errors as a Polars DataFrame. |
Source code in src/plugin_rosetta/translators/io/parquet_reader.py
Writing¶
Write OMOP row dicts to a Parquet file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list[dict[str, Any]]
|
List of dicts, each representing one OMOP table row. |
required |
path
|
Path
|
Destination Parquet file path. |
required |
schema
|
dict[str, DataType] | None
|
Optional explicit Polars schema to enforce column dtypes. If None, Polars infers dtypes from the data. |
None
|
compression
|
str
|
Parquet compression codec. Defaults to |
'zstd'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The written Polars DataFrame. |
Source code in src/plugin_rosetta/translators/io/parquet_writer.py
Convert OMOP row dicts to a Polars DataFrame without writing to disk.
Source code in src/plugin_rosetta/translators/io/parquet_writer.py
Validation¶
Container for OMOP validation results.
Source code in src/plugin_rosetta/translators/io/omop_validator.py
Validate an OMOP Parquet file against a nyctea SchemaModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the OMOP Parquet file. |
required |
schema_model
|
Any
|
A nyctea |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
ValidationResult
|
class: |
Source code in src/plugin_rosetta/translators/io/omop_validator.py
Validate an in-memory OMOP Polars DataFrame against a nyctea SchemaModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
OMOP table as a Polars DataFrame. |
required |
schema_model
|
Any
|
A nyctea |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
ValidationResult
|
class: |
Source code in src/plugin_rosetta/translators/io/omop_validator.py
Schema registry¶
OMOP and FHIR nyctea schema models used for columnar validation.
OMOP schemas¶
from plugin_rosetta.translators.schemas.omop_nyctea import get_schema
schema = get_schema("person") # OMOP Person
schema = get_schema("visit_occurrence") # OMOP VisitOccurrence
schema = get_schema("condition_occurrence")
schema = get_schema("observation")
schema = get_schema("procedure_occurrence")
schema = get_schema("drug_exposure")
FHIR schemas¶
from plugin_rosetta.translators.schemas.fhir_nyctea import get_schema
schema = get_schema("Patient")
schema = get_schema("Encounter")
schema = get_schema("Condition")
schema = get_schema("Observation")
schema = get_schema("Procedure")
schema = get_schema("MedicationStatement")
schema = get_schema("Immunization")
schema = get_schema("AllergyIntolerance")