Skip to content

Commit

Permalink
Put the provider stuff back in for the hook to use
Browse files Browse the repository at this point in the history
  • Loading branch information
wullaski committed Jan 17, 2025
1 parent 81eab4c commit 36f9585
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
27 changes: 27 additions & 0 deletions src/applications/vaos/referral-appointments/redux/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { captureError } from '../../utils/error';
import {
postDraftReferralAppointment,
getProviderById,
getPatientReferrals,
getPatientReferralById,
} from '../../services/referral';
Expand All @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/applications/vaos/referral-appointments/redux/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
100 changes: 100 additions & 0 deletions src/applications/vaos/referral-appointments/utils/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -390,6 +489,7 @@ const hasConflict = (selectedDate, appointmentsByMonth, facilityTimeZone) => {

module.exports = {
createDraftAppointmentInfo,
createProviderDetails,
draftAppointments,
getSlotByDate,
getSlotById,
Expand Down
15 changes: 15 additions & 0 deletions src/applications/vaos/services/mocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
10 changes: 10 additions & 0 deletions src/applications/vaos/services/referral/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down

0 comments on commit 36f9585

Please sign in to comment.