From 8500717a6ade2b6c1afe376a173136f2d3d24416 Mon Sep 17 00:00:00 2001 From: Samuel Male Date: Sat, 25 May 2024 14:35:23 +0300 Subject: [PATCH] Miscellaneous fixes (#291) --- .../patientIdentifierHandler.ts | 4 ++-- .../programStateHandler.ts | 9 ++++++--- .../angular-fe-schema-transformer.ts | 19 +++++++++---------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/submission-handlers/patientIdentifierHandler.ts b/src/submission-handlers/patientIdentifierHandler.ts index 645a5b1f0..43c70a02c 100644 --- a/src/submission-handlers/patientIdentifierHandler.ts +++ b/src/submission-handlers/patientIdentifierHandler.ts @@ -12,7 +12,7 @@ export const PatientIdentifierHandler: SubmissionHandler = { field.meta.submission.newValue = { identifier: value, identifierType: field.questionOptions.identifierType, - uuid: field.meta.previousValue.id, + uuid: field.meta.previousValue?.id, location: context.location, }; return value; @@ -23,7 +23,7 @@ export const PatientIdentifierHandler: SubmissionHandler = { allFormFields: Array, context: EncounterContext, ) => { - const latestIdentifier = context.patient.identifier.find( + const latestIdentifier = context.patient?.identifier?.find( (identifier) => identifier.type?.coding[0]?.code === field.questionOptions.identifierType, ); field.meta = { ...(field.meta || {}), previousValue: latestIdentifier }; diff --git a/src/submission-handlers/programStateHandler.ts b/src/submission-handlers/programStateHandler.ts index f4c79749b..d464ccba2 100644 --- a/src/submission-handlers/programStateHandler.ts +++ b/src/submission-handlers/programStateHandler.ts @@ -6,7 +6,7 @@ import dayjs from 'dayjs'; export const ProgramStateHandler: SubmissionHandler = { handleFieldSubmission: (field: FormField, value: any, context: EncounterContext) => { clearSubmission(field); - if (field.meta?.previousValue?.value === value || isEmpty(value)) { + if (field.meta?.previousValue?.uuid === value || isEmpty(value)) { return null; } field.meta.submission.newValue = { @@ -23,10 +23,13 @@ export const ProgramStateHandler: SubmissionHandler = { const program = context.patientPrograms.find( (program) => program.program.uuid === field.questionOptions.programUuid, ); + if (program?.states?.length > 0) { - return program.states + const currentState = program.states .filter((state) => !state.endDate) - .find((state) => state.state.programWorkflow?.uuid === field.questionOptions.workflowUuid)?.state?.uuid; + .find((state) => state.state.programWorkflow?.uuid === field.questionOptions.workflowUuid)?.state; + field.meta = { ...(field.meta || {}), previousValue: currentState }; + return currentState.uuid; } return null; }, diff --git a/src/transformers/angular-fe-schema-transformer.ts b/src/transformers/angular-fe-schema-transformer.ts index 62b32608f..4bd9942a9 100644 --- a/src/transformers/angular-fe-schema-transformer.ts +++ b/src/transformers/angular-fe-schema-transformer.ts @@ -1,5 +1,6 @@ import { type FormField, type FormSchemaTransformer, type FormSchema } from '../types'; import { isTrue } from '../utils/boolean-utils'; +import { hasRendering } from '../utils/common-utils'; export const AngularFormEngineSchemaTransformer: FormSchemaTransformer = { transform: (form: FormSchema) => { @@ -78,6 +79,9 @@ function transformByType(question: FormField) { case 'encounterRole': question.questionOptions.rendering = 'encounter-role'; break; + case 'encounterDatetime': + question.questionOptions.rendering = 'date'; + break; } } @@ -101,18 +105,13 @@ function transformByRendering(question: FormField) { } function handleLabOrders(question: FormField) { - if (question.questionOptions.rendering === 'repeating' && question.type === 'testOrder') { - updateQuestionAnswers(question); + if (hasRendering(question, 'group') && question.questions?.length) { + question.questions.forEach(handleLabOrders); } - if (question.questionOptions.rendering === 'group') { - question?.questions?.filter((orderQuestion) => orderQuestion.type === 'testOrder').forEach(updateQuestionAnswers); + if (question.type === 'testOrder' && question.questionOptions.selectableOrders?.length) { + question.questionOptions.answers = question.questionOptions.selectableOrders || []; + delete question.questionOptions.selectableOrders; } - return question; -} - -function updateQuestionAnswers(question: FormField) { - question.questionOptions.answers = question.questionOptions.selectableOrders || []; - delete question.questionOptions.selectableOrders; } function handleSelectConceptAnswers(question: FormField) {