From e7546865f36726b7362065d8e6e8031be13990df Mon Sep 17 00:00:00 2001 From: mib-iqbal Date: Fri, 10 Nov 2017 17:30:26 +0800 Subject: [PATCH] MI | Updating form registration logic 2 #6 Signed-off-by: mib-iqbal --- .../gizi/activity/GiziHomeActivity.java | 2 +- .../activity/GiziSmartRegisterActivity.java | 43 ++++++++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziHomeActivity.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziHomeActivity.java index a9eda85..82b4d8b 100644 --- a/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziHomeActivity.java +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziHomeActivity.java @@ -185,7 +185,7 @@ public void afterFetch(HomeContext anmDetails) { private void updateRegisterCounts(HomeContext homeContext) { SmartRegisterQueryBuilder sqb = new SmartRegisterQueryBuilder(); - Cursor childcountcursor = context().commonrepository("anak").rawCustomQueryForAdapter(sqb.queryForCountOnRegisters("ec_anak_search", "ec_anak_search.is_closed=0")); + Cursor childcountcursor = context().commonrepository("ec_anak").rawCustomQueryForAdapter(sqb.queryForCountOnRegisters("ec_anak_search", "ec_anak_search.is_closed=0")); childcountcursor.moveToFirst(); childcount = childcountcursor.getInt(0); childcountcursor.close(); diff --git a/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziSmartRegisterActivity.java b/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziSmartRegisterActivity.java index 1048dba..a7764e9 100755 --- a/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziSmartRegisterActivity.java +++ b/opensrp-gizi/src/main/java/org/smartregister/gizi/activity/GiziSmartRegisterActivity.java @@ -44,6 +44,7 @@ import butterknife.Bind; import butterknife.ButterKnife; +import util.VaksinatorFormUtils; import util.formula.Support; public class GiziSmartRegisterActivity extends SecuredNativeSmartRegisterActivity implements @@ -168,7 +169,8 @@ public void saveFormSubmission(String formSubmission, String id, String formName Log.v("fieldoverride", fieldOverrides.toString()); // save the form try{ - FormUtils formUtils = FormUtils.getInstance(getApplicationContext()); + VaksinatorFormUtils formUtils = VaksinatorFormUtils.getInstance(getApplicationContext()); + // FormUtils formUtils = FormUtils.getInstance(getApplicationContext()); FormSubmission submission = formUtils.generateFormSubmisionFromXMLString(id, formSubmission, formName, fieldOverrides); ClientProcessor.getInstance(getApplicationContext()).processClient(); @@ -177,13 +179,15 @@ public void saveFormSubmission(String formSubmission, String id, String formName context().formSubmissionRouter().handleSubmission(submission, formName); switchToBaseFragment(formSubmission); // Unnecessary!! passing on data - if(formName.equals("registrasi_gizi")) { - Log.d(TAG, "saveFormSubmission: it was registrasi_jurim form"); + if(formName.equals("registrasi_ibu")) { + Log.d(TAG, "saveFormSubmission: it was registrasi_ibu form"); // FieldOverrides fieldOverrides = new FieldOverrides(combined.toString()); fieldOverrides.put("ibuCaseId",submission.entityId()); FieldOverrides fo = new FieldOverrides(fieldOverrides.toString()); - activatingForm("registrasi_anak", null, fo.getJSONString()); + + activatingOtherForm("registrasi_anak", null, fo.getJSONString()); + /// activatingForm("registrasi_anak", null, fo.getJSONString()); } //end capture flurry log for FS @@ -204,6 +208,26 @@ public void saveFormSubmission(String formSubmission, String id, String formName } + public void activatingOtherForm(final String formName, final String entityId, final String metaData){ + final int prevPageIndex = currentPage; + runOnUiThread(new Runnable() { + @Override + public void run() { + //hack reset the form + DisplayFormFragment displayFormFragment = getDisplayFormFragmentAtIndex(prevPageIndex); + if (displayFormFragment != null) { + displayFormFragment.hideTranslucentProgressDialog(); + displayFormFragment.setFormData(null); + + } + + displayFormFragment.setRecordId(null); + activatingForm(formName,entityId,metaData); + } + }); + + } + @Override public void OnLocationSelected(String locationJSONString) { JSONObject combined = null; @@ -227,7 +251,7 @@ public void OnLocationSelected(String locationJSONString) { if (combined != null) { FieldOverrides fieldOverrides = new FieldOverrides(combined.toString()); - startFormActivity("registrasi_gizi", null, fieldOverrides.getJSONString()); + startFormActivity("registrasi_ibu", null, fieldOverrides.getJSONString()); } } @@ -262,12 +286,13 @@ public void startFormActivity(final String formName, final String entityId, fina private void activatingForm(String formName, String entityId, String metaData){ try { - int formIndex = FormUtils.getIndexForFormName(formName, formNames) + 1; // add the offset + int formIndex = VaksinatorFormUtils.getIndexForFormName(formName, formNames) + 1; // add the offset if (entityId != null || metaData != null){ String data = null; + //check if there is previously saved data for the form data = getPreviouslySavedDataForForm(formName, metaData, entityId); if (data == null){ - data = FormUtils.getInstance(getApplicationContext()).generateXMLInputForFormWithEntityId(entityId, formName, metaData); + data = VaksinatorFormUtils.getInstance(getApplicationContext()).generateXMLInputForFormWithEntityId(entityId, formName, metaData); } DisplayFormFragment displayFormFragment = getDisplayFormFragmentAtIndex(formIndex); @@ -371,8 +396,12 @@ public void onBackPressed() { private String[] buildFormNameList(){ List formNames = new ArrayList(); formNames.add("registrasi_gizi"); + formNames.add("registrasi_ibu"); + formNames.add("registrasi_anak"); formNames.add("kunjungan_gizi"); formNames.add("close_form"); + + formNames.add("kartu_ibu_registration"); return formNames.toArray(new String[formNames.size()]); }