From 0f781a73348a4a471e7c6620f9f11e728e66e9e2 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Wed, 29 May 2024 15:31:17 +0530 Subject: [PATCH] #1414 - check if encounter type exists before checking for privilege --- .../src/state/AbstractDataEntryState.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/openchs-android/src/state/AbstractDataEntryState.js b/packages/openchs-android/src/state/AbstractDataEntryState.js index 3d3b54a7d..eabcb8db9 100644 --- a/packages/openchs-android/src/state/AbstractDataEntryState.js +++ b/packages/openchs-android/src/state/AbstractDataEntryState.js @@ -276,7 +276,13 @@ class AbstractDataEntryState { _hasPerformVisitPrivilegeOnScheduledVisit(worklistItemParameters, context) { const {encounterType, programName, programEnrolmentUUID} = worklistItemParameters; - const encounterTypeUuid = context.get(EntityService).findByKey('name', encounterType, EncounterType.schema.name).uuid; + const encounterTypeUuid = _.get(context.get(EntityService).findByKey('name', encounterType, EncounterType.schema.name), "uuid"); + + if (_.isNil(encounterTypeUuid)) { + General.logWarn("AbstractDataEntryState", `EncounterType with name ${encounterType} not found.`) + return false; + } + let performVisitCriteria; if (programEnrolmentUUID) { const programEnrolment = context.get(EntityService).findByUUID(programEnrolmentUUID, ProgramEnrolment.schema.name); @@ -391,9 +397,9 @@ class AbstractDataEntryState { isAlreadyScheduled(entity, newlyScheduledEncounter) { //paranoid code if (_.isNil(entity) - || _.isEmpty(entity.getSchemaName()) - || (entity.getSchemaName() !== Individual.schema.name && entity.getSchemaName() !== ProgramEnrolment.schema.name) - || _.isNil(entity.everScheduledEncountersOfType)) return false; + || _.isEmpty(entity.getSchemaName()) + || (entity.getSchemaName() !== Individual.schema.name && entity.getSchemaName() !== ProgramEnrolment.schema.name) + || _.isNil(entity.everScheduledEncountersOfType)) return false; return _.some(entity.everScheduledEncountersOfType(newlyScheduledEncounter.encounterType), (alreadyScheduledEncounter) => { return General.datesAreSame(newlyScheduledEncounter.earliestDate, alreadyScheduledEncounter.earliestVisitDateTime) && General.datesAreSame(newlyScheduledEncounter.maxDate, alreadyScheduledEncounter.maxVisitDateTime) && newlyScheduledEncounter.name === alreadyScheduledEncounter.name;