Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions database/migrations/000009_add_order_status_reminder_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- +goose Up
CREATE TYPE reminder_status AS ENUM (
'SCHEDULED',
Comment thread
iichr marked this conversation as resolved.
'QUEUED',
'FAILED',
'CANCELLED'
);
Comment thread
iichr marked this conversation as resolved.

CREATE TABLE IF NOT EXISTS order_status_reminder
(
reminder_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
order_uid uuid NOT NULL REFERENCES test_order (order_uid) ON DELETE CASCADE,
trigger_status varchar(50) NOT NULL REFERENCES status_type (status_code),
reminder_number smallint NOT NULL CHECK (reminder_number >= 1),
status reminder_status NOT NULL,
triggered_at timestamp with time zone NOT NULL,
sent_at timestamp with time zone,
created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
CONSTRAINT uq_order_status_reminder
UNIQUE (order_uid, trigger_status, reminder_number)
);

CREATE INDEX IF NOT EXISTS idx_order_status_reminder_status_triggered_at
ON order_status_reminder (status, triggered_at);


-- +goose Down
DROP INDEX IF EXISTS idx_order_status_reminder_status_triggered_at;
DROP TABLE IF EXISTS order_status_reminder;
DROP TYPE IF EXISTS reminder_status;
14 changes: 14 additions & 0 deletions database/schema_diagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ entity "session" as session {
unique(refresh_token_id)
}

entity "order_status_reminder" as order_status_reminder {
**reminder_id : uuid**
*order_uid : uuid*
*trigger_status : varchar(50)*
reminder_number : smallint
status : reminder_status
triggered_at : timestamp
sent_at : timestamp
created_at : timestamp
unique(order_uid, trigger_status, reminder_number)
}

' Relationships
patient ||--o{ orders : "patient_uid"
supplier ||--o{ orders : "supplier_id"
Expand All @@ -118,8 +130,10 @@ test ||--o{ offering : "test_code"
orders ||--o{ order_status : "order_uid"
orders ||--o{ result_status : "order_uid"
orders ||--o| consent : "order_uid"
orders ||--o{ order_status_reminder : "order_uid"

status_type ||--o{ order_status : "status_code"
status_type ||--o{ order_status_reminder : "trigger_status"
result_type ||--o{ result_status : "status"

@enduml
Loading