Skip to content

Commit

Permalink
Finished adding possible data points to submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobjdavey committed Apr 15, 2024
2 parents 85f5d47 + b372d46 commit 0ce841b
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 96 deletions.
3 changes: 0 additions & 3 deletions src/controllers/Dashboard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import type { Request, Response } from 'express';
* @param res - the response object
*/
export const getDashboardStats = async (req: Request, res: Response) => {
// use Joi to validate the request body
// ...

const base = new Airtable({ apiKey: process.env.AIRTABLE_API_KEY || '' }).base(
'appwPsfAb6U8CV3mf'
);
Expand Down
17 changes: 1 addition & 16 deletions src/controllers/FlightRequest.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-irregular-whitespace */
import { createTestFlightLegData } from '../data/test-data';
import logger from '../util/logger';
import { trimFlightLeg, trimRequest } from '../util/trim';
import { createTestFlightLegData } from '../data/test-data';
import Airtable from 'airtable';
import dotenv from 'dotenv';
import type { FlightLegData } from '../interfaces/legs/flight-leg.interface';
Expand All @@ -13,20 +12,6 @@ const base = new Airtable({
apiKey: process.env.AIRTABLE_API_KEY || '',
}).base('appwPsfAb6U8CV3mf');

/**
* This function returns all flight requests for a given user
*
* Steps to complete:
* 1. Get the userId from the query parameters, if it doesn't exist return a 400
* 2. Make a call to AirTable to get all flight requests for the user, if that fails return a 500 (hint, use try/catch)
*    If there are no flight requests for the user return a 400. (hint: use the AirTable API, see TestControllers/retrievePassengers.ts for an example)
*    Another hint - we will be filtering by the "Passenger ID" field in the AirTable
* 3. Remove any unnecessary data from the flight requests (there is a lot of data in the AirTable response we don't need)
* 4. Return the flight requests for the user
*
* @param req - the request object
* @param res - the response object
*/
/**
* Get all flight requests for a given user
*
Expand Down
1 change: 0 additions & 1 deletion src/controllers/Passenger.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable */
import logger from '../util/logger';
import { createTestPassengerData } from '../data/test-data';
import { trimPassenger } from '../util/trim';
import type { PassengerData } from '../interfaces/passenger/passenger.interface';
import type { Request, Response } from 'express';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable autofix/no-unused-vars */
import type { TrimmedPassenger } from '../passenger/trimmed-passenger.interface';

// This is the question array for flight specfic data received from the front end
Expand Down
4 changes: 0 additions & 4 deletions src/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
getAllFlightRequestsForUser,
getFlightRequestById,
getFlightLegsById,
createFlightRequest,
updateFlightRequest,
} from '../controllers/FlightRequest.controller';
import { SubmitJotForm, getQuestions } from '../services/JotFormService';
import express from 'express';
Expand Down Expand Up @@ -52,8 +50,6 @@ router.get('/dashboard/', getDashboardStats);
router.get('/requests', validateAuth, getAllFlightRequestsForUser);
router.get('/requests/:id', validateAuth, getFlightRequestById);
router.get('/requests/:id/legs', validateAuth, getFlightLegsById);
router.post('/requests/', validateAuth, createFlightRequest);
router.put('/requests/:id', validateAuth, updateFlightRequest);

router.post('/submit-flight-request', validateAuth, SubmitJotForm);
router.get('/get-questions', validateAuth, getQuestions);
Expand Down
3 changes: 2 additions & 1 deletion src/services/JotFormService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export const SubmitJotForm = async (req, res) => {
flightRequestData: flightRequestData,
};

const submissionData = JSON.stringify(restructureFlightRequest(rawData));
const restructuredData = restructureFlightRequest(rawData);
const submissionData = JSON.stringify(restructuredData);

