Skip to content

Commit

Permalink
Distinction between pathways (individual) and family pathways; pull d…
Browse files Browse the repository at this point in the history
…ays homeless from assessment if available; use overall days homeless for assessment score for family pathways
  • Loading branch information
eanders committed Feb 4, 2025
1 parent f5b16e9 commit 487a354
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
33 changes: 30 additions & 3 deletions app/models/grda_warehouse/cas_project_client_calculator/boston.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def value_for_cas_project_client(client:, column:)
end
end

def handles_days_homeless?
true
end

def unrelated_columns
[
:vispdat_score,
Expand Down Expand Up @@ -148,6 +152,7 @@ def unrelated_columns
:meth_production_conviction,
:lifetime_sex_offender,
:evicted,
:days_homeless,
]
end
# memoize :pathways_questions
Expand Down Expand Up @@ -430,6 +435,17 @@ def total_homeless_nights_sheltered(client)
question_matching_requirement('c_pathways_nights_sheltered_warehouse_added_total')&.AssessmentAnswer.to_i || 0
end

# all-time days homeless
def days_homeless(client)
overall_nights_homeless(client)
end

private def overall_nights_homeless(client)
most_recent_pathways_or_transfer(client).
question_matching_requirement('c_new_boston_homeless_nights_total')&.AssessmentAnswer.to_i ||
client.days_homeless
end

private def default_shelter_agency_contacts(client)
contact_emails = client.client_contacts.shelter_agency_contacts.where.not(email: nil).pluck(:email)
contact_emails << client.source_assessments.max_by(&:assessment_date)&.user&.user_email
Expand Down Expand Up @@ -500,12 +516,23 @@ def total_homeless_nights_sheltered(client)
question_matching_requirement('c_latest_date_financial_assistance_eligibility_rrh')&.AssessmentAnswer
end

# For 2024/2025 score calculations are:
# Individual Pathways Assessment: days homeless in the past 3 years, prefer Pathways answer clamped to 1,096, use
# days in the past three years from the warehouse if not available.
# Family Pathways Assessment: overall days homeless (all time), prefer Pathways answer, use client.days_homeless if
# not available.
# Transfer Assessment: use assessment score.
private def assessment_score_for_cas(client)
case cas_assessment_name(client)
when 'IdentifiedPathwaysVersionThreePathways', 'IdentifiedPathwaysVersionFourPathways'
# Individual
days_homeless_in_last_three_years_cached(client)
# Family # FIXME:
if most_recent_pathways_or_transfer(client).family_pathways_2024?
# Family
overall_days_homeless(client)
else
# Individual
days_homeless_in_last_three_years_cached(client)
end

# all time homeless days (no cap on total, but self-report limited to 548 if no verification)
# Also need a mechanism to identify family Pathways assessments/AssessmentQuestions
when 'IdentifiedPathwaysVersionThreeTransfer', 'IdentifiedPathwaysVersionFourTransfer'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def value_for_cas_project_client(client:, column:)
client.send(column)
end

# Defer calculation of `days_homeless` to PushClientsToCas
def handles_days_homeless?
false
end

def description_for_column(column)
custom_descriptions[column].presence || GrdaWarehouse::Hud::Client.cas_columns_data.dig(column, :description)
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/grda_warehouse/hud/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class Assessment < Base
where(AssessmentID: GrdaWarehouse::Hud::AssessmentQuestion.transfer.select(:AssessmentID))
end

scope :family_pathways, -> do
where(AssessmentID: GrdaWarehouse::Hud::AssessmentQuestion.family_pathways.select(:AssessmentID))
end

def answer(question)
assessment_questions.find_by(assessment_question: question.to_s)&.assessment_answer
end
Expand Down Expand Up @@ -105,5 +109,9 @@ def name
def pathways?
assessment_questions.any?(&:pathways?)
end

