1
package org.hisp.dhis.pdf.impl;
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.system.util.PDFUtils.addTableToDocument;
31
import static org.hisp.dhis.system.util.PDFUtils.getCell;
32
import static org.hisp.dhis.system.util.PDFUtils.getHeader3Cell;
33
import static org.hisp.dhis.system.util.PDFUtils.getItalicCell;
34
import static org.hisp.dhis.system.util.PDFUtils.getPdfPTable;
35
import static org.hisp.dhis.system.util.PDFUtils.getTextCell;
37
import java.io.OutputStream;
38
import java.util.HashMap;
41
import org.hisp.dhis.dataelement.DataElement;
42
import org.hisp.dhis.dataelement.DataElementService;
43
import org.hisp.dhis.indicator.Indicator;
44
import org.hisp.dhis.indicator.IndicatorService;
45
import org.hisp.dhis.organisationunit.OrganisationUnit;
46
import org.hisp.dhis.organisationunit.OrganisationUnitService;
47
import org.hisp.dhis.pdf.PdfService;
48
import org.hisp.dhis.system.util.PDFUtils;
50
import com.lowagie.text.Document;
51
import com.lowagie.text.pdf.PdfPTable;
54
* @author Lars Helge Overland
57
public class ItextPdfService
60
// -------------------------------------------------------------------------
62
// -------------------------------------------------------------------------
64
private DataElementService dataElementService;
66
public void setDataElementService( DataElementService dataElementService )
68
this.dataElementService = dataElementService;
71
private IndicatorService indicatorService;
73
public void setIndicatorService( IndicatorService indicatorService )
75
this.indicatorService = indicatorService;
78
private OrganisationUnitService organisationUnitService;
80
public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
82
this.organisationUnitService = organisationUnitService;
85
// -------------------------------------------------------------------------
86
// PdfService implementation
87
// -------------------------------------------------------------------------
89
public void writeAllDataElements( OutputStream outputStream )
91
Document document = PDFUtils.openDocument( outputStream );
93
for ( DataElement element : dataElementService.getAllDataElements() )
95
PdfPTable table = getPdfPTable( true, 0.40f, 0.60f );
97
table.addCell( getHeader3Cell( element.getName(), 2 ) );
99
table.addCell( getCell( 2, 15 ) );
101
table.addCell( getItalicCell( "Short name", 1 ) );
102
table.addCell( getTextCell( element.getShortName() ) );
104
table.addCell( getItalicCell( "Alternative name", 1 ) );
105
table.addCell( getTextCell( element.getAlternativeName() ) );
107
table.addCell( getItalicCell( "Code", 1 ) );
108
table.addCell( getTextCell( element.getCode() ) );
110
table.addCell( getItalicCell( "Description", 1 ) );
111
table.addCell( getTextCell( element.getDescription() ) );
113
table.addCell( getItalicCell( "Active", 1 ) );
114
table.addCell( getTextCell( getBoolean().get( element.isActive() ) ) );
116
table.addCell( getItalicCell( "Type", 1 ) );
117
table.addCell( getTextCell( getType().get( element.getType() ) ) );
119
table.addCell( getItalicCell( "Aggregaton operator", 1 ) );
120
table.addCell( getTextCell( getAggregationOperator().get( element.getAggregationOperator() ) ) );
122
table.addCell( getCell( 2, 30 ) );
124
addTableToDocument( document, table );
127
PDFUtils.closeDocument( document );
130
public void writeAllIndicators( OutputStream outputStream )
132
Document document = PDFUtils.openDocument( outputStream );
134
for ( Indicator indicator : indicatorService.getAllIndicators() )
136
PdfPTable table = getPdfPTable( true, 0.40f, 0.60f );
138
table.addCell( getHeader3Cell( indicator.getName(), 2 ) );
140
table.addCell( getCell( 2, 15 ) );
142
table.addCell( getItalicCell( "Short name", 1 ) );
143
table.addCell( getTextCell( indicator.getShortName() ) );
145
table.addCell( getItalicCell( "Alternative name", 1 ) );
146
table.addCell( getTextCell( indicator.getAlternativeName() ) );
148
table.addCell( getItalicCell( "Code", 1 ) );
149
table.addCell( getTextCell( indicator.getCode() ) );
151
table.addCell( getItalicCell( "Description", 1 ) );
152
table.addCell( getTextCell( indicator.getDescription() ) );
154
table.addCell( getItalicCell( "Annualized", 1 ) );
155
table.addCell( getTextCell( getBoolean().get( indicator.getAnnualized() ) ) );
157
table.addCell( getItalicCell( "Indicator type", 1 ) );
158
table.addCell( getTextCell( indicator.getIndicatorType().getName() ) );
160
table.addCell( getItalicCell( "Numerator description", 1 ) );
161
table.addCell( getTextCell( indicator.getNumeratorDescription() ) );
163
table.addCell( getItalicCell( "Denominator description", 1 ) );
164
table.addCell( getTextCell( indicator.getDenominatorDescription() ) );
166
table.addCell( getCell( 2, 30 ) );
168
addTableToDocument( document, table );
171
PDFUtils.closeDocument( document );
174
public void writeAllOrganisationUnits( OutputStream outputStream )
176
Document document = PDFUtils.openDocument( outputStream );
178
for ( OrganisationUnit unit : organisationUnitService.getAllOrganisationUnits() )
180
PdfPTable table = getPdfPTable( true, 0.40f, 0.60f );
182
table.addCell( getHeader3Cell( unit.getName(), 2 ) );
184
table.addCell( getCell( 2, 15 ) );
186
table.addCell( getItalicCell( "Short name", 1 ) );
187
table.addCell( getTextCell( unit.getShortName() ) );
189
table.addCell( getItalicCell( "Code", 1 ) );
190
table.addCell( getTextCell( unit.getCode() ) );
192
table.addCell( getItalicCell( "Opening date", 1 ) );
193
table.addCell( getTextCell( unit.getOpeningDate() != null ? unit.getOpeningDate().toString() : "" ) );
195
table.addCell( getItalicCell( "Closed date", 1 ) );
196
table.addCell( getTextCell( unit.getClosedDate() != null ? unit.getClosedDate().toString() : "" ) );
198
table.addCell( getItalicCell( "Active", 1 ) );
199
table.addCell( getTextCell( getBoolean().get( unit.isActive() ) ) );
201
table.addCell( getItalicCell( "Comment", 1 ) );
202
table.addCell( getTextCell( unit.getComment() ) );
204
table.addCell( getCell( 2, 30 ) );
206
addTableToDocument( document, table );
209
PDFUtils.closeDocument( document );
212
// -------------------------------------------------------------------------
213
// Supportive methods
214
// -------------------------------------------------------------------------
216
private Map<Boolean, String> getBoolean()
218
Map<Boolean, String> map = new HashMap<Boolean, String>();
219
map.put( true, "Yes" );
220
map.put( false, "No" );
224
private Map<String, String> getType()
226
Map<String, String> map = new HashMap<String, String>();
227
map.put( DataElement.TYPE_STRING, "Text" );
228
map.put( DataElement.TYPE_INT, "Number" );
229
map.put( DataElement.TYPE_BOOL, "Yes/No" );
233
private Map<String, String> getAggregationOperator()
235
Map<String, String> map = new HashMap<String, String>();
236
map.put( DataElement.AGGREGATION_OPERATOR_SUM, "Sum" );
237
map.put( DataElement.AGGREGATION_OPERATOR_AVERAGE, "Average" );
238
map.put( DataElement.AGGREGATION_OPERATOR_COUNT, "Count" );