Skip to content

Commit

Permalink
Calculate Consent#responded_at from consent form (#2786)
Browse files Browse the repository at this point in the history
If the consent is linked to a consent form we should get the
`responded_at` date/time from when the consent form was submitted, not
when it was linked with the patient.

This has been spotted as a bug and the testers would like it included as
part of the work to fix inconsistent data between the consent and the
consent form
(#2772).


https://trello.com/c/2yk5lEkG/1769-linked-patient-details-shown-on-consent-response-page-instead-of-consent-form-responses
  • Loading branch information
thomasleese authored Dec 20, 2024
2 parents d47cd52 + 48fdb0b commit 4c6c518
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/consent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def can_invalidate?
end

def responded_at
invalidated_at || withdrawn_at || created_at
invalidated_at || withdrawn_at || consent_form&.recorded_at || created_at
end

def triage_needed?
Expand Down
29 changes: 29 additions & 0 deletions spec/models/consent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,35 @@
end
end

describe "#responded_at" do
subject(:responded_at) { consent.responded_at }

context "with a consent form" do
let(:consent) do
build(
:consent,
created_at: Time.current,
consent_form:
build(:consent_form, recorded_at: Time.zone.local(2024, 12, 20, 12))
)
end

it { should eq(Time.zone.local(2024, 12, 20, 12)) }
end

context "without a consent form" do
let(:consent) do
build(
:consent,
created_at: Time.zone.local(2024, 12, 20, 12),
consent_form: nil
)
end

it { should eq(Time.zone.local(2024, 12, 20, 12)) }
end
end

describe "#from_consent_form!" do
describe "the created consent object" do
subject(:consent) do
Expand Down

0 comments on commit 4c6c518

Please sign in to comment.