Skip to content

Java FHIR Validator Validation

Alistair Johnson edited this page Mar 11, 2022 · 5 revisions

Java FHIR Validator

The Java FHIR Validator is the endorsed validator for FHIR. It is developed and maintained by Grahame Grieve. The validator is designed as a standalone validator for resources, not CodeSystems or Valuesets.

Reason to use Java Validator vs HAPI

For rapid development of the resources in Postgres, validating resources individually with the Java validator is quicker than HAPI. With HAPI if there are any changes to the FSH files, the whole server needs to restart, which can take 5-10 minutes. That time may seem minor but when you start iterating a lot the time starts to add up. There does appear to be a limitation at scale though with the Java validator, so definitely still want HAPI validation.

Validation on a single file

For a single file the Java validator is great. To get started complete the pre-validation steps.

Pre-validation setup

There are four steps needed to set up before running the validator:

  1. Download the Java validator
  2. Generate the latest implementation guide using Sushi
  3. Output resource from Postgres to JSON
  4. Put the IG and the JSON files both in the same folder as the validator

Pre-validation setup example quickstart

The below downloads the validator and prepares the mimic-fhir IG for use.

# get the validator
cd ~/git/mimic-fhir
wget https://github.com/hapifhir/org.hl7.fhir.core/releases/latest/download/validator_cli.jar
# prepare the profiles
cd ../mimic-profiles
sushi .
# go back and export resources from postgres
cd ../mimic-fhir
# TBD.
# run validator
java -jar validator_cli.jar <resource_file> -version 4.0 -ig <latest_ig>

Running the Java Validator

Using the command line interface, you can call the validator: java -jar validator_cli.jar <resource_file> -version 4.0 -ig <latest_ig>

Validation on all resources via pytest

This is still in development. The major issue here is there is one jar file for the validator but pytest tries to run everything in parallel. To handle that I have sequentially ordered the pytests for resources. Total runtime is ~20 minutes, versus HAPI is ~5 minutes

The process:

  • Download the Java validator
  • Generate the latest mimic-profiles implementation guide using Sushi
  • Update .env file to point to your local java validator and implementation guide
  • In conftest.py a flag has been added to flip between HAPI and JAVA validators
  • In conftest.py, each resource will be output to a file if the validator flag is set
  • In test_server_commands.py, each resource will call the validator and pass the json filename
    • To avoid all the processes calling in order, I added pytest.mark.order to make calls sequential
  • The test_valueset and test_codesystem tests will all fail with the java validator since there is no mechanism to validate codes

The value in the Java validator is more in the individual resource validation as development is occurring, so pytest could still work as that platform if you just run individual resource tests. As well since the java validator is meant for resources, the pytests for codesystem and valueset are not possible with the validator.