Skip to content

Commit

Permalink
added lat,lng and boundary code in service additional field
Browse files Browse the repository at this point in the history
  • Loading branch information
yashita-egov committed Dec 3, 2024
1 parent 7a22003 commit b44efb1
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 103 deletions.
84 changes: 35 additions & 49 deletions packages/survey_form/lib/data/repositories/local/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import 'package:digit_data_model/data_model.dart';
import 'package:drift/drift.dart';
import 'package:survey_form/survey_form.dart';


class ServiceLocalRepository
extends LocalRepository<ServiceModel, ServiceSearchModel> {
ServiceLocalRepository(super.sql, super.opLogManager);

// function to create a Service entity in the local database
@override
FutureOr<void> create(
ServiceModel entity, {
bool createOpLog = true,
DataOperation dataOperation = DataOperation.singleCreate,
}) async {
ServiceModel entity, {
bool createOpLog = true,
DataOperation dataOperation = DataOperation.singleCreate,
}) async {
return retryLocalCallOperation(() async {
final serviceCompanion = entity.companion;
final attributes = entity.attributes;
Expand Down Expand Up @@ -46,42 +45,29 @@ class ServiceLocalRepository
serviceDefId: entity.serviceDefId,
isActive: entity.isActive,
accountId: entity.accountId,
additionalDetails: entity.additionalDetails,
tenantId: entity.tenantId,
isDeleted: entity.isDeleted,
rowVersion: entity.rowVersion,
additionalFields: ServiceAdditionalFields(
version: 1,
fields: [
AdditionalField(
'clientCreatedTime',
DateTime.now().millisecondsSinceEpoch.toString(),
),
AdditionalField(
'clientCreatedBy',
entity.auditDetails?.createdBy,
),
],
),
additionalFields: entity.additionalFields,
auditDetails: entity.auditDetails,
clientAuditDetails: entity.clientAuditDetails,
attributes: entity.attributes?.map((e) {
return e.dataType == 'Number'
? e.copyWith(value: int.tryParse(e.value))
: e.dataType == 'MultiValueList'
? e.copyWith(
value: e.value.toString().split('.'),
additionalDetails: e.additionalDetails != null
? {"value": e.additionalDetails}
: null,
)
: e.dataType == 'SingleValueList'
? e.copyWith(
additionalDetails: e.additionalDetails != null
? {"value": e.additionalDetails}
: null,
)
: e;
? e.copyWith(
value: e.value.toString().split('.'),
additionalDetails: e.additionalDetails != null
? {"value": e.additionalDetails}
: null,
)
: e.dataType == 'SingleValueList'
? e.copyWith(
additionalDetails: e.additionalDetails != null
? {"value": e.additionalDetails}
: null,
)
: e;
}).toList(),
);

Expand All @@ -96,21 +82,21 @@ class ServiceLocalRepository
//function to search Service entities corresponding to selected service definition from local database
@override
FutureOr<List<ServiceModel>> search(
ServiceSearchModel query,
) async {
ServiceSearchModel query,
) async {
return retryLocalCallOperation<List<ServiceModel>>(() async {
final selectQuery = sql.select(sql.service).join([]);
final results = await (selectQuery
..where(buildAnd([
if (query.id != null)
sql.service.serviceDefId.equals(
query.id!,
),
if (query.clientId != null)
sql.service.clientId.equals(
query.clientId!,
),
])))
..where(buildAnd([
if (query.id != null)
sql.service.serviceDefId.equals(
query.id!,
),
if (query.clientId != null)
sql.service.clientId.equals(
query.clientId!,
),
])))
.get();

final List<ServiceModel> serviceList = [];
Expand All @@ -119,11 +105,11 @@ class ServiceLocalRepository
final selectattributeQuery = sql.select(sql.serviceAttributes).join([]);

final val = await (selectattributeQuery
..where(buildAnd([
sql.serviceAttributes.referenceId.equals(
data.clientId,
),
])))
..where(buildAnd([
sql.serviceAttributes.referenceId.equals(
data.clientId,
),
])))
.get();
final res = val.map((e) {
final attribute = e.readTableOrNull(sql.serviceAttributes);
Expand Down
114 changes: 60 additions & 54 deletions packages/survey_form/lib/pages/survey_form_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,61 +265,67 @@ class SurveyFormViewPageState extends LocalizedState<SurveyFormViewPage> {
context.read<ServiceBloc>().add(
ServiceCreateEvent(
serviceModel: ServiceModel(
createdAt: DigitDateUtils
.getDateFromTimestamp(
DateTime.now()
.toLocal()
.millisecondsSinceEpoch,
dateFormat: Constants
.SurveyFormViewDateFormat,
),
tenantId: value
.selectedServiceDefinition!
.tenantId,
clientId: isHealthFacilityWorker &&
widget.referralClientRefId !=
null
? widget
.referralClientRefId
.toString()
: referenceId,
serviceDefId: value
.selectedServiceDefinition
?.id,
attributes: attributes,
rowVersion: 1,
accountId:
SurveyFormSingleton()
.projectId,
auditDetails: AuditDetails(
createdBy:
SurveyFormSingleton()
.loggedInUserUuid,
createdTime: DateTime.now()
.millisecondsSinceEpoch,
),
clientAuditDetails:
ClientAuditDetails(
createdBy:
SurveyFormSingleton()
.loggedInUserUuid,
createdTime: context
.millisecondsSinceEpoch(),
lastModifiedBy:
SurveyFormSingleton()
.loggedInUserUuid,
lastModifiedTime: context
.millisecondsSinceEpoch(),
),
additionalDetails: {
"boundaryCode":
createdAt: DigitDateUtils
.getDateFromTimestamp(
DateTime.now()
.toLocal()
.millisecondsSinceEpoch,
dateFormat: Constants
.SurveyFormViewDateFormat,
),
tenantId: value
.selectedServiceDefinition!
.tenantId,
clientId: isHealthFacilityWorker &&
widget.referralClientRefId !=
null
? widget
.referralClientRefId
.toString()
: referenceId,
serviceDefId: value
.selectedServiceDefinition
?.id,
attributes: attributes,
rowVersion: 1,
accountId:
SurveyFormSingleton()
.boundary
?.code,
'lat': latitude,
'lng': longitude,
},
),
.projectId,
auditDetails: AuditDetails(
createdBy:
SurveyFormSingleton()
.loggedInUserUuid,
createdTime: DateTime
.now()
.millisecondsSinceEpoch,
),
clientAuditDetails:
ClientAuditDetails(
createdBy:
SurveyFormSingleton()
.loggedInUserUuid,
createdTime: context
.millisecondsSinceEpoch(),
lastModifiedBy:
SurveyFormSingleton()
.loggedInUserUuid,
lastModifiedTime: context
.millisecondsSinceEpoch(),
),
additionalFields:
ServiceAdditionalFields(
version: 1,
fields: [
AdditionalField(
'lng', longitude),
AdditionalField(
'lat', latitude),
AdditionalField(
'boundaryCode',
SurveyFormSingleton()
.boundary
?.code)
])),
),
);
Navigator.of(
Expand Down

0 comments on commit b44efb1

Please sign in to comment.