-
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 4 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
123 changes: 123 additions & 0 deletions
123
...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,123 @@ | ||
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.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class CustomValueSetExpandTest extends BaseResourceProviderR4Test { | ||
|
||
@Autowired | ||
private FhirContext myFhirCtx; | ||
|
||
@Test | ||
public void testExpandAndPrint() throws Exception { | ||
// 1. 使用低階 API 直接載入 ICD-10-CM CodeSystem (改為2023版本) | ||
edwardlo12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
TermLoaderSvcImpl termLoaderSvc = new TermLoaderSvcImpl(myTerminologyDeferredStorageSvc, myTermCodeSystemStorageSvc); | ||
|
||
// 載入2023版本的ICD-10-CM檔案 | ||
String filename = "icd10cm-tabular-2023.xml"; // 使用你的2023版本檔案 | ||
|
||
String resource = ClasspathUtil.loadResource(filename); | ||
List<ITermLoaderSvc.FileDescriptor> descriptors = new ArrayList<>(); | ||
descriptors.add(new ITermLoaderSvc.ByteArrayFileDescriptor(filename, resource.getBytes(StandardCharsets.UTF_8))); | ||
|
||
// 載入ICD-10-CM | ||
termLoaderSvc.loadIcd10cm(descriptors, new SystemRequestDetails()); | ||
myTerminologyDeferredStorageSvc.saveAllDeferred(); | ||
|
||
// 驗證載入成功 | ||
runInTransaction(() -> { | ||
TermCodeSystem codeSystem = myTermCodeSystemDao.findByCodeSystemUri(ITermLoaderSvc.ICD10CM_URI); | ||
System.out.println("載入的 ICD-10-CM 版本: " + codeSystem.getCurrentVersion().getCodeSystemVersionId()); | ||
System.out.println("載入的概念數量: " + myTermConceptDao.count()); | ||
}); | ||
|
||
// 等待CodeSystem處理完成 - 大型術語系統需要時間索引 | ||
// System.out.println("等待CodeSystem處理完成..."); | ||
// Thread.sleep(10000); // 等待10秒讓系統處理上傳的數據 | ||
|
||
// 2. 讀入並建立 ValueSet | ||
String vsJson = ClasspathUtil.loadResource("/my-valueset.json"); | ||
ValueSet vs = myFhirCtx.newJsonParser().parseResource(ValueSet.class, vsJson); | ||
|
||
// 檢查 ValueSet 的構成 | ||
System.out.println("ValueSet URL: " + vs.getUrl()); | ||
edwardlo12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
System.out.println("ValueSet compose includes:"); | ||
vs.getCompose().getInclude().forEach(include -> { | ||
System.out.println(" System: " + include.getSystem() + " Version: " + include.getVersion()); | ||
if (include.hasFilter()) { | ||
include.getFilter().forEach(filter -> { | ||
System.out.println(" Filter: " + filter.getProperty() + " " + filter.getOp() + " " + filter.getValue()); | ||
}); | ||
} | ||
include.getConcept().forEach(concept -> { | ||
System.out.println(" Code: " + concept.getCode() + " Display: " + concept.getDisplay()); | ||
}); | ||
}); | ||
|
||
myClient.create().resource(vs).execute(); | ||
|
||
// 3. 組裝輸入的 Parameters 並呼叫 $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 { | ||
System.out.println("嘗試第 " + (currentRetry + 1) + " 次展開ValueSet..."); | ||
expanded = myClient | ||
.operation() | ||
.onType(ValueSet.class) | ||
.named("$expand") | ||
.withParameters(inParams) | ||
.returnResourceType(ValueSet.class) | ||
.execute(); | ||
System.out.println("ValueSet展開成功!"); | ||
} catch (Exception e) { | ||
currentRetry++; | ||
System.out.println("展開失敗 (第 " + currentRetry + " 次嘗試): " + e.getMessage()); | ||
if (currentRetry < maxRetries) { | ||
System.out.println("等待5秒後重試..."); | ||
Thread.sleep(5000); | ||
} else { | ||
System.out.println("所有重試都失敗,拋出異常"); | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
// 4. 印出所有 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 |
||
System.out.println( | ||
"system=" + c.getSystem() + | ||
" code=" + c.getCode() + | ||
" display=" + c.getDisplay()); | ||
}); | ||
|
||
System.out.println("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