=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java 2014-05-12 14:37:40 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java 2014-08-29 06:39:13 +0000 @@ -91,6 +91,8 @@ public static String MINUS_OPERATOR = "DATEDIFF"; public static String MINUS_DATAELEMENT_OPERATOR = "DEDATEDIFF"; + + public static String MINUS_ATTRIBUTE_OPERATOR = "ATTRDATEDIFF"; public static String AUTO_STORED_BY = "aggregated_from_tracker"; @@ -108,6 +110,10 @@ + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "([0-9]+" + SEPARATOR_ID + "[0-9]+" + SEPARATOR_ID + "[0-9]+)+\\])\\s*(,)\\s*(\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "([0-9]+" + SEPARATOR_ID + "[0-9]+" + SEPARATOR_ID + "[0-9]+)+\\])\\s*\\)\\s*(>=|<=|!=|>|<|=){1}\\s*([0-9]+)"; + public static final String minusAttributeRegExp = MINUS_ATTRIBUTE_OPERATOR + "{1}\\s*\\(\\s*(\\[" + + OBJECT_TRACKED_ENTITY_ATTRIBUTE + SEPARATOR_OBJECT + "([0-9]+)+\\])\\s*(,)\\s*(\\[" + + OBJECT_TRACKED_ENTITY_ATTRIBUTE + SEPARATOR_OBJECT + "([0-9]+)+\\])\\s*\\)\\s*(>=|<=|!=|>|<|=){1}\\s*([0-9]+)"; + // ------------------------------------------------------------------------- // Fields === modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java' --- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java 2014-08-26 12:43:04 +0000 +++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java 2014-08-29 06:39:13 +0000 @@ -507,7 +507,7 @@ String sqlOrgunitCompleted = ""; - // Get minus(date dataelement, date dataelement) out from the expression + // Get minus(DATE dataelement, DATE dataelement) out from the expression // and run them later Map minus2SQLMap = new HashMap<>(); @@ -530,6 +530,29 @@ idx2++; } + // Get minus(DATE attribute, DATE attribute) out from the expression + // and run them later + + Map minus2AttributeSQLMap = new HashMap<>(); + int idx1 = 0; + Pattern patternAttrMinus2 = Pattern.compile( CaseAggregationCondition.minusAttributeRegExp ); + Matcher matcherAttrMinus2 = patternAttrMinus2.matcher( caseExpression ); + while ( matcherAttrMinus2.find() ) + { + String attribute1 = matcherAttrMinus2.group( 2 ); + String attribute2 = matcherAttrMinus2.group( 5 ); + String compareSide = matcherAttrMinus2.group( 6 ) + matcherAttrMinus2.group( 7 ); + minus2AttributeSQLMap.put( + idx1, + getConditionForMisus2Attribute(attribute1, attribute2, compareSide )); + + caseExpression = caseExpression.replace( matcherAttrMinus2.group( 0 ), + CaseAggregationCondition.MINUS_ATTRIBUTE_OPERATOR + "_" + idx1 ); + + idx1++; + } + + // Get minus(date dataelement, date) out from the expression and run // them later @@ -669,6 +692,13 @@ sql = sql .replace( CaseAggregationCondition.MINUS_DATAELEMENT_OPERATOR + "_" + key, minus2SQLMap.get( key ) ); } + + for ( int key = 0; key < idx1; key++ ) + { + sql = sql + .replace( CaseAggregationCondition.MINUS_ATTRIBUTE_OPERATOR + "_" + key, minus2AttributeSQLMap.get( key ) ); + } + return sql + " ) "; } @@ -949,6 +979,18 @@ + endDate + "' ) AS d2 WHERE DATE(d1.value ) - DATE(d2.value) " + compareSide; } + + private String getConditionForMisus2Attribute(String attribute1, String attribute2, String compareSide) + { + return " EXISTS ( SELECT * FROM ( SELECT _teav.value FROM trackedentityattributevalue _teav " + + " WHERE _teav.trackedentityinstanceid=p.trackedentityinstanceid " + + " and _teav.trackedentityattributeid = " + attribute1 + " ) as a1 , " + + " ( SELECT _teav.value FROM trackedentityattributevalue _teav " + + " WHERE _teav.trackedentityinstanceid=p.trackedentityinstanceid " + + " and _teav.trackedentityattributeid = " + attribute2 + " ) as a2 " + + " WHERE DATE(a1.value ) - DATE(a2.value) " + compareSide; + } + /** * Return the Ids of organisation units which entity instances registered or === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties 2014-08-18 14:21:48 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/org/hisp/dhis/trackedentity/i18n_module.properties 2014-08-29 06:39:13 +0000 @@ -504,4 +504,5 @@ auto_save_tracked_entity_registration_forms = Auto-save tracked entity registration forms filter_by_program = Filter by program enter_an_attribute = Enter an attribute -enter_a_key = Enter a key \ No newline at end of file +enter_a_key = Enter a key +minus_with_attribute = Attribute date diff \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/caseAggregationForm.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/caseAggregationForm.vm 2014-08-11 13:54:43 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/caseAggregationForm.vm 2014-08-29 06:39:13 +0000 @@ -180,6 +180,7 @@ +