Skip to content

[FHIR-Tools] [Bug fixes] Parse error at differential elements, VTL 2.0 syntax, special char in "short" field#113

Closed
Sanjana-Attanayake wants to merge 3 commits intoballerina-platform:mainfrom
Sanjana-Attanayake:test-sanjana
Closed

[FHIR-Tools] [Bug fixes] Parse error at differential elements, VTL 2.0 syntax, special char in "short" field#113
Sanjana-Attanayake wants to merge 3 commits intoballerina-platform:mainfrom
Sanjana-Attanayake:test-sanjana

Conversation

@Sanjana-Attanayake
Copy link
Contributor

@Sanjana-Attanayake Sanjana-Attanayake commented Jun 8, 2025

Purpose

This PR is related to:

Goals

Commit 1
This commit aims to resolve the mysterious datatype mismatch error, discovered while parsing the FHIR R5 specification to birthdate field. The error removes the datatype "date" from the generated ballerina records causing an error when the birthdate is specified in the usual "YYYY-MM-DD" format.

Commit 2
This commit solves the issue when parsing field values with special characters embedded to it without any separator. In the spoken scenario an asterisk (*) mark is included to a field value causing it to generate a ballerina variable with a special character causing a syntax error.

Commit 3
The VTL 2.0 update has removed $velocity.count with $foreach.count. The 3rd commits changes this value in the fhir_resource.vm file, and re-add the union operator (|) so that array elements can have multiple datatypes.

Approach

Commit 1
During debugging, it was found that errors occur when snapshot elements have subfields fully redefined in their corresponding differential elements. However, removing the logic that parses differential elements introduces uncertainty in handling already-validated R4 data. This logic is also version-independent, so removing it would have broader consequences.

Further analysis revealed that the issue specifically arises when an element is extended from a PrimitiveType. This breaks Ballerina’s record structure rules and deviates from typical FHIR definitions. Normally, extensions are derived from general-purpose or special-purpose datatypes, such as BackboneElement, allowing inheritance like this:

public type PatientEuCoreLink record {|
    *r5:BackboneElement;

    r5:Extension [] extension?;
    r5:Reference other;
    r5:Extension [] modifierExtension?;
    string id?;
    PatientEuCoreLinkType 'type;
|};

In this setup, the record includes its parent's fields. However, when a PrimitiveType is used as the base, it has no child fields. This causes a compile-time error in Ballerina, as a record cannot start with a type reference unless it's followed by actual fields.

To handle this edge case, we propose using the Union operator (|). This allows the user to define the field either as a primitive value or as a custom type generated by the health tool.

public type PatientEuCore record {|
    *r5:DomainResource;

    RESOURCE_NAME_PATIENTEUCORE resourceType = RESOURCE_NAME_PATIENTEUCORE;

    r5:code gender?;
    PatientEuCoreBirthDate | r5:date birthDate;
    r5:Resource [] contained?;
}

This ensures compatibility without compromising existing logic.

Notes

  • This is a rare scenario and only applies when extending a PrimitiveType (excluding code).
  • The code type is already handled separately by converting it into an ENUM record with all valid values.

User stories

N/A

Release note

This bug fix will address the rare case of an element being extended from a Primitive type.

Documentation

N/A

Training

N/A

Certification

N/A

Marketing

N/A

Automation tests

Tested with both FHIR versions supported by the current health tool (R4, R5) even though the bug was identified from FHIR R5 specification.

Security checks

Samples

N/A

Related PRs

N/A

Migrations (if applicable)

Migration to Java 21 and Ballerina 2201.12.3 was conducted.

Test environment

Java 21
Ballerina 2201.12.3
Windows 11 Pro

Learning

Europe Base Documentation
Velocity Template Language (VTL) Documentation

@Sanjana-Attanayake Sanjana-Attanayake changed the base branch from main to release-v3.0.0 June 8, 2025 07:49
@Sanjana-Attanayake Sanjana-Attanayake changed the base branch from release-v3.0.0 to main June 8, 2025 07:50
@Sanjana-Attanayake Sanjana-Attanayake changed the title [FHIR-Tools] Bug fix at parsing repeated differential elements [FHIR-Tools] [Bug fixes] Parse error at differential elements, VTL 2.0 syntax, special char in "short" field Jun 11, 2025
@Sanjana-Attanayake
Copy link
Contributor Author

The changes from this PR are handled by
FHIR R5 Extension and
Parse Error and VTL 2.0 Fixes

Therefore the PR will be discarded.

@Sanjana-Attanayake Sanjana-Attanayake deleted the test-sanjana branch July 23, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant