diff --git a/src/adapters/encounter-diagnoses-adapter.ts b/src/adapters/encounter-diagnoses-adapter.ts index 59b2d780..23d44958 100644 --- a/src/adapters/encounter-diagnoses-adapter.ts +++ b/src/adapters/encounter-diagnoses-adapter.ts @@ -59,8 +59,8 @@ const constructNewDiagnosis = (value: any, field: FormField, patientUuid: string diagnosis: { coded: value, }, - certainty: 'CONFIRMED', - rank: field.questionOptions.rank, // rank 1 denotes a diagnosis is primary, else secondary + certainty: 'PROVISIONAL', + rank: field.questionOptions.diagnosis.rank, // rank 1 denotes a diagnosis is primary, else secondary formFieldPath: `rfe-forms-${field.id}`, formFieldNamespace: 'rfe-forms', }; diff --git a/src/adapters/encounter-diagnoses.test.ts b/src/adapters/encounter-diagnoses.test.ts index 97e91eeb..0f753f9a 100644 --- a/src/adapters/encounter-diagnoses.test.ts +++ b/src/adapters/encounter-diagnoses.test.ts @@ -47,7 +47,9 @@ const field = { type: 'diagnosis', questionOptions: { rendering: 'repeating', - rank: 1, + diagnosis: { + rank: 1, + }, datasource: { name: 'problem_datasource', config: { @@ -92,7 +94,7 @@ const diagnoses = [ encounter: { uuid: '9a4b06bd-d655-414f-b9ce-69e940c337ce', }, - certainty: 'CONFIRMED', + certainty: 'PROVISIONAL', rank: 1, voided: false, display: 'Schistosoma Mansonii Infection', @@ -118,7 +120,7 @@ const diagnoses = [ encounter: { uuid: '9a4b06bd-d655-414f-b9ce-69e940c337ce', }, - certainty: 'CONFIRMED', + certainty: 'PROVISIONAL', rank: 1, voided: false, display: 'Infection due to Entamoeba Histolytica', @@ -143,7 +145,7 @@ describe('EncounterDiagnosesAdapter', () => { diagnosis: { coded: '127133AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', }, - certainty: 'CONFIRMED', + certainty: 'PROVISIONAL', rank: 1, formFieldPath: 'rfe-forms-DiagNosIS', formFieldNamespace: 'rfe-forms', @@ -171,7 +173,7 @@ describe('EncounterDiagnosesAdapter', () => { const value = '128138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; field.meta.previousValue = { uuid: '0e20bb67-5d7f-41e0-96a1-751efc21a96f', - certainty: 'CONFIRMED', + certainty: 'PROVISIONAL', condition: null, formFieldPath: 'rfe-forms-DiagNosIS_1', formFieldNamespace: 'rfe-forms', @@ -192,7 +194,7 @@ describe('EncounterDiagnosesAdapter', () => { diagnosis: { coded: '128138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', }, - certainty: 'CONFIRMED', + certainty: 'PROVISIONAL', rank: 1, formFieldPath: 'rfe-forms-DiagNosIS', formFieldNamespace: 'rfe-forms', diff --git a/src/processors/encounter/encounter-processor-helper.ts b/src/processors/encounter/encounter-processor-helper.ts index e0138de1..9ee160b0 100644 --- a/src/processors/encounter/encounter-processor-helper.ts +++ b/src/processors/encounter/encounter-processor-helper.ts @@ -306,7 +306,10 @@ export async function hydrateRepeatField( } const unMappedDiagnoses = encounter.diagnoses.filter((diagnosis) => { - return !assignedDiagnosesIds.includes(diagnosis?.diagnosis?.coded.uuid); + return ( + !assignedDiagnosesIds.includes(diagnosis?.diagnosis?.coded.uuid) && + diagnosis.formFieldPath.startsWith(`rfe-forms-${field.id}_`) + ); }); const sortedDiagnoses = unMappedDiagnoses @@ -360,5 +363,6 @@ export async function hydrateRepeatField( function prepareDiagnosis(fields: FormField[]) { return fields .filter((field) => field.type === 'diagnosis' && hasSubmission(field)) - .map((field) => field.meta.submission.newValue); + .flatMap((field) => [field.meta.submission.newValue, field.meta.submission.voidedValue]) + .filter((d) => d); } diff --git a/src/transformers/default-schema-transformer.ts b/src/transformers/default-schema-transformer.ts index f12ff6d2..68544db4 100644 --- a/src/transformers/default-schema-transformer.ts +++ b/src/transformers/default-schema-transformer.ts @@ -268,11 +268,7 @@ function handleDiagnosis(question: FormField) { question.questionOptions.datasource = { name: 'problem_datasource', config: { - class: [ - '8d4918b0-c2cc-11de-8d13-0010c6dffd0f', - '8d492954-c2cc-11de-8d13-0010c6dffd0f', - '8d492b2a-c2cc-11de-8d13-0010c6dffd0f', - ], + class: '8d4918b0-c2cc-11de-8d13-0010c6dffd0f', }, }; delete question.questionOptions['dataSource']; diff --git a/src/types/schema.ts b/src/types/schema.ts index 983a4a78..e86793ec 100644 --- a/src/types/schema.ts +++ b/src/types/schema.ts @@ -182,7 +182,10 @@ export interface FormQuestionOptions { comment?: string; orientation?: 'vertical' | 'horizontal'; shownCommentOptions?: { validators?: Array>; hide?: { hideWhenExpression: string } }; - rank?: number; + diagnosis?: { + rank?: number; + isConfirmed?: boolean; + }; } export interface QuestionAnswerOption {