Skip to content

Commit

Permalink
(feat) O3-2430: User should be able to look up frequency in dropdown …
Browse files Browse the repository at this point in the history
…by abbreviation (#1767)

Co-authored-by: Dennis Kigen <[email protected]>
Co-authored-by: Ian <[email protected]>
  • Loading branch information
3 people authored May 17, 2024
1 parent eb476fe commit 0894ef4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
20 changes: 19 additions & 1 deletion e2e/specs/drug-orders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,25 @@ test('Record, edit and discontinue a drug order', async ({ page }) => {
});

await test.step('And I change the frequency to `Twice daily`', async () => {
await page.getByPlaceholder(/frequency/i).click();
await page.getByPlaceholder(/frequency/i).clear();
await page.getByText('Twice daily', { exact: true }).click();
});

await test.step('And I set the frequency to `q12`', async () => {
await page.getByPlaceholder(/frequency/i).clear();
await page.getByPlaceholder(/frequency/i).fill('q12');
await page.getByText('Every twelve hours', { exact: true }).click();
});

await test.step('And I set the frequency to `od`', async () => {
await page.getByPlaceholder(/frequency/i).clear();
await page.getByPlaceholder(/frequency/i).fill('od');
await page.getByText('Once daily', { exact: true }).click();
});

await test.step('And I set the frequency to `bd`', async () => {
await page.getByPlaceholder(/frequency/i).clear();
await page.getByPlaceholder(/frequency/i).fill('bd');
await page.getByText('Twice daily', { exact: true }).click();
});

Expand Down
7 changes: 6 additions & 1 deletion packages/esm-patient-common-lib/src/workspaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type DefaultWorkspaceProps, launchWorkspace, navigateAndLaunchWorkspace, usePatient } from '@openmrs/esm-framework';
import {
type DefaultWorkspaceProps,
launchWorkspace,
navigateAndLaunchWorkspace,
usePatient,
} from '@openmrs/esm-framework';
import { getPatientUuidFromUrl } from './get-patient-uuid-from-url';
import { useSystemVisitSetting } from './useSystemVisitSetting';
import { useVisitOrOfflineVisit } from './offline/visit';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,16 @@ export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, prompt
[orderConfigObject, config?.daysDurationUnit],
);

const orderFrequencies: Array<MedicationFrequency> = useMemo(
() => orderConfigObject?.orderFrequencies ?? [],
[orderConfigObject],
);
const orderFrequencies: Array<MedicationFrequency> = useMemo(() => {
return orderConfigObject?.orderFrequencies ?? [];
}, [orderConfigObject]);

const filterItems = useCallback((menu) => {
if (menu?.inputValue?.length) {
return menu.item?.names?.some((abbr: string) => abbr.toLowerCase().includes(menu.inputValue.toLowerCase()));
}
return menu?.item?.names ?? [];
}, []);

const [showStickyMedicationHeader, setShowMedicationHeader] = useState(false);
const { patient, isLoading: isLoadingPatientDetails } = usePatient();
Expand Down Expand Up @@ -479,6 +485,7 @@ export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, prompt
size={isTablet ? 'lg' : 'md'}
id="editFrequency"
items={orderFrequencies}
shouldFilterItem={filterItems}
placeholder={t('editFrequencyComboBoxTitle', 'Frequency')}
titleText={t('editFrequencyComboBoxTitle', 'Frequency')}
itemToString={(item) => item?.value}
Expand Down Expand Up @@ -768,6 +775,8 @@ const ControlledFieldInput = ({
control,
getValues,
handleAfterChange,
optionsWithAbbreviations,
orderFrequencies,
...restProps
}: ControlledFieldInputProps) => {
const {
Expand Down
33 changes: 25 additions & 8 deletions packages/esm-patient-medications-app/src/api/order-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ import {
type QuantityUnit,
} from '../types';

export interface ConceptName {
uuid: string;
display: string;
}
export interface CommonConfigProps {
uuid: string;
display: string;
concept?: {
names: ConceptName[];
};
}

export interface OrderConfig {
Expand All @@ -37,6 +44,14 @@ export function useOrderConfig(): {
`${restBaseUrl}/orderentryconfig`,
openmrsFetch,
);
const {
data: frequencyData,
error: frequencyError,
isLoading: frequencyLoading,
} = useSWRImmutable<{ data: OrderConfig }, Error>(
`${restBaseUrl}/orderentryconfig?v=custom:(uuid,display,concept:(names:(display,uuid)))`,
openmrsFetch,
);

const results = useMemo(
() => ({
Expand All @@ -57,16 +72,18 @@ export function useOrderConfig(): {
valueCoded: uuid,
value: display,
})),
orderFrequencies: data?.data?.orderFrequencies?.map(({ uuid, display }) => ({
valueCoded: uuid,
value: display,
})),
orderFrequencies: frequencyData?.data?.orderFrequencies?.map(({ uuid, display, concept }) => {
return {
valueCoded: uuid,
value: display,
names: concept.names.map((name) => name.display),
};
}),
},
isLoading,
error,
isLoading: isLoading || frequencyLoading,
error: error || frequencyError,
}),
[data, error, isLoading],
[data, error, isLoading, frequencyData, frequencyError, frequencyLoading],
);

return results;
}
1 change: 1 addition & 0 deletions packages/esm-patient-medications-app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ interface CommonMedicationProps {

export interface CommonMedicationValueCoded extends CommonMedicationProps {
valueCoded: string;
names?: string[];
}

0 comments on commit 0894ef4

Please sign in to comment.