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

Issue68 #69

Merged
merged 2 commits into from
May 5, 2020
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.
Jump to
Jump to file
Failed to load files.
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=1.1.21-SNAPSHOT
VERSION_NAME=1.1.22-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Growth Monitoring Application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.smartregister.growthmonitoring.repository.HeightRepository;
import org.smartregister.growthmonitoring.repository.WeightRepository;
import org.smartregister.growthmonitoring.util.AppProperties;
import org.smartregister.growthmonitoring.util.GrowthMonitoringUtils;
import org.smartregister.growthmonitoring.util.ImageUtils;
import org.smartregister.util.DatePickerUtils;
import org.smartregister.util.OpenSRPImageLoader;
Expand Down Expand Up @@ -166,11 +167,14 @@ public View onCreateView(final LayoutInflater inflater, final ViewGroup containe
currentGrowthDate = heightWrapper.getUpdatedHeightDate();
}

earlierDatePicker.setMaxDate(Calendar.getInstance().getTimeInMillis());
if (dateOfBirth != null) {
earlierDatePicker.setMinDate(dateOfBirth.getTime());
long dobTime = GrowthMonitoringUtils.cleanTimestamp(dateOfBirth.getTime());
earlierDatePicker.setMinDate(dobTime);
}

long today = GrowthMonitoringUtils.cleanTimestamp(Calendar.getInstance().getTimeInMillis());
earlierDatePicker.setMaxDate(today);

nameView.setText(weightWrapper.getPatientName());

if (StringUtils.isNotBlank(weightWrapper.getPatientNumber())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.smartregister.growthmonitoring.domain.WeightWrapper;
import org.smartregister.growthmonitoring.listener.GrowthMonitoringActionListener;
import org.smartregister.growthmonitoring.util.AppProperties;
import org.smartregister.growthmonitoring.util.GrowthMonitoringUtils;
import org.smartregister.growthmonitoring.util.ImageUtils;
import org.smartregister.util.DatePickerUtils;
import org.smartregister.util.OpenSRPImageLoader;
Expand Down Expand Up @@ -150,11 +151,14 @@ public View onCreateView(final LayoutInflater inflater, final ViewGroup containe
setWeight();
setHeight();

earlierDatePicker.setMaxDate(Calendar.getInstance().getTimeInMillis());
if (dateOfBirth != null) {
earlierDatePicker.setMinDate(dateOfBirth.getTime());
long dobTime = GrowthMonitoringUtils.cleanTimestamp(dateOfBirth.getTime());
earlierDatePicker.setMinDate(dobTime);
}

long today = GrowthMonitoringUtils.cleanTimestamp(Calendar.getInstance().getTimeInMillis());
earlierDatePicker.setMaxDate(today);

nameView.setText(weightWrapper.getPatientName());

if (StringUtils.isNotBlank(weightWrapper.getPatientNumber())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.joda.time.LocalDate;
import org.opensrp.api.constants.Gender;
import org.smartregister.growthmonitoring.domain.WeightZScore;
import org.smartregister.growthmonitoring.listener.ViewMeasureListener;
Expand Down Expand Up @@ -114,10 +115,11 @@ public static AppProperties getProperties(android.content.Context context) {

/**
* Parse CSV file and build query String for persisting values in the DB
* @param gender Gender for which the chart values belong to
*
* @param gender Gender for which the chart values belong to
* @param context
* @param filename CSV file name
* @param tableName Table where values will be stored
* @param filename CSV file name
* @param tableName Table where values will be stored
* @param csvHeadingColumnMap CSV Headings map
* @return Query String
*/
Expand All @@ -130,7 +132,7 @@ public static String getDumpCsvQuery(Gender gender, Context context, String file

HashMap<Integer, Boolean> columnStatus = new HashMap<>();

queryString = new StringBuilder("INSERT INTO `" + tableName + "` ( `" + GrowthMonitoringConstants.ColumnHeaders.COLUMN_SEX + "`");
queryString = new StringBuilder("INSERT INTO `" + tableName + "` ( `" + GrowthMonitoringConstants.ColumnHeaders.COLUMN_SEX + "`");
for (CSVRecord record : csvParser) {
if (csvParser.getCurrentLineNumber() == 2) {// The second line
queryString.append(")\n VALUES (\"").append(gender.name()).append("\"");
Expand Down Expand Up @@ -162,4 +164,11 @@ public static String getDumpCsvQuery(Gender gender, Context context, String file
}
return null;
}

/**
* This methods cleans a timestamp generated from date string to set value to a consistent time portion at the start of day
*/
public static long cleanTimestamp(long rawTimestamp) {
return new LocalDate(rawTimestamp).toDateTimeAtStartOfDay().toDate().getTime();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.smartregister.growthmonitoring.utils;
package org.smartregister.growthmonitoring.util;

import org.junit.Assert;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package org.smartregister.growthmonitoring.utils;
package org.smartregister.growthmonitoring.util;

import android.os.Build;

import org.joda.time.LocalDateTime;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.opensrp.api.constants.Gender;

import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.smartregister.growthmonitoring.BuildConfig;
import org.smartregister.growthmonitoring.util.GrowthMonitoringConstants;
import org.smartregister.growthmonitoring.util.GrowthMonitoringUtils;

import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -49,4 +47,35 @@ public void getDumpCsvQueryReturnsCorrectQueryString() {
String sqlQueryString = GrowthMonitoringUtils.getDumpCsvQuery(Gender.MALE, RuntimeEnvironment.application.getApplicationContext(), "weight_z_scores_male.csv", "test_table", CSV_HEADING_COLUMN_MAP);
Assert.assertTrue(sqlQueryString.startsWith(queryStringStart));
}

@Test
public void assertStandardiseCalendarDateSetsConsistentTimePortion() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 9);
calendar.set(Calendar.MINUTE, 3);
calendar.set(Calendar.SECOND, 1);
calendar.set(Calendar.MILLISECOND, 1000);

GrowthMonitoringUtils.standardiseCalendarDate(calendar);

Assert.assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
Assert.assertEquals(0, calendar.get(Calendar.SECOND));
Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND));

}

@Test
public void assertCleanTimestampSetsConsistentTimePortion() {

LocalDateTime localDateTime = new LocalDateTime().plusHours(3).plusMinutes(5);
LocalDateTime localDateTime2 = new LocalDateTime().plusHours(7).minusMinutes(2);

Assert.assertNotEquals(localDateTime.toDate().getTime(), localDateTime2.toDate().getTime());

long cleanDate1 = GrowthMonitoringUtils.cleanTimestamp(localDateTime.toDate().getTime());
long cleanDate2 = GrowthMonitoringUtils.cleanTimestamp(localDateTime2.toDate().getTime());

Assert.assertEquals(cleanDate1, cleanDate2);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.smartregister.growthmonitoring.utils;
package org.smartregister.growthmonitoring.util;

import org.junit.Assert;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.smartregister.growthmonitoring.utils;
package org.smartregister.growthmonitoring.util;

import org.junit.Assert;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.smartregister.growthmonitoring.utils;
package org.smartregister.growthmonitoring.util;

import org.junit.Assert;
import org.junit.Test;
Expand Down