Java REST クライアントが FHIR データ モデルを使用して患者を検索する例を教えてください。
5767 次
1 に答える
4
FHIR HAPI Java APIは、FHIR サーバーで動作する単純な RESTful クライアント API です。
特定のサーバーですべての患者を検索し、患者の名前を出力する簡単なコード例を次に示します。
// 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 の基になるワイヤ形式を抽象化します。クライアントの構成に 1 行追加すると、トランスポートが XML から JSON に変更されます。
Bundle bundle = client.search()
.forResource(Patient.class)
.encodedJson() // this one line changes the encoding from XML to JSON
.execute();
検索クエリを制限できる例を次に示します。
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();
同様に、モデル API と FhirJavaReferenceClient を含むHL7 FHIR Web サイトの DSTU Java 参照ライブラリを使用できます。
于 2014-11-24T03:05:07.447 に答える