2016-07-25 87 views
0

我只是想知道是否有方法來訪問捆綁中的資源。訪問捆綁中的資源HL7-FHIR

 FhirContext ctx = FhirContext.forDstu3(); 
     String baseSite= "http://fhirtest.uhn.ca/baseDstu3/"; 
     IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3"); 
     System.out.println("Connected to server"); 
Bundle bundle = client.search().forResource(DiagnosticReport.class).where(DiagnosticReport.IDENTIFIER.exactly().identifier(id)).returnBundle(Bundle.class).execute(); 

     DiagnosticReport diag =client.read().resource(DiagnosticReport.class).withId(bundle.getEntry().get(0).getResource()); 
     String finalBundle=ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(diag); 
     System.out.println(finalBundle); 
     Observation obv = client.read().resource(Observation.class).withUrl(baseSite+diag.getResult().get(0).getReference()).execute(); 
     Sequence seq = client.read().resource(Sequence.class).withUrl(baseSite+obv.getRelated().get(0).getTarget()).execute(); 

診斷目前是什麼原因造成的問題。由於我有一個客戶端通過生成的ID(因此是捆綁搜索命令)來訪問他們的報告,但是要訪問由diagnosticReport引用的所有其他資源,我無法找到一種方法來從資源中分離資源或直接抓取從捆綁。

謝謝

回答

2

如果你只是想抓住從包中DiagnosticReport資源,你應該能夠做一些事情,如:

DiagnosticReport dr = (DiagnosticReport) bundle.getEntry().get(0).getResource(); 

如果你願意,你也可以使用包括返回其他鏈接資源在服務器的單個調用中:

Bundle bundle = client.search().forResource(DiagnosticReport.class) 
    .where(new StringClientParam("_id").matches().value("117376")) 
    .include(new Include("DiagnosticReport:patient")) 
    .include(new Include("DiagnosticReport:result")) 
    .returnBundle(Bundle.class) 
    .execute(); 
+0

對於DiagnosticReport dr = bundle.getEntry()。get(0).getResource();我收到一個錯誤,說明資源無法轉換爲DiagnosticReport – Georgrio

+0

已修復,只需將Cast to DiagnosticReport添加 – Georgrio