domo
domo

Reputation: 39

How to run FHIR Validator (java jar)

I had downloaded "Validation Pack" from http://www.hl7.org/implement/standards/fhir/downloads.html.

After unzip 'validator.zip' and read 'readme.txt', I tried to run 'org.hl7.fhir.validator.jar' file on Windows Command Prompt.

java -jar org.hl7.fhir.validator.jar mysourcefile.xml

I encountered the following error:

java.lang.Exception: Unknown command 'mysourcefile.xml' at org.hl7.fhir.instance.test.ToolsHelper.main(ToolsHelper.java:77) java.lang.ArrayIndexOutOfBoundsException: 1 at org.hl7.fhir.instance.test.ToolsHelper.main(ToolsHelper.java:81)

Why is 'mysourcefile.xml' an unknown command? Please help. Thanks!

Upvotes: 1

Views: 3303

Answers (4)

Grahame Grieve
Grahame Grieve

Reputation: 3586

Updated docmentation

Validation Instructions:

  1. You need java 1.7 jre or jdk installed
  2. Download the validator tool and the validation pack (java executable, and dictionary of FHIR definitions, respectively), and unzip the validator (but not the validation pack)
  3. Execute the validator with the following command line: java –jar org.hl7.fhir.validator.jar [source] (-defn [definitions]) (-profile [profile]) (-output [output]) where:

    • [source] is a file name or url of the resource or bundle feed to validate  [definitions] is the file name or url of the validation pack (validation.zip). Default: get it from inside the jar file

    • [profile] is an optional filename or URL for a specific profile to validate a resource against. In the absence of this parameter, the resource will be checked against the base specification using the definitions.

    • [output] is a filename for the results (OperationOutcome). Default: results are sent to the std out.

Note: at this time, the validator is only able to validate XML resources, not JSON ones.

Here’s a windows batch file that will do all this:

REM get the validator and unzip it
wget.exe http://hl7-fhir.github.io/validator.zip
7z.exe x validator.zip
7z.exe x saxon.zip
REM Get the validation source file (dictionary)
wget.exe http://hl7-fhir.github.io/validation-min.zip
REM get an example to validate
wget.exe http://ec2-54-87-74-90.compute-
1.amazonaws.com/open/Patient/1234 -O daf-patient.xml
REM validate it. The DAF profile will be loaded out of the
definitions in validation-min.zip
java -jar org.hl7.fhir.validator.jar daf-patient.xml -defn
validation-min.zip -profile
http://hl7.org/fhir/StructureDefinition/patient-daf-dafpatient
pause

Upvotes: 1

Alexandra
Alexandra

Reputation: 11

If you want to validate your resource against the base specification run the following command:

java -jar org.hl7.fhir.validator.jar your-fhir-resource.xml -defn validation.zip

If you want to validate your resource against a profile (structure definition) run the following command:

java -jar org.hl7.fhir.validator.jar your-fhir-resource.xml -defn validation.zip -profile your-structure-definition.xml

Upvotes: 1

Grahame Grieve
Grahame Grieve

Reputation: 3586

The jar file is set up to load the wrong class. The correct class is org.hl7.fhir.instance.validation.Validator.

You can name that class explicitly when you run the jar, and you'll get the help, which will say:

  Usage: FHIRValidator.jar [source] (-defn [definitions]) (-output [output]) (-noxslt)

you'll got more documentation as well.

Else you edit the manifest inside the jar and change the main class.

Upvotes: 1

Seth Rylan
Seth Rylan

Reputation: 126

The documentation needs updating. Try:

java -jar org.hl7.fhir.validator.jar round mysourcefile.xml output.xml

But I don't think the DSTU validation.jar is applying the XSD or Schematrons. If this is your goal, then you can use other tools.

For XSD:

xmllint --noout --schema <XSD_FILE> mysourcefile.xml

For Schematron, using probatron4j

java -jar probatron.jar mysourcefile.xml fhir-atom.sch

Upvotes: 0

Related Questions