Dumped on 2024-06-25

Index of database - gnumed_v22


Schema au


Table: au.referral

table for referrals to defined individuals

au.referral Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
row_version integer NOT NULL
modified_when timestamp with time zone NOT NULL DEFAULT now()
modified_by name NOT NULL DEFAULT "current_user"()
pk_item integer NOT NULL DEFAULT nextval('clin.clin_root_item_pk_item_seq'::regclass)
clin_when timestamp with time zone NOT NULL DEFAULT now()
clin.encounter.pk fk_encounter integer NOT NULL
clin.episode.pk fk_episode integer NOT NULL
narrative text

inherited from clin.clin_root_item; stores text of referral letter
soap_cat text
id serial PRIMARY KEY
dem.identity.pk fk_referee integer NOT NULL

person to whom the referral is directed
clin.form_instances.pk fk_form integer NOT NULL

foreign key to the form instance of this referral.

Table au.referral Inherits clin_root_item,

 

au.referral Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_root_item_sane_soap_cat CHECK (((soap_cat IS NULL) OR (soap_cat = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]))))

Index - Schema au


Schema audit


Table: audit.audit_fields

this table holds all the fields needed for auditing

audit.audit_fields Structure
F-Key Name Type Description
pk_audit serial PRIMARY KEY
row_version integer NOT NULL

the version of the row; mainly just a count
modified_when timestamp with time zone NOT NULL DEFAULT now()

when has this row been committed (created/modified)
modified_by name NOT NULL DEFAULT "current_user"()

by whom has this row been committed (created/modified)

 

audit.audit_fields Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema audit


Table: audit.audit_trail

Each table that needs standard auditing must have a log table inheriting from this table. Log tables have the same name with a prepended "log_". However, log_* tables shall not have constraints.

audit.audit_trail Structure
F-Key Name Type Description
pk_audit serial PRIMARY KEY
orig_version integer NOT NULL

the version of this row in the original table previous to the modification
orig_when timestamp with time zone NOT NULL

previous modification date in the original table
orig_by name NOT NULL

who committed the row to the original table
orig_tableoid oid NOT NULL

the table oid of the original table, use this to identify the source table
audit_action text NOT NULL

either "update" or "delete"
audit_when timestamp with time zone NOT NULL DEFAULT now()

when committed to this table for auditing
audit_by name NOT NULL DEFAULT "current_user"()

committed to this table for auditing by whom

 

audit.audit_trail Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.audited_tables

All tables that need standard auditing must be recorded in this table. Audit triggers will be generated automatically for all tables recorded here.

audit.audited_tables Structure
F-Key Name Type Description
id serial PRIMARY KEY
schema name UNIQUE#1 NOT NULL DEFAULT 'public'::name
table_name name UNIQUE#1 NOT NULL

Index - Schema audit


Table: audit.log_access_log

audit.log_access_log Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
user_action text

Table audit.log_access_log Inherits audit_trail,

 

audit.log_access_log Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_address

audit.log_address Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
id_street integer
aux_street text
number text
subunit text
addendum text
lat_lon point

Table audit.log_address Inherits audit_trail,

 

audit.log_address Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_allergy

audit.log_allergy Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer
substance text
substance_code text
generics text
allergene text
atc_code text
fk_type integer
generic_specific boolean
definite boolean

Table audit.log_allergy Inherits audit_trail,

 

audit.log_allergy Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_allergy_state

audit.log_allergy_state Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
has_allergy integer
comment text
last_confirmed timestamp with time zone
fk_encounter integer

Table audit.log_allergy_state Inherits audit_trail,

 

audit.log_allergy_state Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_auto_hint

audit.log_auto_hint Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
query text
title text
hint text
url text
is_active boolean
source text
lang text
recommendation_query text
popup_type integer
highlight_as_priority boolean

Table audit.log_auto_hint Inherits audit_trail,

 

audit.log_auto_hint Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_beh_fall_typ

audit.log_beh_fall_typ Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
code text
kurzform text
name text

Table audit.log_beh_fall_typ Inherits audit_trail,

 

audit.log_beh_fall_typ Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_bill

audit.log_bill Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
invoice_id text
close_date timestamp with time zone
apply_vat boolean
fk_receiver_identity integer
fk_receiver_address integer
fk_doc integer
comment text

Table audit.log_bill Inherits audit_trail,

 

audit.log_bill Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_bill_item

audit.log_bill_item Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_provider integer
fk_encounter integer
date_to_bill date
description text
net_amount_per_unit numeric
currency text
status text
fk_billable integer
fk_bill integer
unit_count integer
amount_multiplier numeric

Table audit.log_bill_item Inherits audit_trail,

 

audit.log_bill_item Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_billable

audit.log_billable Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
pk_coding_system integer
code text
term text
fk_data_source integer
comment text
pk integer
amount numeric
currency text
vat_multiplier numeric
active boolean
discountable boolean

Table audit.log_billable Inherits audit_trail,

 

audit.log_billable Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_clin_aux_note

audit.log_clin_aux_note Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer

Table audit.log_clin_aux_note Inherits audit_trail,

 

audit.log_clin_aux_note Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_clin_diag

audit.log_clin_diag Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_narrative integer
laterality bpchar
is_chronic boolean
is_active boolean
is_definite boolean
clinically_relevant boolean

Table audit.log_clin_diag Inherits audit_trail,

 

audit.log_clin_diag Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_clin_item_type

audit.log_clin_item_type Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
type text
code text

Table audit.log_clin_item_type Inherits audit_trail,

 

audit.log_clin_item_type Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_clin_narrative

audit.log_clin_narrative Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer

Table audit.log_clin_narrative Inherits audit_trail,

 

audit.log_clin_narrative Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_consumable_substance

audit.log_consumable_substance Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
atc_code text
amount numeric
unit text

Table audit.log_consumable_substance Inherits audit_trail,

 

audit.log_consumable_substance Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_consumed_substance

audit.log_consumed_substance Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
atc_code text

Table audit.log_consumed_substance Inherits audit_trail,

 

audit.log_consumed_substance Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_data_source

audit.log_data_source Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
name_short text
name_long text
version text
description text
source text
lang text

Table audit.log_data_source Inherits audit_trail,

 

audit.log_data_source Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_doc_desc

audit.log_doc_desc Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_doc integer
text text

Table audit.log_doc_desc Inherits audit_trail,

 

audit.log_doc_desc Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_doc_med

audit.log_doc_med Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_encounter integer
fk_episode integer
fk_type integer
comment text
clin_when timestamp with time zone
ext_ref text
fk_org_unit integer
unit_is_receiver boolean
fk_hospital_stay integer

Table audit.log_doc_med Inherits audit_trail,

 

audit.log_doc_med Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_dose

audit.log_dose Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
pk integer
fk_substance integer
amount numeric
unit text
dose_unit text

Table audit.log_dose Inherits audit_trail,

 

audit.log_dose Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_drug_product

audit.log_drug_product Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
preparation text
atc_code text
is_fake boolean
fk_data_source integer
external_code text
external_code_type text

Table audit.log_drug_product Inherits audit_trail,

 

audit.log_drug_product Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_encounter

audit.log_encounter Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_patient integer
fk_type integer
fk_location integer
source_time_zone interval
reason_for_encounter text
assessment_of_encounter text
started timestamp with time zone
last_affirmed timestamp with time zone

Table audit.log_encounter Inherits audit_trail,

 

audit.log_encounter Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_episode

audit.log_episode Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_health_issue integer
description text
is_open boolean
fk_encounter integer
diagnostic_certainty_classification text
summary text

Table audit.log_episode Inherits audit_trail,

 

audit.log_episode Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_external_care

audit.log_external_care Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_encounter integer
fk_health_issue integer
issue text
fk_org_unit integer
provider text
comment text
inactive boolean

Table audit.log_external_care Inherits audit_trail,

 

audit.log_external_care Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_family_history

audit.log_family_history Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer
fk_relation_type integer
age_noted text
age_of_death interval
contributed_to_death boolean
name_relative text
dob_relative timestamp with time zone
comment text

Table audit.log_family_history Inherits audit_trail,

 

audit.log_family_history Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_fhx_relation_type

audit.log_fhx_relation_type Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
is_genetic boolean

Table audit.log_fhx_relation_type Inherits audit_trail,

 

audit.log_fhx_relation_type Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_form_data

audit.log_form_data Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_instance integer
fk_form_field integer
value text

Table audit.log_form_data Inherits audit_trail,

 

audit.log_form_data Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_form_instances

audit.log_form_instances Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer
fk_form_def integer
form_name text

Table audit.log_form_instances Inherits audit_trail,

 

audit.log_form_instances Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_gender_label

audit.log_gender_label Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
tag text
label text
sort_weight integer
comment text

Table audit.log_gender_label Inherits audit_trail,

 

audit.log_gender_label Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_health_issue

audit.log_health_issue Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
laterality character varying
age_noted interval
is_active boolean
clinically_relevant boolean
is_confidential boolean
is_cause_of_death boolean
fk_encounter integer
grouping text
diagnostic_certainty_classification text
summary text

Table audit.log_health_issue Inherits audit_trail,

 

audit.log_health_issue Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_hospital_stay

audit.log_hospital_stay Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer
discharge timestamp with time zone
fk_org_unit integer

Table audit.log_hospital_stay Inherits audit_trail,

 

audit.log_hospital_stay Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_hx_family_item

audit.log_hx_family_item Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_narrative_condition integer
fk_relative integer
name_relative text
dob_relative timestamp with time zone
condition text
age_noted text
age_of_death interval
is_cause_of_death boolean

Table audit.log_hx_family_item Inherits audit_trail,

 

audit.log_hx_family_item Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_identity

audit.log_identity Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
deleted boolean
gender text
dob timestamp with time zone
fk_marital_status integer
cob bpchar
deceased timestamp with time zone
title text
tob time without time zone
emergency_contact text
fk_emergency_contact integer
comment text
fk_primary_provider integer
dob_is_estimated boolean

Table audit.log_identity Inherits audit_trail,

 

audit.log_identity Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_identity_tag

audit.log_identity_tag Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_identity integer
fk_tag integer
comment text

Table audit.log_identity_tag Inherits audit_trail,

 

audit.log_identity_tag Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_inbox_item_category

audit.log_inbox_item_category Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
is_user boolean

Table audit.log_inbox_item_category Inherits audit_trail,

 

audit.log_inbox_item_category Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_inbox_item_type

audit.log_inbox_item_type Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_inbox_item_category integer
description text
is_user boolean

Table audit.log_inbox_item_type Inherits audit_trail,

 

audit.log_inbox_item_type Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_incoming_data_unmatchable

audit.log_incoming_data_unmatchable Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_patient_candidates integer[]
request_id text
firstnames text
lastnames text
dob date
postcode text
other_info text
type text
data bytea
gender text
requestor text
external_data_id text
fk_identity_disambiguated integer

Table audit.log_incoming_data_unmatchable Inherits audit_trail,

 

audit.log_incoming_data_unmatchable Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_incoming_data_unmatched

audit.log_incoming_data_unmatched Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_patient_candidates integer[]
request_id text
firstnames text
lastnames text
dob date
postcode text
other_info text
type text
data bytea
gender text
requestor text
external_data_id text
fk_identity_disambiguated integer
comment text
fk_provider_disambiguated integer

Table audit.log_incoming_data_unmatched Inherits audit_trail,

 

audit.log_incoming_data_unmatched Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lab_request

audit.log_lab_request Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer
fk_test_org integer
request_id text
fk_requestor integer
lab_request_id text
lab_rxd_when timestamp with time zone
results_reported_when timestamp with time zone
request_status text
is_pending boolean
diagnostic_service_section text
ordered_service text
note_test_org text

Table audit.log_lab_request Inherits audit_trail,

 

audit.log_lab_request Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lab_test_gnr

audit.log_lab_test_gnr Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
id_test integer

Table audit.log_lab_test_gnr Inherits audit_trail,

 

audit.log_lab_test_gnr Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_code2aoe

audit.log_lnk_code2aoe Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_lnk_code2item integer
fk_generic_code integer
fk_item integer
code_modifier text
pk integer

Table audit.log_lnk_code2aoe Inherits audit_trail,

 

audit.log_lnk_code2aoe Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_code2episode

audit.log_lnk_code2episode Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_lnk_code2item integer
fk_generic_code integer
fk_item integer
code_modifier text
pk integer

Table audit.log_lnk_code2episode Inherits audit_trail,

 

audit.log_lnk_code2episode Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_code2fhx

audit.log_lnk_code2fhx Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_lnk_code2item integer
fk_generic_code integer
fk_item integer
code_modifier text
pk integer

Table audit.log_lnk_code2fhx Inherits audit_trail,

 

audit.log_lnk_code2fhx Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_code2h_issue

audit.log_lnk_code2h_issue Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_lnk_code2item integer
fk_generic_code integer
fk_item integer
code_modifier text
pk integer

Table audit.log_lnk_code2h_issue Inherits audit_trail,

 

audit.log_lnk_code2h_issue Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_code2narrative

audit.log_lnk_code2narrative Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_lnk_code2item integer
fk_generic_code integer
fk_item integer
code_modifier text
pk integer

Table audit.log_lnk_code2narrative Inherits audit_trail,

 

audit.log_lnk_code2narrative Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_code2procedure

audit.log_lnk_code2procedure Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_lnk_code2item integer
fk_generic_code integer
fk_item integer
code_modifier text
pk integer

Table audit.log_lnk_code2procedure Inherits audit_trail,

 

audit.log_lnk_code2procedure Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_code2rfe

audit.log_lnk_code2rfe Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_lnk_code2item integer
fk_generic_code integer
fk_item integer
code_modifier text
pk integer

Table audit.log_lnk_code2rfe Inherits audit_trail,

 

audit.log_lnk_code2rfe Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_code2tst_pnl

audit.log_lnk_code2tst_pnl Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_lnk_code2item integer
fk_generic_code integer
fk_item integer
code_modifier text
pk integer

Table audit.log_lnk_code2tst_pnl Inherits audit_trail,

 

audit.log_lnk_code2tst_pnl Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_constraint2vacc_course

audit.log_lnk_constraint2vacc_course Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_vaccination_course integer
fk_constraint integer

Table audit.log_lnk_constraint2vacc_course Inherits audit_trail,

 

audit.log_lnk_constraint2vacc_course Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_dose2drug

audit.log_lnk_dose2drug Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
pk integer
fk_drug_product integer
fk_dose integer

Table audit.log_lnk_dose2drug Inherits audit_trail,

 

audit.log_lnk_dose2drug Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_identity2ext_id

audit.log_lnk_identity2ext_id Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
id_identity integer
external_id text
fk_origin integer
comment text

Table audit.log_lnk_identity2ext_id Inherits audit_trail,

 

audit.log_lnk_identity2ext_id Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_identity2primary_doc

audit.log_lnk_identity2primary_doc Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
pk integer
fk_identity integer
fk_primary_doc integer

Table audit.log_lnk_identity2primary_doc Inherits audit_trail,

 

audit.log_lnk_identity2primary_doc Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_job2person

audit.log_lnk_job2person Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_identity integer
fk_occupation integer
activities text

Table audit.log_lnk_job2person Inherits audit_trail,

 

audit.log_lnk_job2person Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_loinc2substance

audit.log_lnk_loinc2substance Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
pk integer
fk_substance integer
loinc text
max_age interval
comment text

Table audit.log_lnk_loinc2substance Inherits audit_trail,

 

audit.log_lnk_loinc2substance Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_loinc2test_panel

audit.log_lnk_loinc2test_panel Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
pk integer
fk_test_panel integer
loinc text

Table audit.log_lnk_loinc2test_panel Inherits audit_trail,

 

audit.log_lnk_loinc2test_panel Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_org_unit2comm

audit.log_lnk_org_unit2comm Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_org_unit integer
url text
fk_type integer
is_confidential boolean
comment text

Table audit.log_lnk_org_unit2comm Inherits audit_trail,

 

audit.log_lnk_org_unit2comm Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_org_unit2ext_id

audit.log_lnk_org_unit2ext_id Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_org_unit integer
external_id text
fk_type integer
comment text

Table audit.log_lnk_org_unit2ext_id Inherits audit_trail,

 

audit.log_lnk_org_unit2ext_id Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_pat2vaccination_course

audit.log_lnk_pat2vaccination_course Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_patient integer
fk_course integer

Table audit.log_lnk_pat2vaccination_course Inherits audit_trail,

 

audit.log_lnk_pat2vaccination_course Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_person2relative

audit.log_lnk_person2relative Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
id_identity integer
id_relative integer
id_relation_type integer
started date
ended date

Table audit.log_lnk_person2relative Inherits audit_trail,

 

audit.log_lnk_person2relative Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_substance2brand

audit.log_lnk_substance2brand Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_brand integer
fk_substance integer

Table audit.log_lnk_substance2brand Inherits audit_trail,

 

audit.log_lnk_substance2brand Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_tst2norm

audit.log_lnk_tst2norm Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
id_test integer
id_norm integer

Table audit.log_lnk_tst2norm Inherits audit_trail,

 

audit.log_lnk_tst2norm Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_type2item

audit.log_lnk_type2item Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_type integer
fk_item integer

Table audit.log_lnk_type2item Inherits audit_trail,

 

audit.log_lnk_type2item Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_vaccination_course2schedule

audit.log_lnk_vaccination_course2schedule Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_course integer
fk_schedule integer

Table audit.log_lnk_vaccination_course2schedule Inherits audit_trail,

 

audit.log_lnk_vaccination_course2schedule Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_lnk_vaccine2inds

audit.log_lnk_vaccine2inds Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
fk_vaccine integer
fk_indication integer

Table audit.log_lnk_vaccine2inds Inherits audit_trail,

 

audit.log_lnk_vaccine2inds Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_message_inbox

audit.log_message_inbox Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_staff integer
fk_inbox_item_type integer
comment text
data text
importance smallint
fk_patient integer
ufk_context integer[]
due_date date
expiry_date date

Table audit.log_message_inbox Inherits audit_trail,

 

audit.log_message_inbox Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_occupation

audit.log_occupation Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
name text

Table audit.log_occupation Inherits audit_trail,

 

audit.log_occupation Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_operation

audit.log_operation Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_health_issue integer
fk_encounter integer
clin_where text
comment text

Table audit.log_operation Inherits audit_trail,

 

audit.log_operation Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_org

audit.log_org Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
fk_category integer
fk_data_source integer

Table audit.log_org Inherits audit_trail,

 

audit.log_org Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_org_unit

audit.log_org_unit Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
fk_org integer
fk_address integer
fk_category integer

Table audit.log_org_unit Inherits audit_trail,

 

audit.log_org_unit Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_paperwork_templates

audit.log_paperwork_templates Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_template_type integer
instance_type text
name_short text
name_long text
external_version text
gnumed_revision double precision
engine text
in_use boolean
filename text
data bytea
edit_after_substitution boolean

Table audit.log_paperwork_templates Inherits audit_trail,

 

audit.log_paperwork_templates Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_patient

audit.log_patient Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_identity integer
edc date

Table audit.log_patient Inherits audit_trail,

 

audit.log_patient Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_prax_geb_paid

audit.log_prax_geb_paid Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_fall integer
paid_amount numeric
paid_when date
paid_with integer

Table audit.log_prax_geb_paid Inherits audit_trail,

 

audit.log_prax_geb_paid Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_praxis_branch

audit.log_praxis_branch Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_org_unit integer

Table audit.log_praxis_branch Inherits audit_trail,

 

audit.log_praxis_branch Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_procedure

audit.log_procedure Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer
clin_where text
fk_hospital_stay integer
clin_end timestamp with time zone
is_ongoing boolean
fk_org_unit integer
fk_doc integer
comment text

Table audit.log_procedure Inherits audit_trail,

 

audit.log_procedure Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_referral

audit.log_referral Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
id integer
fk_referee integer
fk_form integer

Table audit.log_referral Inherits audit_trail,

 

audit.log_referral Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_region

audit.log_region Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
code text
country bpchar
name text

Table audit.log_region Inherits audit_trail,

 

audit.log_region Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_relation_types

audit.log_relation_types Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
inverse integer
biological boolean
biol_verified boolean
description text

Table audit.log_relation_types Inherits audit_trail,

 

audit.log_relation_types Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_report_query

audit.log_report_query Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
label text
cmd text

Table audit.log_report_query Inherits audit_trail,

 

audit.log_report_query Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_staff

audit.log_staff Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_identity integer
db_user name
short_alias text
comment text
is_active boolean

Table audit.log_staff Inherits audit_trail,

 

audit.log_staff Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_street

audit.log_street Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
id_urb integer
name text
postcode text
suburb text
lat_lon point

Table audit.log_street Inherits audit_trail,

 

audit.log_street Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_substance

audit.log_substance Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
pk integer
description text
atc text
intake_instructions text

Table audit.log_substance Inherits audit_trail,

 

audit.log_substance Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_substance_in_brand

audit.log_substance_in_brand Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_brand integer
description text
atc_code text

Table audit.log_substance_in_brand Inherits audit_trail,

 

audit.log_substance_in_brand Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_substance_intake

audit.log_substance_intake Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer
fk_substance integer
preparation text
schedule text
aim text
duration interval
intake_is_approved_of boolean
is_long_term boolean
discontinued timestamp with time zone
discontinue_reason text
fk_drug_component integer
comment_on_start text
harmful_use_type integer

Table audit.log_substance_intake Inherits audit_trail,

 

audit.log_substance_intake Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_suppressed_hint

audit.log_suppressed_hint Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_encounter integer
fk_hint integer
suppressed_by name
suppressed_when timestamp with time zone
rationale text
md5_sum text

Table audit.log_suppressed_hint Inherits audit_trail,

 

audit.log_suppressed_hint Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_tag_image

audit.log_tag_image Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
filename text
image bytea

Table audit.log_tag_image Inherits audit_trail,

 

audit.log_tag_image Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_test_org

audit.log_test_org Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_org_unit integer
fk_adm_contact integer
fk_med_contact integer
comment text
contact text

Table audit.log_test_org Inherits audit_trail,

 

audit.log_test_org Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_test_panel

audit.log_test_panel Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text
comment text
fk_test_types integer[]

Table audit.log_test_panel Inherits audit_trail,

 

audit.log_test_panel Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_test_result

audit.log_test_result Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer
fk_type integer
val_num numeric
val_alpha text
val_unit text
val_normal_min numeric
val_normal_max numeric
val_normal_range text
val_target_min numeric
val_target_max numeric
val_target_range text
abnormality_indicator text
norm_ref_group text
note_test_org text
material text
material_detail text
fk_intended_reviewer integer
fk_request integer
status text
source_data text
val_grouping text

Table audit.log_test_result Inherits audit_trail,

 

audit.log_test_result Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_test_type

audit.log_test_type Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_test_org integer
name text
comment text
reference_unit text
loinc text
abbrev text
fk_meta_test_type integer

Table audit.log_test_type Inherits audit_trail,

 

audit.log_test_type Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_urb

audit.log_urb Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
fk_region integer
postcode text
lat_lon point
name text

Table audit.log_urb Inherits audit_trail,

 

audit.log_urb Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_vacc_indication

audit.log_vacc_indication Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
description text
atcs_single_indication text[]
atcs_combi_indication text[]

Table audit.log_vacc_indication Inherits audit_trail,

 

audit.log_vacc_indication Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_vacc_route

audit.log_vacc_route Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
abbreviation text
description text

Table audit.log_vacc_route Inherits audit_trail,

 

audit.log_vacc_route Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_vaccination

audit.log_vaccination Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk_item integer
clin_when timestamp with time zone
fk_encounter integer
fk_episode integer
narrative text
soap_cat text
pk integer
fk_patient integer
fk_provider integer
fk_vaccine integer
site text
batch_no text
reaction text

Table audit.log_vaccination Inherits audit_trail,

 

audit.log_vaccination Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_vaccination_course

audit.log_vaccination_course Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_recommended_by integer
fk_indication integer
is_active boolean
comment text

Table audit.log_vaccination_course Inherits audit_trail,

 

audit.log_vaccination_course Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_vaccination_course_constraint

audit.log_vaccination_course_constraint Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
description text

Table audit.log_vaccination_course_constraint Inherits audit_trail,

 

audit.log_vaccination_course_constraint Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_vaccination_definition

audit.log_vaccination_definition Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
id integer
fk_course integer
is_booster boolean
seq_no integer
min_age_due interval
max_age_due interval
min_interval interval
comment text

Table audit.log_vaccination_definition Inherits audit_trail,

 

audit.log_vaccination_definition Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_vaccination_schedule

audit.log_vaccination_schedule Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
name text
comment text

Table audit.log_vaccination_schedule Inherits audit_trail,

 

audit.log_vaccination_schedule Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_vaccine

audit.log_vaccine Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
id_route integer
is_live boolean
min_age interval
max_age interval
comment text
fk_drug_product integer

Table audit.log_vaccine Inherits audit_trail,

 

audit.log_vaccine Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_vaccine_batches

audit.log_vaccine_batches Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_vaccine integer
batch_no text

Table audit.log_vaccine_batches Inherits audit_trail,

 

audit.log_vaccine_batches Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_waiting_list

audit.log_waiting_list Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
fk_patient integer
registered timestamp with time zone
urgency integer
list_position integer
comment text
area text

Table audit.log_waiting_list Inherits audit_trail,

 

audit.log_waiting_list Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


Table: audit.log_xlnk_identity

audit.log_xlnk_identity Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_trail_pk_audit_seq'::regclass)
orig_version integer NOT NULL

the .row_version in the original row before the audited action took place, should be equal to .row_version
orig_when timestamp with time zone NOT NULL

the .modified_when in the original row before the audited action took place, should be equal to .modified_when
orig_by name NOT NULL

the .modified_by in the original row before the audited action took place, should be equal to .modified_by
orig_tableoid oid NOT NULL

the TG_RELID when the audit trigger was run
audit_action text NOT NULL
audit_when timestamp with time zone NOT NULL DEFAULT now()
audit_by name NOT NULL DEFAULT "current_user"()
row_version integer
modified_when timestamp with time zone
modified_by name
pk integer
xfk_identity integer
pupic text
data text

Table audit.log_xlnk_identity Inherits audit_trail,

 

audit.log_xlnk_identity Constraints
Name Constraint
audit_audit_trail_orig_before_audit_when CHECK (((orig_when <= audit_when) IS TRUE))
audit_audit_trail_sane_audit_when CHECK (((audit_when <= clock_timestamp()) IS TRUE))
audit_audit_trail_sane_orig_when CHECK (((orig_when <= clock_timestamp()) IS TRUE))
audit_trail_audit_action_check CHECK ((audit_action = ANY (ARRAY['UPDATE'::text, 'DELETE'::text])))

Index - Schema audit


View: audit.v_audit_trail

audit.v_audit_trail Structure
F-Key Name Type Description
event_when text
event_by text
event_table regclass
row_version_before integer
row_version_after integer
event text
audit_when_ts timestamp with time zone
pk_audit integer
SELECT to_char
(aat.audit_when
     ,'YYYY-MM-DD HH24:MI'::text
) AS event_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = aat.audit_by)
     )
     , (
           ('<'::text || 
                 (aat.audit_by)::text
           ) || '>'::text
     )
) AS event_by
,
    
(aat.orig_tableoid)::regclass AS event_table
,
    aat.orig_version AS row_version_before
,
        CASE
            WHEN 
(aat.audit_action = 'DELETE'::text) THEN NULL::integer
            ELSE 
(aat.orig_version + 1)
        END AS row_version_after
,
    aat.audit_action AS event
,
    aat.audit_when AS audit_when_ts
,
    aat.pk_audit
   
FROM audit.audit_trail aat

UNION ALL
 
SELECT to_char
(gal.modified_when
     ,'YYYY-MM-DD HH24:MI'::text
) AS event_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = gal.modified_by)
     )
     , (
           ('<'::text || 
                 (gal.modified_by)::text
           ) || '>'::text
     )
) AS event_by
,
    'gm.access_log'::regclass AS event_table
,
    NULL::integer AS row_version_before
,
    0 AS row_version_after
,
    gal.user_action AS event
,
    gal.modified_when AS audit_when_ts
,
    gal.pk_audit
   
FROM gm.access_log gal
  
WHERE (gal.row_version = 0)
UNION ALL
 
SELECT to_char
(aaf.modified_when
     ,'YYYY-MM-DD HH24:MI'::text
) AS event_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = aaf.modified_by)
     )
     , (
           ('<'::text || 
                 (aaf.modified_by)::text
           ) || '>'::text
     )
) AS event_by
,
    
(aaf.tableoid)::regclass AS event_table
,
    NULL::integer AS row_version_before
,
    0 AS row_version_after
,
    'INSERT'::text AS event
,
    aaf.modified_when AS audit_when_ts
,
    aaf.pk_audit
   
FROM audit.audit_fields aaf
  
WHERE (aaf.row_version = 0);

Index - Schema audit


Function: audit.add_table_for_audit(name)

Returns: boolean

Language: SQL

sanity-checking convenience function for marking tables for auditing, schema is always "public"

select audit.add_table_for_audit('public', $1);

Function: audit.add_table_for_audit(name, name)

Returns: boolean

Language: PLPGSQL

sanity-checking convenience function for marking tables for auditing

DECLARE
	_relnamespace alias for $1;
	_relname ALIAS FOR $2;
	dummy RECORD;
	tmp text;
BEGIN
	-- does table exist ?
	select relname into dummy from pg_class where
		relname = _relname and
		relnamespace = (select oid from pg_namespace where nspname = _relnamespace)
	;
	if not found then
		tmp := _relnamespace || '.' || _relname;
		raise exception 'audit.add_table_for_audit: Table [%] does not exist.', tmp;
		return false;
	end if;
	-- already queued for auditing ?
	select 1 into dummy from audit.audited_tables where table_name = _relname and schema = _relnamespace;
	if found then
		return true;
	end if;
	-- add definition
	insert into audit.audited_tables (
		schema, table_name
	) values (
		_relnamespace, _relname
	);
	return true;
END;

Function: audit.ft_del_access_log()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_access_log (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, user_action
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.user_action
	);
	return OLD;
END;

Function: audit.ft_del_active_substance()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_active_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, description, atc_code
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.atc_code
	);
	return OLD;
END;

Function: audit.ft_del_address()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_address (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_street, aux_street, number, subunit, addendum, lat_lon
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_street, OLD.aux_street, OLD.number, OLD.subunit, OLD.addendum, OLD.lat_lon
	);
	return OLD;
END;

Function: audit.ft_del_allergy()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_allergy (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, substance, substance_code, generics, allergene, atc_code, fk_type, generic_specific, definite
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.substance, OLD.substance_code, OLD.generics, OLD.allergene, OLD.atc_code, OLD.fk_type, OLD.generic_specific, OLD.definite
	);
	return OLD;
END;

Function: audit.ft_del_allergy_state()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_allergy_state (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, has_allergy, comment, last_confirmed, fk_encounter
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.has_allergy, OLD.comment, OLD.last_confirmed, OLD.fk_encounter
	);
	return OLD;
END;

Function: audit.ft_del_atc_group()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_atc_group (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, code, description
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.description
	);
	return OLD;
END;

Function: audit.ft_del_atc_substance()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_atc_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, code, name, ddd_amount, fk_ddd_unit, route, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.name, OLD.ddd_amount, OLD.fk_ddd_unit, OLD.route, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_auto_hint()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_auto_hint (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, query, title, hint, url, is_active, source, lang, recommendation_query, popup_type, highlight_as_priority
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.query, OLD.title, OLD.hint, OLD.url, OLD.is_active, OLD.source, OLD.lang, OLD.recommendation_query, OLD.popup_type, OLD.highlight_as_priority
	);
	return OLD;
END;

Function: audit.ft_del_beh_fall_typ()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_beh_fall_typ (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, code, kurzform, name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.code, OLD.kurzform, OLD.name
	);
	return OLD;
END;

