[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
Closed
Conversation
5746469 to
2c47400
Compare
- This PR is fix the [error of parsing special chars](ballerina-platform/ballerina-library#8000)
Contributor
Author
|
The changes from this PR are handled by Therefore the PR will be discarded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.
This ensures compatibility without compromising existing logic.
Notes
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