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

(fix) O3-3609: Fix program enrollment eligibility logic #1915

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion packages/esm-patient-programs-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ export const configSchema = {
};

export interface ConfigObject {
customUrl: string;
hideAddProgramButton: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const ProgramsDetailedSummary: React.FC<ProgramsDetailedSummaryProps> = ({ patie
<span>{isValidating ? <InlineLoading /> : null}</span>
{hideAddProgramButton ? null : (
<Button
disabled={isEnrolledInAllPrograms}
kind="ghost"
renderIcon={(props) => <Add size={16} {...props} />}
iconDescription={t('addPrograms', 'Add programs')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '@openmrs/esm-styleguide/src/vars';
@use '@openmrs/esm-styleguide/src/vars' as *;

.widgetCard {
border: 1px solid $ui-03;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('ProgramsDetailedSummary', () => {
expect(editButton).toBeInTheDocument();

// Clicking "Add" launches the programs form in a workspace
expect(addButton).toBeEnabled();
await user.click(addButton);

expect(launchPatientWorkspace).toHaveBeenCalledWith('programs-form-workspace');
Expand All @@ -111,6 +112,7 @@ describe('ProgramsDetailedSummary', () => {
expect(screen.getByRole('row', { name: /hiv care and treatment/i })).toBeInTheDocument();
expect(screen.getByRole('row', { name: /hiv differentiated care/i })).toBeInTheDocument();
expect(screen.getByRole('row', { name: /oncology screening and diagnosis/i })).toBeInTheDocument();
expect(screen.getByRole('button', { name: /add/i })).toBeDisabled();
expect(screen.getByText(/enrolled in all programs/i)).toBeInTheDocument();
expect(screen.getByText(/there are no more programs left to enroll this patient in/i)).toBeInTheDocument();
});
Expand Down
14 changes: 10 additions & 4 deletions packages/esm-patient-programs-app/src/programs/programs-form.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use '@carbon/styles/scss/type';
@use '@carbon/styles/scss/spacing';
@import '@openmrs/esm-styleguide/src/vars';
@use '@carbon/type';
@use '@carbon/layout';
@use '@openmrs/esm-styleguide/src/vars' as *;

.loading {
margin-left: 1rem;
Expand Down Expand Up @@ -42,6 +42,12 @@

.errorMessage {
@include type.type-style("label-02");
margin-top: spacing.$spacing-03;
margin-top: layout.$spacing-03;
color: $danger;
}

.notification {
margin: 0;
min-width: 100%;
padding: 0;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { type TFunction, useTranslation } from 'react-i18next';
import dayjs from 'dayjs';
import filter from 'lodash-es/filter';
import includes from 'lodash-es/includes';
import map from 'lodash-es/map';
import {
Button,
ButtonSet,
Expand Down Expand Up @@ -72,7 +69,10 @@ const ProgramsForm: React.FC<ProgramsFormProps> = ({

const eligiblePrograms = currentProgram
? [currentProgram]
: filter(availablePrograms, (program) => !includes(map(enrollments, 'program.uuid'), program.uuid));
: availablePrograms.filter((program) => {
const enrollment = enrollments.find((e) => e.program.uuid === program.uuid);
return !enrollment || enrollment.dateCompleted !== null;
});

const getLocationUuid = () => {
if (!currentEnrollment?.location.uuid && session?.sessionLocation?.uuid) {
Expand Down Expand Up @@ -243,7 +243,7 @@ const ProgramsForm: React.FC<ProgramsFormProps> = ({

const formGroups = [
{
style: { maxWidth: isTablet ? '50%' : 'fit-content' },
style: { maxWidth: isTablet && '50%' },
legendText: '',
value: programSelect,
},
Expand All @@ -267,10 +267,10 @@ const ProgramsForm: React.FC<ProgramsFormProps> = ({
return (
<Form className={styles.form} onSubmit={handleSubmit(onSubmit)}>
<Stack className={styles.formContainer} gap={7}>
{!eligiblePrograms.length && (
{!availablePrograms.length && (
<InlineNotification
style={{ minWidth: '100%', margin: '0rem', padding: '0rem' }}
kind={'error'}
className={styles.notification}
kind="error"
lowContrast
subtitle={t('configurePrograms', 'Please configure programs to continue.')}
title={t('noProgramsConfigured', 'No programs configured')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '@openmrs/esm-styleguide/src/vars';
@use '@openmrs/esm-styleguide/src/vars' as *;

.widgetCard {
border: 1px solid $ui-03;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { openmrsFetch } from '@openmrs/esm-framework';
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib';
import { mockEnrolledProgramsResponse } from '__mocks__';

import { mockCareProgramsResponse, mockEnrolledInAllProgramsResponse, mockEnrolledProgramsResponse } from '__mocks__';
import { mockPatient, renderWithSwr, waitForLoadingToFinish } from 'tools';
import ProgramsOverview from './programs-overview.component';

Expand Down Expand Up @@ -81,10 +80,27 @@ describe('ProgramsOverview', () => {
expect(screen.getByRole('row', { name: /HIV Care and Treatment/i })).toBeInTheDocument();

// Clicking "Add" launches the programs form in a workspace
expect(addButton).toBeEnabled();
await user.click(addButton);

expect(launchPatientWorkspace).toHaveBeenCalledWith('programs-form-workspace');
});

it('renders a notification when the patient is enrolled in all available programs', async () => {
mockOpenmrsFetch.mockReturnValueOnce({ data: { results: mockEnrolledInAllProgramsResponse } });
mockOpenmrsFetch.mockReturnValueOnce({ data: { results: mockCareProgramsResponse } });

renderProgramsOverview();

await waitForLoadingToFinish();

expect(screen.getByRole('row', { name: /hiv care and treatment/i })).toBeInTheDocument();
expect(screen.getByRole('row', { name: /hiv differentiated care/i })).toBeInTheDocument();
expect(screen.getByRole('row', { name: /oncology screening and diagnosis/i })).toBeInTheDocument();
expect(screen.getByRole('button', { name: /add/i })).toBeDisabled();
expect(screen.getByText(/enrolled in all programs/i)).toBeInTheDocument();
expect(screen.getByText(/there are no more programs left to enroll this patient in/i)).toBeInTheDocument();
});
});

function renderProgramsOverview() {
Expand Down