=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientAggregateReportStore.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientAggregateReportStore.java 2013-04-02 04:33:34 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientAggregateReportStore.java 2013-05-24 04:19:07 +0000 @@ -27,14 +27,18 @@ package org.hisp.dhis.patientreport.hibernate; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.hibernate.Criteria; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; +import org.hisp.dhis.common.SharingUtils; import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; import org.hisp.dhis.patientreport.PatientAggregateReport; import org.hisp.dhis.patientreport.PatientAggregateReportStore; +import org.hisp.dhis.patientreport.PatientTabularReport; import org.hisp.dhis.user.User; /** @@ -50,34 +54,64 @@ @Override public Collection get( User user, String query, Integer min, Integer max ) { - return search( user, query, min, max ).list(); + Criteria criteria = search( query ); + + List result = new ArrayList(); + Collection reports = criteria.list(); + + for ( PatientAggregateReport report : reports ) + { + if ( SharingUtils.canRead( user, report ) ) + { + result.add( report ); + } + } + + if ( min > result.size() ) + { + min = result.size(); + } + + if ( max > result.size() ) + { + max = result.size(); + } + + return result.subList( min, max ); } + @SuppressWarnings( "unchecked" ) public int countList( User user, String query ) { - Number rs = (Number) search( user, query, null, null ).setProjection( Projections.rowCount() ).uniqueResult(); - - return rs != null ? rs.intValue() : 0; + Criteria criteria = search( query ); + + int count = 0; + Collection reports = criteria.list(); + + for ( PatientAggregateReport report : reports ) + { + if ( SharingUtils.canRead( user, report ) ) + { + count++; + } + } + + return count; } // ------------------------------------------------------------------------- // Support methods // ------------------------------------------------------------------------- - private Criteria search( User user, String query, Integer min, Integer max ) + private Criteria search( String query ) { - Criteria criteria = getCriteria( Restrictions.eq( "user", user ) ); + Criteria criteria = getCriteria(); if ( query != null ) { criteria.add( Restrictions.ilike( "name", "%" + query + "%" ) ); } - if ( min != null && max != null ) - { - criteria.setFirstResult( min ).setMaxResults( max ); - } - return criteria; } } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientTabularReportStore.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientTabularReportStore.java 2013-05-23 14:28:28 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientTabularReportStore.java 2013-05-24 04:19:07 +0000 @@ -29,12 +29,9 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; import java.util.List; import org.hibernate.Criteria; -import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.hisp.dhis.common.SharingUtils; import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; @@ -56,12 +53,7 @@ @Override public Collection get( User user, String query, Integer min, Integer max ) { - Criteria criteria = getCriteria(); - - if ( query != null ) - { - criteria.add( Restrictions.ilike( "name", "%" + query + "%" ) ); - } + Criteria criteria = search( query ); List result = new ArrayList(); Collection reports = criteria.list(); @@ -90,14 +82,9 @@ @Override public int countList( User user, String query ) { - Criteria criteria = getCriteria(); - - if ( query != null ) - { - criteria.add( Restrictions.ilike( "name", "%" + query + "%" ) ); - } - - int result = 0; + Criteria criteria = search( query ); + + int count = 0; @SuppressWarnings( "unchecked" ) Collection reports = criteria.list(); @@ -105,18 +92,18 @@ { if ( SharingUtils.canRead( user, report ) ) { - result++; + count++; } } - return result; + return count; } // ------------------------------------------------------------------------- // Support methods // ------------------------------------------------------------------------- - private Criteria search( User user, String query, Integer min, Integer max ) + private Criteria search( String query ) { Criteria criteria = getCriteria(); @@ -124,17 +111,7 @@ { criteria.add( Restrictions.ilike( "name", "%" + query + "%" ) ); } - - Iterator iterReports = criteria.list().iterator(); - - while ( iterReports.hasNext() ) - { - if ( !SharingUtils.canRead( user, iterReports.next() ) ) - { - iterReports.remove(); - } - } - + return criteria; } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2013-05-23 16:04:26 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2013-05-24 04:19:07 +0000 @@ -273,7 +273,7 @@ grid.addHeader( new GridHeader( "id", true, true ) ); grid.addHeader( new GridHeader( programStage.getReportDateDescription(), false, true ) ); - + if ( anonynousEntryForm == null || !anonynousEntryForm ) { for ( int i = level; i <= maxLevel; i++ ) @@ -282,10 +282,10 @@ grid.addHeader( new GridHeader( name, false, true ) ); } } - - if(displayOrgunitCode!=null && displayOrgunitCode) + + if ( displayOrgunitCode != null && displayOrgunitCode ) { - grid.addHeader( new GridHeader( i18n.getString("orgunit_code"), false, true ) ); + grid.addHeader( new GridHeader( i18n.getString( "orgunit_code" ), false, true ) ); } Collection deKeys = new HashSet(); @@ -888,7 +888,8 @@ private String getTabularReportSql( Boolean anonynousEntryForm, boolean count, ProgramStage programStage, List columns, Collection orgUnits, int level, int maxLevel, Date startDate, - Date endDate, boolean descOrder, Boolean completed, Boolean accessPrivateInfo, Boolean displayOrgunitCode, Integer min, Integer max ) + Date endDate, boolean descOrder, Boolean completed, Boolean accessPrivateInfo, Boolean displayOrgunitCode, + Integer min, Integer max ) { Set deKeys = new HashSet(); String selector = count ? "count(*) " : "* "; @@ -905,12 +906,12 @@ + i + ","; } } - - if( displayOrgunitCode!=null && displayOrgunitCode) + + if ( displayOrgunitCode != null && displayOrgunitCode ) { sql += "(select code from organisationunit where organisationunitid=psi.organisationunitid ) as code_,"; } - + for ( TabularReportColumn column : columns ) { if ( column.isFixedAttribute() ) @@ -921,11 +922,13 @@ { if ( column.isDateType() ) { - where += operator + column.getIdentifier() + " " + column.getOperator() + " " + column.getQuery() + " "; + where += operator + column.getIdentifier() + " " + column.getOperator() + " " + + column.getQuery() + " "; } else { - where += operator + "lower(" + column.getIdentifier() + ") " + column.getOperator() + " " + column.getQuery() + " "; + where += operator + "lower(" + column.getIdentifier() + ") " + column.getOperator() + " " + + column.getQuery() + " "; } operator = "and "; } @@ -943,12 +946,13 @@ { if ( column.isDateType() ) { - where += operator + "identifier_" + column.getIdentifier() + " " + column.getOperator() + " " + column.getQuery() + " "; + where += operator + "identifier_" + column.getIdentifier() + " " + column.getOperator() + " " + + column.getQuery() + " "; } else { - where += operator + "lower(identifier_" + column.getIdentifier() + ") " + column.getOperator() + " " + column.getQuery() - + " "; + where += operator + "lower(identifier_" + column.getIdentifier() + ") " + column.getOperator() + + " " + column.getQuery() + " "; } operator = "and "; } @@ -966,12 +970,13 @@ { if ( column.isDateType() ) { - where += operator + "attribute_" + column.getIdentifier() + " " + column.getOperator() + " " + column.getQuery() + " "; + where += operator + "attribute_" + column.getIdentifier() + " " + column.getOperator() + " " + + column.getQuery() + " "; } else { - where += operator + "lower(attribute_" + column.getIdentifier() + ") " + column.getOperator() + " " + column.getQuery() - + " "; + where += operator + "lower(attribute_" + column.getIdentifier() + ") " + column.getOperator() + + " " + column.getQuery() + " "; } operator = "and "; } @@ -990,7 +995,8 @@ if ( column.hasQuery() ) { - where += operator + "element_" + column.getIdentifier() + " " + column.getOperator() + " " + column.getQuery() + " "; + where += operator + "element_" + column.getIdentifier() + " " + column.getOperator() + " " + + column.getQuery() + " "; operator = "and "; } } @@ -1008,11 +1014,13 @@ { if ( column.isDateType() ) { - where += operator + "element_" + column.getIdentifier() + " " + column.getOperator() + " " + column.getQuery() + " "; + where += operator + "element_" + column.getIdentifier() + " " + column.getOperator() + " " + + column.getQuery() + " "; } else { - where += operator + "lower(element_" + column.getIdentifier() + ") " + column.getOperator() + " " + column.getQuery() + " "; + where += operator + "lower(element_" + column.getIdentifier() + ") " + column.getOperator() + + " " + column.getQuery() + " "; } operator = "and "; } @@ -1153,7 +1161,7 @@ if ( orgunitIds.size() == 0 ) { - sql += "(SELECT \'0\' "; + sql += "(SELECT ( cast( \'0\' as " + statementBuilder.getDoubleColumnType() + " )) "; } else { @@ -1163,7 +1171,8 @@ } else { - sql += "(SELECT " + aggregateType + "( cast( value as DOUBLE PRECISION )) "; + sql += "(SELECT " + aggregateType + "( cast( value as " + + statementBuilder.getDoubleColumnType() + " )) "; } sql += "FROM programstageinstance psi_1 "; sql += " JOIN patientdatavalue pdv_1 "; @@ -1199,9 +1208,8 @@ sql += " ) "; sql += " UNION "; } - sql = sql.substring( 0, sql.length() - 6 ); - sql += " ORDER BY orgunit asc "; + sql += ") ORDER BY orgunit asc "; if ( limit != null ) { sql += "LIMIT " + limit; === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/SaveTabularReportAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/SaveTabularReportAction.java 2013-05-23 16:04:26 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/SaveTabularReportAction.java 2013-05-24 04:19:07 +0000 @@ -200,7 +200,7 @@ { userOrganisationUnit = (userOrganisationUnit == null) ? false : userOrganisationUnit; userOrganisationUnitChildren = (userOrganisationUnitChildren == null) ? false : userOrganisationUnitChildren; - displayOrgunitCode = (displayOrgunitCode == null) ? false : displayOrgunitCode;; + displayOrgunitCode = (displayOrgunitCode == null) ? false : displayOrgunitCode;; Set orgunits = new HashSet( organisationUnitService.getOrganisationUnits( orgunitIds ) ); === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js 2013-05-23 16:16:38 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js 2013-05-24 04:19:07 +0000 @@ -1644,7 +1644,7 @@ } }), aggregateFavorite: Ext.create('Ext.data.Store', { - fields: ['id', 'name', 'lastUpdated'], + fields: ['id', 'uid', 'name', 'lastUpdated', 'access'], proxy: { type: 'ajax', reader: { @@ -3341,7 +3341,7 @@ }, success: function(r) { var sharing = Ext.decode(r.responseText), - window = TR.app.SharingWindow(sharing); + window = TR.app.SharingWindow(sharing, false); window.show(); } }); @@ -3734,6 +3734,9 @@ items: [ { iconCls: 'tr-grid-row-icon-edit', + getClass: function(value, metaData, record) { + return 'tooltip-favorite-edit' + (!record.data.access.update ? ' disabled' : ''); + }, handler: function(grid, rowIndex, colIndex, col, event) { var record = this.up('grid').store.getAt(rowIndex); nameWindow = new NameWindow(record.data.id); @@ -3741,7 +3744,35 @@ } }, { + iconCls: 'tr-grid-row-icon-sharing', + getClass: function(value, metaData, record) { + return 'tooltip-favorite-sharing' + (!record.data.access.manage ? ' disabled' : ''); + }, + handler: function(grid, rowIndex) { + var record = this.up('grid').store.getAt(rowIndex); + + if (record.data.access.manage) { + Ext.Ajax.request({ + url:TR.conf.finals.ajax.path_api + 'sharing?type=patientAggregateReport&id=' + record.data.uid, + method: 'GET', + failure: function(r) { + TR.util.mask.hideMask(); + alert(r.responseText); + }, + success: function(r) { + var sharing = Ext.decode(r.responseText), + window = TR.app.SharingWindow(sharing, true); + window.show(); + } + }); + } + } + }, + { iconCls: 'tr-grid-row-icon-delete', + getClass: function(value, metaData, record) { + return 'tooltip-favorite-overwrite' + (!record.data.access.update ? ' disabled' : ''); + }, handler: function(grid, rowIndex, colIndex, col, event) { var record = this.up('grid').store.getAt(rowIndex); @@ -4258,7 +4289,7 @@ return optionsWindow; }; - TR.app.SharingWindow = function(sharing) { + TR.app.SharingWindow = function(sharing, isAggregate) { // Objects var UserGroupRow, @@ -4306,7 +4337,7 @@ combo = Ext.create('Ext.form.field.ComboBox', { fieldLabel: isPublicAccess ? TR.i18n.public_access : obj.name, //i18n labelStyle: 'color:#333', - cls: 'dv-combo', + cls: 'tr-combo', fieldStyle: 'padding-left:5px', width: 380, labelWidth: 250, @@ -4449,6 +4480,13 @@ access: sharing.object.publicAccess }, true, !sharing.meta.allowPublicAccess)); + getURL = function(objectId) { + if(isAggregate){ + return TR.conf.finals.ajax.path_api + 'sharing?type=patientAggregateReport&id=' + objectId; + } + return TR.conf.finals.ajax.path_api + 'sharing?type=patientTabularReport&id=' + objectId; + }; + if (Ext.isArray(sharing.object.userGroupAccesses)) { for (var i = 0, userGroupRow; i < sharing.object.userGroupAccesses.length; i++) { userGroupRow = UserGroupRow(sharing.object.userGroupAccesses[i]); @@ -4485,7 +4523,7 @@ text: 'Save', handler: function() { Ext.Ajax.request({ - url: TR.conf.finals.ajax.path_api + 'sharing?type=patientTabularReport&id=' + sharing.object.id, + url: getURL(sharing.object.id), method: 'POST', headers: { 'Content-Type': 'application/json' @@ -4499,12 +4537,24 @@ ], listeners: { show: function(w) { - var pos = TR.cmp.caseBasedFavorite.window.getPosition(); - w.setPosition(pos[0] + 5, pos[1] + 5); - TR.cmp.caseBasedFavorite.window.destroyOnBlur = false; + if(isAggregate){ + var pos = TR.cmp.aggregateFavorite.window.getPosition(); + w.setPosition(pos[0] + 5, pos[1] + 5); + TR.cmp.aggregateFavorite.window.destroyOnBlur = false; + } + else { + var pos = TR.cmp.caseBasedFavorite.window.getPosition(); + w.setPosition(pos[0] + 5, pos[1] + 5); + TR.cmp.caseBasedFavorite.window.destroyOnBlur = false; + } }, destroy: function() { - TR.cmp.caseBasedFavorite.window.destroyOnBlur = true; + if(isAggregate){ + TR.cmp.aggregateFavorite.window.destroyOnBlur = true; + } + else{ + TR.cmp.caseBasedFavorite.window.destroyOnBlur = true; + } } } }); @@ -4512,7 +4562,6 @@ return window; }; - TR.viewport = Ext.create('Ext.container.Viewport', { layout: 'border', renderTo: Ext.getBody(), === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonTabularAggregateReport.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonTabularAggregateReport.vm 2013-04-09 05:48:54 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonTabularAggregateReport.vm 2013-05-24 04:19:07 +0000 @@ -1,8 +1,17 @@ #set( $programStage=$aggregateReport.programStage) { "id": "${aggregateReport.id}", + "uid": "${aggregateReport.uid}", "name": "$!encoder.jsonEncode( ${aggregateReport.name} )", "lastUpdated": "$!format.formatDate( ${aggregateReport.lastUpdated} )", + "access": + { + "manage":$security.canManage( $aggregateReport ), + "write":$security.canWrite( $aggregateReport ), + "read":$security.canRead( $aggregateReport ), + "update":$security.canUpdate( $aggregateReport ), + "delete":$security.canDelete( $aggregateReport ) + }, "programId": "${programStage.program.id}", "singleEvent": #if($programStage.program.programStages.size() == 1 )