← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11349: Add Aggregate Query Builder formula for calculaling the number of days between 2 Date-data element.

 

------------------------------------------------------------
revno: 11349
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-07-05 14:05:20 +0700
message:
  Add Aggregate Query Builder formula for calculaling the number of days between 2 Date-data element.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportDataEntryForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/caseaggregation/GetAllCaseAggregationConditionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationList.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/caseaggregation.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/listPatientIdentifierType.vm


--
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/caseaggregation/CaseAggregationCondition.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java	2013-06-18 02:41:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java	2013-07-05 07:05:20 +0000
@@ -89,6 +89,8 @@
 
     public static String MINUS_OPERATOR = "DATEDIFF";
 
+    public static String MINUS_DATAELEMENT_OPERATOR = "DEDATEDIFF";
+
     public static String AUTO_STORED_BY = "DHIS-SYSTEM";
 
     public static final String regExp = "\\[(" + OBJECT_ORGUNIT_COMPLETE_PROGRAM_STAGE + "|" + OBJECT_PATIENT + "|"
@@ -102,6 +104,11 @@
         + "[0-9]+)+\\])\\s*(,)+\\s*(" + OBJECT_PROGRAM_PROPERTY_INCIDENT_DATE + "|"
         + OBJECT_PROGRAM_PROPERTY_REPORT_DATE_DATE + "|" + OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE + ")+\\s*\\)\\s*";
 
+    public static final String minusDataelementRegExp = MINUS_DATAELEMENT_OPERATOR + "{1}\\s*\\(\\s*(\\["
+        + 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]+)";
+
     // -------------------------------------------------------------------------
     // Fields
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java	2013-06-18 03:33:56 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java	2013-07-05 07:05:20 +0000
@@ -346,7 +346,7 @@
                 if ( hasPatients )
                 {
                     sql += "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid ";
-                    sql += "INNER JOIN patient p on p.patientid=pi.patientid  ";
+                    sql += "INNER JOIN patient p on p.patientid=pi.patientid ";
                 }
                 else if ( (hasProgramInstances && !hasPatients)
                     || operator.equals( CaseAggregationCondition.AGGRERATION_COUNT ) )
@@ -607,7 +607,31 @@
 
         String sqlOrgunitCompleted = "";
 
-        // Get minus(date, date) out from the expression and run them later
+        // Get minus(date dataelement, date dataelement) out from the expression
+        // and run them later
+
+        Map<Integer, String> minus2SQLMap = new HashMap<Integer, String>();
+        int idx2 = 0;
+        Pattern patternMinus2 = Pattern.compile( CaseAggregationCondition.minusDataelementRegExp );
+        Matcher matcherMinus2 = patternMinus2.matcher( caseExpression );
+        while ( matcherMinus2.find() )
+        {
+            String[] ids1 = matcherMinus2.group( 2 ).split( SEPARATOR_ID );
+            String[] ids2 = matcherMinus2.group( 5 ).split( SEPARATOR_ID );
+
+            minus2SQLMap.put(
+                idx2,
+                getConditionForMisus2DataElement( orgunitIds, ids1[1], ids1[2], ids2[1], ids2[2],
+                    matcherMinus2.group( 6 ) + matcherMinus2.group( 7 ), startDate, endDate ) );
+
+            caseExpression = caseExpression.replace( matcherMinus2.group( 0 ),
+                CaseAggregationCondition.MINUS_DATAELEMENT_OPERATOR + "_" + idx2 );
+
+            idx2++;
+        }
+
+        // Get minus(date dataelement, date) out from the expression and run
+        // them later
 
         Map<Integer, String> minusSQLMap = new HashMap<Integer, String>();
         int idx = 0;
@@ -746,6 +770,12 @@
             sql = sql.replace( CaseAggregationCondition.MINUS_OPERATOR + "_" + key, minusSQLMap.get( key ) );
         }
 
+        for ( int key = 0; key < idx2; key++ )
+        {
+            sql = sql
+                .replace( CaseAggregationCondition.MINUS_DATAELEMENT_OPERATOR + "_" + key, minus2SQLMap.get( key ) );
+        }
+
         return sql + " ) ";
 
     }
