I have task of implementing a fhir jpa server from within the radiology module. Here is the tutorial I’m using http://hapifhir.io/doc_jpa.html. It uses this example https://github.com/jamesagnew/hapi-fhir/tree/master/hapi-fhir-jpaserver-example. Following the tutorial and the example code I was able to create a fhir server from scratch as a separate web app(i.e not with radiology). Here is my code https://github.com/ivange94/fhir-example-server. It has it’s database configurations in this file https://github.com/ivange94/fhir-example-server/blob/master/src/main/java/com/ivange94/fhir/demo/FhirServerConfig.java. And inside the web.xml it references that config file https://github.com/ivange94/fhir-example-server/blob/master/src/main/webapp/WEB-INF/web.xml
How can I do something similar from within the radiology module and still deploy it to openmrs. It configures it’s own application context inside the web.xml. Also I need to declare some servlets(spring dispatcher and fhir servlet) with their own mappings. OpenMRS modules don’t have a web.xml file. How can I achieve this?
It would be nice if the FHIR module could be extended to support other modules (like this one), so modules could leverage a growing & increasingly robust FHIR base and focus on their needs.
/cc @harsha89 @surangak
@ivange94, this wiki page describes how to define a module in a servlet: https://wiki.openmrs.org/x/RRAz (@wyclif is this page still up-to-date? Does Platform 2.0 + the newer servlet spec mean we have a new preferred way for modules to define servlets?)
Though the servlet spec has a way of dynamically defining servlets, as used here: https://github.com/openmrs/openmrs-module-legacyui/blob/master/omod/src/main/java/org/openmrs/web/WebComponentRegistrar.java#L33-L39
it has a disadvantage of working only the first time OpenMRS is started. That is when you add it with any call that originated from https://github.com/openmrs/openmrs-core/blob/master/web/src/main/java/org/openmrs/web/Listener.java#L138 when the servlet context is being initialised.
Any other times, like during module restarts, it will always fail with a stack trace like below:
What the above exception means is that, it is illegal to do so after the servlet context was already initialised and started.
In summary, our custom module servlet strategy is, for now, the best and hence recommended.
@dkayiwa thanks for this summary!
I assumed that we used this new dynamic way in the legacyui module because the old Module Servlet approach was insufficient for some reason. Is there a limitation on the old way, such that sometimes you’re required to do the new way?
Oh, I see from the wiki page that the limitation of the Module Servlets is that they can’t support wildcard URIs.
(I have updated the wiki docs to also mention the alternative way Daniel shared.)
@burke Yes. We will need to brainstorm on how we can integrate other modules. Currently FHIR depends on some modules which uses those module APIs to support resources.