Stream: hapi
Topic: Validator against us-core?
Peter Teunissen (May 11 2021 at 19:35):
When I try to validate the attached provenance.json, with HAPI 5.3.3, the validator reports an error:
Validation severity ERROR - Location Provenance.agent[1].type.coding[0] - Message Unknown Code System 'http://hl7.org/fhir/us/core/CodeSystem/us-core-provenance-participant-type'
According to the us-core spec (https://www.hl7.org/fhir/us/core/StructureDefinition-us-core-provenance.html) it is an allowed coding.
Here is my code:
FhirContext ctx = FhirContext.forR4();
IParser parser = ctx.newJsonParser();
FhirValidator validator = ctx.newValidator();
IValidatorModule module = new FhirInstanceValidator(ctx);
validator.registerValidatorModule(module);
String json = ...(see attachment)...;
Provenance p = parser.parseResource(Provenance.class, json);
ValidationResult vr = validator.validateWithResult(p);
vr.getMessages()
.forEach(singleValidationMessage -> System.out
.println(String.format(" Validation severity %s - Location %s - Message %s",
singleValidationMessage.getSeverity(), singleValidationMessage.getLocationString(),
singleValidationMessage.getMessage())));
Is this a bug?
Grahame Grieve (May 12 2021 at 12:32):
have you loaded US Core into the validator context?
Peter Teunissen (May 12 2021 at 14:07):
I guess I didn't.... I'm trying to understand the documentation how to do that, but I am not having much luck.
Whatever I try it seems to pass, even when I butcher the input json, so I think it is not validating at all anymore.
FhirContext ctx = FhirContext.forR4();
IParser parser = ctx.newJsonParser();
FhirValidator validator = ctx.newValidator();
String json = ...(see attachment)...;
Provenance p = parser.parseResource(Provenance.class, json);
ValidationResult vr = validator.validateWithResult(p, new ValidationOptions()
.addProfile("https://www.hl7.org/fhir/us/core/StructureDefinition-us-core-provenance.xml"));
vr.getMessages()
.forEach(singleValidationMessage -> System.out
.println(String.format(" Validation severity %s - Location %s - Message %s",
singleValidationMessage.getSeverity(), singleValidationMessage.getLocationString(),
singleValidationMessage.getMessage())));
Is this the right way to do this? What should be the exact url of the profile?
Peter Teunissen (May 12 2021 at 19:54):
@Grahame Grieve
I have been trying some more and when I register the us-core valueset and codeset myself (after downloading the definitions), I can get rid of the ERROR part. But the way I need to code this seems cumbersome. Is there no easier way to load US Core?
FhirContext ctx = FhirContext.forR4();
IParser parser = ctx.newJsonParser();
IParser xmlParser = ctx.newXmlParser();
URL url = new URL("file:///C:\\git_work\\hapi-test\\src\\test\\resources\\provenance.json");
Path resPath = Paths.get(url.toURI());
String json = new String(Files.readAllBytes(resPath), "UTF-8");
Provenance p = parser.parseResource(Provenance.class, json);
ValidationSupportChain supportChain = new ValidationSupportChain();
supportChain.addValidationSupport(new DefaultProfileValidationSupport(ctx));
supportChain.addValidationSupport(new CommonCodeSystemsTerminologyService(ctx));
supportChain.addValidationSupport(new InMemoryTerminologyServerValidationSupport(ctx));
PrePopulatedValidationSupport prePopulatedSupport = new PrePopulatedValidationSupport(ctx);
URL surl = new URL("file:///C:\\temp\\StructureDefinition-us-core-provenance.xml");
Path sPath = Paths.get(surl.toURI());
String sxml = new String(Files.readAllBytes(sPath), "UTF-8");
StructureDefinition sdef = xmlParser.parseResource(StructureDefinition.class, sxml);
prePopulatedSupport.addStructureDefinition(sdef);
URL vurl = new URL("file:///C:\\temp\\ValueSet-us-core-provenance-participant-type.xml");
Path vPath = Paths.get(vurl.toURI());
String vxml = new String(Files.readAllBytes(vPath), "UTF-8");
ValueSet vs = xmlParser.parseResource(ValueSet.class, vxml);
prePopulatedSupport.addValueSet(vs);
URL csurl = new URL("file:///C:\\temp\\CodeSystem-us-core-provenance-participant-type.xml");
Path csPath = Paths.get(csurl.toURI());
String csxml = new String(Files.readAllBytes(csPath), "UTF-8");
CodeSystem cs = xmlParser.parseResource(CodeSystem.class, csxml);
prePopulatedSupport.addCodeSystem(cs);
supportChain.addValidationSupport(prePopulatedSupport);
CachingValidationSupport cache = new CachingValidationSupport(supportChain);
FhirInstanceValidator validatorModule = new FhirInstanceValidator(cache);
FhirValidator validator = ctx.newValidator().registerValidatorModule(validatorModule);
ValidationResult vr = validator.validateWithResult(p);
vr.getMessages()
.forEach(singleValidationMessage -> System.out
.println(String.format(" Validation severity %s - Location %s - Message %s",
singleValidationMessage.getSeverity(), singleValidationMessage.getLocationString(),
singleValidationMessage.getMessage())));
Grahame Grieve (May 13 2021 at 00:24):
well, I would've expected you to do this by package id and just load all of us core
Peter Teunissen (May 13 2021 at 03:00):
How would I do that?
Peter Teunissen (May 14 2021 at 12:42):
@Grahame Grieve How would I load all us-core?
Grahame Grieve (May 14 2021 at 20:53):
@Mark Iantorno ?
Mark Iantorno (May 14 2021 at 23:22):
Hi, I will look at this over the weekend. I was at the community garden and did not see this.
Mark Iantorno (May 17 2021 at 13:03):
Hey @Peter Teunissen, sorry for the delay in responding.
Mark Iantorno (May 17 2021 at 13:03):
(deleted)
Mark Iantorno (May 17 2021 at 13:05):
(deleted)
Mark Iantorno (May 17 2021 at 13:05):
(deleted)
Mark Iantorno (May 17 2021 at 13:05):
(deleted)
Mark Iantorno (May 17 2021 at 13:05):
(deleted)
Mark Iantorno (May 17 2021 at 13:06):
I misread your initial message give me a second to figure it out for you
Mark Iantorno (May 17 2021 at 13:07):
(deleted)
Mark Iantorno (May 17 2021 at 13:42):
Alright, I would start by looking at these tests here: https://github.com/hapifhir/hapi-fhir/blob/75c74a22dbd1f0dde3631b540d1898eef2a2666f/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmR4Test.java
Mark Iantorno (May 17 2021 at 13:42):
Which loads us-core into the package cache using the PackageInstallationSpec class
Mark Iantorno (May 17 2021 at 13:43):
(deleted)
Mark Iantorno (May 17 2021 at 13:45):
That is probably the best place to start. I haven't actually run a test with it, but it seems like they have an implemented test there that uses US-Core
Mark Iantorno (May 17 2021 at 13:46):
Let me know if that helps
Peter Teunissen (May 17 2021 at 17:24):
@Mark Iantorno I will have a look at it.
Last updated: Apr 12 2022 at 19:14 UTC