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

Referral Expired error #33775

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import React from 'react';
import { useLocation } from 'react-router-dom';
import { isAfter } from 'date-fns';

import { useGetReferralById } from '../hooks/useGetReferralById';
import ReferralTaskCard from './ReferralTaskCard';

const isExpired = referral => {
const expirationDate = referral.ReferralExpirationDate;
const now = new Date();
const expiration = new Date(expirationDate);
return isAfter(now, expiration);
};

export default function ReferralTaskCardWithReferral() {
const { search } = useLocation();

Expand All @@ -16,5 +24,28 @@ export default function ReferralTaskCardWithReferral() {
return null;
}

if (isExpired(currentReferral)) {
return (
<va-alert-expandable
status="warning"
trigger="Your community care referral has expired"
disable-analytics="false"
class="vads-u-margin-y--2"
uswds
data-testid="expired-alert"
>
<p>
Call your facility to request a new referral.
<br />
<va-link
href="/find-locations/?facilityType=health"
target="_blank"
text="Find your VA health facility"
/>
</p>
</va-alert-expandable>
);
}

return <ReferralTaskCard data={currentReferral} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,25 @@ describe('VAOS Component: ReferralTaskCardWithReferral', () => {
const taskCard = screen.queryByTestId('referral-task-card');
expect(taskCard).to.be.null;
});
it('should display the expired alert when referral is expired', async () => {
const store = createTestStore({
...initialState,
referral: {
...initialState.referral,
referrals: [
createReferral(
'2024-11-29',
'445e2d1b-7150-4631-97f2-f6f473bdef00',
'111',
'2024-12-01',
),
],
},
});
const screen = renderWithStoreAndRouter(<ReferralTaskCardWithReferral />, {
store,
path: '/?id=445e2d1b-7150-4631-97f2-f6f473bdef00',
});
expect(await screen.getByTestId('expired-alert')).to.exist;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('VAOS referral generator', () => {
expect(referrals[0].ReferralDate).to.equal('2024-10-30');
expect(referrals[1].ReferralDate).to.equal('2024-10-31');
});
it('Creates specified number of expired referrals', () => {
const referrals = referralUtil.createReferrals(3, '2024-10-30', 2);
expect(referrals[0].ReferralExpirationDate).to.equal('2024-05-06');
expect(referrals[1].ReferralExpirationDate).to.equal('2024-05-07');
expect(referrals[2].ReferralExpirationDate).to.equal('2025-05-01');
});
});
describe('getReferralSlotKey', () => {
expect(referralUtil.getReferralSlotKey('111')).to.equal(
Expand Down
34 changes: 27 additions & 7 deletions src/applications/vaos/referral-appointments/utils/referrals.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
/* eslint-disable camelcase */

const { addDays, addMonths, format } = require('date-fns');
const { addDays, addMonths, format, subMonths } = require('date-fns');
const { providers } = require('./provider');

const defaultUUIDBase = 'add2f0f4-a1ea-4dea-a504-a54ab57c68';
const expiredUUIDBase = '445e2d1b-7150-4631-97f2-f6f473bdef';
/**
* Creates a referral object relative to a start date.
*
* @param {String} startDate The date in 'yyyy-MM-dd' format to base the referrals around
* @param {String} uuid The UUID for the referral
* @param {String} providerId The ID for the provider
* @param {String} expirationDate The date in 'yyyy-MM-dd' format to expire the referral
* @returns {Object} Referral object
*/
const createReferral = (startDate, uuid, providerId = '111') => {
const createReferral = (
startDate,
uuid,
providerId = '111',
expirationDate,
) => {
const [year, month, day] = startDate.split('-');
const relativeDate = new Date(year, month - 1, day);

Expand All @@ -21,7 +30,8 @@ const createReferral = (startDate, uuid, providerId = '111') => {
return {
ReferralCategory: 'Inpatient',
ReferralDate: format(relativeDate, mydFormat),
ReferralExpirationDate: format(addMonths(relativeDate, 6), mydFormat),
ReferralExpirationDate:
expirationDate || format(addMonths(relativeDate, 6), mydFormat),
ReferralLastUpdateDate: format(relativeDate, mydFormat),
ReferralLastUpdateDateTime: format(relativeDate, mydWithTimeFormat),
ReferralNumber: 'VA0000009880',
Expand Down Expand Up @@ -59,27 +69,37 @@ const createReferral = (startDate, uuid, providerId = '111') => {
*
* @param {Number} numberOfReferrals The number of referrals to create in the array
* @param {String} baseDate The date in 'yyyy-MM-dd' format to base the referrals around
* @param {Number} numberOfExpiringReferrals The number of referrals that should be expired
* @returns {Array} Referrals array
*/
const createReferrals = (numberOfReferrals = 3, baseDate) => {
const createReferrals = (
numberOfReferrals = 3,
baseDate,
numberOfExpiringReferrals = 0,
) => {
const [year, month, day] = baseDate.split('-');
const baseDateObject = new Date(year, month - 1, day);
const referrals = [];
const baseUUID = 'add2f0f4-a1ea-4dea-a504-a54ab57c68';
const providerIds = ['111', '222'];
const isOdd = number => {
return number % 2;
};

for (let i = 0; i < numberOfReferrals; i++) {
const startDate = addDays(baseDateObject, i);
const isExpired = i < numberOfExpiringReferrals;
const uuidBase = isExpired ? expiredUUIDBase : defaultUUIDBase;
const startDate = addDays(
isExpired ? subMonths(baseDateObject, 6) : baseDateObject,
i,
);
const mydFormat = 'yyyy-MM-dd';
const referralDate = format(startDate, mydFormat);
referrals.push(
createReferral(
referralDate,
`${baseUUID}${i.toString().padStart(2, '0')}`,
`${uuidBase}${i.toString().padStart(2, '0')}`,
isOdd(i) ? providerIds[0] : providerIds[1],
isExpired ? format(addDays(startDate, 6), mydFormat) : undefined,
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/applications/vaos/services/mocks/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* istanbul ignore file */
/* eslint-disable camelcase */
const delay = require('mocker-api/lib/delay');
const moment = require('moment');

Check warning on line 4 in src/applications/vaos/services/mocks/index.js

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/vaos/services/mocks/index.js:4:16:Use date-fns or Native Date methods instead of moment.js
// var
const confirmedVA = require('./var/confirmed_va.json');
const confirmedCC = require('./var/confirmed_cc.json');
Expand Down Expand Up @@ -352,10 +352,10 @@
Array.isArray(requestedPeriods) &&
requestedPeriods.length > 0
) {
date = moment(requestedPeriods[0].start);

Check warning on line 355 in src/applications/vaos/services/mocks/index.js

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/vaos/services/mocks/index.js:355:22:Consider using Native new Date().
}
} else if (status === 'booked') {
date = moment(appointment.attributes.start);

Check warning on line 358 in src/applications/vaos/services/mocks/index.js

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/vaos/services/mocks/index.js:358:20:Consider using Native new Date().
}

if (
Expand Down Expand Up @@ -415,10 +415,10 @@
req,
res,
) => {
const start = moment(req.query.start);

Check warning on line 418 in src/applications/vaos/services/mocks/index.js

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/vaos/services/mocks/index.js:418:19:Consider using Native new Date().
const end = moment(req.query.end);

Check warning on line 419 in src/applications/vaos/services/mocks/index.js

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/vaos/services/mocks/index.js:419:17:Consider using Native new Date().
const slots = appointmentSlotsV2.data.filter(slot => {
const slotStartDate = moment(slot.attributes.start);

Check warning on line 421 in src/applications/vaos/services/mocks/index.js

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/vaos/services/mocks/index.js:421:29:Consider using Native new Date().
return slotStartDate.isBetween(start, end, '[]');
});
return res.json({
Expand Down Expand Up @@ -508,7 +508,7 @@
});
},
'GET /vaos/v2/epsApi/referralDetails/:referralId': (req, res) => {
const referrals = referralUtils.createReferrals(3, '2024-12-02');
const referrals = referralUtils.createReferrals(3, '2024-12-02', 1);
const singleReferral = referrals.find(
referral => referral?.UUID === req.params.referralId,
);
Expand Down
Loading