Skip to content

Commit

Permalink
(feat) Remove implementer-specific logic from Programs widget (#1389)
Browse files Browse the repository at this point in the history
Co-authored-by: Dennis Kigen <[email protected]>
  • Loading branch information
donaldkibet and denniskigen authored Oct 19, 2023
1 parent 5ba3187 commit e38a041
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 147 deletions.
4 changes: 0 additions & 4 deletions packages/esm-patient-programs-app/src/config-schema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Type } from '@openmrs/esm-framework';

export const configSchema = {
customUrl: {
_type: Type.String,
_default: '',
},
hideAddProgramButton: {
_type: Type.Boolean,
_default: false,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import {
Button,
Expand Down Expand Up @@ -38,17 +38,17 @@ interface ProgramEditButtonProps {

const ProgramsDetailedSummary: React.FC<ProgramsDetailedSummaryProps> = ({ patientUuid }) => {
const { t } = useTranslation();
const displayText = t('programEnrollments', 'Program enrollments');
const headerTitle = t('carePrograms', 'Care Programs');
const config = useConfig() as ConfigObject;
const layout = useLayoutType();
const isTablet = layout === 'tablet';
const isDesktop = desktopLayout(layout);
const { hideAddProgramButton } = useConfig<ConfigObject>();
const displayText = t('programEnrollments', 'Program enrollments');
const headerTitle = t('carePrograms', 'Care Programs');

const { enrollments, isLoading, isError, isValidating, availablePrograms, eligiblePrograms } =
usePrograms(patientUuid);

const tableHeaders: Array<typeof DataTableHeader> = React.useMemo(
const tableHeaders: Array<typeof DataTableHeader> = useMemo(
() => [
{
key: 'display',
Expand All @@ -70,7 +70,7 @@ const ProgramsDetailedSummary: React.FC<ProgramsDetailedSummaryProps> = ({ patie
[t],
);

const tableRows = React.useMemo(() => {
const tableRows = useMemo(() => {
return enrollments?.map((program) => {
return {
id: program.uuid,
Expand All @@ -84,7 +84,7 @@ const ProgramsDetailedSummary: React.FC<ProgramsDetailedSummaryProps> = ({ patie
});
}, [enrollments, t]);

const launchProgramsForm = React.useCallback(() => launchPatientWorkspace('programs-form-workspace'), []);
const launchProgramsForm = useCallback(() => launchPatientWorkspace('programs-form-workspace'), []);

if (isLoading) return <DataTableSkeleton role="progressbar" compact={isDesktop} zebra />;
if (isError) return <ErrorState error={isError} headerTitle={headerTitle} />;
Expand All @@ -93,7 +93,7 @@ const ProgramsDetailedSummary: React.FC<ProgramsDetailedSummaryProps> = ({ patie
<div className={styles.widgetCard}>
<CardHeader title={headerTitle}>
<span>{isValidating ? <InlineLoading /> : null}</span>
{config.hideAddProgramButton ? null : (
{hideAddProgramButton ? null : (
<Button
kind="ghost"
renderIcon={(props) => <Add size={16} {...props} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const ProgramsForm: React.FC<ProgramsFormProps> = ({ closeWorkspace, patientUuid

const formGroups = [
{
style: { maxWidth: '50%' },
style: { maxWidth: isTablet ? '50%' : 'fit-content' },
legendText: t('programName', 'Program name'),
value: programSelect,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import capitalize from 'lodash-es/capitalize';
import {
Button,
DataTable,
Expand Down Expand Up @@ -33,7 +32,6 @@ import {
isDesktop as desktopLayout,
} from '@openmrs/esm-framework';
import { usePrograms } from './programs.resource';
import ProgramActionButton from './program-action-button/program-action-button.component';
import { ConfigurableProgram } from '../types';
import styles from './programs-overview.scss';

Expand All @@ -50,27 +48,14 @@ const ProgramsOverview: React.FC<ProgramsOverviewProps> = ({ basePath, patientUu
const headerTitle = t('carePrograms', 'Care Programs');
const urlLabel = t('seeAll', 'See all');
const pageUrl = `\${openmrsSpaBase}/patient/${patientUuid}/chart/Programs`;
const isConfigurable = config.customUrl ? true : false;
const layout = useLayoutType();
const isTablet = layout === 'tablet';
const isDesktop = desktopLayout(layout);

const {
activeEnrollments,
availablePrograms,
configurablePrograms,
eligiblePrograms,
enrollments,
isError,
isLoading,
isValidating,
} = usePrograms(patientUuid);
const { activeEnrollments, availablePrograms, eligiblePrograms, enrollments, isError, isLoading, isValidating } =
usePrograms(patientUuid);

const {
results: paginatedEnrollments,
goTo,
currentPage,
} = usePagination(isConfigurable ? configurablePrograms : enrollments ?? [], programsCount);
const { results: paginatedEnrollments, goTo, currentPage } = usePagination(enrollments ?? [], programsCount);

const launchProgramsForm = React.useCallback(() => launchPatientWorkspace('programs-form-workspace'), []);

Expand Down Expand Up @@ -103,18 +88,15 @@ const ProgramsOverview: React.FC<ProgramsOverviewProps> = ({ basePath, patientUu
display: enrollment.display,
location: enrollment.location?.display ?? '--',
dateEnrolled: enrollment.dateEnrolled ? formatDatetime(new Date(enrollment.dateEnrolled)) : '--',
status: isConfigurable
? capitalize(enrollment.enrollmentStatus)
: enrollment.dateCompleted
status: enrollment.dateCompleted
? `${t('completedOn', 'Completed On')} ${formatDate(new Date(enrollment.dateCompleted))}`
: t('active', 'Active'),
actions: <ProgramActionButton enrollment={enrollment} />,
}));
}, [isConfigurable, paginatedEnrollments, t]);
}, [paginatedEnrollments, t]);

if (isLoading) return <DataTableSkeleton role="progressbar" compact={isDesktop} zebra />;
if (isError) return <ErrorState error={isError} headerTitle={headerTitle} />;
if (isConfigurable ? configurablePrograms.length : activeEnrollments?.length) {
if (activeEnrollments?.length) {
return (
<div className={styles.widgetCard}>
<CardHeader title={headerTitle}>
Expand Down Expand Up @@ -177,7 +159,7 @@ const ProgramsOverview: React.FC<ProgramsOverviewProps> = ({ basePath, patientUu
onPageNumberChange={({ page }) => goTo(page)}
pageNumber={currentPage}
pageSize={programsCount}
totalItems={isConfigurable ? configurablePrograms.length : enrollments?.length}
totalItems={enrollments?.length}
dashboardLinkUrl={pageUrl}
dashboardLinkLabel={urlLabel}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,7 @@ export function updateProgramEnrollment(programEnrollmentUuid: string, payload,
});
}

export const useConfigurableProgram = (patientUuid: string) => {
const { customUrl } = useConfig() as ConfigObject;
const { data, error, isLoading } = useSWR<{ data: Array<ConfigurableProgram> }>(
customUrl ? `${customUrl}${patientUuid}` : null,
openmrsFetch,
);
const configurablePrograms = data?.data ?? [];
return {
configurablePrograms,
isLoading,
error: error,
};
};

export const usePrograms = (patientUuid: string) => {
const { customUrl } = useConfig() as ConfigObject;
const {
data: enrollments,
isError: enrollError,
Expand All @@ -115,18 +100,14 @@ export const usePrograms = (patientUuid: string) => {
activeEnrollments,
} = useEnrollments(patientUuid);
const { data: availablePrograms, eligiblePrograms } = useAvailablePrograms(enrollments);
const { configurablePrograms, isLoading: configLoading, error: configError } = useConfigurableProgram(patientUuid);

const status = customUrl
? { isLoading: configLoading, isError: configError }
: { isLoading: enrolLoading, isError: enrollError };
const status = { isLoading: enrolLoading, isError: enrollError };
return {
enrollments,
...status,
isValidating,
activeEnrollments,
availablePrograms,
eligiblePrograms,
configurablePrograms,
};
};
5 changes: 0 additions & 5 deletions packages/esm-patient-programs-app/translations/am.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
"configurePrograms": "Please configure programs to continue.",
"dateCompleted": "Date completed",
"dateEnrolled": "Date enrolled",
"discontinue": "Discontinue",
"discontinueEnrollment": "Discontinue enrollment",
"editProgram": "Edit Program",
"enroll": "Enroll",
"enrollment": "Enrollment",
"enrollmentLocation": "Enrollment location",
"enrollmentNowVisible": "It is now visible in the Programs table",
"enrollmentSaved": "Program enrollment saved",
"enrollmentUpdated": "Program enrollment updated",
"enrollmentUpdatesNowVisible": "Changes to the program are now visible in the Programs table",
"enrollProgram": "Enroll to program",
"fullyEnrolled": "Enrolled in all programs",
"location": "Location",
"noEligibleEnrollments": "There are no more programs left to enroll this patient in",
Expand Down
5 changes: 0 additions & 5 deletions packages/esm-patient-programs-app/translations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
"configurePrograms": "يرجى تكوين البرامج للمتابعة.",
"dateCompleted": "تاريخ الاكتمال",
"dateEnrolled": "تاريخ التسجيل",
"discontinue": "إيقاف",
"discontinueEnrollment": "إيقاف التسجيل",
"editProgram": "تعديل البرنامج",
"enroll": "سجل",
"enrollment": "التسجيل",
"enrollmentLocation": "موقع التسجيل",
"enrollmentNowVisible": "أصبح الآن مرئيًا في جدول البرامج",
"enrollmentSaved": "تم حفظ التسجيل في البرنامج",
"enrollmentUpdated": "تم تحديث التسجيل في البرنامج",
"enrollmentUpdatesNowVisible": "أصبحت التغييرات في البرنامج مرئية الآن في جدول البرامج",
"enrollProgram": "التسجيل في البرنامج",
"fullyEnrolled": "تم التسجيل في جميع البرامج",
"location": "الموقع",
"noEligibleEnrollments": "لا توجد برامج أخرى لتسجيل هذا المريض فيها",
Expand Down
5 changes: 0 additions & 5 deletions packages/esm-patient-programs-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
"configurePrograms": "Please configure programs to continue.",
"dateCompleted": "Date completed",
"dateEnrolled": "Date enrolled",
"discontinue": "Discontinue",
"discontinueEnrollment": "Discontinue enrollment",
"editProgram": "Edit Program",
"enroll": "Enroll",
"enrollment": "Enrollment",
"enrollmentLocation": "Enrollment location",
"enrollmentNowVisible": "It is now visible in the Programs table",
"enrollmentSaved": "Program enrollment saved",
"enrollmentUpdated": "Program enrollment updated",
"enrollmentUpdatesNowVisible": "Changes to the program are now visible in the Programs table",
"enrollProgram": "Enroll to program",
"fullyEnrolled": "Enrolled in all programs",
"location": "Location",
"noEligibleEnrollments": "There are no more programs left to enroll this patient in",
Expand Down
5 changes: 0 additions & 5 deletions packages/esm-patient-programs-app/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
"configurePrograms": "Por favor, configure programas para continuar.",
"dateCompleted": "Fecha de finalización",
"dateEnrolled": "Fecha de inscripción",
"discontinue": "Suspender",
"discontinueEnrollment": "Suspender inscripción",
"editProgram": "Editar programa",
"enroll": "Inscribir",
"enrollment": "Inscripción",
"enrollmentLocation": "Ubicación de inscripción",
"enrollmentNowVisible": "Ahora es visible en la tabla de Programas",
"enrollmentSaved": "Inscripción en programa guardada",
"enrollmentUpdated": "Inscripción en programa actualizada",
"enrollmentUpdatesNowVisible": "Cambios en el programa ahora son visibles en la tabla de Programas",
"enrollProgram": "Inscribir en programa",
"fullyEnrolled": "Inscrito en todos los programas",
"location": "Ubicación",
"noEligibleEnrollments": "No quedan programas disponibles para inscribir a este paciente",
Expand Down
5 changes: 0 additions & 5 deletions packages/esm-patient-programs-app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
"configurePrograms": "Veuillez configurer des programmes pour continuer.",
"dateCompleted": "Date de fin",
"dateEnrolled": "Date d'enregistrement",
"discontinue": "Cesser",
"discontinueEnrollment": "Discontinue enrollment",
"editProgram": "Edit Program",
"enroll": "Enregistrer",
"enrollment": "Enregistrement",
"enrollmentLocation": "Lieu d'enregistrement",
"enrollmentNowVisible": "C'est maintenant visible dans le tableau des programmes",
"enrollmentSaved": "Enregistrement dans le programme sauvegardé",
"enrollmentUpdated": "Enregistrement dans le programme mis à jour",
"enrollmentUpdatesNowVisible": "Les modifications du programme sont désormais visibles dans le tableau des programmes",
"enrollProgram": "Enroll to program",
"fullyEnrolled": "Enregistré dans tous les programmes",
"location": "Emplacement",
"noEligibleEnrollments": "Il n'y a plus de programme où enregistrer le patient",
Expand Down
5 changes: 0 additions & 5 deletions packages/esm-patient-programs-app/translations/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
"configurePrograms": "אנא הגדר תוכניות כדי להמשיך.",
"dateCompleted": "תאריך השלמה",
"dateEnrolled": "תאריך הרשמה",
"discontinue": "הפסק",
"discontinueEnrollment": "Discontinue enrollment",
"editProgram": "Edit Program",
"enroll": "הרשם",
"enrollment": "הרשמה",
"enrollmentLocation": "מיקום הרשמה",
"enrollmentNowVisible": "הוא כעת נראה בטבלת התוכניות",
"enrollmentSaved": "הרשמת התוכנית נשמרה",
"enrollmentUpdated": "עדכון הרשמה לתוכנית",
"enrollmentUpdatesNowVisible": "שינויים בתוכנית כעת נראים בטבלת התוכניות",
"enrollProgram": "Enroll to program",
"fullyEnrolled": "רשום לכל התוכניות",
"location": "מיקום",
"noEligibleEnrollments": "אין עוד תוכניות שניתן להרשים את המטופל בהן",
Expand Down
5 changes: 0 additions & 5 deletions packages/esm-patient-programs-app/translations/km.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
"configurePrograms": "សូមកំណត់រចនាសម្ព័ន្ធកម្មវិធីដើម្បីបន្ត",
"dateCompleted": "កាលបរិច្ឆេទដែលបានបំពេញ",
"dateEnrolled": "កាលបរិច្ឆេទចុះឈ្មោះ",
"discontinue": "បញ្ឈប់",
"discontinueEnrollment": "Discontinue enrollment",
"editProgram": "Edit Program",
"enroll": "ចុះឈ្មោះ",
"enrollment": "ការចុះឈ្មោះ",
"enrollmentLocation": "ទីតាំងចុះឈ្មោះ",
"enrollmentNowVisible": "ឥឡូវនេះវាអាចមើលឃើញនៅក្នុងតារាងកម្មវិធី",
"enrollmentSaved": "ការចុះឈ្មោះកម្មវិធីត្រូវបានរក្សាទុក",
"enrollmentUpdated": "បានធ្វើបច្ចុប្បន្នភាពការចុះឈ្មោះកម្មវិធី",
"enrollmentUpdatesNowVisible": "ការផ្លាស់ប្តូរទៅកម្មវិធីឥឡូវនេះអាចមើលឃើញនៅក្នុងតារាងកម្មវិធី",
"enrollProgram": "Enroll to program",
"fullyEnrolled": "បានចុះឈ្មោះក្នុងកម្មវិធីទាំងអស់",
"location": "ទីតាំង",
"noEligibleEnrollments": "មិនមានកម្មវិធីទៀតទេដើម្បីចុះឈ្មោះអ្នកជំងឺនេះ",
Expand Down

0 comments on commit e38a041

Please sign in to comment.