-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add support for ValueSet.FilterOperator.EQUAL #7012
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
edwardlo12
wants to merge
7
commits into
hapifhir:master
Choose a base branch
from
ITRI-BDL-D:Add-support-for-ValueSet.FilterOperator.EQUAL
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2cede49
Add support for ValueSet.FilterOperator.EQUAL
edwardlo12 4582d54
Add ValueSet for Esophageal Metal Stent Placement
edwardlo12 7e9af77
Merge branch 'hapifhir:master' into Add-support-for-ValueSet.FilterOp…
edwardlo12 1d8dd86
修正格式:調整條件判斷語句的空格以符合代碼風格
edwardlo12 e36b5ee
Translate comments to English to improve readability
edwardlo12 9bf090b
Use logging instead of System.out.println to improve debugging inform…
edwardlo12 569e067
Adjust the log level from debug to info to improve the readability an…
edwardlo12 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
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
124 changes: 124 additions & 0 deletions
124
...jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/CustomValueSetExpandTest.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,124 @@ | ||
package ca.uhn.fhir.jpa.provider.r4; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemDao; | ||
import ca.uhn.fhir.jpa.dao.data.ITermConceptDao; | ||
import ca.uhn.fhir.jpa.entity.TermCodeSystem; | ||
import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test; | ||
import ca.uhn.fhir.jpa.term.TermLoaderSvcImpl; | ||
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; | ||
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc; | ||
import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc; | ||
import ca.uhn.fhir.rest.api.server.SystemRequestDetails; | ||
import ca.uhn.fhir.util.ClasspathUtil; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hl7.fhir.r4.model.Attachment; | ||
import org.hl7.fhir.r4.model.CodeSystem; | ||
import org.hl7.fhir.r4.model.Parameters; | ||
import org.hl7.fhir.r4.model.UriType; | ||
import org.hl7.fhir.r4.model.ValueSet; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class CustomValueSetExpandTest extends BaseResourceProviderR4Test { | ||
|
||
private static final Logger ourLog = LoggerFactory.getLogger(DiffProviderR4Test.class); | ||
|
||
@Autowired | ||
private FhirContext myFhirCtx; | ||
|
||
@Test | ||
public void testExpandAndPrint() throws Exception { | ||
// 1. Use low-level API to directly load ICD-10-CM CodeSystem (changed to 2023 version) | ||
TermLoaderSvcImpl termLoaderSvc = new TermLoaderSvcImpl(myTerminologyDeferredStorageSvc, myTermCodeSystemStorageSvc); | ||
|
||
// Load 2023 version of ICD-10-CM file | ||
String filename = "icd10cm-tabular-2023.xml"; // Use your 2023 version file | ||
|
||
String resource = ClasspathUtil.loadResource(filename); | ||
List<ITermLoaderSvc.FileDescriptor> descriptors = new ArrayList<>(); | ||
descriptors.add(new ITermLoaderSvc.ByteArrayFileDescriptor(filename, resource.getBytes(StandardCharsets.UTF_8))); | ||
|
||
// Load ICD-10-CM | ||
termLoaderSvc.loadIcd10cm(descriptors, new SystemRequestDetails()); | ||
myTerminologyDeferredStorageSvc.saveAllDeferred(); | ||
|
||
// Verify loading success | ||
runInTransaction(() -> { | ||
TermCodeSystem codeSystem = myTermCodeSystemDao.findByCodeSystemUri(ITermLoaderSvc.ICD10CM_URI); | ||
ourLog.info("Loaded ICD-10-CM Version: " + codeSystem.getCurrentVersion().getCodeSystemVersionId()); | ||
ourLog.info("Loaded concept count: " + myTermConceptDao.count()); | ||
}); | ||
|
||
|
||
// 2. Read and create ValueSet | ||
String vsJson = ClasspathUtil.loadResource("/my-valueset.json"); | ||
ValueSet vs = myFhirCtx.newJsonParser().parseResource(ValueSet.class, vsJson); | ||
|
||
// Check ValueSet composition | ||
ourLog.info("ValueSet URL: " + vs.getUrl()); | ||
ourLog.info("ValueSet compose includes:"); | ||
vs.getCompose().getInclude().forEach(include -> { | ||
ourLog.info(" System: " + include.getSystem() + " Version: " + include.getVersion()); | ||
if (include.hasFilter()) { | ||
include.getFilter().forEach(filter -> { | ||
ourLog.info(" Filter: " + filter.getProperty() + " " + filter.getOp() + " " + filter.getValue()); | ||
}); | ||
} | ||
include.getConcept().forEach(concept -> { | ||
ourLog.info(" Code: " + concept.getCode() + " Display: " + concept.getDisplay()); | ||
}); | ||
}); | ||
|
||
myClient.create().resource(vs).execute(); | ||
|
||
// 3. Assemble input Parameters and call $expand | ||
Parameters inParams = new Parameters(); | ||
inParams.addParameter().setName("url").setValue(vs.getUrlElement()); | ||
|
||
ValueSet expanded = null; | ||
int maxRetries = 3; | ||
int currentRetry = 0; | ||
|
||
while (expanded == null && currentRetry < maxRetries) { | ||
try { | ||
ourLog.info("Attempting to expand ValueSet (attempt " + (currentRetry + 1) + ")..."); | ||
expanded = myClient | ||
.operation() | ||
.onType(ValueSet.class) | ||
.named("$expand") | ||
.withParameters(inParams) | ||
.returnResourceType(ValueSet.class) | ||
.execute(); | ||
ourLog.info("ValueSet expansion successful!"); | ||
} catch (Exception e) { | ||
currentRetry++; | ||
ourLog.info("Expansion failed (attempt " + currentRetry + "): " + e.getMessage()); | ||
if (currentRetry < maxRetries) { | ||
ourLog.info("Waiting 5 seconds before retry..."); | ||
Thread.sleep(5000); | ||
} else { | ||
ourLog.error("All retries failed, throwing exception"); | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
// 4. Print all contains | ||
expanded.getExpansion().getContains().forEach(c -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing assert |
||
ourLog.info( | ||
"system=" + c.getSystem() + | ||
" code=" + c.getCode() + | ||
" display=" + c.getDisplay()); | ||
}); | ||
|
||
ourLog.info("Expansion successful! Found " + expanded.getExpansion().getContains().size() + " concepts."); | ||
|
||
} | ||
} |
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.
this doesn't look right