dassbot / src /dass.ts
brianhuster's picture
Deploy DASS-21 app to Hugging Face Space
a3ee1b6
Raw
History Blame Contribute Delete
4.92 kB
export type Scale = 'stress' | 'anxiety' | 'depression';
export type AnswerValue = 0 | 1 | 2 | 3;
export type Question = {
id: number;
text: string;
scale: Scale;
};
export type SeverityBand = {
label: string;
min: number;
max: number;
tone: string;
};
export const answerOptions = [
'Không đúng với tôi chút nào cả',
'Đúng với tôi một phần, hoặc thỉnh thoảng mới đúng',
'Đúng với tôi phần nhiều, hoặc phần lớn thời gian là đúng',
'Hoàn toàn đúng với tôi, hoặc hầu hết thời gian là đúng',
] as const;
export const questions: Question[] = [
{ id: 1, text: 'Tôi thấy khó mà thoải mái được', scale: 'stress' },
{ id: 2, text: 'Tôi bị khô miệng', scale: 'anxiety' },
{ id: 3, text: 'Tôi không thấy có chút cảm xúc tích cực nào', scale: 'depression' },
{
id: 4,
text: 'Tôi bị rối loạn nhịp thở (thở gấp, khó thở dù chẳng làm việc gì nặng)',
scale: 'anxiety',
},
{ id: 5, text: 'Tôi thấy khó bắt tay vào công việc', scale: 'depression' },
{ id: 6, text: 'Tôi đã phản ứng thái quá khi có những sự việc xảy ra', scale: 'stress' },
{ id: 7, text: 'Tôi bị ra mồ hôi (chẳng hạn như mồ hôi tay...)', scale: 'anxiety' },
{ id: 8, text: 'Tôi thấy mình đang suy nghĩ quá nhiều', scale: 'stress' },
{
id: 9,
text: 'Tôi lo lắng về những tình huống có thể khiến tôi hoảng sợ hoặc biến tôi thành trò cười',
scale: 'anxiety',
},
{ id: 10, text: 'Tôi thấy mình chẳng có gì để mong đợi cả', scale: 'depression' },
{ id: 11, text: 'Tôi thấy bản thân dễ bị kích động', scale: 'stress' },
{ id: 12, text: 'Tôi thấy khó thư giãn được', scale: 'stress' },
{ id: 13, text: 'Tôi cảm thấy chán nản, thất vọng', scale: 'depression' },
{ id: 14, text: 'Tôi không chấp nhận được việc có cái gì đó xen vào cản trở việc tôi đang làm', scale: 'stress' },
{ id: 15, text: 'Tôi thấy mình gần như hoảng loạn', scale: 'anxiety' },
{ id: 16, text: 'Tôi không thấy hăng hái với bất kỳ việc gì nữa', scale: 'depression' },
{ id: 17, text: 'Tôi cảm thấy mình chẳng đáng làm người', scale: 'depression' },
{ id: 18, text: 'Tôi thấy mình khá dễ phật ý, tự ái', scale: 'stress' },
{
id: 19,
text: 'Tôi nghe thấy rõ tiếng nhịp tim dù chẳng làm việc gì cả (ví dụ, tiếng nhịp tim tăng, tiếng tim loạn nhịp)',
scale: 'anxiety',
},
{ id: 20, text: 'Tôi hay sợ vô cớ', scale: 'anxiety' },
{ id: 21, text: 'Tôi thấy cuộc sống vô nghĩa', scale: 'depression' },
] as const;
export const severityBands: Record<Scale, SeverityBand[]> = {
depression: [
{ label: 'Bình thường', min: 0, max: 9, tone: 'normal' },
{ label: 'Nhẹ', min: 10, max: 13, tone: 'mild' },
{ label: 'Vừa', min: 14, max: 20, tone: 'moderate' },
{ label: 'Nặng', min: 21, max: 27, tone: 'severe' },
{ label: 'Rất nặng', min: 28, max: Infinity, tone: 'extreme' },
],
anxiety: [
{ label: 'Bình thường', min: 0, max: 7, tone: 'normal' },
{ label: 'Nhẹ', min: 8, max: 9, tone: 'mild' },
{ label: 'Vừa', min: 10, max: 14, tone: 'moderate' },
{ label: 'Nặng', min: 15, max: 19, tone: 'severe' },
{ label: 'Rất nặng', min: 20, max: Infinity, tone: 'extreme' },
],
stress: [
{ label: 'Bình thường', min: 0, max: 14, tone: 'normal' },
{ label: 'Nhẹ', min: 15, max: 18, tone: 'mild' },
{ label: 'Vừa', min: 19, max: 25, tone: 'moderate' },
{ label: 'Nặng', min: 26, max: 33, tone: 'severe' },
{ label: 'Rất nặng', min: 34, max: Infinity, tone: 'extreme' },
],
};
export const scaleLabels: Record<Scale, string> = {
stress: 'Stress',
anxiety: 'Lo âu',
depression: 'Trầm cảm',
};
export const scaleDescriptions: Record<Scale, string> = {
stress: 'Căng thẳng, quá tải và khó thư giãn',
anxiety: 'Căng thẳng lo âu, hồi hộp và phản ứng sinh lý',
depression: 'Khí sắc thấp, mất hứng thú và tuyệt vọng',
};
export function getSeverity(scale: Scale, score: number) {
return (
severityBands[scale].find((band) => score >= band.min && score <= band.max) ??
severityBands[scale][severityBands[scale].length - 1]
);
}
export function scoreScale(answers: (AnswerValue | null)[]) {
const totals = questions.reduce<Record<Scale, number>>(
(acc, question, index) => {
const value = answers[index] ?? 0;
acc[question.scale] += value;
return acc;
},
{ stress: 0, anxiety: 0, depression: 0 },
);
return {
stress: totals.stress * 2,
anxiety: totals.anxiety * 2,
depression: totals.depression * 2,
};
}