=== 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 2010-12-03 13:29:28 +0000 +++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java 2011-01-05 05:31:43 +0000 @@ -121,4 +121,5 @@ List getDataNotSentOrgUnits( DataSet dataSet, Period period, OrganisationUnit rootOrgunit ); + String getResultSurveyValue( String formula, OrganisationUnit organisationUnit ); } === modified file 'local/in/dhis-in-services/dhis-in-service-reports/pom.xml' --- local/in/dhis-in-services/dhis-in-service-reports/pom.xml 2010-12-29 06:38:03 +0000 +++ local/in/dhis-in-services/dhis-in-service-reports/pom.xml 2011-01-05 05:31:43 +0000 @@ -44,6 +44,11 @@ org.hisp.dhis dhis-support-system + + org.hisp.dhis + dhis-service-reporting + + === 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 2010-12-31 07:16:18 +0000 +++ local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java 2011-01-05 05:31:43 +0000 @@ -34,6 +34,10 @@ import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.source.Source; +import org.hisp.dhis.survey.Survey; +import org.hisp.dhis.survey.SurveyService; +import org.hisp.dhis.surveydatavalue.SurveyDataValue; +import org.hisp.dhis.surveydatavalue.SurveyDataValueService; import org.hisp.dhis.system.util.MathUtils; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.rowset.SqlRowSet; @@ -130,6 +134,20 @@ this.organisationUnitService = organisationUnitService; } + private SurveyService surveyService; + + public void setSurveyService( SurveyService surveyService ) + { + this.surveyService = surveyService; + } + + private SurveyDataValueService surveyDataValueService; + + public void setSurveyDataValueService( SurveyDataValueService surveyDataValueService ) + { + this.surveyDataValueService = surveyDataValueService; + } + // ------------------------------------------------------------------------- // Report_in // ------------------------------------------------------------------------- @@ -1485,4 +1503,277 @@ return deInfo.toString(); } + + public String getResultSurveyValue( String formula, OrganisationUnit organisationUnit ) + { + try + { + int deFlag1 = 0; + int deFlag2 = 0; + Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); + + Matcher matcher = pattern.matcher( formula ); + StringBuffer buffer = new StringBuffer(); + + while ( matcher.find() ) + { + String replaceString = matcher.group(); + + replaceString = replaceString.replaceAll( "[\\[\\]]", "" ); + + String surveyIdString = replaceString.substring( replaceString.indexOf( '.' ) + 1, replaceString.length() ); + + replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) ); + + int indicatorId = Integer.parseInt( replaceString ); + + int surveyId = Integer.parseInt( surveyIdString ); + + Indicator indicator = indicatorService.getIndicator( indicatorId ); + + Survey survey = surveyService.getSurvey( surveyId ); + + if ( indicator == null || survey == null) + { + replaceString = ""; + matcher.appendReplacement( buffer, replaceString ); + continue; + } + + SurveyDataValue surveyDataValue = new SurveyDataValue(); + + surveyDataValue = surveyDataValueService.getSurveyDataValue(organisationUnit, survey, indicator); + + if ( surveyDataValue == null ) + { + replaceString = ""; + matcher.appendReplacement( buffer, replaceString ); + continue; + } + + Double surveyValue = Double.valueOf( surveyDataValue.getValue() ); + + if ( surveyValue == null ) + { + replaceString = NULL_REPLACEMENT; + } + else + { + replaceString = String.valueOf( surveyValue ); + deFlag2 = 1; + } + + matcher.appendReplacement( buffer, replaceString ); + } + + matcher.appendTail( buffer ); + + String resultValue = ""; + if ( deFlag1 == 0 ) + { + double d = 0.0; + try + { + d = MathUtils.calculateExpression( buffer.toString() ); + } + catch ( Exception e ) + { + d = 0.0; + } + if ( d == -1 ) + d = 0.0; + else + { + d = Math.round( d * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 ); + resultValue = "" + d; + } + + if ( deFlag2 == 0 ) + { + resultValue = " "; + } + } + else + { + resultValue = buffer.toString(); + } + //System.out.println("Result in Survey : "+ resultValue); + return resultValue; + } + catch ( NumberFormatException ex ) + { + throw new RuntimeException( "Illegal Indicator and survey id", ex ); + } + } + + // ------------------------------------------------------------------------- + // Get Aggregated Result for dataelement expression from ReportTable + // ------------------------------------------------------------------------- + public String getResultDataValueFromReportTable( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit , String reportModelTB ) + { + int deFlag1 = 0; + int isAggregated = 0; + + try + { + Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); + + Matcher matcher = pattern.matcher( formula ); + 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 ); + + DataElement dataElement = dataElementService.getDataElement( dataElementId ); + DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService.getDataElementCategoryOptionCombo( optionComboId ); + + if ( dataElement == null || optionCombo == null ) + { + replaceString = ""; + matcher.appendReplacement( buffer, replaceString ); + continue; + } + if ( dataElement.getType().equalsIgnoreCase( "int" ) ) + { + Double aggregatedValue = aggregationService.getAggregatedDataValue( dataElement, optionCombo, + startDate, endDate, organisationUnit ); + if ( aggregatedValue == null ) + { + replaceString = NULL_REPLACEMENT; + } + else + { + replaceString = String.valueOf( aggregatedValue ); + + isAggregated = 1; + } + } + else + { + deFlag1 = 1; + PeriodType dePeriodType = getDataElementPeriodType( dataElement ); + //List periodList = new ArrayList( periodService.getIntersectingPeriodsByPeriodType( dePeriodType, startDate, endDate ) ); + List periodList = new ArrayList( periodService.getPeriodsBetweenDates( dePeriodType, startDate, endDate ) ); + Period tempPeriod = new Period(); + if ( periodList == null || periodList.isEmpty() ) + { + replaceString = ""; + matcher.appendReplacement( buffer, replaceString ); + continue; + } + else + { + tempPeriod = (Period) periodList.get( 0 ); + } + + DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, tempPeriod, + optionCombo ); + + if ( dataValue != null && dataValue.getValue() != null ) + { + replaceString = dataValue.getValue(); + } + else + { + replaceString = ""; + } + + if ( replaceString == null ) + { + replaceString = ""; + } + } + matcher.appendReplacement( buffer, replaceString ); + + resultValue = replaceString; + } + + matcher.appendTail( buffer ); + + if ( deFlag1 == 0 ) + { + double d = 0.0; + try + { + d = MathUtils.calculateExpression( buffer.toString() ); + } + catch ( Exception e ) + { + d = 0.0; + resultValue = ""; + } + if ( d == -1 ) + { + d = 0.0; + resultValue = ""; + } + else + { + // This is to display financial data as it is like 2.1476838 + resultValue = "" + d; + + // These lines are to display financial data that do not + // have decimals + d = d * 10; + if ( d % 10 == 0 ) + { + resultValue = "" + (int) d / 10; + } + + d = d / 10; + + // These line are to display non financial data that do not + // require decimals + if ( !(reportModelTB.equalsIgnoreCase( "STATIC-FINANCIAL" )) ) + { + resultValue = "" + (int) d; + } + } + + } + else + { + resultValue = buffer.toString(); + } + + if( isAggregated == 0 ) + { + resultValue = " "; + } + + if ( resultValue.equalsIgnoreCase( "" ) ) + { + resultValue = " "; + } + + return resultValue; + } + catch ( NumberFormatException ex ) + { + throw new RuntimeException( "Illegal DataElement id", ex ); + } + } + + Double getAggregatedDataValueFromReportTable( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, Date startDate, Date endDate, OrganisationUnit organisationUnit ) + { + Double aggValue = null; + List periodList = new ArrayList( periodService.getPeriodsBetweenDates( startDate, endDate ) ); + Period tempPeriod = new Period(); + + + + return aggValue; + } } === 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 2010-12-03 13:29:28 +0000 +++ local/in/dhis-in-services/dhis-in-service-reports/src/main/resources/META-INF/dhis/beans.xml 2011-01-05 05:31:43 +0000 @@ -27,6 +27,8 @@ + + === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/action/GetReportsAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/action/GetReportsAction.java 2010-12-22 07:29:08 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/action/GetReportsAction.java 2011-01-05 05:31:43 +0000 @@ -60,19 +60,11 @@ private String reportType; - public void setReportType( String reportType ) { this.reportType = reportType; } -/* - private String reportTypeName; - public void setReportTypeName( String reportTypeName ) - { - this.reportTypeName = reportTypeName; - } -*/ private List reportList; public List getReportList() === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/benificiaryinfo/action/BenificiaryInfoReportsFormAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/benificiaryinfo/action/BenificiaryInfoReportsFormAction.java 2010-09-29 02:04:14 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/benificiaryinfo/action/BenificiaryInfoReportsFormAction.java 2011-01-05 05:31:43 +0000 @@ -1,18 +1,13 @@ package org.hisp.dhis.reports.benificiaryinfo.action; import java.io.File; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.hisp.dhis.period.MonthlyPeriodType; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.reports.ReportService; -import org.hisp.dhis.reports.Report_in; import org.hisp.dhis.reports.util.Report; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -26,7 +21,6 @@ public class BenificiaryInfoReportsFormAction implements Action { - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -38,13 +32,6 @@ this.reportService = reportService; } - private PeriodService periodService; - - public void setPeriodService( PeriodService periodService ) - { - this.periodService = periodService; - } - // ------------------------------------------------------------------------- // Getter & Setter // ------------------------------------------------------------------------- @@ -56,20 +43,6 @@ return reportList; } - private List periodList; - - public List getPeriodList() - { - return periodList; - } - - private SimpleDateFormat simpleDateFormat; - - public SimpleDateFormat getSimpleDateFormat() - { - return simpleDateFormat; - } - private String raFolderName; // ------------------------------------------------------------------------- @@ -82,14 +55,8 @@ { raFolderName = reportService.getRAFolderName(); - periodList = new ArrayList( periodService.getPeriodsByPeriodType( new MonthlyPeriodType() ) ); - reportList = new ArrayList(); - simpleDateFormat = new SimpleDateFormat( "MMM-yyyy" ); - - System.out.println( "periodList.size " + periodList.size() ); - getSelectedReportList(); return SUCCESS; === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/benificiaryinfo/action/BenificiaryInfoReportsResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/benificiaryinfo/action/BenificiaryInfoReportsResultAction.java 2010-12-29 16:17:28 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/benificiaryinfo/action/BenificiaryInfoReportsResultAction.java 2011-01-05 05:31:43 +0000 @@ -3,7 +3,6 @@ //@23-06-2010 - Date from and to is solved. //Todo merging of cells for same village -// import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -12,6 +11,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -27,8 +27,10 @@ import jxl.format.Alignment; import jxl.format.Border; import jxl.format.BorderLineStyle; +import jxl.format.Colour; import jxl.format.VerticalAlignment; -import jxl.format.Font; +import jxl.write.Label; +import jxl.write.WritableCell; import jxl.write.WritableCellFormat; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; @@ -37,11 +39,16 @@ import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; import org.hisp.dhis.patient.Patient; import org.hisp.dhis.patient.PatientAttribute; import org.hisp.dhis.patient.PatientAttributeService; +import org.hisp.dhis.patient.PatientIdentifier; import org.hisp.dhis.patient.PatientIdentifierService; +import org.hisp.dhis.patient.PatientIdentifierType; +import org.hisp.dhis.patient.PatientIdentifierTypeService; import org.hisp.dhis.patient.PatientService; +import org.hisp.dhis.patientattributevalue.PatientAttributeValue; import org.hisp.dhis.patientattributevalue.PatientAttributeValueService; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodService; @@ -51,6 +58,7 @@ import org.hisp.dhis.program.ProgramInstanceService; import org.hisp.dhis.program.ProgramService; import org.hisp.dhis.program.ProgramStageInstance; +import org.hisp.dhis.relationship.RelationshipTypeService; import org.hisp.dhis.reports.ReportService; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -60,27 +68,14 @@ import org.xml.sax.SAXParseException; import com.opensymphony.xwork2.Action; -import java.util.Collections; -import jxl.format.Colour; -import jxl.write.Label; -import jxl.write.WritableCell; -import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; -import org.hisp.dhis.patient.PatientIdentifier; -import org.hisp.dhis.patient.PatientIdentifierType; -import org.hisp.dhis.patient.PatientIdentifierTypeService; -import org.hisp.dhis.patientattributevalue.PatientAttributeValue; -import org.hisp.dhis.relationship.RelationshipTypeService; -// public class BenificiaryInfoReportsResultAction implements Action { - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- - // RelationshipTypeService relationshipTypeService; public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService ) @@ -177,11 +172,10 @@ this.format = format; } - // // ------------------------------------------------------------------------- // Properties // ------------------------------------------------------------------------- - // + private Map> visitsByPatients = new HashMap>(); public Map> getVisitsByPatients() @@ -316,9 +310,6 @@ private int rowCount; - // - // private String orgUnitInfo = "-1"; - // private String aggDataTableName; // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -331,7 +322,7 @@ // Initialization simpleDateFormat = new SimpleDateFormat( "MMM-yyyy" ); deCodesXMLFileName = reportList + "DECodes.xml"; - // System.out.println( "reportList = " + reportList ); + deCodeType = new ArrayList(); serviceType = new ArrayList(); @@ -340,18 +331,15 @@ colList = new ArrayList(); if ( includePeriod != null ) { - // System.out.println( "startDate = " + startDate + " endDate = " + - // endDate + " reportname = " + reportFileNameTB + - // " includePeriod = " + includePeriod ); Calendar c = Calendar.getInstance(); c.setTime( format.parseDate( startDate ) ); c.add( Calendar.DATE, -1 ); // number of days to add - startDate = format.formatDate( c.getTime() ); // dt is now the new - // date + startDate = format.formatDate( c.getTime() ); + c.setTime( format.parseDate( endDate ) ); c.add( Calendar.DATE, 1 ); // number of days to add - endDate = format.formatDate( c.getTime() ); // dt is now the new - // date + endDate = format.formatDate( c.getTime() ); + sDate = format.parseDate( startDate ); eDate = format.parseDate( endDate ); } @@ -366,8 +354,6 @@ return SUCCESS; } - // public void generatFeedbackReport() throws Exception { @@ -375,7 +361,7 @@ WritableWorkbook outputReportWorkbook = Workbook .createWorkbook( new File( outputReportPath ), templateWorkbook ); - // System.out.println( "outputReportWorkbook = "+outputReportWorkbook ); + // Cell formatting WritableCellFormat wCellformat = new WritableCellFormat(); wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN ); @@ -392,26 +378,21 @@ // OrgUnit Related Info selectedOrgUnit = new OrganisationUnit(); - // System.out.println( "______________ " + reportLevelTB ); selectedOrgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); - // Collection patientIdentifiers = - // patientIdentifierService.getPatientIdentifiersByOrgUnit( - // selectedOrgUnit ); - Collection ouList = new ArrayList(); + // Getting Programs rowCount = 0; List deCodesList = getDECodes( deCodesXMLFileName ); Program curProgram = programService.getProgram( Integer.parseInt( reportLevelTB ) ); - // /System.out.println( "curProgram = " + curProgram.getName() ); + String tempStr = ""; Map ouAndLevel = new HashMap(); if ( curProgram != null ) { - WritableSheet sheet0 = outputReportWorkbook.getSheet( 0 ); - // System.out.println( "curProgram = " + curProgram.getName() ); + int count1 = 0; int rowStart = 0; @@ -420,48 +401,29 @@ orgUnitList = getChildOrgUnitTree( selectedOrgUnit ); List levelsList = new ArrayList(); - // + for ( OrganisationUnit ou : orgUnitList ) { - // int level = organisationUnitService.getLevelOfOrganisationUnit( ou ); ouAndLevel.put( ou, level ); if ( !levelsList.contains( level ) ) { - // System.out.println("ou "+ou.getName() + - // " level = "+level); levelsList.add( level ); } - // + List patientListByOuProgram = new ArrayList(); List patientListByOu = new ArrayList(); - // - patientListByOu.addAll( patientService.getPatients( ou ) );// getting - // all - // the - // patients - // by - // ou + patientListByOu.addAll( patientService.getPatients( ou ) ); + Iterator patientIterator = patientListByOu.iterator(); while ( patientIterator.hasNext() ) { - Patient patient = patientIterator.next();// taking patient - // from - // patientListByChild - Set patientProgramList = patient.getPrograms(); // getting - // enrolled - // programs - // of - // patient - // checking if patient is enrolled to curprog then adding - // them in one list + Patient patient = patientIterator.next(); + Set patientProgramList = patient.getPrograms(); Collection programInstances = new ArrayList(); programInstances = programInstanceService.getProgramInstances( patient, curProgram ); - // System.out.println( "pi size = "+programInstances.size() - // ); + for ( ProgramInstance pi : programInstances ) { if ( patientProgramList != null ) @@ -486,33 +448,25 @@ } } } - // System.out.println( - // "patientListByOuProgram = "+patientListByOuProgram.size() ); + if ( patientListByOuProgram.size() > 0 ) { ouList.add( ou ); ouPatientList.put( ou.getName(), patientListByOuProgram ); - // System.out.println( "ou = " + ou.getName() + - // " patientssise = " + patientListByOuProgram.size() ); } - // } - // - // for ( String deCodeString : deCodesList ) { - String sType = (String) serviceType.get( count1 );// + String sType = (String) serviceType.get( count1 ); if ( sType.equalsIgnoreCase( "rowStart" ) ) { rowStart = Integer.parseInt( deCodeString ); } count1++; } - // + int lastColNo = colList.get( colList.size() - 1 ); - // for ( int i = levelsList.size() - 1; i >= 0; i-- ) { int level = levelsList.get( i ); @@ -520,27 +474,21 @@ sheet0.addCell( new Label( lastColNo, rowStart - 1, organisationUnitService .getOrganisationUnitLevelByLevel( level ).getName(), deWCellformat ) ); } - // - // for ( OrganisationUnit ou : ouList ) { List patientsList = ouPatientList.get( ou.getName() ); - // for ( Patient patient : patientsList ) { int colNo = 0; int rowNo = rowStart + rowCount; count1 = 0; - // + for ( String deCodeString : deCodesList ) { tempStr = ""; String sType = (String) serviceType.get( count1 ); - // + if ( sType.equalsIgnoreCase( "caseProperty" ) ) { if ( deCodeString.equalsIgnoreCase( "Name" ) ) @@ -580,9 +528,6 @@ } } } - // - // else if ( sType.equalsIgnoreCase( "caseAttribute" ) ) { int deCodeInt = Integer.parseInt( deCodeString ); @@ -599,14 +544,9 @@ tempStr = " "; } } - // - // else if ( sType.equalsIgnoreCase( "identifiertype" ) ) { int deCodeInt = Integer.parseInt( deCodeString ); - // _______________________Id. - // no._______________________ PatientIdentifierType patientIdentifierType = patientIdentifierTypeService .getPatientIdentifierType( deCodeInt ); if ( patientIdentifierType != null ) @@ -623,51 +563,31 @@ } } } - // - // else if ( sType.equalsIgnoreCase( "srno" ) ) { int tempNum = 1 + rowCount; tempStr = String.valueOf( tempNum ); } - // - // if ( !sType.equalsIgnoreCase( "rowStart" ) && !sType.equalsIgnoreCase( "reportProperty" ) ) { int tempColNo = colList.get( count1 ); int sheetNo = sheetList.get( count1 ); sheet0 = outputReportWorkbook.getSheet( sheetNo ); WritableCell cell = sheet0.getWritableCell( tempColNo, rowNo ); - // System.out.println( - // "_______________________ count = " - // +count1+"tempColNo = " + tempColNo + " rowNo = " - // + rowNo + " value = " + tempStr ); sheet0.addCell( new Label( tempColNo, rowNo, tempStr, wCellformat ) ); colNo = tempColNo; } - // count1++; }// end of decodelist for loop - // - // OrganisationUnit ouname = ou; for ( int i = levelsList.size() - 1; i >= 0; i-- ) { colNo++; int level = organisationUnitService.getLevelOfOrganisationUnit( ouname ); - // System.out.println( - // "___________i = "+i+" levelsList.get( i ) = " - // +levelsList.get( i ) + " level = "+level + - // " ou = "+ouname.getName() ); if ( levelsList.get( i ) == level ) { sheet0.addCell( new Label( colNo, rowNo, ouname.getName(), wCellformat ) ); - // System.out.println( colNo+" "+ rowNo+" "+ - // ou.getName()+" "+ wCellformat ); } ouname = ouname.getParent(); } @@ -675,10 +595,7 @@ rowCount++; rowNo++; }// end of patientlist - // }// end of oulist - // - }// end of if program not null loop outputReportWorkbook.write(); @@ -686,8 +603,6 @@ fileName = reportFileNameTB.replace( ".xls", "" ); fileName += "_" + selectedOrgUnit.getShortName() + ".xls"; - // System.out.println( "fileName = " + fileName + " outputReportPath = " - // + outputReportPath ); File outputReportFile = new File( outputReportPath ); @@ -696,12 +611,10 @@ outputReportFile.deleteOnExit(); } - // /* * Returns a list which contains the DataElementCodes */ - // public List getChildOrgUnitTree( OrganisationUnit orgUnit ) { List orgUnitTree = new ArrayList(); @@ -717,9 +630,7 @@ return orgUnitTree; }// getChildOrgUnitTree end - // - // public List getDECodes( String fileName ) { List deCodes = new ArrayList(); @@ -782,9 +693,6 @@ return deCodes; } - // - - // public Period getPreviousPeriod( Date sDate ) { Period period = new Period(); @@ -806,9 +714,6 @@ return period; } - // - - // public Period getNextPeriod( Date sDate ) { Period period = new Period(); @@ -830,9 +735,6 @@ return period; } - // - - // public Period getPeriodByMonth( int month, int year, PeriodType periodType ) { int monthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; @@ -867,10 +769,6 @@ return newPeriod; } - // - - // public List getStartingEndingPeriods( String deType, Date sDate, Date eDate ) { @@ -931,5 +829,4 @@ return calendarList; } - // } === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/feedback/action/GenerateFeedbackReportAnalyserFormAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/feedback/action/GenerateFeedbackReportAnalyserFormAction.java 2010-08-28 10:15:38 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/feedback/action/GenerateFeedbackReportAnalyserFormAction.java 2011-01-05 05:31:43 +0000 @@ -1,12 +1,8 @@ package org.hisp.dhis.reports.feedback.action; -import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -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.ReportType; @@ -16,7 +12,6 @@ public class GenerateFeedbackReportAnalyserFormAction implements Action { - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -28,56 +23,10 @@ this.periodService = periodService; } - private OrganisationUnitService organisationUnitService; - - public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) - { - this.organisationUnitService = organisationUnitService; - } - - public OrganisationUnitService getOrganisationUnitService() - { - return organisationUnitService; - } -/* - private ReportService reportService; - - public void setReportService( ReportService reportService ) - { - this.reportService = reportService; - } -*/ - // ------------------------------------------------------------------------- - // Constants - // ------------------------------------------------------------------------- - - private final int ALL = 0; - - public int getALL() - { - return ALL; - } - -// private String raFolderName; - // ------------------------------------------------------------------------- // Properties // ------------------------------------------------------------------------- - private Collection organisationUnits; - - public Collection getOrganisationUnits() - { - return organisationUnits; - } - - private Collection periods = new ArrayList(); - - public Collection getPeriods() - { - return periods; - } - private Collection periodTypes; public Collection getPeriodTypes() @@ -101,19 +50,16 @@ { reportTypeName = ReportType.RT_FEEDBACK; - //raFolderName = reportService.getRAFolderName(); /* Period Info */ periodTypes = periodService.getAllPeriodTypes(); - Iterator alldeIterator = periodTypes.iterator(); while ( alldeIterator.hasNext() ) { PeriodType type = alldeIterator.next(); if (type.getName().equalsIgnoreCase("Monthly") || type.getName().equalsIgnoreCase("quarterly") || type.getName().equalsIgnoreCase("yearly")) { - periods.addAll(periodService.getPeriodsByPeriodType(type)); } else { @@ -123,5 +69,4 @@ return SUCCESS; } - } === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/feedback/action/GenerateFeedbackReportAnalyserResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/feedback/action/GenerateFeedbackReportAnalyserResultAction.java 2010-08-28 10:15:38 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/feedback/action/GenerateFeedbackReportAnalyserResultAction.java 2011-01-05 05:31:43 +0000 @@ -7,17 +7,11 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import jxl.CellType; import jxl.Workbook; @@ -28,25 +22,14 @@ import jxl.format.VerticalAlignment; import jxl.write.Blank; import jxl.write.Label; +import jxl.write.Number; import jxl.write.WritableCell; import jxl.write.WritableCellFormat; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import org.amplecode.quick.StatementManager; -import org.apache.velocity.tools.generic.MathTool; -import org.hisp.dhis.aggregation.AggregationService; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataelement.DataElementCategoryService; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.dataset.DataSetService; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; import org.hisp.dhis.i18n.I18nFormat; -import org.hisp.dhis.indicator.Indicator; -import org.hisp.dhis.indicator.IndicatorService; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; @@ -55,25 +38,13 @@ import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.reports.ReportService; import org.hisp.dhis.reports.Report_in; -import org.hisp.dhis.survey.Survey; -import org.hisp.dhis.survey.SurveyService; -import org.hisp.dhis.surveydatavalue.SurveyDataValue; -import org.hisp.dhis.surveydatavalue.SurveyDataValueService; -import org.hisp.dhis.system.util.MathUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; +import org.hisp.dhis.reports.Report_inDesign; import com.opensymphony.xwork2.Action; public class GenerateFeedbackReportAnalyserResultAction implements Action { - private static final String NULL_REPLACEMENT = "0"; - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -84,13 +55,6 @@ this.statementManager = statementManager; } - private DataSetService dataSetService; - - public void setDataSetService( DataSetService dataSetService ) - { - this.dataSetService = dataSetService; - } - private ReportService reportService; public void setReportService( ReportService reportService ) @@ -105,13 +69,6 @@ this.periodService = periodService; } - private DataElementService dataElementService; - - public void setDataElementService( DataElementService dataElementService ) - { - this.dataElementService = dataElementService; - } - private OrganisationUnitService organisationUnitService; public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) @@ -119,63 +76,6 @@ this.organisationUnitService = organisationUnitService; } - public OrganisationUnitService getOrganisationUnitService() - { - return organisationUnitService; - } - - private AggregationService aggregationService; - - public void setAggregationService( AggregationService aggregationService ) - { - this.aggregationService = aggregationService; - } - - private IndicatorService indicatorService; - - public void setIndicatorService( IndicatorService indicatorService ) - { - this.indicatorService = indicatorService; - } - - private DataValueService dataValueService; - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - private DataElementCategoryService dataElementCategoryOptionComboService; - - public void setDataElementCategoryOptionComboService( DataElementCategoryService dataElementCategoryOptionComboService ) - { - this.dataElementCategoryOptionComboService = dataElementCategoryOptionComboService; - } - - -/* - private DataElementCategoryOptionComboService dataElementCategoryOptionComboService; - - public void setDataElementCategoryOptionComboService( - DataElementCategoryOptionComboService dataElementCategoryOptionComboService ) - { - this.dataElementCategoryOptionComboService = dataElementCategoryOptionComboService; - } -*/ - private SurveyService surveyService; - - public void setSurveyService( SurveyService surveyService ) - { - this.surveyService = surveyService; - } - - private SurveyDataValueService surveyDataValueService; - - public void setSurveyDataValueService( SurveyDataValueService surveyDataValueService ) - { - this.surveyDataValueService = surveyDataValueService; - } - private I18nFormat format; public void setFormat( I18nFormat format ) @@ -186,14 +86,7 @@ // ------------------------------------------------------------------------- // Properties // ------------------------------------------------------------------------- -/* - private PeriodStore periodStore; - public void setPeriodStore( PeriodStore periodStore ) - { - this.periodStore = periodStore; - } -*/ private InputStream inputStream; public InputStream getInputStream() @@ -201,15 +94,6 @@ return inputStream; } - /* - private String contentType; - - public String getContentType() - { - return contentType; - } - */ - private String fileName; public String getFileName() @@ -217,145 +101,13 @@ return fileName; } - /* - private int bufferSize; - - public int getBufferSize() - { - return bufferSize; - } - */ - - private MathTool mathTool; - - public MathTool getMathTool() - { - return mathTool; - } - - // private OrganisationUnit selectedOrgUnit; - - // public OrganisationUnit getSelectedOrgUnit() - // { - // return selectedOrgUnit; - // } - - private List orgUnitList; - - public List getOrgUnitList() - { - return orgUnitList; - } - - private Period selectedPeriod; - - public Period getSelectedPeriod() - { - return selectedPeriod; - } - - private List dataValueList; - - public List getDataValueList() - { - return dataValueList; - } - - private List services; - - public List getServices() - { - return services; - } - - private List slNos; - - public List getSlNos() - { - return slNos; - } - - private SimpleDateFormat simpleDateFormat; - - public SimpleDateFormat getSimpleDateFormat() - { - return simpleDateFormat; - } - - private SimpleDateFormat monthFormat; - - public SimpleDateFormat getMonthFormat() - { - return monthFormat; - } - - private SimpleDateFormat simpleMonthFormat; - - public SimpleDateFormat getSimpleMonthFormat() - { - return simpleMonthFormat; - } - - private SimpleDateFormat yearFormat; - - public SimpleDateFormat getYearFormat() - { - return yearFormat; - } - - private SimpleDateFormat simpleYearFormat; - - public SimpleDateFormat getSimpleYearFormat() - { - return simpleYearFormat; - } - - private List deCodeType; - - private List serviceType; - - private String reportFileNameTB; -/* - public void setReportFileNameTB( String reportFileNameTB ) - { - this.reportFileNameTB = reportFileNameTB; - } -*/ - private String reportModelTB; -/* - public void setReportModelTB( String reportModelTB ) - { - this.reportModelTB = reportModelTB; - } -*/ 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 List orgUnitListCB; - - public void setOrgUnitListCB( List orgUnitListCB ) - { - this.orgUnitListCB = orgUnitListCB; - } -*/ + private int ouIDTB; public void setOuIDTB( int ouIDTB ) @@ -377,13 +129,23 @@ this.aggCB = aggCB; } -// private Hashtable serviceList; - - private List sheetList; - - private List rowList; - - private List colList; + private List orgUnitList; + + private Period selectedPeriod; + + private SimpleDateFormat simpleDateFormat; + + private SimpleDateFormat monthFormat; + + private SimpleDateFormat simpleMonthFormat; + + private SimpleDateFormat yearFormat; + + private SimpleDateFormat simpleYearFormat; + + private String reportFileNameTB; + + private String reportModelTB; private Date sDate; @@ -395,29 +157,10 @@ private PeriodType periodType; - public PeriodType getPeriodType() - { - return periodType; - } - - private List periods; - - public List getPeriods() - { - return periods; - } - -// private List totalOrgUnitsCountList; - private String raFolderName; private List childOrgUnits; - public List getChildOrgUnits() - { - return childOrgUnits; - } - // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -425,26 +168,17 @@ public String execute() throws Exception { - statementManager.initialise(); + // Initialization raFolderName = reportService.getRAFolderName(); - mathTool = new MathTool(); - services = new ArrayList(); - slNos = new ArrayList(); - deCodeType = new ArrayList(); - serviceType = new ArrayList(); -// totalOrgUnitsCountList = new ArrayList(); String deCodesXMLFileName = ""; simpleDateFormat = new SimpleDateFormat( "MMM-yyyy" ); monthFormat = new SimpleDateFormat( "MMMM" ); simpleMonthFormat = new SimpleDateFormat( "MMM" ); yearFormat = new SimpleDateFormat( "yyyy" ); simpleYearFormat = new SimpleDateFormat( "yy" ); - //deCodesXMLFileName = reportList + "DECodes.xml"; - -// String surveyType = ""; //getting Reports Details Report_in selReportObj = reportService.getReport( Integer.parseInt( reportList ) ); @@ -452,77 +186,49 @@ deCodesXMLFileName = selReportObj.getXmlTemplateName(); reportModelTB = selReportObj.getModel(); reportFileNameTB = selReportObj.getExcelTemplateName(); - - System.out.println( reportModelTB + " : " + reportFileNameTB + " : " + deCodesXMLFileName + " : " + ouIDTB ); - - System.out.println( "Report Generation Start Time is : \t" + new Date() ); String parentUnit = ""; - sheetList = new ArrayList(); - rowList = new ArrayList(); - colList = new ArrayList(); - - String inputTemplatePath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator - + "template" + File.separator + reportFileNameTB; - String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator - + "output" + File.separator + UUID.randomUUID().toString() + ".xls"; + OrganisationUnit selOrgUnit = null; + + if( reportModelTB.equalsIgnoreCase( "STATIC" ) ) + { + orgUnitList = new ArrayList(); + selOrgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); + orgUnitList.add( selOrgUnit ); + } + else if( reportModelTB.equalsIgnoreCase( "INDICATOR-AGAINST-PARENT" ) ) + { + selOrgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); + orgUnitList = new ArrayList(); + orgUnitList.add( selOrgUnit ); + } + else if( reportModelTB.equalsIgnoreCase( "INDICATOR-AGAINST-SIBLINGS" ) ) + { + selOrgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); + orgUnitList = new ArrayList(); + orgUnitList.addAll( selOrgUnit.getChildren() ); + Collections.sort( orgUnitList, new OrganisationUnitNameComparator() ); + orgUnitList.add( 0, selOrgUnit ); + } + else if( reportModelTB.equalsIgnoreCase( "INDICATOR-FOR-FEEDBACK" ) ) + { + selOrgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); + orgUnitList = new ArrayList(); + orgUnitList.addAll( selOrgUnit.getChildren() ); + Collections.sort( orgUnitList, new OrganisationUnitNameComparator() ); + orgUnitList.add( 0, selOrgUnit ); + } + + System.out.println( selOrgUnit.getName()+ " : " + selReportObj.getName()+" : Report Generation Start Time is : " + new Date() ); + + String inputTemplatePath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "template" + File.separator + reportFileNameTB; + String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls"; Workbook templateWorkbook = Workbook.getWorkbook( new File( inputTemplatePath ) ); - WritableWorkbook outputReportWorkbook = Workbook - .createWorkbook( new File( outputReportPath ), templateWorkbook ); - - if ( reportModelTB.equalsIgnoreCase( "STATIC" ) ) - { - orgUnitList = new ArrayList(); - OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); - orgUnitList.add( orgUnit ); - - } - - if ( reportModelTB.equalsIgnoreCase( "INDICATOR-AGAINST-PARENT" ) ) - { - OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); -// OrganisationUnit parent = orgUnit.getParent(); - orgUnitList = new ArrayList(); - - Collections.sort( orgUnitList, new OrganisationUnitNameComparator() ); - - // orgUnitList.add( 0, parent ); - - orgUnitList.add( orgUnit ); - - } - else if ( reportModelTB.equalsIgnoreCase( "INDICATOR-AGAINST-SIBLINGS" ) ) - { - OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); - - orgUnitList = new ArrayList(); - - orgUnitList.addAll( orgUnit.getChildren() ); - - Collections.sort( orgUnitList, new OrganisationUnitNameComparator() ); - - orgUnitList.add( 0, orgUnit ); - } - - else if ( reportModelTB.equalsIgnoreCase( "INDICATOR-FOR-FEEDBACK" ) ) - { - OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); - - orgUnitList = new ArrayList(); - - orgUnitList.addAll( orgUnit.getChildren() ); - - Collections.sort( orgUnitList, new OrganisationUnitNameComparator() ); - - orgUnitList.add( 0, orgUnit ); - } - else - { - - } - + WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ), templateWorkbook ); + + selectedPeriod = periodService.getPeriod( availablePeriods ); sDate = format.parseDate( String.valueOf( selectedPeriod.getStartDate() ) ); @@ -532,12 +238,10 @@ simpleDateFormat = new SimpleDateFormat( "MMM-yyyy" ); // Getting DataValues - dataValueList = new ArrayList(); - List deCodesList = getDECodes( deCodesXMLFileName ); + List reportDesignList = reportService.getReportDesign( deCodesXMLFileName ); Iterator it = orgUnitList.iterator(); int orgUnitCount = 0; - int orgUnitGroupCount = 0; int rowCounter = 0; @@ -565,27 +269,21 @@ if ( children == 0 ) { - // int quarterPeriod = 0; - OrganisationUnit currentOrgUnit = (OrganisationUnit) it.next(); - - Iterator it1 = deCodesList.iterator(); int count1 = 0; - while ( it1.hasNext() ) + Iterator reportDesignIterator = reportDesignList.iterator(); + while ( reportDesignIterator.hasNext() ) { - String deCodeString = (String) it1.next(); + Report_inDesign report_inDesign = (Report_inDesign) reportDesignIterator.next(); - String deType = (String) deCodeType.get( count1 ); -// String sType = (String) serviceType.get( count1 ); -// int count = 0; -// double sum = 0.0; -// int flag1 = 0; + String deCodeString = report_inDesign.getExpression(); + String deType = report_inDesign.getPtype(); String tempStr = ""; Calendar tempStartDate = Calendar.getInstance(); Calendar tempEndDate = Calendar.getInstance(); - List calendarList = new ArrayList( getStartingEndingPeriods( deType ) ); + List calendarList = new ArrayList( reportService.getStartingEndingPeriods( deType, selectedPeriod ) ); if ( calendarList == null || calendarList.isEmpty() ) { tempStartDate.setTime( selectedPeriod.getStartDate() ); @@ -598,66 +296,30 @@ tempEndDate = calendarList.get( 1 ); } - if ( deCodeString.equalsIgnoreCase( "FACILITY" ) ) + if( deCodeString.equalsIgnoreCase( "FACILITY" ) ) { tempStr = ""; - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYP" ) ) + else if( deCodeString.equalsIgnoreCase( "FACILITYP" ) ) { tempStr = currentOrgUnit.getName(); - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPP" ) ) - { - OrganisationUnit orgUnitP = new OrganisationUnit(); - - orgUnitP = currentOrgUnit.getParent(); - - tempStr = orgUnitP.getName(); - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPPP" ) ) - { - OrganisationUnit orgUnitP = new OrganisationUnit(); - - OrganisationUnit orgUnitPP = new OrganisationUnit(); - - orgUnitP = currentOrgUnit.getParent(); - - orgUnitPP = orgUnitP.getParent(); - - tempStr = orgUnitPP.getName(); - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPPPP" ) ) - { - OrganisationUnit orgUnitP = new OrganisationUnit(); - - OrganisationUnit orgUnitPP = new OrganisationUnit(); - - OrganisationUnit orgUnitPPP = new OrganisationUnit(); - - orgUnitP = currentOrgUnit.getParent(); - - orgUnitPP = orgUnitP.getParent(); - - orgUnitPPP = orgUnitPP.getParent(); - - tempStr = orgUnitPPP.getName(); - - } - - else if ( deCodeString.equalsIgnoreCase( "PERIOD-MONTH" ) ) + } + else if( deCodeString.equalsIgnoreCase( "FACILITYPP" ) ) + { + tempStr = currentOrgUnit.getParent().getName(); + } + else if( deCodeString.equalsIgnoreCase( "FACILITYPPP" ) ) + { + tempStr = currentOrgUnit.getParent().getParent().getName(); + } + else if( deCodeString.equalsIgnoreCase( "FACILITYPPPP" ) ) + { + tempStr = currentOrgUnit.getParent().getParent().getParent().getName(); + } + else if( deCodeString.equalsIgnoreCase( "PERIOD-MONTH" ) ) { tempStr = monthFormat.format( sDate ); - } - else if ( deCodeString.equalsIgnoreCase( "YEAR-FROMTO" ) ) { @@ -716,10 +378,16 @@ wCellformat.setWrap( true ); wCellformat.setAlignment( Alignment.CENTRE ); + /* int tempRowNo = rowList.get( count1 ); int tempColNo = colList.get( count1 ); int sheetNo = sheetList.get( count1 ) + orgUnitGroupCount; WritableSheet sheet0 = outputReportWorkbook.getSheet( sheetNo ); + */ + int tempRowNo = report_inDesign.getRowno(); + int tempColNo = report_inDesign.getColno(); + int sheetNo = report_inDesign.getSheetno(); + WritableSheet sheet0 = outputReportWorkbook.getSheet( sheetNo ); if ( tempStr == null || tempStr.equals( " " ) ) { @@ -733,40 +401,33 @@ } - // --------------------------------------------------------------------------------------------------- + // --------------------------------------------------------------------- // Feedback without orgunit END - // --------------------------------------------------------------------------------------------------- + // --------------------------------------------------------------------- - // --------------------------------------------------------------------------------------------------- + // --------------------------------------------------------------------- // All other reports START - // --------------------------------------------------------------------------------------------------- + // --------------------------------------------------------------------- while ( it.hasNext() && children != 0 ) { - - // int quarterPeriod = 0; - OrganisationUnit currentOrgUnit = (OrganisationUnit) it.next(); - Iterator it1 = deCodesList.iterator(); int count1 = 0; - while ( it1.hasNext() ) + + Iterator reportDesignIterator = reportDesignList.iterator(); + while ( reportDesignIterator.hasNext() && children != 0 ) { - String deCodeString = (String) it1.next(); - - //System.out.println(deCodeString); - - String deType = (String) deCodeType.get( count1 ); - String sType = (String) serviceType.get( count1 ); - //System.out.println(sType); -// int count = 0; -// double sum = 0.0; -// int flag1 = 0; + Report_inDesign report_inDesign = (Report_inDesign) reportDesignIterator.next(); + + String deType = report_inDesign.getPtype(); + String sType = report_inDesign.getStype(); + String deCodeString = report_inDesign.getExpression(); String tempStr = ""; Calendar tempStartDate = Calendar.getInstance(); Calendar tempEndDate = Calendar.getInstance(); - List calendarList = new ArrayList( getStartingEndingPeriods( deType ) ); + List calendarList = new ArrayList( reportService.getStartingEndingPeriods( deType, selectedPeriod ) ); if ( calendarList == null || calendarList.isEmpty() ) { tempStartDate.setTime( selectedPeriod.getStartDate() ); @@ -782,7 +443,6 @@ if ( deCodeString.equalsIgnoreCase( "FACILITY" ) ) { tempStr = currentOrgUnit.getName(); - } else if ( deCodeString.equalsIgnoreCase( "FACILITY-NOREPEAT" ) ) { @@ -791,88 +451,47 @@ else if ( deCodeString.equalsIgnoreCase( "FACILITYP" ) ) { tempStr = currentOrgUnit.getParent().getName(); - } - else if ( deCodeString.equalsIgnoreCase( "FACILITYPP" ) ) { - OrganisationUnit orgUnitP = new OrganisationUnit(); - - orgUnitP = currentOrgUnit.getParent(); - - tempStr = orgUnitP.getParent().getName(); - + tempStr = currentOrgUnit.getParent().getParent().getName(); } - else if ( deCodeString.equalsIgnoreCase( "FACILITYPPP" ) ) { - OrganisationUnit orgUnitP = new OrganisationUnit(); - - OrganisationUnit orgUnitPP = new OrganisationUnit(); - - orgUnitP = currentOrgUnit.getParent(); - - orgUnitPP = orgUnitP.getParent(); - - tempStr = orgUnitPP.getParent().getName(); - + tempStr = currentOrgUnit.getParent().getParent().getParent().getName(); } - else if ( deCodeString.equalsIgnoreCase( "FACILITYPPPP" ) ) { - OrganisationUnit orgUnitP = new OrganisationUnit(); - - OrganisationUnit orgUnitPP = new OrganisationUnit(); - - OrganisationUnit orgUnitPPP = new OrganisationUnit(); - - orgUnitP = currentOrgUnit.getParent(); - - orgUnitPP = orgUnitP.getParent(); - - orgUnitPPP = orgUnitPP.getParent(); - - tempStr = orgUnitPPP.getParent().getName(); - + tempStr = currentOrgUnit.getParent().getParent().getParent().getParent().getName(); } - else if ( deCodeString.equalsIgnoreCase( "PERIOD" ) || deCodeString.equalsIgnoreCase( "PERIOD-NOREPEAT" ) ) { tempStr = simpleDateFormat.format( sDate ); - } 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" ) ) { @@ -884,7 +503,6 @@ { tempStr = "Quarter I"; } - else if ( startMonth.equalsIgnoreCase( "July" ) ) { tempStr = "Quarter II"; @@ -893,16 +511,11 @@ { tempStr = "Quarter III"; } - else { tempStr = "Quarter IV"; - - // quarterPeriod = 1; - } } - else if ( deCodeString.equalsIgnoreCase( "SIMPLE-QUARTER" ) ) { String startMonth = ""; @@ -913,7 +526,6 @@ { tempStr = "Q1"; } - else if ( startMonth.equalsIgnoreCase( "July" ) ) { tempStr = "Q2"; @@ -922,16 +534,11 @@ { tempStr = "Q3"; } - else { tempStr = "Q4"; - - // quarterPeriod = 1; - } } - else if ( deCodeString.equalsIgnoreCase( "QUARTER-MONTHS-SHORT" ) ) { String startMonth = ""; @@ -942,7 +549,6 @@ { tempStr = "Apr - Jun"; } - else if ( startMonth.equalsIgnoreCase( "July" ) ) { tempStr = "Jul - Sep"; @@ -951,16 +557,11 @@ { tempStr = "Oct - Dec"; } - else { tempStr = "Jan - Mar"; - - // quarterPeriod = 1; - } } - else if ( deCodeString.equalsIgnoreCase( "QUARTER-MONTHS" ) ) { String startMonth = ""; @@ -971,7 +572,6 @@ { tempStr = "April - June"; } - else if ( startMonth.equalsIgnoreCase( "July" ) ) { tempStr = "July - September"; @@ -980,16 +580,11 @@ { tempStr = "October - December"; } - else { tempStr = "January - March"; - - // quarterPeriod = 1; - } } - else if ( deCodeString.equalsIgnoreCase( "QUARTER-START-SHORT" ) ) { String startMonth = ""; @@ -1000,7 +595,6 @@ { tempStr = "Apr"; } - else if ( startMonth.equalsIgnoreCase( "July" ) ) { tempStr = "Jul"; @@ -1009,16 +603,11 @@ { tempStr = "Oct"; } - else { tempStr = "Jan"; - - // quarterPeriod = 1; - } } - else if ( deCodeString.equalsIgnoreCase( "QUARTER-START" ) ) { String startMonth = ""; @@ -1029,7 +618,6 @@ { tempStr = "April"; } - else if ( startMonth.equalsIgnoreCase( "July" ) ) { tempStr = "July"; @@ -1038,16 +626,11 @@ { tempStr = "October"; } - else { tempStr = "January"; - - // quarterPeriod = 1; - } } - else if ( deCodeString.equalsIgnoreCase( "QUARTER-END-SHORT" ) ) { String endMonth = ""; @@ -1058,7 +641,6 @@ { tempStr = "Jun"; } - else if ( endMonth.equalsIgnoreCase( "September" ) ) { tempStr = "Sep"; @@ -1067,16 +649,11 @@ { tempStr = "Dec"; } - else { tempStr = "Mar"; - - //quarterPeriod = 1; - } } - else if ( deCodeString.equalsIgnoreCase( "QUARTER-END" ) ) { String endMonth = ""; @@ -1087,7 +664,6 @@ { tempStr = "June"; } - else if ( endMonth.equalsIgnoreCase( "September" ) ) { tempStr = "September"; @@ -1096,16 +672,11 @@ { tempStr = "December"; } - else { tempStr = "March"; - - //quarterPeriod = 1; - } } - else if ( deCodeString.equalsIgnoreCase( "PERIOD-YEAR" ) ) { sDateTemp = sDate; @@ -1124,7 +695,6 @@ { sDateTemp = sDate; } - else { if ( (startMonth.equalsIgnoreCase( "January" ) || startMonth.equalsIgnoreCase( "February" ) || startMonth @@ -1140,7 +710,6 @@ tempStr = yearFormat.format( sDateTemp ); } - else if ( deCodeString.equalsIgnoreCase( "SIMPLE-YEAR" ) ) { sDateTemp = sDate; @@ -1159,7 +728,6 @@ { sDateTemp = sDate; } - else { if ( (startMonth.equalsIgnoreCase( "January" ) || startMonth.equalsIgnoreCase( "February" ) || startMonth @@ -1175,10 +743,8 @@ tempStr = simpleYearFormat.format( sDateTemp ); } - else if ( deCodeString.equalsIgnoreCase( "YEAR-END" ) ) { - sDateTemp = sDate; Calendar tempQuarterYear = Calendar.getInstance(); @@ -1275,7 +841,6 @@ tempStr = startYear + " - " + endYear; } - else if ( deCodeString.equalsIgnoreCase( "SLNO" ) ) { tempStr = "" + (orgUnitCount + 1); @@ -1288,68 +853,77 @@ { rowCounter += 1; - if ( sType.equalsIgnoreCase( "dataelement" ) ) + if( sType.equalsIgnoreCase( "dataelement" ) ) { if ( aggCB == null ) { - tempStr = getIndividualResultDataValue( deCodeString, tempStartDate.getTime(), tempEndDate - .getTime(), currentOrgUnit ); + //tempStr = getIndividualResultDataValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit ); + tempStr = reportService.getIndividualResultDataValue(deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit, reportModelTB ); } else { - tempStr = getResultDataValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), - currentOrgUnit ); + //tempStr = getResultDataValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit ); + tempStr = reportService.getResultDataValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit, reportModelTB ); } } else if ( sType.equalsIgnoreCase( "indicator-parent" ) ) { if ( aggCB == null ) { - tempStr = getIndividualResultIndicatorValue( deCodeString, tempStartDate.getTime(), - tempEndDate.getTime(), currentOrgUnit.getParent() ); + //tempStr = getIndividualResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit.getParent() ); + tempStr = reportService.getIndividualResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit.getParent() ); } else { - tempStr = getResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate - .getTime(), currentOrgUnit.getParent() ); + //tempStr = getResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit.getParent() ); + tempStr = reportService.getResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit.getParent() ); } } else if ( sType.equalsIgnoreCase( "survey" ) ) { - tempStr = getResultSurveyValue( deCodeString, currentOrgUnit ); + //tempStr = getResultSurveyValue( deCodeString, currentOrgUnit ); + tempStr = reportService.getResultSurveyValue( deCodeString, currentOrgUnit ); } - else if ( sType.equalsIgnoreCase( "dataelement-boolean" ) ) { if ( aggCB == null ) { - tempStr = getBooleanDataValue( deCodeString, tempStartDate.getTime(), - tempEndDate.getTime(), currentOrgUnit ); + //tempStr = getBooleanDataValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit ); + tempStr = reportService.getBooleanDataValue(deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit, reportModelTB); } else { - tempStr = getBooleanDataValue( deCodeString, tempStartDate.getTime(), - tempEndDate.getTime(), currentOrgUnit ); + //tempStr = getBooleanDataValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit ); + tempStr = reportService.getBooleanDataValue(deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit, reportModelTB); } } else { if ( aggCB == null ) { - tempStr = getIndividualResultIndicatorValue( deCodeString, tempStartDate.getTime(), - tempEndDate.getTime(), currentOrgUnit ); + //tempStr = getIndividualResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit ); + tempStr = reportService.getIndividualResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit ); } else { - tempStr = getResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate - .getTime(), currentOrgUnit ); + //tempStr = getResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit ); + tempStr = reportService.getResultIndicatorValue( deCodeString, tempStartDate.getTime(), tempEndDate.getTime(), currentOrgUnit ); } } } + + int tempRowNo = report_inDesign.getRowno(); + int tempColNo = report_inDesign.getColno(); + int sheetNo = report_inDesign.getSheetno(); + WritableSheet sheet0 = outputReportWorkbook.getSheet( sheetNo ); + + /* int tempRowNo = rowList.get( count1 ); int tempColNo = colList.get( count1 ); int sheetNo = sheetList.get( count1 ) + orgUnitGroupCount; WritableSheet sheet0 = outputReportWorkbook.getSheet( sheetNo ); + */ + if ( tempStr == null || tempStr.equals( " " ) ) { tempColNo += orgUnitCount; @@ -1363,58 +937,8 @@ } else { - - if ( reportModelTB.equalsIgnoreCase( "STATIC" ) ) + if ( reportModelTB.equalsIgnoreCase( "STATIC" ) || reportModelTB.equalsIgnoreCase( "INDICATOR-AGAINST-PARENT" ) ) { - if ( deCodeString.equalsIgnoreCase( "FACILITYP" ) ) - { - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPP" ) ) - { - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPPP" ) ) - { - - } - - else if ( 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" ) ) - { - - } - else - { - // tempColNo += - // orgUnitCount; - } - WritableCell cell = sheet0.getWritableCell( tempColNo, tempRowNo ); CellFormat cellFormat = cell.getCellFormat(); @@ -1434,101 +958,15 @@ sheet0.addCell( new Label( tempColNo, tempRowNo, tempStr, wCellformat ) ); } } - - else if ( reportModelTB.equalsIgnoreCase( "INDICATOR-AGAINST-PARENT" ) ) - { - if ( deCodeString.equalsIgnoreCase( "FACILITYP" ) ) - { - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPP" ) ) - { - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPPP" ) ) - { - - } - - else if ( 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" ) ) - { - - } - else - { - // tempColNo += - // (orgUnitCount * 2); - } - - WritableCell cell = sheet0.getWritableCell( tempColNo, tempRowNo ); - - CellFormat cellFormat = cell.getCellFormat(); - WritableCellFormat wCellformat = new WritableCellFormat(); - wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN ); - wCellformat.setAlignment( Alignment.CENTRE ); - - if ( cell.getType() == CellType.LABEL ) - { - Label l = (Label) cell; - l.setString( tempStr ); - l.setCellFormat( cellFormat ); - } - else - { - sheet0.addCell( new Label( tempColNo, tempRowNo, tempStr, wCellformat ) ); - } - } - else if ( reportModelTB.equalsIgnoreCase( "INDICATOR-AGAINST-SIBLINGS" ) || reportModelTB.equalsIgnoreCase( "INDICATOR-FOR-FEEDBACK" ) ) { - if ( deCodeString.equalsIgnoreCase( "FACILITYP" ) ) - { - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPP" ) ) - { - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPPP" ) ) - { - - } - - else if ( deCodeString.equalsIgnoreCase( "FACILITYPPPP" ) ) - { - - } - + 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" ) @@ -1558,46 +996,38 @@ } WritableCell cell = sheet0.getWritableCell( tempColNo, tempRowNo ); - + CellFormat cellFormat = cell.getCellFormat(); WritableCellFormat wCellformat = new WritableCellFormat(); - wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN ); wCellformat.setWrap( true ); wCellformat.setAlignment( Alignment.CENTRE ); wCellformat.setVerticalAlignment( VerticalAlignment.CENTRE ); - + if ( cell.getType() == CellType.LABEL ) { Label l = (Label) cell; l.setString( tempStr ); l.setCellFormat( cellFormat ); - } + } else { - sheet0.addCell( new Label( tempColNo, tempRowNo, tempStr, wCellformat ) ); + try + { + sheet0.addCell( new Number( tempColNo, tempRowNo, Double.parseDouble( tempStr ), wCellformat ) ); + } + catch( Exception e ) + { + sheet0.addCell( new Label( tempColNo, tempRowNo, tempStr, wCellformat ) ); + } } } - else - { - - } - - // } } count1++; }// inner while loop end orgUnitCount++; }// outer while loop end - /* - * ActionContext ctx = ActionContext.getContext(); HttpServletResponse - * res = (HttpServletResponse) ctx.get( - * ServletActionContext.HTTP_RESPONSE ); - * - * res.setContentType("application/vnd.ms-excel"); - */ - outputReportWorkbook.write(); outputReportWorkbook.close(); @@ -1607,7 +1037,7 @@ File outputReportFile = new File( outputReportPath ); inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) ); - System.out.println( "Report Generation End Time is : \t" + new Date() ); + System.out.println( selOrgUnit.getName()+ " : " + selReportObj.getName()+" : Report Generation Start Time is : " + new Date() ); outputReportFile.deleteOnExit(); @@ -1616,1065 +1046,6 @@ return SUCCESS; } - public List getStartingEndingPeriods( String deType ) - { - - List calendarList = new ArrayList(); - - Calendar tempStartDate = Calendar.getInstance(); - Calendar tempEndDate = Calendar.getInstance(); - - Period previousPeriod = new Period(); - previousPeriod = getPreviousPeriod(); - - if ( deType.equalsIgnoreCase( "ccmcy" ) ) - { - tempStartDate.setTime( selectedPeriod.getStartDate() ); - if ( tempStartDate.get( Calendar.MONTH ) < Calendar.APRIL ) - { - tempStartDate.roll( Calendar.YEAR, -1 ); - } - tempStartDate.set( Calendar.MONTH, Calendar.APRIL ); - tempEndDate.setTime( selectedPeriod.getEndDate() ); - // //System.out.println("CCMCY : "+ String.valueOf( - // tempStartDate.getTime()) +" ------ "+String.valueOf( - // tempEndDate.getTime())); - } - else if ( deType.equalsIgnoreCase( "cpmcy" ) ) - { - tempStartDate.setTime( previousPeriod.getStartDate() ); - if ( tempStartDate.get( Calendar.MONTH ) < Calendar.APRIL ) - { - tempStartDate.roll( Calendar.YEAR, -1 ); - } - tempStartDate.set( Calendar.MONTH, Calendar.APRIL ); - tempEndDate.setTime( previousPeriod.getEndDate() ); - } - else if ( deType.equalsIgnoreCase( "cmpy" ) ) - { - tempStartDate.setTime( selectedPeriod.getStartDate() ); - tempEndDate.setTime( selectedPeriod.getEndDate() ); - - tempStartDate.roll( Calendar.YEAR, -1 ); - tempEndDate.roll( Calendar.YEAR, -1 ); - } - else if ( deType.equalsIgnoreCase( "ccmpy" ) ) - { - tempStartDate.setTime( selectedPeriod.getStartDate() ); - tempEndDate.setTime( selectedPeriod.getEndDate() ); - - tempStartDate.roll( Calendar.YEAR, -1 ); - tempEndDate.roll( Calendar.YEAR, -1 ); - - if ( tempStartDate.get( Calendar.MONTH ) < Calendar.APRIL ) - { - tempStartDate.roll( Calendar.YEAR, -1 ); - } - tempStartDate.set( Calendar.MONTH, Calendar.APRIL ); - - } - else if ( deType.equalsIgnoreCase( "pmcy" ) ) - { - tempStartDate.setTime( previousPeriod.getStartDate() ); - tempEndDate.setTime( previousPeriod.getEndDate() ); - - } - - else - { - - tempStartDate.setTime( selectedPeriod.getStartDate() ); - tempEndDate.setTime( selectedPeriod.getEndDate() ); - } - - // //System.out.print(deType+" -- "); - calendarList.add( tempStartDate ); - calendarList.add( tempEndDate ); - - return calendarList; - } - - public Period getPreviousPeriod() - { - Period period = new Period(); - Calendar tempDate = Calendar.getInstance(); - tempDate.setTime( selectedPeriod.getStartDate() ); - if ( tempDate.get( Calendar.MONTH ) == Calendar.JANUARY ) - { - tempDate.set( Calendar.MONTH, Calendar.DECEMBER ); - tempDate.roll( Calendar.YEAR, -1 ); - - } - else - { - tempDate.roll( Calendar.MONTH, -1 ); - } - PeriodType periodType = getPeriodTypeObject( "monthly" ); - period = getPeriodByMonth( tempDate.get( Calendar.MONTH ), tempDate.get( Calendar.YEAR ), periodType ); - - return period; - } - - public Period getPeriodByMonth( int month, int year, PeriodType periodType ) - { - int monthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - - Calendar cal = Calendar.getInstance(); - cal.set( year, month, 1, 0, 0, 0 ); - Date firstDay = new Date( cal.getTimeInMillis() ); - - if ( periodType.getName().equals( "Monthly" ) ) - { - cal.set( year, month, 1, 0, 0, 0 ); - if ( year % 4 == 0 ) - { - cal.set( Calendar.DAY_OF_MONTH, monthDays[month] + 1 ); - } - else - { - cal.set( Calendar.DAY_OF_MONTH, monthDays[month] ); - } - } - else if ( periodType.getName().equals( "Yearly" ) ) - { - cal.set( year, Calendar.DECEMBER, 31 ); - } - - Date lastDay = new Date( cal.getTimeInMillis() ); - - Period newPeriod = new Period(); - - newPeriod.setStartDate( firstDay ); - newPeriod.setEndDate( lastDay ); - newPeriod.setPeriodType( periodType ); - - return newPeriod; - } - - public PeriodType getPeriodTypeObject( String periodTypeName ) - { - Collection periodTypes = periodService.getAllPeriodTypes(); - PeriodType periodType = null; - Iterator iter = periodTypes.iterator(); - while ( iter.hasNext() ) - { - PeriodType tempPeriodType = (PeriodType) iter.next(); - if ( tempPeriodType.getName().toLowerCase().trim().equals( periodTypeName ) ) - { - periodType = tempPeriodType; - - break; - } - } - if ( periodType == null ) - { - //System.out.println( "No Such PeriodType" ); - return null; - } - return periodType; - } - - public List getDECodes( String fileName ) - { - List deCodes = new ArrayList(); - String path = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + raFolderName - + File.separator + fileName; - try - { - String newpath = System.getenv( "DHIS2_HOME" ); - if ( newpath != null ) - { - path = newpath + File.separator + raFolderName + File.separator + fileName; - } - } - catch ( NullPointerException npe ) - { - // do nothing, but we might be using this somewhere without - // USER_HOME set, which will throw a NPE - } - - 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 user home" ); - return null; - } - - NodeList listOfDECodes = doc.getElementsByTagName( "de-code" ); - int totalDEcodes = listOfDECodes.getLength(); - - for ( int s = 0; s < totalDEcodes; s++ ) - { - Element deCodeElement = (Element) listOfDECodes.item( s ); - NodeList textDECodeList = deCodeElement.getChildNodes(); - deCodes.add( ((Node) textDECodeList.item( 0 )).getNodeValue().trim() ); - serviceType.add( deCodeElement.getAttribute( "stype" ) ); - deCodeType.add( deCodeElement.getAttribute( "type" ) ); - sheetList.add( new Integer( deCodeElement.getAttribute( "sheetno" ) ) ); - rowList.add( new Integer( deCodeElement.getAttribute( "rowno" ) ) ); - colList.add( new Integer( deCodeElement.getAttribute( "colno" ) ) ); - - }// 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 deCodes; - }// getDECodes end - - /* - * Returns the PeriodType Object for selected DataElement, If no PeriodType - * is found then by default returns Monthly Period type - */ - public PeriodType getDataElementPeriodType( DataElement de ) - { - List dataSetList = new ArrayList( dataSetService.getAllDataSets() ); - Iterator it = dataSetList.iterator(); - while ( it.hasNext() ) - { - DataSet ds = (DataSet) it.next(); - List dataElementList = new ArrayList( ds.getDataElements() ); - if ( dataElementList.contains( de ) ) - { - return ds.getPeriodType(); - } - } - - return null; - - } // getDataElementPeriodType end - - /** - * Converts an expression on the form
- * [34] + [23], where the numbers are IDs of DataElements, to the form
- * 200 + 450, where the numbers are the values of the DataValues registered - * for the Period and source. - * - * @return The generated expression - */ - private String getResultDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit ) - { - try - { - // //System.out.println( "expression : " + formula + " ***** " + - // String.valueOf( startDate ) + " **** " - // + String.valueOf( endDate ) ); - - int deFlag1 = 0; - // int deFlag2 = 0; - Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); - - Matcher matcher = pattern.matcher( formula ); - 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 ); - - DataElement dataElement = dataElementService.getDataElement( dataElementId ); - DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService - .getDataElementCategoryOptionCombo( optionComboId ); - - if ( dataElement == null || optionCombo == null ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - } - if ( dataElement.getType().equalsIgnoreCase( "int" ) ) - { - Double aggregatedValue = aggregationService.getAggregatedDataValue( dataElement, optionCombo, - startDate, endDate, organisationUnit ); - if ( aggregatedValue == null ) - { - replaceString = NULL_REPLACEMENT; - } - else - { - replaceString = String.valueOf( aggregatedValue ); - - // deFlag2 = 1; - } - - } - else - { - deFlag1 = 1; - PeriodType dePeriodType = getDataElementPeriodType( dataElement ); - List periodList = new ArrayList( periodService.getIntersectingPeriodsByPeriodType( - dePeriodType, startDate, endDate ) ); - Period tempPeriod = new Period(); - if ( periodList == null || periodList.isEmpty() ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - } - else - { - tempPeriod = (Period) periodList.get( 0 ); - } - - DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, tempPeriod, - optionCombo ); - - if ( dataValue != null ) - { - // Works for both text and boolean data types - - replaceString = dataValue.getValue(); - } - - else - replaceString = ""; - - if ( replaceString == null ) - replaceString = ""; - } - matcher.appendReplacement( buffer, replaceString ); - - resultValue = replaceString; - } - - matcher.appendTail( buffer ); - - if ( deFlag1 == 0 ) - { - - double d = 0.0; - try - { - d = MathUtils.calculateExpression( buffer.toString() ); - } - catch ( Exception e ) - { - d = 0.0; - resultValue = ""; - } - if ( d == -1 ) - { - d = 0.0; - resultValue = ""; - } - else - { - - // This is to display financial data as it is like 2.1476838 - resultValue = "" + d; - - // These lines are to display financial data that do not - // have decimals - d = d * 10; - - if ( d % 10 == 0 ) - { - resultValue = "" + (int) d / 10; - } - - d = d / 10; - - // These line are to display non financial data that do not - // require decimals - if ( !(reportModelTB.equalsIgnoreCase( "STATIC-FINANCIAL" )) ) - resultValue = "" + (int) d; - - // if ( resultValue.equalsIgnoreCase( "0" ) ) - // { - // resultValue = ""; - // } - } - - } - else - { - resultValue = buffer.toString(); - } - - if ( resultValue.equalsIgnoreCase( "" ) ) - resultValue = " "; - - return resultValue; - } - catch ( NumberFormatException ex ) - { - throw new RuntimeException( "Illegal DataElement id", ex ); - } - } - - private String getIndividualResultDataValue( String formula, Date startDate, Date endDate, - OrganisationUnit organisationUnit ) - { - try - { - int deFlag1 = 0; - // int deFlag2 = 0; - Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); - - Matcher matcher = pattern.matcher( formula ); - StringBuffer buffer = new StringBuffer(); - - String resultValue = ""; - boolean valueDoesNotExist = true; - - 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 ); - - DataElement dataElement = dataElementService.getDataElement( dataElementId ); - DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService - .getDataElementCategoryOptionCombo( optionComboId ); - - if ( dataElement == null || optionCombo == null ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - } - if ( dataElement.getType().equalsIgnoreCase( "int" ) ) - { - - PeriodType dePeriodType = getDataElementPeriodType( dataElement ); - List periodList = new ArrayList( periodService.getIntersectingPeriodsByPeriodType( - dePeriodType, startDate, endDate ) ); - - if ( periodList == null || periodList.isEmpty() ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - } - else - { - - double aggregatedValue = 0.0; - for ( Period tempPeriod : periodList ) - { - DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, - tempPeriod, optionCombo ); - - if ( dataValue != null ) - { - aggregatedValue += Double.parseDouble( dataValue.getValue() ); - - valueDoesNotExist = false; - } - } - - replaceString = String.valueOf( aggregatedValue ); - - // deFlag2 = 1; - } - - } - else - { - deFlag1 = 1; - PeriodType dePeriodType = getDataElementPeriodType( dataElement ); - List periodList = new ArrayList( periodService.getIntersectingPeriodsByPeriodType( - dePeriodType, startDate, endDate ) ); - Period tempPeriod = new Period(); - if ( periodList == null || periodList.isEmpty() ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - } - else - { - tempPeriod = (Period) periodList.get( 0 ); - } - - DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, tempPeriod, - optionCombo ); - - if ( dataValue != null ) - { - // Works for both text and boolean data types - - replaceString = dataValue.getValue(); - valueDoesNotExist = false; - } - - else - replaceString = ""; - - if ( replaceString == null ) - replaceString = ""; - } - matcher.appendReplacement( buffer, replaceString ); - - resultValue = replaceString; - } - - matcher.appendTail( buffer ); - - if ( deFlag1 == 0 ) - { - double d = 0.0; - try - { - d = MathUtils.calculateExpression( buffer.toString() ); - } - catch ( Exception e ) - { - d = 0.0; - - resultValue = ""; - } - if ( d == -1 ) - { - d = 0.0; - - resultValue = ""; - } - else - { - // This is to display financial data as it is like 2.1476838 - resultValue = "" + d; - - // These lines are to display financial data that do not - // have decimals - d = d * 10; - - if ( d % 10 == 0 ) - { - resultValue = "" + (int) d / 10; - } - - d = d / 10; - - // These line are to display non financial data that do not - // require decimals - if ( !(reportModelTB.equalsIgnoreCase( "STATIC-FINANCIAL" )) ) - resultValue = "" + (int) d; - - // if ( resultValue.equalsIgnoreCase( "0" ) ) - // { - // resultValue = ""; - // } - } - } - else - { - resultValue = buffer.toString(); - } - - if ( valueDoesNotExist ) - resultValue = " "; - - if ( resultValue.equalsIgnoreCase( "" ) ) - resultValue = " "; - - return resultValue; - } - catch ( NumberFormatException ex ) - { - throw new RuntimeException( "Illegal DataElement id", ex ); - } - } - - private String getBooleanDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit ) - { - try - { - int deFlag1 = 0; - int deFlag2 = 0; - Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); - - Matcher matcher = pattern.matcher( formula ); - StringBuffer buffer = new StringBuffer(); - - while ( matcher.find() ) - { - String replaceString = matcher.group(); - - replaceString = replaceString.replaceAll( "[\\[\\]]", "" ); - 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 ); - - DataElement dataElement = dataElementService.getDataElement( dataElementId ); - DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService - .getDataElementCategoryOptionCombo( optionComboId ); - - if ( dataElement == null || optionCombo == null ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - } - - if ( dataElement.getType().equalsIgnoreCase( "bool" ) ) - { - deFlag1 = 1; - PeriodType dePeriodType = getDataElementPeriodType( dataElement ); - List periodList = new ArrayList( periodService.getIntersectingPeriodsByPeriodType( - dePeriodType, startDate, endDate ) ); - Period tempPeriod = new Period(); - if ( periodList == null || periodList.isEmpty() ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - } - else - { - tempPeriod = (Period) periodList.get( 0 ); - } - - DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, tempPeriod, - optionCombo ); - - if ( dataValue != null ) - { - // Works for both text and boolean data types - - if ( dataValue.getValue().equalsIgnoreCase( "true" ) ) - { - replaceString = "Yes"; - } - else if ( dataValue.getValue().equalsIgnoreCase( "false" ) ) - { - replaceString = "No"; - } - else - { - replaceString = dataValue.getValue(); - } - } - - else - { - replaceString = ""; - } - - } - else - { - Double aggregatedValue = aggregationService.getAggregatedDataValue( dataElement, optionCombo, - startDate, endDate, organisationUnit ); - if ( aggregatedValue == null ) - { - replaceString = NULL_REPLACEMENT; - } - else - { - replaceString = String.valueOf( aggregatedValue ); - - deFlag2 = 1; - } - } - matcher.appendReplacement( buffer, replaceString ); - } - - matcher.appendTail( buffer ); - - String resultValue = ""; - if ( deFlag1 == 0 ) - { - double d = 0.0; - try - { - d = MathUtils.calculateExpression( buffer.toString() ); - } - catch ( Exception e ) - { - d = 0.0; - } - if ( d == -1 ) - { - d = 0.0; - } - else - { - d = Math.round( d * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 ); - resultValue = "" + (int) d; - } - - if ( deFlag2 == 0 ) - { - resultValue = " "; - } - } - else - { - resultValue = buffer.toString(); - } - return resultValue; - } - catch ( NumberFormatException ex ) - { - throw new RuntimeException( "Illegal DataElement id", ex ); - } - } - - private String getResultIndicatorValue( String formula, Date startDate, Date endDate, - OrganisationUnit organisationUnit ) - { - try - { - - int deFlag1 = 0; - int deFlag2 = 0; - Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); - - Matcher matcher = pattern.matcher( formula ); - StringBuffer buffer = new StringBuffer(); - - while ( matcher.find() ) - { - String replaceString = matcher.group(); - - replaceString = replaceString.replaceAll( "[\\[\\]]", "" ); - - replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) ); - - int indicatorId = Integer.parseInt( replaceString ); - - Indicator indicator = indicatorService.getIndicator( indicatorId ); - - if ( indicator == null ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - - } - - Double aggregatedValue = aggregationService.getAggregatedIndicatorValue( indicator, startDate, endDate, - organisationUnit ); - - if ( aggregatedValue == null ) - { - replaceString = NULL_REPLACEMENT; - } - else - { - replaceString = String.valueOf( aggregatedValue ); - deFlag2 = 1; - } - matcher.appendReplacement( buffer, replaceString ); - } - - matcher.appendTail( buffer ); - - String resultValue = ""; - if ( deFlag1 == 0 ) - { - double d = 0.0; - try - { - d = MathUtils.calculateExpression( buffer.toString() ); - } - catch ( Exception e ) - { - d = 0.0; - } - if ( d == -1 ) - d = 0.0; - else - { - d = Math.round( d * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 ); - resultValue = "" + d; - } - - if ( deFlag2 == 0 ) - { - resultValue = " "; - } - } - else - { - resultValue = buffer.toString(); - } - return resultValue; - } - catch ( NumberFormatException ex ) - { - throw new RuntimeException( "Illegal DataElement id", ex ); - } - } - - private String getIndividualResultIndicatorValue( String formula, Date startDate, Date endDate, - OrganisationUnit organisationUnit ) - { - try - { - - int deFlag1 = 0; - int deFlag2 = 0; - Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); - - Matcher matcher = pattern.matcher( formula ); - StringBuffer buffer = new StringBuffer(); - - while ( matcher.find() ) - { - String replaceString = matcher.group(); - - replaceString = replaceString.replaceAll( "[\\[\\]]", "" ); - - replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) ); - - int indicatorId = Integer.parseInt( replaceString ); - - Indicator indicator = indicatorService.getIndicator( indicatorId ); - - if ( indicator == null ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - - } - - String numeratorExp = indicator.getNumerator(); - String denominatorExp = indicator.getDenominator(); - int indicatorFactor = indicator.getIndicatorType().getFactor(); - String numeratorVal = getIndividualResultDataValue( numeratorExp, startDate, endDate, organisationUnit ); - String denominatorVal = getIndividualResultDataValue( denominatorExp, startDate, endDate, - organisationUnit ); - - double numeratorValue; - try - { - numeratorValue = Double.parseDouble( numeratorVal ); - } - catch ( Exception e ) - { - //System.out.println( "Exception while getting Numerator : " + numeratorExp + " for Indicaotr " + indicator.getName() ); - numeratorValue = 0.0; - } - - double denominatorValue; - try - { - denominatorValue = Double.parseDouble( denominatorVal ); - } - catch ( Exception e ) - { - //System.out.println( "Exception while getting Deniminator : " + denominatorExp + " for Indicaotr " + indicator.getName() ); - denominatorValue = 1.0; - } - - double aggregatedValue; - try - { - aggregatedValue = (numeratorValue / denominatorValue) * indicatorFactor; - } - catch ( Exception e ) - { - //System.out.println( "Exception while calculating Indicator value for Indicaotr " + indicator.getName() ); - aggregatedValue = 0.0; - } - - replaceString = String.valueOf( aggregatedValue ); - deFlag2 = 1; - - matcher.appendReplacement( buffer, replaceString ); - } - - matcher.appendTail( buffer ); - - String resultValue = ""; - if ( deFlag1 == 0 ) - { - double d = 0.0; - try - { - d = MathUtils.calculateExpression( buffer.toString() ); - } - catch ( Exception e ) - { - d = 0.0; - } - if ( d == -1 ) - d = 0.0; - else - { - d = Math.round( d * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 ); - resultValue = "" + d; - } - - if ( deFlag2 == 0 ) - { - resultValue = " "; - } - } - else - { - resultValue = buffer.toString(); - } - return resultValue; - } - catch ( NumberFormatException ex ) - { - throw new RuntimeException( "Illegal DataElement id", ex ); - } - } - - private String getResultSurveyValue( String formula, OrganisationUnit organisationUnit ) - { - //System.out.println("Inside SurveyValue method : "+ formula + " : " + organisationUnit.getName()); - try - { - - int deFlag1 = 0; - int deFlag2 = 0; - Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); - - Matcher matcher = pattern.matcher( formula ); - StringBuffer buffer = new StringBuffer(); - - while ( matcher.find() ) - { - - String replaceString = matcher.group(); - - replaceString = replaceString.replaceAll( "[\\[\\]]", "" ); - - String surveyIdString = replaceString.substring( replaceString.indexOf( '.' ) + 1, replaceString - .length() ); - - replaceString = replaceString.substring( 0, replaceString.indexOf( '.' ) ); - - - - int indicatorId = Integer.parseInt( replaceString ); - - int surveyId = Integer.parseInt( surveyIdString ); - - Indicator indicator = indicatorService.getIndicator( indicatorId ); - - Survey survey = surveyService.getSurvey( surveyId ); - - //System.out.println(surveyId + " : " + indicatorId + " ----1 "); - - if ( indicator == null || survey == null) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - - } - - //System.out.println(survey.getName() + " : " + indicator.getName() + " ----2 "); - - //double aggregatedValue = aggregationService.getAggregatedIndicatorValue( indicator, startDate, endDate, - // organisationUnit ); - - SurveyDataValue surveyDataValue = new SurveyDataValue(); - - surveyDataValue = surveyDataValueService.getSurveyDataValue(organisationUnit, survey, indicator); - - if ( surveyDataValue == null ) - { - replaceString = ""; - matcher.appendReplacement( buffer, replaceString ); - continue; - - } - - - Double surveyValue = Double.valueOf( surveyDataValue.getValue() ); - - //System.out.println(survey.getName() + " : " + indicator.getName() + " : " + surveyValue ); - - if ( surveyValue == null ) - { - replaceString = NULL_REPLACEMENT; - } - else - { - replaceString = String.valueOf( surveyValue ); - deFlag2 = 1; - } - - matcher.appendReplacement( buffer, replaceString ); - } - - matcher.appendTail( buffer ); - - String resultValue = ""; - if ( deFlag1 == 0 ) - { - double d = 0.0; - try - { - d = MathUtils.calculateExpression( buffer.toString() ); - } - catch ( Exception e ) - { - d = 0.0; - } - if ( d == -1 ) - d = 0.0; - else - { - d = Math.round( d * Math.pow( 10, 1 ) ) / Math.pow( 10, 1 ); - resultValue = "" + d; - } - - if ( deFlag2 == 0 ) - { - resultValue = " "; - } - } - else - { - resultValue = buffer.toString(); - } - //System.out.println("Result in Survey : "+ resultValue); - return resultValue; - } - catch ( NumberFormatException ex ) - { - throw new RuntimeException( "Illegal Indicator and survey id", ex ); - } - } - - } === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/meta/action/GenerateMetaDataReportResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/meta/action/GenerateMetaDataReportResultAction.java 2010-12-31 07:16:18 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/meta/action/GenerateMetaDataReportResultAction.java 2011-01-05 05:31:43 +0000 @@ -39,6 +39,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitGroup; import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; +import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; import org.hisp.dhis.reports.ReportService; @@ -942,9 +943,11 @@ throws Exception { OrganisationUnit rootOrgUnit = organisationUnitService.getRootOrganisationUnits().iterator().next(); + OrganisationUnitHierarchy organisationUnitHierarchy = organisationUnitService.getOrganisationUnitHierarchy(); + //organisationUnitHierarchy. - List OrganisitionUnitList = new ArrayList( - getChildOrgUnitTree( rootOrgUnit ) ); + //List OrganisitionUnitList = new ArrayList( getChildOrgUnitTree( rootOrgUnit ) ); + List OrganisitionUnitList = new ArrayList( organisationUnitService.getOrganisationUnitWithChildren( rootOrgUnit.getId() ) ); String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "output" + File.separator + UUID.randomUUID().toString() + ".xls"; @@ -964,25 +967,18 @@ // Heading if ( incID != null ) { - // sheet0.addCell( new Label( colStart, rowStart, "OrgUnitID", - // getCellFormat1() ) ); - // 30/06/2010 - - // for printing all attributes heading in Excel Sheet 30/06/2010 if ( incID.equalsIgnoreCase( PRINT ) ) { sheet0.addCell( new Label( colStart, rowStart, "OrgUnitID", getCellFormat1() ) ); - sheet0.addCell( new Label( colStart + 1, rowStart, "organisationUnitName", getCellFormat1() ) ); - sheet0.addCell( new Label( colStart + 2, rowStart, "organisationUnitShortName", getCellFormat1() ) ); - sheet0.addCell( new Label( colStart + 3, rowStart, "organisationUnitOpeningDate", getCellFormat1() ) ); - sheet0.addCell( new Label( colStart + 4, rowStart, "organisationUnitClosedDate", getCellFormat1() ) ); - sheet0.addCell( new Label( colStart + 5, rowStart, "organisationUnitParentName", getCellFormat1() ) ); - sheet0.addCell( new Label( colStart + 6, rowStart, "organisationUnitCode", getCellFormat1() ) ); - sheet0.addCell( new Label( colStart + 7, rowStart, "organisationUnitUrl", getCellFormat1() ) ); + sheet0.addCell( new Label( colStart + 1, rowStart, "OrganisationUnitName", getCellFormat1() ) ); + sheet0.addCell( new Label( colStart + 2, rowStart, "OrganisationUnitShortName", getCellFormat1() ) ); + sheet0.addCell( new Label( colStart + 3, rowStart, "OrganisationUnitOpeningDate", getCellFormat1() ) ); + sheet0.addCell( new Label( colStart + 4, rowStart, "OrganisationUnitClosedDate", getCellFormat1() ) ); + sheet0.addCell( new Label( colStart + 5, rowStart, "OrganisationUnitParentName", getCellFormat1() ) ); + sheet0.addCell( new Label( colStart + 6, rowStart, "OrganisationUnitCode", getCellFormat1() ) ); + sheet0.addCell( new Label( colStart + 7, rowStart, "OrganisationUnitUrl", getCellFormat1() ) ); sheet0.addCell( new Label( colStart + 8, rowStart, "Last Updated", getCellFormat1() ) ); - } - else if ( incID.equalsIgnoreCase( SOURCE ) ) { sheet0.addCell( new Label( colStart, rowStart, "OrgUnitID", getCellFormat1() ) ); @@ -994,15 +990,12 @@ } else { - // sheet0.addCell( new Label( colStart, rowStart, "OrgUnitID", - // getCellFormat1() ) ); int maxLevels = organisationUnitService.getNumberOfOrganisationalLevels(); for ( int i = 1; i <= maxLevels; i++ ) { sheet0.addCell( new Label( colStart + i, rowStart, "Level-" + i, getCellFormat1() ) ); } } - } rowStart++; === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ouwiseprogress/action/GenerateOuWiseProgressReportResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ouwiseprogress/action/GenerateOuWiseProgressReportResultAction.java 2010-12-31 07:16:18 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/ouwiseprogress/action/GenerateOuWiseProgressReportResultAction.java 2011-01-05 05:31:43 +0000 @@ -143,7 +143,8 @@ // Initialization raFolderName = reportService.getRAFolderName(); - simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd" ); + simpleDateFormat = new SimpleDateFormat( "MMM-dd" ); + SimpleDateFormat dayFormat = new SimpleDateFormat( "yyyy-MM-dd" ); // Getting Report Details String deCodesXMLFileName = ""; @@ -201,6 +202,22 @@ { tempStr = currentOrgUnit.getName(); } + else if( deCodeString.equalsIgnoreCase( "FACILITYP" ) ) + { + tempStr = selectedOrgUnit.getParent().getName(); + } + else if( deCodeString.equalsIgnoreCase( "FACILITYPP" ) ) + { + tempStr = selectedOrgUnit.getParent().getParent().getName(); + } + else if ( deCodeString.equalsIgnoreCase( "DATE-FROM" ) ) + { + tempStr = dayFormat.format( sDate ); + } + else if ( deCodeString.equalsIgnoreCase( "DATE-TO" ) ) + { + tempStr = dayFormat.format( eDate ); + } else if ( deCodeString.equalsIgnoreCase( "MONTH-FROM" ) ) { tempStr = simpleDateFormat.format( sDate ); @@ -221,62 +238,50 @@ } } - int tempColNo = 0; int tempRowNo = report_inDesign.getRowno(); - if ( tempRowNo > 6 ) - { - tempColNo = report_inDesign.getColno() + orgUnitCount; - } - else - { - tempColNo = report_inDesign.getColno(); - } + int tempColNo = report_inDesign.getColno(); int sheetNo = report_inDesign.getSheetno(); WritableSheet sheet0 = outputReportWorkbook.getSheet( sheetNo ); - if ( tempStr == null || tempStr.equals( " " ) ) + if ( reportModelTB.equalsIgnoreCase( "PROGRESSIVE-ORGUNIT" ) ) { - WritableCellFormat wCellformat = new WritableCellFormat(); - + if( deCodeString.equalsIgnoreCase( "FACILITY" ) || deCodeString.equalsIgnoreCase( "FACILITYP" ) || deCodeString.equalsIgnoreCase( "FACILITYPP" ) + || deCodeString.equalsIgnoreCase( "MONTH-FROM" ) || deCodeString.equalsIgnoreCase( "MONTH-TO" ) + || deCodeString.equalsIgnoreCase( "DATE-FROM" ) || deCodeString.equalsIgnoreCase( "DATE-TO" ) ) + { + } + else + { + tempColNo += orgUnitCount; + } + + WritableCellFormat wCellformat; + + if( orgUnitCount == orgUnitList.size()-1 ) + { + wCellformat = new WritableCellFormat( arialBold ); + } + else + { + wCellformat = new WritableCellFormat(); + } + wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN ); + wCellformat.setAlignment( Alignment.CENTRE ); wCellformat.setWrap( true ); - wCellformat.setAlignment( Alignment.CENTRE ); - - sheet0.addCell( new Blank( tempColNo, tempRowNo, wCellformat ) ); - } - else - { - if ( reportModelTB.equalsIgnoreCase( "PROGRESSIVE-ORGUNIT" ) ) - { - if( deCodeString.equalsIgnoreCase( "FACILITY" ) || deCodeString.equalsIgnoreCase( "MONTH-FROM" ) || deCodeString.equalsIgnoreCase( "MONTH-TO" ) ) - { - } - - WritableCellFormat wCellformat; - - if( orgUnitCount == orgUnitList.size()-1 ) - { - wCellformat = new WritableCellFormat( arialBold ); - } - else - { - wCellformat = new WritableCellFormat(); - } - - wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN ); - wCellformat.setAlignment( Alignment.CENTRE ); - wCellformat.setWrap( true ); - - try - { - sheet0.addCell( new Number( tempColNo, tempRowNo, Double.parseDouble( tempStr ), wCellformat ) ); - } - catch( Exception e ) - { - sheet0.addCell( new Label( tempColNo, tempRowNo, tempStr, wCellformat ) ); - } - } - } + + System.out.println( tempColNo + " : " + tempRowNo + " : " + tempStr ); + + try + { + sheet0.addCell( new Number( tempColNo, tempRowNo, Double.parseDouble( tempStr ), wCellformat ) ); + } + catch( Exception e ) + { + sheet0.addCell( new Label( tempColNo, tempRowNo, tempStr, wCellformat ) ); + } + } + count1++; }// inner while loop end orgUnitCount++; === 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 2010-12-31 07:16:18 +0000 +++ local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml 2011-01-05 05:31:43 +0000 @@ -278,60 +278,18 @@ - - - - - - - + scope="prototype"> + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + @@ -1203,15 +1161,7 @@ id="org.hisp.dhis.reports.benificiaryinfo.action.BenificiaryInfoReportsFormAction" class="org.hisp.dhis.reports.benificiaryinfo.action.BenificiaryInfoReportsFormAction" scope="prototype"> - - - - - - - + - - - === 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 2010-12-31 07:16:18 +0000 +++ local/in/dhis-web-reports-national/src/main/resources/org/hisp/dhis/reports/i18n_module.properties 2011-01-05 05:31:43 +0000 @@ -4,6 +4,7 @@ periodwise_progress_ra = PeriodWise Progress Report Analyser orgunitwise_progress_ra = OrganisationunitWise Progress Report Analyser aggregation_ra = Aggregation Reports Analyser +feedback_ra = Feedback Report Analyser periodtype = PeriodType organisationunit = OrganisationUnit select_periodtype = Select PeriodType === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/benificiaryInfoReportsForm.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/benificiaryInfoReportsForm.vm 2010-12-22 07:29:08 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/benificiaryInfoReportsForm.vm 2011-01-05 05:31:43 +0000 @@ -1,151 +1,153 @@ - -

NBITS Report Analyser



- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Report With Specified Period
- Program :
- -
- OrganisationUnit :
- -
 
-
- -
-
- -
 
 
 
- - - - - - -
-
+ + +

NBITS Report Analyser

+

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+  
+ Program :
+ +
+ OrganisationUnit :
+ +
  
+ +
+ +
+ +
+ +
  
  
  + Report With Specified Period +

+ + + + + + +
+
+ - - === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/feedbackReportAnalysisFront.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/feedbackReportAnalysisFront.vm 2010-08-28 10:15:38 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/feedbackReportAnalysisFront.vm 2011-01-05 05:31:43 +0000 @@ -1,109 +1,77 @@ - - -

Feedback Report Analyser

-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- PeriodType :
- -
- OrganisationUnit :
- -
  
  
- Periods :
- - -
- Reports :
- -
  
  
  - Aggregated Data -

- - - - - - -
-
- - \ No newline at end of file + + +

$i18n.getString( "feedback_ra" )

+

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

+ + + + +
+
\ No newline at end of file === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/javascript/reports.js' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/javascript/reports.js 2010-10-31 08:01:14 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/javascript/reports.js 2011-01-05 05:31:43 +0000 @@ -1,4 +1,22 @@ + +function getSelectedOrgUnit( orgUnitIds ) +{ + jQuery.postJSON("getOrgUnitName.action",{ + id : orgUnitIds[0] + }, function( json ){ + setFieldValue( "ouNameTB",json.organisationUnit.name ); + }); +} + +function responseGetSelectedOrgUnitName( orgunit ) +{ + var element = dataelement.getElementsByTagName("orgunit"); + var orgUnitname = element[0].getElementsByTagName("OugUnitName")[0].firstChild.nodeValue; + document.reportForm.ouNameTB.value = orgUnitname; +} + + function checkStartDate( dtStr ) { === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForBenificiaryInfo.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForBenificiaryInfo.vm 2010-08-11 10:36:52 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForBenificiaryInfo.vm 2011-01-05 05:31:43 +0000 @@ -7,33 +7,34 @@ +
- - $i18n.getString( + $i18n.getString(
-#parse( "/dhis-web-commons/ouwt/orgunittree.vm" ) + +##parse( "/dhis-web-commons/ouwt/orgunittree.vm" ) +#parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" ) === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForDataSetLockReports.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForDataSetLockReports.vm 2010-12-22 07:29:08 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForDataSetLockReports.vm 2011-01-05 05:31:43 +0000 @@ -7,29 +7,23 @@ +
- - $i18n.getString( + $i18n.getString(
+ ##parse( "/dhis-web-commons/ouwt/orgunittree.vm" ) #parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" ) + - === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForFeedback.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForFeedback.vm 2010-08-28 10:15:38 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForFeedback.vm 2011-01-05 05:31:43 +0000 @@ -1,34 +1,33 @@ +

Report Analyser

  • Report Analysis
    • -
    • - Feedback Reports -
    • +
    • Feedback Reports
+
- - $i18n.getString( + $i18n.getString(
+ #parse( "/dhis-web-commons/ouwt/orgunittree.vm" ) - === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForRoutineReport.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForRoutineReport.vm 2010-12-22 07:29:08 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForRoutineReport.vm 2011-01-05 05:31:43 +0000 @@ -8,29 +8,27 @@
- - $i18n.getString( + $i18n.getString(
##parse( "/dhis-web-commons/ouwt/orgunittree.vm" ) -#parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" ) +#parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" ) === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/upwardReportAnalysisFront.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/upwardReportAnalysisFront.vm 2010-11-08 06:10:18 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/upwardReportAnalysisFront.vm 2011-01-05 05:31:43 +0000 @@ -35,7 +35,7 @@ @@ -58,7 +58,7 @@
- 1. $i18n.getString( "periodtype" ) :
+ 1. $i18n.getString( "periodtype" ) :
- 3. $i18n.getString( "organisationunit" ) :
+ 3. $i18n.getString( "organisationunit" ) :
- 2. $i18n.getString( "periods" ) :
+ 2. $i18n.getString( "periods" ) :