FHIR Chat · FHIR Bundle Validation · implementers

Stream: implementers

Topic: FHIR Bundle Validation


view this post on Zulip Yener Topal (Jul 10 2018 at 08:35):

Hello Everyone,

I am getting started with learning the FHIR Api for c# and I would like to ask a question on how i can validate an incoming Bundle request through a POST request to make sure its valid. I receive it as JSON.

I am also looking for documentation on the C# FHIR Api it seems like documentation is incomplete?

view this post on Zulip René Spronk (Jul 12 2018 at 06:52):

@Mirjam Baltus @Ewout Kramer ?

view this post on Zulip Christiaan Knaap (Jul 12 2018 at 13:13):

Documentation is indeed not covering validation. Basics are simple. Create a new Validator and call Validate() on your resource POCO. You can find an example of its use in https://github.com/ewoutkramer/Furore.Fhir.ValidationDemo/blob/master/MainForm.cs

view this post on Zulip Yener Topal (Jul 16 2018 at 08:08):

Documentation is indeed not covering validation. Basics are simple. Create a new Validator and call Validate() on your resource POCO. You can find an example of its use in https://github.com/ewoutkramer/Furore.Fhir.ValidationDemo/blob/master/MainForm.cs

Can I apply this validation for my case? I am receiving a Bundle message in JSON:
This is my code:

        Bundle bundle = new FhirJsonParser().Parse<Bundle>(resource.ToString());

        OperationOutcome result = null;

        ValidationSettings settings = ValidationSettings.Default;
        settings.EnableXsdValidation = true;
        settings.Trace = true;
        settings.ResourceResolver = this.CombinedSource;

        var validator = new Hl7.Fhir.Validation.Validator(settings);
        result = validator.Validate(bundle);

I receive the error: "Unable to resolve reference to profile 'http://hl7.org/fhir/StructureDefinition/Bundle' (at Bundle)"

Not sure if this is how its supposed to work but that given url in the error has been changed to "http://hl7.org/fhir/bundle.html" I believe.

Just need confirmation if i did it right, i can read the bundle perfectly fine, atm the validator doesn't seem to work for my case.

view this post on Zulip Christiaan Knaap (Jul 16 2018 at 14:04):

I think the #dotnet stream is a better fit for .NET API specifics.
@Mirjam Baltus : can you spot an error in the code?

view this post on Zulip Mirjam Baltus (Jul 16 2018 at 15:40):

I'm not sure what's in the CombinedSource for the ResourceResolver. You need the specification to validate against, so one of the sources should be pointing to the specification.zip. One of the ways to do that, is:
var source = new CachedResolver(ZipSource.CreateValidationSource());

Of course you can combine sources with a MultiResolver, for example joining the specs with your own directory containing StructureDefinitions.

view this post on Zulip Yener Topal (Jul 17 2018 at 07:29):

I'm not sure what's in the CombinedSource for the ResourceResolver. You need the specification to validate against, so one of the sources should be pointing to the specification.zip. One of the ways to do that, is:
var source = new CachedResolver(ZipSource.CreateValidationSource());

Of course you can combine sources with a MultiResolver, for example joining the specs with your own directory containing StructureDefinitions.

              string profilePath = @"C:\Users\Yener\Source\Repos\first-stam-rep\packages\Hl7.Fhir.Specification.STU3.0.96.0\contentFiles\any\any";
              DirectorySource = new CachedResolver(new DirectorySource(profilePath, includeSubdirectories: true));
              CombinedSource = new MultiResolver(DirectorySource);

This is how I set up the resolver. Because ZipSource.CreateValidationSource gave me an error I think i need to setup something before i can use that method.


Last updated: Apr 12 2022 at 19:14 UTC