Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Test types should be filterable by synonyms #2006

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ const mockTestTypes = [
{
conceptUuid: 'test-lab-uuid-1',
label: 'HIV VIRAL LOAD',
synonyms: ['HIV VIRAL LOAD', 'HIV VL'],
},
{
conceptUuid: 'test-lab-uuid-2',
label: 'CD4 COUNT',
synonyms: ['CD4 COUNT', 'CD4'],
},
{
conceptUuid: 'test-lab-uuid-3',
label: 'HEMOGLOBIN',
synonyms: ['HEMOGLOBIN', 'HGB'],
},
];
const mockUseTestTypes = jest.fn().mockReturnValue({
Expand Down Expand Up @@ -200,6 +207,15 @@ describe('AddLabOrder', () => {
expect(screen.getByText('04 — Apr — 1972')).toBeInTheDocument();
});

test('should be possible to search for test types by synonyms', async () => {
const user = userEvent.setup();
renderAddLabOrderWorkspace();
const searchInput = screen.getByRole('searchbox');
await user.type(searchInput, 'hgb');
await screen.findByText(/hemoglobin/i);
expect(screen.queryByText(/hiv viral load/i)).not.toBeInTheDocument();
});

test('should display an error message if test types fail to load', () => {
mockUseTestTypes.mockReturnValue({
testTypes: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ function TestTypeSearchResults({ searchTerm, openOrderForm, focusAndClearSearchI
}

if (searchTerm && searchTerm.trim() !== '') {
return testTypes.filter((testType) => testType.label.toLowerCase().includes(searchTerm.toLowerCase()));
return testTypes?.filter((testType) =>
testType.synonyms.some((name) => name.toLowerCase().includes(searchTerm.toLowerCase())),
);
}
}, [searchTerm, testTypes]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ mockOpenrsFetch.mockImplementation((url: string) => {
});

describe('useTestTypes is configurable', () => {
it('should return all Test concepts when no labOrderableConcepts are provided', async () => {
it('should return all test concepts when no labOrderableConcepts are provided', async () => {
const { result } = renderHook(() => useTestTypes());
expect(mockOpenrsFetch).toHaveBeenCalledWith(
'/ws/rest/v1/concept?class=Test?v=custom:(display,uuid,setMembers:(display,uuid,setMembers:(display,uuid)))',
'/ws/rest/v1/concept?class=Test?v=custom:(display,names,uuid,setMembers:(display,uuid,setMembers:(display,uuid,names)))',
denniskigen marked this conversation as resolved.
Show resolved Hide resolved
);
await waitFor(() => expect(result.current.isLoading).toBeFalsy());
expect(result.current.error).toBeFalsy();
Expand All @@ -54,7 +54,7 @@ describe('useTestTypes is configurable', () => {
const { result } = renderHook(() => useTestTypes());
expect(mockOpenrsFetch).toHaveBeenCalledWith(
expect.stringContaining(
'/ws/rest/v1/concept?class=Test?v=custom:(display,uuid,setMembers:(display,uuid,setMembers:(display,uuid)))',
'/ws/rest/v1/concept?class=Test?v=custom:(display,names,uuid,setMembers:(display,uuid,setMembers:(display,uuid,names)))',
),
);
await waitFor(() => expect(result.current.isLoading).toBeFalsy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type ConceptResults = FetchResponse<{ results: Array<Concept> }>;
export interface TestType {
label: string;
conceptUuid: string;
synonyms: string[];
}

export interface UseTestType {
Expand All @@ -31,9 +32,9 @@ function useTestConceptsSWR(labOrderableConcepts?: Array<string>) {
labOrderableConcepts
? labOrderableConcepts.map(
(c) =>
`${restBaseUrl}/concept/${c}?v=custom:(display,uuid,setMembers:(display,uuid,setMembers:(display,uuid)))`,
`${restBaseUrl}/concept/${c}?v=custom:(display,names,uuid,setMembers:(display,uuid,names,setMembers:(display,uuid,names)))`,
)
: `${restBaseUrl}/concept?class=Test?v=custom:(display,uuid,setMembers:(display,uuid,setMembers:(display,uuid)))`,
: `${restBaseUrl}/concept?class=Test?v=custom:(display,names,uuid,setMembers:(display,uuid,setMembers:(display,uuid,names)))`,
(labOrderableConcepts ? openmrsFetchMultiple : openmrsFetch) as any,
{
shouldRetryOnError(err) {
Expand All @@ -58,7 +59,6 @@ function useTestConceptsSWR(labOrderableConcepts?: Array<string>) {

export function useTestTypes(): UseTestType {
const { labOrderableConcepts } = useConfig<ConfigObject>().orders;

const { data, isLoading, error } = useTestConceptsSWR(labOrderableConcepts.length ? labOrderableConcepts : null);

useEffect(() => {
Expand All @@ -73,6 +73,7 @@ export function useTestTypes(): UseTestType {
?.map((concept) => ({
label: concept.display,
conceptUuid: concept.uuid,
synonyms: concept.names?.flatMap((name) => name.display) ?? [],
}))
?.sort((testConcept1, testConcept2) => testConcept1.label.localeCompare(testConcept2.label))
?.filter((item, pos, array) => !pos || array[pos - 1].conceptUuid !== item.conceptUuid),
Expand Down
3 changes: 3 additions & 0 deletions packages/esm-patient-labs-app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export interface Concept {
display: string;
name: string;
};
names: Array<{
display: string;
}>;
answers: [];
setMembers: [];
hiNormal: number;
Expand Down