0

我正在尝试获取分页包中的所有条目。

工作代码如下:

Bundle bundle = fhirClient.search()
            .forResource(...)
            .where(...)
            .returnBundle(Bundle.class)
            .execute();

    if (bundle == null){
        return null;
    }

    // Keep adding entries until the last page
    Bundle tempBundle = fhirClient.loadPage().next(bundle).execute();

    // Put all the new entries into a separated list so that we do not modify the iterator
    List<Bundle.Entry> entries = new ArrayList<>();

    while(tempBundle != null){
        entries.addAll(tempBundle.getEntry());
        if(tempBundle.getLink(Bundle.LINK_NEXT) != null) {
            tempBundle = fhirClient.loadPage().next(tempBundle).execute();
        }
        else{
            tempBundle = null;
        }
    }

    entries.forEach(bundle::addEntry);

    return bundle;

但是,我在 while 循环中做了这样的事情,它最终会进入无限循环:

while(tempBundle != null){
    entries.addAll(tempBundle.getEntry());
    tempBundle = fhirClient.loadPage().next(tempBundle).execute();
}

我期待 tempBundle 对于没有下一页的捆绑包以 null 结束,但它永远不会发生。任何想法?

4

1 回答 1

1

你可能想看看这个例子: BundleFetcher.java

尤其是您使用以下页面填充结果的部分:

while (bundle.getLink(IBaseBundle.LINK_NEXT) != null) {
        bundle = client
            .loadPage()
            .next(bundle)
            .execute();
patients.addAll(BundleUtil.toListOfResources(ctx, bundle));
    }

我认为你的代码中有问题的部分是

// Keep adding entries until the last page
Bundle tempBundle = fhirClient.loadPage().next(bundle).execute();
于 2020-07-03T06:50:21.817 回答