Skip to content

Commit

Permalink
MI | Updating form registration logic 2 #6
Browse files Browse the repository at this point in the history
Signed-off-by: mib-iqbal <[email protected]>
  • Loading branch information
mib-iqbal committed Nov 10, 2017
1 parent f985875 commit e754686
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import butterknife.Bind;
import butterknife.ButterKnife;
import util.VaksinatorFormUtils;
import util.formula.Support;

public class GiziSmartRegisterActivity extends SecuredNativeSmartRegisterActivity implements
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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());
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -371,8 +396,12 @@ public void onBackPressed() {
private String[] buildFormNameList(){
List<String> formNames = new ArrayList<String>();
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()]);
}

Expand Down

0 comments on commit e754686

Please sign in to comment.