Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating a resource with CodeableReference throws an exception System.InvalidOperationException: 'Checking reference type should have been handled already.' #275

Closed
almostchristian opened this issue Jan 27, 2024 · 0 comments · Fixed by #276

Comments

@almostchristian
Copy link

We're currently evaluating moving to the new validator and found a bug when the resource as a CodeableReference property.
The code for validating references does not handle CodeableReference values properly throws an exception.

Reproduction code:

var packageServer = "https://packages.simplifier.net";
var fhirRelease = FhirRelease.R5;
var packageResolver = FhirPackageSource.CreateCorePackageSource(ModelInfo.ModelInspector, fhirRelease, packageServer);
var resourceResolver = new CachedResolver(packageResolver);
var terminologyService = new LocalTerminologyService(resourceResolver);

var validator = new Validator(resourceResolver, terminologyService);
var testEncounter = new Encounter
{
    ServiceType = [ new CodeableReference { Concept = new CodeableConcept("http://hl7.org/fhir/ValueSet/service-type", "test") } ],
};

var profile = Firely.Fhir.Validation.Canonical.ForCoreType("Encounter").ToString();

Exception:

System.InvalidOperationException: 'Checking reference type should have been handled already.'

   at Firely.Fhir.Validation.ReferencedInstanceValidator.Validate(IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.AssertionValidators.<ValidateMany>g__repeat|4_0(IValidatable assertion, IEnumerable`1 input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.AssertionValidators.ValidateMany(IAssertion assertion, IEnumerable`1 input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.AllValidator.<>c__DisplayClass12_0.<Validate>b__0(IAssertion ma)
   at System.Linq.Enumerable.SelectArrayIterator`2.Fill(ReadOnlySpan`1 source, Span`1 destination, Func`2 func)
   at System.Linq.Enumerable.SelectArrayIterator`2.ToList()
   at Firely.Fhir.Validation.AllValidator.Validate(IEnumerable`1 input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.AssertionValidators.ValidateMany(IAssertion assertion, IEnumerable`1 input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.ElementSchema.<>c__DisplayClass19_0.<ValidateInternal>b__0(IAssertion ma)
   at System.Linq.Enumerable.WhereSelectListIterator`2.ToList()
   at Firely.Fhir.Validation.ElementSchema.ValidateInternal(IEnumerable`1 input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.ElementSchema.Firely.Fhir.Validation.IGroupValidatable.Validate(IEnumerable`1 input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.AssertionValidators.ValidateMany(IAssertion assertion, IEnumerable`1 input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.ChildrenValidator.<>c__DisplayClass13_0.<Validate>b__0(Match m)
   at System.Linq.Enumerable.SelectListIterator`2.MoveNext()
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at Firely.Fhir.Validation.ChildrenValidator.Validate(IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.AssertionValidators.ValidateOne(IAssertion assertion, IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.ElementSchema.<>c__DisplayClass21_0.<ValidateInternal>b__0(IAssertion ma)
   at System.Linq.Enumerable.WhereSelectListIterator`2.ToList()
   at Firely.Fhir.Validation.ElementSchema.ValidateInternal(IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.FhirSchema.ValidateInternal(IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.ResourceSchema.<>n__0(IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.ResourceSchema.<>c__DisplayClass5_0.<ValidateResourceSchema>b__0()
   at Firely.Fhir.Validation.ValidationLogger.Start(ValidationState state, String profileUrl, Func`1 validator)
   at Firely.Fhir.Validation.ResourceSchema.ValidateResourceSchema(IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.ResourceSchema.<>c__DisplayClass4_0.<ValidateInternal>b__6(ResourceSchema s)
   at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList()
   at Firely.Fhir.Validation.ResourceSchema.ValidateInternal(IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.ResourceSchema.<>c__DisplayClass3_0.<ValidateInternal>b__0(IScopedNode i, Int32 index)
   at System.Linq.Enumerable.<SelectIterator>d__229`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Firely.Fhir.Validation.ResourceSchema.ValidateInternal(IEnumerable`1 input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.SchemaReferenceValidator.Validate(IEnumerable`1 input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.SchemaReferenceValidator.Validate(IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.AssertionValidators.ValidateOne(IAssertion assertion, IScopedNode input, ValidationSettings vc, ValidationState state)
   at Firely.Fhir.Validation.AssertionValidators.Validate(IAssertion assertion, IScopedNode input, ValidationSettings vc)
   at Firely.Fhir.Validation.Validator.Validate(IScopedNode sn, String profile)
   at Firely.Fhir.Validation.Validator.Validate(Resource instance, String profile)
   at Program.<Main>$(String[] args) in U:\source\ConsoleApp1\ConsoleApp1\Program.cs:line 66
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 a pull request may close this issue.

2 participants