From 314bf040b048d85608acbd82f14b67f1c7f8cb98 Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Thu, 9 Jan 2025 12:14:19 +0900 Subject: [PATCH] clarifications based on test feedback --- packages/workflow/src/records/fhir.test.ts | 108 ++++++++++----------- packages/workflow/src/records/fhir.ts | 2 +- 2 files changed, 54 insertions(+), 56 deletions(-) diff --git a/packages/workflow/src/records/fhir.test.ts b/packages/workflow/src/records/fhir.test.ts index 68b8096b80..5b6f5d40c5 100644 --- a/packages/workflow/src/records/fhir.test.ts +++ b/packages/workflow/src/records/fhir.test.ts @@ -8,7 +8,7 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import { TrackingID } from '@opencrvs/commons/types' +import { SavedTask, TrackingID } from '@opencrvs/commons/types' import { createRegisterTask } from './fhir' import { UUID } from '@opencrvs/commons' @@ -18,13 +18,18 @@ describe('https://github.com/opencrvs/opencrvs-core/issues/8278', () => { * In this case the "previous task" that the registration confirmation uses will have different values from expected. * This test ensures that the new task will not have null values if this happens. */ - test('create register task never produces an extension array with null values even when there is no timeLoggedMS extension in the previous task', () => { - const previousTask = createRegisterTask({ + test('create register task produces an extension array with a pre-existing timeLoggedMS extension from the previous task if such extension exists', () => { + const previousTask: SavedTask = { resourceType: 'Task', status: 'ready', intent: 'proposal', code: { - coding: [{ system: 'http://opencrvs.org/specs/types', code: 'BIRTH' }] + coding: [ + { + system: 'http://opencrvs.org/specs/types', + code: 'BIRTH' + } + ] }, focus: { reference: @@ -33,13 +38,14 @@ describe('https://github.com/opencrvs/opencrvs-core/issues/8278', () => { id: '11af7c9c-8d57-4e83-9c83-93e28725da41' as UUID, requester: { agent: { - reference: 'Practitioner/c3647cf0-4abc-4fa1-896c-91fa7be2ac05' + reference: + 'Practitioner/c3647cf0-4abc-4fa1-896c-91fa7be2ac05' as `Practitioner/${UUID}` } }, identifier: [ { system: 'http://opencrvs.org/specs/id/draft-id', - value: 'b21428dd-6fd8-41bc-aae5-651db50596d2' + value: 'b21428dd-6fd8-41bc-aae5-651db50596d2' as TrackingID }, { system: 'http://opencrvs.org/specs/id/birth-tracking-id', @@ -49,13 +55,17 @@ describe('https://github.com/opencrvs/opencrvs-core/issues/8278', () => { extension: [ { url: 'http://opencrvs.org/specs/extension/informants-signature', - valueString: '/ocrvs/00376d63-2b3f-4e26-890a-e70fad1403f3.png' + valueString: + '/ocrvs/00376d63-2b3f-4e26-890a-e70fad1403f3.png' as `ocrvs/${UUID}.png` }, { url: 'http://opencrvs.org/specs/extension/contact-person-email', valueString: 'informant@example.com' }, - { url: 'http://opencrvs.org/specs/extension/regViewed' }, + { + url: 'http://opencrvs.org/specs/extension/timeLoggedMS', + valueInteger: 0 + }, { url: 'http://opencrvs.org/specs/extension/regLastUser', valueReference: { @@ -71,7 +81,7 @@ describe('https://github.com/opencrvs/opencrvs-core/issues/8278', () => { } } ], - lastModified: '2025-01-08T01:58:16.334Z', + lastModified: '2025-01-08T01:57:45.455Z', businessStatus: { coding: [ { @@ -81,56 +91,44 @@ describe('https://github.com/opencrvs/opencrvs-core/issues/8278', () => { ] }, meta: { - lastUpdated: '2025-01-08T01:57:56.335+00:00', - versionId: '74e0b495-0e83-402e-b968-463f3db2e25b' as UUID + lastUpdated: '2025-01-08T01:57:45.492+00:00', + versionId: '9d39e624-9af6-455a-bdce-8d8e75b8d7d9' } - }) - expect(previousTask).toStrictEqual({ - resourceType: 'Task', - status: 'ready', - intent: 'proposal', - code: { - coding: [{ system: 'http://opencrvs.org/specs/types', code: 'BIRTH' }] + } + expect(createRegisterTask(previousTask).extension).toStrictEqual([ + { + url: 'http://opencrvs.org/specs/extension/informants-signature', + valueString: '/ocrvs/00376d63-2b3f-4e26-890a-e70fad1403f3.png' }, - focus: { reference: 'Composition/1a738c6a-2dfe-4fad-96c8-597834692b07' }, - id: '11af7c9c-8d57-4e83-9c83-93e28725da41', - requester: { - agent: { - reference: 'Practitioner/c3647cf0-4abc-4fa1-896c-91fa7be2ac05' - } + { + url: 'http://opencrvs.org/specs/extension/contact-person-email', + valueString: 'informant@example.com' }, - identifier: [ - { - system: 'http://opencrvs.org/specs/id/draft-id', - value: 'b21428dd-6fd8-41bc-aae5-651db50596d2' - }, - { - system: 'http://opencrvs.org/specs/id/birth-tracking-id', - value: 'BJ5AGDQ' - } - // undefined – this appeared here previously - ], - extension: [ - { - url: 'http://opencrvs.org/specs/extension/informants-signature', - valueString: '/ocrvs/00376d63-2b3f-4e26-890a-e70fad1403f3.png' - }, - { - url: 'http://opencrvs.org/specs/extension/contact-person-email', - valueString: 'informant@example.com' - } - ], - lastModified: expect.any(String), - note: undefined, - businessStatus: { - coding: [ - { system: 'http://opencrvs.org/specs/reg-status', code: 'REGISTERED' } - ] + { + url: 'http://opencrvs.org/specs/extension/timeLoggedMS', + valueInteger: 0 + } + ]) + + const previousTaskWithNoTimeLoggedMS = { + ...previousTask, + extension: previousTask.extension.filter( + (extension) => + extension.url !== 'http://opencrvs.org/specs/extension/timeLoggedMS' + ) + } + expect( + createRegisterTask(previousTaskWithNoTimeLoggedMS).extension + ).toStrictEqual([ + { + url: 'http://opencrvs.org/specs/extension/informants-signature', + valueString: '/ocrvs/00376d63-2b3f-4e26-890a-e70fad1403f3.png' }, - meta: { - lastUpdated: expect.any(String), - versionId: '74e0b495-0e83-402e-b968-463f3db2e25b' + { + url: 'http://opencrvs.org/specs/extension/contact-person-email', + valueString: 'informant@example.com' } - }) + // undefined – this appeared here previously + ]) }) }) diff --git a/packages/workflow/src/records/fhir.ts b/packages/workflow/src/records/fhir.ts index 1e2109f95d..662d1d9092 100644 --- a/packages/workflow/src/records/fhir.ts +++ b/packages/workflow/src/records/fhir.ts @@ -766,7 +766,7 @@ export function createWaitingForValidationTask( export function createRegisterTask(previousTask: SavedTask): Task { const timeLoggedMSExtension = previousTask.extension.find( (e) => e.url === 'http://opencrvs.org/specs/extension/timeLoggedMS' - )! + ) const registeredTask = createNewTaskResource( previousTask,