diff --git a/src/applications/vaos/referral-appointments/components/ReferralTaskCardWithReferral.jsx b/src/applications/vaos/referral-appointments/components/ReferralTaskCardWithReferral.jsx index 52d3b2b0d830..7199a655985a 100644 --- a/src/applications/vaos/referral-appointments/components/ReferralTaskCardWithReferral.jsx +++ b/src/applications/vaos/referral-appointments/components/ReferralTaskCardWithReferral.jsx @@ -1,10 +1,21 @@ import React from 'react'; import { useLocation } from 'react-router-dom'; +import { isAfter } from 'date-fns'; import { useGetReferralById } from '../hooks/useGetReferralById'; import ReferralTaskCard from './ReferralTaskCard'; import { FETCH_STATUS } from '../../utils/constants'; +const isExpired = referral => { + if (!referral?.ReferralExpirationDate) { + return false; + } + const expirationDate = referral.ReferralExpirationDate; + const now = new Date(); + const expiration = new Date(expirationDate); + return isAfter(now, expiration); +}; + export default function ReferralTaskCardWithReferral() { const { search } = useLocation(); @@ -33,5 +44,28 @@ export default function ReferralTaskCardWithReferral() { ); } + if (isExpired(currentReferral)) { + return ( + + + + Call your facility to request a new referral. + + + + + ); + } + return ; } diff --git a/src/applications/vaos/referral-appointments/components/ReferralTaskCardWithReferral.unit.spec.js b/src/applications/vaos/referral-appointments/components/ReferralTaskCardWithReferral.unit.spec.js index 28b144d1285f..e568bc50eef5 100644 --- a/src/applications/vaos/referral-appointments/components/ReferralTaskCardWithReferral.unit.spec.js +++ b/src/applications/vaos/referral-appointments/components/ReferralTaskCardWithReferral.unit.spec.js @@ -86,6 +86,27 @@ 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(, { + store, + path: '/?id=445e2d1b-7150-4631-97f2-f6f473bdef00', + }); + expect(await screen.getByTestId('expired-alert')).to.exist; + }); it('should display the error alert when referral is not found', async () => { const store = createTestStore(initialState); diff --git a/src/applications/vaos/referral-appointments/tests/utils/referrals.unit.spec.js b/src/applications/vaos/referral-appointments/tests/utils/referrals.unit.spec.js index 71fefd0b6b87..ace066c961fd 100644 --- a/src/applications/vaos/referral-appointments/tests/utils/referrals.unit.spec.js +++ b/src/applications/vaos/referral-appointments/tests/utils/referrals.unit.spec.js @@ -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( diff --git a/src/applications/vaos/referral-appointments/utils/referrals.js b/src/applications/vaos/referral-appointments/utils/referrals.js index cb5c1e83630b..814c30ecb62a 100644 --- a/src/applications/vaos/referral-appointments/utils/referrals.js +++ b/src/applications/vaos/referral-appointments/utils/referrals.js @@ -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); @@ -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', @@ -60,24 +70,34 @@ 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', '0', '333']; 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')}`, providerIds[i % providerIds.length], + isExpired ? format(addDays(startDate, 6), mydFormat) : undefined, ), ); } diff --git a/src/applications/vaos/services/mocks/index.js b/src/applications/vaos/services/mocks/index.js index 7a477018ddda..ca5d47efab5e 100644 --- a/src/applications/vaos/services/mocks/index.js +++ b/src/applications/vaos/services/mocks/index.js @@ -331,7 +331,7 @@ const responses = { if (req.params.referralId === 'error') { return res.status(500).json({ error: true }); } - 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, );
+ Call your facility to request a new referral. +