Stream: implementers
Topic: Extending canonical fails json schema
Mirjam Baltus (Jun 30 2021 at 16:10):
If you add an extension to a field of type canonical (FHIR R4), if I understand correctly for json this should go into '_fieldName' since canonical is a primitive type. However, if you validate this with the JSON schema, it fails. Is extending a canonical not allowed, or is the schema wrong? The Java validator does not complain.
Lloyd McKenzie (Jun 30 2021 at 18:27):
@Grahame Grieve
Grahame Grieve (Jun 30 2021 at 19:38):
the json schema is supposed to allow this. Please provide an example
Eric Haas (Jun 30 2021 at 19:48):
canonicals extensions worked for me in ImplementationGuide
Mirjam Baltus (Jun 30 2021 at 20:04):
Thanks, I will check to see how it was validated exactly. What I was told, is that the extension was set on the QuestionnaireResponse.questionnaire field and the error thrown on _questionnaire not being a known field.
Eric Haas (Jun 30 2021 at 23:13):
oops, I did not read this thoroughly. my example validated using fhir validator. Did not test with the json schema
Mirjam Baltus (Jul 01 2021 at 07:52):
@Ilya Sher Maybe you can elaborate on this?
Ilya Sher (Jul 01 2021 at 07:59):
I guess we wait for @Eric Haas to reproduce the issue with QuestionnaireResponse.questionnaire
/ QuestionnaireResponse._questionnaire
and with JSON Schema
Ilya Sher (Jul 01 2021 at 08:56):
The code at https://github.com/awslabs/fhir-works-on-aws-routing/blob/mainline/src/router/validation/jsonSchemaValidator.ts fails with Failed to parse request body as JSON resource ...
Ilya Sher (personal account) (Jul 02 2021 at 10:11):
Waiting for update from @Eric Haas ... or anyone else :)
Eric Haas (Jul 03 2021 at 04:07):
I misunderstood the issue. I have not tried to use json schemas at all. So I am unable to comment
Lloyd McKenzie (Jul 03 2021 at 22:36):
@Grahame Grieve
Ilya Sher (Jul 05 2021 at 15:43):
Eric Haas said:
I misunderstood the issue. I have not tried to use json schemas at all. So I am unable to comment
... and then I misread your comment :)
Mirjam Baltus (Jul 07 2021 at 13:09):
@Grahame Grieve I've tried this with the Newtonsoft libraries for .Net, and do get an error as soon as I add an extension to the QuestionnaireResponse.questionnaire field. Without it, all works fine. Here is a QuestionnaireResponse that is valid according to both HAPI and Firely Server, but not against the schema:
{
"resourceType": "QuestionnaireResponse",
"_questionnaire": {
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
"valueCode": "unknown"
}
]
},
"status": "stopped"
}
Ilya Sher (Jul 28 2021 at 13:04):
Mirjam Baltus said:
Grahame Grieve I've tried this with the Newtonsoft libraries for .Net, and do get an error as soon as I add an extension to the QuestionnaireResponse.questionnaire field. Without it, all works fine. Here is a QuestionnaireResponse that is valid according to both HAPI and Firely Server, but not against the schema:
{ "resourceType": "QuestionnaireResponse", "_questionnaire": { "extension": [ { "url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason", "valueCode": "unknown" } ] }, "status": "stopped" }
How should I proceed with that? Looks like bug in JSON schema. Should I open a Jira issue?
Lloyd McKenzie (Jul 28 2021 at 13:50):
Do you know what the schema should look like?
Ilya Sher (Jul 28 2021 at 14:33):
Lloyd McKenzie said:
Do you know what the schema should look like?
I have a guess. Add (just after "questionnaire": {...}
):
"_questionnaire": {
"description": "Extensions for questionnaire",
"$ref": "#/definitions/Element"
}
that's how extension for other elements of primitive types look.
Ilya Sher (Jul 28 2021 at 14:36):
Lloyd McKenzie said:
Do you know what the schema should look like?
There is also quite a few other elements with "$ref": "#/definitions/canonical"
which don't have _myElementName
extensions. I think maybe all of them.
Lloyd McKenzie (Jul 28 2021 at 14:51):
If you can test the solution, a change request would be most welcome.
Ilya Sher (Jul 29 2021 at 05:16):
Not sure yet. Meanwhile have a question - isn't this file generated?
Lloyd McKenzie (Jul 29 2021 at 13:15):
Yes
Lloyd McKenzie (Jul 29 2021 at 13:15):
So the fix would be to the generation algorithm
Ilya Sher (Aug 03 2021 at 11:03):
Lloyd McKenzie said:
So the fix would be to the generation algorithm
... and where that one is?
Lloyd McKenzie (Aug 03 2021 at 13:21):
Here, I believe: https://github.com/HL7/kindling/blob/main/src/main/java/org/hl7/fhir/definitions/generators/specification/json/SchemaGenerator.java
Ilya Sher (Aug 09 2021 at 10:55):
Meanwhile checked whether other elements have the same issue. Apparently only "canonical" type has the issue:
[
{
"resourceType": "ActivityDefinition",
"element": "library",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ActivityDefinition",
"element": "profile",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ActivityDefinition",
"element": "transform",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "CapabilityStatement",
"element": "instantiates",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "CapabilityStatement",
"element": "imports",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "CapabilityStatement",
"element": "implementationGuide",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "CarePlan",
"element": "instantiatesCanonical",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ChargeItem",
"element": "definitionCanonical",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ChargeItemDefinition",
"element": "partOf",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ChargeItemDefinition",
"element": "replaces",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "CodeSystem",
"element": "valueSet",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "CodeSystem",
"element": "supplements",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "Communication",
"element": "instantiatesCanonical",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "DeviceRequest",
"element": "instantiatesCanonical",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ExampleScenario",
"element": "workflow",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ExampleScenario_Instance",
"element": "resourceType",
"should_have_extension": false,
"has_extenstion": true,
"track_of_refs": []
},
{
"resourceType": "FamilyMemberHistory",
"element": "instantiatesCanonical",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "GraphDefinition",
"element": "profile",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "Measure",
"element": "library",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "MeasureReport",
"element": "measure",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "MessageDefinition",
"element": "replaces",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "MessageDefinition",
"element": "base",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "MessageDefinition",
"element": "parent",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "MessageDefinition",
"element": "graph",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "MessageHeader",
"element": "definition",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "NutritionOrder",
"element": "instantiatesCanonical",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "OperationDefinition",
"element": "base",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "OperationDefinition",
"element": "inputProfile",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "OperationDefinition",
"element": "outputProfile",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "PlanDefinition",
"element": "library",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "Procedure",
"element": "instantiatesCanonical",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "Questionnaire",
"element": "derivedFrom",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "QuestionnaireResponse",
"element": "questionnaire",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ResearchDefinition",
"element": "library",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ResearchElementDefinition",
"element": "library",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "SearchParameter",
"element": "derivedFrom",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "ServiceRequest",
"element": "instantiatesCanonical",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "StructureDefinition",
"element": "baseDefinition",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "StructureMap",
"element": "import",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
},
{
"resourceType": "Task",
"element": "instantiatesCanonical",
"should_have_extension": true,
"has_extenstion": false,
"track_of_refs": [
"#/definitions/canonical"
]
}
]
This was generated by the script I wrote. It is at https://github.com/ngs-lang/nsd/blob/df1e69f22458713a29291449c008f820ec988768/fhir/check-schema-extensions.ngs
Last updated: Apr 12 2022 at 19:14 UTC