-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcdss.pl
58 lines (48 loc) · 1.51 KB
/
cdss.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
use strict;
use warnings;
sub calculate_cdss_total_score {
my @cdss_items = (
'Depression',
'Hopelessness',
'Self-depreciation',
'Guilty ideas of reference',
'Pathological guilt',
'Morning depression',
'Early wakening',
'Suicide',
'Observed depression',
);
my %cdss_scores;
# Get user input for each CDSS item
foreach my $item (@cdss_items) {
my $valid_input = 0;
while (!$valid_input) {
print "Enter score for $item (0-3): ";
my $score = <STDIN>;
chomp($score);
# Validate input
if ($score =~ /^\d+$/ && $score >= 0 && $score <= 3) {
$cdss_scores{$item} = $score;
$valid_input = 1;
} else {
print "Invalid input. Please enter a number between 0 and 3.\n";
}
}
}
# Calculate total CDSS score
my $total_score = 0;
foreach my $item_score (values %cdss_scores) {
$total_score += $item_score;
}
return %cdss_scores, total_score => $total_score;
}
# Main program
print "Calgary Depression Scale for Schizophrenia (CDSS) Total Score Calculator\n";
my %cdss_scores = calculate_cdss_total_score();
# Print the total score
print "\nCDSS Item Scores:\n";
for my $item (keys %cdss_scores) {
print "$item: $cdss_scores{$item}\n";
}
print "\nTotal CDSS Score: $cdss_scores{total_score}\n";