Skip to content

Commit

Permalink
#1414 - check if encounter type exists before checking for privilege
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed May 29, 2024
1 parent 7d17a19 commit 0f781a7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/openchs-android/src/state/AbstractDataEntryState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0f781a7

Please sign in to comment.