← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14805: Fixed bug - Show message exactly which rule is violated and which attribute to correct.

 

------------------------------------------------------------
revno: 14805
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-04-12 12:55:36 +0800
message:
  Fixed bug - Show message exactly which rule is violated and which attribute to correct.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceStore.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateTrackedEntityInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js


--
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/TrackedEntityInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java	2014-04-04 17:20:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java	2014-04-12 04:55:36 +0000
@@ -53,6 +53,7 @@
     public static final int ERROR_NONE = 0;
     public static final int ERROR_DUPLICATE_IDENTIFIER = 1;
     public static final int ERROR_ENROLLMENT = 2;
+    public static final String SAPERATOR = "_";
 
     /**
      * Returns a grid with tracked entity instance values based on the given
@@ -428,10 +429,11 @@
      *        null, the system check unique attribute values of the
      *        entityInstance
      * @param format I18nFormat
-     * @return Error code 0 : Validation is OK 1 : The attribute is duplicated 2
-     *         : Violate validation criteria of the program
+     * @return Error code 0 : Validation is OK 
+     *                    1_<duplicate-value> : The attribute value is duplicated 
+     *                    2_<validation-criteria-id> : Violate validation criteria of the program
      */
-    int validateTrackedEntityInstance( TrackedEntityInstance entityInstance, Program program, I18nFormat format );
+    String validateTrackedEntityInstance( TrackedEntityInstance entityInstance, Program program, I18nFormat format );
 
     /**
      * Validate patient enrollment

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceStore.java	2014-04-01 08:58:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceStore.java	2014-04-12 04:55:36 +0000
@@ -235,10 +235,11 @@
      *        null, the system check attribute values of the instances
      * @param format I18nFormat
      * 
-     * @return Error code 0 : Validation is OK 1 : The attribute value is
-     *         duplicated 2 : Violate validation criteria of the program
+     * @return Error code 0 : Validation is OK 
+     *                    1_<duplicate-value> : The attribute value is duplicated 
+     *                    2_<validation-criteria-id> : Violate validation criteria of the program
      */
