~dhis2-devs-core/dhis2/dhis2-patient-tz

« back to all changes in this revision

Viewing changes to local/tz/dhis-web-caseentry-tz/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateReportAction.java

  • Committer: John Francis Mukulu
  • Date: 2011-08-09 06:36:18 UTC
  • mfrom: (4244.1.21 dhis2)
  • Revision ID: john.f.mukulu@gmail.com-20110809063618-wad1pcc9fd1mnc6k
[merge]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2004-2009, University of Oslo
3
 
 * All rights reserved.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions are met:
7
 
 * * Redistributions of source code must retain the above copyright notice, this
8
 
 *   list of conditions and the following disclaimer.
9
 
 * * Redistributions in binary form must reproduce the above copyright notice,
10
 
 *   this list of conditions and the following disclaimer in the documentation
11
 
 *   and/or other materials provided with the distribution.
12
 
 * * Neither the name of the HISP project nor the names of its contributors may
13
 
 *   be used to endorse or promote products derived from this software without
14
 
 *   specific prior written permission.
15
 
 *
16
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23
 
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 
 */
27
 
 
28
 
package org.hisp.dhis.caseentry.action.report;
29
 
 
30
 
import java.util.ArrayList;
31
 
import java.util.Collection;
32
 
import java.util.Date;
33
 
import java.util.HashMap;
34
 
import java.util.Map;
35
 
 
36
 
import org.hisp.dhis.i18n.I18nFormat;
37
 
import org.hisp.dhis.organisationunit.OrganisationUnit;
38
 
import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
39
 
import org.hisp.dhis.paging.ActionPagingSupport;
40
 
import org.hisp.dhis.program.Program;
41
 
import org.hisp.dhis.program.ProgramInstance;
42
 
import org.hisp.dhis.program.ProgramInstanceService;
43
 
import org.hisp.dhis.program.ProgramService;
44
 
import org.hisp.dhis.program.ProgramStageInstance;
45
 
import org.hisp.dhis.program.ProgramStageInstanceService;
46
 
 
47
 
/**
48
 
 * @author Abyot Asalefew Gizaw
49
 
 * @version $Id$
50
 
 */
51
 
public class GenerateReportAction
52
 
    extends ActionPagingSupport<ProgramInstance>
53
 
{
54
 
    /**
55
 
     * Determines if a de-serialized file is compatible with this class.
56
 
     */
57
 
    private static final long serialVersionUID = 3785792832775238394L;
58
 
 
59
 
    public static final String RED = "#ff0000";
60
 
 
61
 
    public static final String YELLOW = "#ffff00";
62
 
 
63
 
    // -------------------------------------------------------------------------
64
 
    // Dependencies
65
 
    // -------------------------------------------------------------------------
66
 
 
67
 
    private OrganisationUnitSelectionManager selectionManager;
68
 
 
69
 
    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
70
 
    {
71
 
        this.selectionManager = selectionManager;
72
 
    }
73
 
 
74
 
    private ProgramService programService;
75
 
 
76
 
    public void setProgramService( ProgramService programService )
77
 
    {
78
 
        this.programService = programService;
79
 
    }
80
 
 
81
 
    private ProgramInstanceService programInstanceService;
82
 
 
83
 
    public void setProgramInstanceService( ProgramInstanceService programInstanceService )
84
 
    {
85
 
        this.programInstanceService = programInstanceService;
86
 
    }
87
 
 
88
 
    private ProgramStageInstanceService programStageInstanceService;
89
 
 
90
 
    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
91
 
    {
92
 
        this.programStageInstanceService = programStageInstanceService;
93
 
    }
94
 
 
95
 
    private I18nFormat format;
96
 
 
97
 
    public void setFormat( I18nFormat format )
98
 
    {
99
 
        this.format = format;
100
 
    }
101
 
 
102
 
    // -------------------------------------------------------------------------
103
 
    // Input/output
104
 
    // -------------------------------------------------------------------------
105
 
 
106
 
    private Integer programId;
107
 
 
108
 
    public void setProgramId( Integer programId )
109
 
    {
110
 
        this.programId = programId;
111
 
    }
112
 
 
113
 
    private String startDate;
114
 
 
115
 
    public void setStartDate( String startDate )
116
 
    {
117
 
        this.startDate = startDate;
118
 
    }
119
 
 
120
 
    private String endDate;
121
 
 
122
 
    public void setEndDate( String endDate )
123
 
    {
124
 
        this.endDate = endDate;
125
 
    }
126
 
 
127
 
    private OrganisationUnit organisationUnit;
128
 
 
129
 
    public OrganisationUnit getOrganisationUnit()
130
 
    {
131
 
        return organisationUnit;
132
 
    }
133
 
 
134
 
    Collection<ProgramInstance> programInstances = new ArrayList<ProgramInstance>();
135
 
 
136
 
    public Collection<ProgramInstance> getProgramInstances()
137
 
    {
138
 
        return programInstances;
139
 
    }
140
 
 
141
 
    private Map<Integer, String> colorMap = new HashMap<Integer, String>();
142
 
 
143
 
    public Map<Integer, String> getColorMap()
144
 
    {
145
 
        return colorMap;
146
 
    }
147
 
 
148
 
    private Program program;
149
 
 
150
 
    public Program getProgram()
151
 
    {
152
 
        return program;
153
 
    }
154
 
 
155
 
    // -------------------------------------------------------------------------
156
 
    // Action implementation
157
 
    // -------------------------------------------------------------------------
158
 
 
159
 
    public String execute()
160
 
        throws Exception
161
 
    {
162
 
        organisationUnit = selectionManager.getSelectedOrganisationUnit();
163
 
 
164
 
        program = programService.getProgram( programId );
165
 
 
166
 
        Date sDate = format.parseDate( startDate );
167
 
 
168
 
        Date eDate = format.parseDate( endDate );
169
 
 
170
 
        // ---------------------------------------------------------------------
171
 
        // Program instances for the selected program
172
 
        // ---------------------------------------------------------------------
173
 
 
174
 
        int total = programInstanceService.countProgramInstances( program, organisationUnit, sDate, eDate );
175
 
 
176
 
        this.paging = createPaging( total );
177
 
 
178
 
        programInstances = programInstanceService.getProgramInstances( program, organisationUnit, sDate, eDate, paging
179
 
            .getStartPos(), paging.getPageSize() );
180
 
 
181
 
        Collection<ProgramStageInstance> programStageInstances = new ArrayList<ProgramStageInstance>();
182
 
 
183
 
        for ( ProgramInstance programInstance : programInstances )
184
 
        {
185
 
            programStageInstances.addAll( programInstance.getProgramStageInstances() );
186
 
        }
187
 
 
188
 
        colorMap = programStageInstanceService.colorProgramStageInstances( programStageInstances );
189
 
 
190
 
        return SUCCESS;
191
 
    }
192
 
}