Data Fetching Scripts - TISTATechnologies/caseflow GitHub Wiki
Rating issues missing a disposition but with a matching rating issue
This script looks for rating issues that are missing a disposition, but has a matching rating issue, so that we can start to try to backfill the disposition.
Steps:
- Create a report of all of the rating issues in this category
- Determine what the disposition should be for the issue from the decision text (if possible)
- Run the request issues through a script to create the decision issues, and subsequent actions
Pitfalls:
- If a request issue has more than one matching_rating_issue, let's flag it for now, this script only processes those with one
ris_all=RequestIssue.where.not(decision_sync_submitted_at: nil, contention_reference_id: nil, end_product_establishment_id: nil, decision_review_type: "Appeal").where(decision_sync_processed_at: nil, benefit_type: ["compensation", "pension"], closed_status: nil, is_unidentified: nil, nonrating_issue_category: nil).order("id"); 0
# Choose a batch to start with
ris=ris_all[0..1000]; 0
ris_all[1001].id # Check which ID would be the next one to start on, if this batch finished
# If this batch completes, you'll start "ris" with the next RI ID
rating_ris=ris.select(&:rating?); 0
# Rating
rating_with_disposition = rating_ris.select{ |ri| ri.contention_disposition.present? }; 0
rating_without_disposition = rating_ris - rating_with_disposition
rating_with_matching_rating_issue = rating_without_disposition.select do |ri|
begin
ri.send(:matching_rating_issues).any?
rescue
next
end
end
rating_report = rating_with_matching_rating_issue.map do |ri|
begin
matching_rating_issues = ri.send(:matching_rating_issues)
matching_rating_issue = matching_rating_issues.any? && matching_rating_issues.first
matching_rating_issue_count = matching_rating_issues.any? && matching_rating_issues.count
associated_rating = ri.end_product_establishment&.associated_rating
rating_profile=associated_rating.send(:rating_profile)
disabilities = rating_profile && rating_profile.dig(:disabilities) || []
evaluations=disabilities.any? && disabilities.map{|d| d.dig(:disability_evaluations)}.flatten || []
matching_evaluation = evaluations.any? && evaluations.find{|e| e.dig(:rba_issue_id) == matching_rating_issue&.reference_id}
splmntl_decn_tc = matching_evaluation && matching_evaluation.dig(:splmntl_decn_tc)
[ri.id, ri.end_product_establishment&.reference_id, ri.end_product_establishment&.synced_status, ri.end_product_establishment&.last_synced_at&.to_s, ri.contention_reference_id, ri.bgs_contention&.orig_source_type_code, matching_rating_issue&.decision_text, splmntl_decn_tc, matching_rating_issue_count, ri.decision_issues.count]
rescue
next
end
end
# clear buffer
rating_report # prints report
# copy and paste into spreadsheet
issues.each{|d| backfill_disposition(d[0],d[1])}
def backfill_disposition(id, disposition)
request_issue=RequestIssue.find(id)
matching_rating_issues = request_issue.send(:matching_rating_issues)
return unless matching_rating_issues.any?
return if matching_rating_issues.count > 1
matching_rating_issue = matching_rating_issues.first
request_issue.decision_issues << create_decision_issue_with_disposition(request_issue, matching_rating_issue, disposition)
request_issue.decision_review.create_remand_supplemental_claims! if disposition.match?("DTA")
end
def create_decision_issue_with_disposition(request_issue, rating_issue, disposition)
preexisting_decision_issue = DecisionIssue.find_by(
participant_id: rating_issue.participant_id,
rating_issue_reference_id: rating_issue.reference_id,
disposition: disposition
)
return preexisting_decision_issue if preexisting_decision_issue
DecisionIssue.create!(
rating_issue_reference_id: rating_issue.reference_id,
disposition: disposition,
participant_id: rating_issue.participant_id,
rating_promulgation_date: rating_issue.promulgation_date,
decision_text: rating_issue.decision_text,
rating_profile_date: rating_issue.profile_date,
decision_review: request_issue.decision_review,
benefit_type: rating_issue.benefit_type,
subject_text: rating_issue.subject_text,
percent_number: rating_issue.percent_number,
end_product_last_action_date: request_issue.end_product_establishment.last_action_date
)
end
Failed Decision Issue Syncing
This script looks for request issues that have not completed decision issue syncing.
ris_all=RequestIssue.expired_without_processing.order("id"); 0
# Choose a batch to start with
ris=ris_all[1001..2000]; 0
snippets = [
"Rating::NilRatingProfileListError",
"RequestIssue::ErrorCreatingDecisionIssue",
"RequestIssue::NoAssociatedRating"
]
report = ris.map do |ri|
error = ri.send(ri.class.error_column)
error_category = snippets.find{|snippet| error&.match?(snippet)}
[ri.id, ri.end_product_establishment&.reference_id, ri.end_product_establishment&.synced_status, error_category, ri.end_product_establishment&.last_synced_at&.to_s, ri.contention_reference_id, ri.bgs_contention&.orig_source_type_code, ri.decision_issues.count]
end