From 3d28b27f56b5be930244bbf4b583aa3362f0c704 Mon Sep 17 00:00:00 2001 From: Joy A Date: Mon, 25 Nov 2024 15:29:04 +0530 Subject: [PATCH] #1378 | Fix DEA general tab breaking due to voided eligible encounter type --- src/common/mapper/EncounterMapper.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/common/mapper/EncounterMapper.js b/src/common/mapper/EncounterMapper.js index 78ceeb13d..80ef49c8f 100644 --- a/src/common/mapper/EncounterMapper.js +++ b/src/common/mapper/EncounterMapper.js @@ -1,19 +1,20 @@ -import { get } from "lodash"; +import { get, isNil } from "lodash"; import { Encounter } from "avni-models"; import { mapBasicEncounter } from "./BaseEncounterMapper"; export const getNewEligibleEncounters = (encounterTypes, eligibleEncounters) => { - const scheduledEncounters = get(eligibleEncounters, "scheduledEncounters", []).map(pe => - mapBasicEncounter(new Encounter(), pe) - ); - const unplannedEncounters = get(eligibleEncounters, "eligibleEncounterTypeUUIDs", []).map( - uuid => { - const encounter = new Encounter(); - encounter.encounterType = encounterTypes.find(eT => eT.uuid === uuid); - encounter.name = - encounter.encounterType && encounter.encounterType.operationalEncounterTypeName; - return encounter; - } - ); + const scheduledEncounters = get(eligibleEncounters, "scheduledEncounters", []).map(pe => mapBasicEncounter(new Encounter(), pe)); + const unplannedEncounters = get(eligibleEncounters, "eligibleEncounterTypeUUIDs", []) + .map(uuid => { + const result = encounterTypes.find(eT => eT.uuid === uuid); + if (!isNil(result)) { + const encounter = new Encounter(); + encounter.encounterType = result; + encounter.name = encounter.encounterType.operationalEncounterTypeName; + return encounter; + } + return null; + }) + .filter(enc => !isNil(enc)); return { scheduledEncounters, unplannedEncounters }; };