Skip to content

Commit

Permalink
CE Events from CAS Matches (#862)
Browse files Browse the repository at this point in the history
* Find the reason for decline and cancelation more effectively

* Bug fixes for missing data

* Fix for change in API
  • Loading branch information
eanders authored Sep 23, 2024
1 parent cd9e70e commit 2ddb400
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
29 changes: 25 additions & 4 deletions app/models/client_opportunity_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,37 @@ def current_decision
end

def unsuccessful_decision
initialized_decisions.where.not(decline_reason_id: nil)&.first ||
initialized_decisions.where.not(administrative_cancel_reason_id: nil)&.first
return canceled_decision if canceled?

declined_decision
end

def unsuccessful_reason
return unsuccessful_decision&.administrative_cancel_reason if canceled?

unsuccessful_decision&.decline_reason
end

# Find the latest decision in the route that was declined with a reason
# If that doesn't exist, pull the latest initialized decision that was declined
def declined_decision
@declined_decision ||= initialized_decisions.where.not(decline_reason_id: nil)&.first
@declined_decision ||= initialized_decisions.where(status: :declined)&.last
decision_order = match_route.class.match_steps_for_reporting.keys
@declined_decision ||= initialized_decisions.order_as_specified(type: decision_order).where.not(decline_reason_id: nil)&.last
@declined_decision ||= initialized_decisions.order_as_specified(type: decision_order).where(status: :declined)&.last
@declined_decision
end

# Find the latest decision in the route that was canceled with a reason
# If that doesn't exist, pull the latest initialized decision that was canceled
def canceled_decision
return nil unless canceled?

decision_order = match_route.class.match_steps_for_reporting.keys
@canceled_decision ||= initialized_decisions.order_as_specified(type: decision_order).where.not(administrative_cancel_reason_id: nil)&.last
@canceled_decision ||= initialized_decisions.order_as_specified(type: decision_order).where(status: :canceled)&.last
@canceled_decision
end

def clear_current_decision_cache!
@current_decision = nil
end
Expand Down
12 changes: 8 additions & 4 deletions app/models/warehouse/referral_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ def accepted
end

def rejected
reason = client_opportunity_match.current_decision&.decline_reason
reason = client_opportunity_match.unsuccessful_reason
unsuccessful_decision = client_opportunity_match.unsuccessful_decision
closed_timestamp = unsuccessful_decision&.updated_at || client_opportunity_match.updated_at
if reason&.referral_result.present?
update(referral_result: reason.referral_result, referral_result_date: reason.referral_result_date)
update(referral_result: reason.referral_result, referral_result_date: closed_timestamp)
else
destroy
end
Expand Down Expand Up @@ -62,13 +64,15 @@ def self.sync_match_referrals!
)
end
else
reason = match.current_decision&.decline_reason
reason = match.unsuccessful_reason
unsuccessful_decision = match.unsuccessful_decision
closed_timestamp = unsuccessful_decision&.updated_at || match.updated_at
if reason.present? && reason.referral_result.present?
if event.referral_result != reason.referral_result
event.update(
event: match.sub_program.event,
referral_result: reason.referral_result,
referral_result_date: reason.referral_result_date,
referral_result_date: closed_timestamp,
)
end
else
Expand Down

0 comments on commit 2ddb400

Please sign in to comment.