dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22555
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10866: Allow to define formulas based on the difference between Date data element with IncidentDate/Enro...
------------------------------------------------------------
revno: 10866
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-17 15:24:11 +0700
message:
Allow to define formulas based on the difference between Date data element with IncidentDate/EnrollmentDate in Aggregate Query Builder function
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-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/caseAggregation.vm
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
--
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-05-02 03:31:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java 2013-05-17 08:24:11 +0000
@@ -84,6 +84,8 @@
public static String OBJECT_PROGRAM_PROPERTY_INCIDENT_DATE = "dateOfIncident";
public static String OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE = "enrollmentDate";
+
+ public static String MINUS_OPERATOR = "MINUS";
public static String AUTO_STORED_BY = "DHIS-SYSTEM";
@@ -93,6 +95,10 @@
+ OBJECT_PATIENT_ATTRIBUTE + "|" + OBJECT_PATIENT_PROPERTY + "|" + OBJECT_PROGRAM_PROPERTY + ")"
+ SEPARATOR_OBJECT + "([a-zA-Z0-9@#\\- ]+[" + SEPARATOR_ID + "[a-zA-Z0-9]*]*)" + "\\]";
+ public static final String dataelementRegExp = MINUS_OPERATOR + "{1}\\s*\\(\\s*(\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT
+ + SEPARATOR_OBJECT + "([0-9]+" + SEPARATOR_ID + "[0-9]+" + SEPARATOR_ID + "[0-9]+)+\\])\\s*(,)+\\s*("
+ + OBJECT_PROGRAM_PROPERTY_INCIDENT_DATE + "|" + OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE + ")+\\s*\\)\\s*";
+
// -------------------------------------------------------------------------
// 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-05-14 09:31:21 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java 2013-05-17 08:24:11 +0000
@@ -49,8 +49,10 @@
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Future;
import java.util.regex.Matcher;
@@ -365,7 +367,7 @@
sql += "GROUP BY ou.organisationunitid, ou.name";
}
-
+ System.out.println( "\n\n === \n " + sql );
sql = sql.replaceAll( "COMBINE", "" );
return sql;
@@ -584,6 +586,28 @@
String sqlOrgunitCompleted = "";
+ // Get minus(date, date) out from the expression and run them later
+
+ Map<Integer, String> minusSQLMap = new HashMap<Integer, String>();
+ int idx = 0;
+ Pattern patternMinus = Pattern.compile( CaseAggregationCondition.dataelementRegExp );
+ Matcher matcherMinus = patternMinus.matcher( caseExpression );
+ while ( matcherMinus.find() )
+ {
+ String[] ids = matcherMinus.group( 2 ).split( SEPARATOR_ID );
+
+ minusSQLMap.put(
+ idx,
+ getConditionForMinusDataElement( orgunitIds, Integer.parseInt( ids[1] ), Integer.parseInt( ids[2] ),
+ matcherMinus.group( 4 ), startDate, endDate ) );
+
+ caseExpression = caseExpression.replace( matcherMinus.group( 0 ), CaseAggregationCondition.MINUS_OPERATOR
+ + "_" + idx );
+
+ idx++;
+ }
+
+ // Run nornal expression
String[] expression = caseExpression.split( "(AND|OR)" );
caseExpression = caseExpression.replaceAll( "AND", " ) AND " );
caseExpression = caseExpression.replaceAll( "OR", " ) OR " );
@@ -696,7 +720,14 @@
sql = sql.replaceAll( IN_CONDITION_END_SIGN, ")" );
sql = sql.replaceAll( IS_NULL, " " );
+ System.out.println("\n\n minusSQLMap " + minusSQLMap );
+ for ( int key = 0; key < idx; key++ )
+ {
+ sql = sql.replace( CaseAggregationCondition.MINUS_OPERATOR + "_" + key, minusSQLMap.get( key ) );
+ }
+
return sql + " ) ";
+
}
/**
@@ -714,8 +745,8 @@
+ "ON _pi.programinstanceid=_psi.programinstanceid "
+ "WHERE psi.programstageinstanceid=_pdv.programstageinstanceid AND _pdv.dataelementid=" + dataElementId
+ " AND _psi.organisationunitid in (" + TextUtils.getCommaDelimitedString( orgunitIds ) + ") "
- + "AND _pi.programid = " + programId + " AND psi.executionDate>='" + startDate
- + "' AND psi.executionDate <= '" + endDate + "' ";
+ + "AND _pi.programid = " + programId + " AND _psi.executionDate>='" + startDate
+ + "' AND _psi.executionDate <= '" + endDate + "' ";
if ( !programStageId.equals( IN_CONDITION_GET_ALL ) )
{
@@ -911,6 +942,20 @@
return sql;
}
+ private String getConditionForMinusDataElement( Collection<Integer> orgunitIds, Integer programStageId,
+ Integer dataElementId, String compareSide, String startDate, String endDate )
+ {
+ return " EXISTS ( 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=" + dataElementId
+ + " AND _psi.organisationunitid in (" + TextUtils.getCommaDelimitedString( orgunitIds )
+ + ") " + " AND _psi.programstageid = " + programStageId + " AND _psi.executionDate>='"
+ + startDate + "' AND _psi.executionDate <= '" + endDate + "' "
+ + " AND ( DATE(_pdv.value) - DATE(" + compareSide + ") ) ";
+ }
+
/**
* Return the Ids of organisation units which patients registered or events
* happened.
=== 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-05-16 07:31:48 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties 2013-05-17 08:24:11 +0000
@@ -394,4 +394,10 @@
completed = Completed
events = Events
display_on_all_orgunits = Display on all organisation units
-other_program_stages = Other program stages
\ No newline at end of file
+other_program_stages = Other program stages
+minus = Minus
+minus_with_dateOfIncident = MINUS TO INCIDENT DATE
+minus_with_enrollmentDate = MINUS TO ENROLLMENT DATE
+and_operator = AND
+or_operator = OR
+combine_operator = COMBINE
\ 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/caseAggregation.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregation.vm 2013-04-24 08:29:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregation.vm 2013-05-17 08:24:11 +0000
@@ -30,12 +30,12 @@
<table class="listTable">
<col>
<col width="120">
-
- <tr>
- <th>$i18n.getString( "name" )</th>
- <th>$i18n.getString( "operations" )</th>
- </tr>
-
+ <thead>
+ <tr>
+ <th>$i18n.getString( "name" )</th>
+ <th>$i18n.getString( "operations" )</th>
+ </tr>
+ </thead>
<tbody id="list">
#parse( "/dhis-web-maintenance-patient/caseAggregationList.vm" )
</tbody>
=== 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-05-15 04:01:06 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm 2013-05-17 08:24:11 +0000
@@ -8,40 +8,46 @@
<div id="tab-1">
<table>
<tr>
- <th>$i18n.getString("display_name")</th>
- <td>
- <select id='displayNameOption' style="width:220px" onchange='displayNameOnChange( this.value )'>
- <option value='1'>$i18n.getString("name")</option>
- <option value='2'>$i18n.getString("code")</option>
- <option value='3'>$i18n.getString("code_and_name")</option>
- </select>
+ <td colspan='2'>
+ <input type='text' id='txtSearchValue' name='txtSearchValue' onKeyUp="filterDataElement(event, this.value, 'dataElements','dataElementBackups');" style='width:265px;'/>
+ <input type='button' value='$i18n.getString("clear")' onClick="setFieldValue('txtSearchValue', '');" style='width:50px'>
</td>
<td>
<label for="availableValues">$i18n.getString( "available_values" )</label>
<input type='button' title="$i18n.getString( 'insert_selected_values' )" value="»" class="small-button" onClick="insertMultiValues('suggestedDEValues');" >
</td>
</tr>
- <tr>
- <th>$i18n.getString( "sort_by" )</th>
- <td>
- <input type='radio' name='sortBy' value='1' onchange="sortByOnChange('1')" checked >$i18n.getString("name")
- <input type='radio' name='sortBy' value='2' onchange="sortByOnChange('2')">$i18n.getString("code")
- </td>
- <td rowspan="3">
- <select name="suggestedDEValues" size="12" multiple id='suggestedDEValues' ondblclick="insertSingleValue('suggestedDEValues');" ></select>
- </td>
- </tr>
- <tr>
- <td colspan='2'>
- <input type='text' id='txtSearchValue' name='txtSearchValue' onKeyUp="filterDataElement(event, this.value, 'dataElements','dataElementBackups');" style='width:265px;'/>
- <input type='button' value='$i18n.getString("clear")' onClick="setFieldValue('txtSearchValue', '');" style='width:50px'>
- </td>
- </tr>
<tr>
<td colspan='2'>
<select id="dataElements" name="dataElements" size="8" ondblclick="insertDataElement(this);" onclick="getSuggestedValues(this.id, 'suggestedDEValues' )"></select>
<select id="dataElementBackups" name="dataElementBackups" style='display:none;'></select>
</td>
+ <td rowspan='3'>
+ <select name="suggestedDEValues" size="12" multiple id='suggestedDEValues' ondblclick="insertSingleValue('suggestedDEValues');" ></select>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <table style='background-color:#CBDDEB'>
+ <tr>
+ <td>$i18n.getString("display_name")</td>
+ <td>
+ <select id='displayNameOption' style="width:220px" onchange='displayNameOnChange( this.value )'>
+ <option value='1'>$i18n.getString("name")</option>
+ <option value='2'>$i18n.getString("code")</option>
+ <option value='3'>$i18n.getString("code_and_name")</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td>$i18n.getString( "sort_by" )</td>
+ <td>
+ <input type='radio' name='sortBy' value='1' onchange="sortByOnChange('1')" checked >$i18n.getString("name")
+ <input type='radio' name='sortBy' value='2' onchange="sortByOnChange('2')">$i18n.getString("code")
+ </td>
+ </tr>
+ </table>
+ </td>
</tr>
</table>
</div>
@@ -103,25 +109,26 @@
<table>
<tr>
<td>
- <input type='button' class="small-button" alt="$i18n.getString( 'less' )" onclick='insertOperator( "<" );' value="<" />
- <input type='button' class="small-button" alt="$i18n.getString( 'less_or_equal' )" onclick='insertOperator( "<=" );' value="<=" />
- <input type='button' class="small-button" alt="$i18n.getString( 'greater' )" onclick='insertOperator( ">" );' value=">" />
- <input type='button' class="small-button" alt="$i18n.getString( 'greater_or_equal' )" onclick='insertOperator( ">=" );' value=">=" />
- <input type='button' class="small-button" alt="$i18n.getString( 'equal' )" onclick='insertOperator( "=" );' value="=" />
- <input type='button' class="small-button" alt="$i18n.getString( 'diff' )" onclick='insertOperator( "!=" );' value="!=" />
-
- <!-- input type='button' class="small-button" alt="$i18n.getString( 'plus' )" onclick='insertOperator( "+" );' value="+" / -->
- <input type='button' class="small-button" alt="$i18n.getString( 'left_parent' )" onclick='insertOperator( "(" );' value="(" />
- <input type='button' class="small-button" alt="$i18n.getString( 'right_parent' )" onclick='insertOperator( ")" );' value=")" />
-
- <input type='button' class="nornal-button" alt="$i18n.getString( 'yes' )" onclick='insertBoolValue( "true" );' value="$i18n.getString( 'yes' )" />
- <input type='button' class="nornal-button" alt="$i18n.getString( 'no' )" onclick='insertBoolValue( "false" );' value="$i18n.getString( 'no' )" />
- <input type='button' class="nornal-button" alt="$i18n.getString( 'is_null' )" onclick='insertOperator( "is null" );' value="==NULL" />
- <input type='button' class="nornal-button" alt="$i18n.getString( 'not_null' )" onclick='insertOperator( "is not null" );' value="!=NULL" />
-
- <input type='button' style="width:45px;" alt="$i18n.getString( 'and' )" onclick='insertOperator( "AND" );' value="AND" />
- <input type='button' style="width:45px;" alt="$i18n.getString( 'or' )" onclick='insertOperator( "OR" );' value="OR" />
- <input type='button' style="width:85px;" alt="$i18n.getString( 'combine' )" onclick='insertOperator( "COMBINE" );' value="COMBINE" />
+ <input type='button' class="small-button" onclick='insertOperator( "(" );' value="(" />
+ <input type='button' class="small-button" onclick='insertOperator( ")" );' value=")" />
+ <input type='button' class="small-button" onclick='insertOperator( "<" );' value="<" />
+ <input type='button' class="small-button" onclick='insertOperator( "<=" );' value="<=" />
+ <input type='button' class="small-button" onclick='insertOperator( ">" );' value=">" />
+ <input type='button' class="small-button" onclick='insertOperator( ">=" );' value=">=" />
+ <input type='button' class="small-button" onclick='insertOperator( "=" );' value="=" />
+ <input type='button' class="small-button" onclick='insertOperator( "!=" );' value="!=" />
+
+ <input type='button' class="nornal-button" onclick='insertBoolValue( "true" );' value="$i18n.getString( 'yes' )" />
+ <input type='button' class="nornal-button" onclick='insertBoolValue( "false" );' value="$i18n.getString( 'no' )" />
+ <input type='button' class="nornal-button" onclick='insertOperator( "is null" );' value="==NULL" />
+ <input type='button' class="nornal-button" onclick='insertOperator( "is not null" );' value="!=NULL" />
+ <br><br>
+ <input type='button' style="width:54px;" onclick='insertOperator( "AND" );' value="$i18n.getString( 'and_operator' )" />
+ <input type='button' style="width:54px;" onclick='insertOperator( "OR" );' value="$i18n.getString( 'or_operator' )" />
+
+ <input type='button' style="width:92px;" onclick='insertOperator( "COMBINE" );' value="$i18n.getString( 'combine_operator' )" />
+ <input type='button' style="width:150px;" onclick='insertOperator( "MINUS( , dateOfIncident) " );' value="$i18n.getString('minus_with_dateOfIncident')" />
+ <input type='button' style="width:150px;" onclick='insertOperator( "MINUS( , enrollmentDate) " );' value="$i18n.getString('minus_with_enrollmentDate')" />
<input type='button' style="width:45px;" align="right" alt="$i18n.getString( 'clear' )" onclick="byId('aggregationCondition').value='';" value="$i18n.getString('clear')" />
</td>
=== 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-04-24 08:33:05 +0000
+++ 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
@@ -1,6 +1,5 @@
-#set( $mark = true )
#foreach( $aggregationCondition in $aggregationConditions )
- <tr id="tr${aggregationCondition.id}" #alternate( $mark )>
+ <tr id="tr${aggregationCondition.id}">
<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,7 +7,5 @@
<a href="javascript:removeCaseAggregation( '$aggregationCondition.id', '$encoder.jsEncode( $aggregationCondition.displayName )' )" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"></a>
<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