Skip to content

Commit

Permalink
avniproject/avni-models#43 | Support multi/single select observations…
Browse files Browse the repository at this point in the history
… in QG/RQG in server rules execution
  • Loading branch information
mahalakshme committed Aug 18, 2023
1 parent 34b2965 commit 3400d27
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,36 @@ public List<ObservationModelContract> constructObservationModelContracts(Observa
public ObservationModelContract constructObservation(ObservationContract observationContract) {
Concept concept = conceptRepository.findByUuid(observationContract.getConcept().getUuid());
ObservationModelContract observationModelContract = new ObservationModelContract();
observationModelContract.setValue(observationContract.getValue());
Object value = observationContract.getValue();
if (value instanceof ArrayList) {
if (((ArrayList<?>) value).get(0) instanceof ArrayList)
value = constructRepeatableQuestionGroupValue((List<List<ObservationContract>>) value);
else
value = constructQuestionGroupValue((List<ObservationContract>) value);
}

observationModelContract.setValue(value);
ConceptModelContract conceptModelContract = ConceptModelContract.fromConcept(concept);
observationModelContract.setConcept(conceptModelContract);
return observationModelContract;
}

private List<List<ObservationModelContract>> constructRepeatableQuestionGroupValue(List<List<ObservationContract>> repeatableQuestionGroupObservationContract) {
List<List<ObservationModelContract>> observationModelContracts = new ArrayList<>();
for (List<ObservationContract> questionGroupObservationContract : repeatableQuestionGroupObservationContract) {
observationModelContracts.add(constructQuestionGroupValue(questionGroupObservationContract));
}

return observationModelContracts;
}

private List<ObservationModelContract> constructQuestionGroupValue(List<ObservationContract> questionGroupEntries) {
return questionGroupEntries
.stream()
.map(this::constructObservation)
.collect(Collectors.toList());
}

public List<ObservationContract> constructObservations(@NotNull ObservationCollection observationCollection) {
return observationCollection.entrySet().stream().map(this::getObservationContract).collect(Collectors.toList());
}
Expand Down

0 comments on commit 3400d27

Please sign in to comment.