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

The validator is not resolving certain references #1654

Closed
PaulDeac opened this issue Mar 12, 2021 · 2 comments · Fixed by #1880 or #1887
Closed

The validator is not resolving certain references #1654

PaulDeac opened this issue Mar 12, 2021 · 2 comments · Fixed by #1880 or #1887

Comments

@PaulDeac
Copy link

Describe the bug
We have identified some cases in which the validator is not calling the IResourceResolver to resolve certain relative references.

To Reproduce
Steps to reproduce the behavior:

Both this resources have a reference to Patient/UKCore-Patient-RichardSmith-Example:
https://simplifier.net/ukcore/ukcore-careteam-weightmanagementteam-example
https://simplifier.net/ukcore/ukcore-medicationstatement-amoxicillin-example

However, validating them the outcome is different:

  1. Gives warnings: https://simplifier.net/ukcore/ukcore-careteam-weightmanagementteam-example/$validate
  2. Doesn't give warnings: https://simplifier.net/ukcore/ukcore-medicationstatement-amoxicillin-example/$validate

Our investigation concluded that in the case of the resource that doesn't give warnings the validator is not calling the IResourceResolver to resolve the reference.

Expected behavior
Both validations should attempt to resolve the reference to Patient/UKCore-Patient-RichardSmith-Example.

Screenshots
If applicable, add screenshots to help explain your problem.

Version used:

  • FHIR Version: R4 (haven't tried with STU3)
  • Version: Tried with both 1.9.0 and 2.0.2.

Additional context
Add any other context about the problem here.

@marcovisserFurore
Copy link
Member

I have made a unit test for it:

[Theory]
[InlineData("Issue_1654_medicationstatement.xml", typeof(MedicationStatement))]
[InlineData("Issue_1654_careteam.xml", typeof(CareTeam))]
public void Issue_1654(string testFile, Type pocoType)
{
    var client = new FhirClient("https://fhir.simplifier.net/UKCore");
    var visitResolver = new VisitResolver();
    var resolver = new CachedResolver(new MultiResolver(ZipSource.CreateValidationSource(), visitResolver, new WebResolver(id => client)));

    var validator = new Validator(new ValidationSettings() { ResourceResolver = resolver, ResolveExternalReferences = true });

    var xml = File.ReadAllText(Path.Combine("TestData", "validation", testFile));
    var parser = new FhirXmlParser();
    var poco = parser.Parse(xml, pocoType);
    Assert.NotNull(poco);

    var outcome = validator.Validate(poco);
    Assert.True(outcome.Success);
    Assert.True(0 == outcome.Warnings, $"Found {outcome.Warnings} warnings in test file {testFile}");
    Assert.True(visitResolver.Visited("Patient/UKCore-Patient-RichardSmith-Example"), "example patient has not been resolved");
}

class VisitResolver : IResourceResolver
{
    private List<string> _visits = new List<string>();

    public Resource ResolveByCanonicalUri(string uri) => null;

    public Resource ResolveByUri(string uri)
    {
        _visits.Add(uri);
        return null;
    }

    internal bool Visited(string uri) => _visits.Contains(uri);
}

We see indeed that the MedicationStatement case does not resolve the reference Patient/UKCore-Patient-RichardSmith-Example. The CareTeam case does.

Btw, in the CareTeam instance there is a reference to Organization/UKCore-Organisation-WhiteRoseMedicalCentre-Example but that should be UKCore-Organization-WhiteRoseMedicalCentre-Example. And the reference to the Practitioner should be Practitioner/UKCore-Practitioner-DoctorPaulRastall-Example and not Practitioner/UKCore-Practitioner-PaulRastall-Example.

@kensinn
Copy link

kensinn commented Mar 22, 2021

We have found that on our project, validation to resolve references works as expected on non-profiled resources (i.e. if resource.meta.profile is not supplied), but for profiled resources, the validation to resolve references is not executed, and no warnings are generated for broken references.

We tested the same message with and without resource.meta.profile using HL7 FHIR Validator, with identical warning messages re: references not locally contained and references unreachable by traversing from the first Bundle entry.

Not sure if it's related, but it sounds like a similar issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants