Skip to content

Commit

Permalink
(fix) Make extraction of the calculated value null safe (#430)
Browse files Browse the repository at this point in the history
* (fix) Make extraction value of calculateExpression null safe

* fix build
  • Loading branch information
pirupius authored Nov 25, 2024
1 parent e4d6204 commit 2abfe5f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/adapters/obs-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type AttachmentResponse,
type Attachment,
type ValueAndDisplay,
type FormFieldValueAdapter,
} from '../types';
import {
hasRendering,
Expand All @@ -17,7 +18,6 @@ import {
formatDateAsDisplayString,
} from '../utils/common-utils';
import { type FormContextProps } from '../provider/form-provider';
import { type FormFieldValueAdapter } from '../types';
import { isEmpty } from '../validators/form-validator';
import { getAttachmentByUuid } from '../api';
import { formatDate, restBaseUrl } from '@openmrs/esm-framework';
Expand Down
3 changes: 3 additions & 0 deletions src/components/renderer/field/fieldLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { hasRendering } from '../../../utils/common-utils';
import { evaluateAsyncExpression, evaluateExpression } from '../../../utils/expression-runner';
import { evalConditionalRequired, evaluateDisabled, evaluateHide } from '../../../utils/form-helper';
import { isEmpty } from '../../../validators/form-validator';
import { reportError } from '../../../utils/error-utils';

export function handleFieldLogic(field: FormField, context: FormContextProps) {
const {
Expand Down Expand Up @@ -80,6 +81,8 @@ function evaluateFieldDependents(field: FormField, values: any, context: FormCon
context.formFieldAdapters[dependent.type].transformFieldValue(dependent, result, context);
}
updateFormField(dependent);
}).catch((error) => {
reportError(error, 'Error evaluating calculate expression');
});
}
// evaluate hide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import React, { useEffect, useMemo, useState } from 'react';
import {
type FormField,
type FormFieldInputProps,
type FormFieldValidator,
type FormFieldValueAdapter,
type RenderType,
type SessionMode,
type ValidationResult,
type ValueAndDisplay,
} from '../../../types';
Expand Down
2 changes: 1 addition & 1 deletion src/processors/encounter/encounter-form-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class EncounterFormProcessor extends FormProcessor {
patient: patient,
previousEncounter: previousDomainObjectValue,
});
return extractObsValueAndDisplay(field, value);
return value ? extractObsValueAndDisplay(field, value) : null;
}
if (previousDomainObjectValue && field.questionOptions.enablePreviousValue) {
return await adapter.getPreviousValue(field, previousDomainObjectValue, context);
Expand Down

0 comments on commit 2abfe5f

Please sign in to comment.