Function: audit.ft_del_behandlungsfall()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_behandlungsfall (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient, fk_falltyp, started, must_pay_prax_geb
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient, OLD.fk_falltyp, OLD.started, OLD.must_pay_prax_geb
	);
	return OLD;
END;

Function: audit.ft_del_bill()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_bill (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, invoice_id, close_date, apply_vat, fk_receiver_identity, fk_receiver_address, fk_doc, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.invoice_id, OLD.close_date, OLD.apply_vat, OLD.fk_receiver_identity, OLD.fk_receiver_address, OLD.fk_doc, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_bill_item()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_bill_item (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_provider, fk_encounter, date_to_bill, description, net_amount_per_unit, currency, status, fk_billable, fk_bill, unit_count, amount_multiplier
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_provider, OLD.fk_encounter, OLD.date_to_bill, OLD.description, OLD.net_amount_per_unit, OLD.currency, OLD.status, OLD.fk_billable, OLD.fk_bill, OLD.unit_count, OLD.amount_multiplier
	);
	return OLD;
END;

Function: audit.ft_del_clin_aux_note()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_clin_aux_note (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_clin_diag()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_clin_diag (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_narrative, laterality, is_chronic, is_active, is_definite, clinically_relevant
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_narrative, OLD.laterality, OLD.is_chronic, OLD.is_active, OLD.is_definite, OLD.clinically_relevant
	);
	return OLD;
END;

Function: audit.ft_del_clin_item_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_clin_item_type (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, type, code
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.type, OLD.code
	);
	return OLD;
END;

Function: audit.ft_del_clin_medication()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_clin_medication (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, last_prescribed, fk_last_script, discontinued, brandname, generic, adjuvant, dosage_form, ufk_drug, drug_db, atc_code, is_cr, dosage, period, dosage_unit, directions, is_prn
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.last_prescribed, OLD.fk_last_script, OLD.discontinued, OLD.brandname, OLD.generic, OLD.adjuvant, OLD.dosage_form, OLD.ufk_drug, OLD.drug_db, OLD.atc_code, OLD.is_cr, OLD.dosage, OLD.period, OLD.dosage_unit, OLD.directions, OLD.is_prn
	);
	return OLD;
END;

Function: audit.ft_del_clin_narrative()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_clin_narrative (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_coded_phrase()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_coded_phrase (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, term, code, xfk_coding_system
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.term, OLD.code, OLD.xfk_coding_system
	);
	return OLD;
END;

Function: audit.ft_del_consumable_substance()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_consumable_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, atc_code, amount, unit
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.atc_code, OLD.amount, OLD.unit
	);
	return OLD;
END;

Function: audit.ft_del_consumed_substance()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_consumed_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, description, atc_code
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.atc_code
	);
	return OLD;
END;

Function: audit.ft_del_data_source()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_data_source (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, name_long, name_short, version, description, source, lang
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.name_long, OLD.name_short, OLD.version, OLD.description, OLD.source, OLD.lang
	);
	return OLD;
END;

Function: audit.ft_del_doc_desc()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_doc_desc (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_doc, text
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_doc, OLD.text
	);
	return OLD;
END;

Function: audit.ft_del_doc_med()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_doc_med (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_encounter, fk_episode, fk_type, comment, clin_when, ext_ref, fk_org_unit, unit_is_receiver, fk_hospital_stay
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_encounter, OLD.fk_episode, OLD.fk_type, OLD.comment, OLD.clin_when, OLD.ext_ref, OLD.fk_org_unit, OLD.unit_is_receiver, OLD.fk_hospital_stay
	);
	return OLD;
END;

Function: audit.ft_del_dose()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_dose (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_substance, amount, unit, dose_unit
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_substance, OLD.amount, OLD.unit, OLD.dose_unit
	);
	return OLD;
END;

Function: audit.ft_del_drug_product()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_drug_product (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, preparation, atc_code, is_fake, fk_data_source, external_code, external_code_type
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.preparation, OLD.atc_code, OLD.is_fake, OLD.fk_data_source, OLD.external_code, OLD.external_code_type
	);
	return OLD;
END;

Function: audit.ft_del_encounter()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_encounter (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient, fk_type, fk_location, source_time_zone, reason_for_encounter, assessment_of_encounter, started, last_affirmed
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient, OLD.fk_type, OLD.fk_location, OLD.source_time_zone, OLD.reason_for_encounter, OLD.assessment_of_encounter, OLD.started, OLD.last_affirmed
	);
	return OLD;
END;

Function: audit.ft_del_episode()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_episode (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_health_issue, description, is_open, fk_encounter, diagnostic_certainty_classification, summary
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_health_issue, OLD.description, OLD.is_open, OLD.fk_encounter, OLD.diagnostic_certainty_classification, OLD.summary
	);
	return OLD;
END;

Function: audit.ft_del_external_care()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_external_care (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_encounter, fk_health_issue, issue, fk_org_unit, provider, comment, inactive
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_encounter, OLD.fk_health_issue, OLD.issue, OLD.fk_org_unit, OLD.provider, OLD.comment, OLD.inactive
	);
	return OLD;
END;

Function: audit.ft_del_family_history()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_family_history (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_relation_type, age_noted, age_of_death, contributed_to_death, name_relative, dob_relative, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_relation_type, OLD.age_noted, OLD.age_of_death, OLD.contributed_to_death, OLD.name_relative, OLD.dob_relative, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_fhx_relation_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_fhx_relation_type (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, is_genetic
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.is_genetic
	);
	return OLD;
END;

Function: audit.ft_del_form_data()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_form_data (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_instance, fk_form_field, value
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_instance, OLD.fk_form_field, OLD.value
	);
	return OLD;
END;

Function: audit.ft_del_form_defs()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_form_defs (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, fk_type, country, locale, soap_cat, name_short, name_long, revision, template, engine, in_use, url, is_user
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_type, OLD.country, OLD.locale, OLD.soap_cat, OLD.name_short, OLD.name_long, OLD.revision, OLD.template, OLD.engine, OLD.in_use, OLD.url, OLD.is_user
	);
	return OLD;
END;

Function: audit.ft_del_form_instances()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_form_instances (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_form_def, form_name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_form_def, OLD.form_name
	);
	return OLD;
END;

Function: audit.ft_del_gender_label()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_gender_label (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, tag, label, sort_weight, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.tag, OLD.label, OLD.sort_weight, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_health_issue()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_health_issue (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, laterality, age_noted, is_active, clinically_relevant, is_confidential, is_cause_of_death, fk_encounter, grouping, diagnostic_certainty_classification, summary
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.laterality, OLD.age_noted, OLD.is_active, OLD.clinically_relevant, OLD.is_confidential, OLD.is_cause_of_death, OLD.fk_encounter, OLD.grouping, OLD.diagnostic_certainty_classification, OLD.summary
	);
	return OLD;
END;

Function: audit.ft_del_hospital_stay()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_hospital_stay (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, discharge, fk_org_unit
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.discharge, OLD.fk_org_unit
	);
	return OLD;
END;

Function: audit.ft_del_hx_family_item()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_hx_family_item (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, fk_narrative_condition, fk_relative, name_relative, dob_relative, condition, age_noted, age_of_death, is_cause_of_death
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_narrative_condition, OLD.fk_relative, OLD.name_relative, OLD.dob_relative, OLD.condition, OLD.age_noted, OLD.age_of_death, OLD.is_cause_of_death
	);
	return OLD;
END;

Function: audit.ft_del_identity()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_identity (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, deleted, gender, dob, fk_marital_status, cob, deceased, title, tob, emergency_contact, fk_emergency_contact, comment, fk_primary_provider, dob_is_estimated
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.deleted, OLD.gender, OLD.dob, OLD.fk_marital_status, OLD.cob, OLD.deceased, OLD.title, OLD.tob, OLD.emergency_contact, OLD.fk_emergency_contact, OLD.comment, OLD.fk_primary_provider, OLD.dob_is_estimated
	);
	return OLD;
END;

Function: audit.ft_del_identity_tag()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_identity_tag (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, fk_tag, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.fk_tag, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_inbox_item_category()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_inbox_item_category (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, is_user
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.is_user
	);
	return OLD;
END;

Function: audit.ft_del_inbox_item_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_inbox_item_type (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_inbox_item_category, description, is_user
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_inbox_item_category, OLD.description, OLD.is_user
	);
	return OLD;
END;

Function: audit.ft_del_incoming_data_unmatchable()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_incoming_data_unmatchable (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated
	);
	return OLD;
END;

Function: audit.ft_del_incoming_data_unmatched()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_incoming_data_unmatched (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated, comment, fk_provider_disambiguated
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated, OLD.comment, OLD.fk_provider_disambiguated
	);
	return OLD;
END;

Function: audit.ft_del_lab_request()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lab_request (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_test_org, request_id, fk_requestor, lab_request_id, lab_rxd_when, results_reported_when, request_status, is_pending, diagnostic_service_section, ordered_service, note_test_org
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_test_org, OLD.request_id, OLD.fk_requestor, OLD.lab_request_id, OLD.lab_rxd_when, OLD.results_reported_when, OLD.request_status, OLD.is_pending, OLD.diagnostic_service_section, OLD.ordered_service, OLD.note_test_org
	);
	return OLD;
END;

Function: audit.ft_del_lab_test_gnr()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lab_test_gnr (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_test
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_test
	);
	return OLD;
END;

Function: audit.ft_del_lnk_code2aoe()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_code2aoe (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_lnk_code2episode()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_code2episode (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_lnk_code2fhx()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_code2fhx (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_lnk_code2h_issue()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_code2h_issue (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_lnk_code2narrative()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_code2narrative (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_lnk_code2procedure()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_code2procedure (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_lnk_code2rfe()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_code2rfe (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_lnk_code2tst_pnl()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_code2tst_pnl (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return OLD;
END;

Function: audit.ft_del_lnk_constraint2vacc_course()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_constraint2vacc_course (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_vaccination_course, fk_constraint
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_vaccination_course, OLD.fk_constraint
	);
	return OLD;
END;

Function: audit.ft_del_lnk_dose2drug()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_dose2drug (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_drug_product, fk_dose
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_drug_product, OLD.fk_dose
	);
	return OLD;
END;

Function: audit.ft_del_lnk_identity2ext_id()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_identity2ext_id (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_identity, external_id, fk_origin, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_identity, OLD.external_id, OLD.fk_origin, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_lnk_identity2primary_doc()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_lnk_identity2primary_doc (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, fk_primary_doc
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.fk_primary_doc
	);
	return OLD;
END;

Function: audit.ft_del_lnk_job2person()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_job2person (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, fk_occupation, activities
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.fk_occupation, OLD.activities
	);
	return OLD;
END;

Function: audit.ft_del_lnk_loinc2substance()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_loinc2substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_substance, loinc, max_age, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_substance, OLD.loinc, OLD.max_age, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_lnk_loinc2test_panel()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_loinc2test_panel (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_test_panel, loinc
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_test_panel, OLD.loinc
	);
	return OLD;
END;

Function: audit.ft_del_lnk_org_unit2comm()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_org_unit2comm (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_org_unit, url, fk_type, is_confidential, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_org_unit, OLD.url, OLD.fk_type, OLD.is_confidential, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_lnk_org_unit2ext_id()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_org_unit2ext_id (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_org_unit, external_id, fk_type, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_org_unit, OLD.external_id, OLD.fk_type, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_lnk_pat2vaccination_course()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_pat2vaccination_course (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient, fk_course
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient, OLD.fk_course
	);
	return OLD;
END;

Function: audit.ft_del_lnk_person2relative()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_person2relative (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_identity, id_relative, id_relation_type, started, ended
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_identity, OLD.id_relative, OLD.id_relation_type, OLD.started, OLD.ended
	);
	return OLD;
END;

Function: audit.ft_del_lnk_substance2brand()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_substance2brand (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_brand, fk_substance
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_brand, OLD.fk_substance
	);
	return OLD;
END;

Function: audit.ft_del_lnk_tst2norm()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_tst2norm (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_test, id_norm
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_test, OLD.id_norm
	);
	return OLD;
END;

Function: audit.ft_del_lnk_type2item()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_type2item (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_type, fk_item
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_type, OLD.fk_item
	);
	return OLD;
END;

Function: audit.ft_del_lnk_vaccination_course2schedule()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_vaccination_course2schedule (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_course, fk_schedule
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_course, OLD.fk_schedule
	);
	return OLD;
END;

Function: audit.ft_del_lnk_vaccine2inds()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_lnk_vaccine2inds (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, fk_vaccine, fk_indication
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.fk_vaccine, OLD.fk_indication
	);
	return OLD;
END;

Function: audit.ft_del_message_inbox()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_message_inbox (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_staff, fk_inbox_item_type, comment, data, importance, fk_patient, ufk_context, due_date, expiry_date
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_staff, OLD.fk_inbox_item_type, OLD.comment, OLD.data, OLD.importance, OLD.fk_patient, OLD.ufk_context, OLD.due_date, OLD.expiry_date
	);
	return OLD;
END;

Function: audit.ft_del_occupation()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_occupation (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.name
	);
	return OLD;
END;

Function: audit.ft_del_operation()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_operation (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, fk_health_issue, fk_encounter, clin_where, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_health_issue, OLD.fk_encounter, OLD.clin_where, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_org()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_org (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, fk_category, fk_data_source
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.fk_category, OLD.fk_data_source
	);
	return OLD;
END;

Function: audit.ft_del_org_unit()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_org_unit (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, fk_org, fk_address, fk_category
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.fk_org, OLD.fk_address, OLD.fk_category
	);
	return OLD;
END;

Function: audit.ft_del_paperwork_templates()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_paperwork_templates (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_template_type, instance_type, name_short, name_long, external_version, gnumed_revision, engine, in_use, filename, data, edit_after_substitution
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_template_type, OLD.instance_type, OLD.name_short, OLD.name_long, OLD.external_version, OLD.gnumed_revision, OLD.engine, OLD.in_use, OLD.filename, OLD.data, OLD.edit_after_substitution
	);
	return OLD;
END;

Function: audit.ft_del_patient()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_patient (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, edc
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.edc
	);
	return OLD;
END;

Function: audit.ft_del_prax_geb_paid()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_prax_geb_paid (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_fall, paid_amount, paid_when, paid_with
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_fall, OLD.paid_amount, OLD.paid_when, OLD.paid_with
	);
	return OLD;
END;

Function: audit.ft_del_praxis_branch()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_praxis_branch (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_org_unit
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_org_unit
	);
	return OLD;
END;

Function: audit.ft_del_procedure()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_procedure (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_hospital_stay, clin_end, is_ongoing, fk_org_unit, fk_doc, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_hospital_stay, OLD.clin_end, OLD.is_ongoing, OLD.fk_org_unit, OLD.fk_doc, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_ref_source()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_ref_source (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, name_short, name_long, version, description, source
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name_short, OLD.name_long, OLD.version, OLD.description, OLD.source
	);
	return OLD;
END;

Function: audit.ft_del_referral()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_referral (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, id, fk_referee, fk_form
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.id, OLD.fk_referee, OLD.fk_form
	);
	return OLD;
END;

Function: audit.ft_del_region()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_region (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, code, country, name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.code, OLD.country, OLD.name
	);
	return OLD;
END;

Function: audit.ft_del_relation_types()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_relation_types (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, inverse, biological, biol_verified, description
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.inverse, OLD.biological, OLD.biol_verified, OLD.description
	);
	return OLD;
END;

Function: audit.ft_del_report_query()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_report_query (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, label, cmd
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.label, OLD.cmd
	);
	return OLD;
END;

Function: audit.ft_del_staff()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_staff (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, db_user, short_alias, comment, is_active
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.db_user, OLD.short_alias, OLD.comment, OLD.is_active
	);
	return OLD;
END;

Function: audit.ft_del_staff_role()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_staff_role (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, name, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_street()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_street (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_urb, name, postcode, suburb, lat_lon
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_urb, OLD.name, OLD.postcode, OLD.suburb, OLD.lat_lon
	);
	return OLD;
END;

Function: audit.ft_del_substance()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, atc, intake_instructions
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.atc, OLD.intake_instructions
	);
	return OLD;
END;

Function: audit.ft_del_substance_in_brand()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_substance_in_brand (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, fk_brand, description, atc_code
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_brand, OLD.description, OLD.atc_code
	);
	return OLD;
END;

Function: audit.ft_del_substance_intake()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_substance_intake (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, schedule, aim, duration, intake_is_approved_of, is_long_term, discontinued, discontinue_reason, fk_drug_component, comment_on_start, harmful_use_type
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.schedule, OLD.aim, OLD.duration, OLD.intake_is_approved_of, OLD.is_long_term, OLD.discontinued, OLD.discontinue_reason, OLD.fk_drug_component, OLD.comment_on_start, OLD.harmful_use_type
	);
	return OLD;
END;

Function: audit.ft_del_suppressed_hint()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_suppressed_hint (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_encounter, fk_hint, suppressed_by, suppressed_when, rationale, md5_sum
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_encounter, OLD.fk_hint, OLD.suppressed_by, OLD.suppressed_when, OLD.rationale, OLD.md5_sum
	);
	return OLD;
END;

Function: audit.ft_del_tag_image()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_tag_image (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, filename, image
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.filename, OLD.image
	);
	return OLD;
END;

Function: audit.ft_del_test_org()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_test_org (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_org_unit, fk_adm_contact, fk_med_contact, comment, contact
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_org_unit, OLD.fk_adm_contact, OLD.fk_med_contact, OLD.comment, OLD.contact
	);
	return OLD;
END;

Function: audit.ft_del_test_panel()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_test_panel (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_test_result()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_test_result (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_type, val_num, val_alpha, val_unit, val_normal_min, val_normal_max, val_normal_range, val_target_min, val_target_max, val_target_range, abnormality_indicator, norm_ref_group, note_test_org, material, material_detail, fk_intended_reviewer, fk_request, status, source_data, val_grouping
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_type, OLD.val_num, OLD.val_alpha, OLD.val_unit, OLD.val_normal_min, OLD.val_normal_max, OLD.val_normal_range, OLD.val_target_min, OLD.val_target_max, OLD.val_target_range, OLD.abnormality_indicator, OLD.norm_ref_group, OLD.note_test_org, OLD.material, OLD.material_detail, OLD.fk_intended_reviewer, OLD.fk_request, OLD.status, OLD.source_data, OLD.val_grouping
	);
	return OLD;
END;

Function: audit.ft_del_test_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_test_type (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_test_org, name, comment, reference_unit, loinc, abbrev, fk_meta_test_type
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_test_org, OLD.name, OLD.comment, OLD.reference_unit, OLD.loinc, OLD.abbrev, OLD.fk_meta_test_type
	);
	return OLD;
END;

Function: audit.ft_del_urb()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_urb (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, fk_region, postcode, lat_lon, name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.fk_region, OLD.postcode, OLD.lat_lon, OLD.name
	);
	return OLD;
END;

Function: audit.ft_del_vacc_indication()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_vacc_indication (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, description, atcs_single_indication, atcs_combi_indication
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.description, OLD.atcs_single_indication, OLD.atcs_combi_indication
	);
	return OLD;
END;

Function: audit.ft_del_vacc_route()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_vacc_route (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, abbreviation, description
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.abbreviation, OLD.description
	);
	return OLD;
END;

Function: audit.ft_del_vaccination()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_vaccination (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_provider, fk_vaccine, site, batch_no, reaction
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_provider, OLD.fk_vaccine, OLD.site, OLD.batch_no, OLD.reaction
	);
	return OLD;
END;

Function: audit.ft_del_vaccination_course()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_vaccination_course (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_recommended_by, fk_indication, is_active, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_recommended_by, OLD.fk_indication, OLD.is_active, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_vaccination_course_constraint()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_vaccination_course_constraint (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description
	);
	return OLD;
END;

Function: audit.ft_del_vaccination_definition()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_vaccination_definition (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, fk_course, is_booster, seq_no, min_age_due, max_age_due, min_interval, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.fk_course, OLD.is_booster, OLD.seq_no, OLD.min_age_due, OLD.max_age_due, OLD.min_interval, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_vaccination_schedule()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_vaccination_schedule (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, name, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.name, OLD.comment
	);
	return OLD;
END;

Function: audit.ft_del_vaccine()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_vaccine (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, id_route, is_live, min_age, max_age, comment, fk_drug_product
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.id_route, OLD.is_live, OLD.min_age, OLD.max_age, OLD.comment, OLD.fk_drug_product
	);
	return OLD;
END;

Function: audit.ft_del_vaccine_batches()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_vaccine_batches (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_vaccine, batch_no
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_vaccine, OLD.batch_no
	);
	return OLD;
END;

Function: audit.ft_del_waiting_list()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_deleter boolean;
BEGIN
	-- is the session user allowed to delete data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_deleter;
	IF _is_allowed_deleter IS FALSE THEN
		RAISE EXCEPTION
			'DELETE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return OLD;
	END IF;
	INSERT INTO audit.log_waiting_list (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient, registered, urgency, list_position, comment, area
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient, OLD.registered, OLD.urgency, OLD.list_position, OLD.comment, OLD.area
	);
	return OLD;
END;

Function: audit.ft_del_xlnk_identity()

Returns: trigger

Language: PLPGSQL

BEGIN
	INSERT INTO audit.log_xlnk_identity (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, xfk_identity, pupic, data
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.xfk_identity, OLD.pupic, OLD.data
	);
	return OLD;
END;

Function: audit.ft_ins_access_log()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_active_substance()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_address()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_allergy()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_allergy_state()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_atc_group()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_atc_substance()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_auto_hint()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_beh_fall_typ()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_behandlungsfall()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_bill()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_bill_item()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_clin_aux_note()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_clin_diag()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_clin_item_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_clin_medication()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_clin_narrative()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_coded_phrase()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_consumable_substance()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_consumed_substance()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_data_source()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_doc_desc()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_doc_med()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_dose()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_drug_product()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_encounter()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_episode()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_external_care()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_family_history()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_fhx_relation_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_form_data()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_form_defs()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_form_instances()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_gender_label()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_health_issue()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_hospital_stay()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_hx_family_item()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_identity()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_identity_tag()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_inbox_item_category()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_inbox_item_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_incoming_data_unmatchable()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_incoming_data_unmatched()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lab_request()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lab_test_gnr()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_code2aoe()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_code2episode()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_code2fhx()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_code2h_issue()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_code2narrative()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_code2procedure()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_code2rfe()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_code2tst_pnl()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_constraint2vacc_course()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_dose2drug()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_identity2ext_id()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_identity2primary_doc()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_job2person()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_loinc2substance()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_loinc2test_panel()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_org_unit2comm()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_org_unit2ext_id()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_pat2vaccination_course()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_person2relative()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_substance2brand()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_tst2norm()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_type2item()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_vaccination_course2schedule()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_lnk_vaccine2inds()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_message_inbox()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_occupation()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_operation()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_org()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_org_unit()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_paperwork_templates()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_patient()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_prax_geb_paid()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_praxis_branch()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_procedure()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_ref_source()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_referral()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_region()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_relation_types()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_report_query()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_staff()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_staff_role()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_street()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_substance()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_substance_in_brand()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_substance_intake()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_suppressed_hint()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_tag_image()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_test_org()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_test_panel()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_test_result()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_test_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_urb()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_vacc_indication()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_vacc_route()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_vaccination()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_vaccination_course()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_vaccination_course_constraint()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_vaccination_definition()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_vaccination_schedule()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_vaccine()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_vaccine_batches()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_waiting_list()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_inserter boolean;
BEGIN
	-- is the session user allowed to insert data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_inserter;
	IF _is_allowed_inserter IS FALSE THEN
		RAISE EXCEPTION
			'INSERT: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_ins_xlnk_identity()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := 0;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	return NEW;
END;

Function: audit.ft_upd_access_log()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_access_log (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, user_action
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.user_action
	);
	return NEW;
END;

Function: audit.ft_upd_active_substance()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_active_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, description, atc_code
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.atc_code
	);
	return NEW;
END;

Function: audit.ft_upd_address()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_address (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_street, aux_street, number, subunit, addendum, lat_lon
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_street, OLD.aux_street, OLD.number, OLD.subunit, OLD.addendum, OLD.lat_lon
	);
	return NEW;
END;

Function: audit.ft_upd_allergy()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_allergy (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, substance, substance_code, generics, allergene, atc_code, fk_type, generic_specific, definite
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.substance, OLD.substance_code, OLD.generics, OLD.allergene, OLD.atc_code, OLD.fk_type, OLD.generic_specific, OLD.definite
	);
	return NEW;
END;

Function: audit.ft_upd_allergy_state()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_allergy_state (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, has_allergy, comment, last_confirmed, fk_encounter
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.has_allergy, OLD.comment, OLD.last_confirmed, OLD.fk_encounter
	);
	return NEW;
END;

Function: audit.ft_upd_atc_group()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_atc_group (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, code, description
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.description
	);
	return NEW;
END;

Function: audit.ft_upd_atc_substance()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_atc_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, code, name, ddd_amount, fk_ddd_unit, route, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.code, OLD.name, OLD.ddd_amount, OLD.fk_ddd_unit, OLD.route, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_auto_hint()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_auto_hint (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, query, title, hint, url, is_active, source, lang, recommendation_query, popup_type, highlight_as_priority
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.query, OLD.title, OLD.hint, OLD.url, OLD.is_active, OLD.source, OLD.lang, OLD.recommendation_query, OLD.popup_type, OLD.highlight_as_priority
	);
	return NEW;
END;

Function: audit.ft_upd_beh_fall_typ()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_beh_fall_typ (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, code, kurzform, name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.code, OLD.kurzform, OLD.name
	);
	return NEW;
END;

Function: audit.ft_upd_behandlungsfall()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_behandlungsfall (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient, fk_falltyp, started, must_pay_prax_geb
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient, OLD.fk_falltyp, OLD.started, OLD.must_pay_prax_geb
	);
	return NEW;
END;

Function: audit.ft_upd_bill()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_bill (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, invoice_id, close_date, apply_vat, fk_receiver_identity, fk_receiver_address, fk_doc, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.invoice_id, OLD.close_date, OLD.apply_vat, OLD.fk_receiver_identity, OLD.fk_receiver_address, OLD.fk_doc, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_bill_item()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_bill_item (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_provider, fk_encounter, date_to_bill, description, net_amount_per_unit, currency, status, fk_billable, fk_bill, unit_count, amount_multiplier
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_provider, OLD.fk_encounter, OLD.date_to_bill, OLD.description, OLD.net_amount_per_unit, OLD.currency, OLD.status, OLD.fk_billable, OLD.fk_bill, OLD.unit_count, OLD.amount_multiplier
	);
	return NEW;
END;

Function: audit.ft_upd_clin_aux_note()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_clin_aux_note (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_clin_diag()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_clin_diag (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_narrative, laterality, is_chronic, is_active, is_definite, clinically_relevant
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_narrative, OLD.laterality, OLD.is_chronic, OLD.is_active, OLD.is_definite, OLD.clinically_relevant
	);
	return NEW;
END;

Function: audit.ft_upd_clin_item_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_clin_item_type (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, type, code
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.type, OLD.code
	);
	return NEW;
END;

Function: audit.ft_upd_clin_medication()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_clin_medication (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, last_prescribed, fk_last_script, discontinued, brandname, generic, adjuvant, dosage_form, ufk_drug, drug_db, atc_code, is_cr, dosage, period, dosage_unit, directions, is_prn
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.last_prescribed, OLD.fk_last_script, OLD.discontinued, OLD.brandname, OLD.generic, OLD.adjuvant, OLD.dosage_form, OLD.ufk_drug, OLD.drug_db, OLD.atc_code, OLD.is_cr, OLD.dosage, OLD.period, OLD.dosage_unit, OLD.directions, OLD.is_prn
	);
	return NEW;
END;

Function: audit.ft_upd_clin_narrative()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_clin_narrative (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_coded_phrase()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_coded_phrase (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, term, code, xfk_coding_system
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.term, OLD.code, OLD.xfk_coding_system
	);
	return NEW;
END;

Function: audit.ft_upd_consumable_substance()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_consumable_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, atc_code, amount, unit
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.atc_code, OLD.amount, OLD.unit
	);
	return NEW;
END;

Function: audit.ft_upd_consumed_substance()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_consumed_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, description, atc_code
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.description, OLD.atc_code
	);
	return NEW;
END;

Function: audit.ft_upd_data_source()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_data_source (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, name_long, name_short, version, description, source, lang
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.name_long, OLD.name_short, OLD.version, OLD.description, OLD.source, OLD.lang
	);
	return NEW;
END;

Function: audit.ft_upd_doc_desc()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_doc_desc (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_doc, text
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_doc, OLD.text
	);
	return NEW;
END;

Function: audit.ft_upd_doc_med()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_doc_med (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_encounter, fk_episode, fk_type, comment, clin_when, ext_ref, fk_org_unit, unit_is_receiver, fk_hospital_stay
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_encounter, OLD.fk_episode, OLD.fk_type, OLD.comment, OLD.clin_when, OLD.ext_ref, OLD.fk_org_unit, OLD.unit_is_receiver, OLD.fk_hospital_stay
	);
	return NEW;
END;

Function: audit.ft_upd_dose()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_dose (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_substance, amount, unit, dose_unit
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_substance, OLD.amount, OLD.unit, OLD.dose_unit
	);
	return NEW;
END;

Function: audit.ft_upd_drug_product()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_drug_product (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, preparation, atc_code, is_fake, fk_data_source, external_code, external_code_type
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.preparation, OLD.atc_code, OLD.is_fake, OLD.fk_data_source, OLD.external_code, OLD.external_code_type
	);
	return NEW;
END;

Function: audit.ft_upd_encounter()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_encounter (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient, fk_type, fk_location, source_time_zone, reason_for_encounter, assessment_of_encounter, started, last_affirmed
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient, OLD.fk_type, OLD.fk_location, OLD.source_time_zone, OLD.reason_for_encounter, OLD.assessment_of_encounter, OLD.started, OLD.last_affirmed
	);
	return NEW;
END;

Function: audit.ft_upd_episode()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_episode (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_health_issue, description, is_open, fk_encounter, diagnostic_certainty_classification, summary
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_health_issue, OLD.description, OLD.is_open, OLD.fk_encounter, OLD.diagnostic_certainty_classification, OLD.summary
	);
	return NEW;
END;

Function: audit.ft_upd_external_care()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_external_care (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_encounter, fk_health_issue, issue, fk_org_unit, provider, comment, inactive
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_encounter, OLD.fk_health_issue, OLD.issue, OLD.fk_org_unit, OLD.provider, OLD.comment, OLD.inactive
	);
	return NEW;
END;

Function: audit.ft_upd_family_history()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_family_history (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_relation_type, age_noted, age_of_death, contributed_to_death, name_relative, dob_relative, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_relation_type, OLD.age_noted, OLD.age_of_death, OLD.contributed_to_death, OLD.name_relative, OLD.dob_relative, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_fhx_relation_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_fhx_relation_type (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, is_genetic
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.is_genetic
	);
	return NEW;
END;

Function: audit.ft_upd_form_data()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_form_data (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_instance, fk_form_field, value
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_instance, OLD.fk_form_field, OLD.value
	);
	return NEW;
END;

Function: audit.ft_upd_form_defs()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_form_defs (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, fk_type, country, locale, soap_cat, name_short, name_long, revision, template, engine, in_use, url, is_user
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_type, OLD.country, OLD.locale, OLD.soap_cat, OLD.name_short, OLD.name_long, OLD.revision, OLD.template, OLD.engine, OLD.in_use, OLD.url, OLD.is_user
	);
	return NEW;
END;

Function: audit.ft_upd_form_instances()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_form_instances (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_form_def, form_name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_form_def, OLD.form_name
	);
	return NEW;
END;

Function: audit.ft_upd_gender_label()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_gender_label (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, tag, label, sort_weight, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.tag, OLD.label, OLD.sort_weight, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_health_issue()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_health_issue (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, laterality, age_noted, is_active, clinically_relevant, is_confidential, is_cause_of_death, fk_encounter, grouping, diagnostic_certainty_classification, summary
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.laterality, OLD.age_noted, OLD.is_active, OLD.clinically_relevant, OLD.is_confidential, OLD.is_cause_of_death, OLD.fk_encounter, OLD.grouping, OLD.diagnostic_certainty_classification, OLD.summary
	);
	return NEW;
END;

Function: audit.ft_upd_hospital_stay()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_hospital_stay (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, discharge, fk_org_unit
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.discharge, OLD.fk_org_unit
	);
	return NEW;
END;

Function: audit.ft_upd_hx_family_item()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_hx_family_item (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, fk_narrative_condition, fk_relative, name_relative, dob_relative, condition, age_noted, age_of_death, is_cause_of_death
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_narrative_condition, OLD.fk_relative, OLD.name_relative, OLD.dob_relative, OLD.condition, OLD.age_noted, OLD.age_of_death, OLD.is_cause_of_death
	);
	return NEW;
END;

Function: audit.ft_upd_identity()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_identity (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, deleted, gender, dob, fk_marital_status, cob, deceased, title, tob, emergency_contact, fk_emergency_contact, comment, fk_primary_provider, dob_is_estimated
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.deleted, OLD.gender, OLD.dob, OLD.fk_marital_status, OLD.cob, OLD.deceased, OLD.title, OLD.tob, OLD.emergency_contact, OLD.fk_emergency_contact, OLD.comment, OLD.fk_primary_provider, OLD.dob_is_estimated
	);
	return NEW;
END;

Function: audit.ft_upd_identity_tag()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_identity_tag (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, fk_tag, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.fk_tag, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_inbox_item_category()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_inbox_item_category (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, is_user
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.is_user
	);
	return NEW;
END;

Function: audit.ft_upd_inbox_item_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_inbox_item_type (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_inbox_item_category, description, is_user
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_inbox_item_category, OLD.description, OLD.is_user
	);
	return NEW;
END;

Function: audit.ft_upd_incoming_data_unmatchable()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_incoming_data_unmatchable (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated
	);
	return NEW;
END;

Function: audit.ft_upd_incoming_data_unmatched()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_incoming_data_unmatched (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient_candidates, request_id, firstnames, lastnames, dob, postcode, other_info, type, data, gender, requestor, external_data_id, fk_identity_disambiguated, comment, fk_provider_disambiguated
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient_candidates, OLD.request_id, OLD.firstnames, OLD.lastnames, OLD.dob, OLD.postcode, OLD.other_info, OLD.type, OLD.data, OLD.gender, OLD.requestor, OLD.external_data_id, OLD.fk_identity_disambiguated, OLD.comment, OLD.fk_provider_disambiguated
	);
	return NEW;
END;

Function: audit.ft_upd_lab_request()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lab_request (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_test_org, request_id, fk_requestor, lab_request_id, lab_rxd_when, results_reported_when, request_status, is_pending, diagnostic_service_section, ordered_service, note_test_org
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_test_org, OLD.request_id, OLD.fk_requestor, OLD.lab_request_id, OLD.lab_rxd_when, OLD.results_reported_when, OLD.request_status, OLD.is_pending, OLD.diagnostic_service_section, OLD.ordered_service, OLD.note_test_org
	);
	return NEW;
END;

Function: audit.ft_upd_lab_test_gnr()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lab_test_gnr (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_test
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_test
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_code2aoe()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_code2aoe (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_code2episode()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_code2episode (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_code2fhx()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_code2fhx (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_code2h_issue()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_code2h_issue (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_code2narrative()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_code2narrative (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_code2procedure()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_code2procedure (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_code2rfe()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_code2rfe (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_code2tst_pnl()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_code2tst_pnl (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_lnk_code2item, fk_generic_code, fk_item, code_modifier, pk
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_lnk_code2item, OLD.fk_generic_code, OLD.fk_item, OLD.code_modifier, OLD.pk
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_constraint2vacc_course()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_constraint2vacc_course (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_vaccination_course, fk_constraint
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_vaccination_course, OLD.fk_constraint
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_dose2drug()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_dose2drug (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_drug_product, fk_dose
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_drug_product, OLD.fk_dose
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_identity2ext_id()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_identity2ext_id (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_identity, external_id, fk_origin, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_identity, OLD.external_id, OLD.fk_origin, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_identity2primary_doc()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_identity2primary_doc (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, fk_primary_doc
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.fk_primary_doc
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_job2person()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_job2person (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, fk_occupation, activities
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.fk_occupation, OLD.activities
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_loinc2substance()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_loinc2substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_substance, loinc, max_age, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_substance, OLD.loinc, OLD.max_age, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_loinc2test_panel()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_loinc2test_panel (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_test_panel, loinc
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_test_panel, OLD.loinc
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_org_unit2comm()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_org_unit2comm (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_org_unit, url, fk_type, is_confidential, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_org_unit, OLD.url, OLD.fk_type, OLD.is_confidential, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_org_unit2ext_id()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_org_unit2ext_id (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_org_unit, external_id, fk_type, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_org_unit, OLD.external_id, OLD.fk_type, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_pat2vaccination_course()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_pat2vaccination_course (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient, fk_course
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient, OLD.fk_course
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_person2relative()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_person2relative (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_identity, id_relative, id_relation_type, started, ended
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_identity, OLD.id_relative, OLD.id_relation_type, OLD.started, OLD.ended
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_substance2brand()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_substance2brand (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_brand, fk_substance
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_brand, OLD.fk_substance
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_tst2norm()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_tst2norm (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_test, id_norm
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_test, OLD.id_norm
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_type2item()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_type2item (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_type, fk_item
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_type, OLD.fk_item
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_vaccination_course2schedule()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_vaccination_course2schedule (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_course, fk_schedule
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_course, OLD.fk_schedule
	);
	return NEW;
END;

Function: audit.ft_upd_lnk_vaccine2inds()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_lnk_vaccine2inds (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, fk_vaccine, fk_indication
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.fk_vaccine, OLD.fk_indication
	);
	return NEW;
END;

Function: audit.ft_upd_message_inbox()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_message_inbox (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_staff, fk_inbox_item_type, comment, data, importance, fk_patient, ufk_context, due_date, expiry_date
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_staff, OLD.fk_inbox_item_type, OLD.comment, OLD.data, OLD.importance, OLD.fk_patient, OLD.ufk_context, OLD.due_date, OLD.expiry_date
	);
	return NEW;
END;

Function: audit.ft_upd_occupation()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_occupation (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.name
	);
	return NEW;
END;

Function: audit.ft_upd_operation()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_operation (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, fk_health_issue, fk_encounter, clin_where, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_health_issue, OLD.fk_encounter, OLD.clin_where, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_org()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_org (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, fk_category, fk_data_source
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.fk_category, OLD.fk_data_source
	);
	return NEW;
END;

Function: audit.ft_upd_org_unit()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_org_unit (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, fk_org, fk_address, fk_category
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.fk_org, OLD.fk_address, OLD.fk_category
	);
	return NEW;
END;

Function: audit.ft_upd_paperwork_templates()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_paperwork_templates (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_template_type, instance_type, name_short, name_long, external_version, gnumed_revision, engine, in_use, filename, data, edit_after_substitution
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_template_type, OLD.instance_type, OLD.name_short, OLD.name_long, OLD.external_version, OLD.gnumed_revision, OLD.engine, OLD.in_use, OLD.filename, OLD.data, OLD.edit_after_substitution
	);
	return NEW;
END;

Function: audit.ft_upd_patient()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_patient (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, edc
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.edc
	);
	return NEW;
END;

Function: audit.ft_upd_prax_geb_paid()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_prax_geb_paid (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_fall, paid_amount, paid_when, paid_with
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_fall, OLD.paid_amount, OLD.paid_when, OLD.paid_with
	);
	return NEW;
END;

Function: audit.ft_upd_praxis_branch()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_praxis_branch (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_org_unit
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_org_unit
	);
	return NEW;
END;

Function: audit.ft_upd_procedure()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_procedure (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_hospital_stay, clin_end, is_ongoing, fk_org_unit, fk_doc, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_hospital_stay, OLD.clin_end, OLD.is_ongoing, OLD.fk_org_unit, OLD.fk_doc, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_ref_source()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_ref_source (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, name_short, name_long, version, description, source
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name_short, OLD.name_long, OLD.version, OLD.description, OLD.source
	);
	return NEW;
END;

Function: audit.ft_upd_referral()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_referral (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, id, fk_referee, fk_form
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.id, OLD.fk_referee, OLD.fk_form
	);
	return NEW;
END;

Function: audit.ft_upd_region()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_region (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, code, country, name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.code, OLD.country, OLD.name
	);
	return NEW;
END;

Function: audit.ft_upd_relation_types()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_relation_types (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, inverse, biological, biol_verified, description
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.inverse, OLD.biological, OLD.biol_verified, OLD.description
	);
	return NEW;
END;

Function: audit.ft_upd_report_query()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_report_query (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, label, cmd
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.label, OLD.cmd
	);
	return NEW;
END;

Function: audit.ft_upd_staff()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_staff (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_identity, db_user, short_alias, comment, is_active
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_identity, OLD.db_user, OLD.short_alias, OLD.comment, OLD.is_active
	);
	return NEW;
END;

Function: audit.ft_upd_staff_role()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_staff_role (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, name, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_street()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_street (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, id_urb, name, postcode, suburb, lat_lon
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.id_urb, OLD.name, OLD.postcode, OLD.suburb, OLD.lat_lon
	);
	return NEW;
END;

Function: audit.ft_upd_substance()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_substance (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, atc, intake_instructions
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.atc, OLD.intake_instructions
	);
	return NEW;
END;

Function: audit.ft_upd_substance_in_brand()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_substance_in_brand (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, fk_brand, description, atc_code
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_brand, OLD.description, OLD.atc_code
	);
	return NEW;
END;

Function: audit.ft_upd_substance_intake()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_substance_intake (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, schedule, aim, duration, intake_is_approved_of, is_long_term, discontinued, discontinue_reason, fk_drug_component, comment_on_start, harmful_use_type
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.schedule, OLD.aim, OLD.duration, OLD.intake_is_approved_of, OLD.is_long_term, OLD.discontinued, OLD.discontinue_reason, OLD.fk_drug_component, OLD.comment_on_start, OLD.harmful_use_type
	);
	return NEW;
END;

Function: audit.ft_upd_suppressed_hint()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_suppressed_hint (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_encounter, fk_hint, suppressed_by, suppressed_when, rationale, md5_sum
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_encounter, OLD.fk_hint, OLD.suppressed_by, OLD.suppressed_when, OLD.rationale, OLD.md5_sum
	);
	return NEW;
END;

Function: audit.ft_upd_tag_image()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_tag_image (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, filename, image
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.filename, OLD.image
	);
	return NEW;
END;

Function: audit.ft_upd_test_org()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_test_org (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_org_unit, fk_adm_contact, fk_med_contact, comment, contact
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_org_unit, OLD.fk_adm_contact, OLD.fk_med_contact, OLD.comment, OLD.contact
	);
	return NEW;
END;

Function: audit.ft_upd_test_panel()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_test_panel (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_test_result()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_test_result (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_type, val_num, val_alpha, val_unit, val_normal_min, val_normal_max, val_normal_range, val_target_min, val_target_max, val_target_range, abnormality_indicator, norm_ref_group, note_test_org, material, material_detail, fk_intended_reviewer, fk_request, status, source_data, val_grouping
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_type, OLD.val_num, OLD.val_alpha, OLD.val_unit, OLD.val_normal_min, OLD.val_normal_max, OLD.val_normal_range, OLD.val_target_min, OLD.val_target_max, OLD.val_target_range, OLD.abnormality_indicator, OLD.norm_ref_group, OLD.note_test_org, OLD.material, OLD.material_detail, OLD.fk_intended_reviewer, OLD.fk_request, OLD.status, OLD.source_data, OLD.val_grouping
	);
	return NEW;
END;

Function: audit.ft_upd_test_type()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_test_type (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_test_org, name, comment, reference_unit, loinc, abbrev, fk_meta_test_type
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_test_org, OLD.name, OLD.comment, OLD.reference_unit, OLD.loinc, OLD.abbrev, OLD.fk_meta_test_type
	);
	return NEW;
END;

Function: audit.ft_upd_urb()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_urb (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, fk_region, postcode, lat_lon, name
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.fk_region, OLD.postcode, OLD.lat_lon, OLD.name
	);
	return NEW;
END;

Function: audit.ft_upd_vacc_indication()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_vacc_indication (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, description, atcs_single_indication, atcs_combi_indication
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.description, OLD.atcs_single_indication, OLD.atcs_combi_indication
	);
	return NEW;
END;

Function: audit.ft_upd_vacc_route()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_vacc_route (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, abbreviation, description
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.abbreviation, OLD.description
	);
	return NEW;
END;

Function: audit.ft_upd_vaccination()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_vaccination (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_provider, fk_vaccine, site, batch_no, reaction
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_item, OLD.clin_when, OLD.fk_encounter, OLD.fk_episode, OLD.narrative, OLD.soap_cat, OLD.pk, OLD.fk_provider, OLD.fk_vaccine, OLD.site, OLD.batch_no, OLD.reaction
	);
	return NEW;
END;

Function: audit.ft_upd_vaccination_course()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_vaccination_course (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_recommended_by, fk_indication, is_active, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_recommended_by, OLD.fk_indication, OLD.is_active, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_vaccination_course_constraint()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_vaccination_course_constraint (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, description
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.description
	);
	return NEW;
END;

Function: audit.ft_upd_vaccination_definition()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_vaccination_definition (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		id, fk_course, is_booster, seq_no, min_age_due, max_age_due, min_interval, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.id, OLD.fk_course, OLD.is_booster, OLD.seq_no, OLD.min_age_due, OLD.max_age_due, OLD.min_interval, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_vaccination_schedule()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_vaccination_schedule (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, name, comment
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.name, OLD.comment
	);
	return NEW;
END;

Function: audit.ft_upd_vaccine()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_vaccine (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, id_route, is_live, min_age, max_age, comment, fk_drug_product
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.id_route, OLD.is_live, OLD.min_age, OLD.max_age, OLD.comment, OLD.fk_drug_product
	);
	return NEW;
END;

Function: audit.ft_upd_vaccine_batches()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_vaccine_batches (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_vaccine, batch_no
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_vaccine, OLD.batch_no
	);
	return NEW;
END;

Function: audit.ft_upd_waiting_list()

Returns: trigger

Language: PLPGSQL

DECLARE
	_is_allowed_updater boolean;
BEGIN
	-- is the session user allowed to update data ?
	SELECT gm.account_is_dbowner_or_staff(SESSION_USER) INTO STRICT _is_allowed_updater;
	IF _is_allowed_updater IS FALSE THEN
		RAISE EXCEPTION
			'UPDATE: gm.account_is_dbowner_or_staff(NAME): <%> is neither database owner, nor <postgres>, nor on staff', SESSION_USER
			USING ERRCODE = 'integrity_constraint_violation'
		;
		return NEW;
	END IF;
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_waiting_list (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk, fk_patient, registered, urgency, list_position, comment, area
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk, OLD.fk_patient, OLD.registered, OLD.urgency, OLD.list_position, OLD.comment, OLD.area
	);
	return NEW;
END;

Function: audit.ft_upd_xlnk_identity()

Returns: trigger

Language: PLPGSQL

BEGIN
	NEW.row_version := OLD.row_version + 1;
	NEW.modified_when := CURRENT_TIMESTAMP;
	NEW.modified_by := SESSION_USER;
	INSERT INTO audit.log_xlnk_identity (
		orig_version, orig_when, orig_by, orig_tableoid, audit_action,
		pk_audit, row_version, modified_when, modified_by, pk, xfk_identity, pupic, data
	) VALUES (
		OLD.row_version, OLD.modified_when, OLD.modified_by, TG_RELID, TG_OP,
		OLD.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.xfk_identity, OLD.pupic, OLD.data
	);
	return NEW;
END;

Function: audit.register_table_for_auditing(name, name)

Returns: boolean

Language: PLPGSQL

sanity-checking convenience function for registering a table for auditing

DECLARE
	_schema alias for $1;
	_table alias for $2;
BEGIN
	-- does table exist ?
	perform 1 from pg_class where
		relname = _table
			and
		relnamespace = (select oid from pg_namespace where nspname = _schema)
	;
	if not found then
		raise exception 'audit.register_table_for_auditing(): table [%.%] does not exist', _schema, _table;
		return false;
	end if;
	-- already queued for auditing ?
	perform 1 from audit.audited_tables where
		table_name = _table
			and
		schema = _schema;
	if found then
		return true;
	end if;
	-- add definition
	insert into audit.audited_tables (
		schema, table_name
	) values (
		_schema, _table
	);
	return true;
END;

Schema bill

Holds everything related to billing.


Table: bill.bill

actual bills

bill.bill Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
row_version integer NOT NULL
modified_when timestamp with time zone NOT NULL DEFAULT now()
modified_by name NOT NULL DEFAULT "current_user"()
pk serial PRIMARY KEY
invoice_id text UNIQUE

the ID of the bill
close_date timestamp with time zone

cannot add further bill_items after this date if not NULL
apply_vat boolean

whether or not to apply VAT on the invoice
dem.identity.pk fk_receiver_identity integer

link to the receiver as a GNUmed identity, if known
dem.lnk_person_org_address.id fk_receiver_address integer

links the address of the receiver of the invoice
blobs.doc_med.pk fk_doc integer

links to the document which contains the invoice PDF
comment text

arbitrary comments on bills

Table bill.bill Inherits audit_fields,

 

bill.bill Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
bill_bill_sane_apply_vat CHECK (((apply_vat IS NOT NULL) OR ((apply_vat IS NULL) AND (fk_doc IS NULL))))
bill_bill_sane_comment CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))
bill_bill_sane_invoice_id CHECK ((gm.is_null_or_blank_string(invoice_id) IS FALSE))
bill_bill_sane_recv_adr CHECK (((fk_receiver_address IS NOT NULL) OR (close_date IS NULL)))

Tables referencing this one via Foreign Key Constraints:

Index - Schema bill


Table: bill.bill_item

items patients currently *are* billed for

bill.bill_item Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
row_version integer NOT NULL
modified_when timestamp with time zone NOT NULL DEFAULT now()
modified_by name NOT NULL DEFAULT "current_user"()
pk serial PRIMARY KEY
dem.staff.pk fk_provider integer NOT NULL

by whom or on whose behalf did the billable activity happen
clin.encounter.pk fk_encounter integer NOT NULL

the encounter during which the billable action for this item took place
date_to_bill date

The date the bill item was caused. If NULL, use .fk_encounter -> .started
description text

Can be used to further explain the bill item over and above .fk_billable.description.
net_amount_per_unit numeric NOT NULL

How much to charge for one unit of this bill item.
currency text NOT NULL

Which currency to charge in. Must not be NULL if .net_amount_per_unit is not NULL.
status text DEFAULT 'new'::text

the status of this item
ref.billable.pk fk_billable integer NOT NULL

Links to the billable item this bill item stands for.
bill.bill.pk fk_bill integer

Links to the bill this bill item is on if any.
unit_count integer NOT NULL DEFAULT 1

The number of times this item is to be billed. 0 can be used for informative items.
amount_multiplier numeric NOT NULL DEFAULT 1

A multiplier to apply to .net_amount_per_unit. Can be used for discounts, rebates, or increases. Must be > 0.

Table bill.bill_item Inherits audit_fields,

 

bill.bill_item Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
bill_bill_item_sane_count CHECK ((unit_count > '-1'::integer))
bill_bill_item_sane_currency CHECK ((gm.is_null_or_blank_string(currency) IS FALSE))
bill_bill_item_sane_desc CHECK ((gm.is_null_or_non_empty_string(description) IS TRUE))
bill_bill_item_sane_multiplier CHECK ((amount_multiplier > (0)::numeric))
valid_stati CHECK ((status = ANY (ARRAY['new'::text, 'transferred'::text])))

Index - Schema bill


Table: bill.lnk_enc_type2billable

actual bills

bill.lnk_enc_type2billable Structure
F-Key Name Type Description
pk serial PRIMARY KEY
clin.encounter_type.pk fk_encounter_type integer NOT NULL

Links to encounter type this billable is associated with.
ref.billable.pk fk_billable integer NOT NULL

Links to the billable item the encounter type is associated with.

Index - Schema bill


View: bill.v_bill_items

bill.v_bill_items Structure
F-Key Name Type Description
pk_bill_item integer
billable_code text
billable_description text
item_detail text
date_to_bill timestamp with time zone
net_amount_per_unit numeric
unit_count integer
amount_multiplier numeric
total_amount numeric
vat numeric
currency text
raw_date_to_bill date
billable_amount numeric
vat_multiplier numeric
billable_currency text
billable_comment text
billable_active boolean
billable_discountable boolean
catalog_long text
catalog_short text
catalog_version text
catalog_language text
pk_patient integer
pk_encounter_type integer
pk_provider integer
pk_encounter_to_bill integer
pk_bill integer
pk_billable integer
pk_data_source integer
xmin_bill_item xid
SELECT b_bi.pk AS pk_bill_item
,
    r_b.code AS billable_code
,
    r_b.term AS billable_description
,
    b_bi.description AS item_detail
,
    COALESCE
(
     (b_bi.date_to_bill)::timestamp with time zone
     , c_enc.started
) AS date_to_bill
,
    b_bi.net_amount_per_unit
,
    b_bi.unit_count
,
    b_bi.amount_multiplier
,
    
(
     (
           (b_bi.unit_count)::numeric * b_bi.net_amount_per_unit
     ) * b_bi.amount_multiplier
) AS total_amount
,
    
(
     (
           (
                 (b_bi.unit_count)::numeric * b_bi.net_amount_per_unit
           ) * b_bi.amount_multiplier
     ) * r_b.vat_multiplier
) AS vat
,
    b_bi.currency
,
    b_bi.date_to_bill AS raw_date_to_bill
,
    r_b.amount AS billable_amount
,
    r_b.vat_multiplier
,
    r_b.currency AS billable_currency
,
    r_b.comment AS billable_comment
,
    r_b.active AS billable_active
,
    r_b.discountable AS billable_discountable
,
    r_ds.name_long AS catalog_long
,
    r_ds.name_short AS catalog_short
,
    r_ds.version AS catalog_version
,
    r_ds.lang AS catalog_language
,
    c_enc.fk_patient AS pk_patient
,
    c_enc.fk_type AS pk_encounter_type
,
    b_bi.fk_provider AS pk_provider
,
    b_bi.fk_encounter AS pk_encounter_to_bill
,
    b_bi.fk_bill AS pk_bill
,
    r_b.pk AS pk_billable
,
    r_b.fk_data_source AS pk_data_source
,
    b_bi.xmin AS xmin_bill_item
   
FROM (
     (
           (bill.bill_item b_bi
     
              JOIN ref.billable r_b 
                ON (
                       (b_bi.fk_billable = r_b.pk)
                 )
           )
     
   LEFT JOIN ref.data_source r_ds 
          ON (
                 (r_b.fk_data_source = r_ds.pk)
           )
     )
     
LEFT JOIN clin.encounter c_enc 
    ON (
           (b_bi.fk_encounter = c_enc.pk)
     )
);

Index - Schema bill


View: bill.v_bills

bill.v_bills Structure
F-Key Name Type Description
pk_bill integer
invoice_id text
pk_receiver_identity integer
total_amount numeric
total_vat numeric
total_amount_with_vat numeric
percent_vat numeric
currency text
close_date timestamp with time zone
apply_vat boolean
comment text
pk_receiver_address integer
pk_doc integer
pk_patient integer
pk_bill_items integer[]
xmin_bill xid
SELECT b_b.pk AS pk_bill
,
    b_b.invoice_id
,
    b_b.fk_receiver_identity AS pk_receiver_identity
,
    
(
SELECT round
     (sum
           (v_bill_items.total_amount)
           , 2
     ) AS round
           
  FROM bill.v_bill_items
          
 WHERE (v_bill_items.pk_bill = b_b.pk)
) AS total_amount
,
    
(
SELECT round
     (sum
           (v_bill_items.vat)
           , 2
     ) AS round
           
  FROM bill.v_bill_items
          
 WHERE (v_bill_items.pk_bill = b_b.pk)
) AS total_vat
,
    
(
SELECT round
     (sum
           (
                 (v_bill_items.total_amount + v_bill_items.vat)
           )
           , 2
     ) AS round
           
  FROM bill.v_bill_items
          
 WHERE (v_bill_items.pk_bill = b_b.pk)
) AS total_amount_with_vat
,
    
(
SELECT (v_bill_items.vat_multiplier * 
           (100)::numeric
     )
           
  FROM bill.v_bill_items
          
 WHERE (v_bill_items.pk_bill = b_b.pk)
         LIMIT 1
) AS percent_vat
,
    
(
SELECT v_bill_items.currency
           
  FROM bill.v_bill_items
          
 WHERE (v_bill_items.pk_bill = b_b.pk)
         LIMIT 1
) AS currency
,
    b_b.close_date
,
    b_b.apply_vat
,
    b_b.comment
,
    b_b.fk_receiver_address AS pk_receiver_address
,
    b_b.fk_doc AS pk_doc
,
    
(
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = 
           (
            SELECT bill_item.fk_encounter
                   
              FROM bill.bill_item
                  
             WHERE (bill_item.fk_bill = b_b.pk)
                 LIMIT 1
           )
     )
) AS pk_patient
,
    
(
SELECT array_agg
     (sorted_values.pk_bill_item) AS array_agg
           
  FROM (
      SELECT b_vbi.pk_bill_item
                   
        FROM bill.v_bill_items b_vbi
                  
       WHERE (b_vbi.pk_bill = b_b.pk)
                  
    ORDER BY b_vbi.date_to_bill
           , b_vbi.billable_code
     ) sorted_values
) AS pk_bill_items
,
    b_b.xmin AS xmin_bill
   
FROM bill.bill b_b;

Index - Schema bill


Function: bill.get_bill_receiver_identity(integer)

Returns: integer

Language: SQL

select
	value
from (
	select
		id.pk_id,
		id.value::integer
	from
		dem.v_external_ids4identity id
			join dem.identity d_i on (id.value = d_i.pk::text)
	where
		id.pk_type = (select pk from dem.enum_ext_id_types where name = 'bill receiver' and issuer = 'GNUmed')
			and
		id.pk_identity = $1
	union all
	select
		0,
		$1
) me
limit 1;

Function: bill.trf_prevent_empty_bills()

Returns: trigger

Language: PLPGSQL

Prevent bills to become void of items due to deletions/updates of bill items.

DECLARE
	_item_count integer;
	_msg text;
BEGIN
	if TG_OP = 'UPDATE' then
		if OLD.fk_bill IS NULL then
			return NULL;
		end if;
		if OLD.fk_bill IS NOT DISTINCT FROM NEW.fk_bill then
			return NULL;
		end if;
	else
		if OLD.fk_bill is NULL then
			return NULL;
		end if;
	end if;
	-- we now either:
	--	DELETE with .fk_bill NOT NULL
	-- or:
	--	UPDATE with an .fk_bill change (including towards fk_bill = NULL)
	-- let us check whether the (previous) bill still exists
	-- at all or whether we are deleting the bill (and thereby
	-- setting our .fk_bill to NULL)
	-- only works at or below REPEATABLE READ after deletion of bill
	perform 1 from bill.bill where pk = OLD.fk_bill;
	if FOUND is FALSE then
		return NULL;
	end if;
	select count(1) into _item_count
	from bill.bill_item
	where
		fk_bill = OLD.fk_bill
			and
		pk != OLD.pk;
	if _item_count > 0 then
		return NULL;
	end if;
	_msg := '[bill.trf_prevent_empty_bills]: cannot remove (by '
			|| '<' || TG_OP || '>'
			||') the only item (bill.bill_item.pk='
			|| coalesce(OLD.pk::text, '<NULL>'::text)
			|| ') from bill (bill.bill_item.fk_bill=bill.bill.pk='
			|| coalesce(OLD.fk_bill::text, '<NULL>'::text)
			|| ') ';
	raise exception unique_violation using message = _msg;
	return NULL;
END;

Function: bill.trf_prevent_mislinked_bills()

Returns: trigger

Language: PLPGSQL

Prevent bills to link to invoices of another patient.

DECLARE
	_doc_patient integer;
	_bill_patient integer;
	_msg text;
BEGIN
	if NEW.fk_doc IS NULL then
		return NEW;
	end if;
	if TG_OP = 'UPDATE' then
		if OLD.fk_doc IS NOT DISTINCT FROM NEW.fk_doc then
			return NEW;
		end if;
	end if;
	-- we now either:
	--	INSERT with .fk_doc NOT NULL
	-- or:
	--	UPDATE with an .fk_bill change to a NON-NULL value
	select pk_patient into _doc_patient
	from blobs.v_doc_med
	where
		pk_doc = NEW.fk_doc;
	select pk_patient into _bill_patient
	from bill.v_bills
	where
		pk_bill = NEW.pk;
	if _doc_patient = _bill_patient then
		return NEW;
	end if;
	_msg := '[bill.trf_prevent_mislinked_bills]: patient mismatch between '
		|| 'bill (pk=' || NEW.pk || ', patient=' || _bill_patient || ') '
		|| 'and invoice (pk=' || NEW.fk_doc || ', patient=' || _doc_patient || ')';
	raise exception integrity_constraint_violation using message = _msg;
	return NULL;
END;

Schema blobs


Table: blobs.doc_desc

A textual description of the content such as a result summary. Several of these may belong to one document object.

blobs.doc_desc Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
row_version integer NOT NULL
modified_when timestamp with time zone NOT NULL DEFAULT now()
modified_by name NOT NULL DEFAULT "current_user"()
pk serial PRIMARY KEY
blobs.doc_med.pk fk_doc integer UNIQUE#1
text text UNIQUE#1

Table blobs.doc_desc Inherits audit_fields,

 

blobs.doc_desc Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema blobs


Table: blobs.doc_med

a medical document object possibly containing several data objects such as several pages of a paper document

blobs.doc_med Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
row_version integer NOT NULL
modified_when timestamp with time zone NOT NULL DEFAULT now()
modified_by name NOT NULL DEFAULT "current_user"()
pk serial PRIMARY KEY
clin.encounter.pk fk_encounter integer NOT NULL

the encounter in which this document was entered into the system
clin.episode.pk fk_episode integer NOT NULL

the episode this document pertains to, this may not be the only one applicable to the document (think discharge letters), see also lnk_doc_med2episode
blobs.doc_type.pk fk_type integer NOT NULL

semantic type of document (not type of file or mime type), such as "referral letter", "discharge summary", etc.
comment text

additional short comment such as "abdominal", "ward 3, Dr. Stein", etc.
clin_when timestamp with time zone NOT NULL DEFAULT now()

date of document content creation (such as exam date), NOT date of document creation or date of import; may be imprecise such as "7/99"
ext_ref text

external reference string of physical document, original paper copy can be found with this
dem.org_unit.pk fk_org_unit integer

Optional link to the org unit this document originates from.\n Note that the document may contain data from several units but\n there will always be one "sender".
unit_is_receiver boolean NOT NULL DEFAULT false

whether the org unit is the receiver rather than the document source
fk_hospital_stay integer

the hospital stay this document is associated with

Table blobs.doc_med Inherits audit_fields,

 

blobs.doc_med Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Tables referencing this one via Foreign Key Constraints:

Index - Schema blobs


Table: blobs.doc_obj

possibly several of these form a medical document such as multiple scanned pages/images

blobs.doc_obj Structure
F-Key Name Type Description
pk serial PRIMARY KEY
blobs.doc_med.pk fk_doc integer NOT NULL
seq_idx integer

index of this object in the sequence of objects for this document
comment text

optional tiny comment for this object, such as "page 1"
dem.staff.pk fk_intended_reviewer integer NOT NULL

who is *supposed* to review this item
data bytea NOT NULL

actual binary object data; here is why we use bytea: == -------------------------------------------------- To: leon@oss.minimetria.com Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Recommendation on bytea or blob for binary data like images Date: Fri, 02 Sep 2005 16:33:09 -0400 Message-ID: <17794.1125693189@sss.pgh.pa.us> From: Tom Lane <tgl@sss.pgh.pa.us> List-Archive: <http://archives.postgresql.org/pgsql-sql> List-Help: <mailto:majordomo@postgresql.org?body=help> List-ID: <pgsql-sql.postgresql.org> leon@oss.minimetria.com writes: > Hi, I"d like to know what the official recommendation is on which binary > datatype to use for common small-binary size use. If bytea will work for you, it"s definitely the thing to use. The only real drawback to bytea is that there"s currently no API to read and write bytea values in a streaming fashion. If your objects are small enough that you can load and store them as units, bytea is fine. BLOBs, on the other hand, have a number of drawbacks --- hard to dump, impossible to secure, etc. regards, tom lane == --------------------------------------------------
filename text

the filename from when the data was imported - if any, can be NULL, useful for re-export since legacy devices/applications might expect particular file names and not use mime types for file detection

 

blobs.doc_obj Constraints
Name Constraint
doc_obj_filename_check CHECK ((btrim(COALESCE(filename, 'NULL'::text)) <> ''::text))

Tables referencing this one via Foreign Key Constraints:

Index - Schema blobs


Table: blobs.doc_type

this table enumerates the document types known to the system

blobs.doc_type Structure
F-Key Name Type Description
pk serial PRIMARY KEY
name text UNIQUE NOT NULL

the name/label of the document type

Tables referencing this one via Foreign Key Constraints:

Index - Schema blobs


Table: blobs.lnk_doc_med2episode

this allows linking documents to episodes, each document can apply to several episodes but only once each

blobs.lnk_doc_med2episode Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
row_version integer NOT NULL
modified_when timestamp with time zone NOT NULL DEFAULT now()
modified_by name NOT NULL DEFAULT "current_user"()
pk serial PRIMARY KEY
clin.episode.pk fk_episode integer UNIQUE#1 NOT NULL
blobs.doc_med.pk fk_doc_med integer UNIQUE#1 NOT NULL

Table blobs.lnk_doc_med2episode Inherits audit_fields,

 

blobs.lnk_doc_med2episode Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema blobs


Table: blobs.reviewed_doc_objs

review table for documents (per object such as a page)

blobs.reviewed_doc_objs Structure
F-Key Name Type Description
pk_audit integer NOT NULL DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass)
row_version integer NOT NULL
modified_when timestamp with time zone NOT NULL DEFAULT now()
modified_by name NOT NULL DEFAULT "current_user"()
pk integer PRIMARY KEY DEFAULT nextval('clin.review_root_pk_seq'::regclass)
blobs.doc_obj.pk fk_reviewed_row integer UNIQUE#1 NOT NULL
fk_reviewer integer UNIQUE#1 NOT NULL
is_technically_abnormal boolean NOT NULL
clinically_relevant boolean NOT NULL
comment text

Table blobs.reviewed_doc_objs Inherits review_root,

 

blobs.reviewed_doc_objs Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema blobs


View: blobs.v_doc_desc

aggregates some document data descriptions

blobs.v_doc_desc Structure
F-Key Name Type Description
pk_patient integer
pk_doc integer
description text
pk_encounter integer
pk_episode integer
pk_health_issue integer
pk_doc_desc integer
SELECT vdm.pk_patient
,
    dd.fk_doc AS pk_doc
,
    dd.text AS description
,
    vdm.pk_encounter
,
    vdm.pk_episode
,
    vdm.pk_health_issue
,
    dd.pk AS pk_doc_desc
   
FROM blobs.doc_desc dd
,
    blobs.v_doc_med vdm
  
WHERE (dd.fk_doc = vdm.pk_doc);

Index - Schema blobs


View: blobs.v_doc_med

blobs.v_doc_med Structure
F-Key Name Type Description
pk_patient integer
pk_doc integer
clin_when timestamp with time zone
type text
l10n_type text
ext_ref text
comment text
episode text
health_issue text
episode_open boolean
unit text
organization text
unit_is_receiver boolean
seq_idx_list integer[]
pk_type integer
pk_encounter integer
pk_episode integer
pk_health_issue integer
pk_org integer
pk_hospital_stay integer
pk_org_unit integer
modified_when timestamp with time zone
modified_by name
xmin_doc_med xid
SELECT c_enc.fk_patient AS pk_patient
,
    b_dm.pk AS pk_doc
,
    b_dm.clin_when
,
    b_dt.name AS type
,
    _
(b_dt.name) AS l10n_type
,
    b_dm.ext_ref
,
    b_dm.comment
,
    c_epi.description AS episode
,
    c_hi.description AS health_issue
,
    c_epi.is_open AS episode_open
,
    d_ou.description AS unit
,
    d_o.description AS organization
,
    b_dm.unit_is_receiver
,
    COALESCE
(
     (
      SELECT array_agg
           (b_do.seq_idx) AS array_agg
           
        FROM blobs.doc_obj b_do
          
       WHERE (b_do.fk_doc = b_dm.pk)
     )
     , ARRAY[]::integer[]
) AS seq_idx_list
,
    b_dm.fk_type AS pk_type
,
    b_dm.fk_encounter AS pk_encounter
,
    b_dm.fk_episode AS pk_episode
,
    c_epi.fk_health_issue AS pk_health_issue
,
    d_ou.fk_org AS pk_org
,
    b_dm.fk_hospital_stay AS pk_hospital_stay
,
    b_dm.fk_org_unit AS pk_org_unit
,
    b_dm.modified_when
,
    b_dm.modified_by
,
    b_dm.xmin AS xmin_doc_med
   
FROM (
     (
           (
                 (
                       (
                             (blobs.doc_med b_dm
     
                                JOIN blobs.doc_type b_dt 
                                  ON (
                                         (b_dm.fk_type = b_dt.pk)
                                   )
                             )
     
                          JOIN clin.encounter c_enc 
                            ON (
                                   (b_dm.fk_encounter = c_enc.pk)
                             )
                       )
     
                    JOIN clin.episode c_epi 
                      ON (
                             (b_dm.fk_episode = c_epi.pk)
                       )
                 )
     
         LEFT JOIN clin.health_issue c_hi 
                ON (
                       (c_hi.pk = c_epi.fk_health_issue)
                 )
           )
     
   LEFT JOIN dem.org_unit d_ou 
          ON (
                 (b_dm.fk_org_unit = d_ou.pk)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_ou.fk_org = d_o.pk)
     )
);

Index - Schema blobs


View: blobs.v_doc_med_journal

blobs.v_doc_med_journal Structure
F-Key Name Type Description
pk_patient integer
modified_when timestamp with time zone
clin_when timestamp with time zone
modified_by text
soap_cat text
narrative text
pk_encounter integer
pk_episode integer
pk_health_issue integer
src_pk integer
src_table text
row_version integer
health_issue text
issue_laterality character varying(2)
issue_active boolean
issue_clinically_relevant boolean
issue_confidential boolean
episode text
episode_open boolean
encounter_started timestamp with time zone
encounter_last_affirmed timestamp with time zone
encounter_type text
encounter_l10n_type text
SELECT c_enc.fk_patient AS pk_patient
,
    b_dm.modified_when
,
    b_dm.clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = b_dm.modified_by)
     )
     , (
           ('<'::text || 
                 (b_dm.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    NULL::text AS soap_cat
,
    
('"'::text || 
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (_
                                                                                         (b_dt.name) || '" '::text
                                                                                   ) || _
                                                                                   ('with'::text)
                                                                             ) || ' '::text
                                                                       ) || 
                                                                       (
                                                                        SELECT count
                                                                             (1) AS count
           
                                                                          FROM blobs.doc_obj b_do
          
                                                                         WHERE (b_do.fk_doc = b_dm.pk)
                                                                       )
                                                                 ) || ' '::text
                                                           ) || _
                                                           ('part(s)'::text
                                                     )
                                               ) || '
'::text
                                         ) || ' '::text
                                   ) || to_char
                                   (b_dm.clin_when
                                         ,'YYYY-MM-DD HH24:MI'::text
                                   )
                             ) || '
'::text
                       ) || COALESCE
                       (
                             (
                                   (' ['::text || b_dm.ext_ref) || ']'::text
                             )
                             ,''::text
                       )
                 ) ||
        CASE
            WHEN b_dm.unit_is_receiver THEN COALESCE
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (' '::text || _
                                                           ('sent to'::text)
                                                     ) || d_ou.description
                                               ) || ' '::text
                                         ) || _
                                         ('of'::text)
                                   ) || ' '::text
                             ) || d_o.description
                       )
                       ,''::text
                 )
            ELSE COALESCE
                 (
                       (
                             (
                                   (
                                         (
                                               (' @ '::text || d_ou.description) || ' '::text
                                         ) || _
                                         ('of'::text)
                                   ) || ' '::text
                             ) || d_o.description
                       )
                       ,''::text
                 )
        END
           ) || '
'::text
     ) || COALESCE
     (
           (' '::text || b_dm.comment)
           ,''::text
     )
)
)      AS narrative
,     
    b_dm.fk_encounter AS pk_encounter
,     
    b_dm.fk_episode AS pk_episode
,     
    c_epi.fk_health_issue AS pk_health_issue
,     
    b_dm.pk AS src_pk
,     
    'blobs.doc_med'::text AS src_table
,     
    b_dm.row_version
,     
    c_hi.description AS health_issue
,     
    c_hi.laterality AS issue_laterality
,     
    c_hi.is_active AS issue_active
,     
    c_hi.clinically_relevant AS issue_clinically_relevant
,     
    c_hi.is_confidential AS issue_confidential
,     
    c_epi.description AS episode
,     
    c_epi.is_open AS episode_open
,     
    c_enc.started AS encounter_started
,     
    c_enc.last_affirmed AS encounter_last_affirmed
,     
    c_ety.description AS encounter_type
,     
    _
(     c_ety.description) AS encounter_l10n_type
   
FROM   (
(
     (
           (
                 (
                       (
                             (blobs.doc_med b_dm
     
                                JOIN clin.encounter c_enc 
                                  ON (
                                         (b_dm.fk_encounter = c_enc.pk)
                                   )
                             )
     
                          JOIN clin.encounter_type c_ety 
                            ON (
                                   (c_enc.fk_type = c_ety.pk)
                             )
                       )
     
                    JOIN blobs.doc_type b_dt 
                      ON (
                             (b_dm.fk_type = b_dt.pk)
                       )
                 )
     
              JOIN clin.episode c_epi 
                ON (
                       (b_dm.fk_episode = c_epi.pk)
                 )
           )
     
   LEFT JOIN clin.health_issue c_hi 
          ON (
                 (c_epi.fk_health_issue = c_hi.pk)
           )
     )
     
LEFT JOIN dem.org_unit d_ou 
    ON (
           (b_dm.fk_org_unit = d_ou.pk)
     )
)
     
LEFT JOIN dem.org d_o 
ON (
     (d_ou.fk_org = d_o.pk)
)
)     ;

Index - Schema blobs


View: blobs.v_doc_type

list active document types, those that are activated for use

blobs.v_doc_type Structure
F-Key Name Type Description
pk_doc_type integer
type text
l10n_type text
is_user_defined boolean
is_in_use boolean
xmin_doc_type xid
SELECT dt.pk AS pk_doc_type
,
    dt.name AS type
,
    _
(dt.name) AS l10n_type
,
    
(NOT 
     (EXISTS 
           (
            SELECT 1
           
              FROM ref.document_type
          
             WHERE (document_type.description = dt.name)
           )
     )
) AS is_user_defined
,
    
(EXISTS 
     (
      SELECT 1
           
        FROM blobs.doc_med
          
       WHERE (doc_med.fk_type = dt.pk)
     )
) AS is_in_use
,
    dt.xmin AS xmin_doc_type
   
FROM blobs.doc_type dt;

Index - Schema blobs


View: blobs.v_latest_mugshot

shows the latest picture of the patient, currently the highest seq_idx of the newest document of type "patient photograph"

blobs.v_latest_mugshot Structure
F-Key Name Type Description
pk_patient integer
doc_comment text
date_taken timestamp with time zone
ext_ref text
obj_seq_idx integer
obj_comment text
pk_doc integer
pk_obj integer
image bytea
SELECT b_vo4d.pk_patient
,
    b_vo4d.doc_comment
,
    b_vo4d.date_generated AS date_taken
,
    b_vo4d.ext_ref
,
    b_vo4d.seq_idx AS obj_seq_idx
,
    b_vo4d.obj_comment
,
    b_vo4d.pk_doc
,
    b_vo4d.pk_obj
,
    b_do.data AS image
   
FROM blobs.v_obj4doc_no_data b_vo4d
,
    blobs.doc_obj b_do
  
WHERE (
     (b_vo4d.type = 'patient photograph'::text)
   AND (b_vo4d.seq_idx = 
           (
            SELECT max
                 (b_vo4d1.seq_idx) AS max
           
              FROM blobs.v_obj4doc_no_data b_vo4d1
          
             WHERE (
                       (b_vo4d1.pk_patient = b_vo4d.pk_patient)
                     AND (b_vo4d1.type = 'patient photograph'::text)
                 )
          
          GROUP BY b_vo4d1.date_generated
          
          ORDER BY b_vo4d1.date_generated DESC
         LIMIT 1
           )
     )
   AND (b_do.pk = b_vo4d.pk_obj)
);

Index - Schema blobs


View: blobs.v_obj4doc_no_data

denormalized metadata for blobs.doc_obj but without the data itself

blobs.v_obj4doc_no_data Structure
F-Key Name Type Description
pk_patient integer
pk_obj integer
seq_idx integer
size integer
date_generated timestamp with time zone
type text
l10n_type text
ext_ref text
episode text
doc_comment text
obj_comment text
filename text
pk_intended_reviewer integer
reviewed boolean
reviewed_by_you boolean
reviewed_by_intended_reviewer boolean
pk_doc integer
pk_type integer
pk_encounter integer
pk_episode integer
pk_health_issue integer
pk_org integer
pk_org_unit integer
pk_hospital_stay integer
xmin_doc_obj xid
SELECT b_vdm.pk_patient
,
    b_do.pk AS pk_obj
,
    b_do.seq_idx
,
    octet_length
(COALESCE
     (b_do.data
           ,'\x'::bytea
     )
) AS size
,
    b_vdm.clin_when AS date_generated
,
    b_vdm.type
,
    b_vdm.l10n_type
,
    b_vdm.ext_ref
,
    b_vdm.episode
,
    b_vdm.comment AS doc_comment
,
    b_do.comment AS obj_comment
,
    b_do.filename
,
    b_do.fk_intended_reviewer AS pk_intended_reviewer
,
    
(EXISTS 
     (
      SELECT 1
           
        FROM blobs.reviewed_doc_objs
          
       WHERE (reviewed_doc_objs.fk_reviewed_row = b_do.pk)
     )
) AS reviewed
,
    
(EXISTS 
     (
      SELECT 1
           
        FROM blobs.reviewed_doc_objs
          
       WHERE (
                 (reviewed_doc_objs.fk_reviewed_row = b_do.pk)
               AND (reviewed_doc_objs.fk_reviewer = 
                       (
                        SELECT staff.pk
                   
                          FROM dem.staff
                  
                         WHERE (staff.db_user = "current_user"
                                   ()
                             )
                       )
                 )
           )
     )
) AS reviewed_by_you
,
    
(EXISTS 
     (
      SELECT 1
           
        FROM blobs.reviewed_doc_objs
          
       WHERE (
                 (reviewed_doc_objs.fk_reviewed_row = b_do.pk)
               AND (reviewed_doc_objs.fk_reviewer = b_do.fk_intended_reviewer)
           )
     )
) AS reviewed_by_intended_reviewer
,
    b_vdm.pk_doc
,
    b_vdm.pk_type
,
    b_vdm.pk_encounter
,
    b_vdm.pk_episode
,
    b_vdm.pk_health_issue
,
    b_vdm.pk_org
,
    b_vdm.pk_org_unit
,
    b_vdm.pk_hospital_stay
,
    b_do.xmin AS xmin_doc_obj
   
FROM (blobs.v_doc_med b_vdm
     
  JOIN blobs.doc_obj b_do 
    ON (
           (b_do.fk_doc = b_vdm.pk_doc)
     )
)
  
WHERE (b_vdm.pk_doc = b_do.fk_doc);

Index - Schema blobs


View: blobs.v_reviewed_doc_objects

blobs.v_reviewed_doc_objects Structure
F-Key Name Type Description
pk_doc_obj integer
reviewer text
is_technically_abnormal boolean
clinically_relevant boolean
is_review_by_responsible_reviewer boolean
is_your_review boolean
comment text
reviewed_when timestamp with time zone
modified_by name
pk_review_root integer
pk_reviewer integer
pk_patient integer
pk_encounter integer
pk_episode integer
pk_health_issue integer
SELECT b_rdo.fk_reviewed_row AS pk_doc_obj
,
    COALESCE
(d_s.short_alias
     , (
           ('<#'::text || b_rdo.fk_reviewer) || '>'::text
     )
) AS reviewer
,
    b_rdo.is_technically_abnormal
,
    b_rdo.clinically_relevant
,
    
(b_rdo.fk_reviewer = b_do.fk_intended_reviewer) AS is_review_by_responsible_reviewer
,
    
(b_rdo.fk_reviewer = 
     (
      SELECT staff.pk
           
        FROM dem.staff
          
       WHERE (staff.db_user = CURRENT_USER)
     )
) AS is_your_review
,
    b_rdo.comment
,
    b_rdo.modified_when AS reviewed_when
,
    b_rdo.modified_by
,
    b_rdo.pk AS pk_review_root
,
    b_rdo.fk_reviewer AS pk_reviewer
,
    c_enc.fk_patient AS pk_patient
,
    b_dm.fk_encounter AS pk_encounter
,
    b_dm.fk_episode AS pk_episode
,
    c_epi.fk_health_issue AS pk_health_issue
   
FROM (
     (
           (
                 (
                       (blobs.reviewed_doc_objs b_rdo
     
                     LEFT JOIN dem.staff d_s 
                            ON (
                                   (d_s.pk = b_rdo.fk_reviewer)
                             )
                       )
     
               LEFT JOIN blobs.doc_obj b_do 
                      ON (
                             (b_do.pk = b_rdo.fk_reviewed_row)
                       )
                 )
     
         LEFT JOIN blobs.doc_med b_dm 
                ON (
                       (b_do.fk_doc = b_dm.pk)
                 )
           )
     
   LEFT JOIN clin.episode c_epi 
          ON (
                 (b_dm.fk_episode = c_epi.pk)
           )
     )
     
LEFT JOIN clin.encounter c_enc 
    ON (
           (c_epi.fk_encounter = c_enc.pk)
     )
);

Index - Schema blobs


View: blobs.v_unreviewed_docs

blobs.v_unreviewed_docs Structure
F-Key Name Type Description
pk_doc integer
pk_intended_reviewer integer
pk_patient integer
SELECT DISTINCT 
ON (b_do.fk_doc) b_do.fk_doc AS pk_doc
,
    min
(b_do.fk_intended_reviewer) AS pk_intended_reviewer
,
    min
(c_e.fk_patient) AS pk_patient
   
FROM (
     (blobs.doc_obj b_do
     
        JOIN blobs.doc_med b_dm 
          ON (
                 (b_dm.pk = b_do.fk_doc)
           )
     )
     
  JOIN clin.encounter c_e 
    ON (
           (b_dm.fk_encounter = c_e.pk)
     )
)
  
WHERE (NOT 
     (EXISTS 
           (
            SELECT 1
           
              FROM blobs.reviewed_doc_objs b_rdo
          
             WHERE (b_rdo.fk_reviewed_row = b_do.pk)
           )
     )
)
  
GROUP BY b_do.fk_doc;

Index - Schema blobs


View: blobs.v_unreviewed_docs_inbox

blobs.v_unreviewed_docs_inbox Structure
F-Key Name Type Description
received_when timestamp with time zone
modified_by text
provider text
importance integer
category text
l10n_category text
type text
l10n_type text
comment text
pk_context integer[]
data text
pk_inbox_message integer
pk_staff integer
pk_category integer
pk_type integer
pk_patient integer
is_virtual boolean
due_date timestamp with time zone
expiry_date timestamp with time zone
is_overdue boolean
is_expired boolean
interval_due interval
xmin_message_inbox integer
SELECT now
() AS received_when
,
    '<system>'::text AS modified_by
,
    NULL::text AS provider
,
    0 AS importance
,
    'clinical'::text AS category
,
    _
('clinical'::text) AS l10n_category
,
    'review docs'::text AS type
,
    _
('review docs'::text) AS l10n_type
,
    
(
SELECT (
           (
                 (
                       (
                             (
                                   (b_vuds.no_of_docs || ' '::text) || _
                                   ('unreviewed documents for patient'::text)
                             ) || ' '::text
                       ) || d_n.lastnames
                 ) || 
              ', '::text
           ) || d_n.firstnames
     )
) AS comment
,
    NULL::integer[] AS pk_context
,
    NULL::text AS data
,
    NULL::integer AS pk_inbox_message
,
    
(
SELECT staff.pk
           
  FROM dem.staff
          
 WHERE (staff.db_user = "current_user"
           ()
     )
) AS pk_staff
,
    
(
SELECT v_inbox_item_type.pk_category
           
  FROM dem.v_inbox_item_type
          
 WHERE (v_inbox_item_type.type = 'review docs'::text)
) AS pk_category
,
    
(
SELECT v_inbox_item_type.pk_type
           
  FROM dem.v_inbox_item_type
          
 WHERE (v_inbox_item_type.type = 'review docs'::text)
) AS pk_type
,
    b_vuds.pk_patient
,
    true AS is_virtual
,
    
(now
     () - '01:00:00'::interval
) AS due_date
,
    NULL::timestamp with time zone AS expiry_date
,
    true AS is_overdue
,
    false AS is_expired
,
    '01:00:00'::interval AS interval_due
,
    NULL::integer AS xmin_message_inbox
   
FROM (blobs.v_unreviewed_docs_summary b_vuds
     
  JOIN dem.names d_n 
    ON (
           (b_vuds.pk_patient = d_n.id_identity)
     )
)
  
WHERE (d_n.active IS TRUE);

Index - Schema blobs


View: blobs.v_unreviewed_docs_summary

blobs.v_unreviewed_docs_summary Structure
F-Key Name Type Description
pk_patient integer
no_of_docs bigint
SELECT b_vud.pk_patient
,
    count
(1) AS no_of_docs
   
FROM blobs.v_unreviewed_docs b_vud
  
GROUP BY b_vud.pk_patient;

Index - Schema blobs


Function: blobs.delete_document(integer, integer)

Returns: boolean

Language: PLPGSQL

DECLARE
	_pk_doc alias for $1;
	_pk_encounter alias for $2;
	_del_note text;
	_doc_row record;
	_obj_row record;
	tmp text;
BEGIN
	select * into _doc_row from blobs.doc_med where pk = _pk_doc;
	_del_note := _('Deletion of document') || E':
'
		|| ' '
			|| to_char(_doc_row.clin_when, 'YYYY-MM-DD HH24:MI')
			|| ' "' || (select _(dt.name) from blobs.doc_type dt where pk = _doc_row.fk_type) || '"'
			|| coalesce(' (' || _doc_row.ext_ref || ')', '')
		|| coalesce(E'
 ' || _doc_row.comment, '')
	;
	FOR _obj_row IN select * from blobs.doc_obj where fk_doc = _pk_doc order by seq_idx LOOP
		_del_note := _del_note || E'
'
			|| ' #' || coalesce(_obj_row.seq_idx, '-1') || ': "' || coalesce(_obj_row.comment, '') || E'"
'
			|| ' ' || coalesce(_obj_row.filename, '') || E'
';
	end LOOP;
	insert into clin.clin_narrative
		(fk_encounter, fk_episode, narrative, soap_cat)
	values (
		_pk_encounter,
		_doc_row.fk_episode,
		_del_note,
		NULL
	);
	-- should auto-cascade:
	--delete from blobs.doc_obj where fk_doc = _pk_doc;
	-- should auto-NULL:
	--bill.bill.fk_doc
	delete from blobs.doc_med where pk = _pk_doc;
	return True;
END;

Function: blobs.delete_document_part(integer, integer)

Returns: boolean

Language: PLPGSQL

DECLARE
	_pk_doc_part alias for $1;
	_pk_encounter alias for $2;
	_del_note text;
	_doc_row record;
	_obj_row record;
	tmp text;
BEGIN
	select * into _obj_row from blobs.doc_obj where pk = _pk_doc_part;
	select * into _doc_row from blobs.doc_med where pk = _obj_row.fk_doc;
	_del_note := _('Deletion of part from document') || E':
'
		|| ' '
			|| to_char(_doc_row.clin_when, 'YYYY-MM-DD HH24:MI')
			|| ' "' || (select _(dt.name) from blobs.doc_type dt where pk = _doc_row.fk_type) || '"'
			|| coalesce(' (' || _doc_row.ext_ref || ')', '')
		|| coalesce(E'
 ' || _doc_row.comment, '')
		|| E'
'
		|| ' #' || coalesce(_obj_row.seq_idx, '-1') || ': "' || coalesce(_obj_row.comment, '') || E'"
'
		|| ' ' || coalesce(_obj_row.filename, '') || E'
'
	;
	insert into clin.clin_narrative
		(fk_encounter, fk_episode, narrative, soap_cat)
	values (
		_pk_encounter,
		_doc_row.fk_episode,
		_del_note,
		NULL
	);
	delete from blobs.doc_obj where pk = _pk_doc_part;
	return True;
END;

Function: blobs.trf_do_not_duplicate_primary_episode_in_link_table()

Returns: trigger

Language: PLPGSQL

This trigger function is called before a lnk_doc_med2episode row is inserted or updated. It makes sure the episode does not duplicate the primary episode for this document listed in doc_med. If it does the insert/update is skipped.

BEGIN
	-- if already in doc_med
	perform 1 from blobs.doc_med dm where dm.fk_episode = NEW.fk_episode and dm.pk = NEW.fk_doc_med;
	if FOUND then
		-- skip the insert/update
		return null;
	end if;
	return NEW;
END;

Function: blobs.trf_mark_unreviewed_on_doc_obj_update()

Returns: trigger

Language: PLPGSQL

BEGIN
	if (NEW.data != OLD.data) or ((NEW.data != OLD.data) is NULL) then
		delete from blobs.reviewed_doc_objs where fk_reviewed_row = OLD.pk;
	end if;
	return NEW;
END;

Function: blobs.trf_remove_primary_episode_from_link_table()

Returns: trigger

Language: PLPGSQL

This trigger function is called when a doc_med row is inserted or updated. It makes sure the primary episode listed in doc_med is not duplicated in lnk_doc_med2episode for the same document. If it exists in the latter it is removed from there.

BEGIN
	-- if update
	if TG_OP = 'UPDATE' then
		-- and no change
		if NEW.fk_episode = OLD.fk_episode then
			-- then do nothing
			return NEW;
		end if;
	end if;
	-- if already in link table
	perform 1 from blobs.lnk_doc_med2episode ldm2e where ldm2e.fk_episode = NEW.fk_episode and ldm2e.fk_doc_med = NEW.pk;
	if FOUND then
		-- delete from link table
		delete from blobs.lnk_doc_med2episode where fk_episode = NEW.fk_episode and fk_doc_med = NEW.pk;
	end if;
	return NEW;
END;

Function: blobs.trf_set_intended_reviewer()

Returns: trigger

Language: PLPGSQL

Set the default on blobs.doc_obj.fk_intended_reviewer.

DECLARE
	_pk_patient integer;
	_pk_provider integer;
BEGIN
	-- explicitely set ?
	if NEW.fk_intended_reviewer is not NULL then
		return NEW;
	end if;
	-- find patient via document
	select
		fk_patient into _pk_patient
	from
		clin.encounter
	where
		clin.encounter.pk = (
			select fk_encounter from blobs.doc_med where pk = NEW.fk_doc
		);
	-- does patient have primary provider ?
	select
		fk_primary_provider into _pk_provider
	from
		dem.identity
	where
		dem.identity.pk = _pk_patient;
	if _pk_provider is not NULL then
		NEW.fk_intended_reviewer := _pk_provider;
		return NEW;
	end if;
	-- else use CURRENT_USER
	select
		pk into _pk_provider
	from
		dem.staff
	where
		dem.staff.db_user = current_user;
	NEW.fk_intended_reviewer := _pk_provider;
	return NEW;
END;

Function: blobs.trf_verify_page_number()

Returns: trigger

Language: PLPGSQL

declare
	msg text;
begin
	if NEW.seq_idx is NULL then
		return NEW;
	end if;
	perform 1 from blobs.doc_obj where pk <> NEW.pk and fk_doc = NEW.fk_doc and seq_idx = NEW.seq_idx;
	if FOUND then
		msg := '[blobs.trf_verify_page_number]: uniqueness violation: seq_idx [' || NEW.seq_idx || '] already exists for fk_doc [' || NEW.fk_doc || ']';
		raise exception '%', msg;
	end if;
	return NEW;
end;

Schema cfg

This schema holds all the configuration data.


Table: cfg.cfg_data

stores opaque configuration data, either text or binary, note that it will be difficult to share such options among different types of clients

cfg.cfg_data Structure
F-Key Name Type Description
cfg.cfg_item.pk fk_item integer NOT NULL
value bytea NOT NULL
pk serial PRIMARY KEY

Index - Schema cfg


Table: cfg.cfg_item

this table holds all "instances" of cfg.cfg_template

cfg.cfg_item Structure
F-Key Name Type Description
pk serial PRIMARY KEY
cfg.cfg_template.pk fk_template integer UNIQUE#1 NOT NULL

this points to the class of this option, think of this as a base object, this also defines the data type
owner name UNIQUE#1 NOT NULL DEFAULT "current_user"()

the database level user this option belongs to; this is the "role" of the user from the perspective of the database; can be "default" at the application level to indicate that it does not care
workplace text UNIQUE#1

- the logical workplace this option pertains to - can be a hostname but should be a logical rather than a physical identifier as machines get moved, workplaces do not, kind of like a "role" for the machine - associate this with a physical workplace through a local config file or environment variable
cookie text UNIQUE#1

an arbitrary, opaque entity the client code can use to associate this config item with even finer grained context; could be the pertinent patient ID for patient specific options

Tables referencing this one via Foreign Key Constraints:

Index - Schema cfg


Table: cfg.cfg_numeric