FHIR Chat · Custom resources with JPA starter · hapi

Stream: hapi

Topic: Custom resources with JPA starter


view this post on Zulip David Young (Oct 28 2021 at 17:39):

Hi all,

I'm currently working on a PoC with the JPA starter, but I can't seem to figure out the necessary pieces to get everything fully wired together.

What I have:

Customizations added in JpaRestfulServer.java:

BaseHapiFhirResourceDao<FavouriteCookie> myDao = new JpaResourceDao<>();
myDao.setResourceType(FavouriteCookie.class);
myDao.setContext(fhirSystemDao.getContext());
daoRegistry.register(myDao);

JpaResourceProviderR4<FavouriteCookie> favouriteCookieProvider = new FavouriteCookieProvider();
favouriteCookieProvider.setDao(myDao);
favouriteCookieProvider.setContext(ctx);
registerProviders(favouriteCookieProvider);

What I'm missing:

  • An example of how to get my custom resource fully connected up so I can interact with it on /fhir/FavouriteCookie
    • It recognizes that it's a resource, but I get an NPE when the search is called:
      • Caused by: java.lang.NullPointerException: null at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.search(BaseHapiFhirResourceDao.java:1398)

I'm having some trouble tracking down when/where everything is created, so I'm assuming there's some piece I'm missing. The only examples I've seen in the docs seem to implement search or ID as a newly instantiated object that's returned immediately, rather than showing anything on how to connect it up to the DB. I'm obviously missing something, but I can't see what it is.

Is anyone able to provide some guidance?

view this post on Zulip Jens Villadsen (Oct 28 2021 at 17:53):

See https://hapifhir.io/hapi-fhir/docs/model/custom_structures.html#extending-fhir-resource-classes

view this post on Zulip David Young (Oct 28 2021 at 18:44):

Sorry, I'm not sure I see the connection between that section and what I'm trying to do. I'm not looking to add an extension to an existing resource, I'm trying to create an entirely new resource.

view this post on Zulip Jens Villadsen (Oct 28 2021 at 18:46):

It more seems like you are trying to create a new resource type

view this post on Zulip David Young (Oct 28 2021 at 18:51):

Is that not the same thing as a custom resource? Admittedly, I'm pretty new to FHIR, so I may not be using the correct terminology.

view this post on Zulip Joel Schneider (Oct 30 2021 at 00:24):

Adding extensions to the Basic resource is the recommended mechanism for defining a custom data structure conformant with the FHIR spec.
http://hl7.org/fhir/basic.html

Notably,

use of 'custom' resources is NOT considered to be conformant with FHIR


Last updated: Apr 12 2022 at 19:14 UTC