• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenSRP / opensrp-client-immunization / #903

pending completion
#903

Pull #196

github-actions

web-flow
Merge 909d67a41 into ce201bbb0
Pull Request #196: Add status to vaccine overdue count repo

5155 of 6673 relevant lines covered (77.25%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
opensrp-immunization/src/main/java/org/smartregister/immunization/repository/VaccineOverdueCountRepository.java
1
package org.smartregister.immunization.repository;
2

3
import androidx.annotation.NonNull;
4
import androidx.annotation.VisibleForTesting;
5

6
import net.sqlcipher.Cursor;
7
import net.sqlcipher.database.SQLiteDatabase;
8

9
import org.smartregister.repository.BaseRepository;
10

11
import timber.log.Timber;
12

13
public class VaccineOverdueCountRepository extends BaseRepository {
1✔
14

15
    public static final String TABLE_NAME = "vaccine_overdue_count";
16
    public static final String STATUS = "status";
17

18
    public static final String CREATE_TABLE_SQL = "CREATE TABLE " + TABLE_NAME + "("
19
            + VaccineRepository.BASE_ENTITY_ID + " VARCHAR NOT NULL,"
20
            + "UNIQUE(" + VaccineRepository.BASE_ENTITY_ID + ") ON CONFLICT REPLACE)";
21
    public static final String ADD_STATUS_COLUMN = "ALTER TABLE " + TABLE_NAME + " ADD " + STATUS + " VARCHAR;";
22
    @VisibleForTesting
23
    protected static final String UPDATE_QUERY_SQL = "INSERT OR REPLACE INTO " + TABLE_NAME + "(base_entity_id, status) values ( ? , ? );";
24

25
    public static void createTable(@NonNull SQLiteDatabase database) {
26
        database.execSQL(CREATE_TABLE_SQL);
1✔
27
        database.execSQL(ADD_STATUS_COLUMN);
1✔
28
    }
1✔
29

30
    /**
31
     * Gets the count of overdue (urgent) entries in the vaccines table and uses the query filter @link #COUNT_QUERY
32
     */
33
    public int getOverdueCount(String countQuerySQL) {
34
        SQLiteDatabase sqLiteDatabase = getReadableDatabase();
1✔
35
        Cursor cursor = sqLiteDatabase.rawQuery(countQuerySQL, null);
1✔
36
        return cursor != null && cursor.getCount() > 0 && cursor.moveToFirst() ? cursor.getInt(0) : 0;
1✔
37
    }
38

39
    /**
40
     * Inserts a new record into the vaccine overdue count table by baseEntityId or nothing if one already exists
41
     * This table only tracks at least one entry of the corresponding baseEntityId. Removal/Deletion from the table is via the {@link #delete(String baseEntityId)}
42
     *
43
     * @param baseEntityId the entity id of client
44
     */
45
    public void upsert(String baseEntityId, String status) {
46
        try {
47
            getWritableDatabase().execSQL(UPDATE_QUERY_SQL, new String[]{baseEntityId, status});
1✔
48
        } catch (Exception e) {
×
49
            Timber.e(e);
×
50
        }
1✔
51
    }
1✔
52

53
    /**
54
     * Deletes an entry in the table by base entity id
55
     *
56
     * @return boolean true if any records were deleted
57
     */
58
    public boolean delete(String baseEntityId) {
59
        SQLiteDatabase database = getWritableDatabase();
1✔
60
        int affectedRows = database.delete(TABLE_NAME, VaccineRepository.BASE_ENTITY_ID + " = ?", new String[]{baseEntityId});
1✔
61
        return affectedRows > 0;
1✔
62
    }
63

64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc