Skip to content

Commit f704bc8

Browse files
Merge BN-49 | Display lab orders on patient dashboard
A few changes related to the priority-based display of tests need to be made.
2 parents aa431dc + ca2522b commit f704bc8

File tree

9 files changed

+87
-115
lines changed

9 files changed

+87
-115
lines changed

public/locales/locale_en.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"LAB_TEST_REPORTED_ON": "Reported On",
102102
"LAB_TEST_RESULT": "Result",
103103
"LAB_TEST_RESULTS_PENDING": "Results Pending",
104-
"LAB_TEST_ROUTINE": "Routine",
105104
"LAB_TEST_SINGLE_TEST": "Single Test",
106105
"LAB_TEST_STATUS": "Status",
107106
"LAB_TEST_UNAVAILABLE": "No lab Investigations available",

public/locales/locale_es.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"LAB_TEST_REPORTED_ON": "Reportado el",
102102
"LAB_TEST_RESULT": "Resultado",
103103
"LAB_TEST_RESULTS_PENDING": "Resultados pendientes",
104-
"LAB_TEST_ROUTINE": "De rutina",
105104
"LAB_TEST_SINGLE_TEST": "Prueba única",
106105
"LAB_TEST_STATUS": "Estado",
107106
"LAB_TEST_UNAVAILABLE": "No disponible",

src/displayControls/labinvestigation/LabInvestigationControl.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Accordion, AccordionItem, SkeletonText } from '@carbon/react';
55
import LabInvestigationItem from './LabInvestigationItem';
66
import useLabInvestigations from '@/hooks/useLabInvestigations';
77
import { groupLabTestsByDate } from '@/services/labInvestigationService';
8-
import { LabTestsByDate, FormattedLabTest } from '@/types/labInvestigation';
8+
import { LabTestsByDate } from '@/types/labInvestigation';
99

1010
const LabInvestigationControl: React.FC = () => {
1111
const { t } = useTranslation();
@@ -16,17 +16,13 @@ const LabInvestigationControl: React.FC = () => {
1616
return groupLabTestsByDate(labTests);
1717
}, [labTests]);
1818

19-
if (isError) {
20-
return <div>{t('LAB_TEST_ERROR_LOADING')}</div>;
21-
}
22-
23-
if (!isLoading && labTests.length === 0) {
24-
return <div>{t('LAB_TEST_UNAVAILABLE')}</div>;
25-
}
26-
2719
return (
2820
<section className={styles.labInvestigationWrapper}>
2921
<Accordion align="start" size="lg">
22+
{isError && <div>{t('LAB_TEST_ERROR_LOADING')}</div>}
23+
{!isLoading && labTests.length === 0 && (
24+
<div>{t('LAB_TEST_UNAVAILABLE')}</div>
25+
)}
3026
{isLoading && labTests.length === 0 && (
3127
<>
3228
<SkeletonText lineCount={3} width="100%" />
@@ -43,9 +39,25 @@ const LabInvestigationControl: React.FC = () => {
4339
</span>
4440
}
4541
>
46-
{group.tests?.map((test: FormattedLabTest, testIndex: number) => (
47-
<LabInvestigationItem key={testIndex} test={test} />
48-
))}
42+
{/* Render 'urgent' tests first */}
43+
{group.tests
44+
?.filter((test) => test.priority === 'Urgent')
45+
.map((test, index) => (
46+
<LabInvestigationItem
47+
key={`urgent-${group.date}-${test.testName}-${index}`}
48+
test={test}
49+
/>
50+
))}
51+
52+
{/* Then render non-urgent tests */}
53+
{group.tests
54+
?.filter((test) => test.priority !== 'Urgent')
55+
.map((test, index) => (
56+
<LabInvestigationItem
57+
key={`nonurgent-${group.date}-${test.testName}-${index}`}
58+
test={test}
59+
/>
60+
))}
4961
</AccordionItem>
5062
))}
5163
</Accordion>