-    int validate( TrackedEntityInstance entityinstance, Program program, I18nFormat format );
+    String validate( TrackedEntityInstance entityinstance, Program program, I18nFormat format );
 
     /**
      * Validate entity-instance enrollment

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-04-08 15:19:50 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java	2014-04-12 04:55:36 +0000
@@ -877,7 +877,7 @@
     }
 
     @Override
-    public int validateTrackedEntityInstance( TrackedEntityInstance instance, Program program, I18nFormat format )
+    public String validateTrackedEntityInstance( TrackedEntityInstance instance, Program program, I18nFormat format )
     {
         return trackedEntityInstanceStore.validate( instance, program, format );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2014-04-10 14:52:30 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java	2014-04-12 04:55:36 +0000
@@ -100,12 +100,15 @@
 {
     private static final Log log = LogFactory.getLog( HibernateTrackedEntityInstanceStore.class );
 
-    private static final Map<ProgramStatus, Integer> PROGRAM_STATUS_MAP = new HashMap<ProgramStatus, Integer>() { {
-        put( ProgramStatus.ACTIVE, ProgramInstance.STATUS_ACTIVE );
-        put( ProgramStatus.COMPLETED, ProgramInstance.STATUS_COMPLETED );
-        put( ProgramStatus.CANCELLED, ProgramInstance.STATUS_CANCELLED );
-    } };
-    
+    private static final Map<ProgramStatus, Integer> PROGRAM_STATUS_MAP = new HashMap<ProgramStatus, Integer>()
+    {
+        {
+            put( ProgramStatus.ACTIVE, ProgramInstance.STATUS_ACTIVE );
+            put( ProgramStatus.COMPLETED, ProgramInstance.STATUS_COMPLETED );
+            put( ProgramStatus.CANCELLED, ProgramInstance.STATUS_CANCELLED );
+        }
+    };
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -116,7 +119,7 @@
     {
         this.organisationUnitService = organisationUnitService;
     }
-    
+
     private StatementBuilder statementBuilder;
 
     public void setStatementBuilder( StatementBuilder statementBuilder )
@@ -127,7 +130,7 @@
     // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
-    
+
     @Override
     public List<Map<String, String>> getTrackedEntityInstances( TrackedEntityInstanceQueryParams params )
     {
@@ -136,21 +139,18 @@
         // ---------------------------------------------------------------------
         // Select clause
         // ---------------------------------------------------------------------
-        
-        String sql = 
-            "select tei.uid as " + TRACKED_ENTITY_INSTANCE_ID + ", " +
-            "tei.created as " + CREATED_ID + ", " +
-            "tei.lastupdated as " + LAST_UPDATED_ID + ", " +
-            "ou.uid as " + ORG_UNIT_ID + ", " +
-            "te.uid as " + TRACKED_ENTITY_ID + ", ";
-        
+
+        String sql = "select tei.uid as " + TRACKED_ENTITY_INSTANCE_ID + ", " + "tei.created as " + CREATED_ID + ", "
+            + "tei.lastupdated as " + LAST_UPDATED_ID + ", " + "ou.uid as " + ORG_UNIT_ID + ", " + "te.uid as "
+            + TRACKED_ENTITY_ID + ", ";
+
         for ( QueryItem item : params.getAttributes() )
         {
             String col = statementBuilder.columnQuote( item.getItemId() );
-            
+
             sql += col + ".value as " + col + ", ";
         }
-        
+
         sql = removeLastComma( sql ) + " ";
 
         // ---------------------------------------------------------------------
@@ -158,7 +158,7 @@
         // ---------------------------------------------------------------------
 
         sql += getFromWhereClause( params, hlp );
-        
+
         // ---------------------------------------------------------------------
         // Paging clause
         // ---------------------------------------------------------------------
@@ -171,33 +171,33 @@
         // ---------------------------------------------------------------------
         // Query
         // ---------------------------------------------------------------------
-        
+
         Timer t = new Timer().start();
-        
+
         SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
-        
+
         t.getTime( "Tracked entity instance query SQL: " + sql );
-        
-        List<Map<String, String>> list = new ArrayList<Map<String,String>>();
-        
+
+        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
+
         while ( rowSet.next() )
         {
             final Map<String, String> map = new HashMap<String, String>();
-            
+
             map.put( TRACKED_ENTITY_INSTANCE_ID, rowSet.getString( TRACKED_ENTITY_INSTANCE_ID ) );
             map.put( CREATED_ID, rowSet.getString( CREATED_ID ) );
             map.put( LAST_UPDATED_ID, rowSet.getString( LAST_UPDATED_ID ) );
             map.put( ORG_UNIT_ID, rowSet.getString( ORG_UNIT_ID ) );
             map.put( TRACKED_ENTITY_ID, rowSet.getString( TRACKED_ENTITY_ID ) );
-            
+
             for ( QueryItem item : params.getAttributes() )
             {
                 map.put( item.getItemId(), rowSet.getString( item.getItemId() ) );
             }
-            
+
             list.add( map );
         }
-        
+
         return list;
     }
 
@@ -209,7 +209,7 @@
         // ---------------------------------------------------------------------
         // Select clause
         // ---------------------------------------------------------------------
-        
+
         String sql = "select count(tei.uid) as " + TRACKED_ENTITY_INSTANCE_ID + " ";
 
         // ---------------------------------------------------------------------
@@ -221,57 +221,56 @@
         // ---------------------------------------------------------------------
         // Query
         // ---------------------------------------------------------------------
-        
+
         Timer t = new Timer().start();
-        
+
         Integer count = jdbcTemplate.queryForObject( sql, Integer.class );
-        
+
         t.getTime( "Tracked entity instance count SQL: " + sql );
-        
-        return count;        
+
+        return count;
     }
-    
+
     /**
-     * From, join and where clause. For attribute params, restriction is set
-     * in inner join. For query params, restriction is set in where clause.
+     * From, join and where clause. For attribute params, restriction is set in
+     * inner join. For query params, restriction is set in where clause.
      */
     private String getFromWhereClause( TrackedEntityInstanceQueryParams params, SqlHelper hlp )
     {
         final String regexp = statementBuilder.getRegexpMatch();
         final String wordStart = statementBuilder.getRegexpWordStart();
         final String wordEnd = statementBuilder.getRegexpWordEnd();
-        
-        String sql =        
-            "from trackedentityinstance tei " +
-            "inner join trackedentity te on tei.trackedentityid = te.trackedentityid " +
-            "inner join organisationunit ou on tei.organisationunitid = ou.organisationunitid ";
-        
+
+        String sql = "from trackedentityinstance tei "
+            + "inner join trackedentity te on tei.trackedentityid = te.trackedentityid "
+            + "inner join organisationunit ou on tei.organisationunitid = ou.organisationunitid ";
+
         for ( QueryItem item : params.getAttributesAndFilters() )
         {
             final String col = statementBuilder.columnQuote( item.getItemId() );
-            
+
             final String joinClause = item.hasFilter() ? "inner join" : "left join";
-            
-            sql += 
-                joinClause + " trackedentityattributevalue as " + col + " " +
-                "on " + col + ".trackedentityinstanceid = tei.trackedentityinstanceid " +
-                "and " + col + ".trackedentityattributeid = " + item.getItem().getId() + " ";
-            
+
+            sql += joinClause + " trackedentityattributevalue as " + col + " " + "on " + col
+                + ".trackedentityinstanceid = tei.trackedentityinstanceid " + "and " + col
+                + ".trackedentityattributeid = " + item.getItem().getId() + " ";
+
             final String filter = statementBuilder.encode( item.getFilter(), false );
-            
+
             if ( !params.isOrQuery() && item.hasFilter() )
             {
-                final String queryCol = item.isNumeric() ? ( col + ".value" ) : "lower(" + col + ".value)";
-                
-                sql += "and " + queryCol + " " + item.getSqlOperator() + " " + StringUtils.lowerCase( item.getSqlFilter( filter ) ) + " ";
+                final String queryCol = item.isNumeric() ? (col + ".value") : "lower(" + col + ".value)";
+
+                sql += "and " + queryCol + " " + item.getSqlOperator() + " "
+                    + StringUtils.lowerCase( item.getSqlFilter( filter ) ) + " ";
             }
         }
-        
+
         if ( params.isOrganisationUnitMode( OrganisationUnitSelectionMode.DESCENDANTS ) )
         {
             sql += "left join _orgunitstructure ous on tei.organisationunitid = ous.organisationunitid ";
         }
-        
+
         if ( params.hasTrackedEntity() )
         {
             sql += hlp.whereAnd() + " tei.trackedentityid = " + params.getTrackedEntity().getId() + " ";
@@ -280,48 +279,49 @@
         if ( params.isOrganisationUnitMode( OrganisationUnitSelectionMode.DESCENDANTS ) )
         {
             SetMap<Integer, OrganisationUnit> levelOuMap = params.getLevelOrgUnitMap();
-            
+
             for ( Integer level : levelOuMap.keySet() )
             {
-                sql += hlp.whereAnd() + " ous.idlevel" + level + " in (" + getCommaDelimitedString( getIdentifiers( levelOuMap.get( level ) ) ) + ") or ";
+                sql += hlp.whereAnd() + " ous.idlevel" + level + " in ("
+                    + getCommaDelimitedString( getIdentifiers( levelOuMap.get( level ) ) ) + ") or ";
             }
-            
+
             sql = removeLastOr( sql );
         }
         else if ( params.isOrganisationUnitMode( OrganisationUnitSelectionMode.ALL ) )
         {
         }
-        else // SELECTED (default)
+        else
+        // SELECTED (default)
         {
-            sql += hlp.whereAnd() + " tei.organisationunitid in (" + getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ) + ") ";
+            sql += hlp.whereAnd() + " tei.organisationunitid in ("
+                + getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ) + ") ";
         }
