dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32974
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16777: Fixed bug - The attribtue values doesn't displayed properly in sms messsage ( Schedule automated ...
------------------------------------------------------------
revno: 16777
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-09-23 15:08:17 +0700
message:
Fixed bug - The attribtue values doesn't displayed properly in sms messsage ( Schedule automated message reminder function )
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminder.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminderService.java
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/trackedentity/DefaultTrackedEntityInstanceReminderService.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-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminder.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminder.java 2014-06-13 10:58:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminder.java 2014-09-23 08:08:17 +0000
@@ -28,11 +28,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.regex.Pattern;
+
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
@@ -50,6 +53,10 @@
{
private static final long serialVersionUID = 3101502417481903219L;
+ public static final String ATTRIBUTE = "attributeid";
+
+ public static final Pattern ATTRIBUTE_PATTERN = Pattern.compile( "\\{(" + ATTRIBUTE + ")=(\\w+)\\}" );
+
public static final String DUE_DATE_TO_COMPARE = "duedate";
public static final String ENROLLEMENT_DATE_TO_COMPARE = "enrollmentdate";
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminderService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminderService.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminderService.java 2014-09-23 08:08:17 +0000
@@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.List;
import java.util.Set;
import org.hisp.dhis.i18n.I18nFormat;
@@ -107,4 +108,6 @@
* @return The list of DHIS users
*/
Set<User> getUsers( TrackedEntityInstanceReminder instanceReminder, TrackedEntityInstance instance );
+
+ List<String> getAttributeUids( String message );
}
=== 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-08-31 09:04:30 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2014-09-23 08:08:17 +0000
@@ -56,6 +56,8 @@
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;
/**
@@ -76,6 +78,9 @@
this.programInstanceService = programInstanceService;
}
+ @Autowired
+ private TrackedEntityInstanceReminderService reminderService;
+
// -------------------------------------------------------------------------
// Implemented methods
// -------------------------------------------------------------------------
@@ -133,10 +138,24 @@
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 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 programStageName = rs.getString( "programStageName" );
@@ -148,7 +167,7 @@
message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DUE_DATE, dueDate );
message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
message = message.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE, daysSinceDueDate );
- }
+
SchedulingProgramObject schedulingProgramObject = new SchedulingProgramObject();
schedulingProgramObject.setProgramStageInstanceId( rs.getInt( "programstageinstanceid" ) );
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceReminderService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceReminderService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceReminderService.java 2014-09-23 08:08:17 +0000
@@ -28,22 +28,22 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder.ATTRIBUTE;
+import static org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder.ATTRIBUTE_PATTERN;
+
+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 java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
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.trackedentity.TrackedEntityInstance;
-import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
-import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder;
-import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminderService;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserService;
@@ -57,10 +57,6 @@
public class DefaultTrackedEntityInstanceReminderService
implements TrackedEntityInstanceReminderService
{
- private static final String ATTRIBUTE = "attributeid";
-
- private static final Pattern ATTRIBUTE_PATTERN = Pattern.compile( "\\{(" + ATTRIBUTE + ")=(\\w+)\\}" );
-
// -------------------------------------------------------------------------
// Dependency
// -------------------------------------------------------------------------
@@ -195,6 +191,25 @@
return templateMessage;
}
+
+ @Override
+ public List<String> getAttributeUids( String message )
+ {
+ List<String> atttributeUids = new ArrayList<String>();
+
+ Matcher matcher = ATTRIBUTE_PATTERN.matcher( message );
+
+ while ( matcher.find() )
+ {
+ if ( matcher.group( 1 ).equals( ATTRIBUTE ) )
+ {
+ String uid = matcher.group( 2 );
+ atttributeUids.add( uid );
+ }
+ }
+
+ return atttributeUids;
+ }
@Override
public Set<String> getPhonenumbers( TrackedEntityInstanceReminder reminder, TrackedEntityInstance entityInstance )