diff --git a/packages/telemed-intake/zambdas/src/appointment/cancel-appointment/index.ts b/packages/telemed-intake/zambdas/src/appointment/cancel-appointment/index.ts index 52454e1cb..50e7700a4 100644 --- a/packages/telemed-intake/zambdas/src/appointment/cancel-appointment/index.ts +++ b/packages/telemed-intake/zambdas/src/appointment/cancel-appointment/index.ts @@ -153,7 +153,6 @@ async function performEffect(props: PerformEffectInput): Promise { - // return appt.resource && appt.resource.resourceType === 'Location'; - // })?.resource as Location; + const appointmentResources = ['Location', 'Practitioner', 'HealthcareService']; + let appointmentResource: Location | Practitioner | HealthcareService | undefined = undefined; + for (const aptResource of appointmentResources) { + appointmentResource = entry.find((appt) => { + return appt.resource && appt.resource.resourceType === aptResource; + })?.resource as Location | Practitioner | HealthcareService; - // if (!location) { - // throw new Error('Location could not be found'); - // } + if (appointmentResource) { + break; + } + } + if (!appointmentResource) { + throw new Error('Resource could not be found'); + } const questionnaireResponse: QuestionnaireResponse = entry.find((appt) => { return appt.resource && appt.resource.resourceType === 'QuestionnaireResponse'; @@ -44,5 +50,5 @@ export const validateBundleAndExtractAppointment = (bundle: Bundle): ValidateBun // questionnaireResponse associated with the encounter, but it is still // valid for them to check-in. - return { appointment, location: undefined as unknown as Location, questionnaireResponse }; + return { appointment, appointmentResource, questionnaireResponse }; };