2

I was just wondering if there is a way to access a resource within a bundle.

I.E

        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();

diag is currently what is causing issues. Since I have a client access their report via ID that is generated (thus the bundle search command) but to access all the other resources that are referenced by diagnosticReport I can't find a way to either separate the resource from the bundle or directly grab from the bundle.

Thank you

Lloyd McKenzie
  • 6,345
  • 1
  • 13
  • 10
Georgrio
  • 91
  • 2
  • 14

1 Answers1

3

If you just want to grab the DiagnosticReport resource from the bundle you should be able to do something like:

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

If you wanted, you could also use includes to return the other linked resources in a single call to the server:

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();
Georgrio
  • 91
  • 2
  • 14
James Agnew
  • 701
  • 4
  • 3