Skip to content

Commit

Permalink
Merge pull request #700 from Gary-Community-Ventures/feat/add-ins-hhdb
Browse files Browse the repository at this point in the history
Feat/add ins hhdb
  • Loading branch information
CalebPena authored Nov 3, 2023
2 parents 96785a8 + 38c1884 commit ce11d93
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 120 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
Binary file added src/Assets/OptionCardIcons/dont_know.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Assets/OptionCardIcons/emergency_medicaid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Assets/OptionCardIcons/family_planning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@ import padlock from './OptionCardIcons/padlock.png';
import redX from './OptionCardIcons/redX.png';
import teddyDoctor from './OptionCardIcons/teddyDoctor.png';
import umbrella from './OptionCardIcons/umbrella.png';
import dontKnow from './OptionCardIcons/dont_know.png';
import emergencyMedicaid from './OptionCardIcons/emergency_medicaid.png';
import familyPlanning from './OptionCardIcons/family_planning.png';
import { HealthInsurance } from '../Types/FormData';

const healthInsuranceOptions = {
export type HealthInsuranceOptions = {
[Property in keyof HealthInsurance]: {
formattedMessage: JSX.Element;
image: string;
};
};

const healthInsuranceOptions: HealthInsuranceOptions = {
none: {
formattedMessage: (
<FormattedMessage id="healthInsuranceOptions.none-they" defaultMessage="They do not have health insurance" />
),
image: redX,
},
employer: {
formattedMessage: (
<FormattedMessage id="healthInsuranceOptions.employer" defaultMessage="Employer-provided health insurance" />
Expand All @@ -15,13 +32,13 @@ const healthInsuranceOptions = {
},
private: {
formattedMessage: (
<FormattedMessage id="healthInsuranceOptions.private" defaultMessage="Private health insurance" />
<FormattedMessage id="healthInsuranceOptions.private" defaultMessage="Private (non-employer) health insurance" />
),
image: padlock,
},
medicaid: {
formattedMessage: (
<FormattedMessage id="healthInsuranceOptions.medicaid" defaultMessage="Health First Colorado (Medicaid)" />
<FormattedMessage id="healthInsuranceOptions.medicaid" defaultMessage="Health First Colorado (Full Medicaid)" />
),
image: bill,
},
Expand All @@ -35,14 +52,24 @@ const healthInsuranceOptions = {
),
image: teddyDoctor,
},
none: {
emergency_medicaid: {
formattedMessage: (
<FormattedMessage
id="healthInsuranceOptions.none"
defaultMessage="One or more household member(s) do not have health insurance"
id="healthInsuranceOptions.emergency_medicaid"
defaultMessage="Emergency Medicaid / Reproductive Health"
/>
),
image: redX,
image: emergencyMedicaid,
},
family_planning: {
formattedMessage: (
<FormattedMessage id="healthInsuranceOptions.family_planning" defaultMessage="Family Planning Limited Medicaid" />
),
image: familyPlanning,
},
dont_know: {
formattedMessage: <FormattedMessage id="healthInsuranceOptions.dont_know" defaultMessage="Don't Know" />,
image: dontKnow,
},
};

Expand Down
21 changes: 0 additions & 21 deletions src/Assets/questions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ import {
selectHasError,
displayReferralSourceHelperText,
signUpOptionsHaveError,
healthInsuranceHasError,
acuteHHConditionsHasError,
displayHealthInsuranceHelperText,
displayBenefitsHelperText,
countySelectHelperText,
otherReferalSourceHelperText,
} from './validationFunctions.tsx';
import referralOptions from './referralOptions.tsx';
import countiesByZipcode from './countiesByZipcode.js';
import signUpOptions from './signUpOptions.js';
import healthInsuranceOptions from './healthInsuranceOptions.js';
import acuteConditionOptions from './acuteConditionOptions';
import { FormattedMessage } from 'react-intl';

export type QuestionNames =
| 'zipcode'
| 'healthInsurance'
| 'householdSize'
| 'householdData'
| 'hasExpenses'
Expand Down Expand Up @@ -75,23 +71,6 @@ const questions = {
],
headerType: 'aboutHousehold',
},
healthInsurance: {
name: 'healthInsurance',
question: (
<FormattedMessage
id="questions.healthInsurance"
defaultMessage="Which type(s) of health insurance do members of your household have? Check all that apply."
/>
),
componentDetails: {
componentType: 'OptionCardGroup',
inputName: 'healthInsurance',
options: healthInsuranceOptions,
inputError: healthInsuranceHasError,
inputHelperText: displayHealthInsuranceHelperText,
},
headerType: 'aboutHousehold',
},
householdSize: {
name: 'householdSize',
question: (
Expand Down
2 changes: 0 additions & 2 deletions src/Assets/stepDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import questions, { type QuestionNames } from './questions';
export const startingQuestionNumber = 3;
const defaultStepDirectory: QuestionNames[] = [
'zipcode',
'healthInsurance',
//the hhSize and hhData have to be consecutive
'householdSize',
'householdData',
Expand All @@ -16,7 +15,6 @@ const defaultStepDirectory: QuestionNames[] = [
];
const referrerStepDirectory: QuestionNames[] = [
'zipcode',
'healthInsurance',
//the hhSize and hhData have to be consecutive
'householdSize',
'householdData',
Expand Down
11 changes: 2 additions & 9 deletions src/Assets/updateScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ const getScreensBody = (formData, languageCode) => {
has_wic: formData.benefits.wic,
has_upk: formData.benefits.upk,
has_coctc: formData.benefits.coctc,
has_employer_hi: formData.healthInsurance.employer,
has_private_hi: formData.healthInsurance.private,
has_medicaid_hi: formData.healthInsurance.medicaid,
has_medicare_hi: formData.healthInsurance.medicare,
has_chp_hi: formData.healthInsurance.chp,
has_no_hi: formData.healthInsurance.none,
referral_source: finalReferralSource,
referrer_code: formData.immutableReferrer,
needs_food: formData.acuteHHConditions.food,
Expand Down Expand Up @@ -78,16 +72,15 @@ const getHouseholdMemberBody = (householdMemberData) => {
const incomes = getIncomeStreamsBodies(householdMemberData);

return {
relationship: householdMemberData.relationshipToHH,
age: Number(householdMemberData.age),
relationship: householdMemberData.relationshipToHH,
student: householdMemberData.student,
pregnant: householdMemberData.pregnant,
visually_impaired: householdMemberData.blindOrVisuallyImpaired,
disabled: householdMemberData.disabled,
medicaid: householdMemberData.medicaid,
disability_medicaid: householdMemberData.disabilityRelatedMedicaid,
has_income: householdMemberData.hasIncome,
income_streams: incomes,
insurance: householdMemberData.healthInsurance,
};
};

Expand Down
86 changes: 55 additions & 31 deletions src/Assets/validationFunctions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,47 +218,70 @@ const displayHouseholdMemberAgeHelperText: MessageFunction<string> = (applicantA
};

const personDataIsValid: ValidationFunction<HouseholdData> = (householdDataState) => {
const { age, relationshipToHH, hasIncome, incomeStreams } = householdDataState;
const { age, relationshipToHH, hasIncome, incomeStreams, healthInsurance } = householdDataState;

const ageIsValid = Number(age) >= 0 && age !== '';
const relationshipToHHIsValid = relationshipToHH !== '';
const incomeIsValid = (hasIncome && incomeStreamsAreValid(incomeStreams)) || !hasIncome;

return ageIsValid && relationshipToHHIsValid && incomeIsValid;
const healthInsuranceIsValid = healthInsuranceDataIsValid(healthInsurance);

return ageIsValid && relationshipToHHIsValid && incomeIsValid && healthInsuranceIsValid;
};

const getHealthInsuranceError: MessageFunction<HealthInsurance> = (healthInsurance: HealthInsurance) => {
if (healthInsuranceDataIsValid(healthInsurance) === false) {
if (healthInsurance.none === true) {
//then they chose none and another option
return (
<ErrorMessageWrapper fontSize="1rem">
<FormattedMessage
id="validation-helperText.hhMemberInsuranceNone"
defaultMessage="Please do not select any other options if you/they do not have health insurance"
/>
</ErrorMessageWrapper>
);
} else if (healthInsurance.dont_know === true) {
//then they chose dont_know and another option
return (
<ErrorMessageWrapper fontSize="1rem">
<FormattedMessage
id="validation-helperText.hhMemberInsuranceDontKnow"
defaultMessage="Please do not select any other options if you/they don't know"
/>
</ErrorMessageWrapper>
);
} else {
//they haven't selected an option
return (
<ErrorMessageWrapper fontSize="1rem">
<FormattedMessage
id="validation-helperText.hhMemberInsurance"
defaultMessage="Please select at least one health insurance option"
/>
</ErrorMessageWrapper>
);
}
}
};

const getPersonDataErrorMsg: MessageFunction<HouseholdData> = (householdDataState) => {
const { age, relationshipToHH, hasIncome, incomeStreams } = householdDataState;
const healthInsuranceDataIsValid: ValidationFunction<HealthInsurance> = (hhMemberHealthInsData) => {
const numOfTrueValues = Object.values(hhMemberHealthInsData).filter(
(healthInsuranceValue) => healthInsuranceValue === true,
).length;

if (Number(age) < 0 || age === '') {
return (
<ErrorMessageWrapper fontSize="1rem">
<FormattedMessage
id="validation-helperText.hhMemberAgeB"
defaultMessage="Please enter 0 or a positive number for the household member's age"
/>
</ErrorMessageWrapper>
);
} else if (relationshipToHH === '') {
return (
<ErrorMessageWrapper fontSize="1rem">
<FormattedMessage id="errorMessage-HHMemberRelationship" defaultMessage="Please select a relationship" />
</ErrorMessageWrapper>
);
} else if (hasIncome && incomeStreamsAreValid(incomeStreams) === false) {
return (
<ErrorMessageWrapper fontSize="1rem">
<FormattedMessage
id="validation-helperText.hhMemberIncome"
defaultMessage="Please select and enter a response for all income fields"
/>
</ErrorMessageWrapper>
);
if (hhMemberHealthInsData.none === true || hhMemberHealthInsData.dont_know === true) {
//check here to ensure that that is the ONLY option that was selected via numOfTrueValues
return numOfTrueValues === 1;
} else {
return '';
const atLeastOneOptionWasSelected = numOfTrueValues > 0;
return atLeastOneOptionWasSelected;
}
};

const healthInsuranceDataHasError: ValidationFunction<HealthInsurance> = (hhMemberHealthInsData: HealthInsurance) => {
return !healthInsuranceDataIsValid(hhMemberHealthInsData);
};

const emailHasError: ValidationFunction<string> = (email) => {
return !/^.+@(?:[a-zA-Z0-9]+\.)+[A-Za-z]+$/.test(email);
};
Expand Down Expand Up @@ -571,7 +594,6 @@ export {
acuteHHConditionsHasError,
benefitsHasError,
displayBenefitsHelperText,
getPersonDataErrorMsg,
countySelectHelperText,
expenseTypeHelperText,
relationTypeHelperText,
Expand All @@ -580,4 +602,6 @@ export {
otherReferalSourceHelperText,
termsOfServiceHasError,
displayAgreeToTermsErrorMessage,
healthInsuranceDataHasError,
getHealthInsuranceError,
};
57 changes: 45 additions & 12 deletions src/Components/Confirmation/Confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useNavigate, Link, useParams } from 'react-router-dom';
import { Button } from '@mui/material';
import { FormattedMessage, useIntl } from 'react-intl';
import relationshipOptions from '../../Assets/relationshipOptions';
import taxYearOptions from '../../Assets/taxYearOptions';
import referralOptions from '../../Assets/referralOptions';
import incomeOptions from '../../Assets/incomeOptions';
import frequencyOptions from '../../Assets/frequencyOptions';
Expand Down Expand Up @@ -62,7 +61,7 @@ const Confirmation = () => {
const allHouseholdAges = getAllHouseholdAges();

const householdMemberDataBlocks = householdData.map((personData, i) => {
const { hasIncome, incomeStreams } = personData;
const { hasIncome, incomeStreams, healthInsurance } = personData;

return (
<div key={i}>
Expand Down Expand Up @@ -95,6 +94,7 @@ const Confirmation = () => {
{hasIncome && incomeStreams.length > 0 && <ul> {listAllIncomeStreams(incomeStreams)} </ul>}
{hasIncome === false && <FormattedMessage id="confirmation.noIncome" defaultMessage=" None" />}
</article>
{displayHHMHealthInsuranceSection(healthInsurance)}
</Grid>
<Grid item xs={2} display="flex" justifyContent="flex-end">
<button
Expand All @@ -113,6 +113,20 @@ const Confirmation = () => {
return householdMemberDataBlocks;
};

const displayHHMHealthInsuranceSection = (hHMemberHealthInsurance) => {
return (
<article className="section-p">
<b>
<FormattedMessage
id="confirmation.headOfHouseholdDataBlock-healthInsuranceText"
defaultMessage="Health Insurance: "
/>{' '}
</b>
{displayHealthInsurance(hHMemberHealthInsurance)}
</article>
);
};

const displayHouseholdExpenses = () => {
const { hasExpenses, expenses } = formData;

Expand Down Expand Up @@ -387,16 +401,6 @@ const Confirmation = () => {
<>
{displayZipcodeSection()}
<p className="confirmation-section-underline"></p>
{displayHHCheckboxSection(
'healthInsurance',
'confirmation.displayAllFormData-healthInsurance',
'Household Insurance',
getQuestionUrl('healthInsurance'),
refactorOptionsList(healthInsuranceOptions),
<MedicalServicesIcon className="home-icon" />,
'edit health insurance',
)}
<p className="confirmation-section-underline"></p>
{displayHouseholdSizeSection()}
<p className="confirmation-section-underline"></p>
{displayAllMembersDataBlock()}
Expand Down Expand Up @@ -568,6 +572,35 @@ const Confirmation = () => {
return getStepDirectory(formData.immutableReferrer).length + startingQuestionNumber;
};

const displayHealthInsurance = (hHMemberHealthInsurance) => {
const selectedDontKnow = hHMemberHealthInsurance.dont_know === true;
const selectedNone = hHMemberHealthInsurance.none === true;
const allOtherSelectedOptions = Object.entries(hHMemberHealthInsurance).filter(
(hHMemberInsEntry) => hHMemberInsEntry[1] === true,
);

const allOtherSelectedOptionsString = allOtherSelectedOptions.reduce((acc, filteredHHMInsEntry, index) => {
const formattedMessageProp = healthInsuranceOptions[filteredHHMInsEntry[0]].formattedMessage.props;
const translatedAriaLabel = intl.formatMessage({ ...formattedMessageProp });

if (allOtherSelectedOptions.length - 1 === index) {
//we're at the last element in the array => don't include the comma
return (acc += translatedAriaLabel);
} else {
//include a comma to separate each string
return (acc += translatedAriaLabel + ', ');
}
}, '');

if (selectedDontKnow) {
return <>{healthInsuranceOptions.dont_know.formattedMessage}</>;
} else if (selectedNone) {
return <>{healthInsuranceOptions.none.formattedMessage}</>;
} else {
return <>{allOtherSelectedOptionsString}</>;
}
};

return (
<main className="benefits-form">
<h1 className="sub-header">
Expand Down
Loading

0 comments on commit ce11d93

Please sign in to comment.