From 2b2f5c42590f07c6f931353613b4bc4658f21132 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 17 Oct 2024 12:14:19 +0100 Subject: [PATCH] Add a view for a single patient This adds a page that allows the user to see an individual child record based on the designs in the prototype. --- .../app_patient_table_component.html.erb | 2 +- app/controllers/patients_controller.rb | 8 ++++++-- app/views/patients/show.html.erb | 15 +++++++++++++++ config/routes.rb | 2 +- spec/features/manage_children_spec.rb | 15 ++++++++++++++- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 app/views/patients/show.html.erb diff --git a/app/components/app_patient_table_component.html.erb b/app/components/app_patient_table_component.html.erb index 2dd48b93c..37add46f6 100644 --- a/app/components/app_patient_table_component.html.erb +++ b/app/components/app_patient_table_component.html.erb @@ -18,7 +18,7 @@ <% body.with_row do |row| %> <% row.with_cell do %> Full name - <%= patient.full_name %> + <%= link_to patient.full_name, patient_path(patient) %> <% end %> <% row.with_cell do %> diff --git a/app/controllers/patients_controller.rb b/app/controllers/patients_controller.rb index 05768e948..32d2389ac 100644 --- a/app/controllers/patients_controller.rb +++ b/app/controllers/patients_controller.rb @@ -3,9 +3,13 @@ class PatientsController < ApplicationController include Pagy::Backend - layout "full" - def index @pagy, @patients = pagy(policy_scope(Patient).order_by_name) + + render layout: "full" + end + + def show + @patient = policy_scope(Patient).find(params[:id]) end end diff --git a/app/views/patients/show.html.erb b/app/views/patients/show.html.erb new file mode 100644 index 000000000..c3f9a4d94 --- /dev/null +++ b/app/views/patients/show.html.erb @@ -0,0 +1,15 @@ +<% content_for :before_main do %> + <%= render AppBreadcrumbComponent.new(items: [ + { text: "Home", href: programmes_path }, + { text: t("patients.index.title"), href: patients_path }, + ]) %> +<% end %> + +<%= h1 page_title: @patient.initials do %> + <%= @patient.full_name %> +<% end %> + +<%= render AppCardComponent.new do |c| %> + <% c.with_heading { "Child record" } %> + <%= render AppPatientSummaryComponent.new(@patient, show_common_name: true, show_address: true, show_parent_or_guardians: true) %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 2e0433dfb..6a6b5ade9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,7 +79,7 @@ end end - resources :patients, only: :index + resources :patients, only: %i[index show] resources :programmes, only: %i[index show] do get "sessions", on: :member diff --git a/spec/features/manage_children_spec.rb b/spec/features/manage_children_spec.rb index cd40d9ca6..cc283525e 100644 --- a/spec/features/manage_children_spec.rb +++ b/spec/features/manage_children_spec.rb @@ -7,6 +7,9 @@ when_i_click_on_children then_i_see_the_children + + when_i_click_on_a_child + then_i_see_the_child end def given_my_team_exists @@ -14,7 +17,8 @@ def given_my_team_exists end def and_patients_exist - create_list(:patient, 10, team: @team) + create(:patient, team: @team, given_name: "John", family_name: "Smith") + create_list(:patient, 9, team: @team) end def when_i_click_on_children @@ -27,4 +31,13 @@ def when_i_click_on_children def then_i_see_the_children expect(page).to have_content("10 children") end + + def when_i_click_on_a_child + click_on "John Smith" + end + + def then_i_see_the_child + expect(page).to have_title("JS") + expect(page).to have_content("John Smith") + end end