-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
184 additions
and
237 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { z } from 'zod' | ||
import { EnumNumberInputType, ScoreInputSchemaType } from '../../../types' | ||
|
||
export const type = { | ||
type: z | ||
.union([ | ||
z.literal(0), | ||
z.literal(1), | ||
z.literal(2), | ||
z.literal(3), | ||
z.literal(4), | ||
z.literal(5), | ||
]) | ||
.optional(), | ||
uiOptions: { | ||
options: [ | ||
{ value: 0 }, | ||
{ value: 1 }, | ||
{ value: 2 }, | ||
{ value: 3 }, | ||
{ value: 4 }, | ||
{ value: 5 }, | ||
], | ||
}, | ||
} satisfies EnumNumberInputType | ||
|
||
export const OSWESTRY_INPUTS = { | ||
'1_pain': { | ||
label: { | ||
en: 'Pain intensity', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
'2_personal_care': { | ||
label: { | ||
en: 'Personal care (washing, dressing etc)', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
'3_lifting': { | ||
label: { | ||
en: 'Lifting', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
'4_running': { | ||
label: { | ||
en: 'Walking', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
'5_sitting': { | ||
label: { | ||
en: 'Sitting', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
'6_standing': { | ||
label: { | ||
en: 'Standing', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
'7_sleep': { | ||
label: { | ||
en: 'Sleeping', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
'8_sex_life': { | ||
label: { | ||
en: 'Sex life (if applicable)', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
'9_social_life': { | ||
label: { | ||
en: 'Social life', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
'10_travel': { | ||
label: { | ||
en: 'Travelling', | ||
nl: '', | ||
}, | ||
...type, | ||
}, | ||
} satisfies ScoreInputSchemaType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { z } from 'zod' | ||
import { ScoreOutputSchemaType } from '../../../types' | ||
|
||
export const OSWESTRY_OUTPUT = { | ||
OSWESTRY: { | ||
label: { en: 'Oswestry score' }, | ||
type: z.number(), | ||
}, | ||
} satisfies ScoreOutputSchemaType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ScoreType } from '../../types' | ||
import { OSWESTRY_OUTPUT, OSWESTRY_INPUTS } from './definition' | ||
import { sum } from 'lodash' | ||
|
||
export const oswestry: ScoreType< | ||
typeof OSWESTRY_INPUTS, | ||
typeof OSWESTRY_OUTPUT | ||
> = { | ||
name: 'Oswestry', | ||
readmeLocation: __dirname, | ||
inputSchema: OSWESTRY_INPUTS, | ||
outputSchema: OSWESTRY_OUTPUT, | ||
calculate: ({ data }) => { | ||
const MIN_ANSWERS_NEEDED_TO_CALCULATE_SCORE = | ||
Object.keys(OSWESTRY_INPUTS).length - 1 | ||
|
||
const validInputs = Object.values(data).filter(v => v !== undefined) | ||
|
||
if (validInputs.length < MIN_ANSWERS_NEEDED_TO_CALCULATE_SCORE) { | ||
return { | ||
OSWESTRY: null, | ||
} | ||
} | ||
|
||
const MAX_ANSWER = 5 | ||
const MAX_SCORE = validInputs.length * MAX_ANSWER | ||
const score = (sum(validInputs) / MAX_SCORE) * 100 | ||
|
||
return { | ||
OSWESTRY: Math.round(score), | ||
} | ||
}, | ||
} |
Oops, something went wrong.