dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17957
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7366: Tabular report, cleanup
------------------------------------------------------------
revno: 7366
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-06-24 15:42:21 +0200
message:
Tabular report, cleanup
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java
--
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/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2012-06-23 11:05:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2012-06-24 13:42:21 +0000
@@ -86,11 +86,10 @@
List<ProgramStageInstance> getProgramStageInstances( Patient patient, Boolean completed );
- Grid getTabularReport( ProgramStage programStage, List<String> searchingKeys,
- Collection<Integer> organisationUnits, int level, Date startDate, Date endDate, boolean descOrder, Integer min,
- Integer max );
+ Grid getTabularReport( ProgramStage programStage, List<String> searchKeys, Collection<Integer> organisationUnits,
+ int level, Date startDate, Date endDate, boolean descOrder, Integer min, Integer max );
- int getTabularReportCount( ProgramStage programStage, List<String> searchingKeys,
+ int getTabularReportCount( ProgramStage programStage, List<String> searchKeys,
Collection<Integer> organisationUnits, int level, Date startDate, Date endDate );
List<Grid> getProgramStageInstancesReport( ProgramInstance programInstance, I18nFormat format, I18n i18n );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java 2012-06-14 13:07:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceStore.java 2012-06-24 13:42:21 +0000
@@ -74,9 +74,9 @@
List<ProgramStageInstance> get( ProgramStage programStage, OrganisationUnit orgunit, Date startDate, Date endDate, int min, int max );
Grid getTabularReport( ProgramStage programStage, Map<Integer, OrganisationUnitLevel> orgUnitLevelMap,
- Collection<Integer> orgUnits, List<String> searchingKeys, int level, int maxLevel, Date startDate,
+ Collection<Integer> orgUnits, List<String> searchKeys, int level, int maxLevel, Date startDate,
Date endDate, boolean descOrder, Integer min, Integer max );
- int getTabularReportCount( ProgramStage programStage, List<String> searchingKeys,
+ int getTabularReportCount( ProgramStage programStage, List<String> searchKeys,
Collection<Integer> organisationUnits, int level, int maxLevel, Date startDate, Date endDate );
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2012-06-23 11:05:13 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2012-06-24 13:42:21 +0000
@@ -222,16 +222,18 @@
}
public Grid getTabularReport( ProgramStage programStage, Map<Integer, OrganisationUnitLevel> orgUnitLevelMap,
- Collection<Integer> orgUnits, List<String> searchingKeys, int level, int maxLevel, Date startDate,
+ Collection<Integer> orgUnits, List<String> searchKeys, int level, int maxLevel, Date startDate,
Date endDate, boolean descOrder, Integer min, Integer max )
{
+ // ---------------------------------------------------------------------
+ // Headers TODO hidden cols
+ // ---------------------------------------------------------------------
+
Grid grid = new ListGrid();
grid.addHeader( new GridHeader( "id", true, true ) );
grid.addHeader( new GridHeader( "Report date", false, true ) );
- // TODO hidden cols
-
for ( int i = 0; i < maxLevel; i++ )
{
int l = i + 1;
@@ -240,21 +242,21 @@
grid.addHeader( new GridHeader( name, false, true ) );
}
- for ( String searchingKey : searchingKeys )
+ for ( String searchKey : searchKeys )
{
- String[] infor = searchingKey.split( "_" );
- String objectType = infor[0];
+ String[] values = searchKey.split( "_" );
+ String objectType = values[0];
- boolean hidden = Boolean.parseBoolean( infor[2] );
+ boolean hidden = Boolean.parseBoolean( values[2] );
String name = "";
if ( objectType.equals( PREFIX_FIXED_ATTRIBUTE ) )
{
- name = infor[1];
+ name = values[1];
}
else
{
- int objectId = Integer.parseInt( infor[1] );
+ int objectId = Integer.parseInt( values[1] );
if ( objectType.equals( PREFIX_IDENTIFIER_TYPE ) )
{
@@ -273,7 +275,11 @@
grid.addHeader( new GridHeader( name, hidden, true ) );
}
- String sql = getTabularReportSql( false, programStage, searchingKeys, orgUnits, level, maxLevel, startDate,
+ // ---------------------------------------------------------------------
+ // Get SQL and build grid
+ // ---------------------------------------------------------------------
+
+ String sql = getTabularReportSql( false, programStage, searchKeys, orgUnits, level, maxLevel, startDate,
endDate, descOrder, min, max );
SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
@@ -283,10 +289,10 @@
return grid;
}
- public int getTabularReportCount( ProgramStage programStage, List<String> searchingKeys,
+ public int getTabularReportCount( ProgramStage programStage, List<String> searchKeys,
Collection<Integer> organisationUnits, int level, int maxLevel, Date startDate, Date endDate )
{
- String sql = getTabularReportSql( true, programStage, searchingKeys, organisationUnits, level, maxLevel,
+ String sql = getTabularReportSql( true, programStage, searchKeys, organisationUnits, level, maxLevel,
startDate, endDate, false, null, null );
return jdbcTemplate.queryForInt( sql );
@@ -296,7 +302,10 @@
// Supportive methods
// -------------------------------------------------------------------------
- private String getTabularReportSql( boolean count, ProgramStage programStage, List<String> searchingKeys,
+ /**
+ * Search values on format type_id/name_hidden_='query'
+ */
+ private String getTabularReportSql( boolean count, ProgramStage programStage, List<String> searchKeys,
Collection<Integer> orgUnits, int level, int maxLevel, Date startDate, Date endDate, boolean descOrder,
Integer min, Integer max )
{
@@ -309,42 +318,36 @@
for ( int i = 0; i < maxLevel; i++ )
{
int l = i + 1;
- sql += "(select name from organisationunit where organisationunitid=ous.idlevel" + l + ") as level_" + i
- + ",";
+ sql += "(select name from organisationunit where organisationunitid=ous.idlevel" + l + ") as level_" + i + ",";
}
- for ( String searchingKey : searchingKeys )
+ for ( String searchKey : searchKeys )
{
- String[] infor = searchingKey.split( "_" );
- String objectType = infor[0];
+ String[] values = searchKey.split( "_" );
+ String objectType = values[0];
if ( objectType.equals( PREFIX_FIXED_ATTRIBUTE ) )
{
- sql += "p." + infor[1] + ",";
+ sql += "p." + values[1] + ",";
- if ( infor.length == 4 )
+ if ( values.length == 4 )
{
- String value = lower( infor[3] );
- where += operator + "lower(" + infor[1] + ") " + value + " ";
-
+ where += operator + "lower(" + values[1] + ") " + lower( values[3] ) + " ";
operator = "and ";
}
}
else
{
- int objectId = Integer.parseInt( infor[1] );
- String value = "";
+ int objectId = Integer.parseInt( values[1] );
if ( objectType.equals( PREFIX_IDENTIFIER_TYPE ) )
{
sql += "(select identifier from patientidentifier where patientid=p.patientid and patientidentifiertypeid="
+ objectId + ") as identifier_" + objectId + ",";
- if ( infor.length == 4 )
+ if ( values.length == 4 )
{
- value = lower( infor[3] );
- where += operator + "lower(identifier_" + objectId + ") " + value + " ";
-
+ where += operator + "lower(identifier_" + objectId + ") " + lower( values[3] ) + " ";
operator = "and ";
}
}
@@ -352,10 +355,10 @@
{
sql += "(select value from patientattributevalue where patientid=p.patientid and patientattributeid="
+ objectId + ") as attribute_" + objectId + ",";
- if ( infor.length == 4 )
+
+ if ( values.length == 4 )
{
- value = lower( infor[3] );
- where += operator + "lower(attribute_" + objectId + ") " + value + " ";
+ where += operator + "lower(attribute_" + objectId + ") " + lower( values[3] ) + " ";
operator = "and ";
}
}
@@ -364,10 +367,9 @@
sql += "(select value from patientdatavalue where programstageinstanceid=psi.programstageinstanceid and dataelementid="
+ objectId + ") as element_" + objectId + ",";
- if ( infor.length == 4 )
+ if ( values.length == 4 )
{
- value = lower( infor[3] );
- where += operator + "lower(element_" + objectId + ") " + value + " ";
+ where += operator + "lower(element_" + objectId + ") " + lower( values[3] ) + " ";
operator = "and ";
}
}
@@ -407,16 +409,13 @@
sql += "psi.executiondate ";
sql += descOrder ? "desc " : "";
- sql += (min != null && max != null) ? statementBuilder.limitRecord( min, max ) : ""; // TODO
- // page
- // size
- sql += ") as tabular ";
+ sql += (min != null && max != null) ? statementBuilder.limitRecord( min, max ) : "";
+ sql += ") as tabular ";// TODO page size
// filters
sql += where;
sql = sql.substring( 0, sql.length() - 1 ) + " "; // Remove last comma
- // if exists
log.info( sql );
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java 2012-06-20 06:32:51 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java 2012-06-24 13:42:21 +0000
@@ -276,8 +276,7 @@
if ( selectedOrgunit.getParent() == null )
{
- organisationUnits = null; // Ignore org unit criteria when
- // root
+ organisationUnits = null; // Ignore unit criteria when root
}
else
{
@@ -315,12 +314,12 @@
grid = programStageInstanceService.getTabularReport( programStage, searchingValues, organisationUnits,
level, startValue, endValue, !orderByOrgunitAsc, paging.getStartPos(), paging.getPageSize() );
}
- else
- // Download as Excel
+ else // Download as Excel
{
grid = programStageInstanceService.getTabularReport( programStage, searchingValues, organisationUnits,
level, startValue, endValue, !orderByOrgunitAsc, null, null );
}
+
System.out.println();
System.out.println( grid );
@@ -340,31 +339,32 @@
private void getParams()
{
int index = 0;
- for ( String searchingValue : searchingValues )
+
+ for ( String searchValue : searchingValues )
{
- String[] infor = searchingValue.split( "_" );
- String objectType = infor[0];
+ String[] values = searchValue.split( "_" );
+ String prefix = values[0];
- if ( objectType.equals( PREFIX_PATIENT_ATTRIBUTE ) )
+ if ( prefix.equals( PREFIX_PATIENT_ATTRIBUTE ) )
{
- int objectId = Integer.parseInt( infor[1] );
+ int objectId = Integer.parseInt( values[1] );
PatientAttribute attribute = patientAttributeService.getPatientAttribute( objectId );
patientAttributes.add( attribute );
valueTypes.add( attribute.getValueType() );
mapSuggestedValues.put( index, getSuggestedAttributeValues( attribute ) );
}
- else if ( objectType.equals( PREFIX_DATA_ELEMENT ) )
+ else if ( prefix.equals( PREFIX_DATA_ELEMENT ) )
{
- int objectId = Integer.parseInt( infor[1] );
+ int objectId = Integer.parseInt( values[1] );
DataElement dataElement = dataElementService.getDataElement( objectId );
dataElements.add( dataElement );
- // Get value-type && suggested-values
- String valueType = (dataElement.getOptionSet() != null) ? VALUE_TYPE_OPTION_SET : dataElement.getType();
+ String valueType = dataElement.getOptionSet() != null ? VALUE_TYPE_OPTION_SET : dataElement.getType();
valueTypes.add( valueType );
mapSuggestedValues.put( index, getSuggestedDataElementValues( dataElement ) );
}
+
index++;
}
}