Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/controllers/api/testing/patients_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

class API::Testing::PatientsController < API::Testing::BaseController
def create
patient = Patient.new(patient_params)
patient.birth_academic_year = patient.date_of_birth.academic_year

if patient.save
render json: patient, status: :created
else
render json: patient.errors, status: :unprocessable_content
end
end

private

def patient_params
params.require(:patient).permit(
:given_name,
:family_name,
:date_of_birth,
:nhs_number,
:gender_code,
:address_line_1,
:address_line_2,
:address_town,
:address_postcode,
:school_id,
:gp_practice_id
)
end
end
20 changes: 20 additions & 0 deletions app/controllers/api/testing/team_locations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

class API::Testing::TeamLocationsController < API::Testing::BaseController
def create
organisation = Organisation.find_by!(ods_code: params[:workgroup])
school = Location.school.find(params[:school_id])
academic_year = AcademicYear.pending

team_locations =
organisation.teams.map do |team|
TeamLocation.find_or_create_by!(team:, location: school, academic_year:)
end

render json: team_locations, status: :created
rescue ActiveRecord::RecordInvalid => e
render json: { errors: e.record.errors }, status: :unprocessable_entity
rescue ActiveRecord::RecordNotFound => e
render json: { error: e.message }, status: :not_found
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
unless Rails.env.production?
namespace :testing do
post "onboard", to: "onboard#create"
post "patients", to: "patients#create"
post "team-locations", to: "team_locations#create"

resources :locations, only: :index
resources :teams, only: :destroy, param: :workgroup do
Expand Down
Loading