Skip to content

Commit 7f00758

Browse files
committed
Generate consent status from submitted at time
This changes how we determine the most recent consent response from the `created_at` to the `submitted_at`. In most cases these values will be the same, but it's possible for a consent to be matched with a patient manually which can occur some period of time after the consent was submitted. In particular, it's possible to manually match multiple consents in a different order to when they were submitted, which can lead to bugs where the patient is given the wrong consent status.
1 parent cb3bfb7 commit 7f00758

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

app/lib/consent_grouper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ def call
1515
.reject(&:invalidated?)
1616
.select(&:response_provided?)
1717
.group_by(&:name)
18-
.map { it.second.max_by(&:created_at) }
18+
.map { it.second.max_by(&:submitted_at) }
1919
else
2020
consents
2121
.where(programme_id:)
2222
.not_invalidated
2323
.response_provided
2424
.includes(:parent)
2525
.group_by(&:name)
26-
.map { it.second.max_by(&:created_at) }
26+
.map { it.second.max_by(&:submitted_at) }
2727
end
2828
end
2929

spec/models/patient/consent_status_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@
102102
it { should be(:given) }
103103
end
104104

105+
context "with a refused and given consent from the same parent at different times" do
106+
before do
107+
create(
108+
:consent,
109+
:refused,
110+
patient:,
111+
programme:,
112+
created_at: 1.day.ago,
113+
submitted_at: 2.days.ago
114+
)
115+
create(
116+
:consent,
117+
:given,
118+
patient:,
119+
programme:,
120+
created_at: 2.days.ago,
121+
submitted_at: 1.day.ago
122+
)
123+
end
124+
125+
it { should be(:given) }
126+
end
127+
105128
context "with self-consent" do
106129
before { create(:consent, :self_consent, :given, patient:, programme:) }
107130

0 commit comments

Comments
 (0)