-        
+
         if ( params.hasProgram() )
         {
-            sql += 
-                hlp.whereAnd() + " exists (" +
-                "select trackedentityinstanceid from programinstance pi " +
-                "where pi.trackedentityinstanceid=tei.trackedentityinstanceid " +
-                "and pi.programid = " + params.getProgram().getId() + " ";
-            
+            sql += hlp.whereAnd() + " exists (" + "select trackedentityinstanceid from programinstance pi "
+                + "where pi.trackedentityinstanceid=tei.trackedentityinstanceid " + "and pi.programid = "
+                + params.getProgram().getId() + " ";
+
             if ( params.hasProgramStatus() )
             {
                 sql += "and pi.status = " + PROGRAM_STATUS_MAP.get( params.getProgramStatus() + " " );
             }
-            
+
             if ( params.hasProgramDates() )
             {
                 for ( QueryFilter date : params.getProgramDates() )
                 {
                     String filter = statementBuilder.encode( date.getFilter(), false );
-                    
-                    sql += "and pi.enrollmentdate " + date.getSqlOperator() + " " + date.getSqlFilter( filter ) + " ";                    
+
+                    sql += "and pi.enrollmentdate " + date.getSqlOperator() + " " + date.getSqlFilter( filter ) + " ";
                 }
             }
-            
+
             sql += ") ";
         }
