Skip to content

feat: Support FHIRPath type() reflection function#2578

Open
piotrszul wants to merge 7 commits intorelease/9.6.0from
issue/2395
Open

feat: Support FHIRPath type() reflection function#2578
piotrszul wants to merge 7 commits intorelease/9.6.0from
issue/2395

Conversation

@piotrszul
Copy link
Copy Markdown
Collaborator

@piotrszul piotrszul commented Mar 26, 2026

Summary

Implements the FHIRPath type() reflection function based on the CI build FHIRPath specification, which defines a simplified reflection model using SimpleTypeInfo and ClassInfo subtypes with namespace, name, and baseType fields.

  • Returns type information for System types (primitives, Quantity, Coding) and FHIR types (elements, complex types, backbone elements, resources)
  • Uses a single TypeInfo class for both SimpleTypeInfo and ClassInfo, since the CI spec defines identical fields for both (namespace, name, baseType). The spec notes: "Although the SimpleTypeInfo and ClassInfo appear the same here, implementations may have additional information." If a future spec revision adds distinguishing fields, the implementation can be split at that point.
  • Uses a simplified baseType system based on the R4 FHIR type hierarchy with only three base types: System.Any (System primitives), FHIR.Element (FHIR data types and backbone elements), and FHIR.Resource (FHIR resources)
  • Supports choice element per-row type resolution, nested type() calls, and composition with other FHIRPath functions
  • Adds TypeInfoExpectation DSL test helper for concise TypeInfo assertions using toTypeInfo("Namespace.Name(BaseType)") format

Closes #2395

Test plan

  • DSL tests covering all type categories: System primitives, Quantity, Coding, FHIR primitives, complex types, backbone elements, resources, choice elements, empty collections, nested calls, integration with ofType()/where()
  • YAML reference test exclusions added for fhirpath.js format differences (2-field vs 3-field TypeInfo)
  • Full fhirpath test suite passes (2 pre-existing failures in unrelated FhirViewShareableComplianceTest)

🤖 Generated with Claude Code

@github-project-automation github-project-automation bot moved this to Backlog in Pathling Mar 26, 2026
@piotrszul piotrszul moved this from Backlog to In progress in Pathling Mar 26, 2026
@piotrszul piotrszul added fhirpath Related to fhirpath reference implementation new feature New feature or request labels Mar 26, 2026
@piotrszul piotrszul mentioned this pull request Mar 27, 2026
piotrszul and others added 7 commits March 31, 2026 11:52
Add the type() function per the CI build FHIRPath specification, returning
TypeInfo structures with namespace, name, and baseType fields. The function
correctly distinguishes System types (literals and operation results) from
FHIR types (path-navigated elements), including proper handling of
Quantity and Coding which exist in both namespaces.

Also fix string concatenation operator (+) on StringCollection to produce
System.String rather than preserving the FHIR type context.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Consolidate type reflection data and logic into a dedicated TypeInfo
class alongside TypeSpecifier. Moves TYPE_INFO_DEFINITION from
Collection, eliminates raw namespace string literals, and simplifies
TypeFunctions.type() to a thin delegate.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Replace repeated string concatenations with named constants for base
type specifiers. Use Optional.filter() instead of isPresent()/get()
to follow project functional style guidelines.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Proposal, design, specs, and tasks for implementing per-row runtime
type resolution in the FHIRPath type() function for choice fields.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The FHIRPath type() function now resolves the concrete type per row for
polymorphic choice elements (e.g., Observation.component.value[x]),
using a CASE WHEN chain that inspects which field is non-null.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Introduces TypeInfoExpectation marker class enabling single-assertion
comparison of type() results instead of checking namespace, name, and
baseType individually. Refactors TypeFunctionsDslTest to use the new
toTypeInfo() format.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Verifies that backbone elements like Patient.contact return
FHIR.BackboneElement as type name, consistent with the reference
implementation.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@piotrszul piotrszul changed the base branch from main to release/9.6.0 March 31, 2026 01:54
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fhirpath Related to fhirpath reference implementation new feature New feature or request

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

Support reflection

1 participant