=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java 2011-01-12 02:26:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java 2011-03-24 03:34:53 +0000 @@ -32,6 +32,7 @@ import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.patient.Patient; import org.hisp.dhis.patientdatavalue.PatientDataValue; import org.hisp.dhis.period.Period; @@ -59,5 +60,9 @@ Collection getPatientDataValues( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit, Period period ); + Collection getPatients( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit, Period period ); + + Collection getDataElementsInCondition( String aggregationExpression ); + String getConditionDescription( String condition ); } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2011-02-28 04:40:24 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2011-03-24 03:34:53 +0000 @@ -76,7 +76,7 @@ + SEPARATOR_ID + "[0-9]*]*)" + "\\]"; private final String IS_NULL = "is null"; - + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -174,7 +174,7 @@ Period period ) { String sql = createSQL( aggregationCondition, orgunit, period ); - + Collection patientIds = aggregationConditionStore.executeSQL( sql ); return calValue( patientIds, aggregationCondition.getOperator() ); @@ -206,6 +206,23 @@ return result; } + public Collection getPatients( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit, + Period period ) + { + Collection result = new HashSet(); + + String sql = createSQL( aggregationCondition, orgunit, period ); + + Collection patientIds = aggregationConditionStore.executeSQL( sql ); + + for ( Integer patientId : patientIds ) + { + result.add( patientService.getPatient( patientId ) ); + } + + return result; + } + public String getConditionDescription( String condition ) { StringBuffer decription = new StringBuffer(); @@ -247,6 +264,38 @@ return decription.toString(); } + public Collection getDataElementsInCondition( String aggregationExpression ) + { + String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "[0-9]+" + SEPARATOR_ID + + "[0-9]+" + SEPARATOR_ID + "[0-9]+" + "\\]"; + + Collection dataElements = new HashSet(); + + // --------------------------------------------------------------------- + // parse expressions + // --------------------------------------------------------------------- + + Pattern pattern = Pattern.compile( regExp ); + + Matcher matcher = pattern.matcher( aggregationExpression ); + + while ( matcher.find() ) + { + String match = matcher.group(); + match = match.replaceAll( "[\\[\\]]", "" ); + + String[] info = match.split( SEPARATOR_OBJECT ); + String[] ids = info[1].split( SEPARATOR_ID ); + + int dataElementId = Integer.parseInt( ids[1] ); + DataElement dataElement = dataElementService.getDataElement( dataElementId ); + + dataElements.add( dataElement ); + } + + return dataElements; + } + // ------------------------------------------------------------------------- // Support Methods // ------------------------------------------------------------------------- @@ -389,53 +438,26 @@ } - private Collection getDataElementsInCondition( String aggregationExpression ) - { - String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "[0-9]+" + SEPARATOR_ID - + "[0-9]+" + SEPARATOR_ID + "[0-9]+" + "\\]"; - - Collection dataElements = new HashSet(); - - // --------------------------------------------------------------------- - // parse expressions - // --------------------------------------------------------------------- - - Pattern pattern = Pattern.compile( regExp ); - - Matcher matcher = pattern.matcher( aggregationExpression ); - - while ( matcher.find() ) - { - String match = matcher.group(); - match = match.replaceAll( "[\\[\\]]", "" ); - - String[] info = match.split( SEPARATOR_OBJECT ); - String[] ids = info[1].split( SEPARATOR_ID ); - - int dataElementId = Integer.parseInt( ids[1] ); - DataElement dataElement = dataElementService.getDataElement( dataElementId ); - - dataElements.add( dataElement ); - } - - return dataElements; - } - - private String getConditionForNotDataElement( int programStageId, int dataElementId, int optionComboId, int orgunitId, - String startDate, String endDate ) + private String getConditionForNotDataElement( int programStageId, int dataElementId, int optionComboId, + int orgunitId, String startDate, String endDate ) { return "SELECT distinct(pi.patientid) FROM programstageinstance as psi " - + "INNER JOIN programstage as ps ON psi.programstageid = ps.programstageid " - + "INNER JOIN patientdatavalue as pd ON psi.programstageinstanceid = pd.programstageinstanceid " - + "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid " - + "WHERE pd.organisationunitid = " + orgunitId + " AND ps.programstageid = " + programStageId + " " - + "AND psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' " - + "AND ( ( pd.dataelementid != " + dataElementId+ " AND pd.categoryoptioncomboid != " + optionComboId+ " ) " - + " OR ( pd.dataelementid = " + dataElementId+ " AND pd.categoryoptioncomboid != " + optionComboId+ " ) " - + " OR ( pd.dataelementid != " + dataElementId+ " AND pd.categoryoptioncomboid = " + optionComboId+ " ) )"; + + "INNER JOIN programstage as ps ON psi.programstageid = ps.programstageid " + + "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid " + + "LEFT OUTER JOIN patientdatavalue as pd ON psi.programstageinstanceid = pd.programstageinstanceid " + + "WHERE psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' " + + "AND pd.value IS NULL AND pi.patientid NOT IN ( " + + "SELECT distinct(pi.patientid) FROM programstageinstance as psi " + + "INNER JOIN programstage as ps ON psi.programstageid = ps.programstageid " + + "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid " + + "INNER JOIN patientdatavalue as pd ON psi.programstageinstanceid = pd.programstageinstanceid " + + "WHERE pd.organisationunitid = " + orgunitId + " AND ps.programstageid = " + programStageId + " " + + "AND psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' " + + "AND pd.dataelementid = " + dataElementId + " " + "AND pd.categoryoptioncomboid = " + optionComboId + + " ) "; } - + private String getConditionForDataElement( int programStageId, int dataElementId, int optionComboId, int orgunitId, String startDate, String endDate ) { === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java 2011-03-22 02:17:23 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java 2011-03-24 03:34:53 +0000 @@ -127,20 +127,6 @@ // Input & Output Parameters // ------------------------------------------------------------------------- - private int sDateLB; - - public void setSDateLB( int dateLB ) - { - sDateLB = dateLB; - } - - private int eDateLB; - - public void setEDateLB( int dateLB ) - { - eDateLB = dateLB; - } - private String facilityLB; public void setFacilityLB( String facilityLB ) @@ -161,6 +147,13 @@ { return mapDataValues; } + + private Map mapCaseAggCondition; + + public Map getMapCaseAggCondition() + { + return mapCaseAggCondition; + } // ------------------------------------------------------------------------- // Action Implementation @@ -170,7 +163,8 @@ throws Exception { mapDataValues = new HashMap(); - + mapCaseAggCondition = new HashMap(); + String storedBy = currentUserService.getCurrentUsername() + "_CAE"; // --------------------------------------------------------------------- @@ -183,7 +177,7 @@ { return SUCCESS; } - + List orgUnitList = new ArrayList(); if ( facilityLB.equals( "children" ) ) { @@ -218,12 +212,12 @@ Period startPeriod = periodGenericManager.getSelectedPeriod( PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_START, PeriodGenericManager.SESSION_KEY_BASE_PERIOD_START ); - + Period endPeriod = periodGenericManager.getSelectedPeriod( PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_END, PeriodGenericManager.SESSION_KEY_BASE_PERIOD_END ); - - periodList = getPeriodList( (CalendarPeriodType)selectedDataSet.getPeriodType(), startPeriod, endPeriod ); + + periodList = getPeriodList( (CalendarPeriodType) selectedDataSet.getPeriodType(), startPeriod, endPeriod ); // --------------------------------------------------------------------- // Aggregation @@ -250,12 +244,10 @@ double resultValue = aggregationConditionService.parseConditition( condition, orgUnit, period ); - DataValue dataValue = dataValueService - .getDataValue( orgUnit, dElement, period, optionCombo ); - + DataValue dataValue = dataValueService.getDataValue( orgUnit, dElement, period, optionCombo ); + if ( resultValue != 0 ) { - if ( dataValue == null ) { dataValue = new DataValue( dElement, period, orgUnit, "" + resultValue, storedBy, @@ -274,17 +266,19 @@ mapDataValues.put( dataValue, i18n.getString( "updated" ) + " " + message ); } + + mapCaseAggCondition.put( dataValue, condition ); } else if ( dataValue != null ) { - DataValue dvalue = new DataValue( dElement, period, orgUnit, "", storedBy, - new Date(), null, optionCombo ); - dvalue.setValue( dataValue.getValue() + " " + i18n.getString( "old_value" ) ); - - dataValueService.deleteDataValue( dataValue ); - - mapDataValues.put( dvalue, i18n.getString( "deleted" ) + " " + message ); + DataValue dvalue = new DataValue( dElement, period, orgUnit, "", storedBy, new Date(), + null, optionCombo ); + dvalue.setValue( dataValue.getValue() + " " + i18n.getString( "old_value" ) ); + + dataValueService.deleteDataValue( dataValue ); + + mapDataValues.put( dvalue, i18n.getString( "deleted" ) + " " + message ); } }// PeriodList end @@ -319,21 +313,21 @@ private List getPeriodList( CalendarPeriodType periodType, Period startPeriod, Period endPeriod ) { - Period period = periodType.createPeriod( startPeriod.getStartDate()); + Period period = periodType.createPeriod( startPeriod.getStartDate() ); List periods = new ArrayList(); - + periods.add( period ); - - while ( period.getEndDate().before( endPeriod.getEndDate() )) + + while ( period.getEndDate().before( endPeriod.getEndDate() ) ) { - period = periodType.getNextPeriod( period ) ; + period = periodType.getNextPeriod( period ); periods.add( period ); } - period = periodType.createPeriod( endPeriod.getStartDate() ) ; + period = periodType.createPeriod( endPeriod.getStartDate() ); periods.add( period ); - + return periods; } === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultDetailsAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultDetailsAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultDetailsAction.java 2011-03-24 03:34:53 +0000 @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2004-2009, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.caseentry.action.caseaggregation; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.hisp.dhis.caseaggregation.CaseAggregationCondition; +import org.hisp.dhis.caseaggregation.CaseAggregationConditionService; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.patient.Patient; +import org.hisp.dhis.patientdatavalue.PatientDataValue; +import org.hisp.dhis.patientdatavalue.PatientDataValueService; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Chau Thu Tran + * + * @version CaseAggregationResultDetailsAction.java Mar 23, 2011 10:42:51 AM $ + */ +public class CaseAggregationResultDetailsAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private OrganisationUnitService organisationUnitService; + + private PeriodService periodService; + + private CaseAggregationConditionService aggregationConditionService; + + private PatientDataValueService patientDataValueService; + + // ------------------------------------------------------------------------- + // Input and Output + // ------------------------------------------------------------------------- + + private Integer orgunitId; + + private Integer aggregationConditionId; + + private Integer periodId; + + private Map> mapPatients; + + // ------------------------------------------------------------------------- + // Getters && Setters + // ------------------------------------------------------------------------- + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + public void setPatientDataValueService( PatientDataValueService patientDataValueService ) + { + this.patientDataValueService = patientDataValueService; + } + + public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService ) + { + this.aggregationConditionService = aggregationConditionService; + } + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + public Map> getMapPatients() + { + return mapPatients; + } + + public void setOrgunitId( Integer orgunitId ) + { + this.orgunitId = orgunitId; + } + + public void setAggregationConditionId( Integer aggregationConditionId ) + { + this.aggregationConditionId = aggregationConditionId; + } + + public void setPeriodId( Integer periodId ) + { + this.periodId = periodId; + } + + // ------------------------------------------------------------------------- + // Action Implementation + // ------------------------------------------------------------------------- + + @Override + public String execute() + throws Exception + { + mapPatients = new HashMap>(); + + OrganisationUnit orgunit = organisationUnitService.getOrganisationUnit( orgunitId ); + + Period period = periodService.getPeriod( periodId ); + + CaseAggregationCondition aggCondition = aggregationConditionService + .getCaseAggregationCondition( aggregationConditionId ); + + Collection patients = aggregationConditionService.getPatients( aggCondition, orgunit, period ); + + for ( Patient patient : patients ) + { + Collection dataElements = aggregationConditionService.getDataElementsInCondition( aggCondition + .getAggregationExpression() ); + + Collection dataValues = patientDataValueService.getPatientDataValues( patient, + dataElements, period.getStartDate(), period.getEndDate() ); + + mapPatients.put( patient, dataValues ); + } + return SUCCESS; + } + +} === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2011-03-22 02:17:23 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2011-03-24 03:34:53 +0000 @@ -358,6 +358,7 @@ + + + + + + + + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2011-03-22 02:17:23 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2011-03-24 03:34:53 +0000 @@ -238,20 +238,25 @@ /main.vm /dhis-web-caseentry/caseAggregationResult.vm - /dhis-web-caseentry/menu.vm + /dhis-web-caseentry/menu.vm + javascript/caseagg.js,javascript/date.js,javascript/caseAggregationForm.js + + + + /popup.vm + /dhis-web-caseentry/caseAggregationResultDetails.vm - - /dhis-web-commons/ajax/jsonPeriods.vm - + class="org.hisp.dhis.caseentry.state.NextPeriodsAction"> + /dhis-web-commons/ajax/jsonPeriods.vm + - - - /dhis-web-commons/ajax/jsonPeriods.vm - + + /dhis-web-commons/ajax/jsonPeriods.vm + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm 2010-12-03 06:08:58 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm 2011-03-24 03:34:53 +0000 @@ -4,24 +4,33 @@

#if( $mapDataValues.keySet().size() > 0 ) - - - - - - - - #set ( $keys = $mapDataValues.keySet() ) - #set ($index = 1) - #foreach( $key in $keys) - - - - - - - #set ($index = $index + 1) - #end +
#$i18n.getString('name')$i18n.getString('value')$i18n.getString('status')
$index$key.dataElement.getName()$key.getValue()$mapDataValues.get($key)
+ + + + + + + + + + + + + + #set ( $keys = $mapDataValues.keySet() ) + #set ($index = 1) + + #foreach( $key in $keys) + + + + + + + #set ($index = $index + 1) + #end +
#$i18n.getString('name')$i18n.getString('value')$i18n.getString('status')
$index$key.dataElement.getName()$key.getValue()$mapDataValues.get($key)
#else === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResultDetails.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResultDetails.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResultDetails.vm 2011-03-24 03:34:53 +0000 @@ -0,0 +1,34 @@ + + + + + + + + + #foreach( $patient in $mapPatients.keySet()) + + + + + + + + #set($dataValues = $mapPatients.get($patient) ) + #if( $!dataValues ) + #foreach( $dataValue in $dataValues ) + + + + + + + #end + #else + + + + #end + #end + +
$i18n.getString('full_name')$i18n.getString('program_stage')$i18n.getString('data_element')$i18n.getString('value')
$patient.getFullName()
$dataValue.programStageInstance.programStage.name$dataValue.dataElement.name$dataValue.value
\ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseAggregationForm.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseAggregationForm.js 2011-03-22 09:35:27 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseAggregationForm.js 2011-03-24 03:34:53 +0000 @@ -14,6 +14,7 @@ validation2( 'caseAggregationForm', function(form) { validationCaseAggregation(); }, { + 'rules': rules }) }); === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js 2011-03-22 02:17:23 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js 2011-03-24 03:34:53 +0000 @@ -111,3 +111,22 @@ setMessage(message.firstChild.nodeValue); } } + +function viewResultDetails( orgunitId, periodId, aggregationConditionId ) +{ + var url = 'caseAggregationResultDetails.action?'; + url+= 'orgunitId=' + orgunitId; + url+= '&periodId=' + periodId; + url+= '&aggregationConditionId=' + aggregationConditionId; + + $('#contentDetails').dialog('destroy').remove(); + $('
' ).load(url).dialog({ + title: '', + maximize: true, + closable: true, + modal:true, + overlay:{background:'#000000', opacity:0.1}, + width: 800, + height: 400 + }); +}