dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18367
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7718: local/in merge NRHM Report module from 2.7 to trunk
------------------------------------------------------------
revno: 7718
committer: Mithilesh Kumar Thakur<mithilesh.hisp@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-07-26 14:50:56 +0530
message:
local/in merge NRHM Report module from 2.7 to trunk
added:
local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportOrgSpecificDataService.java
local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/StateDistrictFeedbackReportService.java
local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportOrgSpecificDataService.java
local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultStateDistrictFeedbackReportService.java
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action/
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action/GenerateAggregationDistrictFeedbackReportAnalyserFormAction.java
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action/GenerateAggregationDistrictFeedbackReportAnalyserResultAction.java
local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/districtFeedbackReportAnalysisFront.vm
local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForDistrictFeedbackReport.vm
modified:
local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java
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/resources/META-INF/dhis/beans.xml
local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml
local/in/dhis-web-reports-national/src/main/resources/org/hisp/dhis/reports/i18n_module.properties
local/in/dhis-web-reports-national/src/main/resources/struts.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportOrgSpecificDataService.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportOrgSpecificDataService.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportOrgSpecificDataService.java 2012-07-26 09:20:56 +0000
@@ -0,0 +1,17 @@
+package org.hisp.dhis.reports;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.PeriodType;
+
+import java.io.File;
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * <gaurav>,Date: 7/10/12, Time: 5:24 PM
+ */
+public interface ReportOrgSpecificDataService {
+
+ public Map<String, String> getOrgSpecificData(OrganisationUnit District, Date sDate, Date eDate, Date aggSDate, PeriodType periodType, String XmlFileName);
+
+}
=== 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 2012-07-24 12:38:31 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java 2012-07-26 09:20:56 +0000
@@ -105,6 +105,8 @@
List<Report_inDesign> getReportDesign( String fileName );
+ List<Report_inDesign> getDistrictFeedbackReportDesign( String fileName );
+
String getResultDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit , String reportModelTB );
String getIndividualResultDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit, String reportModelTB );
=== added file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/StateDistrictFeedbackReportService.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/StateDistrictFeedbackReportService.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/StateDistrictFeedbackReportService.java 2012-07-26 09:20:56 +0000
@@ -0,0 +1,18 @@
+package org.hisp.dhis.reports;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+
+import java.io.File;
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * <gaurav>,Date: 7/4/12, Time: 12:44 PM
+ */
+public interface StateDistrictFeedbackReportService {
+
+ String ID = StateDistrictFeedbackReportService.class.getName();
+
+ public Map<String, String> getDistrictFeedbackData(OrganisationUnit District, Date sDate, Date eDate, String XmlFileName);
+
+}
=== added file 'local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportOrgSpecificDataService.java'
--- local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportOrgSpecificDataService.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportOrgSpecificDataService.java 2012-07-26 09:20:56 +0000
@@ -0,0 +1,320 @@
+package org.hisp.dhis.reports;
+
+import org.hisp.dhis.config.ConfigurationService;
+import org.hisp.dhis.config.Configuration_IN;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+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.period.PeriodType;
+import org.hisp.dhis.system.database.DatabaseInfo;
+import org.hisp.dhis.system.database.DatabaseInfoProvider;
+import org.hisp.dhis.system.util.MathUtils;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.util.*;
+import java.util.regex.Matcher;
+
+/**
+ * <gaurav>,Date: 7/10/12, Time: 6:50 PM
+ */
+
+public class DefaultReportOrgSpecificDataService
+ implements ReportOrgSpecificDataService
+{
+
+ // ------------------------------------------------------------------------------------------
+ // Dependencies
+ // ------------------------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private OrganisationUnitGroupService organisationUnitGroupService;
+
+ public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+ {
+ this.organisationUnitGroupService = organisationUnitGroupService;
+ }
+
+ private ConfigurationService configurationService;
+
+ public void setConfigurationService( ConfigurationService configurationService )
+ {
+ this.configurationService = configurationService;
+ }
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
+
+ private DataSetService dataSetService;
+
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
+ public DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ public JdbcTemplate jdbcTemplate;
+
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+ {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ private DatabaseInfoProvider databaseInfoProvider;
+
+ public void setDatabaseInfoProvider( DatabaseInfoProvider databaseInfoProvider )
+ {
+ this.databaseInfoProvider = databaseInfoProvider;
+ }
+
+ // ------------------------------------------------------------------------------------------
+ // Implementation
+ // ------------------------------------------------------------------------------------------
+
+ public String getExpressionValue( String expression, String periodIdsByComma, String OrgunitIDsByComma )
+ {
+ final String NULL_REPLACEMENT = "0";
+
+ DatabaseInfo dataBaseInfo = databaseInfoProvider.getDatabaseInfo();
+ String query = "";
+
+ try
+ {
+ java.util.regex.Pattern pattern = java.util.regex.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( "[\\[\\]]", "" );
+ String optionComboIdStr = replaceString.substring( replaceString.indexOf( '.' ) + 1, replaceString
+ .length() );
+
+ replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) );
+
+ 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 IN(" + OrgunitIDsByComma + ")";
+ }
+ else if ( dataBaseInfo.getType().equalsIgnoreCase( "mysql" ) )
+ {
+
+ query = "SELECT SUM(value) FROM aggregateddatavalue WHERE dataelementid = " + dataElementId
+ + " AND categoryoptioncomboid = " + optionComboId + " AND periodid IN (" + periodIdsByComma
+ + ")" + " AND organisationunitid IN(" + OrgunitIDsByComma + ")";
+ }
+
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( query );
+
+ Double aggregatedValue = null;
+ if ( rs.next() )
+ {
+ aggregatedValue = rs.getDouble( 1 );
+ }
+
+ if ( aggregatedValue == null )
+ {
+ replaceString = NULL_REPLACEMENT;
+ }
+ else
+ {
+ replaceString = String.valueOf( aggregatedValue );
+ }
+
+ matcher.appendReplacement( buffer, replaceString );
+
+ resultValue = replaceString;
+ }
+
+ matcher.appendTail( buffer );
+
+ double expValue = 0.0;
+ try
+ {
+ expValue = MathUtils.calculateExpression( buffer.toString() );
+
+ expValue = Math.round( expValue );
+
+ }
+ catch ( Exception e )
+ {
+
+ expValue = 0.0;
+ resultValue = "";
+ }
+
+ resultValue = "" + (double) expValue;
+
+ return resultValue;
+ }
+ catch ( NumberFormatException ex )
+ {
+ throw new RuntimeException( "Illegal DataElement id", ex );
+ }
+ }
+
+ public Map<String, String> getOrgSpecificData( OrganisationUnit District, Date sDate, Date eDate, Date aggSdata,
+ PeriodType periodType, String XmlFileName )
+ {
+
+ final String RA_FOLDER = System.getenv( "DHIS2_HOME" ) + File.separator
+ + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+
+ Map<String, String> DataPositionMap = new HashMap<String, String>();
+
+ String DistrictFeedBackXmlPath = RA_FOLDER + File.separator + XmlFileName;
+
+ 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";
+
+ try
+ {
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+ Document doc = docBuilder.parse( new File( DistrictFeedBackXmlPath ) );
+ if ( doc == null )
+ {
+ System.out.println( "District feedback XML file not found" );
+ }
+
+ NodeList listOfDeFeed = doc.getElementsByTagName( "org-code" );
+ int totalDeFeeds = listOfDeFeed.getLength();
+
+ for ( int s = 0; s < totalDeFeeds; s++ )
+ {
+ Element deFeedElement = (Element) listOfDeFeed.item( s );
+
+ int oucode = new Integer( deFeedElement.getAttribute( "oucode" ) );
+ String ptype = deFeedElement.getAttribute( "type" );
+ int sheetno = new Integer( deFeedElement.getAttribute( "sheetno" ) );
+ int rowno = new Integer( deFeedElement.getAttribute( "rowno" ) );
+ int colno = new Integer( deFeedElement.getAttribute( "colno" ) );
+ String expression = new String( deFeedElement.getAttribute( "expression" ) );
+
+ List<OrganisationUnit> orgUnitList = new ArrayList<OrganisationUnit>( District.getChildren() );
+
+ if ( organisationUnitGroupService == null )
+ {
+ System.out.println( "* ERROR !! OrganisationUnitGroupService is NULL" );
+ }
+
+ List<OrganisationUnit> orgUnitGroupList = new ArrayList<OrganisationUnit>( organisationUnitGroupService
+ .getOrganisationUnitGroup( oucode ).getMembers() );
+ orgUnitList.retainAll( orgUnitGroupList );
+
+ Collection<Period> IntermediatePeriods = periodService.getPeriodsBetweenDates( sDate, eDate );
+
+ Collection<Period> IntermediateAggPeriods = periodService.getPeriodsBetweenDates( aggSdata, eDate );
+
+ String aggregatedValue = "0";
+
+ if ( orgUnitList.size() > 0 && IntermediatePeriods.size() > 0 )
+ {
+ String OrgUnitIDsByComma = "";
+ String PeriodIDsByComma = "";
+
+ for ( OrganisationUnit orgUnit : orgUnitList )
+ {
+
+ OrgUnitIDsByComma = OrgUnitIDsByComma.concat( "," + orgUnit.getId() );
+ }
+
+ if ( ptype.equalsIgnoreCase( "CMCY" ) )
+ {
+ for ( Period period : IntermediatePeriods )
+ {
+ PeriodIDsByComma = PeriodIDsByComma.concat( "," + period.getId() );
+ }
+ }
+
+ else
+ {
+ for ( Period period : IntermediateAggPeriods )
+ {
+
+ PeriodIDsByComma = PeriodIDsByComma.concat( "," + period.getId() );
+
+ }
+ }
+
+ aggregatedValue = getExpressionValue( expression, PeriodIDsByComma.substring( 1 ),
+ OrgUnitIDsByComma.substring( 1 ) );
+
+ }
+
+ int tempColNo = colno;
+ int tempRowNo = rowno;
+
+ String tempStr = aggregatedValue;
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ DataPositionMap.put( cellPos, tempStr );
+
+ }
+
+ }
+ 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 DataPositionMap;
+ }
+
+}
=== 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-24 12:38:31 +0000
+++ local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java 2012-07-26 09:20:56 +0000
@@ -427,6 +427,84 @@
// Fetch Global Decode Configuration
// ----------------------------------------------------------------------------------------------------------
+ public List<Report_inDesign> getDistrictFeedbackReportDesign( 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" ) );
+
+ Report_inDesign report_inDesign = new Report_inDesign( stype, ptype, sheetno, rowno, colno, 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;
+ }
+
public List<Report_inDesign> getReportDesign( Report_in report )
{
List<Report_inDesign> deCodes = new ArrayList<Report_inDesign>();
@@ -437,7 +515,7 @@
String path = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator
+ report.getXmlTemplateName();
- //String configFile = "";
+ // String configFile = "";
try
{
@@ -825,6 +903,7 @@
try
{
d = MathUtils.calculateExpression( buffer.toString() );
+ d = Math.round(d);
}
catch ( Exception e )
{
@@ -1005,6 +1084,7 @@
try
{
d = MathUtils.calculateExpression( buffer.toString() );
+ d = Math.round(d);
}
catch ( Exception e )
{
@@ -1175,6 +1255,7 @@
try
{
d = MathUtils.calculateExpression( buffer.toString() );
+ d = Math.round(d);
}
catch ( Exception e )
{
@@ -1443,6 +1524,7 @@
try
{
d = MathUtils.calculateExpression( buffer.toString() );
+ d = Math.round(d);
}
catch ( Exception e )
{
@@ -1565,6 +1647,7 @@
try
{
d = MathUtils.calculateExpression( buffer.toString() );
+ d = Math.round(d);
}
catch ( Exception e )
{
@@ -1846,6 +1929,7 @@
try
{
d = MathUtils.calculateExpression( buffer.toString() );
+ d = Math.round(d);
}
catch ( Exception e )
{
@@ -1982,6 +2066,7 @@
try
{
d = MathUtils.calculateExpression( buffer.toString() );
+ d = Math.round(d);
}
catch ( Exception e )
{
@@ -2490,6 +2575,7 @@
try
{
d = MathUtils.calculateExpression( buffer.toString() );
+ d = Math.round(d);
}
catch ( Exception e )
{
@@ -2730,6 +2816,7 @@
try
{
d = MathUtils.calculateExpression( buffer.toString() );
+ d = Math.round(d);
}
catch ( Exception e )
{
=== added file 'local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultStateDistrictFeedbackReportService.java'
--- local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultStateDistrictFeedbackReportService.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultStateDistrictFeedbackReportService.java 2012-07-26 09:20:56 +0000
@@ -0,0 +1,388 @@
+package org.hisp.dhis.reports;
+
+import org.hisp.dhis.config.ConfigurationService;
+import org.hisp.dhis.config.Configuration_IN;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+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.springframework.jdbc.core.JdbcTemplate;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.util.*;
+
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+
+/**
+ * <gaurav>,Date: 7/4/12, Time: 12:47 PM
+ */
+public class DefaultStateDistrictFeedbackReportService
+ implements StateDistrictFeedbackReportService
+{
+
+ // ---------------------------------------------------------------------------------------
+ // Dependencies
+ // ---------------------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private OrganisationUnitGroupService organisationUnitGroupService;
+
+ public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+ {
+ this.organisationUnitGroupService = organisationUnitGroupService;
+ }
+
+ private ConfigurationService configurationService;
+
+ public void setConfigurationService( ConfigurationService configurationService )
+ {
+ this.configurationService = configurationService;
+ }
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
+
+ private DataValueService dataValueService;
+
+ public void setDataValueService( DataValueService dataValueService )
+ {
+ this.dataValueService = dataValueService;
+ }
+
+ private DataSetService dataSetService;
+
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
+ public DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ public JdbcTemplate jdbcTemplate;
+
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+ {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ // ---------------------------------------------------------------------------------------
+ // Implementation
+ // ---------------------------------------------------------------------------------------
+
+ public Map<String, String> getDistrictFeedbackData( OrganisationUnit District, Date sDate, Date eDate,
+ String XmlFileName )
+ {
+ final String RA_FOLDER = System.getenv( "DHIS2_HOME" ) + File.separator
+ + configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue();
+
+ String DistrictFeedBackXmlPath = RA_FOLDER + File.separator + XmlFileName;
+
+ Map<String, String> feedbackTemplateMap = new HashMap<String, String>();
+
+ try
+ {
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+ Document doc = docBuilder.parse( new File( DistrictFeedBackXmlPath ) );
+ if ( doc == null )
+ {
+ System.out.println( "District feedback XML file not found" );
+ }
+
+ NodeList excelFiles = doc.getElementsByTagName( "excel" );
+ int numFile = excelFiles.getLength();
+
+ NodeList listOfDeFeed = doc.getElementsByTagName( "dfeed" );
+ int totalDeFeeds = listOfDeFeed.getLength();
+
+ List<OrganisationUnit> orgUnitList = new ArrayList<OrganisationUnit>( organisationUnitService
+ .getOrganisationUnitWithChildren( District.getId() ) );
+
+ for ( int s = 0; s < totalDeFeeds; s++ )
+ {
+ Element deFeedElement = (Element) listOfDeFeed.item( s );
+
+ int fCode = new Integer( deFeedElement.getAttribute( "fcode" ) );
+ int sheetNo = new Integer( deFeedElement.getAttribute( "sheetno" ) );
+ int rowNo = new Integer( deFeedElement.getAttribute( "rowno" ) );
+ int colNo = new Integer( deFeedElement.getAttribute( "colno" ) );
+ int dataSetID = new Integer( deFeedElement.getAttribute( "datasetid" ) );
+
+ if ( organisationUnitGroupService == null )
+ {
+ System.out.println( "* ERROR !! OrganisationUnitGroupService is NULL" );
+ }
+
+ List<OrganisationUnit> orgUnitGroupList = new ArrayList<OrganisationUnit>( organisationUnitGroupService
+ .getOrganisationUnitGroup( fCode ).getMembers() );
+
+ orgUnitGroupList.retainAll( orgUnitList );
+
+ Collection<Period> IntermediatePeriods = periodService.getPeriodsBetweenDates( sDate, eDate );
+
+ int totalMatchedFacilities = orgUnitGroupList.size();
+
+ int totalReported = 0;
+
+ int totalLate = 0;
+
+ int totalEntries = 0;
+
+ int totalNonZero = 0;
+
+ int dataValueCount = 0;
+
+ for ( OrganisationUnit orgUnit : orgUnitGroupList )
+ {
+
+ for ( Period period : IntermediatePeriods )
+ {
+
+ DataSet facilityDataSet = dataSetService.getDataSet( dataSetID );
+
+ int expiryDays = facilityDataSet.getExpiryDays();
+ Calendar cal = Calendar.getInstance();
+ cal.setTime( period.getStartDate() );
+ cal.add( Calendar.DATE, expiryDays );
+ Date expiryDate = cal.getTime();
+
+ List<DataElement> dataElementList = new ArrayList<DataElement>( dataSetService
+ .getDataElements( facilityDataSet ) );
+
+ totalEntries = (dataElementList.size() * orgUnitGroupList.size());
+
+ Collection<Integer> dataElementCollection = new ArrayList<Integer>( getIdentifiers(
+ DataElement.class, dataElementList ) );
+
+ String dataElementIdsByComma = getCommaDelimitedString( dataElementCollection );
+
+ dataValueCount = jdbcTemplate.queryForInt(
+ "SELECT COUNT(0) FROM datavalue WHERE dataelementid IN(?) AND periodid=? AND sourceid=?",
+ new Object[] { new String( dataElementIdsByComma ), new Integer( period.getId() ),
+ new Integer( orgUnit.getId() ) } );
+
+ totalNonZero = jdbcTemplate
+ .queryForInt(
+ "SELECT COUNT(0) FROM datavalue WHERE dataelementid IN(?) AND periodid=? AND sourceid=? AND value>0 ",
+ new Object[] { new String( dataElementIdsByComma ), new Integer( period.getId() ),
+ new Integer( orgUnit.getId() ) } );
+
+ totalLate = jdbcTemplate
+ .queryForInt(
+ "SELECT COUNT(0) FROM datavalue WHERE dataelementid IN(?) AND periodid=? AND sourceid=? AND lastupdated>? ",
+ new Object[] { new String( dataElementIdsByComma ), new Integer( period.getId() ),
+ new Integer( orgUnit.getId() ), (expiryDate) } );
+
+ }
+
+ if ( dataValueCount > 0 )
+ {
+ ++totalReported;
+ }
+
+ }
+
+ totalNonZero = (totalNonZero / IntermediatePeriods.size());
+
+ for ( int iNum = 1; iNum <= 9; ++iNum )
+ {
+ if ( iNum == 1 )
+ {
+ int tempColNo = colNo + 1;
+ int tempRowNo = rowNo;
+ String tempStr = String.valueOf( totalMatchedFacilities );
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ feedbackTemplateMap.put( cellPos, tempStr );
+
+ }
+ if ( iNum == 2 )
+ {
+ int tempColNo = colNo + 3;
+ int tempRowNo = rowNo;
+ String tempStr = String.valueOf( (totalMatchedFacilities - totalReported) );
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ feedbackTemplateMap.put( cellPos, tempStr );
+
+ }
+ if ( iNum == 3 )
+ {
+ int tempColNo = colNo + 5;
+ int tempRowNo = rowNo;
+ String tempStr;
+ if ( totalMatchedFacilities > 0 )
+ {
+ tempStr = String.valueOf( Math.round( ((totalReported) * 100) / totalMatchedFacilities ) )
+ + " %";
+ }
+ else
+ {
+ tempStr = "0 %";
+ }
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ feedbackTemplateMap.put( cellPos, tempStr );
+
+ }
+ if ( iNum == 4 )
+ {
+ int tempColNo = colNo + 1;
+ int tempRowNo = rowNo + 10;
+ String tempStr;
+
+ if ( totalEntries > 0 )
+ {
+ tempStr = String
+ .valueOf( Math.round( ((totalEntries - totalNonZero) * 100) / totalEntries ) )
+ + " %";
+ }
+ else
+ {
+ tempStr = "0 %";
+ }
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ feedbackTemplateMap.put( cellPos, tempStr );
+
+ }
+ if ( iNum == 5 )
+ {
+ int tempColNo = colNo + 4;
+ int tempRowNo = rowNo + 10;
+ String tempStr;
+ if ( totalEntries > 0 )
+ {
+ tempStr = String.valueOf( Math.round( ((totalNonZero * 100) / totalEntries) ) ) + " %";
+ }
+ else
+ {
+ tempStr = "0 %";
+ }
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ feedbackTemplateMap.put( cellPos, tempStr );
+
+ }
+ if ( iNum == 6 )
+ {
+ int tempColNo = colNo + 1;
+ int tempRowNo = rowNo + 20;
+ String tempStr = String.valueOf( totalMatchedFacilities - totalLate );
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ feedbackTemplateMap.put( cellPos, tempStr );
+
+ }
+ if ( iNum == 7 )
+ {
+ int tempColNo = colNo + 3;
+ int tempRowNo = rowNo + 20;
+ String tempStr;
+ if ( totalMatchedFacilities > 0 )
+ {
+ tempStr = String.valueOf( Math.round( ((totalMatchedFacilities - totalLate) * 100)
+ / totalMatchedFacilities ) )
+ + " %";
+ }
+ else
+ {
+ tempStr = "0 %";
+ }
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ feedbackTemplateMap.put( cellPos, tempStr );
+
+ }
+ if ( iNum == 8 )
+ {
+ int tempColNo = colNo + 4;
+ int tempRowNo = rowNo + 20;
+
+ String tempStr = String.valueOf( totalLate );
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ feedbackTemplateMap.put( cellPos, tempStr );
+
+ }
+ if ( iNum == 9 )
+ {
+ int tempColNo = colNo + 6;
+ int tempRowNo = rowNo + 20;
+ String tempStr;
+ if ( totalMatchedFacilities > 0 )
+ {
+ tempStr = String.valueOf( Math.round( ((totalLate) * 100) / totalMatchedFacilities ) )
+ + " %";
+ }
+ else
+ {
+ tempStr = "0 %";
+ }
+
+ String cellPos = String.valueOf( tempColNo ) + ":" + String.valueOf( tempRowNo );
+
+ feedbackTemplateMap.put( cellPos, tempStr );
+ }
+
+ }
+
+ }
+
+ }
+ 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 feedbackTemplateMap;
+ }
+
+}
\ No newline at end of file
=== modified file 'local/in/dhis-in-services/dhis-in-service-reports/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-in-services/dhis-in-service-reports/src/main/resources/META-INF/dhis/beans.xml 2012-06-30 10:19:34 +0000
+++ local/in/dhis-in-services/dhis-in-service-reports/src/main/resources/META-INF/dhis/beans.xml 2012-07-26 09:20:56 +0000
@@ -3,7 +3,33 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
+
+ <!-- State District Feedback Report Service -->
+ <bean id="org.hisp.dhis.reports.StateDistrictFeedbackReportService"
+ class="org.hisp.dhis.reports.DefaultStateDistrictFeedbackReportService">
+ <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+ <property name="configurationService" ref="org.hisp.dhis.config.ConfigurationService"/>
+ <property name="periodService" ref="org.hisp.dhis.period.PeriodService"/>
+ <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+ <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
+ <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+ <property name="jdbcTemplate" ref="jdbcTemplate"/>
+ </bean>
+ <!-- Report Org Specific Data Service -->
+ <bean id="org.hisp.dhis.reports.ReportOrgSpecificDataService"
+ class="org.hisp.dhis.reports.DefaultReportOrgSpecificDataService">
+ <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+ <property name="configurationService" ref="org.hisp.dhis.config.ConfigurationService"/>
+ <property name="periodService" ref="org.hisp.dhis.period.PeriodService"/>
+ <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+ <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+ <property name="jdbcTemplate" ref="jdbcTemplate"/>
+ <property name="databaseInfoProvider" ref="databaseInfoProvider" />
+ </bean>
+
<!-- Store definitions -->
<bean id="org.hisp.dhis.reports.ReportStore"
=== added directory 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback'
=== added directory 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action'
=== added file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action/GenerateAggregationDistrictFeedbackReportAnalyserFormAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action/GenerateAggregationDistrictFeedbackReportAnalyserFormAction.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action/GenerateAggregationDistrictFeedbackReportAnalyserFormAction.java 2012-07-26 09:20:56 +0000
@@ -0,0 +1,70 @@
+package org.hisp.dhis.reports.districtfeedback.action;
+
+import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.reports.ReportType;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+public class GenerateAggregationDistrictFeedbackReportAnalyserFormAction
+ implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ 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;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ public String execute()
+ throws Exception
+ {
+ reportTypeName = ReportType.RT_FEEDBACK_TEMPLATE;
+
+ periodTypes = periodService.getAllPeriodTypes();
+
+ Iterator<PeriodType> periodTypeIterator = periodTypes.iterator();
+ while ( periodTypeIterator.hasNext() )
+ {
+ PeriodType type = periodTypeIterator.next();
+ if ( type.getName().equalsIgnoreCase( "daily" ) || type.getName().equalsIgnoreCase( "Monthly" )
+ || type.getName().equalsIgnoreCase( "quarterly" ) || type.getName().equalsIgnoreCase( "yearly" ) )
+ {
+ }
+ else
+ {
+ periodTypeIterator.remove();
+ }
+ }
+
+ return SUCCESS;
+ }
+}
=== added file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action/GenerateAggregationDistrictFeedbackReportAnalyserResultAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action/GenerateAggregationDistrictFeedbackReportAnalyserResultAction.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/districtfeedback/action/GenerateAggregationDistrictFeedbackReportAnalyserResultAction.java 2012-07-26 09:20:56 +0000
@@ -0,0 +1,1063 @@
+package org.hisp.dhis.reports.districtfeedback.action;
+
+import com.opensymphony.xwork2.Action;
+import jxl.CellType;
+import jxl.Workbook;
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.CellFormat;
+import jxl.write.*;
+import jxl.write.Number;
+import org.amplecode.quick.StatementManager;
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.config.Configuration_IN;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+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.*;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+
+public class GenerateAggregationDistrictFeedbackReportAnalyserResultAction
+ implements Action
+{
+
+ private final String GENERATEAGGDATA = "generateaggdata";
+
+ private final String USEEXISTINGAGGDATA = "useexistingaggdata";
+
+ private final String USECAPTUREDDATA = "usecaptureddata";
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private ReportOrgSpecificDataService reportOrgSpecificDataService;
+
+ public void setReportOrgSpecificDataService( ReportOrgSpecificDataService reportOrgSpecificDataService )
+ {
+ this.reportOrgSpecificDataService = reportOrgSpecificDataService;
+ }
+
+ private StateDistrictFeedbackReportService stateDistrictFeedbackReportService;
+
+ public void setStateDistrictFeedbackReportService(
+ StateDistrictFeedbackReportService stateDistrictFeedbackReportService )
+ {
+ this.stateDistrictFeedbackReportService = stateDistrictFeedbackReportService;
+ }
+
+ private StatementManager statementManager;
+
+ public void setStatementManager( StatementManager statementManager )
+ {
+ this.statementManager = statementManager;
+ }
+
+ private ReportService reportService;
+
+ public void setReportService( ReportService reportService )
+ {
+ this.reportService = reportService;
+ }
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private I18nFormat format;
+
+ public void setFormat( I18nFormat format )
+ {
+ this.format = format;
+ }
+
+ // -------------------------------------------------------------------------
+ // Properties
+ // -------------------------------------------------------------------------
+
+ private int availablePeriods;
+
+ public void setAvailablePeriods( int availablePeriods )
+ {
+ this.availablePeriods = availablePeriods;
+ }
+
+ private InputStream inputStream;
+
+ public InputStream getInputStream()
+ {
+ return inputStream;
+ }
+
+ private String fileName;
+
+ public String getFileName()
+ {
+ return fileName;
+ }
+
+ private String reportFileNameTB;
+
+ public void setReportFileNameTB( String reportFileNameTB )
+ {
+ this.reportFileNameTB = reportFileNameTB;
+ }
+
+ private int ouIDTB;
+
+ public void setOuIDTB( int ouIDTB )
+ {
+ this.ouIDTB = ouIDTB;
+ }
+
+ private String reportList;
+
+ public void setReportList( String reportList )
+ {
+ this.reportList = reportList;
+ }
+
+ private String startDate;
+
+ public void setStartDate( String startDate )
+ {
+ this.startDate = startDate;
+ }
+
+ private String endDate;
+
+ public void setEndDate( String endDate )
+ {
+ this.endDate = endDate;
+ }
+
+ private String aggData;
+
+ public void setAggData( String aggData )
+ {
+ this.aggData = aggData;
+ }
+
+ private Period selectedPeriod;
+
+ private String reportModelTB;
+
+ private List<OrganisationUnit> orgUnitList;
+
+ private Date sDate;
+
+ private Date eDate;
+
+ private Date sDateTemp;
+
+ private Date eDateTemp;
+
+ private PeriodType periodType;
+
+ private String raFolderName;
+
+ private Integer monthCount;
+
+ private Date sAggDate;
+
+ private String periodTypeId;
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ public String execute()
+ throws Exception
+ {
+
+ statementManager.initialise();
+
+ // Initialization
+
+ raFolderName = reportService.getRAFolderName();
+ String ReportXMLFileName = "";
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "MMM-yyyy" );
+ SimpleDateFormat dayFormat = new SimpleDateFormat( "yyyy-MM-dd" );
+ SimpleDateFormat monthFormat = new SimpleDateFormat( "MMMM" );
+ SimpleDateFormat simpleMonthFormat = new SimpleDateFormat( "MMM" );
+ SimpleDateFormat yearFormat = new SimpleDateFormat( "yyyy" );
+ SimpleDateFormat simpleYearFormat = new SimpleDateFormat( "yy" );
+
+ Report_in selReportObj = reportService.getReport( Integer.parseInt( reportList ) );
+
+ ReportXMLFileName = selReportObj.getXmlTemplateName();
+ reportModelTB = selReportObj.getModel();
+ reportFileNameTB = selReportObj.getExcelTemplateName();
+ periodTypeId = "Monthly";
+
+ String parentUnit = "";
+
+ 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";
+
+ if ( reportModelTB.equalsIgnoreCase( "DYNAMIC-ORGUNIT" ) )
+ {
+ OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB );
+ orgUnitList = new ArrayList<OrganisationUnit>( orgUnit.getChildren() );
+ Collections.sort( orgUnitList, new IdentifiableObjectNameComparator() );
+ }
+ else if ( reportModelTB.equalsIgnoreCase( "STATIC" ) || reportModelTB.equalsIgnoreCase( "STATIC-DATAELEMENTS" )
+ || reportModelTB.equalsIgnoreCase( "STATIC-FINANCIAL" ) )
+ {
+ orgUnitList = new ArrayList<OrganisationUnit>();
+ OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB );
+ orgUnitList.add( orgUnit );
+ }
+ else if ( reportModelTB.equalsIgnoreCase( "dynamicwithrootfacility" ) )
+ {
+ OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB );
+ orgUnitList = new ArrayList<OrganisationUnit>( orgUnit.getChildren() );
+ Collections.sort( orgUnitList, new IdentifiableObjectNameComparator() );
+ orgUnitList.add( orgUnit );
+
+ parentUnit = orgUnit.getName();
+ }
+
+ OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB );
+
+ System.out.println( orgUnitList.get( 0 ).getName() + " : " + selReportObj.getName()
+ + " : Report Generation Start Time is : " + new Date() );
+
+ selectedPeriod = periodService.getPeriod( availablePeriods );
+
+ sDate = format.parseDate( String.valueOf( selectedPeriod.getStartDate() ) );
+
+ eDate = format.parseDate( String.valueOf( selectedPeriod.getEndDate() ) );
+
+ Calendar cal = Calendar.getInstance();
+ cal.setTime( sDate );
+ int month = cal.get( Calendar.MONTH );
+
+ if ( month < 4 )
+ {
+ cal.roll( Calendar.YEAR, -1 );
+ }
+
+ cal.set( Calendar.MONTH, 3 );
+
+ sAggDate = cal.getTime();
+
+ periodType = periodService.getPeriodTypeByName( periodTypeId );
+
+ List<Period> periodList = new ArrayList<Period>( periodService
+ .getPeriodsBetweenDates( periodType, sDate, eDate ) );
+
+ System.out.println( "* Period List Size: [" + periodList.size() + "]" );
+
+ Collection<Integer> periodIds = new ArrayList<Integer>( getIdentifiers( Period.class, periodList ) );
+
+ String periodIdsByComma = getCommaDelimitedString( periodIds );
+
+ List<Period> aggPeriodList = new ArrayList<Period>( periodService.getPeriodsBetweenDates( periodType, sAggDate,
+ eDate ) );
+
+ System.out.println( "* Aggregate Period List Size: [" + aggPeriodList.size() + "]" );
+
+ for ( Period period : aggPeriodList )
+ {
+ System.out.println( "* Agg-Month [ " + period.getStartDateString() + " ]" );
+ }
+
+ Collection<Integer> aggPeriodIds = new ArrayList<Integer>( getIdentifiers( Period.class, aggPeriodList ) );
+
+ String aggPeriodIdsByComma = getCommaDelimitedString( aggPeriodIds );
+
+ Calendar tempStartDate = Calendar.getInstance();
+ Calendar tempEndDate = Calendar.getInstance();
+ tempStartDate.setTime( sDate );
+ tempEndDate.setTime( eDate );
+
+ Workbook templateWorkbook = Workbook.getWorkbook( new File( inputTemplatePath ) );
+
+ WritableWorkbook outputReportWorkbook = Workbook
+ .createWorkbook( new File( outputReportPath ), templateWorkbook );
+
+ Map<String, String> feedbackTemplateMap;
+
+ Map<String, String> orgSpecificMap;
+
+ feedbackTemplateMap = stateDistrictFeedbackReportService.getDistrictFeedbackData( orgUnit, sDate, eDate,
+ ReportXMLFileName );
+
+ orgSpecificMap = reportOrgSpecificDataService.getOrgSpecificData( orgUnit, sDate, eDate, sAggDate, periodType,
+ ReportXMLFileName );
+
+ WritableSheet writableSheet = outputReportWorkbook.getSheet( 0 );
+
+ // --------------------------------------------------- Write Data
+ // Quality Entries----------------------------------------
+
+ for ( Map.Entry<String, String> element : feedbackTemplateMap.entrySet() )
+ {
+ String cellPosString[] = element.getKey().split( ":" );
+
+ int tempColNo = Integer.parseInt( cellPosString[0].trim() );
+
+ int tempRowNo = Integer.parseInt( cellPosString[1].trim() );
+
+ String tempStr = element.getValue();
+
+ WritableCell cell = writableSheet.getWritableCell( tempColNo, tempRowNo );
+
+ CellFormat cellFormat = cell.getCellFormat();
+ WritableCellFormat writableCellFormat = new WritableCellFormat();
+ writableCellFormat.setBorder( Border.ALL, BorderLineStyle.THIN );
+ writableCellFormat.setWrap( true );
+ writableCellFormat.setAlignment( Alignment.CENTRE );
+
+ if ( cell.getType() == CellType.LABEL )
+ {
+ Label l = (Label) cell;
+ l.setString( tempStr );
+ l.setCellFormat( cellFormat );
+ }
+ else
+ {
+ try
+ {
+ writableSheet.addCell( new Number( tempColNo, tempRowNo, Double.parseDouble( tempStr ),
+ writableCellFormat ) );
+ }
+ catch ( Exception e )
+ {
+ writableSheet.addCell( new Label( tempColNo, tempRowNo, tempStr, writableCellFormat ) );
+ }
+ }
+ }
+
+ // --------------------------------------------------- Write
+ // OrgUnit-Specific Entries----------------------------------------
+
+ for ( Map.Entry<String, String> element : orgSpecificMap.entrySet() )
+ {
+ String cellPosString[] = element.getKey().split( ":" );
+
+ int tempColNo = Integer.parseInt( cellPosString[0].trim() );
+
+ int tempRowNo = Integer.parseInt( cellPosString[1].trim() );
+
+ String tempStr = element.getValue();
+
+ WritableCell cell = writableSheet.getWritableCell( tempColNo, tempRowNo );
+
+ CellFormat cellFormat = cell.getCellFormat();
+ WritableCellFormat writableCellFormat = new WritableCellFormat();
+ writableCellFormat.setBorder( Border.ALL, BorderLineStyle.THIN );
+ writableCellFormat.setWrap( true );
+ writableCellFormat.setAlignment( Alignment.CENTRE );
+
+ if ( cell.getType() == CellType.LABEL )
+ {
+ Label l = (Label) cell;
+ l.setString( tempStr );
+ l.setCellFormat( cellFormat );
+ }
+ else
+ {
+ try
+ {
+ writableSheet.addCell( new Number( tempColNo, tempRowNo, Double.parseDouble( tempStr ),
+ writableCellFormat ) );
+ }
+ catch ( Exception e )
+ {
+ writableSheet.addCell( new Label( tempColNo, tempRowNo, tempStr, writableCellFormat ) );
+ }
+ }
+ }
+
+ List<Report_inDesign> reportDesignList = reportService.getDistrictFeedbackReportDesign( ReportXMLFileName );
+ String dataElementIdsByComma = reportService.getDataelementIds( reportDesignList );
+
+ int orgUnitCount = 0;
+ Iterator<OrganisationUnit> it = orgUnitList.iterator();
+ while ( it.hasNext() )
+ {
+ OrganisationUnit currentOrgUnit = (OrganisationUnit) it.next();
+
+ // ---------------------------------------------------- Map for
+ // aggregate Period Data Data
+ // --------------------------------------------------------------------
+
+ Map<String, String> aggDeMap = new HashMap<String, String>();
+ if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+ {
+ aggDeMap.putAll( reportService.getResultDataValueFromAggregateTable( currentOrgUnit.getId(),
+ dataElementIdsByComma, aggPeriodIdsByComma ) );
+ }
+ else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+ {
+ List<OrganisationUnit> childOrgUnitTree = new ArrayList<OrganisationUnit>( organisationUnitService
+ .getOrganisationUnitWithChildren( currentOrgUnit.getId() ) );
+ List<Integer> childOrgUnitTreeIds = new ArrayList<Integer>( getIdentifiers( OrganisationUnit.class,
+ childOrgUnitTree ) );
+ String childOrgUnitsByComma = getCommaDelimitedString( childOrgUnitTreeIds );
+
+ aggDeMap.putAll( reportService.getAggDataFromDataValueTable( childOrgUnitsByComma,
+ dataElementIdsByComma, aggPeriodIdsByComma ) );
+ }
+ else if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+ {
+ aggDeMap.putAll( reportService.getAggDataFromDataValueTable( "" + currentOrgUnit.getId(),
+ dataElementIdsByComma, aggPeriodIdsByComma ) );
+ }
+
+ // ---------------------------------------------------- Map for only
+ // current month Data
+ // --------------------------------------------------------------------
+
+ Map<String, String> DeMap = new HashMap<String, String>();
+ if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+ {
+ DeMap.putAll( reportService.getResultDataValueFromAggregateTable( currentOrgUnit.getId(),
+ dataElementIdsByComma, periodIdsByComma ) );
+ }
+ else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+ {
+ List<OrganisationUnit> childOrgUnitTree = new ArrayList<OrganisationUnit>( organisationUnitService
+ .getOrganisationUnitWithChildren( currentOrgUnit.getId() ) );
+ List<Integer> childOrgUnitTreeIds = new ArrayList<Integer>( getIdentifiers( OrganisationUnit.class,
+ childOrgUnitTree ) );
+ String childOrgUnitsByComma = getCommaDelimitedString( childOrgUnitTreeIds );
+
+ DeMap.putAll( reportService.getAggDataFromDataValueTable( childOrgUnitsByComma, dataElementIdsByComma,
+ periodIdsByComma ) );
+ }
+ else if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+ {
+ DeMap.putAll( reportService.getAggDataFromDataValueTable( "" + currentOrgUnit.getId(),
+ dataElementIdsByComma, periodIdsByComma ) );
+ }
+
+ Iterator<Report_inDesign> reportDesignIterator = reportDesignList.iterator();
+ while ( reportDesignIterator.hasNext() )
+ {
+ Report_inDesign report_inDesign = (Report_inDesign) reportDesignIterator.next();
+
+ String sType = report_inDesign.getStype();
+ String pType = report_inDesign.getPtype();
+ String deCodeString = report_inDesign.getExpression();
+ String tempStr = "";
+
+ if ( deCodeString.equalsIgnoreCase( "FACILITY" ) )
+ {
+ tempStr = currentOrgUnit.getName();
+ }
+ else if ( deCodeString.equalsIgnoreCase( "MONTHCOUNT" ) )
+ {
+ int endYear = tempEndDate.get( Calendar.YEAR );
+ int startYear = tempStartDate.get( Calendar.YEAR );
+ int endMonth = tempEndDate.get( Calendar.MONTH );
+ int startMonth = tempStartDate.get( Calendar.MONTH );
+
+ monthCount = ((endYear - startYear) * 12) - startMonth + endMonth + 1;
+ tempStr = monthCount.toString();
+ }
+ else if ( deCodeString.equalsIgnoreCase( "FACILITY-NOREPEAT" ) )
+ {
+ tempStr = parentUnit;
+ }
+ else if ( deCodeString.equalsIgnoreCase( "FACILITYP" ) )
+ {
+ tempStr = currentOrgUnit.getParent().getName();
+ }
+ else if ( deCodeString.equalsIgnoreCase( "FACILITYPP" ) )
+ {
+ tempStr = currentOrgUnit.getParent().getParent().getName();
+ }
+ else if ( deCodeString.equalsIgnoreCase( "FACILITYPPP" ) )
+ {
+ tempStr = currentOrgUnit.getParent().getParent().getParent().getName();
+ }
+ else if ( deCodeString.equalsIgnoreCase( "FACILITYPPPP" ) )
+ {
+ tempStr = currentOrgUnit.getParent().getParent().getParent().getParent().getName();
+ }
+ else if ( deCodeString.equalsIgnoreCase( "PERIOD" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-NOREPEAT" ) )
+ {
+ tempStr = simpleDateFormat.format( sDate );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "PERIODSDED" ) )
+ {
+ tempStr = simpleDateFormat.format( sDate ) + " To " + simpleDateFormat.format( eDate );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "DATE-START-END" ) )
+ {
+ tempStr = dayFormat.format( sDate ) + " To " + dayFormat.format( eDate );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "PERIOD-MONTH" ) )
+ {
+ tempStr = monthFormat.format( sDate );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "MONTH-START-SHORT" ) )
+ {
+ tempStr = simpleMonthFormat.format( sDate );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "MONTH-END-SHORT" ) )
+ {
+ tempStr = simpleMonthFormat.format( eDate );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "MONTH-START" ) )
+ {
+ tempStr = monthFormat.format( sDate );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "MONTH-END" ) )
+ {
+ tempStr = monthFormat.format( eDate );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "PERIOD-WEEK" ) )
+ {
+ tempStr = String.valueOf( tempStartDate.get( Calendar.WEEK_OF_MONTH ) );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "PERIOD-QUARTER" ) )
+ {
+ String startMonth = monthFormat.format( sDate );
+
+ if ( startMonth.equalsIgnoreCase( "April" ) )
+ {
+ tempStr = "Quarter I";
+ }
+ else if ( startMonth.equalsIgnoreCase( "July" ) )
+ {
+ tempStr = "Quarter II";
+ }
+ else if ( startMonth.equalsIgnoreCase( "October" ) )
+ {
+ tempStr = "Quarter III";
+ }
+ else
+ {
+ tempStr = "Quarter IV";
+ }
+ }
+ else if ( deCodeString.equalsIgnoreCase( "SIMPLE-QUARTER" ) )
+ {
+ String startMonth = monthFormat.format( sDate );
+
+ if ( startMonth.equalsIgnoreCase( "April" ) )
+ {
+ tempStr = "Q1";
+ }
+ else if ( startMonth.equalsIgnoreCase( "July" ) )
+ {
+ tempStr = "Q2";
+ }
+ else if ( startMonth.equalsIgnoreCase( "October" ) )
+ {
+ tempStr = "Q3";
+ }
+ else
+ {
+ tempStr = "Q4";
+ }
+ }
+ else if ( deCodeString.equalsIgnoreCase( "QUARTER-MONTHS-SHORT" ) )
+ {
+ String startMonth = monthFormat.format( sDate );
+
+ if ( startMonth.equalsIgnoreCase( "April" ) )
+ {
+ tempStr = "Apr - Jun";
+ }
+ else if ( startMonth.equalsIgnoreCase( "July" ) )
+ {
+ tempStr = "Jul - Sep";
+ }
+ else if ( startMonth.equalsIgnoreCase( "October" ) )
+ {
+ tempStr = "Oct - Dec";
+ }
+ else
+ {
+ tempStr = "Jan - Mar";
+ }
+ }
+ else if ( deCodeString.equalsIgnoreCase( "QUARTER-MONTHS" ) )
+ {
+ String startMonth = monthFormat.format( sDate );
+
+ if ( startMonth.equalsIgnoreCase( "April" ) )
+ {
+ tempStr = "April - June";
+ }
+ else if ( startMonth.equalsIgnoreCase( "July" ) )
+ {
+ tempStr = "July - September";
+ }
+ else if ( startMonth.equalsIgnoreCase( "October" ) )
+ {
+ tempStr = "October - December";
+ }
+ else
+ {
+ tempStr = "January - March";
+ }
+ }
+ else if ( deCodeString.equalsIgnoreCase( "QUARTER-START-SHORT" ) )
+ {
+ String startMonth = monthFormat.format( sDate );
+
+ if ( startMonth.equalsIgnoreCase( "April" ) )
+ {
+ tempStr = "Apr";
+ }
+ else if ( startMonth.equalsIgnoreCase( "July" ) )
+ {
+ tempStr = "Jul";
+ }
+ else if ( startMonth.equalsIgnoreCase( "October" ) )
+ {
+ tempStr = "Oct";
+ }
+ else
+ {
+ tempStr = "Jan";
+ }
+ }
+ else if ( deCodeString.equalsIgnoreCase( "QUARTER-START" ) )
+ {
+ String startMonth = monthFormat.format( sDate );
+
+ if ( startMonth.equalsIgnoreCase( "April" ) )
+ {
+ tempStr = "April";
+ }
+ else if ( startMonth.equalsIgnoreCase( "July" ) )
+ {
+ tempStr = "July";
+ }
+ else if ( startMonth.equalsIgnoreCase( "October" ) )
+ {
+ tempStr = "October";
+ }
+ else
+ {
+ tempStr = "January";
+ }
+ }
+ else if ( deCodeString.equalsIgnoreCase( "QUARTER-END-SHORT" ) )
+ {
+ String endMonth = monthFormat.format( eDate );
+
+ if ( endMonth.equalsIgnoreCase( "June" ) )
+ {
+ tempStr = "Jun";
+ }
+ else if ( endMonth.equalsIgnoreCase( "September" ) )
+ {
+ tempStr = "Sep";
+ }
+ else if ( endMonth.equalsIgnoreCase( "December" ) )
+ {
+ tempStr = "Dec";
+ }
+ else
+ {
+ tempStr = "Mar";
+ }
+ }
+ else if ( deCodeString.equalsIgnoreCase( "QUARTER-END" ) )
+ {
+ String endMonth = monthFormat.format( eDate );
+
+ if ( endMonth.equalsIgnoreCase( "June" ) )
+ {
+ tempStr = "June";
+ }
+ else if ( endMonth.equalsIgnoreCase( "September" ) )
+ {
+ tempStr = "September";
+ }
+ else if ( endMonth.equalsIgnoreCase( "December" ) )
+ {
+ tempStr = "December";
+ }
+ else
+ {
+ tempStr = "March";
+ }
+ }
+ else if ( deCodeString.equalsIgnoreCase( "PERIOD-YEAR" ) )
+ {
+ sDateTemp = sDate;
+
+ Calendar tempQuarterYear = Calendar.getInstance();
+
+ tempQuarterYear.setTime( sDateTemp );
+
+ String startMonth = monthFormat.format( sDateTemp );
+
+ periodType = periodService.getPeriodTypeByName( periodTypeId );
+
+ if ( periodType.getName().equalsIgnoreCase( "Yearly" ) )
+ {
+ sDateTemp = sDate;
+ }
+ else if ( (startMonth.equalsIgnoreCase( "January" ) || startMonth.equalsIgnoreCase( "February" ) || startMonth
+ .equalsIgnoreCase( "March" ))
+ && periodType.getName().equalsIgnoreCase( "Quarterly" ) )
+ {
+ tempQuarterYear.roll( Calendar.YEAR, -1 );
+ sDateTemp = tempQuarterYear.getTime();
+ }
+
+ tempStr = yearFormat.format( sDateTemp );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "SIMPLE-YEAR" ) )
+ {
+ sDateTemp = sDate;
+
+ Calendar tempQuarterYear = Calendar.getInstance();
+
+ tempQuarterYear.setTime( sDateTemp );
+
+ String startMonth = "";
+
+ startMonth = monthFormat.format( sDateTemp );
+
+ periodType = periodService.getPeriodTypeByName( periodTypeId );
+
+ if ( periodType.getName().equalsIgnoreCase( "Yearly" ) )
+ {
+ sDateTemp = sDate;
+ }
+ else if ( (startMonth.equalsIgnoreCase( "January" ) || startMonth.equalsIgnoreCase( "February" ) || startMonth
+ .equalsIgnoreCase( "March" ))
+ && periodType.getName().equalsIgnoreCase( "Quarterly" ) )
+ {
+ tempQuarterYear.roll( Calendar.YEAR, -1 );
+ sDateTemp = tempQuarterYear.getTime();
+ }
+
+ tempStr = simpleYearFormat.format( sDateTemp );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "YEAR-END" ) )
+ {
+ sDateTemp = sDate;
+
+ Calendar tempQuarterYear = Calendar.getInstance();
+
+ tempQuarterYear.setTime( sDate );
+
+ sDate = tempQuarterYear.getTime();
+
+ String startMonth = "";
+
+ startMonth = monthFormat.format( sDateTemp );
+
+ periodType = periodService.getPeriodTypeByName( periodTypeId );
+
+ if ( periodType.getName().equalsIgnoreCase( "Yearly" ) )
+ {
+ tempQuarterYear.roll( Calendar.YEAR, 1 );
+ sDateTemp = tempQuarterYear.getTime();
+ }
+
+ if ( !(startMonth.equalsIgnoreCase( "January" ) || startMonth.equalsIgnoreCase( "February" ) || startMonth
+ .equalsIgnoreCase( "March" )) )
+ {
+ tempQuarterYear.roll( Calendar.YEAR, 1 );
+ sDateTemp = tempQuarterYear.getTime();
+ }
+
+ tempStr = yearFormat.format( sDateTemp );
+ }
+ else if ( deCodeString.equalsIgnoreCase( "YEAR-FROMTO" ) )
+ {
+ sDateTemp = sDate;
+
+ eDateTemp = eDate;
+
+ Calendar tempQuarterYear = Calendar.getInstance();
+
+ String startYear = "";
+
+ String endYear = "";
+
+ String startMonth = monthFormat.format( sDateTemp );
+
+ System.out.println( "The value for periodType is " + periodTypeId );
+
+ periodType = periodService.getPeriodTypeByName( periodTypeId );
+
+ tempQuarterYear.setTime( sDateTemp );
+
+ if ( periodType.getName().equalsIgnoreCase( "Yearly" ) )
+ {
+ sDateTemp = sDate;
+ }
+ else if ( (startMonth.equalsIgnoreCase( "January" ) || startMonth.equalsIgnoreCase( "February" ) || startMonth
+ .equalsIgnoreCase( "March" )) )
+ {
+ tempQuarterYear.roll( Calendar.YEAR, -1 );
+
+ sDateTemp = tempQuarterYear.getTime();
+ }
+
+ startYear = yearFormat.format( sDateTemp );
+
+ tempQuarterYear.setTime( eDateTemp );
+
+ if ( periodType.getName().equalsIgnoreCase( "Yearly" ) )
+ {
+ tempQuarterYear.roll( Calendar.YEAR, 1 );
+
+ eDateTemp = tempQuarterYear.getTime();
+ }
+
+ if ( !(startMonth.equalsIgnoreCase( "January" ) || startMonth.equalsIgnoreCase( "February" ) || startMonth
+ .equalsIgnoreCase( "March" )) )
+ {
+ tempQuarterYear.roll( Calendar.YEAR, 1 );
+
+ eDateTemp = tempQuarterYear.getTime();
+ }
+ endYear = yearFormat.format( eDateTemp );
+
+ tempStr = startYear + " - " + endYear;
+ }
+ else if ( deCodeString.equalsIgnoreCase( "SLNO" ) )
+ {
+ tempStr = "" + (orgUnitCount + 1);
+ }
+ else if ( deCodeString.equalsIgnoreCase( "NA" ) )
+ {
+ tempStr = " ";
+ }
+ else
+ {
+ if ( sType.equalsIgnoreCase( "dataelement" ) )
+ {
+ if ( pType.equalsIgnoreCase( "CCMCY" ) )
+ {
+ if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+ {
+ tempStr = reportService.getAggVal( deCodeString, aggDeMap );
+ }
+ else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+ {
+ tempStr = reportService.getAggVal( deCodeString, aggDeMap );
+ }
+ else if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+ {
+ tempStr = reportService.getAggVal( deCodeString, aggDeMap );
+ }
+ }
+ else if ( pType.equalsIgnoreCase( "CMCY" ) )
+ {
+ if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+ {
+ tempStr = reportService.getAggVal( deCodeString, DeMap );
+ }
+ else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+ {
+ tempStr = reportService.getAggVal( deCodeString, DeMap );
+ }
+ else if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+ {
+ tempStr = reportService.getAggVal( deCodeString, DeMap );
+ }
+ }
+ }
+ else
+ {
+ if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) )
+ {
+ tempStr = reportService.getIndividualResultIndicatorValue( deCodeString, tempStartDate
+ .getTime(), tempEndDate.getTime(), currentOrgUnit );
+ }
+ else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) )
+ {
+ tempStr = reportService.getResultIndicatorValue( deCodeString, tempStartDate.getTime(),
+ tempEndDate.getTime(), currentOrgUnit );
+ }
+ else if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) )
+ {
+ tempStr = reportService.getResultIndicatorValue( deCodeString, tempStartDate.getTime(),
+ tempEndDate.getTime(), currentOrgUnit );
+ }
+ }
+ }
+
+ int tempRowNo = report_inDesign.getRowno();
+ int tempColNo = report_inDesign.getColno();
+ int sheetNo = report_inDesign.getSheetno();
+
+ if ( tempStr == null || tempStr.trim().equals( "" ) )
+ {
+ tempColNo += orgUnitCount;
+
+ WritableCellFormat wCellformat = new WritableCellFormat();
+ wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN );
+ wCellformat.setWrap( true );
+ wCellformat.setAlignment( Alignment.CENTRE );
+
+ writableSheet.addCell( new Blank( tempColNo, tempRowNo, wCellformat ) );
+ }
+ else
+ {
+ if ( reportModelTB.equalsIgnoreCase( "DYNAMIC-ORGUNIT" ) )
+ {
+ if ( deCodeString.equalsIgnoreCase( "FACILITYP" )
+ || deCodeString.equalsIgnoreCase( "FACILITYPP" )
+ || deCodeString.equalsIgnoreCase( "FACILITYPPP" )
+ || deCodeString.equalsIgnoreCase( "FACILITYPPPP" ) )
+ {
+ }
+ else if ( deCodeString.equalsIgnoreCase( "PERIOD" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-NOREPEAT" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-WEEK" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-MONTH" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-QUARTER" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-YEAR" )
+ || deCodeString.equalsIgnoreCase( "MONTH-START" )
+ || deCodeString.equalsIgnoreCase( "MONTH-END" )
+ || deCodeString.equalsIgnoreCase( "MONTH-START-SHORT" )
+ || deCodeString.equalsIgnoreCase( "MONTH-END-SHORT" )
+ || deCodeString.equalsIgnoreCase( "SIMPLE-QUARTER" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-MONTHS-SHORT" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-MONTHS" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-START-SHORT" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-END-SHORT" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-START" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-END" )
+ || deCodeString.equalsIgnoreCase( "SIMPLE-YEAR" )
+ || deCodeString.equalsIgnoreCase( "YEAR-END" )
+ || deCodeString.equalsIgnoreCase( "YEAR-FROMTO" )
+ || deCodeString.equalsIgnoreCase( "DATE-START-END" ) )
+ {
+ }
+ else
+ {
+ tempColNo += orgUnitCount;
+ }
+ }
+ else if ( reportModelTB.equalsIgnoreCase( "dynamicwithrootfacility" ) )
+ {
+ if ( deCodeString.equalsIgnoreCase( "FACILITYP" )
+ || deCodeString.equalsIgnoreCase( "FACILITY-NOREPEAT" )
+ || deCodeString.equalsIgnoreCase( "FACILITYPP" )
+ || deCodeString.equalsIgnoreCase( "FACILITYPPP" )
+ || deCodeString.equalsIgnoreCase( "FACILITYPPPP" ) )
+ {
+ }
+ else if ( deCodeString.equalsIgnoreCase( "PERIOD" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-NOREPEAT" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-WEEK" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-MONTH" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-QUARTER" )
+ || deCodeString.equalsIgnoreCase( "PERIOD-YEAR" )
+ || deCodeString.equalsIgnoreCase( "MONTH-START" )
+ || deCodeString.equalsIgnoreCase( "MONTH-END" )
+ || deCodeString.equalsIgnoreCase( "MONTH-START-SHORT" )
+ || deCodeString.equalsIgnoreCase( "MONTH-END-SHORT" )
+ || deCodeString.equalsIgnoreCase( "SIMPLE-QUARTER" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-MONTHS-SHORT" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-MONTHS" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-START-SHORT" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-END-SHORT" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-START" )
+ || deCodeString.equalsIgnoreCase( "QUARTER-END" )
+ || deCodeString.equalsIgnoreCase( "SIMPLE-YEAR" )
+ || deCodeString.equalsIgnoreCase( "YEAR-END" )
+ || deCodeString.equalsIgnoreCase( "YEAR-FROMTO" )
+ || deCodeString.equalsIgnoreCase( "DATE-START-END" ) )
+ {
+ }
+ else
+ {
+ tempRowNo += orgUnitCount;
+ }
+ }
+
+ WritableCell cell = writableSheet.getWritableCell( tempColNo, tempRowNo );
+
+ CellFormat cellFormat = cell.getCellFormat();
+ WritableCellFormat wCellformat = new WritableCellFormat();
+ wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN );
+ wCellformat.setWrap( true );
+ wCellformat.setAlignment( Alignment.CENTRE );
+
+ if ( cell.getType() == CellType.LABEL )
+ {
+ Label l = (Label) cell;
+ l.setString( tempStr );
+ l.setCellFormat( cellFormat );
+ }
+ else
+ {
+ try
+ {
+ writableSheet.addCell( new Number( tempColNo, tempRowNo, Double.parseDouble( tempStr ),
+ wCellformat ) );
+ }
+ catch ( Exception e )
+ {
+ writableSheet.addCell( new Label( tempColNo, tempRowNo, tempStr, wCellformat ) );
+ }
+ }
+ }
+
+ }
+ orgUnitCount++;
+ }
+
+ outputReportWorkbook.write();
+ outputReportWorkbook.close();
+
+ fileName = reportFileNameTB.replace( ".xls", "" );
+ fileName += "_" + orgUnitList.get( 0 ).getShortName() + "_";
+ fileName += "_" + simpleDateFormat.format( sDate ) + "_";
+ fileName += "_" + simpleDateFormat.format( eDate ) + ".xls";
+ File outputReportFile = new File( outputReportPath );
+ inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+
+ System.out.println( orgUnitList.get( 0 ).getName() + " : " + selReportObj.getName()
+ + " Report Generation End Time is : " + new Date() );
+
+ outputReportFile.deleteOnExit();
+
+ statementManager.destroy();
+
+ 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-07-24 12:38:31 +0000
+++ local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml 2012-07-26 09:20:56 +0000
@@ -352,7 +352,29 @@
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
<property name="reportService" ref="org.hisp.dhis.reports.ReportService" />
</bean>
-
+
+
+ <!--District Feedback Reports -->
+
+ <bean
+ id="org.hisp.dhis.reports.districtfeedback.action.GenerateAggregationDistrictFeedbackReportAnalyserFormAction"
+ class="org.hisp.dhis.reports.districtfeedback.action.GenerateAggregationDistrictFeedbackReportAnalyserFormAction"
+ scope="prototype">
+ <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+ </bean>
+
+ <bean
+ id="org.hisp.dhis.reports.districtfeedback.action.GenerateAggregationDistrictFeedbackReportAnalyserResultAction"
+ class="org.hisp.dhis.reports.districtfeedback.action.GenerateAggregationDistrictFeedbackReportAnalyserResultAction"
+ scope="prototype">
+ <property name="reportService" ref="org.hisp.dhis.reports.ReportService" />
+ <property name="statementManager" ref="statementManager" />
+ <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+ <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <property name="stateDistrictFeedbackReportService" ref="org.hisp.dhis.reports.StateDistrictFeedbackReportService"/>
+ <property name="reportOrgSpecificDataService" ref="org.hisp.dhis.reports.ReportOrgSpecificDataService"/>
+ </bean>
+
<!-- Upward / GOI Reports -->
<bean
id="org.hisp.dhis.reports.upward.action.GenerateUpwardReportAnalyserFormAction"
=== modified file 'local/in/dhis-web-reports-national/src/main/resources/org/hisp/dhis/reports/i18n_module.properties'
--- local/in/dhis-web-reports-national/src/main/resources/org/hisp/dhis/reports/i18n_module.properties 2012-07-02 07:39:05 +0000
+++ local/in/dhis-web-reports-national/src/main/resources/org/hisp/dhis/reports/i18n_module.properties 2012-07-26 09:20:56 +0000
@@ -14,6 +14,7 @@
aggregated_data = Aggregated Data
generate_report = Generate Report
all = ALL
+district_feedback= Feedback Template Analyser
selected_only = Selected Only
orgunitgrouptype = OrgUnitGroupType
year = Year
@@ -21,6 +22,7 @@
generate_agg_data = Generate Aggregate Data
use_captured_data = Use Captured Data
generated_data_type = Generated Data Type
+use_data_type = Use Data Values From
please_select_an_orgUnit= Please select an OrganisationUnit.
please_select_a_dataset= Please select a dataset.
=== 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-07-24 12:38:31 +0000
+++ local/in/dhis-web-reports-national/src/main/resources/struts.xml 2012-07-26 09:20:56 +0000
@@ -1005,6 +1005,28 @@
</result>
</action>
+ <!--District Feedback-->
+
+ <action name="districtFeedbackReportAnalyser"
+ class="org.hisp.dhis.reports.districtfeedback.action.GenerateAggregationDistrictFeedbackReportAnalyserFormAction">
+ <result name="success" type="velocity">/main.vm</result>
+ <param name="page">/dhis-web-reports/districtFeedbackReportAnalysisFront.vm</param>
+ <param name="menu">/dhis-web-reports/menuWithTreeForDistrictFeedbackReport.vm</param>
+ <param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,../dhis-web-commons/calendar/calendar.js,../dhis-web-commons/calendar/calendar-lang.js,../dhis-web-commons/calendar/calendar-setup.js,../dhis-web-commons/lists/lists.js,javascript/reportManagement.js,javascript/hashtable.js,../dhis-web-commons/util/validate/jquery.validate.js,../dhis-web-commons/util/jquery.metadata.js,../dhis-web-commons/util/validate/additional-methods.js,../dhis-web-commons/util/validate/messages_locale.js</param>
+ <param name="stylesheets">css/StylesForTags.css</param>
+ <param name="requiredAuthorities">F_REPORT_DISTRICTFEEDBACK</param>
+ <interceptor-ref name="organisationUnitTreeStack"/>
+ </action>
+ <action name="generateDistrictFeedbackReport"
+ class="org.hisp.dhis.reports.districtfeedback.action.GenerateAggregationDistrictFeedbackReportAnalyserResultAction">
+ <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>
+
<!-- ranking2 Reports -->
<action name="ranking2ReportForm"
class="org.hisp.dhis.reports.ranking2.action.Ranking2ReportFormAction">
=== added file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/districtFeedbackReportAnalysisFront.vm'
--- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/districtFeedbackReportAnalysisFront.vm 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/districtFeedbackReportAnalysisFront.vm 2012-07-26 09:20:56 +0000
@@ -0,0 +1,103 @@
+
+<script>
+
+ function formValidations()
+ {
+ var reportListIndex = document.reportForm.reportList.selectedIndex;
+ var periodIndex = document.reportForm.availablePeriods.selectedIndex;
+ var orgunitIdValue = document.reportForm.ouIDTB.value;
+
+ if(orgunitIdValue == null || orgunitIdValue=="" || orgunitIdValue==" ") {alert("Please Select OrganisationUnit"); return false;}
+ else if(document.reportForm.availablePeriods.options[periodIndex].text == null || document.reportForm.availablePeriods.options[periodIndex].text== "") {alert("Please Select Period"); return false;}
+ else if(reportListIndex < 0 || document.reportForm.reportList.options[reportListIndex].text == null) {alert("Please Select Report"); return false;}
+
+ return true;
+ }
+
+</script>
+
+<h1>$i18n.getString( "district_feedback" )</h1>
+<hr /><br />
+
+<script type="text/javascript">
+
+ window.onload = function()
+ {
+ getPeriods();
+ };
+
+</script>
+
+
+<form id="reportForm" name="reportForm" action="generateDistrictFeedbackReport.action" method="post" onsubmit="return formValidations()" target="_blank" onload="getPeriods()">
+
+ <table align="center" style=" border-collapse: collapse; margin-top: 0;" cellpadding="0" cellspacing="0" width="730" border=0>
+ <tr>
+ <td class="NormalB">
+
+ <!--1. $i18n.getString( "periodtype" ) :<br /> -->
+
+ <select id="periodTypeId" name="periodTypeId" style="display: none;" onchange="getPeriods()">
+ <option value="Monthly">[ Select PeriodType ]</option>
+ <option selected="selected">Monthly</option>
+ #foreach ( $type in $periodTypes )
+ <option value="$type.name">$type.name</option>
+ #end
+ </select>
+
+ 1. $i18n.getString( "periods" ) :<br />
+ <select id="availablePeriods" name="availablePeriods" style="width:200px"></select>
+
+ </td>
+ <td class="NormalB">
+ 2. $i18n.getString( "organisationunit" ) :<br />
+ <input type="text" name="ouNameTB" id="ouNameTB" size="20" style="width: 200px" disabled>
+ </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td> </td>
+ </tr>
+ <tr>
+ <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 class="NormalB">
+ 3. $i18n.getString( "reports" ) :<br />
+ <select id="reportList" name="reportList" style="width:200px"></select>
+ </td>
+
+ <td class="NormalB">
+ 4. $i18n.getString( "use_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">$i18n.getString( "use_captured_data" )</option>
+ </select>
+ </td>
+ </tr>
+
+ <tr>
+ <td> </td>
+ <td class="NormalB" align="left">
+ <br><br><br><br>
+ <input type="submit" name="generate" value='$i18n.getString( "generate_report" )' disabled="disabled"/>
+ <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">
+ </td>
+ </tr>
+
+ </table>
+</form>
=== added file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForDistrictFeedbackReport.vm'
--- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForDistrictFeedbackReport.vm 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForDistrictFeedbackReport.vm 2012-07-26 09:20:56 +0000
@@ -0,0 +1,31 @@
+<a href="index.action"><h2>Report Analyser</h2></a>
+
+<ul>
+ <li>Report Analysis</li>
+ <ul>
+ <li>
+ Feedback Template
+ </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 != "" )
+ {
+ getReports( orgUnitIds, reportTypeName )
+ }
+ }
+
+ selection.setListenerFunction( orgUnitHasBeenSelected );
+
+</script>
+