From 304ef9f3493ca45ef16816042f22be9840732c2c Mon Sep 17 00:00:00 2001 From: Felipe Barreta Date: Tue, 17 Dec 2024 12:15:26 -0800 Subject: [PATCH 1/2] ALCS-1850 Change expiry comparision and compare only date portions --- .../1734465908479-fix_expired_condition.ts | 339 ++++++++++++++++++ 1 file changed, 339 insertions(+) create mode 100644 services/apps/alcs/src/providers/typeorm/migrations/1734465908479-fix_expired_condition.ts diff --git a/services/apps/alcs/src/providers/typeorm/migrations/1734465908479-fix_expired_condition.ts b/services/apps/alcs/src/providers/typeorm/migrations/1734465908479-fix_expired_condition.ts new file mode 100644 index 0000000000..e05ecf644a --- /dev/null +++ b/services/apps/alcs/src/providers/typeorm/migrations/1734465908479-fix_expired_condition.ts @@ -0,0 +1,339 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class FixExpiredCondition1734465908479 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE OR REPLACE FUNCTION alcs.get_current_status_for_application_condition( + application_condition_uuid uuid, + OUT status character varying) + RETURNS character varying + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + AS $BODY$ + 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; + + 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::date >= utc_timestamp_today::date OR date_record.date IS NULL) THEN + is_pending = true; + END IF; + -- check if it's past due + IF (date_record.date::date <= utc_timestamp_today::date 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::date < utc_timestamp_today::date 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$; + + ALTER FUNCTION alcs.get_current_status_for_application_condition(uuid) + OWNER TO postgres; + `); + await queryRunner.query(` + CREATE OR REPLACE FUNCTION alcs.get_current_status_for_noi_condition( + noi_condition_uuid uuid, + OUT status character varying) + RETURNS character varying + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + AS $BODY$ + 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; + + 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::date >= utc_timestamp_today::date OR date_record.date IS NULL) THEN + is_pending = true; + END IF; + -- check if it's past due + IF (date_record.date::date <= utc_timestamp_today::date 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::date < utc_timestamp_today::date 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$; + + ALTER FUNCTION alcs.get_current_status_for_noi_condition(uuid) + OWNER TO postgres; + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE OR REPLACE FUNCTION alcs.get_current_status_for_application_condition( + application_condition_uuid uuid, + OUT status character varying) + RETURNS character varying + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + AS $BODY$ + 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; + + 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$; + + ALTER FUNCTION alcs.get_current_status_for_application_condition(uuid) + OWNER TO postgres; + `); + await queryRunner.query(` + CREATE OR REPLACE FUNCTION alcs.get_current_status_for_noi_condition( + noi_condition_uuid uuid, + OUT status character varying) + RETURNS character varying + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + AS $BODY$ + 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; + + 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$; + + ALTER FUNCTION alcs.get_current_status_for_noi_condition(uuid) + OWNER TO postgres; + `); + } + +} From 91057b5805e7e9c3418c12809d366daf2973f258 Mon Sep 17 00:00:00 2001 From: Felipe Barreta Date: Tue, 17 Dec 2024 12:44:34 -0800 Subject: [PATCH 2/2] ALCS-1858 Change ongoing and past due --- .../migrations/1734465908479-fix_expired_condition.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/services/apps/alcs/src/providers/typeorm/migrations/1734465908479-fix_expired_condition.ts b/services/apps/alcs/src/providers/typeorm/migrations/1734465908479-fix_expired_condition.ts index e05ecf644a..d072da426f 100644 --- a/services/apps/alcs/src/providers/typeorm/migrations/1734465908479-fix_expired_condition.ts +++ b/services/apps/alcs/src/providers/typeorm/migrations/1734465908479-fix_expired_condition.ts @@ -42,7 +42,6 @@ export class FixExpiredCondition1734465908479 implements MigrationInterface { LOOP FETCH NEXT FROM dates_cursor INTO date_record; IF NOT FOUND THEN - is_pending = true; EXIT; END IF; is_ongoing = false; @@ -55,7 +54,7 @@ export class FixExpiredCondition1734465908479 implements MigrationInterface { is_pending = true; END IF; -- check if it's past due - IF (date_record.date::date <= utc_timestamp_today::date AND (date_record.single_date_label = 'Due Date' OR date_record.date_type = 'Multiple')) THEN + IF (date_record.date::date < utc_timestamp_today::date 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 @@ -124,7 +123,6 @@ export class FixExpiredCondition1734465908479 implements MigrationInterface { LOOP FETCH NEXT FROM dates_cursor INTO date_record; IF NOT FOUND THEN - is_pending = true; EXIT; END IF; is_ongoing = false; @@ -137,7 +135,7 @@ export class FixExpiredCondition1734465908479 implements MigrationInterface { is_pending = true; END IF; -- check if it's past due - IF (date_record.date::date <= utc_timestamp_today::date AND (date_record.single_date_label = 'Due Date' OR date_record.date_type = 'Multiple')) THEN + IF (date_record.date::date < utc_timestamp_today::date 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