Skip to content

Commit

Permalink
added search by building name
Browse files Browse the repository at this point in the history
  • Loading branch information
yashita-egov committed Dec 5, 2024
1 parent c36c17c commit c9a7b24
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class HouseholdLocalRepository
? null
: AddressModel(
id: address.id,
buildingName: address.buildingName,
relatedClientReferenceId: household.clientReferenceId,
tenantId: address.tenantId,
doorNo: address.doorNo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:math' as math;

import 'package:digit_data_model/data_model.dart';
import 'package:digit_data_model/models/entities/household_type.dart';
import 'package:drift/drift.dart';
import 'package:flutter/material.dart';
import 'package:registration_delivery/models/entities/task.dart';
Expand Down Expand Up @@ -229,7 +230,12 @@ class HouseHoldGlobalSearchRepository extends LocalRepository {
.individual
.select()
.join([joinName(sql), joinIndividualAddress(sql)]);
await searchByName(selectQuery, params, sql);
if (params.householdType == HouseholdType.community) {
await searchByBuildingName(selectQuery, params, sql);
} else {
await searchByName(selectQuery, params, sql);
}

selectQuery = selectQuery.join([
leftOuterJoin(
sql.householdMember,
Expand All @@ -250,10 +256,14 @@ class HouseHoldGlobalSearchRepository extends LocalRepository {
} else if (params.nameSearch != null &&
params.nameSearch!.isNotEmpty &&
selectQuery != null) {
selectQuery = selectQuery.join([
joinName(sql),
]);
selectQuery = searchByName(selectQuery, params, sql);
if (params.householdType == HouseholdType.community) {
selectQuery = searchByBuildingName(selectQuery, params, sql);
} else {
selectQuery = selectQuery.join([
joinName(sql),
]);
selectQuery = searchByName(selectQuery, params, sql);
}
}
return selectQuery;
}
Expand Down Expand Up @@ -383,6 +393,16 @@ class HouseHoldGlobalSearchRepository extends LocalRepository {
);
}

searchByBuildingName(
selectQuery, GlobalSearchParameters params, LocalSqlDataStore sql) {
return selectQuery.where(buildAnd([
if (params.nameSearch != null)
buildOr([
sql.address.buildingName.contains(params.nameSearch!),
]),
]));
}

joinHouseHoldAddress(LocalSqlDataStore sql) {
return leftOuterJoin(
sql.household,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ class IndividualGlobalSearchRepository extends LocalRepository {
.individual
.select()
.join([joinName(sql), joinIndividualAddress(sql)]);
await searchByName(selectQuery, params, sql);

if (params.householdClientReferenceId != null) {
await searchByName(selectQuery, params, sql);

selectQuery = selectQuery.join([
leftOuterJoin(
sql.household,
Expand All @@ -259,6 +261,12 @@ class IndividualGlobalSearchRepository extends LocalRepository {
.equals(params.householdClientReferenceId ?? '')
]));
} else {
if (params.householdType == HouseholdType.community) {
await searchByBuildingName(selectQuery, params, sql);
} else {
await searchByName(selectQuery, params, sql);
}

selectQuery = selectQuery.join([
leftOuterJoin(
sql.householdMember,
Expand All @@ -283,10 +291,15 @@ class IndividualGlobalSearchRepository extends LocalRepository {
} else if (params.nameSearch != null &&
params.nameSearch!.isNotEmpty &&
selectQuery != null) {
selectQuery = selectQuery.join([
joinName(sql),
]);
selectQuery = searchByName(selectQuery, params, sql);
if (params.householdType == HouseholdType.community &&
params.householdClientReferenceId == null) {
selectQuery = searchByBuildingName(selectQuery, params, sql);
} else {
selectQuery = selectQuery.join([
joinName(sql),
]);
selectQuery = searchByName(selectQuery, params, sql);
}
}
return selectQuery;
}
Expand All @@ -303,6 +316,16 @@ class IndividualGlobalSearchRepository extends LocalRepository {
]));
}

searchByBuildingName(
selectQuery, GlobalSearchParameters params, LocalSqlDataStore sql) {
return selectQuery.where(buildAnd([
if (params.nameSearch != null)
buildOr([
sql.address.buildingName.contains(params.nameSearch!),
]),
]));
}

filterSearch(selectQuery, GlobalSearchParameters params, String filter,
LocalSqlDataStore sql) async {
var sql = super.sql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ class _HouseholdOverviewPageState
.householdOverView
.instituteNameLabel): state
.householdMemberWrapper
.headOfHousehold
?.name
?.givenName ??
.household
?.address
?.buildingName ??
localizations.translate(
i18.common.coreCommonNA),
localizations.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ class _SearchBeneficiaryPageState
null &&
RegistrationDeliverySingleton()
.searchHouseHoldFilter!
.isNotEmpty
.isNotEmpty &&
RegistrationDeliverySingleton()
.householdType !=
HouseholdType.community
? Align(
alignment: Alignment.topLeft,
child: Padding(
Expand Down

0 comments on commit c9a7b24

Please sign in to comment.