Skip to content

Read decimal values from XML input as numbers - #287

Open
pradeeppeddineni wants to merge 1 commit into
FHIR:masterfrom
pradeeppeddineni:fix/xml-decimal-values
Open

pradeeppeddineni wants to merge 1 commit into
FHIR:masterfrom
pradeeppeddineni:fix/xml-decimal-values

Conversation

@pradeeppeddineni

Copy link
Copy Markdown

Description:

Fixes #260. When GoFSH reads XML input, decimal values come out as strings, so an instance like a Location gets

* position.longitude = "-97.7047386"

and SUSHI then fails with "Cannot assign string value". JSON input does not have this problem.

The cause is that readJSONorXML uses xmlToObj from fhir-tool, and xmlToObj keeps decimals as strings on purpose (so it does not lose precision). fhir-tool also has xmlToJson, which writes decimals as real JSON numbers. I switched readJSONorXML to call xmlToJson and parse the result. Now an XML file gives the same content as the matching JSON file, since the JSON path also uses JSON.parse.

Booleans and integers were already converted correctly, so only decimals change. The non-FHIR XML handling is the same as before, because both functions go through the same parsing code and throw the same "Unknown resource type" error.

Testing Instructions:

  • npm run check passes (tests, lint, prettier).
  • New test in test/utils/Processing.test.ts reads a small Location XML fixture and checks that longitude and latitude are numbers and that the content equals the matching JSON fixture. It fails on master and passes with this change.
  • By hand: put test/utils/fixtures/xml-decimals/location.xml in a folder and run gofsh on it with -t xml-only. On master you get quoted values, with this change you get * position.longitude = -97.7047386 and * position.latitude = 30.4159542.

Related Issue:

Fixes #260

GoFSH read XML input with xmlToObj, which keeps decimal values as strings.
That made instances from XML get quoted decimals, like
position.longitude = "-97.7047386", which SUSHI then rejects.

Use xmlToJson and parse the result instead. It writes decimals as JSON
numbers, so XML input now gives the same content as the equivalent JSON
file.

Fixes FHIR#260
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.

GoFSH incorrectly converts decimal types to strings

1 participant