Stream: hapi
Topic: Using validator via NativeHostServices
Morten Ernebjerg (Dec 17 2019 at 11:36):
I'm trying to get use the validator running (outside a HAPI server) for validation STU3 resources using org.hl7.fhir.r5.validation.NativeHostServices
. The JDoc in this class says that the setup includes the following step:
- call init(path) where path refers to one of the definitions files from the main build (e.g. definitions.xml.zip) - required, do only once, do before anything else
However, calling init()
on a NativeHostServices instances and passing the path to a definitions.json.zip file does not seem to work - it fails with the error "Unable to find/resolve/read -ig [path passed]"
Following the call stack, we have
init(src)
--> new ValidationEngine(src)
--> loadDefinitions(src, false)
--> loadIgSource(src, false, true)
In loadIgSource(src,...)
, a comment says
// src can be one of the following:
// - a canonical url for an ig - this will be converted to a package id and loaded into the cache
// - a package id for an ig - this will be loaded into the cache
// - a direct reference to a package ("package.tgz") - this will be extracted by the cache manager, but not put in the cache
Passing the path to definitions.json.zip does not seem to fit here and indeed, it does not match any of the conditions inside the method - it only recognizes files ending with ".tgz", "igpack.zip", or ".pack".
Do I need the base resource defs in another format to get this working?
Grahame Grieve (Dec 17 2019 at 19:05):
oh I need to add a test case for this. I'll do that later today. You need to pass in package Ids now
Grahame Grieve (Dec 17 2019 at 19:06):
have you looked at NativeHostServiceTester ?
Morten Ernebjerg (Dec 18 2019 at 10:04):
Right, looked into it now. Loading via an ID means loading with HTTP, right? My code might be running in an environment where internet access cannot be assumed so I'd need to be able to access the profiles locally. BTW renaming "definition.json.zip" to "definitions.json.igpack.zip" seems to make the load complete since it now matches one of the pattern, but I still need to check that validation runs correctly.
Grahame Grieve (Dec 18 2019 at 10:12):
well, if the packages are installed in the local cache, then there's no need for internet access
Morten Ernebjerg (Dec 18 2019 at 11:08):
I think I may be thinking about this all wrong (Java is not my native home...). When would I load the packages into the local cache?
Grahame Grieve (Dec 18 2019 at 11:19):
it happens once. The NativeHostValidator will fetch it from the web and store it in local cache. But you can put it in there too, or get the java code to do it as a once off
Morten Ernebjerg (Dec 18 2019 at 12:39):
OK, thanks - I'll dive in a bit deeper.
Morten Ernebjerg (Dec 19 2019 at 12:19):
I tried getting NativeHostServicesTester to run. However, the current code in that class tries to load hl7.fhir.core#4.0.0
, but it fails saying "Unable to resolve version 4.0.0 for package hl7.fhir.core" (and similar for 4.0.1). When changing the version in the init()
method call to "hl7.fhir.core#3.0.2", it starts loading the resources but fails because of a duplicate resource:
starting... Creating Package manager? + .. load IG from hl7.fhir.r3.examples#3.0.2 + .. load IG from hl7.fhir.r3.expansions#3.0.2 + .. load IG from hl7.fhir.r3.elements#3.0.2 Error loading ImplementationGuide-fhir.json: Duplicate Resource http://hl7.org/fhir/ImplementationGuide/fhir Exception in thread "main" org.hl7.fhir.exceptions.FHIRException: Error loading ImplementationGuide-fhir.json: Duplicate Resource http://hl7.org/fhir/ImplementationGuide/fhir at org.hl7.fhir.r5.context.SimpleWorkerContext.fromDefinitions(SimpleWorkerContext.java:207) at org.hl7.fhir.r5.validation.ValidationEngine.loadDefinitions(ValidationEngine.java:406) at org.hl7.fhir.r5.validation.ValidationEngine.<init>(ValidationEngine.java:390) at org.hl7.fhir.r5.validation.NativeHostServices.init(NativeHostServices.java:157) at org.hl7.fhir.validation.tests.NativeHostServiceTester.main(NativeHostServiceTester.java:14) Caused by: org.hl7.fhir.exceptions.DefinitionException: Duplicate Resource http://hl7.org/fhir/ImplementationGuide/fhir at org.hl7.fhir.r5.context.BaseWorkerContext.cacheResource(BaseWorkerContext.java:225) at org.hl7.fhir.r5.context.SimpleWorkerContext.loadFromFileJson(SimpleWorkerContext.java:282) at org.hl7.fhir.r5.context.SimpleWorkerContext.loadDefinitionItem(SimpleWorkerContext.java:216) at org.hl7.fhir.r5.context.SimpleWorkerContext.fromDefinitions(SimpleWorkerContext.java:204) ... 4 more Process finished with exit code 1
Is that an issue with the code or the package being loaded?
Morten Ernebjerg (Dec 19 2019 at 12:38):
Looking at the cached file "/packages/hl7.fhir.r3.examples#3.0.2/package/.index.json", the URL "http://hl7.org/fhir/ImplementationGuide/fhir" does indeed occur twice,:
{ "filename": "ig-r4.json", "resourceType": "ImplementationGuide", "id": "fhir", "url": "http://hl7.org/fhir/ImplementationGuide/fhir", "version": "3.0.2" }, ... { "filename": "ImplementationGuide-fhir.json", "resourceType": "ImplementationGuide", "id": "fhir", "url": "http://hl7.org/fhir/ImplementationGuide/fhir", "version": "3.0.2" },
Might that be the issue?
Last updated: Apr 12 2022 at 19:14 UTC