From 2d332f9b34e8ae1239d1272becfdc50a43f4cb12 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Fri, 17 Nov 2023 14:15:33 +0300 Subject: [PATCH 1/5] set force remote login as true --- .../repository/DashboardRepository.java | 33 +++++++++++-------- .../anc/application/AncApplication.java | 4 +-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java index 9b57ba4..bd00957 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java @@ -26,6 +26,7 @@ import java.time.LocalDate; import java.time.Period; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -95,25 +96,29 @@ public static int getWomanLateVisits(LocalDate datetoday) { Cursor cursor = db.rawQuery(query, null); int count=0; while (cursor.moveToNext()){ - String next_contact_date=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); + try{ + String next_contact_date=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); - DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate d1=null; - if(next_contact_date.charAt(0)=='-'){ - d1 = LocalDate.parse(next_contact_date.substring(1), df); - } - else{ - d1 = LocalDate.parse(next_contact_date, df); - } + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); + LocalDate d1=null; + if(next_contact_date.charAt(0)=='-'){ + d1 = LocalDate.parse(next_contact_date.substring(1), df); + } + else{ + d1 = LocalDate.parse(next_contact_date, df); + } - if(datetoday.isAfter(d1)) { + if(datetoday.isAfter(d1)) { // if(datetoday.isEqual(d1)) { - if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ - count++;} - }else{ + if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ + count++;} + }else{ - } + } + } catch (DateTimeParseException e){ + Timber.e(e); + } } diff --git a/reference-app/src/main/java/org/smartregister/anc/application/AncApplication.java b/reference-app/src/main/java/org/smartregister/anc/application/AncApplication.java index ae08c77..571538d 100644 --- a/reference-app/src/main/java/org/smartregister/anc/application/AncApplication.java +++ b/reference-app/src/main/java/org/smartregister/anc/application/AncApplication.java @@ -203,14 +203,14 @@ public Context getContext() { @Override public void onTimeChanged() { Utils.showToast(this, this.getString(org.smartregister.anc.library.R.string.device_time_changed)); - context.userService().getAllSharedPreferences().saveForceRemoteLogin(true, context.allSharedPreferences().fetchRegisteredANM()); + context.userService().getAllSharedPreferences().saveForceRemoteLogin(false, context.allSharedPreferences().fetchRegisteredANM()); logoutCurrentUser(); } @Override public void onTimeZoneChanged() { Utils.showToast(this, this.getString(org.smartregister.anc.library.R.string.device_timezone_changed)); - context.userService().getAllSharedPreferences().saveForceRemoteLogin(true, context.allSharedPreferences().fetchRegisteredANM()); + context.userService().getAllSharedPreferences().saveForceRemoteLogin(false, context.allSharedPreferences().fetchRegisteredANM()); logoutCurrentUser(); } } \ No newline at end of file From ac9193791ce315c8459644fdbc43705913588297 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Wed, 22 Nov 2023 14:24:20 +0300 Subject: [PATCH 2/5] fix formating --- .../repository/DashboardRepository.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java index bd00957..e00278d 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java @@ -100,22 +100,22 @@ public static int getWomanLateVisits(LocalDate datetoday) { String next_contact_date=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); - DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate d1=null; - if(next_contact_date.charAt(0)=='-'){ - d1 = LocalDate.parse(next_contact_date.substring(1), df); - } - else{ - d1 = LocalDate.parse(next_contact_date, df); - } + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); + LocalDate d1=null; + if(next_contact_date.charAt(0)=='-'){ + d1 = LocalDate.parse(next_contact_date.substring(1), df); + } + else{ + d1 = LocalDate.parse(next_contact_date, df); + } - if(datetoday.isAfter(d1)) { + if(datetoday.isAfter(d1)) { // if(datetoday.isEqual(d1)) { - if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ - count++;} - }else{ + if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ + count++;} + }else{ - } + } } catch (DateTimeParseException e){ Timber.e(e); } From ae9455f88d5a2c0f49e80f46cc1429df16493699 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Wed, 22 Nov 2023 14:30:13 +0300 Subject: [PATCH 3/5] fix formating --- .../repository/DashboardRepository.java | 96 +++++++++---------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java index e00278d..06075f0 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java @@ -49,33 +49,33 @@ public class DashboardRepository extends BaseRepository { @RequiresApi(api = Build.VERSION_CODES.O) public static int getDueContactDash(LocalDate datetoday) { - SQLiteDatabase db = getMasterRepository().getReadableDatabase(); + SQLiteDatabase db = getMasterRepository().getReadableDatabase(); // String query = "SELECT COUNT(*) FROM " + getRegisterQueryProvider().getDetailsTable() + " WHERE " + DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE+ "= '"+datetoday+"'"; // SQLiteStatement statement = db.compileStatement(query); // long count = statement.simpleQueryForLong(); // return count; String query = "SELECT * FROM " + getRegisterQueryProvider().getDetailsTable(); - Cursor cursor = db.rawQuery(query, null); - int count=0; - while (cursor.moveToNext()){ - String next_contact_date=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); + Cursor cursor = db.rawQuery(query, null); + int count = 0; + while (cursor.moveToNext()) { + String next_contact_date = cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate d1=null; - if(next_contact_date.charAt(0)=='-'){ + LocalDate d1 = null; + if (next_contact_date.charAt(0) == '-') { d1 = LocalDate.parse(next_contact_date.substring(1), df); - } - else{ + } else { d1 = LocalDate.parse(next_contact_date, df); } // if(datetoday.isEqual(d1) || datetoday.isAfter(d1)) { - if(datetoday.isEqual(d1)) { - if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ - count++;} - }else{ + if (datetoday.isEqual(d1)) { + if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + count++; + } + } else { } @@ -228,9 +228,8 @@ private static boolean isVaccinatedToday(String woman_id) { if (val.get(VALUE).toString().equals("done_today")) { return true; - } - else { - return false; + } else { + return false; } } } catch (JSONException e) { @@ -305,9 +304,8 @@ private static boolean isDewormingPerfomed(String woman_id) { if (val.get(VALUE).toString().equals("yes")) { return true; - } - else { - return false; + } else { + return false; } } } catch (JSONException e) { @@ -349,22 +347,21 @@ private static boolean isAccompanied(String woman_id) { private static boolean isReferred(String woman_id) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '"+woman_id+"'"; - Cursor cursor = db.rawQuery(query, null); - while (cursor.moveToNext()){ + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '" + woman_id + "'"; + Cursor cursor = db.rawQuery(query, null); + while (cursor.moveToNext()) { try { if (cursor.getString(3).equals("referred_hosp")) { - JSONObject val = new JSONObject(cursor.getString(4)); + JSONObject val = new JSONObject(cursor.getString(4)); - if (val.get(VALUE).toString().equals("yes")) { + if (val.get(VALUE).toString().equals("yes")) { - return true; - } - else { - return false; - } + return true; + } else { + return false; + } } } catch (JSONException e) { e.printStackTrace(); @@ -383,17 +380,17 @@ public static long getProcessedVisits(String dateStart, String dateEnd) { // Cursor cursor = db.rawQuery(query, null); // SQLiteStatement statement = db.compileStatement(query); // long count = statement.simpleQueryForLong(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(!isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (!isAnc_Closed(cursor.getString(2))) { count++; } } @@ -402,22 +399,23 @@ public static long getProcessedVisits(String dateStart, String dateEnd) { } return count; } + @RequiresApi(api = Build.VERSION_CODES.O) public static int getWomanWithDangerSing(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(hasDangerSign(cursor.getString(2))&& !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (hasDangerSign(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { count++; } } From 8702e6b9159b80ce739756e86fd67d9fbe47692c Mon Sep 17 00:00:00 2001 From: hilpitome Date: Wed, 22 Nov 2023 14:31:12 +0300 Subject: [PATCH 4/5] Revert "fix formating" This reverts commit ac9193791ce315c8459644fdbc43705913588297. --- .../repository/DashboardRepository.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java index 06075f0..d8f321f 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java @@ -100,22 +100,22 @@ public static int getWomanLateVisits(LocalDate datetoday) { String next_contact_date=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); - DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate d1=null; - if(next_contact_date.charAt(0)=='-'){ - d1 = LocalDate.parse(next_contact_date.substring(1), df); - } - else{ - d1 = LocalDate.parse(next_contact_date, df); - } + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); + LocalDate d1=null; + if(next_contact_date.charAt(0)=='-'){ + d1 = LocalDate.parse(next_contact_date.substring(1), df); + } + else{ + d1 = LocalDate.parse(next_contact_date, df); + } - if(datetoday.isAfter(d1)) { + if(datetoday.isAfter(d1)) { // if(datetoday.isEqual(d1)) { - if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ - count++;} - }else{ + if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ + count++;} + }else{ - } + } } catch (DateTimeParseException e){ Timber.e(e); } From 90b7ab12751510ae24ee21f6b8fdca14d0454c47 Mon Sep 17 00:00:00 2001 From: hilpitome Date: Wed, 22 Nov 2023 14:34:31 +0300 Subject: [PATCH 5/5] fix formating --- .../repository/DashboardRepository.java | 652 +++++++++--------- 1 file changed, 336 insertions(+), 316 deletions(-) diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java index d8f321f..69409b8 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/repository/DashboardRepository.java @@ -83,6 +83,7 @@ public static int getDueContactDash(LocalDate datetoday) { } return count; } + @RequiresApi(api = Build.VERSION_CODES.O) public static int getWomanLateVisits(LocalDate datetoday) { @@ -93,71 +94,74 @@ public static int getWomanLateVisits(LocalDate datetoday) { // long count = statement.simpleQueryForLong(); // return count; String query = "SELECT * FROM " + getRegisterQueryProvider().getDetailsTable(); - Cursor cursor = db.rawQuery(query, null); - int count=0; - while (cursor.moveToNext()){ - try{ - String next_contact_date=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); - - - DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate d1=null; - if(next_contact_date.charAt(0)=='-'){ - d1 = LocalDate.parse(next_contact_date.substring(1), df); - } - else{ - d1 = LocalDate.parse(next_contact_date, df); - } - - if(datetoday.isAfter(d1)) { + Cursor cursor = db.rawQuery(query, null); + int count = 0; + while (cursor.moveToNext()) { + try { + String next_contact_date = cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); + + + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); + LocalDate d1 = null; + if (next_contact_date.charAt(0) == '-') { + d1 = LocalDate.parse(next_contact_date.substring(1), df); + } else { + d1 = LocalDate.parse(next_contact_date, df); + } + + if (datetoday.isAfter(d1)) { // if(datetoday.isEqual(d1)) { - if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ - count++;} - }else{ + if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + count++; + } + } else { - } - } catch (DateTimeParseException e){ - Timber.e(e); - } + } + } catch (DateTimeParseException e) { + Timber.e(e); + } } return count; } + @RequiresApi(api = Build.VERSION_CODES.O) - public static int getExpectedDeliveries (String dateStart, String dateEnd){ + public static int getExpectedDeliveries(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); String query = "SELECT * FROM " + getRegisterQueryProvider().getDetailsTable(); - Cursor cursor = db.rawQuery(query, null); - int count=0; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - String edd=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.EDD)); - - if (!"0".equals(edd) && edd!= null){ - LocalDate d=LocalDate.parse(edd); - if(d.isAfter(start) && d.isBefore(end)) { - if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ - count++; + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + String edd = cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.EDD)); + + if (!"0".equals(edd) && edd != null) { + LocalDate d = LocalDate.parse(edd); + if (d.isAfter(start) && d.isBefore(end)) { + if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + count++; + } } - }} + } } return count; } + private static boolean isAnc_Closed(String base_entity_id) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_EC_CLIENT+ " WHERE base_entity_id='" +base_entity_id+"'"; - Cursor cursor = db.rawQuery(query, null); - while (cursor.moveToNext()){ - if (cursor.getString(cursor.getColumnIndex("date_removed"))!=null){ - return true; + String query = "SELECT * FROM " + TABLE_EC_CLIENT + " WHERE base_entity_id='" + base_entity_id + "'"; + Cursor cursor = db.rawQuery(query, null); + while (cursor.moveToNext()) { + if (cursor.getString(cursor.getColumnIndex("date_removed")) != null) { + return true; } } @@ -169,41 +173,42 @@ public static int getWomanReferred(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isReferred(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))){ - count++; - } - } - } - - } + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isReferred(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { + count++; + } + } + } + + } return count; } + @RequiresApi(api = Build.VERSION_CODES.O) public static int getWomanVaccinated(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isVaccinatedToday(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isVaccinatedToday(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { count++; } } @@ -216,9 +221,9 @@ public static int getWomanVaccinated(String dateStart, String dateEnd) { private static boolean isVaccinatedToday(String woman_id) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '"+woman_id+"'"; - Cursor cursor = db.rawQuery(query, null); - while (cursor.moveToNext()){ + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '" + woman_id + "'"; + Cursor cursor = db.rawQuery(query, null); + while (cursor.moveToNext()) { try { if (cursor.getString(3).equals("tt1_date")) { @@ -245,17 +250,17 @@ public static int getWomanAccompaniedWithPartner(String dateStart, String dateEn SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isAccompanied(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isAccompanied(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { count++; } } @@ -264,22 +269,23 @@ public static int getWomanAccompaniedWithPartner(String dateStart, String dateEn } return count; } + @RequiresApi(api = Build.VERSION_CODES.O) public static int getWomanReceivedDewormingPills(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isDewormingPerfomed(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isDewormingPerfomed(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { count++; } } @@ -292,9 +298,9 @@ public static int getWomanReceivedDewormingPills(String dateStart, String dateEn private static boolean isDewormingPerfomed(String woman_id) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '"+woman_id+"'"; - Cursor cursor = db.rawQuery(query, null); - while (cursor.moveToNext()){ + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '" + woman_id + "'"; + Cursor cursor = db.rawQuery(query, null); + while (cursor.moveToNext()) { try { if (cursor.getString(3).equals("deworming_performed")) { @@ -319,9 +325,9 @@ private static boolean isDewormingPerfomed(String woman_id) { private static boolean isAccompanied(String woman_id) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '"+woman_id+"'"; - Cursor cursor = db.rawQuery(query, null); - while (cursor.moveToNext()){ + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '" + woman_id + "'"; + Cursor cursor = db.rawQuery(query, null); + while (cursor.moveToNext()) { try { if (cursor.getString(3).equals("accompanied_by_partner")) { @@ -331,9 +337,8 @@ private static boolean isAccompanied(String woman_id) { if (val.get(VALUE).toString().equals("yes")) { return true; - } - else { - return false; + } else { + return false; } } } catch (JSONException e) { @@ -424,41 +429,43 @@ public static int getWomanWithDangerSing(String dateStart, String dateEnd) { } return count; } - public static boolean hasDangerSign(String woman_id){ + + public static boolean hasDangerSign(String woman_id) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + getRegisterQueryProvider().getDetailsTable()+" WHERE id= '"+woman_id+"'"; - Cursor cursor = db.rawQuery(query, null); + String query = "SELECT * FROM " + getRegisterQueryProvider().getDetailsTable() + " WHERE id= '" + woman_id + "'"; + Cursor cursor = db.rawQuery(query, null); - while (cursor.moveToNext()){ - String r=cursor.getString(18); - if (!"0".equals(r) && r!= null){ - return true; - }else{ - return false; - } + while (cursor.moveToNext()) { + String r = cursor.getString(18); + if (!"0".equals(r) && r != null) { + return true; + } else { + return false; + } } return false; } + @RequiresApi(api = Build.VERSION_CODES.O) public static int getWomanWithSyphilisPositive(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isSyphilisPositive(cursor.getString(2))&& !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isSyphilisPositive(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { count++; } } @@ -467,16 +474,17 @@ public static int getWomanWithSyphilisPositive(String dateStart, String dateEnd) } return count; } + private static boolean isSyphilisPositive(String woman_id) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '"+woman_id+"'"; - Cursor cursor = db.rawQuery(query, null); - while (cursor.moveToNext()){ + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE base_entity_id= '" + woman_id + "'"; + Cursor cursor = db.rawQuery(query, null); + while (cursor.moveToNext()) { - if (cursor.getString(3).equals("syphilis_positive") && cursor.getString(4).equals("1")) { - return true; - } + if (cursor.getString(3).equals("syphilis_positive") && cursor.getString(4).equals("1")) { + return true; + } } @@ -484,44 +492,44 @@ private static boolean isSyphilisPositive(String woman_id) { } @RequiresApi(api = Build.VERSION_CODES.O) - public static int getWomanInParticularAge(String dateStart, String dateEnd,int age) { + public static int getWomanInParticularAge(String dateStart, String dateEnd, int age) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); String query = "SELECT * FROM ec_details"; - Cursor cursor = db.rawQuery(query, null); - int count=0; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - Long dt=Long.parseLong(cursor.getString(cursor.getColumnIndex("event_date"))); + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + Long dt = Long.parseLong(cursor.getString(cursor.getColumnIndex("event_date"))); DateFormat simple = new SimpleDateFormat("yyyy-MM-dd"); Date result = new Date(dt); - LocalDate d=LocalDate.parse(simple.format(result)); + LocalDate d = LocalDate.parse(simple.format(result)); - if(d.isAfter(start) && d.isBefore(end)) { + if (d.isAfter(start) && d.isBefore(end)) { - if(cursor.getString(1).equals("age_calculated") ) { - int ag = getWomanAge(cursor.getString(cursor.getColumnIndex("base_entity_id"))); - Log.i("TEST1", String.valueOf(ag)+ "getWomanInParticularAge: "+cursor.getString(cursor.getColumnIndex("base_entity_id"))); - if (age == 19) { - if (ag < 20 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { - count++; - } - } else if (age == 30) { + if (cursor.getString(1).equals("age_calculated")) { + int ag = getWomanAge(cursor.getString(cursor.getColumnIndex("base_entity_id"))); + Log.i("TEST1", String.valueOf(ag) + "getWomanInParticularAge: " + cursor.getString(cursor.getColumnIndex("base_entity_id"))); + if (age == 19) { + if (ag < 20 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + count++; + } + } else if (age == 30) { - if ( ag >= 20 && ag < 30 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { - count++; - } + if (ag >= 20 && ag < 30 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + count++; + } - } else { - if (ag >= 30 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { - count++; - } - } - } + } else { + if (ag >= 30 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + count++; + } + } + } } @@ -529,65 +537,67 @@ public static int getWomanInParticularAge(String dateStart, String dateEnd,int a } return count; } + protected static Repository getMasterRepository() { return DrishtiApplication.getInstance().getRepository(); } + private static RegisterQueryProvider getRegisterQueryProvider() { return AncLibrary.getInstance().getRegisterQueryProvider(); } + @RequiresApi(api = Build.VERSION_CODES.O) public static List getWomanProfileDetails(LocalDate datetoday) { Cursor cursor = null; - List clientList=new ArrayList<>(); + List clientList = new ArrayList<>(); try { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); String query = "SELECT " + StringUtils.join(projection, ",") + " FROM " + getRegisterQueryProvider().getDemographicTable() + " join " + getRegisterQueryProvider().getDetailsTable() + - " on " + getRegisterQueryProvider().getDemographicTable() + "." + DBConstantsUtils.KeyUtils.BASE_ENTITY_ID + " = " + getRegisterQueryProvider().getDetailsTable() + "." + DBConstantsUtils.KeyUtils.BASE_ENTITY_ID ; + " on " + getRegisterQueryProvider().getDemographicTable() + "." + DBConstantsUtils.KeyUtils.BASE_ENTITY_ID + " = " + getRegisterQueryProvider().getDetailsTable() + "." + DBConstantsUtils.KeyUtils.BASE_ENTITY_ID; // + " WHERE " + getRegisterQueryProvider().getDetailsTable() + "." + DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE + " = ?"; // cursor = db.rawQuery(query, new String[]{baseEntityId});?? cursor = db.rawQuery(query, null); - if (cursor != null ) { + if (cursor != null) { - while (cursor.moveToNext()){ - CustomClient client=new CustomClient(); - String next_contact_date=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); + while (cursor.moveToNext()) { + CustomClient client = new CustomClient(); + String next_contact_date = cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE)); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate d1=null; - if(next_contact_date.charAt(0)=='-'){ + LocalDate d1 = null; + if (next_contact_date.charAt(0) == '-') { d1 = LocalDate.parse(next_contact_date.substring(1), df); - } - else{ + } else { d1 = LocalDate.parse(next_contact_date, df); } // if(datetoday.isEqual(d1) || datetoday.isAfter(d1)) { - if(datetoday.isAfter(d1)) { - if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ - - - - client.setFirstName(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.FIRST_NAME))); - client.setLastName(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.LAST_NAME))); - client.setAge(String.valueOf(calculateAge(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.DOB))))); - client.setGa(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.EDD))); - client.setRegistrationId(cursor.getString(cursor.getColumnIndex("register_id"))); - client.setNextContactDate(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE))); - String r=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.RED_FLAG_COUNT)); - String red= r == null? "0": r; - String y=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.YELLOW_FLAG_COUNT)); - String yellow= y == null? "0": y; - client.setAttentionFlag(Integer.parseInt(red)+ Integer.parseInt(yellow)); - client.setBaseIntityId(cursor.getString(cursor.getColumnIndex("base_entity_id"))); - clientList.add(client) ; + if (datetoday.isAfter(d1)) { + if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + + + client.setFirstName(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.FIRST_NAME))); + client.setLastName(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.LAST_NAME))); + client.setAge(String.valueOf(calculateAge(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.DOB))))); + client.setGa(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.EDD))); + client.setRegistrationId(cursor.getString(cursor.getColumnIndex("register_id"))); + client.setNextContactDate(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE))); + String r = cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.RED_FLAG_COUNT)); + String red = r == null ? "0" : r; + String y = cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.YELLOW_FLAG_COUNT)); + String yellow = y == null ? "0" : y; + client.setAttentionFlag(Integer.parseInt(red) + Integer.parseInt(yellow)); + client.setBaseIntityId(cursor.getString(cursor.getColumnIndex("base_entity_id"))); + clientList.add(client); } - }else{} + } else { + } + } } - } return clientList; } catch (Exception e) { @@ -599,29 +609,30 @@ public static List getWomanProfileDetails(LocalDate datetoday) { } return null; } + @RequiresApi(api = Build.VERSION_CODES.O) - public static ListgetProcessedVisitsDetails(String dateStart, String dateEnd) { + public static List getProcessedVisitsDetails(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); // String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT + " WHERE " + KEY + "= 'contact_date' AND " +VALUE+ "='"+datet+"'"; // Cursor cursor = db.rawQuery(query, null); - List clientList=new ArrayList<>(); + List clientList = new ArrayList<>(); // // while (cursor.moveToNext()){ // clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); // } - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(!isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (!isAnc_Closed(cursor.getString(2))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } } @@ -631,22 +642,23 @@ public static List getWomanProfileDetails(LocalDate datetoday) { return clientList; } + @RequiresApi(api = Build.VERSION_CODES.O) public static List getWomanReferredDetails(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - List clientList=new ArrayList<>(); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isReferred(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + List clientList = new ArrayList<>(); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isReferred(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } } @@ -657,22 +669,22 @@ public static List getWomanReferredDetails(String dateStart, Strin } @RequiresApi(api = Build.VERSION_CODES.O) - public static List getWomanWithDangerSingDetails(String dateStart, String dateEnd) { + public static List getWomanWithDangerSingDetails(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - List clientList=new ArrayList<>(); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(hasDangerSign(cursor.getString(2))&& !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + List clientList = new ArrayList<>(); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (hasDangerSign(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } @@ -682,23 +694,24 @@ public static List getWomanWithDangerSingDetails(String dateStar } return clientList; } + @RequiresApi(api = Build.VERSION_CODES.O) public static List getWomanAccompaniedWithPartnerDetails(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - List clientList=new ArrayList<>(); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isAccompanied(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + List clientList = new ArrayList<>(); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isAccompanied(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } } @@ -707,23 +720,24 @@ public static List getWomanAccompaniedWithPartnerDetails(String da } return clientList; } + @RequiresApi(api = Build.VERSION_CODES.O) public static List getWomanReceivedDewormingPillsDetails(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - List clientList=new ArrayList<>(); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isDewormingPerfomed(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + List clientList = new ArrayList<>(); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isDewormingPerfomed(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } } @@ -732,70 +746,71 @@ public static List getWomanReceivedDewormingPillsDetails(String da } return clientList; } + @RequiresApi(api = Build.VERSION_CODES.O) - public static List getWomanInParticularAgeDetails(String dateStart, String dateEnd,int age) { + public static List getWomanInParticularAgeDetails(String dateStart, String dateEnd, int age) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); String query = "SELECT * FROM ec_details"; - Cursor cursor = db.rawQuery(query, null); + Cursor cursor = db.rawQuery(query, null); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); + LocalDate start = LocalDate.parse(dateStart, df); - List clientList=new ArrayList<>(); - LocalDate end= LocalDate.parse(dateEnd, df); - while (cursor.moveToNext()){ - Long dt=Long.parseLong(cursor.getString(cursor.getColumnIndex("event_date"))); + List clientList = new ArrayList<>(); + LocalDate end = LocalDate.parse(dateEnd, df); + while (cursor.moveToNext()) { + Long dt = Long.parseLong(cursor.getString(cursor.getColumnIndex("event_date"))); DateFormat simple = new SimpleDateFormat("yyyy-MM-dd"); Date result = new Date(dt); - LocalDate d=LocalDate.parse(simple.format(result)); - if(d.isAfter(start) && d.isBefore(end)) { - if(cursor.getString(1).equals("age_calculated") ) { + LocalDate d = LocalDate.parse(simple.format(result)); + if (d.isAfter(start) && d.isBefore(end)) { + if (cursor.getString(1).equals("age_calculated")) { int ag = getWomanAge(cursor.getString(cursor.getColumnIndex("base_entity_id"))); - Log.i("TEST1", String.valueOf(ag)+ "getWomanInParticularAge: "+cursor.getString(cursor.getColumnIndex("base_entity_id"))); + Log.i("TEST1", String.valueOf(ag) + "getWomanInParticularAge: " + cursor.getString(cursor.getColumnIndex("base_entity_id"))); if (age == 19) { if (ag < 20 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } } else if (age == 30) { - if ( ag >= 20 && ag < 30 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + if (ag >= 20 && ag < 30 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } } else { - if (ag >= 30 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + if (ag >= 30 && !isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } } } - } } return clientList; } + @RequiresApi(api = Build.VERSION_CODES.O) - public static List getWomanVaccinatedDetails(String dateStart, String dateEnd) { + public static List getWomanVaccinatedDetails(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - List clientList=new ArrayList<>(); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isVaccinatedToday(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + List clientList = new ArrayList<>(); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isVaccinatedToday(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } } @@ -804,23 +819,24 @@ public static List getWomanVaccinatedDetails(String dateStart, St } return clientList; } + @RequiresApi(api = Build.VERSION_CODES.O) public static List getWomanWithSyphilisPositiveDetails(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT ; - Cursor cursor = db.rawQuery(query, null); - int count=0; + String query = "SELECT * FROM " + TABLE_PREVIOUS_CONTACT; + Cursor cursor = db.rawQuery(query, null); + int count = 0; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - List clientList=new ArrayList<>(); - while (cursor.moveToNext()){ - if (cursor.getString(3).equals("contact_date")){ - LocalDate d=LocalDate.parse(cursor.getString(4)); - if(d.isAfter(start) && d.isBefore(end)) { - if(isSyphilisPositive(cursor.getString(2))&& !isAnc_Closed(cursor.getString(2))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + List clientList = new ArrayList<>(); + while (cursor.moveToNext()) { + if (cursor.getString(3).equals("contact_date")) { + LocalDate d = LocalDate.parse(cursor.getString(4)); + if (d.isAfter(start) && d.isBefore(end)) { + if (isSyphilisPositive(cursor.getString(2)) && !isAnc_Closed(cursor.getString(2))) { clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } } @@ -829,44 +845,47 @@ public static List getWomanWithSyphilisPositiveDetails(String date } return clientList; } + @RequiresApi(api = Build.VERSION_CODES.O) - public static List getExpectedDeliveriesDetails (String dateStart, String dateEnd){ + public static List getExpectedDeliveriesDetails(String dateStart, String dateEnd) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); String query = "SELECT * FROM " + getRegisterQueryProvider().getDetailsTable(); - Cursor cursor = db.rawQuery(query, null); + Cursor cursor = db.rawQuery(query, null); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-d"); - LocalDate start= LocalDate.parse(dateStart, df); - LocalDate end= LocalDate.parse(dateEnd, df); - Log.i("TESTing", "getExpectedDeliveriesDetails: "+start); - Log.i("TESTing", "getExpectedDeliveriesDetails: "+end); - List clientList=new ArrayList<>(); - while (cursor.moveToNext()){ - String edd=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.EDD)); - - if (!"0".equals(edd) && edd!= null){ - LocalDate d=LocalDate.parse(edd); - if(d.isAfter(start) && d.isBefore(end)) { - if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ + LocalDate start = LocalDate.parse(dateStart, df); + LocalDate end = LocalDate.parse(dateEnd, df); + Log.i("TESTing", "getExpectedDeliveriesDetails: " + start); + Log.i("TESTing", "getExpectedDeliveriesDetails: " + end); + List clientList = new ArrayList<>(); + while (cursor.moveToNext()) { + String edd = cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.EDD)); - clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); + if (!"0".equals(edd) && edd != null) { + LocalDate d = LocalDate.parse(edd); + if (d.isAfter(start) && d.isBefore(end)) { + if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { + + clientList.add(getDetailsList(cursor.getString(cursor.getColumnIndex("base_entity_id")))); } - }} + } + } } return clientList; } + @RequiresApi(api = Build.VERSION_CODES.O) private static int getWomanAge(String base_entity_id) { SQLiteDatabase db = getMasterRepository().getReadableDatabase(); - int age=25; - String query = "SELECT * FROM " + TABLE_EC_CLIENT+ " WHERE base_entity_id='" +base_entity_id+"'"; - Cursor cursor = db.rawQuery(query, null); - while (cursor.moveToNext()){ - age= calculateAge(cursor.getString(cursor.getColumnIndex("dob"))); + int age = 25; + String query = "SELECT * FROM " + TABLE_EC_CLIENT + " WHERE base_entity_id='" + base_entity_id + "'"; + Cursor cursor = db.rawQuery(query, null); + while (cursor.moveToNext()) { + age = calculateAge(cursor.getString(cursor.getColumnIndex("dob"))); - } + } return age; } @@ -883,27 +902,27 @@ public static CustomClient getDetailsList(String baseEntityId) { " on " + getRegisterQueryProvider().getDemographicTable() + "." + DBConstantsUtils.KeyUtils.BASE_ENTITY_ID + " = " + getRegisterQueryProvider().getDetailsTable() + "." + DBConstantsUtils.KeyUtils.BASE_ENTITY_ID + " WHERE " + getRegisterQueryProvider().getDemographicTable() + "." + DBConstantsUtils.KeyUtils.BASE_ENTITY_ID + " = ?"; cursor = db.rawQuery(query, new String[]{baseEntityId}); - CustomClient client=new CustomClient(); - if (cursor != null ) { + CustomClient client = new CustomClient(); + if (cursor != null) { - while (cursor.moveToNext()){ - if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))){ + while (cursor.moveToNext()) { + if (!isAnc_Closed(cursor.getString(cursor.getColumnIndex("base_entity_id")))) { - client.setFirstName(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.FIRST_NAME))); - client.setLastName(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.LAST_NAME))); - client.setAge(String.valueOf(calculateAge(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.DOB))))); - client.setGa(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.EDD))); - client.setRegistrationId(cursor.getString(cursor.getColumnIndex("register_id"))); - client.setNextContactDate(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE))); - String r=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.RED_FLAG_COUNT)); - String red= r == null? "0": r; - String y=cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.YELLOW_FLAG_COUNT)); - String yellow= y == null? "0": y; - client.setAttentionFlag(Integer.parseInt(red)+ Integer.parseInt(yellow)); - client.setBaseIntityId(cursor.getString(cursor.getColumnIndex("base_entity_id"))); + client.setFirstName(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.FIRST_NAME))); + client.setLastName(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.LAST_NAME))); + client.setAge(String.valueOf(calculateAge(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.DOB))))); + client.setGa(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.EDD))); + client.setRegistrationId(cursor.getString(cursor.getColumnIndex("register_id"))); + client.setNextContactDate(cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE))); + String r = cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.RED_FLAG_COUNT)); + String red = r == null ? "0" : r; + String y = cursor.getString(cursor.getColumnIndex(DBConstantsUtils.KeyUtils.YELLOW_FLAG_COUNT)); + String yellow = y == null ? "0" : y; + client.setAttentionFlag(Integer.parseInt(red) + Integer.parseInt(yellow)); + client.setBaseIntityId(cursor.getString(cursor.getColumnIndex("base_entity_id"))); - } + } } } @@ -918,11 +937,12 @@ public static CustomClient getDetailsList(String baseEntityId) { } return null; } + @RequiresApi(api = Build.VERSION_CODES.O) private static int calculateAge(String birthDate) { - LocalDate currentDate = LocalDate.now(); + LocalDate currentDate = LocalDate.now(); if ((birthDate != null) && (currentDate != null)) { - return currentDate.getYear()-Integer.valueOf(birthDate.split("-", 0)[0]); + return currentDate.getYear() - Integer.valueOf(birthDate.split("-", 0)[0]); } else { return 0; }