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

Issue fix 906 [DO NOT MERGE] #910

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f98d2f8
Update coveralls configuration
hamza-vd Jul 4, 2022
b558f03
issue 839 Calculation error in gestational age fixed
junaidwarsivd Jul 14, 2022
f856d14
Merge remote-tracking branch 'origin/fix-develop-errors' into issue-f…
junaidwarsivd Jul 14, 2022
2347393
added correction according to the PR review feedback
junaidwarsivd Aug 25, 2022
dc7bfa0
ignore annotation removed from the loginModelTest
junaidwarsivd Aug 25, 2022
9d25aff
upgraded to latest native form version
junaidwarsivd Aug 26, 2022
e2e1eef
changed StringUtils.isEmpty(widgetValue) to widgetValue != null becau…
junaidwarsivd Sep 22, 2022
e667f63
added StringUtils.isNotBlank
junaidwarsivd Sep 22, 2022
38ea021
Merge branch 'master' into issue-fix-839
junaidwarsivd Sep 22, 2022
80d51c5
removed the unused jsonexception import
junaidwarsivd Sep 23, 2022
b06ec88
Merge branch 'issue-fix-839' into issue-fix-906
junaidwarsivd Oct 3, 2022
39674fa
issue 906 fixed
junaidwarsivd Oct 5, 2022
068957f
volley dependency added
junaidwarsivd Oct 6, 2022
83813cb
upgraded native forms and client core dependency
junaidwarsivd Oct 11, 2022
59e25c6
updated the published snapshots for native and core forms
junaidwarsivd Oct 21, 2022
ea62452
event bus exception thrown in unit tests fixed
junaidwarsivd Oct 25, 2022
3824a2b
event bus exception thrown in unit tests fixed
junaidwarsivd Oct 25, 2022
f9bd803
fixed the remaining test
junaidwarsivd Oct 26, 2022
5758630
fixed codacy and tests
junaidwarsivd Oct 26, 2022
8e86ff3
removed unused import
junaidwarsivd Oct 26, 2022
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ subprojects {
ext.androidToolsBuildGradle = '30.0.3'
ext.androidBuildToolsVersion = '30.0.3'
ext.androidMinSdkVersion = 18
ext.androidCompileSdkVersion = 30
ext.androidTargetSdkVersion = 30
ext.androidCompileSdkVersion = 31
ext.androidTargetSdkVersion = 31
ext.androidAnnotationsVersion = '3.0.1'
ext.androidAnnotationsAPIVersion = '3.0.1'
ext.jacocoVersion = "0.7.9"
Expand Down
10 changes: 5 additions & 5 deletions opensrp-anc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ tasks.withType(Test) {

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation('org.smartregister:opensrp-client-native-form:2.1.19-PREVIEW-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-native-form:3.1.1-PREVIEW-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'recyclerview-v7'
exclude group: 'com.android.support', module: 'appcompat-v7'
Expand All @@ -189,7 +189,7 @@ dependencies {
exclude group: 'org.yaml', module: 'snakeyaml'
exclude group: 'io.ona.rdt-capture', module: 'lib'
}
implementation('org.smartregister:opensrp-client-core:4.3.26-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-core:6.0.0-BETA3-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.github.bmelnychuk', module: 'atv'
exclude group: 'com.google.guava', module: 'guava'
Expand Down Expand Up @@ -246,6 +246,7 @@ dependencies {
}

implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.mcxiaoke.volley:library:1.0.19'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation group: 'org.yaml', name: 'snakeyaml', version: '1.27'
Expand Down Expand Up @@ -326,10 +327,9 @@ task javadoc(type: Javadoc) {
classpath += configurations.compile
}

def jacocoReportPath,sourceDirs

def jacocoReportPath, sourceDirs
task coveralls {
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoTestReport/merged.xml"
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoRootReport/merged.xml"
sourceDirs = ["$project.projectDir/src/main/java"]
}

Expand Down
2 changes: 2 additions & 0 deletions opensrp-anc/src/main/assets/json.form/anc_profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@
"label_info_title": "{{anc_profile.step2.lmp_known.label_info_title}}",
"label_text_style": "bold",
"max_date": "today",
"secondary_value_field":"lmp_known_date",
"options": [
{
"key": "yes",
Expand Down Expand Up @@ -494,6 +495,7 @@
"label_info_text": "{{anc_profile.step2.ultrasound_done.label_info_text}}",
"label_info_title": "{{anc_profile.step2.ultrasound_done.label_info_title}}",
"label_text_style": "bold",
"secondary_value_field": "ultrasound_done_date",
"options": [
{
"key": "yes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description: step2_lmp_known_date
priority: 1
condition: "step2_lmp_known == 'yes'"
actions:
- "calculation = helper.getDateToday()"
- "calculation = helper.getSecondaryValue(step2_lmp_known_date)"
---
name: step2_lmp_edd
description: LMP EDD
Expand Down Expand Up @@ -40,7 +40,7 @@ description: step2_ultrasound_done_date
priority: 1
condition: "step2_ultrasound_done == 'yes'"
actions:
- "calculation = helper.getDateToday()"
- "calculation = helper.getSecondaryValue(step2_ultrasound_done_date)"
---
name: step2_ultrasound_edd
description: Ultrasound edd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class AncLibrary {
private final ActivityConfiguration activityConfiguration;
private AncMetadata ancMetadata = new AncMetadata();
private AppExecutors appExecutors;

private static EventBus eventBus;

private AncLibrary(@NonNull Context context, int dbVersion, @NonNull ActivityConfiguration activityConfiguration, @Nullable SubscriberInfoIndex subscriberInfoIndex, @Nullable RegisterQueryProvider registerQueryProvider) {
this(context, dbVersion, activityConfiguration, subscriberInfoIndex);
Expand All @@ -100,6 +100,7 @@ private AncLibrary(@NonNull Context context, int dbVersion, @NonNull ActivityCon

//Initialize JsonSpec Helper
this.jsonSpecHelper = new JsonSpecHelper(getApplicationContext());
if(eventBus == null)
setUpEventHandling();

//initialize configs processor
Expand Down Expand Up @@ -166,14 +167,15 @@ public android.content.Context getApplicationContext() {

private void setUpEventHandling() {
try {

EventBusBuilder eventBusBuilder = EventBus.builder()
.addIndex(new ANCEventBusIndex());

if (subscriberInfoIndex != null) {
eventBusBuilder.addIndex(subscriberInfoIndex);
}

eventBusBuilder.installDefaultEventBus();
eventBus = eventBusBuilder.installDefaultEventBus();
} catch (Exception e) {
Timber.e(e, " --> setUpEventHandling");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.json.JSONObject;
import org.smartregister.anc.library.AncLibrary;
import org.smartregister.anc.library.R;
import org.smartregister.anc.library.constants.ANCJsonFormConstants;
import org.smartregister.anc.library.contract.ContactContract;
import org.smartregister.anc.library.domain.Contact;
import org.smartregister.anc.library.model.PartialContact;
Expand Down Expand Up @@ -217,7 +218,7 @@ private void process(String[] mainContactForms) {
}
}
//Make profile always complete on second contact onwards
requiredFieldsMap.put(ConstantsUtils.JsonFormUtils.ANC_PROFILE_ENCOUNTER_TYPE, 0);
// requiredFieldsMap.put(ConstantsUtils.JsonFormUtils.ANC_PROFILE_ENCOUNTER_TYPE, 0);
requiredFieldsMap.put(ConstantsUtils.JsonFormUtils.ANC_TEST_TASKS_ENCOUNTER_TYPE, 0);

}
Expand Down Expand Up @@ -606,13 +607,21 @@ private void preProcessDefaultValues(JSONObject object) {
private void updateDefaultValues(JSONArray stepArray, int i, JSONObject fieldObject) throws JSONException {
if (defaultValueFields.contains(fieldObject.getString(JsonFormConstants.KEY))) {

String secondaryValue = null;
if (!fieldObject.has(JsonFormConstants.VALUE) ||
TextUtils.isEmpty(fieldObject.getString(JsonFormConstants.VALUE))) {

String defaultKey = fieldObject.getString(JsonFormConstants.KEY);
String mapValue = getMapValue(defaultKey);

if(fieldObject.has(ANCJsonFormConstants.KeyConstants.SECONDARY_VALUE_FIELD))
secondaryValue = getMapValue(fieldObject.getString(ANCJsonFormConstants.KeyConstants.SECONDARY_VALUE_FIELD));


if (mapValue != null) {
if(mapValue.startsWith("{"))
fieldObject.put(JsonFormConstants.VALUE, new JSONObject(mapValue));
else
fieldObject.put(JsonFormConstants.VALUE, mapValue);
fieldObject.put(JsonFormConstants.EDITABLE, editableFields.contains(defaultKey));
fieldObject.put(JsonFormConstants.READ_ONLY, editableFields.contains(defaultKey));
Expand All @@ -623,8 +632,16 @@ private void updateDefaultValues(JSONArray stepArray, int i, JSONObject fieldObj
if (fieldObject.has(JsonFormConstants.OPTIONS_FIELD_NAME)) {
boolean addDefaults = true;


for (int m = 0; m < fieldObject.getJSONArray(JsonFormConstants.OPTIONS_FIELD_NAME).length(); m++) {
String optionValue;
JSONObject optionsObject = fieldObject.getJSONArray(JsonFormConstants.OPTIONS_FIELD_NAME).getJSONObject(m);
if(optionsObject.has(JsonFormConstants.CONTENT_WIDGET) && secondaryValue != null)
{
JSONObject secondaryValueObject = ANCJsonFormUtils.populateSecondaryValues(secondaryValue,optionsObject);
optionsObject.put(JsonFormConstants.SECONDARY_VALUE,new JSONArray().put(secondaryValueObject));
}

if (fieldObject.getJSONArray(JsonFormConstants.OPTIONS_FIELD_NAME).getJSONObject(m)
.has(JsonFormConstants.VALUE)) {
optionValue = fieldObject.getJSONArray(JsonFormConstants.OPTIONS_FIELD_NAME).getJSONObject(m)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.smartregister.anc.library.constants;

import com.vijay.jsonwizard.constants.JsonFormConstants;

public class ANCJsonFormConstants extends JsonFormConstants {

public static class KeyConstants {
public static final String OPTIBP_BUTTON = "record_bp_using_optibp_button";
public static final String OPTIBP_BUTTON_SECOND = "record_bp_using_optibp_2nd_reading_button";
public static final String SECONDARY_VALUE_FIELD = "secondary_value_field";
public static final String SPECIFY_WIDGET = "specify_widget";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
*/
public class ContactInteractor extends BaseContactInteractor implements ContactContract.Interactor {
private Utils utils = new Utils();
private String edd = null;

public ContactInteractor() {
this(new AppExecutors());
Expand Down Expand Up @@ -130,6 +131,7 @@ public HashMap<String, String> finalizeContactForm(final Map<String, String> det

addTheContactDate(baseEntityId, details);
updateWomanDetails(details, womanDetail);
edd = details.get(DBConstantsUtils.KeyUtils.EDD);
if (referral != null && !TextUtils.isEmpty(details.get(DBConstantsUtils.KeyUtils.EDD))) {
addReferralGa(baseEntityId, details);
}
Expand Down Expand Up @@ -235,12 +237,19 @@ private PreviousContact preLoadPreviousContact(String baseEntityId, Map<String,
private String getCurrentContactState(String baseEntityId) throws JSONException {
List<PreviousContact> previousContactList = getPreviousContactRepository().getPreviousContacts(baseEntityId, null);
JSONObject stateObject = null;
String lastContactNo = null;
if (previousContactList != null) {
stateObject = new JSONObject();

for (PreviousContact previousContact : previousContactList) {
if(lastContactNo == null)
lastContactNo = previousContact.getContactNo();
if(previousContact.getKey().equals(CONTACT_DATE) && stateObject.has(CONTACT_DATE))
continue;

if(!lastContactNo.equals(previousContact.getContactNo()) && !stateObject.has(GEST_AGE_OPENMRS) && !TextUtils.isEmpty(edd))
stateObject.put(GEST_AGE_OPENMRS,String.valueOf(Utils.getGestationAgeFromEDDate(edd)));

if(stateObject.has(previousContact.getKey()))
continue;
stateObject.put(previousContact.getKey(), previousContact.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,16 @@ public static void updateCohabitants(String form, String baseEntityId) {
JSONObject jsonObject = new JSONObject(form);
JSONArray fields = ANCJsonFormUtils.getSingleStepFormfields(jsonObject);
JSONObject cohabitants = ANCJsonFormUtils.getFieldJSONObject(fields, DBConstantsUtils.KeyUtils.COHABITANTS);
JSONObject reminder = ANCJsonFormUtils.getFieldJSONObject(fields, DBConstantsUtils.KeyUtils.REMINDERS);

String value = cohabitants.optString(ConstantsUtils.KeyUtils.VALUE, "[]");

String remindersValue = reminder.optString(ConstantsUtils.KeyUtils.VALUE,"{}");


ContentValues contentValues = new ContentValues();
contentValues.put(DBConstantsUtils.KeyUtils.COHABITANTS, value);
contentValues.put(DBConstantsUtils.KeyUtils.REMINDERS,remindersValue);

updatePatient(baseEntityId, contentValues, getRegisterQueryProvider().getDetailsTable());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,14 @@ private static void processRadioButtonsSpecialWidget(JSONObject widget, List<Str
for (int i = 0; i < jsonArray.length(); i++) {

JSONObject jsonObject = jsonArray.getJSONObject(i);

if (widget.has(JsonFormConstants.VALUE) && !TextUtils.isEmpty(widget.getString(JsonFormConstants.VALUE)) &&
jsonObject.getString(JsonFormConstants.KEY).equals(widget.getString(JsonFormConstants.VALUE))) {
String widgetValue = null;
if(widget.has(JsonFormConstants.VALUE))
widgetValue = widget.getString(JsonFormConstants.VALUE);
if(StringUtils.isNotBlank(widgetValue) && widgetValue.startsWith("{"))
widgetValue = new JSONObject(widgetValue).getString(JsonFormConstants.VALUE);

if (StringUtils.isNotBlank(widgetValue) && !TextUtils.isEmpty(widgetValue) &&
jsonObject.getString(JsonFormConstants.KEY).equals(widgetValue)) {

if (jsonObject.has(JsonFormConstants.SECONDARY_VALUE) &&
!TextUtils.isEmpty(jsonObject.getString(JsonFormConstants.SECONDARY_VALUE))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,4 +1024,22 @@ public class Template {
public String title = "";
public String detail = "";
}

public static JSONObject populateSecondaryValues(String secondaryValue , JSONObject optionsObject)
{
JSONObject secondaryValueObject = new JSONObject();
JSONArray secondaryValueArray = new JSONArray();
try {
secondaryValueArray.put(secondaryValue);
secondaryValueObject.put(JsonFormConstants.KEY, optionsObject.getString(JsonFormConstants.KEY));
secondaryValueObject.put(JsonFormConstants.VALUES, secondaryValueArray);
secondaryValueObject.put(JsonFormConstants.TYPE, optionsObject.getString(JsonFormConstants.CONTENT_WIDGET));
}
catch (JSONException e)
{
Timber.e(e);
}
return secondaryValueObject;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ protected void populateDescendants(JSONObject jsonObject) {
try {
JSONObject parentField = JsonFormUtils.getFieldJSONObject(getFormStep().getJSONArray(FIELDS),
parents.get(jsonObject.getString(KEY)));
String parentId = parentField.getString(VALUE);

String parentId = "";
if (!StringUtils.isNotBlank(parentField.optString(VALUE)) && parentField.optString(VALUE).charAt(0) == '{') {
parentId = new JSONObject(parentField.optString(VALUE)).optString(VALUE);
} else {
parentId = parentField.getString(VALUE);
}
populateLocationSpinner(jsonObject, parentId, jsonObject.getString(KEY), descendants.get(jsonObject.getString(KEY)));
} catch (JSONException e) {
Timber.e(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package org.smartregister.anc.library.interactor;


import com.google.common.collect.ImmutableMap;

import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.anc.library.AncLibrary;
import org.smartregister.anc.library.activity.BaseUnitTest;
import org.smartregister.domain.Setting;
import org.smartregister.repository.AllSettings;
import org.smartregister.util.AppProperties;
import org.smartregister.util.Utils;

import java.util.Map;

/**
* Created by ndegwamartin on 30/08/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Utils.class})
public class CharacteristicsInteractorTest extends BaseUnitTest {


Expand All @@ -29,10 +38,16 @@ public class CharacteristicsInteractorTest extends BaseUnitTest {
@Mock
private AncLibrary ancLibrary;

@Mock
private AppProperties appProperties;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ReflectionHelpers.setStaticField(AncLibrary.class, "instance", ancLibrary);
PowerMockito.mockStatic(Utils.class);
PowerMockito.when(Utils.getProperties(ArgumentMatchers.any())).thenReturn(appProperties);
Mockito.when(appProperties.getProperty(ArgumentMatchers.anyString(),ArgumentMatchers.anyString())).thenReturn("true");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ public void setUp() {
// It was transferred from the app module to the lib module
// The fix might to add an actual OpenSRP application but again UserService testing should be in the
// opensrp-client-core library which provides this data
// ignoring this test as it is already present in Login presenter

@Ignore
@Test
public void testIsUserLoggedOutShouldReturnTrue() {
Assert.assertTrue(model.isUserLoggedOut());
}

@Ignore

@Test
public void testGetOpenSRPContextShouldReturnValidValue() {
Assert.assertNotNull(model.getOpenSRPContext());
Expand Down
Loading