如何使用 FHIR PATH 获取患者的免疫列表?

问题描述 投票:0回答:1

目前,我正在使用以下代码获取患者的免疫资源列表。这是从 FHIR 服务器获取数据的有效方法吗?在这种情况下如何使用 FHIRPATH?

        // Create a client
        IGenericClient client = ctx.newRestfulGenericClient("https://hapi.fhir.org/baseR4");

        // Read a patient with the given ID
        Patient patient = client.read().resource(Patient.class).withId(patientId).execute();

        String id = patient.getId();

        List<IBaseResource> immunizations = new ArrayList<IBaseResource>();
        Bundle bundle = client.search().forResource(Immunization.class).where(Immunization.PATIENT.hasId(id))
                .returnBundle(Bundle.class).execute();
        immunizations.addAll(BundleUtil.toListOfResources(ctx, bundle));

        // Load the subsequent pages
        while (bundle.getLink(IBaseBundle.LINK_NEXT) != null) {
            bundle = client.loadPage().next(bundle).execute();
            immunizations.addAll(BundleUtil.toListOfResources(ctx, bundle));
        }

        String fhirResource = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
java hl7-fhir hapi-fhir smart-on-fhir
1个回答
0
投票

这段代码对我来说看起来很有效,是的。

由于您要为患者卸载整套免疫接种,我会注意页面大小。由于默认情况下,FHIR RESTful 服务器不会分页(请参阅HAPI FHIR 有关分页搜索的官方文档),因此您最好根据数据集显式微调计数大小,以避免不必要的服务器往返尽可能多,另一方面,避免由于巨大的响应包而超时。

您可以像这样指定计数大小:

Bundle bundle = client.search()
                          .forResource(Immunization.class)
                          .where(Immunization.PATIENT.hasId(id))
                          .returnBundle(Bundle.class)
                          .count(200)
                          .execute();

请注意,FHIR 服务器可能不支持分页,因此您也应该考虑到这一点。

现在,关于 FHIRPath:我不确定您到底是如何想象在这种情况下使用它的,但是以任何可以想象的方式(例如,获取该患者的整套资源,无论资源类型如何,并执行 FHIRPath 操作在这个捆绑包上?),它的性能会比您提供的代码低得多。如果您想知道如何编写,FHIRPath 表达式的示例将查看各种资源捆绑并返回免疫资源,如下所示:

entry.resource.where(resourceType='Immunization')

顺便说一句,如果您正在寻求额外的性能提升,总是可以选择开发自定义查询(请参阅HAPI FHIR 有关命名查询的官方文档),但这需要在服务器上进行开发。

© www.soinside.com 2019 - 2024. All rights reserved.