Skip to content

Commit

Permalink
Merge pull request #1377 from OpenSRP/lmh_child_visits
Browse files Browse the repository at this point in the history
Adds lmh-home-visit rule file
  • Loading branch information
paulinembabu authored Oct 5, 2020
2 parents aa599af + 7a4bbe7 commit 3095987
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 9 deletions.
2 changes: 1 addition & 1 deletion opensrp-chw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ android {
}

dependencies {
implementation('org.smartregister:opensrp-client-chw-core:1.5.4-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-chw-core:1.5.5-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'androidx.legacy', module: 'legacy-support-v4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ public Intent getStockReportIntent(Activity activity) {
public Intent getServiceReportIntent(Activity activity) {
return new Intent(activity, HIA2ReportsActivity.class);
}

@Override
public String childNavigationMenuCountString() {return null;
}
}
11 changes: 8 additions & 3 deletions opensrp-chw/src/lmh/assets/rule/home-visit-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ condition: "homeAlertRule.isVisitWithinThisMonth()"
actions:
- "homeAlertRule.buttonStatus = 'VISIT_THIS_MONTH'"
---
name: overdue
description: previous month not visited
priority: 2
condition: "homeAlertRule.evaluateIfOverdueWithinMonth(1)"
actions:
- "homeAlertRule.buttonStatus = 'OVERDUE'"
---
name: due
description: due first day of month and same month
priority: 3
condition: "homeAlertRule.isLmhChildDueWithinMonth()"
condition: "homeAlertRule.isDueWithinMonth()"
actions:
- "homeAlertRule.buttonStatus = 'DUE'"


Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
package org.smartregister.chw.custom_view;

public class NavigationMenuFlv extends DefaultNavigationMenuFlv {
@Override
public boolean hasCommunityResponders() {
return false;
}

@Override
public String childNavigationMenuCountString() {
return "Select count(*)\n" +
" FROM ec_child\n" +
" LEFT JOIN ec_family ON ec_child.relational_id = ec_family.id COLLATE NOCASE \n" +
" LEFT JOIN ec_family_member ON ec_family_member.base_entity_id = ec_family.primary_caregiver COLLATE NOCASE \n" +
" LEFT JOIN (select base_entity_id , max(visit_date) visit_date from visits GROUP by base_entity_id) VISIT_SUMMARY ON VISIT_SUMMARY.base_entity_id = ec_child.base_entity_id \n" +
" WHERE ec_child.date_removed is null\n" +
" AND (( ifnull(ec_child.entry_point,'') <> 'PNC' ) or (ifnull(ec_child.entry_point,'') = 'PNC' and ( date(ec_child.dob, '+28 days') <= date() \n" +
" and ((SELECT is_closed FROM ec_family_member WHERE base_entity_id = ec_child.mother_entity_id ) = 0))) \n" +
" or (ifnull(ec_child.entry_point,'') = 'PNC' \n" +
" and (SELECT is_closed FROM ec_family_member WHERE base_entity_id = ec_child.mother_entity_id ) = 1)) \n" +
" and CASE WHEN ec_child.gender = 'Male' \n" +
" THEN (\n" +
" ((( julianday('now') - julianday(ec_child.dob))/365.25) < +1.8) OR ( (((( julianday('now') - julianday(ec_child.dob))/365.25) >= +1.8) AND ((( julianday('now') - julianday(ec_child.dob))/365.25) <= +2)) AND\n" +
" ((SELECT count(*) FROM alerts WHERE alerts.caseID = ec_child.base_entity_id and alerts.status in ('normal','urgent', 'upcoming')) > 0))\n" +
" )\n" +
" WHEN ec_child.gender = 'Female' \n" +
" THEN (\n" +
" ((( julianday('now') - julianday(ec_child.dob))/365.25) < +1.8) OR ( (((( julianday('now') - julianday(ec_child.dob))/365.25) >= +1.8) AND ((( julianday('now') - julianday(ec_child.dob))/365.25) <= +2)) AND\n" +
" ((SELECT count(*) FROM alerts WHERE alerts.caseID = ec_child.base_entity_id and alerts.status in ('normal','urgent', 'upcoming')) > 0)) OR (((julianday('now') - julianday(ec_child.dob))/365.25) BETWEEN 9 AND 11)\n" +
" ) END";
}

}
2 changes: 2 additions & 0 deletions opensrp-chw/src/lmh/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
<string name="ipv">Polio (IPV)</string>
<string name="mcv_1">Measles (MCV 1)</string>
<string name="mcv_2">Measles (MCV 2)</string>
<string name="hpv_1">HPV 1</string>
<string name="hpv_2">HPV 2</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public Intent getServiceReportIntent(Activity activity) {
return null;
}

@Override
public String childNavigationMenuCountString() {
return null;
}

@Override
public boolean hasCommunityResponders() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ public static String getChildGender(String baseEntityID) {

return values.get(0) == null ? "" : values.get(0); // Return a default value of Low
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ public static String childDueVaccinesFilter(String tableName) {
}

private static String childDueVaccinesFilter(String dateColumn, int age, String entryPoint, String motherEntityId) {
return " (( ifnull(" + CoreConstants.TABLE_NAME.CHILD + "." + entryPoint + ",'') <> 'PNC' ) or (ifnull(" + CoreConstants.TABLE_NAME.CHILD + "." + entryPoint + ",'') = 'PNC' and ( date(" + CoreConstants.TABLE_NAME.CHILD + "." + dateColumn + ", '+28 days') <= date() and ((SELECT is_closed FROM ec_family_member WHERE base_entity_id = " + CoreConstants.TABLE_NAME.CHILD + "." + motherEntityId + " ) = 0))) or (ifnull(ec_child.entry_point,'') = 'PNC' " +
return " (( ifnull(" + CoreConstants.TABLE_NAME.CHILD + "." + entryPoint + ",'') <> 'PNC' ) " +
" or (ifnull(" + CoreConstants.TABLE_NAME.CHILD + "." + entryPoint + ",'') = 'PNC'" +
" and ( date(" + CoreConstants.TABLE_NAME.CHILD + "." + dateColumn + ", '+28 days') <= date() " +
" and ((SELECT is_closed FROM ec_family_member WHERE base_entity_id = " + CoreConstants.TABLE_NAME.CHILD + "." + motherEntityId + " ) = 0))) " +
" or (ifnull(ec_child.entry_point,'') = 'PNC' " +
" and (SELECT is_closed FROM ec_family_member WHERE base_entity_id = ec_child.mother_entity_id ) = 1)) " +
" and CASE WHEN ec_child.gender = 'Male' THEN (((( julianday('now') - julianday(ec_child.dob))/365.25) < +" + age + ") and ((SELECT alerts.expiryDate FROM alerts WHERE alerts.caseID = ec_child.base_entity_id and alerts.status in ('normal','urgent')) > date())) " +
" WHEN ec_child.gender = 'Female' THEN (((( julianday('now') - julianday(ec_child.dob))/365.25) < +" + age + ") and ((SELECT alerts.expiryDate FROM alerts WHERE alerts.caseID = ec_child.base_entity_id and alerts.status in ('normal','urgent')) > date())) OR (SELECT ( ((julianday('now') - julianday(ec_child.dob))/365.25) BETWEEN 9 AND 11) AND ((SELECT alerts.expiryDate FROM alerts WHERE alerts.caseID = ec_child.base_entity_id and alerts.status in ('normal','urgent') and alerts.scheduleName LIKE '%HPV%' COLLATE NOCASE) > date())) END";
" and CASE WHEN ec_child.gender = 'Male' \n" +
" THEN (\n" +
" ((( julianday('now') - julianday(ec_child.dob))/365.25) < +1.8) OR ( (((( julianday('now') - julianday(ec_child.dob))/365.25) >= +1.8) AND ((( julianday('now') - julianday(ec_child.dob))/365.25) <= +2)) AND\n" +
" ((SELECT count(*) FROM alerts WHERE alerts.caseID = ec_child.base_entity_id and alerts.status in ('normal','urgent', 'upcoming')) > 0))\n" +
" )\n" +
" WHEN ec_child.gender = 'Female' \n" +
" THEN (\n" +
" ((( julianday('now') - julianday(ec_child.dob))/365.25) < +1.8) OR ( (((( julianday('now') - julianday(ec_child.dob))/365.25) >= +1.8) AND ((( julianday('now') - julianday(ec_child.dob))/365.25) <= +2)) AND\n" +
" ((SELECT count(*) FROM alerts WHERE alerts.caseID = ec_child.base_entity_id and alerts.status in ('normal','urgent', 'upcoming')) > 0)) OR (((julianday('now') - julianday(ec_child.dob))/365.25) BETWEEN 9 AND 11)\n" +
" ) END ";
}

private static String tableColConcat(String tableName, String columnName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package org.smartregister.chw.fragment;

import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.Robolectric;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.Context;
import org.smartregister.CoreLibrary;
import org.smartregister.chw.BaseUnitTest;
import org.smartregister.chw.fp.contract.BaseFpRegisterFragmentContract;
import org.smartregister.commonregistry.CommonPersonObjectClient;
import org.smartregister.commonregistry.CommonRepository;
import org.smartregister.receiver.SyncStatusBroadcastReceiver;

import java.util.ArrayList;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

public class FpRegisterFragmentTest extends BaseUnitTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private Context context;
@Mock
private FpRegisterFragment fpRegisterFragment;

@Mock
private CommonRepository commonRepository;

@Mock
private View view;

private FragmentActivity activity;
private ActivityController<AppCompatActivity> activityController;

@Mock
private ImageView imageView;

@Mock
private ProgressBar clientsProgressView;

@Mock
private TextView textView;

@Mock
private RelativeLayout relativeLayout;

@Mock
private EditText editText;

@Mock
private TextWatcher textWatcher;

@Mock
private View.OnKeyListener hideKeyboard;

@Mock
private ProgressBar syncProgressBar;

@Mock
private BaseFpRegisterFragmentContract.Presenter presenter;

@Mock
private CommonPersonObjectClient commonPersonObjectClient;


@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
fpRegisterFragment = Mockito.mock(FpRegisterFragment.class, Mockito.CALLS_REAL_METHODS);
ReflectionHelpers.setField(fpRegisterFragment, "presenter", presenter);
ReflectionHelpers.setField(fpRegisterFragment, "view", view);
ReflectionHelpers.setField(fpRegisterFragment, "dueOnlyLayout", view);
ReflectionHelpers.setField(fpRegisterFragment, "clientsProgressView", clientsProgressView);
ReflectionHelpers.setField(fpRegisterFragment, "dueFilterActive", true);
ReflectionHelpers.setField(fpRegisterFragment, "qrCodeScanImageView", imageView);
ReflectionHelpers.setField(fpRegisterFragment, "headerTextDisplay", textView);
ReflectionHelpers.setField(fpRegisterFragment, "filterStatus", textView);
ReflectionHelpers.setField(fpRegisterFragment, "filterRelativeLayout", relativeLayout);
ReflectionHelpers.setField(fpRegisterFragment, "searchView", editText);
ReflectionHelpers.setField(fpRegisterFragment, "textWatcher", textWatcher);
ReflectionHelpers.setField(fpRegisterFragment, "hideKeyboard", hideKeyboard);
ReflectionHelpers.setField(fpRegisterFragment, "syncProgressBar", syncProgressBar);
ReflectionHelpers.setField(fpRegisterFragment, "syncButton", imageView);
ReflectionHelpers.setField(fpRegisterFragment, "globalQrSearch", false);

CoreLibrary.init(context);
when(context.commonrepository(anyString())).thenReturn(commonRepository);
activityController = Robolectric.buildActivity(AppCompatActivity.class).create().resume();
activity = activityController.get();
Context.bindtypes = new ArrayList<>();
SyncStatusBroadcastReceiver.init(activity);
}

@Test
public void testSetupViews() {
when(fpRegisterFragment.getActivity()).thenReturn(activity);
when(fpRegisterFragment.getContext()).thenReturn(activity);
View view = LayoutInflater.from(activity).inflate(org.smartregister.chw.core.R.layout.fragment_base_register, null);
fpRegisterFragment.setupViews(view);

View dueOnlyLayout = view.findViewById(org.smartregister.chw.core.R.id.due_only_layout);
dueOnlyLayout.setVisibility(View.VISIBLE);
View searchBarLayout = view.findViewById(org.smartregister.R.id.search_bar_layout);
searchBarLayout.setBackgroundResource(org.smartregister.chw.core.R.color.customAppThemeBlue);
assertEquals(View.VISIBLE, dueOnlyLayout.getVisibility());
}

@Test
public void testInitializePresenterActivityIsNull() {
fpRegisterFragment.initializePresenter();
TestCase.assertNotNull(fpRegisterFragment.presenter());
}

@Test
public void testInitializePresenter() {
Mockito.doReturn(activity).when(fpRegisterFragment).getActivity();

fpRegisterFragment.initializePresenter();
TestCase.assertNotNull(fpRegisterFragment.presenter());
}

@Test
public void testOpenProfile() {
when(fpRegisterFragment.getActivity()).thenReturn(activity);
fpRegisterFragment.openProfile(commonPersonObjectClient);
}

@After
public void tearDown() {
try {
activityController.pause().stop().destroy();
activity.finish();
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit 3095987

Please sign in to comment.