~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to local/in/dhis-web-integration/src/main/java/org/hisp/dhis/integration/rims/util/Configuration.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2004-2008, 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
package org.hisp.dhis.integration.rims.util;
 
28
 
 
29
import java.sql.Connection;
 
30
import java.sql.SQLException;
 
31
import java.util.ArrayList;
 
32
import java.util.Collection;
 
33
import java.util.HashMap;
 
34
import java.util.List;
 
35
 
 
36
import org.hisp.dhis.integration.rims.api.RIMSTable;
 
37
import org.hisp.dhis.integration.rims.api.tables.RIMS_Aefi_Dtl;
 
38
import org.hisp.dhis.integration.rims.api.tables.RIMS_DIO_Position_Mst;
 
39
import org.hisp.dhis.integration.rims.api.tables.RIMS_Immun_Sessions_Dtl;
 
40
import org.hisp.dhis.integration.rims.api.tables.RIMS_Immun_Vaccine_Dtl;
 
41
import org.hisp.dhis.integration.rims.api.tables.RIMS_Opn_Stock_Vaccine_Dtl;
 
42
import org.hisp.dhis.integration.rims.api.tables.RIMS_Phc_Target_Dtl;
 
43
import org.hisp.dhis.integration.rims.api.tables.RIMS_Surveillance_Dtl;
 
44
import org.hisp.dhis.integration.rims.api.tables.RIMS_Vaccine_Supply_Dtl;
 
45
import org.hisp.dhis.integration.util.DataBaseConnection;
 
46
 
 
47
/**
 
48
 * Eventually this class will read configuration from an XML file.
 
49
 * 
 
50
 * @author Leif Arne Storset
 
51
 * @version $Id$
 
52
 */
 
53
public class Configuration
 
