Stream: implementers
Topic: Using the validator JAR with a local profile file
Morten Ernebjerg (Jan 19 2018 at 14:01):
I am working on a profile and creating example resources along with it. I was hoping to use the current validator JAR to validate those examples against my local StructureDefinition
XML file for the profile. However, despite investing a good deal of time, I have not gotten it to work yet - when passing a path to a file to -profile
, I get errors saying either that it did not complete loading the StructureDefinition or that the StructureDefinition reference could not be resolved.
The documentation I found seems not quite clear on whether validating against a file even possible. In the readme.txt file that comes along with the validator .zip file, the call syntax def seems to leave out the profile parameter
Usage: java -jar org.hl7.fhir.validator.jar [source] (-defn [definitions]) (-output [output]) where:
but a few lines down such a parameter (allowing filenames) is documented:
- [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.
On the other hand, running
java -jar org.hl7.fhir.validator.jar help
outputs documentation stating the the profile parameter must be a URL (and so presumably cannot handle a local file?)
-profile [url]: a canonical URL to validate against (same as if it was specified in Resource.meta.profile)
Any input on how one can validate against a local profile file (if possible) would be great.
Lloyd McKenzie (Jan 19 2018 at 15:59):
The validator expects to load any relevant profiles from an IG Pack. The "-profile" parameter allows you to assert that "the instance I'm about to validate should be validated against profile xyz even if it hasn't declared that profile". It's not intended to reference a file that contains the desired profiles.
Grahame Grieve (Jan 20 2018 at 05:22):
-profile is the url to validate against. The url must be loaded somehow - the validator will load from the url directly, but before doing that, it looks through the cache of loaded files. You can specify the structure definition using -ig - you don't have to specify an OG pack
Morten Ernebjerg (Jan 22 2018 at 09:40):
Thanks for the clarification, I'll give -ig a try.
Joel Francis (Feb 12 2018 at 14:53):
Thanks for the clarification, I'll give -ig a try.
@Morten Ernebjerg , did you manage to successfully use the validator to validate against a local profile? Can you share an example?
Thanks in advance.
Morten Ernebjerg (Feb 12 2018 at 21:00):
Hi @Joel Francis Yes, I did get it to work. Here is what works for me (based on my current understanding & open to corrections):
Suppose you want to validate a Patient
resource in the file examplesdir/patient_xyz.xml . You want to validate it against a profile that is stored in the folder profiles/ and has URL http://hl7.org/fhir/StructureDefinition/xyz_profile (i.e. the corresponding StructureDefinition
resource file is in that folder and itsurl
field contains that URL). Then you can run
java -jar org.hl7.fhir.validator.jar -defn http://hl7.org/fhir -ig profiles/ -profile http://hl7.org/fhir/StructureDefinition/xyz_profile examplesdir/patient_xyz.xml
The -ig
option ensures that the validator preloads the profiles in the profiles/ folder so that it recognizes the corresponding URLs. I explicitly used the -defn
option to point to the STU3 defs. since the validator otherwise (judging from the output) seems to take the base resource definitions from http://build.fhir.org (current build).
If the profile to validate against is explicitly declared in the meta.profile
field of the resource itself, you can leave out the -profile
option. You can also pass a whole folder of examples to validate instead of just a single file (e.g. passing examplesdir/* instead of examplesdir/patient_xyz.xml), though then the profiles of course have to be declared in the meta.profile
fields of resources (unless they are all the same).
Hope that works for you, too!
Joel Francis (Feb 13 2018 at 13:57):
@Morten Ernebjerg , Thank you very much for the clarity in your example. I will try this out.
Joel Francis (Feb 14 2018 at 19:33):
@Morten Ernebjerg following your example and keeping the folder structure you mentioned just to minimize the differences, I get the attached error. Any thoughts?
validation_error.png folder.png
Morten Ernebjerg (Feb 16 2018 at 08:39):
@Joel Francis Hm, I never came across an error like that. Based on the source code in the HAPI FHIR GitHub repo that throws it (assuming it is HAPI FHIR), it looks like the validator is missing the component that retrieves referenced entities. I don't know the code well enough to say whether this is an internal issue or if it comes from the example/profile . My only hunch would be checking that the references in the example are valid. Maybe stripping off the -profile
parameter to first validate against the base profile could also help pinpoint the source (profile vs. example)?
Joel Francis (Feb 20 2018 at 14:58):
@Joel Francis Hm, I never came across an error like that. Based on the source code in the HAPI FHIR GitHub repo that throws it (assuming it is HAPI FHIR), it looks like the validator is missing the component that retrieves referenced entities. I don't know the code well enough to say whether this is an internal issue or if it comes from the example/profile . My only hunch would be checking that the references in the example are valid. Maybe stripping off the
-profile
parameter to first validate against the base profile could also help pinpoint the source (profile vs. example)?
Thanks @Morten Ernebjerg . I will try your suggestions.
Last updated: Apr 12 2022 at 19:14 UTC