我正在尝试获取分页包中的所有条目。
工作代码如下:
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 结束,但它永远不会发生。任何想法?