Stream: hapi
Topic: Overriding providers in the JPA server
Jim Steel (Nov 07 2016 at 02:18):
I'm looking to override a Resource Provider in a HAPI JPA server (customising search, but leaving the JPA/DAO storage backing intact). Is this possible/how do I do this? I've tried defining a new ResourceProvider that delegates to the original tinder-generated DAO-backed provider, but I end up with NPEs because of non-existent DAOs
James Agnew (Nov 07 2016 at 02:59):
We've done this a fair bit internally actually.. Easiest way is to subclass the tinder-generated RP and add your own stuff to it.
One way or the other, it should work though. What kind of NPEs are you getting? Are you still using Spring to create the instance of your new RP?
Jim Steel (Nov 07 2016 at 03:12):
Initially I tried that, but I had problems with it "No qualifying bean of type [ca.uhn.fhir.jpa.demo.provider.MedicationResourceProvider] is defined"
Jim Steel (Nov 07 2016 at 03:12):
so I had reverted to just instantiating it (which could be causing more problems that it solves)
James Agnew (Nov 07 2016 at 03:26):
Now that think about it, it's the DAOs that are more important to create with Spring. The RPs only have one dependency: the corresponding DAO.
Were you actually passing a reference to the DAO to your manually created RP? If so, what is the stacktrace of the error?
Jim Steel (Nov 07 2016 at 03:27):
No.
James Agnew (Nov 07 2016 at 03:28):
Oh yeah it definitely won't work without that.. Just grab it from the spring context and pass it in
Jim Steel (Nov 07 2016 at 03:28):
I tried 2 things. 1: MyRP extends BaseRP, overrides search and delegates to the BaseRP.search
2: MyRP autowires BaseRP, implements search and delegates to the autowired baseRP
Jim Steel (Nov 07 2016 at 03:29):
Not surprising that the first doesn't work, now I think about it
James Agnew (Nov 07 2016 at 03:29):
#1 sounds like the approach we've used..
James Agnew (Nov 07 2016 at 03:29):
but it 100% won't work if you don't give it a dao since that's where basically every method goes
Jim Steel (Nov 07 2016 at 04:58):
Hmm, still struggling to find how to do that.
Jim Steel (Nov 07 2016 at 05:30):
Do I need to register my provider with the web.xml or something?
James Agnew (Nov 07 2016 at 11:39):
Assuming you're basing your work on the hapi-fhir-jpaserver-example
project, one way would be to do it in the RestulServer class in the initialize method, i.e. here
In there you could do a call like:
dao = myAppCtx.getBean("myPatientDaoDstu3", IFhirResourceDao.class);
Last updated: Apr 12 2022 at 19:14 UTC