From da28081a53a843370ea81b58eaaeb6c8e688d2a4 Mon Sep 17 00:00:00 2001 From: vedfordev Date: Wed, 10 Apr 2024 21:43:08 +0530 Subject: [PATCH] #51 | added location properties method same as observation --- src/AddressLevel.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/AddressLevel.js b/src/AddressLevel.js index c618d13..9ea71d5 100644 --- a/src/AddressLevel.js +++ b/src/AddressLevel.js @@ -237,6 +237,27 @@ class AddressLevel extends BaseEntity { getLineage() { return appendLineage(this, []); } + + findObservation(conceptNameOrUuid, parentConceptNameOrUuid) { + const observations = _.isNil(parentConceptNameOrUuid) ? this.locationProperties : this.findGroupedObservation(parentConceptNameOrUuid); + return _.find(observations, (observation) => { + return (observation.concept.name === conceptNameOrUuid) || (observation.concept.uuid === conceptNameOrUuid); + }); + } + + findGroupedObservation(parentConceptNameOrUuid) { + const groupedObservations = _.find(this.locationProperties, (observation) => + (observation.concept.name === parentConceptNameOrUuid) || (observation.concept.uuid === parentConceptNameOrUuid)); + return _.isEmpty(groupedObservations) ? [] : groupedObservations.getValue(); + } + + getObservationReadableValue(conceptNameOrUuid, parentConceptNameOrUuid) { + const observationForConcept = this.findObservation(conceptNameOrUuid, parentConceptNameOrUuid); + return _.isEmpty(observationForConcept) + ? observationForConcept + : observationForConcept.getReadableValue(); + } + } export default AddressLevel;