Skip to content

Commit 5901823

Browse files
committed
optimize code
1 parent 219608f commit 5901823

2 files changed

Lines changed: 5 additions & 68 deletions

File tree

claimManagement/src/main/java/org/openimis/imisclaims/ClaimActivity.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.content.ContentValues;
88
import android.content.Context;
99
import android.content.Intent;
10+
import android.database.Cursor;
1011
import android.os.Bundle;
1112
import android.view.Menu;
1213
import android.view.MenuInflater;
@@ -318,8 +319,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
318319
private void addItem() {
319320
Intent addItemsIntent = new Intent(ClaimActivity.this, AddItems.class);
320321
addItemsIntent.putExtra(EXTRA_READONLY, isIntentReadonly());
321-
JSONArray itemsArray = sqlHandler.getItems();
322-
if(itemsArray.length() == 0){
322+
Cursor c = sqlHandler.getMapping("I");
323+
if(c != null && c.getCount() == 0){
323324
showDialog(getResources().getString(R.string.NoItemsPricelist));
324325
}else {
325326
ClaimActivity.this.startActivity(addItemsIntent);
@@ -329,8 +330,8 @@ private void addItem() {
329330
private void addService() {
330331
Intent addServicesIntent = new Intent(this, AddServices.class);
331332
addServicesIntent.putExtra(EXTRA_READONLY, isIntentReadonly());
332-
JSONArray servicesArray = sqlHandler.getServices();
333-
if(servicesArray.length() == 0){
333+
Cursor c = sqlHandler.getMapping("S");
334+
if(c != null && c.getCount() == 0){
334335
showDialog(getResources().getString(R.string.NoServicesPricelist));
335336
}else {
336337
ClaimActivity.this.startActivity(addServicesIntent);

claimManagement/src/main/java/org/openimis/imisclaims/SQLHandler.java

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -961,68 +961,4 @@ public String getHfId(String code) {
961961
}
962962
return id;
963963
}
964-
965-
public JSONArray getServices() {
966-
String nullOverride="";
967-
JSONArray resultSet = new JSONArray();
968-
try {
969-
String query = "SELECT * FROM tblServices";
970-
Cursor cursor1 = db.rawQuery(query, null);
971-
cursor1.moveToFirst();
972-
// looping through all rows
973-
while (!cursor1.isAfterLast()) {
974-
int totalColumns = cursor1.getColumnCount();
975-
JSONObject rowObject = new JSONObject();
976-
for (int i = 0; i < totalColumns; i++) {
977-
try {
978-
if (cursor1.getString(i) != null)
979-
rowObject.put(cursor1.getColumnName(i), cursor1.getString(i));
980-
else
981-
rowObject.put(cursor1.getColumnName(i), nullOverride);
982-
} catch (JSONException e) {
983-
e.printStackTrace();
984-
Log.d("Tag Name", e.getMessage());
985-
}
986-
}
987-
resultSet.put(rowObject);
988-
cursor1.moveToNext();
989-
}
990-
cursor1.close();
991-
} catch (Exception e) {
992-
e.printStackTrace();
993-
}
994-
return resultSet;
995-
}
996-
997-
public JSONArray getItems() {
998-
String nullOverride="";
999-
JSONArray resultSet = new JSONArray();
1000-
try {
1001-
String query = "SELECT * FROM tblItems";
1002-
Cursor cursor1 = db.rawQuery(query, null);
1003-
cursor1.moveToFirst();
1004-
// looping through all rows
1005-
while (!cursor1.isAfterLast()) {
1006-
int totalColumns = cursor1.getColumnCount();
1007-
JSONObject rowObject = new JSONObject();
1008-
for (int i = 0; i < totalColumns; i++) {
1009-
try {
1010-
if (cursor1.getString(i) != null)
1011-
rowObject.put(cursor1.getColumnName(i), cursor1.getString(i));
1012-
else
1013-
rowObject.put(cursor1.getColumnName(i), nullOverride);
1014-
} catch (JSONException e) {
1015-
e.printStackTrace();
1016-
Log.d("Tag Name", e.getMessage());
1017-
}
1018-
}
1019-
resultSet.put(rowObject);
1020-
cursor1.moveToNext();
1021-
}
1022-
cursor1.close();
1023-
} catch (Exception e) {
1024-
e.printStackTrace();
1025-
}
1026-
return resultSet;
1027-
}
1028964
}

0 commit comments

Comments
 (0)