diff --git a/avni-server-api/src/main/java/org/avni/server/builder/ChecklistDetailBuilder.java b/avni-server-api/src/main/java/org/avni/server/builder/ChecklistDetailBuilder.java index 1e90d6a9d..09d6b38a8 100644 --- a/avni-server-api/src/main/java/org/avni/server/builder/ChecklistDetailBuilder.java +++ b/avni-server-api/src/main/java/org/avni/server/builder/ChecklistDetailBuilder.java @@ -49,7 +49,6 @@ public ChecklistDetailBuilder withItems(List items) .withVoided(item.isVoided()) .withform(form) .withConcept(concept) - .withLeadItem(builtItems.get(item.getDependentOn())) .withScheduleOnExpiryOfDependency(item.getScheduleOnExpiryOfDependency()) .withMinDaysFromStartDate(item.getMinDaysFromStartDate()) .withMinDaysFromDependent(item.getMinDaysFromDependent()) @@ -57,6 +56,8 @@ public ChecklistDetailBuilder withItems(List items) .build(); builtItems.put(builtItemDetail.getUuid(), builtItemDetail); }); + //set dependentOn after all items in request have been processed so order of items in request does not matter for dependents + items.forEach(item -> getExistingChecklistItemDetail(this.get(), item).setLeadChecklistItemDetail(builtItems.get(item.getDependentOn()))); return this; }