-        
+
         if ( params.isOrQuery() && params.hasAttributesOrFilters() )
         {
             sql += hlp.whereAnd() + " (";
@@ -329,27 +329,28 @@
             List<String> queryTokens = getTokens( params.getQuery() );
 
             for ( String queryToken : queryTokens )
-            {  
-                final String query = statementBuilder.encode( queryToken, false );                    
-                
+            {
+                final String query = statementBuilder.encode( queryToken, false );
+
                 sql += "(";
-                
+
                 for ( QueryItem item : params.getAttributesAndFilters() )
                 {
                     final String col = statementBuilder.columnQuote( item.getItemId() );
-                              
-                    sql += "lower(" + col + ".value) " + regexp + " '" + wordStart + StringUtils.lowerCase( query ) + wordEnd + "' or ";                    
+
+                    sql += "lower(" + col + ".value) " + regexp + " '" + wordStart + StringUtils.lowerCase( query )
+                        + wordEnd + "' or ";
                 }
-                
+
                 sql = removeLastOr( sql ) + ") and ";
             }
-            
+
             sql = removeLastAnd( sql ) + ") ";
         }
 
         return sql;
     }
-    
+
     @Override
     @SuppressWarnings( "unchecked" )
     public Collection<TrackedEntityInstance> getByOrgUnit( OrganisationUnit organisationUnit, Integer min, Integer max )
@@ -414,8 +415,10 @@
     public int countGetTrackedEntityInstancesByOrgUnitProgram( OrganisationUnit organisationUnit, Program program )
     {
         String sql = "select count(p.trackedentityinstanceid) from trackedentityinstance p join programinstance pi on p.trackedentityinstanceid=pi.trackedentityinstanceid "
-            + "where p.organisationunitid=" + organisationUnit.getId()
-            + " and pi.programid=" + program.getId()
+            + "where p.organisationunitid="
+            + organisationUnit.getId()
+            + " and pi.programid="
+            + program.getId()
             + " and pi.status=" + ProgramInstance.STATUS_ACTIVE;
 
         return jdbcTemplate.queryForObject( sql, Integer.class );
@@ -449,7 +452,7 @@
         return criteria.list();
     }
 
-    public int validate( TrackedEntityInstance instance, Program program, I18nFormat format )
+    public String validate( TrackedEntityInstance instance, Program program, I18nFormat format )
     {
         if ( instance.getAttributeValues() != null && instance.getAttributeValues().size() > 0 )
         {
@@ -470,6 +473,7 @@
             {
                 Criteria criteria = getCriteria();
                 criteria.createAlias( "attributeValues", "attributeValue" );
+                criteria.createAlias( "attributeValue.attribute", "attribute" );
                 criteria.createAlias( "organisationUnit", "orgunit" );
                 criteria.createAlias( "programInstances", "programInstance" );
 
@@ -483,7 +487,7 @@
                     {
                         Conjunction conjunction = Restrictions.conjunction();
                         conjunction.add( Restrictions.eq( "attributeValue.value", attributeValue.getValue() ) );
-                        conjunction.add( Restrictions.eq( "attributeValue.attribute", attribute ) );
+                        conjunction.add( Restrictions.eq( "attribute", attribute ) );
 
                         if ( attribute.getId() != 0 )
                         {
@@ -518,11 +522,12 @@
 
                 criteria.add( disjunction );
 
-                Number rs = (Number) criteria.setProjection( Projections.rowCount() ).uniqueResult();
+                Number rs = (Number) criteria.setProjection(
+                    Projections.projectionList().add( Projections.property( "attribute.id" ) ) ).uniqueResult();
 
                 if ( rs != null && rs.intValue() > 0 )
                 {
-                    return TrackedEntityInstanceService.ERROR_DUPLICATE_IDENTIFIER;
+                    return TrackedEntityInstanceService.ERROR_DUPLICATE_IDENTIFIER + TrackedEntityInstanceService.SAPERATOR + rs.intValue();
                 }
             }
         }
@@ -533,11 +538,12 @@
 
             if ( validationCriteria != null )
             {
-                return TrackedEntityInstanceService.ERROR_ENROLLMENT;
+                return TrackedEntityInstanceService.ERROR_ENROLLMENT + TrackedEntityInstanceService.SAPERATOR
+                    + validationCriteria.getId();
             }
         }
 
-        return TrackedEntityInstanceService.ERROR_NONE;
+        return TrackedEntityInstanceService.ERROR_NONE + "";
     }
 
     public ValidationCriteria validateEnrollment( TrackedEntityInstance instance, Program program, I18nFormat format )
@@ -966,8 +972,8 @@
         {
             sql += "(select organisationunitid from trackedentityinstance where trackedentityinstanceid=p.trackedentityinstanceid and organisationunitid in ( "
                 + getCommaDelimitedString( getOrganisationUnitIds( orgunits ) ) + " ) ) as orgunitid,";
-            otherWhere += operator + "orgunitid in ( "
-                + getCommaDelimitedString( getOrganisationUnitIds( orgunits ) ) + " ) ";
+            otherWhere += operator + "orgunitid in ( " + getCommaDelimitedString( getOrganisationUnitIds( orgunits ) )
+                + " ) ";
         }
 
         sql = sql.substring( 0, sql.length() - 1 ) + " "; // Removing last comma
@@ -1077,9 +1083,10 @@
         return orgUnitIds;
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     @Override
-    public Collection<TrackedEntityInstance> getByAttributeValue( String searchText, int attributeId, Integer min, Integer max )
+    public Collection<TrackedEntityInstance> getByAttributeValue( String searchText, int attributeId, Integer min,
+        Integer max )
     {
         String hql = "FROM TrackedEntityAttributeValue pav WHERE lower (pav.value) LIKE lower ('%" + searchText
             + "%') AND pav.attribute.id =:attributeId order by pav.entityInstance";

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateTrackedEntityInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateTrackedEntityInstanceAction.java	2014-04-06 15:48:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/ValidateTrackedEntityInstanceAction.java	2014-04-12 04:55:36 +0000
@@ -38,6 +38,7 @@
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.struts2.ServletActionContext;
+import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
@@ -48,6 +49,7 @@
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
+import org.hisp.dhis.validation.ValidationCriteriaService;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
@@ -74,6 +76,9 @@
 
     @Autowired
     private TrackedEntityAttributeService patientAttributeService;
+    
+    @Autowired
+    private ValidationCriteriaService validationCriteriaService;
 
     private I18nFormat format;
 
@@ -82,6 +87,13 @@
         this.format = format;
     }
 
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -148,7 +160,7 @@
                     {
                         value = format.formatDate( TrackedEntityAttribute.getDateFromAge( Integer.parseInt( value ) ) );
                     }
-                    
+
                     attributeValue.setValue( value );
                     attributeValues.add( attributeValue );
                 }
