Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) O3-3274: Fix failing expressions #292

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/form-engine.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ const FormEngine: React.FC<FormProps> = ({
if (sessionMode === 'embedded-view') {
return false;
}

return workspaceLayout === 'minimized' || (workspaceLayout === 'maximized' && scrollablePages.size <= 1);
}, [sessionMode, workspaceLayout, scrollablePages]);

Expand Down
32 changes: 29 additions & 3 deletions src/utils/expression-runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getRegisteredExpressionHelpers } from '../registry/registry';
import { isEmpty } from 'lodash-es';
import { type OpenmrsEncounter, type FormField, type FormPage, type FormSection } from '../types';
import { CommonExpressionHelpers } from './common-expression-helpers';
import { findAndRegisterReferencedFields, linkReferencedFieldValues, parseExpression } from './expression-parser';
Expand Down Expand Up @@ -46,13 +47,18 @@ export function evaluateExpression(
const HD = new HistoricalDataSourceService();

HD.putObject('prevEnc', {
value: context.previousEncounter,
value: context.previousEncounter || { obs: [] },
getValue(concept) {
return this.value.obs.find((obs) => obs.concept.uuid == concept);
},
});

const visitTypeUuid = context.visit?.visitType.uuid ?? '';
const visitType = context.visit?.visitType || { uuid: '' };
const visitTypeUuid = visitType.uuid ?? '';

const _ = {
isEmpty,
};

const expressionContext = {
...new CommonExpressionHelpers(node, patient, fields, fieldValues, allFieldsKeys),
Expand All @@ -64,7 +70,9 @@ export function evaluateExpression(
sex,
age,
HD,
visitType,
visitTypeUuid,
_,
};

expression = linkReferencedFieldValues(fields, fieldValues, parts);
Expand All @@ -91,7 +99,9 @@ export async function evaluateAsyncExpression(
const allFieldsKeys = fields.map((f) => f.id);
let parts = parseExpression(expression.trim());

const visitTypeUuid = context.visit?.visitType.uuid ?? '';
const visitType = context.visit?.visitType || { uuid: '' };
const visitTypeUuid = visitType.uuid ?? '';

// register dependencies
findAndRegisterReferencedFields(node, parts, fields);

Expand All @@ -102,6 +112,19 @@ export async function evaluateAsyncExpression(
myValue = fieldValues[node.value['id']];
}

const HD = new HistoricalDataSourceService();

HD.putObject('prevEnc', {
value: context.previousEncounter || { obs: [] },
getValue(concept) {
return this.value.obs.find((obs) => obs.concept.uuid == concept);
},
});

const _ = {
isEmpty,
};

const expressionContext = {
...new CommonExpressionHelpers(node, patient, fields, fieldValues, allFieldsKeys),
...getRegisteredExpressionHelpers(),
Expand All @@ -112,7 +135,10 @@ export async function evaluateAsyncExpression(
sex,
age,
temporaryObjectsMap: {},
HD,
visitType,
visitTypeUuid,
_,
};

expression = linkReferencedFieldValues(fields, fieldValues, parts);
Expand Down
Loading