2
* Copyright (c) 2004-2008, University of Oslo
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.
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.
27
package org.hisp.dhis.integration.rims.api.tables;
29
import java.sql.SQLException;
30
import org.hisp.dhis.integration.rims.api.RIMS_Mapping_DataElement;
33
* @author Leif Arne Storset
36
public class RIMS_Immun_Vaccine_Dtl
39
public String getDescription()
41
return "Immunization statistics";
44
public String getTableName()
46
return "immun_vaccine_dtl";
49
public void fillInTotals()
52
String query = "UPDATE " + getTableName()
53
+ " SET under1year_total = under1year_male + under1year_female"
54
+ " WHERE under1year_male IS NOT NULL AND under1year_female IS NOT NULL";
55
super.executeUpdate( query );
57
query = "UPDATE " + getTableName()
58
+ " SET over1year_total = over1year_male + over1year_female" +
59
" WHERE over1year_male IS NOT NULL AND over1year_female IS NOT NULL";
60
super.executeUpdate( query );
63
public boolean isData( RIMS_PHC phc, int month, int year,
64
RIMS_Mapping_DataElement mappingDataElement ) throws SQLException
66
String vac_code = mappingDataElement.getVaccine_code();
67
String antigen = mappingDataElement.getAntigen();
69
String query = "SELECT * FROM " + getTableName() + " WHERE phc_code LIKE '" + phc.getCode()
70
+ "' AND mnth = " + month + " AND yr = " + year + " AND vaccine_code LIKE '" + vac_code + "' "
71
+ " AND antigen LIKE '" + antigen + "'";
73
return existingData( query, null );
76
public int updateData( RIMS_PHC rimsOrgUnit, int month, int year,
77
RIMS_Mapping_DataElement mappingDataElement, String resValue ) throws SQLException
79
String vac_code = mappingDataElement.getVaccine_code();
80
String antigen = mappingDataElement.getAntigen();
81
String phc_code = rimsOrgUnit.getPhc_code();
83
String update = "UPDATE " + getTableName() + " SET " + mappingDataElement.getRimsColumn() + " = ? "
84
+ ", updated_by = ?" + " WHERE phc_code LIKE '" + phc_code + "' AND mnth = " + month + " AND yr = " + year
85
+ " AND vaccine_code LIKE '" + vac_code + "' " + " AND antigen LIKE '" + antigen + "'";
87
int numberResult = Integer.parseInt( resValue );
89
if ( numberResult != -1 || numberResult != 0 )
91
Object[] params = { numberResult, "DHIS2" };
92
return executeUpdate( update, params );
96
throw new RuntimeException( "No data available for data element "+
97
mappingDataElement.getDhisExpression() );
101
public int insertData( RIMS_PHC rimsOrgUnit, int month,
102
int year, RIMS_Mapping_DataElement mappingDataElement, String resValue ) throws SQLException
104
String vac_code = mappingDataElement.getVaccine_code();
105
String antigen = mappingDataElement.getAntigen();
107
String insert = "INSERT INTO "
109
+ " (vaccine_code, antigen, phc_code, district_code, mnth, yr, state_code, "
110
+ mappingDataElement.getRimsColumn() + ", created_by)"
111
+ " VALUES (?,?,?,?,?,?,?,?,?)";
113
int numberResult = Integer.parseInt( resValue );
115
if ( numberResult != -1 || numberResult != 0 )
117
Object[] params = { vac_code, antigen, rimsOrgUnit.getPhc_code(),
118
rimsOrgUnit.getDistrict_code(), month, year,
119
rimsOrgUnit.getState_code(), numberResult, "DHIS2" };
121
return executeUpdate( insert, params );
126
throw new RuntimeException( "No data available for data element "
127
+ mappingDataElement.getDhisExpression() );
131
public void markIfComplete() throws SQLException
133
// TODO Make hard-coded vaccines configurable
134
// Mark pregnant women
135
String updateWomen = "UPDATE " + getTableName() + " SET" + " complete = 1"
136
+ " WHERE vaccine_code LIKE 'vac4'"
137
+ " AND preg_women IS NOT NULL";
138
executeUpdate( updateWomen );
141
String updateUnder1 = "UPDATE " + getTableName() + " SET" + " complete = 1"
142
+ " WHERE vaccine_code LIKE 'vac0'"
143
+ " AND antigen = '0'"
144
+ " AND under1year_male IS NOT NULL"
145
+ " AND under1year_female IS NOT NULL";
146
executeUpdate( updateUnder1 );
149
String updateOver1 = "UPDATE " + getTableName() + " SET" + " complete = 1"
150
+ " WHERE vaccine_code IN ( 'vac12', 'vac13', 'vac6', 'vac10', 'vac11' )"
151
+ " OR ( vaccine_code LIKE 'vac5' AND antigen IN ( '2', '3', '4', '5' ) ) "
152
+ " AND over1year_male IS NOT NULL"
153
+ " AND over1year_female IS NOT NULL";
154
executeUpdate( updateOver1 );
157
String updateChildren = "UPDATE " + getTableName() + " SET" + " complete = 1"
158
+ " WHERE vaccine_code IN ( 'vac1', 'vac3', 'vac7', 'vac2' ) "
159
+ " OR ( vaccine_code LIKE 'vac0' AND antigen IN ( '1', '2', '3' ) )"
160
+ " OR ( vaccine_code LIKE 'vac5' AND antigen LIKE '1' )"
161
+ " AND over1year_male IS NOT NULL"
162
+ " AND over1year_female IS NOT NULL";
163
executeUpdate( updateChildren );
166
public String getDataValue( RIMS_Mapping_DataElement mappingDataElement, RIMS_PHC orgUnit, int month, int year ) throws SQLException
168
String getColumn = mappingDataElement.getRimsColumn();
169
String query = "SELECT "+ getColumn +
170
" FROM "+ mappingDataElement.getTableName() +
171
" WHERE vaccine_code = ?"+
176
Object[] params = { mappingDataElement.getVaccine_code(),
177
mappingDataElement.getAntigen(),
178
orgUnit.getPhc_code(),
183
return executeQuery( query, getColumn, params );