=== 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; + +/** + * ,Date: 7/10/12, Time: 5:24 PM + */ +public interface ReportOrgSpecificDataService { + + public Map 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 getReportDesign( String fileName ); + List 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; + +/** + * ,Date: 7/4/12, Time: 12:44 PM + */ +public interface StateDistrictFeedbackReportService { + + String ID = StateDistrictFeedbackReportService.class.getName(); + + public Map 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; + +/** + * ,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 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 DataPositionMap = new HashMap(); + + 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 orgUnitList = new ArrayList( District.getChildren() ); + + if ( organisationUnitGroupService == null ) + { + System.out.println( "* ERROR !! OrganisationUnitGroupService is NULL" ); + } + + List orgUnitGroupList = new ArrayList( organisationUnitGroupService + .getOrganisationUnitGroup( oucode ).getMembers() ); + orgUnitList.retainAll( orgUnitGroupList ); + + Collection IntermediatePeriods = periodService.getPeriodsBetweenDates( sDate, eDate ); + + Collection 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 getDistrictFeedbackReportDesign( String fileName ) + { + List reportDesignList = new ArrayList(); + + 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 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 getReportDesign( Report_in report ) { List deCodes = new ArrayList(); @@ -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; + +/** + * ,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 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 feedbackTemplateMap = new HashMap(); + + 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 orgUnitList = new ArrayList( 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 orgUnitGroupList = new ArrayList( organisationUnitGroupService + .getOrganisationUnitGroup( fCode ).getMembers() ); + + orgUnitGroupList.retainAll( orgUnitList ); + + Collection 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 dataElementList = new ArrayList( dataSetService + .getDataElements( facilityDataSet ) ); + + totalEntries = (dataElementList.size() * orgUnitGroupList.size()); + + Collection dataElementCollection = new ArrayList( 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"> + + + + + + + + + + + + + + + + + + + + + + + + periodTypes; + + public Collection 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 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 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( orgUnit.getChildren() ); + Collections.sort( orgUnitList, new IdentifiableObjectNameComparator() ); + } + else if ( reportModelTB.equalsIgnoreCase( "STATIC" ) || reportModelTB.equalsIgnoreCase( "STATIC-DATAELEMENTS" ) + || reportModelTB.equalsIgnoreCase( "STATIC-FINANCIAL" ) ) + { + orgUnitList = new ArrayList(); + OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); + orgUnitList.add( orgUnit ); + } + else if ( reportModelTB.equalsIgnoreCase( "dynamicwithrootfacility" ) ) + { + OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); + orgUnitList = new ArrayList( 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 periodList = new ArrayList( periodService + .getPeriodsBetweenDates( periodType, sDate, eDate ) ); + + System.out.println( "* Period List Size: [" + periodList.size() + "]" ); + + Collection periodIds = new ArrayList( getIdentifiers( Period.class, periodList ) ); + + String periodIdsByComma = getCommaDelimitedString( periodIds ); + + List aggPeriodList = new ArrayList( 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 aggPeriodIds = new ArrayList( 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 feedbackTemplateMap; + + Map 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 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 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 reportDesignList = reportService.getDistrictFeedbackReportDesign( ReportXMLFileName ); + String dataElementIdsByComma = reportService.getDataelementIds( reportDesignList ); + + int orgUnitCount = 0; + Iterator it = orgUnitList.iterator(); + while ( it.hasNext() ) + { + OrganisationUnit currentOrgUnit = (OrganisationUnit) it.next(); + + // ---------------------------------------------------- Map for + // aggregate Period Data Data + // -------------------------------------------------------------------- + + Map aggDeMap = new HashMap(); + if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) ) + { + aggDeMap.putAll( reportService.getResultDataValueFromAggregateTable( currentOrgUnit.getId(), + dataElementIdsByComma, aggPeriodIdsByComma ) ); + } + else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) ) + { + List childOrgUnitTree = new ArrayList( organisationUnitService + .getOrganisationUnitWithChildren( currentOrgUnit.getId() ) ); + List childOrgUnitTreeIds = new ArrayList( 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 DeMap = new HashMap(); + if ( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) ) + { + DeMap.putAll( reportService.getResultDataValueFromAggregateTable( currentOrgUnit.getId(), + dataElementIdsByComma, periodIdsByComma ) ); + } + else if ( aggData.equalsIgnoreCase( GENERATEAGGDATA ) ) + { + List childOrgUnitTree = new ArrayList( organisationUnitService + .getOrganisationUnitWithChildren( currentOrgUnit.getId() ) ); + List childOrgUnitTreeIds = new ArrayList( 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 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 @@ - + + + + + + + + + + + + + + + + + + + + + /main.vm + /dhis-web-reports/districtFeedbackReportAnalysisFront.vm + /dhis-web-reports/menuWithTreeForDistrictFeedbackReport.vm + ../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 + css/StylesForTags.css + F_REPORT_DISTRICTFEEDBACK + + + + + application/vnd.ms-excel + inputStream + filename="${fileName}" + 1024 + + + === 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 @@ + + + +

$i18n.getString( "district_feedback" )

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + 1. $i18n.getString( "periods" ) :
+ + +
+ 2. $i18n.getString( "organisationunit" ) :
+ +
  
  
+ 3. $i18n.getString( "reports" ) :
+ +
+ 4. $i18n.getString( "use_data_type" ) :
+ +
   +



+ + + + +
+
=== 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 @@ +

Report Analyser

+ +
    +
  • Report Analysis
  • +
      +
    • + Feedback Template +
    • +
    +
+ +#parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" ) + + +