@@ -161,9 +173,20 @@
         // Validate entityInstance
         // ---------------------------------------------------------------------
 
-        int errorCode = entityInstanceService.validateTrackedEntityInstance( entityInstance, program, format );
-
-        message = errorCode + "";
+        String[] errorCode = entityInstanceService.validateTrackedEntityInstance( entityInstance, program, format )
+            .split( "_" );
+        int code = Integer.parseInt( errorCode[0] );
+        
+        if ( code == TrackedEntityInstanceService.ERROR_DUPLICATE_IDENTIFIER )
+        {
+            message = i18n.getString( "duplicate_value_of" ) + " "
+                + attributeService.getTrackedEntityAttribute( Integer.parseInt( errorCode[1] ) ).getDisplayName();
+        }
+        else if ( code == TrackedEntityInstanceService.ERROR_ENROLLMENT )
+        {
+            message = i18n.getString( "violate_validation" ) + " "
+                + validationCriteriaService.getValidationCriteria( Integer.parseInt( errorCode[1] ) ).getDisplayName();
+        }
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2014-04-11 00:54:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2014-04-12 04:55:36 +0000
@@ -684,4 +684,5 @@
 children = Children
 cancelled_enrollments_only = Cancelled enrollments only
 all_statuses = All statuses
-event_date = Event date
\ No newline at end of file
+event_date = Event date
+duplicate_value_of = Duplicate value of
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js	2014-04-12 02:10:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/trackedEntityInstance.js	2014-04-12 04:55:36 +0000
@@ -100,15 +100,9 @@
 			if (message == 0) {
 				return true;
 			} else {
-				if (message == 1) {
-					setMessage(i18n_adding_tracked_entity_instance_failed + ':'
-							+ '\n' + i18n_duplicate_identifier);
-				} else if (message == 2) {
-					setMessage(i18n_adding_tracked_entity_instance_failed
-							+ ':'
-							+ '\n'
-							+ i18n_this_tracked_entity_instance_could_not_be_enrolled_please_check_validation_criteria);
-				}
+				if (message != "") {
+					setMessage(message);
+				} 
 				$("#entityInstanceForm :input").attr("disabled", false);
 				$("#entityInstanceForm").find("select").attr("disabled", false);
 				return false;