problem with DefaultProfileValidationSupportNpmStrategy

72 views
Skip to first unread message

jim....@csiro.au

unread,
Jun 16, 2023, 2:39:10 AM6/16/23
to HAPI FHIR

Hi,

I'm using DefaultProfileValidationSupportNpmStrategy, but all of the StructureDefinitions that are being loaded in from core are coming in with sourcePackage = null, which means that my validation is failing (because the StructureDefinitions I'm using are referencing them in StructureDefinition.type, and they're failing SD_TYPE_NOT_LOCAL with a message like "The type ValueSet is not legal because it is not defined in the FHIR specification. Other types must have a namespace on them"

Has anyone else run across this?

Is there something i'm doing wrong with the way I'm building my validation support chain or something?

(cross posting here from chat.fhir.org in case this is more actively monitored)

Jim.

jim....@csiro.au

unread,
Jun 18, 2023, 7:32:18 PM6/18/23
to HAPI FHIR
Oh, I should clarify, this is only causing problems with R5.

jim....@csiro.au

unread,
Jun 26, 2023, 2:23:57 AM6/26/23
to HAPI FHIR
At the risk of just talking to myself on this one...

I think I've fixed this with some code like this in NpmPackageValidationSupport.loadResourcesFromPackage():

private void loadResourcesFromPackage(NpmPackage thePackage) {
NpmPackage.NpmPackageFolder packageFolder = thePackage.getFolders().get("package");

for (String nextFile : packageFolder.listFiles()) {
if (nextFile.toLowerCase(Locale.US).endsWith(".json")) {
String input = new String(packageFolder.getContent().get(nextFile), StandardCharsets.UTF_8);
IParser parser = getFhirContext().newJsonParser();
parser.setParserErrorHandler(new LenientErrorHandler(false));
IBaseResource resource = parser.parseResource(input);
if (resource instanceof org.hl7.fhir.r5.model.Resource) {
final org.hl7.fhir.r5.model.Resource res = (org.hl7.fhir.r5.model.Resource) resource;
if (!res.hasSourcePackage()) {
res.setSourcePackage(new org.hl7.fhir.r5.model.PackageInformation(thePackage));
}
}
super.addResource(resource);
}
}
}

This is probably horrible since it builds a dependency on R5, but I could refactor it to use reflection is that is cleaner.

Before looking at a PR though, is this a crazy thing to be doing? It seems like a pretty big oversight, since by my reckoning R5 StructureDefinitions can't be validated without a fix like this...

Jim.
Reply all
Reply to author
Forward
0 new messages