Skip to content

Commit

Permalink
remove specific function strategies in favor of general one
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhao99 committed May 16, 2024
1 parent 6f68b66 commit 70cd66f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const CovidAoEForm = ({
const { hasSymptoms } = generateSymptomAoeConstants(
responses,
hasAttemptedSubmit,
mapRespiratorySymptomBoolLiteralsToBool
respiratorySymptomDefinitions
);
return (
<div className="grid-col-auto" id="covid-aoe-form">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ export function generateSexualActivityAoeConstants(
export function generateSymptomAoeConstants(
responses: AoeQuestionResponses,
hasAttemptedSubmit: boolean,
symptomBoolLiteralToBoolTranslator: (
symptomsJsonString: string | null | undefined
) => Record<string, boolean>
symptomDefinitionMap: SymptomDefinitionMap[]
) {
const isSymptomsAnswered = typeof responses.noSymptoms == "boolean";
const isSymptomOnsetDateAnswered = !!responses.symptomOnset;
Expand All @@ -127,23 +125,20 @@ export function generateSymptomAoeConstants(
if (responses.noSymptoms === false) {
hasSymptoms = "YES";
}
const symptoms: Record<string, boolean> = mapSymptomBoolLiteralsToBool(
responses.symptoms,
symptomDefinitionMap
);

const isSymptomOnsetAnswered =
!!responses.symptoms &&
Object.values(symptomBoolLiteralToBoolTranslator(responses.symptoms)).some(
(x) => x?.valueOf()
);
!!responses.symptoms && Object.values(symptoms).some((x) => x?.valueOf());

const showSymptomOnsetError =
hasAttemptedSubmit &&
isSymptomsAnswered &&
responses.noSymptoms === false &&
!isSymptomOnsetAnswered;

const symptoms: Record<string, boolean> = symptomBoolLiteralToBoolTranslator(
responses.symptoms
);

return {
showSymptomsError,
showSymptomOnsetDateError,
Expand All @@ -164,12 +159,12 @@ export function stringifySymptomJsonForAoeUpdate(

if (_.isEqual(symptomKeys, Object.keys(respiratorySymptomsMap))) {
symptomPayload = JSON.stringify(
mapRespiratorySymptomBoolLiteralsToBool(symptomJson)
mapSymptomBoolLiteralsToBool(symptomJson, respiratorySymptomDefinitions)
);
}
if (_.isEqual(symptomKeys, Object.keys(syphilisSymptomsMap))) {
symptomPayload = JSON.stringify(
mapSyphilisSymptomBoolLiteralsToBool(symptomJson)
mapSymptomBoolLiteralsToBool(symptomJson, syphilisSymptomDefinitions)
);
}
return symptomPayload;
Expand All @@ -180,10 +175,16 @@ export function mapSpecifiedSymptomBoolLiteralsToBool(
disease: AOEFormOption
) {
if (disease === AOEFormOption.COVID) {
return mapRespiratorySymptomBoolLiteralsToBool(symptomsJsonString);
return mapSymptomBoolLiteralsToBool(
symptomsJsonString,
syphilisSymptomDefinitions
);
}
if (disease === AOEFormOption.SYPHILIS) {
return mapSyphilisSymptomBoolLiteralsToBool(symptomsJsonString);
return mapSymptomBoolLiteralsToBool(
symptomsJsonString,
syphilisSymptomDefinitions
);
}
// there are no symptoms for that test card, so return true
return {
Expand All @@ -200,15 +201,6 @@ export const mapRespiratorySymptomBoolLiteralsToBool = (
);
};

export const mapSyphilisSymptomBoolLiteralsToBool = (
symptomsJsonString: string | null | undefined
) => {
return mapSymptomBoolLiteralsToBool(
symptomsJsonString,
syphilisSymptomDefinitions
);
};

export const mapSymptomBoolLiteralsToBool = (
symptomsJsonString: string | null | undefined,
symptomSelectionMap: SymptomDefinitionMap[]
Expand Down

0 comments on commit 70cd66f

Please sign in to comment.