Skip to content

Conversation

@fil512
Copy link
Collaborator

@fil512 fil512 commented Nov 19, 2025

This MR adds a new configuration setting that allows database-stored terminology resources (CodeSystem, ValueSet) to take precedence over built-in default profile validation resources during validation. This addresses scenarios where users need to store custom CodeSystems that override HL7 defaults.

  1. Added new JpaStorageSettings.setAllowDatabaseValidationOverride(boolean) setting that controls the order of validation support modules in the chain
  2. Modified JpaValidationSupportChain.postConstruct() to conditionally reorder the JPA validation support before or after the default profile validation support based on the new setting

Code Review Suggestions

  • Verify that changing the validation support chain order does not have unintended side effects on other validation scenarios beyond the case-sensitivity use case
  • Consider whether the setting name allowDatabaseValidationOverride clearly conveys what it does - it specifically changes the order of validation support modules rather than a broad override mechanism
  • Check if there are other places in the codebase that assume a specific order of validation support modules in the chain

QA Test Suggestions

Setup

  1. Deploy a HAPI FHIR JPA server with the new code
  2. Ensure the server has access to create and manage CodeSystem and ValueSet resources
  3. Prepare a test CodeSystem that uses the same URL as a built-in HL7 CodeSystem (e.g., http://terminology.hl7.org/CodeSystem/insurance-plan-type)

Test Cases

(See original bug report for reproduction steps)

  • Default behavior (setting disabled): Create a CodeSystem with the same URL as a built-in HL7 CodeSystem but with different case sensitivity. Verify that ValueSet expansion uses the built-in definition's case sensitivity, not the database version.

  • Override enabled: Enable allowDatabaseValidationOverride=true, create a case-sensitive CodeSystem with codes that differ only by case (e.g., "drug" and "Drug"). Verify that ValueSet expansion includes both case variants when the database CodeSystem takes precedence.

  • Validation behavior: With the override enabled, validate a resource against a ValueSet that references the overridden CodeSystem. Verify that validation uses the database CodeSystem's properties.

  • Setting change at runtime: If the setting is changed after server startup, verify behavior is consistent (note: may require server restart or cache invalidation).

  • FRAGMENT content mode: Test specifically with CodeSystems using FRAGMENT content mode, as this is the scenario where users need to supplement built-in definitions with additional codes.

@fil512 fil512 linked an issue Nov 19, 2025 that may be closed by this pull request
@robogary
Copy link
Contributor

robogary commented Nov 19, 2025

Formatting check succeeded!

Ken Stevens and others added 16 commits November 19, 2025 18:38
…matching

Updated testExpandValueSet_CaseSensitiveCodeSystem_CodesWithDifferentCase to use
FRAGMENT content mode and include entire system instead of enumerating specific
concepts. This ensures the test exercises the Hibernate Search code path where
the case-sensitivity bug manifests, providing proper TDD validation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…ontent

When a user persists a CodeSystem that overrides a built-in HL7 CodeSystem,
the JPA-persisted version should take precedence over the built-in default.
This is critical for case-sensitive CodeSystems where codes differ only by
case (e.g., "drug" vs "Drug").

The fix:
- Add removeCodeSystem/removeValueSet methods to DefaultProfileValidationSupport
  to selectively remove URLs from the in-memory cache
- At startup, scan JPA for persisted CodeSystem/ValueSet URLs and remove them
  from the default profile cache so JPA versions take precedence
- When a CodeSystem or ValueSet is created/updated, remove its URL from the
  default profile cache and invalidate validation caches
- Fix lazy initialization issue where removal was silently ignored if the
  terminology maps hadn't been initialized yet
- Add null checks for delete operations where the resource may be null

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Adds changelog documenting the new JpaStorageSettings.setAllowDatabaseValidationOverride()
setting which allows database-stored CodeSystem and ValueSet resources to take
precedence over built-in default profile validation resources.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Documents the new JpaStorageSettings.setAllowDatabaseValidationOverride(boolean)
setting in the validation support modules documentation, explaining how it can
be used to give database-stored terminology resources precedence over built-in
HL7 definitions during validation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.80%. Comparing base (75a2a6b) to head (67c7e07).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7395   +/-   ##
=========================================
  Coverage     83.80%   83.80%           
- Complexity    30194    30200    +6     
=========================================
  Files          1833     1833           
  Lines        116644   116656   +12     
  Branches      14816    14817    +1     
=========================================
+ Hits          97752    97768   +16     
+ Misses        12594    12591    -3     
+ Partials       6298     6297    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@jmarchionatto jmarchionatto left a comment

Choose a reason for hiding this comment

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

Looks good! Approved with a question

type: add
issue: 7394
title: "A new setting JpaStorageSettings.setAllowDatabaseValidationOverride(boolean) has been added.
When enabled, database-stored CodeSystem and ValueSet resources take precedence over built-in
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the precedence only for validation purposes or any request?
If it is only for validation, it could be indicated here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch!

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.

ValueSet code case-sensitivity

4 participants