Skip to content

Commit

Permalink
Miscellaneous fixes (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmale authored May 25, 2024
1 parent 89a3964 commit 8500717
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/submission-handlers/patientIdentifierHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +23,7 @@ export const PatientIdentifierHandler: SubmissionHandler = {
allFormFields: Array<FormField>,
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 };
Expand Down
9 changes: 6 additions & 3 deletions src/submission-handlers/programStateHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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;
},
Expand Down
19 changes: 9 additions & 10 deletions src/transformers/angular-fe-schema-transformer.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -78,6 +79,9 @@ function transformByType(question: FormField) {
case 'encounterRole':
question.questionOptions.rendering = 'encounter-role';
break;
case 'encounterDatetime':
question.questionOptions.rendering = 'date';
break;
}
}

Expand All @@ -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) {
Expand Down

0 comments on commit 8500717

Please sign in to comment.