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

Add Match Route Eleven as Clone of Provider Only Route #820

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion app/controllers/concerns/decisions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def can_recreate_this_decision?
helper_method :can_recreate_this_decision?

def hsa_can_resend_this_step?
["MatchDecisions::ProviderOnly::HsaAcceptsClient"].include?(@decision&.type) &&
['MatchDecisions::ProviderOnly::HsaAcceptsClient', 'MatchDecisions::Eleven::ElevenHsaAcceptsClient'].include?(@decision&.type) &&
@match.contacts_editable_by_hsa &&
current_contact.in?(@match.housing_subsidy_admin_contacts)
end
Expand Down
1 change: 1 addition & 0 deletions app/mailers/notifications_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class NotificationsMailer < DatabaseMailer
include RouteEightMailerMethods
include RouteNineMailerMethods
include RouteTenMailerMethods
include RouteElevenMailerMethods

def match_recommendation_dnd_staff(notification = nil)
setup_instance_variables(notification)
Expand Down
60 changes: 60 additions & 0 deletions app/mailers/route_eleven_mailer_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
###
# Copyright 2016 - 2024 Green River Data Analysis, LLC
#
# License detail: https://github.com/greenriver/boston-cas/blob/production/LICENSE.md
###

module RouteElevenMailerMethods
extend ActiveSupport::Concern
included do
def eleven_confirm_hsa_decline_dnd_staff(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: "Match Declined by #{Translation.translate('HSA Eleven')} - Requires Your Action")
end

def eleven_hsa_accepts_client_ssp_notification(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: "Match accepted by #{Translation.translate('HSA Eleven')}")
end

def eleven_hsa_accepts_client(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: 'Match ready for review - Requires Your Action')
end

def eleven_hsa_decision_client(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: "Decision from #{Translation.translate('Housing Subsidy Administrator Eleven')}")
end

def eleven_hsa_decision_hsp(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: "Decision from #{Translation.translate('Housing Subsidy Administrator Eleven')}")
end

def eleven_hsa_decision_shelter_agency(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: "Decision from #{Translation.translate('Housing Subsidy Administrator Eleven')}")
end

def eleven_hsa_decision_ssp(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: "Decision from #{Translation.translate('Housing Subsidy Administrator Eleven')}")
end

def eleven_match_initiation_for_hsa(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: 'New Housing Recommendation - Requires Your Action')
end

def eleven_match_initiation_for_shelter_agency(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: 'New Housing Recommendation')
end

def eleven_match_initiation_for_ssp(notification = nil)
setup_instance_variables(notification)
mail(to: @contact.email, subject: 'New Housing Recommendation')
end
end
end
3 changes: 3 additions & 0 deletions app/models/client_opportunity_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def self.model_name
# Match Route 10
include RouteTenDecisions

# Match Route 11
include RouteElevenDecisions

has_many :referral_events, class_name: 'Warehouse::ReferralEvent', foreign_key: 'client_opportunity_match_id'
has_one :active_referral_event, -> { where(referral_result: nil) }, class_name: 'Warehouse::ReferralEvent', foreign_key: 'client_opportunity_match_id'

Expand Down
15 changes: 15 additions & 0 deletions app/models/concerns/route_eleven_decisions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
###
# Copyright 2016 - 2024 Green River Data Analysis, LLC
#
# License detail: https://github.com/greenriver/boston-cas/blob/production/LICENSE.md
###

module RouteElevenDecisions
extend ActiveSupport::Concern

included do
has_decision :eleven_hsa_acknowledges_receipt, decision_class_name: 'MatchDecisions::Eleven::ElevenHsaAcknowledgesReceipt', notification_class_name: 'Notifications::Eleven::MatchInitiationForHsa'
has_decision :eleven_hsa_accepts_client, decision_class_name: 'MatchDecisions::Eleven::ElevenHsaAcceptsClient', notification_class_name: 'Notifications::Eleven::HsaAcceptsClient'
has_decision :eleven_confirm_hsa_accepts_client_decline_dnd_staff, decision_class_name: 'MatchDecisions::Eleven::ElevenConfirmHsaAcceptsClientDeclineDndStaff', notification_class_name: 'Notifications::ConfirmHousingSubsidyAdminDeclineDndStaff'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
###
# Copyright 2016 - 2024 Green River Data Analysis, LLC
#
# License detail: https://github.com/greenriver/boston-cas/blob/production/LICENSE.md
###

module MatchDecisions::Eleven
class ElevenConfirmHsaAcceptsClientDeclineDndStaff < ::MatchDecisions::Base
def to_partial_path
'match_decisions/eleven_confirm_hsa_accepts_client_decline_dnd_staff'
Copy link
Contributor

Choose a reason for hiding this comment

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

How much would it break things if we started putting the decisions into a folder?

Suggested change
'match_decisions/eleven_confirm_hsa_accepts_client_decline_dnd_staff'
'match_decisions/eleven/confirm_hsa_accepts_client_decline_dnd_staff'

Seems like that would help tracking these down in the future for duplication etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From an initial test, it doen't look like it is breaking anything, but I'll do a bit more to get some more thorough results before including in in the next commit.

end

def statuses
{
pending: 'Pending',
decline_overridden: 'Decline Overridden',
decline_overridden_returned: 'Decline Overridden, Returned',
decline_confirmed: 'Decline Confirmed',
canceled: 'Canceled',
}
end

def label
label_for_status status
end

