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

Added reasons for not receiving de-worming #276

Open
wants to merge 2 commits into
base: ecd-main-impl
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import org.json.JSONObject;
import org.smartregister.chw.R;
import org.smartregister.chw.anc.actionhelper.HomeVisitActionHelper;
import org.smartregister.chw.anc.domain.MemberObject;
import org.smartregister.chw.anc.domain.VisitDetail;
import org.smartregister.chw.anc.model.BaseAncHomeVisitAction;
import org.smartregister.chw.util.Constants;
import org.smartregister.chw.util.Utils;
import org.smartregister.chw.util.UtilsFlv;
import org.smartregister.domain.Alert;
import org.smartregister.util.JsonFormUtils;

Expand All @@ -24,12 +27,14 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

import timber.log.Timber;

public class DewormingAction extends HomeVisitActionHelper {
private Context context;
private String serviceIteration;
private final Context context;
private final String serviceIteration;
private MemberObject memberObject;
private String str_date;
private Date parsedDate;
private Alert alert;
Expand All @@ -40,11 +45,12 @@ public DewormingAction(Context context, String serviceIteration, Alert alert) {
this.alert = alert;
}

@Override
public void onJsonFormLoaded(String jsonString, Context context, Map<String, List<VisitDetail>> details) {
// prevent default behavoiur
public DewormingAction(Context context, String serviceIteration, Alert alert, MemberObject member) {
this(context,serviceIteration,alert);
this.memberObject=member;
}


@Override
public BaseAncHomeVisitAction.ScheduleStatus getPreProcessedStatus() {
return isOverDue() ? BaseAncHomeVisitAction.ScheduleStatus.OVERDUE : BaseAncHomeVisitAction.ScheduleStatus.DUE;
Expand Down Expand Up @@ -72,6 +78,22 @@ public JSONObject preProcess(JSONObject jsonObject, String iteration) {
return jsonObject;
}

@Override
public String getPreProcessed() {
try{
String formName= Constants.JSON_FORM.CHILD_HOME_VISIT.getDEWORMING();
JSONObject form= org.smartregister.chw.util.JsonFormUtils.getJson(context, formName, memberObject.getBaseEntityId());

String minDate= UtilsFlv.changeDateFormat(memberObject.getDob(),"yyyy-MM-dd'T'HH:mm:ss","dd-MM-yyyy");
Objects.requireNonNull(JsonFormUtils.getFieldJSONObject(JsonFormUtils.fields(form), "deworming{0}_date"))
.put(JsonFormConstants.MIN_DATE, minDate);
return form.toString().replace("{0}",serviceIteration);
}
catch (Exception e){Timber.e(e);}
return "";
}


@Override
public void onPayloadReceived(String jsonPayload) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,6 @@ public String getPreProcessed() {
}

public void onPayloadReceived(String jsonPayload) {
/** todo nitusima to assit on this since he is the one who improved the function using lambda function
notDoneVaccines.clear();
completedVaccines.clear();

JSONArray jsonArray = UtilsFlv.jsonGet(jsonPayload,"step1.fields",new JSONArray());

Set<String> vaccinesKeys=new FnList<>(wrappers)
.map(VaccineWrapper::getName)
.map(NCUtils::removeSpaces)
.toSet();

//TODO make the check used in the filter method below more effective and intuitive to serve as a general check for if the field is vaccine or not
FnList.range( jsonArray.length() )
.map( jsonArray::getJSONObject )
.map( UtilsFlv::getFieldKeyValuePair )
.filter( field -> vaccinesKeys.contains(field.key))
.forEachItem( field -> {
if( UtilsFlv.isValidDOBDateFormat( field.value )){
List<String> vacs = UtilsFlv.coalesce(completedVaccines.get(field.value),new ArrayList<>());
vacs.add(field.key);
completedVaccines.put(field.value, vacs);
}
else {notDoneVaccines.add(field.key);}
});**/

try {
notDoneVaccines.clear();
completedVaccines.clear();
Expand Down Expand Up @@ -201,12 +176,17 @@ public String evaluateSubTitle() {
completedBuilder.append(getTranslatedValue(vac.toUpperCase()));
}

if(!entry.getKey().matches("\\d{4}-\\d{2}-\\d{2}")){
continue;
}

if (completedBuilder.length() > 0) {
try {
if (builder.length() > 0) {
builder.append(" · ");
}


builder.append(MessageFormat.format("{0} {1} {2}",
completedBuilder.toString(),
context.getString(R.string.given_on_with_spaces),
Expand Down
125 changes: 121 additions & 4 deletions opensrp-chw/src/nacp/assets/json.form-sw/child_hv_deworming.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,138 @@
"encounter_location": ""
},
"step1": {
"title": "Deworming {0} dose",
"title": "Dozi {0} ya tiba na kinga ya minyoo",
"fields": [
{
"key": "deworming{0}_date",
"key": "has_received_deworming{0}",
"openmrs_entity_parent": "84879AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"openmrs_entity": "concept",
"openmrs_entity_id": "1418AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"openmrs_entity_id": "has_received_deworming{0}",
"type": "native_radio",
"image": "ic_form_deworming",
"label": "Je, dozi {0} ya minyoo ilitolewa?",
"v_required": {
"value": "true",
"err": "Tafadhali Chagua Ndio au Hapana"
},
"options": [
{
"key": "yes",
"text": "Ndio",
"openmrs_entity": "concept",
"openmrs_entity_id": "yes"
},
{
"key": "no",
"text": "Hapana",
"openmrs_entity": "concept",
"openmrs_entity_id": "no"
}
]
},
{
"key": "deworming{0}_date",
"openmrs_entity_parent": "deworming{0}_date",
"openmrs_entity": "concept",
"openmrs_entity_id": "deworming{0}_date",
"type": "date_picker",
"image": "ic_form_deworming",
"hint": "Je, dawa ya minyoo {0} ilitolewa lini?",
"min_date": "today-120y",
"max_date": "today",
"v_required": {
"value": "true",
"err": "Tafadhali weka tarehe ambayo dawa ya minyoo ilitolewa"
"err": "Tafadhali jaza tarehe ambayo dawa ya minyoo ilitolewa"
},
"relevance": {
"step1:has_received_deworming{0}": {
"type": "string",
"ex": "equalTo(., \"yes\")"
}
}
},
{
"key": "reason_no_medicine_deworming{0}",
"openmrs_entity_parent": "reason_no_medicine_deworming{0}",
"openmrs_entity": "concept",
"openmrs_entity_id": "reason_no_medicine_deworming{0}",
"type": "check_box",
"label": "Jaza sababu ya kutotolewa dawa ya minyoo",
"v_required": {
"value": "true",
"err": "Tafadhali jaza sababu kuelezea kwanini dawa ya minyoo haikutotolewa"
},
"options": [
{
"openmrs_entity": "concept",
"key": "medicines_not_available",
"openmrs_entity_id": "medicines_not_available",
"text": "Medicines Not Available"
},
{
"openmrs_entity": "concept",
"key": "family_refused",
"openmrs_entity_id": "family_refused",
"text": "Familia ilikataa"
},
{
"openmrs_entity": "concept",
"key": "clinic_closed",
"openmrs_entity_id": "clinic_closed",
"text": "Kituo cha afya kilikuwa kimefungwa"
},
{
"openmrs_entity": "concept",
"key": "return_another_day",
"openmrs_entity_id": "return_another_day",
"text": "Kaombwa arudi siku nyingine"
},
{
"openmrs_entity": "concept",
"key": "did_not_know_deworming",
"openmrs_entity_id": "did_not_know_deworming",
"text": "Hakujua kuhusu dawa za kutokomeza minyoo"
},
{
"openmrs_entity": "concept",
"key": "could_not_take_child_deworming",
"openmrs_entity_id": "could_not_take_child_deworming",
"text": "Hakuweza kumpeleka mtoto kupata dawa za minyoo"
},
{
"openmrs_entity": "concept",
"key": "other",
"openmrs_entity_id": "other",
"text": "Sababu nyingine"
}
],
"relevance": {
"step1:has_received_deworming{0}": {
"type": "string",
"ex": "equalTo(., \"no\")"
}
}
},
{
"key": "other_reason_no_medicine_deworming{0}",
"openmrs_entity_parent": "other_reason_no_medicine_deworming{0}",
"openmrs_entity": "concept",
"openmrs_entity_id": "other_reason_no_medicine_deworming{0}",
"type": "edit_text",
"hint": "Jaza sababu ya kutotolewa dawa ya minyoo",
"v_required": {
"value": "true",
"err": "Tafadhali jaza sababu kuelezea kwanini dawa ya minyoo haikutotolewa"
},
"relevance": {
"step1:reason_no_medicine_deworming{0}": {
"type": "string",
"ex-checkbox": [
{
"or": ["other"]
}
]
}
}
}
]
Expand Down
Loading