Add unit tests verifying contained resource validation fix#609
Merged
andrzejskowronski merged 4 commits intodevelopfrom Oct 30, 2025
Merged
Add unit tests verifying contained resource validation fix#609andrzejskowronski merged 4 commits intodevelopfrom
andrzejskowronski merged 4 commits intodevelopfrom
Conversation
- Created ContainedResourceValidationTests.cs with two test cases - First test verifies only invalid Goal appears in error messages - Second test verifies both valid Goals pass validation - Fixed package version issue in R4 test project - Tests confirm the issue is fixed in SDK6 Co-authored-by: alexzautke <548617+alexzautke@users.noreply.github.com>
Co-authored-by: alexzautke <548617+alexzautke@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix validation error for contained Goal resources
Add unit tests verifying contained resource validation fix
Oct 29, 2025
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.
When validating a CarePlan with multiple contained Goal resources, validation errors for an invalid contained resource incorrectly referenced valid contained resources. This occurred when contained resources had different profiles with fixed values.
Test Coverage
Added
ContainedResourceValidationTests.cswith two test cases:contained[1]) appears in error messages, not the valid Goal (contained[0])Both tests create CarePlan resources with contained Goals having fixed URI constraints:
Technical Changes
SnapshotSourceto handle differential-only StructureDefinition profilesOriginal prompt
This section details on the original issue you should resolve
<issue_title>The first resource in contained section is shown in the error message although the resource is valid</issue_title>
<issue_description>I have a CarePlan resource with two contained Goal resources. Each Goal resource has a profile to restrict the
Goal.description.coding.systemto a fixedUri. The 2nd Goal resource does not comply with the profile and is expected to generate a validation error. However, the validation result incorrectly shows the 1st Goal resource in additional to the 2nd one.Goal profile:
https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g1 and https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g2 are same except the url difference.
{ "resourceType": "StructureDefinition", "url": "https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g1", "name": "Goal-with-fixedurl-g2", "status": "draft", "fhirVersion": "4.3.0", "kind": "resource", "abstract": false, "type": "Goal", "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Goal", "derivation": "constraint", "differential": { "element": [ { "id": "Goal.description.coding.system", "path": "Goal.description.coding.system", "fixedUri": "http://fixed-uri.com/system" } ] } }CarePlan resource:
{ "resourceType": "CarePlan", "contained": [ { "resourceType": "Goal", "id": "f873f0480edf4e7da98c01be4c05ad91", "meta": { "profile": [ "https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g1" ] }, "lifecycleStatus": "active", "description": { "coding": [ { "system": "http://fixed-uri.com/system", "code": "G1" } ] }, "subject": { "reference": "Patient/example", "display": "Peter James Chalmers" } }, { "resourceType": "Goal", "id": "f873f0480edf4e7da98c01be4c05ad92", "meta": { "profile": [ "https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g2" ] }, "lifecycleStatus": "active", "description": { "coding": [ { "system": "http://incorrect-uri.com/system", "code": "G2" } ] }, "subject": { "reference": "Patient/example", "display": "Peter James Chalmers" } } ], "status": "active", "intent": "plan", "subject": { "reference": "Patient/example", "display": "Peter James Chalmers" }, "goal": [ { "reference": "#f873f0480edf4e7da98c01be4c05ad91" }, { "reference": "#f873f0480edf4e7da98c01be4c05ad92" } ] }The validation OperationOutcome:
{ "resourceType": "OperationOutcome", "issue": [ { "severity": "error", "code": "invalid", "details": { "coding": [ { "system": "http://hl7.org/fhir/dotnet-api-operation-outcome", "code": "1008" }, { "system": "http://fire.ly/dotnet-sdk-operation-outcome-structdef-reference", "code": "CarePlan.contained->Goal(https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g2).description.coding.system" } ], "text": "Value 'http://incorrect-uri.com/system' is not exactly equal to fixed value 'http://fixed-uri.com/system'" }, "location": [ "CarePlan.contained[1].description[0].coding[0].system[0], element CarePlan.contained->Goal(https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g2).description.coding.system" ], "expression": [ "CarePlan.contained[1].description[0].coding[0].system[0], element CarePlan.contained->Goal(https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g2).description.coding.system" ] }, { "severity": "error", "code": "invalid", "details": { "coding": [ { "system": "http://hl7.org/fhir/dotnet-api-operation-outcome", "code": "1008" }, { "system": "http://fire.ly/dotnet-sdk-operation-outcome-structdef-reference", "code": "CarePlan.goal->Goal(https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g2).description.coding.system" } ], "text": "Value 'http://incorrect-uri.com/system' is not exactly equal to fixed value 'http://fixed-uri.com/system'" }, "location": [ "CarePlan.contained[0].description[0].coding[0].system[0], element CarePlan.goal->Goal(https://example.org/fhir/StructureDefinition/Goal-with-fixedurl-g2).description.coding.system" ], "expression": [ "CarePlan.contained[0].description[0].coding[0].system[0], element CarePlan.goal->Goal(https://example.org/fhir/StructureDefinition/Goal-with-f... </details> - Fixes FirelyTeam/firely-validator-api#489 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).