def label_for_status status
case status.to_sym
when :pending then "#{Translation.translate('CoC Eleven')} to confirm #{Translation.translate('Housing Subsidy Administrator Eleven')} decline"
when :decline_overridden then "#{Translation.translate('Housing Subsidy Administrator Eleven')} decline overridden by #{Translation.translate('CoC Eleven')}. Match successful"
when :decline_overridden_returned then "#{Translation.translate('Housing Subsidy Administrator Eleven')} decline overridden by #{Translation.translate('CoC Eleven')}. Match returned to #{Translation.translate('Housing Subsidy Administrator Eleven')}"
when :decline_confirmed then "Match rejected by #{Translation.translate('CoC Eleven')}"
when :canceled then canceled_status_label
end
end

def step_name
"#{Translation.translate('CoC Eleven')} Reviews Match Declined by #{Translation.translate('HSA Eleven')}"
end

def actor_type
Translation.translate('CoC Eleven')
end

def contact_actor_type
nil
end

def editable?
super && saved_status !~ /decline_overridden|decline_overridden_returned|decline_confirmed/
end

def initialize_decision! send_notifications: true
super(send_notifications: send_notifications)
update status: 'pending'
send_notifications_for_step if send_notifications
end

def notifications_for_this_step
@notifications_for_this_step ||= [].tap do |m|
m << Notifications::Eleven::ConfirmHsaDeclineDndStaff
m << Notifications::Eleven::HsaDecisionClient
m << Notifications::Eleven::HsaDecisionSsp
m << Notifications::Eleven::HsaDecisionHsp
m << Notifications::Eleven::HsaDecisionShelterAgency
end
end

def accessible_by? contact
contact.user_can_reject_matches? || contact.user_can_approve_matches?
end

def show_client_match_attributes?
true
end

class StatusCallbacks < StatusCallbacks
def pending
end

def decline_overridden
match.succeeded!(user: user)
end

def decline_overridden_returned
# Re-initialize the previous decision
match.eleven_hsa_accepts_client_decision.initialize_decision!
@decision.uninitialize_decision!(send_notifications: false)
end

def decline_confirmed
match.rejected!
# TODO maybe rerun the matching engine for that vacancy and client
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this:

Suggested change
# TODO maybe rerun the matching engine for that vacancy and client

end

def canceled
Notifications::MatchCanceled.create_for_match! match
match.canceled!
end
end
private_constant :StatusCallbacks
end

def step_cancel_reasons
[
'Vacancy should not have been entered',
'Vacancy filled by other client',
'Other',
]
end
end
151 changes: 151 additions & 0 deletions app/models/match_decisions/eleven/eleven_hsa_accepts_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
###
# Copyright 2016 - 2024 Green River Data Analysis, LLC
#
# License detail: https://github.com/greenriver/boston-cas/blob/production/LICENSE.md
###

module MatchDecisions::Eleven
class ElevenHsaAcceptsClient < ::MatchDecisions::Base
def to_partial_path
'match_decisions/eleven_hsa_accepts_client'
end
include MatchDecisions::AcceptsDeclineReason

attr_accessor :building_id
attr_accessor :unit_id

# validate :note_present_if_status_declined

def label
label_for_status status
end

def label_for_status status
case status.to_sym
when :pending, :expiration_update then "#{Translation.translate('Housing Subsidy Administrator Eleven')} reviewing match"
when :accepted then "Match accepted by #{Translation.translate('Housing Subsidy Administrator Eleven')}"
when :declined then "Match declined by #{Translation.translate('Housing Subsidy Administrator Eleven')}. Reason: #{decline_reason_name}"
when :canceled then canceled_status_label
when :back then backup_status_label
end
end

# if we've overridden this decision, indicate that (this is sent to the client)
def status_label
if match.eleven_confirm_hsa_accepts_client_decline_dnd_staff_decision.status == 'decline_overridden'
'Approved'
else
statuses[status && status.to_sym]
end
end

def step_name
Translation.translate('Client Agrees to Match')
end

def actor_type
Translation.translate('HSA Eleven')
end

def contact_actor_type
:housing_subsidy_admin_contacts
end

def statuses
{
pending: 'Pending',
expiration_update: 'Pending',
accepted: 'Accepted',
declined: 'Declined',
canceled: 'Canceled',
back: 'Pending',
}
end

def expires?
true
end

def editable?
super && saved_status !~ /accepted|declined/
end

def initialize_decision! send_notifications: true
super(send_notifications: send_notifications)
update status: 'pending'
send_notifications_for_step if send_notifications
end

def notifications_for_this_step
@notifications_for_this_step ||= [].tap do |m|
m << Notifications::Eleven::HsaAcceptsClient
end
end

def notify_contact_of_action_taken_on_behalf_of contact: # rubocop:disable Lint/UnusedMethodArgument
Notifications::OnBehalfOf.create_for_match! match, contact_actor_type
end

def accessible_by? contact
contact.user_can_act_on_behalf_of_match_contacts? ||
contact.in?(match.housing_subsidy_admin_contacts)
end

def show_client_match_attributes?
true
end

class StatusCallbacks < StatusCallbacks
def pending
end

def accepted
Notifications::Eleven::HsaAcceptsClientSspNotification.create_for_match! match
match.succeeded!(user: user)
end

def declined
match.eleven_confirm_hsa_accepts_client_decline_dnd_staff_decision.initialize_decision!
end

def canceled
Notifications::MatchCanceled.create_for_match! match
match.canceled!
end

def expiration_update
end
end
private_constant :StatusCallbacks

def step_decline_reasons(_contact)
[
'Household could not be located',
'Ineligible for Housing Program',
'Client refused offer',
'Health and Safety',
'Other',
]
end

def step_cancel_reasons
[
'Vacancy should not have been entered',
'Vacancy filled by other client',
'Other',
]
end

def whitelist_params_for_update params
super.merge params.require(:decision).permit(
:building_id,
:unit_id,
:shelter_expiration,
)
end

private def note_present_if_status_declined
errors.add :note, 'Please note why the match is declined.' if note.blank? && status == 'declined'
end
end
end
Loading
Loading