我正在遍历像这样的资源类型的所有实体。
while (query.getLink(IBaseBundle.LINK_NEXT) != null) {
query.getLink("next").setUrl(FhirUtils.replaceBaseUrl(query.getLink("next").getUrl, fhirClient.getServerBase))
query = fhirClient.loadPage().next(query).execute()
resources.addAll(getResourcesFromBundle(query))
}
我遇到的问题是响应中的实体(例如标本)将不包含字段
display
,它将是null
。该字段由我在实施指南中定义的代码系统设置,具体取决于code
值。仅供参考,我附上了样本资源示例的屏幕截图。
如果这样执行查询(使用
search()
):
fhirClient.search().forResource(request.
类型).returnBundle(classOf[Bundle]).execute()
display
字段将出现。
有没有人知道可能的解决方案或为什么会这样?
display 属性并不总是保证存在于所有 FHIR 资源中。它是一个可选属性,可能会或可能不会被填充,具体取决于资源类型和服务器实现。
如果显示属性不存在于资源中,您可以使用其他属性,例如code(如果存在)来识别和描述资源,或者至少确保您的代码可以处理显示不存在时的场景,例如
for (Resource resource : getResourcesFromBundle(query)) {
if (resource instanceof CodeableConcept) {
CodeableConcept concept = (CodeableConcept) resource;
String display = concept.getText();
if (display != null) {
// Do something with the display property
} else {
// Handle case where display property is missing
}
}
}
我最终做的是从 hapi-fhir 创建我自己的拦截器 ResponseTerminologyDisplayPopulationInterceptor。我对它进行了一些定制,也可以根据
GET_PAGE
类型的请求工作。成功了。现在 display
字段返回请求像这样。 http://localhost:8080/fhir?_getpages=...