def family_pathways_2024?
name == 'Family Pathways 2024'
end
end
end
31 changes: 25 additions & 6 deletions app/models/grda_warehouse/hud/assessment_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ class AssessmentQuestion < Base
pathways_or_rrh.
joins(:lookup).
merge(GrdaWarehouse::AssessmentAnswerLookup.where(response_text: pathways_titles))

# Temporary solution until we have the c_housing_assessment_name question in the 2024 pathways assessment
# where(AssessmentQuestion: [:c_housing_assessment_name, :c_pathways_barriers_yn])
end

scope :transfer, -> do
pathways_or_rrh.
joins(:lookup).
merge(GrdaWarehouse::AssessmentAnswerLookup.where(response_text: ['RRH-PSH Transfer', 'RRH-PSH Transfer 2024']))
merge(GrdaWarehouse::AssessmentAnswerLookup.where(response_text: transfer_titles))
end

scope :family_pathways, -> do
pathways_or_rrh.
joins(:lookup).
merge(GrdaWarehouse::AssessmentAnswerLookup.where(response_text: family_pathways_titles))
end

# NOTE: you probably want to join/preload :lookup
Expand All @@ -71,8 +74,6 @@ def default_response_text(answer)
end

def pathways?
# FIXME: this is temporary until we have a more permanent solution
# self.AssessmentQuestion.to_s == 'c_pathways_barriers_yn'
self.AssessmentQuestion.to_s == 'c_housing_assessment_name' && human_readable.in?(self.class.pathways_titles)
end

Expand All @@ -83,6 +84,19 @@ def self.pathways_titles
]
end

def self.transfer_titles
[
'RRH-PSH Transfer',
'RRH-PSH Transfer 2024',
]
end

def self.family_pathways_titles
[
'Family Pathways 2024',
]
end

private def pathways_question?
assessment_question == 'c_housing_assessment_name'
end
Expand All @@ -92,11 +106,16 @@ def assessment_name
return 'Pathways 2021' if pathways_2021?
return 'RRH-PSH Transfer' if transfer_2021?
return 'RRH-PSH Transfer 2024' if transfer_2024?
return 'Family Pathways 2024' if family_pathways_2024?

# unknown from assessment questions
nil
end

def family_pathways_2024?
lookup&.response_text == 'Family Pathways 2024'
end

def pathways_2024?
return nil unless pathways_question?

Expand Down
17 changes: 11 additions & 6 deletions app/models/grda_warehouse/tasks/push_clients_to_cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ def sync!
project_client = project_clients[client.id] || CasAccess::ProjectClient.new(data_source_id: data_source.id, id_in_data_source: client.id)
project_client.assign_attributes(attributes_for_cas_project_client(client))

case GrdaWarehouse::Config.get(:cas_days_homeless_source)
when 'days_homeless_plus_overrides'
project_client.days_homeless = client.processed_service_history&.days_homeless_plus_overrides || client.days_homeless
else
project_client.days_homeless = client.days_homeless
# The Boston calculator handles days homeless natively
unless calculator_instance.handles_days_homeless?
case GrdaWarehouse::Config.get(:cas_days_homeless_source)
when 'days_homeless_plus_overrides'
project_client.days_homeless = client.processed_service_history&.days_homeless_plus_overrides || client.days_homeless
else
project_client.days_homeless = client.days_homeless
end
end

project_client.calculated_last_homeless_night = client.date_of_last_homeless_service
Expand Down Expand Up @@ -296,7 +299,9 @@ def client_source

private def attributes_for_cas_project_client(client)
{}.tap do |options|
project_client_columns.map do |destination, source|
columns = project_client_columns
columns[:days_homeless] = :days_homeless if calculator_instance.handles_days_homeless?
columns.map do |destination, source|
# puts "Processing: #{destination} from: #{source}"
options[destination] = calculator_instance.value_for_cas_project_client(client: client, column: source)
end
Expand Down

0 comments on commit 487a354

Please sign in to comment.