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

Min/APPEALS-63944 #23521

Draft
wants to merge 4 commits into
base: feature/APPEALS-57706
Choose a base branch
from
Draft

Min/APPEALS-63944 #23521

wants to merge 4 commits into from

Conversation

minhazur9
Copy link
Contributor

@minhazur9 minhazur9 commented Nov 15, 2024

Resolves APPEALS-63944

Description

Incorporate User-Provided Cutoff Dates in Schedulability Determinations for AMA Appeals

Acceptance Criteria

  • Code compiles correctly
  • A migration is generated in order to update the national_hearing_queue_entries materialized view in the following fashion:
    The cutoff date used to determine whether an AMA appeal is "schedulable" is changed from the hardcoded value "2019-12-31" to the following:
    • COALESCE(most recently entered cutoff_date from the schedulable_cutoff_dates table, "2019-12-31")
      • If there is not a cutoff date available in the schedulable_cutoff_dates table then the existing "2019-12-31" value is used as a fallback.
  • Appeals whose receipt date is on or before the specified cutoff date will be considered to be "schedulable".
  • cutoff_date in schedulable_cutoff_dates table has a not-null constraint introduced to its column.

Testing Plan

  1. Go to APPEALS-64952
  • For feature branches merging into main: Was this deployed to UAT?

Tests

Test Coverage

Did you include any test coverage for your code? Check below:

  • RSpec
  • Jest
  • Other

@minhazur9 minhazur9 changed the base branch from main to feature/APPEALS-57706 November 15, 2024 18:25
Copy link

codeclimate bot commented Nov 15, 2024

Code Climate has analyzed commit 5c845f9 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Security 1

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
Copy link
Contributor

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!

Comment on lines +2471 to +2508
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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,
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants