Skip to content

FHIR Mapping translate transform fails for ConceptMaps with multiple groups #316

@luisfabib

Description

@luisfabib

Translate.process() iterates over a ConceptMap's groups and their elements to find a
matching source code. The loop is structured so that if the source code is not found in
the first group, the else branch of the for loop immediately raises MappingError.

This means the search stops after the first group regardless of whether subsequent groups
might contain the match. A ConceptMap with multiple groups — a standard FHIR pattern used
when mapping across multiple code systems in a single resource — will always fail unless the
match happens to be in the very first group.

Expected behaviour

All groups are searched in order. A MappingError is raised only after all groups have
been checked and no match was found.

Suggested fix

Restructure the logic to collect results across all groups before deciding to raise:

for group in concept_map.group:
    for element in group.element:
        if element.code == source_code:
            return self._extract_output(element, group, output_type)
raise MappingError(f"No mapping found for code '{source_code}'")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions