Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional RRH Sub Type Adjustments #5116

Merged
merged 2 commits into from
Feb 7, 2025
Merged
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
64 changes: 56 additions & 8 deletions app/models/grda_warehouse/hud/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,44 +76,92 @@ class Project < Base
# Needs to come after has_many :enrollments, bc one extension uses a has_many through: :enrollments relation
include RailsDrivers::Extensions

# A scope to return any projects that are residential (provide housing). Generally, and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment about why Street Outreach is included? It will always confuse me that it's considered residential in the codebase, since docs describe Street Outreach projects as specifically providing non- facility-based care.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, guess I was too late

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gigxz does this suffice?
d713fb2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect thanks!

# completely before the FY2024 data standards, this is based on project type. In FY2024
# Project Type 13 (RRH) was given an RRHSubType column to indicate if it was a services only
# project or if it included housing.
# This handles the RRH Sub Type given a set of project IDs so as to return residential projects
scope :_residential_for_project_type_ids, ->(project_type_ids) do
project_type_ids = Array.wrap(project_type_ids)
return where(project_type: project_type_ids) unless project_type_ids.include?(13)

# Special case RRH with new SSO only RRHSubType
where(
arel_table[:ProjectType].in(project_type_ids - [13]).
or(
arel_table[:ProjectType].eq(13).
# NOTE: officially, only RRHSubType 2 count as residential, but old data won't always have
# the RRHSubType, assume those are residential as well
and(arel_table[:RRHSubType].eq(2).or(arel_table[:RRHSubType].eq(nil))),
),
)
end

# A scope to return any projects that is not residential (doesn't provide housing).
# Generally, and completely before the FY2024 data standards, this is based on project type.
# In FY2024 Project Type 13 (RRH) was given an RRHSubType column to indicate if it was a
# services only project or if it included housing.
# This handles the RRH Sub Type given a set of project IDs so as to return non-residential
# projects
scope :_non_residential_for_project_type_ids, ->(project_type_ids) do
project_type_ids = Array.wrap(project_type_ids)
return where(project_type: project_type_ids) unless project_type_ids.include?(13)

# Special case RRH with new SSO only RRHSubType
where(
arel_table[:ProjectType].in(project_type_ids - [13]).
or(arel_table[:ProjectType].eq(13).and(arel_table[:RRHSubType].eq(1))),
)
end

scope :residential, -> do
where(ProjectType: HudUtility2024.residential_project_type_ids)
hud_residential
end

scope :hud_residential, -> do
where(project_type: HudUtility2024.residential_project_type_ids)
_residential_for_project_type_ids(HudUtility2024.residential_project_type_ids)
end

scope :non_residential, -> do
where.not(ProjectType: HudUtility2024.residential_project_type_ids)
hud_non_residential
end

scope :hud_non_residential, -> do
where.not(project_type: HudUtility2024.residential_project_type_ids)
# all non-residential project types, but re-add 13 for RRH SSO
_non_residential_for_project_type_ids(HudUtility2024.all_project_types - HudUtility2024.residential_project_type_ids + [13])
end

scope :chronic, -> do
where(project_type: HudUtility2024.chronic_project_types)
end

scope :hud_chronic, -> do
where(project_type: HudUtility2024.chronic_project_types)
end

scope :homeless, -> do
where(project_type: HudUtility2024.homeless_project_types)
end

scope :hud_homeless, -> do
where(project_type: HudUtility2024.chronic_project_types)
end

scope :homeless_sheltered, -> do
where(project_type: HudUtility2024.homeless_sheltered_project_types)
end

scope :homeless_unsheltered, -> do
where(project_type: HudUtility2024.homeless_unsheltered_project_types)
end

scope :residential_non_homeless, -> do
r_non_homeless = HudUtility2024.residential_project_type_ids - HudUtility2024.chronic_project_types
where(ProjectType: r_non_homeless)
hud_residential_non_homeless
end

scope :hud_residential_non_homeless, -> do
r_non_homeless = HudUtility2024.residential_project_type_ids - HudUtility2024.chronic_project_types
where(project_type: r_non_homeless)
_residential_for_project_type_ids(r_non_homeless)
end

