Skip to content

Commit

Permalink
Add link to create patients from consent forms
Browse files Browse the repository at this point in the history
When an unmatched consent form doesn't map to any existing patient, we
want to allow users to create a new patient record. This record should
use an NHS number that's looked up via PDS, have a consent attached to
it that matches the consent from the parent form, and a parent that also
uses the details from the form.
  • Loading branch information
tvararu committed Nov 15, 2024
1 parent a2bbce0 commit 64463d7
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/controllers/consent_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def update_match
redirect_to action: :index
end

def new_patient
@patient = Patient.from_consent_form(@consent_form)

render layout: "two_thirds"
end

def create_patient
end

private

def consent_form_scope
Expand Down
15 changes: 15 additions & 0 deletions app/models/patient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@ def move_to_session!(new_session, from:)
end
end

def self.from_consent_form(consent_form)
new(
address_line_1: consent_form.address_line_1,
address_line_2: consent_form.address_line_2,
address_postcode: consent_form.address_postcode,
address_town: consent_form.address_town,
date_of_birth: consent_form.date_of_birth,
family_name: consent_form.family_name,
given_name: consent_form.given_name,
preferred_family_name: consent_form.preferred_family_name,
preferred_given_name: consent_form.preferred_given_name,
school: consent_form.school
)
end

class NHSNumberMismatch < StandardError
end

Expand Down
12 changes: 11 additions & 1 deletion app/views/consent_forms/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@
row.with_cell(text: consent_form.recorded_at.to_date.to_fs(:long))
row.with_cell(text: consent_form.full_name)
row.with_cell(text: consent_form.parent_full_name)
row.with_cell(text: govuk_link_to("Find match", consent_form))
row.with_cell do
tag.ul(class: "app-action-list") do
match_link = link_to("Match with record", consent_form)
create_link = link_to("Create record", patient_consent_form_path(consent_form))

safe_join([
tag.li(class: "app-action-list__item") { match_link },
tag.li(class: "app-action-list__item") { create_link },
])
end
end
end
end
end
Expand Down
45 changes: 45 additions & 0 deletions app/views/consent_forms/new_patient.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<% content_for :before_main do %>
<%= render AppBacklinkComponent.new(
href: consent_forms_path,
name: "unmatched consent responses",
) %>
<% end %>
<% page_title = "Create a new child record from this consent response?" %>
<%= h1 page_title: do %>
<span class="nhsuk-caption-l">
Consent response from <%= @consent_form.parent_full_name %>
</span>
<%= page_title %>
<% end %>
<%= render AppCardComponent.new do |c| %>
<% c.with_heading { "Child record" } %>
<%= render AppPatientSummaryComponent.new(@patient,
show_preferred_name: true,
show_address: true,
show_parent_or_guardians: true) %>
<% end %>
<%= render AppCardComponent.new do |c|
c.with_heading { "Consent response" }
render AppConsentFormSummaryComponent.new(
name: @consent_form.parent_full_name,
relationship: @consent_form.parent_relationship_label,
contact: {
phone: @consent_form.parent_phone,
email: @consent_form.parent_email,
},
response: {
text: @consent_form.summary_with_route,
timestamp: @consent_form.recorded_at,
},
refusal_reason: {
reason: @consent_form.human_enum_name(:reason).presence,
notes: @consent_form.reason_notes,
},
)
end %>
<%= govuk_button_to "Create a new record from response",
patient_consent_form_path(@consent_form) %>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
member do
get "match/:patient_id", action: :edit_match, as: :match
post "match/:patient_id", action: :update_match

get "patient", action: :new_patient
post "patient", action: :create_patient
end
end

Expand Down

0 comments on commit 64463d7

Please sign in to comment.