~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/api/tables/RIMS_Surveillance_Dtl.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.api.tables;
 
28
 
 
29
import java.sql.Date;
 
30
import java.sql.SQLException;
 
31
 
 
32
import org.hisp.dhis.integration.rims.api.RIMS_Mapping_DataElement;
 
33
 
 
34
/**
 
35
 * @author Leif Arne Storset
 
36
 * @version $Id$
 
37
 */
 
38
public class RIMS_Surveillance_Dtl
 
39
    extends PHCTable
 
40
{
 
41
    public String getDescription()
 
42
    {
 
43
        return "Disease surveillance";
 
44
    }
 
45
    public boolean isData( RIMS_PHC phc, int month, int year,
 
46
        RIMS_Mapping_DataElement mappingDataElement ) throws SQLException
 
47
    {
 
48
        String disease_code = mappingDataElement.getDisease_code();
 
49
 
 
50
        String query = "";
 
51
        query = "SELECT * FROM " + getTableName()
 
52
            + " WHERE phc_code LIKE '" + phc.getCode() + "' AND mnth = " + month
 
53
            + " AND yr = " + year + " AND disease_code LIKE '" + disease_code
 
54
            + "'";
 
55
 
 
56
        return existingData( query, null );
 
57
    }
 
58
 
 
59
    public int insertData( RIMS_PHC rimsOrgUnit,
 
60
        int month, int year, RIMS_Mapping_DataElement mappingDataElement,
 
61
        String value ) throws SQLException
 
62
    {
 
63
        String query = "INSERT INTO " + getTableName()
 
64
            + " (disease_code," + "phc_code,district_code,mnth,yr,state_code,"
 
65
            + mappingDataElement.getRimsColumn()
 
66
            + ",created_by,created_date) VALUES (?,?,?,?,?,?,?,?,?)";
 
67
        Date curDate = new Date( new java.util.Date().getTime() );
 
68
        int numberResult = 0;
 
69
        numberResult = Integer.parseInt( value );
 
70
        if ( numberResult != -1 || numberResult != 0 )
 
71
        {
 
72
            Object[] params =
 
73
            {
 
74
                mappingDataElement.getDisease_code(),
 
75
                rimsOrgUnit.getPhc_code(),
 
76
                rimsOrgUnit.getDistrict_code(),
 
77
                month,
 
78
                year,
 
79
                rimsOrgUnit.getState_code(),
 
80
                numberResult,
 
81
                "DHIS2",
 
82
                curDate
 
83
            };
 
84
 
 
85
            return executeUpdate( query, params );
 
86
        }
 
87
        return 0;
 
88
    }
 
89
 
 
90
    public int updateData( RIMS_PHC rimsOrgUnit,
 
91
        int month, int year, RIMS_Mapping_DataElement mappingDataElement,
 
92
        String value ) throws SQLException
 
93
    {
 
94
        String phc_code = rimsOrgUnit.getPhc_code();
 
95
        String query = "UPDATE "
 
96
            + getTableName()
 
97
            + " SET "
 
98
            + mappingDataElement.getRimsColumn()
 
99
            + " = ?, "
 
100
            + "updated_by = ?, updated_date = ?"
 
101
            + " WHERE phc_code = ? AND mnth = ? AND yr = ? AND disease_code = ?";
 
102
        
 
103
        Date curDate = new Date( new java.util.Date().getTime() );
 
104
        int numberResult = Integer.parseInt( value );
 
105
        if ( numberResult != -1 || numberResult != 0 )
 
106
        {
 
107
            Object[] params =
 
108
            {
 
109
                numberResult,
 
110
                "DHIS2",
 
111
                curDate,
 
112
                phc_code,
 
113
                month,
 
114
                year,
 
115
                mappingDataElement.getDisease_code()
 
116
            };
 
117
 
 
118
            return executeUpdate( query, params );
 
119
        }
 
120
        return 0;
 
121
    }
 
122
 
 
123
    public void fillInTotals()
 
124
    {
 
125
        // No totals to fill in
 
126
    }
 
127
 
 
128
    public String getTableName()
 
129
    {
 
130
        return "surveillance_dtl";
 
131
    }
 
132
 
 
133
    public void markIfComplete() throws SQLException
 
134
    {
 
135
        String query = "UPDATE "+ getTableName() +
 
136
                      " SET complete = 1" +
 
137
                      " WHERE cases IS NOT NULL" +
 
138
                      "   AND deaths IS NOT NULL";
 
139
        executeUpdate( query );
 
140
    }
 
141
    public String getDataValue( RIMS_Mapping_DataElement mappingDataElement, RIMS_PHC orgUnit, int month, int year ) throws SQLException
 
142
    {
 
143
        String getColumn = mappingDataElement.getRimsColumn();
 
144
        String query = "SELECT "+ getColumn +
 
145
                      " FROM "+ mappingDataElement.getTableName() +
 
146
                      " WHERE disease_code = ?" +
 
147
                      "   AND phc_code = ?" +
 
148
                      "   AND mnth = ?" +
 
149
                      "   AND yr = ?";
 
150
        Object[] params = { mappingDataElement.getDisease_code(),
 
151
                            orgUnit.getPhc_code(),
 
152
                            month,
 
153
                            year
 
154
        };
 
155
        return executeQuery( query, getColumn, params );
 
156
    }
 
157
}