...
The RequiredDataAdvice (add link) class is AOP'd around all methods that start with save/(un)void/(un)retire. (create/update are also in there for backwards compatibility to pre 1.5 modules).
...
- Make sure your object extends the right parent class from openmrs core: Auditable, Voidable, or Retireable.
- Make sure the method name starts with the right phrase. It should be "save__" or "void__", "unvoid_", "retire__", or "unretire___"
- Add the "listener" with id="requiredDataInterceptor" to your service definition in the spring module application context file:
<property name="preInterceptors">
<ref bean="serviceInterceptors" />
</property>
Disabling Handlers
All RequiredDataHandlers are called on all child collections the OpenmrsObject being handled. Therefore, for instance, if you void an Encounter, the VoidHandler is called for all Obs associated with that Encounter. In a one-to-many relationship, this is the functionality we want, but it is not necessarily what we want in a many-to-many case. For instance, in the Provider Management module, there is a "ProviderRole" object that contains the collection of RelationshipTypes that the particular ProviderRole can support. As more than one ProviderRole can support the same relationship type, when retiring a ProviderRole we do NOT want to retire the associated RelationshipTypes.
By annotating a Collection with a @DisableHandlers annotation, you specific that RequiredDataAdvice should NOT apply the specified handler(s) to a child collection. For example:
Code Block |
---|
private class ClassWithDisableHandlersAnnotation extends BaseOpenmrsData { @DisableHandlers(handlerTypes = {VoidHandler.class, SaveHandler.class}) private List<Person> persons; } |
...