~dhis2-devs-core/dhis2/dqa

« back to all changes in this revision

Viewing changes to dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dqa/DefaultDQAReportService.java

  • Committer: Harsh Atal
  • Date: 2013-06-14 12:47:22 UTC
  • Revision ID: harsh.atal@gmail.com-20130614124722-92jm2myuodhdcjbf
update

Show diffs side-by-side

added added

removed removed

Lines of Context:
818
818
        
819
819
        if ( aggIndicatorNumValue == null ) aggIndicatorNumValue = 0.0;
820
820
        
821
 
        //System.out.println( " aggIndicatorValue - >" + aggIndicatorNumValue );
 
821
        System.out.println( " aggIndicatorValue - >" + aggIndicatorNumValue );
822
822
        
823
 
        aggIndicatorNumValue = Math.round( aggIndicatorNumValue * Math.pow( 10, 2 ) )/ Math.pow( 10, 2 );
 
823
       // aggIndicatorNumValue = Math.round( aggIndicatorNumValue * Math.pow( 10, 2 ) )/ Math.pow( 10, 2 );
824
824
        
825
825
        //System.out.println( " aggIndicatorNumValue - >" + aggIndicatorNumValue );
826
826
        System.out.println("startdate="+startDate + "endDate = "+endDate);
847
847
                
848
848
            }
849
849
        }
850
 
         
 
850
         System.out.println("aggdenomin - >" + aggIndicatorDenumValue);
851
851
         result = aggIndicatorNumValue/aggIndicatorDenumValue;
852
852
        return result;
853
853
    }
1099
1099
        
1100
1100
        @Override
