Skip to content

Commit 803a47f

Browse files
feat: add polygamous family support with sub-household management
1 parent 4ad5b04 commit 803a47f

12 files changed

Lines changed: 562 additions & 408 deletions

claimManagement/src/main/graphql/org.openimis.imisclaim/GetFamilyWithType.graphql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ query GetFamilyWithType($uuid: String!) {
4848
code
4949
type
5050
}
51+
headInsuree {
52+
id
53+
uuid
54+
chfId
55+
lastName
56+
otherNames
57+
gender {
58+
code
59+
gender
60+
}
61+
dob
62+
photo {
63+
id
64+
photo
65+
}
66+
}
5167
}
5268
}
5369
}

claimManagement/src/main/java/org/openimis/imisclaims/EnquireActivity.java

Lines changed: 150 additions & 93 deletions
Large diffs are not rendered by default.

claimManagement/src/main/java/org/openimis/imisclaims/SubHouseholdActivity.java

Lines changed: 185 additions & 71 deletions
Large diffs are not rendered by default.

claimManagement/src/main/java/org/openimis/imisclaims/adapter/FamilyMemberAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private String formatDate(String dateString) {
156156
}
157157
}
158158

159-
// Si aucun format ne fonctionne, retourner la chaîne originale
159+
// If no format works, return the original string
160160
Log.w(LOG_TAG, "Unable to parse date: " + dateString);
161161
return dateString;
162162
}

claimManagement/src/main/java/org/openimis/imisclaims/adapter/PolygamousSubFamilyAdapter.java

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
import java.util.ArrayList;
2222
import java.util.Date;
23+
import java.util.HashSet;
2324
import java.util.List;
25+
import java.util.Set;
2426

