Skip to content

Cross Version Translation

Daniel Carbone edited this page Nov 21, 2026 · 1 revision

Cross-Version Translation

The generated translation API converts a typed FHIR resource from one generated version to another. It can chain through intermediate versions and lets you register translators for individual types.

Beta (experimental): This page describes the current generator templates; older published or pre-generated packages may not include this API. The generic translator is not lossless and does not establish semantic equivalence between versions. Retain the original resource and do not rely on this implementation for production or clinical conversion.

Prerequisites

  • PHP 8.1 or later.
  • The phar and zlib extensions when reading .tgz packages during generation.
  • Generate the shared core and the versions you need together, from a generator revision that includes the translation templates. See Getting Started and CLI Usage.
  • Register the generated autoloader or configure Composer to autoload the generated library. The examples below use the default DCarbone\PHPFHIRGenerated namespace and assume the libraryPath is generated/src.

The generated Translation\VersionRegistry contains the versions selected when the core files were generated. Source resources must be instances of types in a registered version namespace. When version namespaces are nested (for example R4 and R4\Custom), the most specific namespace wins. If you change which versions are generated, regenerate the core along with those versions.

Example: translate an R4 Patient to R5

This example assumes the generated registry contains R4 and R5 only. Parse the source with its actual FHIR version first; raw JSON and XML do not tell the translator which version to use.

<?php declare(strict_types=1);

use DCarbone\PHPFHIRGenerated\Autoloader;
use DCarbone\PHPFHIRGenerated\Encoding\ResourceParser;
use DCarbone\PHPFHIRGenerated\Translation\OnUnmappableFieldEnum;
use DCarbone\PHPFHIRGenerated\Translation\TranslationConfig;
use DCarbone\PHPFHIRGenerated\Translation\Translator;
use DCarbone\PHPFHIRGenerated\Versions\R4\Types\FHIRResource\FHIRDomainResource\FHIRPatient as R4Patient;
use DCarbone\PHPFHIRGenerated\Versions\R4\Version as R4Version;
use DCarbone\PHPFHIRGenerated\Versions\R5\Version as R5Version;

require __DIR__ . '/generated/src/DCarbone/PHPFHIRGenerated/Autoloader.php';
Autoloader::register();

$r4 = new R4Version();
$r5 = new R5Version();

$json = <<<'JSON'
{
  "resourceType": "Patient",
  "text": {
    "status": "generated",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Example</div>"
  },
  "active": true,
  "name": [{"family": "Example", "given": ["Alex"]}]
}
JSON;

$source = ResourceParser::parse($r4, $json);
if (!($source instanceof R4Patient)) {
    throw new \UnexpectedValueException('Expected an R4 Patient.');
}

$translator = new Translator(new TranslationConfig(
    onUnmappableField: OnUnmappableFieldEnum::THROW,
));
$result = $translator->translate($source, $r5);
$r5Patient = $result->getResource();

foreach ($result->getNotices() as $notice) {
    error_log(sprintf(
        '%s -> %s [%s] %s: %s',
        $notice->getSourceVersion(),
        $notice->getTargetVersion(),
        $notice->getKind(),
        $notice->getPath(),
        $notice->getMessage(),
    ));
}

echo json_encode($r5Patient, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR), PHP_EOL;

For this input, the translated JSON contains the same narrative, active, and name values:

{
    "text": {
        "status": "generated",
        "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Example</div>"
    },
    "active": true,
    "name": [
        {
            "family": "Example",
            "given": ["Alex"]
        }
    ],
    "resourceType": "Patient"
}

No custom translator is needed for this narrative. The target field's declared class handles the changed enum class names between releases; XHTML is copied as a leaf value. This preserves the status string, but does not map a status whose meaning or allowed values changed.

To translate in the other direction, pass the translated resource and the R4 version to the same translator:

$reverseResult = $translator->translate($r5Patient, $r4);
$r4Patient = $reverseResult->getResource();

Inspect the reverse result's notices separately. A round trip is not a guarantee of equivalent data: compare the output with the source and validate it for the target server and profiles. The THROW policy in this example is stricter than the default, but it does not prevent every kind of loss in the current implementation.

Configure local xver packages

The generator reads ConceptMaps and cross-version extension definitions from a local FHIR NPM package directory or .tgz archive. Packages are published by HL7 as hl7.fhir.uv.xver-<source>.<target> (for example hl7.fhir.uv.xver-r5.r4). Configure each package at the top level, with explicit source and target versions. The generator does not download packages, and the generated runtime does not need the original archives.