src/displayControls/labinvestigation/LabInvestigationItem.tsx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,25 @@ const LabInvestigationItem: React.FC<LabInvestigationItemProps> = ({
1414
}) => {
1515
const { t } = useTranslation();
1616

17-
// Determine tag color based on priority
18-
const getTagType = (priority: LabTestPriority): 'gray' | 'green' => {
19-
switch (priority) {
20-
case LabTestPriority.stat:
21-
return 'gray' as const;
22-
case LabTestPriority.routine:
23-
return 'green' as const;
24-
default:
25-
return 'green' as const;
26-
}
27-
};
28-
2917
return (
3018
<div className={styles.labBox}>
3119
<div className={styles.labHeader}>
3220
<div>
3321
<strong>{test.testName}</strong>
34-
<span className={styles.testType}>
35-
{' '}
36-
{t(`LAB_TEST_${test.testType.replace(/\s+/g, '_').toUpperCase()}`)}
37-
</span>
22+
{test.testType === 'Panel' && (
23+
<span className={styles.testType}>
24+
{t(`LAB_TEST_${test.testType.toUpperCase()}`)}
25+
</span>
26+
)}
3827
</div>
39-
<Tag type={getTagType(test.priority)}>
40-
{t(`LAB_TEST_${test.priority.toUpperCase()}`)}
41-
</Tag>
28+
{test.priority === LabTestPriority.stat && (
29+
<Tag
30+
className={styles['yellow-tag']}
31+
data-testid={`lab-test-priority-${test.priority}`}
32+
>
33+
{t(`LAB_TEST_${test.priority.toUpperCase()}`)}
34+
</Tag>
35+
)}
4236
<div className={styles.orderedBy}>
4337
<BahmniIcon name="fa-user" size={ICON_SIZE.SM} id="homeIcon" />
4438
{t('LAB_TEST_ORDERED_BY')}: {test.orderedBy}

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,9 @@ describe('LabInvestigationControl Integration', () => {
101101

102102
render(<LabInvestigationControl />);
103103

104-
// Verify the priorities are displayed by checking for tag elements
105-
// Carbon Design System's Tag component might not render text content properly in tests
106-
const tags = document.querySelectorAll('.cds--tag');
107-
expect(tags.length).toBe(3); // Total of 3 tags
108-
109-
// Check for green tags (routine priority)
110-
const greenTags = document.querySelectorAll('.cds--tag--green');
111-
expect(greenTags.length).toBe(2); // Two routine tests (actual count in the DOM)
112-
113-
// Check for gray tags (stat priority)
114-
const grayTags = document.querySelectorAll('.cds--tag--gray');
115-
expect(grayTags.length).toBe(1); // One stat priority test
104+
// Check for stat priority tag using data-testid
105+
const statPriorityTag = screen.getByTestId('lab-test-priority-Urgent');
106+
expect(statPriorityTag).toBeInTheDocument();
116107
});
117108

118109
it('should display ordered by information', () => {

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('LabInvestigationControl', () => {
9595
id: 'test-3',
9696
testName: 'Liver Function',
9797
status: LabTestStatus.Pending,
98-
priority: LabTestPriority.stat,
98+
priority: LabTestPriority.routine,
9999
orderedBy: 'Dr. Williams',
100100
orderedDate: '2025-04-09T13:21:22+00:00',
101101
formattedDate: '04/09/2025',
@@ -108,12 +108,15 @@ describe('LabInvestigationControl', () => {
108108
{
109109
date: '05/08/2025',
110110
rawDate: '2025-05-08T12:44:24+00:00',
111-
tests: [mockFormattedLabTests[0]],
111+
tests: [mockFormattedLabTests[0]], // Complete Blood Count (routine)
112112
},
113113
{
114114
date: '04/09/2025',
115115
rawDate: '2025-04-09T13:21:22+00:00',
116-
tests: [mockFormattedLabTests[1], mockFormattedLabTests[2]],
116+
tests: [
117+
mockFormattedLabTests[1], // Lipid Panel (stat/Urgent) - should be first
118+
mockFormattedLabTests[2], // Liver Function (stat/Urgent) - should be second
119+
],
117120
},
118121
];
119122

@@ -180,7 +183,7 @@ describe('LabInvestigationControl', () => {
180183
expect(testPriorities).toHaveLength(3);
181184
expect(testPriorities[0].textContent).toBe(LabTestPriority.routine);
182185
expect(testPriorities[1].textContent).toBe(LabTestPriority.stat);
183-
expect(testPriorities[2].textContent).toBe(LabTestPriority.stat);
186+
expect(testPriorities[2].textContent).toBe(LabTestPriority.routine);
184187
});
185188

186189
it('renders "No lab Investigations available" message when there are no lab tests and isLoading is false', () => {
@@ -215,4 +218,33 @@ describe('LabInvestigationControl', () => {
215218
// Check that the error message is displayed
216219
expect(screen.getByText('Error loading lab tests')).toBeInTheDocument();
217220
});
221+
222+
it('renders urgent tests before non-urgent tests within each group', () => {
223+
// Mock the hook to return lab tests
224+
(useLabInvestigations as jest.Mock).mockReturnValue({
225+
labTests: mockFormattedLabTests,
226+
isLoading: false,
227+
isError: false,
228+
});
229+
230+
render(<LabInvestigationControl />);
231+
232+
// Get all test names in DOM order
233+
const testNames = screen.getAllByTestId('test-name');
234+
const testPriorities = screen.getAllByTestId('test-priority');
235+
236+
expect(testNames).toHaveLength(3);
237+
238+
// The component renders by date groups first, then by priority within each group
239+
// First date group (05/08/2025): Complete Blood Count (routine)
240+
expect(testNames[0].textContent).toBe('Complete Blood Count');
241+
expect(testPriorities[0].textContent).toBe(LabTestPriority.routine);
242+
243+
// Second date group (04/09/2025): Urgent tests first within this group
244+
expect(testNames[1].textContent).toBe('Lipid Panel');
245+
expect(testPriorities[1].textContent).toBe(LabTestPriority.stat);
246+
247+
expect(testNames[2].textContent).toBe('Liver Function');
248+
expect(testPriorities[2].textContent).toBe(LabTestPriority.routine);
249+
});
218250
});

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

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ describe('LabInvestigationItem', () => {
4343
// Return appropriate values based on the translation key
4444
const translations: Record<string, string> = {
4545
LAB_TEST_PANEL: 'Panel',
46-
LAB_TEST_SINGLE_TEST: 'Single Test',
47-
LAB_TEST_5_TESTS: '5 Tests',
48-
LAB_TEST_ROUTINE: 'Routine',
4946
LAB_TEST_URGENT: 'Urgent',
5047
LAB_TEST_ORDERED_BY: 'Ordered by:',
5148
LAB_TEST_RESULTS_PENDING: 'Results pending…',
@@ -64,9 +61,6 @@ describe('LabInvestigationItem', () => {
6461
// Check that the test type is displayed (using translation)
6562
expect(screen.getByText('Panel')).toBeInTheDocument();
6663

67-
// Check that the priority is displayed (using translation)
68-
expect(screen.getByText('Routine')).toBeInTheDocument();
69-
7064
// Check that the ordered by information is displayed
7165
expect(screen.getByText(/Ordered by:/)).toBeInTheDocument();
7266
expect(screen.getByText(/Dr. Smith/)).toBeInTheDocument();
@@ -90,69 +84,15 @@ describe('LabInvestigationItem', () => {
9084
expect(screen.getByText('Urgent')).toBeInTheDocument();
9185
});
9286

93-
it('handles unknown priority values and defaults to green tag', () => {
94-
// Create a test with an unknown priority value
95-
const unknownPriorityTest = {
96-
...mockLabTest,
97-
priority: 'unknown' as unknown as LabTestPriority,
98-
};
99-
100-
// Update the translation mock for this specific test
101-
(useTranslation as jest.Mock).mockReturnValue({
102-
t: (key: string) => {
103-
if (key === 'LAB_TEST_UNKNOWN') return 'unknown';
104-
const translations: Record<string, string> = {
105-
LAB_TEST_PANEL: 'Panel',
106-
LAB_TEST_ORDERED_BY: 'Ordered by:',
107-
LAB_TEST_RESULTS_PENDING: 'Results pending…',
108-
};
109-
return translations[key] || key;
110-
},
111-
});
112-
113-
render(<LabInvestigationItem test={unknownPriorityTest} />);
114-
115-
// The tag should still be rendered with the unknown priority text
116-
expect(screen.getByText('unknown')).toBeInTheDocument();
117-
118-
// We can't directly test the color, but we can verify the component renders
119-
// without errors, which means the default case was used
120-
});
121-
122-
it('displays different test types correctly', () => {
123-
// Test with Single Test type
124-
const singleTest = {
87+
it('displays test type correctly', () => {
88+
// Test with Panel Test type
89+
const panelTest = {
12590
...mockLabTest,
126-
testType: 'Single Test',
91+
testType: 'Panel',
12792
};
12893

129-
const { rerender } = render(<LabInvestigationItem test={singleTest} />);
130-
expect(screen.getByText('Single Test')).toBeInTheDocument();
131-
13294
// Test with Panel type
133-
rerender(<LabInvestigationItem test={mockLabTest} />);
95+
render(<LabInvestigationItem test={panelTest} />);
13496
expect(screen.getByText('Panel')).toBeInTheDocument();
135-
136-
// Test with X Tests type
137-
const multipleTest = {
138-
...mockLabTest,
139-
testType: '5 Tests',
140-
};
141-
142-
// Update the translation mock for this specific test case
143-
(useTranslation as jest.Mock).mockReturnValue({
144-
t: (key: string) => {
145-
const translations: Record<string, string> = {
146-
LAB_TEST_5_TESTS: '5 Tests',
147-
LAB_TEST_ROUTINE: 'Routine',
148-
LAB_TEST_ORDERED_BY: 'Ordered by:',
149-
LAB_TEST_RESULTS_PENDING: 'Results pending…',
150-
};
151-
return translations[key] || key;
152-
},
153-
});
154-
155-
rerender(<LabInvestigationItem test={multipleTest} />);
156-
expect(screen.getByText('5 Tests')).toBeInTheDocument();
15797
});
15898
});

src/displayControls/labinvestigation/styles/LabInvestigation.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@
6060
padding-inline-end: 0%;
6161
}
6262
}
63+
64+
.yellow-tag {
65+
background-color: #f8d465 !important;
66+
color: #333 !important;
67+
}

src/types/labInvestigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export interface FormattedLabTest {
108108
readonly orderedDate: string; // ISO date string
109109
readonly formattedDate: string; // Formatted date for display
110110
readonly result?: string | LabTestResult[];
111-
readonly testType: string; // "Panel" or "Single Test"
111+
readonly testType: string; // "Panel" or not
112112
}
113113

114114
/**

0 commit comments

Comments
 (0)