-
Notifications
You must be signed in to change notification settings - Fork 1.4k
ValueSet code case sensitivity #7395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fil512
wants to merge
19
commits into
master
Choose a base branch
from
7394-valueset-code-case-sensitivity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b2a90bb
fix with test
45af0fa
Add changelog entry for ValueSet case-sensitive code fix
ab487ef
Fix ValueSet expansion test to properly validate case-sensitive code …
99cbe67
merge master
3d42e44
fix with test
d65e81d
merge master
74e7d18
merge master
33ccfb9
fix with test
9d79889
Fix ValueSet expansion for case-sensitive CodeSystems with FRAGMENT c…
6f86120
fix test
c2cf715
back out first change
892e24e
back out first change
fcbe49c
add fix discussed with James
50738b8
Add changelog entry for database validation override setting
271bfe3
fix version
378dc86
Add documentation for allowDatabaseValidationOverride setting
67c7e07
doc
578b823
spotless and review feedback
459c5b5
version bump
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.../main/resources/ca/uhn/hapi/fhir/changelog/8_8_0/7394-valueset-code-case-sensitivity.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| 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 | ||
| default profile validation resources. This allows user-defined terminology resources to override | ||
| built-in HL7 definitions." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...-test-r4/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionCaseSensitiveManualTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Created by claude-sonnet-4-5 | ||
| package ca.uhn.fhir.jpa.term; | ||
|
|
||
| import ca.uhn.fhir.context.support.IValidationSupport; | ||
| import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; | ||
| import ca.uhn.fhir.jpa.test.BaseJpaR4Test; | ||
| import ca.uhn.fhir.jpa.validation.JpaValidationSupportChain; | ||
| import org.hl7.fhir.r4.model.CodeSystem; | ||
| import org.hl7.fhir.r4.model.CodeType; | ||
| import org.hl7.fhir.r4.model.Enumerations; | ||
| import org.hl7.fhir.r4.model.ValueSet; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * This test validates that ValueSet expansion correctly handles case-sensitive | ||
| * CodeSystems where codes differ only by case (e.g., "drug" vs "Drug"). | ||
| * | ||
| * The test uses FRAGMENT content mode to reproduce the bug scenario where | ||
| * a user-defined CodeSystem should override the built-in HL7 CodeSystem. | ||
| */ | ||
| class ValueSetExpansionCaseSensitiveManualTest extends BaseJpaR4Test { | ||
|
|
||
| private static final Logger ourLog = LoggerFactory.getLogger(ValueSetExpansionCaseSensitiveManualTest.class); | ||
| @Autowired | ||
| private IValidationSupport myJpaValidationSupportChain; | ||
|
|
||
| @AfterEach | ||
| public void after() { | ||
| myStorageSettings.setAllowDatabaseValidationOverride(new JpaStorageSettings().isAllowDatabaseValidationOverride()); | ||
| ((JpaValidationSupportChain)myJpaValidationSupportChain).rebuildChainForUnitTest(); | ||
| } | ||
|
|
||
| @Test | ||
| void testValueSetExpansion_CaseSensitive_IncludeEntireSystem() { | ||
| myStorageSettings.setAllowDatabaseValidationOverride(true); | ||
| ((JpaValidationSupportChain)myJpaValidationSupportChain).rebuildChainForUnitTest(); | ||
|
|
||
| // Create case-sensitive CodeSystem with FRAGMENT content mode | ||
| CodeSystem codeSystem = new CodeSystem(); | ||
| codeSystem.setUrl("http://terminology.hl7.org/CodeSystem/insurance-plan-type"); | ||
| codeSystem.setStatus(Enumerations.PublicationStatus.ACTIVE); | ||
| codeSystem.setCaseSensitive(true); | ||
| codeSystem.setContent(CodeSystem.CodeSystemContentMode.FRAGMENT); | ||
| codeSystem.setVersion("4.0.1"); | ||
|
|
||
| // Add all the codes from the real HL7 resource | ||
| codeSystem.addConcept().setCode("medical").setDisplay("Medical"); | ||
| codeSystem.addConcept().setCode("dental").setDisplay("Dental"); | ||
| codeSystem.addConcept().setCode("mental").setDisplay("Mental Health"); | ||
| codeSystem.addConcept().setCode("subst-ab").setDisplay("Substance Abuse"); | ||
| codeSystem.addConcept().setCode("vision").setDisplay("Vision"); | ||
| codeSystem.addConcept().setCode("drug").setDisplay("Drug"); // lowercase - active | ||
| codeSystem.addConcept().setCode("short-term").setDisplay("Short Term"); | ||
| codeSystem.addConcept().setCode("long-term").setDisplay("Long Term Care"); | ||
| codeSystem.addConcept().setCode("hospice").setDisplay("Hospice"); | ||
| codeSystem.addConcept().setCode("home").setDisplay("Home Health"); | ||
|
|
||
| // Add "Drug" (uppercase D) - retired | ||
| CodeSystem.ConceptDefinitionComponent drugRetired = codeSystem.addConcept(); | ||
| drugRetired.setCode("Drug"); | ||
| drugRetired.setDisplay("Drug"); | ||
| CodeSystem.ConceptPropertyComponent statusProp = drugRetired.addProperty(); | ||
| statusProp.setCode("status"); | ||
| statusProp.setValue(new CodeType("retired")); | ||
| CodeSystem.ConceptPropertyComponent inactiveProp = drugRetired.addProperty(); | ||
| inactiveProp.setCode("inactive"); | ||
| inactiveProp.setValue(new CodeType("true")); | ||
|
|
||
| myCodeSystemDao.create(codeSystem, mySrd); | ||
| myTerminologyDeferredStorageSvc.saveAllDeferred(); | ||
|
|
||
| // Create ValueSet that includes the entire CodeSystem (NOT enumerated concepts) | ||
| ValueSet valueSet = new ValueSet(); | ||
| valueSet.setUrl("http://terminology.hl7.org/ValueSet/insuranceplan-type"); | ||
| valueSet.setStatus(Enumerations.PublicationStatus.ACTIVE); | ||
|
|
||
| ValueSet.ConceptSetComponent include = valueSet.getCompose().addInclude(); | ||
| include.setSystem("http://terminology.hl7.org/CodeSystem/insurance-plan-type"); | ||
| // CRITICAL: Do NOT enumerate specific concepts - include entire system | ||
|
|
||
| myValueSetDao.create(valueSet, mySrd); | ||
|
|
||
| // Act: Expand the ValueSet | ||
| ValueSet expanded = myTermSvc.expandValueSet(null, valueSet); | ||
|
|
||
| // Assert: Both case variants should be present | ||
| List<String> codes = expanded.getExpansion().getContains().stream() | ||
| .map(ValueSet.ValueSetExpansionContainsComponent::getCode) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| ourLog.info("Expanded ValueSet contains {} codes: {}", codes.size(), codes); | ||
|
|
||
| assertThat(codes) | ||
| .as("ValueSet expansion should include both case variants") | ||
| .contains("Drug", "drug"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!