@@ -13,30 +13,40 @@ def initialize(sessions, programme:)
13
13
attr_reader :sessions , :programme
14
14
15
15
def cohort_count ( session :)
16
- session . patient_sessions . length . to_s
16
+ format_number ( session . patient_sessions . count )
17
17
end
18
18
19
19
def number_stat ( session :)
20
- session . patient_sessions . select { yield it } . length . to_s
20
+ format_number ( session . patient_sessions . select { yield it } . length )
21
21
end
22
22
23
23
def percentage_stat ( session :)
24
- total_count = session . patient_sessions . length
25
- return nil if total_count . zero?
26
-
27
- count = session . patient_sessions . select { yield it } . length
24
+ format_percentage (
25
+ session . patient_sessions . select { yield it } . length ,
26
+ session . patient_sessions . count
27
+ )
28
+ end
28
29
29
- number_to_percentage ( count / total_count . to_f * 100.0 , precision : 0 )
30
+ def no_response_scope ( session :)
31
+ session . patient_sessions . where (
32
+ Patient ::ConsentStatus
33
+ . for_patient_session
34
+ . where ( programme :)
35
+ . no_response
36
+ . arel
37
+ . exists
38
+ )
30
39
end
31
40
32
41
def no_response_count ( session :)
33
- number_stat ( session :) { it . patient . consent_outcome . no_response? ( programme ) }
42
+ format_number ( no_response_scope ( session :) . count )
34
43
end
35
44
36
45
def no_response_percentage ( session :)
37
- percentage_stat ( session :) do
38
- it . patient . consent_outcome . no_response? ( programme )
39
- end
46
+ format_percentage (
47
+ no_response_scope ( session :) . count ,
48
+ session . patient_sessions . count
49
+ )
40
50
end
41
51
42
52
def triage_needed_count ( session :)
@@ -50,4 +60,12 @@ def vaccinated_count(session:)
50
60
def vaccinated_percentage ( session :)
51
61
percentage_stat ( session :) { it . session_outcome . vaccinated? ( programme ) }
52
62
end
63
+
64
+ def format_number ( count ) = count . to_s
65
+
66
+ def format_percentage ( count , total_count )
67
+ return nil if total_count . zero?
68
+
69
+ number_to_percentage ( count / total_count . to_f * 100.0 , precision : 0 )
70
+ end
53
71
end
0 commit comments