diff --git a/src/applications/vaos/referral-appointments/ReviewAndConfirm.jsx b/src/applications/vaos/referral-appointments/ReviewAndConfirm.jsx index 8b44345776d1..27749c88bdd3 100644 --- a/src/applications/vaos/referral-appointments/ReviewAndConfirm.jsx +++ b/src/applications/vaos/referral-appointments/ReviewAndConfirm.jsx @@ -37,7 +37,7 @@ const ReviewAndConfirm = props => { const [loading, setLoading] = useState(true); const [failed, setFailed] = useState(false); const slotDetails = getSlotById( - draftAppointmentInfo.slots.slots, + draftAppointmentInfo.slots?.slots, selectedSlot, ); const facilityTimeZone = getTimezoneByFacilityId( diff --git a/src/applications/vaos/referral-appointments/redux/actions.js b/src/applications/vaos/referral-appointments/redux/actions.js index 0ec93cc9ab31..530ecb6a75e8 100644 --- a/src/applications/vaos/referral-appointments/redux/actions.js +++ b/src/applications/vaos/referral-appointments/redux/actions.js @@ -1,6 +1,7 @@ import { captureError } from '../../utils/error'; import { postDraftReferralAppointment, + getProviderById, getPatientReferrals, getPatientReferralById, } from '../../services/referral'; @@ -13,6 +14,10 @@ export const CREATE_DRAFT_REFERRAL_APPOINTMENT_SUCCEEDED = 'CREATE_DRAFT_REFERRAL_APPOINTMENT_SUCCEEDED'; export const CREATE_DRAFT_REFERRAL_APPOINTMENT_FAILED = 'CREATE_DRAFT_REFERRAL_APPOINTMENT_FAILED'; +export const FETCH_PROVIDER_DETAILS = 'FETCH_PROVIDER_DETAILS'; +export const FETCH_PROVIDER_DETAILS_SUCCEEDED = + 'FETCH_PROVIDER_DETAILS_SUCCEEDED'; +export const FETCH_PROVIDER_DETAILS_FAILED = 'FETCH_PROVIDER_DETAILS_FAILED'; export const FETCH_REFERRALS = 'FETCH_REFERRALS'; export const FETCH_REFERRALS_SUCCEEDED = 'FETCH_REFERRALS_SUCCEEDED'; export const FETCH_REFERRALS_FAILED = 'FETCH_REFERRALS_FAILED'; @@ -51,6 +56,28 @@ export function createDraftReferralAppointment(referralId) { }; } +export function fetchProviderDetails(id) { + return async dispatch => { + try { + dispatch({ + type: FETCH_PROVIDER_DETAILS, + }); + const providerDetails = await getProviderById(id); + + dispatch({ + type: FETCH_PROVIDER_DETAILS_SUCCEEDED, + data: providerDetails, + }); + return providerDetails; + } catch (error) { + dispatch({ + type: FETCH_PROVIDER_DETAILS_FAILED, + }); + return captureError(error); + } + }; +} + export function fetchReferrals() { return async dispatch => { try { diff --git a/src/applications/vaos/referral-appointments/redux/reducers.js b/src/applications/vaos/referral-appointments/redux/reducers.js index 90ccb0973a44..64301c8b123f 100644 --- a/src/applications/vaos/referral-appointments/redux/reducers.js +++ b/src/applications/vaos/referral-appointments/redux/reducers.js @@ -90,6 +90,8 @@ function ccAppointmentReducer(state = initialState, action) { case SET_INIT_REFERRAL_FLOW: return { ...state, + provider: {}, + providerFetchStatus: FETCH_STATUS.notStarted, draftAppointmentInfo: {}, draftAppointmentCreateStatus: FETCH_STATUS.notStarted, selectedSlot: '', diff --git a/src/applications/vaos/referral-appointments/redux/selectors.js b/src/applications/vaos/referral-appointments/redux/selectors.js index a428443c52f4..1586792b3ed9 100644 --- a/src/applications/vaos/referral-appointments/redux/selectors.js +++ b/src/applications/vaos/referral-appointments/redux/selectors.js @@ -1,6 +1,13 @@ export const selectCurrentPage = state => state.referral.currentPage; export const getSelectedSlot = state => state.referral.selectedSlot; +export function getProviderInfo(state) { + return { + provider: state.referral.selectedProvider, + providerFetchStatus: state.referral.providerFetchStatus, + }; +} + export function getDraftAppointmentInfo(state) { return { draftAppointmentInfo: state.referral.draftAppointmentInfo, diff --git a/src/applications/vaos/referral-appointments/utils/provider.js b/src/applications/vaos/referral-appointments/utils/provider.js index ebc7cd230869..e180acd864ac 100644 --- a/src/applications/vaos/referral-appointments/utils/provider.js +++ b/src/applications/vaos/referral-appointments/utils/provider.js @@ -2,6 +2,105 @@ const dateFns = require('date-fns'); const dateFnsTz = require('date-fns-tz'); +const providers = { + '0': { + id: '0', + providerName: 'Dr. Perpetually Unavailable', + typeOfCare: 'Physical Therapy', + orgName: 'Ethereal Adjunct of Deferred Care', + orgAddress: { + street1: '421 Promethean Circuit', + street2: 'Suite 300', + street3: '', + city: 'Portland', + state: 'Oregon', + zip: '97214', + }, + orgPhone: '555-687-6736', + driveTime: '1 hour drive', + driveDistance: '100 miles', + location: 'Hypothetical Adjunct Node, Sublime Care Complex', + }, + '111': { + id: '111', + providerName: 'Dr. Bones', + typeOfCare: 'Physical Therapy', + orgName: 'Stronger Bone Technologies', + orgAddress: { + street1: '111 Lori Ln.', + street2: '', + street3: '', + city: 'New York', + state: 'New York', + zip: '10016', + }, + orgPhone: '555-600-8043', + driveTime: '7 minute drive', + driveDistance: '8 miles', + location: 'Stronger bone technologies bldg 2', + }, + '222': { + id: '222', + providerName: 'Dr. Peetee', + typeOfCare: 'Physical Therapy', + orgName: 'Physical Therapy Solutions', + orgAddress: { + street1: '222 John Dr.', + street2: '', + street3: '', + city: 'New York', + state: 'New York', + zip: '10016', + }, + orgPhone: '555-867-5309', + driveTime: '3 minute drive', + driveDistance: '20 miles', + location: 'Physical Therapy Solutions World Headquarters', + }, + '333': { + id: '333', + providerName: 'Dr. Smith', + typeOfCare: 'Mental Health', + orgName: 'Smith Mental Health Clinic', + orgAddress: { + street1: '333 Main St.', + street2: '', + street3: '', + city: 'New York', + state: 'New York', + zip: '10016', + }, + orgPhone: '555-555-5555', + driveTime: '5 minute drive', + driveDistance: '5 miles', + location: 'Smith Mental Health Clinic', + }, +}; + +/** + * Creates a provider object with a configurable number of slots an hour apart. + * + * @param {Number} numberOfSlots How many slots to create + * @param {String} providerId The ID for the provider + * @returns {Object} Provider object + */ +const createProviderDetails = (numberOfSlots, providerId = '111') => { + const provider = providers[providerId]; + provider.slots = []; + const tomorrow = dateFns.addDays(dateFns.startOfDay(new Date()), 1); + let hourFromNow = 12; + for (let i = 0; i < numberOfSlots; i++) { + const startTime = dateFns.addHours(tomorrow, hourFromNow); + provider.slots.push({ + end: dateFns.addMinutes(startTime, 30).toISOString(), + id: i.toString(), + start: startTime.toISOString(), + }); + hourFromNow++; + } + return { ...provider }; +}; + const draftAppointments = { '0': { appointment: { @@ -390,6 +489,7 @@ const hasConflict = (selectedDate, appointmentsByMonth, facilityTimeZone) => { module.exports = { createDraftAppointmentInfo, + createProviderDetails, draftAppointments, getSlotByDate, getSlotById, diff --git a/src/applications/vaos/services/mocks/index.js b/src/applications/vaos/services/mocks/index.js index e310328554d1..e6e2e7abde4d 100644 --- a/src/applications/vaos/services/mocks/index.js +++ b/src/applications/vaos/services/mocks/index.js @@ -339,6 +339,21 @@ const responses = { data: singleReferral ?? {}, }); }, + 'GET /vaos/v2/epsApi/providerDetails/:providerId': (req, res) => { + // Provider 3 throws error + if (req.params.providerId === '3') { + return res.status(500).json({ error: true }); + } + // Provider 0 has no available slots + if (req.params.providerId === '0') { + return res.json({ + data: providerUtils.createProviderDetails(0, req.params.providerId), + }); + } + return res.json({ + data: providerUtils.createProviderDetails(5, req.params.providerId), + }); + }, 'POST /vaos/v2/epsApi/providerDetails/:referralId': (req, res) => { // Provider 3 throws error if (req.params.referralId === '3') { diff --git a/src/applications/vaos/services/referral/index.js b/src/applications/vaos/services/referral/index.js index 74f76dcd3033..7c14c06ea2c6 100644 --- a/src/applications/vaos/services/referral/index.js +++ b/src/applications/vaos/services/referral/index.js @@ -18,6 +18,16 @@ export async function getPatientReferralById(referralId) { return response.data; } +export async function getProviderById(referralId) { + const response = await apiRequestWithUrl( + `/vaos/v2/epsApi/providerDetails/${referralId}`, + { + method: 'GET', + }, + ); + return response.data; +} + export async function postDraftReferralAppointment(referralId) { const response = await apiRequestWithUrl( `/vaos/v2/epsApi/providerDetails/${referralId}`,