=== modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/TwentyPoint/action/GenerateTwentyPointReportsResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/TwentyPoint/action/GenerateTwentyPointReportsResultAction.java 2011-07-07 10:56:12 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/TwentyPoint/action/GenerateTwentyPointReportsResultAction.java 2011-12-14 11:06:08 +0000 @@ -66,14 +66,14 @@ import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import com.opensymphony.xwork2.ActionSupport; +import com.opensymphony.xwork2.Action; /** * @author Brajesh Murari * */ public class GenerateTwentyPointReportsResultAction - extends ActionSupport + implements Action { // private static final long serialVersionUID = 1L; @@ -486,7 +486,8 @@ List deCodesList = getDECodes( deCodesXMLFileName ); String levelName = "Level"; - int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ) + 1; + //int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ) + 1; + int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit.getId() ) + 1; if ( selOULevel <= organisationUnitService.getNumberOfOrganisationalLevels() ) { === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/action/GetOrgUnitsAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/action/GetOrgUnitsAction.java 2010-12-22 07:29:08 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/action/GetOrgUnitsAction.java 2011-12-14 11:06:08 +0000 @@ -54,8 +54,8 @@ if ( orgUnitId != null ) { orgUnit = organisationUnitService.getOrganisationUnit( orgUnitId ); - ouLevel = "" + organisationUnitService.getLevelOfOrganisationUnit( orgUnit ); - + ouLevel = "" + organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getId() ); + //ouLevel = "" + organisationUnitService.getLevelOfOrganisationUnit( orgUnit ) System.out.println( " Org Short name : " + orgUnit.getShortName() + ", level is : " + ouLevel ); } === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/advanced/action/GenerateAdvancedReportResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/advanced/action/GenerateAdvancedReportResultAction.java 2011-07-07 10:56:12 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/advanced/action/GenerateAdvancedReportResultAction.java 2011-12-14 11:06:08 +0000 @@ -441,7 +441,8 @@ List deCodesList = getDECodes( deCodesXMLFileName ); String levelName = "Level"; - int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ) + 1; + int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit.getId() ) + 1; + //int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ) + 1; if ( selOULevel <= organisationUnitService.getNumberOfOrganisationalLevels() ) { === 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 2011-07-07 10:56:12 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/benificiaryinfo/action/BenificiaryInfoReportsResultAction.java 2011-12-14 11:06:08 +0000 @@ -412,8 +412,8 @@ for ( OrganisationUnit ou : orgUnitList ) { - int level = organisationUnitService.getLevelOfOrganisationUnit( ou ); - + //int level = organisationUnitService.getLevelOfOrganisationUnit( ou ); + int level = organisationUnitService.getLevelOfOrganisationUnit( ou.getId() ); ouAndLevel.put( ou, level ); if ( !levelsList.contains( level ) ) { @@ -592,7 +592,8 @@ for ( int i = levelsList.size() - 1; i >= 0; i-- ) { colNo++; - int level = organisationUnitService.getLevelOfOrganisationUnit( ouname ); + int level = organisationUnitService.getLevelOfOrganisationUnit( ouname.getId() ); + //int level = organisationUnitService.getLevelOfOrganisationUnit( ouname ); if ( levelsList.get( i ) == level ) { sheet0.addCell( new Label( colNo, rowNo, ouname.getName(), wCellformat ) ); === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GenerateGradingReportResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GenerateGradingReportResultAction.java 2011-07-07 10:56:12 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GenerateGradingReportResultAction.java 2011-12-14 11:06:08 +0000 @@ -407,7 +407,8 @@ String heading1 = ""; String heading2 = ""; - int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ); + int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit.getId() ); + //int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ); int maxOULevels = organisationUnitService.getNumberOfOrganisationalLevels(); if( selOULevel < maxOULevels-1 ) @@ -549,16 +550,16 @@ OrganisationUnit tempOU = new OrganisationUnit(); - if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 2) - tempOU = ccOU.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 3) - tempOU = ccOU.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 4) + if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 2) + tempOU = ccOU.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 3) + tempOU = ccOU.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 4) tempOU = ccOU.getParent().getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 5) + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 5) tempOU = ccOU.getParent().getParent(); - if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) != 1) + if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) != 1) { String tempdeCodeString = "([1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*100/([14.1]+[15.1]+[1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*10"; === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GenerateImmChildGradingReportAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GenerateImmChildGradingReportAction.java 2011-07-07 10:56:12 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GenerateImmChildGradingReportAction.java 2011-12-14 11:06:08 +0000 @@ -511,17 +511,16 @@ resultVal = tempd1; OrganisationUnit tempOU = new OrganisationUnit(); - - if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 2) - tempOU = ccOU.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 3) - tempOU = ccOU.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 4) - tempOU = ccOU.getParent().getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 5) - tempOU = ccOU.getParent().getParent(); - - if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) != 1) + if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 2) + tempOU = ccOU.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 3) + tempOU = ccOU.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 4) + tempOU = ccOU.getParent().getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 5) + tempOU = ccOU.getParent().getParent(); + + if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) != 1) { String tempdeCodeString = "([1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*100/([14.1]+[15.1]+[1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*10"; //tempd1 = reportService.getResultDataValue( tempdeCodeString, tempStartDate.getTime(), tempEndDate.getTime(), tempOU, sType, con); @@ -687,16 +686,16 @@ OrganisationUnit tempOU = new OrganisationUnit(); - if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 2) - tempOU = ccOU.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 3) - tempOU = ccOU.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 4) + if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 2) + tempOU = ccOU.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 3) + tempOU = ccOU.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 4) tempOU = ccOU.getParent().getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 5) + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 5) tempOU = ccOU.getParent().getParent(); - if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) != 1) + if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) != 1) { String tempdeCodeString = "([1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*100/([14.1]+[15.1]+[1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*10"; === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GenerateSelChildGradingReportAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GenerateSelChildGradingReportAction.java 2011-07-07 10:56:12 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GenerateSelChildGradingReportAction.java 2011-12-14 11:06:08 +0000 @@ -500,16 +500,16 @@ OrganisationUnit tempOU = new OrganisationUnit(); - if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit ) == 2) - tempOU = orgUnit.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit ) == 3) - tempOU = orgUnit.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit ) == 4) + if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getId() ) == 2) + tempOU = orgUnit.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getId() ) == 3) + tempOU = orgUnit.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getId() ) == 4) tempOU = orgUnit.getParent().getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit ) == 5) + else if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getId() ) == 5) tempOU = orgUnit.getParent().getParent(); - if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit ) != 1) + if(organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getId() ) != 1) { String tempdeCodeString = "([1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*100/([14.1]+[15.1]+[1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*10"; === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GradingAbstractionResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GradingAbstractionResultAction.java 2011-07-07 10:56:12 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/grading/action/GradingAbstractionResultAction.java 2011-12-14 11:06:08 +0000 @@ -397,7 +397,8 @@ String reportHeading = ""; - int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ); + int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit.getId() ); + //int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ); int maxOULevels = organisationUnitService.getNumberOfOrganisationalLevels(); if( selOULevel < maxOULevels-1 ) @@ -431,17 +432,17 @@ selLevel = 5; } - if(organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit) == 2) + if( organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit.getId() ) == 2) { reportHeading += "Block, "+simpleDateFormat.format( eDate ); heading1 = "Taluk / Block"; } - else if(organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit) == 1) + else if(organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit.getId() ) == 1) { reportHeading += "District, "+simpleDateFormat.format( eDate ); heading1 = "District"; } - else if(organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit) == 3) + else if(organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit.getId() ) == 3) { reportHeading += "PHC, "+simpleDateFormat.format( eDate ); heading1 = "PHC"; @@ -573,16 +574,16 @@ OrganisationUnit tempOU = new OrganisationUnit(); - if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 2) - tempOU = ccOU.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 3) - tempOU = ccOU.getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 4) + if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 2) + tempOU = ccOU.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 3) + tempOU = ccOU.getParent(); + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 4) tempOU = ccOU.getParent().getParent(); - else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) == 5) + else if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) == 5) tempOU = ccOU.getParent().getParent(); - if(organisationUnitService.getLevelOfOrganisationUnit( ccOU ) != 1) + if(organisationUnitService.getLevelOfOrganisationUnit( ccOU.getId() ) != 1) { String tempdeCodeString = "([1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*100/([14.1]+[15.1]+[1251.1]+[1252.1]+[1253.1]+[1254.1]+[1255.1]+[26.1])*10"; @@ -768,7 +769,7 @@ while(it.hasNext()) { OrganisationUnit ou = (OrganisationUnit) it.next(); - if(organisationUnitService.getLevelOfOrganisationUnit( ou ) == selLevel) + if(organisationUnitService.getLevelOfOrganisationUnit( ou.getId() ) == selLevel) { ouList.add( ou ); } === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/leprosy/action/LeprosyReportResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/leprosy/action/LeprosyReportResultAction.java 2011-07-07 10:56:12 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/leprosy/action/LeprosyReportResultAction.java 2011-12-14 11:06:08 +0000 @@ -405,7 +405,8 @@ List deCodesList = getDECodes( deCodesXMLFileName ); String levelName = "Level"; - int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ) + 1; + //int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ) + 1; + int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit.getId() ) + 1; if ( selOULevel <= organisationUnitService.getNumberOfOrganisationalLevels() ) { === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/malarya/action/GenerateMalaryaReportResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/malarya/action/GenerateMalaryaReportResultAction.java 2011-07-07 10:56:12 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/malarya/action/GenerateMalaryaReportResultAction.java 2011-12-14 11:06:08 +0000 @@ -447,7 +447,8 @@ List deCodesList = getDECodes( deCodesXMLFileName ); String levelName = "Level"; - int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ) + 1; + //int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit ) + 1; + int selOULevel = organisationUnitService.getLevelOfOrganisationUnit( selectedOrgUnit.getId() ) + 1; if ( selOULevel <= organisationUnitService.getNumberOfOrganisationalLevels() ) { === added directory 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/md' === added directory 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/md/action' === added file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/md/action/GenerateMDReportAnalyserResultAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/md/action/GenerateMDReportAnalyserResultAction.java 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/md/action/GenerateMDReportAnalyserResultAction.java 2011-12-14 11:06:08 +0000 @@ -0,0 +1,680 @@ +package org.hisp.dhis.reports.md.action; + +import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers; +import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import jxl.Workbook; +import jxl.format.Alignment; +import jxl.format.Border; +import jxl.format.BorderLineStyle; +import jxl.format.Colour; +import jxl.format.VerticalAlignment; +import jxl.write.Blank; +import jxl.write.Label; +import jxl.write.Number; +import jxl.write.WritableCellFormat; +import jxl.write.WritableFont; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; + +import org.amplecode.quick.StatementManager; +import org.hisp.dhis.config.Configuration_IN; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitGroup; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; +import org.hisp.dhis.reports.ReportService; +import org.hisp.dhis.reports.Report_in; +import org.hisp.dhis.reports.Report_inDesign; +import org.hisp.dhis.system.util.MathUtils; + +import com.opensymphony.xwork2.Action; + +public class GenerateMDReportAnalyserResultAction implements Action +{ + private final String GENERATEAGGDATA = "generateaggdata"; + + private final String USEEXISTINGAGGDATA = "useexistingaggdata"; + + private final String USECAPTUREDDATA = "usecaptureddata"; + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private StatementManager statementManager; + + public void setStatementManager( StatementManager statementManager ) + { + this.statementManager = statementManager; + } + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + private ReportService reportService; + + public void setReportService( ReportService reportService ) + { + this.reportService = reportService; + } + + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } +/* + private I18nFormat format; + + public void setFormat( I18nFormat format ) + { + this.format = format + } +*/ + // ------------------------------------------------------------------------- + // Input/Output + // ------------------------------------------------------------------------- + + private InputStream inputStream; + + public InputStream getInputStream() + { + return inputStream; + } + + private String fileName; + + public String getFileName() + { + return fileName; + } + + private Integer selectedStartPeriodId; + + public void setSelectedStartPeriodId( Integer selectedStartPeriodId ) + { + this.selectedStartPeriodId = selectedStartPeriodId; + } + + private Integer selectedEndPeriodId; + + public void setSelectedEndPeriodId( Integer selectedEndPeriodId ) + { + this.selectedEndPeriodId = selectedEndPeriodId; + } + + private String reportList; + + public void setReportList( String reportList ) + { + this.reportList = reportList; + } + + private int ouIDTB; + + public void setOuIDTB( int ouIDTB ) + { + this.ouIDTB = ouIDTB; + } + + private String aggData; + + public void setAggData( String aggData ) + { + this.aggData = aggData; + } + + + private List orgUnitList; + + private String raFolderName; + + private SimpleDateFormat simpleDateFormat; + + //private SimpleDateFormat monthFormat; + + //private SimpleDateFormat yearFormat; + + //private SimpleDateFormat simpleMonthFormat; + + private String reportFileNameTB; + + //private String reportModelTB; + + private Date sDate; + + private Date eDate; + + // private OrganisationUnit selectedFacilityName; + + private List orgUnitGroupMemberList; + + // ------------------------------------------------------------------------- + // Action Implementation + // ------------------------------------------------------------------------- + public String execute() throws Exception + { + + // Initialization + statementManager.initialise(); + + raFolderName = reportService.getRAFolderName(); + String deCodesXMLFileName = ""; + simpleDateFormat = new SimpleDateFormat( "MMM-yyyy" ); + //monthFormat = new SimpleDateFormat( "MMMM" ); + //yearFormat = new SimpleDateFormat( "yyyy" ); + //simpleMonthFormat = new SimpleDateFormat( "MMM" ); + //String parentUnit = ""; + + Report_in selReportObj = reportService.getReport( Integer.parseInt( reportList ) ); + + deCodesXMLFileName = selReportObj.getXmlTemplateName(); + + + reportFileNameTB = selReportObj.getExcelTemplateName(); + + String inputTemplatePath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + "template" + File.separator + reportFileNameTB; + String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + Configuration_IN.DEFAULT_TEMPFOLDER; + File newdir = new File( outputReportPath ); + if( !newdir.exists() ) + { + newdir.mkdirs(); + } + outputReportPath += File.separator + UUID.randomUUID().toString() + ".xls"; + + Workbook templateWorkbook = Workbook.getWorkbook( new File( inputTemplatePath ) ); + WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ), templateWorkbook ); + + WritableCellFormat wCellformat = new WritableCellFormat(); + wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN ); + wCellformat.setAlignment( Alignment.CENTRE ); + wCellformat.setVerticalAlignment( VerticalAlignment.CENTRE ); + wCellformat.setWrap( true ); + + // Getting selected orgunit and its immediate children + OrganisationUnit selOrgUnit = organisationUnitService.getOrganisationUnit( ouIDTB ); + orgUnitList = new ArrayList( selOrgUnit.getChildren() ); + Collections.sort( orgUnitList, new OrganisationUnitNameComparator() ); + + // Org unit Group Information + OrganisationUnitGroup orgUnitGroup = selReportObj.getOrgunitGroup(); + orgUnitGroupMemberList = new ArrayList( orgUnitGroup.getMembers() ); + + // Period Info + Period selectedStartPeriod = periodService.getPeriod( selectedStartPeriodId ); + Period selectedEndPeriod = periodService.getPeriod( selectedEndPeriodId ); + sDate = selectedStartPeriod.getStartDate(); + eDate = selectedEndPeriod.getEndDate(); + + List periodList = new ArrayList( periodService.getIntersectingPeriods( selectedStartPeriod.getStartDate(), selectedEndPeriod.getEndDate() ) ); + Collection tempPeriodIds = new ArrayList( getIdentifiers(Period.class, periodList ) ); + String periodIdsByComma = getCommaDelimitedString( tempPeriodIds ); + + // Getting DataValues + List reportDesignList = reportService.getReportDesign( deCodesXMLFileName ); + + // collect dataElementIDs by commaSepareted + String dataElmentIdsByComma = reportService.getDataelementIds( reportDesignList ); + System.out.println( selOrgUnit.getName()+ " : " + selReportObj.getName()+" : Report Generation Start Time is : " + new Date() ); + + int orgUnitCount = 0; + int rowIncr = 0; + int tempOrgUnitCount = 0; + + int rowStart = 5; + int colStart = 0; + + int rowInc = 0; + int slno = 1; + + + Iterator it = orgUnitList.iterator(); + while ( it.hasNext() ) + { + OrganisationUnit tempOrgUnit = (OrganisationUnit) it.next(); + + Map subTotalMap = new HashMap(); + + List orgUnitWithChildTree = new ArrayList( organisationUnitService.getOrganisationUnitWithChildren( tempOrgUnit.getId() ) ); + orgUnitWithChildTree.retainAll( orgUnitGroupMemberList ); + + List childOrgUnitTreeIds = new ArrayList( getIdentifiers( OrganisationUnit.class, orgUnitWithChildTree ) ); + String childOrgUnitsByComma = getCommaDelimitedString( childOrgUnitTreeIds ); + + WritableSheet sheet0 = outputReportWorkbook.getSheet( 0 ); + + Map aggDeMap = new HashMap(); + if( aggData.equalsIgnoreCase( USECAPTUREDDATA ) ) + { + aggDeMap.putAll( reportService.getAggDataFromDataValueTableForOrgUnitWise( childOrgUnitsByComma, dataElmentIdsByComma, periodIdsByComma ) ); + } + //else if( aggData.equalsIgnoreCase( GENERATEAGGDATA ) ) + //{ + // List childOrgUnitTree = new ArrayList( organisationUnitService.getOrganisationUnitWithChildren( tempOrgUnit.getId() ) ); + // List tempChildOrgUnitTreeIds = new ArrayList( getIdentifiers( OrganisationUnit.class, childOrgUnitTree ) ); + // String tempChildOrgUnitsByComma = getCommaDelimitedString( tempChildOrgUnitTreeIds ); + + // aggDeMap.putAll( reportService.getAggDataFromDataValueTable( tempChildOrgUnitsByComma, dataElmentIdsByComma, periodIdsByComma ) ); + //} + else if( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) ) + { + aggDeMap.putAll( reportService.getAggDataFromAggDataValueTableForOrgUnitWise( childOrgUnitsByComma, dataElmentIdsByComma, periodIdsByComma ) ); + } + + Double tempSubTotal = 0.0; + + //List tempTotal = new ArrayList(); + int tempOuMemeberCount = 0; + Iterator currIt = orgUnitWithChildTree.iterator(); + while ( currIt.hasNext() ) + { + OrganisationUnit currentOrgUnit = (OrganisationUnit) currIt.next(); + + Map tempAggDeMap = new HashMap(); + if( aggData.equalsIgnoreCase( GENERATEAGGDATA ) ) + { + List childOrgUnitTree = new ArrayList( organisationUnitService.getOrganisationUnitWithChildren( currentOrgUnit.getId() ) ); + List tempchildOrgUnitTreeIds = new ArrayList( getIdentifiers( OrganisationUnit.class, childOrgUnitTree ) ); + String tempchildOrgUnitsByComma = getCommaDelimitedString( tempchildOrgUnitTreeIds ); + + tempAggDeMap.putAll( reportService.getAggDataFromDataValueTable( tempchildOrgUnitsByComma, dataElmentIdsByComma, periodIdsByComma ) ); + } + sheet0.addCell( new Number( colStart, rowStart+rowInc, slno, getCellFormat1() ) ); + sheet0.addCell( new Label( colStart+1, rowStart+rowInc, tempOrgUnit.getName(), getCellFormat1() ) ); + sheet0.addCell( new Label( colStart+2, rowStart+rowInc, currentOrgUnit.getName(), getCellFormat1() ) ); + + int count1 = 0; + Integer deCount = 0; + Iterator reportDesignIterator = reportDesignList.iterator(); + while ( reportDesignIterator.hasNext() ) + { + 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 = ""; + // String tempSubTotal = ""; + + if( deCodeString.equalsIgnoreCase( "FACILITY" ) ) + { + tempStr = selOrgUnit.getName(); + } + else if( deCodeString.equalsIgnoreCase( "PERIOD-NOREPEAT" ) ) + { + tempStr = simpleDateFormat.format( sDate ) + " To " + simpleDateFormat.format( eDate ); + } + else if ( deCodeString.equalsIgnoreCase( "NA" ) ) + { + tempStr = " "; + } + else + { + deCount++; + if( sType.equalsIgnoreCase( "dataelement" ) ) + { + if ( aggData.equalsIgnoreCase( USECAPTUREDDATA ) ) + { + Double tempAggValue = 0.0; + tempStr = getAggVal( deCodeString, currentOrgUnit.getId(), aggDeMap ); + + try + { + tempAggValue = Double.parseDouble( tempStr ); + } + catch ( Exception e ) + { + tempAggValue = 0.0; + } + tempSubTotal += tempAggValue; + + Double tempST = subTotalMap.get( deCount ); + if( tempST != null ) + { + tempST += tempAggValue; + } + else + { + tempST = tempAggValue; + } + //System.out.println( "tempST : "+tempST + " Count : "+ deCount + " OU : "+ currentOrgUnit.getName()); + subTotalMap.put( deCount, tempST ); + //tempSubTotal += aggValue; + } + + else if( aggData.equalsIgnoreCase( GENERATEAGGDATA ) ) + { + Double tempAggValue = 0.0; + //tempStr = reportService.getResultDataValue( deCodeString, sDate, eDate, currentOrgUnit, selReportObj.getModel() ); + tempStr = getAggVal( deCodeString, tempAggDeMap ); + try + { + tempAggValue = Double.parseDouble( tempStr ); + } + catch ( Exception e ) + { + tempAggValue = 0.0; + } + tempSubTotal += tempAggValue; + Double tempST = subTotalMap.get( deCount ); + if( tempST != null ) + { + tempST += tempAggValue; + } + else + { + tempST = tempAggValue; + } + //System.out.println( "tempST : "+tempST + " Count : "+ deCount + " OU : "+ currentOrgUnit.getName()); + subTotalMap.put( deCount, tempST ); + + } + else if( aggData.equalsIgnoreCase( USEEXISTINGAGGDATA ) ) + { + Double tempAggValue = 0.0; + tempStr = getAggVal( deCodeString, aggDeMap ); + try + { + tempAggValue = Double.parseDouble( tempStr ); + } + catch ( Exception e ) + { + tempAggValue = 0.0; + } + tempSubTotal += tempAggValue; + Double tempST = subTotalMap.get( deCount ); + if( tempST != null ) + { + tempST += tempAggValue; + } + else + { + tempST = tempAggValue; + } + subTotalMap.put( deCount, tempST ); + + } + //tempTotal.add( tempSubTotal ); + } + } + int tempRowNo = report_inDesign.getRowno(); + rowIncr = tempRowNo; + int tempColNo = report_inDesign.getColno(); + int sheetNo = report_inDesign.getSheetno(); + sheet0 = outputReportWorkbook.getSheet( sheetNo ); + + if ( tempStr == null || tempStr.equals( " " ) ) + { + sheet0.addCell( new Blank( tempColNo, tempRowNo, wCellformat ) ); + } + else + { + if ( deCodeString.equalsIgnoreCase( "FACILITY" ) || deCodeString.equalsIgnoreCase( "PERIOD-NOREPEAT" ) ) + { + + } + else + { + tempRowNo += tempOrgUnitCount; + rowIncr += tempOrgUnitCount; + } + + if ( sType.equalsIgnoreCase( "dataelement" ) ) + { + if( tempOuMemeberCount == orgUnitWithChildTree.size()-1 ) + { + if( deCodeString.equalsIgnoreCase( "FACILITY" ) || deCodeString.equalsIgnoreCase( "PERIOD-NOREPEAT" ) ) + { + + } + else + { + try + { + sheet0.addCell( new Number( tempColNo, tempRowNo, Integer.parseInt( tempStr ), getCellFormat1() ) ); + } + catch ( Exception e ) + { + sheet0.addCell( new Label( tempColNo, tempRowNo, tempStr, getCellFormat1() ) ); + } + + tempRowNo++; + + try + { + sheet0.addCell( new Number( tempColNo, tempRowNo, subTotalMap.get( deCount ) , getCellFormat2() ) ); + } + catch ( Exception e ) + { + sheet0.addCell( new Label( tempColNo, tempRowNo, " ", getCellFormat2() ) ); + } + //tempOrgUnitCount++; + //rowInc++; + } + } + else + { + try + { + sheet0.addCell( new Number( tempColNo, tempRowNo, Integer.parseInt( tempStr ), getCellFormat1() ) ); + } + catch ( Exception e ) + { + sheet0.addCell( new Label( tempColNo, tempRowNo, tempStr, getCellFormat1() ) ); + } + } + } + } + count1++; + } + + rowIncr++; + rowInc++; + tempOuMemeberCount++; + tempOrgUnitCount++; + slno++; + } + + if( orgUnitWithChildTree.size() != 0 ) + { + sheet0.addCell( new Label( colStart, rowStart+rowInc, " ", getCellFormat2() ) ); + sheet0.addCell( new Label( colStart+1, rowStart+rowInc, " ", getCellFormat2() ) ); + sheet0.addCell( new Label( colStart+2, rowStart+rowInc, "SUB TOTAL", getCellFormat2() ) ); + rowInc++; + tempOrgUnitCount++; + } + + rowIncr++; + orgUnitCount++; + } + + outputReportWorkbook.write(); + outputReportWorkbook.close(); + + fileName = reportFileNameTB.replace( ".xls", "" ); + fileName += "_" + selOrgUnit.getShortName() + "_"; + fileName += "_" + simpleDateFormat.format( sDate ) + ".xls"; + File outputReportFile = new File( outputReportPath ); + inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) ); + + System.out.println( selOrgUnit.getName()+ " : " + selReportObj.getName()+" : Report Generation End Time is : " + new Date() ); + + statementManager.destroy(); + return SUCCESS; + } + + // Returns the OrgUnitTree for which Root is the orgUnit + @SuppressWarnings( "unchecked" ) + public List getChildOrgUnitTree( OrganisationUnit orgUnit ) + { + List orgUnitTree = new ArrayList(); + orgUnitTree.add( orgUnit ); + + List children = new ArrayList( orgUnit.getChildren() ); + Collections.sort( children, new OrganisationUnitNameComparator() ); + + Iterator childIterator = children.iterator(); + OrganisationUnit child; + while ( childIterator.hasNext() ) + { + child = (OrganisationUnit) childIterator.next(); + orgUnitTree.addAll( getChildOrgUnitTree( child ) ); + } + return orgUnitTree; + }// getChildOrgUnitTree end + + + // getting data value using Map + private String getAggVal( String expression, Integer orgUnitID, Map aggDeMap ) + { + try + { + Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); + + Matcher matcher = pattern.matcher( expression ); + StringBuffer buffer = new StringBuffer(); + + String resultValue = ""; + + while ( matcher.find() ) + { + String replaceString = matcher.group(); + + replaceString = replaceString.replaceAll( "[\\[\\]]", "" ); + + replaceString = aggDeMap.get( replaceString +":"+ orgUnitID ); + + if( replaceString == null ) + { + replaceString = "0"; + } + + matcher.appendReplacement( buffer, replaceString ); + + resultValue = replaceString; + } + + matcher.appendTail( buffer ); + + double d = 0.0; + try + { + d = MathUtils.calculateExpression( buffer.toString() ); + } + catch ( Exception e ) + { + d = 0.0; + resultValue = ""; + } + + resultValue = "" + (double) d; + + return resultValue; + } + catch ( NumberFormatException ex ) + { + throw new RuntimeException( "Illegal DataElement id", ex ); + } + } + + public WritableCellFormat getCellFormat1()throws Exception + { + WritableCellFormat wCellformat = new WritableCellFormat(); + + wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN ); + wCellformat.setAlignment( Alignment.CENTRE ); + wCellformat.setWrap( true ); + + return wCellformat; + } + + public WritableCellFormat getCellFormat2() throws Exception + { + WritableFont arialBold = new WritableFont( WritableFont.ARIAL, 10, WritableFont.BOLD ); + WritableCellFormat wCellformat = new WritableCellFormat( arialBold ); + + wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN ); + wCellformat.setAlignment( Alignment.CENTRE ); + wCellformat.setBackground( Colour.ICE_BLUE ); + wCellformat.setWrap( true ); + + return wCellformat; + } + + private String getAggVal( String expression, Map aggDeMap ) + { + try + { + Pattern pattern = Pattern.compile( "(\\[\\d+\\.\\d+\\])" ); + + Matcher matcher = pattern.matcher( expression ); + StringBuffer buffer = new StringBuffer(); + + String resultValue = ""; + + while ( matcher.find() ) + { + String replaceString = matcher.group(); + + replaceString = replaceString.replaceAll( "[\\[\\]]", "" ); + + replaceString = aggDeMap.get( replaceString ); + + if( replaceString == null ) + { + replaceString = "0"; + } + + matcher.appendReplacement( buffer, replaceString ); + + resultValue = replaceString; + } + + matcher.appendTail( buffer ); + + double d = 0.0; + try + { + d = MathUtils.calculateExpression( buffer.toString() ); + } + catch ( Exception e ) + { + d = 0.0; + resultValue = ""; + } + + resultValue = "" + (double) d; + + return resultValue; + } + catch ( NumberFormatException ex ) + { + throw new RuntimeException( "Illegal DataElement id", ex ); + } + } +} === added file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/md/action/MDReportFormAction.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/md/action/MDReportFormAction.java 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/md/action/MDReportFormAction.java 2011-12-14 11:06:08 +0000 @@ -0,0 +1,92 @@ +package org.hisp.dhis.reports.md.action; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.hisp.dhis.period.MonthlyPeriodType; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; +import org.hisp.dhis.period.comparator.PeriodComparator; +import org.hisp.dhis.reports.ReportType; + +import com.opensymphony.xwork2.Action; + +public class MDReportFormAction implements Action +{ + //-------------------------------------------------------------------------- + // Dependencies + //-------------------------------------------------------------------------- + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + //-------------------------------------------------------------------------- + //Input/Output + //-------------------------------------------------------------------------- + + private List periods; + + public List getPeriods() + { + return periods; + } + + private String reportTypeName; + + public String getReportTypeName() + { + return reportTypeName; + } + + private String periodTypeName; + + public String getPeriodTypeName() + { + return periodTypeName; + } + + //-------------------------------------------------------------------------- + // Action Implementation + //-------------------------------------------------------------------------- + + private SimpleDateFormat simpleDateFormat; + + public SimpleDateFormat getSimpleDateFormat() + { + return simpleDateFormat; + } + + public String execute() throws Exception + { + reportTypeName = ReportType.RT_MD_REPORT; + periodTypeName = MonthlyPeriodType.NAME; + + //period information + periods = new ArrayList( periodService.getPeriodsByPeriodType( new MonthlyPeriodType() ) ); + + Iterator periodIterator = periods.iterator(); + while ( periodIterator.hasNext() ) + { + Period p1 = periodIterator.next(); + if ( p1.getStartDate().compareTo( new Date() ) > 0 ) + { + periodIterator.remove(); + } + + + } + simpleDateFormat = new SimpleDateFormat( "MMM-yy" ); + Collections.sort( periods, new PeriodComparator() ); + return SUCCESS; + } + + +} === modified file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/util/OrganisationUnitLevelComparator.java' --- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/util/OrganisationUnitLevelComparator.java 2010-06-04 11:50:05 +0000 +++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/util/OrganisationUnitLevelComparator.java 2011-12-14 11:06:08 +0000 @@ -10,7 +10,8 @@ OrganisationUnitService organisationUnitService = new org.hisp.dhis.organisationunit.DefaultOrganisationUnitService(); public int compare( OrganisationUnit organisationUnit0, OrganisationUnit organisationUnit1 ) - { - return (organisationUnitService.getLevelOfOrganisationUnit(organisationUnit1) - organisationUnitService.getLevelOfOrganisationUnit(organisationUnit0)); + { + //return (organisationUnitService.getLevelOfOrganisationUnit(organisationUnit1) - organisationUnitService.getLevelOfOrganisationUnit(organisationUnit0)); + return (organisationUnitService.getLevelOfOrganisationUnit(organisationUnit1.getId()) - organisationUnitService.getLevelOfOrganisationUnit(organisationUnit0.getId())); } } === 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 2011-12-05 05:56:00 +0000 +++ local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml 2011-12-14 11:06:08 +0000 @@ -207,7 +207,22 @@ - + + + + + + + + + + + + 1024 - + + + + /main.vm + /dhis-web-reports/mdReportForm.vm + /dhis-web-reports/menuWithTreeForMDReport.vm + ../dhis-web-commons/ouwt/ouwt.js,../dhis-web-commons/lists/lists.js,javascript/reportManagement.js,javascript/hashtable.js + css/StylesForTags.css + F_MDREPORT_GENERATE + + + + + application/vnd.ms-excel + inputStream + filename="${fileName}" + 1024 + + + === added file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/mdReportForm.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/mdReportForm.vm 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/mdReportForm.vm 2011-12-14 11:06:08 +0000 @@ -0,0 +1,102 @@ + +

$i18n.getString( "md_report_ra" )

+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 1.$i18n.getString( "organisationunit" ) :
+ +
+ 3.From Date :
+ +
+ +  
  
+ 2. $i18n.getString( "reports" ) :
+ +
+ 4.To Date :
+ +
  
  
+ 5.$i18n.getString( "generated_data_type" ) :
+ +
  
  
+ + + + + +
+
\ No newline at end of file === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.vm 2011-10-14 12:26:01 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.vm 2011-12-14 11:06:08 +0000 @@ -71,7 +71,10 @@ #end #if( $auth.hasAccess( "dhis-web-reports", "lineListingBulkReportAnalyser") )
  • Linelisting Bulk Report - #end + #end + #if( $auth.hasAccess( "dhis-web-reports", "mdReportAnalyser") ) +
  • MD Report + #end === added file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForMDReport.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForMDReport.vm 1970-01-01 00:00:00 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForMDReport.vm 2011-12-14 11:06:08 +0000 @@ -0,0 +1,31 @@ + +

    Report Analyser

    + +
      +
    • Report Analysis
    • +
        +
      • + MD Reports +
      • +
      +
    + +#parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" ) + + \ No newline at end of file === modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/ouWiseProgressReportFront.vm' --- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/ouWiseProgressReportFront.vm 2011-12-05 05:56:00 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/ouWiseProgressReportFront.vm 2011-12-14 11:06:08 +0000 @@ -92,7 +92,7 @@ - 6. $i18n.getString( "orgunit_group" ) :
    + 6. $i18n.getString( "orgunitgroup" ) :