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..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 @@ -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; @@ -48,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 { } @@ -82,6 +83,7 @@ public static int getDueContactDash(LocalDate datetoday) { } return count; } + @RequiresApi(api = Build.VERSION_CODES.O) public static int getWomanLateVisits(LocalDate datetoday) { @@ -92,67 +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()){ - 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()) { + 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); } } 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; } } @@ -164,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++; } } @@ -211,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")) { @@ -223,9 +233,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) { @@ -241,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++; } } @@ -260,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++; } } @@ -288,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")) { @@ -300,9 +310,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) { @@ -316,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")) { @@ -328,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) { @@ -344,22 +352,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(); @@ -378,17 +385,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++; } } @@ -397,22 +404,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++; } } @@ -421,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++; } } @@ -464,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; + } } @@ -481,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++; + } + } + } } @@ -526,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) { @@ -596,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")))); } } @@ -628,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")))); } } @@ -654,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")))); } @@ -679,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")))); } } @@ -704,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")))); } } @@ -729,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")))); } } @@ -801,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")))); } } @@ -826,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)); + + 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")))); + 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; } @@ -880,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"))); - } + } } } @@ -915,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; } 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