【发布时间】:2014-07-23 13:05:43
【问题描述】:
谁能举个例子让 Java REST 客户端使用 FHIR 数据模型搜索患者?
【问题讨论】:
谁能举个例子让 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。
【讨论】: