=== 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-03-21 09:29:10 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java 2014-05-12 14:37:40 +0000 @@ -77,7 +77,11 @@ public static String OBJECT_TRACKED_ENTITY_PROGRAM_STAGE_PROPERTY = "PC"; public static String OBJECT_ORGUNIT_COMPLETE_PROGRAM_STAGE = "PSIC"; - + + public static String FORMULA_AGE = "age"; + + public static String FORMULA_VISIT = "visit"; + public static String OBJECT_PROGRAM_PROPERTY_INCIDENT_DATE = "dateOfIncident"; public static String OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE = "enrollmentDate"; === 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-03-25 06:23:18 +0000 +++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java 2014-05-12 14:37:40 +0000 @@ -652,17 +652,30 @@ private String getConditionForTrackedEntityAttribute( String attributeId, Collection orgunitIds, boolean isExist ) { - String sql = " SELECT * FROM trackedentityattributevalue _pav " - + " WHERE _pav.trackedentityinstanceid=pi.trackedentityinstanceid "; + String sql = " SELECT * FROM trackedentityattributevalue _pav "; + if ( attributeId.split( SEPARATOR_ID ).length == 2 ) { - attributeId = attributeId.split( SEPARATOR_ID )[0]; - sql += " AND _pav.trackedentityattributeid=" + attributeId + " AND DATE(now()) - DATE( _pav.value ) "; + if ( attributeId.split( SEPARATOR_ID )[1].equals( CaseAggregationCondition.FORMULA_VISIT ) ) + { + sql += " inner join programinstance _pi on _pav.trackedentityinstanceid=_pi.trackedentityinstanceid "; + sql += " inner join programstageinstance _psi on _pi.programinstanceid=_psi.programinstanceid "; + + attributeId = attributeId.split( SEPARATOR_ID )[0]; + sql += " WHERE _pav.patientid=pi.patientid AND _pav.trackedentityattributeid=" + attributeId + " AND DATE(_psi.executiondate) - DATE( _pav.value ) "; + } + else if ( attributeId.split( SEPARATOR_ID )[1].equals( CaseAggregationCondition.FORMULA_AGE ) ) + { + sql += " inner join programinstance _pi on _pav.trackedentityinstanceid=_pi.trackedentityinstanceid "; + + attributeId = attributeId.split( SEPARATOR_ID )[0]; + sql += " WHERE _pav.patientid=pi.patientid AND _pav.trackedentityattributeid=" + attributeId + " AND DATE(_psi.enrollmentdate) - DATE( _pav.value ) "; + } } else { - sql += " AND _pav.trackedentityattributeid=" + attributeId + " AND _pav.value "; + sql += " WHERE _pav.patientid=pi.patientid AND _pav.trackedentityattributeid=" + attributeId + " AND _pav.value "; } if ( isExist ) === 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-05-10 06:45:30 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/caseAggregationForm.vm 2014-05-12 14:37:40 +0000 @@ -81,7 +81,9 @@ #foreach($attribute in $attributes) #if($attribute.valueType=='age') #set($attId=$attribute.id + ".age") - + #set($attVisitId=$attribute.id + ".visit") + + #else #end