dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23083
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11221: Fix bug - the result from case aggregate query builder is wrong with number dataelements.
------------------------------------------------------------
revno: 11221
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-06-18 09:41:49 +0700
message:
Fix bug - the result from case aggregate query builder is wrong with number dataelements.
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-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
--
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-17 05:28:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java 2013-06-18 02:41:49 +0000
@@ -84,9 +84,9 @@
public static String OBJECT_PROGRAM_PROPERTY_INCIDENT_DATE = "dateOfIncident";
public static String OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE = "enrollmentDate";
-
+
public static String OBJECT_PROGRAM_PROPERTY_REPORT_DATE_DATE = "executionDate";
-
+
public static String MINUS_OPERATOR = "DATEDIFF";
public static String AUTO_STORED_BY = "DHIS-SYSTEM";
@@ -97,13 +97,11 @@
+ 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_REPORT_DATE_DATE + "|" + OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE + ")+\\s*\\)\\s*";
+ 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_REPORT_DATE_DATE + "|" + OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE + ")+\\s*\\)\\s*";
- // Group 2
- public static final String operatorRegExp = "]\\s*(>=|<=|!=|>|<|=)+\\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-17 05:44:11 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionManager.java 2013-06-18 02:41:49 +0000
@@ -63,8 +63,11 @@
import org.hisp.dhis.caseaggregation.CaseAggregationConditionManager;
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.GridHeader;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.CalendarPeriodType;
import org.hisp.dhis.period.Period;
@@ -108,6 +111,20 @@
this.jdbcTemplate = jdbcTemplate;
}
+ private StatementBuilder statementBuilder;
+
+ public void setStatementBuilder( StatementBuilder statementBuilder )
+ {
+ this.statementBuilder = statementBuilder;
+ }
+
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
// -------------------------------------------------------------------------
// Implementation Methods
// -------------------------------------------------------------------------
@@ -188,7 +205,7 @@
SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
grid.addRows( rs );
-
+
return grid;
}
@@ -287,7 +304,6 @@
Integer aggregateDeId, String aggregateDeName, Integer optionComboId, String optionComboName, Integer deSumId,
Collection<Integer> orgunitIds, Period period )
{
- caseExpression = formatExpression( caseExpression );
String sql = "SELECT '" + aggregateDeId + "' as dataelementid, '" + optionComboId
+ "' as categoryoptioncomboid, ou.organisationunitid as sourceid, '" + period.getId() + "' as periodid,'"
+ CaseAggregationCondition.AUTO_STORED_BY + "' as comment, ";
@@ -368,17 +384,15 @@
sql += "GROUP BY ou.organisationunitid, ou.name";
}
-
+
sql = sql.replaceAll( "COMBINE", "" );
-
+
return sql;
}
@Override
public String parseExpressionDetailsToSql( String caseExpression, String operator, Integer orgunitId, Period period )
{
- caseExpression = formatExpression( caseExpression );
-
String sql = "SELECT ";
boolean hasPatients = hasPatientCriteria( caseExpression );
@@ -550,7 +564,7 @@
periodid = rs.getInt( "periodid" );
}
- if ( periodid == null)
+ if ( periodid == null )
{
String insertSql = "insert into period (periodtypeid,startdate,enddate) " + " VALUES " + "("
+ periodTypeId + ",'" + start + "','" + end + "' )";
@@ -757,7 +771,15 @@
if ( isExist )
{
- sql += " AND _pdv.value ";
+ DataElement dataElement = dataElementService.getDataElement( dataElementId );
+ if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
+ {
+ sql += " AND ( cast( _pdv.value as " + statementBuilder.getDoubleColumnType() + " ) ) ";
+ }
+ else
+ {
+ sql += " AND _pdv.value ";
+ }
}
return sql;
@@ -970,7 +992,7 @@
sql += " UNION ";
sql += "( select distinct organisationunitid from patient where registrationdate>='" + startDate
+ "' and registrationdate<='" + endDate + "')";
-
+
Collection<Integer> orgunitIds = new HashSet<Integer>();
orgunitIds = jdbcTemplate.query( sql, new RowMapper<Integer>()
{
@@ -1071,23 +1093,4 @@
return false;
}
- private String formatExpression( String expression )
- {
- StringBuffer result = new StringBuffer();
- Pattern pattern = Pattern.compile( CaseAggregationCondition.operatorRegExp );
- Matcher matcher = pattern.matcher( expression );
- while ( matcher.find() )
- {
- String value = matcher.group( 2 );
- value = value.startsWith( "\'" ) ? value : "\'" + value;
- value = value.endsWith( "\'" ) ? value : value + "\'";
-
- value = "]" + matcher.group( 1 ) + " " + value;
- matcher.appendReplacement( result, value );
- }
-
- matcher.appendTail( result );
-
- return result.toString();
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-05-30 07:18:04 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-06-18 02:41:49 +0000
@@ -15,6 +15,8 @@
<bean id="org.hisp.dhis.caseaggregation.CaseAggregationConditionManager"
class="org.hisp.dhis.caseaggregation.jdbc.JdbcCaseAggregationConditionManager">
<property name="jdbcTemplate" ref="jdbcTemplate" />
+ <property name="statementBuilder" ref="statementBuilder" />
+ <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
</bean>
<bean id="org.hisp.dhis.caseaggregation.CaseAggregationConditionStore"