2527
public class PolygamousSubFamilyAdapter extends RecyclerView.Adapter<PolygamousSubFamilyAdapter.ViewHolder> {
2628
private static final String LOG_TAG = "PolygamousSubFamilyAdapter";
@@ -167,7 +169,7 @@ private void bindSubFamily(ViewHolder holder, PolygamousSubFamily subFamily) {
167169
holder.tvMembersCount.setTextColor(context.getResources().getColor(R.color.colorAccent));
168170
Log.d(LOG_TAG, "Chef de sous-famille identifié: " + subFamily.getFullName());
169171
} else {
170-
// Cas par défaut (ne devrait pas arriver)
172+
// Default case (should not happen)
171173
membersText = context.getResources().getQuantityString(
172174
R.plurals.sub_family_members_count, membersCount, membersCount);
173175
holder.tvMembersCount.setTextColor(context.getResources().getColor(android.R.color.darker_gray));
@@ -207,7 +209,7 @@ private void loadPhoto(ImageView imageView, PolygamousSubFamily subFamily) {
207209
try {
208210
if (photoData != null && !photoData.isEmpty()) {
209211
Log.d(LOG_TAG, "Attempting to decode Base64 photo...");
210-
// Décoder la photo Base64
212+
// Decode Base64 photo
211213
byte[] decodedBytes = Base64.decode(photoData, Base64.DEFAULT);
212214
Log.d(LOG_TAG, "Decoded bytes length: " + decodedBytes.length);
213215

@@ -226,7 +228,7 @@ private void loadPhoto(ImageView imageView, PolygamousSubFamily subFamily) {
226228
Log.e(LOG_TAG, "❌ Error loading photo for sub-family head", e);
227229
}
228230

229-
// Photo par défaut
231+
// Default photo
230232
Log.d(LOG_TAG, "Using default placeholder image");
231233
imageView.setImageResource(R.drawable.ic_person_placeholder);
232234
}
@@ -238,16 +240,59 @@ public void updateData(List<PolygamousSubFamily> newSubFamilies) {
238240
if (newSubFamilies == null) {
239241
this.subFamilies = new ArrayList<>();
240242
} else {
241-
this.subFamilies = new ArrayList<>(newSubFamilies); // Copie défensive
243+
// Deduplication based on UUID and CHFID to avoid duplicates
244+
this.subFamilies = removeDuplicates(newSubFamilies);
242245
}
243246

244247
notifyDataSetChanged();
245-
Log.d(LOG_TAG, "Données mises à jour avec succès");
248+
Log.d(LOG_TAG, "Données mises à jour avec succès - après déduplication: " + this.subFamilies.size());
246249
} catch (Exception e) {
247250
Log.e(LOG_TAG, "Erreur lors de la mise à jour des données", e);
248251
}
249252
}
250253

254+
/**
255+
* Supprime les doublons de la liste des sous-familles polygames
256+
* basé sur l'UUID et le CHFID pour éviter l'affichage de chefs en double
257+
*/
258+
private List<PolygamousSubFamily> removeDuplicates(List<PolygamousSubFamily> subFamilies) {
259+
List<PolygamousSubFamily> uniqueSubFamilies = new ArrayList<>();
260+
Set<String> seenUuids = new HashSet<>();
261+
Set<String> seenChfIds = new HashSet<>();
262+
263+
for (PolygamousSubFamily subFamily : subFamilies) {
264+
if (subFamily == null) {
265+
continue;
266+
}
267+
268+
String uuid = subFamily.getUuid();
269+
String chfId = subFamily.getChfId();
270+
271+
// Check duplicates based on UUID or CHFID
272+
boolean isDuplicateByUuid = uuid != null && seenUuids.contains(uuid);
273+
boolean isDuplicateByChfId = chfId != null && seenChfIds.contains(chfId);
274+
275+
if (!isDuplicateByUuid && !isDuplicateByChfId) {
276+
uniqueSubFamilies.add(subFamily);
277+
if (uuid != null) {
278+
seenUuids.add(uuid);
279+
}
280+
if (chfId != null) {
281+
seenChfIds.add(chfId);
282+
}
283+
} else {
284+
Log.w(LOG_TAG, "Doublon détecté et supprimé - UUID: " + uuid + ", CHFID: " + chfId);
285+
}
286+
}
287+
288+
int duplicatesRemoved = subFamilies.size() - uniqueSubFamilies.size();
289+
if (duplicatesRemoved > 0) {
290+
Log.i(LOG_TAG, "Déduplication terminée - " + duplicatesRemoved + " doublon(s) supprimé(s)");
291+
}
292+
293+
return uniqueSubFamilies;
294+
}
295+
251296
public static class ViewHolder extends RecyclerView.ViewHolder {
252297
ImageView ivPhoto;
253298
TextView tvName;

claimManagement/src/main/java/org/openimis/imisclaims/domain/entity/Family.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Family {
1010
private String headInsureeUuid;
1111
private String headInsureeChfId;
1212
private String headInsureeName;
13+
private Insuree headInsuree;
1314
private String location;
1415
private String familyType;
1516
private List<FamilyMember> members;
@@ -112,6 +113,14 @@ public void setFamilyType(String familyType) {
112113
this.familyType = familyType;
113114
}
114115

116+
public Insuree getHeadInsuree() {
117+
return headInsuree;
118+
}
119+
120+
public void setHeadInsuree(Insuree headInsuree) {
121+
this.headInsuree = headInsuree;
122+
}
123+
115124
/**
116125
* Vérifie si cette famille a un parent (donc c'est une sous-famille)
117126
*/

claimManagement/src/main/java/org/openimis/imisclaims/domain/entity/PolygamousSubFamily.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ public String getFullName() {
147147
}
148148

149149
public boolean isPolygamousHead() {
150-
// Un chef de ménage polygame principal est identifié par sa relation "Head" et l'absence de parentUuid
151-
// Les chefs de sous-familles ont la relation "SubFamilyHead" et un parentUuid défini
150+
// A main polygamous household head is identified by "Head" relationship and absence of parentUuid
151+
// Sub-family heads have "SubFamilyHead" relationship and a defined parentUuid
152152
return "Head".equalsIgnoreCase(relationship) && (parentUuid == null || parentUuid.isEmpty());
153153
}
154154

155155
public boolean isSubFamilyHead() {
156-
// Un chef de sous-famille est identifié par sa relation "SubFamilyHead" et un parentUuid défini
156+
// A sub-family head is identified by "SubFamilyHead" relationship and a defined parentUuid
157157
return "SubFamilyHead".equalsIgnoreCase(relationship) && parentUuid != null && !parentUuid.isEmpty();
158158
}
159159

@@ -170,7 +170,7 @@ public static boolean isInsureeInPolygamousFamily(FamilyMember insuree, Family i
170170
return false;
171171
}
172172

173-
// Détection basée uniquement sur le familyType
173+
// Detection based only on familyType
174174
return FamilyTypeConstants.isPolygamyFamilyType(insureeFamily.getFamilyType());
175175
}
176176

@@ -211,12 +211,12 @@ public static boolean isPartOfPolygamousFamily(Family family, Family parentFamil
211211
return false;
212212
}
213213

214-
// Vérification directe : si la famille est polygame
214+
// Direct verification: if family is polygamous
215215
if (FamilyTypeConstants.isPolygamyFamilyType(family.getFamilyType())) {
216216
return true;
217217
}
218218

219-
// Vérification indirecte : si c'est une sous-famille d'une famille polygame
219+
// Indirect verification: if it's a sub-family of a polygamous family
220220
if (parentFamily != null && FamilyTypeConstants.isPolygamyFamilyType(parentFamily.getFamilyType())) {
221221
return true;
222222
}
@@ -249,19 +249,19 @@ public boolean hasActiveInsuranceContract(Context context) {
249249
}
250250

251251
SQLHandler sqlHandler = new SQLHandler(context);
252-
// S'assurer que les tables sont créées
252+
// Ensure tables are created
253253
sqlHandler.createTables();
254254
SQLiteDatabase db = sqlHandler.getReadableDatabase();
255255

256-
// Vérifier si la table existe
256+
// Check if table exists
257257
Cursor tableCheck = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='tblPolicyInquiry'", null);
258258
if (tableCheck.getCount() == 0) {
259-
Log.e("PolygamousSubFamily", "Table tblPolicyInquiry n'existe pas!");
259+
260260
tableCheck.close();
261261
return false;
262262
}
263263
tableCheck.close();
264-
Log.d("PolygamousSubFamily", "Table tblPolicyInquiry trouvée, exécution de la requête");
264+
265265

266266
String[] columns = {"Status", "ExpiryDate"};
267267
String[] selectionArgs = {chfId.trim()};
@@ -275,15 +275,15 @@ public boolean hasActiveInsuranceContract(Context context) {
275275
String status = cursor.getString(cursor.getColumnIndex("Status"));
276276
String expiryDate = cursor.getString(cursor.getColumnIndex("ExpiryDate"));
277277

278-
// Vérifier si le contrat est actif
278+
// Check if contract is active
279279
if ("ACTIVE".equals(status)) {
280280
return true;
281281
}
282282
} while (cursor.moveToNext());
283283
}
284284
} catch (Exception e) {
285285
// Log l'erreur mais ne pas faire planter l'application
286-
android.util.Log.e("PolygamousSubFamily", "Erreur lors de la vérification du contrat d'assurance", e);
286+
287287
} finally {
288288
if (cursor != null) {
289289
cursor.close();

0 commit comments

Comments
 (0)