← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16786: Fixed bug - The attribtue values doesn't displayed properly in sms messsages of program-instances...

 

------------------------------------------------------------
revno: 16786
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-09-23 22:47:39 +0700
message:
  Fixed bug - The attribtue values doesn't displayed properly in sms messsages of program-instances ( Schedule automated message reminder function )
modified:
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java


--
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-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java	2014-09-23 15:47:39 +0000
@@ -28,6 +28,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+
 import org.hibernate.Criteria;
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Projections;
@@ -38,15 +44,13 @@
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramInstanceStore;
 import org.hisp.dhis.program.SchedulingProgramObject;
+import org.hisp.dhis.system.util.TextUtils;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder;
+import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminderService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.support.rowset.SqlRowSet;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-
 /**
  * @author Abyot Asalefew
  */
@@ -54,6 +58,9 @@
     extends HibernateIdentifiableObjectStore<ProgramInstance>
     implements ProgramInstanceStore
 {
+    @Autowired
+    private TrackedEntityInstanceReminderService reminderService;
+    
     // -------------------------------------------------------------------------
     // Implemented methods
     // -------------------------------------------------------------------------
@@ -258,27 +265,41 @@
 
         while ( rs.next() )
         {
-            String message = "";
-            for ( int i = 1; i <= cols; i++ )
+             String message = rs.getString( "templatemessage" );
+
+            List<String> attributeUids = reminderService.getAttributeUids( message );
+            SqlRowSet attributeValueRow = jdbcTemplate
+                .queryForRowSet( "select tea.uid ,teav.value from trackedentityattributevalue teav "
+                    + " INNER JOIN trackedentityattribute tea on tea.trackedentityattributeid=teav.trackedentityattributeid "
+                    + " INNER JOIN programinstance ps on teav.trackedentityinstanceid=ps.trackedentityinstanceid "
+                    + " INNER JOIN programstageinstance psi on ps.programinstanceid=psi.programinstanceid "
+                    + " where tea.uid in ( " + TextUtils.getQuotedCommaDelimitedString( attributeUids ) + ") " );
+
+            while ( attributeValueRow.next() )
             {
-                message = rs.getString( "templatemessage" );
-                String organisationunitName = rs.getString( "orgunitName" );
-                String programName = rs.getString( "programName" );
-                String incidentDate = rs.getString( "dateofincident" ).split( " " )[0];
-                String daysSinceIncidentDate = rs.getString( "days_since_incident_date" );
-                String erollmentDate = rs.getString( "enrollmentdate" ).split( " " )[0];
-                String daysSinceEnrollementDate = rs.getString( "days_since_erollment_date" );
-
-                message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
-                message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
-                message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_INCIDENT_DATE, incidentDate );
-                message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_ENROLLMENT_DATE, erollmentDate );
-                message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE,
-                    daysSinceEnrollementDate );
-                message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE,
-                    daysSinceIncidentDate );
+                String uid = attributeValueRow.getString( "uid" );
+                String value = attributeValueRow.getString( "value" );
+                String key = "\\{(" + TrackedEntityInstanceReminder.ATTRIBUTE + ")=(" + uid + ")\\}";
+                message = message.replaceAll( key, value );
             }
 
+            String organisationunitName = rs.getString( "orgunitName" );
+            String programName = rs.getString( "programName" );
+            String incidentDate = rs.getString( "dateofincident" ).split( " " )[0];
+            String daysSinceIncidentDate = rs.getString( "days_since_incident_date" );
+            String erollmentDate = rs.getString( "enrollmentdate" ).split( " " )[0];
+            String daysSinceEnrollementDate = rs.getString( "days_since_erollment_date" );
+
+            message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
+            message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME,
+                organisationunitName );
+            message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_INCIDENT_DATE, incidentDate );
+            message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_ENROLLMENT_DATE, erollmentDate );
+            message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE,
+                daysSinceEnrollementDate );
+            message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE,
+                daysSinceIncidentDate );
+            
             SchedulingProgramObject schedulingProgramObject = new SchedulingProgramObject();
             schedulingProgramObject.setProgramInstanceId( rs.getInt( "programinstanceid" ) );
             schedulingProgramObject.setPhoneNumber( rs.getString( "phonenumber" ) );

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2014-09-23 09:51:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2014-09-23 15:47:39 +0000
@@ -153,7 +153,7 @@
                 String key = "\\{(" + TrackedEntityInstanceReminder.ATTRIBUTE + ")=(" + uid + ")\\}";
                 message = message.replaceAll( key, value );
             }  
-                          
+            
             String organisationunitName = rs.getString( "orgunitName" );
             String programName = rs.getString( "programName" );
             String programStageName = rs.getString( "programStageName" );