Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4 add status to vaccine overdue count repo #197

Merged
merged 3 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=4.0.7-SNAPSHOT
VERSION_NAME=4.0.8-ALPHA1-SNAPSHOT
VERSION_CODE=3
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Immunization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ private static VaccineSchedule getVaccineSchedule(String vaccineName, String vac

VaccineRepo.Vaccine vaccine = VaccineRepo.getVaccine(vaccineName, vaccineCategory);


if (vaccine != null) {
ArrayList<VaccineCondition> conditions = new ArrayList<>();
if (schedule.conditions != null) {
Expand Down Expand Up @@ -151,7 +150,6 @@ public static List<String> updateOfflineAlerts(String baseEntityId, DateTime dob
List<Alert> newAlerts = updateOfflineAlertsAndReturnNewAlertList(baseEntityId, dob, vaccineCategory);
List<String> notInNew = getAlertsNotInNew(newAlerts);
return notInNew;

} catch (Exception e) {
Timber.e(VaccineSchedule.class.getName(), e.toString(), e);
return new ArrayList<>();
Expand Down Expand Up @@ -199,7 +197,6 @@ public static List<String> updateOfflineAlertsAndReturnAffectedVaccineNames(Stri
* @param vaccineCategory
*/
private static List<Alert> updateOfflineAlertsAndReturnNewAlertList(String baseEntityId, DateTime dob, String vaccineCategory) {

List<Alert> newAlerts = new ArrayList<>();
try {
VaccineRepository vaccineRepository = ImmunizationLibrary.getInstance().vaccineRepository();
Expand Down Expand Up @@ -228,10 +225,12 @@ private static List<Alert> updateOfflineAlertsAndReturnNewAlertList(String baseE
newAlerts.add(curAlert);
alertService.updateFtsSearch(curAlert, true);

if (!isAnyVaccineUrgent && AlertStatus.urgent.equals(curAlert.status())) {
if (!isAnyVaccineUrgent && (AlertStatus.urgent.equals(curAlert.status())
|| AlertStatus.normal.equals(curAlert.status()))) {
try {
isAnyVaccineUrgent = true;
ImmunizationLibrary.getInstance().getVaccineOverdueCountRepository().upsert(baseEntityId);
ImmunizationLibrary.getInstance().getVaccineOverdueCountRepository()
.upsert(baseEntityId, curAlert.status().value());
} catch (Exception e) {
Timber.e(e);
}
Expand All @@ -250,8 +249,7 @@ private static List<Alert> updateOfflineAlertsAndReturnNewAlertList(String baseE
alertService.create(newAlerts);
}

} catch (
Exception e) {
} catch (Exception e) {
Timber.e(VaccineSchedule.class.getName(), e.toString(), e);
}

Expand Down Expand Up @@ -358,8 +356,7 @@ public static void setVaccineSchedules(HashMap<String, HashMap<String, VaccineSc
*
* @return An {@link Alert} object if one exists, or {@code NULL} if non exists
*/
public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth,
List<Vaccine> issuedVaccines) {
public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth, List<Vaccine> issuedVaccines) {
Alert defaultAlert = null;

// Check if all conditions pass
Expand All @@ -384,14 +381,15 @@ public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth,
}

if (alertStatus != null) {

Alert offlineAlert = new Alert(baseEntityId,
Alert offlineAlert = new Alert(
baseEntityId,
vaccine.display(),
vaccine.name().toLowerCase(Locale.ENGLISH).replace(" ", ""),
alertStatus,
dueDate == null ? null : DateUtil.yyyyMMdd.format(dueDate),
expiryDate == null ? null : DateUtil.yyyyMMdd.format(expiryDate),
true);
true
);

return offlineAlert;
}
Expand All @@ -400,7 +398,6 @@ public Alert getOfflineAlert(String baseEntityId, Date dateOfBirth,
}

protected boolean isVaccineIssued(String currentVaccine, List<Vaccine> issuedVaccines) {

for (Vaccine vaccine : issuedVaccines) {
if (currentVaccine.equalsIgnoreCase(vaccine.getName().replaceAll(" ", ""))) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
public class VaccineOverdueCountRepository extends BaseRepository {

public static final String TABLE_NAME = "vaccine_overdue_count";
public static final String STATUS = "status";

public static final String CREATE_TABLE_SQL = "CREATE TABLE " + TABLE_NAME + "("
+ VaccineRepository.BASE_ENTITY_ID + " VARCHAR NOT NULL,"
+ "UNIQUE(" + VaccineRepository.BASE_ENTITY_ID + ") ON CONFLICT REPLACE)";

public static final String ADD_STATUS_COLUMN = "ALTER TABLE " + TABLE_NAME + " ADD " + STATUS + " VARCHAR;";
@VisibleForTesting
protected static final String UPDATE_QUERY_SQL = "INSERT INTO " + TABLE_NAME + "(base_entity_id) values ( ? ) ON conflict(base_entity_id) do nothing;";
protected static final String UPDATE_QUERY_SQL = "INSERT OR REPLACE INTO " + TABLE_NAME + "(base_entity_id, status) values ( ? , ? );";

public static void createTable(@NonNull SQLiteDatabase database) {
database.execSQL(CREATE_TABLE_SQL);
database.execSQL(ADD_STATUS_COLUMN);
}

/**
Expand All @@ -40,9 +42,9 @@ public int getOverdueCount(String countQuerySQL) {
*
* @param baseEntityId the entity id of client
*/
public void upsert(String baseEntityId) {
public void upsert(String baseEntityId, String status) {
try {
getWritableDatabase().execSQL(UPDATE_QUERY_SQL, new String[]{baseEntityId});
getWritableDatabase().execSQL(UPDATE_QUERY_SQL, new String[]{baseEntityId, status});
} catch (Exception e) {
Timber.e(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;

import timber.log.Timber;

Expand Down Expand Up @@ -74,7 +75,10 @@ protected void onHandleIntent(Intent intent) {
if (!serviceRecordList.isEmpty()) {
for (ServiceRecord serviceRecord : serviceRecordList) {

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"yyyy-MM-dd",
Locale.getDefault().toString().startsWith("ar") ? Locale.ENGLISH : Locale.getDefault()
);
String formattedDate = simpleDateFormat.format(serviceRecord.getDate());

ServiceType serviceType = recurringServiceTypeRepository.find(serviceRecord.getRecurringServiceId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
*/

public class ServiceCard extends LinearLayout {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yy");
private static final SimpleDateFormat SHORT_DATE_FORMAT = new SimpleDateFormat("dd/MM");

private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yy", Locale.ENGLISH);
private static final SimpleDateFormat SHORT_DATE_FORMAT = new SimpleDateFormat("dd/MM", Locale.ENGLISH);
private Context context;
private ImageView statusIV;
private TextView nameTV;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -67,18 +68,22 @@ private void init(Context context) {
this.context = context;
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.view_vaccine_group, this, true).setFilterTouchesWhenObscured(true);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
setLayoutParams(layoutParams);

READABLE_DATE_FORMAT = new SimpleDateFormat("dd MMMM, yyyy");
READABLE_DATE_FORMAT = new SimpleDateFormat(
"dd MMMM, yyyy",
Locale.getDefault().toString().startsWith("ar") ? Locale.ENGLISH : Locale.getDefault()
);

nameTV = findViewById(R.id.name_tv);
vaccinesGV = findViewById(R.id.vaccines_gv);
vaccinesGV.setExpanded(true);
recordAllTV = findViewById(R.id.record_all_tv);
recordAllTV.setOnClickListener(this);

}

public VaccineGroup(Context context, AttributeSet attrs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public void testCreateTableExecutesCorrectSQLQuery() {

VaccineOverdueCountRepository.createTable(sqliteDatabase);

Mockito.verify(sqliteDatabase).execSQL(stringArgumentCaptor.capture());
Mockito.verify(sqliteDatabase, Mockito.times(2)).execSQL(stringArgumentCaptor.capture());

String sQLExecuted = stringArgumentCaptor.getValue();

Assert.assertNotNull(sQLExecuted);
Assert.assertEquals(VaccineOverdueCountRepository.CREATE_TABLE_SQL, sQLExecuted);
Assert.assertEquals(VaccineOverdueCountRepository.ADD_STATUS_COLUMN, sQLExecuted);

}

Expand Down Expand Up @@ -95,14 +95,15 @@ public void testGetOverdueCountReturnsZeroIfCursorNull() {
@Test
public void testUpsertExecuteCorrectUpdateAndInsertQuery() {
String TEST_BASE_ENTIY_ID = "test-id";
String STATUS = "urgent";

Mockito.doNothing().when(sqliteDatabase).execSQL(ArgumentMatchers.anyString(), ArgumentMatchers.any(String[].class));
Mockito.doReturn(sqliteDatabase).when(overdueCountRepository).getWritableDatabase();

ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String[]> stringArrayArgumentCaptor = ArgumentCaptor.forClass(String[].class);

overdueCountRepository.upsert(TEST_BASE_ENTIY_ID);
overdueCountRepository.upsert(TEST_BASE_ENTIY_ID, STATUS);

Mockito.verify(sqliteDatabase).execSQL(stringArgumentCaptor.capture(), stringArrayArgumentCaptor.capture());

Expand All @@ -113,8 +114,9 @@ public void testUpsertExecuteCorrectUpdateAndInsertQuery() {

String[] resultParameters = stringArrayArgumentCaptor.getValue();
Assert.assertNotNull(resultParameters);
Assert.assertEquals(1, resultParameters.length);
Assert.assertEquals(2, resultParameters.length);
Assert.assertEquals(TEST_BASE_ENTIY_ID, resultParameters[0]);
Assert.assertEquals(STATUS, resultParameters[1]);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
Expand All @@ -74,7 +75,10 @@ public class DetailActivity extends AppCompatActivity implements VaccinationActi
public static Gender gender;

public static final String EXTRA_CHILD_DETAILS = "child_details";
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
"dd-MM-yyyy",
Locale.getDefault().toString().startsWith("ar") ? Locale.ENGLISH : Locale.getDefault()
);
private ImmunizationFragment immunizationFragment;

public CommonPersonObjectClient getChildDetails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Random;

/**
* Created by keyman on 01/08/2017.
*/
public class SampleUtil {
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
"dd/MM/yyyy",
Locale.getDefault().toString().startsWith("ar") ? Locale.ENGLISH : Locale.getDefault()
);

public static final String ENTITY_ID = "1";
public static final String DOB_STRING = "2018-06-01T00:00:00.000Z";
Expand Down