For the examples below, extract R4 and R5 schemas into schemas/R4 and schemas/R5 (see Getting Started), then download the same R5-to-R4 package version used by the integration suite:

mkdir -p generated/src packages
curl -fL -o packages/hl7.fhir.uv.xver-r5.r4.tgz \
    https://packages.fhir.org/hl7.fhir.uv.xver-r5.r4/0.1.0

Save this as generate.php beside those directories:

<?php declare(strict_types=1);

use DCarbone\PHPFHIR\Builder;
use DCarbone\PHPFHIR\Config;
use DCarbone\PHPFHIR\Config\TranslationPackageConfig;
use DCarbone\PHPFHIR\Config\VersionConfig;

require __DIR__ . '/vendor/autoload.php';

$config = new Config(
    libraryPath: __DIR__ . '/generated/src',
    versions: [
        new VersionConfig(name: 'R4', schemaPath: __DIR__ . '/schemas/R4'),
        new VersionConfig(name: 'R5', schemaPath: __DIR__ . '/schemas/R5'),
    ],
    translationPackages: [
        new TranslationPackageConfig(
            sourceVersion: 'R5',
            targetVersion: 'R4',
            source: __DIR__ . '/packages/hl7.fhir.uv.xver-r5.r4.tgz',
        ),
    ],
);

(new Builder($config))->render();

Run php -d memory_limit=2G generate.php, then run the translation examples in a new PHP process. Output directories must already exist. Omitting testsPath skips generated tests.

The source must be readable and contain package.json. sourceVersion and targetVersion refer to the configured version names (STU3, for example, not the package's r3 token). A package is embedded only when both versions are selected for generation. Rebuild the shared core and hop maps when changing versions or packages; coreFiles: false leaves the old registries and maps in place.

translationPackages is separate from per-version profile configuration. Listing an xver package under profilesConfig does not activate its translation mappings. The repository's default bin/config.php includes an xver package as a profile dependency, but does not configure top-level translation packages.

Package direction has three distinct effects:

Operation Required package
Map codings and emit extensions for R5-only fields while translating R5 → R4 R5 → R4
Restore those R5 fields from extensions while translating R4 → R5 The same R5 → R4 package; no second package is needed
Map codings and emit extensions for R4-only fields while translating R4 → R5 A separate R4 → R5 package

ConceptMaps are never inverted. A configured non-adjacent package pair creates direct hop maps in both directions, but only the declared direction receives the package's mappings and definitions. Exact maps take precedence over intermediate hops, which can change which ConceptMaps are applied; see Routing and current limitations.

Coding behavior

At runtime, ConceptMaps apply only to Coding values with an explicit system and code, including codings nested under CodeableConcept.coding. The source system must match the ConceptMap group's source system. A specified source code-system version must also match Coding.version exactly; a missing version is not inferred from the resource's FHIR release. R4 groups use sourceVersion / targetVersion; R5 canonical URLs can carry a |version suffix. Groups without a source-version constraint can match codings with or without a version.

A code is translated only when there is one distinct usable target: R4 equivalence may be equal or equivalent, while R5 relationship must be equivalent. Targets with non-empty dependsOn conditions or required product outputs are excluded because the engine cannot evaluate or fulfill them. Across matching groups, exactly one target system, code, and version must remain. Missing, version-incompatible, ambiguous, or unsupported mappings for a matched source system follow the configured unmappable-field policy. If no map applies to a coding's system, the coding is copied unchanged. Numeric codes such as "123" remain strings. Bare code primitives, such as Encounter.status, are also left unchanged because their binding system is not available in runtime field metadata. Register a custom type translator for the owning type to map them (see Register custom translators).

An explicit target version replaces Coding.version, even when the system is unchanged, and is added when the source had none. Without a target version, a same-system mapping retains the source version. A cross-system mapping without a target version treats a populated source version as unmappable: DROP removes it with a notice, while the other policies reject it. No target version is guessed, and display is not rewritten.

This feature does not translate structure, infer field renames, or execute FML/StructureMap. Generated hop maps expose CodeMap objects through HopMapInterface::getCodeMaps() and XverExtension objects through HopMapInterface::getXverExtensions(), and cache them after first access. The extension definitions drive EXTENSION emission and reverse unfolding. The generator creates a direct reverse map for a non-adjacent package hop; the unfolder looks up the definitions from the original emitting direction.

Example: map coded values and inspect notices

After generating with the R5 → R4 package above, use the imports, autoloader, $r4, and $r5 from the first runtime example. The HL7 systems used here declare source version 5.0.0 and target version 4.0.1; these are the map's code-system versions, not a rule for arbitrary terminologies. This example deliberately chooses DROP to demonstrate losses:

$codingSource = ResourceParser::parse($r5, <<<'JSON'
{
  "resourceType": "Basic",
  "code": {
    "coding": [
      {"system": "http://hl7.org/fhir/encounter-status", "version": "5.0.0", "code": "on-hold"},
      {"system": "http://hl7.org/fhir/fhir-types", "version": "5.0.0", "code": "DeviceUsage"},
      {"system": "http://hl7.org/fhir/observation-status", "version": "5.0.0", "code": "mitigated"},
      {"system": "http://example.org", "code": "123"}
    ]
  }
}
JSON);
if (null === $codingSource) {
    throw new \UnexpectedValueException('Expected an R5 Basic resource.');
}

$mappingResult = (new Translator(new TranslationConfig(
    onUnmappableField: OnUnmappableFieldEnum::DROP,
)))->translate($codingSource, $r4);

echo json_encode($mappingResult->getResource(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR), PHP_EOL;
foreach ($mappingResult->getNotices() as $notice) {
    printf("%s %s %s->%s\n", $notice->getKind(), $notice->getPath(),
        $notice->getSourceVersion(), $notice->getTargetVersion());
}

The R4 code.coding array is:

[
    {"system": "http://hl7.org/fhir/encounter-status", "version": "4.0.1", "code": "onleave"},
    {"system": "http://hl7.org/fhir/resource-types", "version": "4.0.1", "code": "DeviceUseStatement"},
    {"system": "http://example.org", "code": "123"}
]

The notices are:

dropped Basic.code.coding.code R5->R4
dropped Basic.code.coding.version R5->R4
dropped Basic.code.coding R5->R4

The first two codings receive the target version from their maps; DeviceUsage also changes code systems. mitigated has no usable equivalent in this package, so its system, code, and version are discarded, followed by the now-empty Coding. A failed mapping that leaves other fields, such as display, need not drop the entire Coding. The unknown system passes through, and "123" remains a string. Omitting version from the first two codings would make them unmappable too; THROW would raise an exception instead of returning these partial results.

Unmappable values and notices

TranslationConfig accepts an OnUnmappableFieldEnum:

Policy Current behavior
EXTENSION Default. A field absent from the target is preserved using the hop map's official xver definition when every value can be carried. Missing definitions, incompatible values, and other unsupported cases throw MissingXverDefinitionException.
THROW An unmappable field throws UnmappableFieldException.
DROP An unmappable field is discarded; the engine creates a dropped notice, including for nested fields.

If the root resource type has no target representation, translation fails under every policy rather than returning an empty replacement resource. A custom translator can also throw an exception or return null for an unmappable nested value, which applies the configured policy. When every populated field of a nested element is dropped, the element itself is also dropped, so DROP reports both paths (for example Patient.name.family and Patient.name). Root resources are never collapsed this way.

TranslationResult::getNotices() returns TranslationNotice objects. Each exposes getPath(), getKind(), getSourceVersion(), getTargetVersion(), and getMessage(). Nested notices propagate to the result with their field paths. An empty list is not proof of semantic equivalence. Avoid DROP unless your application accounts for the data it discards.

Preserving fields as xver extensions

With a package configured for the hop, a field the target version lacks is appended to the target's extension (or modifierExtension for modifier elements) using the URL defined by the package. The URL names the source release, for example http://hl7.org/fhir/5.0/StructureDefinition/extension-Account.currency when translating R5 to R4.

  • A repeating field produces one extension per value, in order.
  • A complex element such as Account.balance produces nested extension children named after the definition's slices, plus a _datatype child when the definition requires one.
  • Emission is all-or-nothing per missing field: if any value cannot be carried, translation throws rather than emitting only some of its extensions. Extensions already present on the target are kept.
  • Values the translator preserves this way emit no notice.
  • Enum-bound fields use valueCode where the definition permits it. For example, R5 Coverage.kind = "insurance" becomes an R4 extension with valueCode: "insurance". The complete primitive container is translated, so element IDs and primitive extensions are retained in _valueCode and restored with the enum value on a supported reverse hop.
  • When translating back, compatible extensions restore fields and are removed from the extension list. Unfolding runs under all three policies, not just EXTENSION.

Example: round-trip R5 Account through R4

This continues the same runtime setup and requires only the R5 → R4 package. It exercises both a simple currency extension and a complex, repeating balance field:

$accountSource = ResourceParser::parse($r5, <<<'JSON'
{
  "resourceType": "Account",
  "id": "a1",
  "status": "active",
  "currency": {"coding": [{"system": "urn:iso:std:iso:4217", "code": "USD"}]},
  "balance": [{"amount": {"value": 12.5, "currency": "USD"}}]
}
JSON);
if (null === $accountSource) {
    throw new \UnexpectedValueException('Expected an R5 Account resource.');
}

$extensionTranslator = new Translator();
$carried = $extensionTranslator->translate($accountSource, $r4);
$restored = $extensionTranslator->translate($carried->getResource(), $r5);

foreach ([$carried, $restored] as $result) {
    foreach ($result->getNotices() as $notice) {
        error_log(sprintf('%s %s: %s', $notice->getKind(), $notice->getPath(), $notice->getMessage()));
    }
    echo json_encode($result->getResource(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR), PHP_EOL;
}

R4 has neither field, so its extension array contains:

[
    {
        "url": "http://hl7.org/fhir/5.0/StructureDefinition/extension-Account.currency",
        "valueCodeableConcept": {"coding": [{"system": "urn:iso:std:iso:4217", "code": "USD"}]}
    },
    {
        "url": "http://hl7.org/fhir/5.0/StructureDefinition/extension-Account.balance",
        "extension": [
            {"url": "amount", "valueMoney": {"value": 12.5, "currency": "USD"}}
        ]
    }
]

The restored R5 resource has the original currency and balance, with no leftover extensions for these fields. The amount remains a JSON number (12.5), not a string. Both results have empty notice lists for this input. Compare decoded content rather than JSON object-key order; this successful example does not imply that arbitrary resources round-trip without loss.

Current limitations:

  • Unfolding is conservative: it restores only extensions whose URL, modifier status, value type, and supported content fit the configured definition and target field. A populated single-valued field is never overwritten; repeating fields append restored values in extension order, without deduplication. Unrecognized extensions, wrong value types, and unsupported extra content stay in the extension list without a notice, including under THROW.
  • To preserve fields emitted in both directions, configure the corresponding xver package for each direction. Unfolding itself uses the package for the original emission direction and runs independently of the unmappable-field policy.
  • Values whose type changed between releases (for example CodeableReference to CodeableConcept) are not converted and fall back to the policy.
  • Unsupported extension shapes are skipped during generation, such as generic value[x] of any type, Task and Transport input/output, and ElementDefinition.maxValue/minValue.
  • Whole removed types are not preserved, only fields.
  • A hop without xver definitions can still copy compatible fields. It throws under EXTENSION only when it encounters a value it cannot preserve; there is no automatic package discovery.
  • Translation does not validate extension invariants, required nested slices, or target profiles.
  • Notice order need not match the original JSON field order.

Customize field metadata discovery

Pass a FieldMetadataFactoryInterface implementation to the Translator constructor. You can replace discovery entirely or decorate the default implementation. Its descriptors are immutable FieldMetadata objects exposing getType(), isCollection(), getGetter(), and getSetter(); reflection and caching belong to the factory, not the descriptors. The contract is:

/**
 * @return array<string, \DCarbone\PHPFHIRGenerated\Translation\FieldMetadata>
 */
public function forType(TypeInterface $type): array;

The generic translator passes the actual non-leaf source and newly constructed target instances to the factory. It matches fields by the returned array keys, reads values using each source descriptor's getter, translates nested values, checks the target descriptor's type and collection flag, and writes values using its setter. Missing target keys still apply the configured unmappable-field policy. Keys also appear in notice paths. Primitive and XHTML leaf values bypass metadata discovery; primitive containers do not. Resource-container fields such as Bundle.entry.resource and DomainResource.contained describe unwrapped resources with the version's VersionContainedTypeInterface.

For example, this decorator normalizes the logical matching key family to familyName on both sides, without changing generated accessors or serialized FHIR field names:

use DCarbone\PHPFHIRGenerated\Translation\FieldMetadataFactory;
use DCarbone\PHPFHIRGenerated\Translation\FieldMetadataFactoryInterface;
use DCarbone\PHPFHIRGenerated\Types\TypeInterface;

final class ApplicationFieldMetadataFactory implements FieldMetadataFactoryInterface
{
    public function __construct(
        private readonly FieldMetadataFactoryInterface $default = new FieldMetadataFactory(),
    ) {
    }

    /** @return array<string, \DCarbone\PHPFHIRGenerated\Translation\FieldMetadata> */
    public function forType(TypeInterface $type): array
    {
        $fields = $this->default->forType($type);
        if (isset($fields['family'])) {
            $fields['familyName'] = $fields['family'];
            unset($fields['family']);
        }
        return $fields;
    }
}

$metadataFactory = new ApplicationFieldMetadataFactory();
$translator = new Translator(
    config: new TranslationConfig(onUnmappableField: OnUnmappableFieldEnum::THROW),
    metadataFactory: $metadataFactory,
);
$result = $translator->translate($source, $r5);

The same injected factory serves all default translations, including intermediate hops and nested values. Factory exceptions propagate to the caller. A custom factory controls its own caching; the default factory caches by $type::class, not globally. Custom factories may inspect instance state and need not cache by class. Use a registered type translator for semantic rules that depend on the source/target pair.

Package xver lookups also use the field keys. Preserve the original FHIR field names for package-driven emission and unfolding, or handle renamed keys in a custom translator.

Register custom translators

Implement TypeTranslatorInterface to replace the translation of a specific FHIR type for a specific source and target version. A translator receives the source object and a TranslationContext, and returns a target-version TypeInterface or null:

public function translate(TypeInterface $source, TranslationContext $context): null|TypeInterface;

Register it with register($from, $to, $typeName, $translator). The type name is the generated FHIR name returned by _getFHIRTypeName(), not the PHP class name. Registrations are directional: R5 to R4 needs its own translator. register() takes a TypeTranslatorInterface object directly; it does not accept a callable or factory. This keeps custom translation behavior explicitly typed and lets the dispatcher select the registered translator for each hop.

Example: map a bare Encounter.status

ConceptMaps apply to Coding, not bare code fields. The default translator therefore copies R5 Encounter.status = "on-hold" unchanged even though R4 uses "onleave". A typed wrapper can delegate structural copying to the default translator and then apply this specific code mapping.

use DCarbone\PHPFHIRGenerated\Translation\GenericTypeTranslator;
use DCarbone\PHPFHIRGenerated\Translation\TranslationContext;
use DCarbone\PHPFHIRGenerated\Translation\TypeTranslatorInterface;
use DCarbone\PHPFHIRGenerated\Types\TypeInterface;
use DCarbone\PHPFHIRGenerated\Versions\R4\Types\FHIRResource\FHIRDomainResource\FHIREncounter as R4Encounter;
use DCarbone\PHPFHIRGenerated\Versions\R5\Types\FHIRBase\FHIRResource\FHIRDomainResource\FHIREncounter as R5Encounter;

final class R5ToR4EncounterTranslator implements TypeTranslatorInterface
{
    public function __construct(
        private readonly TypeTranslatorInterface $defaultTranslator = new GenericTypeTranslator(),
    ) {}

    public function translate(TypeInterface $source, TranslationContext $context): null|TypeInterface
    {
        if (!$source instanceof R5Encounter) {
            throw new \InvalidArgumentException('Expected an R5 Encounter.');
        }
        $target = $this->defaultTranslator->translate($source, $context);
        if (null === $target) {
            return null;
        }
        if (!$target instanceof R4Encounter) {
            throw new \UnexpectedValueException('Expected an R4 Encounter.');
        }
        if ('on-hold' === (string)$source->getStatus()) {
            $status = $target->getStatus()?->getValue();
            if (!$status instanceof TypeInterface || !method_exists($status, 'setValue')) {
                throw new \UnexpectedValueException('Translated Encounter.status must expose a mutable value.');
            }
            $status->setValue('onleave');
        }
        return $target;
    }
}

$customTranslator = new Translator(new TranslationConfig(
    onUnmappableField: OnUnmappableFieldEnum::THROW,
));
$customTranslator->register(
    $r5, $r4, R5Encounter::FHIR_TYPE_NAME, new R5ToR4EncounterTranslator(),
);
$encounter = new R5Encounter(status: 'on-hold');
$customResult = $customTranslator->translate($encounter, $r4);
echo json_encode($customResult->getResource(), JSON_THROW_ON_ERROR), PHP_EOL;

This prints {"status":"onleave","resourceType":"Encounter"}. It is a minimal mapping demonstration, not a complete valid Encounter: required target fields and other changed statuses need application-specific handling. Registering a root Encounter translator makes this request a direct R5-to-R4 hop; nested-type registrations alone do not select a route.

If you injected a custom metadata factory into Translator, explicitly pass the same instance when constructing a default translator for a wrapper:

$wrapper = new R5ToR4EncounterTranslator(
    new GenericTypeTranslator(metadataFactory: $metadataFactory),
);

Register $wrapper on the facade using the same factory. Registered translators own their dependencies; the facade does not replace dependencies inside supplied objects.

TranslationContext also provides getSourceVersion(), getTargetVersion(), getConfig(), getHopMap(), getPath(), getExpectedTargetClass(), translate() / translateField() for nested values, handleUnmappableField(), and addNotice(). Its version, configuration, path, dispatcher, and collector references are readonly. Nested contexts use the typed dispatcher directly, while one mutable notice collector is shared across nested values and hops for a translation call. Notices added by nested translators propagate to the result.

Generated hop maps

The generator emits a Translation\Maps class in each direction for every adjacent pair of selected versions, plus a Translation\HopMapRegistry used by Translator during routing. Configured non-adjacent package pairs also get maps in both directions. Maps are derived from the generated version definitions. Their file paths are included in the generated standalone autoloader, so Composer is not required to load them:

  • Fields missing from the target are detected at run time and handled by the configured policy.
  • Types missing from the target are recorded as removed; translating one returns null, so the configured unmappable-value policy handles it. Value-set enumerations (X-list in R4, XEnum in R4B/R5) are excluded because their names differ between releases; they translate through the target field's declared class.
  • Type renames are not modelled; types match by name or by the target field's declared class. Use a custom translator for a rename.

An unmappable field follows the configured OnUnmappableFieldEnum policy. In particular, EXTENSION emits an official xver extension when a configured package defines one and throws MissingXverDefinitionException otherwise; schema-diff generation does not invent an xver URL or placeholder extension. A custom translator can inspect the current hop map with $context->getHopMap() and provide application- specific behavior. Configured local xver packages contribute directional ConceptMap mappings for Coding values and extension definitions for unmappable fields; see Configure local xver packages.

Routing and current limitations

  • The source version is resolved from the generated class namespace. The target is the Version object passed to translate().
  • A direct root-type registration takes precedence, followed by an exact generated map for the requested pair. Otherwise the engine chooses the shortest route using adjacent releases and generated direct maps. Every hop must move toward the target; routes never overshoot or backtrack. Equally short routes are rejected rather than chosen arbitrarily.
  • With R4, R4B, and R5 generated and no package for the R4/R5 pair, R4 → R5 chains through R4B. Adding only R5 → R4 creates direct maps both ways: R4 → R5 then skips R4B, but does not gain reverse ConceptMaps. It can unfold R5 fields from extensions using the R5 → R4 definitions. Code maps and custom translators registered only on the skipped hops no longer run.
  • Shortcuts also work inside longer routes. With STU3, R4, R4B, and R5 generated and the R5 → R4 and R4 → STU3 packages configured, R5 → STU3 uses R5 → R4 → STU3, not R4B. An encounter-status Coding changes from on-hold / 5.0.0 to onleave / 4.0.1. The R4 → STU3 package has no map for this system, so that code and code-system version pass through unchanged; terminology versions are not derived from the target FHIR release. R5 fields preserved as xver extensions on the first hop can also survive the remaining hops and unfold on a supported return route.
  • With just R4 and R5 generated, they are adjacent in the selected set and already have direct two-way maps. Type translators are registered per hop; register each hop you intend to customize.
  • A direct registration for the root resource type, such as Patient for R4 → R5, bypasses intermediate hops for that type. If multiple shortest routes exist, including equally short choices between variants of one release, automatic routing throws AmbiguousTranslationRouteException. An exact generated map or direct root-type translator can resolve the ambiguity. Variants skipped by the selected route do not make it ambiguous. Translating between two variants of the same release requires an explicit direct route.
  • Translating to the same generated version returns the original resource instance, not a copy.
  • The generic translator matches type and field names using generated schema-diff hop maps and applies configured ConceptMaps only to Coding values with explicit systems. It does not infer structural mappings or perform broader terminology translation, and emits official xver extensions only for fields a configured package defines. Matching names alone do not establish semantic equivalence.
  • Unsupported or incompatible values may require custom translators or raise exceptions. A dateTime containing a time component is not silently truncated to date; it is unmappable. Test every resource shape you use.
  • Translation does not automatically validate the target, migrate profile constraints, or choose a target profile class. Review profile metadata, run appropriate target-version and profile validation, and verify application-specific meaning before using the result.

Clone this wiki locally