Skip to content

Commit

Permalink
Remove crh created practices endpoint (#709)
Browse files Browse the repository at this point in the history
* add factories

* spacing

* remove `javascript_include_tag` for `clinical_resource_hubs/crh_show` js from crh show view

* remove `clinical_resource_hubs/crh_show.es6` file

* remove `#created-crh-practices` endpoint and route

* add specs for `:get_by_created_crh` and `:get_by_adopted_crh` scopes

* remove `get_crh_created_innovations` method from `ClinicalResourceHub` model

* remove `clinical_resource_hubs/crh_show.js` from rails assets precompile list

* spacing

* add specs for `Practice.get_by_created_crh` and `Practice.get_by_adopted_crh` scopes

* update `:visns` factory

* update `:va_facility` factory

* update `:diffusion_history_statuses` factory to have default status

* add note to `diffusion_histories` factory

* remove deleted action from `before_action` in `ClinicalResourceHubsController`

* remove errant pry
  • Loading branch information
PhilipDeFraties authored Oct 3, 2023
1 parent 5cd6182 commit ab741f5
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 66 deletions.
29 changes: 0 additions & 29 deletions app/assets/javascripts/clinical_resource_hubs/crh_show.es6

This file was deleted.

27 changes: 1 addition & 26 deletions app/controllers/clinical_resource_hubs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ClinicalResourceHubsController < ApplicationController
include PracticesHelper
include PracticeUtils
before_action :set_crh, only: [:show, :created_crh_practices]
before_action :set_crh, only: :show
def show
@visn_va_facilities = VaFacility.get_by_visn(@visn).get_relevant_attributes
@visn_crh = ClinicalResourceHub.cached_clinical_resource_hubs.find_by(visn: @visn)
Expand All @@ -20,31 +20,6 @@ def show
get_categories_by_practices(@practices_adopted_by_crh, @crh_practices_adopted_categories)
end

# GET /crh/:id/created_crh_practices
def created_crh_practices
page = 1
page = params[:page].to_i if params[:page].present?
sort_option = params[:sort_option] || 'a_to_z'
search_term = params[:search_term] ? params[:search_term].downcase : nil
categories = params[:categories] || nil
created_practices = @crh.get_crh_created_innovations(@crh.id, search_term, sort_option, categories, helpers.is_user_a_guest?)
@pagy_created_practices = pagy_array(
created_practices,
items: 3,
page: page
)
@pagy_created_info = @pagy_created_practices[0]
practices = @pagy_created_practices[1]
practice_cards_html = ''
practices.each do |pr|
pr_html = render_to_string('shared/_practice_card', layout: false, locals: { practice: pr })
practice_cards_html += pr_html
end
respond_to do |format|
format.json { render :json => { practice_cards_html: practice_cards_html, count: created_practices.size, next: @pagy_created_info.next } }
end
end

private
def set_crh
@visn = params[:id].present? ? Visn.find_by!(number: params[:id]) : Visn.find_by!(number: params[:number])
Expand Down
5 changes: 0 additions & 5 deletions app/models/clinical_resource_hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,4 @@ def get_crh_created_practices(crh_id, options = { is_user_guest: true })
options[:is_user_guest] ? Practice.public_facing.load_associations.get_by_created_crh(crh_id) :
Practice.published_enabled_approved.load_associations.get_by_created_crh(crh_id)
end

def get_crh_created_innovations(crh_id, search_term = nil, sort = 'a_to_z', categories = nil, is_user_guest = true)
practices = Practice.search_practices(search_term, sort, categories, is_user_guest)
practices.select { |pr| pr.practice_origin_facilities.where(clinical_resource_hub_id: crh_id)}
end
end
1 change: 0 additions & 1 deletion app/views/clinical_resource_hubs/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<%# set visnNumber before loading the crh/show file %>
var visnNumber = <%= visn_number %>;
<% end %>
<%= javascript_include_tag 'clinical_resource_hubs/crh_show', 'data-turbolinks-track': 'reload' %>
<% end %>

<div id="crh-show" class="grid-col-12" data-reload="true">
Expand Down
1 change: 0 additions & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
_alert_message_utilities.js
_page_show.js
facility_status_definitions_modal.js
clinical_resource_hubs/crh_show.js
practices/publication_validation.js
page/page_map.js
shared/_signed_resource.js
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@

root 'home#index'
resources :clinical_resource_hubs, path: :crh, param: :number
get '/crh/:number/created-crh-practices', controller: 'clinical_resource_hubs', action: 'created_crh_practices'
get '/practices' => 'practices#index'
get '/partners' => 'practice_partners#index'
# Adding this for the View Toolkit button on practice page. Though we don't have any uploaded yet so I'm not using it.
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/diffusion_histories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
association :clinical_resource_hub
end

# there are places in the application that expect a diffusion_history to have an associated
# diffusion_history_status, if you create a diffusion_history in rails console without one
# of the :with_status traits it will cause a breakage, ie /diffusion-map

trait :with_status_complete do
after(:create) do |dh|
create(:diffusion_history_status, :complete, diffusion_history: dh)
Expand Down
1 change: 1 addition & 0 deletions spec/factories/diffusion_history_statuses.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :diffusion_history_status do
association :diffusion_history
status { 'Complete' }

trait :in_progress do
status { 'In progress' }
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/practice_origin_facilities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FactoryBot.define do
factory :practice_origin_facility do
association :practice
end
end
33 changes: 31 additions & 2 deletions spec/factories/va_facilities.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FactoryBot.define do
factory :va_facility do
association :visn

sta3n { Faker::Number.unique.number(digits: 5) }
station_number { Faker::Number.unique.number(digits: 5) }
official_station_name { Faker::Company.unique.name }
common_name { Faker::Company.unique.industry }
fy17_parent_station_complexity_level { Faker::Lorem.unique.word }
latitude { Faker::Address.unique.latitude }
longitude { Faker::Address.unique.longitude }
rurality { Faker::Alphanumeric.alpha(number: 1) }
Expand All @@ -23,5 +22,35 @@
mobile { Faker::Boolean.boolean.to_s }
parent_station_number { Faker::Number.unique.number(digits: 3) }
official_parent_station_name { Faker::Company.unique.name }

complexity_levels = [
"3 -Low Complexity",
"2 -Medium Complexity",
"1c-High Complexity",
"1b-High Complexity",
"1a-High Complexity"
]

fy17_parent_station_complexity_level { complexity_levels.sample }

trait :low_complexity do
fy17_parent_station_complexity_level { "3 -Low Complexity" }
end

trait :medium_complexity do
fy17_parent_station_complexity_level { "2 -Medium Complexity" }
end

trait :high_complexity_1c do
fy17_parent_station_complexity_level { "1c-High Complexity" }
end

trait :high_complexity_1b do
fy17_parent_station_complexity_level { "1b-High Complexity" }
end

trait :high_complexity_1a do
fy17_parent_station_complexity_level { "1a-High Complexity" }
end
end
end
8 changes: 7 additions & 1 deletion spec/factories/visns.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
FactoryBot.define do
factory :visn do
name { Faker::Company.unique.name }
sequence(:number) { |n| n }
sequence(:number) do |n|
num = n
while Visn.exists?(number: num)
num += 1
end
num
end
end
end
41 changes: 41 additions & 0 deletions spec/models/practice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,45 @@
}.to change { @practice.reload.diffusion_histories_count }.by(-1)
end
end

