Skip to content

Commit

Permalink
ALCS-1858 Fix multiple dates check
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarreta committed Dec 17, 2024
1 parent e34ed5d commit 9d8a475
Showing 1 changed file with 130 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,73 @@ export class FixConditionStatusFunction1734394698009 implements MigrationInterfa
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE
dates_cursor CURSOR FOR
SELECT
t.single_date_label, d.uuid, d.date, d.comment, d.completed_date
FROM alcs.application_decision_condition_date d
INNER JOIN alcs.application_decision_condition c ON c.uuid = d.condition_uuid
INNER JOIN alcs.application_decision_condition_type t ON t.code = c.type_code
WHERE
d.condition_uuid = application_condition_uuid;
utc_timestamp_today timestamptz;
is_ongoing boolean;
is_completed boolean;
is_pastdue boolean;
is_pending boolean;
is_expired boolean;
date_record RECORD;
BEGIN
utc_timestamp_today = timezone('utc', (now()));
status = 'ONGOING';
is_ongoing = true;
is_completed = false;
is_pastdue = false;
is_pending = false;
is_expired = false;
DECLARE
dates_cursor CURSOR FOR
SELECT
t.single_date_label, t.date_type, d.uuid, d.date, d.comment, d.completed_date
FROM alcs.application_decision_condition_date d
INNER JOIN alcs.application_decision_condition c ON c.uuid = d.condition_uuid
INNER JOIN alcs.application_decision_condition_type t ON t.code = c.type_code
WHERE
d.condition_uuid = application_condition_uuid;
utc_timestamp_today timestamptz;
is_ongoing boolean;
is_completed boolean;
is_pastdue boolean;
is_pending boolean;
is_expired boolean;
date_record RECORD;
BEGIN
utc_timestamp_today = timezone('utc', (now()));
status = 'ONGOING';
is_ongoing = true;
is_completed = false;
is_pastdue = false;
is_pending = false;
is_expired = false;
OPEN dates_cursor;
OPEN dates_cursor;
LOOP
FETCH NEXT FROM dates_cursor INTO date_record;
IF NOT FOUND THEN
is_pending = true;
EXIT;
END IF;
is_ongoing = false;
IF (date_record.completed_date IS NOT NULL) THEN
is_completed = true;
ELSE
is_completed = false;
-- check if it's pending
IF (date_record.date >= utc_timestamp_today OR date_record.date IS NULL) THEN
is_pending = true;
END IF;
-- check if it's past due
IF (date_record.date <= utc_timestamp_today AND date_record.single_date_label = 'Due Date') THEN
is_pastdue = true;
END IF;
-- check if it's expired
IF (date_record.date <= utc_timestamp_today AND date_record.single_date_label = 'End Date') THEN
is_expired = true;
END IF;
END IF;
END LOOP;
CLOSE dates_cursor;
IF (is_completed) THEN
status = 'COMPLETED';
END IF;
IF (is_pending) THEN
status = 'PENDING';
END IF;
IF (is_expired) THEN
status = 'EXPIRED';
END IF;
IF (is_pastdue) THEN
status = 'PASTDUE';
END IF;
END;
LOOP
FETCH NEXT FROM dates_cursor INTO date_record;
IF NOT FOUND THEN
is_pending = true;
EXIT;
END IF;
is_ongoing = false;
IF (date_record.completed_date IS NOT NULL) THEN
is_completed = true;
ELSE
is_completed = false;
-- check if it's pending
IF (date_record.date >= utc_timestamp_today OR date_record.date IS NULL) THEN
is_pending = true;
END IF;
-- check if it's past due
IF (date_record.date <= utc_timestamp_today AND (date_record.single_date_label = 'Due Date' OR date_record.date_type = 'Multiple')) THEN
is_pastdue = true;
END IF;
-- check if it's expired
IF (date_record.date <= utc_timestamp_today AND date_record.single_date_label = 'End Date') THEN
is_expired = true;
END IF;
END IF;
END LOOP;
CLOSE dates_cursor;
IF (is_completed) THEN
status = 'COMPLETED';
END IF;
IF (is_pending) THEN
status = 'PENDING';
END IF;
IF (is_expired) THEN
status = 'EXPIRED';
END IF;
IF (is_pastdue) THEN
status = 'PASTDUE';
END IF;
END;
$BODY$;
Expand All @@ -93,72 +94,73 @@ export class FixConditionStatusFunction1734394698009 implements MigrationInterfa
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE
dates_cursor CURSOR FOR
SELECT
t.single_date_label, d.uuid, d.date, d.comment, d.completed_date
FROM alcs.notice_of_intent_decision_condition_date d
INNER JOIN alcs.notice_of_intent_decision_condition c ON c.uuid = d.condition_uuid
INNER JOIN alcs.notice_of_intent_decision_condition_type t ON t.code = c.type_code
WHERE
d.condition_uuid = noi_condition_uuid;
utc_timestamp_today timestamptz;
is_ongoing boolean;
is_completed boolean;
is_pastdue boolean;
is_pending boolean;
is_expired boolean;
date_record RECORD;
BEGIN
utc_timestamp_today = timezone('utc', (now()));
status = 'ONGOING';
is_ongoing = true;
is_completed = false;
is_pastdue = false;
is_pending = false;
is_expired = false;
DECLARE
dates_cursor CURSOR FOR
SELECT
t.single_date_label, t.date_type, d.uuid, d.date, d.comment, d.completed_date
FROM alcs.notice_of_intent_decision_condition_date d
INNER JOIN alcs.notice_of_intent_decision_condition c ON c.uuid = d.condition_uuid
INNER JOIN alcs.notice_of_intent_decision_condition_type t ON t.code = c.type_code
WHERE
d.condition_uuid = noi_condition_uuid;
utc_timestamp_today timestamptz;
is_ongoing boolean;
is_completed boolean;
is_pastdue boolean;
is_pending boolean;
is_expired boolean;
date_record RECORD;
BEGIN
utc_timestamp_today = timezone('utc', (now()));
status = 'ONGOING';
is_ongoing = true;
is_completed = false;
is_pastdue = false;
is_pending = false;
is_expired = false;
OPEN dates_cursor;
OPEN dates_cursor;
LOOP
FETCH NEXT FROM dates_cursor INTO date_record;
IF NOT FOUND THEN
is_pending = true;
EXIT;
END IF;
is_ongoing = false;
IF (date_record.completed_date IS NOT NULL) THEN
is_completed = true;
ELSE
is_completed = false;
-- check if it's pending
IF (date_record.date >= utc_timestamp_today OR date_record.date IS NULL) THEN
is_pending = true;
END IF;
-- check if it's past due
IF (date_record.date <= utc_timestamp_today AND date_record.single_date_label = 'Due Date') THEN
is_pastdue = true;
END IF;
-- check if it's expired
IF (date_record.date <= utc_timestamp_today AND date_record.single_date_label = 'End Date') THEN
is_expired = true;
END IF;
END IF;
END LOOP;
CLOSE dates_cursor;
IF (is_completed) THEN
status = 'COMPLETED';
END IF;
IF (is_pending) THEN
status = 'PENDING';
END IF;
IF (is_expired) THEN
status = 'EXPIRED';
END IF;
IF (is_pastdue) THEN
status = 'PASTDUE';
END IF;
END;
LOOP
FETCH NEXT FROM dates_cursor INTO date_record;
IF NOT FOUND THEN
is_pending = true;
EXIT;
END IF;
is_ongoing = false;
IF (date_record.completed_date IS NOT NULL) THEN
is_completed = true;
ELSE
is_completed = false;
-- check if it's pending
IF (date_record.date >= utc_timestamp_today OR date_record.date IS NULL) THEN
is_pending = true;
END IF;
-- check if it's past due
IF (date_record.date <= utc_timestamp_today AND (date_record.single_date_label = 'Due Date' OR date_record.date_type = 'Multiple')) THEN
is_pastdue = true;
END IF;
-- check if it's expired
IF (date_record.date <= utc_timestamp_today AND date_record.single_date_label = 'End Date') THEN
is_expired = true;
END IF;
END IF;
END LOOP;
CLOSE dates_cursor;
IF (is_completed) THEN
status = 'COMPLETED';
END IF;
IF (is_pending) THEN
status = 'PENDING';
END IF;
IF (is_expired) THEN
status = 'EXPIRED';
END IF;
IF (is_pastdue) THEN
status = 'PASTDUE';
END IF;
END;
$BODY$;
Expand Down

0 comments on commit 9d8a475

Please sign in to comment.