dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23802
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11596: Re-organize sending sms function in tracker module.
------------------------------------------------------------
revno: 11596
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-08-07 10:44:17 +0700
message:
Re-organize sending sms function in tracker module.
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminderService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientReminderService.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminder.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/SendScheduledMessageTask.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientAggregateReportStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CompleteDataEntryAction.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SetEventStatusAction.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminder.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminder.java 2013-07-19 06:04:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminder.java 2013-08-07 03:44:17 +0000
@@ -35,148 +35,167 @@
* @author Chau Thu Tran
* @version PatientReminder.java 1:07:58 PM Sep 18, 2012 $
*/
-public class PatientReminder implements Serializable {
- private static final long serialVersionUID = 3101502417481903219L;
-
- public static final String DUE_DATE_TO_COMPARE = "duedate";
-
- public static final String ENROLLEMENT_DATE_TO_COMPARE = "enrollmentdate";
-
- public static final String INCIDENT_DATE_TO_COMPARE = "dateofincident";
-
- public static final String TEMPLATE_MESSSAGE_PATIENT_NAME = "{patient-name}";
-
- public static final String TEMPLATE_MESSSAGE_PROGRAM_NAME = "{program-name}";
-
- public static final String TEMPLATE_MESSSAGE_PROGAM_STAGE_NAME = "{program-stage-name}";
-
- public static final String TEMPLATE_MESSSAGE_DUE_DATE = "{due-date}";
-
- public static final String TEMPLATE_MESSSAGE_ORGUNIT_NAME = "{orgunit-name}";
-
- public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE = "{days-since-due-date}";
-
- public static final String TEMPLATE_MESSSAGE_INCIDENT_DATE = "{incident-date}";
-
- public static final String TEMPLATE_MESSSAGE_ENROLLMENT_DATE = "{enrollement-date}";
-
- public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE = "{days-since-enrollment-date}";
-
- public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE = "{days-since-incident-date}";
-
- public static final int SEND_TO_PATIENT = 1;
-
- public static final int SEND_TO_HEALTH_WORKER = 2;
-
- public static final int SEND_TO_ORGUGNIT_REGISTERED = 3;
-
- public static final int SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED = 4;
-
- public static final int SEND_TO_USER_GROUP = 5;
-
- public static final int SEND_WHEN_TO_EMROLLEMENT = 1;
-
- public static final int SEND_WHEN_TO_C0MPLETED_EVENT = 2;
-
- public static final int SEND_WHEN_TO_C0MPLETED_PROGRAM = 3;
-
- private int id;
-
- private String name;
-
- private Integer daysAllowedSendMessage;
-
- private String templateMessage;
-
- private String dateToCompare;
-
- private Integer sendTo;
-
- private Integer whenToSend;
-
- private UserGroup userGroup;
-
- // -------------------------------------------------------------------------
- // Constructors
- // -------------------------------------------------------------------------
-
- public PatientReminder(String name, Integer daysAllowedSendMessage,
- String templateMessage) {
- this.name = name;
- this.daysAllowedSendMessage = daysAllowedSendMessage;
- this.templateMessage = templateMessage;
- }
-
- // -------------------------------------------------------------------------
- // Getter && Setter
- // -------------------------------------------------------------------------
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Integer getDaysAllowedSendMessage() {
- return daysAllowedSendMessage;
- }
-
- public void setDaysAllowedSendMessage(Integer daysAllowedSendMessage) {
- this.daysAllowedSendMessage = daysAllowedSendMessage;
- }
-
- public String getTemplateMessage() {
- return templateMessage;
- }
-
- public void setTemplateMessage(String templateMessage) {
- this.templateMessage = templateMessage;
- }
-
- public String getDateToCompare() {
- return dateToCompare;
- }
-
- public void setDateToCompare(String dateToCompare) {
- this.dateToCompare = dateToCompare;
- }
-
- public Integer getSendTo() {
- return sendTo;
- }
-
- public void setSendTo(Integer sendTo) {
- this.sendTo = sendTo;
- }
-
- public Integer getWhenToSend() {
- return whenToSend;
- }
-
- public void setWhenToSend(Integer whenToSend) {
- this.whenToSend = whenToSend;
- }
-
- public PatientReminder() {
-
- }
-
- public UserGroup getUserGroup() {
- return userGroup;
- }
-
- public void setUserGroup( UserGroup userGroup ) {
- this.userGroup = userGroup;
- }
+public class PatientReminder
+ implements Serializable
+{
+ private static final long serialVersionUID = 3101502417481903219L;
+
+ public static final String DUE_DATE_TO_COMPARE = "duedate";
+
+ public static final String ENROLLEMENT_DATE_TO_COMPARE = "enrollmentdate";
+
+ public static final String INCIDENT_DATE_TO_COMPARE = "dateofincident";
+
+ public static final String TEMPLATE_MESSSAGE_PATIENT_NAME = "{patient-name}";
+
+ public static final String TEMPLATE_MESSSAGE_PROGRAM_NAME = "{program-name}";
+
+ public static final String TEMPLATE_MESSSAGE_PROGAM_STAGE_NAME = "{program-stage-name}";
+
+ public static final String TEMPLATE_MESSSAGE_DUE_DATE = "{due-date}";
+
+ public static final String TEMPLATE_MESSSAGE_ORGUNIT_NAME = "{orgunit-name}";
+
+ public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE = "{days-since-due-date}";
+
+ public static final String TEMPLATE_MESSSAGE_INCIDENT_DATE = "{incident-date}";
+
+ public static final String TEMPLATE_MESSSAGE_ENROLLMENT_DATE = "{enrollement-date}";
+
+ public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE = "{days-since-enrollment-date}";
+
+ public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE = "{days-since-incident-date}";
+
+ public static final int SEND_TO_PATIENT = 1;
+
+ public static final int SEND_TO_HEALTH_WORKER = 2;
+
+ public static final int SEND_TO_ORGUGNIT_REGISTERED = 3;
+
+ public static final int SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED = 4;
+
+ public static final int SEND_TO_USER_GROUP = 5;
+
+ public static final int SEND_WHEN_TO_EMROLLEMENT = 1;
+
+ public static final int SEND_WHEN_TO_C0MPLETED_EVENT = 2;
+
+ public static final int SEND_WHEN_TO_C0MPLETED_PROGRAM = 3;
+
+ private int id;
+
+ private String name;
+
+ private Integer daysAllowedSendMessage;
+
+ private String templateMessage;
+
+ private String dateToCompare;
+
+ private Integer sendTo;
+
+ private Integer whenToSend;
+
+ private UserGroup userGroup;
+
+ // -------------------------------------------------------------------------
+ // Constructors
+ // -------------------------------------------------------------------------
+
+ public PatientReminder( String name, Integer daysAllowedSendMessage, String templateMessage )
+ {
+ this.name = name;
+ this.daysAllowedSendMessage = daysAllowedSendMessage;
+ this.templateMessage = templateMessage;
+ }
+
+ // -------------------------------------------------------------------------
+ // Getter && Setter
+ // -------------------------------------------------------------------------
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ public Integer getDaysAllowedSendMessage()
+ {
+ return daysAllowedSendMessage;
+ }
+
+ public void setDaysAllowedSendMessage( Integer daysAllowedSendMessage )
+ {
+ this.daysAllowedSendMessage = daysAllowedSendMessage;
+ }
+
+ public String getTemplateMessage()
+ {
+ return templateMessage;
+ }
+
+ public void setTemplateMessage( String templateMessage )
+ {
+ this.templateMessage = templateMessage;
+ }
+
+ public String getDateToCompare()
+ {
+ return dateToCompare;
+ }
+
+ public void setDateToCompare( String dateToCompare )
+ {
+ this.dateToCompare = dateToCompare;
+ }
+
+ public Integer getSendTo()
+ {
+ return sendTo;
+ }
+
+ public void setSendTo( Integer sendTo )
+ {
+ this.sendTo = sendTo;
+ }
+
+ public Integer getWhenToSend()
+ {
+ return whenToSend;
+ }
+
+ public void setWhenToSend( Integer whenToSend )
+ {
+ this.whenToSend = whenToSend;
+ }
+
+ public PatientReminder()
+ {
+
+ }
+
+ public UserGroup getUserGroup()
+ {
+ return userGroup;
+ }
+
+ public void setUserGroup( UserGroup userGroup )
+ {
+ this.userGroup = userGroup;
+ }
}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminderService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminderService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientReminderService.java 2013-08-07 03:44:17 +0000
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.patient;
+
+import java.util.Set;
+
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramStageInstance;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ PatientReminderService.java Aug 7, 2013 9:53:19 AM $
+ */
+public interface PatientReminderService
+{
+ String getMessageFromTemplate( PatientReminder patientReminder, ProgramInstance programInstance, I18nFormat format );
+
+ String getMessageFromTemplate( PatientReminder patientReminder, ProgramStageInstance programStageInstance, I18nFormat format );
+
+ Set<String> getPhonenumbers( PatientReminder patientReminder, Patient patient );
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java 2013-04-10 08:45:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java 2013-08-07 03:44:17 +0000
@@ -35,6 +35,7 @@
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.sms.outbound.OutboundSms;
/**
* @author Abyot Asalefew
@@ -82,7 +83,7 @@
Collection<ProgramInstance> getProgramInstances( Program program, Collection<Integer> orgunitIds, Date startDate,
Date endDate, int min, int max );
-
+
int countProgramInstances( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate );
List<Grid> getProgramInstanceReport( Patient patient, I18n i18n, I18nFormat format );
@@ -96,7 +97,9 @@
Collection<Integer> orgunitIds, Date startDate, Date endDate );
void removeProgramEnrollment( ProgramInstance programInstance );
-
- Collection<SchedulingProgramObject> getSendMesssageEvents();
+
+ Collection<SchedulingProgramObject> getScheduleMesssages();
+
+ Collection<OutboundSms> sendMessages( ProgramInstance programInstance, int status, I18nFormat format );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-07-23 04:16:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-08-07 03:44:17 +0000
@@ -134,5 +134,7 @@
Grid getCompletenessProgramStageInstance( Collection<Integer> orgunits, Program program, String startDate,
String endDate, I18n i18n );
+
+ Collection<OutboundSms> sendMessages( ProgramStageInstance programStageInstance, int status, I18nFormat format );
}
=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientReminderService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientReminderService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientReminderService.java 2013-08-07 03:44:17 +0000
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.patient;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.system.util.DateUtils;
+import org.hisp.dhis.user.User;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ DefaultPatientReminderService.java Aug 7, 2013 9:54:59 AM $
+ */
+public class DefaultPatientReminderService
+ implements PatientReminderService
+{
+
+ @Override
+ public String getMessageFromTemplate( PatientReminder patientReminder, ProgramInstance programInstance,
+ I18nFormat format )
+ {
+ Patient patient = programInstance.getPatient();
+ String templateMessage = patientReminder.getTemplateMessage();
+
+ String patientName = patient.getFirstName();
+ String organisationunitName = patient.getOrganisationUnit().getName();
+ String programName = programInstance.getProgram().getName();
+ String daysSinceEnrollementDate = DateUtils.daysBetween( new Date(), programInstance.getEnrollmentDate() ) + "";
+ String daysSinceIncidentDate = DateUtils.daysBetween( new Date(), programInstance.getDateOfIncident() ) + "";
+ String incidentDate = format.formatDate( programInstance.getDateOfIncident() );
+ String erollmentDate = format.formatDate( programInstance.getEnrollmentDate() );
+
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_PATIENT_NAME, patientName );
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
+ templateMessage = templateMessage
+ .replace( PatientReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_INCIDENT_DATE, incidentDate );
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_ENROLLMENT_DATE, erollmentDate );
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE,
+ daysSinceEnrollementDate );
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE,
+ daysSinceIncidentDate );
+
+ return templateMessage;
+ }
+
+ @Override
+ public String getMessageFromTemplate( PatientReminder patientReminder, ProgramStageInstance programStageInstance,
+ I18nFormat format )
+ {
+ Patient patient = programStageInstance.getProgramInstance().getPatient();
+ String templateMessage = patientReminder.getTemplateMessage();
+
+ String patientName = patient.getFirstName();
+ String organisationunitName = patient.getOrganisationUnit().getName();
+ String programName = programStageInstance.getProgramInstance().getProgram().getName();
+ String programStageName = programStageInstance.getProgramStage().getName();
+ String daysSinceDueDate = DateUtils.daysBetween( new Date(), programStageInstance.getDueDate() ) + "";
+ String dueDate = format.formatDate( programStageInstance.getDueDate() );
+
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_PATIENT_NAME, patientName );
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_PROGAM_STAGE_NAME,
+ programStageName );
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_DUE_DATE, dueDate );
+ templateMessage = templateMessage
+ .replace( PatientReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
+ templateMessage = templateMessage.replace( PatientReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE,
+ daysSinceDueDate );
+
+ return templateMessage;
+ }
+
+ @Override
+ public Set<String> getPhonenumbers( PatientReminder patientReminder, Patient patient )
+ {
+ Set<String> phoneNumbers = new HashSet<String>();
+
+ switch ( patientReminder.getSendTo() )
+ {
+ case PatientReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED:
+ Collection<User> users = patient.getOrganisationUnit().getUsers();
+ for ( User user : users )
+ {
+ if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
+ {
+ phoneNumbers.add( user.getPhoneNumber() );
+ }
+ }
+ break;
+ case PatientReminder.SEND_TO_HEALTH_WORKER:
+ if ( patient.getHealthWorker() != null && patient.getHealthWorker().getPhoneNumber() != null )
+ {
+ phoneNumbers.add( patient.getHealthWorker().getPhoneNumber() );
+ }
+ break;
+ case PatientReminder.SEND_TO_ORGUGNIT_REGISTERED:
+ if ( patient.getOrganisationUnit().getPhoneNumber() != null
+ && !patient.getOrganisationUnit().getPhoneNumber().isEmpty() )
+ {
+ phoneNumbers.add( patient.getOrganisationUnit().getPhoneNumber() );
+ }
+ break;
+ case PatientReminder.SEND_TO_USER_GROUP:
+ for ( User user : patientReminder.getUserGroup().getMembers() )
+ {
+ if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
+ {
+ phoneNumbers.add( user.getPhoneNumber() );
+ }
+ }
+ break;
+ default:
+ if ( patient.getPhoneNumber() != null && !patient.getPhoneNumber().isEmpty() )
+ {
+ phoneNumbers.add( patient.getPhoneNumber() );
+ }
+ break;
+ }
+ return phoneNumbers;
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/SendScheduledMessageTask.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/SendScheduledMessageTask.java 2013-07-24 07:03:54 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/scheduling/SendScheduledMessageTask.java 2013-08-07 03:44:17 +0000
@@ -199,7 +199,7 @@
{
notifier.notify( taskId, "Start to prepare reminder messages for enrollements" );
- Collection<SchedulingProgramObject> schedulingProgramObjects = programInstanceService.getSendMesssageEvents();
+ Collection<SchedulingProgramObject> schedulingProgramObjects = programInstanceService.getScheduleMesssages();
for ( SchedulingProgramObject schedulingProgramObject : schedulingProgramObjects )
{
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientAggregateReportStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientAggregateReportStore.java 2013-05-24 04:19:07 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientAggregateReportStore.java 2013-08-07 03:44:17 +0000
@@ -32,13 +32,11 @@
import java.util.List;
import org.hibernate.Criteria;
-import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.SharingUtils;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
import org.hisp.dhis.patientreport.PatientAggregateReport;
import org.hisp.dhis.patientreport.PatientAggregateReportStore;
-import org.hisp.dhis.patientreport.PatientTabularReport;
import org.hisp.dhis.user.User;
/**
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2013-07-23 03:14:03 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2013-08-07 03:44:17 +0000
@@ -29,8 +29,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.GridHeader;
@@ -43,13 +45,17 @@
import org.hisp.dhis.patient.PatientIdentifier;
import org.hisp.dhis.patient.PatientIdentifierType;
import org.hisp.dhis.patient.PatientReminder;
+import org.hisp.dhis.patient.PatientReminderService;
import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
import org.hisp.dhis.patientcomment.PatientComment;
import org.hisp.dhis.patientdatavalue.PatientDataValue;
import org.hisp.dhis.patientdatavalue.PatientDataValueService;
+import org.hisp.dhis.sms.SmsServiceException;
import org.hisp.dhis.sms.outbound.OutboundSms;
+import org.hisp.dhis.sms.outbound.OutboundSmsService;
import org.hisp.dhis.system.grid.ListGrid;
+import org.hisp.dhis.user.CurrentUserService;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -92,6 +98,27 @@
this.programService = programService;
}
+ private OutboundSmsService outboundSmsService;
+
+ public void setOutboundSmsService( OutboundSmsService outboundSmsService )
+ {
+ this.outboundSmsService = outboundSmsService;
+ }
+
+ private CurrentUserService currentUserService;
+
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
+ private PatientReminderService patientReminderService;
+
+ public void setPatientReminderService( PatientReminderService patientReminderService )
+ {
+ this.patientReminderService = patientReminderService;
+ }
+
// -------------------------------------------------------------------------
// Implementation methods
// -------------------------------------------------------------------------
@@ -396,16 +423,17 @@
{
for ( PatientIdentifier identifier : identifiers )
{
- if ( identifier.getIdentifierType() != null && identifier.getIdentifierType().equals( identifierType ) )
+ if ( identifier.getIdentifierType() != null
+ && identifier.getIdentifierType().equals( identifierType ) )
{
grid.addRow();
grid.addValue( identifierType.getDisplayName() );
grid.addValue( identifier.getIdentifier() );
}
- else if ( identifier.getIdentifierType() == null )
+ else if ( identifier.getIdentifierType() == null )
{
grid.addRow();
- grid.addValue( i18n.getString( "system_identifier" ));
+ grid.addValue( i18n.getString( "system_identifier" ) );
grid.addValue( identifier.getIdentifier() );
}
}
@@ -480,7 +508,7 @@
programInstanceStore.removeProgramEnrollment( programInstance );
}
- public Collection<SchedulingProgramObject> getSendMesssageEvents()
+ public Collection<SchedulingProgramObject> getScheduleMesssages()
{
Collection<SchedulingProgramObject> result = programInstanceStore
.getSendMesssageEvents( PatientReminder.ENROLLEMENT_DATE_TO_COMPARE );
@@ -490,8 +518,29 @@
return result;
}
+ public Collection<OutboundSms> sendMessages( ProgramInstance programInstance, int status, I18nFormat format )
+ {
+ Patient patient = programInstance.getPatient();
+ Collection<OutboundSms> outboundSmsList = new HashSet<OutboundSms>();
+
+ Collection<PatientReminder> reminders = programInstance.getProgram().getPatientReminders();
+ for ( PatientReminder rm : reminders )
+ {
+ if ( rm != null && rm.getWhenToSend() != null && rm.getWhenToSend() == status )
+ {
+ OutboundSms outboundSms = sendProgramMessage( rm, programInstance, patient, format );
+ if ( outboundSms != null )
+ {
+ outboundSmsList.add( outboundSms );
+ }
+ }
+ }
+
+ return outboundSmsList;
+ }
+
// -------------------------------------------------------------------------
- // due-date && report-date
+ // Supportive methods
// -------------------------------------------------------------------------
private void getProgramStageInstancesReport( Grid grid, ProgramInstance programInstance, I18nFormat format,
@@ -574,4 +623,31 @@
}
}
+ private OutboundSms sendProgramMessage( PatientReminder patientReminder, ProgramInstance programInstance,
+ Patient patient, I18nFormat format )
+ {
+ Set<String> phoneNumbers = patientReminderService.getPhonenumbers( patientReminder, patient );
+ OutboundSms outboundSms = null;
+
+ if ( phoneNumbers.size() > 0 )
+ {
+ String msg = patientReminderService.getMessageFromTemplate( patientReminder, programInstance, format );
+
+ try
+ {
+ outboundSms = new OutboundSms();
+ outboundSms.setMessage( msg );
+ outboundSms.setRecipients( phoneNumbers );
+ outboundSms.setSender( currentUserService.getCurrentUsername() );
+ outboundSmsService.sendMessage( outboundSms, null );
+ }
+ catch ( SmsServiceException e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ return outboundSms;
+ }
+
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-07-23 04:16:21 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-08-07 03:44:17 +0000
@@ -26,6 +26,15 @@
*/
package org.hisp.dhis.program;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.GridHeader;
import org.hisp.dhis.dataelement.DataElement;
@@ -35,21 +44,19 @@
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientReminder;
+import org.hisp.dhis.patient.PatientReminderService;
import org.hisp.dhis.patientdatavalue.PatientDataValue;
import org.hisp.dhis.patientdatavalue.PatientDataValueService;
import org.hisp.dhis.patientreport.TabularReportColumn;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.sms.SmsServiceException;
import org.hisp.dhis.sms.outbound.OutboundSms;
+import org.hisp.dhis.sms.outbound.OutboundSmsService;
import org.hisp.dhis.system.grid.ListGrid;
+import org.hisp.dhis.user.CurrentUserService;
import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* @author Abyot Asalefew
* @version $Id$
@@ -90,6 +97,27 @@
this.organisationUnitService = organisationUnitService;
}
+ private OutboundSmsService outboundSmsService;
+
+ public void setOutboundSmsService( OutboundSmsService outboundSmsService )
+ {
+ this.outboundSmsService = outboundSmsService;
+ }
+
+ private CurrentUserService currentUserService;
+
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
+ private PatientReminderService patientReminderService;
+
+ public void setPatientReminderService( PatientReminderService patientReminderService )
+ {
+ this.patientReminderService = patientReminderService;
+ }
+
// -------------------------------------------------------------------------
// Implementation methods
// -------------------------------------------------------------------------
@@ -499,7 +527,8 @@
Boolean useFormNameDataElement, I18nFormat format, I18n i18n )
{
return programStageInstanceStore.getAggregateReport( position, programStage, orgunitIds, facilityLB, deGroupBy,
- deSum, deFilters, periods, aggregateType, limit, useCompletedEvents, displayTotals, useFormNameDataElement, format, i18n );
+ deSum, deFilters, periods, aggregateType, limit, useCompletedEvents, displayTotals, useFormNameDataElement,
+ format, i18n );
}
@Override
@@ -529,4 +558,56 @@
return programStageInstanceStore.getCompleteness( orgunitIds, program, startDate, endDate, i18n );
}
+ @Override
+ public Collection<OutboundSms> sendMessages( ProgramStageInstance programStageInstance, int status,
+ I18nFormat format )
+ {
+ Patient patient = programStageInstance.getProgramInstance().getPatient();
+ Collection<OutboundSms> outboundSmsList = new HashSet<OutboundSms>();
+
+ Collection<PatientReminder> reminders = programStageInstance.getProgramStage().getPatientReminders();
+ for ( PatientReminder rm : reminders )
+ {
+ if ( rm != null && rm.getWhenToSend() != null && rm.getWhenToSend() == status )
+ {
+ OutboundSms outboundSms = sendEventMessage( rm, programStageInstance, patient, format );
+ if ( outboundSms != null )
+ {
+ outboundSmsList.add( outboundSms );
+ }
+ }
+ }
+
+ return outboundSmsList;
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ private OutboundSms sendEventMessage( PatientReminder patientReminder, ProgramStageInstance programStageInstance,
+ Patient patient, I18nFormat format )
+ {
+ Set<String> phoneNumbers = patientReminderService.getPhonenumbers( patientReminder, patient );
+ OutboundSms outboundSms = null;
+
+ if ( phoneNumbers.size() > 0 )
+ {
+ String msg = patientReminderService.getMessageFromTemplate( patientReminder, programStageInstance, format );
+ try
+ {
+ outboundSms = new OutboundSms();
+ outboundSms.setMessage( msg );
+ outboundSms.setRecipients( phoneNumbers );
+ outboundSms.setSender( currentUserService.getCurrentUsername() );
+ outboundSmsService.sendMessage( outboundSms, null );
+ }
+ catch ( SmsServiceException e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ return outboundSms;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-06-18 02:41:49 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-08-07 03:44:17 +0000
@@ -210,6 +210,12 @@
ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
<property name="organisationUnitService"
ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <property name="outboundSmsService"
+ ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
+ <property name="currentUserService"
+ ref="org.hisp.dhis.user.CurrentUserService" />
+ <property name="patientReminderService"
+ ref="org.hisp.dhis.patient.PatientReminderService" />
</bean>
<bean id="org.hisp.dhis.program.ProgramInstanceService" class="org.hisp.dhis.program.DefaultProgramInstanceService">
@@ -220,6 +226,12 @@
ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
<property name="programService"
ref="org.hisp.dhis.program.ProgramService" />
+ <property name="outboundSmsService"
+ ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
+ <property name="currentUserService"
+ ref="org.hisp.dhis.user.CurrentUserService" />
+ <property name="patientReminderService"
+ ref="org.hisp.dhis.patient.PatientReminderService" />
</bean>
<bean id="org.hisp.dhis.program.ProgramStageService" class="org.hisp.dhis.program.DefaultProgramStageService">
@@ -523,6 +535,11 @@
<property name="sessionFactory" ref="sessionFactory" />
</bean>
+ <!-- Patient Reminder -->
+
+ <bean id="org.hisp.dhis.patient.PatientReminderService" class="org.hisp.dhis.patient.DefaultPatientReminderService">
+ </bean>
+
<!-- Startup -->
<bean id="org.hisp.dhis.patient.startup.TableAlteror" class="org.hisp.dhis.patient.startup.TableAlteror">
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CompleteDataEntryAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CompleteDataEntryAction.java 2013-08-05 03:00:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/CompleteDataEntryAction.java 2013-08-07 03:44:17 +0000
@@ -28,9 +28,7 @@
import java.util.ArrayList;
import java.util.Calendar;
-import java.util.Collection;
import java.util.Date;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -44,12 +42,8 @@
import org.hisp.dhis.program.ProgramInstanceService;
import org.hisp.dhis.program.ProgramStageInstance;
import org.hisp.dhis.program.ProgramStageInstanceService;
-import org.hisp.dhis.sms.SmsServiceException;
import org.hisp.dhis.sms.outbound.OutboundSms;
-import org.hisp.dhis.sms.outbound.OutboundSmsService;
-import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.user.User;
import com.opensymphony.xwork2.Action;
@@ -91,13 +85,6 @@
this.currentUserService = currentUserService;
}
- private OutboundSmsService outboundSmsService;
-
- public void setOutboundSmsService( OutboundSmsService outboundSmsService )
- {
- this.outboundSmsService = outboundSmsService;
- }
-
private I18nFormat format;
public void setFormat( I18nFormat format )
@@ -159,7 +146,14 @@
// Send message when to completed the event
- sendSMSToCompletedEvent( programStageInstance );
+ List<OutboundSms> psiOutboundSms = programStageInstance.getOutboundSms();
+ if ( psiOutboundSms == null )
+ {
+ psiOutboundSms = new ArrayList<OutboundSms>();
+ }
+
+ psiOutboundSms.addAll( programStageInstanceService.sendMessages( programStageInstance,
+ PatientReminder.SEND_WHEN_TO_C0MPLETED_EVENT, format ) );
programStageInstanceService.updateProgramStageInstance( programStageInstance );
@@ -185,7 +179,14 @@
programInstance.setStatus( ProgramInstance.STATUS_COMPLETED );
programInstance.setEndDate( new Date() );
- sendSMSToCompletedProgram( programInstance );
+ List<OutboundSms> piOutboundSms = programInstance.getOutboundSms();
+ if ( piOutboundSms == null )
+ {
+ piOutboundSms = new ArrayList<OutboundSms>();
+ }
+
+ piOutboundSms.addAll( programInstanceService.sendMessages( programInstance,
+ PatientReminder.SEND_WHEN_TO_C0MPLETED_PROGRAM, format ) );
programInstanceService.updateProgramInstance( programInstance );
@@ -200,202 +201,4 @@
return "programcompleted";
}
-
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- private void sendSMSToCompletedEvent( ProgramStageInstance programStageInstance )
- {
- Patient patient = programStageInstance.getProgramInstance().getPatient();
-
- if ( patient != null )
- {
- Collection<PatientReminder> reminders = programStageInstance.getProgramStage().getPatientReminders();
- for ( PatientReminder rm : reminders )
- {
- if ( rm != null && rm.getWhenToSend() != null
- && rm.getWhenToSend() == PatientReminder.SEND_WHEN_TO_C0MPLETED_EVENT )
- {
- sendEventMessage( rm, programStageInstance, patient );
- }
- }
- }
- }
-
- private void sendEventMessage( PatientReminder reminder, ProgramStageInstance programStageInstance, Patient patient )
- {
- Set<String> phoneNumbers = getPhonenumbers( reminder, patient );
-
- if ( phoneNumbers.size() > 0 )
- {
- String msg = getStringMsgFromTemplateMsg( reminder, programStageInstance, patient );
- try
- {
- OutboundSms outboundSms = new OutboundSms();
- outboundSms.setMessage( msg );
- outboundSms.setRecipients( phoneNumbers );
- outboundSms.setSender( currentUserService.getCurrentUsername() );
- outboundSmsService.sendMessage( outboundSms, null );
-
- List<OutboundSms> outboundSmsList = programStageInstance.getOutboundSms();
- if ( outboundSmsList == null )
- {
- outboundSmsList = new ArrayList<OutboundSms>();
- }
- outboundSmsList.add( outboundSms );
- programStageInstance.setOutboundSms( outboundSmsList );
- }
- catch ( SmsServiceException e )
- {
- e.printStackTrace();
- }
- }
-
- }
-
- private void sendSMSToCompletedProgram( ProgramInstance programInstance )
- {
- Patient patient = programInstance.getPatient();
-
- if ( patient != null )
- {
- Collection<PatientReminder> reminders = programInstance.getProgram().getPatientReminders();
- for ( PatientReminder rm : reminders )
- {
- if ( rm != null && rm.getWhenToSend() != null
- && rm.getWhenToSend() == PatientReminder.SEND_WHEN_TO_C0MPLETED_PROGRAM )
- {
- sendProgramMessage( rm, programInstance, patient );
- }
- }
- }
- }
-
- private void sendProgramMessage( PatientReminder reminder, ProgramInstance programInstance, Patient patient )
- {
- Set<String> phoneNumbers = getPhonenumbers( reminder, patient );
-
- if ( phoneNumbers.size() > 0 )
- {
- String msg = getStringMsgFromTemplateMsg( reminder, programInstance, patient );
-
- try
- {
- OutboundSms outboundSms = new OutboundSms();
- outboundSms.setMessage( msg );
- outboundSms.setRecipients( phoneNumbers );
- outboundSms.setSender( currentUserService.getCurrentUsername() );
- outboundSmsService.sendMessage( outboundSms, null );
-
- List<OutboundSms> outboundSmsList = programInstance.getOutboundSms();
- if ( outboundSmsList == null )
- {
- outboundSmsList = new ArrayList<OutboundSms>();
- }
- outboundSmsList.add( outboundSms );
- programInstance.setOutboundSms( outboundSmsList );
- }
- catch ( SmsServiceException e )
- {
- e.printStackTrace();
- }
- }
-
- }
-
- private Set<String> getPhonenumbers( PatientReminder reminder, Patient patient )
- {
- Set<String> phoneNumbers = new HashSet<String>();
-
- switch ( reminder.getSendTo() )
- {
- case PatientReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED:
- Collection<User> users = patient.getOrganisationUnit().getUsers();
- for ( User user : users )
- {
- if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( user.getPhoneNumber() );
- }
- }
- break;
- case PatientReminder.SEND_TO_HEALTH_WORKER:
- if ( patient.getHealthWorker() != null && patient.getHealthWorker().getPhoneNumber() != null )
- {
- phoneNumbers.add( patient.getHealthWorker().getPhoneNumber() );
- }
- break;
- case PatientReminder.SEND_TO_ORGUGNIT_REGISTERED:
- if ( patient.getOrganisationUnit().getPhoneNumber() != null
- && !patient.getOrganisationUnit().getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( patient.getOrganisationUnit().getPhoneNumber() );
- }
- break;
- case PatientReminder.SEND_TO_USER_GROUP:
- for ( User user : reminder.getUserGroup().getMembers() )
- {
- if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( user.getPhoneNumber() );
- }
- }
- break;
- default:
- if ( patient.getPhoneNumber() != null && !patient.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( patient.getPhoneNumber() );
- }
- break;
- }
- return phoneNumbers;
- }
-
- public String getStringMsgFromTemplateMsg( PatientReminder reminder, ProgramStageInstance programStageInstance,
- Patient patient )
- {
- String msg = reminder.getTemplateMessage();
-
- String patientName = patient.getFirstName();
- String organisationunitName = patient.getOrganisationUnit().getName();
- String programName = programStageInstance.getProgramInstance().getProgram().getName();
- String programStageName = programStageInstance.getProgramStage().getName();
- String daysSinceDueDate = DateUtils.daysBetween( new Date(), programStageInstance.getDueDate() ) + "";
- String dueDate = format.formatDate( programStageInstance.getDueDate() );
-
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PATIENT_NAME, patientName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PROGAM_STAGE_NAME, programStageName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_DUE_DATE, dueDate );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE, daysSinceDueDate );
-
- return msg;
- }
-
- public String getStringMsgFromTemplateMsg( PatientReminder reminder, ProgramInstance programInstance,
- Patient patient )
- {
- String msg = reminder.getTemplateMessage();
-
- String patientName = patient.getFirstName();
- String organisationunitName = patient.getOrganisationUnit().getName();
- String programName = programInstance.getProgram().getName();
- String daysSinceEnrollementDate = DateUtils.daysBetween( new Date(), programInstance.getEnrollmentDate() ) + "";
- String daysSinceIncidentDate = DateUtils.daysBetween( new Date(), programInstance.getDateOfIncident() ) + "";
- String incidentDate = format.formatDate( programInstance.getDateOfIncident() );
- String erollmentDate = format.formatDate( programInstance.getEnrollmentDate() );
-
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PATIENT_NAME, patientName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_INCIDENT_DATE, incidentDate );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_ENROLLMENT_DATE, erollmentDate );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE, daysSinceEnrollementDate );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE, daysSinceIncidentDate );
-
- return msg;
- }
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java 2013-08-02 03:34:24 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SaveProgramEnrollmentAction.java 2013-08-07 03:44:17 +0000
@@ -29,9 +29,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.hisp.dhis.caseentry.state.SelectedStateManager;
import org.hisp.dhis.i18n.I18nFormat;
@@ -45,12 +43,8 @@
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageInstance;
import org.hisp.dhis.program.ProgramStageInstanceService;
-import org.hisp.dhis.sms.SmsServiceException;
import org.hisp.dhis.sms.outbound.OutboundSms;
-import org.hisp.dhis.sms.outbound.OutboundSmsService;
import org.hisp.dhis.system.util.DateUtils;
-import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.user.User;
import com.opensymphony.xwork2.Action;
@@ -107,20 +101,6 @@
this.format = format;
}
- private CurrentUserService currentUserService;
-
- public void setCurrentUserService( CurrentUserService currentUserService )
- {
- this.currentUserService = currentUserService;
- }
-
- private OutboundSmsService outboundSmsService;
-
- public void setOutboundSmsService( OutboundSmsService outboundSmsService )
- {
- this.outboundSmsService = outboundSmsService;
- }
-
// -------------------------------------------------------------------------
// Input/Output
// -------------------------------------------------------------------------
@@ -266,7 +246,15 @@
}
// send messages after enrollment program
- sendMessage(programInstance);
+ List<OutboundSms> outboundSms = programInstance.getOutboundSms();
+ if ( outboundSms == null )
+ {
+ outboundSms = new ArrayList<OutboundSms>();
+ }
+
+ outboundSms.addAll( programInstanceService.sendMessages( programInstance,
+ PatientReminder.SEND_WHEN_TO_EMROLLEMENT, format ) );
+ programInstanceService.updateProgramInstance( programInstance );
}
else
{
@@ -293,129 +281,4 @@
return SUCCESS;
}
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- private void sendMessage( ProgramInstance programInstance )
- {
- Patient patient = programInstance.getPatient();
-
- if ( patient != null )
- {
- Collection<PatientReminder> reminders = programInstance.getProgram().getPatientReminders();
- for ( PatientReminder rm : reminders )
- {
- if ( rm != null && rm.getWhenToSend() != null
- && rm.getWhenToSend() == PatientReminder.SEND_WHEN_TO_EMROLLEMENT )
- {
- sendProgramMessage( rm, programInstance, patient );
- }
- }
- }
- }
-
- private void sendProgramMessage( PatientReminder reminder, ProgramInstance programInstance, Patient patient )
- {
- Set<String> phoneNumbers = getPhonenumbers( reminder, patient );
-
- if ( phoneNumbers.size() > 0 )
- {
- String msg = getStringMsgFromTemplateMsg( reminder, programInstance, patient );
-
- try
- {
- OutboundSms outboundSms = new OutboundSms();
- outboundSms.setMessage( msg );
- outboundSms.setRecipients( phoneNumbers );
- outboundSms.setSender( currentUserService.getCurrentUsername() );
- outboundSmsService.sendMessage( outboundSms, null );
-
- List<OutboundSms> outboundSmsList = programInstance.getOutboundSms();
- if ( outboundSmsList == null )
- {
- outboundSmsList = new ArrayList<OutboundSms>();
- }
- outboundSmsList.add( outboundSms );
- programInstance.setOutboundSms( outboundSmsList );
- }
- catch ( SmsServiceException e )
- {
- e.printStackTrace();
- }
- }
- }
-
- private Set<String> getPhonenumbers( PatientReminder reminder, Patient patient )
- {
- Set<String> phoneNumbers = new HashSet<String>();
-
- switch ( reminder.getSendTo() )
- {
- case PatientReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED:
- Collection<User> users = patient.getOrganisationUnit().getUsers();
- for ( User user : users )
- {
- if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( user.getPhoneNumber() );
- }
- }
- break;
- case PatientReminder.SEND_TO_HEALTH_WORKER:
- if ( patient.getHealthWorker() != null && patient.getHealthWorker().getPhoneNumber() != null )
- {
- phoneNumbers.add( patient.getHealthWorker().getPhoneNumber() );
- }
- break;
- case PatientReminder.SEND_TO_ORGUGNIT_REGISTERED:
- if ( patient.getOrganisationUnit().getPhoneNumber() != null
- && !patient.getOrganisationUnit().getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( patient.getOrganisationUnit().getPhoneNumber() );
- }
- break;
- case PatientReminder.SEND_TO_USER_GROUP:
- for ( User user : reminder.getUserGroup().getMembers() )
- {
- if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( user.getPhoneNumber() );
- }
- }
- break;
- default:
- if ( patient.getPhoneNumber() != null && !patient.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( patient.getPhoneNumber() );
- }
- break;
- }
- return phoneNumbers;
- }
-
- public String getStringMsgFromTemplateMsg( PatientReminder reminder, ProgramInstance programInstance,
- Patient patient )
- {
- String msg = reminder.getTemplateMessage();
-
- String patientName = patient.getFirstName();
- String organisationunitName = patient.getOrganisationUnit().getName();
- String programName = programInstance.getProgram().getName();
- String daysSinceEnrollementDate = DateUtils.daysBetween( new Date(), programInstance.getEnrollmentDate() ) + "";
- String daysSinceIncidentDate = DateUtils.daysBetween( new Date(), programInstance.getDateOfIncident() ) + "";
- String incidentDate = format.formatDate( programInstance.getDateOfIncident() );
- String erollmentDate = format.formatDate( programInstance.getEnrollmentDate() );
-
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PATIENT_NAME, patientName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_INCIDENT_DATE, incidentDate );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_ENROLLMENT_DATE, erollmentDate );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE, daysSinceEnrollementDate );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE, daysSinceIncidentDate );
-
- return msg;
- }
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SetEventStatusAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SetEventStatusAction.java 2013-08-05 03:00:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SetEventStatusAction.java 2013-08-07 03:44:17 +0000
@@ -28,23 +28,13 @@
package org.hisp.dhis.caseentry.action.reminder;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientReminder;
import org.hisp.dhis.program.ProgramStageInstance;
import org.hisp.dhis.program.ProgramStageInstanceService;
-import org.hisp.dhis.sms.SmsServiceException;
import org.hisp.dhis.sms.outbound.OutboundSms;
-import org.hisp.dhis.sms.outbound.OutboundSmsService;
-import org.hisp.dhis.system.util.DateUtils;
-import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.user.User;
import com.opensymphony.xwork2.Action;
@@ -67,20 +57,6 @@
this.programStageInstanceService = programStageInstanceService;
}
- private CurrentUserService currentUserService;
-
- public void setCurrentUserService( CurrentUserService currentUserService )
- {
- this.currentUserService = currentUserService;
- }
-
- private OutboundSmsService outboundSmsService;
-
- public void setOutboundSmsService( OutboundSmsService outboundSmsService )
- {
- this.outboundSmsService = outboundSmsService;
- }
-
private I18nFormat format;
public void setFormat( I18nFormat format )
@@ -122,7 +98,15 @@
case ProgramStageInstance.COMPLETED_STATUS:
programStageInstance.setCompleted( true );
programStageInstance.setStatus( null );
- sendSMSToCompletedEvent(programStageInstance);
+
+ // Send message when to completed the event
+ List<OutboundSms> psiOutboundSms = programStageInstance.getOutboundSms();
+ if ( psiOutboundSms == null )
+ {
+ psiOutboundSms = new ArrayList<OutboundSms>();
+ }
+ psiOutboundSms.addAll( programStageInstanceService.sendMessages( programStageInstance,
+ PatientReminder.SEND_WHEN_TO_C0MPLETED_EVENT, format ) );
break;
case ProgramStageInstance.VISITED_STATUS:
programStageInstance.setCompleted( false );
@@ -148,126 +132,4 @@
return SUCCESS;
}
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- private void sendSMSToCompletedEvent( ProgramStageInstance programStageInstance )
- {
- Patient patient = programStageInstance.getProgramInstance().getPatient();
-
- if ( patient != null )
- {
- Collection<PatientReminder> reminders = programStageInstance.getProgramStage().getPatientReminders();
- for ( PatientReminder rm : reminders )
- {
- if ( rm != null && rm.getWhenToSend() == PatientReminder.SEND_WHEN_TO_C0MPLETED_EVENT )
- {
- sendEventMessage( rm, programStageInstance, patient );
- }
- }
- }
- }
-
- private void sendEventMessage( PatientReminder reminder, ProgramStageInstance programStageInstance, Patient patient )
- {
- Set<String> phoneNumbers = getPhonenumbers( reminder, patient );
-
- if ( phoneNumbers.size() > 0 )
- {
- String msg = getStringMsgFromTemplateMsg( reminder, programStageInstance, patient );
- try
- {
- OutboundSms outboundSms = new OutboundSms();
- outboundSms.setMessage( msg );
- outboundSms.setRecipients( phoneNumbers );
- outboundSms.setSender( currentUserService.getCurrentUsername() );
- outboundSmsService.sendMessage( outboundSms, null );
-
- List<OutboundSms> outboundSmsList = programStageInstance.getOutboundSms();
- if ( outboundSmsList == null )
- {
- outboundSmsList = new ArrayList<OutboundSms>();
- }
- outboundSmsList.add( outboundSms );
- programStageInstance.setOutboundSms( outboundSmsList );
- }
- catch ( SmsServiceException e )
- {
- e.printStackTrace();
- }
- }
-
- }
-
- public String getStringMsgFromTemplateMsg( PatientReminder reminder, ProgramStageInstance programStageInstance,
- Patient patient )
- {
- String msg = reminder.getTemplateMessage();
-
- String patientName = patient.getFirstName();
- String organisationunitName = patient.getOrganisationUnit().getName();
- String programName = programStageInstance.getProgramInstance().getProgram().getName();
- String programStageName = programStageInstance.getProgramStage().getName();
- String daysSinceDueDate = DateUtils.daysBetween( new Date(), programStageInstance.getDueDate() ) + "";
- String dueDate = format.formatDate( programStageInstance.getDueDate() );
-
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PATIENT_NAME, patientName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_PROGAM_STAGE_NAME, programStageName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_DUE_DATE, dueDate );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
- msg = msg.replace( PatientReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE, daysSinceDueDate );
-
- return msg;
- }
-
- private Set<String> getPhonenumbers( PatientReminder reminder, Patient patient )
- {
- Set<String> phoneNumbers = new HashSet<String>();
-
- switch ( reminder.getSendTo() )
- {
- case PatientReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED:
- Collection<User> users = patient.getOrganisationUnit().getUsers();
- for ( User user : users )
- {
- if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( user.getPhoneNumber() );
- }
- }
- break;
- case PatientReminder.SEND_TO_HEALTH_WORKER:
- if ( patient.getHealthWorker() != null && patient.getHealthWorker().getPhoneNumber() != null )
- {
- phoneNumbers.add( patient.getHealthWorker().getPhoneNumber() );
- }
- break;
- case PatientReminder.SEND_TO_ORGUGNIT_REGISTERED:
- if ( patient.getOrganisationUnit().getPhoneNumber() != null
- && !patient.getOrganisationUnit().getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( patient.getOrganisationUnit().getPhoneNumber() );
- }
- break;
- case PatientReminder.SEND_TO_USER_GROUP:
- for ( User user : reminder.getUserGroup().getMembers() )
- {
- if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( user.getPhoneNumber() );
- }
- }
- break;
- default:
- if ( patient.getPhoneNumber() != null && !patient.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( patient.getPhoneNumber() );
- }
- break;
- }
- return phoneNumbers;
- }
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-08-06 06:33:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-08-07 03:44:17 +0000
@@ -121,8 +121,6 @@
<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
- <property name="outboundSmsService"
- ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
</bean>
<bean
@@ -651,9 +649,6 @@
ref="org.hisp.dhis.program.ProgramStageInstanceService" />
<property name="selectedStateManager"
ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
- <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
- <property name="outboundSmsService"
- ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
</bean>
<bean id="org.hisp.dhis.caseentry.action.patient.SaveDueDateAction"
@@ -1104,9 +1099,6 @@
scope="prototype">
<property name="programStageInstanceService"
ref="org.hisp.dhis.program.ProgramStageInstanceService" />
- <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
- <property name="outboundSmsService"
- ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
</bean>