-
Notifications
You must be signed in to change notification settings - Fork 19
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
Min/APPEALS-63944 #23521
base: feature/APPEALS-57706
Are you sure you want to change the base?
Min/APPEALS-63944 #23521
Conversation
Code Climate has analyzed commit 5c845f9 and detected 1 issue on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
@@ -0,0 +1,5 @@ | |||
class AddNotNullConstraintToSchedulableCutoffColumn < ActiveRecord::Migration[6.1] | |||
def change | |||
change_column_null :schedulable_cutoff_dates, :cutoff_date, false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding this in!
create_function :update_claim_status_trigger_function, sql_definition: <<-'SQL' | ||
CREATE OR REPLACE FUNCTION public.update_claim_status_trigger_function() | ||
RETURNS trigger | ||
LANGUAGE plpgsql | ||
AS $function$ | ||
declare | ||
string_claim_id varchar(25); | ||
epe_id integer; | ||
begin | ||
if (NEW."EP_CODE" LIKE '04%' | ||
OR NEW."EP_CODE" LIKE '03%' | ||
OR NEW."EP_CODE" LIKE '93%' | ||
OR NEW."EP_CODE" LIKE '68%') | ||
and (NEW."LEVEL_STATUS_CODE" = 'CLR' OR NEW."LEVEL_STATUS_CODE" = 'CAN') then | ||
string_claim_id := cast(NEW."CLAIM_ID" as varchar); | ||
select id into epe_id | ||
from end_product_establishments | ||
where (reference_id = string_claim_id | ||
and (synced_status is null or synced_status <> NEW."LEVEL_STATUS_CODE")); | ||
if epe_id > 0 | ||
then | ||
if not exists ( | ||
select 1 | ||
from priority_end_product_sync_queue | ||
where end_product_establishment_id = epe_id | ||
) then | ||
insert into priority_end_product_sync_queue (created_at, end_product_establishment_id, updated_at) | ||
values (now(), epe_id, now()); | ||
end if; | ||
end if; | ||
end if; | ||
return null; | ||
end; | ||
$function$ | ||
SQL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create_function :update_claim_status_trigger_function, sql_definition: <<-'SQL' | |
CREATE OR REPLACE FUNCTION public.update_claim_status_trigger_function() | |
RETURNS trigger | |
LANGUAGE plpgsql | |
AS $function$ | |
declare | |
string_claim_id varchar(25); | |
epe_id integer; | |
begin | |
if (NEW."EP_CODE" LIKE '04%' | |
OR NEW."EP_CODE" LIKE '03%' | |
OR NEW."EP_CODE" LIKE '93%' | |
OR NEW."EP_CODE" LIKE '68%') | |
and (NEW."LEVEL_STATUS_CODE" = 'CLR' OR NEW."LEVEL_STATUS_CODE" = 'CAN') then | |
string_claim_id := cast(NEW."CLAIM_ID" as varchar); | |
select id into epe_id | |
from end_product_establishments | |
where (reference_id = string_claim_id | |
and (synced_status is null or synced_status <> NEW."LEVEL_STATUS_CODE")); | |
if epe_id > 0 | |
then | |
if not exists ( | |
select 1 | |
from priority_end_product_sync_queue | |
where end_product_establishment_id = epe_id | |
) then | |
insert into priority_end_product_sync_queue (created_at, end_product_establishment_id, updated_at) | |
values (now(), epe_id, now()); | |
end if; | |
end if; | |
end if; | |
return null; | |
end; | |
$function$ | |
SQL |
I'm not sure if we want to keep this in just yet.. I've been removing it while I deliberate haha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new fx
gem keeps pulling it in.
AND claimants.decision_review_type = 'Appeal' | ||
AND people.date_of_birth <= CURRENT_DATE - INTERVAL '75 years' | ||
) aod_based_on_age_recognized_claimants ON TRUE | ||
LEFT JOIN schedulable_cutoff_dates ON schedulable_cutoff_dates.created_by_id = tasks.assigned_to_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cutoff dates are "global" and will need to apply to all appeals regardless of who the tasks are assigned to.
Right now all ScheduleHearingTasks are assigned to the same org, but soon with NHQ they'll be bulk assigned to individual hearing coordinators.
It may be good to make this a CTE at the top of this query:
WITH latest_cutoff_date AS (
SELECT *
FROM schedulable_cutoff_dates
ORDER BY created_at DESC
LIMIT 1
)
SELECT *,
... OR receipt_date <= COALESCE(latest_cutoff_date.cutoff_date,'2019-12-31')
FROM my_quite_intimidating_nhq_union
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could even potentially be materialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so the only date that matters is the most recent one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! And it'll apply to all appeals. We're keeping them all in the table as a sort of audit log, but only the latest one is used to determine schedulability.
appeals.changed_hearing_request_type, | ||
appeals.original_hearing_request_type | ||
) AS hearing_request_type, | ||
REPLACE (CAST(appeals.receipt_date AS TEXT), '-', '') AS receipt_date, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String manipulation is incredibly inefficient in SQL. This shouldn't be changed if it works but something we should keep in mind incase we run into efficiency issues
JOIN veterans ON appeals.veteran_file_number = veterans.file_number | ||
LEFT JOIN people veteran_person ON veteran_person.participant_id = veterans.participant_id | ||
LEFT JOIN LATERAL ( | ||
SELECT count(*) as quantity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider making this select into it's own materialized view to condense the code?
More of an @ThorntonMatthew question. Would probably require a new ticket/effort
@@ -0,0 +1,124 @@ | |||
SELECT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThorntonMatthew In the future it might be worth taking this view and splitting it into two views. Legacy appeals view and appeals view then just uniting them here. If possible I'd like to avoid this query being huge
entry = NationalHearingQueueEntry.find_by( | ||
appeal: appeal | ||
) | ||
expect(entry.schedulable).to eq(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check if the entry is set to false? Shouldn't we have the tests setup in a way where it should always be false at the beginning of the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense. The schedulable field should always just be set to false by default because the conditions that the appeal will initially have but just in case I'll just add that condition in to the find_by.
Resolves APPEALS-63944
Description
Incorporate User-Provided Cutoff Dates in Schedulability Determinations for AMA Appeals
Acceptance Criteria
The cutoff date used to determine whether an AMA appeal is "schedulable" is changed from the hardcoded value "2019-12-31" to the following:
Testing Plan
Tests
Test Coverage
Did you include any test coverage for your code? Check below: