From 9d8a475761b72d7b9f76fbba3c36e36b37b323b2 Mon Sep 17 00:00:00 2001 From: Felipe Barreta Date: Tue, 17 Dec 2024 09:26:47 -0800 Subject: [PATCH] ALCS-1858 Fix multiple dates check --- ...394698009-fix_condition_status_function.ts | 258 +++++++++--------- 1 file changed, 130 insertions(+), 128 deletions(-) diff --git a/services/apps/alcs/src/providers/typeorm/migrations/1734394698009-fix_condition_status_function.ts b/services/apps/alcs/src/providers/typeorm/migrations/1734394698009-fix_condition_status_function.ts index fe243c9aba..6e16b25d27 100644 --- a/services/apps/alcs/src/providers/typeorm/migrations/1734394698009-fix_condition_status_function.ts +++ b/services/apps/alcs/src/providers/typeorm/migrations/1734394698009-fix_condition_status_function.ts @@ -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$; @@ -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$;