Skip to content

Commit 195dfbc

Browse files
authored
Merge pull request #213 from mngoe/OP-2536
fetch family policies in update process
2 parents 4fc521d + d6c7946 commit 195dfbc

File tree

7 files changed

+95
-8
lines changed

7 files changed

+95
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fastlane/test_output
6060
fastlane/readme.md
6161

6262
app/release/output.json
63-
**/.DS_Store
63+
.DS_Store
6464

6565
# Custom product flavours
6666

app/src/main/graphql/org.openimis.imispolicies/GetFamily.graphql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ query GetFamily($headChfId: String) {
7979
}
8080
}
8181
}
82+
policies{
83+
edges {
84+
node {
85+
id
86+
uuid
87+
product {
88+
id
89+
}
90+
officer {
91+
id
92+
}
93+
value
94+
enrollDate
95+
effectiveDate
96+
startDate
97+
expiryDate
98+
status
99+
}
100+
}
101+
}
82102
}
83103
}
84104
}

app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,8 @@ private Family familyFromJSONObject(
31733173
/* confirmationNumber = */ JsonUtils.getStringOrDefault(json, "ConfirmationNo"),
31743174
/* confirmationType = */ JsonUtils.getStringOrDefault(json, "ConfirmationType"),
31753175
/* isOffline = */ JsonUtils.getBooleanOrDefault(json, "isOffline", false),
3176-
/* members = */ members
3176+
/* members = */ members,
3177+
null
31773178
);
31783179
}
31793180

@@ -4722,6 +4723,7 @@ public int ModifyFamily(final String insuranceNumber) {
47224723
Family family = new FetchFamily().execute(insuranceNumber);
47234724
InsertFamilyDataFromOnline(family);
47244725
InsertInsureeDataFromOnline(family.getMembers());
4726+
InsertPolicyDataFromOnline(family.getPolicies());
47254727
return 1;
47264728
} catch (Exception e) {
47274729
Log.e("MODIFYFAMILY", "Error while downloading a family", e);
@@ -4793,6 +4795,22 @@ private void InsertInsureeDataFromOnline(@NonNull List<Family.Member> members) t
47934795
sqlHandler.insertData("tblInsuree", Columns, array, "");
47944796
}
47954797

4798+
private void InsertPolicyDataFromOnline(@NonNull List<Family.Policy> policies) throws JSONException {
4799+
JSONArray array = new JSONArray();
4800+
for (Family.Policy policy: policies) {
4801+
@Language("SQL")
4802+
String QueryCheck = "SELECT PolicyId FROM tblPolicy WHERE PolicyId = " + policy.getId();
4803+
if (sqlHandler.getResult(QueryCheck, null).length() == 0) {
4804+
array.put(toPolicyJSONObject(policy));
4805+
}
4806+
}
4807+
String[] Columns = {"PolicyId", "FamilyId", "EnrollDate", "StartDate", "EffectiveDate", "ExpiryDate", "PolicyStatus",
4808+
"PolicyValue", "ProdId", "OfficerId", "IsOffline"};
4809+
final String[] policyColumns;
4810+
policyColumns = Columns;
4811+
sqlHandler.insertData("tblPolicy", policyColumns, array, "");
4812+
}
4813+
47964814
@NonNull
47974815
private JSONObject toJSONObject(@NonNull Family.Member member) throws JSONException {
47984816
JSONObject jsonObject = new JSONObject();
@@ -4824,6 +4842,23 @@ private JSONObject toJSONObject(@NonNull Family.Member member) throws JSONExcept
48244842
return jsonObject;
48254843
}
48264844

4845+
@NonNull
4846+
private JSONObject toPolicyJSONObject (Family.Policy policy) throws JSONException {
4847+
JSONObject policyObject = new JSONObject();
4848+
policyObject.put("PolicyId",policy.getId());
4849+
policyObject.put("FamilyId",policy.getFamilyId());
4850+
policyObject.put("EnrollDate",policy.getEnrollDate());
4851+
policyObject.put("StartDate",DateUtils.toDateString(Objects.requireNonNull(policy.getStartDate())));
4852+
policyObject.put("EffectiveDate", DateUtils.toDateString(Objects.requireNonNull(policy.getEffectiveDate())));
4853+
policyObject.put("ExpiryDate", DateUtils.toDateString(Objects.requireNonNull(policy.getExpiryDate())));
4854+
policyObject.put("PolicyStatus",policy.getStatus());
4855+
policyObject.put("PolicyValue",policy.getValue());
4856+
policyObject.put("ProdId",policy.getProductId());
4857+
policyObject.put("OfficerId",policy.getOfficerId());
4858+
policyObject.put("IsOffline",false);
4859+
return policyObject;
4860+
}
4861+
48274862
//****************************Online Statistics ******************************//
48284863
@JavascriptInterface
48294864
@SuppressWarnings("unused")

