Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4308418
added pagination for household_overview
yashita-egov Nov 25, 2024
a0cea61
added search and filter functionality in household_overview
yashita-egov Nov 27, 2024
4d1caa7
fixed issues with test
yashita-egov Nov 28, 2024
47d0ef9
hcmpre-1259-added homepage card for institution
yashita-egov Nov 19, 2024
0b4ea20
added enum householdType for facility based campaign
yashita-egov Nov 28, 2024
8592a36
hcmpre-1421: ui changes for search and overview page
yashita-egov Dec 3, 2024
72d22f9
localization code added
yashita-egov Dec 3, 2024
589c6f5
hcmpre-1249: mapping search query based on the household type
yashita-egov Dec 3, 2024
78aab22
fix issues with filter ui and query
yashita-egov Dec 3, 2024
f551013
added ui changes and mapping head of household search for clf
yashita-egov Dec 5, 2024
c36c17c
individual global search to show all total members
yashita-egov Dec 5, 2024
c9a7b24
added search by building name
yashita-egov Dec 5, 2024
77fbcbe
added test case for household overview bloc
yashita-egov Dec 5, 2024
8bf341c
removed clf hard-coded value
yashita-egov Dec 6, 2024
7793560
added placeholder for building name for clf
yashita-egov Dec 16, 2024
ce7745a
fix member count
yashita-egov Dec 19, 2024
fafc934
fix issues with pagination and filter
yashita-egov Dec 20, 2024
c90f7a4
resolved review comments
yashita-egov Dec 20, 2024
832fbbb
fix address issues
yashita-egov Dec 20, 2024
8c20de1
new mdms data for search clf filters
naveenr-egov Dec 23, 2024
4ec0b1f
revert search based on household
yashita-egov Dec 23, 2024
9ef6443
Revert "revert search based on household"
yashita-egov Dec 23, 2024
8743cd7
Merge branch 'hcmpre-1250-beneficiary' of https://github.com/egovernm…
yashita-egov Dec 23, 2024
ed4608a
removed search based on household
yashita-egov Dec 23, 2024
1e7a3e7
Merge branch 'develop' of https://github.com/egovernments/health-camp…
yashita-egov Dec 23, 2024
f51cf7e
added search clf in app configuration
yashita-egov Dec 23, 2024
50e60ae
clf filters initialization fix
naveenr-egov Dec 23, 2024
d477508
component issue fix
yashita-egov Dec 23, 2024
373b2a7
fix dob
yashita-egov Dec 23, 2024
68d971b
fix household type issues
yashita-egov Dec 23, 2024
a6e615e
build fix
yashita-egov Dec 23, 2024
d114234
added household details screen for clf
yashita-egov Dec 26, 2024
99f5570
build and review comment fix
yashita-egov Dec 30, 2024
d95ddaa
resolved review comments
yashita-egov Jan 8, 2025
6445408
integrate clf downysnc api
yashita-egov Jan 21, 2025
db6939b
added apiOperation for clf downsync
yashita-egov Jan 21, 2025
4bf2fae
added downsyncReository provider
yashita-egov Jan 21, 2025
f65bea6
clf api changes added to project beneficiary bloc
yashita-egov Jan 22, 2025
5a98374
added clf Offset and count tin table
yashita-egov Jan 22, 2025
9caa9b5
added code comment
yashita-egov Jan 23, 2025
dc1ce70
Merge remote-tracking branch 'origin/develop' into hcmpre-1250-benefi…
yashita-egov Jan 28, 2025
f62ffe3
fix page issues
yashita-egov Jan 28, 2025
b57ea86
fix popUp context issue in beneficiary checklist
yashita-egov Jan 29, 2025
49568cf
Merge remote-tracking branch 'origin/develop' into hcmpre-1250-benefi…
yashita-egov Jan 29, 2025
7647caf
added editable numeric field
yashita-egov Jan 30, 2025
7977025
fix build issue
yashita-egov Jan 31, 2025
c327131
fix apk workflow
yashita-egov Jan 31, 2025
dac274e
fix upload apk workflow
yashita-egov Jan 31, 2025
1024122
generate apk issue
yashita-egov Jan 31, 2025
6e09db7
Merge branch 'hcmpre-1250-beneficiary' into HCMPRE-1795
yashita-egov Feb 20, 2025
1b6b93d
Merge branch 'develop' into HCMPRE-1795
naveenr-egov Mar 25, 2025
b40b8f3
merge conflicts with dev
naveenr-egov Mar 25, 2025
bc6b87d
merge conflicts with dev
naveenr-egov Mar 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ class MdmsConfig {
final List<ServiceRegistry> serviceRegistryList;
final List<DashboardConfigSchema?>? dashboardConfigSchema;


const MdmsConfig(
{required this.appConfigs,
required this.serviceRegistryList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import 'dart:async';

import 'package:digit_data_model/data_model.dart';
import 'package:digit_data_model/models/entities/household_type.dart';
import 'package:disk_space_update/disk_space_update.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
Expand All @@ -11,6 +12,7 @@ import 'package:sync_service/sync_service_lib.dart';
import '../../data/local_store/no_sql/schema/app_configuration.dart';
import '../../data/local_store/secure_store/secure_store.dart';
import '../../data/repositories/remote/bandwidth_check.dart';
import '../../data/repositories/remote/downsync.dart';
import '../../models/downsync/downsync.dart';
import '../../utils/background_service.dart';
import '../../utils/environment_config.dart';
Expand All @@ -23,20 +25,19 @@ class BeneficiaryDownSyncBloc
extends Bloc<BeneficiaryDownSyncEvent, BeneficiaryDownSyncState> {
final LocalRepository<IndividualModel, IndividualSearchModel>
individualLocalRepository;
final RemoteRepository<DownsyncModel, DownsyncSearchModel>
downSyncRemoteRepository;
final DownsyncRemoteRepository downSyncRemoteRepository;
final LocalRepository<DownsyncModel, DownsyncSearchModel>
downSyncLocalRepository;
final BandwidthCheckRepository bandwidthCheckRepository;
final LocalRepository<HouseholdModel, HouseholdSearchModel>
householdLocalRepository;
householdLocalRepository;
final LocalRepository<HouseholdMemberModel, HouseholdMemberSearchModel>
householdMemberLocalRepository;
householdMemberLocalRepository;
final LocalRepository<ProjectBeneficiaryModel, ProjectBeneficiarySearchModel>
projectBeneficiaryLocalRepository;
projectBeneficiaryLocalRepository;
final LocalRepository<TaskModel, TaskSearchModel> taskLocalRepository;
final LocalRepository<SideEffectModel, SideEffectSearchModel>
sideEffectLocalRepository;
sideEffectLocalRepository;
final LocalRepository<ReferralModel, ReferralSearchModel>
referralLocalRepository;
BeneficiaryDownSyncBloc({
Expand Down Expand Up @@ -107,6 +108,8 @@ class BeneficiaryDownSyncBloc
} else {
emit(const BeneficiaryDownSyncState.loading(true));
await LocalSecureStore.instance.setManualSyncTrigger(true);

int serverTotalCount = 0, clfServerCount = 0;
final existingDownSyncData =
await downSyncLocalRepository.search(DownsyncSearchModel(
locality: event.boundaryCode,
Expand All @@ -116,32 +119,65 @@ class BeneficiaryDownSyncBloc
? null
: existingDownSyncData.first.lastSyncedTime;

//To get the server totalCount,
final initialResults = await downSyncRemoteRepository.downSync(
DownsyncSearchModel(
//Check if the event is for DISTRIBUTOR
if (event.isDistributor) {
//To get the server totalCount,
final initialResults = await downSyncRemoteRepository.downSync(
DownsyncSearchModel(
locality: event.boundaryCode,
offset: existingDownSyncData.firstOrNull?.offset ?? 0,
limit: 1,
isDeleted: true,
lastSyncedTime: lastSyncedTime,
tenantId: envConfig.variables.tenantId,
projectId: event.projectId,
),
);

//If API request failed, reset the State and emit a failure state
if (initialResults.isEmpty) {
await LocalSecureStore.instance.setManualSyncTrigger(false);
emit(const BeneficiaryDownSyncState.resetState());
emit(const BeneficiaryDownSyncState.totalCountCheckFailed());
return;
}

//Extract server total count
serverTotalCount = initialResults["DownsyncCriteria"]["totalCount"];
}

//Check if the event is for COMMUNITY_CREATOR
if (event.isCommunityCreator) {
//To get the CLF server totalCount
final initialResults = await downSyncRemoteRepository
.searchClfDownSync(DownsyncSearchModel(
locality: event.boundaryCode,
offset: existingDownSyncData.firstOrNull?.offset ?? 0,
limit: 1,
isDeleted: true,
lastSyncedTime: lastSyncedTime,
tenantId: envConfig.variables.tenantId,
projectId: event.projectId,
),
);
if (initialResults.isNotEmpty) {
// Current response from server is String, Expecting it to be int
//[TODO: Need to move the dynamic keys to constants
int serverTotalCount = initialResults["DownsyncCriteria"]["totalCount"];

emit(BeneficiaryDownSyncState.dataFound(
serverTotalCount,
event.batchSize,
));
} else {
await LocalSecureStore.instance.setManualSyncTrigger(false);
emit(const BeneficiaryDownSyncState.resetState());
emit(const BeneficiaryDownSyncState.totalCountCheckFailed());

//If API request failed, reset the State and emit a failure state
if (initialResults.isEmpty) {
await LocalSecureStore.instance.setManualSyncTrigger(false);
emit(const BeneficiaryDownSyncState.resetState());
emit(const BeneficiaryDownSyncState.totalCountCheckFailed());
return;
}

//Extract clf total count
clfServerCount = initialResults["DownsyncCriteria"]["totalCount"];
}

// Emit a new state indicating that data has been found. Pass the server's total count, and clf total count
emit(BeneficiaryDownSyncState.dataFound(
serverTotalCount,
clfServerCount,
event.batchSize,
));
}
}

Expand Down Expand Up @@ -169,23 +205,42 @@ class BeneficiaryDownSyncBloc
int offset = existingDownSyncData.isEmpty
? 0
: existingDownSyncData.first.offset ?? 0;

int clfOffset = existingDownSyncData.isEmpty
? 0
: existingDownSyncData.first.clfOffset ?? 0;

int totalCount = event.initialServerCount;

int clfTotalCount = event.clfServerCount;

int? lastSyncedTime = existingDownSyncData.isEmpty
? null
: existingDownSyncData.first.lastSyncedTime;

if (existingDownSyncData.isEmpty) {
await downSyncLocalRepository.create(DownsyncModel(
offset: offset,
clfOffset: clfOffset,
limit: event.batchSize,
lastSyncedTime: lastSyncedTime,
totalCount: totalCount,
clfTotalCount: clfTotalCount,
locality: event.boundaryCode,
boundaryName: event.boundaryName,
));
}

if (offset < totalCount) {
emit(BeneficiaryDownSyncState.inProgress(offset, totalCount));
//Flag to check if any API calls are made, if not then break out of loop
bool flag = false;

emit(BeneficiaryDownSyncState.inProgress(
offset, totalCount, clfTotalCount));

//Check if logged in user has role DISTRIBUTOR and offset value is less than totalcount
//then make API call
if (event.isDistributor && offset < totalCount) {
flag = true;
//Make the batch API call
final downSyncResults = await downSyncRemoteRepository.downSync(
DownsyncSearchModel(
Expand All @@ -199,6 +254,7 @@ class BeneficiaryDownSyncBloc
isDeleted: true,
),
);

// check if the API response is there or it failed
if (downSyncResults.isNotEmpty) {
await SyncServiceSingleton()
Expand All @@ -214,43 +270,122 @@ class BeneficiaryDownSyncBloc
]);
// Update the local downSync data for the boundary with the new values
totalCount = downSyncResults["DownsyncCriteria"]["totalCount"];

await downSyncLocalRepository.update(DownsyncModel(
offset: offset + event.batchSize,
limit: event.batchSize,
lastSyncedTime: lastSyncedTime,
totalCount: totalCount,
locality: event.boundaryCode,
boundaryName: event.boundaryName,
));
}
// When API response failed
else {
emit(const BeneficiaryDownSyncState.failed());
await LocalSecureStore.instance.setManualSyncTrigger(false);
break;
}
} else {
}

//Check if logged in user has role COMMUNITY_CREATOR and clfOffset value is less than clfTotalCount
//then make API call
if (event.isCommunityCreator && clfOffset < clfTotalCount) {
flag = true;

//Get households
final downSyncResults = await downSyncRemoteRepository
.searchClfDownSync(DownsyncSearchModel(
locality: event.boundaryCode,
offset: clfOffset,
limit: event.batchSize,
totalCount: clfTotalCount,
tenantId: envConfig.variables.tenantId,
projectId: event.projectId,
lastSyncedTime: lastSyncedTime,
isDeleted: true,
));

if (downSyncResults.isNotEmpty) {
final householdList = downSyncResults["Households"] as List;
final memberCountList =
downSyncResults["numberOfMembers"] as List;
int idx = 0;

//Get memberData for each household
householdList.forEach((e) async {
int memberOffset = 0;
int memberCount = memberCountList[idx++];
while (memberCount > 0) {
final memberData = await downSyncRemoteRepository
.getMemberData(DownsyncSearchModel(
locality: event.boundaryCode,
offset: memberOffset,
limit: event.batchSize,
totalCount: clfTotalCount,
tenantId: envConfig.variables.tenantId,
projectId: event.projectId,
lastSyncedTime: lastSyncedTime,
isDeleted: true,
householdId: e["id"],
));

if (memberData.isEmpty) break;
if (memberData["Households"] == null) {
memberData["Households"] = [];
memberData["Households"].add(e);
}
await SyncServiceSingleton()
.entityMapper
?.writeToEntityDB(memberData, [
individualLocalRepository,
householdLocalRepository,
householdMemberLocalRepository,
projectBeneficiaryLocalRepository,
taskLocalRepository,
sideEffectLocalRepository,
referralLocalRepository,
]);
memberCount -= event.batchSize;
memberOffset += event.batchSize;
}
});

clfTotalCount = downSyncResults["DownsyncCriteria"]["totalCount"];
} else {
emit(const BeneficiaryDownSyncState.failed());
await LocalSecureStore.instance.setManualSyncTrigger(false);
break;
}
}

if (!flag) {
//Update DownSync result
await downSyncLocalRepository.update(
existingDownSyncData.first.copyWith(
offset: 0,
limit: 0,
totalCount: totalCount,
clfTotalCount: clfTotalCount,
locality: event.boundaryCode,
boundaryName: event.boundaryName,
lastSyncedTime: DateTime.now().millisecondsSinceEpoch,
),
);
final result = DownsyncModel(
offset: totalCount,
clfOffset: clfTotalCount,
lastSyncedTime: DateTime.now().millisecondsSinceEpoch,
totalCount: totalCount,
clfTotalCount: clfTotalCount,
locality: event.boundaryCode,
boundaryName: event.boundaryName,
);
await LocalSecureStore.instance.setManualSyncTrigger(false);
emit(BeneficiaryDownSyncState.success(result));
break; // If offset is greater than or equal to totalCount, exit the loop
break;
} else {
await downSyncLocalRepository.update(DownsyncModel(
offset: (totalCount != 0) ? offset + event.batchSize : 0,
clfOffset: (clfTotalCount != 0) ? clfOffset + event.batchSize : 0,
limit: event.batchSize,
lastSyncedTime: lastSyncedTime,
totalCount: totalCount,
clfTotalCount: clfTotalCount,
locality: event.boundaryCode,
boundaryName: event.boundaryName,
));
}
}
} catch (e) {
Expand All @@ -276,7 +411,10 @@ class BeneficiaryDownSyncEvent with _$BeneficiaryDownSyncEvent {
required String boundaryCode,
required int batchSize,
required int initialServerCount,
required int clfServerCount,
required String boundaryName,
required bool isCommunityCreator,
required bool isDistributor,
}) = DownSyncBeneficiaryEvent;

const factory BeneficiaryDownSyncEvent.checkForData({
Expand All @@ -285,6 +423,8 @@ class BeneficiaryDownSyncEvent with _$BeneficiaryDownSyncEvent {
required int pendingSyncCount,
required int batchSize,
required String boundaryName,
required bool isCommunityCreator,
required bool isDistributor,
}) = DownSyncCheckTotalCountEvent;

const factory BeneficiaryDownSyncEvent.getBatchSize({
Expand All @@ -307,6 +447,7 @@ class BeneficiaryDownSyncState with _$BeneficiaryDownSyncState {
const factory BeneficiaryDownSyncState.inProgress(
int syncedCount,
int totalCount,
int clfTotalCount,
) = _DownSyncInProgressState;
const factory BeneficiaryDownSyncState.success(
DownsyncModel downSyncResult,
Expand All @@ -324,6 +465,7 @@ class BeneficiaryDownSyncState with _$BeneficiaryDownSyncState {
_DownSyncInsufficientStorageState;
const factory BeneficiaryDownSyncState.dataFound(
int initialServerCount,
int initialClfServerCount,
int batchSize,
) = _DownSyncDataFoundState;
const factory BeneficiaryDownSyncState.resetState() = _DownSyncResetState;
Expand Down
Loading