scope :with_hud_project_type, ->(project_types) do
Expand Down Expand Up @@ -663,7 +711,7 @@ def name(user = nil, include_project_type: false, ignore_confidential_status: fa
else
safe_project_name
end
project_name += " (#{HudUtility2024.project_type_brief(project_type)})" if include_project_type && project_type.present?
project_name += " (#{HudUtility2024.brief_project_type_with_sub_type(project_type, rrh_sub_type)})" if include_project_type && project_type.present?

project_name
end
Expand Down
15 changes: 9 additions & 6 deletions app/models/grda_warehouse/service_history_enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,27 @@ def self.service_types
service_types << 'extrapolated' if GrdaWarehouse::Config.get(:so_day_as_month)
end
scope :residential, -> {
in_project_type(HudUtility2024.residential_project_type_ids)
# Need to join project to use RRHSubType
joins(:project).merge(GrdaWarehouse::Hud::Project.residential)
}

scope :hud_residential, -> do
hud_project_type(HudUtility2024.residential_project_type_ids)
# Need to join project to use RRHSubType
joins(:project).merge(GrdaWarehouse::Hud::Project.hud_residential)
end

scope :hud_non_residential, -> do
# Need to join project to use RRHSubType
joins(:project).merge(GrdaWarehouse::Hud::Project.hud_non_residential)
end

scope :residential_non_homeless, -> do
r_non_homeless = HudUtility2024.residential_project_type_numbers_by_code[:ph] + HudUtility2024.residential_project_type_numbers_by_code[:th]
in_project_type(r_non_homeless)
# Need to join project to use RRHSubType
joins(:project).merge(GrdaWarehouse::Hud::Project.residential_non_homeless)
end
scope :hud_residential_non_homeless, -> do
r_non_homeless = HudUtility2024.residential_project_type_numbers_by_code[:ph] + HudUtility2024.residential_project_type_numbers_by_code[:th]
hud_project_type(r_non_homeless)
# Need to join project to use RRHSubType
joins(:project).merge(GrdaWarehouse::Hud::Project.hud_residential_non_homeless)
end
scope :permanent_housing, -> do
project_types = HudUtility2024.residential_project_type_numbers_by_code.values_at(:ph).flatten
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ def max_date(client)
def add_project_for_week(projects:, project:, she:, user:)
return projects unless project.present?

project_type = project.project_type_to_use
project_type = project.project_type
projects[she.id] ||= {
project_id: project.id.to_s,
project_name: project.name(user),
project_type: project_type.to_s,
project_type_name: HudUtility2024.project_type_brief(project_type),
project_type_name: HudUtility2024.brief_project_type_with_sub_type(project_type, project.rrh_sub_type),
entry_date: she.entry_date,
exit_date: she.exit_date.presence || Date.current,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%label Project
%select.js-client-calendar-filter__project{name: 'projects[]', multiple: 'multiple', data: {name: 'projects'}}
- data.available_projects(month: @month, year: @year, client: @client, user: current_user).each do |project|
%option{value: project.id.to_s, selected: @filters[:projects].include?(project.id.to_s)}= project.name(current_user)
%option{value: project.id.to_s, selected: @filters[:projects].include?(project.id.to_s)}= project.name(current_user, include_project_type: true)
.mb-4
%label Contact Type
%select.js-client-calendar-filter__contact-type{name: 'contact_types[]', multiple: 'multiple', data: {name: 'contactTypes'}}
Expand Down
16 changes: 16 additions & 0 deletions spec/models/grda_warehouse/hud/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@
p = ->(*projects) { projects.map(&:id).sort }

describe 'scopes' do
it 'handles RRH Sub Type correctly' do
p1.update(project_type: 13, rrh_sub_type: 1) # services only
p2.update(project_type: 13, rrh_sub_type: 2) # housing
p3.update(project_type: 2) # TH
p4.update(project_type: 10) # PH
p5.update(project_type: 7) # other
p6.update(project_type: 0) # ES Entry/Exit
p7.update(project_type: 11) # Day Shelter
p8.update(project_type: 12) # Prevention
aggregate_failures do
expect(GrdaWarehouse::Hud::Project.hud_residential.to_a.sort).to eq([p2, p3, p4, p6].sort)
expect(GrdaWarehouse::Hud::Project.hud_non_residential.to_a.sort).to eq([p1, p5, p7, p8].sort)
expect(GrdaWarehouse::Hud::Project.hud_residential_non_homeless.to_a.sort).to eq([p2, p3, p4].sort)
end
end

describe 'viewability' do
describe 'ordinary user' do
it 'sees nothing' do
Expand Down