Dumped on 2023-09-30

Index of database - gnumed_v22


Schema au


Table: au.referral

table for referrals to defined individuals

au.referral Structure
F-Key Name Type Description
clin.episode.pk fk_episode
id PRIMARY KEY
dem.identity.pk fk_referee
clin.encounter.pk fk_encounter
clin.form_instances.pk fk_form

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]))))
idx_au_referral_fk_encounter fk_encounter idx_au_referral_fk_episode fk_episode

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 PRIMARY KEY

 

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 PRIMARY KEY

 

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
schema UNIQUE#1
id PRIMARY KEY
table_name UNIQUE#1

Index - Schema audit


Table: audit.log_access_log

audit.log_access_log Structure
F-Key Name Type Description

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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
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
dem.lnk_person_org_address.id fk_receiver_address
dem.identity.pk fk_receiver_identity
pk PRIMARY KEY
invoice_id UNIQUE
blobs.doc_med.pk fk_doc

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
ref.billable.pk fk_billable
bill.bill.pk fk_bill
pk PRIMARY KEY
dem.staff.pk fk_provider
clin.encounter.pk fk_encounter

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])))
idx_bill_bill_item_fk_bill fk_bill idx_bill_bill_item_fk_billable fk_billable

Index - Schema bill


Table: bill.lnk_enc_type2billable

actual bills

bill.lnk_enc_type2billable Structure
F-Key Name Type Description
clin.encounter_type.pk fk_encounter_type
ref.billable.pk fk_billable
pk PRIMARY KEY
idx_lnk_enc_type2billable_fk_billable fk_billable idx_lnk_enc_type2billable_fk_encounter_type fk_encounter_type

Index - Schema bill


View: bill.v_bill_items

bill.v_bill_items Structure
F-Key Name Type Description
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
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
blobs.doc_med.pk fk_doc UNIQUE#1
text UNIQUE#1
pk PRIMARY KEY

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))
idx_doc_desc_fk_doc fk_doc

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
blobs.doc_type.pk fk_type
clin.episode.pk fk_episode
dem.org_unit.pk fk_org_unit
pk PRIMARY KEY
clin.encounter.pk fk_encounter

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 PRIMARY KEY
dem.staff.pk fk_intended_reviewer
blobs.doc_med.pk fk_doc

 

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
name UNIQUE
pk PRIMARY KEY

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 PRIMARY KEY
clin.episode.pk fk_episode UNIQUE#1
blobs.doc_med.pk fk_doc_med UNIQUE#1

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 PRIMARY KEY
blobs.doc_obj.pk fk_reviewed_row UNIQUE#1
fk_reviewer UNIQUE#1

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
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
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
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
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
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
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
SELECT rdo.fk_reviewed_row AS pk_doc_obj
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.pk = rdo.fk_reviewer)
     )
     , (
           ('<#'::text || rdo.fk_reviewer) || '>'::text
     )
) AS reviewer
,
    rdo.is_technically_abnormal
,
    rdo.clinically_relevant
,
    
(EXISTS 
     (
      SELECT 1
           
        FROM blobs.doc_obj
          
       WHERE (
                 (doc_obj.pk = rdo.fk_reviewed_row)
               AND (doc_obj.fk_intended_reviewer = rdo.fk_reviewer)
           )
     )
) AS is_review_by_responsible_reviewer
,
    
(EXISTS 
     (
      SELECT 1
           
        FROM dem.staff
          
       WHERE (
                 (staff.pk = rdo.fk_reviewer)
               AND (staff.db_user = "current_user"
                       ()
                 )
           )
     )
) AS is_your_review
,
    rdo.comment
,
    rdo.modified_when AS reviewed_when
,
    rdo.modified_by
,
    rdo.pk AS pk_review_root
,
    rdo.fk_reviewer AS pk_reviewer
,
    
(
SELECT v_obj4doc_no_data.pk_patient
           
  FROM blobs.v_obj4doc_no_data
          
 WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
) AS pk_patient
,
    
(
SELECT v_obj4doc_no_data.pk_encounter
           
  FROM blobs.v_obj4doc_no_data
          
 WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
) AS pk_encounter
,
    
(
SELECT v_obj4doc_no_data.pk_episode
           
  FROM blobs.v_obj4doc_no_data
          
 WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
) AS pk_episode
,
    
(
SELECT v_obj4doc_no_data.pk_health_issue
           
  FROM blobs.v_obj4doc_no_data
          
 WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)
) AS pk_health_issue
   
FROM blobs.reviewed_doc_objs rdo;

Index - Schema blobs


View: blobs.v_unreviewed_docs

blobs.v_unreviewed_docs Structure
F-Key Name Type Description
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
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
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
pk 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 PRIMARY KEY
owner UNIQUE#1
workplace UNIQUE#1
cfg.cfg_template.pk fk_template UNIQUE#1
cookie UNIQUE#1

Tables referencing this one via Foreign Key Constraints:

Index - Schema cfg


Table: cfg.cfg_numeric

cfg.cfg_numeric Structure
F-Key Name Type Description
cfg.cfg_item.pk fk_item
pk PRIMARY KEY

Index - Schema cfg


Table: cfg.cfg_str_array

cfg.cfg_str_array Structure
F-Key Name Type Description
cfg.cfg_item.pk fk_item
pk PRIMARY KEY

Index - Schema cfg


Table: cfg.cfg_string

cfg.cfg_string Structure
F-Key Name Type Description
cfg.cfg_item.pk fk_item
pk PRIMARY KEY

Index - Schema cfg


Table: cfg.cfg_template

meta definition of config items

cfg.cfg_template Structure
F-Key Name Type Description
pk PRIMARY KEY
cfg.cfg_type_enum.name type

Tables referencing this one via Foreign Key Constraints:

Index - Schema cfg


Table: cfg.cfg_type_enum

enumeration of config option data types

cfg.cfg_type_enum Structure
F-Key Name Type Description
name UNIQUE

Tables referencing this one via Foreign Key Constraints:

Index - Schema cfg


Table: cfg.config

maps a service name to a database location for a particular user, includes user credentials for that database

cfg.config Structure
F-Key Name Type Description
id PRIMARY KEY

Index - Schema cfg


Table: cfg.db_logon_banner

Stores a banner to show when clients log on.

cfg.db_logon_banner Structure
F-Key Name Type Description
singularizer UNIQUE

 

cfg.db_logon_banner Constraints
Name Constraint
db_logon_banner_message_check CHECK ((btrim(message) <> ''::text))
db_logon_banner_singularizer_check CHECK ((singularizer IS TRUE))

Index - Schema cfg


Table: cfg.report_query

This table stores SQL commands to be used in frontend report style queries.

cfg.report_query Structure
F-Key Name Type Description
label UNIQUE
pk PRIMARY KEY

Table cfg.report_query Inherits audit_fields,

 

cfg.report_query Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
report_query_cmd_check CHECK ((btrim(COALESCE(cmd, 'NULL'::text)) <> ''::text))
report_query_label_check CHECK ((btrim(COALESCE(label, 'NULL'::text)) <> ''::text))

Index - Schema cfg


View: cfg.v_cfg_options

cfg.v_cfg_options Structure
F-Key Name Type Description
SELECT cfg_t.name AS option
,
    cfg_t.description
,
    cfg_i.owner
,
    cfg_i.workplace
,
    cfg_i.cookie
,
    cfg_t.type
,
    cfg_t.cfg_group AS "group"
,
    cfg_t.pk AS pk_cfg_template
,
    cfg_i.pk AS pk_cfg_item
   
FROM cfg.cfg_template cfg_t
,
    cfg.cfg_item cfg_i
  
WHERE (cfg_i.fk_template = cfg_t.pk);

Index - Schema cfg


View: cfg.v_cfg_opts_data

cfg.v_cfg_opts_data Structure
F-Key Name Type Description
SELECT cfg_t.name AS option
,
    cfg_v.value
,
    cfg_t.description
,
    cfg_i.owner
,
    cfg_i.workplace
,
    cfg_i.cookie
,
    cfg_t.cfg_group AS "group"
,
    cfg_t.pk AS pk_cfg_template
,
    cfg_i.pk AS pk_cfg_item
   
FROM cfg.cfg_template cfg_t
,
    cfg.cfg_item cfg_i
,
    cfg.cfg_data cfg_v
  
WHERE (
     (cfg_i.fk_template = cfg_t.pk)
   AND (cfg_v.fk_item = cfg_i.pk)
);

Index - Schema cfg


View: cfg.v_cfg_opts_numeric

cfg.v_cfg_opts_numeric Structure
F-Key Name Type Description
SELECT cfg_t.name AS option
,
    cfg_v.value
,
    cfg_t.description
,
    cfg_i.owner
,
    cfg_i.workplace
,
    cfg_i.cookie
,
    cfg_t.cfg_group AS "group"
,
    cfg_t.pk AS pk_cfg_template
,
    cfg_i.pk AS pk_cfg_item
   
FROM cfg.cfg_template cfg_t
,
    cfg.cfg_item cfg_i
,
    cfg.cfg_numeric cfg_v
  
WHERE (
     (cfg_i.fk_template = cfg_t.pk)
   AND (cfg_v.fk_item = cfg_i.pk)
);

Index - Schema cfg


View: cfg.v_cfg_opts_str_array

cfg.v_cfg_opts_str_array Structure
F-Key Name Type Description
SELECT cfg_t.name AS option
,
    cfg_v.value
,
    cfg_t.description
,
    cfg_i.owner
,
    cfg_i.workplace
,
    cfg_i.cookie
,
    cfg_t.cfg_group AS "group"
,
    cfg_t.pk AS pk_cfg_template
,
    cfg_i.pk AS pk_cfg_item
   
FROM cfg.cfg_template cfg_t
,
    cfg.cfg_item cfg_i
,
    cfg.cfg_str_array cfg_v
  
WHERE (
     (cfg_i.fk_template = cfg_t.pk)
   AND (cfg_v.fk_item = cfg_i.pk)
);

Index - Schema cfg


View: cfg.v_cfg_opts_string

cfg.v_cfg_opts_string Structure
F-Key Name Type Description
SELECT cfg_t.name AS option
,
    cfg_v.value
,
    cfg_t.description
,
    cfg_i.owner
,
    cfg_i.workplace
,
    cfg_i.cookie
,
    cfg_t.cfg_group AS "group"
,
    cfg_t.pk AS pk_cfg_template
,
    cfg_i.pk AS pk_cfg_item
   
FROM cfg.cfg_template cfg_t
,
    cfg.cfg_item cfg_i
,
    cfg.cfg_string cfg_v
  
WHERE (
     (cfg_i.fk_template = cfg_t.pk)
   AND (cfg_v.fk_item = cfg_i.pk)
);

Index - Schema cfg


Function: cfg.create_cfg_item(text, text, text, text, text)

Returns: integer

Language: PLPGSQL

declare
	_option alias for $1;
	_val_type alias for $2;
	_workplace alias for $3;
	_cookie alias for $4;
	_owner alias for $5;
	real_owner text;
	pk_template integer;
	pk_item integer;
begin
	-- check template
	select into pk_template pk from cfg.cfg_template where name = _option and type = _val_type;
	if not FOUND then
		insert into cfg.cfg_template (name, type) values (_option, _val_type);
		select into pk_template currval('cfg.cfg_template_pk_seq');
	end if;
	if _owner is null then
		select into real_owner CURRENT_USER;
	else
		real_owner := _owner;
	end if;
	-- check item
	if _cookie is NULL then
		select into pk_item pk from cfg.cfg_item where
			fk_template = pk_template and
			owner = real_owner and
			workplace = _workplace and
			cookie is null;
	else
		select into pk_item pk from cfg.cfg_item where
			fk_template = pk_template and
			owner = real_owner and
			workplace = _workplace and
			cookie = _cookie;
	end if;
	if FOUND then
		return pk_item;
	end if;
	insert into cfg.cfg_item (
		fk_template, workplace, cookie, owner
	) values (
		pk_template,
		_workplace,
		_cookie,
		real_owner
	);
	select into pk_item currval('cfg.cfg_item_pk_seq');
	return pk_item;
end;

Function: cfg.set_option(text, anyelement, text, text, text)

Returns: boolean

Language: PLPGSQL

set option, owner = NULL means CURRENT_USER

declare
	_option alias for $1;
	_value alias for $2;
	_workplace alias for $3;
	_cookie alias for $4;
	_owner alias for $5;
	val_type text;
	pk_item integer;
	rows integer;
	cmd text;
