Skip to content

Commit 56420e4

Browse files
committed
Added try catch for resolving additionalFields
Updated config for registration_flows.dart
1 parent 63ce903 commit 56420e4

File tree

2 files changed

+72
-37
lines changed

2 files changed

+72
-37
lines changed

apps/health_campaign_field_worker_app/lib/sampleJsonConfigs/registration_flows.dart

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,25 +3207,41 @@ final dynamic sampleFlows = {
32073207
"fallback": 1,
32083208
"condition": {
32093209
"if": {
3210-
"left": {"value": "{{dose}}", "operation": "increment"},
3211-
"right": "{{deliveryLength}}",
3212-
"operator": "lte"
3210+
"left": "{{cycle}}",
3211+
"right": "{{currentRunningCycle}}",
3212+
"operator": "equals"
32133213
},
3214-
"else": 1,
3215-
"then": {"value": "{{dose}}", "operation": "increment"}
3214+
"then": {
3215+
"if": {
3216+
"left": {"value": "{{dose}}", "operation": "increment"},
3217+
"right": "{{deliveryLength}}",
3218+
"operator": "lte"
3219+
},
3220+
"then": {"value": "{{dose}}", "operation": "increment"},
3221+
"else": 1
3222+
},
3223+
"else": 1
32163224
}
32173225
},
32183226
"nextCycleId": {
32193227
"order": 5,
3220-
"fallback": "{{cycle}}",
3228+
"fallback": "{{currentRunningCycle}}",
32213229
"condition": {
32223230
"if": {
3223-
"left": {"value": "{{dose}}", "operation": "increment"},
3224-
"right": "{{deliveryLength}}",
3225-
"operator": "lte"
3231+
"left": "{{cycle}}",
3232+
"right": "{{currentRunningCycle}}",
3233+
"operator": "equals"
3234+
},
3235+
"then": {
3236+
"if": {
3237+
"left": {"value": "{{dose}}", "operation": "increment"},
3238+
"right": "{{deliveryLength}}",
3239+
"operator": "lte"
3240+
},
3241+
"then": "{{cycle}}",
3242+
"else": {"value": "{{cycle}}", "operation": "increment"}
32263243
},
3227-
"else": {"value": "{{cycle}}", "operation": "increment"},
3228-
"then": "{{cycle}}"
3244+
"else": "{{currentRunningCycle}}"
32293245
}
32303246
},
32313247
"deliveryLength": {
@@ -3261,6 +3277,19 @@ final dynamic sampleFlows = {
32613277
"select": "{{id}}",
32623278
"default": -1,
32633279
"takeFirst": true
3280+
},
3281+
"effectiveDose": {
3282+
"order": 6,
3283+
"fallback": 0,
3284+
"condition": {
3285+
"if": {
3286+
"left": "{{nextCycleId}}",
3287+
"right": "{{cycle}}",
3288+
"operator": "equals"
3289+
},
3290+
"then": "{{dose}}",
3291+
"else": 0
3292+
}
32643293
}
32653294
},
32663295
"relations": [
@@ -3368,7 +3397,7 @@ final dynamic sampleFlows = {
33683397
},
33693398
"futureDeliveries": {
33703399
"from": "{{targetCycle.0.deliveries}}",
3371-
"skip": {"from": "{{dose}}"},
3400+
"skip": {"from": "{{effectiveDose}}"},
33723401
"order": 3,
33733402
"where": {
33743403
"left": "{{item.deliveryStrategy}}",
@@ -3605,7 +3634,7 @@ final dynamic sampleFlows = {
36053634
{
36063635
"key": "deliveryStrategy",
36073636
"value": "{{navigation.deliveryStrategy}}"
3608-
},
3637+
}
36093638
],
36103639
"onError": [
36113640
{
@@ -3619,7 +3648,7 @@ final dynamic sampleFlows = {
36193648
{
36203649
"actionType": "CREATE_EVENT",
36213650
"properties": {
3622-
"entity": "HOUSEHOLD, INDIVIDUAL, PROJECTBENEFICIARY, MEMBER",
3651+
"entity": "TASK",
36233652
"onError": [
36243653
{
36253654
"actionType": "SHOW_TOAST",
@@ -3670,7 +3699,7 @@ final dynamic sampleFlows = {
36703699
}
36713700
}
36723701
],
3673-
"condition": {"expression": "doseIndex == '1'"}
3702+
"condition": {"expression": "doseIndex == 1"}
36743703
},
36753704
{
36763705
"actionType": "NAVIGATION",
@@ -3692,7 +3721,9 @@ final dynamic sampleFlows = {
36923721
"actionType": "SHOW_TOAST",
36933722
"properties": {"message": "Navigation failed."}
36943723
}
3695-
]
3724+
],
3725+
"navigationMode": "popUntilAndPush",
3726+
"popUntilPageName": "householdOverview"
36963727
}
36973728
}
36983729
],

packages/digit_flow_builder/lib/blocs/state_wrapper_builder.dart

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,22 @@ class WrapperBuilder {
166166
}
167167
}
168168

169-
170-
try{
169+
try {
171170
// 3. Computed fields
172171
final computed = _applyComputed(wrapperData, config);
173172
wrapperData.addAll(computed);
174-
} catch(e){
173+
} catch (e) {
175174
print(e.toString());
176175
}
177176

178-
try{
177+
try {
179178
// 4. Computed list fields
180179
final computedList = _applyComputedList(wrapperData, config);
181180
wrapperData.addAll(computedList);
182-
} catch(e){
181+
} catch (e) {
183182
print(e.toString());
184183
}
185184

186-
187185
wrappers.add(wrapperData);
188186
}
189187
} catch (e, st) {
@@ -273,7 +271,8 @@ class WrapperBuilder {
273271

274272
// Handle equalsFrom with template resolution
275273
if (equalsFrom != null) {
276-
final resolvedEquals = _resolveValue(equalsFrom, root, resolveContext);
274+
final resolvedEquals =
275+
_resolveValue(equalsFrom, root, resolveContext);
277276
if (resolvedEquals != null && value != resolvedEquals) return false;
278277
} else if (equals != null && value != equals) return false;
279278
} else {
@@ -625,22 +624,27 @@ class WrapperBuilder {
625624

626625
final List<dynamic> next = [];
627626
for (final item in current) {
628-
dynamic val;
629-
if (item is Map) {
630-
val = item[part];
631-
} else if (item is EntityModel)
632-
val = EnhancedEntityFieldAccessor.getFieldValue(item, part);
633-
else if (item is AdditionalField) if ((part == 'key')) {
634-
val = item.key;
635-
} else {
636-
val = (part == 'value') ? item.value : null;
637-
}
638-
if (val != null) {
639-
if (val is Iterable && val is! String) {
640-
next.addAll(val.where((e) => e != null));
627+
try {
628+
dynamic val;
629+
if (item is Map) {
630+
val = item[part];
631+
} else if (item is EntityModel)
632+
val = EnhancedEntityFieldAccessor.getFieldValue(item, part);
633+
else if (item is AdditionalField) if ((part == 'key')) {
634+
val = item.key;
641635
} else {
642-
next.add(val);
636+
val = (part == 'value') ? item.value : null;
637+
}
638+
if (val != null) {
639+
if (val is Iterable && val is! String) {
640+
next.addAll(val.where((e) => e != null));
641+
} else {
642+
next.add(val);
643+
}
643644
}
645+
} catch (_) {
646+
// Skip items where field access fails (e.g., tasks without additionalFields)
647+
continue;
644648
}
645649
}
646650
if (next.isEmpty) return null;

0 commit comments

Comments
 (0)