54
{
 
55
   private HashMap<String, RIMSTable> tables = new HashMap<String, RIMSTable>();
 
56
   private List<String> monthlyFields = new ArrayList<String>();
 
57
   private List<String> yearlyFields = new ArrayList<String>();
 
58
private String connectionName;
 
59
   
 
60
    public Configuration( String connectionName )
 
61
    {
 
62
        setConnectionName( connectionName );
 
63
        init();
 
64
    }
 
65
    
 
66
    public Configuration()
 
67
    {
 
68
        init();
 
69
    }
 
70
    
 
71
    private void init()
 
72
    {
 
73
        // ---------------------------------------------------------------------
 
74
        // RIMS Tables
 
75
        // ---------------------------------------------------------------------
 
76
        RIMSTable[] phcTableArray = new RIMSTable[] {
 
77
            new RIMS_Immun_Vaccine_Dtl(), new RIMS_Immun_Sessions_Dtl(),
 
78
            new RIMS_Vaccine_Supply_Dtl(), new RIMS_Aefi_Dtl(),
 
79
            new RIMS_Surveillance_Dtl(), new RIMS_Phc_Target_Dtl(),
 
80
            new RIMS_Opn_Stock_Vaccine_Dtl(), new RIMS_DIO_Position_Mst() };
 
81
        for ( RIMSTable table : phcTableArray )
 
82
        {
 
83
            tables.put( table.getTableName(), table );
 
84
            table.setConfiguration( this );
 
85
        }
 
86
        
 
87
        // ---------------------------------------------------------------------
 
88
        // Fields
 
89
        // ---------------------------------------------------------------------
 
90
        // immun_session_dtl
 
91
        monthlyFields.add( "ses_planned" );
 
92
        monthlyFields.add( "ses_held" );
 
93
        monthlyFields.add( "ses_vac_rcvd" );
 
94
        monthlyFields.add( "ses_voln_eng" );
 
95
        monthlyFields.add( "anim_hired" );
 
96
        monthlyFields.add( "undser_area" );
 
97
        monthlyFields.add( "urban_slums" );
 
98
        monthlyFields.add( "ses_held_aanganwadi" );
 
99
        monthlyFields.add( "fully_immu_infants" );
 
100
 
 
101
        // immun_vaccine_dtl
 
102
        monthlyFields.add( "preg_women" );
 
103
        monthlyFields.add( "under1year_total" );
 
104
        monthlyFields.add( "under1year_male" );
 
105
        monthlyFields.add( "under1year_female" );
 
106
        monthlyFields.add( "over1year_total" );
 
107
        monthlyFields.add( "over1year_male" );
 
108
        monthlyFields.add( "over1year_female" );
 
109
 
 
110
        // vaccine_supply_dtl
 
111
        monthlyFields.add( "opn_balance" );
 
112
        monthlyFields.add( "vaccine_rcvd" );
 
113
        monthlyFields.add( "vaccine_consd" );
 
114
        monthlyFields.add( "vaccine_unused" );
 
115
        monthlyFields.add( "vaccine_bal" );
 
116
        monthlyFields.add( "vaccine_dispd" );
 
117
        monthlyFields.add( "vaccine_consd" );
 
118
 
 
119
        // aefi_dtl
 
120
        monthlyFields.add( "during_the_mnth" );
 
121
        
 
122
        // surveillance_dtl
 
123
        monthlyFields.add( "cases" );
 
124
        monthlyFields.add( "deaths" );
 
125
        
 
126
        // dio_position_mst
 
127
        monthlyFields.add( "dio_position" );
 
128
        monthlyFields.add( "blockphc_level" );
 
129
        monthlyFields.add( "phc_level" );
 
130
        monthlyFields.add( "sub_center" );
 
131
        monthlyFields.add( "session_sites" );
 
132
        monthlyFields.add( "budget_obal" );
 
133
        monthlyFields.add( "budget_received" );
 
134
        monthlyFields.add( "budget_released" );
 
135
        monthlyFields.add( "budget_disbursed" );
 
136
        monthlyFields.add( "budget_cbal" );
 
137
        monthlyFields.add( "utilized_received" );
 
138
        monthlyFields.add( "utilized_released" );
 
139
        monthlyFields.add( "utilizedtillpre_month" );
 
140
        monthlyFields.add( "utilizedduring_month" );
 
141
        monthlyFields.add( "cuml_exp" );
 
142
        monthlyFields.add( "ret_state" );
 
143
        monthlyFields.add( "balance" );
 
144
        
 
145
        // phc_target_dtl
 
146
        yearlyFields.add( "cur_target" );
 
147
        yearlyFields.add( "lst_target" );
 
148
        yearlyFields.add( "snd_target" );
 
149
        
 
150
        // opn_stock_vaccine_dtl
 
151
        yearlyFields.add( "opening_bal" );
 
152
    }
 
153
 
 
154
    public RIMSTable getTable( String name )
 
155
    {
 
156
        RIMSTable table = tables.get( name );
 
157
        if ( table == null ) 
 
158
        {
 
159
            throw new RuntimeException( "Table "+ name +" not found");
 
160
        }
 
161
        return table;
 
162
    }
 
163
 
 
164
    public Collection<RIMSTable> getTables()
 
165
    {
 
166
        return tables.values();
 
167
    }
 
168
 
 
169
    public Connection getConnection() throws SQLException
 
170
    {
 
171
        if ( connectionName == null )
 
172
        {
 
173
            throw new IllegalStateException( "Connection name not set" );
 
174
        }
 
175
        return (new DataBaseConnection())
 
176
            .openConnection( DataBaseConnection.RIMS, connectionName );
 
177
    }
 
178
    
 
179
    public void setConnectionName( String name )
 
180
    {
 
181
        connectionName = name;
 
182
    }
 
183
    
 
184
    public String getConnectionName()
 
185
    {
 
186
        return connectionName;
 
187
    }
 
188
 
 
189
    public String getStoredBy()
 
190
    {
 
191
        return "dhis-web-integration";
 
192
    }
 
193
 
 
194
    public List<String> getMonthlyFields()
 
195
    {
 
196
        return monthlyFields;
 
197
    }
 
198
 
 
199
    public List<String> getYearlyFields()
 
200
    {
 
201
        return yearlyFields;
 
202
    }
 
203
}