Skip to content

Commit cc2d863

Browse files
committed
Fix reporting API consent no-response totals
Follow up to 0f43de1, which fixed the model count but not the aggregate query used by the reporting API. Update the aggregate totals to include the full no-response status set so the breakdown matches the no consent recorded total. Add regression coverage for the aggregate path. Jira-Issue: MAV-7075
1 parent 25ad0b5 commit cc2d863

2 files changed

Lines changed: 74 additions & 1 deletion

File tree

app/models/reporting_api/total.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ def self.with_aggregate_metrics
119119
"consent_status IN (#{CONSENT_GIVEN_STATUSES.join(",")})"
120120
no_consent_condition =
121121
"consent_status IN (#{NO_CONSENT_STATUSES.join(",")})"
122+
consent_no_response_condition =
123+
"consent_status IN (#{CONSENT_NO_RESPONSE_STATUSES.join(",")})"
122124
select(
123125
"COUNT(DISTINCT patient_id) AS cohort",
124126
"COUNT(DISTINCT patient_id) FILTER (WHERE #{vaccinated_condition}) AS vaccinated",
125127
"COUNT(DISTINCT patient_id) FILTER (WHERE NOT (#{vaccinated_condition})) AS not_vaccinated",
126128
"COUNT(DISTINCT patient_id) FILTER (WHERE #{consent_given_condition}) AS consent_given",
127129
"COUNT(DISTINCT patient_id) FILTER (WHERE #{no_consent_condition}) AS no_consent",
128-
"COUNT(DISTINCT patient_id) FILTER (WHERE consent_status = #{CONSENT_NO_RESPONSE}) AS consent_no_response",
130+
"COUNT(DISTINCT patient_id) FILTER (WHERE #{consent_no_response_condition}) AS consent_no_response",
129131
"COUNT(DISTINCT patient_id) FILTER (WHERE consent_status = #{CONSENT_REFUSED}) AS consent_refused",
130132
"COUNT(DISTINCT patient_id) FILTER (WHERE consent_status = #{CONSENT_CONFLICTS}) AS consent_conflicts"
131133
)

spec/controllers/api/reporting/totals_controller_spec.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,77 @@
286286
"consent_conflicts" => 0
287287
)
288288
end
289+
290+
it "counts all no response consent statuses consistently in aggregate totals" do
291+
team = Team.last
292+
programme = Programme.hpv
293+
team.programmes << programme
294+
295+
session = create(:session, team:, programmes: [programme])
296+
297+
no_response_patient =
298+
create(:patient, session:, parents: [create(:parent)])
299+
create(
300+
:consent_notification,
301+
:request,
302+
patient: no_response_patient,
303+
session:,
304+
programmes: [programme]
305+
)
306+
307+
create(:patient, session:, parents: [create(:parent, :non_contactable)])
308+
309+
request_scheduled_session =
310+
create(
311+
:session,
312+
team:,
313+
programmes: [programme],
314+
send_consent_requests_at: Date.tomorrow
315+
)
316+
create(
317+
:patient,
318+
session: request_scheduled_session,
319+
parents: [create(:parent)]
320+
)
321+
322+
create(:patient, session:, parents: [create(:parent)])
323+
324+
refused_patient = create(:patient, session:, parents: [create(:parent)])
325+
create(:consent, :refused, patient: refused_patient, programme:, team:)
326+
327+
conflict_patient = create(:patient, session:)
328+
parent1 = create(:parent)
329+
parent2 = create(:parent)
330+
create(:parent_relationship, patient: conflict_patient, parent: parent1)
331+
create(:parent_relationship, patient: conflict_patient, parent: parent2)
332+
create(
333+
:consent,
334+
:given,
335+
patient: conflict_patient,
336+
programme:,
337+
team:,
338+
parent: parent1
339+
)
340+
create(
341+
:consent,
342+
:refused,
343+
patient: conflict_patient,
344+
programme:,
345+
team:,
346+
parent: parent2
347+
)
348+
349+
PatientStatusUpdater.call
350+
351+
refresh_reporting_views!
352+
353+
get :index, params: { programme: "hpv" }
354+
355+
expect(parsed_response["no_consent"]).to eq(6)
356+
expect(parsed_response["consent_refused"]).to eq(1)
357+
expect(parsed_response["consent_conflicts"]).to eq(1)
358+
expect(parsed_response["consent_no_response"]).to eq(4)
359+
end
289360
end
290361

291362
describe "#index.csv" do

0 commit comments

Comments
 (0)