Skip to content

Commit

Permalink
Release/v1.4.0 [dev] (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbanting authored Nov 7, 2024
2 parents eb7bb34 + f97d768 commit 6e0fb58
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/models/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,26 @@ export class ActivityEntity {
const subscaleTableData = subscaleItem.subscaleTableData

const subscaleTableDataItem = subscaleTableData.find(({ sex, age, rawScore }) => {
let reportedAge: number | null = null
let reportedAge: string | null = null
if (typeof ageAnswer === 'string') {
reportedAge = Number(ageAnswer)
} else if ('value' in ageAnswer && typeof ageAnswer.value === 'number') {
reportedAge = ageAnswer.value
reportedAge = ageAnswer
} else if (ageAnswer && 'value' in ageAnswer && ['number', 'string'].includes(typeof ageAnswer.value)) {
reportedAge = String(ageAnswer.value)
}

const hasAgeInterval = age && typeof age === 'string' && age.includes(INTERVAL_SYMBOL)
let withAge = true

if (age) {
if (!hasAgeInterval) {
withAge = String(age) === reportedAge
} else {
const [minAge, maxAge] = age.replace(/\s/g, '').split(INTERVAL_SYMBOL)
const reportedAgeNum = Number(reportedAge)
withAge = Number(minAge) <= reportedAgeNum && reportedAgeNum <= Number(maxAge)
}
}

const withAge = age === reportedAge
const withSex = parseSex(sex) === String(genderAnswer?.value)

if (!withSex || !withAge) return false
Expand Down

0 comments on commit 6e0fb58

Please sign in to comment.