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

Unable to retreive RepeatableQuestionGroup Observation concept value for a ProgramEncounter #42

Open himeshr opened 1 year ago

himeshr commented 1 year ago

In "Lend a hand India" org, for "LAHI Intern" Subject, "Internship LAHI" Program, "LAHI INTERN ATTENDANCE" Program Encounter is to be created.

As part of the ProgramEncounter's Decision rule, we need to fetch "Date of Attendance" concept value from within the "Attendance Day" RepeatableQuestionGroup's groupObservations.

Attempting this results in failure, as following method fails to handle the array nature of "Attendance Day" RepeatableQuestionGroup :

const dateOfAttendance = programEncounter.findObservation("Date of Attendance","Attendance Day");
**ERROR: undefined is not an object (evaluating 't.concept.name')**

In avni-models, AbstractEncounter.js:

  findObservation(conceptNameOrUuid, parentConceptNameOrUuid) {
    const observations = _.isNil(parentConceptNameOrUuid) ? this.observations : this.findGroupedObservation(parentConceptNameOrUuid);
    return _.find(observations, (observation) => {
      return (observation.concept.name === conceptNameOrUuid) || (observation.concept.uuid === conceptNameOrUuid);
    });
  }

ERROR is at "(observation.concept.name === conceptNameOrUuid)".. observation.concept is undefined.

Instead, we should fetch the value from the first entry in RepeatableQuestionGroup as follows:

const groupedObservations = programEncounter.findGroupedObservation("Attendance Day");
  const groupObservations = _.isEmpty(groupedObservations) ? [] : groupedObservations[0].groupObservations;
  const dateOfAttendance =  _.find(groupObservations, (observation) => {
    return (observation.concept.name === "Date of Attendance");
  });

Tech tasks:

himeshr commented 1 year ago

GroupedObservation Output JSON: [{ groupObservations: [{ that: { concept: { name: 'Task Assigned Status_Intern', datatype: 'Coded', uuid: '97e242a2-8f0e-4d82-b2fc-708a3c77cb65', keyValues: [], unit: null, lowAbsolute: null, lowNormal: null, hiNormal: undefined, hiAbsolute: undefined, answers: [{ uuid: 'a8cec34c-29f2-4a39-addc-3170096ed49d', answerOrder: 2, abnormal: false, unique: false, voided: false, concept: { name: 'Delayed / Pending', uuid: 'e06bb821-0bea-4923-8aa3-f6d8958d8905', datatype: 'NA', lowAbsolute: null, hiAbsolute: undefined, lowNormal: null, hiNormal: undefined, unit: null, voided: false, keyValues: [], answers: [] } }, { uuid: 'e1046ebc-12a8-4021-9161-a6af36190d37', answerOrder: 0, abnormal: false, unique: false, voided: false, concept: { name: 'Completed', uuid: '9a07ba44-2b41-44c9-8fc7-adab74ecb752', datatype: 'NA', lowAbsolute: null, hiAbsolute: undefined, lowNormal: null, hiNormal: undefined, unit: null, voided: false, keyValues: [], answers: [] } }, { uuid: '0481807e-c0c4-4db0-9695-26731651d1c1', answerOrder: 1, abnormal: false, unique: false, voided: false, concept: { name: 'Going As Planned', uuid: '93a7d4c8-a805-4203-878d-bed534c6f62c', datatype: 'NA', lowAbsolute: null, hiAbsolute: undefined, lowNormal: null, hiNormal: undefined, unit: null, voided: false, keyValues: [], answers: [] } }] }, valueJSON: {answer: '93a7d4c8-a805-4203-878d-bed534c6f62c'} } }, { that: { concept: { name: 'Date of Attendance', datatype: 'Date', uuid: 'f90c8c11-caad-4e05-abb0-a28ff8af5799', keyValues: [], unit: null, lowAbsolute: null, lowNormal: null, hiNormal: undefined, hiAbsolute: undefined, answers: [] }, valueJSON: { value: '2023-04-10T18:30:00.000Z', datatype: 'Date', answer: "Tue Apr 11 2023 00:00:00 GMT+0530 (IST)" } } }] }]