question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FHIR server $validate accepts resource json with duplicate keys

See original GitHub issue

During initial PDM R6.0 testing, it was discovered that a FHIR $validate operation would return a NoError response for a resource with duplicate keys. This can be reproduced as follows:

url: https://us-south.wh-fhir.dev.cloud.ibm.com/wh-fhir-dev/api/v4//Condition/$validate

POST payload:

{
	"resourceType": "Condition",
	"subject": {
		"reference": "Patient/b589c393-4146-4fef-921d-3facbfbd3bd0"
	},
	"subject": {
		"reference": "Patient/e8f4d046-4eb5-4c9e-972a-fb02c5e4d5f4"
	}
}

Strictly speaking, the json spec allows duplicate keys. But many json editors and other tooling flag dup keys as an error. I then sent the above resource to the create API. The Condition was successfully created, with the second subject only.

I think it would be prudent for FHIR to detect duplicate keys on resources and return the appropriate failure responses on validate, create, update. Persisting data in the FHIR database that passed validation and yet is not a reflection of the data sent in by the user is misleading, IMHO.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
JohnTimmcommented, May 29, 2020

#After further research, I found that Jackson supports a configuration that will reject duplicate keys:

    @Test
    public void testDuplicateKeys2() throws Exception {
        try (InputStream in = DuplicateKeysTest.class.getClassLoader().getResourceAsStream("JSON/condition-duplicate-keys.json")) {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
            JsonNode jsonNode = objectMapper.readValue(in, JsonNode.class);
            System.out.println(jsonNode);
        }
    }

Jackson also has compatibility with javax.json: https://github.com/FasterXML/jackson-datatypes-misc/tree/master/jsr-353

This module implements the javax.json object model on top of Jackson. I worked out a way that we could wire this up in the fhir-provider module. It fixes the original issue, but introduces a new issue related to BigDecimal precision. Precision in does not always equal precision out. In order to fix the precision issue, I would need to modify a source file coming from the Jackson project. This doesn’t seem like a viable solution. We have raised an issue with the jakarta-ee JSON-P project here:

https://github.com/eclipse-ee4j/jsonp/issues/240

They said that they would welcome a PR to fix the issue directly in their codebase.

0reactions
prb112commented, Oct 1, 2021
{
    "resourceType": "OperationOutcome",
    "issue": [
        {
            "severity": "fatal",
            "code": "invalid",
            "details": {
                "text": "FHIRProvider: Duplicate key 'status' is not allowed"
            },
            "expression": [
                "<no expression>"
            ]
        }
    ]
}

Test passes now as expected and rejects nested duplication in the Bundle, contained and nested JSON objects

Read more comments on GitHub >

github_iconTop Results From Across the Web

FHIR server $validate accepts resource json with duplicate keys
I think it would be prudent for FHIR to detect duplicate keys on resources and return the appropriate failure responses on validate, create, ......
Read more >
Operation-resource-validate.json - FHIR v5.0.0-cibuild
The action the server takes depends on the mode parameter: \n\n* [mode not provided]: The server checks the content of the resource against...
Read more >
Ask Question - Stack Overflow
That's an issue in HAPI - it validates the objects it loads from the JSON, and the JSON parser silently drops the duplicate...
Read more >
FHIR - InterSystems Developer Community
Hi Team,. I want to implement functionality in Intersystems IRIS for Health 2021.1. Which Received FHIR JSON from FHIR Repository and Convert them...
Read more >
Available Localization Keys - Smile CDR Documentation
Unable to determine encoding (e.g. XML / JSON) on validation input. Is this a valid FHIR resource body? ca.uhn.fhir.validation.ValidationResult.noIssuesDetected ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found