From a7bee00d3bb4c57f8ad5f352466a7e7d17bbde09 Mon Sep 17 00:00:00 2001 From: vaneck237 Date: Sun, 24 May 2026 10:40:47 +0100 Subject: [PATCH] fix print user policy renewals --- .../GetPolicyRenewals.graphql | 32 +++++++++++++++++++ .../imispolicies/ClientAndroidInterface.java | 4 +-- .../org/openimis/imispolicies/RenewList.java | 15 +++++++-- .../GetPolicyRenewalsGraphQLRequest.java | 12 ++++--- .../usecase/DeletePolicyRenewal.java | 11 +++++-- .../usecase/FetchPolicyRenewals.java | 31 +++++++++--------- 6 files changed, 78 insertions(+), 27 deletions(-) create mode 100644 app/src/main/graphql/org.openimis.imispolicies/GetPolicyRenewals.graphql diff --git a/app/src/main/graphql/org.openimis.imispolicies/GetPolicyRenewals.graphql b/app/src/main/graphql/org.openimis.imispolicies/GetPolicyRenewals.graphql new file mode 100644 index 00000000..10b420d1 --- /dev/null +++ b/app/src/main/graphql/org.openimis.imispolicies/GetPolicyRenewals.graphql @@ -0,0 +1,32 @@ +query GetPolicyRenewals($officerCode: String) { + policies(stage: "R", officer_Code: $officerCode, orderBy: ["-enrollDate"]){ + edges { + node { + id + uuid + startDate + product { + id + code + name + } + officer { + id + code + } + family { + headInsuree { + id + chfId + lastName + otherNames + phone + currentVillage { + name + } + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java b/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java index b9c35d71..7147ffc0 100644 --- a/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java +++ b/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java @@ -2273,8 +2273,8 @@ public String OfflineEnquire(String CHFID) { public String OfflineRenewals(String OfficerCode) { @Language("SQL") String Query = "SELECT RenewalId, PolicyId, OfficerId, OfficerCode, CHFID, LastName, OtherNames, ProductCode, ProductName, VillageName, RenewalPromptDate, IMEI, Phone,LocationId,PolicyValue, EnrollDate, RenewalUUID " + - " FROM tblRenewals WHERE LOWER(OfficerCode)=? AND isDone = ? "; - String[] arg = {OfficerCode.toLowerCase(), "N"}; + " FROM tblRenewals WHERE isDone = ? "; + String[] arg = {"N"}; JSONArray Renews = sqlHandler.getResult(Query, arg); return Renews.toString(); } diff --git a/app/src/main/java/org/openimis/imispolicies/RenewList.java b/app/src/main/java/org/openimis/imispolicies/RenewList.java index 95f824b6..dfb01644 100644 --- a/app/src/main/java/org/openimis/imispolicies/RenewList.java +++ b/app/src/main/java/org/openimis/imispolicies/RenewList.java @@ -57,16 +57,20 @@ import org.openimis.imispolicies.network.exception.HttpException; import org.openimis.imispolicies.tools.Log; import org.openimis.imispolicies.usecase.FetchPolicyRenewals; +import org.openimis.imispolicies.util.DateUtils; import org.openimis.imispolicies.util.FileUtils; import org.openimis.imispolicies.util.UriUtils; import java.io.File; import java.net.HttpURLConnection; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; public class RenewList extends AppCompatActivity { @@ -280,6 +284,7 @@ private void fillRenewals() { ClientAndroidInterface ca = new ClientAndroidInterface(this); String result = ca.OfflineRenewals(OfficerCode); + Log.e("policy renewals", result); JSONObject object; try { @@ -312,13 +317,16 @@ private void fillRenewals() { for (int i = 0; i < jsonArray.length(); i++) { object = jsonArray.getJSONObject(i); + SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH); + SimpleDateFormat outputFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + Date promptDate = inputFormat.parse(object.getString("RenewalPromptDate")); HashMap renewal = new HashMap<>(); renewal.put("RenewalId", object.getString("RenewalId")); renewal.put("CHFID", object.getString("CHFID")); renewal.put("FullName", object.getString("LastName") + " " + object.getString("OtherNames")); renewal.put("Product", object.getString("ProductCode") + " : " + object.getString("ProductName")); renewal.put("VillageName", object.getString("VillageName")); - renewal.put("RenewalPromptDate", object.getString("RenewalPromptDate")); + renewal.put("RenewalPromptDate", format.format(promptDate)); renewal.put("PolicyId", object.getString("PolicyId")); renewal.put("ProductCode", object.getString("ProductCode")); renewal.put("LocationId", object.getString("LocationId")); @@ -337,6 +345,8 @@ private void fillRenewals() { } catch (JSONException e) { e.printStackTrace(); + } catch (ParseException e) { + throw new RuntimeException(e); } } @@ -347,7 +357,8 @@ private void refreshRenewals() { new Thread(() -> { try { - List renewals = new FetchPolicyRenewals().execute(); + List renewals = new FetchPolicyRenewals().execute(OfficerCode); + Log.e("renewals", toJson(renewals).toString()); ca.InsertRenewalsFromApi(toJson(renewals)); runOnUiThread(this::fillRenewals); } catch (Exception e) { diff --git a/app/src/main/java/org/openimis/imispolicies/network/request/GetPolicyRenewalsGraphQLRequest.java b/app/src/main/java/org/openimis/imispolicies/network/request/GetPolicyRenewalsGraphQLRequest.java index 77d05453..130aa63c 100644 --- a/app/src/main/java/org/openimis/imispolicies/network/request/GetPolicyRenewalsGraphQLRequest.java +++ b/app/src/main/java/org/openimis/imispolicies/network/request/GetPolicyRenewalsGraphQLRequest.java @@ -3,8 +3,10 @@ import androidx.annotation.NonNull; import androidx.annotation.WorkerThread; +import com.apollographql.apollo.api.Input; import com.apollographql.apollo.api.Response; +import org.openimis.imispolicies.GetPolicyRenewalsQuery; import org.openimis.imispolicies.GetRenewalsQuery; import org.openimis.imispolicies.network.exception.HttpException; @@ -16,12 +18,12 @@ public class GetPolicyRenewalsGraphQLRequest extends BaseGraphQLRequest { @WorkerThread @NonNull - public List get() throws Exception { - Response response = makeSynchronous(new GetRenewalsQuery()); - GetRenewalsQuery.Data data = response.getData(); - if (data == null || data.policyRenewals() == null) { + public List get(String officerCode) throws Exception { + Response response = makeSynchronous(new GetPolicyRenewalsQuery(Input.fromNullable(officerCode))); + GetPolicyRenewalsQuery.Data data = response.getData(); + if (data == null || data.policies() == null) { throw new HttpException(HttpURLConnection.HTTP_NOT_FOUND, "No renewals found", null, null); } - return Objects.requireNonNull(data.policyRenewals()).edges(); + return Objects.requireNonNull(data.policies()).edges(); } } diff --git a/app/src/main/java/org/openimis/imispolicies/usecase/DeletePolicyRenewal.java b/app/src/main/java/org/openimis/imispolicies/usecase/DeletePolicyRenewal.java index 5bf1b413..04bb6601 100644 --- a/app/src/main/java/org/openimis/imispolicies/usecase/DeletePolicyRenewal.java +++ b/app/src/main/java/org/openimis/imispolicies/usecase/DeletePolicyRenewal.java @@ -3,6 +3,7 @@ import androidx.annotation.NonNull; import androidx.annotation.WorkerThread; +import org.openimis.imispolicies.Global; import org.openimis.imispolicies.ToRestApi; import org.openimis.imispolicies.domain.entity.PolicyRenewal; import org.openimis.imispolicies.network.exception.HttpException; @@ -19,28 +20,32 @@ public class DeletePolicyRenewal { private final DeletePolicyRenewalGraphQLRequest deletePolicyRenewalGraphQLRequest; @NonNull private final CheckMutation checkMutation; + private final Global global; public DeletePolicyRenewal() { this( new FetchPolicyRenewals(), new DeletePolicyRenewalGraphQLRequest(), - new CheckMutation() + new CheckMutation(), + new Global() ); } public DeletePolicyRenewal( @NonNull FetchPolicyRenewals fetchPolicyRenewals, @NonNull DeletePolicyRenewalGraphQLRequest deletePolicyRenewalGraphQLRequest, - @NonNull CheckMutation checkMutation + @NonNull CheckMutation checkMutation, + @NonNull Global global ) { this.fetchPolicyRenewals = fetchPolicyRenewals; this.deletePolicyRenewalGraphQLRequest = deletePolicyRenewalGraphQLRequest; this.checkMutation = checkMutation; + this.global = global; } @WorkerThread public int execute(int id) throws Exception { - List renewals = fetchPolicyRenewals.execute(); + List renewals = fetchPolicyRenewals.execute(global.getOfficerCode()); for (PolicyRenewal renewal : renewals) { if (renewal.getId() == id) { return execute(renewal.getUuid()); diff --git a/app/src/main/java/org/openimis/imispolicies/usecase/FetchPolicyRenewals.java b/app/src/main/java/org/openimis/imispolicies/usecase/FetchPolicyRenewals.java index bfc8316e..05ad2ddc 100644 --- a/app/src/main/java/org/openimis/imispolicies/usecase/FetchPolicyRenewals.java +++ b/app/src/main/java/org/openimis/imispolicies/usecase/FetchPolicyRenewals.java @@ -3,6 +3,7 @@ import androidx.annotation.NonNull; import androidx.annotation.WorkerThread; +import org.openimis.imispolicies.GetPolicyRenewalsQuery; import org.openimis.imispolicies.GetRenewalsQuery; import org.openimis.imispolicies.domain.entity.PolicyRenewal; import org.openimis.imispolicies.domain.utils.IdUtils; @@ -27,28 +28,28 @@ public FetchPolicyRenewals(@NonNull GetPolicyRenewalsGraphQLRequest getPolicyRen @NonNull @WorkerThread - public List execute() throws Exception { - List edges = getPolicyRenewalsGraphQLRequest.get(); + public List execute(String officerCode) throws Exception { + List edges = getPolicyRenewalsGraphQLRequest.get(officerCode); return Mapper.map(edges, this::toRenewal); } @NonNull - private PolicyRenewal toRenewal(@NonNull GetRenewalsQuery.Edge edge) { - GetRenewalsQuery.Node node = Objects.requireNonNull(edge.node()); + private PolicyRenewal toRenewal(@NonNull GetPolicyRenewalsQuery.Edge edge) { + GetPolicyRenewalsQuery.Node node = Objects.requireNonNull(edge.node()); return new PolicyRenewal( /* id = */ IdUtils.getIdFromGraphQLString(node.id()), /* uuid = */ node.uuid(), - /* policyId = */ IdUtils.getIdFromGraphQLString(node.policy().id()), - /* officerId = */ IdUtils.getIdFromGraphQLString(node.policy().officer().id()), - /* officerCode = */ node.policy().officer().code(), - /* chfId = */ node.insuree().chfId(), - /* lastName = */ node.insuree().lastName(), - /* otherNames = */ node.insuree().otherNames(), - /* productCode = */ node.policy().product().code(), - /* productName = */ node.policy().product().name(), - /* villageName = */ node.insuree().currentVillage() != null ? node.insuree().currentVillage().name() : null, - /* renewalPromptDate = */ node.renewalPromptDate(), - /* phone = */ node.insuree().phone() + /* policyId = */ IdUtils.getIdFromGraphQLString(node.id()), + /* officerId = */ IdUtils.getIdFromGraphQLString(node.officer().id()), + /* officerCode = */ node.officer().code(), + /* chfId = */ node.family().headInsuree().chfId(), + /* lastName = */ node.family().headInsuree().lastName(), + /* otherNames = */ node.family().headInsuree().otherNames(), + /* productCode = */ node.product().code(), + /* productName = */ node.product().name(), + /* villageName = */ node.family().headInsuree().currentVillage() != null ? node.family().headInsuree().currentVillage().name() : null, + /* renewalPromptDate = */ node.startDate(), + /* phone = */ node.family().headInsuree().phone() ); } }