1
package org.hisp.dhis.de.action;
4
* Copyright (c) 2004-2007, 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.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import static org.hisp.dhis.options.SystemSettingManager.KEY_ZERO_VALUE_SAVE_MODE;
32
import java.util.ArrayList;
33
import java.util.Collection;
34
import java.util.HashMap;
35
import java.util.List;
38
import org.hisp.dhis.dataelement.CalculatedDataElement;
39
import org.hisp.dhis.dataelement.DataElement;
40
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
41
import org.hisp.dhis.dataset.DataEntryForm;
42
import org.hisp.dhis.dataset.DataEntryFormService;
43
import org.hisp.dhis.dataset.DataSet;
44
import org.hisp.dhis.datavalue.DataValue;
45
import org.hisp.dhis.datavalue.DataValueService;
46
import org.hisp.dhis.de.comments.StandardCommentsManager;
47
import org.hisp.dhis.de.screen.DataEntryScreenManager;
48
import org.hisp.dhis.de.state.SelectedStateManager;
49
import org.hisp.dhis.i18n.I18n;
50
import org.hisp.dhis.minmax.MinMaxDataElement;
51
import org.hisp.dhis.minmax.MinMaxDataElementStore;
52
import org.hisp.dhis.options.SystemSettingManager;
53
import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler;
54
import org.hisp.dhis.order.manager.DataElementOrderManager;
55
import org.hisp.dhis.organisationunit.OrganisationUnit;
56
import org.hisp.dhis.period.Period;
58
import com.opensymphony.xwork.Action;
61
* @author Torgeir Lorange Ostby
62
* @version $Id: FormAction.java 6216 2008-11-06 18:06:42Z eivindwa $
64
public class FormAction
67
// -------------------------------------------------------------------------
69
// -------------------------------------------------------------------------
71
private SystemSettingManager systemSettingManager;
73
public void setSystemSettingManager( SystemSettingManager systemSettingManager )
75
this.systemSettingManager = systemSettingManager;
78
private DataElementOrderManager dataElementOrderManager;
80
public void setDataElementOrderManager( DataElementOrderManager dataElementOrderManager )
82
this.dataElementOrderManager = dataElementOrderManager;
85
private DataValueService dataValueService;
87
public void setDataValueService( DataValueService dataValueService )
89
this.dataValueService = dataValueService;
92
private DataEntryFormService dataEntryFormService;
94
public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
96
this.dataEntryFormService = dataEntryFormService;
99
private StandardCommentsManager standardCommentsManager;
101
public void setStandardCommentsManager( StandardCommentsManager standardCommentsManager )
103
this.standardCommentsManager = standardCommentsManager;
106
private MinMaxDataElementStore minMaxDataElementStore;
108
public void setMinMaxDataElementStore( MinMaxDataElementStore minMaxDataElementStore )
110
this.minMaxDataElementStore = minMaxDataElementStore;
113
private SelectedStateManager selectedStateManager;
115
public void setSelectedStateManager( SelectedStateManager selectedStateManager )
117
this.selectedStateManager = selectedStateManager;
120
private DataEntryScreenManager dataEntryScreenManager;
122
public void setDataEntryScreenManager( DataEntryScreenManager dataEntryScreenManager )
124
this.dataEntryScreenManager = dataEntryScreenManager;
129
public void setI18n( I18n i18n )
134
// -------------------------------------------------------------------------
135
// DisplayPropertyHandler
136
// -------------------------------------------------------------------------
138
private DisplayPropertyHandler displayPropertyHandler;
140
public void setDisplayPropertyHandler( DisplayPropertyHandler displayPropertyHandler )
142
this.displayPropertyHandler = displayPropertyHandler;
145
// -------------------------------------------------------------------------
147
// -------------------------------------------------------------------------
149
private List<DataElement> orderedDataElements = new ArrayList<DataElement>();
151
public List<DataElement> getOrderedDataElements()
153
return orderedDataElements;
156
private Map<Integer, DataValue> dataValueMap;
158
public Map<Integer, DataValue> getDataValueMap()
163
private Map<CalculatedDataElement,Integer> calculatedValueMap;
165
public Map<CalculatedDataElement,Integer> getCalculatedValueMap()
167
return calculatedValueMap;
170
private List<String> standardComments;
172
public List<String> getStandardComments()
174
return standardComments;
177
private Map<String, String> dataElementTypeMap;
179
public Map<String, String> getDataElementTypeMap()
181
return dataElementTypeMap;
184
private Map<Integer, MinMaxDataElement> minMaxMap;
186
public Map<Integer, MinMaxDataElement> getMinMaxMap()
191
private Integer integer = 0;
193
public Integer getInteger()
198
private Boolean cdeFormExists;
200
private DataEntryForm dataEntryForm;
202
public DataEntryForm getDataEntryForm()
204
return this.dataEntryForm;
207
private String customDataEntryFormCode;
209
public String getCustomDataEntryFormCode()
211
return this.customDataEntryFormCode;
214
private Boolean zeroValueSaveMode;
216
public Boolean getZeroValueSaveMode()
218
return zeroValueSaveMode;
221
// -------------------------------------------------------------------------
223
// -------------------------------------------------------------------------
225
private Integer selectedDataSetId;
227
public void setSelectedDataSetId( Integer selectedDataSetId )
229
this.selectedDataSetId = selectedDataSetId;
232
public Integer getSelectedDataSetId()
234
return selectedDataSetId;
237
private Integer selectedPeriodIndex;
239
public void setSelectedPeriodIndex( Integer selectedPeriodIndex )
241
this.selectedPeriodIndex = selectedPeriodIndex;
244
public Integer getSelectedPeriodIndex()
246
return selectedPeriodIndex;
249
private String disabled = " ";
251
// -------------------------------------------------------------------------
252
// Action implementation
253
// -------------------------------------------------------------------------
255
public String execute()
258
zeroValueSaveMode = (Boolean) systemSettingManager.getSystemSetting( KEY_ZERO_VALUE_SAVE_MODE, false );
260
OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
262
DataSet dataSet = selectedStateManager.getSelectedDataSet();
264
Period period = selectedStateManager.getSelectedPeriod();
266
if ( dataSet.getLockedPeriods().contains( period ) )
268
disabled = "disabled";
271
Collection<DataElement> dataElements = dataSet.getDataElements();
273
if ( dataElements.size() == 0 )
278
Collection<DataElementCategoryOptionCombo> defaultOptionCombo = dataElements.iterator().next().getCategoryCombo().getOptionCombos();
280
// ---------------------------------------------------------------------
281
// Get the min/max values
282
// ---------------------------------------------------------------------
284
Collection<MinMaxDataElement> minMaxDataElements = minMaxDataElementStore.getMinMaxDataElements(
285
organisationUnit, dataElements );
287
minMaxMap = new HashMap<Integer, MinMaxDataElement>( minMaxDataElements.size() );
289
for ( MinMaxDataElement minMaxDataElement : minMaxDataElements )
291
minMaxMap.put( minMaxDataElement.getDataElement().getId(), minMaxDataElement );
294
// ---------------------------------------------------------------------
295
// Get the DataValues and create a map
296
// ---------------------------------------------------------------------
298
Collection<DataValue> dataValues = dataValueService.getDataValues( organisationUnit, period, dataElements, defaultOptionCombo );
300
dataValueMap = new HashMap<Integer, DataValue>( dataValues.size() );
302
for ( DataValue dataValue : dataValues )
304
dataValueMap.put( dataValue.getDataElement().getId(), dataValue );
307
// ---------------------------------------------------------------------
308
// Prepare values for unsaved CalculatedDataElements
309
// ---------------------------------------------------------------------
311
calculatedValueMap = dataEntryScreenManager.populateValuesForCalculatedDataElements( organisationUnit, dataSet, period );
313
// ---------------------------------------------------------------------
314
// Make the standard comments available
315
// ---------------------------------------------------------------------
317
standardComments = standardCommentsManager.getStandardComments();
319
// ---------------------------------------------------------------------
320
// Make the DataElement types available
321
// ---------------------------------------------------------------------
323
dataElementTypeMap = new HashMap<String, String>();
324
dataElementTypeMap.put( DataElement.TYPE_BOOL, i18n.getString( "yes_no" ) );
325
dataElementTypeMap.put( DataElement.TYPE_INT, i18n.getString( "number" ) );
326
dataElementTypeMap.put( DataElement.TYPE_STRING, i18n.getString( "text" ) );
328
// ---------------------------------------------------------------------
329
// Get the custom data entry form (if any)
330
// ---------------------------------------------------------------------
332
dataEntryForm = dataEntryFormService.getDataEntryFormByDataSet( dataSet );
333
cdeFormExists = ( dataEntryForm != null );
337
customDataEntryFormCode = dataEntryScreenManager.populateCustomDataEntryScreen( dataEntryForm.getHtmlCode(), dataValues, calculatedValueMap, minMaxMap, disabled, i18n );
340
// ---------------------------------------------------------------------
341
// Working on the display of dataelements
342
// ---------------------------------------------------------------------
344
orderedDataElements = dataElementOrderManager.getOrderedDataElements( dataSet );
346
displayPropertyHandler.handle( orderedDataElements );