Skip to content

Commit 3b569ef

Browse files
BN-49. Lab investigation order requests shouldn't be getting duplicated when a user places an order and subsequently removes ordered requests. (#32)
* BN-49| Add. count=100 for lab test pagination * BN-49. Fix. Lab investigation order requests shouldn't get duplicated when a user places an order and subsequently removes ordered requests. * BN-49. fix: Add sort parameter to PATIENT_LAB_INVESTIGATION_RESOURCE_URL. * BN-49| refactor: replaced FhirLabTestBundle with the standard Bundle type and FhirLabTest with ServiceRequest from fhir/r4 * BN-49. fix: Failing tests after using Fhir Bundle and ServiceRequest instead of custom interface --------- Co-authored-by: Dev Singh <88476780+devsingh05298@users.noreply.github.com>
1 parent 2206132 commit 3b569ef

File tree

9 files changed

+170
-306
lines changed

9 files changed

+170
-306
lines changed

src/__mocks__/labInvestigationMocks.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import {
2-
FhirLabTest,
3-
FhirLabTestBundle,
42
FormattedLabTest,
5-
LabTestStatus,
63
LabTestPriority,
74
LabTestsByDate,
85
} from '@types/labInvestigation';
6+
import { Bundle, ServiceRequest } from 'fhir/r4';
97

108
// Mock patient UUID
119
export const mockPatientUUID = 'test-patient-uuid';
1210

