Skip to content

Commit

Permalink
🔨 completed for QA
Browse files Browse the repository at this point in the history
  • Loading branch information
vend committed Jul 3, 2020
1 parent 264df01 commit caeb1a5
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.AlertDialog;
import android.content.Intent;
import android.database.Cursor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

Expand All @@ -10,8 +11,11 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.smartregister.commonregistry.CommonPersonObject;
import org.smartregister.commonregistry.CommonPersonObjectClient;
import org.smartregister.domain.FetchStatus;
import org.smartregister.giz.R;
import org.smartregister.giz.configuration.GizPncRegisterQueryProvider;
import org.smartregister.giz.interactor.MaternityRegisterActivityInteractor;
import org.smartregister.maternity.activity.BaseMaternityRegisterActivity;
import org.smartregister.maternity.contract.MaternityRegisterActivityContract;
Expand Down Expand Up @@ -48,7 +52,6 @@ public class MaternityRegisterActivityPresenter extends BaseMaternityRegisterAct

public MaternityRegisterActivityPresenter(@NonNull MaternityRegisterActivityContract.View view, @NonNull MaternityRegisterActivityContract.Model model) {
super(view, model);
processPncRegistration();
}

@NonNull
Expand Down Expand Up @@ -100,7 +103,6 @@ public void onEventSaved() {
}

public void processPncRegistration() {
maternityBaseEntityId = "3738e11c-6f6b-4174-bf0f-8aa25b087bdf";
String pncBaseEntityId = JsonFormUtils.generateRandomUUIDString();

JSONObject jsonObject = PncUtils.getJsonFormToJsonObject("pnc_registration_template");
Expand All @@ -111,11 +113,15 @@ public void processPncRegistration() {
String q1 = "SELECT * FROM ec_client WHERE base_entity_id='" + maternityBaseEntityId + "'";
String q2 = "SELECT * FROM maternity_registration_details WHERE base_entity_id='" + maternityBaseEntityId + "'";

String q3 = "SELECT * FROM maternity_outcome WHERE base_entity_id='" + maternityBaseEntityId + "'";
HashMap<String, String> tempData = getMergedData(q3);

Set<String> possibleJsonArrayKeys = new HashSet<>();
possibleJsonArrayKeys.add("dob_unknown");
possibleJsonArrayKeys.add("occupation");

HashMap<String, String> data = getMergedData(q1, q2);
data.put("mother_status", tempData.get("mother_status"));

if ("alive".equalsIgnoreCase(data.get("mother_status"))) {

Expand Down Expand Up @@ -202,7 +208,7 @@ public void processPncOutcome(String pncBaseEntityId) {
processPncData(intent, () -> {
if (getView() != null) {
getView().hideProgressDialog();
showAlertDialog(getView());
showAlertDialog(getView(), pncBaseEntityId);
}
});
}
Expand Down Expand Up @@ -348,15 +354,15 @@ private void processPncData(Intent data, PncEventActionCallBack callBack) {
}
PncUtils.saveRegistrationFormSilent(jsonString, registerParam, callBack);
} else if (encounterType.equals(PncConstants.EventTypeConstants.PNC_OUTCOME)) {
PncUtils.saveOutcomeAndVisitFormSilent(jsonString, data, callBack);
PncUtils.saveOutcomeAndVisitFormSilent(encounterType, data, callBack);
}

} catch (JSONException e) {
Timber.e(e);
}
}

private void showAlertDialog(MaternityRegisterActivityContract.View view) {
private void showAlertDialog(MaternityRegisterActivityContract.View view, String pncBaseEntityId) {
if (view instanceof BaseMaternityRegisterActivity) {
BaseMaternityRegisterActivity activity = (BaseMaternityRegisterActivity) view;
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
Expand All @@ -366,9 +372,19 @@ private void showAlertDialog(MaternityRegisterActivityContract.View view) {

PncMetadata pncMetadata = PncLibrary.getInstance().getPncConfiguration().getPncMetadata();

GizPncRegisterQueryProvider pncRegisterQueryProvider = new GizPncRegisterQueryProvider();
String query = pncRegisterQueryProvider.mainSelectWhereIDsIn().replace("%s", "'" + pncBaseEntityId + "'");
Cursor cursor = PncLibrary.getInstance().getRepository().getReadableDatabase().rawQuery(query, null);
cursor.moveToFirst();

CommonPersonObject personinlist = PncLibrary.getInstance().context().commonrepository("ec_client").readAllcommonforCursorAdapter(cursor);
CommonPersonObjectClient pClient = new CommonPersonObjectClient(personinlist.getCaseId(),
personinlist.getDetails(), personinlist.getDetails().get("FWHOHFNAME"));
pClient.setColumnmaps(personinlist.getColumnmaps());

if (pncMetadata != null) {
Intent intent = new Intent(activity, pncMetadata.getProfileActivity());
//intent.putExtra(PncConstants.IntentKey.CLIENT_OBJECT, commonPersonObjectClient);
intent.putExtra(PncConstants.IntentKey.CLIENT_OBJECT, pClient);
activity.startActivity(intent);
}
});
Expand Down

0 comments on commit caeb1a5

Please sign in to comment.