dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18339
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7693: local/in merge 2.7 to trunk NRHM-Report module work in progress
------------------------------------------------------------
revno: 7693
committer: Mithilesh Kumar Thakur<mithilesh.hisp@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-07-24 18:08:31 +0530
message:
local/in merge 2.7 to trunk NRHM-Report module work in progress
added:
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action/
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action/GenerateRanking2ReportAction.java
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action/Ranking2ReportFormAction.java
local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForRanking2Reports.vm
local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/ranking2ReportFront.vm
modified:
local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java
local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportType.java
local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/Report_inDesign.java
local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ouwiseprogress/action/GenerateOuWiseProgressReportResultAction.java
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/periodwiseprogress/action/GeneratePeriodWiseProgressAnalyserResultAction.java
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/periodwiseprogress/action/GeneratePeriodWiseProgressReportAnalyserFormAction.java
local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml
local/in/dhis-web-reports-national/src/main/resources/struts.xml
local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.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 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java 2011-12-14 11:09:39 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java 2012-07-24 12:38:31 +0000
@@ -165,4 +165,18 @@
Map<String, String> getAggDataFromDataValueTableForOrgUnitWise( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
Map<String, String> getAggDataFromAggDataValueTableForOrgUnitWise( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
+
+ Map<String, String> getResultDataValueFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
+
+ Map<String, String> getAggDataFromAggDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
+
+ Integer getOrgunitCountByOrgunitGroup( String orgunitGroupIdsByComma, Integer orgUnitId );
+
+ Integer getReportingOrgunitCountByDataset( Integer dataSetId, Integer orgUnitId, Integer periodId );
+
+ Integer getReportingOrgunitCountByDataset( Integer dataSetId, Integer orgUnitId );
+
+ String getDataelementIdsByStype( List<Report_inDesign> reportDesignList, String sType );
+
+ Map<String, String> getAggNonNumberDataFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma );
}
=== modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportType.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportType.java 2011-12-14 11:09:39 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportType.java 2012-07-24 12:38:31 +0000
@@ -63,6 +63,10 @@
public final static String RT_COLDCHAIN_REPORT = "Cold Chain Reports";
public final static String RT_MD_REPORT = "MD Reports";
+
+ public final static String RT_RANKING_REPORT = "Ranking Reports";
+
+ public final static String RT_FEEDBACK_TEMPLATE = "Feedback Template";
public static List<String> getReportTypes()
{
@@ -100,6 +104,10 @@
reportTypes.add( RT_MD_REPORT );
+ reportTypes.add( RT_RANKING_REPORT);
+
+ reportTypes.add(RT_FEEDBACK_TEMPLATE);
+
return reportTypes;
}
}
=== modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/Report_inDesign.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/Report_inDesign.java 2011-06-27 07:27:58 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/Report_inDesign.java 2012-07-24 12:38:31 +0000
@@ -191,23 +191,25 @@
// -------------------------------------------------------------------------
// Constants for stype
- public final String ST_DATAELEMENT = "dataelement";
- public final String ST_DATAELEMENT_NO_REPEAT = "dataelementnorepeat";
- public final String ST_LLDATAELEMENT = "lldataelement";
- public final String ST_INDICATOR = "indicator";
- public final String ST_LLDEATHDATAELEMENTAGE = "lldeathdataelementage";
- public final String ST_LLMATERNALDEATHDATAELEMENTAGE = "llmaternaldeathdataelement";
+ public static final String ST_DATAELEMENT = "dataelement";
+ public static final String ST_DATAELEMENT_NO_REPEAT = "dataelementnorepeat";
+ public static final String ST_LLDATAELEMENT = "lldataelement";
+ public static final String ST_INDICATOR = "indicator";
+ public static final String ST_LLDEATHDATAELEMENTAGE = "lldeathdataelementage";
+ public static final String ST_LLMATERNALDEATHDATAELEMENTAGE = "llmaternaldeathdataelement";
+ public static final String ST_NON_NUMBER_DATAELEMENT = "nonnumberdataelement";
// Constants for ptype
- public final String PT_CMCY = "CMCY";
- public final String PT_CMPY = "CMPY";
- public final String PT_CCMCY = "CCMCY";
- public final String PT_CCMPY = "CCMPY";
- public final String PT_PMCY = "PMCY";
+ public static final String PT_CMCY = "CMCY";
+ public static final String PT_CMPY = "CMPY";
+ public static final String PT_CCMCY = "CCMCY";
+ public static final String PT_CCMPY = "CCMPY";
+ public static final String PT_PMCY = "PMCY";
// Constants for LineListDataElementMapping
- public final String E_FACILITY = "FACILITY";
- public final String E_PERIOD_MONTH = "PERIOD-MONTH";
- public final String E_PERIOD_YEAR = "PERIOD-YEAR";
+ public static final String E_FACILITY = "FACILITY";
+ public static final String E_PERIOD_MONTH = "PERIOD-MONTH";
+ public static final String E_PERIOD_YEAR = "PERIOD-YEAR";
+
}
\ No newline at end of file
=== modified file 'local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java'
--- local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java 2012-07-02 11:35:09 +0000
+++ local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java 2012-07-24 12:38:31 +0000
@@ -1,5 +1,26 @@
package org.hisp.dhis.reports;
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
import org.hisp.dhis.aggregation.AggregatedDataValueService;
import org.hisp.dhis.aggregation.AggregationService;
import org.hisp.dhis.config.ConfigurationService;
@@ -37,18 +58,6 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.File;
-import java.io.IOException;
-import java.util.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
-import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
-
public class DefaultReportService
implements ReportService
{
@@ -60,7 +69,6 @@
private ReportStore reportStore;
-
public void setReportStore( ReportStore reportStore )
{
this.reportStore = reportStore;
@@ -86,7 +94,7 @@
{
this.jdbcTemplate = jdbcTemplate;
}
-
+
private IndicatorService indicatorService;
public void setIndicatorService( IndicatorService indicatorService )
@@ -114,28 +122,29 @@
{
this.dataElementService = dataElementService;
}
-
+
private DataElementCategoryService dataElementCategoryOptionComboService;
-
- public void setDataElementCategoryOptionComboService( DataElementCategoryService dataElementCategoryOptionComboService )
+
+ public void setDataElementCategoryOptionComboService(
+ DataElementCategoryService dataElementCategoryOptionComboService )
{
this.dataElementCategoryOptionComboService = dataElementCategoryOptionComboService;
}
-
+
private AggregationService aggregationService;
public void setAggregationService( AggregationService aggregationService )
{
this.aggregationService = aggregationService;
}
-
+
private DataValueService dataValueService;
public void setDataValueService( DataValueService dataValueService )
{
this.dataValueService = dataValueService;
}
-
+
private SurveyService surveyService;
public void setSurveyService( SurveyService surveyService )
@@ -151,7 +160,7 @@
}
private AggregatedDataValueService aggregatedDataValueService;
-
+
public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService )
{
this.aggregatedDataValueService = aggregatedDataValueService;
@@ -235,13 +244,11 @@
return reportStore.getReportsByPeriodSourceAndReportType( periodType, source, reportType );
}
-
// -------------------------------------------------------------------------
// for Report Result Action input/otput
// -------------------------------------------------------------------------
-
- // private String reportModelTB;
+ // private String reportModelTB;
// -------------------------------------------------------------------------
// Support Methods Defination
@@ -272,19 +279,25 @@
int dataElementid = 1020;
- if ( lltype.equalsIgnoreCase( "lllivebirth-l4DECodes.xml" ) || lltype.equalsIgnoreCase( "lllivebirth-l5DECodes.xml" ) || lltype.equalsIgnoreCase( "lllivebirth-l6DECodes.xml" ) )
+ if ( lltype.equalsIgnoreCase( "lllivebirth-l4DECodes.xml" )
+ || lltype.equalsIgnoreCase( "lllivebirth-l5DECodes.xml" )
+ || lltype.equalsIgnoreCase( "lllivebirth-l6DECodes.xml" ) )
{
dataElementid = 1020;
}
- else if ( lltype.equalsIgnoreCase( "lldeath-l4DECodes.xml" ) || lltype.equalsIgnoreCase( "lldeath-l5DECodes.xml" ) || lltype.equalsIgnoreCase( "lldeath-l6DECodes.xml" ) || lltype.equalsIgnoreCase( "monthly_SCWebPortalDECodes.xml" ) )
+ else if ( lltype.equalsIgnoreCase( "lldeath-l4DECodes.xml" )
+ || lltype.equalsIgnoreCase( "lldeath-l5DECodes.xml" ) || lltype.equalsIgnoreCase( "lldeath-l6DECodes.xml" )
+ || lltype.equalsIgnoreCase( "monthly_SCWebPortalDECodes.xml" ) )
{
- dataElementid = 1027;
+ dataElementid = 1027;
}
- else if ( lltype.equalsIgnoreCase( "llmaternaldeath-l4DECodes.xml" ) || lltype.equalsIgnoreCase( "llmaternaldeath-l5DECodes.xml" ) || lltype.equalsIgnoreCase( "llmaternaldeath-l6DECodes.xml" ) )
+ else if ( lltype.equalsIgnoreCase( "llmaternaldeath-l4DECodes.xml" )
+ || lltype.equalsIgnoreCase( "llmaternaldeath-l5DECodes.xml" )
+ || lltype.equalsIgnoreCase( "llmaternaldeath-l6DECodes.xml" ) )
{
dataElementid = 1032;
}
-
+
try
{
query = "SELECT recordno FROM lldatavalue WHERE dataelementid = " + dataElementid + " AND periodid = "
@@ -307,32 +320,28 @@
return recordNosList;
}
- //----------------------------------------------------------------------------------------------------
- // START
- // Fetch Global Decode Configuration
- //----------------------------------------------------------------------------------------------------
-
+ // ----------------------------------------------------------------------------------------------------
+ // START
+ // Fetch Global Decode Configuration
+ // ----------------------------------------------------------------------------------------------------
/**
- * Generates a map of
- * global-to-local ids
- * using the global settings
- * XML file.
+ * Generates a map of global-to-local ids using the global settings XML
+ * file.
+ *
* @return
*/
-
- public Map<String,String> mapGlobalValues ()
+ public Map<String, String> mapGlobalValues()
{
final String configFileName = "globalsettings.xml";
- Map<String,String> globalValuesMap = new HashMap<String, String>();
+ Map<String, String> globalValuesMap = new HashMap<String, String>();
String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER )
- .getValue();
+ .getValue();
- String path = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator
- + configFileName ;
+ String path = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + configFileName;
try
{
@@ -352,23 +361,29 @@
for ( int s = 0; s < totalConfigCodes; s++ )
{
- Element configElement = (Element) listOfConfigCodes.item( s );
+ Element configElement = (Element) listOfConfigCodes.item( s );
- String value = configElement.getAttribute("dhisid").trim();
+ String value = configElement.getAttribute( "dhisid" ).trim();
String id = configElement.getAttribute( "commonid" ).trim();
- //System.out.println("\n*INFO : DhisID: "+value+" || "+"CommonID: "+id+"\n");
+ // System.out.println("\n*INFO : DhisID: "+value+" || "+"CommonID: "+id+"\n");
- globalValuesMap.put(id,value);
+ globalValuesMap.put( id, value );
}
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
+ }
+ catch ( ParserConfigurationException e )
+ {
+ e.printStackTrace();
+ }
+ catch ( SAXException e )
+ {
+ e.printStackTrace();
+ }
+ catch ( IOException e )
+ {
e.printStackTrace();
}
@@ -376,54 +391,53 @@
}
/**
- * Replaces global ids
- * with local values
+ * Replaces global ids with local values
+ *
* @param expression
* @return
*/
- public String getGlobalExpression(String expression,Map<String, String> globalValuesMap)
+ public String getGlobalExpression( String expression, Map<String, String> globalValuesMap )
{
String result = null;
- Pattern p = Pattern.compile("\\[(.*?)\\]");
- Matcher matcher = p.matcher(expression);
+ Pattern p = Pattern.compile( "\\[(.*?)\\]" );
+ Matcher matcher = p.matcher( expression );
- System.out.println("*INFO :Expression: "+expression);
+ System.out.println( "*INFO :Expression: " + expression );
String localValue;
- while(matcher.find())
+ while ( matcher.find() )
{
- result = matcher.group(1);
- localValue = globalValuesMap.get(result);
- expression = expression.replace("["+result+"]","["+localValue+"]");
+ result = matcher.group( 1 );
+ localValue = globalValuesMap.get( result );
+ expression = expression.replace( "[" + result + "]", "[" + localValue + "]" );
}
result = expression;
- System.out.println("*INFO :Result:" + result);
+ System.out.println( "*INFO :Result:" + result );
return result;
}
- //----------------------------------------------------------------------------------------------------------
- // END
- // Fetch Global Decode Configuration
- //----------------------------------------------------------------------------------------------------------
-
+ // ----------------------------------------------------------------------------------------------------------
+ // END
+ // Fetch Global Decode Configuration
+ // ----------------------------------------------------------------------------------------------------------
public List<Report_inDesign> getReportDesign( Report_in report )
{
List<Report_inDesign> deCodes = new ArrayList<Report_inDesign>();
-
+
String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER )
.getValue();
String path = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator
+ report.getXmlTemplateName();
- String configFile= "";
+ //String configFile = "";
try
{
@@ -438,7 +452,7 @@
NodeList listOfDECodes = doc.getElementsByTagName( "de-code" );
int totalDEcodes = listOfDECodes.getLength();
- Map<String,String> globalValuesMap = mapGlobalValues();
+ Map<String, String> globalValuesMap = mapGlobalValues();
for ( int s = 0; s < totalDEcodes; s++ )
{
@@ -446,13 +460,14 @@
NodeList textDECodeList = deCodeElement.getChildNodes();
String expression = ((Node) textDECodeList.item( 0 )).getNodeValue().trim();
-
- // ------------------------replace global values------------------------------------------------
-
- expression = getGlobalExpression(expression,globalValuesMap);
+
+ // ------------------------replace global
+ // values------------------------------------------------
+
+ expression = getGlobalExpression( expression, globalValuesMap );
// ---------------------------------------------------------------------------------------------
-
+
String stype = deCodeElement.getAttribute( "stype" );
String ptype = deCodeElement.getAttribute( "type" );
int sheetno = new Integer( deCodeElement.getAttribute( "sheetno" ) );
@@ -613,13 +628,12 @@
tempEndDate.setTime( endDate );
}
-
calendarList.add( tempStartDate );
calendarList.add( tempEndDate );
return calendarList;
}
-
+
public List<Period> getMonthlyPeriods( Date start, Date end )
{
List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates( start, end ) );
@@ -704,12 +718,12 @@
// getDataElementPeriodType end
-
// -------------------------------------------------------------------------
// Get Aggregated Result for dataelement expression
// -------------------------------------------------------------------------
- public String getResultDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit , String reportModelTB )
+ public String getResultDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit,
+ String reportModelTB )
{
int deFlag1 = 0;
int isAggregated = 0;
@@ -737,7 +751,8 @@
int optionComboId = Integer.parseInt( optionComboIdStr );
DataElement dataElement = dataElementService.getDataElement( dataElementId );
- DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService.getDataElementCategoryOptionCombo( optionComboId );
+ DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService
+ .getDataElementCategoryOptionCombo( optionComboId );
if ( dataElement == null || optionCombo == null )
{
@@ -766,10 +781,11 @@
deFlag1 = 1;
PeriodType dePeriodType = getDataElementPeriodType( dataElement );
- List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates( dePeriodType, startDate, endDate ) );
+ List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates(
+ dePeriodType, startDate, endDate ) );
Period tempPeriod = new Period();
if ( periodList == null || periodList.isEmpty() )
- {
+ {
replaceString = "";
matcher.appendReplacement( buffer, replaceString );
continue;
@@ -802,7 +818,7 @@
}
matcher.appendTail( buffer );
-
+
if ( deFlag1 == 0 )
{
double d = 0.0;
@@ -849,7 +865,7 @@
resultValue = buffer.toString();
}
- if( isAggregated == 0 )
+ if ( isAggregated == 0 )
{
resultValue = " ";
}
@@ -867,14 +883,14 @@
}
}
-
- // -------------------------------------------------------------------------
- // Get Individual Result for dataelement expression
- // -------------------------------------------------------------------------
- public String getIndividualResultDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit , String reportModelTB )
+ // -------------------------------------------------------------------------
+ // Get Individual Result for dataelement expression
+ // -------------------------------------------------------------------------
+ public String getIndividualResultDataValue( String formula, Date startDate, Date endDate,
+ OrganisationUnit organisationUnit, String reportModelTB )
{
int deFlag1 = 0;
-
+
try
{
Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
@@ -890,7 +906,8 @@
String replaceString = matcher.group();
replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
- String optionComboIdStr = replaceString.substring( replaceString.indexOf( '.' ) + 1, replaceString.length() );
+ String optionComboIdStr = replaceString.substring( replaceString.indexOf( '.' ) + 1, replaceString
+ .length() );
replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
@@ -898,7 +915,8 @@
int optionComboId = Integer.parseInt( optionComboIdStr );
DataElement dataElement = dataElementService.getDataElement( dataElementId );
- DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService.getDataElementCategoryOptionCombo( optionComboId );
+ DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService
+ .getDataElementCategoryOptionCombo( optionComboId );
if ( dataElement == null || optionCombo == null )
{
@@ -910,7 +928,8 @@
{
PeriodType dePeriodType = getDataElementPeriodType( dataElement );
- List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates( dePeriodType, startDate, endDate ) );
+ List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates(
+ dePeriodType, startDate, endDate ) );
if ( periodList == null || periodList.isEmpty() )
{
@@ -941,7 +960,8 @@
deFlag1 = 1;
PeriodType dePeriodType = getDataElementPeriodType( dataElement );
- List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates( dePeriodType, startDate, endDate ) );
+ List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates(
+ dePeriodType, startDate, endDate ) );
Period tempPeriod = new Period();
if ( periodList == null || periodList.isEmpty() )
{
@@ -954,7 +974,8 @@
tempPeriod = (Period) periodList.get( 0 );
}
- DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, tempPeriod, optionCombo );
+ DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, tempPeriod,
+ optionCombo );
if ( dataValue != null )
{
@@ -1043,10 +1064,11 @@
throw new RuntimeException( "Illegal DataElement id", ex );
}
}
-
- // Function getBooleanDataValue Start
-
- public String getBooleanDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit , String reportModelTB )
+
+ // Function getBooleanDataValue Start
+
+ public String getBooleanDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit,
+ String reportModelTB )
{
int deFlag1 = 0;
int deFlag2 = 0;
@@ -1062,7 +1084,8 @@
String replaceString = matcher.group();
replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
- String optionComboIdStr = replaceString.substring( replaceString.indexOf( '.' ) + 1, replaceString.length() );
+ String optionComboIdStr = replaceString.substring( replaceString.indexOf( '.' ) + 1, replaceString
+ .length() );
replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
@@ -1070,7 +1093,8 @@
int optionComboId = Integer.parseInt( optionComboIdStr );
DataElement dataElement = dataElementService.getDataElement( dataElementId );
- DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService.getDataElementCategoryOptionCombo( optionComboId );
+ DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService
+ .getDataElementCategoryOptionCombo( optionComboId );
if ( dataElement == null || optionCombo == null )
{
@@ -1085,7 +1109,8 @@
deFlag2 = 0;
PeriodType dePeriodType = getDataElementPeriodType( dataElement );
- List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates( dePeriodType, startDate, endDate ) );
+ List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates(
+ dePeriodType, startDate, endDate ) );
Period tempPeriod = new Period();
if ( periodList == null || periodList.isEmpty() )
{
@@ -1098,7 +1123,8 @@
tempPeriod = (Period) periodList.get( 0 );
}
- DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, tempPeriod, optionCombo );
+ DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, tempPeriod,
+ optionCombo );
if ( dataValue != null )
{
@@ -1181,497 +1207,511 @@
throw new RuntimeException( "Illegal DataElement id", ex );
}
}
-
- // Function getBooleanDataValue End
-
-
- // Function getStartingEndingPeriods Starts
-
-public List<Calendar> getStartingEndingPeriods( String deType , Period selectedPeriod )
-{
- List<Calendar> calendarList = new ArrayList<Calendar>();
-
- Calendar tempStartDate = Calendar.getInstance();
- Calendar tempEndDate = Calendar.getInstance();
-
- Period previousPeriod = new Period();
- previousPeriod = getPreviousPeriod( selectedPeriod );
-
- if ( deType.equalsIgnoreCase( "ccmcy" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- if ( tempStartDate.get( Calendar.MONTH ) < Calendar.APRIL )
- {
- tempStartDate.roll( Calendar.YEAR, -1 );
- }
- tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- }
- else if ( deType.equalsIgnoreCase( "cpmcy" ) )
- {
- tempStartDate.setTime( previousPeriod.getStartDate() );
- if ( tempStartDate.get( Calendar.MONTH ) < Calendar.APRIL )
- {
- tempStartDate.roll( Calendar.YEAR, -1 );
- }
- tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
- tempEndDate.setTime( previousPeriod.getEndDate() );
- }
- else if ( deType.equalsIgnoreCase( "cmpy" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempEndDate.setTime( selectedPeriod.getEndDate() );
-
- tempStartDate.roll( Calendar.YEAR, -1 );
- tempEndDate.roll( Calendar.YEAR, -1 );
- }
- else if ( deType.equalsIgnoreCase( "ccmpy" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempEndDate.setTime( selectedPeriod.getEndDate() );
-
- tempStartDate.roll( Calendar.YEAR, -1 );
- tempEndDate.roll( Calendar.YEAR, -1 );
-
- if ( tempStartDate.get( Calendar.MONTH ) < Calendar.APRIL )
- {
- tempStartDate.roll( Calendar.YEAR, -1 );
- }
- tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
- }
- else if ( deType.equalsIgnoreCase( "pmcy" ) )
- {
- tempStartDate.setTime( previousPeriod.getStartDate() );
- tempEndDate.setTime( previousPeriod.getEndDate() );
- }
- else if ( deType.equalsIgnoreCase( "bccmcy" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- if ( tempStartDate.get( Calendar.MONTH ) < Calendar.JULY )
- {
- tempStartDate.roll( Calendar.YEAR, -1 );
- }
- tempStartDate.set( Calendar.MONTH, Calendar.JULY );
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- }
- else if ( deType.equalsIgnoreCase( "bq1" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempStartDate.set( Calendar.MONTH, Calendar.JANUARY );
-
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- tempEndDate.set( Calendar.MONTH, Calendar.MARCH );
- tempEndDate.set( Calendar.DATE, 31 );
- }
- else if ( deType.equalsIgnoreCase( "bq2" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
-
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- tempEndDate.set( Calendar.MONTH, Calendar.JUNE );
- tempEndDate.set( Calendar.DATE, 30 );
- }
- else if ( deType.equalsIgnoreCase( "bq3" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempStartDate.set( Calendar.MONTH, Calendar.JULY );
-
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- tempEndDate.set( Calendar.MONTH, Calendar.SEPTEMBER );
- tempEndDate.set( Calendar.DATE, 31 );
- }
- else if ( deType.equalsIgnoreCase( "bq4" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempStartDate.set( Calendar.MONTH, Calendar.OCTOBER );
-
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- tempEndDate.set( Calendar.MONTH, Calendar.DECEMBER );
- tempEndDate.set( Calendar.DATE, 31 );
- }
- else if ( deType.equalsIgnoreCase( "bfq1" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempStartDate.set( Calendar.MONTH, Calendar.JULY );
-
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- tempEndDate.set( Calendar.MONTH, Calendar.SEPTEMBER );
- tempEndDate.set( Calendar.DATE, 30 );
- }
- else if ( deType.equalsIgnoreCase( "bfq2" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempStartDate.set( Calendar.MONTH, Calendar.OCTOBER );
-
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- tempEndDate.set( Calendar.MONTH, Calendar.DECEMBER );
- tempEndDate.set( Calendar.DATE, 31 );
- }
- else if ( deType.equalsIgnoreCase( "bfq3" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempStartDate.set( Calendar.MONTH, Calendar.JANUARY );
- tempStartDate.roll( Calendar.YEAR, 1 );
-
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- tempEndDate.set( Calendar.MONTH, Calendar.MARCH );
- tempEndDate.set( Calendar.DATE, 31 );
- }
- else if ( deType.equalsIgnoreCase( "bfq4" ) )
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
- tempStartDate.roll( Calendar.YEAR, 1 );
-
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- tempEndDate.set( Calendar.MONTH, Calendar.JUNE );
- tempEndDate.set( Calendar.DATE, 30 );
- }
- else
- {
- tempStartDate.setTime( selectedPeriod.getStartDate() );
- tempEndDate.setTime( selectedPeriod.getEndDate() );
- }
-
- calendarList.add( tempStartDate );
- calendarList.add( tempEndDate );
-
- return calendarList;
-}
-
-//Function getPreviousPeriod Starts
-public Period getPreviousPeriod( Period selectedPeriod )
-{
- Period period = new Period();
- Calendar tempDate = Calendar.getInstance();
- tempDate.setTime( selectedPeriod.getStartDate() );
- if ( tempDate.get( Calendar.MONTH ) == Calendar.JANUARY )
- {
- tempDate.set( Calendar.MONTH, Calendar.DECEMBER );
- tempDate.roll( Calendar.YEAR, -1 );
-
- } else
- {
- tempDate.roll( Calendar.MONTH, -1 );
- }
- PeriodType periodType = getPeriodTypeObject( "monthly" );
- period = getPeriodByMonth( tempDate.get( Calendar.MONTH ), tempDate.get( Calendar.YEAR ), periodType );
-
- return period;
-}
-
-
-public String getResultIndicatorValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit )
-{
- int deFlag1 = 0;
- int deFlag2 = 0;
-
- try
- {
- Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
-
- Matcher matcher = pattern.matcher( formula );
- StringBuffer buffer = new StringBuffer();
-
- while ( matcher.find() )
- {
- String replaceString = matcher.group();
-
- replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
-
- replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
-
- int indicatorId = Integer.parseInt( replaceString );
-
- Indicator indicator = indicatorService.getIndicator( indicatorId );
-
- if ( indicator == null )
- {
- replaceString = "";
+
+ // Function getBooleanDataValue End
+
+ // Function getStartingEndingPeriods Starts
+
+ public List<Calendar> getStartingEndingPeriods( String deType, Period selectedPeriod )
+ {
+ List<Calendar> calendarList = new ArrayList<Calendar>();
+
+ Calendar tempStartDate = Calendar.getInstance();
+ Calendar tempEndDate = Calendar.getInstance();
+
+ Period previousPeriod = new Period();
+ previousPeriod = getPreviousPeriod( selectedPeriod );
+
+ if ( deType.equalsIgnoreCase( "ccmcy" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ if ( tempStartDate.get( Calendar.MONTH ) < Calendar.APRIL )
+ {
+ tempStartDate.roll( Calendar.YEAR, -1 );
+ }
+ tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ }
+ else if ( deType.equalsIgnoreCase( "cpmcy" ) )
+ {
+ tempStartDate.setTime( previousPeriod.getStartDate() );
+ if ( tempStartDate.get( Calendar.MONTH ) < Calendar.APRIL )
+ {
+ tempStartDate.roll( Calendar.YEAR, -1 );
+ }
+ tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
+ tempEndDate.setTime( previousPeriod.getEndDate() );
+ }
+ else if ( deType.equalsIgnoreCase( "cmpy" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+
+ tempStartDate.roll( Calendar.YEAR, -1 );
+ tempEndDate.roll( Calendar.YEAR, -1 );
+ }
+ else if ( deType.equalsIgnoreCase( "ccmpy" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+
+ tempStartDate.roll( Calendar.YEAR, -1 );
+ tempEndDate.roll( Calendar.YEAR, -1 );
+
+ if ( tempStartDate.get( Calendar.MONTH ) < Calendar.APRIL )
+ {
+ tempStartDate.roll( Calendar.YEAR, -1 );
+ }
+ tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
+ }
+ else if ( deType.equalsIgnoreCase( "pmcy" ) )
+ {
+ tempStartDate.setTime( previousPeriod.getStartDate() );
+ tempEndDate.setTime( previousPeriod.getEndDate() );
+ }
+ else if ( deType.equalsIgnoreCase( "bccmcy" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ if ( tempStartDate.get( Calendar.MONTH ) < Calendar.JULY )
+ {
+ tempStartDate.roll( Calendar.YEAR, -1 );
+ }
+ tempStartDate.set( Calendar.MONTH, Calendar.JULY );
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ }
+ else if ( deType.equalsIgnoreCase( "bq1" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempStartDate.set( Calendar.MONTH, Calendar.JANUARY );
+
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ tempEndDate.set( Calendar.MONTH, Calendar.MARCH );
+ tempEndDate.set( Calendar.DATE, 31 );
+ }
+ else if ( deType.equalsIgnoreCase( "bq2" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
+
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ tempEndDate.set( Calendar.MONTH, Calendar.JUNE );
+ tempEndDate.set( Calendar.DATE, 30 );
+ }
+ else if ( deType.equalsIgnoreCase( "bq3" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempStartDate.set( Calendar.MONTH, Calendar.JULY );
+
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ tempEndDate.set( Calendar.MONTH, Calendar.SEPTEMBER );
+ tempEndDate.set( Calendar.DATE, 31 );
+ }
+ else if ( deType.equalsIgnoreCase( "bq4" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempStartDate.set( Calendar.MONTH, Calendar.OCTOBER );
+
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ tempEndDate.set( Calendar.MONTH, Calendar.DECEMBER );
+ tempEndDate.set( Calendar.DATE, 31 );
+ }
+ else if ( deType.equalsIgnoreCase( "bfq1" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempStartDate.set( Calendar.MONTH, Calendar.JULY );
+
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ tempEndDate.set( Calendar.MONTH, Calendar.SEPTEMBER );
+ tempEndDate.set( Calendar.DATE, 30 );
+ }
+ else if ( deType.equalsIgnoreCase( "bfq2" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempStartDate.set( Calendar.MONTH, Calendar.OCTOBER );
+
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ tempEndDate.set( Calendar.MONTH, Calendar.DECEMBER );
+ tempEndDate.set( Calendar.DATE, 31 );
+ }
+ else if ( deType.equalsIgnoreCase( "bfq3" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempStartDate.set( Calendar.MONTH, Calendar.JANUARY );
+ tempStartDate.roll( Calendar.YEAR, 1 );
+
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ tempEndDate.set( Calendar.MONTH, Calendar.MARCH );
+ tempEndDate.set( Calendar.DATE, 31 );
+ }
+ else if ( deType.equalsIgnoreCase( "bfq4" ) )
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempStartDate.set( Calendar.MONTH, Calendar.APRIL );
+ tempStartDate.roll( Calendar.YEAR, 1 );
+
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ tempEndDate.set( Calendar.MONTH, Calendar.JUNE );
+ tempEndDate.set( Calendar.DATE, 30 );
+ }
+ else
+ {
+ tempStartDate.setTime( selectedPeriod.getStartDate() );
+ tempEndDate.setTime( selectedPeriod.getEndDate() );
+ }
+
+ calendarList.add( tempStartDate );
+ calendarList.add( tempEndDate );
+
+ return calendarList;
+ }
+
+ // Function getPreviousPeriod Starts
+ public Period getPreviousPeriod( Period selectedPeriod )
+ {
+ Period period = new Period();
+ Calendar tempDate = Calendar.getInstance();
+ tempDate.setTime( selectedPeriod.getStartDate() );
+ if ( tempDate.get( Calendar.MONTH ) == Calendar.JANUARY )
+ {
+ tempDate.set( Calendar.MONTH, Calendar.DECEMBER );
+ tempDate.roll( Calendar.YEAR, -1 );
+
+ }
+ else
+ {
+ tempDate.roll( Calendar.MONTH, -1 );
+ }
+ PeriodType periodType = getPeriodTypeObject( "monthly" );
+ period = getPeriodByMonth( tempDate.get( Calendar.MONTH ), tempDate.get( Calendar.YEAR ), periodType );
+
+ return period;
+ }
+
+ public String getResultIndicatorValue( String formula, Date startDate, Date endDate,
+ OrganisationUnit organisationUnit )
+ {
+ int deFlag1 = 0;
+ int deFlag2 = 0;
+
+ try
+ {
+ Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
+
+ Matcher matcher = pattern.matcher( formula );
+ StringBuffer buffer = new StringBuffer();
+
+ while ( matcher.find() )
+ {
+ String replaceString = matcher.group();
+
+ replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
+
+ replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
+
+ int indicatorId = Integer.parseInt( replaceString );
+
+ Indicator indicator = indicatorService.getIndicator( indicatorId );
+
+ if ( indicator == null )
+ {
+ replaceString = "";
+ matcher.appendReplacement( buffer, replaceString );
+ continue;
+ }
+
+ Double aggregatedValue = aggregationService.getAggregatedIndicatorValue( indicator, startDate, endDate,
+ organisationUnit );
+
+ if ( aggregatedValue == null )
+ {
+ replaceString = NULL_REPLACEMENT;
+ }
+ else
+ {
+ replaceString = String.valueOf( aggregatedValue );
+ deFlag2 = 1;
+ }
matcher.appendReplacement( buffer, replaceString );
- continue;
}
- Double aggregatedValue = aggregationService.getAggregatedIndicatorValue( indicator, startDate, endDate,
- organisationUnit );
+ matcher.appendTail( buffer );
- if ( aggregatedValue == null )
+ String resultValue = "";
+ if ( deFlag1 == 0 )
{
- replaceString = NULL_REPLACEMENT;
- }
+ double d = 0.0;
+ try
+ {
+ d = MathUtils.calculateExpression( buffer.toString() );
+ }
+ catch ( Exception e )
+ {
+ d = 0.0;
+ }
+ if ( d == -1 )
+ {
+ d = 0.0;
+ }
+ else
+ {
+ d = Math.round( d * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+ resultValue = "" + d;
+ }
+
+ if ( deFlag2 == 0 )
+ {
+ resultValue = " ";
+ }
+ }
else
{
+ resultValue = buffer.toString();
+ deFlag2 = 0;
+ }
+
+ return resultValue;
+ }
+ catch ( NumberFormatException ex )
+ {
+ throw new RuntimeException( "Illegal DataElement id", ex );
+ }
+ }
+
+ public String getIndividualResultIndicatorValue( String formula, Date startDate, Date endDate,
+ OrganisationUnit organisationUnit )
+ {
+
+ int deFlag1 = 0;
+ int deFlag2 = 0;
+ try
+ {
+ Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
+
+ Matcher matcher = pattern.matcher( formula );
+ StringBuffer buffer = new StringBuffer();
+
+ while ( matcher.find() )
+ {
+ String replaceString = matcher.group();
+
+ replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
+
+ replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
+
+ int indicatorId = Integer.parseInt( replaceString );
+
+ Indicator indicator = indicatorService.getIndicator( indicatorId );
+
+ if ( indicator == null )
+ {
+ replaceString = "";
+ matcher.appendReplacement( buffer, replaceString );
+ continue;
+ }
+
+ String numeratorExp = indicator.getNumerator();
+ String denominatorExp = indicator.getDenominator();
+ int indicatorFactor = indicator.getIndicatorType().getFactor();
+ String reportModelTB = "";
+ String numeratorVal = getIndividualResultDataValue( numeratorExp, startDate, endDate, organisationUnit,
+ reportModelTB );
+ String denominatorVal = getIndividualResultDataValue( denominatorExp, startDate, endDate,
+ organisationUnit, reportModelTB );
+
+ double numeratorValue;
+ try
+ {
+ numeratorValue = Double.parseDouble( numeratorVal );
+ }
+ catch ( Exception e )
+ {
+ numeratorValue = 0.0;
+ }
+
+ double denominatorValue;
+ try
+ {
+ denominatorValue = Double.parseDouble( denominatorVal );
+ }
+ catch ( Exception e )
+ {
+ denominatorValue = 1.0;
+ }
+
+ double aggregatedValue;
+ try
+ {
+ aggregatedValue = (numeratorValue / denominatorValue) * indicatorFactor;
+ }
+ catch ( Exception e )
+ {
+ System.out.println( "Exception while calculating Indicator value for Indicaotr "
+ + indicator.getName() );
+ aggregatedValue = 0.0;
+ }
+
replaceString = String.valueOf( aggregatedValue );
deFlag2 = 1;
- }
- matcher.appendReplacement( buffer, replaceString );
- }
-
- matcher.appendTail( buffer );
-
- String resultValue = "";
- if ( deFlag1 == 0 )
- {
- double d = 0.0;
- try
- {
- d = MathUtils.calculateExpression( buffer.toString() );
- }
- catch ( Exception e )
- {
- d = 0.0;
- }
- if ( d == -1 )
- {
- d = 0.0;
- }
+
+ matcher.appendReplacement( buffer, replaceString );
+ }
+
+ matcher.appendTail( buffer );
+
+ String resultValue = "";
+ if ( deFlag1 == 0 )
+ {
+ double d = 0.0;
+ try
+ {
+ d = MathUtils.calculateExpression( buffer.toString() );
+ }
+ catch ( Exception e )
+ {
+ d = 0.0;
+ }
+ if ( d == -1 )
+ {
+ d = 0.0;
+ }
+ else
+ {
+ d = Math.round( d * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
+ resultValue = "" + d;
+ }
+
+ if ( deFlag2 == 0 )
+ {
+ resultValue = " ";
+ }
+ }
else
{
- d = Math.round( d * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
- resultValue = "" + d;
- }
-
- if ( deFlag2 == 0 )
- {
- resultValue = " ";
- }
- }
- else
- {
- resultValue = buffer.toString();
- deFlag2 = 0;
- }
-
- return resultValue;
- }
- catch ( NumberFormatException ex )
- {
- throw new RuntimeException( "Illegal DataElement id", ex );
- }
-}
-
-public String getIndividualResultIndicatorValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit )
- {
-
- int deFlag1 = 0;
- int deFlag2 = 0;
- try
- {
- Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
-
- Matcher matcher = pattern.matcher( formula );
- StringBuffer buffer = new StringBuffer();
-
- while ( matcher.find() )
- {
- String replaceString = matcher.group();
-
- replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
-
- replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
-
- int indicatorId = Integer.parseInt( replaceString );
-
- Indicator indicator = indicatorService.getIndicator( indicatorId );
-
- if ( indicator == null )
- {
- replaceString = "";
- matcher.appendReplacement( buffer, replaceString );
- continue;
- }
-
- String numeratorExp = indicator.getNumerator();
- String denominatorExp = indicator.getDenominator();
- int indicatorFactor = indicator.getIndicatorType().getFactor();
- String reportModelTB = "";
- String numeratorVal = getIndividualResultDataValue( numeratorExp, startDate, endDate, organisationUnit, reportModelTB );
- String denominatorVal = getIndividualResultDataValue( denominatorExp, startDate, endDate, organisationUnit, reportModelTB );
-
- double numeratorValue;
- try
- {
- numeratorValue = Double.parseDouble( numeratorVal );
- } catch ( Exception e )
- {
- numeratorValue = 0.0;
- }
-
- double denominatorValue;
- try
- {
- denominatorValue = Double.parseDouble( denominatorVal );
- } catch ( Exception e )
- {
- denominatorValue = 1.0;
- }
-
- double aggregatedValue;
- try
- {
- aggregatedValue = ( numeratorValue / denominatorValue ) * indicatorFactor;
- }
- catch ( Exception e )
- {
- System.out.println( "Exception while calculating Indicator value for Indicaotr " + indicator.getName() );
- aggregatedValue = 0.0;
- }
-
- replaceString = String.valueOf( aggregatedValue );
- deFlag2 = 1;
-
- matcher.appendReplacement( buffer, replaceString );
- }
-
- matcher.appendTail( buffer );
-
- String resultValue = "";
- if ( deFlag1 == 0 )
- {
- double d = 0.0;
- try
- {
- d = MathUtils.calculateExpression( buffer.toString() );
- } catch ( Exception e )
- {
- d = 0.0;
- }
- if ( d == -1 )
- {
- d = 0.0;
- } else
- {
- d = Math.round( d * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 );
- resultValue = "" + d;
- }
-
- if ( deFlag2 == 0 )
- {
- resultValue = " ";
- }
- } else
- {
- deFlag2 = 0;
- resultValue = buffer.toString();
- }
-
- return resultValue;
-
- }
- catch ( NumberFormatException ex )
- {
- throw new RuntimeException( "Illegal DataElement id", ex );
- }
-
- }
-
-
-// -------------------------------------------------------------------------
-// Get ReportDesign (decode tags) from corresponding xml file
-// -------------------------------------------------------------------------
-
-public List<Report_inDesign> getReportDesignWithMergeCells( String fileName )
-{
- List<Report_inDesign> reportDesignList = new ArrayList<Report_inDesign>();
-
- String path = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue()
- + File.separator + fileName;
- try
- {
- String newpath = System.getenv( "DHIS2_HOME" );
- if ( newpath != null )
- {
- path = newpath + File.separator + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue() + File.separator + fileName;
- }
- }
- catch ( NullPointerException npe )
- {
- System.out.println("DHIS2_HOME not set");
- }
-
- try
- {
- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
- Document doc = docBuilder.parse( new File( path ) );
- if ( doc == null )
- {
- System.out.println( "There is no DECodes related XML file in the ra folder" );
- return null;
- }
-
- NodeList listOfDECodes = doc.getElementsByTagName( "de-code" );
- int totalDEcodes = listOfDECodes.getLength();
- Map<String,String> globalValuesMap = mapGlobalValues();
-
- for ( int s = 0; s < totalDEcodes; s++ )
- {
- Element deCodeElement = (Element) listOfDECodes.item( s );
- NodeList textDECodeList = deCodeElement.getChildNodes();
-
- String expression = ((Node) textDECodeList.item( 0 )).getNodeValue().trim();
-
- // ------------------------replace global values------------------------------------------------
-
- expression = getGlobalExpression(expression, globalValuesMap);
-
- // ---------------------------------------------------------------------------------------------
-
- String stype = deCodeElement.getAttribute( "stype" );
- String ptype = deCodeElement.getAttribute( "type" );
- int sheetno = new Integer( deCodeElement.getAttribute( "sheetno" ) );
- int rowno = new Integer( deCodeElement.getAttribute( "rowno" ) );
- int colno = new Integer( deCodeElement.getAttribute( "colno" ) );
- int rowMerge = new Integer( deCodeElement.getAttribute( "rowmerge" ) );
- int colMerge = new Integer( deCodeElement.getAttribute( "colmerge" ) );
-
- Report_inDesign report_inDesign = new Report_inDesign( stype, ptype, sheetno, rowno, colno, rowMerge, colMerge, expression );
- reportDesignList.add( report_inDesign );
- }
- // end of for loop with s var
- }
- // try block end
- catch ( SAXParseException err )
- {
- System.out.println( "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId() );
- System.out.println( " " + err.getMessage() );
- }
- catch ( SAXException e )
- {
- Exception x = e.getException();
- ((x == null) ? e : x).printStackTrace();
- }
- catch ( Throwable t )
- {
- t.printStackTrace();
- }
- return reportDesignList;
-}
-
-
-
- // -------------------------------------------------------------------------
- // Get Aggregated Result for dataelement expression
+ deFlag2 = 0;
+ resultValue = buffer.toString();
+ }
+
+ return resultValue;
+
+ }
+ catch ( NumberFormatException ex )
+ {
+ throw new RuntimeException( "Illegal DataElement id", ex );
+ }
+
+ }
+
+ // -------------------------------------------------------------------------
+ // Get ReportDesign (decode tags) from corresponding xml file
+ // -------------------------------------------------------------------------
+
+ public List<Report_inDesign> getReportDesignWithMergeCells( String fileName )
+ {
+ List<Report_inDesign> reportDesignList = new ArrayList<Report_inDesign>();
+
+ String path = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator
+ + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue()
+ + File.separator + fileName;
+ try
+ {
+ String newpath = System.getenv( "DHIS2_HOME" );
+ if ( newpath != null )
+ {
+ path = newpath + File.separator
+ + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue()
+ + File.separator + fileName;
+ }
+ }
+ catch ( NullPointerException npe )
+ {
+ System.out.println( "DHIS2_HOME not set" );
+ }
+
+ try
+ {
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+ Document doc = docBuilder.parse( new File( path ) );
+ if ( doc == null )
+ {
+ System.out.println( "There is no DECodes related XML file in the ra folder" );
+ return null;
+ }
+
+ NodeList listOfDECodes = doc.getElementsByTagName( "de-code" );
+ int totalDEcodes = listOfDECodes.getLength();
+ Map<String, String> globalValuesMap = mapGlobalValues();
+
+ for ( int s = 0; s < totalDEcodes; s++ )
+ {
+ Element deCodeElement = (Element) listOfDECodes.item( s );
+ NodeList textDECodeList = deCodeElement.getChildNodes();
+
+ String expression = ((Node) textDECodeList.item( 0 )).getNodeValue().trim();
+
+ // ------------------------replace global
+ // values------------------------------------------------
+
+ expression = getGlobalExpression( expression, globalValuesMap );
+
+ // ---------------------------------------------------------------------------------------------
+
+ String stype = deCodeElement.getAttribute( "stype" );
+ String ptype = deCodeElement.getAttribute( "type" );
+ int sheetno = new Integer( deCodeElement.getAttribute( "sheetno" ) );
+ int rowno = new Integer( deCodeElement.getAttribute( "rowno" ) );
+ int colno = new Integer( deCodeElement.getAttribute( "colno" ) );
+ int rowMerge = new Integer( deCodeElement.getAttribute( "rowmerge" ) );
+ int colMerge = new Integer( deCodeElement.getAttribute( "colmerge" ) );
+
+ Report_inDesign report_inDesign = new Report_inDesign( stype, ptype, sheetno, rowno, colno, rowMerge,
+ colMerge, expression );
+ reportDesignList.add( report_inDesign );
+ }
+ // end of for loop with s var
+ }
+ // try block end
+ catch ( SAXParseException err )
+ {
+ System.out.println( "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId() );
+ System.out.println( " " + err.getMessage() );
+ }
+ catch ( SAXException e )
+ {
+ Exception x = e.getException();
+ ((x == null) ? e : x).printStackTrace();
+ }
+ catch ( Throwable t )
+ {
+ t.printStackTrace();
+ }
+ return reportDesignList;
+ }
+
+ // -------------------------------------------------------------------------
+ // Get Aggregated Result for dataelement expression
// -------------------------------------------------------------------------
public List<Report_inDesign> getReportDesign( String fileName )
{
List<Report_inDesign> reportDesignList = new ArrayList<Report_inDesign>();
-
- String path = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue()
+
+ String path = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator
+ + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue()
+ File.separator + fileName;
try
{
String newpath = System.getenv( "DHIS2_HOME" );
if ( newpath != null )
{
- path = newpath + File.separator + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue() + File.separator + fileName;
+ path = newpath + File.separator
+ + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue()
+ + File.separator + fileName;
}
}
catch ( NullPointerException npe )
{
- System.out.println("DHIS2_HOME not set");
+ System.out.println( "DHIS2_HOME not set" );
}
try
@@ -1687,22 +1727,23 @@
NodeList listOfDECodes = doc.getElementsByTagName( "de-code" );
int totalDEcodes = listOfDECodes.getLength();
- Map<String,String> globalValuesMap = mapGlobalValues();
+ Map<String, String> globalValuesMap = mapGlobalValues();
for ( int s = 0; s < totalDEcodes; s++ )
{
Element deCodeElement = (Element) listOfDECodes.item( s );
NodeList textDECodeList = deCodeElement.getChildNodes();
-
+
String expression = ((Node) textDECodeList.item( 0 )).getNodeValue().trim();
- // ------------------------replace global values------------------------------------------------
+ // ------------------------replace global
+ // values------------------------------------------------
- System.out.println("\n*INFO :<< CHECKING CONFIG FILE SETUP(2) >>");
- System.out.println("*INFO :Global Value: "+expression);
- expression = getGlobalExpression(expression, globalValuesMap);
- System.out.println("*INFO :Local Value: "+expression);
- System.out.println("*INFO :<<CHECK FINISHED>>\n");
+ System.out.println( "\n*INFO :<< CHECKING CONFIG FILE SETUP(2) >>" );
+ System.out.println( "*INFO :Global Value: " + expression );
+ expression = getGlobalExpression( expression, globalValuesMap );
+ System.out.println( "*INFO :Local Value: " + expression );
+ System.out.println( "*INFO :<<CHECK FINISHED>>\n" );
// ---------------------------------------------------------------------------------------------
@@ -1711,7 +1752,7 @@
int sheetno = new Integer( deCodeElement.getAttribute( "sheetno" ) );
int rowno = new Integer( deCodeElement.getAttribute( "rowno" ) );
int colno = new Integer( deCodeElement.getAttribute( "colno" ) );
-
+
Report_inDesign report_inDesign = new Report_inDesign( stype, ptype, sheetno, rowno, colno, expression );
reportDesignList.add( report_inDesign );
}// end of for loop with s var
@@ -1732,8 +1773,7 @@
}
return reportDesignList;
}
-
-
+
public String getResultSurveyValue( String formula, OrganisationUnit organisationUnit )
{
try
@@ -1751,7 +1791,8 @@
replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
- String surveyIdString = replaceString.substring( replaceString.indexOf( '.' ) + 1, replaceString.length() );
+ String surveyIdString = replaceString.substring( replaceString.indexOf( '.' ) + 1, replaceString
+ .length() );
replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
@@ -1763,7 +1804,7 @@
Survey survey = surveyService.getSurvey( surveyId );
- if ( indicator == null || survey == null)
+ if ( indicator == null || survey == null )
{
replaceString = "";
matcher.appendReplacement( buffer, replaceString );
@@ -1772,7 +1813,7 @@
SurveyDataValue surveyDataValue = new SurveyDataValue();
- surveyDataValue = surveyDataValueService.getSurveyDataValue(organisationUnit, survey, indicator);
+ surveyDataValue = surveyDataValueService.getSurveyDataValue( organisationUnit, survey, indicator );
if ( surveyDataValue == null )
{
@@ -1827,7 +1868,7 @@
{
resultValue = buffer.toString();
}
- //System.out.println("Result in Survey : "+ resultValue);
+ // System.out.println("Result in Survey : "+ resultValue);
return resultValue;
}
catch ( NumberFormatException ex )
@@ -1839,11 +1880,12 @@
// -------------------------------------------------------------------------
// Get Aggregated Result for dataelement expression from Aggregated Table
// -------------------------------------------------------------------------
- public String getResultDataValueFromAggregateTable( String formula, Collection<Integer> periodIds, OrganisationUnit organisationUnit , String reportModelTB )
+ public String getResultDataValueFromAggregateTable( String formula, Collection<Integer> periodIds,
+ OrganisationUnit organisationUnit, String reportModelTB )
{
int deFlag1 = 0;
int isAggregated = 0;
-
+
try
{
Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
@@ -1867,7 +1909,8 @@
int optionComboId = Integer.parseInt( optionComboIdStr );
DataElement dataElement = dataElementService.getDataElement( dataElementId );
- DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService.getDataElementCategoryOptionCombo( optionComboId );
+ DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService
+ .getDataElementCategoryOptionCombo( optionComboId );
if ( dataElement == null || optionCombo == null )
{
@@ -1877,8 +1920,9 @@
}
if ( dataElement.getType().equalsIgnoreCase( "int" ) )
{
- Double aggregatedValue = aggregatedDataValueService.getAggregatedValue( dataElement.getId(), optionCombo.getId(), periodIds, organisationUnit.getId() );
-
+ Double aggregatedValue = aggregatedDataValueService.getAggregatedValue( dataElement.getId(),
+ optionCombo.getId(), periodIds, organisationUnit.getId() );
+
if ( aggregatedValue == null )
{
replaceString = NULL_REPLACEMENT;
@@ -1889,14 +1933,14 @@
isAggregated = 1;
}
-
+
}
else
{
deFlag1 = 1;
-
+
Period tempPeriod = new Period();
-
+
if ( periodIds == null || periodIds.isEmpty() )
{
replaceString = "";
@@ -1931,7 +1975,7 @@
}
matcher.appendTail( buffer );
-
+
if ( deFlag1 == 0 )
{
double d = 0.0;
@@ -1978,7 +2022,7 @@
resultValue = buffer.toString();
}
- if( isAggregated == 0 )
+ if ( isAggregated == 0 )
{
resultValue = " ";
}
@@ -1996,156 +2040,189 @@
}
}
- public Map<String, String> getResultDataValueFromAggregateTable( Integer orgunitId, String dataElmentIdsByComma, String periodIdsByComma )
+ public Map<String, String> getResultDataValueFromAggregateTable( Integer orgunitId, String dataElmentIdsByComma,
+ String periodIdsByComma )
{
Map<String, String> aggDeMap = new HashMap<String, String>();
DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
try
{
String query = "";
- if( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
{
- query = "SELECT dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM aggregateddatavalue" +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
- " organisationunitid = "+ orgunitId +" AND "+
- " periodid IN (" + periodIdsByComma +") GROUP BY dataelementid,categoryoptioncomboid";
+ query = "SELECT dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM aggregateddatavalue"
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + " ) AND "
+ + " organisationunitid = "
+ + orgunitId
+ + " AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid";
}
- else if( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
{
- query = "SELECT dataelementid,categoryoptioncomboid, SUM( value ) FROM aggregateddatavalue" +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
- " organisationunitid = "+ orgunitId +" AND "+
- " periodid IN (" + periodIdsByComma +") GROUP BY dataelementid,categoryoptioncomboid";
+ query = "SELECT dataelementid,categoryoptioncomboid, SUM( value ) FROM aggregateddatavalue"
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " organisationunitid = "
+ + orgunitId + " AND " + " periodid IN (" + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid";
}
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
+
while ( rs.next() )
{
Integer deId = rs.getInt( 1 );
Integer optionComId = rs.getInt( 2 );
Double aggregatedValue = rs.getDouble( 3 );
- if( aggregatedValue != null )
+ if ( aggregatedValue != null )
{
- aggDeMap.put( deId+"."+optionComId, ""+aggregatedValue );
+ aggDeMap.put( deId + "." + optionComId, "" + aggregatedValue );
}
}
-
+
return aggDeMap;
}
- catch( Exception e )
- {
- throw new RuntimeException( "Illegal DataElement id", e );
- }
- }
-
- public Map<String, String> getResultDataValueFromAggregateTableByPeriodAgg( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
- {
- Map<String, String> aggDataMap = new HashMap<String, String>();
- DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
- try
- {
- String query = "";
- if( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
- {
- query = "SELECT organisationunitid, dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM aggregateddatavalue" +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + ") AND "+
- " organisationunitid IN ("+ orgUnitIdsByComma +") AND "+
- " periodid IN (" + periodIdsByComma +") " +
- " GROUP BY organisationunitid,dataelementid,categoryoptioncomboid";
- }
- else if( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
- {
- query = "SELECT organisationunitid, dataelementid,categoryoptioncomboid, SUM(value) FROM aggregateddatavalue" +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + ") AND "+
- " organisationunitid IN ("+ orgUnitIdsByComma +") AND "+
- " periodid IN (" + periodIdsByComma +") " +
- " GROUP BY organisationunitid,dataelementid,categoryoptioncomboid";
- }
-
- SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
- while ( rs.next() )
- {
- Integer ouId = rs.getInt( 1 );
- Integer deId = rs.getInt( 2 );
- Integer optionComId = rs.getInt( 3 );
- Double aggregatedValue = rs.getDouble( 4 );
- if( aggregatedValue != null )
- {
- aggDataMap.put( ouId+":"+deId+":"+optionComId, ""+aggregatedValue );
- }
- }
-
- return aggDataMap;
- }
- catch( Exception e )
- {
- throw new RuntimeException( "Illegal DataElement id", e );
- }
- }
-
-
- public Map<String, String> getAggDataFromAggDataValueTableForOrgUnitWise( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
- {
- Map<String, String> aggDataMap = new HashMap<String, String>();
- DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
- try
- {
- String query = "";
- if( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
- {
- query = "SELECT organisationunitid, dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM aggregateddatavalue" +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + ") AND "+
- " organisationunitid IN ("+ orgUnitIdsByComma +") AND "+
- " periodid IN (" + periodIdsByComma +") " +
- " GROUP BY organisationunitid,dataelementid,categoryoptioncomboid";
- }
- else if( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
- {
- query = "SELECT organisationunitid, dataelementid,categoryoptioncomboid, SUM(value) FROM aggregateddatavalue" +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + ") AND "+
- " organisationunitid IN ("+ orgUnitIdsByComma +") AND "+
- " periodid IN (" + periodIdsByComma +") " +
- " GROUP BY organisationunitid,dataelementid,categoryoptioncomboid";
- }
-
- SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
- while ( rs.next() )
- {
- Integer ouId = rs.getInt( 1 );
- Integer deId = rs.getInt( 2 );
- Integer optionComId = rs.getInt( 3 );
- Double aggregatedValue = rs.getDouble( 4 );
- if( aggregatedValue != null )
- {
- aggDataMap.put( deId+"."+optionComId+":"+ouId, ""+aggregatedValue );
- }
- }
-
- return aggDataMap;
- }
- catch( Exception e )
- {
- throw new RuntimeException( "Illegal DataElement id", e );
- }
- }
-
-
-
- public Map<String, String> getResultDataValueFromAggregateTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
- {
- Map<String, String> aggDataMap = new HashMap<String, String>();
- try
- {
- String query = "SELECT organisationunitid,dataelementid,categoryoptioncomboid,periodid,value FROM aggregateddatavalue " +
- " WHERE organisationunitid IN ("+ orgUnitIdsByComma +") AND "+
- " dataelementid IN ("+ dataElmentIdsByComma +") AND "+
- " periodid IN ("+ periodIdsByComma +")";
-
- SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Illegal DataElement id", e );
+ }
+ }
+
+ public Map<String, String> getResultDataValueFromAggregateTableByPeriodAgg( String orgUnitIdsByComma,
+ String dataElmentIdsByComma, String periodIdsByComma )
+ {
+ Map<String, String> aggDataMap = new HashMap<String, String>();
+ DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
+ try
+ {
+ String query = "";
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ {
+ query = "SELECT organisationunitid, dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM aggregateddatavalue"
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + ") AND "
+ + " organisationunitid IN ("
+ + orgUnitIdsByComma
+ + ") AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") "
+ + " GROUP BY organisationunitid,dataelementid,categoryoptioncomboid";
+ }
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ {
+ query = "SELECT organisationunitid, dataelementid,categoryoptioncomboid, SUM(value) FROM aggregateddatavalue"
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + ") AND "
+ + " organisationunitid IN ("
+ + orgUnitIdsByComma
+ + ") AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") "
+ + " GROUP BY organisationunitid,dataelementid,categoryoptioncomboid";
+ }
+
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
+ while ( rs.next() )
+ {
+ Integer ouId = rs.getInt( 1 );
+ Integer deId = rs.getInt( 2 );
+ Integer optionComId = rs.getInt( 3 );
+ Double aggregatedValue = rs.getDouble( 4 );
+ if ( aggregatedValue != null )
+ {
+ aggDataMap.put( ouId + ":" + deId + ":" + optionComId, "" + aggregatedValue );
+ }
+ }
+
+ return aggDataMap;
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Illegal DataElement id", e );
+ }
+ }
+
+ public Map<String, String> getAggDataFromAggDataValueTableForOrgUnitWise( String orgUnitIdsByComma,
+ String dataElmentIdsByComma, String periodIdsByComma )
+ {
+ Map<String, String> aggDataMap = new HashMap<String, String>();
+ DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
+ try
+ {
+ String query = "";
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ {
+ query = "SELECT organisationunitid, dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM aggregateddatavalue"
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + ") AND "
+ + " organisationunitid IN ("
+ + orgUnitIdsByComma
+ + ") AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") "
+ + " GROUP BY organisationunitid,dataelementid,categoryoptioncomboid";
+ }
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ {
+ query = "SELECT organisationunitid, dataelementid,categoryoptioncomboid, SUM(value) FROM aggregateddatavalue"
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + ") AND "
+ + " organisationunitid IN ("
+ + orgUnitIdsByComma
+ + ") AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") "
+ + " GROUP BY organisationunitid,dataelementid,categoryoptioncomboid";
+ }
+
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
+ while ( rs.next() )
+ {
+ Integer ouId = rs.getInt( 1 );
+ Integer deId = rs.getInt( 2 );
+ Integer optionComId = rs.getInt( 3 );
+ Double aggregatedValue = rs.getDouble( 4 );
+ if ( aggregatedValue != null )
+ {
+ aggDataMap.put( deId + "." + optionComId + ":" + ouId, "" + aggregatedValue );
+ }
+ }
+
+ return aggDataMap;
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Illegal DataElement id", e );
+ }
+ }
+
+ public Map<String, String> getResultDataValueFromAggregateTable( String orgUnitIdsByComma,
+ String dataElmentIdsByComma, String periodIdsByComma )
+ {
+ Map<String, String> aggDataMap = new HashMap<String, String>();
+ try
+ {
+ String query = "SELECT organisationunitid,dataelementid,categoryoptioncomboid,periodid,value FROM aggregateddatavalue "
+ + " WHERE organisationunitid IN ("
+ + orgUnitIdsByComma
+ + ") AND "
+ + " dataelementid IN ("
+ + dataElmentIdsByComma + ") AND " + " periodid IN (" + periodIdsByComma + ")";
+
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
while ( rs.next() )
{
Integer orgUnitId = rs.getInt( 1 );
@@ -2153,163 +2230,177 @@
Integer optionComId = rs.getInt( 3 );
Integer periodId = rs.getInt( 4 );
Double aggregatedValue = rs.getDouble( 5 );
- if( aggregatedValue != null )
+ if ( aggregatedValue != null )
{
- aggDataMap.put( orgUnitId+":"+deId+":"+optionComId+":"+periodId, ""+aggregatedValue );
+ aggDataMap.put( orgUnitId + ":" + deId + ":" + optionComId + ":" + periodId, "" + aggregatedValue );
}
}
-
+
return aggDataMap;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new RuntimeException( "Illegal DataElement id", e );
}
}
-
- public Map<String, String> getAggDataFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+ public Map<String, String> getAggDataFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma,
+ String periodIdsByComma )
{
Map<String, String> aggDeMap = new HashMap<String, String>();
DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
try
{
String query = "";
- if( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
{
- query = "SELECT dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM datavalue " +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
- " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
- " periodid IN (" + periodIdsByComma +") GROUP BY dataelementid,categoryoptioncomboid";
+ query = "SELECT dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM datavalue "
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " sourceid IN ("
+ + orgUnitIdsByComma + " ) AND " + " periodid IN (" + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid";
}
- else if( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
{
- query = "SELECT dataelementid,categoryoptioncomboid, SUM(value) FROM datavalue " +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
- " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
- " periodid IN (" + periodIdsByComma +") GROUP BY dataelementid,categoryoptioncomboid";
+ query = "SELECT dataelementid,categoryoptioncomboid, SUM(value) FROM datavalue "
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " sourceid IN ("
+ + orgUnitIdsByComma + " ) AND " + " periodid IN (" + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid";
}
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
+
while ( rs.next() )
{
Integer deId = rs.getInt( 1 );
Integer optionComId = rs.getInt( 2 );
Double aggregatedValue = rs.getDouble( 3 );
- if( aggregatedValue != null )
+ if ( aggregatedValue != null )
{
- aggDeMap.put( deId+"."+optionComId, ""+aggregatedValue );
+ aggDeMap.put( deId + "." + optionComId, "" + aggregatedValue );
}
}
-
+
return aggDeMap;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new RuntimeException( "Illegal DataElement id", e );
}
}
- public Map<String, String> getAggDataFromDataValueTableByDeAndPeriodwise( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+ public Map<String, String> getAggDataFromDataValueTableByDeAndPeriodwise( String orgUnitIdsByComma,
+ String dataElmentIdsByComma, String periodIdsByComma )
{
Map<String, String> aggDataMap = new HashMap<String, String>();
DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
try
{
String query = "";
- if( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
{
- query = "SELECT dataelementid,categoryoptioncomboid,periodid,SUM( cast( value as numeric) ) FROM datavalue " +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
- " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
- " periodid IN (" + periodIdsByComma +") GROUP BY dataelementid,categoryoptioncomboid,periodid";
+ query = "SELECT dataelementid,categoryoptioncomboid,periodid,SUM( cast( value as numeric) ) FROM datavalue "
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + " ) AND "
+ + " sourceid IN ("
+ + orgUnitIdsByComma
+ + " ) AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid,periodid";
}
- else if( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
{
- query = "SELECT dataelementid,categoryoptioncomboid,periodid,SUM( value ) FROM datavalue " +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
- " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
- " periodid IN (" + periodIdsByComma +") GROUP BY dataelementid,categoryoptioncomboid,periodid";
+ query = "SELECT dataelementid,categoryoptioncomboid,periodid,SUM( value ) FROM datavalue "
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " sourceid IN ("
+ + orgUnitIdsByComma + " ) AND " + " periodid IN (" + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid,periodid";
}
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
+
while ( rs.next() )
{
Integer deId = rs.getInt( 1 );
Integer optionComId = rs.getInt( 2 );
Integer periodId = rs.getInt( 3 );
Double aggregatedValue = rs.getDouble( 4 );
- if( aggregatedValue != null )
+ if ( aggregatedValue != null )
{
- aggDataMap.put( deId+":"+optionComId+":"+periodId, ""+aggregatedValue );
+ aggDataMap.put( deId + ":" + optionComId + ":" + periodId, "" + aggregatedValue );
}
}
-
+
return aggDataMap;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new RuntimeException( "Illegal DataElement id", e );
}
- }
+ }
- public Map<String, String> getDataFromDataValueTableByPeriodAgg( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+ public Map<String, String> getDataFromDataValueTableByPeriodAgg( String orgUnitIdsByComma,
+ String dataElmentIdsByComma, String periodIdsByComma )
{
Map<String, String> aggDataMap = new HashMap<String, String>();
DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
try
{
String query = "";
- if( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
- {
- query = "SELECT sourceid,dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM datavalue " +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
- " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
- " periodid IN (" + periodIdsByComma +") GROUP BY sourceid,dataelementid,categoryoptioncomboid";
- }
- else if( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
- {
- query = "SELECT sourceid,dataelementid,categoryoptioncomboid, SUM(value) FROM datavalue " +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
- " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
- " periodid IN (" + periodIdsByComma +") GROUP BY sourceid,dataelementid,categoryoptioncomboid";
- }
-
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ {
+ query = "SELECT sourceid,dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM datavalue "
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + " ) AND "
+ + " sourceid IN ("
+ + orgUnitIdsByComma
+ + " ) AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") GROUP BY sourceid,dataelementid,categoryoptioncomboid";
+ }
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ {
+ query = "SELECT sourceid,dataelementid,categoryoptioncomboid, SUM(value) FROM datavalue "
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " sourceid IN ("
+ + orgUnitIdsByComma + " ) AND " + " periodid IN (" + periodIdsByComma
+ + ") GROUP BY sourceid,dataelementid,categoryoptioncomboid";
+ }
+
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
+
while ( rs.next() )
{
Integer orgUnitId = rs.getInt( 1 );
Integer deId = rs.getInt( 2 );
Integer optionComId = rs.getInt( 3 );
Double aggregatedValue = rs.getDouble( 4 );
- if( aggregatedValue != null )
+ if ( aggregatedValue != null )
{
- aggDataMap.put( orgUnitId+":"+deId+":"+optionComId, ""+aggregatedValue );
+ aggDataMap.put( orgUnitId + ":" + deId + ":" + optionComId, "" + aggregatedValue );
}
}
-
+
return aggDataMap;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new RuntimeException( "Illegal DataElement id", e );
}
- }
+ }
- public Map<String, String> getDataFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+ public Map<String, String> getDataFromDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma,
+ String periodIdsByComma )
{
Map<String, String> aggDataMap = new HashMap<String, String>();
try
{
- String query = "SELECT sourceid,dataelementid,categoryoptioncomboid,periodid,value FROM datavalue " +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND "+
- " sourceid IN ("+ orgUnitIdsByComma +" ) AND "+
- " periodid IN (" + periodIdsByComma +")";
+ String query = "SELECT sourceid,dataelementid,categoryoptioncomboid,periodid,value FROM datavalue "
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " sourceid IN (" + orgUnitIdsByComma
+ + " ) AND " + " periodid IN (" + periodIdsByComma + ")";
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
+
while ( rs.next() )
{
Integer orgUnitId = rs.getInt( 1 );
@@ -2317,26 +2408,25 @@
Integer optionComId = rs.getInt( 3 );
Integer periodId = rs.getInt( 4 );
Double aggregatedValue = rs.getDouble( 5 );
- if( aggregatedValue != null )
+ if ( aggregatedValue != null )
{
- aggDataMap.put( orgUnitId+":"+deId+":"+optionComId+":"+periodId, ""+aggregatedValue );
+ aggDataMap.put( orgUnitId + ":" + deId + ":" + optionComId + ":" + periodId, "" + aggregatedValue );
}
}
-
+
return aggDataMap;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new RuntimeException( "Illegal DataElement id", e );
}
- }
+ }
-
public String getResultDataValueFromAggregateTable( String formula, String periodIdsByComma, Integer orgunitId )
{
DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
String query = "";
-
+
try
{
Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
@@ -2358,26 +2448,24 @@
int dataElementId = Integer.parseInt( replaceString );
int optionComboId = Integer.parseInt( optionComboIdStr );
-
- if( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
- {
- query = "SELECT SUM( cast( value as numeric) ) FROM aggregateddatavalue WHERE dataelementid = " + dataElementId +
- " AND categoryoptioncomboid = "+optionComboId +
- " AND periodid IN ("+ periodIdsByComma +")"+
- " AND organisationunitid = "+ orgunitId;
- }
- else if( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
- {
- query = "SELECT SUM(value) FROM aggregateddatavalue WHERE dataelementid = " + dataElementId +
- " AND categoryoptioncomboid = "+optionComboId +
- " AND periodid IN ("+ periodIdsByComma +")"+
- " AND organisationunitid = "+ orgunitId;
- }
-
+
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ {
+ query = "SELECT SUM( cast( value as numeric) ) FROM aggregateddatavalue WHERE dataelementid = "
+ + dataElementId + " AND categoryoptioncomboid = " + optionComboId + " AND periodid IN ("
+ + periodIdsByComma + ")" + " AND organisationunitid = " + orgunitId;
+ }
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ {
+ query = "SELECT SUM(value) FROM aggregateddatavalue WHERE dataelementid = " + dataElementId
+ + " AND categoryoptioncomboid = " + optionComboId + " AND periodid IN (" + periodIdsByComma
+ + ")" + " AND organisationunitid = " + orgunitId;
+ }
+
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
Double aggregatedValue = null;
- if( rs.next() )
+ if ( rs.next() )
{
aggregatedValue = rs.getDouble( 1 );
}
@@ -2390,14 +2478,14 @@
{
replaceString = String.valueOf( aggregatedValue );
}
-
+
matcher.appendReplacement( buffer, replaceString );
resultValue = replaceString;
}
matcher.appendTail( buffer );
-
+
double d = 0.0;
try
{
@@ -2408,7 +2496,7 @@
d = 0.0;
resultValue = "";
}
-
+
resultValue = "" + (double) d;
return resultValue;
@@ -2418,7 +2506,7 @@
throw new RuntimeException( "Illegal DataElement id", ex );
}
}
-
+
public String getSurveyDesc( String formula )
{
try
@@ -2456,7 +2544,8 @@
matcher.appendTail( buffer );
- String resultValue = buffer.toString();;
+ String resultValue = buffer.toString();
+ ;
return resultValue;
}
@@ -2466,80 +2555,80 @@
}
}
- public String getAggCountForTextData( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit )
+ public String getAggCountForTextData( String formula, Date startDate, Date endDate,
+ OrganisationUnit organisationUnit )
{
String[] partsOfFormula = formula.split( ":" );
-
+
int dataElementId = Integer.parseInt( partsOfFormula[0] );
int optComboId = Integer.parseInt( partsOfFormula[1] );
String compareText = partsOfFormula[2];
-
+
Collection<Period> periods = new ArrayList<Period>( periodService.getPeriodsBetweenDates( startDate, endDate ) );
- Collection<OrganisationUnit> orgUnits = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId() ) );
-
+ Collection<OrganisationUnit> orgUnits = new ArrayList<OrganisationUnit>( organisationUnitService
+ .getOrganisationUnitWithChildren( organisationUnit.getId() ) );
+
int recordCount = 0;
try
{
- String query = "SELECT COUNT(*) FROM datavalue WHERE dataelementid = " + dataElementId +
- " AND categoryoptioncomboid = "+optComboId +
- " AND periodid IN ("+ getCommaDelimitedString( getIdentifiers(Period.class, periods )) +")"+
- " AND sourceid IN ("+ getCommaDelimitedString( getIdentifiers(OrganisationUnit.class, orgUnits )) +")" +
- " AND value like '" + compareText + "'";
-
+ String query = "SELECT COUNT(*) FROM datavalue WHERE dataelementid = " + dataElementId
+ + " AND categoryoptioncomboid = " + optComboId + " AND periodid IN ("
+ + getCommaDelimitedString( getIdentifiers( Period.class, periods ) ) + ")" + " AND sourceid IN ("
+ + getCommaDelimitedString( getIdentifiers( OrganisationUnit.class, orgUnits ) ) + ")"
+ + " AND value like '" + compareText + "'";
+
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
- if( rs.next() )
+
+ if ( rs.next() )
{
recordCount = rs.getInt( 1 );
}
- }
+ }
catch ( Exception e )
{
e.printStackTrace();
}
-
- return ""+recordCount;
+
+ return "" + recordCount;
}
-
-
+
public String getCountForTextData( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit )
{
String[] partsOfFormula = formula.split( ":" );
-
+
int dataElementId = Integer.parseInt( partsOfFormula[0] );
int optComboId = Integer.parseInt( partsOfFormula[1] );
String compareText = partsOfFormula[2];
-
+
Collection<Period> periods = new ArrayList<Period>( periodService.getPeriodsBetweenDates( startDate, endDate ) );
-
+
int recordCount = 0;
try
{
- String query = "SELECT COUNT(*) FROM datavalue WHERE dataelementid = " + dataElementId +
- " AND categoryoptioncomboid = "+optComboId +
- " AND periodid IN ("+ getCommaDelimitedString( getIdentifiers(Period.class, periods )) +")"+
- " AND sourceid IN ("+ organisationUnit.getId() +")" +
- " AND value like '" + compareText + "'";
-
+ String query = "SELECT COUNT(*) FROM datavalue WHERE dataelementid = " + dataElementId
+ + " AND categoryoptioncomboid = " + optComboId + " AND periodid IN ("
+ + getCommaDelimitedString( getIdentifiers( Period.class, periods ) ) + ")" + " AND sourceid IN ("
+ + organisationUnit.getId() + ")" + " AND value like '" + compareText + "'";
+
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
- if( rs.next() )
+
+ if ( rs.next() )
{
recordCount = rs.getInt( 1 );
}
- }
+ }
catch ( Exception e )
{
e.printStackTrace();
}
-
- return ""+recordCount;
+
+ return "" + recordCount;
}
-
+
public String getDataelementIdsAsString( List<Indicator> indicatorList )
{
String dataElmentIdsByComma = "-1";
- for( Indicator indicator : indicatorList )
+ for ( Indicator indicator : indicatorList )
{
String formula = indicator.getNumerator() + " + " + indicator.getDenominator();
try
@@ -2562,19 +2651,19 @@
matcher.appendReplacement( buffer, replaceString );
}
}
- catch( Exception e )
+ catch ( Exception e )
{
-
+
}
}
-
+
return dataElmentIdsByComma;
}
public String getDataelementIds( List<Report_inDesign> reportDesignList )
{
String dataElmentIdsByComma = "-1";
- for( Report_inDesign report_inDesign : reportDesignList )
+ for ( Report_inDesign report_inDesign : reportDesignList )
{
String formula = report_inDesign.getExpression();
try
@@ -2597,12 +2686,12 @@
matcher.appendReplacement( buffer, replaceString );
}
}
- catch( Exception e )
+ catch ( Exception e )
{
-
+
}
}
-
+
return dataElmentIdsByComma;
}
@@ -2624,19 +2713,19 @@
replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
replaceString = aggDeMap.get( replaceString );
-
- if( replaceString == null )
+
+ if ( replaceString == null )
{
replaceString = "0";
}
-
+
matcher.appendReplacement( buffer, replaceString );
resultValue = replaceString;
}
matcher.appendTail( buffer );
-
+
double d = 0.0;
try
{
@@ -2647,7 +2736,7 @@
d = 0.0;
resultValue = "";
}
-
+
resultValue = "" + (double) d;
return resultValue;
@@ -2657,96 +2746,98 @@
throw new RuntimeException( "Illegal DataElement id", ex );
}
}
-
- public Map<String, List<String>> getIndicatorDataValueFromAggregateTable( Integer orgunitId, String indicatorIdsByComma, Integer periodId )
+
+ public Map<String, List<String>> getIndicatorDataValueFromAggregateTable( Integer orgunitId,
+ String indicatorIdsByComma, Integer periodId )
{
Map<String, List<String>> aggIndicatorMap = new HashMap<String, List<String>>();
try
{
- String query = "SELECT indicatorid, numeratorvalue, denominatorvalue FROM aggregatedindicatorvalue " +
- " WHERE indicatorid IN (" + indicatorIdsByComma + " ) AND "+
- " organisationunitid = "+ orgunitId +" AND "+
- " periodid = " + periodId;
+ String query = "SELECT indicatorid, numeratorvalue, denominatorvalue FROM aggregatedindicatorvalue "
+ + " WHERE indicatorid IN (" + indicatorIdsByComma + " ) AND " + " organisationunitid = " + orgunitId
+ + " AND " + " periodid = " + periodId;
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
+
while ( rs.next() )
- {
+ {
Integer indicatorId = rs.getInt( 1 );
Double aggregatedIndicatorValue = rs.getDouble( 2 );
Double aggNumeratorValue = rs.getDouble( 3 );
Double aggDenominatorValue = rs.getDouble( 4 );
-
- List<String> tempList = new ArrayList<String>();
- if( aggregatedIndicatorValue != null )
+
+ List<String> tempList = new ArrayList<String>();
+ if ( aggregatedIndicatorValue != null )
{
- tempList.add( ""+aggregatedIndicatorValue );
- tempList.add( ""+aggNumeratorValue );
- tempList.add( ""+aggDenominatorValue );
-
- aggIndicatorMap.put( ""+indicatorId, tempList );
+ tempList.add( "" + aggregatedIndicatorValue );
+ tempList.add( "" + aggNumeratorValue );
+ tempList.add( "" + aggDenominatorValue );
+
+ aggIndicatorMap.put( "" + indicatorId, tempList );
}
}
-
+
return aggIndicatorMap;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new RuntimeException( "Illegal DataElement id", e );
}
- }
-
- public double getIndividualIndicatorValue( Indicator indicator, OrganisationUnit orgunit, Date startDate, Date endDate )
+ }
+
+ public double getIndividualIndicatorValue( Indicator indicator, OrganisationUnit orgunit, Date startDate,
+ Date endDate )
{
String numeratorExp = indicator.getNumerator();
String denominatorExp = indicator.getDenominator();
int indicatorFactor = indicator.getIndicatorType().getFactor();
String reportModelTB = "";
- String numeratorVal = getIndividualResultDataValue( numeratorExp, startDate, endDate, orgunit, reportModelTB );
- String denominatorVal = getIndividualResultDataValue( denominatorExp, startDate, endDate, orgunit, reportModelTB );
-
+ String numeratorVal = getIndividualResultDataValue( numeratorExp, startDate, endDate, orgunit, reportModelTB );
+ String denominatorVal = getIndividualResultDataValue( denominatorExp, startDate, endDate, orgunit,
+ reportModelTB );
+
double numeratorValue;
try
{
numeratorValue = Double.parseDouble( numeratorVal );
- }
+ }
catch ( Exception e )
{
numeratorValue = 0.0;
}
-
+
double denominatorValue;
try
{
denominatorValue = Double.parseDouble( denominatorVal );
- }
+ }
catch ( Exception e )
{
denominatorValue = 1.0;
}
-
+
double aggregatedValue;
try
{
- if( denominatorValue == 0 )
+ if ( denominatorValue == 0 )
{
aggregatedValue = 0.0;
}
else
{
- aggregatedValue = ( numeratorValue / denominatorValue ) * indicatorFactor;
+ aggregatedValue = (numeratorValue / denominatorValue) * indicatorFactor;
}
- }
+ }
catch ( Exception e )
{
System.out.println( "Exception while calculating Indicator value for Indicaotr " + indicator.getName() );
aggregatedValue = 0.0;
}
-
+
return aggregatedValue;
}
- public Map<Integer, Integer> getOrgunitLevelMap( )
+ public Map<Integer, Integer> getOrgunitLevelMap()
{
Map<Integer, Integer> orgUnitLevelMap = new HashMap<Integer, Integer>();
try
@@ -2754,86 +2845,92 @@
String query = "SELECT organisationunitid,level FROM _orgunitstructure";
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
+
while ( rs.next() )
- {
+ {
Integer orgUnitId = rs.getInt( 1 );
Integer level = rs.getInt( 2 );
-
+
orgUnitLevelMap.put( orgUnitId, level );
}
-
+
return orgUnitLevelMap;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new RuntimeException( "Illegal DataElement id", e );
}
}
//
-
- public Map<String, String> getLLDeathDataFromLLDataValueTable( Integer orgunitId, String dataElmentIdsForLLDeathByComma, String periodIdsByComma , String recordNoByComma )
+
+ public Map<String, String> getLLDeathDataFromLLDataValueTable( Integer orgunitId,
+ String dataElmentIdsForLLDeathByComma, String periodIdsByComma, String recordNoByComma )
{
Map<String, String> aggDeForLLDeathMap = new HashMap<String, String>();
- // DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
+ // DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
try
{
String query = "";
- query = "SELECT value,dataelementid,categoryoptioncomboid,recordno FROM lldatavalue" +
- " WHERE dataelementid IN (" + dataElmentIdsForLLDeathByComma + " ) AND "+
- " sourceid = "+ orgunitId +" AND "+
- " periodid IN (" + periodIdsByComma +") AND recordno IN (" + recordNoByComma + ")";
-
+ query = "SELECT value,dataelementid,categoryoptioncomboid,recordno FROM lldatavalue"
+ + " WHERE dataelementid IN (" + dataElmentIdsForLLDeathByComma + " ) AND " + " sourceid = " + orgunitId
+ + " AND " + " periodid IN (" + periodIdsByComma + ") AND recordno IN (" + recordNoByComma + ")";
+
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
-
+
String tempValue = "";
-
+
while ( rs.next() )
{
tempValue = rs.getString( 1 );
Integer deId = rs.getInt( 2 );
Integer optionComId = rs.getInt( 3 );
Integer recordNo = rs.getInt( 4 );
- //Double aggregatedValue = rs.getDouble( 3 );
- if( tempValue != null )
+ // Double aggregatedValue = rs.getDouble( 3 );
+ if ( tempValue != null )
{
- aggDeForLLDeathMap.put( deId+"."+optionComId+":"+recordNo, ""+ tempValue );
+ aggDeForLLDeathMap.put( deId + "." + optionComId + ":" + recordNo, "" + tempValue );
}
}
-
+
return aggDeForLLDeathMap;
}
- catch( Exception e )
+ catch ( Exception e )
{
throw new RuntimeException( "Illegal DataElement id", e );
}
- }
+ }
- public Map<String, String> getAggDataFromDataValueTableForOrgUnitWise( String orgUnitIdsByComma, String dataElmentIdsByComma, String periodIdsByComma )
+ public Map<String, String> getAggDataFromDataValueTableForOrgUnitWise( String orgUnitIdsByComma,
+ String dataElmentIdsByComma, String periodIdsByComma )
{
Map<String, String> aggDataMap = new HashMap<String, String>();
DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
try
{
String query = "";
- if( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
- {
- query = "SELECT sourceid, dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM datavalue" +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + ") AND "+
- " sourceid IN ("+ orgUnitIdsByComma +") AND "+
- " periodid IN (" + periodIdsByComma +") " +
- " GROUP BY sourceid,dataelementid,categoryoptioncomboid";
- }
- else if( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
- {
- query = "SELECT sourceid, dataelementid,categoryoptioncomboid, SUM(value) FROM datavalue" +
- " WHERE dataelementid IN (" + dataElmentIdsByComma + ") AND "+
- " sourceid IN ("+ orgUnitIdsByComma +") AND "+
- " periodid IN (" + periodIdsByComma +") " +
- " GROUP BY sourceid,dataelementid,categoryoptioncomboid";
- }
-
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ {
+ query = "SELECT sourceid, dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM datavalue"
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + ") AND "
+ + " sourceid IN ("
+ + orgUnitIdsByComma
+ + ") AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") "
+ + " GROUP BY sourceid,dataelementid,categoryoptioncomboid";
+ }
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ {
+ query = "SELECT sourceid, dataelementid,categoryoptioncomboid, SUM(value) FROM datavalue"
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + ") AND " + " sourceid IN ("
+ + orgUnitIdsByComma + ") AND " + " periodid IN (" + periodIdsByComma + ") "
+ + " GROUP BY sourceid,dataelementid,categoryoptioncomboid";
+ }
+
SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
String tempValue = "";
while ( rs.next() )
@@ -2842,16 +2939,350 @@
Integer deId = rs.getInt( 2 );
Integer optionComId = rs.getInt( 3 );
tempValue = rs.getString( 4 );
- //Double aggregatedValue = rs.getDouble( 4 );
- if( tempValue != null )
- {
- aggDataMap.put( deId+"."+optionComId+":"+ouId, ""+tempValue );
- }
- }
-
- return aggDataMap;
- }
- catch( Exception e )
+ // Double aggregatedValue = rs.getDouble( 4 );
+ if ( tempValue != null )
+ {
+ aggDataMap.put( deId + "." + optionComId + ":" + ouId, "" + tempValue );
+ }
+ }
+
+ return aggDataMap;
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Illegal DataElement id", e );
+ }
+ }
+
+ public Map<String, String> getResultDataValueFromDataValueTable( String orgUnitIdsByComma,
+ String dataElmentIdsByComma, String periodIdsByComma )
+ {
+ Map<String, String> aggDataMap = new HashMap<String, String>();
+ DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
+ try
+ {
+ String query = "";
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ {
+ query = "SELECT sourceid,dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM datavalue "
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + " ) AND "
+ + " sourceid IN ("
+ + orgUnitIdsByComma
+ + " ) AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") GROUP BY sourceid,dataelementid,categoryoptioncomboid";
+ }
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ {
+ query = "SELECT sourceid,dataelementid,categoryoptioncomboid, SUM(value) FROM datavalue "
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " sourceid IN ("
+ + orgUnitIdsByComma + " ) AND " + " periodid IN (" + periodIdsByComma
+ + ") GROUP BY sourceid,dataelementid,categoryoptioncomboid";
+ }
+
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
+ while ( rs.next() )
+ {
+ Integer orgUnitId = rs.getInt( 1 );
+ Integer deId = rs.getInt( 2 );
+ Integer optionComId = rs.getInt( 3 );
+ Double aggregatedValue = rs.getDouble( 4 );
+ if ( aggregatedValue != null )
+ {
+ aggDataMap.put( deId + "." + optionComId + ":" + orgUnitId, "" + aggregatedValue );
+
+ // aggDataMap.put( orgUnitId+":"+deId+":"+optionComId,
+ // ""+aggregatedValue );
+ }
+ }
+
+ return aggDataMap;
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Illegal DataElement id", e );
+ }
+ }
+
+ public Map<String, String> getAggDataFromAggDataValueTable( String orgUnitIdsByComma, String dataElmentIdsByComma,
+ String periodIdsByComma )
+ {
+ // System.out.println("o,p,d"+orgUnitIdsByComma+periodIdsByComma+dataElmentIdsByComma
+ // );
+ Map<String, String> aggDeMap = new HashMap<String, String>();
+ DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
+ try
+ {
+ String query = "";
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ {
+ query = "SELECT dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM aggregateddatavalue "
+ + " WHERE dataelementid IN ("
+ + dataElmentIdsByComma
+ + " ) AND "
+ + " organisationunitid IN ("
+ + orgUnitIdsByComma
+ + " ) AND "
+ + " periodid IN ("
+ + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid";
+ }
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ {
+ query = "SELECT dataelementid,categoryoptioncomboid, SUM(value) FROM aggregateddatavalue "
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " organisationunitid IN ("
+ + orgUnitIdsByComma + " ) AND " + " periodid IN (" + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid";
+ }
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
+ while ( rs.next() )
+ {
+ Integer deId = rs.getInt( 1 );
+ Integer optionComId = rs.getInt( 2 );
+ Double aggregatedValue = rs.getDouble( 3 );
+ if ( aggregatedValue != null )
+ {
+ aggDeMap.put( deId + "." + optionComId, "" + aggregatedValue );
+ }
+ }
+
+ return aggDeMap;
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Illegal DataElement id", e );
+ }
+ }
+
+ public Integer getOrgunitCountByOrgunitGroup( String orgunitGroupIdsByComma, Integer orgUnitId )
+ {
+ Integer totalOrgUnitCount = 0;
+ int maxOULevels = organisationUnitService.getMaxOfOrganisationUnitLevels();
+
+ try
+ {
+ String query = "SELECT COUNT(*) FROM orgunitgroupmembers WHERE orgunitgroupid IN ( "
+ + orgunitGroupIdsByComma + " ) AND "
+ + " organisationunitid IN ( SELECT organisationunitid FROM _orgunitstructure WHERE ";
+
+ for ( int i = 1; i <= maxOULevels; i++ )
+ {
+ query += " idlevel" + i + " = " + orgUnitId + " OR ";
+ }
+ query = query.substring( 0, query.length() - 4 );
+
+ query += ")";
+
+ /*
+ * " idlevel1 = "+ orgUnitId +" OR idlevel2 = "+ orgUnitId
+ * +" OR idlevel3 = "+ orgUnitId +" OR " + " idlevel4 = "+ orgUnitId
+ * +" OR idlevel5 = "+ orgUnitId +" OR " + " idlevel6 = "+ orgUnitId
+ * +" OR idlevel7 = "+ orgUnitId +" OR idlevel8 = "+ orgUnitId
+ * +" )";
+ */
+
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
+ if ( rs.next() )
+ {
+ totalOrgUnitCount = rs.getInt( 1 );
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ return totalOrgUnitCount;
+ }
+
+ public Integer getReportingOrgunitCountByDataset( Integer dataSetId, Integer orgUnitId )
+ {
+ Integer reportingOrgUnitCount = 0;
+ int maxOULevels = organisationUnitService.getMaxOfOrganisationUnitLevels();
+
+ try
+ {
+ String query = "SELECT COUNT(*) FROM datasetsource WHERE datasetid = " + dataSetId + " AND "
+ + " sourceid IN ( SELECT organisationunitid FROM _orgunitstructure WHERE ";
+
+ for ( int i = 1; i <= maxOULevels; i++ )
+ {
+ query += " idlevel" + i + " = " + orgUnitId + " OR ";
+ }
+ query = query.substring( 0, query.length() - 4 );
+
+ query += ")";
+
+ /*
+ * " idlevel1 = "+ orgUnitId +" OR idlevel2 = "+ orgUnitId
+ * +" OR idlevel3 = "+ orgUnitId +" OR " + " idlevel4 = "+ orgUnitId
+ * +" OR idlevel5 = "+ orgUnitId +" OR " + " idlevel6 = "+ orgUnitId
+ * +" OR idlevel7 = "+ orgUnitId +" OR idlevel8 = "+ orgUnitId
+ * +" )";
+ */
+
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
+ if ( rs.next() )
+ {
+ reportingOrgUnitCount = rs.getInt( 1 );
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ return reportingOrgUnitCount;
+ }
+
+ public Integer getReportingOrgunitCountByDataset( Integer dataSetId, Integer orgUnitId, Integer periodId )
+ {
+ Double constValue = 0.0;
+ Integer reportingOrgUnitCount = 0;
+
+ List<OrganisationUnit> orgUnitList = new ArrayList<OrganisationUnit>();
+ orgUnitList.addAll( organisationUnitService.getOrganisationUnitWithChildren( orgUnitId ) );
+
+ DataSet dataSet = dataSetService.getDataSet( dataSetId );
+
+ Collection<DataElement> dataElements = new ArrayList<DataElement>( dataSet.getDataElements() );
+ int dataSetMemberCount = 0;
+ for ( DataElement de : dataElements )
+ {
+ dataSetMemberCount += de.getCategoryCombo().getOptionCombos().size();
+ }
+ Collection<Integer> dataElementIds = new ArrayList<Integer>( getIdentifiers( DataElement.class, dataElements ) );
+ String dataElementIdsByComma = getCommaDelimitedString( dataElementIds );
+
+ List<OrganisationUnit> dataSetOrgunits = new ArrayList<OrganisationUnit>( dataSet.getSources() );
+ orgUnitList.retainAll( dataSetOrgunits );
+
+ for ( OrganisationUnit orgUnit : orgUnitList )
+ {
+ String query = "SELECT COUNT(*) FROM datavalue WHERE dataelementid IN (" + dataElementIdsByComma
+ + ") AND sourceid = " + orgUnit.getId() + " AND periodid =" + periodId;
+
+ double dataStatusPercentatge = 0.0;
+
+ SqlRowSet sqlResultSet = jdbcTemplate.queryForRowSet( query );
+
+ if ( sqlResultSet.next() )
+ {
+ try
+ {
+ dataStatusPercentatge = ((double) sqlResultSet.getInt( 1 ) / (double) dataSetMemberCount) * 100.0;
+ }
+ catch ( Exception e )
+ {
+ dataStatusPercentatge = 0.0;
+ }
+ }
+ else
+ {
+ dataStatusPercentatge = 0.0;
+ }
+
+ if ( dataStatusPercentatge > 100.0 )
+ {
+ dataStatusPercentatge = 100;
+ }
+
+ System.out.println( query + " : " + dataStatusPercentatge );
+
+ dataStatusPercentatge = Math.round( dataStatusPercentatge * Math.pow( 10, 0 ) ) / Math.pow( 10, 0 );
+ if ( dataStatusPercentatge > constValue )
+ {
+ reportingOrgUnitCount += 1;
+ }
+ }
+
+ return reportingOrgUnitCount;
+ }
+
+ public String getDataelementIdsByStype( List<Report_inDesign> reportDesignList, String sType )
+ {
+ String dataElmentIdsByComma = "-1";
+ for ( Report_inDesign report_inDesign : reportDesignList )
+ {
+ if ( report_inDesign.getStype().equalsIgnoreCase( sType ) )
+ {
+ String formula = report_inDesign.getExpression();
+
+ try
+ {
+ Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
+
+ Matcher matcher = pattern.matcher( formula );
+ StringBuffer buffer = new StringBuffer();
+
+ while ( matcher.find() )
+ {
+ String replaceString = matcher.group();
+
+ replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
+ replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
+
+ int dataElementId = Integer.parseInt( replaceString );
+ dataElmentIdsByComma += "," + dataElementId;
+ replaceString = "";
+ matcher.appendReplacement( buffer, replaceString );
+ }
+ }
+ catch ( Exception e )
+ {
+
+ }
+ }
+ }
+
+ return dataElmentIdsByComma;
+ }
+
+ public Map<String, String> getAggNonNumberDataFromDataValueTable( String orgUnitIdsByComma,
+ String dataElmentIdsByComma, String periodIdsByComma )
+ {
+ Map<String, String> aggDeMap = new HashMap<String, String>();
+ DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
+ try
+ {
+ String query = "";
+ if ( dataBaseInfo.getType().equalsIgnoreCase( "postgresql" ) )
+ {
+ query = "SELECT dataelementid,categoryoptioncomboid, SUM( cast( value as numeric) ) FROM datavalue "
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " sourceid IN ("
+ + orgUnitIdsByComma + " ) AND " + " periodid IN (" + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid";
+ }
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ {
+ query = "SELECT dataelementid,categoryoptioncomboid, GROUP_CONCAT(value) FROM datavalue "
+ + " WHERE dataelementid IN (" + dataElmentIdsByComma + " ) AND " + " sourceid IN ("
+ + orgUnitIdsByComma + " ) AND " + " periodid IN (" + periodIdsByComma
+ + ") GROUP BY dataelementid,categoryoptioncomboid";
+ }
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
+ while ( rs.next() )
+ {
+ Integer deId = rs.getInt( 1 );
+ Integer optionComId = rs.getInt( 2 );
+ String aggregatedNonNumberValue = rs.getString( 3 );
+ if ( aggregatedNonNumberValue != null )
+ {
+ aggDeMap.put( deId + "." + optionComId, aggregatedNonNumberValue );
+ }
+ }
+
+ return aggDeMap;
+ }
+ catch ( Exception e )
{
throw new RuntimeException( "Illegal DataElement id", e );
}
=== modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ouwiseprogress/action/GenerateOuWiseProgressReportResultAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ouwiseprogress/action/GenerateOuWiseProgressReportResultAction.java 2012-02-02 09:56:51 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ouwiseprogress/action/GenerateOuWiseProgressReportResultAction.java 2012-07-24 12:38:31 +0000
@@ -45,6 +45,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.reports.ReportService;
import org.hisp.dhis.reports.Report_in;
import org.hisp.dhis.reports.Report_inDesign;
@@ -230,12 +231,13 @@
selectedOrgUnit = organisationUnitService.getOrganisationUnit( ouIDTB );
int selectedOrgUnitLevel = organisationUnitService.getLevelOfOrganisationUnit( ouIDTB );
+ System.out.println( selectedOrgUnit.getName()+ " : " + selReportObj.getName()+" : Report Generation Start Time is : " + new Date() );
+
if ( reportModelTB.equalsIgnoreCase( "PROGRESSIVE-ORGUNIT" ) )
- {
- orgUnitList = new ArrayList<OrganisationUnit>( selectedOrgUnit.getChildren() );
-
+ {
if( orgUnitGroup != 0 )
{
+ orgUnitList = getChildOrgUnitTree( selectedOrgUnit );
OrganisationUnitGroup ouGroup = organisationUnitGroupService.getOrganisationUnitGroup( orgUnitGroup );
if( ouGroup != null )
@@ -243,6 +245,10 @@
orgUnitList.retainAll( ouGroup.getMembers() );
}
}
+ else
+ {
+ orgUnitList = new ArrayList<OrganisationUnit>( selectedOrgUnit.getChildren() );
+ }
Collections.sort( orgUnitList, new IdentifiableObjectNameComparator() );
@@ -260,7 +266,7 @@
*/
}
- System.out.println( selectedOrgUnit.getName()+ " : " + selReportObj.getName()+" : Report Generation Start Time is : " + new Date() );
+
String inputTemplatePath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "template" + File.separator + reportFileNameTB;
//String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
@@ -288,12 +294,14 @@
sDate = format.parseDate( startDate );
eDate = format.parseDate( endDate );
- List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
-
- Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
-
+ PeriodType selPeriodType = selReportObj.getPeriodType();
+ List<Period> periodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates( selPeriodType, sDate, eDate ) );
+ //List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+ Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
String periodIdsByComma = getCommaDelimitedString( periodIds );
+ //System.out.println( "periodIdsByComma :"+ periodIdsByComma );
+
// Getting DataValues
List<Report_inDesign> reportDesignList = reportService.getReportDesign( deCodesXMLFileName );
@@ -649,5 +657,27 @@
throw new RuntimeException( "Illegal DataElement id", ex );
}
}
-
+
+
+ // Returns the OrgUnitTree for which Root is the orgUnit
+ public List<OrganisationUnit> getChildOrgUnitTree( OrganisationUnit orgUnit )
+ {
+ List<OrganisationUnit> orgUnitTree = new ArrayList<OrganisationUnit>();
+ orgUnitTree.add( orgUnit );
+
+ List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( orgUnit.getChildren() );
+ Collections.sort( children, new IdentifiableObjectNameComparator() );
+ //Collections.sort( children, new OrganisationUnitNameComparator() );
+
+ Iterator<OrganisationUnit> childIterator = children.iterator();
+ OrganisationUnit child;
+ while ( childIterator.hasNext() )
+ {
+ child = (OrganisationUnit) childIterator.next();
+ orgUnitTree.addAll( getChildOrgUnitTree( child ) );
+ }
+ return orgUnitTree;
+ }
+ // getChildOrgUnitTree end
+
}
=== modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/periodwiseprogress/action/GeneratePeriodWiseProgressAnalyserResultAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/periodwiseprogress/action/GeneratePeriodWiseProgressAnalyserResultAction.java 2011-11-21 11:46:15 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/periodwiseprogress/action/GeneratePeriodWiseProgressAnalyserResultAction.java 2012-07-24 12:38:31 +0000
@@ -271,14 +271,26 @@
List<Report_inDesign> reportDesignList = reportService.getReportDesign( deCodesXMLFileName );
- String dataElmentIdsByComma = reportService.getDataelementIds( reportDesignList );
-
+ //String dataElmentIdsByComma = reportService.getDataelementIds( reportDesignList );
+ String dataElmentIdsByComma = reportService.getDataelementIdsByStype( reportDesignList, Report_inDesign.ST_DATAELEMENT );
+ String nonNumberDataElementIdsByComma = reportService.getDataelementIdsByStype( reportDesignList, Report_inDesign.ST_NON_NUMBER_DATAELEMENT );
+
+ //Collection<Integer> periodIds1 = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+ String periodsByComma = "";
+ //getCommaDelimitedString( periodIds1 );
+
int colCount = 0;
for( Period period : periodList )
- {
-
- Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodService.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ) ) );
- String periodsByComma = getCommaDelimitedString( periodIds );
+ {
+ if( periodTypeId.equalsIgnoreCase( "daily" ) )
+ {
+ periodsByComma = ""+period.getId();
+ }
+ else
+ {
+ Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodService.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ) ) );
+ periodsByComma = getCommaDelimitedString( periodIds );
+ }
Map<String, String> aggDeMap = new HashMap<String, String>();
if( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
@@ -288,12 +300,16 @@
else if( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
{
aggDeMap.putAll( reportService.getAggDataFromDataValueTable( childOrgUnitsByComma, dataElmentIdsByComma, periodsByComma ) );
+ aggDeMap.putAll( reportService.getAggNonNumberDataFromDataValueTable(childOrgUnitsByComma, nonNumberDataElementIdsByComma, periodsByComma ) );
+ System.out.println(childOrgUnitsByComma +" \n " + dataElmentIdsByComma + " \n " + periodsByComma );
}
else if( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
{
aggDeMap.putAll( reportService.getAggDataFromDataValueTable( ""+currentOrgUnit.getId(), dataElmentIdsByComma, periodsByComma ) );
+ aggDeMap.putAll( reportService.getAggNonNumberDataFromDataValueTable(""+currentOrgUnit.getId(), nonNumberDataElementIdsByComma, periodsByComma ) );
}
-
+ System.out.println( "aggDeMap size : " + aggDeMap.size() );
+
Iterator<Report_inDesign> reportDesignIterator = reportDesignList.iterator();
while ( reportDesignIterator.hasNext() )
{
@@ -341,7 +357,15 @@
{
tempStr = getAggVal( deCodeString, aggDeMap );
}
- }
+ }
+ else if( sType.equalsIgnoreCase( Report_inDesign.ST_DATAELEMENT_NO_REPEAT ) )
+ {
+ deCodeString = deCodeString.replaceAll( ":", "\\." );
+ deCodeString = deCodeString.replaceAll( "[", "" );
+ deCodeString = deCodeString.replaceAll( "]", "" );
+ System.out.println( "deCodeString : "+ deCodeString );
+ tempStr = aggDeMap.get( deCodeString );
+ }
}
if( tempStr == null || tempStr.equals( " " ) )
@@ -471,6 +495,7 @@
replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
+ System.out.println( replaceString + " : " + aggDeMap.get( replaceString ) );
replaceString = aggDeMap.get( replaceString );
if( replaceString == null )
=== modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/periodwiseprogress/action/GeneratePeriodWiseProgressReportAnalyserFormAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/periodwiseprogress/action/GeneratePeriodWiseProgressReportAnalyserFormAction.java 2010-11-09 15:02:39 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/periodwiseprogress/action/GeneratePeriodWiseProgressReportAnalyserFormAction.java 2012-07-24 12:38:31 +0000
@@ -56,7 +56,7 @@
while ( periodTypeIterator.hasNext() )
{
PeriodType type = periodTypeIterator.next();
- if (type.getName().equalsIgnoreCase("Monthly") || type.getName().equalsIgnoreCase("quarterly") || type.getName().equalsIgnoreCase("yearly"))
+ if ( type.getName().equalsIgnoreCase("Daily") || type.getName().equalsIgnoreCase("Monthly") || type.getName().equalsIgnoreCase("quarterly") || type.getName().equalsIgnoreCase("yearly"))
{
}
else
=== added directory 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2'
=== added directory 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action'
=== added file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action/GenerateRanking2ReportAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action/GenerateRanking2ReportAction.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action/GenerateRanking2ReportAction.java 2012-07-24 12:38:31 +0000
@@ -0,0 +1,487 @@
+package org.hisp.dhis.reports.ranking2.action;
+
+
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import jxl.Workbook;
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.format.VerticalAlignment;
+import jxl.write.Label;
+import jxl.write.Number;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableFont;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+
+import org.amplecode.quick.StatementManager;
+import org.hisp.dhis.config.Configuration_IN;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.reports.ReportService;
+import org.hisp.dhis.reports.Report_in;
+import org.hisp.dhis.reports.Report_inDesign;
+import org.hisp.dhis.system.util.MathUtils;
+
+import com.opensymphony.xwork2.Action;
+
+public class GenerateRanking2ReportAction implements Action
+{
+
+ private final String GENERATEAGGDATA = "generateaggdata";
+
+ private final String USEEXISTINGAGGDATA = "useexistingaggdata";
+
+ private final String USECAPTUREDDATA = "usecaptureddata";
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+ private StatementManager statementManager;
+
+ public void setStatementManager( StatementManager statementManager )
+ {
+ this.statementManager = statementManager;
+ }
+
+ private ReportService reportService;
+
+ public void setReportService( ReportService reportService )
+ {
+ this.reportService = reportService;
+ }
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private OrganisationUnitGroupService organisationUnitGroupService;
+
+ public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+ {
+ this.organisationUnitGroupService = organisationUnitGroupService;
+ }
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input & Output
+ // -------------------------------------------------------------------------
+ private I18nFormat format;
+
+ public void setFormat( I18nFormat format )
+ {
+ this.format = format;
+ }
+
+ private InputStream inputStream;
+
+ public InputStream getInputStream()
+ {
+ return inputStream;
+ }
+
+ private String fileName;
+
+ public String getFileName()
+ {
+ return fileName;
+ }
+
+ private String reportList;
+
+ public void setReportList( String reportList )
+ {
+ this.reportList = reportList;
+ }
+
+ private int ouIDTB;
+
+ public void setOuIDTB( int ouIDTB )
+ {
+ this.ouIDTB = ouIDTB;
+ }
+
+ private int availablePeriods;
+
+ public void setAvailablePeriods( int availablePeriods )
+ {
+ this.availablePeriods = availablePeriods;
+
+ }
+
+ private String aggData;
+
+ public void setAggData( String aggData )
+ {
+ this.aggData = aggData;
+ }
+
+ private Integer orgUnitGroup;
+
+ public void setOrgUnitGroup( Integer orgUnitGroup )
+ {
+ this.orgUnitGroup = orgUnitGroup;
+ }
+
+ /*
+ private String aggCB;
+
+ public void setAggCB( String aggCB )
+ {
+ this.aggCB = aggCB;
+ }
+ */
+ private String reportFileNameTB;
+
+
+
+ private List<OrganisationUnit> orgUnitList;
+
+ private Period selectedPeriod;
+
+ private SimpleDateFormat simpleDateFormat;
+
+ private SimpleDateFormat defaultDateFromat;
+
+ private OrganisationUnit selectedOrgUnit;
+
+ private SimpleDateFormat dateTimeFormat;
+
+ private Date sDate;
+
+ private Date eDate;
+
+ private String raFolderName;
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+ public String execute()
+ throws Exception
+ {
+ System.out.println( ouIDTB + "-" + availablePeriods + "" + aggData );
+
+
+ statementManager.initialise();
+ // Initialization
+ simpleDateFormat = new SimpleDateFormat( "MMM-yyyy" );
+ defaultDateFromat = new SimpleDateFormat( "yyyy-MM-dd" );
+ dateTimeFormat = new SimpleDateFormat( "EEEE, dd MMMM yyyy HH:mm:ss zzzz" );
+
+ raFolderName = reportService.getRAFolderName();
+
+ Report_in selReportObj = reportService.getReport( Integer.parseInt( reportList ) );
+
+ // OrgUnit Info
+ OrganisationUnit current1OrgUnit = organisationUnitService.getOrganisationUnit( ouIDTB );
+
+ System.out.println( current1OrgUnit.getName() + " : " + selReportObj.getName() + " : Report Generation Start Time is : " + new Date() );
+
+ selectedOrgUnit = new OrganisationUnit();
+ selectedOrgUnit = organisationUnitService.getOrganisationUnit( ouIDTB );
+
+ orgUnitList = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( ouIDTB ) );
+
+ if ( orgUnitGroup != 0 )
+ {
+ OrganisationUnitGroup ouGroup = organisationUnitGroupService.getOrganisationUnitGroup( orgUnitGroup );
+
+ if ( ouGroup != null )
+ {
+ orgUnitList.retainAll( ouGroup.getMembers() );
+ }
+ }
+ List<Integer> orgUnitListIds = new ArrayList<Integer>( getIdentifiers( OrganisationUnit.class, orgUnitList ) );
+ String orgUnitListIdsByComma = getCommaDelimitedString( orgUnitListIds );
+
+ String deCodesXMLFileName = selReportObj.getXmlTemplateName();
+ reportFileNameTB = selReportObj.getExcelTemplateName();
+
+ String inputTemplatePath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "template" + File.separator + reportFileNameTB;
+ String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + Configuration_IN.DEFAULT_TEMPFOLDER;
+ File newdir = new File( outputReportPath );
+ if ( !newdir.exists() )
+ {
+ newdir.mkdirs();
+ }
+ outputReportPath += File.separator + UUID.randomUUID().toString() + ".xls";
+ //System.out.println( inputTemplatePath + " " + outputReportPath );
+
+ Workbook templateWorkbook = Workbook.getWorkbook( new File( inputTemplatePath ) );
+
+ WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ), templateWorkbook );
+ WritableCellFormat wCellformat = new WritableCellFormat();
+ wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN );
+ wCellformat.setAlignment( Alignment.CENTRE );
+ wCellformat.setVerticalAlignment( VerticalAlignment.CENTRE );
+ wCellformat.setWrap( true );
+
+ selectedPeriod = periodService.getPeriod( availablePeriods );
+
+ sDate = format.parseDate( String.valueOf( selectedPeriod.getStartDate() ) );
+ eDate = format.parseDate( String.valueOf( selectedPeriod.getEndDate() ) );
+
+ // Period Info
+// not required!
+
+ // List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+//
+// Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+//
+ String periodIdsByComma;
+// periodIdsByComma= getCommaDelimitedString( periodIds );
+//
+// only one period can be selected=>
+ periodIdsByComma = "" + availablePeriods;
+
+ // Getting DataValues
+ List<Report_inDesign> reportDesignList = reportService.getReportDesign( deCodesXMLFileName );
+
+ String dataElmentIdsByComma = reportService.getDataelementIds( reportDesignList );
+ //System.out.println("orgunitlistidbycomma="+ orgUnitListIdsByComma+"dataelementidbycomma"+dataElmentIdsByComma);
+
+ Map<String, String> aggDeMapForselectedFacility = new HashMap<String, String>();
+
+
+ if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+ {
+ List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+ Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+ periodIdsByComma= getCommaDelimitedString( periodIds );
+
+ aggDeMapForselectedFacility.putAll( reportService.getAggDataFromDataValueTable( orgUnitListIdsByComma, dataElmentIdsByComma, periodIdsByComma ) );
+ }
+ else if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+ {
+ aggDeMapForselectedFacility.putAll( reportService.getAggDataFromAggDataValueTable( orgUnitListIdsByComma, dataElmentIdsByComma, periodIdsByComma ) );
+ }
+ else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+ {
+ String childOrgUnitsByComma = "-1";
+ for( OrganisationUnit orgUnit : orgUnitList )
+ {
+ List<OrganisationUnit> childOrgUnitTree = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnitWithChildren( orgUnit.getId() ) );
+ List<Integer> childOrgUnitTreeIds = new ArrayList<Integer>( getIdentifiers( OrganisationUnit.class, childOrgUnitTree ) );
+ childOrgUnitsByComma += "," + getCommaDelimitedString( childOrgUnitTreeIds );
+ }
+ List<Period> periodList = new ArrayList<Period>( periodService.getIntersectingPeriods( sDate, eDate ) );
+ Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers(Period.class, periodList ) );
+ periodIdsByComma= getCommaDelimitedString( periodIds );
+
+ aggDeMapForselectedFacility.putAll( reportService.getAggDataFromDataValueTable( childOrgUnitsByComma, dataElmentIdsByComma, periodIdsByComma ) );
+ }
+
+ //System.out.println( "aggdemapforselectedfacility=" + aggDeMapForselectedFacility.size() );
+
+ int count1 = 0;
+ Iterator<Report_inDesign> reportDesignIterator = reportDesignList.iterator();
+ while ( reportDesignIterator.hasNext() )
+ {
+ Report_inDesign report_inDesign = (Report_inDesign) reportDesignIterator.next();
+
+ String sType = report_inDesign.getStype();
+ String deCodeString = report_inDesign.getExpression();
+ System.out.print( "deCode=" + deCodeString + "---" );
+ String tempStr = "";
+
+ if ( deCodeString.equalsIgnoreCase( "FACILITY" ) )
+ {
+ tempStr = selectedOrgUnit.getName();
+ }
+ else if ( deCodeString.equalsIgnoreCase( "PERIOD-MONTH" ) )
+ {
+ tempStr = simpleDateFormat.format( sDate );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "CURRENTDATETIME" ) )
+ {
+ tempStr = dateTimeFormat.format( new Date() );
+ }
+ else if( sType.equalsIgnoreCase( "orgunitcountbygroup" ) )
+ {
+ tempStr = ""+reportService.getOrgunitCountByOrgunitGroup( deCodeString, selectedOrgUnit.getId() );
+ }
+ else if( sType.equalsIgnoreCase( "reportingunitcountbyperiod" ) )
+ {
+ tempStr = ""+reportService.getReportingOrgunitCountByDataset( Integer.parseInt( deCodeString ), selectedOrgUnit.getId(), selectedPeriod.getId() );
+ }
+ else if( sType.equalsIgnoreCase( "reportingunitcount" ) )
+ {
+ tempStr = ""+reportService.getReportingOrgunitCountByDataset( Integer.parseInt( deCodeString ), selectedOrgUnit.getId() );
+ }
+ else if ( sType.equalsIgnoreCase( "dataelementxmonthdays" ) )
+ {
+ String tempDate = defaultDateFromat.format( sDate );
+ Integer month = Integer.parseInt( tempDate.split( "-" )[1] );
+ Integer year = Integer.parseInt( tempDate.split( "-" )[2] );
+ Integer monthDays[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
+ tempStr = getAggVal( deCodeString, aggDeMapForselectedFacility );
+ if( year % 4 == 0 && month == 2 )
+ {
+ tempStr = "" + Double.parseDouble( tempStr ) * (monthDays[ month ]+1);
+ }
+ else
+ {
+ tempStr = "" + Double.parseDouble( tempStr ) * monthDays[ month ];
+ }
+ System.out.println( tempStr + " : " + month + " : " + year );
+ }
+ else if ( sType.equalsIgnoreCase( "dataelement" ) )
+ {
+ tempStr = getAggVal( deCodeString, aggDeMapForselectedFacility );
+ }
+
+ int tempRowNo = report_inDesign.getRowno();
+ int tempColNo = report_inDesign.getColno();
+ int sheetNo = report_inDesign.getSheetno();
+ WritableSheet sheet0 = outputReportWorkbook.getSheet( sheetNo );
+ try
+ {
+ try
+ {
+ sheet0.addCell( new Number( tempColNo, tempRowNo, Double.parseDouble( tempStr ), wCellformat ) );
+ }
+ catch ( Exception e )
+ {
+ sheet0.addCell( new Label( tempColNo, tempRowNo, tempStr, wCellformat ) );
+ }
+ }
+ catch ( Exception e )
+ {
+ System.out.println( "Cannot write to Excel" );
+ }
+
+ count1++;
+ }// while loop end
+
+
+ outputReportWorkbook.write();
+ outputReportWorkbook.close();
+
+ fileName = reportFileNameTB.replace( ".xls", "" );
+ fileName += "_" + selectedOrgUnit.getShortName() + "_";
+ fileName += "_" + simpleDateFormat.format( sDate ) + ".xls";
+ File outputReportFile = new File( outputReportPath );
+ inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+
+ System.out.println( selectedOrgUnit.getName() + " : " + selReportObj.getName() + " Report Generation End Time is : " + new Date() );
+
+ outputReportFile.deleteOnExit();
+
+ statementManager.destroy();
+
+
+ return SUCCESS;
+ }
+
+ public WritableCellFormat getCellFormat1() throws Exception
+ {
+ WritableFont arialBold = new WritableFont( WritableFont.ARIAL, 10, WritableFont.BOLD );
+ WritableCellFormat wCellformat = new WritableCellFormat( arialBold );
+
+ wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN );
+ wCellformat.setAlignment( Alignment.CENTRE );
+ wCellformat.setBackground( Colour.GRAY_25 );
+ wCellformat.setVerticalAlignment( VerticalAlignment.CENTRE );
+ wCellformat.setWrap( true );
+
+ return wCellformat;
+ }
+
+ public WritableCellFormat getCellFormat2() throws Exception
+ {
+ WritableFont arialBold = new WritableFont( WritableFont.ARIAL, 10, WritableFont.NO_BOLD );
+ WritableCellFormat wCellformat = new WritableCellFormat( arialBold );
+
+ wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN );
+ wCellformat.setAlignment( Alignment.CENTRE );
+ wCellformat.setBackground( Colour.ICE_BLUE );
+ wCellformat.setVerticalAlignment( VerticalAlignment.CENTRE );
+ wCellformat.setWrap( true );
+
+ return wCellformat;
+ }
+
+ private String getAggVal( String expression, Map<String, String> aggDeMap )
+ {
+ try
+ {
+ Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" );
+
+ Matcher matcher = pattern.matcher( expression );
+ StringBuffer buffer = new StringBuffer();
+
+ String resultValue = "";
+
+ while ( matcher.find() )
+ {
+ String replaceString = matcher.group();
+
+ replaceString = replaceString.replaceAll( "[\\[\\]]", "" );
+
+ replaceString = aggDeMap.get( replaceString );
+
+ if ( replaceString == null )
+ {
+ replaceString = "0";
+ }
+
+ matcher.appendReplacement( buffer, replaceString );
+
+ resultValue = replaceString;
+ }
+
+ matcher.appendTail( buffer );
+
+ double d = 0.0;
+ try
+ {
+ d = MathUtils.calculateExpression( buffer.toString() );
+ }
+ catch ( Exception e )
+ {
+ d = 0.0;
+ resultValue = "";
+ }
+
+ resultValue = "" + (double) d;
+
+ return resultValue;
+ } catch ( NumberFormatException ex )
+ {
+ throw new RuntimeException( "Illegal DataElement id", ex );
+ }
+ }
+}
=== added file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action/Ranking2ReportFormAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action/Ranking2ReportFormAction.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ranking2/action/Ranking2ReportFormAction.java 2012-07-24 12:38:31 +0000
@@ -0,0 +1,98 @@
+package org.hisp.dhis.reports.ranking2.action;
+
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.reports.ReportType;
+
+import com.opensymphony.xwork2.Action;
+
+public class Ranking2ReportFormAction implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private OrganisationUnitGroupService organisationUnitGroupService;
+
+ public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+ {
+ this.organisationUnitGroupService = organisationUnitGroupService;
+ }
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
+
+
+
+ // -------------------------------------------------------------------------
+ // Input & Output
+ // -------------------------------------------------------------------------
+
+ private Collection<PeriodType> periodTypes;
+
+ public Collection<PeriodType> getPeriodTypes()
+ {
+ return periodTypes;
+ }
+
+ private String reportTypeName;
+
+ public String getReportTypeName()
+ {
+ return reportTypeName;
+ }
+
+
+ private List<Period> monthlyPeriods;
+
+ public List<Period> getMonthlyPeriods()
+ {
+ return monthlyPeriods;
+ }
+
+ private SimpleDateFormat simpleDateFormat;
+
+ public SimpleDateFormat getSimpleDateFormat()
+ {
+ return simpleDateFormat;
+ }
+
+ private List<OrganisationUnitGroup> orgUnitGroups;
+
+ public List<OrganisationUnitGroup> getOrgUnitGroups()
+ {
+ return orgUnitGroups;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+ public String execute()
+ throws Exception
+ {
+ PeriodType monthlyPeriodType = new MonthlyPeriodType();
+ periodTypes = new ArrayList<PeriodType>();
+ periodTypes.add( monthlyPeriodType );
+ orgUnitGroups = new ArrayList<OrganisationUnitGroup>( organisationUnitGroupService.getAllOrganisationUnitGroups() );
+
+ reportTypeName=ReportType.RT_RANKING_REPORT;
+
+
+
+ return SUCCESS;
+ }
+}
=== modified file 'local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml 2012-06-30 10:19:34 +0000
+++ local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml 2012-07-24 12:38:31 +0000
@@ -1575,5 +1575,27 @@
<property name="jdbcTemplate" ref="jdbcTemplate"/>
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
<property name="dataElementCategoryOptionComboService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
- </bean>
+ </bean>
+
+ <!-- Ranking2 Reports - -->
+
+ <bean
+ id="org.hisp.dhis.reports.ranking2.action.Ranking2ReportFormAction"
+ class="org.hisp.dhis.reports.ranking2.action.Ranking2ReportFormAction"
+ scope="prototype">
+ <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+ <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+ </bean>
+
+ <bean
+ id="org.hisp.dhis.reports.ranking2.action.GenerateRanking2ReportAction"
+ class="org.hisp.dhis.reports.ranking2.action.GenerateRanking2ReportAction"
+ scope="prototype">
+ <property name="statementManager" ref="statementManager"/>
+ <property name="reportService" ref="org.hisp.dhis.reports.ReportService" />
+ <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+ <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+ </bean>
+
</beans>
=== modified file 'local/in/dhis-web-reports-national/src/main/resources/struts.xml'
--- local/in/dhis-web-reports-national/src/main/resources/struts.xml 2012-06-30 10:19:34 +0000
+++ local/in/dhis-web-reports-national/src/main/resources/struts.xml 2012-07-24 12:38:31 +0000
@@ -1005,6 +1005,27 @@
</result>
</action>
+ <!-- ranking2 Reports -->
+ <action name="ranking2ReportForm"
+ class="org.hisp.dhis.reports.ranking2.action.Ranking2ReportFormAction">
+ <result name="success" type="velocity">/main.vm</result>
+ <param name="page">/dhis-web-reports/ranking2ReportFront.vm</param>
+ <param name="menu">/dhis-web-reports/menuWithTreeForRanking2Reports.vm</param>
+ <param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,../dhis-web-commons/lists/lists.js,javascript/reportManagement.js,javascript/hashtable.js</param>
+ <param name="stylesheets">css/StylesForTags.css</param>
+ <param name="requiredAuthorities">F_REPORT_RANKING</param>
+ <interceptor-ref name="organisationUnitTreeStack"/>
+ </action>
+
+ <action name="generateRanking2Report"
+ class="org.hisp.dhis.reports.ranking2.action.GenerateRanking2ReportAction">
+ <result name="success" type="stream">
+ <param name="contentType">application/vnd.ms-excel</param>
+ <param name="inputName">inputStream</param>
+ <param name="contentDisposition">filename="${fileName}"</param>
+ <param name="bufferSize">1024</param></result>
+ </action>
+
<!-- AJAX Requests -->
<action name="getDataElements"
class="org.hisp.dhis.reports.action.GetDataElementsAction">
=== modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.vm'
--- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.vm 2012-06-30 10:19:34 +0000
+++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.vm 2012-07-24 12:38:31 +0000
@@ -75,7 +75,13 @@
#end
#if( $auth.hasAccess( "dhis-web-reports", "mdReportAnalyser") )
<li><a href = "mdReportAnalyser.action">MD Report</a>
- #end
+ #end
+ #if( $auth.hasAccess( "dhis-web-reports", "ranking2ReportForm") )
+ <li><a href = "ranking2ReportForm.action">Ranking Report</a></li>
+ #end
+ #if( $auth.hasAccess( "dhis-web-reports", "districtFeedbackReportAnalyser") )
+ <li><a href = "districtFeedbackReportAnalyser.action">Feedback Template</a></li>
+ #end
<!--<li><a href = "advancedReportAnalyser.action">Advanced Reports</a></li>-->
</ul>
</ul>
=== added file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForRanking2Reports.vm'
--- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForRanking2Reports.vm 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForRanking2Reports.vm 2012-07-24 12:38:31 +0000
@@ -0,0 +1,32 @@
+
+<a href="index.action"><h2>Report Analyser</h2></a>
+
+<ul>
+ <li>Report Analysis</li>
+ <ul>
+ <li>
+ Ranking ~ Reports
+ </li>
+ </ul>
+</ul>
+
+#parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" )
+
+<script type="text/javascript">
+
+ function orgUnitHasBeenSelected( orgUnitIds )
+ {
+ document.reportForm.ouIDTB.value = orgUnitIds;
+
+ reportTypeName = document.reportForm.reportTypeNameTB.value;
+
+ if(orgUnitIds != null && orgUnitIds != "" )
+ {
+ getPeriods();
+ }
+
+ }
+
+ selection.setListenerFunction( orgUnitHasBeenSelected );
+
+</script>
=== added file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/ranking2ReportFront.vm'
--- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/ranking2ReportFront.vm 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/ranking2ReportFront.vm 2012-07-24 12:38:31 +0000
@@ -0,0 +1,113 @@
+
+<script>
+ function formValidations()
+ {
+ var reportList = document.getElementById("reportList");
+ var reportListIndex = reportList.selectedIndex;
+ var periodList = document.getElementById("availablePeriods");
+ var periodIndex = periodList.selectedIndex;
+ var ouIdTb = document.getElementById("ouIDTB");
+ var orgunitIdValue = ouIdTb.value;
+
+ if( periodList.options[periodIndex].text == null || periodList.options[periodIndex].text == "" )
+ {
+ alert("Please Select Period");
+ return false;
+ }
+ else if( orgunitIdValue == null || orgunitIdValue == "" || orgunitIdValue == " " )
+ {
+ alert("Please Select OrganisationUnit");
+ return false;
+ }
+ else if( reportListIndex < 0 || reportList.options[reportListIndex].text == null )
+ {
+ alert("Please Select Report");
+ return false;
+ }
+
+ return true;
+ }
+</script>
+
+<h1>$i18n.getString( "Ranking Report" )</h1>
+<hr /><br />
+<form id="reportForm" name="reportForm" action="generateRanking2Report.action" method="post" onsubmit="return formValidations()" target="_blank">
+ <div style="display:none">
+ <select id="periodTypeId" name="periodTypeId" style="width:200px" >
+ <option value="Monthly">Monthly</option>
+ </select>
+ <input type="hidden" name="autogen" id="autogen" value="0" />
+ <input type="hidden" name="ouIDTB" id="ouIDTB" />
+ <input type="hidden" name="reportTypeNameTB" id="reportTypeNameTB" value="$reportTypeName" />
+ </div>
+ <table align="center" style=" border-collapse: collapse; margin-top: 0;" cellpadding="0" cellspacing="6" border=0>
+ <tr>
+ <td class="NormalB">
+ 1. $i18n.getString( "organisationunit" ) :<br />
+ <input type="text" name="ouNameTB" id="ouNameTB" style="width:200px" disabled />
+ </td>
+ <td style="width:50px"> </td>
+ <td class="NormalB">
+ 3. $i18n.getString( "generated_data_type" ) :<br />
+ <select id="aggData" name="aggData" style="width:200px">
+ <option value="generateaggdata">$i18n.getString( "generate_agg_data" )</option>
+ <option value="useexistingaggdata">$i18n.getString( "use_existing_agg_data" )</option>
+ <option value="usecaptureddata" selected>$i18n.getString( "use_captured_data" )</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ </tr>
+
+ <tr>
+ <td class="NormalB">
+ 2. $i18n.getString( "periods" ) :<br />
+ <select id="availablePeriods" name="availablePeriods" style="width:200px">
+ </select>
+ </td>
+ <td> </td>
+ <td class="NormalB">
+ 4. $i18n.getString( "orgunitgroup" ) :<br />
+ <select id="orgUnitGroup" name="orgUnitGroup" style="width:200px">
+ <option value="0">ALL</option>
+ #foreach( $orgUnitGroup in $orgUnitGroups )
+ <option value="$orgUnitGroup.id">$orgUnitGroup.name</option>
+ #end
+ </select>
+ </td>
+ </tr>
+ <tr style="display:none">
+ <td class="NormalB" >
+ $i18n.getString( "reports" ) :<br />
+ <select id="reportList" name="reportList" style="width:200px"></select>
+ </td>
+ <td class="NormalB"> </td>
+ <td class="NormalB"> </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td> </td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td> </td>
+ <td>
+ <input type="submit" id= "generate" name="generate" value='$i18n.getString( "generate_report" )' style="width:200px" />
+ </td>
+ </tr>
+ </table>
+</form>
\ No newline at end of file