Stream: implementers
Topic: Validation Questions
Raghav Rajagopalan (Oct 21 2020 at 21:52):
Hi y'all, I'm new to FHIR and am currently looking into using the FHIR validator in a process. My issue is that running (what I think is) the same validation using the ValidationEngine vs using the command line jar gives me two different results.
For context, I want to validate:
- this resource - https://www.hl7.org/fhir/us/core/Patient-example.html (downloaded as an XML file)
- against - https://www.hl7.org/fhir/us/core/index.html
I'm using the ValidationEngine like so (validating against r4 base spec, so want to use that as an IG):
ValidationEngine validator = null;
try {
validator = new ValidationEngine("hl7.fhir.r4.core");
validator.connectToTSServer("http://tx.fhir.org", null, FhirPublication.fromCode("4.0"));
validator.loadIg("hl7.fhir.r4.core", true);
OperationOutcome o = validator.validate(Manager.FhirFormat.XML, this.getClass().getClassLoader().getResourceAsStream("fhir-us-core/patient/validResource.xml"), null);
List<OperationOutcome.OperationOutcomeIssueComponent> issues = o.getIssue();
issues.forEach((issue) -> {
if (issue.getSeverity() == OperationOutcome.IssueSeverity.ERROR || issue.getSeverity() == OperationOutcome.IssueSeverity.FATAL) {
System.out.println(issue.getDetails().getText());
}
});
} catch (IOException | URISyntaxException | EOperationOutcome e) {
e.printStackTrace();
}
....
This is an error that gets outputted: "URL value 'http://hospital.smarthealthit.org' does not resolve "
However it seems to work, with an Informational "ALL OK" message when I run the following in my terminal: java -jar /path/to/validator_cli.jar path/to/valid/patientResource.xml -version 4.0 -ig http://hl7.org/fhir/us/core/
ryan moehrke (Oct 21 2020 at 23:28):
this may not be your root issue here but I notice that your terminal command points to the -ig http://hl7.org/fhir/us/core/ but your code uses validator.loadIg("hl7.fhir.r4.core", true);
If I'm reading this right you are validating against US Core in the terminal but against base FHIR core in the code block. I'm not sure what the package name for us-core is but I'd try using that first.
and the next question I'd ask if that doesn't work is, what level of error are you seeing in the operationoutcome? is it an error, warning, or informational. I'm not sure but what might be happening is some of the low-severity warning/informationals may be hidden from the terminal call without a specific flag set
Raghav Rajagopalan (Oct 21 2020 at 23:43):
Thanks for your response!
Sorry the IG I put in the code block was a typo - I did mean to use "http://hl7.org/fhir/us/core/" in both places, and when I do that the level of error for the message is either Fatal or Error - whereas the running it in the CLI has no errors or warning level messages.
Grahame Grieve (Oct 22 2020 at 00:41):
it looks to me like you should investigate the validator settings - for instance, validation options relating to unknown references
Raghav Rajagopalan (Oct 22 2020 at 18:49):
Hmm not sure how to allow it to not worry about URLs it can't resolve without changing the resource file itself.
For reference, the resolveURL code in https://github.com/hapifhir/org.hl7.fhir.core/blob/master/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java#L1763 seems to consider URLs that don't begin with "http://" or "https://" as valid .
If it helps, the URL that fails doesn't seem to point to anything now (http://hospital.smarthealthit.org), so that could be an issue with the example patient resource.
Grahame Grieve (Oct 22 2020 at 20:57):
have you implemented IValidatorResourceFetcher ?
Raghav Rajagopalan (Oct 22 2020 at 21:23):
No, ValidationEngine implements it, and since the CLI was calling it under the hood I was assuming I was doing something wrong there. Can definitely implement it and be less strict when resolving URLs if that's the best course.
Would using ValidationEngine the same way the CLI does via ValidationService (like https://github.com/hapifhir/org.hl7.fhir.core/blob/master/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorCli.java#L159) be a better way to go about that.
Are there usage examples or documentation surrounding ValidationEngine besides the comments in the file?
Grahame Grieve (Oct 22 2020 at 23:29):
no the code and comments are what you have.
Raghav Rajagopalan (Oct 23 2020 at 15:37):
I think I may have figured it out! - If InstanceValidator cannot resolve the URL, it tries using a fetcher's (if non null) resolveURL. By default, the fetcher is null. ValidationService initializes a fetcher (StandAloneValidatorFetcher) and that fetcher is able to resolve the URL.
When using ValidationEngine and setting the fetcher to the StandAloneValidatorFetcher, the URL is able to be resolved.
Last updated: Apr 12 2022 at 19:14 UTC