app/src/main/java/org/openimis/imispolicies/domain/entity/Family.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class Family implements Parcelable {
3636
private final boolean isOffline;
3737
@NonNull
3838
private final List<Member> members;
39+
@Nullable
40+
private final List<Policy> policies;
3941

4042
@Nullable
4143
private Member head = null;
@@ -53,7 +55,8 @@ public Family(
5355
@Nullable String confirmationNumber,
5456
@Nullable String confirmationType,
5557
boolean isOffline,
56-
@NonNull List<Member> members
58+
@NonNull List<Member> members,
59+
@Nullable List<Policy> policies
5760
) {
5861
this.headChfId = headChfId;
5962
this.id = id;
@@ -68,6 +71,7 @@ public Family(
6871
this.confirmationType = confirmationType;
6972
this.isOffline = isOffline;
7073
this.members = members;
74+
this.policies = policies;
7175
}
7276

7377
protected Family(Parcel in) {
@@ -89,6 +93,7 @@ protected Family(Parcel in) {
8993
confirmationType = in.readString();
9094
isOffline = in.readByte() != 0;
9195
members = Objects.requireNonNull(in.createTypedArrayList(Member.CREATOR));
96+
policies = in.createTypedArrayList(Policy.CREATOR);
9297
}
9398

9499
@Override
@@ -106,6 +111,7 @@ public void writeToParcel(Parcel dest, int flags) {
106111
dest.writeString(confirmationType);
107112
dest.writeByte((byte) (isOffline ? 1 : 0));
108113
dest.writeTypedList(members);
114+
dest.writeTypedList(policies);
109115
}
110116

111117
@Override
@@ -198,6 +204,9 @@ public List<Member> getMembers() {
198204
return members;
199205
}
200206

207+
@Nullable
208+
public List<Policy> getPolicies (){ return policies; }
209+
201210
public static final Creator<Family> CREATOR = new Creator<>() {
202211
@Override
203212
public Family createFromParcel(Parcel in) {

app/src/main/java/org/openimis/imispolicies/network/okhttp/AuthorizationInterceptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import okhttp3.Response;
1515

1616
public class AuthorizationInterceptor implements Interceptor {
17-
private static final String REQUESTED_WITH = "webapp";
17+
private static final String USER_AGENT = "mobile_app";
1818

1919
@NonNull
2020
private final LoginRepository repository;
@@ -33,10 +33,9 @@ public Response intercept(@NonNull Chain chain) throws IOException {
3333
}
3434
Request.Builder builder = chain.request().newBuilder();
3535
builder.addHeader("Authorization", "bearer " + token.trim());
36-
//builder.addHeader("Content-Type", "application/json");
36+
builder.addHeader("User-Agent", USER_AGENT);
3737
if(!StringUtils.isEmpty(csrfToken)){
3838
builder.addHeader("X-Csrftoken", csrfToken);
39-
builder.addHeader("X-Requested-With", REQUESTED_WITH);
4039
}
4140
Response response = chain.proceed(builder.build());
4241
if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) {

app/src/main/java/org/openimis/imispolicies/network/request/BaseGraphQLRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public abstract class BaseGraphQLRequest {
3131

3232
private static final ApolloClient apolloClient = ApolloClient.builder()
3333
.okHttpClient(OkHttpUtils.getDefaultOkHttpClient())
34-
.useHttpGetMethodForQueries(true)
3534
.serverUrl(URI)
3635
.addCustomTypeAdapter(CustomType.DATE, new DateCustomTypeAdapter())
3736
.addCustomTypeAdapter(CustomType.DATETIME, new DateTimeCustomTypeAdapter())

app/src/main/java/org/openimis/imispolicies/usecase/FetchFamily.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.FileOutputStream;
2222
import java.io.OutputStream;
23+
import java.util.ArrayList;
2324
import java.util.Objects;
2425

2526
public class FetchFamily {
@@ -52,7 +53,8 @@ public Family execute(@NonNull String headChfId) throws Exception {
5253
/* confirmationNumber = */ node.confirmationNo(),
5354
/* confirmationType = */ node.confirmationType() != null ? Objects.requireNonNull(node.confirmationType()).code() : null,
5455
/* isOffline = */ node.isOffline() != null ? Objects.requireNonNull(node.isOffline()) : false,
55-
/* insurees = */ Mapper.map(node.members().edges(), (edge) -> toMember(edge, node))
56+
/* insurees = */ Mapper.map(node.members().edges(), (edge) -> toMember(edge, node)),
57+
/* policies = */ Mapper.map(node.policies().edges(), (edge) -> toPolicy(edge, node))
5658
);
5759
}
5860

@@ -89,6 +91,29 @@ private Family.Member toMember(@NonNull GetFamilyQuery.Edge1 edge, @NonNull GetF
8991
);
9092
}
9193

94+
@NonNull
95+
private Family.Policy toPolicy(@NonNull GetFamilyQuery.Edge2 edge, @NonNull GetFamilyQuery.Node family){
96+
GetFamilyQuery.Node2 policy = Objects.requireNonNull(edge.node());
97+
return new Family.Policy(
98+
/* id = */IdUtils.getIdFromGraphQLString(policy.id()),
99+
/* uuid = */ policy.uuid(),
100+
/* familyId = */ IdUtils.getIdFromGraphQLString(family.id()),
101+
/* familyUuid = */ family.uuid(),
102+
/* enrollDate = */ policy.enrollDate(),
103+
/* startDate = */ policy.startDate(),
104+
/* effectiveDate = */ policy.effectiveDate(),
105+
/* expiryDate = */ Objects.requireNonNull(policy.expiryDate()),
106+
/* status = */ String.valueOf(policy.status()),
107+
/* value = */ policy.value(),
108+
/* productId = */ IdUtils.getIdFromGraphQLString(policy.product().id()),
109+
/* officerId = */ IdUtils.getIdFromGraphQLString(policy.officer().id()),
110+
null,
111+
true,
112+
null,
113+
new ArrayList<>()
114+
);
115+
}
116+
92117
@Nullable
93118
private String downloadPhoto(@Nullable GetFamilyQuery.Photo photo) {
94119
String photoPath = getPhotoPath(photo);

0 commit comments

Comments
 (0)