Skip to content

Commit

Permalink
Merge pull request #237 from OpenSRP/immunization
Browse files Browse the repository at this point in the history
Added child visit events
  • Loading branch information
rkodev authored Aug 26, 2019
2 parents 6a63cf6 + d7e10a7 commit de09086
Show file tree
Hide file tree
Showing 22 changed files with 584 additions and 174 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=0.1.5-SNAPSHOT
VERSION_NAME=0.1.6-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client CHW Anc Library
Expand Down
2 changes: 1 addition & 1 deletion opensrp-chw-anc/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
POM_SETTING_NAME=OpenSRP Client Chw Anc
POM_SETTING_ARTIFACT_ID=opensrp-client-chw-anc
POM_SETTING_PACKAGING=aar
VERSION_NAME=0.1.11-SNAPSHOT
VERSION_NAME=0.1.12-SNAPSHOT
VERSION_CODE=1
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ public void redrawVisitUI() {
boolean valid = actionList.size() > 0;
for (Map.Entry<String, BaseAncHomeVisitAction> entry : actionList.entrySet()) {
BaseAncHomeVisitAction action = entry.getValue();
if (!action.isOptional()
&& action.getActionStatus() == BaseAncHomeVisitAction.Status.PENDING
&& action.isValid()
if (
(!action.isOptional() && (action.getActionStatus() == BaseAncHomeVisitAction.Status.PENDING && action.isValid()))
|| !action.isEnabled()
) {
valid = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ protected void onCreation() {
upArrow.setColorFilter(getResources().getColor(R.color.text_blue), PorterDuff.Mode.SRC_ATOP);
actionBar.setHomeAsUpIndicator(upArrow);
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
toolbar.setNavigationOnClickListener(v -> finish());
appBarLayout = findViewById(R.id.collapsing_toolbar_appbarlayout);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
appBarLayout.setOutlineProvider(null);
Expand Down Expand Up @@ -373,7 +368,6 @@ public void setFamilyStatus(AlertStatus status) {
}
}


@Override
public void setMemberName(String memberName) {
text_view_anc_member_name.setText(memberName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ private void setUpActionBar() {
upArrow.setColorFilter(getResources().getColor(R.color.text_blue), PorterDuff.Mode.SRC_ATOP);
actionBar.setHomeAsUpIndicator(upArrow);
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
toolbar.setNavigationOnClickListener(v -> finish());
}

public void setUpView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,20 @@ public void onBindViewHolder(@NotNull MyViewHolder holder, int position) {
holder.descriptionText.setVisibility(View.VISIBLE);
holder.invalidText.setVisibility(View.GONE);
holder.descriptionText.setText(ancHomeVisitAction.getSubTitle());

boolean isOverdue = ancHomeVisitAction.getScheduleStatus() == BaseAncHomeVisitAction.ScheduleStatus.OVERDUE &&
ancHomeVisitAction.isEnabled();

holder.descriptionText.setTextColor(
isOverdue ? context.getResources().getColor(R.color.alert_urgent_red) :
context.getResources().getColor(android.R.color.darker_gray)
);

} else {
holder.descriptionText.setVisibility(View.GONE);
holder.invalidText.setVisibility(View.VISIBLE);
holder.invalidText.setText(Html.fromHtml("<i>" + ancHomeVisitAction.getDisabledMessage() + "</i>"));
}

holder.descriptionText.setVisibility(View.VISIBLE);

boolean isOverdue = ancHomeVisitAction.getScheduleStatus() == BaseAncHomeVisitAction.ScheduleStatus.OVERDUE &&
ancHomeVisitAction.isEnabled();

holder.descriptionText.setTextColor(
isOverdue ? context.getResources().getColor(R.color.alert_urgent_red) :
context.getResources().getColor(android.R.color.darker_gray)
);
} else {
holder.descriptionText.setVisibility(View.GONE);
}
Expand All @@ -122,6 +121,10 @@ public void onBindViewHolder(@NotNull MyViewHolder holder, int position) {

private int getCircleColor(BaseAncHomeVisitAction ancHomeVisitAction) {
int color_res;
boolean valid = ancHomeVisitAction.isValid() && ancHomeVisitAction.isEnabled();
if (!valid)
return R.color.transparent_gray;

switch (ancHomeVisitAction.getActionStatus()) {
case PENDING:
color_res = R.color.transparent_gray;
Expand All @@ -140,8 +143,10 @@ private int getCircleColor(BaseAncHomeVisitAction ancHomeVisitAction) {
}

private void bindClickListener(View view, final BaseAncHomeVisitAction ancHomeVisitAction) {
if (!ancHomeVisitAction.isEnabled())
if (!ancHomeVisitAction.isEnabled() || !ancHomeVisitAction.isValid()) {
view.setOnClickListener(null);
return;
}

view.setOnClickListener(v -> {
if (StringUtils.isNotBlank(ancHomeVisitAction.getFormName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class VaccineDisplay {
private VaccineWrapper vaccineWrapper;
private Date startDate;
private Date endDate;
private Date dateGiven;
private Boolean isValid;

public VaccineWrapper getVaccineWrapper() {
Expand All @@ -34,6 +35,14 @@ public void setEndDate(Date endDate) {
this.endDate = endDate;
}

public Date getDateGiven() {
return dateGiven;
}

public void setDateGiven(Date dateGiven) {
this.dateGiven = dateGiven;
}

public Boolean getValid() {
return isValid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class Visit {
private String visitId;
private String visitType;
private String parentVisitID;
private String baseEntityId;
private Date date;
private Date updatedAt;
Expand Down Expand Up @@ -35,6 +36,14 @@ public void setVisitType(String visitType) {
this.visitType = visitType;
}

public String getParentVisitID() {
return parentVisitID;
}

public void setParentVisitID(String parentVisitID) {
this.parentVisitID = parentVisitID;
}

public String getBaseEntityId() {
return baseEntityId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class VisitDetail {
private String visitId;
private String baseEntityId;
private String visitKey;
private String parentCode;
private String details; //
private String humanReadable; //
private String jsonDetails;
Expand Down Expand Up @@ -48,6 +49,14 @@ public void setVisitKey(String visitKey) {
this.visitKey = visitKey;
}

public String getParentCode() {
return parentCode;
}

public void setParentCode(String parentCode) {
this.parentCode = parentCode;
}

public String getDetails() {
return details;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ private void prepareRadioView() {

String key = object.getString(JsonFormConstants.KEY);
rb.setTag(R.id.home_visit_radio_key, key);
rb.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked)
rb.setOnClickListener(v -> {
if (rb.isChecked())
onSelectOption(key);
});
} catch (JSONException e) {
Expand Down Expand Up @@ -342,13 +342,15 @@ public void setCount(String count) {
public void setValue(String value) {
if (getQuestionType() == QuestionType.BOOLEAN) {
if (radioButtonNo != null && radioButtonYes != null) {
setYesNoListenersActive(false);
if (value.equalsIgnoreCase("Yes")) {
radioButtonYes.setChecked(true);
radioButtonNo.setChecked(false);
} else if (value.equalsIgnoreCase("No")) {
radioButtonYes.setChecked(false);
radioButtonNo.setChecked(true);
}
setYesNoListenersActive(true);
}
} else if (getQuestionType() == QuestionType.DATE_SELECTOR) {
// datePicker.updateDate();
Expand All @@ -363,6 +365,9 @@ public void setValue(String value) {
}
} else if (getQuestionType() == QuestionType.RADIO) {
//
if (radioGroupDynamic.getChildCount() == 0)
prepareRadioView();

int count = radioGroupDynamic.getChildCount();
int x = 0;
while (count > x) {
Expand All @@ -376,6 +381,16 @@ public void setValue(String value) {
}
}

private void setYesNoListenersActive(boolean active) {
if (active) {
radioButtonYes.setOnClickListener(this);
radioButtonNo.setOnClickListener(this);
} else {
radioButtonYes.setOnClickListener(null);
radioButtonNo.setOnClickListener(null);
}
}

@Override
public void setOptions(List<JSONObject> options) {
if (this.optionList == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.smartregister.chw.anc.model.BaseHomeVisitImmunizationFragmentModel;
import org.smartregister.chw.anc.presenter.BaseHomeVisitImmunizationFragmentPresenter;
import org.smartregister.chw.anc.util.Constants;
import org.smartregister.chw.anc.util.JsonFormUtils;
import org.smartregister.chw.anc.util.NCUtils;
import org.smartregister.chw.opensrp_chw_anc.R;
import org.smartregister.immunization.db.VaccineRepo;
Expand Down Expand Up @@ -51,6 +52,7 @@ public class BaseHomeVisitImmunizationFragment extends BaseHomeVisitFragment imp
private CheckBox checkBoxNoVaccinesDone;
private DatePicker singleDatePicker;
private Button saveButton;
private SimpleDateFormat dateFormat = new SimpleDateFormat(Constants.DATE_FORMATS.NATIVE_FORMS, Locale.getDefault());

public static BaseHomeVisitImmunizationFragment getInstance(final BaseAncHomeVisitContract.VisitView view, String baseEntityID, Map<String, List<VisitDetail>> details, List<VaccineDisplay> vaccineDisplays) {
BaseHomeVisitImmunizationFragment fragment = new BaseHomeVisitImmunizationFragment();
Expand All @@ -60,6 +62,12 @@ public static BaseHomeVisitImmunizationFragment getInstance(final BaseAncHomeVis
for (VaccineDisplay vaccineDisplay : vaccineDisplays) {
fragment.vaccineDisplays.put(vaccineDisplay.getVaccineWrapper().getName(), vaccineDisplay);
}

if (details != null && details.size() > 0) {
fragment.jsonObject = NCUtils.getVisitJSONFromVisitDetails(baseEntityID, details, vaccineDisplays);
JsonFormUtils.populateForm(fragment.jsonObject, details);
}

return fragment;
}

Expand All @@ -85,7 +93,7 @@ public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container,
singleDatePicker = view.findViewById(R.id.earlier_date_picker);

if (vaccineDisplays.size() > 0)
initializeDatePicker(singleDatePicker, vaccineDisplays.entrySet().iterator().next().getValue());
initializeDatePicker(singleDatePicker, vaccineDisplays);

checkBoxNoVaccinesDone = view.findViewById(R.id.select);
checkBoxNoVaccinesDone.setOnClickListener(this);
Expand Down Expand Up @@ -120,9 +128,13 @@ public void setVaccineDisplays(Map<String, VaccineDisplay> vaccineDisplays) {
this.vaccineDisplays = vaccineDisplays;

// redraw all vaccine views
if (vaccineDisplays.size() > 0)
initializeDatePicker(singleDatePicker, vaccineDisplays.entrySet().iterator().next().getValue());
addVaccineViews();
if (vaccineDisplays.size() > 0 && singleDatePicker != null) {
initializeDatePicker(singleDatePicker, vaccineDisplays);
addVaccineViews();
}

// reset the json payload if the vaccine view was updated manually
this.jsonObject = null;
}

@Override
Expand Down Expand Up @@ -165,12 +177,41 @@ private void addVaccineViews() {
}

private void initializeDatePicker(@NotNull DatePicker datePicker, @NotNull VaccineDisplay vaccineDisplay) {
if (vaccineDisplay.getStartDate().getTime() > vaccineDisplay.getEndDate().getTime()) {
datePicker.setMinDate(vaccineDisplay.getStartDate().getTime());
datePicker.setMaxDate(vaccineDisplay.getStartDate().getTime());
Date startDate = vaccineDisplay.getStartDate();
Date endDate = (vaccineDisplay.getEndDate() != null && vaccineDisplay.getEndDate().getTime() < new Date().getTime()) ?
vaccineDisplay.getEndDate() : new Date();

if (startDate.getTime() > endDate.getTime()) {
datePicker.setMinDate(endDate.getTime());
datePicker.setMaxDate(endDate.getTime());
} else {
datePicker.setMinDate(vaccineDisplay.getStartDate().getTime());
datePicker.setMaxDate(vaccineDisplay.getEndDate().getTime());
datePicker.setMinDate(startDate.getTime());
datePicker.setMaxDate(endDate.getTime());
}
}

private void initializeDatePicker(@NotNull DatePicker datePicker, @NotNull Map<String, VaccineDisplay> vaccineDisplays) {
//compute the start date and the end date
Date startDate = null;
Date endDate = new Date();
for (Map.Entry<String, VaccineDisplay> entry : vaccineDisplays.entrySet()) {
VaccineDisplay display = entry.getValue();

// get the largest start date
if (startDate == null || display.getStartDate().getTime() < startDate.getTime())
startDate = display.getStartDate();

// get the lowest end date
if (display.getEndDate() != null && display.getEndDate().getTime() < endDate.getTime())
endDate = display.getEndDate();
}

if (startDate != null && startDate.getTime() > endDate.getTime()) {
datePicker.setMinDate(endDate.getTime());
datePicker.setMaxDate(endDate.getTime());
} else {
datePicker.setMinDate(startDate != null ? startDate.getTime() : endDate.getTime());
datePicker.setMaxDate(endDate.getTime());
}
}

Expand Down Expand Up @@ -230,22 +271,29 @@ private void onSave() {
// notify the view (write to json file then dismiss)

Date vaccineDate = getDateFromDatePicker(singleDatePicker);
SimpleDateFormat dateFormat = new SimpleDateFormat(Constants.DATE_FORMATS.NATIVE_FORMS, Locale.getDefault());
HashMap<VaccineWrapper, String> vaccineDateMap = new HashMap<>();

boolean multiModeActive = multipleVaccineDatePickerView.getVisibility() == View.GONE;

for (VaccineView vaccineView : vaccineViews) {
VaccineWrapper wrapper = vaccineDisplays.get(vaccineView.getVaccineName()).getVaccineWrapper();
VaccineDisplay display = vaccineDisplays.get(vaccineView.getVaccineName());
VaccineWrapper wrapper = display.getVaccineWrapper();
if (wrapper != null) {
if (!checkBoxNoVaccinesDone.isChecked() && vaccineView.getCheckBox().isChecked()) {
if (vaccineView.getDatePickerView() != null && multiModeActive) {
vaccineDateMap.put(wrapper, dateFormat.format(getDateFromDatePicker(vaccineView.getDatePickerView())));
Date dateGiven = getDateFromDatePicker(vaccineView.getDatePickerView());
vaccineDateMap.put(wrapper, dateFormat.format(dateGiven));
display.setDateGiven(dateGiven);
display.setValid(true);
} else if (vaccineDate != null) {
vaccineDateMap.put(wrapper, dateFormat.format(vaccineDate));
display.setDateGiven(vaccineDate);
display.setValid(true);
}
} else {
vaccineDateMap.put(wrapper, Constants.HOME_VISIT.VACCINE_NOT_GIVEN);
display.setDateGiven(null);
display.setValid(false);
}
}
}
Expand All @@ -262,6 +310,14 @@ private void onSave() {
}
}

/**
* reset the view payload
*/
public void resetViewPayload() {
jsonObject = null;
visitView.onDialogOptionUpdated("");
}

/**
* executed to close the vaccine screen
*/
Expand Down
Loading

0 comments on commit de09086

Please sign in to comment.