Skip to content

Commit

Permalink
Misc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen committed Dec 16, 2024
1 parent 3e4b478 commit f6cf58c
Show file tree
Hide file tree
Showing 18 changed files with 553 additions and 535 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"eslint-plugin-unused-imports": "^2.0.0",
"husky": "^6.0.0",
"i18next": "^21.10.0",
"i18next-parser": "^6.6.0",
"i18next-parser": "^9.0.2",
"identity-obj-proxy": "^3.0.0",
"jest": "^28.1.3",
"jest-cli": "^28.1.3",
Expand Down
2 changes: 1 addition & 1 deletion src/dispensing-tiles/dispensing-tiles.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styles from './dispensing-tiles.scss';

const DispensingTiles: React.FC = () => {
const { t } = useTranslation();
const { metrics, isError, isLoading } = useMetrics();
const { metrics, error, isLoading } = useMetrics();

if (isLoading) {
return <DataTableSkeleton role="progressbar" />;
Expand Down
2 changes: 1 addition & 1 deletion src/dispensing-tiles/dispensing-tiles.resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useMetrics() {

return {
metrics: metrics,
isError: error,
error,
isLoading: !data && !error,
};
}
Expand Down
22 changes: 0 additions & 22 deletions src/dispensing.test.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
/**
* This is the root test for this page. It simply checks that the page
* renders. If the components of your page are highly interdependent,
* (e.g., if the `Hello` component had state that communicated
* information between `Greeter` and `PatientGetter`) then you might
* want to do most of your testing here. If those components are
* instead quite independent (as is the case in this example), then
* it would make more sense to test those components independently.
*
* The key thing to remember, always, is: write tests that behave like
* users. They should *look* for elements by their visual
* characteristics, *interact* with them, and (mostly) *assert* based
* on things that would be visually apparent to a user.
*
* To learn more about how we do testing, see the following resources:
* https://kentcdodds.com/blog/how-to-know-what-to-test
* https://kentcdodds.com/blog/testing-implementation-details
* https://kentcdodds.com/blog/common-mistakes-with-react-testing-library
*
* Kent C. Dodds is the inventor of `@testing-library`:
* https://testing-library.com/docs/guiding-principles
*/
import React from 'react';
import { render } from '@testing-library/react';
import Dispensing from './dispensing.component';
Expand Down
12 changes: 5 additions & 7 deletions src/history/history-and-comments.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const HistoryAndComments: React.FC<{
const { t } = useTranslation();
const session = useSession();
const config = useConfig<PharmacyConfig>();
const { medicationRequestBundles, prescriptionDate, isError, isLoading } = usePrescriptionDetails(
const { medicationRequestBundles, prescriptionDate, error, isLoading } = usePrescriptionDetails(
encounterUuid,
config.refreshInterval,
);
Expand All @@ -60,7 +60,7 @@ const HistoryAndComments: React.FC<{
(performer) =>
performer?.actor?.reference?.length > 1 &&
performer.actor.reference.split('/')[1] === session.currentProvider.uuid,
) != null
) !== null
) {
return true;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ const HistoryAndComments: React.FC<{
props: Record<string, unknown>;
};
const workspaceTitle = getWorkspaceTitle(medicationDispense);
launchWorkspace(workspaceName, { workspaceTitle, ...props, });
launchWorkspace(workspaceName, { workspaceTitle, ...props });
};

if (!editable && !deletable) {
Expand All @@ -145,9 +145,7 @@ const HistoryAndComments: React.FC<{
flipped={true}
className={styles.medicationEventActionMenu}>
{editable && (
<OverflowMenuItem
onClick={handleEdit}
itemText={t('editRecord', 'Edit Record')}></OverflowMenuItem>
<OverflowMenuItem onClick={handleEdit} itemText={t('editRecord', 'Edit record')}></OverflowMenuItem>
)}
{deletable && (
<OverflowMenuItem
Expand Down Expand Up @@ -215,7 +213,7 @@ const HistoryAndComments: React.FC<{
return (
<div className={styles.historyAndCommentsContainer}>
{isLoading && <DataTableSkeleton role="progressbar" />}
{isError && <p>{t('error', 'Error')}</p>}
{error && <p>{t('error', 'Error')}</p>}
{medicationRequestBundles &&
medicationRequestBundles
.flatMap((medicationDispenseBundle) => medicationDispenseBundle.dispenses)
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const pauseActionButton = getSyncLifecycle(PauseActionButton, options);
// Dispensing workspace
// t('closePrescription', 'Close prescription')
export const closeDispenseWorkspace = getAsyncLifecycle(() => import('./forms/close-dispense-form.workspace'), options);
// t('dispensDPrescription', 'Dispense prescription')
// t('dispensePrescription', 'Dispense prescription')
export const dispenseWorkspace = getAsyncLifecycle(() => import('./forms/dispense-form.workspace'), options);
// t('pausePrescription', 'Pause prescription')
export const pauseDispenseWorkspace = getAsyncLifecycle(() => import('./forms/pause-dispense-form.workspace'), options);
Expand Down
2 changes: 1 addition & 1 deletion src/location/location.resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function useLocationForFiltering(config: PharmacyConfig) {

return {
filterLocations,
isError: error,
error,
isLoading: !filterLocations && !error,
};
}
4 changes: 2 additions & 2 deletions src/medication-dispense/medication-dispense.resource.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fhirBaseUrl, restBaseUrl, openmrsFetch, type Session } from '@openmrs/esm-framework';
import dayjs from 'dayjs';
import useSWR from 'swr';
import { fhirBaseUrl, restBaseUrl, openmrsFetch, type Session } from '@openmrs/esm-framework';
import {
type MedicationDispense,
type MedicationDispenseStatus,
Expand Down Expand Up @@ -51,8 +51,8 @@ export function useOrderConfig() {
);
return {
orderConfigObject: data ? data.data : null,
error,
isLoading: !data && !error,
isError: error,
isValidating,
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/medication-request/medication-request.resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function usePrescriptionDetails(encounterUuid: string, refreshInterval =
return {
medicationRequestBundles,
prescriptionDate,
isError: error,
error,
isLoading,
};
}
Expand All @@ -193,7 +193,7 @@ export function usePatientAllergies(patientUuid: string, refreshInterval) {
return {
allergies,
totalAllergies: data?.data.total,
isError: error,
error,
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/prescriptions/prescription-actions.component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { Layer } from '@carbon/react';
import PrescriptionPrintAction from '../print-prescription/prescription-print-action.component';
import styles from './prescription-actions.scss';
import { Layer } from '@carbon/react';

type PrescriptionsActionsFooterProps = {
encounterUuid: string;
patientUuid: string;
Expand Down
2 changes: 1 addition & 1 deletion src/prescriptions/prescription-actions.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use '@carbon/colors';
@use '@carbon/layout';
@use '@carbon/type';
@use '@carbon/colors';

.actionsContainer {
flex-direction: row;
Expand Down
9 changes: 3 additions & 6 deletions src/prescriptions/prescription-details.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { PRIVILEGE_CREATE_DISPENSE } from '../constants';
import { usePatientAllergies, usePrescriptionDetails } from '../medication-request/medication-request.resource';
import ActionButtons from '../components/action-buttons.component';
import MedicationEvent from '../components/medication-event.component';
import styles from './prescription-details.scss';
import PrescriptionsActionsFooter from './prescription-actions.component';
import styles from './prescription-details.scss';

const PrescriptionDetails: React.FC<{
encounterUuid: string;
Expand All @@ -21,10 +21,7 @@ const PrescriptionDetails: React.FC<{
const config = useConfig<PharmacyConfig>();
const [isAllergiesLoading, setAllergiesLoadingStatus] = useState(true);
const { allergies, totalAllergies } = usePatientAllergies(patientUuid, config.refreshInterval);
const { medicationRequestBundles, isError, isLoading } = usePrescriptionDetails(
encounterUuid,
config.refreshInterval,
);
const { medicationRequestBundles, error, isLoading } = usePrescriptionDetails(encounterUuid, config.refreshInterval);

useEffect(() => {
if (typeof totalAllergies == 'number') {
Expand Down Expand Up @@ -92,7 +89,7 @@ const PrescriptionDetails: React.FC<{
)}
<h5 style={{ paddingTop: '8px', paddingBottom: '8px', fontSize: '0.9rem' }}>{t('prescribed', 'Prescribed')}</h5>
{isLoading && <DataTableSkeleton role="progressbar" />}
{isError && <p>{t('error', 'Error')}</p>}
{error && <p>{t('error', 'Error')}</p>}
{medicationRequestBundles &&
medicationRequestBundles.map((bundle) => {
return (
Expand Down
25 changes: 11 additions & 14 deletions src/print-prescription/prescription-print-preview.modal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import React, { useRef, useState } from 'react';
import { useReactToPrint } from 'react-to-print';
import { useTranslation } from 'react-i18next';
import {
Button,
ButtonSet,
Expand All @@ -8,13 +11,10 @@ import {
ModalHeader,
} from '@carbon/react';
import { ErrorState, getCoreTranslation } from '@openmrs/esm-framework';
import React, { useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useReactToPrint } from 'react-to-print';
import { usePrescriptionDetails } from '../medication-request/medication-request.resource';
import PrescriptionsPrintout from './prescription-printout.component';
import styles from './print-prescription.scss';
import PrintablePrescriptionsSelector from './printable-prescriptions.component';
import styles from './print-prescription.scss';

type PrescriptionPrintPreviewModalProps = {
onClose: () => void;
Expand All @@ -23,17 +23,14 @@ type PrescriptionPrintPreviewModalProps = {
status: string;
};

const PrescriptionPrintPreviewModal: React.FC<PrescriptionPrintPreviewModalProps> = ({
onClose,
encounterUuid,
patientUuid,
status,
}) => {
const PrescriptionPrintPreviewModal: React.FC<PrescriptionPrintPreviewModalProps> = ({ onClose, encounterUuid }) => {
const { t } = useTranslation();
const { medicationRequestBundles, isError, isLoading } = usePrescriptionDetails(encounterUuid);
const { medicationRequestBundles, error, isLoading } = usePrescriptionDetails(encounterUuid);

const [excludedPrescriptions, setExcludedPrescriptions] = useState<string[]>([]);
const componentRef = useRef<HTMLDivElement>(null);
const [printError, setPrintError] = useState<string | null>(null);
const componentRef = useRef<HTMLDivElement>(null);

const handlePrint = useReactToPrint({
content: () => componentRef.current,
onBeforeGetContent: () => {
Expand All @@ -48,7 +45,7 @@ const PrescriptionPrintPreviewModal: React.FC<PrescriptionPrintPreviewModalProps
return (
<>
<ModalHeader closeModal={onClose} className={styles.title}>
{t('printPrescriptions', 'Print Prescriptions')}
{t('printPrescriptions', 'Print prescriptions')}
</ModalHeader>
<ModalBody>
{isLoading && (
Expand All @@ -58,7 +55,7 @@ const PrescriptionPrintPreviewModal: React.FC<PrescriptionPrintPreviewModalProps
description={t('loading', 'Loading prescriptions') + '....'}
/>
)}
{isError && <ErrorState error={isError} headerTitle={t('error', 'Error')} />}
{error && <ErrorState error={error} headerTitle={t('error', 'Error')} />}
{!isLoading && medicationRequestBundles?.length > 0 && (
<div className={styles.printoutSelectorRow}>
<PrintablePrescriptionsSelector
Expand Down
15 changes: 9 additions & 6 deletions src/print-prescription/prescription-printout.component.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Layer, StructuredListBody, StructuredListCell, StructuredListRow, StructuredListWrapper } from '@carbon/react';
import { formatDate, parseDate, useSession } from '@openmrs/esm-framework';
import classNames from 'classnames';
import React from 'react';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import { Layer, StructuredListBody, StructuredListCell, StructuredListRow, StructuredListWrapper } from '@carbon/react';
import { formatDate, parseDate, useSession } from '@openmrs/esm-framework';
import { type DosageInstruction, type MedicationRequestBundle, type Quantity } from '../types';
import {
getDosageInstruction,
Expand Down Expand Up @@ -34,7 +34,7 @@ const PrescriptionsPrintout: React.FC<PrescriptionsPrintoutProps> = ({ medicatio
<StructuredListCell head>
<br />
<br />
<p className={styles.printoutTitle}>{t('prescriptionInstructions', 'Prescription Instructions')}</p>
<p className={styles.printoutTitle}>{t('prescriptionInstructions', 'Prescription instructions')}</p>
{patient && (
<p className={classNames(styles.patientName, styles.faintText)}>
{extractPatientName(patient.display)}
Expand All @@ -50,7 +50,8 @@ const PrescriptionsPrintout: React.FC<PrescriptionsPrintoutProps> = ({ medicatio
const medicationEvent = request.request;
const dosageInstruction: DosageInstruction = getDosageInstruction(medicationEvent.dosageInstruction);
const quantity: Quantity = getQuantity(medicationEvent);
const refillsAllowed: number = getRefillsAllowed(medicationEvent);
const numberOfRefillsAllowed: number = getRefillsAllowed(medicationEvent);

return (
<div key={index}>
{dosageInstruction && (
Expand Down Expand Up @@ -99,7 +100,9 @@ const PrescriptionsPrintout: React.FC<PrescriptionsPrintoutProps> = ({ medicatio
<span className={styles.faintText}>{t('refills', 'Refills')}</span>
{': '}{' '}
<span>
{refillsAllowed || refillsAllowed === 0 ? refillsAllowed : t('notRefills', 'No Refills')}
{numberOfRefillsAllowed || numberOfRefillsAllowed === 0
? numberOfRefillsAllowed
: t('noRefills', 'No refills')}
</span>
</p>

Expand Down
2 changes: 1 addition & 1 deletion src/print-prescription/print-prescription.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use '@carbon/colors';
@use '@carbon/layout';
@use '@carbon/type';
@use '@carbon/colors';

.title {
@include type.type-style('heading-02');
Expand Down
7 changes: 5 additions & 2 deletions src/print-prescription/printable-prescriptions.component.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useCallback } from 'react';
import { type DosageInstruction, type MedicationRequestBundle } from '../types';
import { getDosageInstruction, getMedicationDisplay, getMedicationReferenceOrCodeableConcept } from '../utils';
import { Checkbox } from '@carbon/react';
import { useTranslation } from 'react-i18next';
import { type DosageInstruction, type MedicationRequestBundle } from '../types';
import { getDosageInstruction, getMedicationDisplay, getMedicationReferenceOrCodeableConcept } from '../utils';

type PrintablePrescriptionsSelectorProps = {
medicationRequests: Array<MedicationRequestBundle>;
Expand All @@ -16,6 +16,7 @@ const PrintablePrescriptionsSelector: React.FC<PrintablePrescriptionsSelectorPro
excludedPrescription,
}) => {
const { t } = useTranslation();

const handleChange = useCallback(
(checked: boolean, medicationEventId: string) => {
if (checked) {
Expand All @@ -26,6 +27,7 @@ const PrintablePrescriptionsSelector: React.FC<PrintablePrescriptionsSelectorPro
},
[onExcludedPrescriptionChange, excludedPrescription],
);

return (
<div>
<p>
Expand All @@ -34,6 +36,7 @@ const PrintablePrescriptionsSelector: React.FC<PrintablePrescriptionsSelectorPro
{medicationRequests?.map((request) => {
const medicationEvent = request.request;
const dosageInstruction: DosageInstruction = getDosageInstruction(medicationEvent.dosageInstruction);

return (
<div key={medicationEvent.id}>
{dosageInstruction && (
Expand Down
Loading

0 comments on commit f6cf58c

Please sign in to comment.