gpt4 book ai didi

FHIR 数据模型的 Java REST 客户端

转载 作者:行者123 更新时间:2023-12-02 11:11:03 27 4
gpt4 key购买 nike

有人可以举一个 Java REST 客户端使用 FHIR 数据模型搜索患者的示例吗?

最佳答案

FHIR HAPI Java API是一个简单的 RESTful 客户端 API,可与 FHIR 服务器配合使用。

这是一个简单的代码示例,用于搜索给定服务器上的所有患者,然后打印出他们的姓名。

 // Create a client (only needed once)
FhirContext ctx = new FhirContext();
IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/base");

// Invoke the client
Bundle bundle = client.search()
.forResource(Patient.class)
.execute();

System.out.println("patients count=" + bundle.size());
List<Patient> list = bundle.getResources(Patient.class);
for (Patient p : list) {
System.out.println("name=" + p.getName());
}

调用上面的 execute() 方法会调用对目标服务器的 RESTful HTTP 调用,并将响应解码为 Java 对象。

客户端抽象出用于检索资源的 XML 或 JSON 的底层传输格式。在客户端构造中添加一行会将传输从 XML 更改为 JSON。

 Bundle bundle = client.search()
.forResource(Patient.class)
.encodedJson() // this one line changes the encoding from XML to JSON
.execute();

这是一个example您可以在其中限制搜索查询:

Bundle response = client.search()
.forResource(Patient.class)
.where(Patient.BIRTHDATE.beforeOrEquals().day("2011-01-01"))
.and(Patient.PROVIDER.hasChainedProperty(Organization.NAME.matches().value("Health")))
.execute();

同样,您可以使用 HL7 FHIR website 中的 DSTU Java 引用库其中包括模型 API 和 FhirJavaReferenceClient。

关于FHIR 数据模型的 Java REST 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24911293/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com