describe 'scopes' do
describe '.get_by_created_crh' do
let!(:clinical_resource_hub_1) { create(:clinical_resource_hub) }
let!(:clinical_resource_hub_2) { create(:clinical_resource_hub) }

let!(:practice1) { create(:practice, published: true, enabled: true, approved: true, hidden: false) }
let!(:practice2) { create(:practice, published: true, enabled: true, approved: true, hidden: false) }
let!(:practice3) { create(:practice, published: false, enabled: false, approved: false, hidden: true) }

let!(:facility_with_hub_1) { create(:practice_origin_facility, practice: practice1, clinical_resource_hub: clinical_resource_hub_1) }
let!(:facility_with_hub_2) { create(:practice_origin_facility, practice: practice2, clinical_resource_hub: clinical_resource_hub_2) }

it 'returns practices that are published, enabled, approved, associated with provided clinical_resource_hub_id, and have loaded associations' do
result = Practice.published_enabled_approved.load_associations.get_by_created_crh(clinical_resource_hub_1.id)

expect(result).to include(practice1)
expect(result).not_to include(practice2, practice3)
end
end

describe '.get_by_adopted_crh' do
let!(:clinical_resource_hub_1) { create(:clinical_resource_hub) }
let!(:clinical_resource_hub_2) { create(:clinical_resource_hub) }

let!(:practice1) { create(:practice, published: true, enabled: true, approved: true, hidden: false) }
let!(:practice2) { create(:practice, published: true, enabled: true, approved: true, hidden: false) }
let!(:practice3) { create(:practice, published: false, enabled: false, approved: false, hidden: true) } # Will be filtered out by `published_enabled_approved` scope

let!(:diffusion_history_1) { create(:diffusion_history, practice: practice1, clinical_resource_hub: clinical_resource_hub_1) }
let!(:diffusion_history_2) { create(:diffusion_history, practice: practice2, clinical_resource_hub: clinical_resource_hub_2) }


it 'returns practices that are published, enabled, approved, adopted by the given clinical_resource_hub_id, and have loaded associations' do
result = Practice.published_enabled_approved.load_associations.get_by_adopted_crh(clinical_resource_hub_1.id)

expect(result).to include(practice1)
expect(result).not_to include(practice2, practice3)
end
end
end
end

0 comments on commit ab741f5

Please sign in to comment.