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) O3-2430: User should be able to look up frequency in dropdown by abbreviation #1767

Merged
merged 20 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b111f73
add frequency through abbreviation
piyushmishra1416 Mar 31, 2024
e39432b
improved handleInputchange logic
piyushmishra1416 Mar 31, 2024
a21f756
Merge branch 'main' into O3-2430
denniskigen Apr 19, 2024
287752f
improved logic for searching through abbreviation
piyushmishra1416 Apr 22, 2024
aed4530
Merge branch 'O3-2430' of github.com:piyushmishra1416/openmrs-esm-pat…
piyushmishra1416 Apr 22, 2024
c7ab612
Merge branch 'main' of github.com:openmrs/openmrs-esm-patient-chart i…
piyushmishra1416 Apr 29, 2024
520f4e3
added two separate urls to fetch data
piyushmishra1416 Apr 29, 2024
bbb79f7
changed abbreviation to names
piyushmishra1416 May 6, 2024
a5eeef6
Merge branch 'main' of github.com:openmrs/openmrs-esm-patient-chart i…
piyushmishra1416 May 6, 2024
23e4c14
added test for names
piyushmishra1416 May 6, 2024
e537fc0
Merge branch 'main' into O3-2430
denniskigen May 7, 2024
8699b58
removed commented code
piyushmishra1416 May 8, 2024
621e326
Merge branch 'main' of github.com:openmrs/openmrs-esm-patient-chart i…
piyushmishra1416 May 9, 2024
1fc2874
Merge branch 'main' of github.com:openmrs/openmrs-esm-patient-chart i…
piyushmishra1416 May 9, 2024
0e823f8
Merge branch 'O3-2430' of github.com:piyushmishra1416/openmrs-esm-pat…
piyushmishra1416 May 9, 2024
13abb92
Update packages/esm-patient-medications-app/src/api/order-config.ts
piyushmishra1416 May 9, 2024
1d85c38
Merge branch 'O3-2430' of github.com:piyushmishra1416/openmrs-esm-pat…
piyushmishra1416 May 10, 2024
bfec996
added usememo hook to the filteritems
piyushmishra1416 May 10, 2024
a56a6b1
used useCallback hook
piyushmishra1416 May 17, 2024
1a80b07
Merge branch 'main' of github.com:openmrs/openmrs-esm-patient-chart i…
piyushmishra1416 May 17, 2024
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
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;
}
denniskigen marked this conversation as resolved.
Show resolved Hide resolved
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[];
}
Loading