After installing the Xforms module alongside the other OpenMRS 2.2 modules I ran into the problem that I could not save diagnosis (visit notes) any more. Initially I thought this to be an xforms bug that I reported here (for those of us who like to see the stacktrace…):
However I found that after installing the Reference Demo Data Module I could save diagnosis.
Considering the name of the module I am a little bit confused it seems to be mandatory to have it installed. I just thought it would provide some data in case you don’t have your own. I actually would like to not use it as I am not really interested in all that demo data (sorry… )
Any ideas what it is in the module that seems to be mandatory?
You should definitely not need the demo data to be able to fill out the
visit note. Peeking at the stack trace, it seems like the issue is:
Caused by: org.hibernate.LazyInitializationException: could not initialize
proxy - no Session
...
at
org.openmrs.Concept_$$_javassist_16.getName(Concept_$$_javassist_16.java)
at org.openmrs.Obs.getValueAsString(Obs.java:982)
at
org.openmrs.module.htmlformentry.HtmlFormEntryUtil.removeEmptyObs(HtmlFormEntryUtil.java:1754)
This error isn’t familiar to me, and it makes no sense at all to me that it would appear when you install xforms, and disappear when you install referencedemodata. (Are you absolutely sure it was working consistently without xforms, and breaking consistently when you installed xforms?)
Can you use the debugger and see what’s going on at Obs.java:982 in this case?
could not initialize proxy - no Session org.hibernate.LazyInitializationException: could not initialize proxy - no Session usually implies that a call to a proxy object has been made, the hibernate session of which has been closed. Probably an object that was fetched in a previous request and stored in a session or cached in any other way. I would look for a reason here:
I have no idea why installing the Demo Data module helps and I suspect it is a coincidence.
I’ve been doing some testing on this and can add a little detail.
Starting from the standalone 2.2 version with the demo data loaded (and the Reference Demo Data module loaded):
Found patient Betty Johnson
Started new visit for patient
Added new visit note with Malaria as primary diagnosis and Diabetes Mellitus as the secondary diagnosis
Saved the visit note
Ended the visit
The visit and visit note can be saved without issue
Installed XForms module (version 4.3.4)
Created a new visit for patient
Added new visit note with Malaria and primary diagnosis and Diabetes Mellitus as the secondary diagnosis
Attempted to save the visit note and got the exception that Mario noted
Stopped the XForms module
Added new visit note with Malaria and primary diagnosis and Diabetes Mellitus as the secondary diagnosis
Attempted to save the visit note and again got the exception that Mario noted
Restarted OpenMRS
Added new visit note with Malaria and primary diagnosis and Diabetes Mellitus as the secondary diagnosis
Able to save visit note without issue
The fact that you have to restart OpenMRS to fix the issue once the XForms module is started makes me wonder if that module is changing the mapping for the Obs or Concept and must then be completely unloaded to be fixed. Just a guess here, I haven’t yet looked into it deeper. Also, the Reference Demo Data module had no impact on this exception for me.
If OpenMRS is restarted with the XForms modules loaded, visit notes can be saved. However, once any module is added/stopped/started saving visit notes again starts to throw an exception. (I tested this by stopping/starting the XForms, Reference Demo Data, and OpenHMIS Commons (should be completely neutral) modules).
@dkayiwa You are correct that simply restarting OpenMRS fixes the issue. I no longer think this is an XForms issue at all. If you add, remove, start, or stop ANY module the patient visit notes can no longer be saved. Note that visit notes cannot be saved irrespective of whether they have single or multiple diagnoses.
Can someone else replicate this? I’m using the stand-alone version of OpenMRS 2.2 running on Java 1.7.0_51 on Mac OS 10.10.3.
Adding/stopping/starting modules results in closing Hibernate’s session factory and creating a new one, thus any module which keeps objects fetched with the previous session factory will most likely end up getting initialization exception at some point. It is probably the case for the HtmlFormEntry module as I wrote above.
I was able to reproduce this even more simply by starting/stopping any
other module and then just try add a concept visit note to any patient.
It turns out that this was a bug in the coreapps module as per this ticket
Thanks @wesley and @mario for bringing it to our attention!
In summary, the coreapps module was setting up htmlformentry service
handlers in the activator’s started() instead of contextRefreshed()
callback. Because started() is called only when the module is started,
context refreshes caused by module activities (install, start, stop)
resulted into the htmlformentry module using a no longer valid service and
hence closed hibernate session factory via its dao. The fix was to move
whatever was in the started() callback into the contextRefreshed() callback
such that the services get updated whenever the application context is
refreshed by any module activity that triggers it.