FHIR Chat · Instance Validation with HAPI FHIR · implementers

Stream: implementers

Topic: Instance Validation with HAPI FHIR


view this post on Zulip Claude Nanjo (Jan 29 2021 at 17:10):

Hello folks, does anyone have experience validating a FHIR instance (say a specific patient) against a 'home-made' (not US Core) profile programmatically (not via CLI)? If so, would you be able to share a code snippet on how to do that? I was hoping there would be a method such as validator.validate(myInstance, myProfile) or validator.validate(myInstance, myProfileURL) and if the latter, a way to register the profile with the FHIR context. Thank you!

view this post on Zulip Lloyd McKenzie (Jan 29 2021 at 22:03):

@Mark Iantorno

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:03):

hey

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:04):

What do you mean by "validate a FHIR resource programmatically" and not via the cli

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:04):

Validating a resource is huge

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:04):

Like...I can point you to the repository in GitHub where that code lives, but it is 100k+ lines of code

view this post on Zulip Lloyd McKenzie (Jan 29 2021 at 22:04):

I presume "how do you trigger validation from code" - is there documentation about how to instantiate the ValidationEngine and then trigger validation of an instance?

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:04):

@Claude Nanjo

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:05):

There is not documentation on that

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:05):

you would have to clone the repository and the write the call the method in the validation package

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:06):

I do this in the soon to be a real tool validation website, I can point you to that repo

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:06):

https://github.com/hapifhir/org.hl7.fhir.validator-wrapper is the project

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:07):

If you look at this class here: https://github.com/hapifhir/org.hl7.fhir.validator-wrapper/blob/master/src/jvmMain/kotlin/routes/ValidationRoutes.kt

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:08):

I create something called a ValidationRequest (https://github.com/hapifhir/org.hl7.fhir.validator-wrapper/blob/master/src/commonMain/kotlin/model/ValidationRequest.kt) and then send it to the Validator

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:09):

it contains the Validation CliContext, in addition to the list of files that need to be validated

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:09):

The CliContext contains all the information that a request for validation takes in

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:09):

it's named CliContext because I originally refactored it when only the Cli existed

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:10):

Take a look at that code, it should give you a starting point, but if you have other questions, let me know

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:17):

Also, in the core libs the ValidationService class is here: https://github.com/hapifhir/org.hl7.fhir.core/blob/master/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java

view this post on Zulip Claude Nanjo (Jan 29 2021 at 22:26):

James responded to my enquiry with the following recommendation which we are trying now:

There is an example of how to supply custom definitions to the validator here: https://hapifhir.io/hapi-fhir/docs/validation/validation_support_modules.html#recipe-supplying-custom-definitions

This example is actually a bit out of date, a new version is about to get pushed. You'll want to add the following two lines as well:
// This module supplies several code systems that are commonly used in validation
supportChain.addValidationSupport(new CommonCodeSystemsTerminologyService(ctx));

// This module implements terminology services for in-memory code validation
supportChain.addValidationSupport(new InMemoryTerminologyServerValidationSupport(ctx));

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:27):

So, just keep in mind that the HAPI validator does not align 100% with the core validator

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:27):

your results may vary

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:28):

So, you may have a resource that passes in HAPI but when run through the core validator, it fails

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:28):

or the other way around

view this post on Zulip Mark Iantorno (Jan 29 2021 at 22:28):

but they are _mostly_ aligned

view this post on Zulip Claude Nanjo (Jan 29 2021 at 22:28):

Thank you Mark. Sounds good. At some point, hopefully the two will converge.

view this post on Zulip Claude Nanjo (Jan 29 2021 at 22:29):

I will post our code once we verify it works for others who need to do the same thing.

view this post on Zulip Oliver Egger (Jan 30 2021 at 15:06):

@Claude Nanjo on the server se we implemented on top of hapi-fhir a $validate operation for both approaches and I think it might work similiar on the client side 1) hapi-fhir: https://github.com/ahdis/hapi-fhir-jpaserver-validator/blob/530/src/main/java/ch/ahdis/fhir/hapi/jpa/validation/ValidationProvider.java and 2) hapi-fhir but using directly the core validator: https://github.com/ahdis/matchbox/blob/master/src/main/java/ch/ahdis/matchbox/validation/ValidationProvider.java. @Mark Iantorno @James Agnew happy to provide a pull request on the base hapi-fhir implementation if this would be something of interest to you to add $valdiate operation (it is not 100% spec conform because it is on the root of the server and not on the resource).


Last updated: Apr 12 2022 at 19:14 UTC