Skip to content

Commit

Permalink
updates validation
Browse files Browse the repository at this point in the history
  • Loading branch information
GiladSchneider committed Sep 12, 2024
1 parent 2d8b8ab commit 2c084a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ async function performEffect(props: PerformEffectInput): Promise<APIGatewayProxy
const transactionBundle = await fhirClient.transactionRequest({ requests: requests });
console.log('getting appointment from transaction bundle');
const { appointment } = validateBundleAndExtractAppointment(transactionBundle);
console.log(1);

// todo: this could be done in the same request to get the appointment

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Appointment, Bundle, Location, QuestionnaireResponse } from 'fhir/r4';
import { Appointment, Bundle, HealthcareService, Location, Practitioner, QuestionnaireResponse } from 'fhir/r4';

interface ValidateBundleOutput {
appointment: Appointment;
location: Location;
appointmentResource: Location | Practitioner | HealthcareService;
questionnaireResponse: QuestionnaireResponse;
}

Expand All @@ -27,14 +27,20 @@ export const validateBundleAndExtractAppointment = (bundle: Bundle): ValidateBun
throw new Error('Appointment could not be found');
}

// todo: add better validation for different schedule types
// const location: Location = entry.find((appt) => {
// 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';
Expand All @@ -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 };
};

0 comments on commit 2c084a8

Please sign in to comment.