1311
// Mock FHIR lab tests
14-
export const mockFhirLabTests: FhirLabTest[] = [
12+
export const mockFhirLabTests: ServiceRequest[] = [
1513
{
1614
resourceType: 'ServiceRequest',
1715
id: 'lab-test-1',
@@ -29,7 +27,7 @@ export const mockFhirLabTests: FhirLabTest[] = [
2927
valueString: 'Panel',
3028
},
3129
],
32-
status: 'Pending',
30+
status: 'completed',
3331
intent: 'order',
3432
category: [
3533
{
@@ -43,7 +41,7 @@ export const mockFhirLabTests: FhirLabTest[] = [
4341
text: 'Laboratory',
4442
},
4543
],
46-
priority: 'Routine',
44+
priority: 'routine',
4745
code: {
4846
coding: [
4947
{
@@ -94,7 +92,7 @@ export const mockFhirLabTests: FhirLabTest[] = [
9492
valueString: 'Panel',
9593
},
9694
],
97-
status: 'Pending',
95+
status: 'revoked',
9896
intent: 'order',
9997
category: [
10098
{
@@ -108,7 +106,7 @@ export const mockFhirLabTests: FhirLabTest[] = [
108106
text: 'Laboratory',
109107
},
110108
],
111-
priority: 'Stat',
109+
priority: 'stat',
112110
code: {
113111
coding: [
114112
{
@@ -158,7 +156,7 @@ export const mockFhirLabTests: FhirLabTest[] = [
158156
valueString: 'Test',
159157
},
160158
],
161-
status: 'Pending',
159+
status: 'completed',
162160
intent: 'order',
163161
category: [
164162
{
@@ -172,7 +170,7 @@ export const mockFhirLabTests: FhirLabTest[] = [
172170
text: 'Laboratory',
173171
},
174172
],
175-
priority: 'Routine',
173+
priority: 'routine',
176174
code: {
177175
coding: [
178176
{
@@ -208,7 +206,7 @@ export const mockFhirLabTests: FhirLabTest[] = [
208206
];
209207

210208
// Mock FHIR lab test bundle
211-
export const mockFhirLabTestBundle: FhirLabTestBundle = {
209+
export const mockFhirLabTestBundle: Bundle = {
212210
resourceType: 'Bundle',
213211
id: 'test-bundle',
214212
meta: {
@@ -233,7 +231,6 @@ export const mockFormattedLabTests: FormattedLabTest[] = [
233231
{
234232
id: 'lab-test-1',
235233
testName: 'Complete Blood Count',
236-
status: LabTestStatus.Pending,
237234
priority: LabTestPriority.routine,
238235
orderedBy: 'Dr. John Doe',
239236
orderedDate: '2025-03-25T06:48:32.000+00:00',
@@ -243,7 +240,6 @@ export const mockFormattedLabTests: FormattedLabTest[] = [
243240
{
244241
id: 'lab-test-2',
245242
testName: 'Lipid Panel',
246-
status: LabTestStatus.Pending,
247243
priority: LabTestPriority.stat,
248244
orderedBy: 'Dr. Jane Smith',
249245
orderedDate: '2025-03-25T06:48:32.000+00:00',
@@ -253,7 +249,6 @@ export const mockFormattedLabTests: FormattedLabTest[] = [
253249
{
254250
id: 'lab-test-3',
255251
testName: 'Glucose Test',
256-
status: LabTestStatus.Pending,
257252
priority: LabTestPriority.routine,
258253
orderedBy: 'Dr. John Doe',
259254
orderedDate: '2025-03-24T06:48:32.000+00:00',
@@ -277,7 +272,7 @@ export const mockLabTestsByDate: LabTestsByDate[] = [
277272
];
278273

279274
// Mock lab test with missing optional fields
280-
export const mockLabTestWithMissingFields: FhirLabTest = {
275+
export const mockLabTestWithMissingFields: ServiceRequest = {
281276
resourceType: 'ServiceRequest',
282277
id: 'lab-test-incomplete',
283278
meta: {
@@ -290,7 +285,7 @@ export const mockLabTestWithMissingFields: FhirLabTest = {
290285
valueString: 'Test',
291286
},
292287
],
293-
status: 'Pending',
288+
status: 'completed',
294289
intent: 'order',
295290
category: [
296291
{
@@ -304,7 +299,7 @@ export const mockLabTestWithMissingFields: FhirLabTest = {
304299
text: 'Laboratory',
305300
},
306301
],
307-
priority: 'Routine',
302+
priority: 'routine',
308303
code: {
309304
coding: [
310305
{
@@ -337,7 +332,6 @@ export const mockLabTestWithMissingFields: FhirLabTest = {
337332
export const mockFormattedLabTestWithMissingFields: FormattedLabTest = {
338333
id: 'lab-test-incomplete',
339334
testName: 'Incomplete Test',
340-
status: LabTestStatus.Pending,
341335
priority: LabTestPriority.routine,
342336
orderedBy: 'Unknown Doctor',
343337
orderedDate: '2025-03-25T06:48:32.000+00:00',

src/constants/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const PATIENT_VISITS_URL = (patientUUID: string) =>
2727
OPENMRS_FHIR_R4 + `/Encounter?subject:Patient=${patientUUID}&_tag=visit`;
2828
export const PATIENT_LAB_INVESTIGATION_RESOURCE_URL = (patientUUID: string) =>
2929
OPENMRS_FHIR_R4 +
30-
`/ServiceRequest?category=${LAB_ORDER_TYPE_UUID}&patient=${patientUUID}&numberOfVisits=5`;
30+
`/ServiceRequest?category=${LAB_ORDER_TYPE_UUID}&patient=${patientUUID}&numberOfVisits=5&_count=100&_sort=_lastUpdated`;
3131
export const DASHBOARD_CONFIG_URL = (dashboardURL: string) =>
3232
`/bahmni_config/openmrs/apps/clinical/v2/dashboards/${dashboardURL}`;
3333
export const PATIENT_DIAGNOSIS_RESOURCE_URL = (patientUUID: string) =>

src/displayControls/labinvestigation/__tests__/LabInvestigationControl.test.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import useLabInvestigations from '@hooks/useLabInvestigations';
55
import { groupLabTestsByDate } from '@services/labInvestigationService';
66
import {
77
LabTestsByDate,
8-
LabTestStatus,
98
LabTestPriority,
109
FormattedLabTest,
1110
} from '@types/labInvestigation';
@@ -25,7 +24,6 @@ jest.mock('../LabInvestigationItem', () => ({
2524
default: ({ test }: { test: FormattedLabTest }) => (
2625
<div data-testid="lab-investigation-item">
2726
<span data-testid="test-name">{test.testName}</span>
28-
<span data-testid="test-status">{test.status}</span>
2927
<span data-testid="test-priority">{test.priority}</span>
3028
</div>
3129
),
@@ -72,7 +70,6 @@ describe('LabInvestigationControl', () => {
7270
{
7371
id: 'test-1',
7472
testName: 'Complete Blood Count',
75-
status: LabTestStatus.Normal,
7673
priority: LabTestPriority.routine,
7774
orderedBy: 'Dr. Smith',
7875
orderedDate: '2025-05-08T12:44:24+00:00',
@@ -83,7 +80,6 @@ describe('LabInvestigationControl', () => {
8380
{
8481
id: 'test-2',
8582
testName: 'Lipid Panel',
86-
status: LabTestStatus.Abnormal,
8783
priority: LabTestPriority.stat,
8884
orderedBy: 'Dr. Johnson',
8985
orderedDate: '2025-04-09T13:21:22+00:00',
@@ -94,7 +90,6 @@ describe('LabInvestigationControl', () => {
9490
{
9591
id: 'test-3',
9692
testName: 'Liver Function',
97-
status: LabTestStatus.Pending,
9893
priority: LabTestPriority.routine,
9994
orderedBy: 'Dr. Williams',
10095
orderedDate: '2025-04-09T13:21:22+00:00',
@@ -171,13 +166,6 @@ describe('LabInvestigationControl', () => {
171166
expect(testNames[1].textContent).toBe('Lipid Panel');
172167
expect(testNames[2].textContent).toBe('Liver Function');
173168

174-
// Check that the test statuses are displayed
175-
const testStatuses = screen.getAllByTestId('test-status');
176-
expect(testStatuses).toHaveLength(3);
177-
expect(testStatuses[0].textContent).toBe(LabTestStatus.Normal);
178-
expect(testStatuses[1].textContent).toBe(LabTestStatus.Abnormal);
179-
expect(testStatuses[2].textContent).toBe(LabTestStatus.Pending);
180-
181169
// Check that the test priorities are displayed
182170
const testPriorities = screen.getAllByTestId('test-priority');
183171
expect(testPriorities).toHaveLength(3);

src/displayControls/labinvestigation/__tests__/LabInvestigationItem.test.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import LabInvestigationItem from '../LabInvestigationItem';
4-
import {
5-
FormattedLabTest,
6-
LabTestStatus,
7-
LabTestPriority,
8-
} from '@types/labInvestigation';
4+
import { FormattedLabTest, LabTestPriority } from '@types/labInvestigation';
95
import { useTranslation } from 'react-i18next';
106

117
// Mock the BahmniIcon component
@@ -26,7 +22,6 @@ describe('LabInvestigationItem', () => {
2622
const mockLabTest: FormattedLabTest = {
2723
id: 'test-123',
2824
testName: 'Complete Blood Count',
29-
status: LabTestStatus.Normal,
3025
priority: LabTestPriority.routine,
3126
orderedBy: 'Dr. Smith',
3227
orderedDate: '2025-05-08T12:44:24+00:00',

src/hooks/__tests__/useLabInvestigations.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { getLabTests, formatLabTests } from '@services/labInvestigationService';
55
import { usePatientUUID } from '@hooks/usePatientUUID';
66
import {
77
FormattedLabTest,
8-
LabTestStatus,
98
LabTestPriority,
109
} from '../../types/labInvestigation';
1110

@@ -35,7 +34,6 @@ describe('useLabInvestigations', () => {
3534
{
3635
id: 'aba2a637-05f5-44c6-9021-c5cd05548342',
3736
testName: 'CD8%',
38-
status: LabTestStatus.Normal,
3937
priority: LabTestPriority.routine,
4038
orderedBy: 'Super Man',
4139
orderedDate: '2025-05-08T12:44:24+00:00',
@@ -46,7 +44,6 @@ describe('useLabInvestigations', () => {
4644
{
4745
id: '29e240ce-5a3d-4643-8d4b-ca5b4cbf665d',
4846
testName: 'Absolute eosinophil count test',
49-
status: LabTestStatus.Normal,
5047
priority: LabTestPriority.routine,
5148
orderedBy: 'Super Man',
5249
orderedDate: '2025-04-09T13:21:22+00:00',
@@ -57,7 +54,6 @@ describe('useLabInvestigations', () => {
5754
{
5855
id: 'e7eca932-1d6f-44a4-bd94-e1105860ab77',
5956
testName: 'Clotting Panel',
60-
status: LabTestStatus.Normal,
6157
priority: LabTestPriority.routine,
6258
orderedBy: 'Super Man',
6359
orderedDate: '2025-04-09T13:21:22+00:00',

src/services/__tests__/labInvestigationService.internal.test.ts

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import {
2-
FhirLabTest,
3-
LabTestStatus,
4-
LabTestPriority,
5-
} from '../../types/labInvestigation';
1+
import { LabTestPriority } from '../../types/labInvestigation';
62
import { getFormattedError } from '../../utils/common';
73
import notificationService from '../notificationService';
84
import {
9-
mapLabTestStatus,
105
mapLabTestPriority,
116
getPatientLabTestsByDate,
127
} from '../labInvestigationService';
138
import * as api from '../api';
9+
import { ServiceRequest } from 'fhir/r4';
1410

1511
// Mock dependencies
1612
jest.mock('../../utils/common');
@@ -26,44 +22,22 @@ describe('labInvestigationService internal functions', () => {
2622
});
2723
});
2824

29-
describe('mapLabTestStatus', () => {
30-
it('should map known status values correctly', () => {
31-
const pendingTest = { status: 'Pending' } as FhirLabTest;
32-
const abnormalTest = { status: 'Abnormal' } as FhirLabTest;
33-
const normalTest = { status: 'Normal' } as FhirLabTest;
34-
35-
expect(mapLabTestStatus(pendingTest)).toBe(LabTestStatus.Pending);
36-
expect(mapLabTestStatus(abnormalTest)).toBe(LabTestStatus.Abnormal);
37-
expect(mapLabTestStatus(normalTest)).toBe(LabTestStatus.Normal);
38-
});
39-
40-
it('should default to Normal for unknown, null, or undefined status', () => {
41-
const unknownTest = { status: 'Unknown' } as FhirLabTest;
42-
const nullTest = { status: null } as unknown as FhirLabTest;
43-
const undefinedTest = { status: undefined } as unknown as FhirLabTest;
44-
const emptyTest = {} as FhirLabTest;
45-
46-
expect(mapLabTestStatus(unknownTest)).toBe(LabTestStatus.Normal);
47-
expect(mapLabTestStatus(nullTest)).toBe(LabTestStatus.Normal);
48-
expect(mapLabTestStatus(undefinedTest)).toBe(LabTestStatus.Normal);
49-
expect(mapLabTestStatus(emptyTest)).toBe(LabTestStatus.Normal);
50-
});
51-
});
52-
5325
describe('mapLabTestPriority', () => {
5426
it('should map known priority values correctly', () => {
55-
const routineTest = { priority: 'routine' } as FhirLabTest;
56-
const statTest = { priority: 'stat' } as FhirLabTest;
27+
const routineTest = { priority: 'routine' } as ServiceRequest;
28+
const statTest = { priority: 'stat' } as ServiceRequest;
5729

5830
expect(mapLabTestPriority(routineTest)).toBe(LabTestPriority.routine);
5931
expect(mapLabTestPriority(statTest)).toBe(LabTestPriority.stat);
6032
});
6133

6234
it('should default to routine for unknown, null, or undefined priority', () => {
63-
const unknownTest = { priority: 'unknown' } as FhirLabTest;
64-
const nullTest = { priority: null } as unknown as FhirLabTest;
65-
const undefinedTest = { priority: undefined } as unknown as FhirLabTest;
66-
const emptyTest = {} as FhirLabTest;
35+
const unknownTest = { priority: 'unknown' } as unknown as ServiceRequest;
36+
const nullTest = { priority: null } as unknown as ServiceRequest;
37+
const undefinedTest = {
38+
priority: undefined,
39+
} as unknown as ServiceRequest;
40+
const emptyTest = {} as ServiceRequest;
6741

6842
expect(mapLabTestPriority(unknownTest)).toBe(LabTestPriority.routine);
6943
expect(mapLabTestPriority(nullTest)).toBe(LabTestPriority.routine);

0 commit comments

Comments
 (0)