Skip to content

Add Conditional Custom eCR FhirValidator Configuration#1047

Draft
Chris0296 wants to merge 1 commit into
mainfrom
cor-validate-config
Draft

Add Conditional Custom eCR FhirValidator Configuration#1047
Chris0296 wants to merge 1 commit into
mainfrom
cor-validate-config

Conversation

@Chris0296

Copy link
Copy Markdown
Collaborator

Part of: DBCG/aphl-vsm#604

Configuration of custom FhirValidator Bean which is conditionally loaded, based on the property cr.ecr.validate.enabled

Validator support chain loads prepopulated validation support via Npm, with the packages to load being determined by the CrSettings validatorPackages field.

This FhirValidator is marked @Primary, so when it is conditionally created - it becomes the FhirValidator in use for FHIRs $validate operation.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Formatting check succeeded!

@Chris0296 Chris0296 requested a review from c-schuler June 8, 2026 20:05
Validator support chain loads US eCR package via Npm
@Chris0296 Chris0296 force-pushed the cor-validate-config branch from 6daac71 to a78193b Compare June 16, 2026 15:32
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
16.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@c-schuler c-schuler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far. A few suggestions and we definitely need more testing. Nice work!

}

} catch (IOException e) {
logger.error("Error listing Resources from package {}", npmPackage.id(), e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NpmRepository.ensurePackagesLoaded() catches all exceptions and leaves loadedPackages as an empty list. Then loadPrePopulatedValidationSupport catches IOException per package and continues. Then addResource catches all exceptions per resource (line 108).

So if hl7.fhir.us.ecr#2.1.2 isn't in the local ~/.fhir cache and can't be downloaded, getLoadedPackages() returns empty, prePopulatedValidationSupport is empty. However, the @primary FhirValidator is still created and installed, replacing the default. Combined with setValidateAgainstStandardSchema(false) / setValidateAgainstStandardSchematron(false), $validate then runs with effectively no profile support and silently stops doing meaningful validation for the lifetime of the server, with only a warning in the log. For a feature whose entire purpose is validation, "fail open and quiet" is probably the wrong default. Consider failing bean creation (or at least surfacing a hard error) when the configured packages don't load.

public FhirInstanceValidator crEcrFhirInstanceValidator(
FhirContext fhirContext, DaoRegistry daoRegistry, CrSettings crSettings) {
NpmRepository npmRepository = new NpmRepository(fhirContext, crSettings.getValidatorPackages());
PrePopulatedValidationSupport prePopulatedValidationSupport = loadPrePopulatedValidationSupport(npmRepository);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call chain: loadPrePopulatedValidationSupport then npmRepository.getLoadedPackages() at bean-construction time is problematic. FilesystemPackageCacheManager.loadPackage will attempt a network fetch from the package server when the package isn't cached, and then every StructureDefinition/ValueSet/CodeSystem in every transitive package is parsed into memory (all synchronously on the bean-init thread). This blocks application startup and can hang on a slow/unavailable package server. Worth at least documenting the pre-warm requirement, and ideally moving the load off the startup critical path.

.withEvaluationSettings(evaluationSettings)
.withTerminologyServerClientSettings(terminologyServerClientSettings);
.withTerminologyServerClientSettings(terminologyServerClientSettings)
.withValidatorPackage(new String[] {"hl7.fhir.us.ecr", "2.1.2"});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR says packages "are determined by the CrSettings validatorPackages field," but the field is populated with a hardcoded id/version, not from any property. The only knob is the on/off flag, not which packages.

Just flagging this for now. I understand this will likely be addressed once the PR is ready for a final review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants