Stream: hapi
Topic: Custom resources with JPA starter
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:
- I've created the resource class
FavouriteCookie
and have registered it withcontext.registerCustomTypes(...)
- I followed the example here: https://hapifhir.io/hapi-fhir/docs/model/custom_structures.html#custom-resource-structure
- I've created
FavouriteCookieProvider
(patterned afterPatientResourceProvider
) and have tried to connect it up (example below)
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)
- It recognizes that it's a resource, but I get an NPE when the search is called:
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?
Jens Villadsen (Oct 28 2021 at 17:53):
See https://hapifhir.io/hapi-fhir/docs/model/custom_structures.html#extending-fhir-resource-classes
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.
Jens Villadsen (Oct 28 2021 at 18:46):
It more seems like you are trying to create a new resource type
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.
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