Skip to content

Commit

Permalink
fix (sync): wrong delivery status of Ibu
Browse files Browse the repository at this point in the history
**The Cause**

1. Client (the application) does:
- ANC: event date: 15 Feb 2019
- Dokumentasi Persalinan: event date: 15 Feb 2019

2. Sync (upload):
ANC and Dokumentasi Persalinan (delivery document) will be sent, and the server will add the same time for dateCreated. Because it's a bulky transaction.

3. Sync (download), sometimes like this:
Dokumentasi Persalinan data is above ANC. Because the date is the same, so no order (sorted by), and the data can be flipped.
While in the client (application), Dokumentasi Persalinan is processed first, then ANC.
That's why the status is still ANC (EDD Passed).

**The Fix**

When there are both ANC and Dokumentasi Persalinan, with actually it's a sequence, so the status should be Dokumentasi Persalinan (delivered).

#32
  • Loading branch information
rizkisunaryo committed Feb 18, 2019
1 parent 9bcd766 commit 6b4a1c0
Showing 1 changed file with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,50 @@ public synchronized void processClient(List<JSONObject> events) throws Exception

if (!events.isEmpty()) {
for (JSONObject event : events) {

if (event.getString("eventType").equals(ANC_REGISTRATION)){
// START: find existing anc_id in ec_pnc (Dokumentasi Persalinan)
// get obs of event
JSONArray obs = event.has("obs") ? event.getJSONArray("obs") : null;
if (obs != null) {
// ANC ID is possible to be more than 1,
// so we use List
List<String> ancList = null;
// get ANC ID list
for (int i = 0; i < obs.length(); i++) {
JSONObject ob = obs.getJSONObject(i);
String fieldCode = ob.has("fieldCode") ? ob.getString("fieldCode") : null;
// check whether the fieldCode is ancId
if (fieldCode != null && fieldCode.equalsIgnoreCase("ancId")) {
JSONArray values = ob.has("values") ? ob.getJSONArray("values") : null;
// store values to ancList
ancList = getValues(values);
break;
}
}

if (ancList != null) {
// building question marks for query
String inQuestionMarks = "?";
for (int i = 2; i < ancList.size(); i++) {
inQuestionMarks += ", ?";
}

// query, to get whether there is existing data in ec_pnc (Dokumentasi Persalinan)
// that matches ANC ID list
net.sqlcipher.Cursor temp = BidanApplication
.getInstance()
.getContext()
.initRepository()
.getWritableDatabase()
.rawQuery("SELECT * FROM ec_pnc WHERE anc_id IN ("+ inQuestionMarks +")", ancList.toArray(new String[ancList.size()]));
// if yes, then skip both removePncData and removeAncData
if (temp.getCount() > 0) {
continue;
}
}
}
// END: find existing anc_id in ec_pnc (Dokumentasi Persalinan)

removePncData(event.getString("baseEntityId"));
removeAncData(event.getString("baseEntityId"));
}
Expand Down

0 comments on commit 6b4a1c0

Please sign in to comment.