@@ -984,6 +1014,28 @@
             + "                 AND ( DATE(_pdv.value) - DATE(" + compareSide + ") ) ";
     }
 
+    private String getConditionForMisus2DataElement( Collection<Integer> orgunitIds, String programStageId1,
+        String dataElementId1, String programStageId2, String dataElementId2, String compareSide, String startDate,
+        String endDate )
+    {
+        return " EXISTS ( SELECT * FROM ( SELECT  * FROM patientdatavalue _pdv INNER JOIN programstageinstance _psi "
+            + "                         ON _pdv.programstageinstanceid=_psi.programstageinstanceid "
+            + "                 JOIN programinstance _pi ON _pi.programinstanceid=_psi.programinstanceid "
+            + "           WHERE psi.programstageinstanceid=_pdv.programstageinstanceid and _pdv.dataelementid= " + dataElementId1 
+            + "                 AND _psi.organisationunitid in ("+ TextUtils.getCommaDelimitedString( orgunitIds )+") "
+            + "                 AND _psi.programstageid = " + programStageId1
+            + "                 AND _psi.executionDate>='" + startDate + "'  "
+            + "                 AND _psi.executionDate <= '" + endDate + "' ) AS d1 cross join "
+            + "         (  SELECT * FROM patientdatavalue _pdv INNER JOIN programstageinstance _psi "
+            + "                        ON _pdv.programstageinstanceid=_psi.programstageinstanceid "
+            + "                  JOIN programinstance _pi ON _pi.programinstanceid=_psi.programinstanceid "
+            + "           WHERE psi.programstageinstanceid=_pdv.programstageinstanceid and _pdv.dataelementid= " + dataElementId2
+            + "                 AND _psi.organisationunitid in ("+ TextUtils.getCommaDelimitedString( orgunitIds )+") "
+            + "                 AND _psi.programstageid =  " + programStageId2
+            + "                 AND _psi.executionDate>='" + startDate + "'  "
+            + "                 AND _psi.executionDate <= '" + endDate + "' ) AS d2 WHERE DATE(d1.value ) - DATE(d2.value) " + compareSide;
+    }
+
     /**
      * Return the Ids of organisation units which patients registered or events
      * happened.

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportDataEntryForm.vm	2013-06-12 04:19:18 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportDataEntryForm.vm	2013-07-05 07:05:20 +0000
@@ -12,12 +12,11 @@
 				</td>
 				<td class='coordinates2'>
 					$encoder.htmlEncode( $patient.getFullName() ) 
-					( #if($patient.gender=='F')
-							<img src='images/female_small.png'>
-						#else
-							<img src='images/male_small.png'>
-						#end
-					)
+					#if($patient.gender=='F')
+						<img src='images/female_small.png'>
+					#else
+						<img src='images/male_small.png'>
+					#end
 				</td>
 				<td class='bold coordinates1'>$i18n.getString('program'):</td>
 				<td class='coordinates2'>$program.displayName</td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/caseaggregation/GetAllCaseAggregationConditionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/caseaggregation/GetAllCaseAggregationConditionAction.java	2013-05-30 09:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/caseaggregation/GetAllCaseAggregationConditionAction.java	2013-07-05 07:05:20 +0000
@@ -30,6 +30,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 
 import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
@@ -105,16 +106,17 @@
     public String execute()
         throws Exception
     {
-        dataSets = new ArrayList<DataSet>( dataSetService.getAllDataSets() );
+        Collection<DataSet> _datasets = new HashSet<DataSet>();
         aggregationConditions = aggregationConditionService.getAllCaseAggregationCondition();
 
         for ( CaseAggregationCondition aggCondition : aggregationConditions )
         {
             DataElement dataElement = aggCondition.getAggregationDataElement();
 
-            dataSets.addAll( dataElement.getDataSets() );
+            _datasets.addAll( dataElement.getDataSets() );
         }
 
+        dataSets = new ArrayList<DataSet>( _datasets );
         Collections.sort( dataSets, IdentifiableObjectNameComparator.INSTANCE );
 
         if ( dataSetId != null )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-07-02 14:26:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-07-05 07:05:20 +0000
@@ -347,6 +347,7 @@
             programStage.setDescription( description );
             programStage.setProgram( program );
             programStage.setMinDaysFromStart( 0 );
+            programStage.setAutoGenerateEvent( true );
             programStage.setReportDateDescription( REPORT_DATE_DESCRIPTION );
 
             programStageService.saveProgramStage( programStage );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-07-04 05:57:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-07-05 07:05:20 +0000
@@ -440,4 +440,5 @@
 deathDate = Date of death
 isDead = Is dead
 healthWorker = Health worker
-create_default_registration_form = Create default registration form
\ No newline at end of file
+create_default_registration_form = Create default registration form
+minus_with_dataelement = Data Element Date Diff
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm	2013-07-04 13:09:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm	2013-07-05 07:05:20 +0000
@@ -146,6 +146,7 @@
 			<input type='button' style="width:175px;" onclick='insertOperator( "DATEDIFF( , dateOfIncident) " );' value="$i18n.getString('minus_with_dateOfIncident')" />
 			<input type='button' style="width:175px;" onclick='insertOperator( "DATEDIFF( , enrollmentDate) " );' value="$i18n.getString('minus_with_enrollmentDate')" />
 			<input type='button' style="width:175px;" onclick='insertOperator( "DATEDIFF( , executionDate) " );' value="$i18n.getString('minus_with_executionDate')" />
+			<input type='button' style="width:175px;" onclick='insertOperator( "DEDATEDIFF( , ) " );' value="$i18n.getString('minus_with_dataelement')" />
 			<span style='padding-left:110px'>
 				<input type='button' style="width:45px;" align="right" alt="$i18n.getString( 'clear' )" onclick="byId('aggregationCondition').value='';" value="$i18n.getString('clear')" />
 			</span>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationList.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationList.vm	2013-05-17 08:24:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationList.vm	2013-07-05 07:05:20 +0000
@@ -1,5 +1,6 @@
+#set($mark=false)
 #foreach( $aggregationCondition in $aggregationConditions )
-	<tr id="tr${aggregationCondition.id}">
+	<tr id="tr${aggregationCondition.id}" #alternate( $mark )>
 		<td onclick="javascript:showCaseAggregationDetails( $aggregationCondition.id )" >$encoder.htmlEncode( $aggregationCondition.displayName )</td>                
 		<td>
 		  <a href="showUpdateCaseAggregationForm.action?id=$aggregationCondition.id&dataSetId=$!dataSetId" title="$i18n.getString( "edit" )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a>
@@ -8,4 +9,5 @@
 		  <a href="javascript:showCaseAggregationDetails( $aggregationCondition.id )" title="$i18n.getString( "show_details" )"><img src="../images/information.png" alt="$i18n.getString( 'show_details' )"></a>
 		</td>
 	</tr>
+	#set($mark=!$mark)
 #end
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/caseaggregation.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/caseaggregation.js	2013-07-04 13:09:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/caseaggregation.js	2013-07-05 07:05:20 +0000
@@ -423,6 +423,7 @@
 		}
 		, function( html ) 
 		{
+			setTableStyles();
 			setInnerHTML('list', html );
 		} );
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/listPatientIdentifierType.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/listPatientIdentifierType.vm	2013-07-03 15:40:29 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/listPatientIdentifierType.vm	2013-07-05 07:05:20 +0000
@@ -23,7 +23,7 @@
               
                 <td onclick="showPatientIdentifierTypeDetails( $identifierType.id )">$encoder.htmlEncode( $identifierType.displayName )</td>                
                 
-                <td style="text-align:center"#alternate( $mark )>
+                <td style="text-align:center" #alternate( $mark )>
                   <a href="showUpdatePatientIdentifierTypeForm.action?id=$identifierType.id" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a>
                   <a href="javascript:translate( 'PatientIdentifierType', '$identifierType.id' )" title="$i18n.getString( 'translation_translate' )"><img src="../images/i18n.png" alt="$i18n.getString( 'translation_translate' )"/></a>
 				  <a href="javascript:removePatientIdentifierType( '$identifierType.id', '$encoder.jsEncode( $identifierType.displayName )' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"></a>