Skip to content

Commit

Permalink
avniproject/avni-webapp#759 | Introduce methods to order Observations…
Browse files Browse the repository at this point in the history
… per FEG
  • Loading branch information
himeshr committed Mar 21, 2024
1 parent 74c2a21 commit e502dae
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/application/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,33 @@ class Form extends BaseEntity {
return orderedObservations.concat(extraObs);
}

//TODO add tests
orderObservationsPerFEG(observations) {
const orderedObservations = [];
const formElementOrdering = _.sortBy(this.formElementGroups, (feg) => feg.displayOrder)
.map(feg => {
let fegOrderedObservations = [];
const returnValue = {};
returnValue.uuid = feg.uuid;
returnValue.feg = feg;
returnValue.sortedObservationsArray = fegOrderedObservations;
this.orderObservationsWithinAFEG(feg.getFormElements(), observations, fegOrderedObservations);
orderedObservations.concat(fegOrderedObservations);
return returnValue;
});
return formElementOrdering;
}

orderObservationsWithinAFEG(formElements, observations, orderedObservations) {
_.sortBy(formElements, (fe) => fe.displayOrder)
.forEach(formElement => this.addSortedObservations(formElement, observations, orderedObservations));
const extraObs = observations.filter((obs) =>
_.isNil(orderedObservations.find((oobs) => oobs.concept.uuid === obs.concept.uuid))
);
orderedObservations.concat(extraObs);
return extraObs;
}

sectionWiseOrderedObservations(observations) {
const sections = [];
const allObservations = [];
Expand Down

0 comments on commit e502dae

Please sign in to comment.