1
package org.hisp.dhis.trackedentity.action.caseaggregation;
4
* Copyright (c) 2004-2016, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
12
* Redistributions in binary form must reproduce the above copyright notice,
13
* this list of conditions and the following disclaimer in the documentation
14
* and/or other materials provided with the distribution.
15
* Neither the name of the HISP project nor the names of its contributors may
16
* be used to endorse or promote products derived from this software without
17
* specific prior written permission.
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
import java.util.ArrayList;
32
import java.util.Collection;
33
import java.util.Collections;
34
import java.util.HashSet;
35
import java.util.List;
37
import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
38
import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
39
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
40
import org.hisp.dhis.dataelement.DataElement;
41
import org.hisp.dhis.dataset.DataSet;
42
import org.hisp.dhis.dataset.DataSetService;
43
import org.hisp.dhis.paging.ActionPagingSupport;
46
* @author Chau Thu Tran
48
* @version GetAllCaseAggregationConditionAction.java Nov 18, 2010 10:42:01 AM
50
public class GetAllCaseAggregationConditionAction
51
extends ActionPagingSupport<CaseAggregationCondition>
53
// -------------------------------------------------------------------------
55
// -------------------------------------------------------------------------
57
private CaseAggregationConditionService aggregationConditionService;
59
public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService )
61
this.aggregationConditionService = aggregationConditionService;
64
public DataSetService dataSetService;
66
public void setDataSetService( DataSetService dataSetService )
68
this.dataSetService = dataSetService;
71
// -------------------------------------------------------------------------
73
// -------------------------------------------------------------------------
75
private Integer dataSetId;
77
public void setDataSetId( Integer dataSetId )
79
this.dataSetId = dataSetId;
82
public Integer getDataSetId()
89
public void setKey( String key )
94
private Collection<CaseAggregationCondition> aggregationConditions;
96
public Collection<CaseAggregationCondition> getAggregationConditions()
98
return aggregationConditions;
101
private List<DataSet> dataSets;
103
public List<DataSet> getDataSets()
108
// -------------------------------------------------------------------------
109
// Action implementation
110
// -------------------------------------------------------------------------
113
public String execute()
116
Collection<DataSet> _datasets = new HashSet<>();
117
aggregationConditions = aggregationConditionService.getAllCaseAggregationCondition();
119
for ( CaseAggregationCondition aggCondition : aggregationConditions )
121
DataElement dataElement = aggCondition.getAggregationDataElement();
123
_datasets.addAll( dataElement.getDataSets() );
126
dataSets = new ArrayList<>( _datasets );
127
Collections.sort( dataSets, IdentifiableObjectNameComparator.INSTANCE );
129
Collection<DataElement> dataElements = ( dataSetId == null ) ? null : dataSetService.getDataSet( dataSetId ).getDataElements();
130
this.paging = createPaging( aggregationConditionService.countCaseAggregationCondition( dataElements, key ) );
131
aggregationConditions = aggregationConditionService.getCaseAggregationConditions( dataElements, key,
132
paging.getStartPos(), paging.getPageSize() );