try {
// form ID: 240586898219170 - clone one of the forms from the JotForm account
Expand Down
2 changes: 1 addition & 1 deletion src/tests/Trimming.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('UTIL Trimming', () => {
expect(passengerData.fields['All Flight Legs']).to.equal(
trimmedPassenger['All Flight Legs']
);
expect(passengerData.fields.Diagnosis).to.equal(trimmedPassenger.Diagnosis);
expect(passengerData.fields.Diagnoses).to.equal(trimmedPassenger.Diagnoses);
expect(passengerData.fields['AirTable Record ID']).to.equal(
trimmedPassenger['AirTable Record ID']
);
Expand Down
155 changes: 85 additions & 70 deletions src/util/restructures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const restructureFlightRequest = (
Gender: patientGender,
Street: patientStreetAddress,
City: patientCity,
Country: patientCountry,
Email: patientEmail,
'Household Income': householdIncome,
'Household Size': householdSize,
Expand Down Expand Up @@ -55,7 +56,6 @@ export const restructureFlightRequest = (
} = passengerThree ?? {};

const {
enoughDaysAway,
travelType,
ScheduledMedicalAppointmentDate,
DepartureDate,
Expand All @@ -76,10 +76,15 @@ export const restructureFlightRequest = (
[questionIdMap.patientGender]: patientGender,
[questionIdMap.patientStreetAddress]: patientStreetAddress,
[questionIdMap.patientCity]: patientCity,
[questionIdMap.patientCountry]: patientCountry,
[questionIdMap.patientEmail]: patientEmail,
[questionIdMap.annualFamilyIncome]: householdIncome.toString(),
[questionIdMap.householdSize]: householdSize.toString(),
[questionIdMap.patientCellPhone]: patientCellPhone,
[questionIdMap.grossHouseholdIncome]: householdIncome.toString(),
[questionIdMap.childPatientVerification]:
'Yes - Miracle Flights will provide flights to a qualifying child patient (age 17 and under at the time of medical appointment) and up to two additional parents/legal guardians/family members (up to 3 total passengers).',
[questionIdMap.isFirstTime]: 'No',
[questionIdMap.patientCellPhone]: patientCellPhone, // Not being sent over to JotForm. Does it have to do with format? Frontend is sending airtable data, backend is sending it as a string in this format: "(123) 456-7890"
[questionIdMap.patientHomePhone]: patientHomePhone,
[questionIdMap.patientHighestEducation]: patientHighestEducation,
[questionIdMap.patientMaritalStatus]: maritalStatus,
Expand Down Expand Up @@ -120,8 +125,11 @@ export const restructureFlightRequest = (
[questionIdMap.passenger3CellPhone]: passenger3CellPhone ?? '',

// Flight Request Data
[questionIdMap.enoughDaysAway]: enoughDaysAway,
[questionIdMap.travelType]: travelType,
[questionIdMap.enoughDaysAway]: isFourteenDaysAway(DepartureDate),
[questionIdMap.enoughDaysAway2]: isFourteenDaysAway(DepartureDate),
[questionIdMap.travelType]: travelType
? 'One-Way Flight (Departure Flight Only)'
: 'Roundtrip Flight (Departure and Return Flight)',
[questionIdMap.ScheduledMedicalAppointmentDate]: convertToDateJSON(
ScheduledMedicalAppointmentDate
),
Expand All @@ -134,78 +142,76 @@ export const restructureFlightRequest = (
[questionIdMap.FullNameOfTreatmentSite]: FullNameOfTreatmentSite,
[questionIdMap.FullNameOfPrimaryTreatmentSiteDoctor]:
FullNameOfPrimaryTreatmentSiteDoctor,
454: '',
536: '',
548: '',
427: '',
563: '',
560: '',
444: '',
539: '',
445: '',
540: '',

// These are data points not being sent over, we need to incorporate these in the frontend
454: 'Yes',
536: 'Yes',
548: 'Yes',
427: 'Yes',
563: '', // Type of gov. assistance
560: 'Yes',
543: '',
193: '',
479: '',
206: '',
519: '',
207: '',
288: '',
554: '',
555: '',
556: '',
557: '',
473: '',
474: '',
162: '',
535: '',
163: '',
170: '',
413: '',
415: '',
547: '',
416: '',
289: '',
419: '',
265: '',
306: '',
480: '',
301: '',
302: '',
343: '',
257: '',
258: '',
260: '',
303: '',
355: '',
267: '',
526: '',
531: '',
307: '',
481: '',
293: '',
218: '',
367: '',
350: '',
352: '',
353: '',
418: '',
356: '',
176: '',
178: '',
177: '',
190: '',
191: '',
285: '',
561: '',
219: '',
153: '',
154: '',
193: '', // Patient Middle Name
479: '', // State
206: '', // Postal code
519: '', // County
288: '', // Type of treatment
554: '', // Does the child patient presently have medical insurance coverage?
555: '', // Medical Insurance Company Name
556: '', // Subscriber ID #, Policy #, or Member ID #
557: '', // Group #
473: '', // Treatment Site City and State
474: '', // Treatment Site Phone Number
162: '', // Oxygen Required
535: '', // Will you be flying with a service dog?
163: '', // Wheelchair Required
170: '', // Birth Certificate or Proof of Legal Guardianship Required for Child Patient (17 and under)
413: patientFirstName + patientLastName, // Child Patient Name (as it appears on government issued identification)
415: 'Furthermore, I do herewith unequivocally waive and deny, for myself and all my assigns, any and all rights to pursue any action against said Miracle Flights for any action or inaction executed by them in good faith.', // Waive Right to Pursue Legal Action
547: 'I acknowledge and confirm that both parents and/or legal guardians consent and approve of the medical treatment that the child patient is receiving as listed in this Flight Request Application.', // Consent for Medical Treatment
416: 'I AGREE and hereby authorize Miracle Flights and its partners, sponsors, and affiliates to use my name, likeness, photographs, reproductions, videos, recordings, or endorsements of/by me and/or my child for publicity, social media, and/or any other related Miracle Flights marketing purposes.', // Photo/Video Release
289: '', // Patient Signer Name
419: '', // Relationship to Patient
265: '', // Passenger 2 - Middle Name
306: '', // Passenger 2 - Address is the same as the patient?
480: '', // Passenger 2 - State
301: '', // Passenger 2 - Postal Code
302: '', // Passenger 2 - Country
343: '', // Passenger 2 Waiver of Responsibility
257: passenger2FirstName + passenger2LastName, // Passenger Name (as it appears on government issued identification)
258: 'Furthermore, I do herewith unequivocally waive and deny, for myself and all my assigns, any and all rights to pursue any action against said Miracle Flights for any action or inaction executed by them in good faith.', // Passenger 2 Waive Right to Pursue Legal Action
260: 'I AGREE and hereby authorize Miracle Flights and its partners, sponsors, and affiliates to use my name, likeness, photographs, reproductions, videos, recordings, or endorsements of/by me and/or my child for publicity, social media, and/or any other related Miracle Flights marketing purposes.', // Passenger 2 Photo/Video Release
303: '', // Passenger 3 - Relationship to Patient
355: '', // Passenger 2 Signer Name
267: '', // Passenger 3 - Middle Name
526: '', // Is Passenger 3 returning on a different date than Patient/Passenger 1?
531: '', // Explain why Passenger 3 is requesting a different return date than Patient/Passenger 1
307: '', // Passenger 3 - Address is the same as the patient?
481: '', // Passenger 3 - State
293: '', // Passenger 3 - Postal Code
218: '', // Passenger 3 - Country
367: '', // Passenger 3 Waiver of Responsibility
350: passenger3FirstName + (passenger3LastName ?? ''), // Passenger 3 Name (as it appears on government issued identification)
352: 'Furthermore, I do herewith unequivocally waive and deny, for myself and all my assigns, any and all rights to pursue any action against said Miracle Flights for any action or inaction executed by them in good faith.', // Passenger 3 Waive Right to Pursue Legal Action
353: 'I AGREE and hereby authorize Miracle Flights and its partners, sponsors, and affiliates to use my name, likeness, photographs, reproductions, videos, recordings, or endorsements of/by me and/or my child for publicity, social media, and/or any other related Miracle Flights marketing purposes.', // Passenger 3 Photo / Video Release
418: passenger3FirstName + (passenger3LastName ?? ''), // Passenger 3 signer name
356: '', // Relationship to passenger 3
176: householdSize.toString(), // # people in household
178: '', // Sources of income
177: '', // Proof of income
190: 'I hereby acknowledge financial assistance for air travel will be provided to me by Miracle Flights and certify that our total gross family/household income from all sources and my family size are as indicated above.', // Eligibility is determined by total family income and size
191: 'I will call Miracle Flights with any flight cancellations or changes needed to my original itinerary. I acknowledge that Miracle Flights is the only party that can cancel or amend my flights and I will not contact the airlines directly. Failure to do comply with this may put Miracle Flights and its airline relationships in jeopardy and may result in fewer flights provided to myself and others.', // Cancelling or amending flights?
285: 'I understand that the airline tickets are provided at no cost to me and/or my family by Miracle Flights. I will contact Miracle Flights as soon as possible to make them aware of any changes that may result in my family not being able to fly on the flights that were provided to us. Therefore, any change or cancellation not pre-approved by Miracle Flights may result in Miracle Flights losing the resources spent on your flights. In the case of a "no call no show" resulting in Miracle Flights losing resources, Miracle Flights may seek financial compensation for the travel costs and/or may deny the patient and their family future program services.', // No call, no show
561: 'I acknowledge and confirm that both parents and/or legal guardians consent and approve of the medical treatment that the child patient is receiving as listed in this Flight Request Application.', // Final consent for medical treatment
219: '', // signer email
153: '', // Name of signer
154: '', // Final relationship to patient
};

return restructuredRequest;
};

// Converts the date string to an object with the month, day, and year
const convertToDateJSON = (
date: string
): { month: string; day: string; year: string } => {
Expand All @@ -220,3 +226,12 @@ const convertToDateJSON = (
year: year,
};
};

// This function is used to determine if the scheduled date is 14 days away
const isFourteenDaysAway = (scheduledDate): string => {
const today = new Date();
const scheduled = new Date(scheduledDate);
const differenceInTime = scheduled.getTime() - today.getTime();
const differenceInDays = differenceInTime / (1000 * 3600 * 24);
return differenceInDays > 14 ? 'Yes' : 'No';
};

0 comments on commit 0ce841b

Please sign in to comment.