Patch to add option to print Emailed reminders

I have been asked to create a option so that reminders that are emailed can also be printed in the same run for the same event.

I have attached the patch file 

and a new ADL for the remindertypetemplate.  

 

its a quick hack and I still need to work out a number of functions but can anyone see major flaws before I work on refinements.  I didnt make this with the intent of asking for integration in the core.   

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Patch to add option to print Emailed reminders

You also need to change ReminderGenerator to copy email ReminderEvents flagged for printing i.e. iterate through the list of reminders returned by:

List<List<ReminderEvent>> emailReminders = emailCollector.getReminders();

and add the matches to the list returned by:

List<List<ReminderEvent>> printReminders = printCollector.getReminders();

 

Re: Patch to add option to print Emailed reminders

I actually added them to the list during generation....in the ReminderProcessor.   

    protected ReminderEvent email(Act reminder, ReminderType reminderType, Party patient, Party customer,
                                  Contact contact, Entity documentTemplate, boolean alwaysPrint) {
        ReminderEvent event = new ReminderEvent(Action.EMAIL, reminder, reminderType, patient, customer, contact,documentTemplate, alwaysPrint);
        notifyListeners(event.getAction(), event);
        if(alwaysPrint){
            notifyListeners(Action.PRINT, event);
        }
        return event;

The only thing I didnt do was update the event's action that is sent to the notifier to reflect the fact it was printed....however it still prints ok because its collected  by the printercollecter process.  During statistic generation however its recorded as being emailed twice.... 

As I said its a quick and dirty hack, I guess the better option would be to create an entirely new EVENT action called EmailsPrinted or something, that basically takes the duplicates and keeps them seperate. 

It would mean a new collector and new listeners etc.  but it would look better.

Regards
 
Ben 
OpenVPMS Installer and Helper 
Ph: +61423044823 
Email: info[at]charltonit.com[dot]au

Re: Patch to add option to print Emailed reminders

Changed tactic here...decided that it was much easier to override the event when it was generated.  In effect that means that if the alwaysPrint flag is set we just ensure the contact returned is a contact.location.  ie override the REMINDER flag on contact.purpose.  

# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: C:\Users\benjamincharlton\Documents\NetBeansProjects\openvpms-archetypes\src\java\org\openvpms\archetype\rules\patient\reminder
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: ReminderProcessor.java
--- ReminderProcessor.java Base (BASE)
+++ ReminderProcessor.java Locally Modified (Based On LOCAL)
@@ -97,6 +97,7 @@
      * @param to             the 'to' date. Nay be {@code null}
      * @param processingDate the processing date
      * @param service        the archetype service
+     * @param patientRules   the patient rules
      */
     public ReminderProcessor(Date from, Date to, Date processingDate, IArchetypeService service,
                              PatientRules patientRules) {
@@ -168,13 +169,14 @@
             IMObjectBean templateBean = new IMObjectBean(template, service);
             boolean list = templateBean.getBoolean("list");
             boolean export = templateBean.getBoolean("export");
+            boolean alwaysPrint = templateBean.getBoolean("alwaysprint");
             if (!list && !export && documentTemplate == null) {
                 // no template, so can't process. Strictly speaking this shouldn't happen - a template relationship
                 // should always have a template
                 result = skip(reminder, reminderType, patient);
             } else {
                 Party customer = getCustomer(patient);
-                Contact contact = getContact(customer);
+                Contact contact = getContact(customer,alwaysPrint);
                 if (list) {
                     result = list(reminder, reminderType, patient, customer, contact, documentTemplate);
                 } else if (TypeHelper.isA(contact, ContactArchetypes.LOCATION)) {
@@ -307,7 +309,7 @@
     /**
      * Notifies listeners to list a reminder. This is for reminders that
      * have no contact, or a contact that is not one of
-     * <em>contact.location<em>, <em>contact.phoneNumber</em>,
+     * <em>contact.location</em>, <em>contact.phoneNumber</em>,
      * or <em>contact.email</em>
      *
      * @param reminder         the reminder
@@ -449,7 +451,22 @@
      * @return the default contact, or {@code null}
      */
     private Contact getContact(Party customer) {
-        return (customer != null) ? rules.getContact(customer.getContacts()) : null;
+        return  getContact(customer, false);
     }
+    /**
+     * Returns the default contact for a customer.
+     *
+     * @param customer the customer. May be {@code null}
+     * @param alwaysPrint  boolean to determines if we need to get a LOCATION v any other.      
+     *                         Defaults to {@code false}
+     * @return the default contact, or {@code null}
+     */
+    private Contact getContact(Party customer, boolean alwaysPrint) {
+        if(customer != null){
+            return (alwaysPrint == true)? rules.getLocationContact(customer.getContacts()) : rules.getContact(customer.getContacts());
+                    }else {
+            return null;
+        }
+    }
 
 }
Index: ReminderRules.java
--- ReminderRules.java Base (BASE)
+++ ReminderRules.java Locally Modified (Based On LOCAL)
@@ -79,9 +79,18 @@
      * Reminder due indicator.
      */
     public enum DueState {
-        NOT_DUE,      // indicates the reminder is in the future, outside the sensitivity period
-        DUE,          // indicates the reminder is inside the sensitivity period
-        OVERDUE       // indicates the reminder is overdue
+        /**
+         * indicates the reminder is in the future, outside the sensitivity period
+         */
+        NOT_DUE,     
+        /**
+         * indicates the reminder is inside the sensitivity period
+         */
+        DUE,   
+        /**
+         * indicates the reminder is overdue
+         */
+        OVERDUE  
     }
 
     /**
@@ -433,6 +442,18 @@
     public Contact getContact(Set<Contact> contacts) {
         return getContact(contacts, true, ContactArchetypes.LOCATION);
     }
+    /**
+     * Returns the first contact.location with classification 'REMINDER', or; the
+     * preferred contact.location if no contact has this classification,
+     * or; the first contact.location if none is preferred.
+     *
+     * @param contacts the contacts
+     * @return a contact, or {@code null} if none is found
+     * @throws ArchetypeServiceException for any archetype service error
+     */
+    public Contact getLocationContact(Set<Contact> contacts) {
+        return getContact(contacts, false, ContactArchetypes.LOCATION);
+    }
 
     /**
      * Returns the first phone contact with classification 'REMINDER' or

This with the updated adl is all I think we needed in the end  

Mind there are some javadoc changes in there that arent part of my changes.

 

Regards
 
Ben 
OpenVPMS Installer and Helper 
Ph: +61423044823 
Email: info[at]charltonit.com[dot]au
Syndicate content