begin
	-- determine data type
	if _value is of (text, char, varchar, name) then
		val_type := 'string';
	elsif _value is of (smallint, integer, bigint, numeric, boolean) then
		val_type := 'numeric';
	elsif _value is of (bytea) then
		val_type := 'data';
	elsif _value is of (text[]) then
		val_type := 'str_array';
	else
		raise exception 'cfg.set_option(text, any, text, text, text): invalid type of value';
	end if;
	-- create template/item if need be
	select into pk_item cfg.create_cfg_item(_option, val_type, _workplace, _cookie, _owner);
	-- set item value
	cmd := 'select 1 from cfg.cfg_' || val_type || ' where fk_item=' || pk_item || ';';
	execute cmd;
	get diagnostics rows = row_count;
	found := rows <> 0;
	if FOUND then
		if val_type = 'str_array' then
			cmd := 'update cfg.cfg_str_array set value=''{"' || array_to_string(_value, '","') || '"}'' where fk_item=' || pk_item || ';';
		elsif val_type = 'data' then
			cmd := 'update cfg.cfg_data set value=''' || encode(_value, 'escape') || ''' where fk_item=' || pk_item || ';';
		else
			cmd := 'update cfg.cfg_' || val_type || ' set value=' || quote_literal(_value) || ' where fk_item=' || pk_item || ';';
		end if;
		execute cmd;
		return True;
	end if;
	if val_type = 'str_array' then
		cmd := 'insert into cfg.cfg_str_array(fk_item, value) values (' || pk_item || ', ''{"' || array_to_string(_value, '","') || '"}'');';
	elsif val_type = 'data' then
		cmd := 'insert into cfg.cfg_data(fk_item, value) values (' || pk_item || ', ''' || encode(_value, 'escape') || ''');';
	else
		cmd := 'insert into cfg.cfg_' || val_type || ' (fk_item, value) values (' || pk_item || ', ' || quote_literal(_value) || ');';
	end if;
	execute cmd;
	return True;
end;

Schema clin


Table: clin._enum_allergy_type

clin._enum_allergy_type Structure
F-Key Name Type Description
pk PRIMARY KEY
value UNIQUE

Tables referencing this one via Foreign Key Constraints:

Index - Schema clin


View: clin._view_emr_journal_without_suppressed_hints

clin._view_emr_journal_without_suppressed_hints Structure
F-Key Name Type Description
SELECT v_emr_journal.pk_patient
,
    v_emr_journal.modified_when
,
    v_emr_journal.clin_when
,
    v_emr_journal.modified_by
,
    v_emr_journal.soap_cat
,
    v_emr_journal.narrative
,
    v_emr_journal.pk_encounter
,
    v_emr_journal.pk_episode
,
    v_emr_journal.pk_health_issue
,
    v_emr_journal.src_pk
,
    v_emr_journal.src_table
,
    v_emr_journal.row_version
,
    v_emr_journal.health_issue
,
    v_emr_journal.issue_laterality
,
    v_emr_journal.issue_active
,
    v_emr_journal.issue_clinically_relevant
,
    v_emr_journal.issue_confidential
,
    v_emr_journal.episode
,
    v_emr_journal.episode_open
,
    v_emr_journal.encounter_started
,
    v_emr_journal.encounter_last_affirmed
,
    v_emr_journal.encounter_type
,
    v_emr_journal.encounter_l10n_type
   
FROM clin.v_emr_journal
  
WHERE (v_emr_journal.src_table <> 'clin.suppressed_hint'::text);

Index - Schema clin


Table: clin.allergy

patient allergy details

clin.allergy Structure
F-Key Name Type Description
clin._enum_allergy_type.pk fk_type
clin.episode.pk fk_episode
pk PRIMARY KEY
clin.encounter.pk fk_encounter

Table clin.allergy Inherits clin_root_item,

 

clin.allergy 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]))))
idx_clin_allergy_fk_encounter fk_encounter idx_clin_allergy_fk_episode fk_episode

Index - Schema clin


Table: clin.allergy_state

clin.allergy_state Structure
F-Key Name Type Description
pk PRIMARY KEY
clin.encounter.pk fk_encounter

Table clin.allergy_state Inherits audit_fields,

 

clin.allergy_state Constraints
Name Constraint
allergy_state_check CHECK (((has_allergy IS NULL) OR ((has_allergy IS NOT NULL) AND (last_confirmed IS NOT NULL))))
allergy_state_has_allergy_check CHECK ((has_allergy = ANY (ARRAY[NULL::integer, 0, 1])))
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.clin_aux_note

Other tables link to this if they need more free text fields.

clin.clin_aux_note Structure
F-Key Name Type Description
clin.episode.pk fk_episode
pk PRIMARY KEY
clin.encounter.pk fk_encounter

Table clin.clin_aux_note Inherits clin_root_item,

 

clin.clin_aux_note 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]))))
idx_clin_clin_aux_note_fk_encounter fk_encounter idx_clin_clin_aux_note_fk_episode fk_episode

Index - Schema clin


Table: clin.clin_diag

stores additional detail on those clin.clin_narrative rows where soap_cat=a that are true diagnoses, true diagnoses DO have a code from one of the coding systems

clin.clin_diag Structure
F-Key Name Type Description
clin.clin_narrative.pk fk_narrative UNIQUE
pk PRIMARY KEY

Table clin.clin_diag Inherits audit_fields,

 

clin.clin_diag Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_diag_laterality_check CHECK (((laterality = ANY (ARRAY['l'::bpchar, 'r'::bpchar, 'b'::bpchar, '?'::bpchar])) OR (laterality IS NULL)))
if_active_then_relevant CHECK (((is_active = false) OR ((is_active = true) AND (clinically_relevant = true))))

Index - Schema clin


Table: clin.clin_item_type

stores arbitrary types for tagging clinical items

clin.clin_item_type Structure
F-Key Name Type Description
code UNIQUE
pk PRIMARY KEY
type UNIQUE

Table clin.clin_item_type Inherits audit_fields,

 

clin.clin_item_type 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 clin


Table: clin.clin_narrative

Used to store clinical free text *not* associated with any other table. Used to implement a simple SOAP structure. Also other tags can be associated via link tables.

clin.clin_narrative Structure
F-Key Name Type Description
clin.episode.pk fk_episode
pk PRIMARY KEY
clin.encounter.pk fk_encounter

Table clin.clin_narrative Inherits clin_root_item,

 

clin.clin_narrative 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]))))
narrative_neither_null_nor_empty CHECK ((btrim(COALESCE(narrative, ''::text)) <> ''::text))

Tables referencing this one via Foreign Key Constraints:

idx_clin_clin_narrative_fk_encounter fk_encounter idx_clin_clin_narrative_fk_episode fk_episode idx_narrative_modified_by modified_by idx_narrative_soap_cat soap_cat) WHERE (soap_cat = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text])

Index - Schema clin


Table: clin.clin_root_item

ancestor table for clinical items of any kind, basic unit of clinical information, do *not* store data in here directly, use child tables, contains all the clinical narrative aggregated for full text search, ancestor for all tables that want to store clinical free text

clin.clin_root_item Structure
F-Key Name Type Description
clin.episode.pk fk_episode
pk_item PRIMARY KEY
clin.encounter.pk fk_encounter

Table clin.clin_root_item Inherits audit_fields,

 

clin.clin_root_item 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]))))
idx_cri_encounter fk_encounter idx_cri_episode fk_episode

Index - Schema clin


Table: clin.encounter

a clinical encounter between a person and the health care system

clin.encounter Structure
F-Key Name Type Description
clin.patient.fk_identity fk_patient
pk PRIMARY KEY
clin.encounter_type.pk fk_type
dem.org_unit.pk fk_location

Table clin.encounter Inherits audit_fields,

 

clin.encounter Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_enc_sane_duration CHECK ((last_affirmed >= started))
encounter_assessment_of_encounter_check CHECK ((btrim(COALESCE(assessment_of_encounter, 'xxxDEFAULTxxx'::text)) <> ''::text))
encounter_reason_for_encounter_check CHECK ((btrim(COALESCE(reason_for_encounter, 'xxxDEFAULTxxx'::text)) <> ''::text))

Tables referencing this one via Foreign Key Constraints:

idx_clin_encounter_fk_location fk_location idx_encounter_affirmed last_affirmed idx_encounter_modified_by modified_by idx_encounter_started started idx_pat_per_encounter fk_patient

Index - Schema clin


Table: clin.encounter_type

these are the types of encounter

clin.encounter_type Structure
F-Key Name Type Description
pk PRIMARY KEY
description UNIQUE

Tables referencing this one via Foreign Key Constraints:

Index - Schema clin


Table: clin.episode

Clinical episodes such as "Otitis media", "traffic accident 7/99", "Hepatitis B". This covers a range of time in which activity of illness was noted for the problem episode.description.

clin.episode Structure
F-Key Name Type Description
clin.health_issue.pk fk_health_issue
pk PRIMARY KEY
clin.encounter.pk fk_encounter

Table clin.episode Inherits audit_fields,

 

clin.episode Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
episode_sane_summary CHECK (gm.is_null_or_non_empty_string(summary))
sane_description CHECK ((gm.is_null_or_blank_string(description) IS FALSE))
valid_diagnostic_certainty_classification CHECK ((diagnostic_certainty_classification = ANY (ARRAY['A'::text, 'B'::text, 'C'::text, 'D'::text, NULL::text])))

Tables referencing this one via Foreign Key Constraints:

idx_episode_fk_encounter fk_encounter idx_episode_issue fk_health_issue idx_episode_modified_by modified_by idx_episode_with_issue fk_health_issue) WHERE (fk_health_issue IS NOT NULL idx_episode_without_issue fk_health_issue) WHERE (fk_health_issue IS NULL

Index - Schema clin


Table: clin.export_item

A table to hold binary data for patients intended for export as print/mail/fax/removable media/...

clin.export_item Structure
F-Key Name Type Description
blobs.doc_obj.pk fk_doc_obj UNIQUE
description UNIQUE#1
pk PRIMARY KEY
clin.patient.fk_identity fk_identity UNIQUE#1

 

clin.export_item Constraints
Name Constraint
clin_export_item_fk_obj_or_data CHECK ((((data IS NULL) AND (fk_doc_obj IS NOT NULL)) OR ((data IS NOT NULL) AND (fk_doc_obj IS NULL))))
clin_export_item_fk_obj_or_filename CHECK ((((filename IS NULL) AND (fk_doc_obj IS NOT NULL)) OR ((filename IS NOT NULL) AND (fk_doc_obj IS NULL))))
clin_export_item_sane_by CHECK ((length((created_by)::text) > 0))
clin_export_item_sane_data CHECK (((data IS NULL) OR (length(data) > 0)))
clin_export_item_sane_description CHECK ((gm.is_null_or_blank_string(description) IS FALSE))
clin_export_item_sane_designation CHECK ((gm.is_null_or_non_empty_string(designation) IS TRUE))
clin_export_item_sane_filename CHECK ((gm.is_null_or_non_empty_string(filename) IS TRUE))

Index - Schema clin


Table: clin.external_care

lists external care situations for patients

clin.external_care Structure
F-Key Name Type Description
clin.health_issue.pk fk_health_issue UNIQUE#1
pk PRIMARY KEY
clin.encounter.pk fk_encounter
dem.org_unit.pk fk_org_unit UNIQUE#1

Table clin.external_care Inherits audit_fields,

 

clin.external_care Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_ext_care_issue_xor_fk_issue CHECK ((((fk_health_issue IS NULL) AND (issue IS NOT NULL)) OR ((fk_health_issue IS NOT NULL) AND (issue IS NULL))))
clin_ext_care_sane_comment CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))
clin_ext_care_sane_issue CHECK ((gm.is_null_or_non_empty_string(issue) IS TRUE))
clin_ext_care_sane_provider CHECK ((gm.is_null_or_non_empty_string(provider) IS TRUE))
idx_external_care_fk_encounter fk_encounter idx_external_care_fk_health_issue fk_health_issue idx_external_care_fk_org_unit fk_org_unit

Index - Schema clin


Table: clin.family_history

This table stores family history items on persons not otherwise in the database.

clin.family_history Structure
F-Key Name Type Description
clin.fhx_relation_type.pk fk_relation_type
pk PRIMARY KEY
clin.encounter.pk fk_encounter
clin.episode.pk fk_episode

Table clin.family_history Inherits clin_root_item,

 

clin.family_history Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
c_family_history_sane_age_noted CHECK ((gm.is_null_or_non_empty_string(age_noted) IS TRUE))
c_family_history_sane_condition CHECK ((gm.is_null_or_blank_string(narrative) IS FALSE))
c_family_history_sane_name CHECK ((gm.is_null_or_non_empty_string(name_relative) 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]))))
narrative_neither_null_nor_empty CHECK ((btrim(COALESCE(narrative, ''::text)) <> ''::text))

Tables referencing this one via Foreign Key Constraints:

idx_clin_family_history_fk_encounter fk_encounter idx_clin_family_history_fk_episode fk_episode

Index - Schema clin


Table: clin.fhx_relation_type

Enumerates inter-person relations for family history linking.

clin.fhx_relation_type Structure
F-Key Name Type Description
pk PRIMARY KEY
description UNIQUE#1
is_genetic UNIQUE#1

Table clin.fhx_relation_type Inherits audit_fields,

 

clin.fhx_relation_type Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
c_fhx_relation_type_sane_desc CHECK ((gm.is_null_or_blank_string(description) IS FALSE))

Tables referencing this one via Foreign Key Constraints:

Index - Schema clin


Table: clin.form_data

holds the values used in form instances, for later re-use/validation

clin.form_data Structure
F-Key Name Type Description
clin.form_instances.pk fk_instance UNIQUE#1
public.form_fields.pk fk_form_field UNIQUE#1
pk PRIMARY KEY

Table clin.form_data Inherits audit_fields,

 

clin.form_data Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.form_instances

instances of forms, like a log of all processed forms

clin.form_instances Structure
F-Key Name Type Description
ref.paperwork_templates.pk fk_form_def
clin.episode.pk fk_episode
pk PRIMARY KEY
clin.encounter.pk fk_encounter

Table clin.form_instances Inherits clin_root_item,

 

clin.form_instances 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]))))
form_is_plan CHECK ((soap_cat = 'p'::text))

Tables referencing this one via Foreign Key Constraints:

idx_clin_form_instances_fk_encounter fk_encounter idx_clin_form_instances_fk_episode fk_episode

Index - Schema clin


Table: clin.health_issue

This is pretty much what others would call "Past Medical History" or "Foundational illness", eg. longer-ranging, underlying, encompassing issues with one's health such as "immunodeficiency", "type 2 diabetes". In Belgium it is called "problem". L.L.Weed includes lots of little things into it, we do not.

clin.health_issue Structure
F-Key Name Type Description
pk PRIMARY KEY
clin.encounter.pk fk_encounter

Table clin.health_issue Inherits audit_fields,

 

clin.health_issue Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
health_issue_laterality_check CHECK (((laterality)::text = ANY (ARRAY[(NULL::character varying)::text, ('s'::character varying)::text, ('d'::character varying)::text, ('sd'::character varying)::text, ('na'::character varying)::text])))
health_issue_sane_summary CHECK (gm.is_null_or_non_empty_string(summary))
issue_name_not_empty CHECK ((btrim(description) <> ''::text))
sane_grouping CHECK (gm.is_null_or_non_empty_string("grouping"))
valid_diagnostic_certainty_classification CHECK ((diagnostic_certainty_classification = ANY (ARRAY['A'::text, 'B'::text, 'C'::text, 'D'::text, NULL::text])))

Tables referencing this one via Foreign Key Constraints:

idx_health_issue_modified_by modified_by

Index - Schema clin


Table: clin.hospital_stay

collects data on hospitalisations of patients, reasons are linked via a link table

clin.hospital_stay Structure
F-Key Name Type Description
pk PRIMARY KEY
clin.encounter.pk fk_encounter
dem.org_unit.pk fk_org_unit
clin.episode.pk fk_episode

Table clin.hospital_stay Inherits clin_root_item,

 

clin.hospital_stay 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]))))
sane_duration CHECK (((discharge IS NULL) OR (discharge > clin_when)))
sane_hospital CHECK (gm.is_null_or_non_empty_string(narrative))

Tables referencing this one via Foreign Key Constraints:

idx_clin_hospital_stay_fk_encounter fk_encounter idx_clin_hospital_stay_fk_episode fk_episode

Index - Schema clin


Table: clin.incoming_data_unmatchable

this table holds test results that could not be matched to any patient, it is intended to prevent overflow of incoming_data_unmatched with unmatchable data

clin.incoming_data_unmatchable Structure
F-Key Name Type Description
pk PRIMARY KEY

Table clin.incoming_data_unmatchable Inherits audit_fields,

 

clin.incoming_data_unmatchable Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.incoming_data_unmatched

this table holds incoming data (lab results, documents) that could not be matched to one single patient automatically, it is intended to facilitate manual matching, - use "modified_when" for import time

clin.incoming_data_unmatched Structure
F-Key Name Type Description
dem.staff.pk fk_provider_disambiguated
clin.patient.fk_identity fk_identity_disambiguated
pk PRIMARY KEY

Table clin.incoming_data_unmatched Inherits audit_fields,

 

clin.incoming_data_unmatched Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
unmatched_data_sane_comment CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))

Index - Schema clin


Table: clin.lab_request

test request metadata

clin.lab_request Structure
F-Key Name Type Description
dem.identity.pk fk_requestor
clin.episode.pk fk_episode
pk PRIMARY KEY
request_id UNIQUE#1
clin.test_org.pk fk_test_org UNIQUE#1
clin.encounter.pk fk_encounter

Table clin.lab_request Inherits clin_root_item,

 

clin.lab_request Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_lab_req_sane_test_org_note CHECK ((gm.is_null_or_non_empty_string(note_test_org) 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]))))
lab_request_request_id_check CHECK ((btrim(request_id) <> ''::text))
lab_request_request_status_check CHECK ((request_status = ANY (ARRAY['pending'::text, 'preliminary'::text, 'partial'::text, 'final'::text])))

Tables referencing this one via Foreign Key Constraints:

idx_clin_lab_request_fk_encounter fk_encounter idx_clin_lab_request_fk_episode fk_episode

Index - Schema clin


Table: clin.lnk_code2aoe

Links codes to encounter.aoe.

clin.lnk_code2aoe Structure
F-Key Name Type Description
fk_generic_code UNIQUE#1
clin.encounter.pk fk_item UNIQUE#1
pk PRIMARY KEY

Table clin.lnk_code2aoe Inherits lnk_code2item_root,

 

clin.lnk_code2aoe Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
idx_c_lc2aoe_fk_item fk_item

Index - Schema clin


Table: clin.lnk_code2episode

Links codes to episodes.

clin.lnk_code2episode Structure
F-Key Name Type Description
pk PRIMARY KEY
clin.episode.pk fk_item UNIQUE#1
fk_generic_code UNIQUE#1

Table clin.lnk_code2episode Inherits lnk_code2item_root,

 

clin.lnk_code2episode Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
idx_c_lc2epi_fk_item fk_item

Index - Schema clin


Table: clin.lnk_code2fhx

Links codes to family history items.

clin.lnk_code2fhx Structure
F-Key Name Type Description
fk_generic_code UNIQUE#1
clin.family_history.pk fk_item UNIQUE#1
pk PRIMARY KEY

Table clin.lnk_code2fhx Inherits lnk_code2item_root,

 

clin.lnk_code2fhx Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
idx_c_lc2fhx_fk_item fk_item

Index - Schema clin


Table: clin.lnk_code2h_issue

Links codes to health issues.

clin.lnk_code2h_issue Structure
F-Key Name Type Description
fk_generic_code UNIQUE#1
pk PRIMARY KEY
clin.health_issue.pk fk_item UNIQUE#1

Table clin.lnk_code2h_issue Inherits lnk_code2item_root,

 

clin.lnk_code2h_issue Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
idx_c_lc2iss_fk_item fk_item

Index - Schema clin


Table: clin.lnk_code2item_root

The parent table of all tables linking codes to EMR structures. Coding tables check this table for existence of their PK in .fk_generic_code in order to prevent cascading DELETEs/UPDATEs from breaking referential integrity. EMR structure tables foreign key into children of this table in order to link structures to codes.

clin.lnk_code2item_root Structure
F-Key Name Type Description
pk_lnk_code2item PRIMARY KEY

Table clin.lnk_code2item_root Inherits audit_fields,

 

clin.lnk_code2item_root Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.lnk_code2narrative

Links codes to SOAP narrative.

clin.lnk_code2narrative Structure
F-Key Name Type Description
fk_generic_code UNIQUE#1
pk PRIMARY KEY
clin.clin_narrative.pk fk_item UNIQUE#1

Table clin.lnk_code2narrative Inherits lnk_code2item_root,

 

clin.lnk_code2narrative Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
idx_c_lc2narr_fk_item fk_item

Index - Schema clin


Table: clin.lnk_code2procedure

Links codes to procedures. OPS comes to mind.

clin.lnk_code2procedure Structure
F-Key Name Type Description
pk PRIMARY KEY
clin.procedure.pk fk_item UNIQUE#1
fk_generic_code UNIQUE#1

Table clin.lnk_code2procedure Inherits lnk_code2item_root,

 

clin.lnk_code2procedure Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
idx_c_lc2proc_fk_item fk_item

Index - Schema clin


Table: clin.lnk_code2rfe

Links codes to encounters.

clin.lnk_code2rfe Structure
F-Key Name Type Description
fk_generic_code UNIQUE#1
pk PRIMARY KEY
clin.encounter.pk fk_item UNIQUE#1

Table clin.lnk_code2rfe Inherits lnk_code2item_root,

 

clin.lnk_code2rfe Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
idx_c_lc2rfe_fk_item fk_item

Index - Schema clin


Table: clin.lnk_code2tst_pnl

Links codes to test panels.

clin.lnk_code2tst_pnl Structure
F-Key Name Type Description
fk_generic_code UNIQUE#1
pk PRIMARY KEY
clin.test_panel.pk fk_item UNIQUE#1

Table clin.lnk_code2tst_pnl Inherits lnk_code2item_root,

 

clin.lnk_code2tst_pnl Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
idx_c_lc2tp_fk_item fk_item

Index - Schema clin


Table: clin.lnk_constraint2vacc_course

links constraints to courses

clin.lnk_constraint2vacc_course Structure
F-Key Name Type Description
clin.vaccination_course_constraint.pk fk_constraint UNIQUE#1
clin.vaccination_course.pk fk_vaccination_course UNIQUE#1
pk PRIMARY KEY

Table clin.lnk_constraint2vacc_course Inherits audit_fields,

 

clin.lnk_constraint2vacc_course Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.lnk_loinc2test_panel

Links LOINC codes to test panels which thusly become part of said panel.

clin.lnk_loinc2test_panel Structure
F-Key Name Type Description
pk PRIMARY KEY
clin.test_panel.pk fk_test_panel

Table clin.lnk_loinc2test_panel Inherits audit_fields,

 

clin.lnk_loinc2test_panel Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_ll2tp_sane_loinc CHECK ((gm.is_null_or_blank_string(loinc) IS FALSE))

Index - Schema clin


Table: clin.lnk_pat2vaccination_course

links patients to vaccination courses they are actually on, this allows for per-patient selection of courses to be followed, eg. children at different ages may be on different vaccination courses or some people are on a course due to a trip abroad while most others are not

clin.lnk_pat2vaccination_course Structure
F-Key Name Type Description
pk PRIMARY KEY
clin.patient.fk_identity fk_patient UNIQUE#1
clin.vaccination_course.pk fk_course UNIQUE#1

Table clin.lnk_pat2vaccination_course Inherits audit_fields,

 

clin.lnk_pat2vaccination_course Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.lnk_substance2episode

clin.lnk_substance2episode Structure
F-Key Name Type Description
clin.episode.pk fk_episode
clin.substance_intake.pk fk_substance
pk PRIMARY KEY

Table clin.lnk_substance2episode Inherits audit_fields,

 

clin.lnk_substance2episode Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.lnk_tst2norm

links test result evaluation norms to tests

clin.lnk_tst2norm Structure
F-Key Name Type Description
id PRIMARY KEY
clin.test_type.pk id_test UNIQUE#1
id_norm UNIQUE#1

Table clin.lnk_tst2norm Inherits audit_fields,

 

clin.lnk_tst2norm Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.lnk_type2item

allow to link many-to-many between clin.clin_root_item and clin.clin_item_type

clin.lnk_type2item Structure
F-Key Name Type Description
pk PRIMARY KEY
fk_item UNIQUE#1
clin.clin_item_type.pk fk_type UNIQUE#1

Table clin.lnk_type2item Inherits audit_fields,

 

clin.lnk_type2item Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.lnk_vaccination_course2schedule

this table links vaccination courses for a single epitope into schedules defined and recommended by a vaccination council or similar entity

clin.lnk_vaccination_course2schedule Structure
F-Key Name Type Description
clin.vaccination_course.pk fk_course UNIQUE
pk PRIMARY KEY
clin.vaccination_schedule.pk fk_schedule

Table clin.lnk_vaccination_course2schedule Inherits audit_fields,

 

clin.lnk_vaccination_course2schedule Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.meta_test_type

this table merges test types from various test orgs which are intended to measure the same value but have differing names into one logical test type, this is not intended to be used for aggregating semantically different test types into "profiles"

clin.meta_test_type Structure
F-Key Name Type Description
abbrev UNIQUE#1
name UNIQUE#1
pk PRIMARY KEY

Tables referencing this one via Foreign Key Constraints:

Index - Schema clin


Table: clin.patient

A table to hold unique-per-identity *clinical* items, such as Expected Due Date.

clin.patient Structure
F-Key Name Type Description
dem.identity.pk fk_identity UNIQUE
pk PRIMARY KEY

Table clin.patient Inherits audit_fields,

 

clin.patient Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_patient_sane_edc CHECK (((edc IS NULL) OR ((clin.get_dod(fk_identity) IS NULL) AND ((clin.get_dob(fk_identity) IS NULL) OR (edc > (clin.get_dob(fk_identity) + '5 years'::interval))))))

Tables referencing this one via Foreign Key Constraints:

Index - Schema clin


Table: clin.procedure

This table holds procedure/operations performed on the patient both in hospital or in community care.

clin.procedure Structure
F-Key Name Type Description
clin.hospital_stay.pk fk_hospital_stay
clin.encounter.pk fk_encounter
pk PRIMARY KEY
dem.org_unit.pk fk_org_unit
clin.episode.pk fk_episode
blobs.doc_med.pk fk_doc

Table clin.procedure Inherits clin_root_item,

 

clin.procedure Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_procedure_lnk_org_or_stay CHECK ((((fk_hospital_stay IS NULL) AND (fk_org_unit IS NOT NULL)) OR ((fk_hospital_stay IS NOT NULL) AND (fk_org_unit IS NULL))))
clin_procedure_sane_comment CHECK ((gm.is_null_or_non_empty_string(comment) 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]))))
procedure_sane_end CHECK (((clin_end IS NULL) OR (clin_end >= clin_when)))
sane_procedure CHECK ((gm.is_null_or_blank_string(narrative) IS FALSE))
sane_soap_cat CHECK ((soap_cat = ANY (ARRAY['a'::text, 'p'::text])))

Tables referencing this one via Foreign Key Constraints:

idx_clin_procedure_fk_encounter fk_encounter idx_clin_procedure_fk_episode fk_episode

Index - Schema clin


Table: clin.review_root

this table tracks whether a particular clinical item was reviewed by a clinician or not

clin.review_root Structure
F-Key Name Type Description
fk_reviewed_row UNIQUE#1
pk PRIMARY KEY
dem.staff.pk fk_reviewer UNIQUE#1

Table clin.review_root Inherits audit_fields,

 

clin.review_root Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Index - Schema clin


Table: clin.reviewed_test_results

review table for test results

clin.reviewed_test_results Structure
F-Key Name Type Description
pk PRIMARY KEY
clin.test_result.pk fk_reviewed_row UNIQUE#1 UNIQUE
dem.staff.pk fk_reviewer UNIQUE#1

Table clin.reviewed_test_results Inherits review_root,

 

clin.reviewed_test_results Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
idx_rtr_fk_reviewer fk_reviewer

Index - Schema clin


Table: clin.soap_cat_ranks

clin.soap_cat_ranks Structure
F-Key Name Type Description
pk PRIMARY KEY

 

clin.soap_cat_ranks Constraints
Name Constraint
clin_soap_cat_ranks_sane_cats CHECK (((soap_cat IS NULL) OR (soap_cat = ANY (ARRAY['s'::bpchar, 'o'::bpchar, 'a'::bpchar, 'p'::bpchar, 'u'::bpchar]))))
clin_soap_cat_ranks_sane_ranks CHECK ((rank = ANY (ARRAY[1, 2, 3, 4, 5, 6])))

Index - Schema clin


Table: clin.substance_intake

The substances a patient is actually currently taking.

clin.substance_intake Structure
F-Key Name Type Description
clin.encounter.pk fk_encounter
pk PRIMARY KEY
clin.episode.pk fk_episode
ref.lnk_dose2drug.pk fk_drug_component

Table clin.substance_intake Inherits clin_root_item,

 

clin.substance_intake Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_patient_sane_use_type CHECK (((harmful_use_type IS NULL) OR ((harmful_use_type >= 0) AND (harmful_use_type <= 3))))
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]))))
clin_substance_intake_sane_start_comment CHECK (gm.is_null_or_non_empty_string(comment_on_start))
discontinued_after_started CHECK (((harmful_use_type IS NOT NULL) OR (clin_when IS NULL) OR (discontinued IS NULL) OR ((discontinued >= clin_when) AND (discontinued <= now()))))
medication_is_plan CHECK ((soap_cat = 'p'::text))
sane_aim CHECK ((gm.is_null_or_non_empty_string(aim) IS TRUE))
sane_discontinue_reason CHECK ((((discontinued IS NULL) AND (discontinue_reason IS NULL)) OR ((discontinued IS NOT NULL) AND (gm.is_null_or_non_empty_string(discontinue_reason) IS TRUE))))
sane_schedule CHECK ((gm.is_null_or_non_empty_string(schedule) IS TRUE))

Tables referencing this one via Foreign Key Constraints:

idx_c_subst_int_fk_drug_comp fk_drug_component idx_clin_substance_intake_fk_encounter fk_encounter idx_clin_substance_intake_fk_episode fk_episode

Index - Schema clin


Table: clin.suppressed_hint

A table to hold hints suppressed per patient

clin.suppressed_hint Structure
F-Key Name Type Description
ref.auto_hint.pk fk_hint
pk PRIMARY KEY
clin.encounter.pk fk_encounter

Table clin.suppressed_hint Inherits audit_fields,

 

clin.suppressed_hint Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_suppressed_hint_sane_by CHECK ((length((suppressed_by)::text) > 0))
clin_suppressed_hint_sane_md5 CHECK ((gm.is_null_or_blank_string(md5_sum) IS FALSE))
clin_suppressed_hint_sane_rationale CHECK ((gm.is_null_or_blank_string(rationale) IS FALSE))
idx_suppressed_hint_fk_encounter fk_encounter idx_suppressed_hint_fk_hint fk_hint

Index - Schema clin


Table: clin.test_org

organisation providing results

clin.test_org Structure
F-Key Name Type Description
dem.identity.pk fk_adm_contact
dem.identity.pk fk_med_contact
pk PRIMARY KEY
dem.org_unit.pk fk_org_unit UNIQUE

Table clin.test_org Inherits audit_fields,

 

clin.test_org Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
sane_comment CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))
sane_contact CHECK ((gm.is_null_or_non_empty_string(contact) IS TRUE))

Tables referencing this one via Foreign Key Constraints:

Index - Schema clin


Table: clin.test_panel

Panels of tests. The same test can appear in several panels.

clin.test_panel Structure
F-Key Name Type Description
pk PRIMARY KEY

Table clin.test_panel Inherits audit_fields,

 

clin.test_panel Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))
clin_test_panel_sane_cmt CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE))
clin_test_panel_sane_desc CHECK ((gm.is_null_or_blank_string(description) IS FALSE))

Tables referencing this one via Foreign Key Constraints:

Index - Schema clin


Table: clin.test_result

the results of a single measurement

clin.test_result Structure
F-Key Name Type Description
clin.encounter.pk fk_encounter
pk PRIMARY KEY
dem.staff.pk fk_intended_reviewer
clin.test_type.pk fk_type
clin.episode.pk fk_episode
clin.lab_request.pk fk_request

Table clin.test_result Inherits clin_root_item,

 

clin.test_result 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]))))
clin_test_result_sane_source_data CHECK (gm.is_null_or_non_empty_string(source_data))
clin_test_result_sane_status CHECK (gm.is_null_or_non_empty_string(status))
clin_test_result_sane_val_grouping CHECK (gm.is_null_or_non_empty_string(val_grouping))
numval_needs_unit CHECK ((((val_num IS NOT NULL) AND (btrim(COALESCE(val_unit, ''::text)) <> ''::text)) OR (val_num IS NULL)))
test_result_check CHECK (((val_num IS NOT NULL) OR (val_alpha IS NOT NULL) OR ((val_num IS NULL) AND (val_alpha <> ''::text) AND (val_alpha IS NOT NULL))))

Tables referencing this one via Foreign Key Constraints:

idx_clin_test_result_fk_encounter fk_encounter idx_clin_test_result_fk_episode fk_episode idx_test_result_fk_type fk_type idx_test_result_status status idx_test_result_unit val_unit

Index - Schema clin


Table: clin.test_type

measurement type, like a "method" in a lab

clin.test_type Structure
F-Key Name Type Description
pk PRIMARY KEY
clin.meta_test_type.pk fk_meta_test_type
name UNIQUE#2
abbrev UNIQUE#1
clin.test_org.pk fk_test_org UNIQUE#1 UNIQUE#2

Table clin.test_type Inherits audit_fields,

 

clin.test_type Constraints
Name Constraint
audit_audit_fields_sane_modified_when CHECK (((modified_when <= clock_timestamp()) IS TRUE))

Tables referencing this one via Foreign Key Constraints:

idx_test_type_fk_meta_test_type fk_meta_test_type idx_test_type_fk_test_org fk_test_org idx_test_type_loinc loinc) WHERE (loinc IS NOT NULL

Index - Schema clin


View: clin.v_candidate_diagnoses

Candidates for diagnoses.

clin.v_candidate_diagnoses Structure
F-Key Name Type Description
SELECT (
SELECT c_enc.fk_patient
           
  FROM clin.encounter c_enc
          
 WHERE (c_enc.pk = c_hi.fk_encounter)
) AS pk_patient
,
    
(c_hi.description || COALESCE
     (
           (
                 (
                    ' ('::text || 
                             (c_hi.laterality)::text
                       ) || 
               ')'::text
           )
           ,''::text
     )
) AS diagnosis
,
    c_hi.is_confidential AS explicitely_confidential
,
    c_hi.diagnostic_certainty_classification
,
    'clin.health_issue'::text AS source
   
FROM clin.health_issue c_hi

UNION ALL
 
SELECT (
SELECT c_enc.fk_patient
           
  FROM clin.encounter c_enc
          
 WHERE (c_enc.pk = c_epi.fk_encounter)
) AS pk_patient
,
    c_epi.description AS diagnosis
,
    COALESCE
(
     (
      SELECT c_hi.is_confidential
           
        FROM clin.health_issue c_hi
          
       WHERE (c_hi.pk = c_epi.fk_health_issue)
     )
     , false
) AS explicitely_confidential
,
    c_epi.diagnostic_certainty_classification
,
    'clin.episode'::text AS source
   
FROM clin.episode c_epi
  
WHERE (c_epi.is_open IS TRUE)
UNION ALL
 
SELECT c_enc.fk_patient AS pk_patient
,
    c_enc.assessment_of_encounter AS diagnosis
,
    false AS explicitely_confidential
,
    NULL::text AS diagnostic_certainty_classification
,
    'clin.encounter'::text AS source
   
FROM clin.encounter c_enc
  
WHERE (
     (c_enc.assessment_of_encounter IS NOT NULL)
   AND (c_enc.pk IN 
           (
            SELECT c_cri.fk_encounter
           
              FROM clin.clin_root_item c_cri
          
             WHERE (c_cri.fk_episode IN 
                       (
                        SELECT c_epi.pk
                   
                          FROM clin.episode c_epi
                  
                         WHERE (c_epi.is_open IS TRUE)
                       )
                 )
           )
     )
)
UNION ALL
 
SELECT (
SELECT c_enc.fk_patient
           
  FROM clin.encounter c_enc
          
 WHERE (c_enc.pk = c_cn.fk_encounter)
) AS pk_patient
,
    c_cn.narrative AS diagnosis
,
    false AS explicitely_confidential
,
    NULL::text AS diagnostic_certainty_classification
,
    'clin.clin_narrative'::text AS source
   
FROM clin.clin_narrative c_cn
  
WHERE (
     (c_cn.soap_cat = 'a'::text)
   AND (c_cn.fk_episode IN 
           (
            SELECT c_epi.pk
           
              FROM clin.episode c_epi
          
             WHERE (c_epi.is_open IS TRUE)
           )
     )
);

Index - Schema clin


View: clin.v_edc_journal

clin.v_edc_journal Structure
F-Key Name Type Description
SELECT c_p.fk_identity AS pk_patient
,
    c_p.modified_when
,
    c_p.modified_when AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_p.modified_by)
     )
     , (
           ('<'::text || 
                 (c_p.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    's'::text AS soap_cat
,
    
(_
     ('EDC'::text) || to_char
     (
           (c_p.edc)::timestamp with time zone
           ,': YYYY Mon DD'::text
     )
) AS narrative
,
    
(
SELECT c_e.pk
           
  FROM clin.encounter c_e
          
 WHERE (c_e.fk_patient = c_p.fk_identity)
          
ORDER BY c_e.started DESC
         LIMIT 1
) AS pk_encounter
,
    NULL::integer AS pk_episode
,
    NULL::integer AS pk_health_issue
,
    c_p.pk AS src_pk
,
    'clin.patient'::text AS src_table
,
    c_p.row_version
,
    NULL::text AS health_issue
,
    NULL::text AS issue_laterality
,
    NULL::boolean AS issue_active
,
    NULL::boolean AS issue_clinically_relevant
,
    NULL::boolean AS issue_confidential
,
    NULL::text AS episode
,
    NULL::boolean AS episode_open
,
    NULL::timestamp with time zone AS encounter_started
,
    NULL::timestamp with time zone AS encounter_last_affirmed
,
    NULL::text AS encounter_type
,
    NULL::text AS encounter_l10n_type
   
FROM clin.patient c_p
  
WHERE (c_p.edc IS NOT NULL);

Index - Schema clin


View: clin.v_emr_journal

Clinical patient data formatted into one string per clinical entity even if it constains several user- visible fields. Mainly useful for display as a simple EMR journal.

clin.v_emr_journal Structure
F-Key Name Type Description
SELECT v_pat_narrative_journal.pk_patient
,
    v_pat_narrative_journal.modified_when
,
    v_pat_narrative_journal.clin_when
,
    v_pat_narrative_journal.modified_by
,
    v_pat_narrative_journal.soap_cat
,
    v_pat_narrative_journal.narrative
,
    v_pat_narrative_journal.pk_encounter
,
    v_pat_narrative_journal.pk_episode
,
    v_pat_narrative_journal.pk_health_issue
,
    v_pat_narrative_journal.src_pk
,
    v_pat_narrative_journal.src_table
,
    v_pat_narrative_journal.row_version
,
    v_pat_narrative_journal.health_issue
,
    v_pat_narrative_journal.issue_laterality
,
    v_pat_narrative_journal.issue_active
,
    v_pat_narrative_journal.issue_clinically_relevant
,
    v_pat_narrative_journal.issue_confidential
,
    v_pat_narrative_journal.episode
,
    v_pat_narrative_journal.episode_open
,
    v_pat_narrative_journal.encounter_started
,
    v_pat_narrative_journal.encounter_last_affirmed
,
    v_pat_narrative_journal.encounter_type
,
    v_pat_narrative_journal.encounter_l10n_type
   
FROM clin.v_pat_narrative_journal

UNION ALL
 
SELECT v_health_issues_journal.pk_patient
,
    v_health_issues_journal.modified_when
,
    v_health_issues_journal.clin_when
,
    v_health_issues_journal.modified_by
,
    v_health_issues_journal.soap_cat
,
    v_health_issues_journal.narrative
,
    v_health_issues_journal.pk_encounter
,
    v_health_issues_journal.pk_episode
,
    v_health_issues_journal.pk_health_issue
,
    v_health_issues_journal.src_pk
,
    v_health_issues_journal.src_table
,
    v_health_issues_journal.row_version
,
    v_health_issues_journal.health_issue
,
    v_health_issues_journal.issue_laterality
,
    v_health_issues_journal.issue_active
,
    v_health_issues_journal.issue_clinically_relevant
,
    v_health_issues_journal.issue_confidential
,
    v_health_issues_journal.episode
,
    v_health_issues_journal.episode_open
,
    v_health_issues_journal.encounter_started
,
    v_health_issues_journal.encounter_last_affirmed
,
    v_health_issues_journal.encounter_type
,
    v_health_issues_journal.encounter_l10n_type
   
FROM clin.v_health_issues_journal

UNION ALL
 
SELECT v_pat_encounters_journal.pk_patient
,
    v_pat_encounters_journal.modified_when
,
    v_pat_encounters_journal.clin_when
,
    v_pat_encounters_journal.modified_by
,
    v_pat_encounters_journal.soap_cat
,
    v_pat_encounters_journal.narrative
,
    v_pat_encounters_journal.pk_encounter
,
    v_pat_encounters_journal.pk_episode
,
    v_pat_encounters_journal.pk_health_issue
,
    v_pat_encounters_journal.src_pk
,
    v_pat_encounters_journal.src_table
,
    v_pat_encounters_journal.row_version
,
    v_pat_encounters_journal.health_issue
,
    v_pat_encounters_journal.issue_laterality
,
    v_pat_encounters_journal.issue_active
,
    v_pat_encounters_journal.issue_clinically_relevant
,
    v_pat_encounters_journal.issue_confidential
,
    v_pat_encounters_journal.episode
,
    v_pat_encounters_journal.episode_open
,
    v_pat_encounters_journal.encounter_started
,
    v_pat_encounters_journal.encounter_last_affirmed
,
    v_pat_encounters_journal.encounter_type
,
    v_pat_encounters_journal.encounter_l10n_type
   
FROM clin.v_pat_encounters_journal

UNION ALL
 
SELECT v_pat_episodes_journal.pk_patient
,
    v_pat_episodes_journal.modified_when
,
    v_pat_episodes_journal.clin_when
,
    v_pat_episodes_journal.modified_by
,
    v_pat_episodes_journal.soap_cat
,
    v_pat_episodes_journal.narrative
,
    v_pat_episodes_journal.pk_encounter
,
    v_pat_episodes_journal.pk_episode
,
    v_pat_episodes_journal.pk_health_issue
,
    v_pat_episodes_journal.src_pk
,
    v_pat_episodes_journal.src_table
,
    v_pat_episodes_journal.row_version
,
    v_pat_episodes_journal.health_issue
,
    v_pat_episodes_journal.issue_laterality
,
    v_pat_episodes_journal.issue_active
,
    v_pat_episodes_journal.issue_clinically_relevant
,
    v_pat_episodes_journal.issue_confidential
,
    v_pat_episodes_journal.episode
,
    v_pat_episodes_journal.episode_open
,
    v_pat_episodes_journal.encounter_started
,
    v_pat_episodes_journal.encounter_last_affirmed
,
    v_pat_episodes_journal.encounter_type
,
    v_pat_episodes_journal.encounter_l10n_type
   
FROM clin.v_pat_episodes_journal

UNION ALL
 
SELECT v_family_history_journal.pk_patient
,
    v_family_history_journal.modified_when
,
    v_family_history_journal.clin_when
,
    v_family_history_journal.modified_by
,
    v_family_history_journal.soap_cat
,
    v_family_history_journal.narrative
,
    v_family_history_journal.pk_encounter
,
    v_family_history_journal.pk_episode
,
    v_family_history_journal.pk_health_issue
,
    v_family_history_journal.src_pk
,
    v_family_history_journal.src_table
,
    v_family_history_journal.row_version
,
    v_family_history_journal.health_issue
,
    v_family_history_journal.issue_laterality
,
    v_family_history_journal.issue_active
,
    v_family_history_journal.issue_clinically_relevant
,
    v_family_history_journal.issue_confidential
,
    v_family_history_journal.episode
,
    v_family_history_journal.episode_open
,
    v_family_history_journal.encounter_started
,
    v_family_history_journal.encounter_last_affirmed
,
    v_family_history_journal.encounter_type
,
    v_family_history_journal.encounter_l10n_type
   
FROM clin.v_family_history_journal

UNION ALL
 
SELECT v_pat_allergies_journal.pk_patient
,
    v_pat_allergies_journal.modified_when
,
    v_pat_allergies_journal.clin_when
,
    v_pat_allergies_journal.modified_by
,
    v_pat_allergies_journal.soap_cat
,
    v_pat_allergies_journal.narrative
,
    v_pat_allergies_journal.pk_encounter
,
    v_pat_allergies_journal.pk_episode
,
    v_pat_allergies_journal.pk_health_issue
,
    v_pat_allergies_journal.src_pk
,
    v_pat_allergies_journal.src_table
,
    v_pat_allergies_journal.row_version
,
    v_pat_allergies_journal.health_issue
,
    v_pat_allergies_journal.issue_laterality
,
    v_pat_allergies_journal.issue_active
,
    v_pat_allergies_journal.issue_clinically_relevant
,
    v_pat_allergies_journal.issue_confidential
,
    v_pat_allergies_journal.episode
,
    v_pat_allergies_journal.episode_open
,
    v_pat_allergies_journal.encounter_started
,
    v_pat_allergies_journal.encounter_last_affirmed
,
    v_pat_allergies_journal.encounter_type
,
    v_pat_allergies_journal.encounter_l10n_type
   
FROM clin.v_pat_allergies_journal

UNION ALL
 
SELECT v_pat_allergy_state_journal.pk_patient
,
    v_pat_allergy_state_journal.modified_when
,
    v_pat_allergy_state_journal.clin_when
,
    v_pat_allergy_state_journal.modified_by
,
    v_pat_allergy_state_journal.soap_cat
,
    v_pat_allergy_state_journal.narrative
,
    v_pat_allergy_state_journal.pk_encounter
,
    v_pat_allergy_state_journal.pk_episode
,
    v_pat_allergy_state_journal.pk_health_issue
,
    v_pat_allergy_state_journal.src_pk
,
    v_pat_allergy_state_journal.src_table
,
    v_pat_allergy_state_journal.row_version
,
    v_pat_allergy_state_journal.health_issue
,
    v_pat_allergy_state_journal.issue_laterality
,
    v_pat_allergy_state_journal.issue_active
,
    v_pat_allergy_state_journal.issue_clinically_relevant
,
    v_pat_allergy_state_journal.issue_confidential
,
    v_pat_allergy_state_journal.episode
,
    v_pat_allergy_state_journal.episode_open
,
    v_pat_allergy_state_journal.encounter_started
,
    v_pat_allergy_state_journal.encounter_last_affirmed
,
    v_pat_allergy_state_journal.encounter_type
,
    v_pat_allergy_state_journal.encounter_l10n_type
   
FROM clin.v_pat_allergy_state_journal

UNION ALL
 
SELECT v_test_results_journal.pk_patient
,
    v_test_results_journal.modified_when
,
    v_test_results_journal.clin_when
,
    v_test_results_journal.modified_by
,
    v_test_results_journal.soap_cat
,
    v_test_results_journal.narrative
,
    v_test_results_journal.pk_encounter
,
    v_test_results_journal.pk_episode
,
    v_test_results_journal.pk_health_issue
,
    v_test_results_journal.src_pk
,
    v_test_results_journal.src_table
,
    v_test_results_journal.row_version
,
    v_test_results_journal.health_issue
,
    v_test_results_journal.issue_laterality
,
    v_test_results_journal.issue_active
,
    v_test_results_journal.issue_clinically_relevant
,
    v_test_results_journal.issue_confidential
,
    v_test_results_journal.episode
,
    v_test_results_journal.episode_open
,
    v_test_results_journal.encounter_started
,
    v_test_results_journal.encounter_last_affirmed
,
    v_test_results_journal.encounter_type
,
    v_test_results_journal.encounter_l10n_type
   
FROM clin.v_test_results_journal

UNION ALL
 
SELECT v_hospital_stays_journal.pk_patient
,
    v_hospital_stays_journal.modified_when
,
    v_hospital_stays_journal.clin_when
,
    v_hospital_stays_journal.modified_by
,
    v_hospital_stays_journal.soap_cat
,
    v_hospital_stays_journal.narrative
,
    v_hospital_stays_journal.pk_encounter
,
    v_hospital_stays_journal.pk_episode
,
    v_hospital_stays_journal.pk_health_issue
,
    v_hospital_stays_journal.src_pk
,
    v_hospital_stays_journal.src_table
,
    v_hospital_stays_journal.row_version
,
    v_hospital_stays_journal.health_issue
,
    v_hospital_stays_journal.issue_laterality
,
    v_hospital_stays_journal.issue_active
,
    v_hospital_stays_journal.issue_clinically_relevant
,
    v_hospital_stays_journal.issue_confidential
,
    v_hospital_stays_journal.episode
,
    v_hospital_stays_journal.episode_open
,
    v_hospital_stays_journal.encounter_started
,
    v_hospital_stays_journal.encounter_last_affirmed
,
    v_hospital_stays_journal.encounter_type
,
    v_hospital_stays_journal.encounter_l10n_type
   
FROM clin.v_hospital_stays_journal

UNION ALL
 
SELECT v_doc_med_journal.pk_patient
,
    v_doc_med_journal.modified_when
,
    v_doc_med_journal.clin_when
,
    v_doc_med_journal.modified_by
,
    v_doc_med_journal.soap_cat
,
    v_doc_med_journal.narrative
,
    v_doc_med_journal.pk_encounter
,
    v_doc_med_journal.pk_episode
,
    v_doc_med_journal.pk_health_issue
,
    v_doc_med_journal.src_pk
,
    v_doc_med_journal.src_table
,
    v_doc_med_journal.row_version
,
    v_doc_med_journal.health_issue
,
    v_doc_med_journal.issue_laterality
,
    v_doc_med_journal.issue_active
,
    v_doc_med_journal.issue_clinically_relevant
,
    v_doc_med_journal.issue_confidential
,
    v_doc_med_journal.episode
,
    v_doc_med_journal.episode_open
,
    v_doc_med_journal.encounter_started
,
    v_doc_med_journal.encounter_last_affirmed
,
    v_doc_med_journal.encounter_type
,
    v_doc_med_journal.encounter_l10n_type
   
FROM blobs.v_doc_med_journal

UNION ALL
 
SELECT v_substance_intake_journal.pk_patient
,
    v_substance_intake_journal.modified_when
,
    v_substance_intake_journal.clin_when
,
    v_substance_intake_journal.modified_by
,
    v_substance_intake_journal.soap_cat
,
    v_substance_intake_journal.narrative
,
    v_substance_intake_journal.pk_encounter
,
    v_substance_intake_journal.pk_episode
,
    v_substance_intake_journal.pk_health_issue
,
    v_substance_intake_journal.src_pk
,
    v_substance_intake_journal.src_table
,
    v_substance_intake_journal.row_version
,
    v_substance_intake_journal.health_issue
,
    v_substance_intake_journal.issue_laterality
,
    v_substance_intake_journal.issue_active
,
    v_substance_intake_journal.issue_clinically_relevant
,
    v_substance_intake_journal.issue_confidential
,
    v_substance_intake_journal.episode
,
    v_substance_intake_journal.episode_open
,
    v_substance_intake_journal.encounter_started
,
    v_substance_intake_journal.encounter_last_affirmed
,
    v_substance_intake_journal.encounter_type
,
    v_substance_intake_journal.encounter_l10n_type
   
FROM clin.v_substance_intake_journal

UNION ALL
 
SELECT v_procedures_journal.pk_patient
,
    v_procedures_journal.modified_when
,
    v_procedures_journal.clin_when
,
    v_procedures_journal.modified_by
,
    v_procedures_journal.soap_cat
,
    v_procedures_journal.narrative
,
    v_procedures_journal.pk_encounter
,
    v_procedures_journal.pk_episode
,
    v_procedures_journal.pk_health_issue
,
    v_procedures_journal.src_pk
,
    v_procedures_journal.src_table
,
    v_procedures_journal.row_version
,
    v_procedures_journal.health_issue
,
    v_procedures_journal.issue_laterality
,
    v_procedures_journal.issue_active
,
    v_procedures_journal.issue_clinically_relevant
,
    v_procedures_journal.issue_confidential
,
    v_procedures_journal.episode
,
    v_procedures_journal.episode_open
,
    v_procedures_journal.encounter_started
,
    v_procedures_journal.encounter_last_affirmed
,
    v_procedures_journal.encounter_type
,
    v_procedures_journal.encounter_l10n_type
   
FROM clin.v_procedures_journal

UNION ALL
 
SELECT v_vaccinations_journal.pk_patient
,
    v_vaccinations_journal.modified_when
,
    v_vaccinations_journal.clin_when
,
    v_vaccinations_journal.modified_by
,
    v_vaccinations_journal.soap_cat
,
    v_vaccinations_journal.narrative
,
    v_vaccinations_journal.pk_encounter
,
    v_vaccinations_journal.pk_episode
,
    v_vaccinations_journal.pk_health_issue
,
    v_vaccinations_journal.src_pk
,
    v_vaccinations_journal.src_table
,
    v_vaccinations_journal.row_version
,
    v_vaccinations_journal.health_issue
,
    v_vaccinations_journal.issue_laterality
,
    v_vaccinations_journal.issue_active
,
    v_vaccinations_journal.issue_clinically_relevant
,
    v_vaccinations_journal.issue_confidential
,
    v_vaccinations_journal.episode
,
    v_vaccinations_journal.episode_open
,
    v_vaccinations_journal.encounter_started
,
    v_vaccinations_journal.encounter_last_affirmed
,
    v_vaccinations_journal.encounter_type
,
    v_vaccinations_journal.encounter_l10n_type
   
FROM clin.v_vaccinations_journal

UNION ALL
 
SELECT v_suppressed_hints_journal.pk_patient
,
    v_suppressed_hints_journal.modified_when
,
    v_suppressed_hints_journal.clin_when
,
    v_suppressed_hints_journal.modified_by
,
    v_suppressed_hints_journal.soap_cat
,
    v_suppressed_hints_journal.narrative
,
    v_suppressed_hints_journal.fk_encounter AS pk_encounter
,
    v_suppressed_hints_journal.pk_episode
,
    v_suppressed_hints_journal.pk_health_issue
,
    v_suppressed_hints_journal.src_pk
,
    v_suppressed_hints_journal.src_table
,
    v_suppressed_hints_journal.row_version
,
    v_suppressed_hints_journal.health_issue
,
    v_suppressed_hints_journal.issue_laterality
,
    v_suppressed_hints_journal.issue_active
,
    v_suppressed_hints_journal.issue_clinically_relevant
,
    v_suppressed_hints_journal.issue_confidential
,
    v_suppressed_hints_journal.episode
,
    v_suppressed_hints_journal.episode_open
,
    v_suppressed_hints_journal.encounter_started
,
    v_suppressed_hints_journal.encounter_last_affirmed
,
    v_suppressed_hints_journal.encounter_type
,
    v_suppressed_hints_journal.encounter_l10n_type
   
FROM clin.v_suppressed_hints_journal

UNION ALL
 
SELECT v_external_care_journal.pk_patient
,
    v_external_care_journal.modified_when
,
    v_external_care_journal.clin_when
,
    v_external_care_journal.modified_by
,
    v_external_care_journal.soap_cat
,
    v_external_care_journal.narrative
,
    v_external_care_journal.pk_encounter
,
    v_external_care_journal.pk_episode
,
    v_external_care_journal.pk_health_issue
,
    v_external_care_journal.src_pk
,
    v_external_care_journal.src_table
,
    v_external_care_journal.row_version
,
    v_external_care_journal.health_issue
,
    v_external_care_journal.issue_laterality
,
    v_external_care_journal.issue_active
,
    v_external_care_journal.issue_clinically_relevant
,
    v_external_care_journal.issue_confidential
,
    v_external_care_journal.episode
,
    v_external_care_journal.episode_open
,
    v_external_care_journal.encounter_started
,
    v_external_care_journal.encounter_last_affirmed
,
    v_external_care_journal.encounter_type
,
    v_external_care_journal.encounter_l10n_type
   
FROM clin.v_external_care_journal

UNION ALL
 
SELECT v_edc_journal.pk_patient
,
    v_edc_journal.modified_when
,
    v_edc_journal.clin_when
,
    v_edc_journal.modified_by
,
    v_edc_journal.soap_cat
,
    v_edc_journal.narrative
,
    v_edc_journal.pk_encounter
,
    v_edc_journal.pk_episode
,
    v_edc_journal.pk_health_issue
,
    v_edc_journal.src_pk
,
    v_edc_journal.src_table
,
    v_edc_journal.row_version
,
    v_edc_journal.health_issue
,
    v_edc_journal.issue_laterality
,
    v_edc_journal.issue_active
,
    v_edc_journal.issue_clinically_relevant
,
    v_edc_journal.issue_confidential
,
    v_edc_journal.episode
,
    v_edc_journal.episode_open
,
    v_edc_journal.encounter_started
,
    v_edc_journal.encounter_last_affirmed
,
    v_edc_journal.encounter_type
,
    v_edc_journal.encounter_l10n_type
   
FROM clin.v_edc_journal

UNION ALL
 
SELECT v_reminders_journal.pk_patient
,
    v_reminders_journal.modified_when
,
    v_reminders_journal.clin_when
,
    v_reminders_journal.modified_by
,
    v_reminders_journal.soap_cat
,
    v_reminders_journal.narrative
,
    v_reminders_journal.pk_encounter
,
    v_reminders_journal.pk_episode
,
    v_reminders_journal.pk_health_issue
,
    v_reminders_journal.src_pk
,
    v_reminders_journal.src_table
,
    v_reminders_journal.row_version
,
    v_reminders_journal.health_issue
,
    v_reminders_journal.issue_laterality
,
    v_reminders_journal.issue_active
,
    v_reminders_journal.issue_clinically_relevant
,
    v_reminders_journal.issue_confidential
,
    v_reminders_journal.episode
,
    v_reminders_journal.episode_open
,
    v_reminders_journal.encounter_started
,
    v_reminders_journal.encounter_last_affirmed
,
    v_reminders_journal.encounter_type
,
    v_reminders_journal.encounter_l10n_type
   
FROM clin.v_reminders_journal;

Index - Schema clin


View: clin.v_export_items

clin.v_export_items Structure
F-Key Name Type Description
SELECT inner_export_items.pk_export_item
,
    inner_export_items.pk_identity
,
    inner_export_items.created_by
,
    inner_export_items.created_when
,
    inner_export_items.designation
,
    inner_export_items.description
,
    inner_export_items.pk_doc_obj
,
    inner_export_items.md5_sum
,
    inner_export_items.size
,
    inner_export_items.filename
,
    inner_export_items.pk_identity_raw
,
    inner_export_items.xmin_export_item
,
    
(inner_export_items.pk_identity IS DISTINCT 
  FROM inner_export_items.pk_identity_raw
) AS pk_identity_raw_needs_update
,
    d_vp.title
,
    d_vp.firstnames
,
    d_vp.lastnames
,
    d_vp.preferred
,
    d_vp.gender
,
    d_vp.dob
   
FROM (
     (
      SELECT c_ei.pk AS pk_export_item
           ,
                CASE
                    WHEN 
           (c_ei.fk_doc_obj IS NULL) THEN c_ei.fk_identity
                    ELSE 
           (
            SELECT encounter.fk_patient
                       
              FROM clin.encounter
                      
             WHERE (encounter.pk = 
                       (
                        SELECT doc_med.fk_encounter
                               
                          FROM blobs.doc_med
                              
                         WHERE (doc_med.pk = 
                                   (
                                    SELECT doc_obj.fk_doc
                                       
                                      FROM blobs.doc_obj
                                      
                                     WHERE (doc_obj.pk = c_ei.fk_doc_obj)
                                   )
                             )
                       )
                 )
           )
                END AS pk_identity
           ,
            COALESCE
           (
                 (
                  SELECT staff.short_alias
                   
                    FROM dem.staff
                  
                   WHERE (staff.db_user = c_ei.created_by)
                 )
                 , (c_ei.created_by)::text
           ) AS created_by
           ,
            c_ei.created_when
           ,
            c_ei.designation
           ,
            c_ei.description
           ,
            c_ei.fk_doc_obj AS pk_doc_obj
           ,
            md5
           (COALESCE
                 (c_ei.data
                       , COALESCE
                       (
                             (
                              SELECT b_do.data
                   
                                FROM blobs.doc_obj b_do
                  
                               WHERE (b_do.pk = c_ei.fk_doc_obj)
                             )
                             ,'\x'::bytea
                       )
                 )
           ) AS md5_sum
           ,
            octet_length
           (COALESCE
                 (c_ei.data
                       ,'\x'::bytea
                 )
           ) AS size
           ,
            COALESCE
           (c_ei.filename
                 , (
                  SELECT b_do.filename
                   
                    FROM blobs.doc_obj b_do
                  
                   WHERE (b_do.pk = c_ei.fk_doc_obj)
                 )
           ) AS filename
           ,
            c_ei.fk_identity AS pk_identity_raw
           ,
            c_ei.xmin AS xmin_export_item
           
        FROM clin.export_item c_ei
     ) inner_export_items
     
  JOIN dem.v_all_persons d_vp 
    ON (
           (d_vp.pk_identity = inner_export_items.pk_identity)
     )
);

Index - Schema clin


View: clin.v_external_care

clin.v_external_care Structure
F-Key Name Type Description
SELECT c_ec.pk AS pk_external_care
,
    
(
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = c_ec.fk_encounter)
) AS pk_identity
,
    COALESCE
(c_ec.issue
     , c_hi.description
) AS issue
,
    c_ec.provider
,
    d_ou.description AS unit
,
    d_o.description AS organization
,
    c_ec.comment
,
    c_ec.inactive
,
    c_ec.fk_health_issue AS pk_health_issue
,
    c_ec.fk_org_unit AS pk_org_unit
,
    c_ec.fk_encounter AS pk_encounter
,
    c_ec.xmin AS xmin_external_care
,
    c_ec.modified_when
,
    c_ec.modified_by
,
    c_ec.row_version
   
FROM (
     (
           (clin.external_care c_ec
     
         LEFT JOIN clin.health_issue c_hi 
                ON (
                       (c_hi.pk = c_ec.fk_health_issue)
                 )
           )
     
   LEFT JOIN dem.org_unit d_ou 
          ON (
                 (c_ec.fk_org_unit = d_ou.pk)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_ou.fk_org = d_o.pk)
     )
);

Index - Schema clin


View: clin.v_external_care_journal

clin.v_external_care_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_ec.modified_when
,
    c_ec.modified_when AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_ec.modified_by)
     )
     , (
           ('<'::text || 
                 (c_ec.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    's'::text AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (_
                                                                                   ('External care'::text) ||
        CASE
            WHEN c_ec.inactive THEN 
                                                                                   (
                                                                                         (
                                                                                            ' ('::text || _
                                                                                                     ('inactive'::text)
                                                                                               ) || 
                                                                                       ')'::text
                                                                                   )
            ELSE ''::text
        END
                                                                             ) || COALESCE
                                                                             (
                                                                                   (
                                                                                         (
                                                                                               (' '::text || _
                                                                                                     ('by'::text)
                                                                                               ) || ' '::text
                                                                                         ) || c_ec.provider
                                                                                   )
                                                                                   ,''::text
                                                                             )
                                                                       ) || ' @ '::text
                                                                 ) || d_ou.description
                                                           ) || ' '::text
                                                     ) || _
                                                     ('of'::text)
                                               ) || ' '::text
                                         ) || d_o.description
                                   ) || '
'::text
                             ) || _
                             ('Issue:'::text)
                       ) || ' '::text
                 ) || COALESCE
                 (c_hi.description
                       , c_ec.issue
                 )
           ) || '
'::text
     ) || COALESCE
     (
           (
                 (_
                       ('Comment:'::text) || ' '::text
                 ) || c_ec.comment
           )
           ,''::text
     )
) AS narrative
,
    c_ec.fk_encounter AS pk_encounter
,
    NULL::integer AS pk_episode
,
    c_ec.fk_health_issue AS pk_health_issue
,
    c_ec.pk AS src_pk
,
    'clin.external_care'::text AS src_table
,
    c_ec.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
,
    NULL::text AS episode
,
    NULL::boolean 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 (
     (
           (
                 (
                       (clin.external_care c_ec
     
                          JOIN clin.encounter c_enc 
                            ON (
                                   (c_ec.fk_encounter = c_enc.pk)
                             )
                       )
     
                    JOIN clin.encounter_type c_ety 
                      ON (
                             (c_enc.fk_type = c_ety.pk)
                       )
                 )
     
         LEFT JOIN clin.health_issue c_hi 
                ON (
                       (c_ec.fk_health_issue = c_hi.pk)
                 )
           )
     
   LEFT JOIN dem.org_unit d_ou 
          ON (
                 (c_ec.fk_org_unit = d_ou.pk)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_ou.fk_org = d_o.pk)
     )
);

Index - Schema clin


View: clin.v_family_history

family history denormalized

clin.v_family_history Structure
F-Key Name Type Description
SELECT c_fh.pk AS pk_family_history
,
    cenc.fk_patient AS pk_patient
,
    c_fh.soap_cat
,
    c_fhrt.description AS relation
,
    _
(c_fhrt.description) AS l10n_relation
,
    c_fh.narrative AS condition
,
    c_fh.age_noted
,
    c_fh.age_of_death
,
    c_fh.contributed_to_death
,
    c_fh.comment
,
    cep.description AS episode
,
    c_fh.clin_when AS when_known_to_patient
,
    c_fh.name_relative
,
    c_fh.dob_relative
,
    c_fhrt.is_genetic AS is_genetic_relative
,
    c_fh.fk_encounter AS pk_encounter
,
    c_fh.fk_episode AS pk_episode
,
    cep.fk_health_issue AS pk_health_issue
,
    c_fhrt.pk AS pk_fhx_relation_type
,
    c_fh.modified_when
,
    COALESCE
(
     (
      SELECT array_agg
           (c_lc2fhx.fk_generic_code) AS array_agg
           
        FROM clin.lnk_code2fhx c_lc2fhx
          
       WHERE (c_lc2fhx.fk_item = c_fh.pk)
     )
     , ARRAY[]::integer[]
) AS pk_generic_codes
,
    c_fh.xmin AS xmin_family_history
   
FROM (
     (
           (clin.family_history c_fh
     
              JOIN clin.encounter cenc 
                ON (
                       (c_fh.fk_encounter = cenc.pk)
                 )
           )
     
        JOIN clin.episode cep 
          ON (
                 (c_fh.fk_episode = cep.pk)
           )
     )
     
LEFT JOIN clin.fhx_relation_type c_fhrt 
    ON (
           (c_fh.fk_relation_type = c_fhrt.pk)
     )
);

Index - Schema clin


View: clin.v_family_history_journal

clin.v_family_history_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_fh.modified_when
,
    c_fh.clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_fh.modified_by)
     )
     , (
           ('<'::text || 
                 (c_fh.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_fh.soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (_
                                                                       (c_fhrt.description) || COALESCE
                                                                       (
                                                                             (' @ '::text || c_fh.age_noted)
                                                                             ,''::text
                                                                       )
                                                                 ) || ': '::text
                                                           ) || c_fh.narrative
                                                     ) || '
'::text
                                               ) || ' '::text
                                         ) ||
        CASE
            WHEN 
                                         (c_fh.contributed_to_death IS TRUE) THEN 
                                         (_
                                               ('contributed to death'::text) || ' '::text
                                         )
            ELSE ''::text
        END
                                   ) || COALESCE
                                   (
                                         ('@ '::text || 
                                               (justify_interval
                                                     (c_fh.age_of_death)
                                               )::text
                                         )
                                         ,''::text
                                   )
                             ) || '
'::text
                       ) || COALESCE
                       (
                             (
                                   (' '::text || c_fh.name_relative) || 
                                 ','::text
                             )
                             ,''::text
                       )
                 ) || COALESCE
                 (
                       (' '::text || to_char
                             (c_fh.dob_relative
                                   ,'YYYY-MM-DD'::text
                             )
                       )
                       ,''::text
                 )
           ) || COALESCE
           (
                 ('
 '::text || c_fh.comment)
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 (';
'::text || array_to_string
                       (
                             (
                              SELECT array_agg
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (r_csr.code || 
                                                                                      ' ('::text) || r_ds.name_short
                                                                                   ) || ' - '::text
                                                                             ) || r_ds.version
                                                                       ) || ' - '::text
                                                                 ) || r_ds.lang
                                                           ) || 
                                                 '): '::text
                                               ) || r_csr.term
                                         )
                                   ) AS array_agg
           
                                FROM (
                                         (clin.lnk_code2fhx c_lc2fhx
             
                                            JOIN ref.coding_system_root r_csr 
                                              ON (
                                                     (c_lc2fhx.fk_generic_code = r_csr.pk_coding_system)
                                               )
                                         )
             
                                      JOIN ref.data_source r_ds 
                                        ON (
                                               (r_ds.pk = r_csr.fk_data_source)
                                         )
                                   )
          
                               WHERE (c_lc2fhx.fk_item = c_fh.pk)
                             )
                             ,'; '::text
                       )
                 ) || ';'::text
           )
           ,''::text
     )
) AS narrative
,
    c_fh.fk_encounter AS pk_encounter
,
    c_fh.fk_episode AS pk_episode
,
    c_epi.fk_health_issue AS pk_health_issue
,
    c_fh.pk AS src_pk
,
    'clin.family_history'::text AS src_table
,
    c_fh.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 (
     (
           (
                 (
                       (clin.family_history c_fh
     
                          JOIN clin.encounter c_enc 
                            ON (
                                   (c_fh.fk_encounter = c_enc.pk)
                             )
                       )
     
                    JOIN clin.encounter_type c_ety 
                      ON (
                             (c_enc.fk_type = c_ety.pk)
                       )
                 )
     
              JOIN clin.episode c_epi 
                ON (
                       (c_fh.fk_episode = c_epi.pk)
                 )
           )
     
   LEFT JOIN clin.fhx_relation_type c_fhrt 
          ON (
                 (c_fh.fk_relation_type = c_fhrt.pk)
           )
     )
     
LEFT JOIN clin.health_issue c_hi 
    ON (
           (c_epi.fk_health_issue = c_hi.pk)
     )
);

Index - Schema clin


View: clin.v_health_issues

clin.v_health_issues Structure
F-Key Name Type Description
SELECT (
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = c_hi.fk_encounter)
) AS pk_patient
,
    c_hi.pk AS pk_health_issue
,
    c_hi.description
,
    c_hi.summary
,
    c_hi.laterality
,
    c_hi.age_noted
,
    c_hi.is_active
,
    c_hi.clinically_relevant
,
    c_hi.is_confidential
,
    c_hi.is_cause_of_death
,
    c_hi.fk_encounter AS pk_encounter
,
    c_hi.modified_when
,
    c_hi.modified_by
,
    c_hi.row_version
,
    c_hi."grouping"
,
    c_hi.diagnostic_certainty_classification
,
    
(EXISTS 
     (
      SELECT 1
           
        FROM clin.episode c_ep
          
       WHERE (
                 (c_ep.fk_health_issue = c_hi.pk)
               AND (c_ep.is_open IS TRUE)
           )
         LIMIT 1
     )
) AS has_open_episode
,
    COALESCE
(
     (
      SELECT array_agg
           (c_lc2h.fk_generic_code) AS array_agg
           
        FROM clin.lnk_code2h_issue c_lc2h
          
       WHERE (c_lc2h.fk_item = c_hi.pk)
     )
     , ARRAY[]::integer[]
) AS pk_generic_codes
,
    c_hi.xmin AS xmin_health_issue
   
FROM clin.health_issue c_hi;

Index - Schema clin


View: clin.v_health_issues_journal

clin.v_health_issues_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_hi.modified_when
,
    COALESCE
(
     (
      SELECT (identity.dob + c_hi.age_noted)
           
        FROM dem.identity
          
       WHERE (identity.pk = 
                 (
                  SELECT encounter.fk_patient
                   
                    FROM clin.encounter
                  
                   WHERE (encounter.pk = c_hi.fk_encounter)
                 )
           )
     )
     , c_enc.started
) AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_hi.modified_by)
     )
     , (
           ('<'::text || 
                 (c_hi.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    'a'::text AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (_
                                                                             ('Health Issue'::text) || 
                                                                          ' ('::text) ||
        CASE
            WHEN c_hi.is_active THEN _
                                                                             ('active'::text)
            ELSE _
                                                                             ('inactive'::text)
        END
                                                                       ) || 
                                                                    ', '::text
                                                                 ) ||
        CASE
            WHEN c_hi.clinically_relevant THEN _
                                                                 ('clinically relevant'::text)
            ELSE _
                                                                 ('clinically not relevant'::text)
        END
                                                           ) || COALESCE
                                                           (
                                                                 (
                                                                    ', '::text || c_hi.diagnostic_certainty_classification
                                                                 )
                                                                 ,''::text
                                                           )
                                                     ) || 
                                           '): '::text
                                         ) || c_hi.description
                                   ) || COALESCE
                                   (
                                         (
                                               (
                                                     (
                                                           (';
'::text || _
                                                                 ('noted at age'::text)
                                                           ) || ': '::text
                                                     ) || 
                                                     (c_hi.age_noted)::text
                                               ) || ';
'::text
                                         )
                                         ,';
'::text
                                   )
                             ) || COALESCE
                             (
                                   (
                                         (
                                               (_
                                                     ('Laterality'::text) || ': '::text
                                               ) || 
                                               (c_hi.laterality)::text
                                         ) || ' / '::text
                                   )
                                   ,''::text
                             )
                       ) ||
        CASE
            WHEN c_hi.is_confidential THEN 
                       (_
                             ('confidential'::text) || ' / '::text
                       )
            ELSE ''::text
        END
                 ) ||
        CASE
            WHEN c_hi.is_cause_of_death THEN _
                 ('cause of death'::text)
            ELSE ''::text
        END
           ) || COALESCE
           (
                 (
                       (
                             (';
'::text || _
                                   ('Summary'::text)
                             ) || ':
'::text
                       ) || c_hi.summary
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 (';
'::text || array_to_string
                       (
                             (
                              SELECT array_agg
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (r_csr.code || 
                                                                                      ' ('::text) || r_ds.name_short
                                                                                   ) || ' - '::text
                                                                             ) || r_ds.version
                                                                       ) || ' - '::text
                                                                 ) || r_ds.lang
                                                           ) || 
                                                 '): '::text
                                               ) || r_csr.term
                                         )
                                   ) AS array_agg
           
                                FROM (
                                         (clin.lnk_code2h_issue c_lc2h
             
                                            JOIN ref.coding_system_root r_csr 
                                              ON (
                                                     (c_lc2h.fk_generic_code = r_csr.pk_coding_system)
                                               )
                                         )
             
                                      JOIN ref.data_source r_ds 
                                        ON (
                                               (r_ds.pk = r_csr.fk_data_source)
                                         )
                                   )
          
                               WHERE (c_lc2h.fk_item = c_hi.pk)
                             )
                             ,'; '::text
                       )
                 ) || ';'::text
           )
           ,''::text
     )
) AS narrative
,
    c_hi.fk_encounter AS pk_encounter
,
    NULL::integer AS pk_episode
,
    c_hi.pk AS pk_health_issue
,
    c_hi.pk AS src_pk
,
    'clin.health_issue'::text AS src_table
,
    c_hi.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
,
    NULL::text AS episode
,
    NULL::boolean 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 (
     (clin.health_issue c_hi
     
        JOIN clin.encounter c_enc 
          ON (
                 (c_hi.fk_encounter = c_enc.pk)
           )
     )
     
  JOIN clin.encounter_type c_ety 
    ON (
           (c_enc.fk_type = c_ety.pk)
     )
);

Index - Schema clin


View: clin.v_hospital_stays

clin.v_hospital_stays Structure
F-Key Name Type Description
SELECT c_hs.pk AS pk_hospital_stay
,
    
(
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = c_hs.fk_encounter)
) AS pk_patient
,
    d_o.description AS hospital
,
    d_ou.description AS ward
,
    c_hs.narrative AS comment
,
    c_hs.clin_when AS admission
,
    c_hs.discharge
,
    c_hs.soap_cat
,
    c_e.description AS episode
,
    c_hi.description AS health_issue
,
    c_hs.fk_encounter AS pk_encounter
,
    c_hs.fk_episode AS pk_episode
,
    c_hi.pk AS pk_health_issue
,
    c_hs.fk_org_unit AS pk_org_unit
,
    d_o.pk AS pk_org
,
    COALESCE
(
     (
      SELECT array_agg
           (b_dm.pk) AS array_agg
           
        FROM blobs.doc_med b_dm
          
       WHERE (b_dm.fk_hospital_stay = c_hs.pk)
     )
     , ARRAY[]::integer[]
) AS pk_documents
,
    c_hs.modified_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_hs.modified_by)
     )
     , (
           ('<'::text || 
                 (c_hs.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_hs.row_version
,
    c_hs.xmin AS xmin_hospital_stay
   
FROM (
     (
           (
                 (clin.hospital_stay c_hs
     
               LEFT JOIN clin.episode c_e 
                      ON (
                             (c_e.pk = c_hs.fk_episode)
                       )
                 )
     
         LEFT JOIN clin.health_issue c_hi 
                ON (
                       (c_hi.pk = c_e.fk_health_issue)
                 )
           )
     
   LEFT JOIN dem.org_unit d_ou 
          ON (
                 (d_ou.pk = c_hs.fk_org_unit)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_o.pk = d_ou.fk_org)
     )
);

Index - Schema clin


View: clin.v_hospital_stays_journal

clin.v_hospital_stays_journal Structure
F-Key Name Type Description
SELECT v_hospital_stays_journal_no_discharge.pk_patient
,
    v_hospital_stays_journal_no_discharge.modified_when
,
    v_hospital_stays_journal_no_discharge.clin_when
,
    v_hospital_stays_journal_no_discharge.modified_by
,
    v_hospital_stays_journal_no_discharge.soap_cat
,
    v_hospital_stays_journal_no_discharge.narrative
,
    v_hospital_stays_journal_no_discharge.pk_encounter
,
    v_hospital_stays_journal_no_discharge.pk_episode
,
    v_hospital_stays_journal_no_discharge.pk_health_issue
,
    v_hospital_stays_journal_no_discharge.src_pk
,
    v_hospital_stays_journal_no_discharge.src_table
,
    v_hospital_stays_journal_no_discharge.row_version
,
    v_hospital_stays_journal_no_discharge.health_issue
,
    v_hospital_stays_journal_no_discharge.issue_laterality
,
    v_hospital_stays_journal_no_discharge.issue_active
,
    v_hospital_stays_journal_no_discharge.issue_clinically_relevant
,
    v_hospital_stays_journal_no_discharge.issue_confidential
,
    v_hospital_stays_journal_no_discharge.episode
,
    v_hospital_stays_journal_no_discharge.episode_open
,
    v_hospital_stays_journal_no_discharge.encounter_started
,
    v_hospital_stays_journal_no_discharge.encounter_last_affirmed
,
    v_hospital_stays_journal_no_discharge.encounter_type
,
    v_hospital_stays_journal_no_discharge.encounter_l10n_type
   
FROM clin.v_hospital_stays_journal_no_discharge

UNION ALL
 
SELECT v_hospital_stays_journal_one_day.pk_patient
,
    v_hospital_stays_journal_one_day.modified_when
,
    v_hospital_stays_journal_one_day.clin_when
,
    v_hospital_stays_journal_one_day.modified_by
,
    v_hospital_stays_journal_one_day.soap_cat
,
    v_hospital_stays_journal_one_day.narrative
,
    v_hospital_stays_journal_one_day.pk_encounter
,
    v_hospital_stays_journal_one_day.pk_episode
,
    v_hospital_stays_journal_one_day.pk_health_issue
,
    v_hospital_stays_journal_one_day.src_pk
,
    v_hospital_stays_journal_one_day.src_table
,
    v_hospital_stays_journal_one_day.row_version
,
    v_hospital_stays_journal_one_day.health_issue
,
    v_hospital_stays_journal_one_day.issue_laterality
,
    v_hospital_stays_journal_one_day.issue_active
,
    v_hospital_stays_journal_one_day.issue_clinically_relevant
,
    v_hospital_stays_journal_one_day.issue_confidential
,
    v_hospital_stays_journal_one_day.episode
,
    v_hospital_stays_journal_one_day.episode_open
,
    v_hospital_stays_journal_one_day.encounter_started
,
    v_hospital_stays_journal_one_day.encounter_last_affirmed
,
    v_hospital_stays_journal_one_day.encounter_type
,
    v_hospital_stays_journal_one_day.encounter_l10n_type
   
FROM clin.v_hospital_stays_journal_one_day

UNION ALL
 
SELECT v_hospital_stays_journal_multi_day_adm.pk_patient
,
    v_hospital_stays_journal_multi_day_adm.modified_when
,
    v_hospital_stays_journal_multi_day_adm.clin_when
,
    v_hospital_stays_journal_multi_day_adm.modified_by
,
    v_hospital_stays_journal_multi_day_adm.soap_cat
,
    v_hospital_stays_journal_multi_day_adm.narrative
,
    v_hospital_stays_journal_multi_day_adm.pk_encounter
,
    v_hospital_stays_journal_multi_day_adm.pk_episode
,
    v_hospital_stays_journal_multi_day_adm.pk_health_issue
,
    v_hospital_stays_journal_multi_day_adm.src_pk
,
    v_hospital_stays_journal_multi_day_adm.src_table
,
    v_hospital_stays_journal_multi_day_adm.row_version
,
    v_hospital_stays_journal_multi_day_adm.health_issue
,
    v_hospital_stays_journal_multi_day_adm.issue_laterality
,
    v_hospital_stays_journal_multi_day_adm.issue_active
,
    v_hospital_stays_journal_multi_day_adm.issue_clinically_relevant
,
    v_hospital_stays_journal_multi_day_adm.issue_confidential
,
    v_hospital_stays_journal_multi_day_adm.episode
,
    v_hospital_stays_journal_multi_day_adm.episode_open
,
    v_hospital_stays_journal_multi_day_adm.encounter_started
,
    v_hospital_stays_journal_multi_day_adm.encounter_last_affirmed
,
    v_hospital_stays_journal_multi_day_adm.encounter_type
,
    v_hospital_stays_journal_multi_day_adm.encounter_l10n_type
   
FROM clin.v_hospital_stays_journal_multi_day_adm

UNION ALL
 
SELECT v_hospital_stays_journal_multi_day_dis.pk_patient
,
    v_hospital_stays_journal_multi_day_dis.modified_when
,
    v_hospital_stays_journal_multi_day_dis.clin_when
,
    v_hospital_stays_journal_multi_day_dis.modified_by
,
    v_hospital_stays_journal_multi_day_dis.soap_cat
,
    v_hospital_stays_journal_multi_day_dis.narrative
,
    v_hospital_stays_journal_multi_day_dis.pk_encounter
,
    v_hospital_stays_journal_multi_day_dis.pk_episode
,
    v_hospital_stays_journal_multi_day_dis.pk_health_issue
,
    v_hospital_stays_journal_multi_day_dis.src_pk
,
    v_hospital_stays_journal_multi_day_dis.src_table
,
    v_hospital_stays_journal_multi_day_dis.row_version
,
    v_hospital_stays_journal_multi_day_dis.health_issue
,
    v_hospital_stays_journal_multi_day_dis.issue_laterality
,
    v_hospital_stays_journal_multi_day_dis.issue_active
,
    v_hospital_stays_journal_multi_day_dis.issue_clinically_relevant
,
    v_hospital_stays_journal_multi_day_dis.issue_confidential
,
    v_hospital_stays_journal_multi_day_dis.episode
,
    v_hospital_stays_journal_multi_day_dis.episode_open
,
    v_hospital_stays_journal_multi_day_dis.encounter_started
,
    v_hospital_stays_journal_multi_day_dis.encounter_last_affirmed
,
    v_hospital_stays_journal_multi_day_dis.encounter_type
,
    v_hospital_stays_journal_multi_day_dis.encounter_l10n_type
   
FROM clin.v_hospital_stays_journal_multi_day_dis;

Index - Schema clin


View: clin.v_hospital_stays_journal_multi_day_adm

clin.v_hospital_stays_journal_multi_day_adm Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_hs.modified_when
,
    c_hs.clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_hs.modified_by)
     )
     , (
           ('<'::text || 
                 (c_hs.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_hs.soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (
                                                                                         (
                                                                                               (
                                                                                                     (
                                                                                                           (
                                                                                                                 (_
                                                                                                                       ('hospital stay'::text) || '
'::text
                                                                                                                 ) || ' '::text
                                                                                                           ) || _
                                                                                                           ('admitted'::text)
                                                                                                     ) || ': '::text
                                                                                               ) || to_char
                                                                                               (c_hs.clin_when
                                                                                                     ,'YYYY-MM-DD'::text
                                                                                               )
                                                                                         ) || '
'::text
                                                                                   ) || ' '::text
                                                                             ) || _
                                                                             ('discharged'::text)
                                                                       ) || ': '::text
                                                                 ) || to_char
                                                                 (c_hs.discharge
                                                                       ,'YYYY-MM-DD'::text
                                                                 )
                                                           ) || '
'::text
                                                     ) || ' '::text
                                               ) || _
                                               ('hospital'::text)
                                         ) || ': "'::text
                                   ) || d_ou.description
                             ) || ' @ '::text
                       ) || d_o.description
                 ) || '"'::text
           ) || '
'::text
     ) || COALESCE
     (
           ('
 '::text || c_hs.narrative)
           ,''::text
     )
) AS narrative
,
    c_hs.fk_encounter AS pk_encounter
,
    c_hs.fk_episode AS pk_episode
,
    
(
SELECT episode.fk_health_issue
           
  FROM clin.episode
          
 WHERE (episode.pk = c_hs.fk_episode)
) AS pk_health_issue
,
    c_hs.pk AS src_pk
,
    'clin.hospital_stay'::text AS src_table
,
    c_hs.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 (
     (
           (
                 (
                       (
                             (clin.hospital_stay c_hs
     
                                JOIN clin.encounter c_enc 
                                  ON (
                                         (c_hs.fk_encounter = c_enc.pk)
                                   )
                             )
     
                          JOIN clin.encounter_type c_ety 
                            ON (
                                   (c_enc.fk_type = c_ety.pk)
                             )
                       )
     
                    JOIN clin.episode c_epi 
                      ON (
                             (c_hs.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 (
                 (d_ou.pk = c_hs.fk_org_unit)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_o.pk = d_ou.fk_org)
     )
)
  
WHERE (
     (c_hs.discharge IS NOT NULL)
   AND (to_char
           (c_hs.clin_when
                 ,'YYYYMMDD'::text
           ) <> to_char
           (c_hs.discharge
                 ,'YYYYMMDD'::text
           )
     )
);

Index - Schema clin


View: clin.v_hospital_stays_journal_multi_day_dis

clin.v_hospital_stays_journal_multi_day_dis Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_hs.modified_when
,
    c_hs.discharge AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_hs.modified_by)
     )
     , (
           ('<'::text || 
                 (c_hs.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_hs.soap_cat
,
    
(
     (
           (
                 (
                       (_
                             ('discharged from'::text) || ' "'::text
                       ) || d_ou.description
                 ) || ' @ '::text
           ) || d_o.description
     ) || '"'::text
) AS narrative
,
    c_hs.fk_encounter AS pk_encounter
,
    c_hs.fk_episode AS pk_episode
,
    
(
SELECT episode.fk_health_issue
           
  FROM clin.episode
          
 WHERE (episode.pk = c_hs.fk_episode)
) AS pk_health_issue
,
    c_hs.pk AS src_pk
,
    'clin.hospital_stay'::text AS src_table
,
    c_hs.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 (
     (
           (
                 (
                       (
                             (clin.hospital_stay c_hs
     
                                JOIN clin.encounter c_enc 
                                  ON (
                                         (c_hs.fk_encounter = c_enc.pk)
                                   )
                             )
     
                          JOIN clin.encounter_type c_ety 
                            ON (
                                   (c_enc.fk_type = c_ety.pk)
                             )
                       )
     
                    JOIN clin.episode c_epi 
                      ON (
                             (c_hs.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 (
                 (d_ou.pk = c_hs.fk_org_unit)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_o.pk = d_ou.fk_org)
     )
)
  
WHERE (
     (c_hs.discharge IS NOT NULL)
   AND (to_char
           (c_hs.clin_when
                 ,'YYYYMMDD'::text
           ) <> to_char
           (c_hs.discharge
                 ,'YYYYMMDD'::text
           )
     )
);

Index - Schema clin


View: clin.v_hospital_stays_journal_no_discharge

clin.v_hospital_stays_journal_no_discharge Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_hs.modified_when
,
    c_hs.clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_hs.modified_by)
     )
     , (
           ('<'::text || 
                 (c_hs.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_hs.soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (_
                                                                                   ('hospital stay'::text) || '
'::text
                                                                             ) || ' '::text
                                                                       ) || _
                                                                       ('admitted'::text)
                                                                 ) || ': '::text
                                                           ) || to_char
                                                           (c_hs.clin_when
                                                                 ,'YYYY-MM-DD'::text
                                                           )
                                                     ) || '
'::text
                                               ) || ' '::text
                                         ) || _
                                         ('hospital'::text)
                                   ) || ': "'::text
                             ) || d_ou.description
                       ) || ' @ '::text
                 ) || d_o.description
           ) || '"'::text
     ) || COALESCE
     (
           ('
 '::text || c_hs.narrative)
           ,''::text
     )
) AS narrative
,
    c_hs.fk_encounter AS pk_encounter
,
    c_hs.fk_episode AS pk_episode
,
    
(
SELECT episode.fk_health_issue
           
  FROM clin.episode
          
 WHERE (episode.pk = c_hs.fk_episode)
) AS pk_health_issue
,
    c_hs.pk AS src_pk
,
    'clin.hospital_stay'::text AS src_table
,
    c_hs.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 (
     (
           (
                 (
                       (
                             (clin.hospital_stay c_hs
     
                                JOIN clin.encounter c_enc 
                                  ON (
                                         (c_hs.fk_encounter = c_enc.pk)
                                   )
                             )
     
                          JOIN clin.encounter_type c_ety 
                            ON (
                                   (c_enc.fk_type = c_ety.pk)
                             )
                       )
     
                    JOIN clin.episode c_epi 
                      ON (
                             (c_hs.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 (
                 (d_ou.pk = c_hs.fk_org_unit)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_o.pk = d_ou.fk_org)
     )
)
  
WHERE (c_hs.discharge IS NULL);

Index - Schema clin


View: clin.v_hospital_stays_journal_one_day

clin.v_hospital_stays_journal_one_day Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_hs.modified_when
,
    c_hs.clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_hs.modified_by)
     )
     , (
           ('<'::text || 
                 (c_hs.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_hs.soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (_
                                                                                         ('hospital stay'::text) || '
'::text
                                                                                   ) || ' '::text
                                                                             ) || _
                                                                             ('admitted/discharged'::text)
                                                                       ) || ': '::text
                                                                 ) || to_char
                                                                 (c_hs.clin_when
                                                                       ,'YYYY-MM-DD'::text
                                                                 )
                                                           ) || '
'::text
                                                     ) || ' '::text
                                               ) || _
                                               ('hospital'::text)
                                         ) || ': "'::text
                                   ) || d_ou.description
                             ) || ' @ '::text
                       ) || d_o.description
                 ) || '"'::text
           ) || '
'::text
     ) || COALESCE
     (
           ('
 '::text || c_hs.narrative)
           ,''::text
     )
) AS narrative
,
    c_hs.fk_encounter AS pk_encounter
,
    c_hs.fk_episode AS pk_episode
,
    
(
SELECT episode.fk_health_issue
           
  FROM clin.episode
          
 WHERE (episode.pk = c_hs.fk_episode)
) AS pk_health_issue
,
    c_hs.pk AS src_pk
,
    'clin.hospital_stay'::text AS src_table
,
    c_hs.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 (
     (
           (
                 (
                       (
                             (clin.hospital_stay c_hs
     
                                JOIN clin.encounter c_enc 
                                  ON (
                                         (c_hs.fk_encounter = c_enc.pk)
                                   )
                             )
     
                          JOIN clin.encounter_type c_ety 
                            ON (
                                   (c_enc.fk_type = c_ety.pk)
                             )
                       )
     
                    JOIN clin.episode c_epi 
                      ON (
                             (c_hs.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 (
                 (d_ou.pk = c_hs.fk_org_unit)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_o.pk = d_ou.fk_org)
     )
)
  
WHERE (
     (c_hs.discharge IS NOT NULL)
   AND (to_char
           (c_hs.clin_when
                 ,'YYYYMMDD'::text
           ) = to_char
           (c_hs.discharge
                 ,'YYYYMMDD'::text
           )
     )
);

Index - Schema clin


View: clin.v_incoming_data_unmatched

Shows incoming data but w/o the data field.

clin.v_incoming_data_unmatched Structure
F-Key Name Type Description
SELECT c_idu.pk AS pk_incoming_data_unmatched
,
    c_idu.fk_patient_candidates AS pk_patient_candidates
,
    c_idu.firstnames
,
    c_idu.lastnames
,
    c_idu.dob
,
    c_idu.gender
,
    c_idu.postcode
,
    c_idu.other_info
,
    c_idu.request_id
,
    c_idu.requestor
,
    c_idu.external_data_id
,
    c_idu.comment
,
    c_idu.fk_identity_disambiguated AS pk_identity_disambiguated
,
    c_idu.fk_provider_disambiguated AS pk_provider_disambiguated
,
    c_idu.type AS data_type
,
    md5
(c_idu.data) AS md5_sum
,
    octet_length
(c_idu.data) AS data_size
,
    c_idu.xmin AS xmin_incoming_data_unmatched
   
FROM clin.incoming_data_unmatched c_idu;

Index - Schema clin


View: clin.v_linked_codes

Denormalized codes linked to EMR structures.

clin.v_linked_codes Structure
F-Key Name Type Description
SELECT c_lc2ir.fk_item AS pk_item
,
    
(c_lc2ir.tableoid)::regclass AS item_table
,
    
(r_csr.code || COALESCE
     (c_lc2ir.code_modifier
           ,''::text
     )
) AS code
,
    r_csr.code AS base_code
,
    c_lc2ir.code_modifier
,
    r_csr.term
,
    r_ds.name_long
,
    r_ds.name_short
,
    r_ds.version
,
    r_ds.lang
,
    
(r_csr.tableoid)::regclass AS code_table
,
    r_csr.pk_coding_system AS pk_generic_code
,
    r_csr.fk_data_source AS pk_data_source
,
    c_lc2ir.pk_lnk_code2item
   
FROM (
     (clin.lnk_code2item_root c_lc2ir
     
        JOIN ref.coding_system_root r_csr 
          ON (
                 (r_csr.pk_coding_system = c_lc2ir.fk_generic_code)
           )
     )
     
  JOIN ref.data_source r_ds 
    ON (
           (r_ds.pk = r_csr.fk_data_source)
     )
);

Index - Schema clin


View: clin.v_most_recent_encounters

Lists the most recent encounters per patient. Logic of "most recent" is: for a patient: 1) select encounters with latest "last_affirmed", 2) from those select encounters with latest "started" 3) limit those to 1 if there are duplicates (same start and end of encounter!)

clin.v_most_recent_encounters Structure
F-Key Name Type Description
SELECT ce1.pk AS pk_encounter
,
    ce1.fk_patient AS pk_patient
,
    ce1.reason_for_encounter
,
    ce1.assessment_of_encounter
,
    et.description AS type
,
    _
(et.description) AS l10n_type
,
    ce1.started
,
    ce1.last_affirmed
,
    ce1.fk_type AS pk_type
,
    ce1.fk_location AS pk_location
   
FROM clin.encounter ce1
,
    clin.encounter_type et
  
WHERE (
     (ce1.fk_type = et.pk)
   AND (ce1.started = 
           (
            SELECT max
                 (ce2.started) AS max
           
              FROM clin.encounter ce2
          
             WHERE (ce2.last_affirmed = 
                       (
                        SELECT max
                             (ce3.last_affirmed) AS max
                   
                          FROM clin.encounter ce3
                  
                         WHERE (ce3.fk_patient = ce1.fk_patient)
                       )
                 )
         LIMIT 1
           )
     )
);

Index - Schema clin


View: clin.v_narrative

patient narrative with denormalized context added

clin.v_narrative Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_n.clin_when AS date
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_n.modified_by)
     )
     , (
           ('<'::text || 
                 (c_n.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_n.soap_cat
,
    c_n.narrative
,
    c_epi.description AS episode
,
    c_hi.description AS health_issue
,
    c_n.pk_item
,
    c_n.pk AS pk_narrative
,
    c_epi.fk_health_issue AS pk_health_issue
,
    c_n.fk_episode AS pk_episode
,
    c_n.fk_encounter AS pk_encounter
,
    c_n.xmin AS xmin_clin_narrative
,
    c_n.modified_when
,
    c_n.row_version
,
    c_n.pk_audit
,
    c_n.modified_by AS modified_by_raw
,
    COALESCE
(
     (
      SELECT array_agg
           (c_lc2n.fk_generic_code) AS array_agg
           
        FROM clin.lnk_code2narrative c_lc2n
          
       WHERE (c_lc2n.fk_item = c_n.pk)
     )
     , ARRAY[]::integer[]
) AS pk_generic_codes
   
FROM (
     (
           (clin.clin_narrative c_n
     
         LEFT JOIN clin.encounter c_enc 
                ON (
                       (c_n.fk_encounter = c_enc.pk)
                 )
           )
     
   LEFT JOIN clin.episode c_epi 
          ON (
                 (c_n.fk_episode = c_epi.pk)
           )
     )
     
LEFT JOIN clin.health_issue c_hi 
    ON (
           (c_epi.fk_health_issue = c_hi.pk)
     )
);

Index - Schema clin


View: clin.v_pat_allergies

denormalizes clin.allergy

clin.v_pat_allergies Structure
F-Key Name Type Description
SELECT a.pk AS pk_allergy
,
    
(
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = a.fk_encounter)
) AS pk_patient
,
    a.soap_cat
,
        CASE
            WHEN 
(COALESCE
     (btrim
           (a.allergene)
           ,''::text
     ) = ''::text
) THEN a.substance
            ELSE a.allergene
        END AS descriptor
,
    a.allergene
,
    a.substance
,
    a.substance_code
,
    a.generics
,
    a.generic_specific
,
    a.atc_code
,
    at.value AS type
,
    _
(at.value) AS l10n_type
,
    a.definite
,
    a.narrative AS reaction
,
    a.fk_type AS pk_type
,
    a.pk_item
,
    a.clin_when AS date
,
    
(
SELECT episode.fk_health_issue
           
  FROM clin.episode
          
 WHERE (episode.pk = a.fk_episode)
) AS pk_health_issue
,
    a.fk_episode AS pk_episode
,
    a.fk_encounter AS pk_encounter
,
    a.modified_when
,
    a.modified_by
,
    a.xmin AS xmin_allergy
   
FROM clin.allergy a
,
    clin._enum_allergy_type at
  
WHERE (at.pk = a.fk_type);

Index - Schema clin


View: clin.v_pat_allergies_journal

clin.v_pat_allergies_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_all.modified_when
,
    c_all.clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_all.modified_by)
     )
     , (
           ('<'::text || 
                 (c_all.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_all.soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (_
                                                                       ('Allergy'::text) || 
                                                                    ' ('::text) || _
                                                                       (c_at.value)
                                                                 ) || 
                                                       '): '::text
                                                     ) || COALESCE
                                                     (c_all.narrative
                                                           ,''::text
                                                     )
                                               ) || '
'::text
                                         ) || _
                                         ('substance'::text)
                                   ) || ': '::text
                             ) || c_all.substance
                       ) || '; '::text
                 ) || COALESCE
                 (
                       (
                             (
                                   (_
                                         ('allergene'::text) || ': '::text
                                   ) || c_all.allergene
                             ) || '; '::text
                       )
                       ,''::text
                 )
           ) || COALESCE
           (
                 (
                       (
                             (_
                                   ('generic'::text) || ': '::text
                             ) || c_all.generics
                       ) || '; '::text
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 (
                       (_
                             ('ATC code'::text) || ': '::text
                       ) || c_all.atc_code
                 ) || '; '::text
           )
           ,''::text
     )
) AS narrative
,
    c_all.fk_encounter AS pk_encounter
,
    c_all.fk_episode AS pk_episode
,
    c_epi.fk_health_issue AS pk_health_issue
,
    c_all.pk AS src_pk
,
    'clin.allergy'::text AS src_table
,
    c_all.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 (
     (
           (
                 (
                       (clin.allergy c_all
     
                          JOIN clin._enum_allergy_type c_at 
                            ON (
                                   (c_all.fk_type = c_at.pk)
                             )
                       )
     
                    JOIN clin.encounter c_enc 
                      ON (
                             (c_all.fk_encounter = c_enc.pk)
                       )
                 )
     
              JOIN clin.encounter_type c_ety 
                ON (
                       (c_enc.fk_type = c_ety.pk)
                 )
           )
     
        JOIN clin.episode c_epi 
          ON (
                 (c_all.fk_episode = c_epi.pk)
           )
     )
     
LEFT JOIN clin.health_issue c_hi 
    ON (
           (c_epi.fk_health_issue = c_hi.pk)
     )
);

Index - Schema clin


View: clin.v_pat_allergy_state

clin.v_pat_allergy_state Structure
F-Key Name Type Description
SELECT (
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = a.fk_encounter)
) AS pk_patient
,
    a.modified_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = a.modified_by)
     )
     , (
           ('<'::text || 
                 (a.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    a.last_confirmed
,
    a.has_allergy
,
    a.comment
,
    a.fk_encounter AS pk_encounter
,
    a.pk AS pk_allergy_state
,
    a.xmin AS xmin_allergy_state
   
FROM clin.allergy_state a;

Index - Schema clin


View: clin.v_pat_allergy_state_journal

clin.v_pat_allergy_state_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_ast.modified_when
,
    COALESCE
(c_ast.last_confirmed
     , c_ast.modified_when
) AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_ast.modified_by)
     )
     , (
           ('<'::text || 
                 (c_ast.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    'o'::text AS soap_cat
,
    
(
     (
           (
                 (_
                       ('Allergy state'::text) || ': '::text
                 ) ||
        CASE
            WHEN 
                 (c_ast.has_allergy IS NULL) THEN _
                 (
      'unknown, unasked'::text
                 )
            WHEN 
                 (c_ast.has_allergy = 0) THEN _
                 ('no known allergies'::text)
            WHEN 
                 (c_ast.has_allergy = 1) THEN _
                 ('does have allergies'::text)
            ELSE NULL::text
        END
           ) || COALESCE
           (
                 (
                       (
                             (
                                ' ('::text || _
                                         ('last confirmed'::text)
                                   ) || to_char
                                   (c_ast.last_confirmed
                                         ,' YYYY-MM-DD HH24:MI'::text
                                   )
                             ) || 
                     ')'::text
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           ('
 '::text || c_ast.comment)
           ,''::text
     )
) AS narrative
,
    c_ast.fk_encounter AS pk_encounter
,
    NULL::integer AS pk_episode
,
    NULL::integer AS pk_health_issue
,
    c_ast.pk AS src_pk
,
    'clin.allergy_state'::text AS src_table
,
    c_ast.row_version
,
    NULL::text AS health_issue
,
    NULL::text AS issue_laterality
,
    NULL::boolean AS issue_active
,
    NULL::boolean AS issue_clinically_relevant
,
    NULL::boolean AS issue_confidential
,
    NULL::text AS episode
,
    NULL::boolean 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 (
     (clin.allergy_state c_ast
     
        JOIN clin.encounter c_enc 
          ON (
                 (c_ast.fk_encounter = c_enc.pk)
           )
     )
     
  JOIN clin.encounter_type c_ety 
    ON (
           (c_enc.fk_type = c_ety.pk)
     )
)
UNION ALL
 
SELECT c_enc.fk_patient AS pk_patient
,
    now
() AS modified_when
,
    now
() AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_ast.modified_by)
     )
     , (
           ('<'::text || 
                 (c_ast.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    'o'::text AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (_
                                                     ('Allergy state'::text) || 
                                                  ' ('::text) || _
                                                     ('copy'::text)
                                               ) || 
                                     '): '::text
                                   ) ||
        CASE
            WHEN 
                                   (c_ast.has_allergy IS NULL) THEN _
                                   (
                        'unknown, unasked'::text
                                   )
            WHEN 
                                   (c_ast.has_allergy = 0) THEN _
                                   ('no known allergies'::text)
            WHEN 
                                   (c_ast.has_allergy = 1) THEN _
                                   ('does have allergies'::text)
            ELSE NULL::text
        END
                             ) || COALESCE
                             (
                                   ('
 '::text || c_ast.comment)
                                   ,''::text
                             )
                       ) || COALESCE
                       (
                             (
                                   ('
 '::text || _
                                         ('last confirmed'::text)
                                   ) || to_char
                                   (c_ast.last_confirmed
                                         ,' YYYY-MM-DD HH24:MI'::text
                                   )
                             )
                             ,''::text
                       )
                 ) || COALESCE
                 (
                       (
                             ('
 '::text || _
                                   ('entry last modified'::text)
                             ) || to_char
                             (c_ast.modified_when
                                   ,' YYYY-MM-DD HH24:MI'::text
                             )
                       )
                       ,''::text
                 )
           ) || COALESCE
           (
                 (
                       ('
 '::text || _
                             ('encounter started'::text)
                       ) || to_char
                       (c_enc.started
                             ,' YYYY-MM-DD HH24:MI'::text
                       )
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 ('
 '::text || _
                       ('encounter last affirmed'::text)
                 ) || to_char
                 (c_enc.last_affirmed
                       ,' YYYY-MM-DD HH24:MI'::text
                 )
           )
           ,''::text
     )
) AS narrative
,
    c_ast.fk_encounter AS pk_encounter
,
    NULL::integer AS pk_episode
,
    NULL::integer AS pk_health_issue
,
    c_ast.pk AS src_pk
,
    'clin.allergy_state'::text AS src_table
,
    c_ast.row_version
,
    NULL::text AS health_issue
,
    NULL::text AS issue_laterality
,
    NULL::boolean AS issue_active
,
    NULL::boolean AS issue_clinically_relevant
,
    NULL::boolean AS issue_confidential
,
    NULL::text AS episode
,
    NULL::boolean AS episode_open
,
    now
() AS encounter_started
,
    now
() AS encounter_last_affirmed
,
    c_ety.description AS encounter_type
,
    _
(c_ety.description) AS encounter_l10n_type
   
FROM (
     (clin.allergy_state c_ast
     
        JOIN clin.encounter c_enc 
          ON (
                 (c_ast.fk_encounter = c_enc.pk)
           )
     )
     
  JOIN clin.encounter_type c_ety 
    ON (
           (c_enc.fk_type = c_ety.pk)
     )
);

Index - Schema clin


View: clin.v_pat_encounters

Details on encounters.

clin.v_pat_encounters Structure
F-Key Name Type Description
SELECT c_enc.pk AS pk_encounter
,
    c_enc.fk_patient AS pk_patient
,
    c_enc.started
,
    c_et.description AS type
,
    _
(c_et.description) AS l10n_type
,
    c_enc.reason_for_encounter
,
    c_enc.assessment_of_encounter
,
    c_enc.last_affirmed
,
    c_enc.source_time_zone
,
    
(
SELECT timezone
     (
           (
            SELECT c_enc1.source_time_zone
                   
              FROM clin.encounter c_enc1
                  
             WHERE (c_enc1.pk = c_enc.pk)
           )
           , c_enc.started
     ) AS timezone
) AS started_original_tz
,
    
(
SELECT timezone
     (
           (
            SELECT c_enc1.source_time_zone
                   
              FROM clin.encounter c_enc1
                  
             WHERE (c_enc1.pk = c_enc.pk)
           )
           , c_enc.last_affirmed
     ) AS timezone
) AS last_affirmed_original_tz
,
    COALESCE
(d_ou.description
     ,'?'::text
) AS praxis_branch
,
    COALESCE
(d_o.description
     ,'?'::text
) AS praxis
,
    c_enc.fk_location AS pk_org_unit
,
    d_ou.fk_org AS pk_org
,
    d_ou.fk_category AS pk_unit_type
,
    d_o.fk_category AS pk_org_type
,
    c_enc.fk_type AS pk_type
,
    COALESCE
(
     (
      SELECT array_agg
           (c_lc2r.fk_generic_code) AS array_agg
           
        FROM clin.lnk_code2rfe c_lc2r
          
       WHERE (c_lc2r.fk_item = c_enc.pk)
     )
     , ARRAY[]::integer[]
) AS pk_generic_codes_rfe
,
    COALESCE
(
     (
      SELECT array_agg
           (c_lc2a.fk_generic_code) AS array_agg
           
        FROM clin.lnk_code2aoe c_lc2a
          
       WHERE (c_lc2a.fk_item = c_enc.pk)
     )
     , ARRAY[]::integer[]
) AS pk_generic_codes_aoe
,
    c_enc.xmin AS xmin_encounter
,
    c_enc.row_version
,
    c_enc.pk_audit
,
    c_enc.modified_when
,
    c_enc.modified_by AS modified_by_raw
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_enc.modified_by)
     )
     , (
           ('<'::text || 
                 (c_enc.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
   
FROM (
     (
           (clin.encounter c_enc
     
         LEFT JOIN clin.encounter_type c_et 
                ON (
                       (c_enc.fk_type = c_et.pk)
                 )
           )
     
   LEFT JOIN dem.org_unit d_ou 
          ON (
                 (c_enc.fk_location = d_ou.pk)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_ou.fk_org = d_o.pk)
     )
);

Index - Schema clin


View: clin.v_pat_encounters_journal

clin.v_pat_encounters_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_enc.modified_when
,
    c_enc.started AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_enc.modified_by)
     )
     , (
           ('<'::text || 
                 (c_enc.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    NULL::text AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (_
                                                     ('Encounter'::text) || ': '::text
                                               ) || 
                                               (
                                                SELECT _
                                                     (encounter_type.description) AS _
           
                                                  FROM clin.encounter_type
          
                                                 WHERE (encounter_type.pk = c_enc.fk_type)
                                               )
                                         ) || to_char
                                         (c_enc.started
                                               ,' YYYY-MM-DD HH24:MI'::text
                                         )
                                   ) || to_char
                                   (c_enc.last_affirmed
                                         ,' - HH24:MI'::text
                                   )
                             ) || COALESCE
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             ('
 @ '::text || _
                                                                                   ('branch'::text)
                                                                             ) || ' "'::text
                                                                       ) || d_ou.description
                                                                 ) || '" '::text
                                                           ) || _
                                                           ('of'::text)
                                                     ) || ' "'::text
                                               ) || d_o.description
                                         ) || '"'::text
                                   )
                                   ,''::text
                             )
                       ) || COALESCE
                       (
                             (
                                   (
                                         ('
 '::text || _
                                               ('RFE'::text)
                                         ) || ': '::text
                                   ) || c_enc.reason_for_encounter
                             )
                             ,''::text
                       )
                 ) || COALESCE
                 (
                       (
                             ('
'::text || array_to_string
                                   (
                                         (
                                          SELECT array_agg
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (
                                                                                         (
                                                                                               (r_csr.code || 
                                                                                                  ' ('::text) || r_ds.name_short
                                                                                               ) || ' - '::text
                                                                                         ) || r_ds.version
                                                                                   ) || ' - '::text
                                                                             ) || r_ds.lang
                                                                       ) || 
                                                             '): '::text
                                                           ) || r_csr.term
                                                     )
                                               ) AS array_agg
           
                                            FROM (
                                                     (clin.lnk_code2rfe c_lc2r
             
                                                        JOIN ref.coding_system_root r_csr 
                                                          ON (
                                                                 (c_lc2r.fk_generic_code = r_csr.pk_coding_system)
                                                           )
                                                     )
             
                                                  JOIN ref.data_source r_ds 
                                                    ON (
                                                           (r_ds.pk = r_csr.fk_data_source)
                                                     )
                                               )
          
                                           WHERE (c_lc2r.fk_item = c_enc.pk)
                                         )
                                         ,'; '::text
                                   )
                             ) || ';'::text
                       )
                       ,''::text
                 )
           ) || COALESCE
           (
                 (
                       (
                             ('
 '::text || _
                                   ('AOE'::text)
                             ) || ': '::text
                       ) || c_enc.assessment_of_encounter
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 ('
'::text || array_to_string
                       (
                             (
                              SELECT array_agg
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (r_csr.code || 
                                                                                      ' ('::text) || r_ds.name_short
                                                                                   ) || ' - '::text
                                                                             ) || r_ds.version
                                                                       ) || ' - '::text
                                                                 ) || r_ds.lang
                                                           ) || 
                                                 '): '::text
                                               ) || r_csr.term
                                         )
                                   ) AS array_agg
           
                                FROM (
                                         (clin.lnk_code2aoe c_lc2a
             
                                            JOIN ref.coding_system_root r_csr 
                                              ON (
                                                     (c_lc2a.fk_generic_code = r_csr.pk_coding_system)
                                               )
                                         )
             
                                      JOIN ref.data_source r_ds 
                                        ON (
                                               (r_ds.pk = r_csr.fk_data_source)
                                         )
                                   )
          
                               WHERE (c_lc2a.fk_item = c_enc.pk)
                             )
                             ,'; '::text
                       )
                 ) || ';'::text
           )
           ,''::text
     )
) AS narrative
,
    c_enc.pk AS pk_encounter
,
    NULL::integer AS pk_episode
,
    NULL::integer AS pk_health_issue
,
    c_enc.pk AS src_pk
,
    'clin.encounter'::text AS src_table
,
    c_enc.row_version
,
    NULL::text AS health_issue
,
    NULL::text AS issue_laterality
,
    NULL::boolean AS issue_active
,
    NULL::boolean AS issue_clinically_relevant
,
    NULL::boolean AS issue_confidential
,
    NULL::text AS episode
,
    NULL::boolean 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 (
     (
           (clin.encounter c_enc
     
              JOIN clin.encounter_type c_ety 
                ON (
                       (c_enc.fk_type = c_ety.pk)
                 )
           )
     
   LEFT JOIN dem.org_unit d_ou 
          ON (
                 (c_enc.fk_location = d_ou.pk)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_ou.fk_org = d_o.pk)
     )
);

Index - Schema clin


View: clin.v_pat_episodes

clin.v_pat_episodes Structure
F-Key Name Type Description
SELECT cenc.fk_patient AS pk_patient
,
    cep.description
,
    cep.summary
,
    cep.is_open AS episode_open
,
    NULL::text AS health_issue
,
    NULL::boolean AS issue_active
,
    NULL::boolean AS issue_clinically_relevant
,
    
(
SELECT min
     (cle.started) AS min
           
  FROM clin.encounter cle
          
 WHERE (cle.pk = cep.fk_encounter)
         LIMIT 1
) AS started_first
,
    
(
SELECT max
     (cle.started) AS max
           
  FROM clin.encounter cle
          
 WHERE (cle.pk = cep.fk_encounter)
         LIMIT 1
) AS started_last
,
    
(
SELECT max
     (cle.last_affirmed) AS max
           
  FROM clin.encounter cle
          
 WHERE (cle.pk = cep.fk_encounter)
         LIMIT 1
) AS last_affirmed
,
    cep.pk AS pk_episode
,
    cep.fk_encounter AS pk_encounter
,
    NULL::integer AS pk_health_issue
,
    cep.modified_when AS episode_modified_when
,
    cep.modified_by AS episode_modified_by
,
    cep.diagnostic_certainty_classification
,
    NULL::text AS diagnostic_certainty_classification_issue
,
    COALESCE
(
     (
      SELECT array_agg
           (c_lc2e.fk_generic_code) AS array_agg
           
        FROM clin.lnk_code2episode c_lc2e
          
       WHERE (c_lc2e.fk_item = cep.pk)
     )
     , ARRAY[]::integer[]
) AS pk_generic_codes
,
    cep.xmin AS xmin_episode
   
FROM (clin.episode cep
     
  JOIN clin.encounter cenc 
    ON (
           (cep.fk_encounter = cenc.pk)
     )
)
  
WHERE (cep.fk_health_issue IS NULL)
UNION ALL
 
SELECT cenc.fk_patient AS pk_patient
,
    cep.description
,
    cep.summary
,
    cep.is_open AS episode_open
,
    chi.description AS health_issue
,
    chi.is_active AS issue_active
,
    chi.clinically_relevant AS issue_clinically_relevant
,
    
(
SELECT min
     (cle.started) AS min
           
  FROM clin.encounter cle
          
 WHERE (cle.pk = cep.fk_encounter)
         LIMIT 1
) AS started_first
,
    
(
SELECT max
     (cle.started) AS max
           
  FROM clin.encounter cle
          
 WHERE (cle.pk = cep.fk_encounter)
         LIMIT 1
) AS started_last
,
    
(
SELECT max
     (cle.last_affirmed) AS max
           
  FROM clin.encounter cle
          
 WHERE (cle.pk = cep.fk_encounter)
         LIMIT 1
) AS last_affirmed
,
    cep.pk AS pk_episode
,
    cep.fk_encounter AS pk_encounter
,
    cep.fk_health_issue AS pk_health_issue
,
    cep.modified_when AS episode_modified_when
,
    cep.modified_by AS episode_modified_by
,
    cep.diagnostic_certainty_classification
,
    chi.diagnostic_certainty_classification AS diagnostic_certainty_classification_issue
,
    COALESCE
(
     (
      SELECT array_agg
           (c_lc2e.fk_generic_code) AS array_agg
           
        FROM clin.lnk_code2episode c_lc2e
          
       WHERE (c_lc2e.fk_item = cep.pk)
     )
     , ARRAY[]::integer[]
) AS pk_generic_codes
,
    cep.xmin AS xmin_episode
   
FROM (
     (clin.episode cep
     
        JOIN clin.encounter cenc 
          ON (
                 (cep.fk_encounter = cenc.pk)
           )
     )
     
  JOIN clin.health_issue chi 
    ON (
           (cep.fk_health_issue = chi.pk)
     )
);

Index - Schema clin


View: clin.v_pat_episodes_journal

clin.v_pat_episodes_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_epi.modified_when
,
    c_enc.started AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_epi.modified_by)
     )
     , (
           ('<'::text || 
                 (c_epi.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    'a'::text AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (_
                                               ('Episode'::text) || 
                                            ' ('::text) ||
        CASE
            WHEN c_epi.is_open THEN _
                                               ('open'::text)
            ELSE _
                                               ('closed'::text)
        END
                                         ) || COALESCE
                                         (
                                               (
                                                  ', '::text || c_epi.diagnostic_certainty_classification
                                               )
                                               ,''::text
                                         )
                                   ) || 
                         '): '::text
                       ) || c_epi.description
                 ) || ';'::text
           ) || COALESCE
           (
                 (
                       (
                             (
                                   ('
 '::text || _
                                         ('Synopsis'::text)
                                   ) || ': '::text
                             ) || c_epi.summary
                       ) || ';'::text
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 ('
'::text || array_to_string
                       (
                             (
                              SELECT array_agg
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (r_csr.code || 
                                                                                      ' ('::text) || r_ds.name_short
                                                                                   ) || ' - '::text
                                                                             ) || r_ds.version
                                                                       ) || ' - '::text
                                                                 ) || r_ds.lang
                                                           ) || 
                                                 '): '::text
                                               ) || r_csr.term
                                         )
                                   ) AS array_agg
           
                                FROM (
                                         (clin.lnk_code2episode c_lc2e
             
                                            JOIN ref.coding_system_root r_csr 
                                              ON (
                                                     (c_lc2e.fk_generic_code = r_csr.pk_coding_system)
                                               )
                                         )
             
                                      JOIN ref.data_source r_ds 
                                        ON (
                                               (r_ds.pk = r_csr.fk_data_source)
                                         )
                                   )
          
                               WHERE (c_lc2e.fk_item = c_epi.pk)
                             )
                             ,'; '::text
                       )
                 ) || ';'::text
           )
           ,''::text
     )
) AS narrative
,
    c_epi.fk_encounter AS pk_encounter
,
    c_epi.pk AS pk_episode
,
    c_epi.fk_health_issue AS pk_health_issue
,
    c_epi.pk AS src_pk
,
    'clin.episode'::text AS src_table
,
    c_epi.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 (
     (
           (clin.episode c_epi
     
              JOIN clin.encounter c_enc 
                ON (
                       (c_epi.fk_encounter = c_enc.pk)
                 )
           )
     
        JOIN clin.encounter_type c_ety 
          ON (
                 (c_enc.fk_type = c_ety.pk)
           )
     )
     
LEFT JOIN clin.health_issue c_hi 
    ON (
           (c_epi.fk_health_issue = c_hi.pk)
     )
);

Index - Schema clin


View: clin.v_pat_items

clin.v_pat_items Structure
F-Key Name Type Description
SELECT cri.modified_when
,
    cri.modified_by
,
    cri.clin_when
,
        CASE cri.row_version
            WHEN 0 THEN false
            ELSE true
        END AS is_modified
,
    cenc.fk_patient AS pk_patient
,
    cri.pk_item
,
    cri.fk_encounter AS pk_encounter
,
    cri.fk_episode AS pk_episode
,
    cepi.fk_health_issue AS pk_health_issue
,
    cri.soap_cat
,
    cri.narrative
,
    
(
     (
           (pgn.nspname)::text || '.'::text
     ) || 
     (pgc.relname)::text
) AS src_table
   
FROM clin.clin_root_item cri
,
    clin.encounter cenc
,
    clin.episode cepi
,
    
(pg_class pgc
     
LEFT JOIN pg_namespace pgn 
    ON (
           (pgc.relnamespace = pgn.oid)
     )
)
  
WHERE (
     (cri.fk_encounter = cenc.pk)
   AND (cri.fk_episode = cepi.pk)
   AND (cri.tableoid = pgc.oid)
);

Index - Schema clin


View: clin.v_pat_last_vacc4indication

Lists *latest* vaccinations with total count per indication.

clin.v_pat_last_vacc4indication Structure
F-Key Name Type Description
SELECT c_vpv4i.pk_patient
,
    c_vpv4i.pk_vaccination
,
    c_vpv4i.date_given
,
    c_vpv4i.vaccine
,
    c_vpv4i.indication
,
    c_vpv4i.l10n_indication
,
    c_vpv4i.site
,
    c_vpv4i.batch_no
,
    c_vpv4i.reaction
,
    c_vpv4i.comment
,
    c_vpv4i.soap_cat
,
    c_vpv4i.modified_when
,
    c_vpv4i.modified_by
,
    c_vpv4i.row_version
,
    c_vpv4i.pk_vaccine
,
    c_vpv4i.atc_indication
,
    c_vpv4i.pk_provider
,
    c_vpv4i.pk_encounter
,
    c_vpv4i.pk_episode
,
    c_vpv4i.xmin_vaccination
,
    shots_per_ind.no_of_shots
   
FROM (clin.v_pat_vaccs4indication c_vpv4i
     
  JOIN (
      SELECT count
           (1) AS no_of_shots
           ,
            v_pat_vaccs4indication.pk_patient
           ,
            v_pat_vaccs4indication.atc_indication
           
        FROM clin.v_pat_vaccs4indication
          
    GROUP BY v_pat_vaccs4indication.pk_patient
           , v_pat_vaccs4indication.atc_indication
     ) shots_per_ind 
    ON (
           (
                 (c_vpv4i.pk_patient = shots_per_ind.pk_patient)
               AND (c_vpv4i.atc_indication = shots_per_ind.atc_indication)
           )
     )
)
  
WHERE (c_vpv4i.date_given = 
     (
      SELECT max
           (c_vpv4i_2.date_given) AS max
           
        FROM clin.v_pat_vaccs4indication c_vpv4i_2
          
       WHERE (
                 (c_vpv4i.pk_patient = c_vpv4i_2.pk_patient)
               AND (c_vpv4i.atc_indication = c_vpv4i_2.atc_indication)
           )
     )
);

Index - Schema clin


View: clin.v_pat_narrative_journal

clin.v_pat_narrative_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_n.modified_when
,
        CASE
            WHEN 
(c_n.soap_cat = ANY 
     (ARRAY['s'::text
           ,'o'::text
           ,'u'::text]
     )
) THEN c_enc.started
            WHEN 
(c_n.soap_cat IS NULL) THEN c_enc.last_affirmed
            WHEN 
(c_n.soap_cat = ANY 
     (ARRAY['a'::text
           ,'p'::text]
     )
) THEN c_enc.last_affirmed
            ELSE NULL::timestamp with time zone
        END AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_n.modified_by)
     )
     , (
           ('<'::text || 
                 (c_n.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_n.soap_cat
,
    c_n.narrative
,
    c_n.fk_encounter AS pk_encounter
,
    c_n.fk_episode AS pk_episode
,
    c_epi.fk_health_issue AS pk_health_issue
,
    c_n.pk AS src_pk
,
    'clin.clin_narrative'::text AS src_table
,
    c_n.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 (
     (
           (
                 (clin.clin_narrative c_n
     
                    JOIN clin.encounter c_enc 
                      ON (
                             (c_n.fk_encounter = c_enc.pk)
                       )
                 )
     
              JOIN clin.encounter_type c_ety 
                ON (
                       (c_enc.fk_type = c_ety.pk)
                 )
           )
     
        JOIN clin.episode c_epi 
          ON (
                 (c_n.fk_episode = c_epi.pk)
           )
     )
     
LEFT JOIN clin.health_issue c_hi 
    ON (
           (c_epi.fk_health_issue = c_hi.pk)
     )
);

Index - Schema clin


View: clin.v_pat_vaccs4indication

Lists all vaccinations for each indication for patients

clin.v_pat_vaccs4indication Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_shot.pk AS pk_vaccination
,
    c_shot.clin_when AS date_given
,
    r_dp.description AS vaccine
,
    _
(
     (r_s.atc || '-target'::text)
     ,'en'::text
) AS indication
,
        CASE
            WHEN 
(_
     (
           (r_s.atc || '-target'::text)
     ) = 
     (r_s.atc || '-target'::text)
) THEN _
(
     (r_s.atc || '-target'::text)
     ,'en'::text
)
            ELSE _
(
     (r_s.atc || '-target'::text)
)
        END AS l10n_indication
,
    c_shot.site
,
    c_shot.batch_no
,
    c_shot.reaction
,
    c_shot.narrative AS comment
,
    c_shot.soap_cat
,
    c_shot.modified_when
,
    c_shot.modified_by
,
    c_shot.row_version
,
    c_shot.fk_vaccine AS pk_vaccine
,
    r_s.atc AS atc_indication
,
    c_shot.fk_provider AS pk_provider
,
    c_shot.fk_encounter AS pk_encounter
,
    c_shot.fk_episode AS pk_episode
,
    c_shot.xmin AS xmin_vaccination
   
FROM (
     (
           (
                 (
                       (
                             (clin.vaccination c_shot
     
                                JOIN clin.encounter c_enc 
                                  ON (
                                         (c_enc.pk = c_shot.fk_encounter)
                                   )
                             )
     
                          JOIN ref.vaccine r_v 
                            ON (
                                   (r_v.pk = c_shot.fk_vaccine)
                             )
                       )
     
                    JOIN ref.drug_product r_dp 
                      ON (
                             (r_dp.pk = r_v.fk_drug_product)
                       )
                 )
     
              JOIN ref.lnk_dose2drug r_ld2d 
                ON (
                       (r_ld2d.fk_drug_product = r_dp.pk)
                 )
           )
     
        JOIN ref.dose r_d 
          ON (
                 (r_d.pk = r_ld2d.fk_dose)
           )
     )
     
  JOIN ref.substance r_s 
    ON (
           (r_s.pk = r_d.fk_substance)
     )
);

Index - Schema clin


View: clin.v_potential_problem_list

clin.v_potential_problem_list Structure
F-Key Name Type Description
SELECT (
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = cep.fk_encounter)
) AS pk_patient
,
    cep.description AS problem
,
    cep.summary
,
    'episode'::text AS type
,
    _
('episode'::text) AS l10n_type
,
    false AS problem_active
,
    false AS clinically_relevant
,
    cep.pk AS pk_episode
,
    cep.fk_health_issue AS pk_health_issue
,
    cep.diagnostic_certainty_classification
,
    cep.fk_encounter AS pk_encounter
,
    cep.modified_when
   
FROM clin.episode cep
  
WHERE (cep.is_open IS FALSE)
UNION
 
SELECT (
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = chi.fk_encounter)
) AS pk_patient
,
    chi.description AS problem
,
    chi.summary
,
    'issue'::text AS type
,
    _
('health issue'::text) AS l10n_type
,
    chi.is_active AS problem_active
,
    false AS clinically_relevant
,
    NULL::integer AS pk_episode
,
    chi.pk AS pk_health_issue
,
    chi.diagnostic_certainty_classification
,
    chi.fk_encounter AS pk_encounter
,
    chi.modified_when
   
FROM clin.health_issue chi
  
WHERE (chi.clinically_relevant IS FALSE);

Index - Schema clin


View: clin.v_problem_list

clin.v_problem_list Structure
F-Key Name Type Description
SELECT (
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = cep.fk_encounter)
) AS pk_patient
,
    cep.description AS problem
,
    cep.summary
,
    'episode'::text AS type
,
    _
('episode'::text) AS l10n_type
,
    true AS problem_active
,
    true AS clinically_relevant
,
    cep.pk AS pk_episode
,
    cep.fk_health_issue AS pk_health_issue
,
    cep.diagnostic_certainty_classification
,
    cep.fk_encounter AS pk_encounter
,
    cep.modified_when
   
FROM clin.episode cep
  
WHERE (cep.is_open IS TRUE)
UNION
 
SELECT (
SELECT encounter.fk_patient
           
  FROM clin.encounter
          
 WHERE (encounter.pk = chi.fk_encounter)
) AS pk_patient
,
    chi.description AS problem
,
    chi.summary
,
    'issue'::text AS type
,
    _
('health issue'::text) AS l10n_type
,
    chi.is_active AS problem_active
,
    true AS clinically_relevant
,
    NULL::integer AS pk_episode
,
    chi.pk AS pk_health_issue
,
    chi.diagnostic_certainty_classification
,
    chi.fk_encounter AS pk_encounter
,
    chi.modified_when
   
FROM clin.health_issue chi
  
WHERE (chi.clinically_relevant IS TRUE);

Index - Schema clin


View: clin.v_procedures

clin.v_procedures Structure
F-Key Name Type Description
SELECT v_procedures_at_hospital.pk_procedure
,
    v_procedures_at_hospital.pk_patient
,
    v_procedures_at_hospital.soap_cat
,
    v_procedures_at_hospital.clin_when
,
    v_procedures_at_hospital.clin_end
,
    v_procedures_at_hospital.is_ongoing
,
    v_procedures_at_hospital.performed_procedure
,
    v_procedures_at_hospital.comment
,
    v_procedures_at_hospital.unit
,
    v_procedures_at_hospital.organization
,
    v_procedures_at_hospital.episode
,
    v_procedures_at_hospital.health_issue
,
    v_procedures_at_hospital.modified_when
,
    v_procedures_at_hospital.modified_by
,
    v_procedures_at_hospital.row_version
,
    v_procedures_at_hospital.pk_encounter
,
    v_procedures_at_hospital.pk_episode
,
    v_procedures_at_hospital.pk_hospital_stay
,
    v_procedures_at_hospital.pk_health_issue
,
    v_procedures_at_hospital.pk_doc
,
    v_procedures_at_hospital.pk_org
,
    v_procedures_at_hospital.pk_org_unit
,
    v_procedures_at_hospital.pk_generic_codes
,
    v_procedures_at_hospital.xmin_procedure
   
FROM clin.v_procedures_at_hospital

UNION ALL
 
SELECT v_procedures_not_at_hospital.pk_procedure
,
    v_procedures_not_at_hospital.pk_patient
,
    v_procedures_not_at_hospital.soap_cat
,
    v_procedures_not_at_hospital.clin_when
,
    v_procedures_not_at_hospital.clin_end
,
    v_procedures_not_at_hospital.is_ongoing
,
    v_procedures_not_at_hospital.performed_procedure
,
    v_procedures_not_at_hospital.comment
,
    v_procedures_not_at_hospital.unit
,
    v_procedures_not_at_hospital.organization
,
    v_procedures_not_at_hospital.episode
,
    v_procedures_not_at_hospital.health_issue
,
    v_procedures_not_at_hospital.modified_when
,
    v_procedures_not_at_hospital.modified_by
,
    v_procedures_not_at_hospital.row_version
,
    v_procedures_not_at_hospital.pk_encounter
,
    v_procedures_not_at_hospital.pk_episode
,
    v_procedures_not_at_hospital.pk_hospital_stay
,
    v_procedures_not_at_hospital.pk_health_issue
,
    v_procedures_not_at_hospital.pk_doc
,
    v_procedures_not_at_hospital.pk_org
,
    v_procedures_not_at_hospital.pk_org_unit
,
    v_procedures_not_at_hospital.pk_generic_codes
,
    v_procedures_not_at_hospital.xmin_procedure
   
FROM clin.v_procedures_not_at_hospital;

Index - Schema clin


View: clin.v_procedures_at_hospital

clin.v_procedures_at_hospital Structure
F-Key Name Type Description
SELECT c_pr.pk AS pk_procedure
,
    c_enc.fk_patient AS pk_patient
,
    c_pr.soap_cat
,
    c_pr.clin_when
,
    c_pr.clin_end
,
    c_pr.is_ongoing
,
    c_pr.narrative AS performed_procedure
,
    c_pr.comment
,
    c_vhs.ward AS unit
,
    c_vhs.hospital AS organization
,
    c_ep.description AS episode
,
    c_hi.description AS health_issue
,
    c_pr.modified_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_pr.modified_by)
     )
     , (
           ('<'::text || 
                 (c_pr.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_pr.row_version
,
    c_pr.fk_encounter AS pk_encounter
,
    c_pr.fk_episode AS pk_episode
,
    c_pr.fk_hospital_stay AS pk_hospital_stay
,
    c_ep.fk_health_issue AS pk_health_issue
,
    c_pr.fk_doc AS pk_doc
,
    c_vhs.pk_org
,
    c_vhs.pk_org_unit
,
    COALESCE
(
     (
      SELECT array_agg
           (c_lc2p.fk_generic_code) AS array_agg
           
        FROM clin.lnk_code2procedure c_lc2p
          
       WHERE (c_lc2p.fk_item = c_pr.pk)
     )
     , ARRAY[]::integer[]
) AS pk_generic_codes
,
    c_pr.xmin AS xmin_procedure
   
FROM (
     (
           (
                 (clin.procedure c_pr
     
                    JOIN clin.encounter c_enc 
                      ON (
                             (c_pr.fk_encounter = c_enc.pk)
                       )
                 )
     
              JOIN clin.episode c_ep 
                ON (
                       (c_pr.fk_episode = c_ep.pk)
                 )
           )
     
   LEFT JOIN clin.health_issue c_hi 
          ON (
                 (c_ep.fk_health_issue = c_hi.pk)
           )
     )
     
LEFT JOIN clin.v_hospital_stays c_vhs 
    ON (
           (c_pr.fk_hospital_stay = c_vhs.pk_hospital_stay)
     )
)
  
WHERE (c_pr.fk_hospital_stay IS NOT NULL);

Index - Schema clin


View: clin.v_procedures_at_hospital_journal

clin.v_procedures_at_hospital_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_pr.modified_when
,
    c_pr.clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_pr.modified_by)
     )
     , (
           ('<'::text || 
                 (c_pr.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
        CASE
            WHEN 
(c_pr.is_ongoing IS TRUE) THEN 'p'::text
            ELSE 'o'::text
        END AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (_
                                                                       ('Procedure'::text) || ' "'::text
                                                                 ) || c_pr.narrative
                                                           ) || '"'::text
                                                     ) || 
                                                  ' ('::text) || d_ou.description
                                               ) || ' @ '::text
                                         ) || d_o.description
                                   ) || COALESCE
                                   (
                                         (
                                               (
                                                     (
                                                        ', '::text || _
                                                           ('until'::text)
                                                     ) || ' '::text
                                               ) || to_char
                                               (c_pr.clin_end
                                                     ,'YYYY Mon DD'::text
                                               )
                                         )
                                         ,
        CASE
            WHEN 
                                         (c_pr.is_ongoing IS TRUE) THEN 
                                         (
                                            ', '::text || _
                                               ('ongoing'::text)
                                         )
            ELSE ''::text
        END
                                   )
                             ) || 
                     ')'::text
                 ) || COALESCE
                 (
                       ('
 '::text || c_pr.comment)
                       ,''::text
                 )
           ) || COALESCE
           (
                 (
                       ('
 '::text || _
                             ('document #'::text)
                       ) || c_pr.fk_doc
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 ('
'::text || array_to_string
                       (
                             (
                              SELECT array_agg
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (r_csr.code || 
                                                                                      ' ('::text) || r_ds.name_short
                                                                                   ) || ' - '::text
                                                                             ) || r_ds.version
                                                                       ) || ' - '::text
                                                                 ) || r_ds.lang
                                                           ) || 
                                                 '): '::text
                                               ) || r_csr.term
                                         )
                                   ) AS array_agg
           
                                FROM (
                                         (clin.lnk_code2procedure c_lc2p
             
                                            JOIN ref.coding_system_root r_csr 
                                              ON (
                                                     (c_lc2p.fk_generic_code = r_csr.pk_coding_system)
                                               )
                                         )
             
                                      JOIN ref.data_source r_ds 
                                        ON (
                                               (r_ds.pk = r_csr.fk_data_source)
                                         )
                                   )
          
                               WHERE (c_lc2p.fk_item = c_pr.pk)
                             )
                             ,'; '::text
                       )
                 ) || ';'::text
           )
           ,''::text
     )
) AS narrative
,
    c_pr.fk_encounter AS pk_encounter
,
    c_pr.fk_episode AS pk_episode
,
    c_epi.fk_health_issue AS pk_health_issue
,
    c_pr.pk AS src_pk
,
    'clin.procedure'::text AS src_table
,
    c_pr.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 (
     (
           (
                 (
                       (
                             (
                                   (clin.procedure c_pr
     
                                      JOIN clin.encounter c_enc 
                                        ON (
                                               (c_pr.fk_encounter = c_enc.pk)
                                         )
                                   )
     
                                JOIN clin.encounter_type c_ety 
                                  ON (
                                         (c_enc.fk_type = c_ety.pk)
                                   )
                             )
     
                          JOIN clin.episode c_epi 
                            ON (
                                   (c_pr.fk_episode = c_epi.pk)
                             )
                       )
     
               LEFT JOIN clin.health_issue c_hi 
                      ON (
                             (c_epi.fk_health_issue = c_hi.pk)
                       )
                 )
     
         LEFT JOIN clin.hospital_stay c_hs 
                ON (
                       (c_pr.fk_hospital_stay = c_hs.pk)
                 )
           )
     
   LEFT JOIN dem.org_unit d_ou 
          ON (
                 (c_hs.fk_org_unit = d_ou.pk)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_ou.fk_org = d_o.pk)
     )
)
  
WHERE (c_pr.fk_hospital_stay IS NOT NULL);

Index - Schema clin


View: clin.v_procedures_journal

clin.v_procedures_journal Structure
F-Key Name Type Description
SELECT v_procedures_at_hospital_journal.pk_patient
,
    v_procedures_at_hospital_journal.modified_when
,
    v_procedures_at_hospital_journal.clin_when
,
    v_procedures_at_hospital_journal.modified_by
,
    v_procedures_at_hospital_journal.soap_cat
,
    v_procedures_at_hospital_journal.narrative
,
    v_procedures_at_hospital_journal.pk_encounter
,
    v_procedures_at_hospital_journal.pk_episode
,
    v_procedures_at_hospital_journal.pk_health_issue
,
    v_procedures_at_hospital_journal.src_pk
,
    v_procedures_at_hospital_journal.src_table
,
    v_procedures_at_hospital_journal.row_version
,
    v_procedures_at_hospital_journal.health_issue
,
    v_procedures_at_hospital_journal.issue_laterality
,
    v_procedures_at_hospital_journal.issue_active
,
    v_procedures_at_hospital_journal.issue_clinically_relevant
,
    v_procedures_at_hospital_journal.issue_confidential
,
    v_procedures_at_hospital_journal.episode
,
    v_procedures_at_hospital_journal.episode_open
,
    v_procedures_at_hospital_journal.encounter_started
,
    v_procedures_at_hospital_journal.encounter_last_affirmed
,
    v_procedures_at_hospital_journal.encounter_type
,
    v_procedures_at_hospital_journal.encounter_l10n_type
   
FROM clin.v_procedures_at_hospital_journal

UNION ALL
 
SELECT v_procedures_not_at_hospital_journal.pk_patient
,
    v_procedures_not_at_hospital_journal.modified_when
,
    v_procedures_not_at_hospital_journal.clin_when
,
    v_procedures_not_at_hospital_journal.modified_by
,
    v_procedures_not_at_hospital_journal.soap_cat
,
    v_procedures_not_at_hospital_journal.narrative
,
    v_procedures_not_at_hospital_journal.pk_encounter
,
    v_procedures_not_at_hospital_journal.pk_episode
,
    v_procedures_not_at_hospital_journal.pk_health_issue
,
    v_procedures_not_at_hospital_journal.src_pk
,
    v_procedures_not_at_hospital_journal.src_table
,
    v_procedures_not_at_hospital_journal.row_version
,
    v_procedures_not_at_hospital_journal.health_issue
,
    v_procedures_not_at_hospital_journal.issue_laterality
,
    v_procedures_not_at_hospital_journal.issue_active
,
    v_procedures_not_at_hospital_journal.issue_clinically_relevant
,
    v_procedures_not_at_hospital_journal.issue_confidential
,
    v_procedures_not_at_hospital_journal.episode
,
    v_procedures_not_at_hospital_journal.episode_open
,
    v_procedures_not_at_hospital_journal.encounter_started
,
    v_procedures_not_at_hospital_journal.encounter_last_affirmed
,
    v_procedures_not_at_hospital_journal.encounter_type
,
    v_procedures_not_at_hospital_journal.encounter_l10n_type
   
FROM clin.v_procedures_not_at_hospital_journal;

Index - Schema clin


View: clin.v_procedures_not_at_hospital

clin.v_procedures_not_at_hospital Structure
F-Key Name Type Description
SELECT c_pr.pk AS pk_procedure
,
    c_enc.fk_patient AS pk_patient
,
    c_pr.soap_cat
,
    c_pr.clin_when
,
    c_pr.clin_end
,
    c_pr.is_ongoing
,
    c_pr.narrative AS performed_procedure
,
    c_pr.comment
,
    d_ou.description AS unit
,
    d_o.description AS organization
,
    c_ep.description AS episode
,
    c_hi.description AS health_issue
,
    c_pr.modified_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_pr.modified_by)
     )
     , (
           ('<'::text || 
                 (c_pr.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    c_pr.row_version
,
    c_pr.fk_encounter AS pk_encounter
,
    c_pr.fk_episode AS pk_episode
,
    c_pr.fk_hospital_stay AS pk_hospital_stay
,
    c_ep.fk_health_issue AS pk_health_issue
,
    c_pr.fk_doc AS pk_doc
,
    d_o.pk AS pk_org
,
    d_ou.pk AS pk_org_unit
,
    COALESCE
(
     (
      SELECT array_agg
           (c_lc2p.fk_generic_code) AS array_agg
           
        FROM clin.lnk_code2procedure c_lc2p
          
       WHERE (c_lc2p.fk_item = c_pr.pk)
     )
     , ARRAY[]::integer[]
) AS pk_generic_codes
,
    c_pr.xmin AS xmin_procedure
   
FROM (
     (
           (
                 (
                       (clin.procedure c_pr
     
                          JOIN clin.encounter c_enc 
                            ON (
                                   (c_pr.fk_encounter = c_enc.pk)
                             )
                       )
     
                    JOIN clin.episode c_ep 
                      ON (
                             (c_pr.fk_episode = c_ep.pk)
                       )
                 )
     
         LEFT JOIN clin.health_issue c_hi 
                ON (
                       (c_ep.fk_health_issue = c_hi.pk)
                 )
           )
     
   LEFT JOIN dem.org_unit d_ou 
          ON (
                 (d_ou.pk = c_pr.fk_org_unit)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_o.pk = d_ou.fk_org)
     )
)
  
WHERE (c_pr.fk_hospital_stay IS NULL);

Index - Schema clin


View: clin.v_procedures_not_at_hospital_journal

clin.v_procedures_not_at_hospital_journal Structure
F-Key Name Type Description
SELECT c_enc.fk_patient AS pk_patient
,
    c_pr.modified_when
,
    c_pr.clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = c_pr.modified_by)
     )
     , (
           ('<'::text || 
                 (c_pr.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
        CASE
            WHEN 
(c_pr.is_ongoing IS TRUE) THEN 'p'::text
            ELSE 'o'::text
        END AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (_
                                                                       ('Procedure'::text) || ' "'::text
                                                                 ) || c_pr.narrative
                                                           ) || '"'::text
                                                     ) || 
                                                  ' ('::text) || d_ou.description
                                               ) || ' @ '::text
                                         ) || d_o.description
                                   ) || COALESCE
                                   (
                                         (
                                               (
                                                     (
                                                        ', '::text || _
                                                           ('until'::text)
                                                     ) || ' '::text
                                               ) || to_char
                                               (c_pr.clin_end
                                                     ,'YYYY Mon DD'::text
                                               )
                                         )
                                         ,
        CASE
            WHEN 
                                         (c_pr.is_ongoing IS TRUE) THEN 
                                         (
                                            ', '::text || _
                                               ('ongoing'::text)
                                         )
            ELSE ''::text
        END
                                   )
                             ) || 
                     ')'::text
                 ) || COALESCE
                 (
                       ('
 '::text || c_pr.comment)
                       ,''::text
                 )
           ) || COALESCE
           (
                 (
                       ('
 '::text || _
                             ('document #'::text)
                       ) || c_pr.fk_doc
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 ('
'::text || array_to_string
                       (
                             (
                              SELECT array_agg
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (r_csr.code || 
                                                                                      ' ('::text) || r_ds.name_short
                                                                                   ) || ' - '::text
                                                                             ) || r_ds.version
                                                                       ) || ' - '::text
                                                                 ) || r_ds.lang
                                                           ) || 
                                                 '): '::text
                                               ) || r_csr.term
                                         )
                                   ) AS array_agg
           
                                FROM (
                                         (clin.lnk_code2procedure c_lc2p
             
                                            JOIN ref.coding_system_root r_csr 
                                              ON (
                                                     (c_lc2p.fk_generic_code = r_csr.pk_coding_system)
                                               )
                                         )
             
                                      JOIN ref.data_source r_ds 
                                        ON (
                                               (r_ds.pk = r_csr.fk_data_source)
                                         )
                                   )
          
                               WHERE (c_lc2p.fk_item = c_pr.pk)
                             )
                             ,'; '::text
                       )
                 ) || ';'::text
           )
           ,''::text
     )
) AS narrative
,
    c_pr.fk_encounter AS pk_encounter
,
    c_pr.fk_episode AS pk_episode
,
    c_epi.fk_health_issue AS pk_health_issue
,
    c_pr.pk AS src_pk
,
    'clin.procedure'::text AS src_table
,
    c_pr.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 (
     (
           (
                 (
                       (
                             (clin.procedure c_pr
     
                                JOIN clin.encounter c_enc 
                                  ON (
                                         (c_pr.fk_encounter = c_enc.pk)
                                   )
                             )
     
                          JOIN clin.encounter_type c_ety 
                            ON (
                                   (c_enc.fk_type = c_ety.pk)
                             )
                       )
     
                    JOIN clin.episode c_epi 
                      ON (
                             (c_pr.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 (
                 (c_pr.fk_org_unit = d_ou.pk)
           )
     )
     
LEFT JOIN dem.org d_o 
    ON (
           (d_ou.fk_org = d_o.pk)
     )
)
  
WHERE (c_pr.fk_hospital_stay IS NULL);

Index - Schema clin


View: clin.v_reminders_journal

clin.v_reminders_journal Structure
F-Key Name Type Description
SELECT d_mi.fk_patient AS pk_patient
,
    d_mi.modified_when
,
    d_mi.due_date AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = d_mi.modified_by)
     )
     , (
           ('<'::text || 
                 (d_mi.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    NULL::text AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (
                                                                                         (_
                                                                                               ('Due today'::text) || 
                                                                                            ' ('::text) || d_vit.l10n_category
                                                                                         ) || ' - '::text
                                                                                   ) || d_vit.l10n_type
                                                                             ) || 
                                                                     ')'::text
                                                                 ) || '
'::text
                                                           ) || COALESCE
                                                           (
                                                                 (
                                                                       (' '::text || d_mi.comment) || '
'::text
                                                                 )
                                                                 ,''::text
                                                           )
                                                     ) || COALESCE
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (' '::text || _
                                                                                   ('Will expire:'::text)
                                                                             ) || ' '::text
                                                                       ) || to_char
                                                                       (
                                                                             (d_mi.expiry_date)::timestamp with time zone
                                                                             ,'YYYY-MM-DD'::text
                                                                       )
                                                                 ) || '
'::text
                                                           )
                                                           ,''::text
                                                     )
                                               ) || ' '::text
                                         ) || _
                                         ('Importance:'::text)
                                   ) || ' '::text
                             ) || d_mi.importance
                       ) || '
'::text
                 ) || COALESCE
                 (
                       (
                             (
                                   (
                                         (' '::text || _
                                               ('Context:'::text)
                                         ) || ' '::text
                                   ) || array_to_string
                                   (d_mi.ufk_context
                                         ,','::text
                                         ,'?'::text
                                   )
                             ) || '
'::text
                       )
                       ,''::text
                 )
           ) || COALESCE
           (
                 (
                       (
                             (
                                   (' '::text || _
                                         ('Data:'::text)
                                   ) || ' '::text
                             ) || d_mi.data
                       ) || '
'::text
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 (
                       (' '::text || _
                             ('Provider:'::text)
                       ) || ' '::text
                 ) || d_st.short_alias
           )
           ,''::text
     )
) AS narrative
,
    
(
SELECT c_e.pk
           
  FROM clin.encounter c_e
          
 WHERE (c_e.fk_patient = d_mi.fk_patient)
          
ORDER BY c_e.started DESC
         LIMIT 1
) AS pk_encounter
,
    NULL::integer AS pk_episode
,
    NULL::integer AS pk_health_issue
,
    d_mi.pk AS src_pk
,
    'dem.message_inbox'::text AS src_table
,
    d_mi.row_version
,
    NULL::text AS health_issue
,
    NULL::text AS issue_laterality
,
    NULL::boolean AS issue_active
,
    NULL::boolean AS issue_clinically_relevant
,
    NULL::boolean AS issue_confidential
,
    NULL::text AS episode
,
    NULL::boolean AS episode_open
,
    
(
SELECT c_e.started
           
  FROM clin.encounter c_e
          
 WHERE (c_e.fk_patient = d_mi.fk_patient)
          
ORDER BY c_e.started DESC
         LIMIT 1
) AS encounter_started
,
    
(
SELECT c_e.last_affirmed
           
  FROM clin.encounter c_e
          
 WHERE (c_e.fk_patient = d_mi.fk_patient)
          
ORDER BY c_e.started DESC
         LIMIT 1
) AS encounter_last_affirmed
,
    NULL::text AS encounter_type
,
    NULL::text AS encounter_l10n_type
   
FROM (
     (dem.message_inbox d_mi
     
        JOIN dem.v_inbox_item_type d_vit 
          ON (
                 (d_mi.fk_inbox_item_type = d_vit.pk_type)
           )
     )
     
LEFT JOIN dem.staff d_st 
    ON (
           (d_mi.fk_staff = d_st.pk)
     )
)
  
WHERE (
     (d_mi.fk_patient IS NOT NULL)
   AND (d_vit.category = 'clinical'::text)
   AND (d_mi.due_date IS NOT NULL)
)
UNION
 
SELECT d_mi.fk_patient AS pk_patient
,
    d_mi.modified_when
,
    d_mi.expiry_date AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = d_mi.modified_by)
     )
     , (
           ('<'::text || 
                 (d_mi.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    NULL::text AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (
                                                                                         (_
                                                                                               ('Epires today'::text) || 
                                                                                            ' ('::text) || d_vit.l10n_category
                                                                                         ) || ' - '::text
                                                                                   ) || d_vit.l10n_type
                                                                             ) || 
                                                                     ')'::text
                                                                 ) || '
'::text
                                                           ) || COALESCE
                                                           (
                                                                 (
                                                                       (' '::text || d_mi.comment) || '
'::text
                                                                 )
                                                                 ,''::text
                                                           )
                                                     ) || COALESCE
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (' '::text || _
                                                                                   ('Was due:'::text)
                                                                             ) || ' '::text
                                                                       ) || to_char
                                                                       (
                                                                             (d_mi.due_date)::timestamp with time zone
                                                                             ,'YYYY-MM-DD'::text
                                                                       )
                                                                 ) || '
'::text
                                                           )
                                                           ,''::text
                                                     )
                                               ) || ' '::text
                                         ) || _
                                         ('Importance:'::text)
                                   ) || ' '::text
                             ) || d_mi.importance
                       ) || '
'::text
                 ) || COALESCE
                 (
                       (
                             (
                                   (
                                         (' '::text || _
                                               ('Context:'::text)
                                         ) || ' '::text
                                   ) || array_to_string
                                   (d_mi.ufk_context
                                         ,','::text
                                         ,'?'::text
                                   )
                             ) || '
'::text
                       )
                       ,''::text
                 )
           ) || COALESCE
           (
                 (
                       (
                             (
                                   (' '::text || _
                                         ('Data:'::text)
                                   ) || ' '::text
                             ) || d_mi.data
                       ) || '
'::text
                 )
                 ,''::text
           )
     ) || COALESCE
     (
           (
                 (
                       (' '::text || _
                             ('Provider:'::text)
                       ) || ' '::text
                 ) || d_st.short_alias
           )
           ,''::text
     )
) AS narrative
,
    
(
SELECT c_e.pk
           
  FROM clin.encounter c_e
          
 WHERE (c_e.fk_patient = d_mi.fk_patient)
          
ORDER BY c_e.started DESC
         LIMIT 1
) AS pk_encounter
,
    NULL::integer AS pk_episode
,
    NULL::integer AS pk_health_issue
,
    d_mi.pk AS src_pk
,
    'dem.message_inbox'::text AS src_table
,
    d_mi.row_version
,
    NULL::text AS health_issue
,
    NULL::text AS issue_laterality
,
    NULL::boolean AS issue_active
,
    NULL::boolean AS issue_clinically_relevant
,
    NULL::boolean AS issue_confidential
,
    NULL::text AS episode
,
    NULL::boolean AS episode_open
,
    
(
SELECT c_e.started
           
  FROM clin.encounter c_e
          
 WHERE (c_e.fk_patient = d_mi.fk_patient)
          
ORDER BY c_e.started DESC
         LIMIT 1
) AS encounter_started
,
    
(
SELECT c_e.last_affirmed
           
  FROM clin.encounter c_e
          
 WHERE (c_e.fk_patient = d_mi.fk_patient)
          
ORDER BY c_e.started DESC
         LIMIT 1
) AS encounter_last_affirmed
,
    NULL::text AS encounter_type
,
    NULL::text AS encounter_l10n_type
   
FROM (
     (dem.message_inbox d_mi
     
        JOIN dem.v_inbox_item_type d_vit 
          ON (
                 (d_mi.fk_inbox_item_type = d_vit.pk_type)
           )
     )
     
LEFT JOIN dem.staff d_st 
    ON (
           (d_mi.fk_staff = d_st.pk)
     )
)
  
WHERE (
     (d_mi.fk_patient IS NOT NULL)
   AND (d_vit.category = 'clinical'::text)
   AND (d_mi.expiry_date IS NOT NULL)
)
UNION
 
SELECT d_mi.fk_patient AS pk_patient
,
    d_mi.modified_when
,
    d_mi.modified_when AS clin_when
,
    COALESCE
(
     (
      SELECT staff.short_alias
           
        FROM dem.staff
          
       WHERE (staff.db_user = d_mi.modified_by)
     )
     , (
           ('<'::text || 
                 (d_mi.modified_by)::text
           ) || '>'::text
     )
) AS modified_by
,
    NULL::text AS soap_cat
,
    
(
     (
           (
                 (
                       (
                             (
                                   (
                                         (
                                               (
                                                     (
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (
                                                                                         (
                                                                                               (_
                                                                                                     ('Clinical reminder'::text) || 
                                                                                                  ' ('::text) || d_vit.l10n_category
                                                                                               ) || ' - '::text
                                                                                         ) || d_vit.l10n_type
                                                                                   ) || 
                                                                           ')'::text
                                                                       ) || '
'::text
                                                                 ) || COALESCE
                                                                 (
                                                                       (
                                                                             (' '::text || d_mi.comment) || '
'::text
                                                                       )
                                                                       ,''::text
                                                                 )
                                                           ) || COALESCE
                                                           (
                                                                 (
                                                                       (
                                                                             (
                                                                                   (' '::text || _
                                                                                         ('Due:'::text)
                                                                                   ) || ' '::text
                                                                             ) || to_char