avniproject / avni-models

Avni data model to be used by front end clients
https://avniproject.org
GNU Affero General Public License v3.0
1 stars 4 forks source link

getEncounters doesn't sortBy cancelDateTime #44

Open mahalakshme opened 1 year ago

mahalakshme commented 1 year ago

Issue: getEncounters function in Individual.js and ProgramEnrolment.js has facility to consider cancelled encounters as well. But it is not considering cancelDateTime when sorting the encounters. Hence when need to get the latest(including cancelled encounters) another sorting as below need to be done in the report card query:

const encounters = enrolment.getEncounters(false);
      const sortedEncounters = _.sortBy(encounters, (encounter) => {
      return _.isNil(encounter.cancelDateTime)? moment().diff(encounter.encounterDateTime) : 
      moment().diff(encounter.cancelDateTime)}); 
      const latestEncounter = _.head(sortedEncounters);

Significance of fixing this issue: