FHIR Chat · How to read multiple resources by using list of resource ids · implementers

Stream: implementers

Topic: How to read multiple resources by using list of resource ids


view this post on Zulip Markku Nikkanen (Jul 20 2020 at 08:46):

Hello,

I am building pagination for a custom Encounter search method. There is a nice instruction how to do this:

https://hapifhir.io/hapi-fhir/docs/server_plain/paging.html

So far I have listed all the ids.

  private List<Long> ids() {
    Bundle bundle = client
      .search()
      .forResource(Encounter.class)
...
      .execute();

    List<IBaseResource> resources = new ArrayList<>();
    resources.addAll(BundleUtil.toListOfResources(ctx, bundle));

    List<Long> list = new ArrayList<>();
    for (IBaseResource e : resources) {
      list.add(e.getIdElement().getIdPartAsLong());
    }

    return list;
}

Next step would be to get list of Encounters using:

private List<IBaseResource> loadResourcesByIds(List<Long> theIdsToReturn) {
// TODO: how to get Encounters by list of ids?
}

You can get single Encounter by id:

Encounter e = client.read().resource(Encounter.class).withId(id).execute();

Running above query in a loop does not feel as a correct implementation. Read operation does not support reading multiple Encounters using list of ids, I think. Should I use "where" operation?

    Bundle bundle = client
      .search()
      .forResource(Encounter.class)
      .where(<what should I place here?)
      .execute();

    List<IBaseResource> encounters = new ArrayList<>();
    encounters.addAll(BundleUtil.toListOfResources(ctx, bundle));

view this post on Zulip Yunwei Wang (Jul 20 2020 at 13:56):

Search returns a bundle of resources. Why do you want to get the id of returned resources and read from server again? did I miss something herer?

view this post on Zulip Markku Nikkanen (Jul 20 2020 at 17:03):

Yunwei Wang

I think you missed something. In Bundle search I must return Encounters (with ref resources, thats why Bundle). Problem is that I do not know how do I formulate "where" operation so that it matches list of Encounter IDs.

    Bundle bundle = client
      .search()
      .forResource(Encounter.class)
      .where(<what should I place here?)
      .execute();

view this post on Zulip ryan moehrke (Jul 20 2020 at 17:38):

I'm not sure what you're asking for still, but [baseUrl]/Encounter?_id=id1,id2,id3 should return a searchset bundle including the three Encounters whose ids are listed.

view this post on Zulip Yunwei Wang (Jul 20 2020 at 17:45):

Sorry, I still don't get it. In your first code block, you received a bundle of Encounter and returns a list of Encounter Ids. And in your second code block, you are trying to read Encounter using the Encounter Ids returned from first code block. Is that correct? My question is if so, why not just return Encounters from the first block?

view this post on Zulip Markku Nikkanen (Jul 21 2020 at 05:42):

Yunwei Wang
Because I am building pagination see: https://hapifhir.io/hapi-fhir/docs/server_plain/paging.html


Last updated: Apr 12 2022 at 19:14 UTC