FHIR数据模型的Java REST客户端

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

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

java rest hl7 hl7-fhir
1个回答
4
投票

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。

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