diff --git a/app/controllers/admin/protocol_drugs_controller.rb b/app/controllers/admin/protocol_drugs_controller.rb
new file mode 100644
index 0000000000..a16a360caa
--- /dev/null
+++ b/app/controllers/admin/protocol_drugs_controller.rb
@@ -0,0 +1,54 @@
+class Admin::ProtocolDrugsController < ApplicationController
+ before_action :set_protocol_drug, only: %i[show edit update destroy]
+ before_action :set_protocols, only: %i[create edit update new]
+
+ def index
+ @protocol_drugs = ProtocolDrug.all
+ end
+
+ def show
+ end
+
+ def new
+ @protocol_drug = ProtocolDrug.new
+ end
+
+ def edit
+ end
+
+ def create
+ @protocol_drug = ProtocolDrug.new(protocol_drug_params)
+ if @protocol_drug.save
+ redirect_to [:admin, :protocols], notice: 'Protocol drug was successfully created.'
+ else
+ render :new
+ end
+ end
+
+ def update
+ if @protocol_drug.update(protocol_drug_params)
+ redirect_to [:admin, :protocols], notice: 'Protocol drug was successfully updated.'
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @protocol_drug.destroy
+ redirect_to [:admin, :protocols], notice: 'Protocol drug was successfully destroyed.'
+ end
+
+ private
+
+ def set_protocols
+ @protocols = Protocol.all
+ end
+
+ def set_protocol_drug
+ @protocol_drug = ProtocolDrug.find(params[:id])
+ end
+
+ def protocol_drug_params
+ params.require(:protocol_drug).permit(:name, :dosage, :rxnorm_code, :protocol_id)
+ end
+end
diff --git a/app/controllers/admin/protocols_controller.rb b/app/controllers/admin/protocols_controller.rb
new file mode 100644
index 0000000000..f6ab5d8373
--- /dev/null
+++ b/app/controllers/admin/protocols_controller.rb
@@ -0,0 +1,49 @@
+class Admin::ProtocolsController < ApplicationController
+ before_action :set_protocol, only: %i[show edit update destroy]
+
+ def index
+ @protocols = Protocol.all
+ end
+
+ def show
+ end
+
+ def new
+ @protocol = Protocol.new
+ end
+
+ def edit
+ end
+
+ def create
+ @protocol = Protocol.new(protocol_params)
+ if @protocol.save
+ redirect_to [:admin, @protocol], notice: 'Protocol was successfully created.'
+ else
+ render :new
+ end
+ end
+
+ def update
+ if @protocol.update(protocol_params)
+ redirect_to [:admin, @protocol], notice: 'Protocol was successfully updated.'
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @protocol.destroy
+ redirect_to admin_protocols_url, notice: 'Protocol was successfully destroyed.'
+ end
+
+ private
+
+ def set_protocol
+ @protocol = Protocol.find(params[:id])
+ end
+
+ def protocol_params
+ params.require(:protocol).permit(:name, :follow_up_days)
+ end
+end
diff --git a/app/controllers/protocol_drugs_controller.rb b/app/controllers/protocol_drugs_controller.rb
deleted file mode 100644
index 4b9034eee9..0000000000
--- a/app/controllers/protocol_drugs_controller.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-class ProtocolDrugsController < ApplicationController
- before_action :set_protocol_drug, only: %i[show edit update destroy]
- before_action :set_protocols, only: %i[create edit update new]
-
- def index
- @protocol_drugs = ProtocolDrug.all
- end
-
- def show
- end
-
- def new
- @protocol_drug = ProtocolDrug.new
- end
-
- def edit
- end
-
- def create
- @protocol_drug = ProtocolDrug.new(protocol_drug_params)
-
- respond_to do |format|
- if @protocol_drug.save
- format.html { redirect_to :protocols, notice: 'Protocol drug was successfully created.' }
- format.json { render :show, status: :created, location: @protocol_drug }
- else
- format.html { render :new }
- format.json { render json: @protocol_drug.errors, status: :unprocessable_entity }
- end
- end
- end
-
- def update
- respond_to do |format|
- if @protocol_drug.update(protocol_drug_params)
- format.html { redirect_to :protocols, notice: 'Protocol drug was successfully updated.' }
- format.json { render :show, status: :ok, location: @protocol_drug }
- else
- format.html { render :edit }
- format.json { render json: @protocol_drug.errors, status: :unprocessable_entity }
- end
- end
- end
-
- def destroy
- @protocol_drug.destroy
- respond_to do |format|
- format.html { redirect_to protocol_drugs_url, notice: 'Protocol drug was successfully destroyed.' }
- format.json { head :no_content }
- end
- end
-
- private
-
- def set_protocols
- @protocols = Protocol.all
- end
-
- def set_protocol_drug
- @protocol_drug = ProtocolDrug.find(params[:id])
- end
-
- def protocol_drug_params
- params.require(:protocol_drug).permit(:name, :dosage, :rxnorm_code, :protocol_id)
- end
-end
diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb
deleted file mode 100644
index b147886ac4..0000000000
--- a/app/controllers/protocols_controller.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-class ProtocolsController < ApplicationController
- before_action :set_protocol, only: %i[show edit update destroy]
-
- def index
- @protocols = Protocol.all
- end
-
- def show
- end
-
- def new
- @protocol = Protocol.new
- end
-
- def edit
- end
-
- def create
- @protocol = Protocol.new(protocol_params)
-
- respond_to do |format|
- if @protocol.save
- format.html { redirect_to @protocol, notice: 'Protocol was successfully created.' }
- format.json { render :show, status: :created, location: @protocol }
- else
- format.html { render :new }
- format.json { render json: @protocol.errors, status: :unprocessable_entity }
- end
- end
- end
-
- def update
- respond_to do |format|
- if @protocol.update(protocol_params)
- format.html { redirect_to @protocol, notice: 'Protocol was successfully updated.' }
- format.json { render :show, status: :ok, location: @protocol }
- else
- format.html { render :edit }
- format.json { render json: @protocol.errors, status: :unprocessable_entity }
- end
- end
- end
-
- def destroy
- @protocol.destroy
- respond_to do |format|
- format.html { redirect_to protocols_url, notice: 'Protocol was successfully destroyed.' }
- format.json { head :no_content }
- end
- end
-
- private
-
- def set_protocol
- @protocol = Protocol.find(params[:id])
- end
-
- def protocol_params
- params.require(:protocol).permit(:name, :follow_up_days)
- end
-end
diff --git a/app/views/protocol_drugs/_form.html.erb b/app/views/admin/protocol_drugs/_form.html.erb
similarity index 93%
rename from app/views/protocol_drugs/_form.html.erb
rename to app/views/admin/protocol_drugs/_form.html.erb
index 6f583bb265..4941d678a8 100644
--- a/app/views/protocol_drugs/_form.html.erb
+++ b/app/views/admin/protocol_drugs/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_with(model: protocol_drug, local: true) do |form| %>
+<%= form_with(model: [:admin, protocol_drug], local: true) do |form| %>
<% if protocol_drug.errors.any? %>
<%= pluralize(protocol_drug.errors.count, "error") %> prohibited this protocol_drug from being saved:
diff --git a/app/views/admin/protocol_drugs/edit.html.erb b/app/views/admin/protocol_drugs/edit.html.erb
new file mode 100644
index 0000000000..4cc21d227b
--- /dev/null
+++ b/app/views/admin/protocol_drugs/edit.html.erb
@@ -0,0 +1,6 @@
+
Editing Protocol Drug
+
+<%= render 'form', protocol_drug: @protocol_drug %>
+
+<%= link_to 'Show', [:admin, @protocol_drug] %> |
+<%= link_to 'Back', admin_protocol_drugs_path %>
diff --git a/app/views/protocol_drugs/index.html.erb b/app/views/admin/protocol_drugs/index.html.erb
similarity index 61%
rename from app/views/protocol_drugs/index.html.erb
rename to app/views/admin/protocol_drugs/index.html.erb
index 43801d6766..902a0e9cf2 100644
--- a/app/views/protocol_drugs/index.html.erb
+++ b/app/views/admin/protocol_drugs/index.html.erb
@@ -20,9 +20,9 @@
<%= protocol_drug.dosage %> |
<%= protocol_drug.rxnorm_code %> |
<%= protocol_drug.protocol %> |
-
<%= link_to 'Show', protocol_drug %> |
-
<%= link_to 'Edit', edit_protocol_drug_path(protocol_drug) %> |
-
<%= link_to 'Destroy', protocol_drug, method: :delete, data: { confirm: 'Are you sure?' } %> |
+
<%= link_to 'Show', [:admin, protocol_drug] %> |
+
<%= link_to 'Edit', edit_admin_protocol_drug_path(protocol_drug) %> |
+
<%= link_to 'Destroy', [:admin, protocol_drug], method: :delete, data: { confirm: 'Are you sure?' } %> |
<% end %>
@@ -30,4 +30,4 @@
-<%= link_to 'New Protocol Drug', new_protocol_drug_path %>
+<%= link_to 'New Protocol Drug', new_admin_protocol_drug_path %>
diff --git a/app/views/protocol_drugs/new.html.erb b/app/views/admin/protocol_drugs/new.html.erb
similarity index 62%
rename from app/views/protocol_drugs/new.html.erb
rename to app/views/admin/protocol_drugs/new.html.erb
index 9ffa46a34e..0035e6505a 100644
--- a/app/views/protocol_drugs/new.html.erb
+++ b/app/views/admin/protocol_drugs/new.html.erb
@@ -2,4 +2,4 @@
<%= render 'form', protocol_drug: @protocol_drug %>
-<%= link_to 'Back', protocol_drugs_path %>
+<%= link_to 'Back', admin_protocol_drugs_path %>
diff --git a/app/views/protocol_drugs/show.html.erb b/app/views/admin/protocol_drugs/show.html.erb
similarity index 100%
rename from app/views/protocol_drugs/show.html.erb
rename to app/views/admin/protocol_drugs/show.html.erb
diff --git a/app/views/protocols/_form.html.erb b/app/views/admin/protocols/_form.html.erb
similarity index 90%
rename from app/views/protocols/_form.html.erb
rename to app/views/admin/protocols/_form.html.erb
index 35c67ecf0e..e224c7b4e0 100644
--- a/app/views/protocols/_form.html.erb
+++ b/app/views/admin/protocols/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_with(model: protocol, local: true) do |form| %>
+<%= form_with(model: [:admin, protocol], local: true) do |form| %>
<% if protocol.errors.any? %>
<%= pluralize(protocol.errors.count, "error") %> prohibited this protocol from being saved:
diff --git a/app/views/admin/protocols/edit.html.erb b/app/views/admin/protocols/edit.html.erb
new file mode 100644
index 0000000000..fff772d8b4
--- /dev/null
+++ b/app/views/admin/protocols/edit.html.erb
@@ -0,0 +1,6 @@
+Editing Protocol
+
+<%= render 'form', protocol: @protocol %>
+
+<%= link_to 'Show', [:admin, @protocol]%> |
+<%= link_to 'Back', admin_protocols_path %>
diff --git a/app/views/protocols/index.html.erb b/app/views/admin/protocols/index.html.erb
similarity index 58%
rename from app/views/protocols/index.html.erb
rename to app/views/admin/protocols/index.html.erb
index a49dfe8e87..7ae4ba0744 100644
--- a/app/views/protocols/index.html.erb
+++ b/app/views/admin/protocols/index.html.erb
@@ -16,9 +16,9 @@
<%= protocol.name %> |
<%= protocol.follow_up_days %> |
- <%= link_to 'Show', protocol %> |
- <%= link_to 'Edit', edit_protocol_path(protocol) %> |
- <%= link_to 'Destroy', protocol, method: :delete, data: { confirm: 'Are you sure?' } %> |
+ <%= link_to 'Show', [:admin, protocol] %> |
+ <%= link_to 'Edit', edit_admin_protocol_path(protocol) %> |
+ <%= link_to 'Destroy', [:admin, protocol], method: :delete, data: { confirm: 'Are you sure?' } %> |
<% end %>
@@ -26,7 +26,7 @@
-<%= link_to 'New Protocol', new_protocol_path %>
+<%= link_to 'New Protocol', new_admin_protocol_path %>
<% @protocols.each do |protocol| %>
Protocol Drugs for <%= protocol.name %>
@@ -47,9 +47,9 @@
<%= protocol_drug.name %> |
<%= protocol_drug.dosage %> |
<%= protocol_drug.rxnorm_code %> |
- <%= link_to 'Show', protocol_drug %> |
- <%= link_to 'Edit', edit_protocol_drug_path(protocol_drug) %> |
- <%= link_to 'Destroy', protocol_drug, method: :delete, data: { confirm: 'Are you sure?' } %> |
+ <%= link_to 'Show', [:admin, protocol_drug] %> |
+ <%= link_to 'Edit', edit_admin_protocol_drug_path(protocol_drug) %> |
+ <%= link_to 'Destroy', [:admin, protocol_drug], method: :delete, data: { confirm: 'Are you sure?' } %> |
<% end %>
@@ -57,5 +57,5 @@
- <%= link_to 'New Protocol Drug', new_protocol_drug_path %>
+ <%= link_to 'New Protocol Drug', new_admin_protocol_drug_path %>
<% end %>
diff --git a/app/views/admin/protocols/new.html.erb b/app/views/admin/protocols/new.html.erb
new file mode 100644
index 0000000000..9ea64b425b
--- /dev/null
+++ b/app/views/admin/protocols/new.html.erb
@@ -0,0 +1,5 @@
+New Protocol
+
+<%= render 'form', protocol: @protocol%>
+
+<%= link_to 'Back', admin_protocols_path %>
diff --git a/app/views/protocols/show.html.erb b/app/views/admin/protocols/show.html.erb
similarity index 62%
rename from app/views/protocols/show.html.erb
rename to app/views/admin/protocols/show.html.erb
index e83020a154..e2cebed336 100644
--- a/app/views/protocols/show.html.erb
+++ b/app/views/admin/protocols/show.html.erb
@@ -10,5 +10,5 @@
<%= @protocol.follow_up_days %>
-<%= link_to 'Edit', edit_protocol_path(@protocol) %> |
-<%= link_to 'Back', protocols_path %>
+<%= link_to 'Edit', edit_admin_protocol_path(@protocol) %> |
+<%= link_to 'Back', admin_protocols_path %>
diff --git a/app/views/protocol_drugs/edit.html.erb b/app/views/protocol_drugs/edit.html.erb
deleted file mode 100644
index da91fefa60..0000000000
--- a/app/views/protocol_drugs/edit.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-Editing Protocol Drug
-
-<%= render 'form', protocol_drug: @protocol_drug %>
-
-<%= link_to 'Show', @protocol_drug %> |
-<%= link_to 'Back', protocol_drugs_path %>
diff --git a/app/views/protocols/edit.html.erb b/app/views/protocols/edit.html.erb
deleted file mode 100644
index 5a866e1107..0000000000
--- a/app/views/protocols/edit.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-Editing Protocol
-
-<%= render 'form', protocol: @protocol %>
-
-<%= link_to 'Show', @protocol %> |
-<%= link_to 'Back', protocols_path %>
diff --git a/app/views/protocols/new.html.erb b/app/views/protocols/new.html.erb
deleted file mode 100644
index b4fe9b32a3..0000000000
--- a/app/views/protocols/new.html.erb
+++ /dev/null
@@ -1,5 +0,0 @@
-New Protocol
-
-<%= render 'form', protocol: @protocol %>
-
-<%= link_to 'Back', protocols_path %>
diff --git a/config/routes.rb b/config/routes.rb
index 1f01a67997..163ac2185b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,6 +1,4 @@
Rails.application.routes.draw do
- resources :protocol_drugs
- resources :protocols
mount Rswag::Ui::Engine => '/api-docs'
mount Rswag::Api::Engine => '/api-docs'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
@@ -20,4 +18,9 @@
end
end
end
+
+ namespace :admin do
+ resources :protocol_drugs
+ resources :protocols
+ end
end
diff --git a/spec/controllers/protocol_drugs_controller_spec.rb b/spec/controllers/admin/protocol_drugs_controller_spec.rb
similarity index 93%
rename from spec/controllers/protocol_drugs_controller_spec.rb
rename to spec/controllers/admin/protocol_drugs_controller_spec.rb
index 4f9713a16f..50abc21084 100644
--- a/spec/controllers/protocol_drugs_controller_spec.rb
+++ b/spec/controllers/admin/protocol_drugs_controller_spec.rb
@@ -1,6 +1,6 @@
require 'rails_helper'
-RSpec.describe ProtocolDrugsController, type: :controller do
+RSpec.describe Admin::ProtocolDrugsController, type: :controller do
let(:valid_attributes) {
protocol = FactoryBot.create(:protocol)
@@ -53,7 +53,7 @@
it "redirects to the list of protocols" do
post :create, params: {protocol_drug: valid_attributes}
- expect(response).to redirect_to(:protocols)
+ expect(response).to redirect_to([:admin, :protocols])
end
end
@@ -83,7 +83,7 @@
it "redirects to the list of protocols" do
protocol_drug = ProtocolDrug.create! valid_attributes
put :update, params: {id: protocol_drug.to_param, protocol_drug: valid_attributes}
- expect(response).to redirect_to(:protocols)
+ expect(response).to redirect_to([:admin, :protocols])
end
end
@@ -107,7 +107,7 @@
it "redirects to the protocol_drugs list" do
protocol_drug = ProtocolDrug.create! valid_attributes
delete :destroy, params: {id: protocol_drug.to_param}
- expect(response).to redirect_to(protocol_drugs_url)
+ expect(response).to redirect_to(admin_protocol_drugs_url)
end
end
diff --git a/spec/controllers/protocols_controller_spec.rb b/spec/controllers/admin/protocols_controller_spec.rb
similarity index 90%
rename from spec/controllers/protocols_controller_spec.rb
rename to spec/controllers/admin/protocols_controller_spec.rb
index 01ab915c77..44c3afffe7 100644
--- a/spec/controllers/protocols_controller_spec.rb
+++ b/spec/controllers/admin/protocols_controller_spec.rb
@@ -1,6 +1,6 @@
require 'rails_helper'
-RSpec.describe ProtocolsController, type: :controller do
+RSpec.describe Admin::ProtocolsController, type: :controller do
let(:valid_attributes) {
FactoryBot.attributes_for(:protocol)
@@ -51,7 +51,7 @@
it "redirects to the created protocol" do
post :create, params: {protocol: valid_attributes}
- expect(response).to redirect_to(Protocol.last)
+ expect(response).to redirect_to([:admin, Protocol.last])
end
end
@@ -74,7 +74,7 @@
protocol = Protocol.create! valid_attributes
put :update, params: {id: protocol.to_param, protocol: new_attributes}
protocol.reload
- expect(response).to redirect_to(protocol)
+ expect(response).to redirect_to([:admin, protocol])
expect(protocol.attributes.except('id', 'created_at', 'updated_at'))
.to eq new_attributes.with_indifferent_access
end
@@ -82,7 +82,7 @@
it "redirects to the protocol" do
protocol = Protocol.create! valid_attributes
put :update, params: {id: protocol.to_param, protocol: valid_attributes}
- expect(response).to redirect_to(protocol)
+ expect(response).to redirect_to([:admin, protocol])
end
end
@@ -106,7 +106,7 @@
it "redirects to the protocols list" do
protocol = Protocol.create! valid_attributes
delete :destroy, params: {id: protocol.to_param}
- expect(response).to redirect_to(protocols_url)
+ expect(response).to redirect_to(admin_protocols_url)
end
end
end