Reference Demo Data Module necessary to save a Diagnosis in OpenMRS 2.2

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… :wink: )

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):

  1. Found patient Betty Johnson
  2. Started new visit for patient
  3. Added new visit note with Malaria as primary diagnosis and Diabetes Mellitus as the secondary diagnosis
  4. Saved the visit note
  5. Ended the visit
  6. The visit and visit note can be saved without issue
  7. Installed XForms module (version 4.3.4)
  8. Created a new visit for patient
  9. Added new visit note with Malaria and primary diagnosis and Diabetes Mellitus as the secondary diagnosis
  10. Attempted to save the visit note and got the exception that Mario noted
  11. Stopped the XForms module
  12. Added new visit note with Malaria and primary diagnosis and Diabetes Mellitus as the secondary diagnosis
  13. Attempted to save the visit note and again got the exception that Mario noted
  14. Restarted OpenMRS
  15. Added new visit note with Malaria and primary diagnosis and Diabetes Mellitus as the secondary diagnosis
  16. 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.

What happens if you do all the way up to 16 but skip step 11 (Stopped the XForms module)?

Some further oddness to add:

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.

Can we look at the full tomcat log at the point when the error happens?

@dkayiwa

Here is the full stack trace:

I can send more of the log if needed, just let me know.

1 Like

FWIW, i was able to reproduce this on devtest02

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.

If my explanation is not clear, feel free to ask. :slight_smile:

2 Likes

Please make sure that the fix you do still accounts for unregistering the handlers when the module is stopped.

What method is used to unregister handlers?