1101
1101
        public boolean generatechart4(  
1102
 
                        OrganisationUnit rootOrganisationUnit, Collection<OrganisationUnit> analysisOrgUnits, Date startDate, Date endDate, Indicator indicator,String chartName) {
 
1102
                        OrganisationUnit rootOrganisationUnit, Collection<OrganisationUnit> analysisOrgUnits, Date startDate, Date endDate, Indicator indicator,DataElement standardErrorDE,String chartName) {
1103
1103
                // get values for all orgunits : mean and current
1104
1104
                List<Double> values = new ArrayList<Double>();
1105
1105
                List<Double> surveyValues = new ArrayList<Double>();
 
1106
                List<Double> standardError = new ArrayList<Double>();
1106
1107
                List<String> ouNames = new ArrayList<String>();
1107
1108
                TreeMap<Double,OrganisationUnit> valueOrgUnittreeMap = new TreeMap<Double, OrganisationUnit>();
1108
1109
                TreeMap<Double,Double> valueSurveyValueTreeMap = new TreeMap<Double, Double>();
 
1110
                TreeMap<Double,Double> standardErrorTreeMap = new TreeMap<Double, Double>();
1109
1111
                
1110
1112
                Collection<OrganisationUnit> analysisOrgUnitsLocal = new ArrayList<OrganisationUnit>();
1111
1113
                analysisOrgUnitsLocal.addAll(analysisOrgUnits);
1112
1114
                //analysisOrgUnitsLocal.add(rootOrganisationUnit);
1113
 
                
 
1115
                  PeriodType periodType = periodService.getPeriodTypeByName("Yearly");
 
1116
                  Period period = periodService.getPeriod(startDate, endDate, periodType);
 
1117
                  DataElementCategoryOptionCombo decoc = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo();      
 
1118
                        
1114
1119
                double rootVal  = aggregationService.getAggregatedNumeratorValue(indicator, startDate, endDate, rootOrganisationUnit);
1115
1120
                double rootSurveyVal = getIndicatorDenominatorDataValue(indicator, startDate, endDate, rootOrganisationUnit);
 
1121
                DataValue rootDataValue =  dataValueService.getDataValue(rootOrganisationUnit, standardErrorDE, period,decoc);
1116
1122
                
 
1123
                double rootStandardError = 0.0;
 
1124
                if (rootDataValue!=null){
 
1125
                rootStandardError = Double.parseDouble(rootDataValue.getValue());
 
1126
                }
1117
1127
                // preappend root values
1118
1128
                                values.add(rootVal);
1119
1129
                                surveyValues.add(rootSurveyVal);
 
1130
                                standardError.add(rootStandardError);
1120
1131
                                ouNames.add(rootOrganisationUnit.getDisplayName());
1121
1132
                                
1122
1133
                
1123
1134
                for (OrganisationUnit organisationUnit : analysisOrgUnitsLocal){
1124
1135
                        double val  = aggregationService.getAggregatedNumeratorValue(indicator, startDate, endDate, organisationUnit);
1125
1136
                        double surveyVal = getIndicatorDenominatorDataValue(indicator, startDate, endDate, organisationUnit);
 
1137
                        DataValue dataValue =  dataValueService.getDataValue(organisationUnit, standardErrorDE, period,decoc);
1126
1138
                        
 
1139
                        double SE = 0.0;
 
1140
                        if (dataValue!=null){
 
1141
                        SE = Double.parseDouble(dataValue.getValue());
 
1142
                        }
 
1143
                
1127
1144
                        valueOrgUnittreeMap.put(val, organisationUnit);
1128
1145
                        valueSurveyValueTreeMap.put(val, surveyVal);
1129
 
                        
 
1146
                        standardErrorTreeMap.put(val, SE);
 
1147
                        System.out.println("se value="+SE);
1130
1148
                }
1131
1149
                
1132
1150
                
1133
1151
                values.addAll(valueOrgUnittreeMap.descendingMap().keySet());
1134
 
                surveyValues.addAll(valueSurveyValueTreeMap.descendingMap().values());
 
1152
                surveyValues.addAll(valueSurveyValueTreeMap.descendingMap().values());  
 
1153
                standardError.addAll(standardErrorTreeMap.descendingMap().values());
1135
1154
                
1136
1155
                for (OrganisationUnit ou : valueOrgUnittreeMap.descendingMap().values()){
1137
 
                        ouNames.add(ou.getDisplayName());
1138
 
                        
 
1156
                        ouNames.add(ou.getDisplayName());               
1139
1157
                }
1140
1158
                
1141
 
                
1142
 
                
1143
1159
                String commaSeparatedValues = commafyList(values);
1144
1160
                String commaSeparatedSurveyValues = commafyList(surveyValues);
1145
1161
                String commaSeparatedOuNames =commafyStringList(ouNames);
1146
 
                
 
1162
                String commaSeparatedStandardError = commafyList(standardError);
1147
1163
                        // pass them to r script
1148
1164
                // Rscript chart1.R commaSeparatedMeanvalues commaSeparatedCurrentValues maxMeanValue rootRatio 
1149
1165
                   String chartOutputPath = System.getenv("DHIS2_HOME") + File.separator + "dqa" + File.separator + "chartoutput" + File.separator;
1150
 
               String rScriptPath = "Rscript " + System.getenv("DHIS2_HOME") + File.separator + "dqa" + File.separator + "rscript" +  File.separator + "dqaChart4.R" + " \"" +commaSeparatedValues+"\" \""+ commaSeparatedSurveyValues + "\" \"" +commaSeparatedOuNames +"\" "+  chartOutputPath + " " + chartName;
 
1166
               String rScriptPath = "Rscript " + System.getenv("DHIS2_HOME") + File.separator + "dqa" + File.separator + "rscript" +  File.separator + "dqaChart4.R" + " \"" +commaSeparatedValues+"\" \""+ commaSeparatedSurveyValues + "\" \"" +commaSeparatedOuNames +"\" \"" +commaSeparatedStandardError+"\" "+  chartOutputPath + " " + chartName;
1151
1167
               
1152
1168
                System.out.println( "rScriptPath : "+ rScriptPath );
1153
1169
                //rScriptPath = "Rscript " + System.getenv("DHIS2_HOME") + File.separator + "fpmureports" + File.separator + "rscript" +  File.separator +  R_QUARTERLY_SCRIPT_FILE_A + " " + currentQuarterMonth3End + " " + chartOutputPath;