diff --git a/src/__mocks__/patientLabDetails.mock.ts b/src/__mocks__/patientLabDetails.mock.ts index 1e069be..549ad2c 100644 --- a/src/__mocks__/patientLabDetails.mock.ts +++ b/src/__mocks__/patientLabDetails.mock.ts @@ -17,7 +17,13 @@ export const mockPendingLabOrder = { testName: 'Dummy Test', date: 'May 03, 2022', orderedBy: 'Superman', - } + }, + { + id: 'abf-123', + testName: 'Haemoglobin', + date: 'May 03, 2022', + orderedBy: 'Superman', + }, ], goTo: jest.fn(), currentPage: 1, diff --git a/src/__mocks__/pendingLabOrders.mock.ts b/src/__mocks__/pendingLabOrders.mock.ts index a7a147c..64d5b82 100644 --- a/src/__mocks__/pendingLabOrders.mock.ts +++ b/src/__mocks__/pendingLabOrders.mock.ts @@ -34,7 +34,18 @@ export const mockPendingLabOrdersResponse: LabOrdersFetchResponse = { provider: 'Super Man', providerUuid: '2', fulfillerStatus: null, - } + }, + { + concept: { + name: 'Haemoglobin', + uuid: '21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + }, + orderDate: 1657188834000, + orderUuid: 'abf-123', + provider: 'Super Man', + providerUuid: '2', + fulfillerStatus: null, + }, ], } diff --git a/src/__mocks__/selectTests.mock.ts b/src/__mocks__/selectTests.mock.ts index d47a3b6..e66fd81 100644 --- a/src/__mocks__/selectTests.mock.ts +++ b/src/__mocks__/selectTests.mock.ts @@ -86,7 +86,7 @@ export const mockLabTestsResponse: LabTestResult = { setMembers: [], }, { - uuid: 'fe769568-16da-4d9e-9c99-fbed0a8a60f5', + uuid: '21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', name: { display: 'Haemoglobin', uuid: 'b8b8c317-43d2-4c4b-a67d-2ef3782c53eb', @@ -170,7 +170,7 @@ export const mockLabTestsResponse: LabTestResult = { setMembers: [], }, { - uuid: 'fe769568-16da-4d9e-9c99-fbed0a8a60f5', + uuid: '21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', name: { display: 'Haemoglobin', uuid: 'b8b8c317-43d2-4c4b-a67d-2ef3782c53eb', @@ -373,7 +373,7 @@ export const mockAlltestAndPanels = [ setMembers: [], }, { - uuid: 'fe769568-16da-4d9e-9c99-fbed0a8a60f5', + uuid: '21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', name: { display: 'Haemoglobin', uuid: 'b8b8c317-43d2-4c4b-a67d-2ef3782c53eb', @@ -456,7 +456,7 @@ export const mockAlltestAndPanels = [ setMembers: [], }, { - uuid: 'fe769568-16da-4d9e-9c99-fbed0a8a60f5', + uuid: '21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', name: { display: 'Haemoglobin', uuid: 'b8b8c317-43d2-4c4b-a67d-2ef3782c53eb', @@ -555,8 +555,10 @@ export const selfDiagnosticRequestBody = reportDate => export const diagnosticReportRequestBodyWithBasedOn = reportDate => `{"resourceType":"DiagnosticReport","status":"final","code":{"coding":[{"code":"07a128f7-f596-45d5-a2a9-c447bc9e5112","display":"Absolute Eosinphil Count"}]},"subject":{"reference":"Patient/123"},"issued":"${reportDate}","presentedForm":[{"url":"100/76-Patient Document-7baff463-fdaa-43d0-a402-aa948c296958.pdf","title":"test.pdf"}],"basedOn":[{"identifier":{"value":"abc-123"},"reference":"ServiceRequest","display":"Absolute Eosinphil Count"}],"performer":[{"reference":"Practitioner/1"}]}` export const testResultsdiagnosticReportRequestBody = reportDate => - `{"resourceType":"DiagnosticReport","status":"final","code":{"coding":[{"code":"07a128f7-f596-45d5-a2a9-c447bc9e5112"}]},"subject":{"reference":"Patient/123"},"issued":"${reportDate}","contained":[{"resourceType":"Observation","id":"lab-test-result","status":"final","code":{"coding":[{"code":"07a128f7-f596-45d5-a2a9-c447bc9e5112"}]},"subject":{"reference":"Patient/123"},"valueBoolean":false}],"result":[{"reference":"#lab-test-result","type":"Observation"}],"conclusion":"Normal Report","basedOn":[{"identifier":{"value":"abc-123"},"reference":"ServiceRequest"}],"performer":[{"reference":"Practitioner/1"}]}` + `{"resourceType":"DiagnosticReport","status":"final","code":{"coding":[{"code":"07a128f7-f596-45d5-a2a9-c447bc9e5112"}]},"subject":{"reference":"Patient/123"},"issued":"${reportDate}","contained":[{"resourceType":"Observation","id":"lab-test-result1","status":"final","code":{"coding":[{"code":"07a128f7-f596-45d5-a2a9-c447bc9e5112","display":"Absolute Eosinphil Count"}]},"subject":{"reference":"Patient/123"},"valueBoolean":false}],"result":[{"reference":"#lab-test-result1","type":"Observation"}],"conclusion":"Normal Report","basedOn":[{"identifier":{"value":"abc-123"},"reference":"ServiceRequest"}],"performer":[{"reference":"Practitioner/1"}]}` export const testResultsdiagnosticNumericReportRequestBody = reportDate => - `{"resourceType":"DiagnosticReport","status":"final","code":{"coding":[{"code":"1643AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}]},"subject":{"reference":"Patient/123"},"issued":"${reportDate}","contained":[{"resourceType":"Observation","id":"lab-test-result","status":"final","code":{"coding":[{"code":"1643AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}]},"subject":{"reference":"Patient/123"},"valueQuantity":{"value":"7"}}],"result":[{"reference":"#lab-test-result","type":"Observation"}],"conclusion":"Normal Report","basedOn":[{"identifier":{"value":"abe-123"},"reference":"ServiceRequest"}],"performer":[{"reference":"Practitioner/2"}]}` + `{"resourceType":"DiagnosticReport","status":"final","code":{"coding":[{"code":"21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}]},"subject":{"reference":"Patient/123"},"issued":"${reportDate}","contained":[{"resourceType":"Observation","id":"lab-test-result1","status":"final","code":{"coding":[{"code":"21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","display":"Haemoglobin"}]},"subject":{"reference":"Patient/123"},"valueQuantity":{"value":"11"}}],"result":[{"reference":"#lab-test-result1","type":"Observation"}],"conclusion":"Normal Report","basedOn":[{"identifier":{"value":"abf-123"},"reference":"ServiceRequest"}],"performer":[{"reference":"Practitioner/2"}]}` export const testResultsdiagnosticInterpretationReportRequestBody = reportDate => - `{"resourceType":"DiagnosticReport","status":"final","code":{"coding":[{"code":"1643AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}]},"subject":{"reference":"Patient/123"},"issued":"${reportDate}","contained":[{"resourceType":"Observation","id":"lab-test-result","status":"final","code":{"coding":[{"code":"1643AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}]},"subject":{"reference":"Patient/123"},"interpretation":[{"coding":[{"code":"A"}]}],"valueQuantity":{"value":"7"}}],"result":[{"reference":"#lab-test-result","type":"Observation"}],"conclusion":"Normal Report","basedOn":[{"identifier":{"value":"abe-123"},"reference":"ServiceRequest"}],"performer":[{"reference":"Practitioner/2"}]}` + `{"resourceType":"DiagnosticReport","status":"final","code":{"coding":[{"code":"21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}]},"subject":{"reference":"Patient/123"},"issued":"${reportDate}","contained":[{"resourceType":"Observation","id":"lab-test-result1","status":"final","code":{"coding":[{"code":"21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","display":"Haemoglobin"}]},"subject":{"reference":"Patient/123"},"interpretation":[{"coding":[{"code":"A"}]}],"valueQuantity":{"value":"11"}}],"result":[{"reference":"#lab-test-result1","type":"Observation"}],"conclusion":"Normal Report","basedOn":[{"identifier":{"value":"abf-123"},"reference":"ServiceRequest"}],"performer":[{"reference":"Practitioner/2"}]}` +export const panelTestResultsDiagnosticReportRequestBody = reportDate => + `{"resourceType":"DiagnosticReport","status":"final","code":{"coding":[{"code":"5b0cdc41-7371-4c2f-a1e4-ed1bf7416a8d","display":"Anaemia panel"}]},"subject":{"reference":"Patient/123"},"issued":"${reportDate}","contained":[{"resourceType":"Observation","id":"lab-test-result1","status":"final","code":{"coding":[{"code":"07a128f7-f596-45d5-a2a9-c447bc9e5112","display":"Absolute Eosinphil Count"}]},"subject":{"reference":"Patient/123"},"valueQuantity":{"value":"40"}},{"resourceType":"Observation","id":"lab-test-result2","status":"final","code":{"coding":[{"code":"21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","display":"Haemoglobin"}]},"subject":{"reference":"Patient/123"},"valueCodeableConcept":{"coding":[{"code":"703AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","display":"Positive"}]}}],"result":[{"reference":"#lab-test-result1","type":"Observation"},{"reference":"#lab-test-result2","type":"Observation"}],"basedOn":[{"identifier":{"value":"5b0cdc41-7371-4c2f-a1e4-ed1bf7416a8d"},"reference":"ServiceRequest","display":"Anaemia panel"}]}` diff --git a/src/__mocks__/testResults.ts b/src/__mocks__/testResults.ts index 114f522..22d26d1 100644 --- a/src/__mocks__/testResults.ts +++ b/src/__mocks__/testResults.ts @@ -93,11 +93,11 @@ export const mockTestResultResponse: any = { export const mockPanelTestResult = { data: { - uuid: '161430AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + uuid: '5b0cdc41-7371-4c2f-a1e4-ed1bf7416a8d', name: { - display: 'Routine blood panel', - uuid: '110966BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'Routine blood panel', + display: 'Anaemia Panel', + uuid: '8ce76a2c-e63d-4358-aabb-f8c5a6239fbd', + name: 'Anaemia Panel', locale: 'en', localePreferred: true, conceptNameType: 'FULLY_SPECIFIED', @@ -106,9 +106,9 @@ export const mockPanelTestResult = { }, names: [ { - display: 'Routine blood panel', + display: 'Anaemia Panel', uuid: '110966BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'Routine blood panel', + name: 'Anaemia Panel', locale: 'en', localePreferred: true, conceptNameType: 'FULLY_SPECIFIED', @@ -149,11 +149,11 @@ export const mockPanelTestResult = { answers: [], setMembers: [ { - uuid: '1015AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + uuid: '07a128f7-f596-45d5-a2a9-c447bc9e5112', name: { - display: 'Hematocrit', - uuid: '1066BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'Hematocrit', + display: 'Absolute Eosinphil Count', + uuid: 'fd2ec116-74c9-4d48-86cf-1c7e8aa1a748', + name: 'Absolute Eosinphil Count', locale: 'en', localePreferred: true, conceptNameType: 'FULLY_SPECIFIED', @@ -180,7 +180,7 @@ export const mockPanelTestResult = { conceptNameType: 'FULLY_SPECIFIED', links: [], resourceVersion: '1.9', - } + }, ], set: false, datatype: { @@ -229,90 +229,10 @@ export const mockPanelTestResult = { resourceVersion: '2.0', }, { - uuid: '1026AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', - name: { - display: 'Differential', - uuid: '1079BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'Differential', - locale: 'en', - localePreferred: true, - conceptNameType: 'FULLY_SPECIFIED', - links: [], - resourceVersion: '1.9', - }, - names: [ - { - display: 'Differential', - uuid: '1079BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'Differential', - locale: 'en', - localePreferred: true, - conceptNameType: 'FULLY_SPECIFIED', - links: [], - resourceVersion: '1.9', - }, - { - display: 'Diff', - uuid: '86758BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'Diff', - locale: 'en', - localePreferred: false, - conceptNameType: 'SHORT', - links: [], - resourceVersion: '1.9', - }, - ], - set: true, - datatype: { - uuid: '8d4a4c94-c2cc-11de-8d13-0010c6dffd0f', - display: 'N/A', - name: 'N/A', - description: - 'Not associated with a datatype (e.g., term answers, sets)', - hl7Abbreviation: 'ZZ', - retired: false, - links: [], - resourceVersion: '1.8', - }, - conceptClass: { - uuid: '8d492026-c2cc-11de-8d13-0010c6dffd0f', - display: 'LabSet', - name: 'LabSet', - description: 'Panels', - retired: false, - links: [], - resourceVersion: '1.8', - }, - hiNormal: null, - hiAbsolute: null, - hiCritical: null, - lowNormal: null, - lowAbsolute: null, - lowCritical: null, - units: null, - allowDecimal: null, - handler: null, - descriptions: [ - { - display: - 'Describes the relative distribution of the different types of white blood cells', - uuid: '1028FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', - description: - 'Describes the relative distribution of the different types of white blood cells', - locale: 'en', - links: [], - resourceVersion: '1.9', - }, - ], - answers: [], - setMembers: [], - resourceVersion: '2.0', - }, - { - uuid: '1643AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + uuid: '21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', name: { - display: 'Rapid test for malaria', - uuid: '1923BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', + display: 'Haemoglobin', + uuid: 'b8b8c317-43d2-4c4b-a67d-2ef3782c53eb', name: 'Rapid test for malaria', locale: 'en', localePreferred: true, @@ -425,26 +345,61 @@ export const mockPanelTestResult = { export const mockTestResult = { data: { - uuid: '1643AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + uuid: '21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', name: { - display: 'Dummy test', - uuid: '1923BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'Dummy test', + display: 'Haemoglobin', + uuid: '23BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', + name: 'Haemoglobin', locale: 'en', localePreferred: true, conceptNameType: 'FULLY_SPECIFIED', - links: [], resourceVersion: '1.9', }, names: [ { - display: 'RDT Malaria', - uuid: '86926BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'RDT Malaria', + display: 'Hemoglobin', + uuid: '110964BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', + name: 'Hemoglobin', locale: 'en', localePreferred: false, - conceptNameType: 'SHORT', - links: [], + conceptNameType: null, + links: [ + { + rel: 'self', + uri: + 'http://localhost:8080/openmrs/ws/rest/v1/concept/21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/name/110964BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', + resourceAlias: 'name', + }, + { + rel: 'full', + uri: + 'http://localhost:8080/openmrs/ws/rest/v1/concept/21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/name/110964BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB?v=full', + resourceAlias: 'name', + }, + ], + resourceVersion: '1.9', + }, + { + display: 'Haemoglobin', + uuid: '23BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', + name: 'Haemoglobin', + locale: 'en', + localePreferred: true, + conceptNameType: 'FULLY_SPECIFIED', + links: [ + { + rel: 'self', + uri: + 'http://localhost:8080/openmrs/ws/rest/v1/concept/21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/name/23BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', + resourceAlias: 'name', + }, + { + rel: 'full', + uri: + 'http://localhost:8080/openmrs/ws/rest/v1/concept/21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/name/23BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB?v=full', + resourceAlias: 'name', + }, + ], resourceVersion: '1.9', }, ], @@ -469,61 +424,41 @@ export const mockTestResult = { links: [], resourceVersion: '1.8', }, - hiNormal: null, + hiNormal: 17.8, hiAbsolute: null, hiCritical: null, - lowNormal: null, - lowAbsolute: null, - lowCritical: null, - units: null, - allowDecimal: null, + lowNormal: 10.4, + lowAbsolute: 0, + lowCritical: 7, + units: 'g/dL', + allowDecimal: true, handler: null, descriptions: [ { - display: 'Test for rapid diagnosis of Malaria.', - uuid: '1483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', - description: 'Test for rapid diagnosis of Malaria.', + display: + 'The iron-containing respiratory pigment in red blood cells of vertebrates, consisting of about 6 percent heme and 94 percent globin.', + uuid: '21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', + description: + 'The iron-containing respiratory pigment in red blood cells of vertebrates, consisting of about 6 percent heme and 94 percent globin.', locale: 'en', links: [ { rel: 'self', uri: - 'http://localhost/openmrs/ws/rest/v1/concept/1643AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/description/1483FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', + 'http://localhost:8080/openmrs/ws/rest/v1/concept/21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/description/21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', resourceAlias: 'description', }, - ], - resourceVersion: '1.9', - }, - ], - answers: [ - { - uuid: '703AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', - name: { - display: 'Positive', - uuid: '737BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'Positive', - locale: 'en', - localePreferred: true, - conceptNameType: 'FULLY_SPECIFIED', - links: [], - resourceVersion: '1.9', - }, - names: [ { - display: 'Positive', - uuid: '737BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB', - name: 'Positive', - locale: 'en', - localePreferred: true, - conceptNameType: 'FULLY_SPECIFIED', - links: [], - resourceVersion: '1.9', + rel: 'full', + uri: + 'http://localhost:8080/openmrs/ws/rest/v1/concept/21AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/description/21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF?v=full', + resourceAlias: 'description', }, ], - displayString: 'Positive', - resourceVersion: '2.0', + resourceVersion: '1.9', }, ], + answers: [], setMembers: [], resourceVersion: '2.0', }, @@ -531,9 +466,10 @@ export const mockTestResult = { export const mockSelectedPendingOrder = [ { - id: '161430AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', - testName: 'Routine blood panel', + id: '5b0cdc41-7371-4c2f-a1e4-ed1bf7416a8d', + testName: 'Anaemia panel', date: 'May 03, 2022', orderedBy: 'Superman', + conceptUuid: '5b0cdc41-7371-4c2f-a1e4-ed1bf7416a8d', }, ] diff --git a/src/patient-lab-dashboard/patient-lab-details/patient-lab-details.test.tsx b/src/patient-lab-dashboard/patient-lab-details/patient-lab-details.test.tsx index 9b0cc4f..f25e12c 100644 --- a/src/patient-lab-dashboard/patient-lab-details/patient-lab-details.test.tsx +++ b/src/patient-lab-dashboard/patient-lab-details/patient-lab-details.test.tsx @@ -867,9 +867,9 @@ describe('Patient lab details', () => { expect(screen.getByText(/Pending lab orders/i)).toBeInTheDocument() }) - expect(screen.getByRole('cell', {name: 'Dummy Test'})).toBeInTheDocument() + expect(screen.getByRole('cell', {name: 'Haemoglobin'})).toBeInTheDocument() - userEvent.click(screen.getAllByRole('checkbox', {name: /Select row/i})[2]) + userEvent.click(screen.getAllByRole('checkbox', {name: /Select row/i})[3]) userEvent.click(screen.getByRole('button', {name: /enter test results/i})) @@ -880,7 +880,7 @@ describe('Patient lab details', () => { await waitFor(() => expect(screen.getByPlaceholderText(/Enter value/i)).toBeInTheDocument(), ) - userEvent.type(screen.getByPlaceholderText(/Enter value/i), '7') + userEvent.type(screen.getByPlaceholderText(/Enter value/i), '11') userEvent.click( screen.getByRole('textbox', { @@ -948,9 +948,9 @@ describe('Patient lab details', () => { expect(screen.getByText(/Pending lab orders/i)).toBeInTheDocument() }) - expect(screen.getByRole('cell', {name: 'Dummy Test'})).toBeInTheDocument() + expect(screen.getByRole('cell', {name: 'Haemoglobin'})).toBeInTheDocument() - userEvent.click(screen.getAllByRole('checkbox', {name: /Select row/i})[2]) + userEvent.click(screen.getAllByRole('checkbox', {name: /Select row/i})[3]) userEvent.click(screen.getByRole('button', {name: /enter test results/i})) @@ -961,7 +961,7 @@ describe('Patient lab details', () => { await waitFor(() => expect(screen.getByPlaceholderText(/Enter value/i)).toBeInTheDocument(), ) - userEvent.type(screen.getByPlaceholderText(/Enter value/i), '7') + userEvent.type(screen.getByPlaceholderText(/Enter value/i), '11') userEvent.click(screen.getAllByLabelText(/abnormal/i)[0]) diff --git a/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.test.tsx b/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.test.tsx index fd2a2bd..f8303fb 100644 --- a/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.test.tsx +++ b/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.test.tsx @@ -62,7 +62,6 @@ describe('Paginated Table', () => { patientUuid={mockPatientUuid} onButtonClick={false} onEnterResultButtonClick={false} - /> @@ -98,7 +97,7 @@ describe('Paginated Table', () => { name: /select row/i, }).length, ).toEqual(1) - expect(screen.getByText(/3 \/ 3 items/i)).toBeInTheDocument() + expect(screen.getByText(/4 \/ 4 items/i)).toBeInTheDocument() userEvent.click( screen.getByRole('checkbox', { @@ -165,7 +164,7 @@ describe('Paginated Table', () => { userEvent.click(screen.getByRole('checkbox', {name: /select all rows/i})) - expect(screen.getByRole('checkbox', { name: /select row/i })).toBeChecked() + expect(screen.getByRole('checkbox', {name: /select row/i})).toBeChecked() }) it('should display error message when call for orders data is unsuccessful', async () => { const mockedOpenmrsFetch = openmrsFetch as jest.Mock diff --git a/src/patient-lab-dashboard/test-results/test-results.test.tsx b/src/patient-lab-dashboard/test-results/test-results.test.tsx index 113882e..b1addf8 100644 --- a/src/patient-lab-dashboard/test-results/test-results.test.tsx +++ b/src/patient-lab-dashboard/test-results/test-results.test.tsx @@ -8,11 +8,20 @@ import { mockSelectedPendingOrder, mockTestResult, } from '../../__mocks__/testResults' -import {LabTestResultsProvider} from '../../context/lab-test-results-context' +import { + LabTestResultsProvider, + useAllTestAndPanel, +} from '../../context/lab-test-results-context' import {PendingLabOrdersProvider} from '../../context/pending-orders-context' import {UploadReportProvider} from '../../context/upload-report-context' -import {localStorageMock} from '../../utils/test-utils' +import {localStorageMock, verifyApiCall} from '../../utils/test-utils' import TestResults from './test-results' +import { + mockAlltestAndPanels, + panelTestResultsDiagnosticReportRequestBody, +} from '../../__mocks__/selectTests.mock' +import {saveDiagnosticReportURL} from '../../utils/api-utils' +import {mockDoctorNames} from '../../__mocks__/doctorNames.mock' jest.mock('../../context/pending-orders-context', () => ({ ...jest.requireActual('../../context/pending-orders-context'), @@ -21,6 +30,12 @@ jest.mock('../../context/pending-orders-context', () => ({ })), })) +jest.mock('../../context/lab-test-results-context', () => ({ + ...jest.requireActual('../../context/lab-test-results-context'), + useLabTestResultsContext: jest.fn(), + useAllTestAndPanel: jest.fn(), +})) + describe('TestResults Report', () => { const saveHandler = jest.fn() const closeHandler = jest.fn() @@ -30,6 +45,10 @@ describe('TestResults Report', () => { value: 'bahmni.user.location={"uuid":"locationuuid123"}', }) Object.defineProperty(window, 'localStorage', {value: localStorageMock}) + const mockUseAllTestAndPanel = useAllTestAndPanel as jest.Mock + mockUseAllTestAndPanel.mockImplementation(() => ({ + allTestsAndPanels: mockAlltestAndPanels, + })) }) afterEach(() => { jest.clearAllMocks(), localStorage.clear() @@ -194,7 +213,7 @@ describe('TestResults Report', () => { screen.getByRole('button', {name: /save and upload/i}), ).toBeDisabled() - expect(screen.getAllByRole('checkbox', {name: /Abnormal/i}).length).toBe(3) + expect(screen.getAllByRole('checkbox', {name: /Abnormal/i}).length).toBe(2) userEvent.type(screen.getAllByPlaceholderText(/Enter value/i)[0], '6') @@ -232,7 +251,7 @@ describe('TestResults Report', () => { screen.getAllByPlaceholderText(/Enter value/i)[0], ).toBeInTheDocument(), ) - expect(screen.getAllByPlaceholderText(/Enter value/i).length).toBe(2) + expect(screen.getAllByPlaceholderText(/Enter value/i).length).toBe(1) expect(screen.getByText(/select an answer/i)).toBeInTheDocument() }) it('should indicate error message when user enters invalid data', async () => { @@ -261,7 +280,6 @@ describe('TestResults Report', () => { ).toBeDisabled() userEvent.type(screen.getAllByPlaceholderText(/Enter value/i)[0], 'numeric') - userEvent.type(screen.getAllByPlaceholderText(/Enter value/i)[1], '22') expect(screen.getByText(/select an answer/i)).toBeInTheDocument() userEvent.click( @@ -336,6 +354,59 @@ describe('TestResults Report', () => { screen.getByRole('button', {name: /save and upload/i}), ).toBeDisabled() }) + it('should save test results when user enter test results for panel test and click save and upload button', async () => { + localStorage.setItem('i18nextLng', 'en') + const mockedOpenmrsFetch = openmrsFetch as jest.Mock + mockedOpenmrsFetch + .mockReturnValueOnce(mockDoctorNames) + .mockReturnValueOnce(mockPanelTestResult) + .mockReturnValueOnce(mockAlltestAndPanels) + .mockReturnValueOnce(mockSelectedPendingOrder) + + const mockedLayout = useLayoutType as jest.Mock + mockedLayout.mockReturnValue('desktop') + + renderWithContextProvider( + , + ) + + userEvent.click( + screen.getByRole('textbox', { + name: /report date/i, + }), + ) + const currentDay: string = getFormatedDate(0) + userEvent.click(screen.getByLabelText(currentDay)) + + await waitFor(() => + expect(screen.queryByText(/loading \.\.\./i)).not.toBeInTheDocument(), + ) + + const input = await screen.findByText('Hct [32.3 - 51.9 %]') + userEvent.type(input, '40') + userEvent.click(await screen.findByText('Select an answer')) + userEvent.click(await screen.findByText('Positive')) + + const saveButton = screen.getByRole('button', {name: /save and upload/i}) + expect(saveButton).not.toBeDisabled() + userEvent.click(saveButton) + + await waitFor(() => { + expect(mockedOpenmrsFetch).toBeCalledTimes(3) + }) + verifyApiCall( + saveDiagnosticReportURL, + 'POST', + panelTestResultsDiagnosticReportRequestBody( + new Date(currentDay).toISOString(), + ), + ) + }) }) function getFormatedDate(addDays: number): string { diff --git a/src/patient-lab-dashboard/test-results/test-results.tsx b/src/patient-lab-dashboard/test-results/test-results.tsx index 46363f0..d27248e 100644 --- a/src/patient-lab-dashboard/test-results/test-results.tsx +++ b/src/patient-lab-dashboard/test-results/test-results.tsx @@ -8,7 +8,7 @@ import { TextInput, } from 'carbon-components-react' import dayjs from 'dayjs' -import React, {useState} from 'react' +import React, {useEffect, useState} from 'react' import useSWR from 'swr' import Overlay from '../../common/overlay' import {usePendingLabOrderContext} from '../../context/pending-orders-context' @@ -19,6 +19,7 @@ import {getTestName} from '../../utils/helperFunctions' import DoctorListDropdown from '../doctors-list-dropdown/doctor-list-dropdown' import {saveTestDiagnosticReport} from '../upload-report/upload-report.resources' import {TestResultsLabOrder} from '../../types' +import {useAllTestAndPanel} from '../../context/lab-test-results-context' interface TestResultProps { saveHandler: Function @@ -49,11 +50,23 @@ const TestResults: React.FC = ({ >(true) const [isSaveButtonClicked, setIsSaveButtonClicked] = useState(false) const [labResult, setLabResult] = useState(new Map()) - const testResultData = [] + const [selectedTests, setSelectedTests] = useState([]) + const {allTestsAndPanels} = useAllTestAndPanel() + useEffect(() => { + const filteredTests = allTestsAndPanels.filter( + pendingOrderTest => + selectedPendingOrder.findIndex( + tempPendingTest => + tempPendingTest?.conceptUuid === pendingOrderTest.uuid, + ) > -1, + ) + setSelectedTests(filteredTests) + }, [selectedPendingOrder, allTestsAndPanels]) const handleDiscard = () => { setReportDate(null) setReportConclusion('') + setSelectedTests([]) setDoctor(null) setShowReportConclusionLabel(true) setLabResult(new Map()) @@ -73,11 +86,18 @@ const TestResults: React.FC = ({ !reportDate || !doctor || !isValidDataPresent() || isSaveButtonClicked const getTestData = test => { - for (let index = 0; index < testResultData.length; index++) { - if (testResultData[index].data.uuid === test.conceptUuid) { - return testResultData[index].data - } + const matchingData = testResultData.find( + item => item.data.uuid === test.uuid, + ) + + if (matchingData) { + const dataType = + matchingData.data.setMembers.length > 0 + ? matchingData.data.setMembers.map(member => member.datatype) + : [matchingData.data.datatype] + return dataType } + return [] } const isInvalid = test => { @@ -94,8 +114,7 @@ const TestResults: React.FC = ({ } const isValidDataPresent = () => { - if (labResult.size == 0 || labResult.size !== selectedPendingOrder.length) - return false + if (labResult.size == 0) return false for (let mapEntry of labResult.values()) { if (mapEntry.value === '') return false @@ -134,17 +153,18 @@ const TestResults: React.FC = ({ const ac = new AbortController() let allSuccess: boolean = true try { - for (let index = 0; index < selectedPendingOrder.length; index++) { + for (let index = 0; index < selectedTests.length; index++) { const response = await saveTestDiagnosticReport( undefined, patientUuid, doctor.uuid, + selectedTests[index], reportDate, reportConclusion, ac, selectedPendingOrder[index], labResult, - getTestData(selectedPendingOrder[index]).datatype, + getTestData(selectedTests[index]), ) if (allSuccess && !response.ok) { allSuccess = false diff --git a/src/patient-lab-dashboard/upload-report/upload-report.resources.tsx b/src/patient-lab-dashboard/upload-report/upload-report.resources.tsx index 86fc983..474bca3 100644 --- a/src/patient-lab-dashboard/upload-report/upload-report.resources.tsx +++ b/src/patient-lab-dashboard/upload-report/upload-report.resources.tsx @@ -163,6 +163,7 @@ export function saveTestDiagnosticReport( encounter, patientUuid: string, performerUuid: string, + selectedTest: LabTest, reportDate: Date, reportConclusion: string, ac: AbortController, @@ -171,7 +172,7 @@ export function saveTestDiagnosticReport( string, {value: string; abnormal?: boolean; codableConceptUuid?: string} >, - dataType: Datatype, + dataType: Datatype[], ) { let basedOn: Array = null if (selectedPendingOrder) @@ -183,6 +184,78 @@ export function saveTestDiagnosticReport( }, ] + let containedArray: Contained[] = [] + + const createObservation = (item, index) => { + const observation: Contained = { + resourceType: 'Observation', + id: `lab-test-result${index + 1}`, + status: 'final', + code: { + coding: [ + { + code: item.uuid, + display: item.name.display, + }, + ], + }, + subject: {reference: `Patient/${patientUuid}`}, + } + + const labItem = labResult.get(item.uuid) + + if (labItem?.abnormal === true) { + observation.interpretation = [ + { + coding: [ + { + code: 'A', + }, + ], + }, + ] + } + + switch (dataType[index]?.name) { + case 'Boolean': + observation.valueBoolean = labItem?.value.toLowerCase() === 'true' + break + case 'Numeric': + observation.valueQuantity = { + value: labItem?.value, + } + break + case 'Coded': + observation.valueCodeableConcept = { + coding: [ + { + code: labItem?.codableConceptUuid, + display: labItem?.value, + }, + ], + } + break + default: + observation.valueString = labItem?.value + } + + return observation + } + + if (selectedTest.setMembers && selectedTest.setMembers.length > 0) { + containedArray = selectedTest.setMembers.map(createObservation) + } else { + const observation = createObservation(selectedTest, 0) + containedArray.push(observation) + } + + const resultArray = containedArray.map(item => { + return { + reference: `#${item.id}`, + type: 'Observation', + } + }) + const requestBody: TestResultDiagnosticReportRequestType = { resourceType: 'DiagnosticReport', status: 'final', @@ -198,66 +271,9 @@ export function saveTestDiagnosticReport( reference: 'Patient/' + patientUuid, }, issued: reportDate, - contained: [ - { - resourceType: 'Observation', - id: 'lab-test-result', - status: 'final', - code: { - coding: [ - { - code: selectedPendingOrder.conceptUuid, - display: selectedPendingOrder.testName, - }, - ], - }, - subject: { - reference: 'Patient/' + patientUuid, - }, - }, - ], - result: [ - { - reference: '#lab-test-result', - type: 'Observation', - }, - ], + contained: containedArray, + result: resultArray, } - if (labResult.get(selectedPendingOrder.conceptUuid).abnormal === true) { - requestBody.contained[0].interpretation = [ - { - coding: [ - { - code: 'A', - }, - ], - }, - ] - } - if (dataType.name == 'Boolean') { - requestBody.contained[0].valueBoolean = - labResult.get(selectedPendingOrder.conceptUuid)?.value.toLowerCase() == - 'true' - } else if (dataType.name == 'Numeric') { - requestBody.contained[0].valueQuantity = { - value: labResult.get(selectedPendingOrder.conceptUuid)?.value, - } - } else if (dataType.name == 'Coded') { - requestBody.contained[0].valueCodeableConcept = { - coding: [ - { - code: labResult.get(selectedPendingOrder.conceptUuid) - ?.codableConceptUuid, - display: labResult.get(selectedPendingOrder.conceptUuid)?.value, - }, - ], - } - } else { - requestBody.contained[0].valueString = labResult.get( - selectedPendingOrder.conceptUuid, - )?.value - } - if (reportConclusion) { requestBody.conclusion = reportConclusion }