=== 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-08-19 10:40:50 +0000 +++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/reports/ReportService.java 2010-08-20 07:21:39 +0000 @@ -32,58 +32,70 @@ import java.util.Date; import java.util.List; +import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.source.Source; -public interface ReportService +public interface ReportService { String ID = ReportService.class.getName(); - + // ------------------------------------------------------------------------- // Report_in // ------------------------------------------------------------------------- int addReport( Report_in report ); - + void updateReport( Report_in report ); - + void deleteReport( Report_in report ); - + Report_in getReport( int id ); - + Report_in getReportByName( String name ); - + Collection getReportBySource( Source source ); - + Collection getAllReports(); - + Collection getReportsByReportType( String reportType ); - + Collection getReportsByPeriodType( PeriodType periodType ); - + Collection getReportsByPeriodAndReportType( PeriodType periodType, String reportType ); - + Collection getReportsByPeriodSourceAndReportType( PeriodType periodType, Source source, String reportType ); - // ------------------------------------------------------------------------- // Report_in Design // ------------------------------------------------------------------------- - Collection getReportDesign( Report_in report); - + Collection getReportDesign( Report_in report ); + // ------------------------------------------------------------------------- // // ------------------------------------------------------------------------- - + List getStartingEndingPeriods( String deType, Date startDate, Date endDate ); - - String getResultDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit, String aggCB ); String getRAFolderName(); - + List getLinelistingRecordNos( OrganisationUnit organisationUnit, Period period, String lltype ); - + + // ------------------------------------------------------------------------- + // ReportService Design + // ------------------------------------------------------------------------- + + public List getMonthlyPeriods( Date start, Date end ); + + public PeriodType getPeriodTypeObject( String periodTypeName ); + + public Period getPeriodByMonth( int month, int year, PeriodType periodType ); + + public List getAllChildren( OrganisationUnit selecteOU ); + + public PeriodType getDataElementPeriodType( DataElement de ); + } === 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-08-19 10:40:50 +0000 +++ local/in/dhis-in-services/dhis-in-service-reports/src/main/java/org/hisp/dhis/reports/DefaultReportService.java 2010-08-20 07:21:39 +0000 @@ -6,29 +6,22 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.Iterator; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; - import org.hisp.dhis.config.ConfigurationService; import org.hisp.dhis.config.Configuration_IN; 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.datamart.DataMartStore; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.MonthlyPeriodType; import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.PeriodStore; +import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.source.Source; -import org.hisp.dhis.system.util.MathUtils; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.transaction.annotation.Transactional; @@ -42,8 +35,7 @@ public class DefaultReportService implements ReportService { - private static final String NULL_REPLACEMENT = "0"; - + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -54,62 +46,39 @@ { this.reportStore = reportStore; } - + private ConfigurationService configurationService; - + public void setConfigurationService( ConfigurationService configurationService ) { this.configurationService = configurationService; } - private PeriodStore periodStore; - - public void setPeriodStore( PeriodStore periodStore ) - { - this.periodStore = periodStore; - } - - private DataElementService dataElementService; - - public void setDataElementService( DataElementService dataElementService ) - { - this.dataElementService = dataElementService; - } - - private DataValueService dataValueService; - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - private DataElementCategoryService dataElementCategoryOptionComboService; - - public void setDataElementCategoryOptionComboService( - DataElementCategoryService dataElementCategoryOptionComboService ) - { - this.dataElementCategoryOptionComboService = dataElementCategoryOptionComboService; - } - - private DataMartStore dataMartStore; - - public void setDataMartStore( DataMartStore dataMartStore ) - { - this.dataMartStore = dataMartStore; - } - private JdbcTemplate jdbcTemplate; - + public void setJdbcTemplate( JdbcTemplate jdbcTemplate ) { this.jdbcTemplate = jdbcTemplate; } + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + private DataSetService dataSetService; + + public void setDataSetService( DataSetService dataSetService ) + { + this.dataSetService = dataSetService; + } + // ------------------------------------------------------------------------- // Report_in // ------------------------------------------------------------------------- - @Transactional public int addReport( Report_in report ) { @@ -171,12 +140,16 @@ } @Transactional - public Collection getReportsByPeriodSourceAndReportType( PeriodType periodType, Source source, String reportType ) + public Collection getReportsByPeriodSourceAndReportType( PeriodType periodType, Source source, + String reportType ) { return reportStore.getReportsByPeriodSourceAndReportType( periodType, source, reportType ); } - - + + // ------------------------------------------------------------------------- + // Support Methods Defination + // ------------------------------------------------------------------------- + public String getRAFolderName() { String raFolderName = "ra_national"; @@ -193,7 +166,7 @@ return raFolderName; } - + public List getLinelistingRecordNos( OrganisationUnit organisationUnit, Period period, String lltype ) { List recordNosList = new ArrayList(); @@ -202,13 +175,15 @@ int dataElementid = 1020; - if ( lltype.equalsIgnoreCase( "lldeath-l4DECodes.xml" ) || lltype.equalsIgnoreCase( "lllivebirth-l5DECodes.xml" ) + if ( lltype.equalsIgnoreCase( "lldeath-l4DECodes.xml" ) + || lltype.equalsIgnoreCase( "lllivebirth-l5DECodes.xml" ) || lltype.equalsIgnoreCase( "lllivebirth-l6DECodes.xml" ) ) dataElementid = 1020; - else if ( lltype.equalsIgnoreCase( "lldeath-l4DECodes.xml" ) || lltype.equalsIgnoreCase( "lldeath-l5DECodes.xml" ) - || lltype.equalsIgnoreCase( "lldeath-l6DECodes.xml" ) ) + else if ( lltype.equalsIgnoreCase( "lldeath-l4DECodes.xml" ) + || lltype.equalsIgnoreCase( "lldeath-l5DECodes.xml" ) || lltype.equalsIgnoreCase( "lldeath-l6DECodes.xml" ) ) dataElementid = 1027; - else if ( lltype.equalsIgnoreCase( "llmaternaldeath-l4DECodes.xml" ) || lltype.equalsIgnoreCase( "llmaternaldeath-l5DECodes.xml" ) + else if ( lltype.equalsIgnoreCase( "llmaternaldeath-l4DECodes.xml" ) + || lltype.equalsIgnoreCase( "llmaternaldeath-l5DECodes.xml" ) || lltype.equalsIgnoreCase( "llmaternaldeath-l6DECodes.xml" ) ) dataElementid = 1032; @@ -234,17 +209,18 @@ return recordNosList; } - public List getReportDesign( Report_in report ) { List deCodes = new ArrayList(); - String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ).getValue(); - - String path = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + report.getXmlTemplateName(); - - if( path == null ) + String raFolderName = configurationService.getConfigurationByKey( Configuration_IN.KEY_REPORTFOLDER ) + .getValue(); + + String path = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator + + report.getXmlTemplateName(); + + if ( path == null ) { - System.out.println("DHIS2_HOME is not set"); + System.out.println( "DHIS2_HOME is not set" ); } try @@ -265,18 +241,19 @@ { Element deCodeElement = (Element) listOfDECodes.item( s ); NodeList textDECodeList = deCodeElement.getChildNodes(); - + String expression = ((Node) textDECodeList.item( 0 )).getNodeValue().trim(); String stype = deCodeElement.getAttribute( "stype" ); String ptype = deCodeElement.getAttribute( "type" ); int sheetno = new Integer( deCodeElement.getAttribute( "sheetno" ) ); - int rowno = new Integer( deCodeElement.getAttribute( "rowno" ) ); + int rowno = new Integer( deCodeElement.getAttribute( "rowno" ) ); int colno = new Integer( deCodeElement.getAttribute( "colno" ) ); int rowMerge = new Integer( deCodeElement.getAttribute( "rowmerge" ) ); int colMerge = new Integer( deCodeElement.getAttribute( "colmerge" ) ); - - Report_inDesign reportDesign = new Report_inDesign( stype, ptype, sheetno, rowno, colno, rowMerge, colMerge, expression ); - + + Report_inDesign reportDesign = new Report_inDesign( stype, ptype, sheetno, rowno, colno, rowMerge, + colMerge, expression ); + deCodes.add( reportDesign ); }// end of for loop with s var @@ -297,13 +274,12 @@ } return deCodes; }// getDECodes end - - + /* * Returns Previous Month's Period object For ex:- selected period is * Aug-2007 it returns the period object corresponding July-2007 */ - public Period getPreviousPeriod(Date startDate, Date endDate) + public Period getPreviousPeriod( Date startDate, Date endDate ) { Period period = new Period(); Calendar tempDate = Calendar.getInstance(); @@ -322,11 +298,11 @@ return period; } - + /* - * Returns the Period Object of the given date - * For ex:- if the month is 3, year is 2006 and periodType Object of type Monthly then - * it returns the corresponding Period Object + * Returns the Period Object of the given date For ex:- if the month is 3, + * year is 2006 and periodType Object of type Monthly then it returns the + * corresponding Period Object */ public Period getPeriodByMonth( int month, int year, PeriodType periodType ) { @@ -351,15 +327,14 @@ else if ( periodType.getName().equals( "Yearly" ) ) { cal.set( year, Calendar.DECEMBER, 31 ); - } + } Date lastDay = new Date( cal.getTimeInMillis() ); - System.out.println( lastDay.toString() ); + System.out.println( lastDay.toString() ); Period newPeriod = new Period(); - newPeriod = periodStore.getPeriod( firstDay, lastDay, periodType ); + newPeriod = periodService.getPeriod( firstDay, lastDay, periodType ); return newPeriod; } - public List getStartingEndingPeriods( String deType, Date startDate, Date endDate ) { List calendarList = new ArrayList(); @@ -429,150 +404,87 @@ return calendarList; } - - - public String getResultDataValue( String formula, Date startDate, Date endDate, OrganisationUnit organisationUnit, String aggCB ) - { - try - { - int deFlag1 = 0; - int deFlag2 = 0; - - List periodList = new ArrayList(periodStore.getIntersectingPeriods( startDate, endDate )); - - 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 ); - - double aggregatedValue = 0.0; - for(Period p : periodList) - { - Double tempAggVal = dataMartStore.getAggregatedValue( dataElement, optionCombo, p, organisationUnit ); - - if( tempAggVal == null ) - { - aggregatedValue += tempAggVal; - } - } - - replaceString = String.valueOf( aggregatedValue ); - - deFlag2 = 1; - } - else - { - deFlag1 = 1; - - for( Period p : periodList ) - { - DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, p, optionCombo ); - - if ( dataValue != null ) - { - replaceString += dataValue.getValue(); - } - } - - 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 ); - } - } + + public List getMonthlyPeriods( Date start, Date end ) + { + List periodList = new ArrayList( periodService.getPeriodsBetweenDates( start, end ) ); + PeriodType monthlyPeriodType = getPeriodTypeObject( "monthly" ); + + List monthlyPeriodList = new ArrayList(); + Iterator it = periodList.iterator(); + while ( it.hasNext() ) + { + Period period = (Period) it.next(); + if ( period.getPeriodType().getId() == monthlyPeriodType.getId() ) + { + monthlyPeriodList.add( period ); + } + } + return monthlyPeriodList; + } + + /* + * Returns the PeriodType Object based on the Period Type Name For ex:- if + * we pass name as Monthly then it returns the PeriodType Object for Monthly + * PeriodType If there is no such PeriodType returns null + */ + 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; + } + + /* + * Returns the child tree of the selected Orgunit + */ + public List getAllChildren( OrganisationUnit selecteOU ) + { + List ouList = new ArrayList(); + Iterator it = selecteOU.getChildren().iterator(); + while ( it.hasNext() ) + { + OrganisationUnit orgU = (OrganisationUnit) it.next(); + ouList.add( orgU ); + } + return ouList; + } + + /* + * 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 + } - === 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-08-19 10:40:50 +0000 +++ local/in/dhis-in-services/dhis-in-service-reports/src/main/resources/META-INF/dhis/beans.xml 2010-08-20 07:21:39 +0000 @@ -1,59 +1,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + === 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-06-04 11:50:05 +0000 +++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/upwardReportAnalysisFront.vm 2010-08-20 07:21:39 +0000 @@ -1,9 +1,5 @@ - - - Government of India Reports - - - - + +

Government of India Reports Analyser



@@ -118,5 +114,4 @@ - - \ No newline at end of file + \ No newline at end of file