-- -- PostgreSQL database dump -- SET client_encoding = 'UTF8'; SET standard_conforming_strings = off; SET check_function_bodies = false; SET client_min_messages = warning; SET escape_string_warning = off; -- -- Name: gnumed_v13; Type: DATABASE; Schema: -; Owner: gm-dbo -- CREATE DATABASE gnumed_v13 WITH TEMPLATE = template0 ENCODING = 'UTF8'; ALTER DATABASE gnumed_v13 OWNER TO "gm-dbo"; \connect gnumed_v13 SET client_encoding = 'UTF8'; SET standard_conforming_strings = off; SET check_function_bodies = false; SET client_min_messages = warning; SET escape_string_warning = off; -- -- Name: au; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA au; ALTER SCHEMA au OWNER TO "gm-dbo"; -- -- Name: audit; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA audit; ALTER SCHEMA audit OWNER TO "gm-dbo"; -- -- Name: bill; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA bill; ALTER SCHEMA bill OWNER TO "gm-dbo"; -- -- Name: SCHEMA bill; Type: COMMENT; Schema: -; Owner: gm-dbo -- COMMENT ON SCHEMA bill IS 'Holds everything related to billing.'; -- -- Name: blobs; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA blobs; ALTER SCHEMA blobs OWNER TO "gm-dbo"; -- -- Name: cfg; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA cfg; ALTER SCHEMA cfg OWNER TO "gm-dbo"; -- -- Name: SCHEMA cfg; Type: COMMENT; Schema: -; Owner: gm-dbo -- COMMENT ON SCHEMA cfg IS 'This schema holds all the configuration data.'; -- -- Name: clin; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA clin; ALTER SCHEMA clin OWNER TO "gm-dbo"; -- -- Name: de_de; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA de_de; ALTER SCHEMA de_de OWNER TO "gm-dbo"; -- -- Name: dem; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA dem; ALTER SCHEMA dem OWNER TO "gm-dbo"; -- -- Name: gm; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA gm; ALTER SCHEMA gm OWNER TO "gm-dbo"; -- -- Name: i18n; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA i18n; ALTER SCHEMA i18n OWNER TO "gm-dbo"; -- -- Name: ref; Type: SCHEMA; Schema: -; Owner: gm-dbo -- CREATE SCHEMA ref; ALTER SCHEMA ref OWNER TO "gm-dbo"; -- -- Name: SCHEMA ref; Type: COMMENT; Schema: -; Owner: gm-dbo -- COMMENT ON SCHEMA ref IS 'This schema holds data that is "reference material" which comes pre-installed with a GNUmed database. Examples are: - document types - ICD codes - form templates'; -- -- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres -- CREATE PROCEDURAL LANGUAGE plpgsql; ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres; SET search_path = audit, pg_catalog; -- -- Name: add_table_for_audit(name, name); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION add_table_for_audit(name, name) RETURNS unknown AS $_$ 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;$_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.add_table_for_audit(name, name) OWNER TO "gm-dbo"; -- -- Name: FUNCTION add_table_for_audit(name, name); Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON FUNCTION add_table_for_audit(name, name) IS 'sanity-checking convenience function for marking tables for auditing'; -- -- Name: add_table_for_audit(name); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION add_table_for_audit(name) RETURNS unknown AS $_$ select audit.add_table_for_audit('public', $1);$_$ LANGUAGE sql SECURITY DEFINER; ALTER FUNCTION audit.add_table_for_audit(name) OWNER TO "gm-dbo"; -- -- Name: FUNCTION add_table_for_audit(name); Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON FUNCTION add_table_for_audit(name) IS 'sanity-checking convenience function for marking tables for auditing, schema is always "public"'; -- -- Name: ft_del_access_log(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_access_log() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_access_log ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, user_action ) 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.user_action ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_access_log() OWNER TO "gm-dbo"; -- -- Name: ft_del_active_substance(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_active_substance() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_active_substance() OWNER TO "gm-dbo"; -- -- Name: ft_del_address(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_address() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_address ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_street, OLD.aux_street, OLD.number, OLD.subunit, OLD.addendum, OLD.lat_lon ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_address() OWNER TO "gm-dbo"; -- -- Name: ft_del_allergy(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_allergy() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_allergy ( 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, 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_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.substance, OLD.substance_code, OLD.generics, OLD.allergene, OLD.atc_code, OLD.fk_type, OLD.generic_specific, OLD.definite ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_allergy() OWNER TO "gm-dbo"; -- -- Name: ft_del_allergy_state(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_allergy_state() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_allergy_state ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, has_allergy, comment, last_confirmed, fk_encounter ) 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.has_allergy, OLD.comment, OLD.last_confirmed, OLD.fk_encounter ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_allergy_state() OWNER TO "gm-dbo"; -- -- Name: ft_del_atc_group(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_atc_group() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_atc_group() OWNER TO "gm-dbo"; -- -- Name: ft_del_atc_substance(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_atc_substance() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_atc_substance() OWNER TO "gm-dbo"; -- -- Name: ft_del_beh_fall_typ(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_beh_fall_typ() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_beh_fall_typ ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, code, kurzform, name ) 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.kurzform, OLD.name ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_beh_fall_typ() OWNER TO "gm-dbo"; -- -- Name: ft_del_behandlungsfall(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_behandlungsfall() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_behandlungsfall() OWNER TO "gm-dbo"; -- -- Name: ft_del_branded_drug(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_branded_drug() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_branded_drug ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_branded_drug() OWNER TO "gm-dbo"; -- -- Name: ft_del_clin_aux_note(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_clin_aux_note() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_clin_aux_note ( 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 ) 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 ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_clin_aux_note() OWNER TO "gm-dbo"; -- -- Name: ft_del_clin_diag(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_clin_diag() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_clin_diag ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_narrative, OLD.laterality, OLD.is_chronic, OLD.is_active, OLD.is_definite, OLD.clinically_relevant ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_clin_diag() OWNER TO "gm-dbo"; -- -- Name: ft_del_clin_hx_family(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_clin_hx_family() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_clin_hx_family ( 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, fk_hx_family_item ) 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.fk_hx_family_item ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_clin_hx_family() OWNER TO "gm-dbo"; -- -- Name: ft_del_clin_item_type(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_clin_item_type() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_clin_item_type ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, type, 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.type, OLD.code ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_clin_item_type() OWNER TO "gm-dbo"; -- -- Name: ft_del_clin_medication(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_clin_medication() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_clin_medication() OWNER TO "gm-dbo"; -- -- Name: ft_del_clin_narrative(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_clin_narrative() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_clin_narrative ( 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 ) 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 ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_clin_narrative() OWNER TO "gm-dbo"; -- -- Name: ft_del_coded_phrase(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_coded_phrase() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_coded_phrase() OWNER TO "gm-dbo"; -- -- Name: ft_del_consumed_substance(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_consumed_substance() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_consumed_substance() OWNER TO "gm-dbo"; -- -- Name: ft_del_data_source(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_data_source() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_data_source ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name_long, OLD.name_short, OLD.version, OLD.description, OLD.source, OLD.lang ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_data_source() OWNER TO "gm-dbo"; -- -- Name: ft_del_doc_desc(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_doc_desc() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_doc_desc ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_doc, text ) 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_doc, OLD.text ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_doc_desc() OWNER TO "gm-dbo"; -- -- Name: ft_del_doc_med(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_doc_med() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_doc_med ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_encounter, fk_episode, fk_type, comment, clin_when, ext_ref ) 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_encounter, OLD.fk_episode, OLD.fk_type, OLD.comment, OLD.clin_when, OLD.ext_ref ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_doc_med() OWNER TO "gm-dbo"; -- -- Name: ft_del_episode(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_episode() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_episode ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_health_issue, description, is_open, fk_encounter, diagnostic_certainty_classification ) 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.description, OLD.is_open, OLD.fk_encounter, OLD.diagnostic_certainty_classification ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_episode() OWNER TO "gm-dbo"; -- -- Name: ft_del_form_data(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_form_data() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_form_data ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_instance, fk_form_field, value ) 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_instance, OLD.fk_form_field, OLD.value ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_form_data() OWNER TO "gm-dbo"; -- -- Name: ft_del_form_defs(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_form_defs() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_form_defs() OWNER TO "gm-dbo"; -- -- Name: ft_del_form_instances(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_form_instances() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_form_instances ( 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, fk_form_def, form_name ) 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.fk_form_def, OLD.form_name ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_form_instances() OWNER TO "gm-dbo"; -- -- Name: ft_del_gender_label(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_gender_label() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_gender_label ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, tag, label, sort_weight, 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.tag, OLD.label, OLD.sort_weight, OLD.comment ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_gender_label() OWNER TO "gm-dbo"; -- -- Name: ft_del_health_issue(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_health_issue() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_health_issue ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, description, laterality, age_noted, is_active, clinically_relevant, is_confidential, is_cause_of_death, fk_encounter, grouping, diagnostic_certainty_classification ) 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.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 ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_health_issue() OWNER TO "gm-dbo"; -- -- Name: ft_del_hospital_stay(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_hospital_stay() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_hospital_stay ( 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, discharge ) 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.discharge ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_hospital_stay() OWNER TO "gm-dbo"; -- -- Name: ft_del_hx_family_item(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_hx_family_item() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_hx_family_item() OWNER TO "gm-dbo"; -- -- Name: ft_del_identity(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_identity() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_identity ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, deleted, pupic, gender, karyotype, dob, fk_marital_status, cob, deceased, title, tob ) 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.deleted, OLD.pupic, OLD.gender, OLD.karyotype, OLD.dob, OLD.fk_marital_status, OLD.cob, OLD.deceased, OLD.title, OLD.tob ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_identity() OWNER TO "gm-dbo"; -- -- Name: ft_del_inbox_item_category(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_inbox_item_category() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_inbox_item_category ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, description, 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.description, OLD.is_user ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_inbox_item_category() OWNER TO "gm-dbo"; -- -- Name: ft_del_inbox_item_type(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_inbox_item_type() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_inbox_item_type ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_inbox_item_category, description, 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_inbox_item_category, OLD.description, OLD.is_user ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_inbox_item_type() OWNER TO "gm-dbo"; -- -- Name: ft_del_incoming_data_unmatchable(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_incoming_data_unmatchable() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_incoming_data_unmatchable ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_incoming_data_unmatchable() OWNER TO "gm-dbo"; -- -- Name: ft_del_incoming_data_unmatched(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_incoming_data_unmatched() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_incoming_data_unmatched ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_incoming_data_unmatched() OWNER TO "gm-dbo"; -- -- Name: ft_del_lab_request(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lab_request() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lab_request ( 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, 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 ) 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.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 ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lab_request() OWNER TO "gm-dbo"; -- -- Name: ft_del_lab_test_gnr(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lab_test_gnr() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lab_test_gnr ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, id_test ) 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.id, OLD.id_test ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lab_test_gnr() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_constraint2vacc_course(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_constraint2vacc_course() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lnk_constraint2vacc_course ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_vaccination_course, fk_constraint ) 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_vaccination_course, OLD.fk_constraint ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_constraint2vacc_course() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_identity2ext_id(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_identity2ext_id() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lnk_identity2ext_id ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, id_identity, external_id, fk_origin, 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.id, OLD.id_identity, OLD.external_id, OLD.fk_origin, OLD.comment ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_identity2ext_id() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_identity2primary_doc(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_identity2primary_doc() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_identity2primary_doc() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_job2person(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_job2person() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lnk_job2person ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_identity, fk_occupation, activities ) 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_identity, OLD.fk_occupation, OLD.activities ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_job2person() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_pat2vaccination_course(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_pat2vaccination_course() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lnk_pat2vaccination_course ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_patient, fk_course ) 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_patient, OLD.fk_course ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_pat2vaccination_course() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_person2relative(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_person2relative() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lnk_person2relative ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_identity, OLD.id_relative, OLD.id_relation_type, OLD.started, OLD.ended ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_person2relative() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_tst2norm(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_tst2norm() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lnk_tst2norm ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, id_test, id_norm ) 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.id, OLD.id_test, OLD.id_norm ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_tst2norm() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_type2item(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_type2item() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lnk_type2item ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_type, fk_item ) 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.fk_item ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_type2item() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_vaccination_course2schedule(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_vaccination_course2schedule() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lnk_vaccination_course2schedule ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_course, fk_schedule ) 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_course, OLD.fk_schedule ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_vaccination_course2schedule() OWNER TO "gm-dbo"; -- -- Name: ft_del_lnk_vaccine2inds(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_lnk_vaccine2inds() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_lnk_vaccine2inds ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, fk_vaccine, fk_indication ) 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.id, OLD.fk_vaccine, OLD.fk_indication ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_lnk_vaccine2inds() OWNER TO "gm-dbo"; -- -- Name: ft_del_message_inbox(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_message_inbox() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_message_inbox ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_staff, fk_inbox_item_type, comment, ufk_context, data, importance, fk_patient ) 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_staff, OLD.fk_inbox_item_type, OLD.comment, OLD.ufk_context, OLD.data, OLD.importance, OLD.fk_patient ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_message_inbox() OWNER TO "gm-dbo"; -- -- Name: ft_del_occupation(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_occupation() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_occupation ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, name ) 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.id, OLD.name ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_occupation() OWNER TO "gm-dbo"; -- -- Name: ft_del_operation(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_operation() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_operation() OWNER TO "gm-dbo"; -- -- Name: ft_del_paperwork_templates(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_paperwork_templates() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_paperwork_templates ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_template_type, instance_type, name_short, name_long, external_version, gnumed_revision, engine, in_use, filename, 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.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 ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_paperwork_templates() OWNER TO "gm-dbo"; -- -- Name: ft_del_prax_geb_paid(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_prax_geb_paid() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_prax_geb_paid ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_fall, OLD.paid_amount, OLD.paid_when, OLD.paid_with ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_prax_geb_paid() OWNER TO "gm-dbo"; -- -- Name: ft_del_procedure(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_procedure() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_procedure ( 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, clin_where, fk_hospital_stay ) 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.clin_where, OLD.fk_hospital_stay ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_procedure() OWNER TO "gm-dbo"; -- -- Name: ft_del_ref_source(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_ref_source() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_ref_source() OWNER TO "gm-dbo"; -- -- Name: ft_del_referral(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_referral() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_referral ( 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, id, fk_referee, fk_form ) 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.id, OLD.fk_referee, OLD.fk_form ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_referral() OWNER TO "gm-dbo"; -- -- Name: ft_del_relation_types(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_relation_types() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_relation_types ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, inverse, biological, biol_verified, 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.id, OLD.inverse, OLD.biological, OLD.biol_verified, OLD.description ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_relation_types() OWNER TO "gm-dbo"; -- -- Name: ft_del_report_query(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_report_query() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_report_query ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, label, cmd ) 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.label, OLD.cmd ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_report_query() OWNER TO "gm-dbo"; -- -- Name: ft_del_staff(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_staff() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_staff ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_identity, fk_role, db_user, short_alias, comment, is_active ) 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_identity, OLD.fk_role, OLD.db_user, OLD.short_alias, OLD.comment, OLD.is_active ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_staff() OWNER TO "gm-dbo"; -- -- Name: ft_del_staff_role(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_staff_role() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_staff_role() OWNER TO "gm-dbo"; -- -- Name: ft_del_state(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_state() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_state ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, code, country, name ) 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.id, OLD.code, OLD.country, OLD.name ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_state() OWNER TO "gm-dbo"; -- -- Name: ft_del_street(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_street() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_street ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, id_urb, name, postcode, suburb, lat_lon ) 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.id, OLD.id_urb, OLD.name, OLD.postcode, OLD.suburb, OLD.lat_lon ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_street() OWNER TO "gm-dbo"; -- -- Name: ft_del_substance_in_brand(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_substance_in_brand() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_substance_in_brand() OWNER TO "gm-dbo"; -- -- Name: ft_del_substance_intake(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_substance_intake() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_substance_intake ( 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, fk_brand, fk_substance, strength, preparation, schedule, aim, duration, intake_is_approved_of, is_long_term, discontinued, discontinue_reason ) 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.fk_brand, OLD.fk_substance, OLD.strength, OLD.preparation, OLD.schedule, OLD.aim, OLD.duration, OLD.intake_is_approved_of, OLD.is_long_term, OLD.discontinued, OLD.discontinue_reason ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_substance_intake() OWNER TO "gm-dbo"; -- -- Name: ft_del_test_org(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_test_org() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_test_org ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_org, fk_adm_contact, fk_med_contact, internal_name, comment, contact ) 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_org, OLD.fk_adm_contact, OLD.fk_med_contact, OLD.internal_name, OLD.comment, OLD.contact ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_test_org() OWNER TO "gm-dbo"; -- -- Name: ft_del_test_result(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_test_result() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_test_result ( 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, 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 ) 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.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 ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_test_result() OWNER TO "gm-dbo"; -- -- Name: ft_del_test_type(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_test_type() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_test_type ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_test_org, code, coding_system, name, comment, conversion_unit, loinc, abbrev ) 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_test_org, OLD.code, OLD.coding_system, OLD.name, OLD.comment, OLD.conversion_unit, OLD.loinc, OLD.abbrev ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_test_type() OWNER TO "gm-dbo"; -- -- Name: ft_del_urb(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_urb() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_urb ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, id_state, postcode, lat_lon, name ) 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.id, OLD.id_state, OLD.postcode, OLD.lat_lon, OLD.name ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_urb() OWNER TO "gm-dbo"; -- -- Name: ft_del_vacc_indication(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_vacc_indication() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_vacc_indication ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, 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.id, OLD.description ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_vacc_indication() OWNER TO "gm-dbo"; -- -- Name: ft_del_vacc_route(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_vacc_route() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_vacc_route ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, abbreviation, 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.id, OLD.abbreviation, OLD.description ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_vacc_route() OWNER TO "gm-dbo"; -- -- Name: ft_del_vaccination(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_vaccination() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_vaccination ( 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, id, fk_provider, fk_vaccine, site, batch_no ) 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.id, OLD.fk_provider, OLD.fk_vaccine, OLD.site, OLD.batch_no ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_vaccination() OWNER TO "gm-dbo"; -- -- Name: ft_del_vaccination_course(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_vaccination_course() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_vaccination_course ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_recommended_by, OLD.fk_indication, OLD.is_active, OLD.comment ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_vaccination_course() OWNER TO "gm-dbo"; -- -- Name: ft_del_vaccination_course_constraint(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_vaccination_course_constraint() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_vaccination_course_constraint ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, 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.description ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_vaccination_course_constraint() OWNER TO "gm-dbo"; -- -- Name: ft_del_vaccination_definition(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_vaccination_definition() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_vaccination_definition ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_vaccination_definition() OWNER TO "gm-dbo"; -- -- Name: ft_del_vaccination_schedule(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_vaccination_schedule() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_vaccination_schedule ( 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_vaccination_schedule() OWNER TO "gm-dbo"; -- -- Name: ft_del_vaccine(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_vaccine() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_vaccine ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, id_route, trade_name, short_name, is_live, min_age, max_age, 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.id_route, OLD.trade_name, OLD.short_name, OLD.is_live, OLD.min_age, OLD.max_age, OLD.comment ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_vaccine() OWNER TO "gm-dbo"; -- -- Name: ft_del_vaccine_batches(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_vaccine_batches() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_vaccine_batches ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, pk, fk_vaccine, batch_no ) 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_vaccine, OLD.batch_no ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_vaccine_batches() OWNER TO "gm-dbo"; -- -- Name: ft_del_waiting_list(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_waiting_list() RETURNS trigger AS $$ BEGIN INSERT INTO audit.log_waiting_list ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient, OLD.registered, OLD.urgency, OLD.list_position, OLD.comment, OLD.area ); return OLD; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_waiting_list() OWNER TO "gm-dbo"; -- -- Name: ft_del_xlnk_identity(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_del_xlnk_identity() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_del_xlnk_identity() OWNER TO "gm-dbo"; -- -- Name: ft_ins_access_log(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_access_log() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_access_log() OWNER TO "gm-dbo"; -- -- Name: ft_ins_active_substance(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_active_substance() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_active_substance() OWNER TO "gm-dbo"; -- -- Name: ft_ins_address(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_address() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_address() OWNER TO "gm-dbo"; -- -- Name: ft_ins_allergy(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_allergy() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_allergy() OWNER TO "gm-dbo"; -- -- Name: ft_ins_allergy_state(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_allergy_state() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_allergy_state() OWNER TO "gm-dbo"; -- -- Name: ft_ins_atc_group(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_atc_group() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_atc_group() OWNER TO "gm-dbo"; -- -- Name: ft_ins_atc_substance(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_atc_substance() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_atc_substance() OWNER TO "gm-dbo"; -- -- Name: ft_ins_beh_fall_typ(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_beh_fall_typ() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_beh_fall_typ() OWNER TO "gm-dbo"; -- -- Name: ft_ins_behandlungsfall(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_behandlungsfall() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_behandlungsfall() OWNER TO "gm-dbo"; -- -- Name: ft_ins_branded_drug(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_branded_drug() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_branded_drug() OWNER TO "gm-dbo"; -- -- Name: ft_ins_clin_aux_note(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_clin_aux_note() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_clin_aux_note() OWNER TO "gm-dbo"; -- -- Name: ft_ins_clin_diag(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_clin_diag() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_clin_diag() OWNER TO "gm-dbo"; -- -- Name: ft_ins_clin_hx_family(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_clin_hx_family() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_clin_hx_family() OWNER TO "gm-dbo"; -- -- Name: ft_ins_clin_item_type(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_clin_item_type() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_clin_item_type() OWNER TO "gm-dbo"; -- -- Name: ft_ins_clin_medication(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_clin_medication() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_clin_medication() OWNER TO "gm-dbo"; -- -- Name: ft_ins_clin_narrative(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_clin_narrative() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_clin_narrative() OWNER TO "gm-dbo"; -- -- Name: ft_ins_coded_phrase(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_coded_phrase() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_coded_phrase() OWNER TO "gm-dbo"; -- -- Name: ft_ins_consumed_substance(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_consumed_substance() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_consumed_substance() OWNER TO "gm-dbo"; -- -- Name: ft_ins_data_source(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_data_source() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_data_source() OWNER TO "gm-dbo"; -- -- Name: ft_ins_doc_desc(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_doc_desc() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_doc_desc() OWNER TO "gm-dbo"; -- -- Name: ft_ins_doc_med(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_doc_med() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_doc_med() OWNER TO "gm-dbo"; -- -- Name: ft_ins_episode(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_episode() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_episode() OWNER TO "gm-dbo"; -- -- Name: ft_ins_form_data(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_form_data() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_form_data() OWNER TO "gm-dbo"; -- -- Name: ft_ins_form_defs(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_form_defs() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_form_defs() OWNER TO "gm-dbo"; -- -- Name: ft_ins_form_instances(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_form_instances() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_form_instances() OWNER TO "gm-dbo"; -- -- Name: ft_ins_gender_label(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_gender_label() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_gender_label() OWNER TO "gm-dbo"; -- -- Name: ft_ins_health_issue(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_health_issue() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_health_issue() OWNER TO "gm-dbo"; -- -- Name: ft_ins_hospital_stay(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_hospital_stay() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_hospital_stay() OWNER TO "gm-dbo"; -- -- Name: ft_ins_hx_family_item(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_hx_family_item() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_hx_family_item() OWNER TO "gm-dbo"; -- -- Name: ft_ins_identity(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_identity() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_identity() OWNER TO "gm-dbo"; -- -- Name: ft_ins_inbox_item_category(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_inbox_item_category() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_inbox_item_category() OWNER TO "gm-dbo"; -- -- Name: ft_ins_inbox_item_type(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_inbox_item_type() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_inbox_item_type() OWNER TO "gm-dbo"; -- -- Name: ft_ins_incoming_data_unmatchable(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_incoming_data_unmatchable() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_incoming_data_unmatchable() OWNER TO "gm-dbo"; -- -- Name: ft_ins_incoming_data_unmatched(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_incoming_data_unmatched() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_incoming_data_unmatched() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lab_request(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lab_request() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lab_request() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lab_test_gnr(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lab_test_gnr() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lab_test_gnr() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_constraint2vacc_course(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_constraint2vacc_course() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_constraint2vacc_course() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_identity2ext_id(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_identity2ext_id() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_identity2ext_id() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_identity2primary_doc(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_identity2primary_doc() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_identity2primary_doc() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_job2person(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_job2person() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_job2person() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_pat2vaccination_course(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_pat2vaccination_course() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_pat2vaccination_course() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_person2relative(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_person2relative() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_person2relative() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_tst2norm(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_tst2norm() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_tst2norm() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_type2item(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_type2item() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_type2item() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_vaccination_course2schedule(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_vaccination_course2schedule() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_vaccination_course2schedule() OWNER TO "gm-dbo"; -- -- Name: ft_ins_lnk_vaccine2inds(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_lnk_vaccine2inds() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_lnk_vaccine2inds() OWNER TO "gm-dbo"; -- -- Name: ft_ins_message_inbox(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_message_inbox() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_message_inbox() OWNER TO "gm-dbo"; -- -- Name: ft_ins_occupation(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_occupation() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_occupation() OWNER TO "gm-dbo"; -- -- Name: ft_ins_operation(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_operation() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_operation() OWNER TO "gm-dbo"; -- -- Name: ft_ins_paperwork_templates(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_paperwork_templates() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_paperwork_templates() OWNER TO "gm-dbo"; -- -- Name: ft_ins_prax_geb_paid(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_prax_geb_paid() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_prax_geb_paid() OWNER TO "gm-dbo"; -- -- Name: ft_ins_procedure(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_procedure() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_procedure() OWNER TO "gm-dbo"; -- -- Name: ft_ins_ref_source(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_ref_source() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_ref_source() OWNER TO "gm-dbo"; -- -- Name: ft_ins_referral(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_referral() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_referral() OWNER TO "gm-dbo"; -- -- Name: ft_ins_relation_types(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_relation_types() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_relation_types() OWNER TO "gm-dbo"; -- -- Name: ft_ins_report_query(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_report_query() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_report_query() OWNER TO "gm-dbo"; -- -- Name: ft_ins_staff(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_staff() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_staff() OWNER TO "gm-dbo"; -- -- Name: ft_ins_staff_role(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_staff_role() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_staff_role() OWNER TO "gm-dbo"; -- -- Name: ft_ins_state(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_state() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_state() OWNER TO "gm-dbo"; -- -- Name: ft_ins_street(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_street() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_street() OWNER TO "gm-dbo"; -- -- Name: ft_ins_substance_in_brand(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_substance_in_brand() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_substance_in_brand() OWNER TO "gm-dbo"; -- -- Name: ft_ins_substance_intake(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_substance_intake() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_substance_intake() OWNER TO "gm-dbo"; -- -- Name: ft_ins_test_org(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_test_org() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_test_org() OWNER TO "gm-dbo"; -- -- Name: ft_ins_test_result(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_test_result() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_test_result() OWNER TO "gm-dbo"; -- -- Name: ft_ins_test_type(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_test_type() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_test_type() OWNER TO "gm-dbo"; -- -- Name: ft_ins_urb(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_urb() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_urb() OWNER TO "gm-dbo"; -- -- Name: ft_ins_vacc_indication(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_vacc_indication() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_vacc_indication() OWNER TO "gm-dbo"; -- -- Name: ft_ins_vacc_route(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_vacc_route() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_vacc_route() OWNER TO "gm-dbo"; -- -- Name: ft_ins_vaccination(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_vaccination() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_vaccination() OWNER TO "gm-dbo"; -- -- Name: ft_ins_vaccination_course(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_vaccination_course() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_vaccination_course() OWNER TO "gm-dbo"; -- -- Name: ft_ins_vaccination_course_constraint(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_vaccination_course_constraint() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_vaccination_course_constraint() OWNER TO "gm-dbo"; -- -- Name: ft_ins_vaccination_definition(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_vaccination_definition() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_vaccination_definition() OWNER TO "gm-dbo"; -- -- Name: ft_ins_vaccination_schedule(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_vaccination_schedule() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_vaccination_schedule() OWNER TO "gm-dbo"; -- -- Name: ft_ins_vaccine(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_vaccine() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_vaccine() OWNER TO "gm-dbo"; -- -- Name: ft_ins_vaccine_batches(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_vaccine_batches() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_vaccine_batches() OWNER TO "gm-dbo"; -- -- Name: ft_ins_waiting_list(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_waiting_list() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_waiting_list() OWNER TO "gm-dbo"; -- -- Name: ft_ins_xlnk_identity(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_ins_xlnk_identity() RETURNS trigger AS $$ BEGIN NEW.row_version := 0; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_ins_xlnk_identity() OWNER TO "gm-dbo"; -- -- Name: ft_upd_access_log(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_access_log() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, user_action ) 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.user_action ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_access_log() OWNER TO "gm-dbo"; -- -- Name: ft_upd_active_substance(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_active_substance() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_active_substance() OWNER TO "gm-dbo"; -- -- Name: ft_upd_address(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_address() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, 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.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_street, OLD.aux_street, OLD.number, OLD.subunit, OLD.addendum, OLD.lat_lon ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_address() OWNER TO "gm-dbo"; -- -- Name: ft_upd_allergy(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_allergy() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_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.substance, OLD.substance_code, OLD.generics, OLD.allergene, OLD.atc_code, OLD.fk_type, OLD.generic_specific, OLD.definite ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_allergy() OWNER TO "gm-dbo"; -- -- Name: ft_upd_allergy_state(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_allergy_state() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, has_allergy, comment, last_confirmed, fk_encounter ) 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.has_allergy, OLD.comment, OLD.last_confirmed, OLD.fk_encounter ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_allergy_state() OWNER TO "gm-dbo"; -- -- Name: ft_upd_atc_group(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_atc_group() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_atc_group() OWNER TO "gm-dbo"; -- -- Name: ft_upd_atc_substance(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_atc_substance() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_atc_substance() OWNER TO "gm-dbo"; -- -- Name: ft_upd_beh_fall_typ(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_beh_fall_typ() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, code, kurzform, name ) 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.kurzform, OLD.name ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_beh_fall_typ() OWNER TO "gm-dbo"; -- -- Name: ft_upd_behandlungsfall(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_behandlungsfall() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_behandlungsfall() OWNER TO "gm-dbo"; -- -- Name: ft_upd_branded_drug(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_branded_drug() RETURNS trigger AS $$ BEGIN NEW.row_version := OLD.row_version + 1; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; INSERT INTO audit.log_branded_drug ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_branded_drug() OWNER TO "gm-dbo"; -- -- Name: ft_upd_clin_aux_note(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_clin_aux_note() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_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 ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_clin_aux_note() OWNER TO "gm-dbo"; -- -- Name: ft_upd_clin_diag(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_clin_diag() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_narrative, OLD.laterality, OLD.is_chronic, OLD.is_active, OLD.is_definite, OLD.clinically_relevant ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_clin_diag() OWNER TO "gm-dbo"; -- -- Name: ft_upd_clin_hx_family(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_clin_hx_family() RETURNS trigger AS $$ BEGIN NEW.row_version := OLD.row_version + 1; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; INSERT INTO audit.log_clin_hx_family ( 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, fk_hx_family_item ) 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.fk_hx_family_item ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_clin_hx_family() OWNER TO "gm-dbo"; -- -- Name: ft_upd_clin_item_type(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_clin_item_type() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, type, 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.type, OLD.code ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_clin_item_type() OWNER TO "gm-dbo"; -- -- Name: ft_upd_clin_medication(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_clin_medication() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_clin_medication() OWNER TO "gm-dbo"; -- -- Name: ft_upd_clin_narrative(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_clin_narrative() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_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 ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_clin_narrative() OWNER TO "gm-dbo"; -- -- Name: ft_upd_coded_phrase(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_coded_phrase() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_coded_phrase() OWNER TO "gm-dbo"; -- -- Name: ft_upd_consumed_substance(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_consumed_substance() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_consumed_substance() OWNER TO "gm-dbo"; -- -- Name: ft_upd_data_source(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_data_source() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.name_long, OLD.name_short, OLD.version, OLD.description, OLD.source, OLD.lang ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_data_source() OWNER TO "gm-dbo"; -- -- Name: ft_upd_doc_desc(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_doc_desc() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_doc, text ) 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_doc, OLD.text ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_doc_desc() OWNER TO "gm-dbo"; -- -- Name: ft_upd_doc_med(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_doc_med() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_encounter, fk_episode, fk_type, comment, clin_when, ext_ref ) 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_encounter, OLD.fk_episode, OLD.fk_type, OLD.comment, OLD.clin_when, OLD.ext_ref ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_doc_med() OWNER TO "gm-dbo"; -- -- Name: ft_upd_episode(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_episode() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_health_issue, description, is_open, fk_encounter, diagnostic_certainty_classification ) 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.description, OLD.is_open, OLD.fk_encounter, OLD.diagnostic_certainty_classification ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_episode() OWNER TO "gm-dbo"; -- -- Name: ft_upd_form_data(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_form_data() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_instance, fk_form_field, value ) 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_instance, OLD.fk_form_field, OLD.value ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_form_data() OWNER TO "gm-dbo"; -- -- Name: ft_upd_form_defs(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_form_defs() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_form_defs() OWNER TO "gm-dbo"; -- -- Name: ft_upd_form_instances(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_form_instances() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_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.fk_form_def, OLD.form_name ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_form_instances() OWNER TO "gm-dbo"; -- -- Name: ft_upd_gender_label(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_gender_label() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, tag, label, sort_weight, 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.tag, OLD.label, OLD.sort_weight, OLD.comment ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_gender_label() OWNER TO "gm-dbo"; -- -- Name: ft_upd_health_issue(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_health_issue() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, description, laterality, age_noted, is_active, clinically_relevant, is_confidential, is_cause_of_death, fk_encounter, grouping, diagnostic_certainty_classification ) 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.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 ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_health_issue() OWNER TO "gm-dbo"; -- -- Name: ft_upd_hospital_stay(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_hospital_stay() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, discharge ) 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.discharge ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_hospital_stay() OWNER TO "gm-dbo"; -- -- Name: ft_upd_hx_family_item(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_hx_family_item() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_hx_family_item() OWNER TO "gm-dbo"; -- -- Name: ft_upd_identity(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_identity() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, deleted, pupic, gender, karyotype, dob, fk_marital_status, cob, deceased, title, tob ) 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.deleted, OLD.pupic, OLD.gender, OLD.karyotype, OLD.dob, OLD.fk_marital_status, OLD.cob, OLD.deceased, OLD.title, OLD.tob ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_identity() OWNER TO "gm-dbo"; -- -- Name: ft_upd_inbox_item_category(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_inbox_item_category() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, description, 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.description, OLD.is_user ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_inbox_item_category() OWNER TO "gm-dbo"; -- -- Name: ft_upd_inbox_item_type(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_inbox_item_type() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_inbox_item_category, description, 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_inbox_item_category, OLD.description, OLD.is_user ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_inbox_item_type() OWNER TO "gm-dbo"; -- -- Name: ft_upd_incoming_data_unmatchable(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_incoming_data_unmatchable() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_incoming_data_unmatchable() OWNER TO "gm-dbo"; -- -- Name: ft_upd_incoming_data_unmatched(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_incoming_data_unmatched() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_incoming_data_unmatched() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lab_request(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lab_request() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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 ) 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.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 ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lab_request() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lab_test_gnr(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lab_test_gnr() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, id_test ) 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.id, OLD.id_test ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lab_test_gnr() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_constraint2vacc_course(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_constraint2vacc_course() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_vaccination_course, fk_constraint ) 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_vaccination_course, OLD.fk_constraint ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_constraint2vacc_course() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_identity2ext_id(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_identity2ext_id() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, id_identity, external_id, fk_origin, 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.id, OLD.id_identity, OLD.external_id, OLD.fk_origin, OLD.comment ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_identity2ext_id() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_identity2primary_doc(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_identity2primary_doc() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_identity2primary_doc() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_job2person(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_job2person() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_identity, fk_occupation, activities ) 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_identity, OLD.fk_occupation, OLD.activities ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_job2person() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_pat2vaccination_course(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_pat2vaccination_course() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_patient, fk_course ) 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_patient, OLD.fk_course ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_pat2vaccination_course() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_person2relative(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_person2relative() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, 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.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.id, OLD.id_identity, OLD.id_relative, OLD.id_relation_type, OLD.started, OLD.ended ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_person2relative() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_tst2norm(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_tst2norm() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, id_test, id_norm ) 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.id, OLD.id_test, OLD.id_norm ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_tst2norm() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_type2item(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_type2item() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_type, fk_item ) 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.fk_item ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_type2item() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_vaccination_course2schedule(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_vaccination_course2schedule() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_course, fk_schedule ) 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_course, OLD.fk_schedule ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_vaccination_course2schedule() OWNER TO "gm-dbo"; -- -- Name: ft_upd_lnk_vaccine2inds(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_lnk_vaccine2inds() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, fk_vaccine, fk_indication ) 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.id, OLD.fk_vaccine, OLD.fk_indication ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_lnk_vaccine2inds() OWNER TO "gm-dbo"; -- -- Name: ft_upd_message_inbox(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_message_inbox() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_staff, fk_inbox_item_type, comment, ufk_context, data, importance, fk_patient ) 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_staff, OLD.fk_inbox_item_type, OLD.comment, OLD.ufk_context, OLD.data, OLD.importance, OLD.fk_patient ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_message_inbox() OWNER TO "gm-dbo"; -- -- Name: ft_upd_occupation(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_occupation() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, name ) 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.id, OLD.name ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_occupation() OWNER TO "gm-dbo"; -- -- Name: ft_upd_operation(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_operation() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_operation() OWNER TO "gm-dbo"; -- -- Name: ft_upd_paperwork_templates(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_paperwork_templates() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_template_type, instance_type, name_short, name_long, external_version, gnumed_revision, engine, in_use, filename, 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.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 ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_paperwork_templates() OWNER TO "gm-dbo"; -- -- Name: ft_upd_prax_geb_paid(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_prax_geb_paid() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_fall, OLD.paid_amount, OLD.paid_when, OLD.paid_with ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_prax_geb_paid() OWNER TO "gm-dbo"; -- -- Name: ft_upd_procedure(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_procedure() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, clin_where, fk_hospital_stay ) 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.clin_where, OLD.fk_hospital_stay ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_procedure() OWNER TO "gm-dbo"; -- -- Name: ft_upd_ref_source(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_ref_source() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_ref_source() OWNER TO "gm-dbo"; -- -- Name: ft_upd_referral(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_referral() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_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.id, OLD.fk_referee, OLD.fk_form ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_referral() OWNER TO "gm-dbo"; -- -- Name: ft_upd_relation_types(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_relation_types() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, inverse, biological, biol_verified, 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.id, OLD.inverse, OLD.biological, OLD.biol_verified, OLD.description ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_relation_types() OWNER TO "gm-dbo"; -- -- Name: ft_upd_report_query(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_report_query() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, label, cmd ) 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.label, OLD.cmd ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_report_query() OWNER TO "gm-dbo"; -- -- Name: ft_upd_staff(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_staff() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_identity, fk_role, db_user, short_alias, comment, is_active ) 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_identity, OLD.fk_role, OLD.db_user, OLD.short_alias, OLD.comment, OLD.is_active ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_staff() OWNER TO "gm-dbo"; -- -- Name: ft_upd_staff_role(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_staff_role() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_staff_role() OWNER TO "gm-dbo"; -- -- Name: ft_upd_state(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_state() RETURNS trigger AS $$ BEGIN NEW.row_version := OLD.row_version + 1; NEW.modified_when := CURRENT_TIMESTAMP; NEW.modified_by := SESSION_USER; INSERT INTO audit.log_state ( orig_version, orig_when, orig_by, orig_tableoid, audit_action, pk_audit, row_version, modified_when, modified_by, id, code, country, name ) 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.id, OLD.code, OLD.country, OLD.name ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_state() OWNER TO "gm-dbo"; -- -- Name: ft_upd_street(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_street() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, id_urb, name, postcode, suburb, lat_lon ) 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.id, OLD.id_urb, OLD.name, OLD.postcode, OLD.suburb, OLD.lat_lon ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_street() OWNER TO "gm-dbo"; -- -- Name: ft_upd_substance_in_brand(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_substance_in_brand() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_substance_in_brand() OWNER TO "gm-dbo"; -- -- Name: ft_upd_substance_intake(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_substance_intake() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, pk, fk_brand, fk_substance, strength, preparation, schedule, aim, duration, intake_is_approved_of, is_long_term, discontinued, discontinue_reason ) 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.fk_brand, OLD.fk_substance, OLD.strength, OLD.preparation, OLD.schedule, OLD.aim, OLD.duration, OLD.intake_is_approved_of, OLD.is_long_term, OLD.discontinued, OLD.discontinue_reason ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_substance_intake() OWNER TO "gm-dbo"; -- -- Name: ft_upd_test_org(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_test_org() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_org, fk_adm_contact, fk_med_contact, internal_name, comment, contact ) 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_org, OLD.fk_adm_contact, OLD.fk_med_contact, OLD.internal_name, OLD.comment, OLD.contact ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_test_org() OWNER TO "gm-dbo"; -- -- Name: ft_upd_test_result(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_test_result() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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 ) 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.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 ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_test_result() OWNER TO "gm-dbo"; -- -- Name: ft_upd_test_type(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_test_type() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_test_org, code, coding_system, name, comment, conversion_unit, loinc, abbrev ) 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_test_org, OLD.code, OLD.coding_system, OLD.name, OLD.comment, OLD.conversion_unit, OLD.loinc, OLD.abbrev ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_test_type() OWNER TO "gm-dbo"; -- -- Name: ft_upd_urb(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_urb() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, id_state, postcode, lat_lon, name ) 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.id, OLD.id_state, OLD.postcode, OLD.lat_lon, OLD.name ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_urb() OWNER TO "gm-dbo"; -- -- Name: ft_upd_vacc_indication(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_vacc_indication() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, 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.id, OLD.description ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_vacc_indication() OWNER TO "gm-dbo"; -- -- Name: ft_upd_vacc_route(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_vacc_route() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, id, abbreviation, 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.id, OLD.abbreviation, OLD.description ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_vacc_route() OWNER TO "gm-dbo"; -- -- Name: ft_upd_vaccination(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_vaccination() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk_item, clin_when, fk_encounter, fk_episode, narrative, soap_cat, id, fk_provider, fk_vaccine, site, batch_no ) 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.id, OLD.fk_provider, OLD.fk_vaccine, OLD.site, OLD.batch_no ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_vaccination() OWNER TO "gm-dbo"; -- -- Name: ft_upd_vaccination_course(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_vaccination_course() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_recommended_by, OLD.fk_indication, OLD.is_active, OLD.comment ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_vaccination_course() OWNER TO "gm-dbo"; -- -- Name: ft_upd_vaccination_course_constraint(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_vaccination_course_constraint() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, 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.description ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_vaccination_course_constraint() OWNER TO "gm-dbo"; -- -- Name: ft_upd_vaccination_definition(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_vaccination_definition() RETURNS trigger AS $$ BEGIN 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, pk_audit, row_version, modified_when, modified_by, 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.pk_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_vaccination_definition() OWNER TO "gm-dbo"; -- -- Name: ft_upd_vaccination_schedule(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_vaccination_schedule() RETURNS trigger AS $$ BEGIN 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_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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_vaccination_schedule() OWNER TO "gm-dbo"; -- -- Name: ft_upd_vaccine(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_vaccine() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, id_route, trade_name, short_name, is_live, min_age, max_age, 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.id_route, OLD.trade_name, OLD.short_name, OLD.is_live, OLD.min_age, OLD.max_age, OLD.comment ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_vaccine() OWNER TO "gm-dbo"; -- -- Name: ft_upd_vaccine_batches(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_vaccine_batches() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, pk, fk_vaccine, batch_no ) 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_vaccine, OLD.batch_no ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_vaccine_batches() OWNER TO "gm-dbo"; -- -- Name: ft_upd_waiting_list(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_waiting_list() RETURNS trigger AS $$ BEGIN 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_audit, row_version, modified_when, modified_by, 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_audit, OLD.row_version, OLD.modified_when, OLD.modified_by, OLD.pk, OLD.fk_patient, OLD.registered, OLD.urgency, OLD.list_position, OLD.comment, OLD.area ); return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_waiting_list() OWNER TO "gm-dbo"; -- -- Name: ft_upd_xlnk_identity(); Type: FUNCTION; Schema: audit; Owner: gm-dbo -- CREATE FUNCTION ft_upd_xlnk_identity() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION audit.ft_upd_xlnk_identity() OWNER TO "gm-dbo"; SET search_path = bill, pg_catalog; -- -- Name: trf_announce_bill_item_mod(); Type: FUNCTION; Schema: bill; Owner: gm-dbo -- CREATE FUNCTION trf_announce_bill_item_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'bill.trf_announce_bill_item_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "bill_item_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION bill.trf_announce_bill_item_mod() OWNER TO "gm-dbo"; SET search_path = blobs, pg_catalog; -- -- Name: delete_document(integer, integer); Type: FUNCTION; Schema: blobs; Owner: gm-dbo -- CREATE FUNCTION delete_document(integer, integer) RETURNS boolean AS $_$ 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 ); delete from blobs.doc_obj where fk_doc = _pk_doc; delete from blobs.doc_med where pk = _pk_doc; return True; END;$_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION blobs.delete_document(integer, integer) OWNER TO "gm-dbo"; -- -- Name: trf_announce_doc_mod(); Type: FUNCTION; Schema: blobs; Owner: gm-dbo -- CREATE FUNCTION trf_announce_doc_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'blobs.trf_announce_doc_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "doc_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION blobs.trf_announce_doc_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_doc_page_mod_no_pk(); Type: FUNCTION; Schema: blobs; Owner: gm-dbo -- CREATE FUNCTION trf_announce_doc_page_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "doc_page_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION blobs.trf_announce_doc_page_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_announce_doc_type_mod_no_pk(); Type: FUNCTION; Schema: blobs; Owner: gm-dbo -- CREATE FUNCTION trf_announce_doc_type_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "doc_type_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION blobs.trf_announce_doc_type_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_do_not_duplicate_primary_episode_in_link_table(); Type: FUNCTION; Schema: blobs; Owner: gm-dbo -- CREATE FUNCTION trf_do_not_duplicate_primary_episode_in_link_table() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql; ALTER FUNCTION blobs.trf_do_not_duplicate_primary_episode_in_link_table() OWNER TO "gm-dbo"; -- -- Name: FUNCTION trf_do_not_duplicate_primary_episode_in_link_table(); Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON FUNCTION trf_do_not_duplicate_primary_episode_in_link_table() IS '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.'; -- -- Name: trf_mark_unreviewed_on_doc_obj_update(); Type: FUNCTION; Schema: blobs; Owner: gm-dbo -- CREATE FUNCTION trf_mark_unreviewed_on_doc_obj_update() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql; ALTER FUNCTION blobs.trf_mark_unreviewed_on_doc_obj_update() OWNER TO "gm-dbo"; -- -- Name: trf_remove_primary_episode_from_link_table(); Type: FUNCTION; Schema: blobs; Owner: gm-dbo -- CREATE FUNCTION trf_remove_primary_episode_from_link_table() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql; ALTER FUNCTION blobs.trf_remove_primary_episode_from_link_table() OWNER TO "gm-dbo"; -- -- Name: FUNCTION trf_remove_primary_episode_from_link_table(); Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON FUNCTION trf_remove_primary_episode_from_link_table() IS '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.'; -- -- Name: trf_verify_page_number(); Type: FUNCTION; Schema: blobs; Owner: gm-dbo -- CREATE FUNCTION trf_verify_page_number() RETURNS trigger AS $$ 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;$$ LANGUAGE plpgsql; ALTER FUNCTION blobs.trf_verify_page_number() OWNER TO "gm-dbo"; SET search_path = cfg, pg_catalog; -- -- Name: create_cfg_item(text, text, text, text, text); Type: FUNCTION; Schema: cfg; Owner: gm-dbo -- CREATE FUNCTION create_cfg_item(text, text, text, text, text) RETURNS integer AS $_$ 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;$_$ LANGUAGE plpgsql; ALTER FUNCTION cfg.create_cfg_item(text, text, text, text, text) OWNER TO "gm-dbo"; -- -- Name: set_option(text, anyelement, text, text, text); Type: FUNCTION; Schema: cfg; Owner: gm-dbo -- CREATE FUNCTION set_option(text, anyelement, text, text, text) RETURNS boolean AS $_$ 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;$_$ LANGUAGE plpgsql; ALTER FUNCTION cfg.set_option(text, anyelement, text, text, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION set_option(text, anyelement, text, text, text); Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON FUNCTION set_option(text, anyelement, text, text, text) IS 'set option, owner = NULL means CURRENT_USER'; SET search_path = clin, pg_catalog; -- -- Name: add_coded_phrase(text, text, text); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION add_coded_phrase(text, text, text) RETURNS boolean AS $_$ declare _term alias for $1; _code alias for $2; _system alias for $3; _tmp text; begin select into _tmp 1 from clin.coded_phrase where term = _term and code = _code and xfk_coding_system = _system; if found then return True; end if; insert into clin.coded_phrase (term, code, xfk_coding_system) values (_term, _code, _system); return True; end;$_$ LANGUAGE plpgsql; ALTER FUNCTION clin.add_coded_phrase(text, text, text) OWNER TO "gm-dbo"; -- -- Name: f_announce_clin_item_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION f_announce_clin_item_mod() RETURNS trigger AS $$ declare episode_id integer; patient_id integer; begin -- get episode ID if TG_OP = 'DELETE' then episode_id := OLD.fk_episode; else episode_id := NEW.fk_episode; end if; -- track back to patient ID select into patient_id pk_patient from clin.v_pat_episodes vpep where vpep.pk_episode = episode_id limit 1; -- now, execute() the NOTIFY execute 'notify "item_change_db:' || patient_id || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.f_announce_clin_item_mod() OWNER TO "gm-dbo"; -- -- Name: f_del_booster_must_have_base_immunity(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION f_del_booster_must_have_base_immunity() RETURNS trigger AS $$ DECLARE msg text; BEGIN -- do not worry about booster deletes if OLD.is_booster then return null; end if; -- any non-booster rows left ? perform 1 from clin.vaccination_definition where fk_course = OLD.fk_course and seq_no is not null; if FOUND then return null; end if; -- *any* rows left ? perform 1 from clin.vaccination_definition where fk_course = OLD.fk_course; if not FOUND then -- no problem return null; end if; -- any remaining rows can only be booster rows - which is a problem msg := 'Cannot delete last non-booster vacc def [' || OLD.pk || '] from course [' || OLD.fk_course || ']. There would be only booster definitions left.'; raise exception '%', msg; return null; END;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.f_del_booster_must_have_base_immunity() OWNER TO "gm-dbo"; -- -- Name: f_fk_reviewer_default(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION f_fk_reviewer_default() RETURNS integer AS $$ declare _pk_staff integer; begin select pk into _pk_staff from dem.staff where db_user = current_user; return _pk_staff; end;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.f_fk_reviewer_default() OWNER TO "gm-dbo"; -- -- Name: f_ins_booster_must_have_base_immunity(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION f_ins_booster_must_have_base_immunity() RETURNS trigger AS $$ BEGIN -- do not worry about non-booster inserts if NEW.is_booster is false then return NEW; end if; -- only insert booster def if non-booster def exists perform 1 from clin.vaccination_definition where fk_course = NEW.fk_course and seq_no is not null; if FOUND then return NEW; end if; raise exception 'Cannot define booster shot for course [%]. There is no base immunization definition.', NEW.fk_course; return null; END; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.f_ins_booster_must_have_base_immunity() OWNER TO "gm-dbo"; -- -- Name: f_protect_clin_root_item(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION f_protect_clin_root_item() RETURNS boolean AS $$ begin raise exception 'INSERT/DELETE on not allowed.'; return False; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.f_protect_clin_root_item() OWNER TO "gm-dbo"; -- -- Name: FUNCTION f_protect_clin_root_item(); Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON FUNCTION f_protect_clin_root_item() IS 'protect from direct inserts/deletes which the inheritance system cannot handle properly'; -- -- Name: f_upd_booster_must_have_base_immunity(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION f_upd_booster_must_have_base_immunity() RETURNS trigger AS $$ DECLARE msg text; BEGIN -- do not worry about non-booster updates if NEW.is_booster is false then return null; end if; -- after update to booster still non-booster def available ? perform 1 from clin.vaccination_definition where fk_course = NEW.fk_course and seq_no is not null; if FOUND then return null; end if; msg := 'Cannot set vacc def [' || NEW.pk || '] to booster for course [' || NEW.fk_course || ']. There would be no base immunization definition left.'; raise exception '%', msg; return null; END;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.f_upd_booster_must_have_base_immunity() OWNER TO "gm-dbo"; -- -- Name: move_waiting_list_entry(integer, integer); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION move_waiting_list_entry(integer, integer) RETURNS boolean AS $_$ DECLARE _wl_pos_src alias for $1; _wl_pos_dest alias for $2; _tmp_pos integer; _curr_max_pos integer; BEGIN if _wl_pos_src = _wl_pos_dest then return true; end if; if _wl_pos_dest < 1 then raise notice 'clin.move_waiting_list_entry(): Will not move entry [%] before start of list [%].', _wl_pos_src, _wl_pos_dest; return False; end if; select max(list_position) into _curr_max_pos from clin.waiting_list; -- do not move last entry further down if _wl_pos_src = _curr_max_pos then if _wl_pos_dest > _wl_pos_src then raise notice 'clin.move_waiting_list_entry(): Will not move last entry [%] beyond end of list to [%].', _wl_pos_src, _wl_pos_dest; return False; end if; end if; -- does the source row exist ? perform 1 from clin.waiting_list where list_position = _wl_pos_src; if not found then raise notice 'clin.move_waiting_list_entry(): Cannot move entry [%] to [%]. Entry does not exist.', _wl_pos_src, wl_pos_dest ; return false; end if; -- load destination row perform 1 from clin.waiting_list where list_position = _wl_pos_dest; -- does not exist if not found then -- do not move entry beyond end of list more than necessary if _wl_pos_dest > (_curr_max_pos + 1) then _tmp_pos := _curr_max_pos + 1; else _tmp_pos := _wl_pos_dest; end if; -- so update row to move and be done with it update clin.waiting_list set list_position = _tmp_pos where list_position = _wl_pos_src; return true; end if; -- move existing row out of the way select (max(list_position) + _wl_pos_dest + _wl_pos_src) into _tmp_pos from clin.waiting_list; update clin.waiting_list set list_position = _tmp_pos where list_position = _wl_pos_dest; -- move row to move update clin.waiting_list set list_position = _wl_pos_dest where list_position = _wl_pos_src; -- move back existing row update clin.waiting_list set list_position = _wl_pos_src where list_position = _tmp_pos; return true; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION clin.move_waiting_list_entry(integer, integer) OWNER TO "gm-dbo"; -- -- Name: FUNCTION move_waiting_list_entry(integer, integer); Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON FUNCTION move_waiting_list_entry(integer, integer) IS 'Move row with logical position $1 into logical position $2. If another row exists with position $2 it will be moved to position $1 in the process. Fails if there is no row with position $1.'; -- -- Name: trf_announce_active_substance_mod_no_pk(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_active_substance_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "active_substance_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_active_substance_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_announce_allg_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_allg_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_allg_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "allg_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_allg_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_allg_state_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_allg_state_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_allg_state_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "allg_state_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_allg_state_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_consumed_substance_mod_no_pk(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_consumed_substance_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "consumed_substance_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_consumed_substance_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_announce_encounter_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_encounter_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_patient if TG_OP = 'DELETE' then _pk_identity := OLD.fk_patient; else _pk_identity := NEW.fk_patient; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_encounter_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "encounter_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_encounter_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_episode_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_episode_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_episode_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "episode_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_episode_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_health_issue_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_health_issue_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_health_issue_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "health_issue_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_health_issue_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_hospital_stay_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_hospital_stay_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_hospital_stay_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "hospital_stay_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_hospital_stay_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_narrative_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_narrative_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_narrative_mod(): cannot determine identity PK on clin.clin_root_item child table'; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "narrative_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_narrative_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_procedure_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_procedure_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_procedure_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "procedure_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_procedure_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_reviewed_test_results_mod_no_pk(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_reviewed_test_results_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "reviewed_test_results_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_reviewed_test_results_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_announce_substance_brand_mod_no_pk(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_substance_brand_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "substance_brand_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_substance_brand_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_announce_substance_intake_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_substance_intake_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_substance_intake_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "substance_intake_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_substance_intake_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_test_result_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_test_result_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_test_result_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "test_result_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_test_result_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_vacc_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_vacc_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_encounter if TG_OP = 'DELETE' then select into _pk_identity fk_patient from clin.encounter where pk = OLD.fk_encounter limit 1; else select into _pk_identity fk_patient from clin.encounter where pk = NEW.fk_encounter limit 1; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_vacc_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "vacc_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_vacc_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_waiting_list_generic_mod_no_pk(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_waiting_list_generic_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "waiting_list_generic_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_waiting_list_generic_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_announce_waiting_list_mod(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_announce_waiting_list_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_patient if TG_OP = 'DELETE' then _pk_identity := OLD.fk_patient; else _pk_identity := NEW.fk_patient; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'clin.trf_announce_waiting_list_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "waiting_list_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_announce_waiting_list_mod() OWNER TO "gm-dbo"; -- -- Name: trf_ensure_one_allergy_state_per_patient(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_ensure_one_allergy_state_per_patient() RETURNS trigger AS $$ declare _new_pk_patient integer; _old_pk_patient integer; begin -- find patient from encounter select into _new_pk_patient fk_patient from clin.encounter where pk = NEW.fk_encounter; if not FOUND then raise exception 'Encounter % does not exist !?', NEW.fk_encounter; return NEW; end if; -- new row if TG_OP = 'INSERT' then -- patient already there ? perform 1 from clin.allergy_state where fk_encounter in (select pk from clin.encounter where fk_patient = _new_pk_patient); if FOUND then raise exception 'Cannot insert second allergy state for patient % via encounter %.', _new_pk_patient, NEW.fk_encounter; return NEW; end if; return NEW; end if; if TG_OP = 'UPDATE' then if NEW.fk_encounter = OLD.fk_encounter then return NEW; end if; select into _old_pk_patient fk_patient from clin.encounter where pk = OLD.fk_encounter; if _new_pk_patient = _old_pk_patient then return NEW; end if; raise exception 'Invalid fk_encounter update (% -> %): it would change the associated patient (% -> %).', OLD.fk_encounter, NEW.fk_encounter, _old_pk_patient, _new_pk_patient; return NEW; end if; return NEW; end;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_ensure_one_allergy_state_per_patient() OWNER TO "gm-dbo"; -- -- Name: trf_invalidate_review_on_result_change(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_invalidate_review_on_result_change() RETURNS trigger AS $$ DECLARE is_modified bool; BEGIN is_modified := False; -- change of test type if NEW.fk_type != OLD.fk_type then is_modified := True; end if; -- change of numeric value if NEW.val_num != OLD.val_num then is_modified := True; end if; -- change of alpha value if NEW.val_alpha != OLD.val_alpha then is_modified := True; end if; -- change of unit if NEW.val_unit != OLD.val_unit then is_modified := True; end if; if is_modified is True then delete from clin.reviewed_test_results where fk_reviewed_row = OLD.pk; end if; return NEW; END;$$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION clin.trf_invalidate_review_on_result_change() OWNER TO "gm-dbo"; -- -- Name: trf_notify_reviewer_of_review_change(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_notify_reviewer_of_review_change() RETURNS trigger AS $$ declare _pk_patient integer; _pk_type integer; begin -- disallow change of referenced row -- for cleanliness this really *should* be in another trigger if NEW.fk_reviewed_row <> OLD.fk_reviewed_row then raise exception 'Attaching an existing review to another test result is not allowed (fk_reviewed_row change).'; return NEW; end if; -- change of last reviewer ? if NEW.fk_reviewer = OLD.fk_reviewer then return NEW; end if; -- review change ? if (NEW.is_technically_abnormal <> OLD.is_technically_abnormal) or (NEW.clinically_relevant <> OLD.clinically_relevant) then -- find patient for test result select pk_patient into _pk_patient from clin.v_test_results where pk_test_result = OLD.fk_reviewed_row; -- find inbox item type select pk_type into _pk_type from dem.v_inbox_item_type where type = 'results review change'; -- create it if necessary if not found then insert into dem.inbox_item_type ( fk_inbox_item_category, description ) values ( (select pk from dem.item_inbox_category where description = 'clinical'), 'results review change' ); select pk_type into _pk_type from dem.v_inbox_item_type where type = 'results review change'; end if; -- already notified ? perform 1 from dem.message_inbox where fk_staff = OLD.fk_reviewer and fk_inbox_item_type = _pk_type and ufk_context = _pk_patient; -- nope, so notify now if not found then insert into dem.message_inbox ( fk_staff, fk_inbox_item_type, comment, ufk_context ) values ( OLD.fk_reviewer, _pk_type, (select _('results review changed for patient') || ' [' || vpb.lastnames || ', ' || vbp.firstnames || ']' from dem.v_basic_person vbp where vpb.pk_identity = _pk_patient ), _pk_patient ); end if; end if; return NEW; end;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_notify_reviewer_of_review_change() OWNER TO "gm-dbo"; -- -- Name: trf_sanity_check_enc_epi_insert(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_sanity_check_enc_epi_insert() RETURNS trigger AS $$ declare _identity_from_encounter integer; _identity_from_episode integer; begin -- sometimes .fk_episode can actually be NULL (eg. clin.substance_intake) -- in which case we do not need to run the sanity check if NEW.fk_episode is NULL then return NEW; end if; select fk_patient into _identity_from_encounter from clin.encounter where pk = NEW.fk_encounter; select fk_patient into _identity_from_episode from clin.encounter where pk = ( select fk_encounter from clin.episode where pk = NEW.fk_episode ); if _identity_from_encounter <> _identity_from_episode then raise exception 'INSERT into %.%: Sanity check failed. Encounter % patient = %. Episode % patient = %.', TG_TABLE_SCHEMA, TG_TABLE_NAME, NEW.fk_encounter, _identity_from_encounter, NEW.fk_episode, _identity_from_episode ; return NULL; end if; return NEW; end; $$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_sanity_check_enc_epi_insert() OWNER TO "gm-dbo"; -- -- Name: trf_sanity_check_enc_vs_issue_on_epi(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_sanity_check_enc_vs_issue_on_epi() RETURNS trigger AS $$ declare _identity_from_encounter integer; _identity_from_issue integer; begin -- if issue is NULL, do not worry about mismatch if NEW.fk_health_issue is NULL then return NEW; end if; -- .fk_episode must belong to the same patient as .fk_encounter select fk_patient into _identity_from_encounter from clin.encounter where pk = NEW.fk_encounter; select fk_patient into _identity_from_issue from clin.encounter where pk = ( select fk_encounter from clin.health_issue where pk = NEW.fk_health_issue ); if _identity_from_encounter <> _identity_from_issue then raise exception 'INSERT/UPDATE into %.%: Sanity check failed. Encounter % patient = %. Issue % patient = %.', TG_TABLE_SCHEMA, TG_TABLE_NAME, NEW.fk_encounter, _identity_from_encounter, NEW.fk_health_issue, _identity_from_episode ; return NULL; end if; return NEW; end;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_sanity_check_enc_vs_issue_on_epi() OWNER TO "gm-dbo"; -- -- Name: trf_sanity_check_procedure_episode(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_sanity_check_procedure_episode() RETURNS trigger AS $$ DECLARE _hospital_stay_episode_pk integer; BEGIN if NEW.fk_hospital_stay is null then return NEW; end if; select into _hospital_stay_episode_pk fk_episode from clin.hospital_stay where pk = NEW.fk_hospital_stay; if NEW.fk_episode = _hospital_stay_episode_pk then return NEW; end if; raise exception '[clin.procedure]: INSERT/UPDATE failed: fk_episode (%) does not match fk_episode (%) behind fk_hospital_stay (%)', NEW.fk_episode, _hospital_stay_episode_pk, NEW.fk_hospital_stay; return NEW; END;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_sanity_check_procedure_episode() OWNER TO "gm-dbo"; -- -- Name: trf_sanity_check_substance_episode(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_sanity_check_substance_episode() RETURNS trigger AS $$ declare _identity_from_encounter integer; _identity_from_episode integer; begin -- episode can only be NULL if intake is not approved of, -- IOW, if clinician approves of intake she better know why if NEW.intake_is_approved_of is True then if NEW.fk_episode is NULL then raise exception 'clin.trf_sanity_check_substance_episode(): substance intake is approved of but .fk_episode is NULL'; return NULL; end if; end if; -- .fk_episode can be NULL (except in the above case) if NEW.fk_episode is NULL then return NEW; end if; -- .fk_episode must belong to the same patient as .fk_encounter select fk_patient into _identity_from_encounter from clin.encounter where pk = NEW.fk_encounter; select fk_patient into _identity_from_episode from clin.encounter where pk = ( select fk_encounter from clin.episode where pk = NEW.fk_episode ); if _identity_from_encounter <> _identity_from_episode then raise exception 'INSERT/UPDATE into %.%: Sanity check failed. Encounter % patient = %. Episode % patient = %.', TG_TABLE_SCHEMA, TG_TABLE_NAME, NEW.fk_encounter, _identity_from_encounter, NEW.fk_episode, _identity_from_episode ; return NULL; end if; return NEW; end;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_sanity_check_substance_episode() OWNER TO "gm-dbo"; -- -- Name: trf_sync_allergic_state_on_allergies_modified(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_sync_allergic_state_on_allergies_modified() RETURNS trigger AS $$ DECLARE _fk_patient integer; _fk_encounter integer; _state integer; _no_of_allergies integer; BEGIN if TG_OP = 'INSERT' then select into _fk_patient fk_patient from clin.encounter where pk = NEW.fk_encounter; _fk_encounter := NEW.fk_encounter; _state := 1; end if; if TG_OP = 'DELETE' then -- only run this trigger if deleting last allergy select into _fk_patient fk_patient from clin.encounter where pk = OLD.fk_encounter; select into _no_of_allergies count(1) from clin.allergy where fk_encounter in ( select pk from clin.encounter where fk_patient = _fk_patient ); if _no_of_allergies > 1 then return OLD; -- still allergies left end if; _fk_encounter := OLD.fk_encounter; _state := 0; end if; update clin.allergy_state set has_allergy = _state, last_confirmed = coalesce(last_confirmed, now()) where fk_encounter in ( select pk from clin.encounter where fk_patient = _fk_patient ); if not FOUND then insert into clin.allergy_state (fk_encounter, has_allergy, last_confirmed) values (_fk_encounter, _state, now()); end if; return NEW; END;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_sync_allergic_state_on_allergies_modified() OWNER TO "gm-dbo"; -- -- Name: FUNCTION trf_sync_allergic_state_on_allergies_modified(); Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON FUNCTION trf_sync_allergic_state_on_allergies_modified() IS 'trigger function to sync the allergy state on insert/delete'; -- -- Name: trf_undiscontinue_unsets_reason(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_undiscontinue_unsets_reason() RETURNS trigger AS $$ declare _identity_from_encounter integer; _identity_from_issue integer; begin if NEW.discontinued is NULL then NEW.discontinue_reason := NULL; end if; return NEW; end;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_undiscontinue_unsets_reason() OWNER TO "gm-dbo"; -- -- Name: trf_unique_indication_in_schedule(); Type: FUNCTION; Schema: clin; Owner: gm-dbo -- CREATE FUNCTION trf_unique_indication_in_schedule() RETURNS trigger AS $$ DECLARE _msg text; BEGIN -- is the indication already linked ? perform 1 from clin.v_vaccination_courses_in_schedule where pk_vaccination_schedule = NEW.fk_schedule and pk_indication = (select fk_indication from clin.vaccination_course where pk=NEW.fk_course); if FOUND then _msg := 'Cannot link course [' || NEW.fk_course || '] into schedule [' || NEW.fk_schedule || ']. The indication is already linked.'; raise exception '%', _msg; return null; end if; return null; END;$$ LANGUAGE plpgsql; ALTER FUNCTION clin.trf_unique_indication_in_schedule() OWNER TO "gm-dbo"; SET search_path = dem, pg_catalog; -- -- Name: add_external_id_type(text, text, text); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION add_external_id_type(text, text, text) RETURNS integer AS $_$ declare _name alias for $1; _issuer alias for $2; _context alias for $3; _pk int; begin select pk into _pk from dem.enum_ext_id_types where name = _name and issuer = _issuer; if FOUND then return _pk; end if; insert into dem.enum_ext_id_types(name, issuer, context) values (_name, _issuer, _context); select currval(pg_get_serial_sequence('dem.enum_ext_id_types', 'pk')) into _pk; return _pk; end;$_$ LANGUAGE plpgsql; ALTER FUNCTION dem.add_external_id_type(text, text, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION add_external_id_type(text, text, text); Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON FUNCTION add_external_id_type(text, text, text) IS 'Add an external ID type if it does not exist yet. This implementation is prone to concurrency issues.'; -- -- Name: add_name(integer, text, text, boolean); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION add_name(integer, text, text, boolean) RETURNS integer AS $_$ DECLARE _id_identity alias for $1; _first alias for $2; _last alias for $3; _active alias for $4; _id integer; BEGIN -- deactivate all the existing names if this name is to become active if _active then update dem.names set active = false where id_identity = _id_identity; end if; -- name already there for this identity ? select into _id id from dem.names where id_identity = _id_identity and firstnames = _first and lastnames = _last; if FOUND then update dem.names set active = _active where id = _id; return _id; end if; -- no, insert new name insert into dem.names (id_identity, firstnames, lastnames, active) values (_id_identity, _first, _last, _active); if FOUND then return currval('dem.names_id_seq'); end if; return NULL; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION dem.add_name(integer, text, text, boolean) OWNER TO "gm-dbo"; -- -- Name: create_address(text, text, text, text, text, text, text); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION create_address(text, text, text, text, text, text, text) RETURNS integer AS $_$ DECLARE _number ALIAS FOR $1; _street ALIAS FOR $2; _postcode ALIAS FOR $3; _urb ALIAS FOR $4; _state_code ALIAS FOR $5; _country_code ALIAS FOR $6; _subunit alias for $7; _street_id integer; _address_id integer; msg text; BEGIN -- create/get street SELECT INTO _street_id dem.create_street(_street, _postcode, _urb, _state_code, _country_code); -- create/get and return address SELECT INTO _address_id a.id from dem.address a WHERE a.number ILIKE _number and a.id_street = _street_id; IF FOUND THEN RETURN _address_id; END IF; INSERT INTO dem.address (number, id_street, subunit) VALUES ( _number, _street_id, _subunit); RETURN currval('dem.address_id_seq'); END;$_$ LANGUAGE plpgsql; ALTER FUNCTION dem.create_address(text, text, text, text, text, text, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION create_address(text, text, text, text, text, text, text); Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON FUNCTION create_address(text, text, text, text, text, text, text) IS 'This function takes as parameters the number of the address, the name of the street, the postal code of the address, the name of the urb, the code of the state, the code of the country and the subunit. If the country or the state do not exist in the database, the function fails. At first, the urb, the street and the address are tried to be retrieved according to the supplied information. If the fields do not match exactly an existing row, a new urb or street is created or a new address is created and returned.'; -- -- Name: create_comm_type(text); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION create_comm_type(text) RETURNS integer AS $_$ DECLARE _description alias for $1; _pk_type integer; BEGIN select pk into _pk_type from dem.enum_comm_types where _(description) = _description; if FOUND then return _pk_type; end if; select pk into _pk_type from dem.enum_comm_types where description = _description; if FOUND then return _pk_type; end if; insert into dem.enum_comm_types(description) values (_description); select currval(pg_get_serial_sequence('dem.enum_comm_types', 'pk')) into _pk_type; return _pk_type; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION dem.create_comm_type(text) OWNER TO "gm-dbo"; -- -- Name: create_occupation(text); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION create_occupation(text) RETURNS integer AS $_$ DECLARE _job alias for $1; _id integer; BEGIN select into _id id from dem.occupation where name = _job; if FOUND then return _id; end if; insert into dem.occupation (name) values (_job); return currval('dem.occupation_id_seq'); END;$_$ LANGUAGE plpgsql; ALTER FUNCTION dem.create_occupation(text) OWNER TO "gm-dbo"; -- -- Name: create_street(text, text, text, text, text); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION create_street(text, text, text, text, text) RETURNS integer AS $_$ DECLARE _street ALIAS FOR $1; _postcode ALIAS FOR $2; _urb ALIAS FOR $3; _state_code ALIAS FOR $4; _country_code ALIAS FOR $5; _urb_id integer; _street_id integer; msg text; BEGIN -- create/get urb SELECT INTO _urb_id dem.create_urb(_urb, _postcode, _state_code, _country_code); -- create/get and return street SELECT INTO _street_id s.id from dem.street s WHERE s.name ILIKE _street AND s.id_urb = _urb_id AND postcode ILIKE _postcode; IF FOUND THEN RETURN _street_id; END IF; INSERT INTO dem.street (name, postcode, id_urb) VALUES (_street, _postcode, _urb_id); RETURN currval('dem.street_id_seq'); END;$_$ LANGUAGE plpgsql; ALTER FUNCTION dem.create_street(text, text, text, text, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION create_street(text, text, text, text, text); Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON FUNCTION create_street(text, text, text, text, text) IS 'This function takes a parameters the name of the street, the postal code, the name of the urb, the postcode of the urb, the code of the state and the code of the country. If the country or the state does not exists in the tables, the function fails. At first, both the urb and street are tried to be retrieved according to the supplied information. If the fields do not match exactly an existing row, a new urb is created or a new street is created and returned.'; -- -- Name: create_urb(text, text, text, text); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION create_urb(text, text, text, text) RETURNS integer AS $_$ DECLARE _urb ALIAS FOR $1; _urb_postcode ALIAS FOR $2; _state_code ALIAS FOR $3; _country_code ALIAS FOR $4; _state_id integer; _urb_id integer; msg text; BEGIN -- get state SELECT INTO _state_id s.id from dem.state s WHERE s.code = _state_code and s.country = _country_code; IF NOT FOUND THEN msg := 'Cannot set address [' || coalesce(_country_code, 'country_code:NULL') || ', ' || coalesce(_state_code, 'state_code:NULL') || ', ' || coalesce(_urb, 'urb:NULL') || ', ' || coalesce(_urb_postcode, 'urb_postcode:NULL') || '].'; RAISE EXCEPTION '=> %', msg; END IF; -- get/create and return urb SELECT INTO _urb_id u.id from dem.urb u WHERE u.name ILIKE _urb AND u.id_state = _state_id; IF FOUND THEN RETURN _urb_id; END IF; INSERT INTO dem.urb (name, postcode, id_state) VALUES (_urb, _urb_postcode, _state_id); RETURN currval('dem.urb_id_seq'); END;$_$ LANGUAGE plpgsql; ALTER FUNCTION dem.create_urb(text, text, text, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION create_urb(text, text, text, text); Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON FUNCTION create_urb(text, text, text, text) IS 'This function takes a parameters the name of the urb, the postcode of the urb, the name of the state and the name of the country. If the country or the state does not exists in the tables, the function fails. At first, the urb is tried to be retrieved according to the supplied information. If the fields do not match exactly an existing row, a new urb is created and returned.'; -- -- Name: date_trunc_utc(text, timestamp with time zone); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION date_trunc_utc(text, timestamp with time zone) RETURNS timestamp without time zone AS $_$select date_trunc($1, $2 at time zone 'UTC');$_$ LANGUAGE sql IMMUTABLE; ALTER FUNCTION dem.date_trunc_utc(text, timestamp with time zone) OWNER TO "gm-dbo"; -- -- Name: FUNCTION date_trunc_utc(text, timestamp with time zone); Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON FUNCTION date_trunc_utc(text, timestamp with time zone) IS 'date_trunc() is not immutable because it depends on the timezone setting, hence need to use this in index creation, but also need to use it in queries which want to use that index, so make it generally available as a function'; -- -- Name: dob_is_in_range(timestamp with time zone, interval, interval); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION dob_is_in_range(timestamp with time zone, interval, interval) RETURNS boolean AS $_$ select ($1 - (extract(year from $1) * '1 year'::interval)) - (now() - (extract(year from now()) * '1 year'::interval)) between (-1 * $2) and $3$_$ LANGUAGE sql; ALTER FUNCTION dem.dob_is_in_range(timestamp with time zone, interval, interval) OWNER TO "gm-dbo"; -- -- Name: f_always_active_name(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION f_always_active_name() RETURNS trigger AS $$ BEGIN if NEW.active = false then raise exception 'Cannot delete/disable active name. Another name must be activated first.'; return OLD; end if; return NEW; END; $$ LANGUAGE plpgsql; ALTER FUNCTION dem.f_always_active_name() OWNER TO "gm-dbo"; -- -- Name: f_delete_names(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION f_delete_names() RETURNS trigger AS $$ DECLARE BEGIN DELETE from dem.names WHERE id_identity=OLD.id; RETURN OLD; END;$$ LANGUAGE plpgsql; ALTER FUNCTION dem.f_delete_names() OWNER TO "gm-dbo"; -- -- Name: f_uniq_active_name(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION f_uniq_active_name() RETURNS trigger AS $$ DECLARE -- tmp text; BEGIN -- tmp := 'identity:' || NEW.id_identity || ',id:' || NEW.id || ',name:' || NEW.firstnames || ' ' || NEW.lastnames; -- raise notice 'uniq_active_name: [%]', tmp; if NEW.active = true then update dem.names set active = false where id_identity = NEW.id_identity and active = true; end if; return NEW; END;$$ LANGUAGE plpgsql; ALTER FUNCTION dem.f_uniq_active_name() OWNER TO "gm-dbo"; -- -- Name: gm_upd_default_states(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION gm_upd_default_states() RETURNS boolean AS $$ declare _state_code text; _state_name text; _country_row record; begin _state_code := '??'; _state_name := 'state/territory/province/region not available'; -- add default state to countries needing one for _country_row in select distinct code from dem.country where code not in ( select country from dem.state where code = _state_code ) loop raise notice 'adding default state for [%]', _country_row.code; execute 'insert into dem.state (code, country, name) values (' || quote_literal(_state_code) || ', ' || quote_literal(_country_row.code) || ', ' || quote_literal(_state_name) || ');'; end loop; return true; end; $$ LANGUAGE plpgsql; ALTER FUNCTION dem.gm_upd_default_states() OWNER TO "gm-dbo"; -- -- Name: new_pupic(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION new_pupic() RETURNS character AS $$ DECLARE BEGIN -- how does this work? How do we get new 'unique' numbers? RETURN '0000000000'; END;$$ LANGUAGE plpgsql; ALTER FUNCTION dem.new_pupic() OWNER TO "gm-dbo"; -- -- Name: set_nickname(integer, text); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION set_nickname(integer, text) RETURNS integer AS $_$ DECLARE _id_identity alias for $1; _nick alias for $2; _names_row record; msg text; BEGIN -- 0.1: Just always set the nickname inside the active name -- post 0.1: openEHR-like (name: pk, fk_identity, name, fk_type, comment, is_legal, is_active ...) -- does name exist ? select into _names_row * from dem.names where id_identity = _id_identity and active = true; if not found then msg := 'Cannot set nickname [' || _nick || ']. No active row with id_identity [' || _id_identity || '] found.'; raise exception '%', msg; end if; update dem.names set preferred = _nick where id = _names_row.id; return _names_row.id; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION dem.set_nickname(integer, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION set_nickname(integer, text); Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON FUNCTION set_nickname(integer, text) IS 'Setting the nickname only makes sense for the currently active name. However, we also want to keep track of previous nicknames. Hence we would set the nickname right in the active name if it is NULL. It it contains a previous nickname (eg IS NOT NULL) we will inactivate the currently active name and copy it into a new active name but with the nickname set to the new one. Unsetting works the same (IOW *setting* to NULL).'; -- -- Name: trf_announce_comm_channel_mod(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION trf_announce_comm_channel_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_identity if TG_OP = 'DELETE' then _pk_identity := OLD.fk_identity; else _pk_identity := NEW.fk_identity; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'dem.trf_announce_comm_channel_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "comm_channel_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION dem.trf_announce_comm_channel_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_identity_mod(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION trf_announce_identity_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via pk if TG_OP = 'DELETE' then _pk_identity := OLD.pk; else _pk_identity := NEW.pk; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'dem.trf_announce_identity_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "identity_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION dem.trf_announce_identity_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_message_inbox_generic_mod_no_pk(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION trf_announce_message_inbox_generic_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "message_inbox_generic_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION dem.trf_announce_message_inbox_generic_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_announce_message_inbox_mod(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION trf_announce_message_inbox_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via fk_patient if TG_OP = 'DELETE' then _pk_identity := OLD.fk_patient; else _pk_identity := NEW.fk_patient; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'dem.trf_announce_message_inbox_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "message_inbox_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION dem.trf_announce_message_inbox_mod() OWNER TO "gm-dbo"; -- -- Name: trf_announce_name_mod(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION trf_announce_name_mod() RETURNS trigger AS $$ declare _pk_identity integer; begin _pk_identity := NULL; -- retrieve identity PK via id_identity if TG_OP = 'DELETE' then _pk_identity := OLD.id_identity; else _pk_identity := NEW.id_identity; end if; -- soft error out if not found if _pk_identity is NULL then raise notice 'dem.trf_announce_name_mod(): cannot determine identity PK on table '; return NULL; end if; -- now, execute() the NOTIFY execute 'notify "name_mod_db:' || _pk_identity || '"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION dem.trf_announce_name_mod() OWNER TO "gm-dbo"; -- -- Name: trf_normalize_time_in_dob(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION trf_normalize_time_in_dob() RETURNS trigger AS $$ BEGIN if NEW.dob is NULL then return NEW; end if; NEW.dob = date_trunc('day', NEW.dob) + '11 hours 11 minutes 11 seconds 111 milliseconds'::interval; return NEW; END;$$ LANGUAGE plpgsql; ALTER FUNCTION dem.trf_normalize_time_in_dob() OWNER TO "gm-dbo"; -- -- Name: trf_null_empty_title(); Type: FUNCTION; Schema: dem; Owner: gm-dbo -- CREATE FUNCTION trf_null_empty_title() RETURNS trigger AS $$ begin if (NEW.title is null) then return NEW; end if; if trim(NEW.title) <> '' then return NEW; end if; NEW.title := NULL; return NEW; end;$$ LANGUAGE plpgsql; ALTER FUNCTION dem.trf_null_empty_title() OWNER TO "gm-dbo"; SET search_path = gm, pg_catalog; -- -- Name: add_table_for_notifies(name, name, name); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION add_table_for_notifies(name, name, name) RETURNS boolean AS $_$ DECLARE _namespace alias for $1; _table alias for $2; _signal alias for $3; dummy RECORD; BEGIN -- does table exist ? select relname into dummy from pg_class where relname = _table and relnamespace = (select oid from pg_namespace where nspname = _namespace) ; if not found then raise exception 'add_table_for_notifies: Table [%.%] does not exist.', _namespace, _table; end if; -- make sure we can insert delete from gm.notifying_tables where table_name = _table and schema_name = _namespace and signal = _signal; insert into gm.notifying_tables ( schema_name, table_name, signal ) values ( _namespace, _table, _signal ); return true; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION gm.add_table_for_notifies(name, name, name) OWNER TO "gm-dbo"; -- -- Name: FUNCTION add_table_for_notifies(name, name, name); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION add_table_for_notifies(name, name, name) IS 'Mark given table for notification trigger generator. Parameters are: (schema, table, signal name)'; -- -- Name: add_table_for_notifies(name, name); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION add_table_for_notifies(name, name) RETURNS boolean AS $_$select gm.add_table_for_notifies($1, $2, $2);$_$ LANGUAGE sql; ALTER FUNCTION gm.add_table_for_notifies(name, name) OWNER TO "gm-dbo"; -- -- Name: FUNCTION add_table_for_notifies(name, name); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION add_table_for_notifies(name, name) IS 'Mark given table for notification trigger generator. Parameters are: (schema, table). Defaults signal to table name.'; -- -- Name: concat_table_structure(integer); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION concat_table_structure(integer) RETURNS text AS $_$ declare _db_ver alias for $1; _struct text; begin if _db_ver < 6 then select into _struct gm.concat_table_structure_v1(); return _struct; end if; if _db_ver < 8 then select into _struct gm.concat_table_structure_v2(); return _struct; end if; select into _struct gm.concat_table_structure_v3(); return _struct; end; $_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION gm.concat_table_structure(integer) OWNER TO "gm-dbo"; -- -- Name: concat_table_structure(); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION concat_table_structure() RETURNS text AS $$ declare _struct text; begin select into _struct gm.concat_table_structure_v3(); return _struct; end; $$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION gm.concat_table_structure() OWNER TO "gm-dbo"; -- -- Name: concat_table_structure_v1(); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION concat_table_structure_v1() RETURNS text AS $$ declare _row record; _total text; begin _total := ''; -- schema.table.column.data_type for _row in select * from information_schema.columns cols where cols.table_name in ( select tabs.table_name from information_schema.tables tabs where -- those which hold clinical data tabs.table_schema in ('public', 'dem', 'clin', 'blobs') and tabs.table_type = 'BASE TABLE' ) order by md5(cols.table_schema || cols.table_name || cols.column_name || cols.data_type) loop _total := _total || _row.table_schema || '.' || _row.table_name || '.' || _row.column_name || '::' || _row.udt_name || ' '; end loop; return _total; end; $$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION gm.concat_table_structure_v1() OWNER TO "gm-dbo"; -- -- Name: FUNCTION concat_table_structure_v1(); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION concat_table_structure_v1() IS 'copy of gm_concat_table_structure() until gnumed_v5, works on public, dem, clin, blobs'; -- -- Name: concat_table_structure_v2(); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION concat_table_structure_v2() RETURNS text AS $$ declare _row record; _total text; begin _total := ''; -- schema.table.column.data_type for _row in select * from information_schema.columns cols where cols.table_name in ( select tabs.table_name from information_schema.tables tabs where -- those which hold clinical data tabs.table_schema in ('dem', 'clin', 'blobs', 'cfg', 'ref', 'i18n') and tabs.table_type = 'BASE TABLE' ) order by md5(cols.table_schema || cols.table_name || cols.column_name || cols.data_type) loop _total := _total || _row.table_schema || '.' || _row.table_name || '.' || _row.column_name || '::' || _row.udt_name || ' '; end loop; return _total; end; $$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION gm.concat_table_structure_v2() OWNER TO "gm-dbo"; -- -- Name: FUNCTION concat_table_structure_v2(); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION concat_table_structure_v2() IS 'new concat_table_structure() starting with gnumed_v6, works on dem, clin, blobs, cfg, ref, i18n'; -- -- Name: concat_table_structure_v3(); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION concat_table_structure_v3() RETURNS text AS $$ declare _row record; _total text; begin _total := ''; -- schema.table.column.data_type for _row in select * from information_schema.columns cols where cols.table_name in ( select tabs.table_name from information_schema.tables tabs where -- those which hold clinical data tabs.table_schema in ('dem', 'clin', 'blobs', 'cfg', 'ref', 'i18n') and tabs.table_type = 'BASE TABLE' ) order by decode(md5(cols.table_schema || cols.table_name || cols.column_name || cols.data_type), 'hex') loop _total := _total || _row.table_schema || '.' || _row.table_name || '.' || _row.column_name || '::' || _row.udt_name || ' '; end loop; return _total; end; $$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION gm.concat_table_structure_v3() OWNER TO "gm-dbo"; -- -- Name: FUNCTION concat_table_structure_v3(); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION concat_table_structure_v3() IS 'new concat_table_structure() starting with gnumed_v8, works on dem, clin, blobs, cfg, ref, i18n, sorts properly by bytea'; -- -- Name: create_user(name, text); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION create_user(name, text) RETURNS boolean AS $_$ DECLARE _username alias for $1; _password alias for $2; _database text; _query text; BEGIN perform 1 from pg_user where usename = _username; if not FOUND then _query := 'create user ' || quote_ident(_username) || ' with password ' || quote_literal(_password) || ';'; execute _query; perform 1 from pg_user where usename = _username; if not FOUND then raise exception 'cannot create user [%]', _username; return false; end if; end if; _query := 'alter group "gm-logins" add user ' || quote_ident(_username) || ';'; execute _query; _query := 'alter group "gm-doctors" add user ' || quote_ident(_username) || ';'; execute _query; _query := 'alter group "gm-public" add user ' || quote_ident(_username) || ';'; execute _query; -- satisfy "database = samegroup" in pg_hba.conf select into _database current_database(); _query := 'alter group ' || quote_ident(_database) || ' add user ' || quote_ident(_username) || ';'; execute _query; return true; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION gm.create_user(name, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION create_user(name, text); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION create_user(name, text) IS 'To create users one needs to have CREATEROLE rights. Only gm-dbo is GRANTed EXECUTE. This way users need to know the gm-dbo (GNUmed admin) password to execute the function.'; -- -- Name: disable_user(name); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION disable_user(name) RETURNS boolean AS $_$ DECLARE _username alias for $1; _query text; BEGIN perform 1 from pg_user where usename = _username; if not FOUND then return true; end if; _query := 'alter group "gm-logins" drop user ' || quote_ident(_username) || ';'; execute _query; return true; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION gm.disable_user(name) OWNER TO "gm-dbo"; -- -- Name: FUNCTION disable_user(name); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION disable_user(name) IS 'To disable users one needs to have CREATEROLE rights. Only gm-dbo is GRANTed EXECUTE. This way users need to know the gm-dbo (GNUmed admin) password to execute the function.'; -- -- Name: drop_user(name); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION drop_user(name) RETURNS boolean AS $_$ DECLARE _username alias for $1; _query text; BEGIN perform 1 from pg_user where usename = _username; if not FOUND then return true; end if; _query := 'drop user ' || quote_ident(_username) || ';'; execute _query; perform 1 from pg_user where usename = _username; if FOUND then return false; end if; return true; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION gm.drop_user(name) OWNER TO "gm-dbo"; -- -- Name: FUNCTION drop_user(name); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION drop_user(name) IS 'To drop users one needs to have CREATEROLE rights. Only gm-dbo is GRANTed EXECUTE. This way users need to know the gm-dbo (GNUmed admin) password to execute the function.'; -- -- Name: get_users(name); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION get_users(name) RETURNS text[] AS $_$ DECLARE _db alias for $1; _gm_users text[]; _user text; BEGIN _gm_users := ARRAY['gm-logins', 'gm-public', 'gm-doctors', _db]; -- add members of groups gm-logins, gm-public, _db FOR _user in select distinct rolname from pg_roles where oid in ( select member from pg_auth_members where roleid in ( select oid from pg_roles where rolname in ('gm-logins', 'gm-public', _db) ) ) LOOP continue when _user = 'postgres'; continue when _user = any(_gm_users); _gm_users := _gm_users || _user; END LOOP; -- add *.modified_by entries FOR _user in select distinct modified_by from audit.audit_fields LOOP continue when _user = 'postgres'; continue when _user = any(_gm_users); _gm_users := _gm_users || _user; END LOOP; -- add dem.staff.db_user entries FOR _user in select distinct db_user from dem.staff LOOP continue when _user = 'postgres'; continue when _user = any(_gm_users); _gm_users := _gm_users || _user; END LOOP; return _gm_users; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION gm.get_users(name) OWNER TO "gm-dbo"; -- -- Name: get_users(); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION get_users() RETURNS text[] AS $$select gm.get_users(current_database());$$ LANGUAGE sql; ALTER FUNCTION gm.get_users() OWNER TO "gm-dbo"; -- -- Name: is_null_or_blank_string(text); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION is_null_or_blank_string(text) RETURNS boolean AS $_$select (coalesce(trim($1), '') = '');$_$ LANGUAGE sql; ALTER FUNCTION gm.is_null_or_blank_string(text) OWNER TO "gm-dbo"; -- -- Name: is_null_or_non_empty_string(text); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION is_null_or_non_empty_string(text) RETURNS boolean AS $_$select (coalesce(trim($1), 'NULL') != '');$_$ LANGUAGE sql; ALTER FUNCTION gm.is_null_or_non_empty_string(text) OWNER TO "gm-dbo"; -- -- Name: log_access2emr(text); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION log_access2emr(text) RETURNS void AS $_$ DECLARE _action alias for $1; BEGIN if gm.is_null_or_blank_string(_action) then raise exception 'gm.log_access2emr(): action detail cannot be NULL or empty'; end if; insert into gm.access_log (user_action) values ('EMR access: ' || _action); return; END;$_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION gm.log_access2emr(text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION log_access2emr(text); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION log_access2emr(text) IS 'This logs access to a patient EMR.'; -- -- Name: log_other_access(text); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION log_other_access(text) RETURNS void AS $_$insert into gm.access_log (user_action) values ($1);$_$ LANGUAGE sql SECURITY DEFINER; ALTER FUNCTION gm.log_other_access(text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION log_other_access(text); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION log_other_access(text) IS 'This logs access to the database.'; -- -- Name: log_script_insertion(text, text); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION log_script_insertion(text, text) RETURNS text AS $_$ declare _filename alias for $1; _version alias for $2; _hash text; begin delete from gm.schema_revision where filename = _filename; insert into gm.schema_revision (filename, version) values ( _filename, _version ); perform gm.log_other_access ( 'database change script inserted: $RCSfile: v12-gm-log_script_insertion.sql,v $ ($Revision: 1.1 $)' ); select into _hash md5(gm.concat_table_structure()); return _hash; end;$_$ LANGUAGE plpgsql; ALTER FUNCTION gm.log_script_insertion(text, text) OWNER TO "gm-dbo"; -- -- Name: nullify_empty_string(text); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION nullify_empty_string(text) RETURNS text AS $_$ DECLARE _input alias for $1; BEGIN if _input is null then return null; end if; if trim(_input) = '' then return null; end if; return _input; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION gm.nullify_empty_string(text) OWNER TO "gm-dbo"; -- -- Name: transfer_users(text, text); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION transfer_users(text, text) RETURNS boolean AS $_$ DECLARE _source_group alias for $1; _target_group alias for $2; member_ids int[]; member_id int; member_name text; tmp text; BEGIN -- source group exists ? perform 1 from pg_group where groname = _source_group; if not FOUND then raise exception 'gm_transfer_users(): source group [%] does not exist', _source_group; return false; end if; -- target group exists ? perform 1 from pg_group where groname = _target_group; if not FOUND then raise exception 'gm_transfer_users(): target group [%] does not exist', _target_group; return false; end if; -- loop over group member IDs select into member_ids grolist from pg_group where groname = _source_group; FOR idx IN coalesce(array_lower(member_ids, 1), 0) .. coalesce(array_upper(member_ids, 1), -1) LOOP member_id := member_ids[idx]; select into member_name usename from pg_user where usesysid = member_id; tmp := 'gm_transfer_users(text): transferring "' || member_name || '" (' || member_id || ') from group "' || _source_group || '" to group "' || _target_group || '"'; raise notice '%', tmp; -- satisfy "database = samegroup" in pg_hba.conf tmp := 'alter group ' || quote_ident(_target_group) || ' add user ' || quote_ident(member_name) || ';'; execute tmp; end LOOP; return true; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION gm.transfer_users(text, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION transfer_users(text, text); Type: COMMENT; Schema: gm; Owner: gm-dbo -- COMMENT ON FUNCTION transfer_users(text, text) IS 'This function transfers adds users from the group role given in the argument to the group role corresponding to the current database name. This enables group membership based authentication as used in GNUmed. This operation is typically only run on database upgrade and is only available to gm-dbo.'; -- -- Name: transfer_users(text); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION transfer_users(text) RETURNS boolean AS $_$select gm.transfer_users($1, current_database());$_$ LANGUAGE sql; ALTER FUNCTION gm.transfer_users(text) OWNER TO "gm-dbo"; -- -- Name: user_exists(name); Type: FUNCTION; Schema: gm; Owner: gm-dbo -- CREATE FUNCTION user_exists(name) RETURNS boolean AS $_$ BEGIN perform 1 from pg_user where usename = $1; if not FOUND then raise notice 'Cannot set database language. User % does not exist.', $1; return false; end if; return true; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION gm.user_exists(name) OWNER TO "gm-dbo"; SET search_path = i18n, pg_catalog; -- -- Name: _(text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION _(text) RETURNS text AS $_$select i18n._($1, i18n.get_curr_lang())$_$ LANGUAGE sql; ALTER FUNCTION i18n._(text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION _(text); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION _(text) IS 'will return either the translation into i18n.curr_lang.lang for the current user or the input, created in public schema for easy access'; -- -- Name: _(text, text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION _(text, text) RETURNS text AS $_$ DECLARE _orig alias for $1; _lang alias for $2; trans_str text; BEGIN select into trans_str trans from i18n.translations where lang = _lang and orig = _orig; if not found then return _orig; end if; return trans_str; END; $_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION i18n._(text, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION _(text, text); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION _(text, text) IS 'will return either the translation into (2nd argument) for the current user or the input, created in public schema for easy access'; -- -- Name: force_curr_lang(text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION force_curr_lang(text) RETURNS unknown AS $_$ DECLARE _lang ALIAS FOR $1; _status boolean; BEGIN select into _status i18n.force_curr_lang(_lang, CURRENT_USER); return _status; END;$_$ LANGUAGE plpgsql; ALTER FUNCTION i18n.force_curr_lang(text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION force_curr_lang(text); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION force_curr_lang(text) IS 'force preferred language to some language for "current user"'; -- -- Name: force_curr_lang(text, name); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION force_curr_lang(text, name) RETURNS unknown AS $_$ DECLARE _lang ALIAS FOR $1; _db_user ALIAS FOR $2; BEGIN raise notice 'Forcing current language for [%] to [%] without checking for translations...', _db_user, _lang; delete from i18n.curr_lang where db_user = _db_user; insert into i18n.curr_lang(db_user, lang) values (_db_user, _lang); return True; END; $_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION i18n.force_curr_lang(text, name) OWNER TO "gm-dbo"; -- -- Name: FUNCTION force_curr_lang(text, name); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION force_curr_lang(text, name) IS 'force preferred language to some language for a user'; -- -- Name: get_curr_lang(); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION get_curr_lang() RETURNS text AS $$select i18n.get_curr_lang(CURRENT_USER)$$ LANGUAGE sql; ALTER FUNCTION i18n.get_curr_lang() OWNER TO "gm-dbo"; -- -- Name: get_curr_lang(text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION get_curr_lang(text) RETURNS text AS $_$select lang from i18n.curr_lang where db_user = $1$_$ LANGUAGE sql; ALTER FUNCTION i18n.get_curr_lang(text) OWNER TO "gm-dbo"; -- -- Name: i18n(text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION i18n(text) RETURNS text AS $_$ DECLARE original ALIAS FOR $1; BEGIN if not exists(select pk from i18n.keys where orig = original) then insert into i18n.keys (orig) values (original); end if; return original; END; $_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION i18n.i18n(text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION i18n(text); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION i18n(text) IS 'insert original strings into i18n.keys for later translation'; -- -- Name: set_curr_lang(text, name); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION set_curr_lang(text, name) RETURNS boolean AS $_$ DECLARE _lang ALIAS FOR $1; _db_user ALIAS FOR $2; lang_has_tx boolean; BEGIN select into lang_has_tx exists(select pk from i18n.translations where lang = _lang); if lang_has_tx is False then raise notice 'Cannot set current language to [%]. No translations available.', _lang; return False; end if; delete from i18n.curr_lang where db_user = _db_user; insert into i18n.curr_lang (db_user, lang) values (_db_user, _lang); return true; END; $_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION i18n.set_curr_lang(text, name) OWNER TO "gm-dbo"; -- -- Name: FUNCTION set_curr_lang(text, name); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION set_curr_lang(text, name) IS 'set language to first argument for the user named in the second argument if translations are available'; -- -- Name: set_curr_lang(text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION set_curr_lang(text) RETURNS boolean AS $_$ DECLARE _lang ALIAS FOR $1; _status boolean; BEGIN select into _status i18n.set_curr_lang(_lang, CURRENT_USER); return _status; END; $_$ LANGUAGE plpgsql; ALTER FUNCTION i18n.set_curr_lang(text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION set_curr_lang(text); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION set_curr_lang(text) IS 'set preferred language: - for "current user" - only if translations for this language are available'; -- -- Name: tx_or_null(text, text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION tx_or_null(text, text) RETURNS text AS $_$ DECLARE _orig alias for $1; _lang alias for $2; trans_str text; BEGIN select into trans_str trans from i18n.translations where lang = _lang and orig = _orig; if not found then return null; end if; return trans_str; END; $_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION i18n.tx_or_null(text, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION tx_or_null(text, text); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION tx_or_null(text, text) IS 'will return either the translation into language (2nd argument) or null'; -- -- Name: tx_or_null(text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION tx_or_null(text) RETURNS text AS $_$select i18n.tx_or_null($1, i18n.get_curr_lang())$_$ LANGUAGE sql; ALTER FUNCTION i18n.tx_or_null(text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION tx_or_null(text); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION tx_or_null(text) IS 'will return either the translation into i18n.curr_lang.lang for the current user or null'; -- -- Name: unset_curr_lang(name); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION unset_curr_lang(name) RETURNS void AS $_$ BEGIN delete from i18n.curr_lang where db_user = $1; return; END;$_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION i18n.unset_curr_lang(name) OWNER TO "gm-dbo"; -- -- Name: FUNCTION unset_curr_lang(name); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION unset_curr_lang(name) IS 'unset the db language for a user (thereby reverting to the default English)'; -- -- Name: unset_curr_lang(); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION unset_curr_lang() RETURNS void AS $$select i18n.unset_curr_lang(CURRENT_USER);$$ LANGUAGE sql; ALTER FUNCTION i18n.unset_curr_lang() OWNER TO "gm-dbo"; -- -- Name: FUNCTION unset_curr_lang(); Type: COMMENT; Schema: i18n; Owner: gm-dbo -- COMMENT ON FUNCTION unset_curr_lang() IS 'unset the db language for the current user'; -- -- Name: upd_tx(text, text, text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION upd_tx(text, text, text) RETURNS boolean AS $_$ declare _lang alias for $1; _orig alias for $2; _trans alias for $3; _tmp text; begin if _lang is null then raise notice 'i18n.upd_tx(text, text, text): Cannot create translation for language .'; return False; end if; if _trans = _orig then raise notice 'i18n.upd_tx(text, text, text): Original = translation. Skipping.'; return True; end if; select into _tmp '1' from i18n.keys where orig = _orig; if not found then raise notice 'i18n.upd_tx(text, text, text): [%] not found in i18n.keys. Creating entry.', _orig; insert into i18n.keys (orig) values (_orig); end if; delete from i18n.translations where lang = _lang and orig = _orig; insert into i18n.translations (lang, orig, trans) values (_lang, _orig, _trans); raise notice 'i18n.upd_tx(%: [%] ==> [%])', _lang, _orig, _trans; return True; end;$_$ LANGUAGE plpgsql SECURITY DEFINER; ALTER FUNCTION i18n.upd_tx(text, text, text) OWNER TO "gm-dbo"; -- -- Name: upd_tx(text, text); Type: FUNCTION; Schema: i18n; Owner: gm-dbo -- CREATE FUNCTION upd_tx(text, text) RETURNS boolean AS $_$select i18n.upd_tx((select i18n.get_curr_lang()), $1, $2)$_$ LANGUAGE sql; ALTER FUNCTION i18n.upd_tx(text, text) OWNER TO "gm-dbo"; SET search_path = public, pg_catalog; -- -- Name: _(text); Type: FUNCTION; Schema: public; Owner: gm-dbo -- CREATE FUNCTION _(text) RETURNS text AS $_$select i18n._($1)$_$ LANGUAGE sql; ALTER FUNCTION public._(text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION _(text); Type: COMMENT; Schema: public; Owner: gm-dbo -- COMMENT ON FUNCTION _(text) IS 'will return either the translation into i18n.curr_lang.lang for the current user or the input, created in public schema for easy access'; -- -- Name: _(text, text); Type: FUNCTION; Schema: public; Owner: gm-dbo -- CREATE FUNCTION _(text, text) RETURNS text AS $_$select i18n._($1, $2)$_$ LANGUAGE sql; ALTER FUNCTION public._(text, text) OWNER TO "gm-dbo"; -- -- Name: FUNCTION _(text, text); Type: COMMENT; Schema: public; Owner: gm-dbo -- COMMENT ON FUNCTION _(text, text) IS 'will return either the translation into (2nd argument) for the current user or the input, created in public schema for easy access'; -- -- Name: f_rfi_type2item(); Type: FUNCTION; Schema: public; Owner: gm-dbo -- CREATE FUNCTION f_rfi_type2item() RETURNS trigger AS $$ declare dummy integer; msg text; begin -- does fk_item change at all ? if TG_OP = 'UPDATE' then if NEW.fk_item = OLD.fk_item then return NEW; end if; end if; -- check referential integrity select into dummy 1 from clin.clin_root_item where pk_item=NEW.fk_item; if not found then msg := 'referential integrity violation: clin.lnk_type2item.fk_item [' || NEW.fk_item || '] not in '; raise exception '%', msg; return NULL; end if; return NEW; end; $$ LANGUAGE plpgsql; ALTER FUNCTION public.f_rfi_type2item() OWNER TO "gm-dbo"; -- -- Name: FUNCTION f_rfi_type2item(); Type: COMMENT; Schema: public; Owner: gm-dbo -- COMMENT ON FUNCTION f_rfi_type2item() IS 'function used to check referential integrity from clin.lnk_type2item to clin.clin_root_item with a custom trigger'; -- -- Name: f_set_encounter_timezone(); Type: FUNCTION; Schema: public; Owner: gm-dbo -- CREATE FUNCTION f_set_encounter_timezone() RETURNS trigger AS $$ begin if TG_OP = 'INSERT' then NEW.source_time_zone := (select (extract(timezone from (select now()))::text || 'seconds')::interval); else NEW.source_time_zone := OLD.source_time_zone; end if; return NEW; end; $$ LANGUAGE plpgsql; ALTER FUNCTION public.f_set_encounter_timezone() OWNER TO "gm-dbo"; SET search_path = ref, pg_catalog; -- -- Name: trf_announce_branded_drug_mod_no_pk(); Type: FUNCTION; Schema: ref; Owner: gm-dbo -- CREATE FUNCTION trf_announce_branded_drug_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "branded_drug_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION ref.trf_announce_branded_drug_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_announce_substance_in_brand_mod_no_pk(); Type: FUNCTION; Schema: ref; Owner: gm-dbo -- CREATE FUNCTION trf_announce_substance_in_brand_mod_no_pk() RETURNS trigger AS $$ begin execute 'notify "substance_in_brand_mod_db:"'; return NULL; end; $$ LANGUAGE plpgsql; ALTER FUNCTION ref.trf_announce_substance_in_brand_mod_no_pk() OWNER TO "gm-dbo"; -- -- Name: trf_protect_template_data(); Type: FUNCTION; Schema: ref; Owner: gm-dbo -- CREATE FUNCTION trf_protect_template_data() RETURNS trigger AS $$ BEGIN if NEW.data != OLD.data then -- look for references in clin.form_instances -- if there are any we fail this update no matter what perform 1 from clin.form_instances where fk_form_def = NEW.pk; if FOUND then raise exception 'Updating ref.paperwork_templates.data not allowed because it is referenced from existing forms.'; end if; end if; -- otherwise let it happen return NEW; END;$$ LANGUAGE plpgsql; ALTER FUNCTION ref.trf_protect_template_data() OWNER TO "gm-dbo"; -- -- Name: FUNCTION trf_protect_template_data(); Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON FUNCTION trf_protect_template_data() IS 'Do not allow updates to the template data if any forms already use this template.'; SET search_path = audit, pg_catalog; SET default_tablespace = ''; SET default_with_oids = false; -- -- Name: audit_fields; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE audit_fields ( pk_audit integer NOT NULL, row_version integer DEFAULT 0 NOT NULL, modified_when timestamp with time zone DEFAULT now() NOT NULL, modified_by name DEFAULT "current_user"() NOT NULL ); ALTER TABLE audit.audit_fields OWNER TO "gm-dbo"; -- -- Name: TABLE audit_fields; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON TABLE audit_fields IS 'this table holds all the fields needed for auditing'; -- -- Name: COLUMN audit_fields.row_version; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_fields.row_version IS 'the version of the row; mainly just a count'; -- -- Name: COLUMN audit_fields.modified_when; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_fields.modified_when IS 'when has this row been committed (created/modified)'; -- -- Name: COLUMN audit_fields.modified_by; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_fields.modified_by IS 'by whom has this row been committed (created/modified)'; -- -- Name: audit_fields_pk_audit_seq; Type: SEQUENCE; Schema: audit; Owner: gm-dbo -- CREATE SEQUENCE audit_fields_pk_audit_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE audit.audit_fields_pk_audit_seq OWNER TO "gm-dbo"; -- -- Name: audit_fields_pk_audit_seq; Type: SEQUENCE OWNED BY; Schema: audit; Owner: gm-dbo -- ALTER SEQUENCE audit_fields_pk_audit_seq OWNED BY audit_fields.pk_audit; -- -- Name: pk_audit; Type: DEFAULT; Schema: audit; Owner: gm-dbo -- ALTER TABLE audit_fields ALTER COLUMN pk_audit SET DEFAULT nextval('audit_fields_pk_audit_seq'::regclass); SET search_path = clin, pg_catalog; -- -- Name: clin_root_item; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE clin_root_item ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk_item integer NOT NULL, clin_when timestamp with time zone DEFAULT now() NOT NULL, fk_encounter integer NOT NULL, fk_episode integer NOT NULL, narrative text, soap_cat text, CONSTRAINT clin_root_item_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))) ) INHERITS (audit.audit_fields); ALTER TABLE clin.clin_root_item OWNER TO "gm-dbo"; -- -- Name: TABLE clin_root_item; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE clin_root_item IS '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'; -- -- Name: COLUMN clin_root_item.pk_item; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_root_item.pk_item IS 'the primary key, not named "id" or "pk" as usual since child tables will have "id"/"pk"-named primary keys already and we would get duplicate columns while inheriting from this table'; -- -- Name: COLUMN clin_root_item.clin_when; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_root_item.clin_when IS 'when this clinical item became known, can be different from when it was entered into the system (= audit.audit_fields.modified_when)'; -- -- Name: COLUMN clin_root_item.fk_encounter; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_root_item.fk_encounter IS 'the encounter this item belongs to'; -- -- Name: COLUMN clin_root_item.fk_episode; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_root_item.fk_episode IS 'the episode this item belongs to'; -- -- Name: COLUMN clin_root_item.narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_root_item.narrative IS 'each clinical item by default inherits a free text field for clinical narrative'; -- -- Name: COLUMN clin_root_item.soap_cat; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_root_item.soap_cat IS 'each clinical item must be either one of the S, O, A, P categories or NULL to indicate a non-clinical item'; -- -- Name: clin_root_item_pk_item_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE clin_root_item_pk_item_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.clin_root_item_pk_item_seq OWNER TO "gm-dbo"; -- -- Name: clin_root_item_pk_item_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE clin_root_item_pk_item_seq OWNED BY clin_root_item.pk_item; -- -- Name: pk_item; Type: DEFAULT; Schema: clin; Owner: gm-dbo -- ALTER TABLE clin_root_item ALTER COLUMN pk_item SET DEFAULT nextval('clin_root_item_pk_item_seq'::regclass); SET search_path = au, pg_catalog; -- -- Name: referral; Type: TABLE; Schema: au; Owner: gm-dbo; Tablespace: -- CREATE TABLE referral ( pk_item integer DEFAULT nextval('clin.clin_root_item_pk_item_seq'::regclass), id integer NOT NULL, fk_referee integer NOT NULL, fk_form integer NOT NULL, CONSTRAINT referral_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))) ) INHERITS (clin.clin_root_item); ALTER TABLE au.referral OWNER TO "gm-dbo"; -- -- Name: TABLE referral; Type: COMMENT; Schema: au; Owner: gm-dbo -- COMMENT ON TABLE referral IS 'table for referrals to defined individuals'; -- -- Name: COLUMN referral.narrative; Type: COMMENT; Schema: au; Owner: gm-dbo -- COMMENT ON COLUMN referral.narrative IS 'inherited from clin.clin_root_item; stores text of referral letter'; -- -- Name: COLUMN referral.fk_referee; Type: COMMENT; Schema: au; Owner: gm-dbo -- COMMENT ON COLUMN referral.fk_referee IS 'person to whom the referral is directed'; -- -- Name: COLUMN referral.fk_form; Type: COMMENT; Schema: au; Owner: gm-dbo -- COMMENT ON COLUMN referral.fk_form IS 'foreign key to the form instance of this referral.'; -- -- Name: referral_id_seq; Type: SEQUENCE; Schema: au; Owner: gm-dbo -- CREATE SEQUENCE referral_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE au.referral_id_seq OWNER TO "gm-dbo"; -- -- Name: referral_id_seq; Type: SEQUENCE OWNED BY; Schema: au; Owner: gm-dbo -- ALTER SEQUENCE referral_id_seq OWNED BY referral.id; SET search_path = audit, pg_catalog; -- -- Name: audit_trail; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE audit_trail ( pk_audit integer NOT NULL, orig_version integer DEFAULT 0 NOT NULL, orig_when timestamp with time zone NOT NULL, orig_by name NOT NULL, orig_tableoid oid NOT NULL, audit_action text NOT NULL, audit_when timestamp with time zone DEFAULT now() NOT NULL, audit_by name DEFAULT "current_user"() NOT NULL, CONSTRAINT audit_trail_audit_action_check CHECK (((audit_action = 'UPDATE'::text) OR (audit_action = 'DELETE'::text))) ); ALTER TABLE audit.audit_trail OWNER TO "gm-dbo"; -- -- Name: TABLE audit_trail; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON TABLE audit_trail IS '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.'; -- -- Name: COLUMN audit_trail.orig_version; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_trail.orig_version IS 'the version of this row in the original table previous to the modification'; -- -- Name: COLUMN audit_trail.orig_when; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_trail.orig_when IS 'previous modification date in the original table'; -- -- Name: COLUMN audit_trail.orig_by; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_trail.orig_by IS 'who committed the row to the original table'; -- -- Name: COLUMN audit_trail.orig_tableoid; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_trail.orig_tableoid IS 'the table oid of the original table, use this to identify the source table'; -- -- Name: COLUMN audit_trail.audit_action; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_trail.audit_action IS 'either "update" or "delete"'; -- -- Name: COLUMN audit_trail.audit_when; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_trail.audit_when IS 'when committed to this table for auditing'; -- -- Name: COLUMN audit_trail.audit_by; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN audit_trail.audit_by IS 'committed to this table for auditing by whom'; -- -- Name: audit_trail_pk_audit_seq; Type: SEQUENCE; Schema: audit; Owner: gm-dbo -- CREATE SEQUENCE audit_trail_pk_audit_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE audit.audit_trail_pk_audit_seq OWNER TO "gm-dbo"; -- -- Name: audit_trail_pk_audit_seq; Type: SEQUENCE OWNED BY; Schema: audit; Owner: gm-dbo -- ALTER SEQUENCE audit_trail_pk_audit_seq OWNED BY audit_trail.pk_audit; -- -- Name: audited_tables; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE audited_tables ( id integer NOT NULL, schema name DEFAULT 'public'::name NOT NULL, table_name name NOT NULL ); ALTER TABLE audit.audited_tables OWNER TO "gm-dbo"; -- -- Name: TABLE audited_tables; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON TABLE audited_tables IS 'All tables that need standard auditing must be recorded in this table. Audit triggers will be generated automatically for all tables recorded here.'; -- -- Name: audited_tables_id_seq; Type: SEQUENCE; Schema: audit; Owner: gm-dbo -- CREATE SEQUENCE audited_tables_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE audit.audited_tables_id_seq OWNER TO "gm-dbo"; -- -- Name: audited_tables_id_seq; Type: SEQUENCE OWNED BY; Schema: audit; Owner: gm-dbo -- ALTER SEQUENCE audited_tables_id_seq OWNED BY audited_tables.id; -- -- Name: log_access_log; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_access_log ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, user_action text ) INHERITS (audit_trail); ALTER TABLE audit.log_access_log OWNER TO "gm-dbo"; -- -- Name: log_active_substance; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_active_substance ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, description text, atc_code text ) INHERITS (audit_trail); ALTER TABLE audit.log_active_substance OWNER TO "gm-dbo"; -- -- Name: log_address; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_address ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, id_street integer, aux_street text, number text, subunit text, addendum text, lat_lon point ) INHERITS (audit_trail); ALTER TABLE audit.log_address OWNER TO "gm-dbo"; -- -- Name: log_allergy; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_allergy ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer, substance text, substance_code text, generics text, allergene text, atc_code text, fk_type integer, generic_specific boolean, definite boolean ) INHERITS (audit_trail); ALTER TABLE audit.log_allergy OWNER TO "gm-dbo"; -- -- Name: log_allergy_state; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_allergy_state ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, has_allergy integer, comment text, last_confirmed timestamp with time zone, fk_encounter integer ) INHERITS (audit_trail); ALTER TABLE audit.log_allergy_state OWNER TO "gm-dbo"; -- -- Name: log_beh_fall_typ; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_beh_fall_typ ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, code text, kurzform text, name text ) INHERITS (audit_trail); ALTER TABLE audit.log_beh_fall_typ OWNER TO "gm-dbo"; -- -- Name: log_behandlungsfall; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_behandlungsfall ( pk integer, fk_patient integer, fk_falltyp integer, started date, must_pay_prax_geb boolean ) INHERITS (audit_trail); ALTER TABLE audit.log_behandlungsfall OWNER TO "gm-dbo"; -- -- Name: log_branded_drug; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_branded_drug ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, description text, preparation text, atc_code text, is_fake boolean, fk_data_source integer, external_code text, external_code_type text ) INHERITS (audit_trail); ALTER TABLE audit.log_branded_drug OWNER TO "gm-dbo"; -- -- Name: log_clin_aux_note; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_clin_aux_note ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer ) INHERITS (audit_trail); ALTER TABLE audit.log_clin_aux_note OWNER TO "gm-dbo"; -- -- Name: log_clin_diag; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_clin_diag ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_narrative integer, laterality bpchar, is_chronic boolean, is_active boolean, is_definite boolean, clinically_relevant boolean ) INHERITS (audit_trail); ALTER TABLE audit.log_clin_diag OWNER TO "gm-dbo"; -- -- Name: log_clin_hx_family; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_clin_hx_family ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer, fk_hx_family_item integer ) INHERITS (audit_trail); ALTER TABLE audit.log_clin_hx_family OWNER TO "gm-dbo"; -- -- Name: log_clin_item_type; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_clin_item_type ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, type text, code text ) INHERITS (audit_trail); ALTER TABLE audit.log_clin_item_type OWNER TO "gm-dbo"; -- -- Name: log_clin_narrative; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_clin_narrative ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer ) INHERITS (audit_trail); ALTER TABLE audit.log_clin_narrative OWNER TO "gm-dbo"; -- -- Name: log_coded_phrase; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_coded_phrase ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, term text, code text, xfk_coding_system text ) INHERITS (audit_trail); ALTER TABLE audit.log_coded_phrase OWNER TO "gm-dbo"; -- -- Name: log_consumed_substance; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_consumed_substance ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, description text, atc_code text ) INHERITS (audit_trail); ALTER TABLE audit.log_consumed_substance OWNER TO "gm-dbo"; -- -- Name: COLUMN log_consumed_substance.orig_version; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_consumed_substance.orig_version IS 'the .row_version in the original row before the audited action took place, should be equal to .row_version'; -- -- Name: COLUMN log_consumed_substance.orig_when; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_consumed_substance.orig_when IS 'the .modified_when in the original row before the audited action took place, should be equal to .modified_when'; -- -- Name: COLUMN log_consumed_substance.orig_by; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_consumed_substance.orig_by IS 'the .modified_by in the original row before the audited action took place, should be equal to .modified_by'; -- -- Name: COLUMN log_consumed_substance.orig_tableoid; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_consumed_substance.orig_tableoid IS 'the TG_RELID when the audit trigger was run'; -- -- Name: log_data_source; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_data_source ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, name_short text, name_long text, version text, description text, source text, lang text ) INHERITS (audit_trail); ALTER TABLE audit.log_data_source OWNER TO "gm-dbo"; -- -- Name: log_doc_desc; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_doc_desc ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_doc integer, text text ) INHERITS (audit_trail); ALTER TABLE audit.log_doc_desc OWNER TO "gm-dbo"; -- -- Name: log_doc_med; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_doc_med ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_encounter integer, fk_episode integer, fk_type integer, comment text, clin_when timestamp with time zone, ext_ref text ) INHERITS (audit_trail); ALTER TABLE audit.log_doc_med OWNER TO "gm-dbo"; -- -- Name: log_episode; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_episode ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_health_issue integer, description text, is_open boolean, fk_encounter integer, diagnostic_certainty_classification text ) INHERITS (audit_trail); ALTER TABLE audit.log_episode OWNER TO "gm-dbo"; -- -- Name: log_form_data; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_form_data ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_instance integer, fk_form_field integer, value text ) INHERITS (audit_trail); ALTER TABLE audit.log_form_data OWNER TO "gm-dbo"; -- -- Name: log_form_instances; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_form_instances ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer, fk_form_def integer, form_name text ) INHERITS (audit_trail); ALTER TABLE audit.log_form_instances OWNER TO "gm-dbo"; -- -- Name: log_gender_label; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_gender_label ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, tag text, label text, sort_weight integer, comment text ) INHERITS (audit_trail); ALTER TABLE audit.log_gender_label OWNER TO "gm-dbo"; -- -- Name: log_health_issue; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_health_issue ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, description text, laterality character varying, age_noted interval, is_active boolean, clinically_relevant boolean, is_confidential boolean, is_cause_of_death boolean, fk_encounter integer, grouping text, diagnostic_certainty_classification text ) INHERITS (audit_trail); ALTER TABLE audit.log_health_issue OWNER TO "gm-dbo"; -- -- Name: log_hospital_stay; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_hospital_stay ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer, discharge timestamp with time zone ) INHERITS (audit_trail); ALTER TABLE audit.log_hospital_stay OWNER TO "gm-dbo"; -- -- Name: log_hx_family_item; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_hx_family_item ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_narrative_condition integer, fk_relative integer, name_relative text, dob_relative timestamp with time zone, condition text, age_noted text, age_of_death interval, is_cause_of_death boolean ) INHERITS (audit_trail); ALTER TABLE audit.log_hx_family_item OWNER TO "gm-dbo"; -- -- Name: log_identity; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_identity ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, deleted boolean, pupic bpchar, gender text, karyotype text, dob timestamp with time zone, fk_marital_status integer, cob bpchar, deceased timestamp with time zone, title text, tob time without time zone ) INHERITS (audit_trail); ALTER TABLE audit.log_identity OWNER TO "gm-dbo"; -- -- Name: log_inbox_item_category; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_inbox_item_category ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, description text, is_user boolean ) INHERITS (audit_trail); ALTER TABLE audit.log_inbox_item_category OWNER TO "gm-dbo"; -- -- Name: log_inbox_item_type; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_inbox_item_type ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_inbox_item_category integer, description text, is_user boolean ) INHERITS (audit_trail); ALTER TABLE audit.log_inbox_item_type OWNER TO "gm-dbo"; -- -- Name: log_incoming_data_unmatchable; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_incoming_data_unmatchable ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_patient_candidates integer[], request_id text, firstnames text, lastnames text, dob date, postcode text, other_info text, type text, data bytea, gender text, requestor text, external_data_id text, fk_identity_disambiguated integer ) INHERITS (audit_trail); ALTER TABLE audit.log_incoming_data_unmatchable OWNER TO "gm-dbo"; -- -- Name: log_incoming_data_unmatched; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_incoming_data_unmatched ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_patient_candidates integer[], request_id text, firstnames text, lastnames text, dob date, postcode text, other_info text, type text, data bytea, gender text, requestor text, external_data_id text, fk_identity_disambiguated integer ) INHERITS (audit_trail); ALTER TABLE audit.log_incoming_data_unmatched OWNER TO "gm-dbo"; -- -- Name: log_lab_request; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lab_request ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer, fk_test_org integer, request_id text, fk_requestor integer, lab_request_id text, lab_rxd_when timestamp with time zone, results_reported_when timestamp with time zone, request_status text, is_pending boolean, diagnostic_service_section text, ordered_service text ) INHERITS (audit_trail); ALTER TABLE audit.log_lab_request OWNER TO "gm-dbo"; -- -- Name: log_lab_test_gnr; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lab_test_gnr ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, id_test integer ) INHERITS (audit_trail); ALTER TABLE audit.log_lab_test_gnr OWNER TO "gm-dbo"; -- -- Name: log_lnk_constraint2vacc_course; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_constraint2vacc_course ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_vaccination_course integer, fk_constraint integer ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_constraint2vacc_course OWNER TO "gm-dbo"; -- -- Name: log_lnk_identity2ext_id; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_identity2ext_id ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, id_identity integer, external_id text, fk_origin integer, comment text ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_identity2ext_id OWNER TO "gm-dbo"; -- -- Name: log_lnk_identity2primary_doc; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_identity2primary_doc ( pk integer, fk_identity integer, fk_primary_doc integer ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_identity2primary_doc OWNER TO "gm-dbo"; -- -- Name: log_lnk_job2person; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_job2person ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_identity integer, fk_occupation integer, activities text ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_job2person OWNER TO "gm-dbo"; -- -- Name: log_lnk_pat2vaccination_course; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_pat2vaccination_course ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_patient integer, fk_course integer ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_pat2vaccination_course OWNER TO "gm-dbo"; -- -- Name: log_lnk_person2relative; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_person2relative ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, id_identity integer, id_relative integer, id_relation_type integer, started date, ended date ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_person2relative OWNER TO "gm-dbo"; -- -- Name: log_lnk_tst2norm; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_tst2norm ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, id_test integer, id_norm integer ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_tst2norm OWNER TO "gm-dbo"; -- -- Name: log_lnk_type2item; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_type2item ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_type integer, fk_item integer ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_type2item OWNER TO "gm-dbo"; -- -- Name: log_lnk_vaccination_course2schedule; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_vaccination_course2schedule ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_course integer, fk_schedule integer ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_vaccination_course2schedule OWNER TO "gm-dbo"; -- -- Name: log_lnk_vaccine2inds; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_lnk_vaccine2inds ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, fk_vaccine integer, fk_indication integer ) INHERITS (audit_trail); ALTER TABLE audit.log_lnk_vaccine2inds OWNER TO "gm-dbo"; -- -- Name: log_message_inbox; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_message_inbox ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_staff integer, fk_inbox_item_type integer, comment text, ufk_context integer, data text, importance smallint, fk_patient integer ) INHERITS (audit_trail); ALTER TABLE audit.log_message_inbox OWNER TO "gm-dbo"; -- -- Name: log_occupation; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_occupation ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, name text ) INHERITS (audit_trail); ALTER TABLE audit.log_occupation OWNER TO "gm-dbo"; -- -- Name: log_operation; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_operation ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_health_issue integer, fk_encounter integer, clin_where text, comment text ) INHERITS (audit_trail); ALTER TABLE audit.log_operation OWNER TO "gm-dbo"; -- -- Name: log_paperwork_templates; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_paperwork_templates ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_template_type integer, instance_type text, name_short text, name_long text, external_version text, gnumed_revision double precision, engine text, in_use boolean, filename text, data bytea ) INHERITS (audit_trail); ALTER TABLE audit.log_paperwork_templates OWNER TO "gm-dbo"; -- -- Name: log_prax_geb_paid; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_prax_geb_paid ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_fall integer, paid_amount numeric, paid_when date, paid_with integer ) INHERITS (audit_trail); ALTER TABLE audit.log_prax_geb_paid OWNER TO "gm-dbo"; -- -- Name: log_procedure; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_procedure ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer, clin_where text, fk_hospital_stay integer ) INHERITS (audit_trail); ALTER TABLE audit.log_procedure OWNER TO "gm-dbo"; -- -- Name: COLUMN log_procedure.orig_version; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_procedure.orig_version IS 'the .row_version in the original row before the audited action took place, should be equal to .row_version'; -- -- Name: COLUMN log_procedure.orig_when; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_procedure.orig_when IS 'the .modified_when in the original row before the audited action took place, should be equal to .modified_when'; -- -- Name: COLUMN log_procedure.orig_by; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_procedure.orig_by IS 'the .modified_by in the original row before the audited action took place, should be equal to .modified_by'; -- -- Name: COLUMN log_procedure.orig_tableoid; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_procedure.orig_tableoid IS 'the TG_RELID when the audit trigger was run'; -- -- Name: log_referral; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_referral ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, id integer, fk_referee integer, fk_form integer ) INHERITS (audit_trail); ALTER TABLE audit.log_referral OWNER TO "gm-dbo"; -- -- Name: log_relation_types; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_relation_types ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, inverse integer, biological boolean, biol_verified boolean, description text ) INHERITS (audit_trail); ALTER TABLE audit.log_relation_types OWNER TO "gm-dbo"; -- -- Name: log_report_query; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_report_query ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, label text, cmd text ) INHERITS (audit_trail); ALTER TABLE audit.log_report_query OWNER TO "gm-dbo"; -- -- Name: log_staff; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_staff ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_identity integer, fk_role integer, db_user name, short_alias text, comment text, is_active boolean ) INHERITS (audit_trail); ALTER TABLE audit.log_staff OWNER TO "gm-dbo"; -- -- Name: log_staff_role; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_staff_role ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, name text, comment text ) INHERITS (audit_trail); ALTER TABLE audit.log_staff_role OWNER TO "gm-dbo"; -- -- Name: log_state; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_state ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, code text, country bpchar, name text ) INHERITS (audit_trail); ALTER TABLE audit.log_state OWNER TO "gm-dbo"; -- -- Name: log_street; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_street ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, id_urb integer, name text, postcode text, suburb text, lat_lon point ) INHERITS (audit_trail); ALTER TABLE audit.log_street OWNER TO "gm-dbo"; -- -- Name: log_substance_in_brand; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_substance_in_brand ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_brand integer, description text, atc_code text ) INHERITS (audit_trail); ALTER TABLE audit.log_substance_in_brand OWNER TO "gm-dbo"; -- -- Name: COLUMN log_substance_in_brand.orig_version; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_substance_in_brand.orig_version IS 'the .row_version in the original row before the audited action took place, should be equal to .row_version'; -- -- Name: COLUMN log_substance_in_brand.orig_when; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_substance_in_brand.orig_when IS 'the .modified_when in the original row before the audited action took place, should be equal to .modified_when'; -- -- Name: COLUMN log_substance_in_brand.orig_by; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_substance_in_brand.orig_by IS 'the .modified_by in the original row before the audited action took place, should be equal to .modified_by'; -- -- Name: COLUMN log_substance_in_brand.orig_tableoid; Type: COMMENT; Schema: audit; Owner: gm-dbo -- COMMENT ON COLUMN log_substance_in_brand.orig_tableoid IS 'the TG_RELID when the audit trigger was run'; -- -- Name: log_substance_intake; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_substance_intake ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer, fk_brand integer, fk_substance integer, strength text, preparation text, schedule text, aim text, duration interval, intake_is_approved_of boolean, is_long_term boolean, discontinued timestamp with time zone, discontinue_reason text ) INHERITS (audit_trail); ALTER TABLE audit.log_substance_intake OWNER TO "gm-dbo"; -- -- Name: log_test_org; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_test_org ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_org integer, fk_adm_contact integer, fk_med_contact integer, internal_name text, comment text, contact text ) INHERITS (audit_trail); ALTER TABLE audit.log_test_org OWNER TO "gm-dbo"; -- -- Name: log_test_result; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_test_result ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, pk integer, fk_type integer, val_num numeric, val_alpha text, val_unit text, val_normal_min numeric, val_normal_max numeric, val_normal_range text, val_target_min numeric, val_target_max numeric, val_target_range text, abnormality_indicator text, norm_ref_group text, note_test_org text, material text, material_detail text, fk_intended_reviewer integer ) INHERITS (audit_trail); ALTER TABLE audit.log_test_result OWNER TO "gm-dbo"; -- -- Name: log_test_type; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_test_type ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_test_org integer, code text, coding_system text, name text, comment text, conversion_unit text, loinc text, abbrev text ) INHERITS (audit_trail); ALTER TABLE audit.log_test_type OWNER TO "gm-dbo"; -- -- Name: log_urb; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_urb ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, id_state integer, postcode text, lat_lon point, name text ) INHERITS (audit_trail); ALTER TABLE audit.log_urb OWNER TO "gm-dbo"; -- -- Name: log_vacc_indication; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_vacc_indication ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, description text ) INHERITS (audit_trail); ALTER TABLE audit.log_vacc_indication OWNER TO "gm-dbo"; -- -- Name: log_vacc_route; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_vacc_route ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, abbreviation text, description text ) INHERITS (audit_trail); ALTER TABLE audit.log_vacc_route OWNER TO "gm-dbo"; -- -- Name: log_vaccination; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_vaccination ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk_item integer, clin_when timestamp with time zone, fk_encounter integer, fk_episode integer, narrative text, soap_cat text, id integer, fk_patient integer, fk_provider integer, fk_vaccine integer, site text, batch_no text ) INHERITS (audit_trail); ALTER TABLE audit.log_vaccination OWNER TO "gm-dbo"; -- -- Name: log_vaccination_course; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_vaccination_course ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_recommended_by integer, fk_indication integer, is_active boolean, comment text ) INHERITS (audit_trail); ALTER TABLE audit.log_vaccination_course OWNER TO "gm-dbo"; -- -- Name: log_vaccination_course_constraint; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_vaccination_course_constraint ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, description text ) INHERITS (audit_trail); ALTER TABLE audit.log_vaccination_course_constraint OWNER TO "gm-dbo"; -- -- Name: log_vaccination_definition; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_vaccination_definition ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, id integer, fk_course integer, is_booster boolean, seq_no integer, min_age_due interval, max_age_due interval, min_interval interval, comment text ) INHERITS (audit_trail); ALTER TABLE audit.log_vaccination_definition OWNER TO "gm-dbo"; -- -- Name: log_vaccination_schedule; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_vaccination_schedule ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, name text, comment text ) INHERITS (audit_trail); ALTER TABLE audit.log_vaccination_schedule OWNER TO "gm-dbo"; -- -- Name: log_vaccine; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_vaccine ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, id_route integer, trade_name text, short_name text, is_live boolean, min_age interval, max_age interval, comment text ) INHERITS (audit_trail); ALTER TABLE audit.log_vaccine OWNER TO "gm-dbo"; -- -- Name: log_vaccine_batches; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_vaccine_batches ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_vaccine integer, batch_no text ) INHERITS (audit_trail); ALTER TABLE audit.log_vaccine_batches OWNER TO "gm-dbo"; -- -- Name: log_waiting_list; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_waiting_list ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, fk_patient integer, registered timestamp with time zone, urgency integer, list_position integer, comment text, area text ) INHERITS (audit_trail); ALTER TABLE audit.log_waiting_list OWNER TO "gm-dbo"; -- -- Name: log_xlnk_identity; Type: TABLE; Schema: audit; Owner: gm-dbo; Tablespace: -- CREATE TABLE log_xlnk_identity ( pk_audit integer, row_version integer, modified_when timestamp with time zone, modified_by name, pk integer, xfk_identity integer, pupic text, data text ) INHERITS (audit_trail); ALTER TABLE audit.log_xlnk_identity OWNER TO "gm-dbo"; SET search_path = bill, pg_catalog; -- -- Name: bill_item; Type: TABLE; Schema: bill; Owner: gm-dbo; Tablespace: -- CREATE TABLE bill_item ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_provider integer NOT NULL, fk_encounter integer NOT NULL, date_to_bill date DEFAULT ('now'::text)::date NOT NULL, code text, system text, description text, receiver text, amount_to_bill numeric, currency text, locale text, status text DEFAULT 'new'::text, CONSTRAINT code_not_empty CHECK (gm.is_null_or_non_empty_string(code)), CONSTRAINT currency_not_empty_if_amount CHECK (((amount_to_bill IS NULL) OR (gm.is_null_or_blank_string(currency) IS FALSE))), CONSTRAINT desc_not_empty CHECK ((gm.is_null_or_blank_string(description) IS FALSE)), CONSTRAINT sane_receiver CHECK (gm.is_null_or_non_empty_string(description)), CONSTRAINT system_not_empty_if_code CHECK (((code IS NULL) OR (system IS NOT NULL))), CONSTRAINT valid_stati CHECK ((status = ANY (ARRAY['new'::text, 'transferred'::text]))) ) INHERITS (audit.audit_fields); ALTER TABLE bill.bill_item OWNER TO "gm-dbo"; -- -- Name: TABLE bill_item; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON TABLE bill_item IS 'Holds items ready for being billed.'; -- -- Name: COLUMN bill_item.fk_provider; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.fk_provider IS 'by whom or on whose behalf did the billable activity happen'; -- -- Name: COLUMN bill_item.fk_encounter; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.fk_encounter IS 'the encounter during which the billable action for this item took place'; -- -- Name: COLUMN bill_item.date_to_bill; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.date_to_bill IS 'the date under which this item is to be billed'; -- -- Name: COLUMN bill_item.code; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.code IS 'a code for the billing item'; -- -- Name: COLUMN bill_item.system; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.system IS 'the coding system for the code for the billing item'; -- -- Name: COLUMN bill_item.description; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.description IS 'a human comprehensible description of the item'; -- -- Name: COLUMN bill_item.receiver; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.receiver IS 'who is to receive the bill'; -- -- Name: COLUMN bill_item.amount_to_bill; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.amount_to_bill IS 'how much to bill for this item if known'; -- -- Name: COLUMN bill_item.currency; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.currency IS 'what currency to bill in'; -- -- Name: COLUMN bill_item.status; Type: COMMENT; Schema: bill; Owner: gm-dbo -- COMMENT ON COLUMN bill_item.status IS 'the status of this item'; -- -- Name: bill_item_pk_seq; Type: SEQUENCE; Schema: bill; Owner: gm-dbo -- CREATE SEQUENCE bill_item_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE bill.bill_item_pk_seq OWNER TO "gm-dbo"; -- -- Name: bill_item_pk_seq; Type: SEQUENCE OWNED BY; Schema: bill; Owner: gm-dbo -- ALTER SEQUENCE bill_item_pk_seq OWNED BY bill_item.pk; SET search_path = blobs, pg_catalog; -- -- Name: doc_desc; Type: TABLE; Schema: blobs; Owner: gm-dbo; Tablespace: -- CREATE TABLE doc_desc ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_doc integer, text text ) INHERITS (audit.audit_fields); ALTER TABLE blobs.doc_desc OWNER TO "gm-dbo"; -- -- Name: TABLE doc_desc; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON TABLE doc_desc IS 'A textual description of the content such as a result summary. Several of these may belong to one document object.'; -- -- Name: doc_desc_pk_seq; Type: SEQUENCE; Schema: blobs; Owner: gm-dbo -- CREATE SEQUENCE doc_desc_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE blobs.doc_desc_pk_seq OWNER TO "gm-dbo"; -- -- Name: doc_desc_pk_seq; Type: SEQUENCE OWNED BY; Schema: blobs; Owner: gm-dbo -- ALTER SEQUENCE doc_desc_pk_seq OWNED BY doc_desc.pk; -- -- Name: doc_med; Type: TABLE; Schema: blobs; Owner: gm-dbo; Tablespace: -- CREATE TABLE doc_med ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_encounter integer NOT NULL, fk_episode integer NOT NULL, fk_type integer NOT NULL, comment text, clin_when timestamp with time zone DEFAULT now() NOT NULL, ext_ref text ) INHERITS (audit.audit_fields); ALTER TABLE blobs.doc_med OWNER TO "gm-dbo"; -- -- Name: TABLE doc_med; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON TABLE doc_med IS 'a medical document object possibly containing several data objects such as several pages of a paper document'; -- -- Name: COLUMN doc_med.fk_encounter; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_med.fk_encounter IS 'the encounter in which this document was entered into the system'; -- -- Name: COLUMN doc_med.fk_episode; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_med.fk_episode IS 'the episode this document pertains to, this may not be the only one applicable to the document (think discharge letters), see also lnk_doc_med2episode'; -- -- Name: COLUMN doc_med.fk_type; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_med.fk_type IS 'semantic type of document (not type of file or mime type), such as "referral letter", "discharge summary", etc.'; -- -- Name: COLUMN doc_med.comment; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_med.comment IS 'additional short comment such as "abdominal", "ward 3, Dr. Stein", etc.'; -- -- Name: COLUMN doc_med.clin_when; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_med.clin_when IS 'date of document content creation (such as exam date), NOT date of document creation or date of import; may be imprecise such as "7/99"'; -- -- Name: COLUMN doc_med.ext_ref; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_med.ext_ref IS 'external reference string of physical document, original paper copy can be found with this'; -- -- Name: doc_med_pk_seq; Type: SEQUENCE; Schema: blobs; Owner: gm-dbo -- CREATE SEQUENCE doc_med_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE blobs.doc_med_pk_seq OWNER TO "gm-dbo"; -- -- Name: doc_med_pk_seq; Type: SEQUENCE OWNED BY; Schema: blobs; Owner: gm-dbo -- ALTER SEQUENCE doc_med_pk_seq OWNED BY doc_med.pk; -- -- Name: doc_obj; Type: TABLE; Schema: blobs; Owner: gm-dbo; Tablespace: -- CREATE TABLE doc_obj ( pk integer NOT NULL, fk_doc integer NOT NULL, seq_idx integer, comment text, fk_intended_reviewer integer NOT NULL, data bytea NOT NULL, filename text, CONSTRAINT doc_obj_filename_check CHECK ((btrim(COALESCE(filename, 'NULL'::text)) <> ''::text)) ); ALTER TABLE blobs.doc_obj OWNER TO "gm-dbo"; -- -- Name: TABLE doc_obj; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON TABLE doc_obj IS 'possibly several of these form a medical document such as multiple scanned pages/images'; -- -- Name: COLUMN doc_obj.seq_idx; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_obj.seq_idx IS 'index of this object in the sequence of objects for this document'; -- -- Name: COLUMN doc_obj.comment; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_obj.comment IS 'optional tiny comment for this object, such as "page 1"'; -- -- Name: COLUMN doc_obj.fk_intended_reviewer; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_obj.fk_intended_reviewer IS 'who is *supposed* to review this item'; -- -- Name: COLUMN doc_obj.data; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_obj.data IS 'actual binary object data; here is why we use bytea: == -------------------------------------------------- To: leon@oss.minimetria.com Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Recommendation on bytea or blob for binary data like images Date: Fri, 02 Sep 2005 16:33:09 -0400 Message-ID: <17794.1125693189@sss.pgh.pa.us> From: Tom Lane List-Archive: List-Help: List-ID: leon@oss.minimetria.com writes: > Hi, I"d like to know what the official recommendation is on which binary > datatype to use for common small-binary size use. If bytea will work for you, it"s definitely the thing to use. The only real drawback to bytea is that there"s currently no API to read and write bytea values in a streaming fashion. If your objects are small enough that you can load and store them as units, bytea is fine. BLOBs, on the other hand, have a number of drawbacks --- hard to dump, impossible to secure, etc. regards, tom lane == --------------------------------------------------'; -- -- Name: COLUMN doc_obj.filename; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_obj.filename IS 'the filename from when the data was imported - if any, can be NULL, useful for re-export since legacy devices/applications might expect particular file names and not use mime types for file detection'; -- -- Name: doc_obj_pk_seq; Type: SEQUENCE; Schema: blobs; Owner: gm-dbo -- CREATE SEQUENCE doc_obj_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE blobs.doc_obj_pk_seq OWNER TO "gm-dbo"; -- -- Name: doc_obj_pk_seq; Type: SEQUENCE OWNED BY; Schema: blobs; Owner: gm-dbo -- ALTER SEQUENCE doc_obj_pk_seq OWNED BY doc_obj.pk; -- -- Name: doc_type; Type: TABLE; Schema: blobs; Owner: gm-dbo; Tablespace: -- CREATE TABLE doc_type ( pk integer NOT NULL, name text NOT NULL ); ALTER TABLE blobs.doc_type OWNER TO "gm-dbo"; -- -- Name: TABLE doc_type; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON TABLE doc_type IS 'this table enumerates the document types known to the system'; -- -- Name: COLUMN doc_type.name; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON COLUMN doc_type.name IS 'the name/label of the document type'; -- -- Name: doc_type_pk_seq; Type: SEQUENCE; Schema: blobs; Owner: gm-dbo -- CREATE SEQUENCE doc_type_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE blobs.doc_type_pk_seq OWNER TO "gm-dbo"; -- -- Name: doc_type_pk_seq; Type: SEQUENCE OWNED BY; Schema: blobs; Owner: gm-dbo -- ALTER SEQUENCE doc_type_pk_seq OWNED BY doc_type.pk; -- -- Name: lnk_doc2hospital_stay; Type: TABLE; Schema: blobs; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_doc2hospital_stay ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_stay integer NOT NULL, fk_document integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE blobs.lnk_doc2hospital_stay OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_doc2hospital_stay; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON TABLE lnk_doc2hospital_stay IS 'links documents to any hospital stay they might pertain to'; -- -- Name: lnk_doc2hospital_stay_pk_seq; Type: SEQUENCE; Schema: blobs; Owner: gm-dbo -- CREATE SEQUENCE lnk_doc2hospital_stay_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE blobs.lnk_doc2hospital_stay_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_doc2hospital_stay_pk_seq; Type: SEQUENCE OWNED BY; Schema: blobs; Owner: gm-dbo -- ALTER SEQUENCE lnk_doc2hospital_stay_pk_seq OWNED BY lnk_doc2hospital_stay.pk; -- -- Name: lnk_doc_med2episode; Type: TABLE; Schema: blobs; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_doc_med2episode ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_episode integer NOT NULL, fk_doc_med integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE blobs.lnk_doc_med2episode OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_doc_med2episode; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON TABLE lnk_doc_med2episode IS 'this allows linking documents to episodes, each document can apply to several episodes but only once each'; -- -- Name: lnk_doc_med2episode_pk_seq; Type: SEQUENCE; Schema: blobs; Owner: gm-dbo -- CREATE SEQUENCE lnk_doc_med2episode_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE blobs.lnk_doc_med2episode_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_doc_med2episode_pk_seq; Type: SEQUENCE OWNED BY; Schema: blobs; Owner: gm-dbo -- ALTER SEQUENCE lnk_doc_med2episode_pk_seq OWNED BY lnk_doc_med2episode.pk; SET search_path = clin, pg_catalog; -- -- Name: review_root; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE review_root ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_reviewed_row integer NOT NULL, fk_reviewer integer NOT NULL, is_technically_abnormal boolean NOT NULL, clinically_relevant boolean NOT NULL, comment text ) INHERITS (audit.audit_fields); ALTER TABLE clin.review_root OWNER TO "gm-dbo"; -- -- Name: TABLE review_root; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE review_root IS 'this table tracks whether a particular clinical item was reviewed by a clinician or not'; -- -- Name: COLUMN review_root.fk_reviewed_row; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN review_root.fk_reviewed_row IS 'the row the review status is for: to be qualified as a proper foreign key in child tables'; -- -- Name: COLUMN review_root.fk_reviewer; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN review_root.fk_reviewer IS 'who has reviewed the item'; -- -- Name: COLUMN review_root.is_technically_abnormal; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN review_root.is_technically_abnormal IS 'whether test provider flagged this result as abnormal, *not* a clinical assessment but rather a technical one LDT: exist(8422)'; -- -- Name: COLUMN review_root.clinically_relevant; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN review_root.clinically_relevant IS 'whether this result is considered relevant clinically, need not correspond to the value of "techically_abnormal" since abnormal values may be irrelevant while normal ones can be of significance'; -- -- Name: review_root_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE review_root_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.review_root_pk_seq OWNER TO "gm-dbo"; -- -- Name: review_root_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE review_root_pk_seq OWNED BY review_root.pk; -- -- Name: pk; Type: DEFAULT; Schema: clin; Owner: gm-dbo -- ALTER TABLE review_root ALTER COLUMN pk SET DEFAULT nextval('review_root_pk_seq'::regclass); SET search_path = blobs, pg_catalog; -- -- Name: reviewed_doc_objs; Type: TABLE; Schema: blobs; Owner: gm-dbo; Tablespace: -- CREATE TABLE reviewed_doc_objs ( pk integer DEFAULT nextval('clin.review_root_pk_seq'::regclass) ) INHERITS (clin.review_root); ALTER TABLE blobs.reviewed_doc_objs OWNER TO "gm-dbo"; -- -- Name: TABLE reviewed_doc_objs; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON TABLE reviewed_doc_objs IS 'review table for documents (per object such as a page)'; SET search_path = clin, pg_catalog; -- -- Name: encounter; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE encounter ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_patient integer NOT NULL, fk_type integer DEFAULT 1 NOT NULL, fk_location integer, source_time_zone interval, reason_for_encounter text, assessment_of_encounter text, started timestamp with time zone DEFAULT now() NOT NULL, last_affirmed timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT encounter_assessment_of_encounter_check CHECK ((btrim(COALESCE(assessment_of_encounter, 'xxxDEFAULTxxx'::text)) <> ''::text)), CONSTRAINT encounter_reason_for_encounter_check CHECK ((btrim(COALESCE(reason_for_encounter, 'xxxDEFAULTxxx'::text)) <> ''::text)) ) INHERITS (audit.audit_fields); ALTER TABLE clin.encounter OWNER TO "gm-dbo"; -- -- Name: TABLE encounter; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE encounter IS 'a clinical encounter between a person and the health care system'; -- -- Name: COLUMN encounter.fk_patient; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN encounter.fk_patient IS 'PK of subject of care, should be PUPIC, actually'; -- -- Name: COLUMN encounter.fk_type; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN encounter.fk_type IS 'PK of type of this encounter'; -- -- Name: COLUMN encounter.fk_location; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN encounter.fk_location IS 'PK of location *of care*, e.g. where the provider is at'; -- -- Name: COLUMN encounter.source_time_zone; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN encounter.source_time_zone IS 'time zone of location, used to approximate source time zone for all timestamps in this encounter'; -- -- Name: COLUMN encounter.reason_for_encounter; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN encounter.reason_for_encounter IS 'the RFE for the encounter as related by either the patient or the provider (say, in a chart review)'; -- -- Name: COLUMN encounter.assessment_of_encounter; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN encounter.assessment_of_encounter IS 'the Assessment of Encounter (eg consultation summary) as determined by the provider, may simply be a concatenation of soAp narrative, this assessment should go across all problems'; -- -- Name: episode; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE episode ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_health_issue integer, description text NOT NULL, is_open boolean DEFAULT true, fk_encounter integer NOT NULL, diagnostic_certainty_classification text, CONSTRAINT sane_description CHECK ((gm.is_null_or_blank_string(description) IS FALSE)), CONSTRAINT valid_diagnostic_certainty_classification CHECK ((diagnostic_certainty_classification = ANY (ARRAY['A'::text, 'B'::text, 'C'::text, 'D'::text, NULL::text]))) ) INHERITS (audit.audit_fields); ALTER TABLE clin.episode OWNER TO "gm-dbo"; -- -- Name: TABLE episode; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE episode IS '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.'; -- -- Name: COLUMN episode.fk_health_issue; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN episode.fk_health_issue IS 'health issue this episode belongs to'; -- -- Name: COLUMN episode.description; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN episode.description IS 'description/name of this episode'; -- -- Name: COLUMN episode.is_open; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN episode.is_open IS 'whether the episode is open (eg. there is activity for it), means open in a temporal sense as in "not closed yet"; only one episode can be open per health issue'; -- -- Name: COLUMN episode.fk_encounter; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN episode.fk_encounter IS 'The encounter during which this episode was added (begun).'; -- -- Name: COLUMN episode.diagnostic_certainty_classification; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN episode.diagnostic_certainty_classification IS 'The certainty at which this problem is believed to be a diagnosis: A: sign (Symptom) B: cluster of signs (Symptomkomplex) C: syndromic diagnosis (Bild einer Diagnose) D: proven diagnosis (diagnostisch gesichert)'; SET search_path = blobs, pg_catalog; -- -- Name: v_doc_med; Type: VIEW; Schema: blobs; Owner: gm-dbo -- CREATE VIEW v_doc_med AS SELECT (SELECT encounter.fk_patient FROM clin.encounter WHERE (encounter.pk = dm.fk_encounter)) AS pk_patient, dm.pk AS pk_doc, dm.clin_when, dt.name AS type, public._(dt.name) AS l10n_type, dm.ext_ref, cle.description AS episode, dm.comment, cle.is_open AS episode_open, dm.fk_type AS pk_type, dm.fk_encounter AS pk_encounter, dm.fk_episode AS pk_episode, cle.fk_health_issue AS pk_health_issue, dm.modified_when, dm.modified_by, dm.xmin AS xmin_doc_med FROM doc_med dm, doc_type dt, clin.episode cle WHERE ((dt.pk = dm.fk_type) AND (cle.pk = dm.fk_episode)); ALTER TABLE blobs.v_doc_med OWNER TO "gm-dbo"; -- -- Name: v_doc_desc; Type: VIEW; Schema: blobs; Owner: gm-dbo -- CREATE VIEW v_doc_desc AS 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 doc_desc dd, v_doc_med vdm WHERE (dd.fk_doc = vdm.pk_doc); ALTER TABLE blobs.v_doc_desc OWNER TO "gm-dbo"; -- -- Name: VIEW v_doc_desc; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON VIEW v_doc_desc IS 'aggregates some document data descriptions'; SET search_path = dem, pg_catalog; -- -- Name: staff; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE staff ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_identity integer NOT NULL, fk_role integer NOT NULL, db_user name DEFAULT "current_user"() NOT NULL, short_alias text NOT NULL, comment text, is_active boolean DEFAULT true NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE dem.staff OWNER TO "gm-dbo"; -- -- Name: TABLE staff; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE staff IS 'one-to-one mapping of database user accounts (db_user) to staff identities (fk_identity)'; -- -- Name: COLUMN staff.short_alias; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN staff.short_alias IS 'a short signature unique to this staff member to be used in the GUI, actually this is somewhat redundant with ext_person_id...'; SET search_path = blobs, pg_catalog; -- -- Name: v_doc_med_journal; Type: VIEW; Schema: blobs; Owner: gm-dbo -- CREATE VIEW v_doc_med_journal AS SELECT (SELECT encounter.fk_patient FROM clin.encounter WHERE (encounter.pk = dm.fk_encounter)) AS pk_patient, dm.modified_when, dm.clin_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = dm.modified_by)), (('<'::text || (dm.modified_by)::text) || '>'::text)) AS modified_by, NULL::text AS soap_cat, ((((((public._('Document'::text) || ': '::text) || public._(dt.name)) || COALESCE(((' "'::text || dm.ext_ref) || '" ('::text), ' ('::text)) || to_char(dm.clin_when, 'YYYY-MM-DD HH24:MI'::text)) || ')'::text) || COALESCE((' '::text || dm.comment), ''::text)) AS narrative, dm.fk_encounter AS pk_encounter, dm.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM clin.episode WHERE (episode.pk = dm.fk_episode)) AS pk_health_issue, dm.pk AS src_pk, 'blobs.doc_med'::text AS src_table FROM doc_med dm, doc_type dt WHERE (dt.pk = dm.fk_type); ALTER TABLE blobs.v_doc_med_journal OWNER TO "gm-dbo"; SET search_path = ref, pg_catalog; -- -- Name: document_type; Type: TABLE; Schema: ref; Owner: gm-dbo; Tablespace: -- CREATE TABLE document_type ( pk integer NOT NULL, scope text, description text NOT NULL ); ALTER TABLE ref.document_type OWNER TO "gm-dbo"; -- -- Name: TABLE document_type; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON TABLE document_type IS 'pre-installed document types, do not change these as they will be overwritten during database upgrades at the discretion of the GNUmed team'; -- -- Name: COLUMN document_type.scope; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON COLUMN document_type.scope IS 'can be used to group document types according to applicability, say, per country'; SET search_path = blobs, pg_catalog; -- -- Name: v_doc_type; Type: VIEW; Schema: blobs; Owner: gm-dbo -- CREATE VIEW v_doc_type AS SELECT dt.pk AS pk_doc_type, dt.name AS type, public._(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 doc_med WHERE (doc_med.fk_type = dt.pk))) AS is_in_use, dt.xmin AS xmin_doc_type FROM doc_type dt; ALTER TABLE blobs.v_doc_type OWNER TO "gm-dbo"; -- -- Name: VIEW v_doc_type; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON VIEW v_doc_type IS 'list active document types, those that are activated for use'; -- -- Name: v_obj4doc_no_data; Type: VIEW; Schema: blobs; Owner: gm-dbo -- CREATE VIEW v_obj4doc_no_data AS SELECT vdm.pk_patient, dobj.pk AS pk_obj, dobj.seq_idx, octet_length(COALESCE(dobj.data, ''::bytea)) AS size, vdm.clin_when AS date_generated, vdm.type, vdm.l10n_type, vdm.ext_ref, vdm.episode, vdm.comment AS doc_comment, dobj.comment AS obj_comment, dobj.filename, dobj.fk_intended_reviewer AS pk_intended_reviewer, (EXISTS (SELECT 1 FROM reviewed_doc_objs WHERE (reviewed_doc_objs.fk_reviewed_row = dobj.pk))) AS reviewed, (EXISTS (SELECT 1 FROM reviewed_doc_objs WHERE ((reviewed_doc_objs.fk_reviewed_row = dobj.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 reviewed_doc_objs WHERE ((reviewed_doc_objs.fk_reviewed_row = dobj.pk) AND (reviewed_doc_objs.fk_reviewer = dobj.fk_intended_reviewer)))) AS reviewed_by_intended_reviewer, vdm.pk_doc, vdm.pk_type, vdm.pk_encounter, vdm.pk_episode, vdm.pk_health_issue, dobj.xmin AS xmin_doc_obj FROM v_doc_med vdm, doc_obj dobj WHERE (vdm.pk_doc = dobj.fk_doc); ALTER TABLE blobs.v_obj4doc_no_data OWNER TO "gm-dbo"; -- -- Name: VIEW v_obj4doc_no_data; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON VIEW v_obj4doc_no_data IS 'denormalized metadata for blobs.doc_obj but without the data itself'; -- -- Name: v_latest_mugshot; Type: VIEW; Schema: blobs; Owner: gm-dbo -- CREATE VIEW v_latest_mugshot AS SELECT vo4d.pk_patient, vo4d.doc_comment, vo4d.date_generated AS date_taken, vo4d.ext_ref, vo4d.seq_idx AS obj_seq_idx, vo4d.obj_comment, vo4d.pk_doc, vo4d.pk_obj, bdo.data AS image FROM v_obj4doc_no_data vo4d, doc_obj bdo WHERE (((vo4d.type = 'patient photograph'::text) AND (vo4d.seq_idx = (SELECT max(vo4d1.seq_idx) AS max FROM v_obj4doc_no_data vo4d1 WHERE ((vo4d1.pk_patient = vo4d.pk_patient) AND (vo4d1.type = 'patient photograph'::text)) GROUP BY vo4d1.date_generated ORDER BY vo4d1.date_generated DESC LIMIT 1))) AND (bdo.pk = vo4d.pk_obj)); ALTER TABLE blobs.v_latest_mugshot OWNER TO "gm-dbo"; -- -- Name: VIEW v_latest_mugshot; Type: COMMENT; Schema: blobs; Owner: gm-dbo -- COMMENT ON VIEW v_latest_mugshot IS 'shows the latest picture of the patient, currently the highest seq_idx of the newest document of type "patient photograph"'; -- -- Name: v_reviewed_doc_objects; Type: VIEW; Schema: blobs; Owner: gm-dbo -- CREATE VIEW v_reviewed_doc_objects AS 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 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 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 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 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 v_obj4doc_no_data WHERE (v_obj4doc_no_data.pk_obj = rdo.fk_reviewed_row)) AS pk_health_issue FROM reviewed_doc_objs rdo; ALTER TABLE blobs.v_reviewed_doc_objects OWNER TO "gm-dbo"; SET search_path = cfg, pg_catalog; -- -- Name: cfg_data; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE cfg_data ( fk_item integer NOT NULL, value bytea NOT NULL ); ALTER TABLE cfg.cfg_data OWNER TO "gm-dbo"; -- -- Name: TABLE cfg_data; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON TABLE cfg_data IS 'stores opaque configuration data, either text or binary, note that it will be difficult to share such options among different types of clients'; -- -- Name: cfg_item; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE cfg_item ( pk integer NOT NULL, fk_template integer NOT NULL, owner name DEFAULT "current_user"() NOT NULL, workplace text, cookie text ); ALTER TABLE cfg.cfg_item OWNER TO "gm-dbo"; -- -- Name: TABLE cfg_item; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON TABLE cfg_item IS 'this table holds all "instances" of cfg.cfg_template'; -- -- Name: COLUMN cfg_item.fk_template; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN cfg_item.fk_template IS 'this points to the class of this option, think of this as a base object, this also defines the data type'; -- -- Name: COLUMN cfg_item.owner; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN cfg_item.owner IS 'the database level user this option belongs to; this is the "role" of the user from the perspective of the database; can be "default" at the application level to indicate that it does not care'; -- -- Name: COLUMN cfg_item.workplace; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN cfg_item.workplace IS '- the logical workplace this option pertains to - can be a hostname but should be a logical rather than a physical identifier as machines get moved, workplaces do not, kind of like a "role" for the machine - associate this with a physical workplace through a local config file or environment variable'; -- -- Name: COLUMN cfg_item.cookie; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN cfg_item.cookie IS 'an arbitrary, opaque entity the client code can use to associate this config item with even finer grained context; could be the pertinent patient ID for patient specific options'; -- -- Name: cfg_item_pk_seq; Type: SEQUENCE; Schema: cfg; Owner: gm-dbo -- CREATE SEQUENCE cfg_item_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE cfg.cfg_item_pk_seq OWNER TO "gm-dbo"; -- -- Name: cfg_item_pk_seq; Type: SEQUENCE OWNED BY; Schema: cfg; Owner: gm-dbo -- ALTER SEQUENCE cfg_item_pk_seq OWNED BY cfg_item.pk; -- -- Name: cfg_numeric; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE cfg_numeric ( fk_item integer NOT NULL, value numeric NOT NULL ); ALTER TABLE cfg.cfg_numeric OWNER TO "gm-dbo"; -- -- Name: cfg_str_array; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE cfg_str_array ( fk_item integer NOT NULL, value text[] NOT NULL ); ALTER TABLE cfg.cfg_str_array OWNER TO "gm-dbo"; -- -- Name: cfg_string; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE cfg_string ( fk_item integer NOT NULL, value text NOT NULL ); ALTER TABLE cfg.cfg_string OWNER TO "gm-dbo"; -- -- Name: cfg_template; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE cfg_template ( pk integer NOT NULL, name text DEFAULT 'must set this !'::text NOT NULL, type text NOT NULL, cfg_group text DEFAULT 'xxxDEFAULTxxx'::text NOT NULL, description text DEFAULT 'programmer is an avid Camel Book Reader'::text NOT NULL ); ALTER TABLE cfg.cfg_template OWNER TO "gm-dbo"; -- -- Name: TABLE cfg_template; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON TABLE cfg_template IS 'meta definition of config items'; -- -- Name: COLUMN cfg_template.name; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN cfg_template.name IS 'the name of the option; this MUST be set to something meaningful'; -- -- Name: COLUMN cfg_template.type; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN cfg_template.type IS 'type of the value'; -- -- Name: COLUMN cfg_template.cfg_group; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN cfg_template.cfg_group IS 'just for logical grouping of options according to task sets to facilitate better config management'; -- -- Name: COLUMN cfg_template.description; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN cfg_template.description IS 'arbitrary description (user visible)'; -- -- Name: cfg_template_pk_seq; Type: SEQUENCE; Schema: cfg; Owner: gm-dbo -- CREATE SEQUENCE cfg_template_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE cfg.cfg_template_pk_seq OWNER TO "gm-dbo"; -- -- Name: cfg_template_pk_seq; Type: SEQUENCE OWNED BY; Schema: cfg; Owner: gm-dbo -- ALTER SEQUENCE cfg_template_pk_seq OWNED BY cfg_template.pk; -- -- Name: cfg_type_enum; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE cfg_type_enum ( name text NOT NULL ); ALTER TABLE cfg.cfg_type_enum OWNER TO "gm-dbo"; -- -- Name: TABLE cfg_type_enum; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON TABLE cfg_type_enum IS 'enumeration of config option data types'; -- -- Name: config; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE config ( id integer NOT NULL, profile character(25) DEFAULT 'default'::bpchar, username character(25) DEFAULT "current_user"(), ddb integer, db integer, crypt_pwd text, crypt_algo text, pwd_hash text, hash_algo text ); ALTER TABLE cfg.config OWNER TO "gm-dbo"; -- -- Name: TABLE config; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON TABLE config IS 'maps a service name to a database location for a particular user, includes user credentials for that database'; -- -- Name: COLUMN config.profile; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN config.profile IS 'allows multiple profiles per user/ pseudo user, one user may have different configuration profiles depending on role, need and location'; -- -- Name: COLUMN config.username; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN config.username IS 'user name as used within the GNUmed system'; -- -- Name: COLUMN config.ddb; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN config.ddb IS 'which GNUmed service are we mapping to a database here'; -- -- Name: COLUMN config.db; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN config.db IS 'how to reach the database host for this service'; -- -- Name: COLUMN config.crypt_pwd; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN config.crypt_pwd IS 'password for user and database, encrypted'; -- -- Name: COLUMN config.crypt_algo; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN config.crypt_algo IS 'encryption algorithm used for password encryption'; -- -- Name: COLUMN config.pwd_hash; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN config.pwd_hash IS 'hash of the unencrypted password'; -- -- Name: COLUMN config.hash_algo; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN config.hash_algo IS 'algorithm used for password hashing'; -- -- Name: config_id_seq; Type: SEQUENCE; Schema: cfg; Owner: gm-dbo -- CREATE SEQUENCE config_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE cfg.config_id_seq OWNER TO "gm-dbo"; -- -- Name: config_id_seq; Type: SEQUENCE OWNED BY; Schema: cfg; Owner: gm-dbo -- ALTER SEQUENCE config_id_seq OWNED BY config.id; -- -- Name: db_logon_banner; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE db_logon_banner ( message text, singularizer boolean DEFAULT true, CONSTRAINT db_logon_banner_message_check CHECK ((btrim(message) <> ''::text)), CONSTRAINT db_logon_banner_singularizer_check CHECK ((singularizer IS TRUE)) ); ALTER TABLE cfg.db_logon_banner OWNER TO "gm-dbo"; -- -- Name: TABLE db_logon_banner; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON TABLE db_logon_banner IS 'Stores a banner to show when clients log on.'; -- -- Name: COLUMN db_logon_banner.message; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN db_logon_banner.message IS 'The actual message to show.'; -- -- Name: COLUMN db_logon_banner.singularizer; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON COLUMN db_logon_banner.singularizer IS 'Makes sure there only ever is one such banner at any given time.'; -- -- Name: report_query; Type: TABLE; Schema: cfg; Owner: gm-dbo; Tablespace: -- CREATE TABLE report_query ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, label text NOT NULL, cmd text NOT NULL, CONSTRAINT report_query_cmd_check CHECK ((btrim(COALESCE(cmd, 'NULL'::text)) <> ''::text)), CONSTRAINT report_query_label_check CHECK ((btrim(COALESCE(label, 'NULL'::text)) <> ''::text)) ) INHERITS (audit.audit_fields); ALTER TABLE cfg.report_query OWNER TO "gm-dbo"; -- -- Name: TABLE report_query; Type: COMMENT; Schema: cfg; Owner: gm-dbo -- COMMENT ON TABLE report_query IS 'This table stores SQL commands to be used in frontend report style queries.'; -- -- Name: report_query_pk_seq; Type: SEQUENCE; Schema: cfg; Owner: gm-dbo -- CREATE SEQUENCE report_query_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE cfg.report_query_pk_seq OWNER TO "gm-dbo"; -- -- Name: report_query_pk_seq; Type: SEQUENCE OWNED BY; Schema: cfg; Owner: gm-dbo -- ALTER SEQUENCE report_query_pk_seq OWNED BY report_query.pk; -- -- Name: v_cfg_options; Type: VIEW; Schema: cfg; Owner: gm-dbo -- CREATE VIEW v_cfg_options AS 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_template cfg_t, cfg_item cfg_i WHERE (cfg_i.fk_template = cfg_t.pk); ALTER TABLE cfg.v_cfg_options OWNER TO "gm-dbo"; -- -- Name: v_cfg_opts_data; Type: VIEW; Schema: cfg; Owner: gm-dbo -- CREATE VIEW v_cfg_opts_data AS 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_template cfg_t, cfg_item cfg_i, cfg_data cfg_v WHERE ((cfg_i.fk_template = cfg_t.pk) AND (cfg_v.fk_item = cfg_i.pk)); ALTER TABLE cfg.v_cfg_opts_data OWNER TO "gm-dbo"; -- -- Name: v_cfg_opts_numeric; Type: VIEW; Schema: cfg; Owner: gm-dbo -- CREATE VIEW v_cfg_opts_numeric AS 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_template cfg_t, cfg_item cfg_i, cfg_numeric cfg_v WHERE ((cfg_i.fk_template = cfg_t.pk) AND (cfg_v.fk_item = cfg_i.pk)); ALTER TABLE cfg.v_cfg_opts_numeric OWNER TO "gm-dbo"; -- -- Name: v_cfg_opts_str_array; Type: VIEW; Schema: cfg; Owner: gm-dbo -- CREATE VIEW v_cfg_opts_str_array AS 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_template cfg_t, cfg_item cfg_i, cfg_str_array cfg_v WHERE ((cfg_i.fk_template = cfg_t.pk) AND (cfg_v.fk_item = cfg_i.pk)); ALTER TABLE cfg.v_cfg_opts_str_array OWNER TO "gm-dbo"; -- -- Name: v_cfg_opts_string; Type: VIEW; Schema: cfg; Owner: gm-dbo -- CREATE VIEW v_cfg_opts_string AS 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_template cfg_t, cfg_item cfg_i, cfg_string cfg_v WHERE ((cfg_i.fk_template = cfg_t.pk) AND (cfg_v.fk_item = cfg_i.pk)); ALTER TABLE cfg.v_cfg_opts_string OWNER TO "gm-dbo"; SET search_path = clin, pg_catalog; -- -- Name: _enum_allergy_type; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE _enum_allergy_type ( pk integer NOT NULL, value text NOT NULL ); ALTER TABLE clin._enum_allergy_type OWNER TO "gm-dbo"; -- -- Name: _enum_allergy_type_id_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE _enum_allergy_type_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin._enum_allergy_type_id_seq OWNER TO "gm-dbo"; -- -- Name: _enum_allergy_type_id_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE _enum_allergy_type_id_seq OWNED BY _enum_allergy_type.pk; -- -- Name: active_substance; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE active_substance ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, description text NOT NULL, atc_code text, CONSTRAINT sane_atc CHECK ((gm.is_null_or_non_empty_string(atc_code) IS TRUE)) ) INHERITS (audit.audit_fields); ALTER TABLE clin.active_substance OWNER TO "gm-dbo"; -- -- Name: TABLE active_substance; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE active_substance IS '(Active) substances (consumables) a patient may be taking.'; -- -- Name: COLUMN active_substance.description; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN active_substance.description IS 'The substance as such, say, Metoprolol.'; -- -- Name: COLUMN active_substance.atc_code; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN active_substance.atc_code IS 'ATC code, if any.'; -- -- Name: active_substance_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE active_substance_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.active_substance_pk_seq OWNER TO "gm-dbo"; -- -- Name: active_substance_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE active_substance_pk_seq OWNED BY active_substance.pk; -- -- Name: allergy; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE allergy ( soap_cat text DEFAULT 'o'::text, pk integer NOT NULL, substance text NOT NULL, substance_code text, generics text, allergene text, atc_code text, fk_type integer NOT NULL, generic_specific boolean DEFAULT false, definite boolean DEFAULT false, CONSTRAINT allergy_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))) ) INHERITS (clin_root_item); ALTER TABLE clin.allergy OWNER TO "gm-dbo"; -- -- Name: TABLE allergy; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE allergy IS 'patient allergy details'; -- -- Name: COLUMN allergy.narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy.narrative IS 'used as field "reaction"'; -- -- Name: COLUMN allergy.substance; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy.substance IS 'real-world name of substance the patient reacted to, brand name if drug'; -- -- Name: COLUMN allergy.substance_code; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy.substance_code IS 'data source specific opaque product code; must provide a link to a unique product/substance in the database in use; should follow the parseable convention of "::::", e.g. "MIMS::2003-1::190" for Zantac; it is left as an exercise to the application to know what to do with this information'; -- -- Name: COLUMN allergy.generics; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy.generics IS 'names of generic compounds if drug; brand names change/disappear, generic names do not'; -- -- Name: COLUMN allergy.allergene; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy.allergene IS 'name of allergenic ingredient in substance if known'; -- -- Name: COLUMN allergy.atc_code; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy.atc_code IS 'ATC code of allergene or substance if approprate, applicable for penicilline, not so for cat fur'; -- -- Name: COLUMN allergy.fk_type; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy.fk_type IS 'allergy/sensitivity'; -- -- Name: COLUMN allergy.generic_specific; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy.generic_specific IS 'only meaningful for *drug*/*generic* reactions: 1) true: applies to one in "generics" forming "substance", if more than one generic listed in "generics" then "allergene" *must* contain the generic in question; 2) false: applies to drug class of "substance";'; -- -- Name: COLUMN allergy.definite; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy.definite IS 'true: definite, false: not definite'; -- -- Name: allergy_id_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE allergy_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.allergy_id_seq OWNER TO "gm-dbo"; -- -- Name: allergy_id_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE allergy_id_seq OWNED BY allergy.pk; -- -- Name: allergy_state; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE allergy_state ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, has_allergy integer, comment text, last_confirmed timestamp with time zone, fk_encounter integer NOT NULL, CONSTRAINT allergy_state_check CHECK (((has_allergy IS NULL) OR ((has_allergy IS NOT NULL) AND (last_confirmed IS NOT NULL)))), CONSTRAINT allergy_state_has_allergy_check CHECK ((has_allergy = ANY (ARRAY[NULL::integer, 0, 1]))) ) INHERITS (audit.audit_fields); ALTER TABLE clin.allergy_state OWNER TO "gm-dbo"; -- -- Name: COLUMN allergy_state.has_allergy; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy_state.has_allergy IS 'patient allergenic state: - null: unknown, not asked, no data available - -1: unknown, asked, no data obtained - 0: known, asked, has no known allergies - 1: known, asked, does have allergies '; -- -- Name: COLUMN allergy_state.comment; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy_state.comment IS 'A comment on the state, such as "patient says no allergies but I think he is holding back some".'; -- -- Name: COLUMN allergy_state.last_confirmed; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN allergy_state.last_confirmed IS 'When was the state of allergies last confirmed. Must be not NULL if has_allergy is not NULL.'; -- -- Name: allergy_state_id_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE allergy_state_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.allergy_state_id_seq OWNER TO "gm-dbo"; -- -- Name: allergy_state_id_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE allergy_state_id_seq OWNED BY allergy_state.pk; -- -- Name: clin_aux_note; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE clin_aux_note ( pk integer NOT NULL, CONSTRAINT clin_aux_note_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))) ) INHERITS (clin_root_item); ALTER TABLE clin.clin_aux_note OWNER TO "gm-dbo"; -- -- Name: TABLE clin_aux_note; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE clin_aux_note IS 'Other tables link to this if they need more free text fields.'; -- -- Name: clin_aux_note_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE clin_aux_note_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.clin_aux_note_pk_seq OWNER TO "gm-dbo"; -- -- Name: clin_aux_note_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE clin_aux_note_pk_seq OWNED BY clin_aux_note.pk; -- -- Name: clin_diag; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE clin_diag ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_narrative integer NOT NULL, laterality character(1), is_chronic boolean DEFAULT false NOT NULL, is_active boolean DEFAULT true NOT NULL, is_definite boolean DEFAULT false NOT NULL, clinically_relevant boolean DEFAULT true NOT NULL, CONSTRAINT clin_diag_laterality_check CHECK ((((((laterality = 'l'::bpchar) OR (laterality = 'r'::bpchar)) OR (laterality = 'b'::bpchar)) OR (laterality = '?'::bpchar)) OR (laterality IS NULL))), CONSTRAINT if_active_then_relevant CHECK (((is_active = false) OR ((is_active = true) AND (clinically_relevant = true)))) ) INHERITS (audit.audit_fields); ALTER TABLE clin.clin_diag OWNER TO "gm-dbo"; -- -- Name: TABLE clin_diag; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE clin_diag IS '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'; -- -- Name: COLUMN clin_diag.is_chronic; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_diag.is_chronic IS 'whether this diagnosis is chronic, eg. no complete cure is to be expected, regardless of whether it is *active* right now (think of active/non-active phases of Multiple Sclerosis which is sure chronic)'; -- -- Name: COLUMN clin_diag.is_active; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_diag.is_active IS 'whether diagnosis is currently active or dormant'; -- -- Name: COLUMN clin_diag.clinically_relevant; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_diag.clinically_relevant IS 'whether this diagnosis is considered clinically relevant, eg. significant; currently active diagnoses are considered to always be relevant, while inactive ones may or may not be'; -- -- Name: clin_diag_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE clin_diag_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.clin_diag_pk_seq OWNER TO "gm-dbo"; -- -- Name: clin_diag_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE clin_diag_pk_seq OWNED BY clin_diag.pk; -- -- Name: clin_hx_family; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE clin_hx_family ( pk integer NOT NULL, fk_hx_family_item integer NOT NULL, CONSTRAINT clin_hx_family_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))), CONSTRAINT narrative_neither_null_nor_empty CHECK ((btrim(COALESCE(narrative, ''::text)) <> ''::text)) ) INHERITS (clin_root_item); ALTER TABLE clin.clin_hx_family OWNER TO "gm-dbo"; -- -- Name: TABLE clin_hx_family; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE clin_hx_family IS 'stores family history for a given patient'; -- -- Name: COLUMN clin_hx_family.clin_when; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_hx_family.clin_when IS 'when the family history item became known'; -- -- Name: COLUMN clin_hx_family.fk_encounter; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_hx_family.fk_encounter IS 'encounter during which family history item became known'; -- -- Name: COLUMN clin_hx_family.fk_episode; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_hx_family.fk_episode IS 'episode to which family history item is of importance'; -- -- Name: COLUMN clin_hx_family.narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_hx_family.narrative IS 'how is the afflicted person related to the patient'; -- -- Name: COLUMN clin_hx_family.soap_cat; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_hx_family.soap_cat IS 'as usual, must be NULL if fk_narrative_condition is not but this is not enforced and only done in the view'; -- -- Name: clin_hx_family_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE clin_hx_family_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.clin_hx_family_pk_seq OWNER TO "gm-dbo"; -- -- Name: clin_hx_family_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE clin_hx_family_pk_seq OWNED BY clin_hx_family.pk; -- -- Name: clin_item_type; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE clin_item_type ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, type text DEFAULT 'history'::text NOT NULL, code text DEFAULT 'Hx'::text NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.clin_item_type OWNER TO "gm-dbo"; -- -- Name: TABLE clin_item_type; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE clin_item_type IS 'stores arbitrary types for tagging clinical items'; -- -- Name: COLUMN clin_item_type.type; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_item_type.type IS 'the full name of the item type such as "family history"'; -- -- Name: COLUMN clin_item_type.code; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_item_type.code IS 'shorthand for the type, eg "FHx"'; -- -- Name: clin_item_type_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE clin_item_type_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.clin_item_type_pk_seq OWNER TO "gm-dbo"; -- -- Name: clin_item_type_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE clin_item_type_pk_seq OWNED BY clin_item_type.pk; -- -- Name: clin_narrative; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE clin_narrative ( pk integer NOT NULL, CONSTRAINT clin_narrative_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))), CONSTRAINT narrative_neither_null_nor_empty CHECK ((btrim(COALESCE(narrative, ''::text)) <> ''::text)) ) INHERITS (clin_root_item); ALTER TABLE clin.clin_narrative OWNER TO "gm-dbo"; -- -- Name: TABLE clin_narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE clin_narrative IS '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.'; -- -- Name: COLUMN clin_narrative.clin_when; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN clin_narrative.clin_when IS 'when did the item reach clinical reality'; -- -- Name: clin_narrative_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE clin_narrative_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.clin_narrative_pk_seq OWNER TO "gm-dbo"; -- -- Name: clin_narrative_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE clin_narrative_pk_seq OWNED BY clin_narrative.pk; -- -- Name: coded_phrase; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE coded_phrase ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, term text NOT NULL, code text NOT NULL, xfk_coding_system text NOT NULL, CONSTRAINT coded_narrative_code_check CHECK ((btrim(code) <> ''::text)), CONSTRAINT coded_narrative_code_check1 CHECK ((btrim(code) <> ''::text)), CONSTRAINT coded_narrative_term_check CHECK ((btrim(term) <> ''::text)) ) INHERITS (audit.audit_fields); ALTER TABLE clin.coded_phrase OWNER TO "gm-dbo"; -- -- Name: TABLE coded_phrase; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE coded_phrase IS 'associates codes with text snippets which may be in use in clinical tables'; -- -- Name: COLUMN coded_phrase.term; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN coded_phrase.term IS 'the text snippet that is to be coded'; -- -- Name: COLUMN coded_phrase.code; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN coded_phrase.code IS 'the code in the coding system'; -- -- Name: COLUMN coded_phrase.xfk_coding_system; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN coded_phrase.xfk_coding_system IS 'the coding system used to code the text snippet'; -- -- Name: coded_narrative_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE coded_narrative_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.coded_narrative_pk_seq OWNER TO "gm-dbo"; -- -- Name: coded_narrative_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE coded_narrative_pk_seq OWNED BY coded_phrase.pk; -- -- Name: consumed_substance; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE consumed_substance ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, description text NOT NULL, atc_code text, CONSTRAINT sane_description CHECK ((gm.is_null_or_blank_string(description) IS FALSE)) ) INHERITS (audit.audit_fields); ALTER TABLE clin.consumed_substance OWNER TO "gm-dbo"; -- -- Name: TABLE consumed_substance; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE consumed_substance IS 'Substances currently or previously actually being consumed by patients.'; -- -- Name: COLUMN consumed_substance.description; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN consumed_substance.description IS 'human-readable description of substance'; -- -- Name: COLUMN consumed_substance.atc_code; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN consumed_substance.atc_code IS 'NULL or ATC code of substance.'; -- -- Name: consumed_substance_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE consumed_substance_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.consumed_substance_pk_seq OWNER TO "gm-dbo"; -- -- Name: consumed_substance_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE consumed_substance_pk_seq OWNED BY consumed_substance.pk; -- -- Name: encounter_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE encounter_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.encounter_pk_seq OWNER TO "gm-dbo"; -- -- Name: encounter_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE encounter_pk_seq OWNED BY encounter.pk; -- -- Name: encounter_type; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE encounter_type ( pk integer NOT NULL, description text NOT NULL ); ALTER TABLE clin.encounter_type OWNER TO "gm-dbo"; -- -- Name: TABLE encounter_type; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE encounter_type IS 'these are the types of encounter'; -- -- Name: encounter_type_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE encounter_type_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.encounter_type_pk_seq OWNER TO "gm-dbo"; -- -- Name: encounter_type_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE encounter_type_pk_seq OWNED BY encounter_type.pk; -- -- Name: episode_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE episode_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.episode_pk_seq OWNER TO "gm-dbo"; -- -- Name: episode_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE episode_pk_seq OWNED BY episode.pk; -- -- Name: form_data; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE form_data ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_instance integer NOT NULL, fk_form_field integer NOT NULL, value text NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.form_data OWNER TO "gm-dbo"; -- -- Name: TABLE form_data; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE form_data IS 'holds the values used in form instances, for later re-use/validation'; -- -- Name: COLUMN form_data.fk_instance; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN form_data.fk_instance IS 'the form instance this value was used in'; -- -- Name: COLUMN form_data.fk_form_field; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN form_data.fk_form_field IS 'points to the definition of the field in the form which in turn defines the place holder in the template to replace with '; -- -- Name: COLUMN form_data.value; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN form_data.value IS 'the value to replace the place holder with'; -- -- Name: form_data_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE form_data_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.form_data_pk_seq OWNER TO "gm-dbo"; -- -- Name: form_data_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE form_data_pk_seq OWNED BY form_data.pk; -- -- Name: form_instances; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE form_instances ( pk integer NOT NULL, fk_form_def integer NOT NULL, form_name text NOT NULL, CONSTRAINT form_instances_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))), CONSTRAINT form_is_plan CHECK ((soap_cat = 'p'::text)) ) INHERITS (clin_root_item); ALTER TABLE clin.form_instances OWNER TO "gm-dbo"; -- -- Name: TABLE form_instances; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE form_instances IS 'instances of forms, like a log of all processed forms'; -- -- Name: COLUMN form_instances.narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN form_instances.narrative IS 'can be used as a status field, eg. "printed", "faxed" etc.'; -- -- Name: COLUMN form_instances.fk_form_def; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN form_instances.fk_form_def IS 'points to the definition of this instance, this FK will fail once we start separating services, make it into a x_db_fk then'; -- -- Name: COLUMN form_instances.form_name; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN form_instances.form_name IS 'a string uniquely identifying the form template, necessary for the audit trail'; -- -- Name: form_instances_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE form_instances_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.form_instances_pk_seq OWNER TO "gm-dbo"; -- -- Name: form_instances_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE form_instances_pk_seq OWNED BY form_instances.pk; -- -- Name: health_issue; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE health_issue ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, description text NOT NULL, laterality character varying(2), age_noted interval, is_active boolean DEFAULT true, clinically_relevant boolean DEFAULT true, is_confidential boolean DEFAULT false, is_cause_of_death boolean DEFAULT false NOT NULL, fk_encounter integer NOT NULL, grouping text, diagnostic_certainty_classification text, CONSTRAINT health_issue_laterality_check CHECK (((((((laterality)::text = NULL::text) OR ((laterality)::text = 's'::text)) OR ((laterality)::text = 'd'::text)) OR ((laterality)::text = 'sd'::text)) OR ((laterality)::text = 'na'::text))), CONSTRAINT issue_name_not_empty CHECK ((btrim(description) <> ''::text)), CONSTRAINT sane_grouping CHECK (gm.is_null_or_non_empty_string(grouping)), CONSTRAINT valid_diagnostic_certainty_classification CHECK ((diagnostic_certainty_classification = ANY (ARRAY['A'::text, 'B'::text, 'C'::text, 'D'::text, NULL::text]))) ) INHERITS (audit.audit_fields); ALTER TABLE clin.health_issue OWNER TO "gm-dbo"; -- -- Name: TABLE health_issue; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE health_issue IS '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.'; -- -- Name: COLUMN health_issue.description; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN health_issue.description IS 'descriptive name of this health issue, may change over time as evidence increases'; -- -- Name: COLUMN health_issue.laterality; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN health_issue.laterality IS 'NULL: don''t know s: sinister - left d: dexter - right sd: sinister and dexter - both sides na: not applicable'; -- -- Name: COLUMN health_issue.age_noted; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN health_issue.age_noted IS 'at what age the patient acquired the condition'; -- -- Name: COLUMN health_issue.is_active; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN health_issue.is_active IS 'whether this health issue (problem) is active'; -- -- Name: COLUMN health_issue.clinically_relevant; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN health_issue.clinically_relevant IS 'whether this health issue (problem) has any clinical relevance'; -- -- Name: COLUMN health_issue.fk_encounter; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN health_issue.fk_encounter IS 'The encounter during which this health issue was added.'; -- -- Name: COLUMN health_issue.grouping; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN health_issue.grouping IS 'This can be used to entirely arbitrarily group health issues felt to belong to each other.'; -- -- Name: COLUMN health_issue.diagnostic_certainty_classification; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN health_issue.diagnostic_certainty_classification IS 'The certainty at which this issue is believed to be a diagnosis: A: sign (Symptom) B: cluster of signs (Symptomkomplex) C: syndromic diagnosis (Bild einer Diagnose) D: proven diagnosis (diagnostisch gesichert)'; -- -- Name: health_issue_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE health_issue_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.health_issue_pk_seq OWNER TO "gm-dbo"; -- -- Name: health_issue_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE health_issue_pk_seq OWNED BY health_issue.pk; -- -- Name: hospital_stay; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE hospital_stay ( pk integer NOT NULL, discharge timestamp with time zone, CONSTRAINT sane_duration CHECK (((discharge IS NULL) OR (discharge > clin_when))), CONSTRAINT sane_hospital CHECK (gm.is_null_or_non_empty_string(narrative)) ) INHERITS (clin_root_item); ALTER TABLE clin.hospital_stay OWNER TO "gm-dbo"; -- -- Name: TABLE hospital_stay; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE hospital_stay IS 'collects data on hospitalisations of patients, reasons are linked via a link table'; -- -- Name: COLUMN hospital_stay.clin_when; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hospital_stay.clin_when IS 'to be used as when the patient was admitted'; -- -- Name: COLUMN hospital_stay.narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hospital_stay.narrative IS 'the hospital to which the patient was admitted'; -- -- Name: COLUMN hospital_stay.discharge; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hospital_stay.discharge IS 'when was the patient discharged'; -- -- Name: hospital_stay_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE hospital_stay_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.hospital_stay_pk_seq OWNER TO "gm-dbo"; -- -- Name: hospital_stay_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE hospital_stay_pk_seq OWNED BY hospital_stay.pk; -- -- Name: hx_family_item; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE hx_family_item ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_narrative_condition integer, fk_relative integer, name_relative text, dob_relative timestamp with time zone, condition text, age_noted text, age_of_death interval, is_cause_of_death boolean DEFAULT false NOT NULL, CONSTRAINT hx_family_item_condition_check CHECK ((COALESCE(btrim(condition), 'dummy'::text) <> ''::text)), CONSTRAINT hx_family_item_name_relative_check CHECK ((COALESCE(btrim(name_relative), 'dummy'::text) <> ''::text)), CONSTRAINT link_or_know_condition CHECK ((((fk_narrative_condition IS NOT NULL) AND (condition IS NULL)) OR ((fk_narrative_condition IS NULL) AND (condition IS NOT NULL)))), CONSTRAINT link_or_know_relative CHECK (((((((fk_narrative_condition IS NOT NULL) AND (fk_relative IS NULL)) AND (name_relative IS NULL)) AND (dob_relative IS NULL)) OR ((((fk_narrative_condition IS NULL) AND (fk_relative IS NOT NULL)) AND (name_relative IS NULL)) AND (dob_relative IS NULL))) OR (((fk_narrative_condition IS NULL) AND (fk_relative IS NULL)) AND (name_relative IS NOT NULL)))) ) INHERITS (audit.audit_fields); ALTER TABLE clin.hx_family_item OWNER TO "gm-dbo"; -- -- Name: TABLE hx_family_item; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE hx_family_item IS 'stores family history items independant of the patient, this is out-of-EMR so that several patients can link to it'; -- -- Name: COLUMN hx_family_item.fk_narrative_condition; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hx_family_item.fk_narrative_condition IS 'can point to a narrative item of a relative if in database'; -- -- Name: COLUMN hx_family_item.fk_relative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hx_family_item.fk_relative IS 'foreign key to relative if in database'; -- -- Name: COLUMN hx_family_item.name_relative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hx_family_item.name_relative IS 'name of the relative if not in database'; -- -- Name: COLUMN hx_family_item.dob_relative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hx_family_item.dob_relative IS 'DOB of relative if not in database'; -- -- Name: COLUMN hx_family_item.condition; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hx_family_item.condition IS 'narrative holding the condition the relative suffered from, must be NULL if fk_narrative_condition is not'; -- -- Name: COLUMN hx_family_item.age_noted; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hx_family_item.age_noted IS 'at what age the relative acquired the condition'; -- -- Name: COLUMN hx_family_item.age_of_death; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hx_family_item.age_of_death IS 'at what age the relative died'; -- -- Name: COLUMN hx_family_item.is_cause_of_death; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN hx_family_item.is_cause_of_death IS 'whether relative died of this problem, Richard suggested to allow that several times per relative'; -- -- Name: hx_family_item_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE hx_family_item_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.hx_family_item_pk_seq OWNER TO "gm-dbo"; -- -- Name: hx_family_item_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE hx_family_item_pk_seq OWNED BY hx_family_item.pk; -- -- Name: incoming_data_unmatchable; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE incoming_data_unmatchable ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_patient_candidates integer[], request_id text, firstnames text, lastnames text, dob date, postcode text, other_info text, type text, data bytea NOT NULL, gender text, requestor text, external_data_id text, fk_identity_disambiguated integer ) INHERITS (audit.audit_fields); ALTER TABLE clin.incoming_data_unmatchable OWNER TO "gm-dbo"; -- -- Name: TABLE incoming_data_unmatchable; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE incoming_data_unmatchable IS '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'; -- -- Name: incoming_data_unmatchable_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE incoming_data_unmatchable_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.incoming_data_unmatchable_pk_seq OWNER TO "gm-dbo"; -- -- Name: incoming_data_unmatchable_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE incoming_data_unmatchable_pk_seq OWNED BY incoming_data_unmatchable.pk; -- -- Name: incoming_data_unmatched; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE incoming_data_unmatched ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_patient_candidates integer[], request_id text, firstnames text, lastnames text, dob date, postcode text, other_info text, type text, data bytea NOT NULL, gender text, requestor text, external_data_id text, fk_identity_disambiguated integer ) INHERITS (audit.audit_fields); ALTER TABLE clin.incoming_data_unmatched OWNER TO "gm-dbo"; -- -- Name: TABLE incoming_data_unmatched; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE incoming_data_unmatched IS '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'; -- -- Name: COLUMN incoming_data_unmatched.fk_patient_candidates; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.fk_patient_candidates IS 'a matching algorithm can be applied to produce a list of likely candidate patients, the question remains whether this should not be done at runtime'; -- -- Name: COLUMN incoming_data_unmatched.request_id; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.request_id IS 'request ID as found in '; -- -- Name: COLUMN incoming_data_unmatched.firstnames; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.firstnames IS 'first names as found in '; -- -- Name: COLUMN incoming_data_unmatched.lastnames; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.lastnames IS 'last names as found in '; -- -- Name: COLUMN incoming_data_unmatched.dob; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.dob IS 'date of birth as found in '; -- -- Name: COLUMN incoming_data_unmatched.postcode; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.postcode IS 'postcode as found in '; -- -- Name: COLUMN incoming_data_unmatched.other_info; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.other_info IS 'other identifying information as found in '; -- -- Name: COLUMN incoming_data_unmatched.type; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.type IS 'the type of , eg HL7, LDT, ..., useful for selecting an importer'; -- -- Name: COLUMN incoming_data_unmatched.data; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.data IS 'the raw data'; -- -- Name: COLUMN incoming_data_unmatched.gender; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.gender IS 'Gender of patient in source data if available.'; -- -- Name: COLUMN incoming_data_unmatched.requestor; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.requestor IS 'Requestor of data (e.g. who ordered test results) if available in source data.'; -- -- Name: COLUMN incoming_data_unmatched.external_data_id; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.external_data_id IS 'ID of content of .data in external system (e.g. importer) where appropriate'; -- -- Name: COLUMN incoming_data_unmatched.fk_identity_disambiguated; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN incoming_data_unmatched.fk_identity_disambiguated IS 'ID of patient the data is judged to really belong to.'; -- -- Name: incoming_data_unmatched_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE incoming_data_unmatched_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.incoming_data_unmatched_pk_seq OWNER TO "gm-dbo"; -- -- Name: incoming_data_unmatched_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE incoming_data_unmatched_pk_seq OWNED BY incoming_data_unmatched.pk; -- -- Name: keyword_expansion; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE keyword_expansion ( pk integer NOT NULL, fk_staff integer, keyword text NOT NULL, expansion text NOT NULL, owner text DEFAULT "current_user"() NOT NULL, CONSTRAINT keyword_expansion_keyword_check CHECK ((btrim(keyword) <> ''::text)) ); ALTER TABLE clin.keyword_expansion OWNER TO "gm-dbo"; -- -- Name: TABLE keyword_expansion; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE keyword_expansion IS 'A table for expanding text typed by the user based on keywords.'; -- -- Name: COLUMN keyword_expansion.fk_staff; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN keyword_expansion.fk_staff IS 'The provider this expansion applies to. If NULL: applies to all providers.'; -- -- Name: COLUMN keyword_expansion.keyword; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN keyword_expansion.keyword IS 'The keyword to expand. Can only exist once per provider.'; -- -- Name: COLUMN keyword_expansion.expansion; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN keyword_expansion.expansion IS 'The expansion for this keyword.'; -- -- Name: COLUMN keyword_expansion.owner; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN keyword_expansion.owner IS 'Who "owns" this text expansion.'; -- -- Name: keyword_expansion_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE keyword_expansion_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.keyword_expansion_pk_seq OWNER TO "gm-dbo"; -- -- Name: keyword_expansion_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE keyword_expansion_pk_seq OWNED BY keyword_expansion.pk; -- -- Name: lab_request; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lab_request ( soap_cat text DEFAULT 'p'::text, pk integer NOT NULL, fk_test_org integer, request_id text NOT NULL, fk_requestor integer, lab_request_id text, lab_rxd_when timestamp with time zone, results_reported_when timestamp with time zone, request_status text NOT NULL, is_pending boolean DEFAULT true NOT NULL, diagnostic_service_section text, ordered_service text, CONSTRAINT lab_request_request_id_check CHECK ((btrim(request_id) <> ''::text)), CONSTRAINT lab_request_request_status_check CHECK (((((request_status = 'pending'::text) OR (request_status = 'preliminary'::text)) OR (request_status = 'partial'::text)) OR (request_status = 'final'::text))), CONSTRAINT lab_request_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))) ) INHERITS (clin_root_item); ALTER TABLE clin.lab_request OWNER TO "gm-dbo"; -- -- Name: TABLE lab_request; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE lab_request IS 'test request metadata'; -- -- Name: COLUMN lab_request.clin_when; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.clin_when IS 'the time the sample for this request was taken LDT: 8432:8433 HL7: OBR.quantity_timing'; -- -- Name: COLUMN lab_request.narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.narrative IS 'free text comment on request'; -- -- Name: COLUMN lab_request.request_id; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.request_id IS 'ID this request had when sent to the lab LDT: 8310 HL7: OBR.filler_order_number'; -- -- Name: COLUMN lab_request.fk_requestor; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.fk_requestor IS 'who requested the test - really needed ?'; -- -- Name: COLUMN lab_request.lab_request_id; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.lab_request_id IS 'ID this request had internally at the lab LDT: 8311'; -- -- Name: COLUMN lab_request.lab_rxd_when; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.lab_rxd_when IS 'when did the lab receive the request+sample LDT: 8301 HL7: OBR.requested_date_time'; -- -- Name: COLUMN lab_request.results_reported_when; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.results_reported_when IS 'when was the report on the result generated, LDT: 8302 HL7: OBR.results_report_status_change'; -- -- Name: COLUMN lab_request.request_status; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.request_status IS 'pending, final, preliminary, partial LDT: 8401'; -- -- Name: COLUMN lab_request.is_pending; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.is_pending IS 'true if any (even partial) results are still pending'; -- -- Name: COLUMN lab_request.diagnostic_service_section; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.diagnostic_service_section IS 'The (section of) the diagnostic service which performed the test. - HL7 2.3: OBR:24 Diagnostic Service Section ID - somewhat redundant with fk_test_org, which, however, points to more normalized data'; -- -- Name: COLUMN lab_request.ordered_service; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lab_request.ordered_service IS 'The (battery of) test(s)/service(s) ordered. - HL7 2.3: OBR:4 Universal Service ID'; -- -- Name: lab_request_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lab_request_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lab_request_pk_seq OWNER TO "gm-dbo"; -- -- Name: lab_request_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lab_request_pk_seq OWNED BY lab_request.pk; -- -- Name: lnk_constraint2vacc_course; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_constraint2vacc_course ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_vaccination_course integer NOT NULL, fk_constraint integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.lnk_constraint2vacc_course OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_constraint2vacc_course; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE lnk_constraint2vacc_course IS 'links constraints to courses'; -- -- Name: lnk_constraint2vacc_course_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lnk_constraint2vacc_course_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lnk_constraint2vacc_course_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_constraint2vacc_course_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lnk_constraint2vacc_course_pk_seq OWNED BY lnk_constraint2vacc_course.pk; -- -- Name: lnk_pat2vaccination_course; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_pat2vaccination_course ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_patient integer NOT NULL, fk_course integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.lnk_pat2vaccination_course OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_pat2vaccination_course; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE lnk_pat2vaccination_course IS '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'; -- -- Name: lnk_pat2vaccination_course_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lnk_pat2vaccination_course_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lnk_pat2vaccination_course_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_pat2vaccination_course_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lnk_pat2vaccination_course_pk_seq OWNED BY lnk_pat2vaccination_course.pk; -- -- Name: lnk_result2lab_req; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_result2lab_req ( pk integer NOT NULL, fk_result integer NOT NULL, fk_request integer NOT NULL ); ALTER TABLE clin.lnk_result2lab_req OWNER TO "gm-dbo"; -- -- Name: lnk_result2lab_req_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lnk_result2lab_req_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lnk_result2lab_req_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_result2lab_req_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lnk_result2lab_req_pk_seq OWNED BY lnk_result2lab_req.pk; -- -- Name: lnk_substance2episode; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_substance2episode ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_episode integer, fk_substance integer ) INHERITS (audit.audit_fields); ALTER TABLE clin.lnk_substance2episode OWNER TO "gm-dbo"; -- -- Name: lnk_substance2episode_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lnk_substance2episode_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lnk_substance2episode_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_substance2episode_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lnk_substance2episode_pk_seq OWNED BY lnk_substance2episode.pk; -- -- Name: lnk_tst2norm; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_tst2norm ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), id integer NOT NULL, id_test integer NOT NULL, id_norm integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.lnk_tst2norm OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_tst2norm; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE lnk_tst2norm IS 'links test result evaluation norms to tests'; -- -- Name: COLUMN lnk_tst2norm.id_test; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lnk_tst2norm.id_test IS 'which test does the linked norm apply to'; -- -- Name: COLUMN lnk_tst2norm.id_norm; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lnk_tst2norm.id_norm IS 'the norm to apply to the linked test'; -- -- Name: lnk_tst2norm_id_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lnk_tst2norm_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lnk_tst2norm_id_seq OWNER TO "gm-dbo"; -- -- Name: lnk_tst2norm_id_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lnk_tst2norm_id_seq OWNED BY lnk_tst2norm.id; -- -- Name: lnk_ttype2unified_type; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_ttype2unified_type ( pk integer NOT NULL, fk_test_type integer NOT NULL, fk_test_type_unified integer NOT NULL ); ALTER TABLE clin.lnk_ttype2unified_type OWNER TO "gm-dbo"; -- -- Name: lnk_ttype2unified_type_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lnk_ttype2unified_type_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lnk_ttype2unified_type_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_ttype2unified_type_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lnk_ttype2unified_type_pk_seq OWNED BY lnk_ttype2unified_type.pk; -- -- Name: lnk_type2item; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_type2item ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_type integer NOT NULL, fk_item integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.lnk_type2item OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_type2item; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE lnk_type2item IS 'allow to link many-to-many between clin.clin_root_item and clin.clin_item_type'; -- -- Name: COLUMN lnk_type2item.fk_item; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN lnk_type2item.fk_item IS 'the item this type is linked to, since PostgreSQL apparently cannot reference a value inserted from a child table (?) we must simulate referential integrity checks with a custom trigger, this, however, does not deal with update/delete cascading :-('; -- -- Name: lnk_type2item_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lnk_type2item_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lnk_type2item_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_type2item_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lnk_type2item_pk_seq OWNED BY lnk_type2item.pk; -- -- Name: lnk_vaccination_course2schedule; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_vaccination_course2schedule ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_course integer NOT NULL, fk_schedule integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.lnk_vaccination_course2schedule OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_vaccination_course2schedule; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE lnk_vaccination_course2schedule IS 'this table links vaccination courses for a single epitope into schedules defined and recommended by a vaccination council or similar entity'; -- -- Name: lnk_vaccination_course2schedule_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lnk_vaccination_course2schedule_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lnk_vaccination_course2schedule_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_vaccination_course2schedule_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lnk_vaccination_course2schedule_pk_seq OWNED BY lnk_vaccination_course2schedule.pk; -- -- Name: lnk_vaccine2inds; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_vaccine2inds ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), id integer NOT NULL, fk_vaccine integer NOT NULL, fk_indication integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.lnk_vaccine2inds OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_vaccine2inds; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE lnk_vaccine2inds IS 'links vaccines to their indications'; -- -- Name: lnk_vaccine2inds_id_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE lnk_vaccine2inds_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.lnk_vaccine2inds_id_seq OWNER TO "gm-dbo"; -- -- Name: lnk_vaccine2inds_id_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE lnk_vaccine2inds_id_seq OWNED BY lnk_vaccine2inds.id; -- -- Name: meta_test_type; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE meta_test_type ( pk integer NOT NULL, abbrev text NOT NULL, name text NOT NULL, loinc text, comment text ); ALTER TABLE clin.meta_test_type OWNER TO "gm-dbo"; -- -- Name: TABLE meta_test_type; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE meta_test_type IS '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"'; -- -- Name: operation; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE operation ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_health_issue integer NOT NULL, fk_encounter integer NOT NULL, clin_where text, comment text ) INHERITS (audit.audit_fields); ALTER TABLE clin.operation OWNER TO "gm-dbo"; -- -- Name: TABLE operation; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE operation IS 'data about operations a patient had, links to clin.health_issue, use clin.health_issue.age_noted for date of operation'; -- -- Name: COLUMN operation.fk_health_issue; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN operation.fk_health_issue IS 'which clin.health_issue this row refers to'; -- -- Name: COLUMN operation.fk_encounter; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN operation.fk_encounter IS 'during which encounter we learned of this'; -- -- Name: COLUMN operation.clin_where; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN operation.clin_where IS 'where did this operation take place'; -- -- Name: operation_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE operation_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.operation_pk_seq OWNER TO "gm-dbo"; -- -- Name: operation_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE operation_pk_seq OWNED BY operation.pk; -- -- Name: procedure; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE procedure ( pk integer NOT NULL, clin_where text, fk_hospital_stay integer, CONSTRAINT sane_location CHECK (gm.is_null_or_non_empty_string(clin_where)), CONSTRAINT sane_procedure CHECK ((gm.is_null_or_blank_string(narrative) IS FALSE)), CONSTRAINT sane_soap_cat CHECK ((soap_cat = ANY (ARRAY['a'::text, 'p'::text]))), CONSTRAINT single_location_definition CHECK ((((fk_hospital_stay IS NULL) AND (clin_where IS NOT NULL)) OR ((fk_hospital_stay IS NOT NULL) AND (clin_where IS NULL)))) ) INHERITS (clin_root_item); ALTER TABLE clin.procedure OWNER TO "gm-dbo"; -- -- Name: TABLE procedure; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE procedure IS 'This table holds procedure/operations performed on the patient both in hospital or in community care.'; -- -- Name: COLUMN procedure.narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN procedure.narrative IS 'Which procedure/operation was performed.'; -- -- Name: COLUMN procedure.clin_where; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN procedure.clin_where IS 'Where was the procedure/operation performed, unless fk_hospital_stay is not null'; -- -- Name: COLUMN procedure.fk_hospital_stay; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN procedure.fk_hospital_stay IS 'At which hospital was the procedure performed, unless clin_where is not null, if null it was an ambulatory procedure.'; -- -- Name: procedure_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE procedure_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.procedure_pk_seq OWNER TO "gm-dbo"; -- -- Name: procedure_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE procedure_pk_seq OWNED BY procedure.pk; -- -- Name: reviewed_test_results; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE reviewed_test_results ( fk_reviewer integer DEFAULT f_fk_reviewer_default() ) INHERITS (review_root); ALTER TABLE clin.reviewed_test_results OWNER TO "gm-dbo"; -- -- Name: TABLE reviewed_test_results; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE reviewed_test_results IS 'review table for test results'; -- -- Name: soap_cat_ranks; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE soap_cat_ranks ( pk integer NOT NULL, rank integer NOT NULL, soap_cat character(1), CONSTRAINT soap_cat_ranks_rank_check CHECK ((((((rank = 1) OR (rank = 2)) OR (rank = 3)) OR (rank = 4)) OR (rank = 5))), CONSTRAINT soap_cat_ranks_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower((soap_cat)::text) = 's'::text) OR (lower((soap_cat)::text) = 'o'::text)) OR (lower((soap_cat)::text) = 'a'::text)) OR (lower((soap_cat)::text) = 'p'::text)))) ); ALTER TABLE clin.soap_cat_ranks OWNER TO "gm-dbo"; -- -- Name: soap_cat_ranks_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE soap_cat_ranks_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.soap_cat_ranks_pk_seq OWNER TO "gm-dbo"; -- -- Name: soap_cat_ranks_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE soap_cat_ranks_pk_seq OWNED BY soap_cat_ranks.pk; -- -- Name: substance_intake; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE substance_intake ( soap_cat text DEFAULT 'p'::text, pk integer NOT NULL, fk_brand integer, fk_substance integer NOT NULL, strength text, preparation text NOT NULL, schedule text, aim text, duration interval, intake_is_approved_of boolean NOT NULL, is_long_term boolean, discontinued timestamp with time zone, discontinue_reason text, CONSTRAINT discontinued_after_started CHECK ((((clin_when IS NULL) OR (discontinued IS NULL)) OR ((discontinued >= clin_when) AND (discontinued <= now())))), CONSTRAINT medication_is_plan CHECK ((soap_cat = 'p'::text)), CONSTRAINT sane_aim CHECK ((gm.is_null_or_non_empty_string(aim) IS TRUE)), CONSTRAINT 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)))), CONSTRAINT sane_fk_episode CHECK (((intake_is_approved_of IS FALSE) OR ((intake_is_approved_of IS TRUE) AND (fk_episode IS NOT NULL)))), CONSTRAINT sane_schedule CHECK ((gm.is_null_or_non_empty_string(schedule) IS TRUE)), CONSTRAINT sane_strength CHECK ((gm.is_null_or_non_empty_string(strength) IS TRUE)) ) INHERITS (clin_root_item); ALTER TABLE clin.substance_intake OWNER TO "gm-dbo"; -- -- Name: TABLE substance_intake; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE substance_intake IS 'The substances a patient is actually currently taking.'; -- -- Name: COLUMN substance_intake.clin_when; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.clin_when IS 'When was this substance started.'; -- -- Name: COLUMN substance_intake.fk_encounter; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.fk_encounter IS 'The encounter use of this substance was documented under.'; -- -- Name: COLUMN substance_intake.narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.narrative IS 'Any notes on this substance use.'; -- -- Name: COLUMN substance_intake.fk_brand; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.fk_brand IS 'The brand (may be a fake entry) the patient is taking.'; -- -- Name: COLUMN substance_intake.fk_substance; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.fk_substance IS 'The substance a patient is taking.'; -- -- Name: COLUMN substance_intake.strength; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.strength IS 'The amount of the substance, often in mg.'; -- -- Name: COLUMN substance_intake.preparation; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.preparation IS 'How this substance is delivered, tablet, pill, liquid, cream.'; -- -- Name: COLUMN substance_intake.schedule; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.schedule IS 'The schedule, if any, the substance is to be taken by. An XML snippet to be interpreted by the middleware.'; -- -- Name: COLUMN substance_intake.aim; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.aim IS 'The aim of taking this substance.'; -- -- Name: COLUMN substance_intake.duration; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.duration IS 'How long is this substances intended to be taken.'; -- -- Name: COLUMN substance_intake.intake_is_approved_of; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.intake_is_approved_of IS 'Whether or not intake of this substance is recommended/approved of by the provider'; -- -- Name: COLUMN substance_intake.is_long_term; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.is_long_term IS 'whether this is expected to be a regular/ongoing/chronic/long-term/repeat/permament/perpetual/life-long substance intake'; -- -- Name: COLUMN substance_intake.discontinued; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN substance_intake.discontinued IS 'why was this entry discontinued'; -- -- Name: substance_intake_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE substance_intake_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.substance_intake_pk_seq OWNER TO "gm-dbo"; -- -- Name: substance_intake_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE substance_intake_pk_seq OWNED BY substance_intake.pk; -- -- Name: test_org; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE test_org ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_org integer, fk_adm_contact integer, fk_med_contact integer, internal_name text NOT NULL, comment text, contact text, CONSTRAINT sane_comment CHECK ((gm.is_null_or_non_empty_string(comment) IS TRUE)), CONSTRAINT sane_contact CHECK ((gm.is_null_or_non_empty_string(contact) IS TRUE)), CONSTRAINT sane_internal_name CHECK ((gm.is_null_or_blank_string(internal_name) IS FALSE)) ) INHERITS (audit.audit_fields); ALTER TABLE clin.test_org OWNER TO "gm-dbo"; -- -- Name: TABLE test_org; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE test_org IS 'organisation providing results'; -- -- Name: COLUMN test_org.fk_org; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_org.fk_org IS 'link to organisation HL7: MSH.sending_facility/sending_application'; -- -- Name: COLUMN test_org.fk_adm_contact; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_org.fk_adm_contact IS 'whom to call for admin questions (modem link, etc.)'; -- -- Name: COLUMN test_org.fk_med_contact; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_org.fk_med_contact IS 'whom to call for medical questions (result verification, additional test requests)'; -- -- Name: COLUMN test_org.internal_name; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_org.internal_name IS 'you can store here the name a test org identifies itself with when sending data HL7: MSH.sending_application/OBR.universal_service_id'; -- -- Name: COLUMN test_org.comment; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_org.comment IS 'useful for, say, dummy records where you want to mark up stuff like "pharmacy such-and-such" if you don''t have it in your contacts'; -- -- Name: COLUMN test_org.contact; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_org.contact IS 'free-text contact information for this lab'; -- -- Name: test_org_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE test_org_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.test_org_pk_seq OWNER TO "gm-dbo"; -- -- Name: test_org_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE test_org_pk_seq OWNED BY test_org.pk; -- -- Name: test_result; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE test_result ( soap_cat text DEFAULT 'o'::text, pk integer NOT NULL, fk_type integer NOT NULL, val_num numeric, val_alpha text, val_unit text, val_normal_min numeric, val_normal_max numeric, val_normal_range text, val_target_min numeric, val_target_max numeric, val_target_range text, abnormality_indicator text, norm_ref_group text, note_test_org text, material text, material_detail text, fk_intended_reviewer integer NOT NULL, CONSTRAINT numval_needs_unit CHECK ((((val_num IS NOT NULL) AND (btrim(COALESCE(val_unit, ''::text)) <> ''::text)) OR (val_num IS NULL))), CONSTRAINT 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)))), CONSTRAINT test_result_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))) ) INHERITS (clin_root_item); ALTER TABLE clin.test_result OWNER TO "gm-dbo"; -- -- Name: TABLE test_result; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE test_result IS 'the results of a single measurement'; -- -- Name: COLUMN test_result.clin_when; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.clin_when IS 'the time when this result was *actually* obtained, if this is a lab result this should be between lab_request.clin_when and lab_request.results_reported_when, HL7: OBR.observation_date_time'; -- -- Name: COLUMN test_result.narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.narrative IS 'clinical comment, progress note'; -- -- Name: COLUMN test_result.fk_type; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.fk_type IS 'the type of test this result is from'; -- -- Name: COLUMN test_result.val_num; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.val_num IS 'numeric value if any, HL7: OBX.observation_results if OBX.value_type == NM'; -- -- Name: COLUMN test_result.val_alpha; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.val_alpha IS 'alphanumeric value if any, HL7: OBX.observation_results if OBX.value_type == FT'; -- -- Name: COLUMN test_result.val_unit; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.val_unit IS 'the unit this result came in HL7: OBX.units'; -- -- Name: COLUMN test_result.val_normal_min; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.val_normal_min IS 'lower bound of normal range if numerical as defined by provider for this result'; -- -- Name: COLUMN test_result.val_normal_max; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.val_normal_max IS 'upper bound of normal range if numerical as defined by provider for this result'; -- -- Name: COLUMN test_result.val_normal_range; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.val_normal_range IS 'range of normal values if alphanumerical as defined by provider for this result, eg. "less than 0.5 but detectable" HL7: OBX.reference_range'; -- -- Name: COLUMN test_result.val_target_min; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.val_target_min IS 'lower bound of target range if numerical as defined by clinician caring this patient'; -- -- Name: COLUMN test_result.val_target_max; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.val_target_max IS 'upper bound of target range if numerical as defined by clinician caring for this patient'; -- -- Name: COLUMN test_result.val_target_range; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.val_target_range IS 'range of target values if alphanumerical as defined by clinician caring for this patient'; -- -- Name: COLUMN test_result.abnormality_indicator; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.abnormality_indicator IS 'how the test provider flagged this result as abnormal, *not* a clinical assessment but rather a technical one LDT: 8422'; -- -- Name: COLUMN test_result.norm_ref_group; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.norm_ref_group IS 'what sample of the population does this normal range applay to, eg what type of patient was assumed when interpreting this result, LDT: 8407'; -- -- Name: COLUMN test_result.note_test_org; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.note_test_org IS 'A comment on the test result provided by the tester or testing entity.'; -- -- Name: COLUMN test_result.material; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.material IS 'the submitted material, eg. smear, serum, urine, etc., LDT: 8430'; -- -- Name: COLUMN test_result.material_detail; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.material_detail IS 'details re the material, eg. site taken from, etc. LDT: 8431'; -- -- Name: COLUMN test_result.fk_intended_reviewer; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_result.fk_intended_reviewer IS 'who is *supposed* to review this item'; -- -- Name: test_result_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE test_result_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.test_result_pk_seq OWNER TO "gm-dbo"; -- -- Name: test_result_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE test_result_pk_seq OWNED BY test_result.pk; -- -- Name: test_type; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE test_type ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_test_org integer, code text, coding_system text, name text NOT NULL, comment text, conversion_unit text, loinc text, abbrev text NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.test_type OWNER TO "gm-dbo"; -- -- Name: TABLE test_type; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE test_type IS 'measurement type, like a "method" in a lab'; -- -- Name: COLUMN test_type.fk_test_org; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_type.fk_test_org IS 'organisation carrying out this type of measurement, eg. a particular lab'; -- -- Name: COLUMN test_type.code; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_type.code IS 'short name, acronym or code of this type of measurement, may conform to some official list or other such as LOINC, Australian Pathology request codes or German lab-specific ELVs, actually, this column should be checked against the coding system tables, too, the only problem being that we do not know which one ... as it depends on the *value* in "coding_system", HL7: OBX.observation_identifier'; -- -- Name: COLUMN test_type.coding_system; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_type.coding_system IS 'identifier of coding system that the code of this measurement type is taken from, should be verifiable against the "reference" service of GnuMed'; -- -- Name: COLUMN test_type.name; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_type.name IS 'descriptive name of this measurement type, HL7: OBX.observation_identifier'; -- -- Name: COLUMN test_type.comment; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_type.comment IS 'arbitrary comment on this type of measurement/test such as "outdated" or "only reliable when ..."'; -- -- Name: COLUMN test_type.conversion_unit; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN test_type.conversion_unit IS 'the basic unit for this test type, preferably SI, used for comparing results delivered in differing units, this does not relate to what unit the test provider delivers results in but rather the unit we think those results need to be converted to in order to be comparable to OTHER results'; -- -- Name: test_type_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE test_type_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.test_type_pk_seq OWNER TO "gm-dbo"; -- -- Name: test_type_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE test_type_pk_seq OWNED BY test_type.pk; -- -- Name: test_type_unified_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE test_type_unified_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.test_type_unified_pk_seq OWNER TO "gm-dbo"; -- -- Name: test_type_unified_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE test_type_unified_pk_seq OWNED BY meta_test_type.pk; SET search_path = dem, pg_catalog; -- -- Name: identity; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE identity ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, deleted boolean DEFAULT false NOT NULL, pupic character(24), gender text, karyotype text, dob timestamp with time zone, fk_marital_status integer, cob character(2), deceased timestamp with time zone, title text, tob time without time zone, CONSTRAINT identity_check CHECK (((deceased IS NULL) OR (deceased >= dob))), CONSTRAINT identity_title_check CHECK ((btrim(COALESCE(title, 'NULL'::text)) <> ''::text)) ) INHERITS (audit.audit_fields); ALTER TABLE dem.identity OWNER TO "gm-dbo"; -- -- Name: TABLE identity; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE identity IS 'represents the unique identity of a person'; -- -- Name: COLUMN identity.deleted; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN identity.deleted IS 'whether this identity is considered deleted'; -- -- Name: COLUMN identity.pupic; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN identity.pupic IS 'Portable Unique Person Identification Code as per gnumed white papers'; -- -- Name: COLUMN identity.gender; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN identity.gender IS 'the gender code'; -- -- Name: COLUMN identity.dob; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN identity.dob IS 'date/time of birth'; -- -- Name: COLUMN identity.cob; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN identity.cob IS 'country of birth as per date of birth, coded as 2 character ISO code'; -- -- Name: COLUMN identity.deceased; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN identity.deceased IS 'date when a person has died'; -- -- Name: COLUMN identity.title; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN identity.title IS 'Yes, a title is an attribute of an identity, not of a name ! Also, there are some incredible rants of titles.'; SET search_path = clin, pg_catalog; -- -- Name: v_health_issues_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_health_issues_journal AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chi.fk_encounter)) AS pk_patient, chi.modified_when, COALESCE((SELECT (identity.dob + chi.age_noted) FROM dem.identity WHERE (identity.pk = (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chi.fk_encounter)))), (SELECT encounter.started FROM encounter WHERE (encounter.pk = chi.fk_encounter))) AS clin_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = chi.modified_by)), (('<'::text || (chi.modified_by)::text) || '>'::text)) AS modified_by, 'a'::text AS soap_cat, (((((((((((public._('Health Issue'::text) || COALESCE(((' ('::text || chi.diagnostic_certainty_classification) || ')'::text), ''::text)) || ': '::text) || chi.description) || COALESCE(((' ('::text || (chi.laterality)::text) || ')'::text), ''::text)) || ' '::text) || COALESCE((((public._('noted at age'::text) || ': '::text) || (chi.age_noted)::text) || ' '::text), ''::text)) || CASE WHEN chi.is_active THEN public._('active'::text) ELSE public._('inactive'::text) END) || ' / '::text) || CASE WHEN chi.clinically_relevant THEN public._('clinically relevant'::text) ELSE public._('clinically not relevant'::text) END) || CASE WHEN chi.is_confidential THEN (' / '::text || public._('confidential'::text)) ELSE ''::text END) || CASE WHEN chi.is_cause_of_death THEN (' / '::text || public._('cause of death'::text)) ELSE ''::text END) AS narrative, chi.fk_encounter AS pk_encounter, (-1) AS pk_episode, chi.pk AS pk_health_issue, chi.pk AS src_pk, 'clin.health_issue'::text AS src_table, chi.row_version FROM health_issue chi; ALTER TABLE clin.v_health_issues_journal OWNER TO "gm-dbo"; SET search_path = dem, pg_catalog; -- -- Name: names; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE names ( id integer NOT NULL, id_identity integer NOT NULL, active boolean DEFAULT true, lastnames text NOT NULL, firstnames text NOT NULL, preferred text, comment text ); ALTER TABLE dem.names OWNER TO "gm-dbo"; -- -- Name: TABLE names; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE names IS 'all the names an identity is known under; As opposed to the versioning of all other tables, changed names should not be moved into the audit trail tables. Search functionality must be available at any time for all names a person ever had.'; -- -- Name: COLUMN names.active; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN names.active IS 'true if the name is still in use'; -- -- Name: COLUMN names.lastnames; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN names.lastnames IS 'all last names of an identity in legal order, IOW "major" name, "group identifier", eg. family, village, tribe, ...'; -- -- Name: COLUMN names.firstnames; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN names.firstnames IS 'all first names of an identity in legal order, IOW "minor" name, identifier of this identity within the group defined by '; -- -- Name: COLUMN names.preferred; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN names.preferred IS 'preferred first name, the name a person is usually called (nickname, warrior name)'; -- -- Name: COLUMN names.comment; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN names.comment IS 'a comment regarding this name, useful in things like "this was the name before marriage" etc'; SET search_path = clin, pg_catalog; -- -- Name: v_hx_family; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_hx_family AS (SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chxf.fk_encounter)) AS pk_patient, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = chxf.fk_episode)) AS pk_health_issue, chxf.clin_when, chxf.modified_when, chxf.modified_by, chxf.fk_encounter AS pk_encounter, chxf.fk_episode AS pk_episode, chxf.narrative AS relationship, chxf.soap_cat, chxf.pk AS pk_clin_hx_family, chxf.fk_hx_family_item AS pk_hx_family_item, NULL::integer AS pk_narrative_condition, NULL::integer AS pk_relative_identity, hxfi.name_relative, hxfi.dob_relative, hxfi.condition, hxfi.age_noted, hxfi.age_of_death, hxfi.is_cause_of_death FROM clin_hx_family chxf, hx_family_item hxfi WHERE (((hxfi.pk = chxf.fk_hx_family_item) AND (hxfi.fk_narrative_condition IS NULL)) AND (hxfi.fk_relative IS NULL)) UNION SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chxf.fk_encounter)) AS pk_patient, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = chxf.fk_episode)) AS pk_health_issue, chxf.clin_when, chxf.modified_when, chxf.modified_by, chxf.fk_encounter AS pk_encounter, chxf.fk_episode AS pk_episode, chxf.narrative AS relationship, chxf.soap_cat, chxf.pk AS pk_clin_hx_family, chxf.fk_hx_family_item AS pk_hx_family_item, NULL::integer AS pk_narrative_condition, hxfi.fk_relative AS pk_relative_identity, ((dn.firstnames || ' '::text) || dn.lastnames) AS name_relative, di.dob AS dob_relative, hxfi.condition, hxfi.age_noted, hxfi.age_of_death, hxfi.is_cause_of_death FROM clin_hx_family chxf, hx_family_item hxfi, dem.identity di, dem.names dn WHERE ((((hxfi.pk = chxf.fk_hx_family_item) AND (hxfi.fk_narrative_condition IS NULL)) AND (hxfi.fk_relative = di.pk)) AND (hxfi.fk_relative = dn.id_identity))) UNION SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chxf.fk_encounter)) AS pk_patient, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = chxf.fk_episode)) AS pk_health_issue, chxf.clin_when, chxf.modified_when, chxf.modified_by, chxf.fk_encounter AS pk_encounter, chxf.fk_episode AS pk_episode, chxf.narrative AS relationship, chxf.soap_cat, chxf.pk AS pk_clin_hx_family, chxf.fk_hx_family_item AS pk_hx_family_item, hxfi.fk_narrative_condition AS pk_narrative_condition, hxfi.fk_relative AS pk_relative_identity, ((dn.firstnames || ' '::text) || dn.lastnames) AS name_relative, di.dob AS dob_relative, (SELECT clin_narrative.narrative FROM clin_narrative WHERE (clin_narrative.pk = hxfi.fk_narrative_condition)) AS condition, hxfi.age_noted, hxfi.age_of_death, hxfi.is_cause_of_death FROM clin_hx_family chxf, hx_family_item hxfi, dem.identity di, dem.names dn WHERE ((((hxfi.pk = chxf.fk_hx_family_item) AND (hxfi.fk_relative IS NULL)) AND (hxfi.fk_relative = di.pk)) AND (hxfi.fk_relative = dn.id_identity)); ALTER TABLE clin.v_hx_family OWNER TO "gm-dbo"; -- -- Name: VIEW v_hx_family; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_hx_family IS 'family history denormalized'; -- -- Name: v_hx_family_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_hx_family_journal AS SELECT vhxf.pk_patient, vhxf.modified_when, vhxf.clin_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = vhxf.modified_by)), (('<'::text || (vhxf.modified_by)::text) || '>'::text)) AS modified_by, vhxf.soap_cat, (((((((((public._('Family Hx'::text) || ': '::text) || public._(vhxf.relationship)) || ' '::text) || vhxf.name_relative) || ' @ '::text) || vhxf.age_noted) || ': '::text) || vhxf.condition) || ';'::text) AS narrative, vhxf.pk_encounter, vhxf.pk_episode, vhxf.pk_health_issue, vhxf.pk_hx_family_item AS src_pk, 'clin.hx_family_item'::text AS src_table FROM v_hx_family vhxf; ALTER TABLE clin.v_hx_family_journal OWNER TO "gm-dbo"; -- -- Name: v_meta_test_types; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_meta_test_types AS SELECT ttm.pk AS pk_meta_test_type, ltt2mt.fk_test_type AS pk_test_type, ttm.abbrev AS abbrev_meta, ttm.name AS name_meta, ttm.loinc AS loinc_meta, ttm.comment AS comment_meta, ltt2mt.pk AS pk_lnk_ttype2meta_type, ttm.xmin AS xmin_meta_test_type FROM meta_test_type ttm, lnk_ttype2unified_type ltt2mt WHERE (ltt2mt.fk_test_type_unified = ttm.pk); ALTER TABLE clin.v_meta_test_types OWNER TO "gm-dbo"; -- -- Name: VIEW v_meta_test_types; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_meta_test_types IS 'denormalized view of meta_test_type + link table to test_type, shows all meta test types to which a test type is linked'; -- -- Name: v_pat_allergies_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_allergies_journal AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = a.fk_encounter)) AS pk_patient, a.modified_when, a.clin_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.soap_cat, ((((((((((((public._('Allergy'::text) || ' ('::text) || public._(at.value)) || '): '::text) || COALESCE(a.narrative, ''::text)) || ' '::text) || public._('substance'::text)) || ': '::text) || a.substance) || '; '::text) || COALESCE((((public._('allergene'::text) || ': '::text) || a.allergene) || '; '::text), ''::text)) || COALESCE((((public._('generic'::text) || ': '::text) || a.generics) || '; '::text), ''::text)) || COALESCE((((public._('ATC code'::text) || ': '::text) || a.atc_code) || '; '::text), ''::text)) AS narrative, a.fk_encounter AS pk_encounter, a.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = a.fk_episode)) AS pk_health_issue, a.pk AS src_pk, 'clin.allergy'::text AS src_table FROM allergy a, _enum_allergy_type at WHERE (at.pk = a.fk_type); ALTER TABLE clin.v_pat_allergies_journal OWNER TO "gm-dbo"; -- -- Name: v_pat_allergy_state_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_allergy_state_journal AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = a.fk_encounter)) AS pk_patient, a.modified_when, a.last_confirmed AS clin_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, 'o'::text AS soap_cat, ((((public._('Allergy state'::text) || ': '::text) || CASE WHEN (a.has_allergy IS NULL) THEN public._('unknown, unasked'::text) WHEN (a.has_allergy = 0) THEN public._('no known allergies'::text) WHEN (a.has_allergy = 1) THEN public._('does have allergies'::text) ELSE NULL::text END) || COALESCE((((' ('::text || public._('last confirmed'::text)) || to_char(a.last_confirmed, ' YYYY-MM-DD HH24:MI'::text)) || ')'::text), ''::text)) || COALESCE((' '::text || a.comment), ''::text)) AS narrative, a.fk_encounter, NULL::integer AS fk_episode, NULL::integer AS pk_health_issue, a.pk AS src_pk, 'clin.allergy_state'::text AS src_table, a.row_version FROM allergy_state a; ALTER TABLE clin.v_pat_allergy_state_journal OWNER TO "gm-dbo"; -- -- Name: v_pat_encounters_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_encounters_journal AS SELECT cenc.fk_patient AS pk_patient, cenc.modified_when, cenc.started AS clin_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = cenc.modified_by)), (('<'::text || (cenc.modified_by)::text) || '>'::text)) AS modified_by, NULL::text AS soap_cat, (((((public._('Encounter: '::text) || (SELECT public._(encounter_type.description) AS _ FROM encounter_type WHERE (encounter_type.pk = cenc.fk_type))) || to_char(cenc.started, ' YYYY-MM-DD HH24:MI'::text)) || to_char(cenc.last_affirmed, ' - HH24:MI'::text)) || COALESCE((((' '::text || public._('RFE'::text)) || ': '::text) || cenc.reason_for_encounter), ''::text)) || COALESCE((((' '::text || public._('AOE'::text)) || ': '::text) || cenc.assessment_of_encounter), ''::text)) AS narrative, cenc.pk AS pk_encounter, (-1) AS pk_episode, (-1) AS pk_health_issue, cenc.pk AS src_pk, 'clin.encounter'::text AS src_table FROM encounter cenc; ALTER TABLE clin.v_pat_encounters_journal OWNER TO "gm-dbo"; -- -- Name: v_pat_episodes_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_episodes_journal AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cep.fk_encounter)) AS pk_patient, cep.modified_when, cep.modified_when AS clin_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = cep.modified_by)), (('<'::text || (cep.modified_by)::text) || '>'::text)) AS modified_by, 'a'::text AS soap_cat, ((((((public._('Episode'::text) || COALESCE(((' ('::text || cep.diagnostic_certainty_classification) || ')'::text), ''::text)) || ': '::text) || cep.description) || ' ('::text) || CASE WHEN cep.is_open THEN public._('open'::text) ELSE public._('closed'::text) END) || ')'::text) AS narrative, cep.fk_encounter AS pk_encounter, cep.pk AS pk_episode, cep.fk_health_issue AS pk_health_issue, cep.pk AS src_pk, 'clin.episode'::text AS src_table, cep.row_version FROM episode cep; ALTER TABLE clin.v_pat_episodes_journal OWNER TO "gm-dbo"; -- -- Name: v_pat_hospital_stays_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_hospital_stays_journal AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chs.fk_encounter)) AS pk_patient, chs.modified_when, chs.clin_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = chs.modified_by)), (('<'::text || (chs.modified_by)::text) || '>'::text)) AS modified_by, chs.soap_cat, (((((public._('hospital stay'::text) || ': '::text) || to_char(chs.clin_when, 'YYYY-MM-DD'::text)) || ' - '::text) || COALESCE(to_char(chs.discharge, 'YYYY-MM-DD'::text), '?'::text)) || COALESCE(((' "'::text || chs.narrative) || '"'::text), ''::text)) AS narrative, chs.fk_encounter AS pk_encounter, chs.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = chs.fk_episode)) AS pk_health_issue, chs.pk AS src_pk, 'clin.hospital_stay'::text AS src_table, chs.row_version FROM hospital_stay chs; ALTER TABLE clin.v_pat_hospital_stays_journal OWNER TO "gm-dbo"; -- -- Name: v_pat_narrative_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_narrative_journal AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cn.fk_encounter)) AS pk_patient, cn.modified_when, cn.clin_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = cn.modified_by)), (('<'::text || (cn.modified_by)::text) || '>'::text)) AS modified_by, cn.soap_cat, cn.narrative, cn.fk_encounter AS pk_encounter, cn.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = cn.fk_episode)) AS pk_health_issue, cn.pk AS src_pk, 'clin.clin_narrative'::text AS src_table FROM clin_narrative cn; ALTER TABLE clin.v_pat_narrative_journal OWNER TO "gm-dbo"; -- -- Name: v_pat_procedures_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_procedures_journal AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cpr.fk_encounter)) AS pk_patient, cpr.modified_when, cpr.clin_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = cpr.modified_by)), (('<'::text || (cpr.modified_by)::text) || '>'::text)) AS modified_by, cpr.soap_cat, (((((public._('Procedure'::text) || ' "'::text) || cpr.narrative) || '" ('::text) || COALESCE((SELECT chs.narrative FROM hospital_stay chs WHERE (cpr.fk_hospital_stay = chs.pk)), cpr.clin_where)) || ')'::text) AS narrative, cpr.fk_encounter AS pk_encounter, cpr.pk AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = cpr.fk_episode)) AS pk_health_issue, cpr.pk AS src_pk, 'clin.procedure'::text AS src_table, cpr.row_version FROM procedure cpr; ALTER TABLE clin.v_pat_procedures_journal OWNER TO "gm-dbo"; SET search_path = ref, pg_catalog; -- -- Name: branded_drug; Type: TABLE; Schema: ref; Owner: gm-dbo; Tablespace: -- CREATE TABLE branded_drug ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, description text NOT NULL, preparation text NOT NULL, atc_code text, is_fake boolean DEFAULT false NOT NULL, fk_data_source integer, external_code text, external_code_type text, CONSTRAINT desc_not_empty CHECK ((gm.is_null_or_blank_string(description) IS FALSE)), CONSTRAINT drug_sane_external_code CHECK ((gm.is_null_or_non_empty_string(external_code) IS TRUE)), CONSTRAINT drug_sane_external_code_type CHECK ((((external_code IS NULL) AND (external_code_type IS NULL)) OR ((external_code IS NOT NULL) AND (external_code_type IS NOT NULL)))), CONSTRAINT prep_not_empty CHECK ((gm.is_null_or_blank_string(preparation) IS FALSE)), CONSTRAINT sane_atc CHECK ((gm.is_null_or_non_empty_string(atc_code) IS TRUE)) ) INHERITS (audit.audit_fields); ALTER TABLE ref.branded_drug OWNER TO "gm-dbo"; -- -- Name: TABLE branded_drug; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON TABLE branded_drug IS 'The medicine chest of this praxis. Stores brands of drugs patients have been taking regardless of whether that brand still exists or in fact ever existed as such (as in lifestyle thingies).'; -- -- Name: COLUMN branded_drug.description; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON COLUMN branded_drug.description IS 'the name of this drug it is marketed under by the manufacturer'; -- -- Name: COLUMN branded_drug.preparation; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON COLUMN branded_drug.preparation IS 'the preparation the drug is delivered in, eg liquid, cream, tablet, etc.'; -- -- Name: COLUMN branded_drug.atc_code; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON COLUMN branded_drug.atc_code IS 'the Anatomic Therapeutic Chemical code for this drug, used to compute possible substitutes'; -- -- Name: COLUMN branded_drug.is_fake; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON COLUMN branded_drug.is_fake IS 'Whether this truly is an actual brand of an actual drug rather than a fake brand created for documenting a, say, lifestyle nutrient or simply a component as opposed to a particular actual brand.'; -- -- Name: COLUMN branded_drug.fk_data_source; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON COLUMN branded_drug.fk_data_source IS 'the data source this entry came from'; -- -- Name: COLUMN branded_drug.external_code; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON COLUMN branded_drug.external_code IS 'an opaque code from an external data source, such as "PZN" in Germany'; -- -- Name: COLUMN branded_drug.external_code_type; Type: COMMENT; Schema: ref; Owner: gm-dbo -- COMMENT ON COLUMN branded_drug.external_code_type IS 'an opaque code type from an external data source, such as "PZN" in Germany'; SET search_path = clin, pg_catalog; -- -- Name: v_pat_substance_intake_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_substance_intake_journal AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = csi.fk_encounter)) AS pk_patient, csi.modified_when, csi.clin_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = csi.modified_by)), (('<'::text || (csi.modified_by)::text) || '>'::text)) AS modified_by, csi.soap_cat, ((((((((((((((((((CASE WHEN (csi.is_long_term IS TRUE) THEN (public._('long-term'::text) || ' '::text) ELSE ''::text END || public._('substance intake'::text)) || ' '::text) || CASE WHEN (csi.intake_is_approved_of IS TRUE) THEN public._('(approved of)'::text) WHEN (csi.intake_is_approved_of IS FALSE) THEN public._('(not approved of)'::text) ELSE public._('(of unknown approval)'::text) END) || ': '::text) || ' '::text) || ccs.description) || COALESCE(((' ['::text || ccs.atc_code) || '] '::text), ' '::text)) || csi.strength) || ' '::text) || csi.preparation) || COALESCE((' '::text || csi.schedule), ''::text)) || ', '::text) || to_char(csi.clin_when, 'YYYY-MM-DD'::text)) || COALESCE((' -> '::text || csi.duration), ''::text)) || ' '::text) || COALESCE(((((' '::text || public._('discontinued'::text)) || to_char(csi.discontinued, ': YYYY-MM-DD'::text)) || COALESCE((('('::text || csi.discontinue_reason) || ')'::text), ''::text)) || ' '::text), ''::text)) || COALESCE(NULLIF(((COALESCE((' '::text || csi.aim), ''::text) || COALESCE(((' ('::text || csi.narrative) || ')'::text), ''::text)) || ' '::text), ' '::text), ''::text)) || COALESCE(((((((' "'::text || rbd.description) || ' '::text) || rbd.preparation) || '"'::text) || COALESCE(((' ['::text || rbd.atc_code) || ']'::text), ''::text)) || COALESCE(((((' ('::text || rbd.external_code_type) || ': '::text) || rbd.external_code) || ')'::text), ''::text)), ''::text)) AS narrative, csi.fk_encounter AS pk_encounter, csi.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = csi.fk_episode)) AS pk_health_issue, csi.pk AS src_pk, 'clin.substance_intake'::text AS src_table, csi.row_version FROM ((substance_intake csi LEFT JOIN ref.branded_drug rbd ON ((csi.fk_brand = rbd.pk))) LEFT JOIN consumed_substance ccs ON ((csi.fk_substance = ccs.pk))); ALTER TABLE clin.v_pat_substance_intake_journal OWNER TO "gm-dbo"; -- -- Name: v_unified_test_types; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_unified_test_types AS SELECT ctt.pk AS pk_test_type, COALESCE(vmtt.abbrev_meta, ctt.abbrev) AS unified_abbrev, COALESCE(vmtt.name_meta, ctt.name) AS unified_name, COALESCE(vmtt.loinc_meta, ctt.loinc) AS unified_loinc, ctt.abbrev AS abbrev_tt, ctt.name AS name_tt, ctt.loinc AS loinc_tt, ctt.comment AS comment_tt, ctt.code AS code_tt, ctt.coding_system AS coding_system_tt, ctt.conversion_unit, vmtt.abbrev_meta, vmtt.name_meta, vmtt.loinc_meta, vmtt.comment_meta, ctt.fk_test_org AS pk_test_org, vmtt.pk_meta_test_type, vmtt.pk_lnk_ttype2meta_type, (vmtt.pk_meta_test_type IS NULL) AS is_fake_unified_type FROM (test_type ctt LEFT JOIN v_meta_test_types vmtt ON ((ctt.pk = vmtt.pk_test_type))); ALTER TABLE clin.v_unified_test_types OWNER TO "gm-dbo"; -- -- Name: VIEW v_unified_test_types; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_unified_test_types IS 'provides a "unified" view of test types aggregated under their corresponding unified name if any; if not linked to a meta test type the original name is used'; -- -- Name: v_test_results; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_test_results AS SELECT cenc.fk_patient AS pk_patient, tr.pk AS pk_test_result, tr.clin_when, vutt.unified_abbrev, vutt.unified_name, vutt.unified_loinc, CASE WHEN (COALESCE(btrim(tr.val_alpha), ''::text) = ''::text) THEN (tr.val_num)::text ELSE CASE WHEN (tr.val_num IS NULL) THEN tr.val_alpha ELSE ((((tr.val_num)::text || ' ('::text) || tr.val_alpha) || ')'::text) END END AS unified_val, COALESCE(tr.val_target_min, tr.val_normal_min) AS unified_target_min, COALESCE(tr.val_target_max, tr.val_normal_max) AS unified_target_max, COALESCE(tr.val_target_range, tr.val_normal_range) AS unified_target_range, tr.soap_cat, tr.narrative AS comment, tr.val_num, tr.val_alpha, tr.val_unit, vutt.conversion_unit, tr.val_normal_min, tr.val_normal_max, tr.val_normal_range, tr.val_target_min, tr.val_target_max, tr.val_target_range, tr.abnormality_indicator, tr.norm_ref_group, tr.note_test_org, tr.material, tr.material_detail, vutt.abbrev_tt, vutt.name_tt, vutt.loinc_tt, vutt.code_tt, vutt.coding_system_tt, vutt.comment_tt, cto.internal_name AS name_test_org, cto.contact AS contact_test_org, vutt.abbrev_meta, vutt.name_meta, vutt.loinc_meta, vutt.comment_meta, epi.description AS episode, chi.description AS health_issue, (COALESCE(rtr.fk_reviewed_row, 0))::boolean AS reviewed, rtr.is_technically_abnormal, rtr.clinically_relevant AS is_clinically_relevant, rtr.comment AS review_comment, (SELECT staff.short_alias FROM dem.staff WHERE (staff.pk = rtr.fk_reviewer)) AS last_reviewer, rtr.modified_when AS last_reviewed, COALESCE((rtr.fk_reviewer = (SELECT staff.pk FROM dem.staff WHERE (staff.db_user = "current_user"()))), false) AS review_by_you, COALESCE((tr.fk_intended_reviewer = rtr.fk_reviewer), false) AS review_by_responsible_reviewer, (SELECT staff.short_alias FROM dem.staff WHERE (staff.pk = tr.fk_intended_reviewer)) AS responsible_reviewer, COALESCE((tr.fk_intended_reviewer = (SELECT staff.pk FROM dem.staff WHERE (staff.db_user = "current_user"()))), false) AS you_are_responsible, CASE WHEN ((SELECT 1 FROM dem.staff WHERE (staff.db_user = tr.modified_by)) IS NULL) THEN (('<'::text || (tr.modified_by)::text) || '>'::text) ELSE (SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = tr.modified_by)) END AS modified_by, tr.modified_when, tr.row_version, tr.pk_item, tr.fk_encounter AS pk_encounter, tr.fk_episode AS pk_episode, tr.fk_type AS pk_test_type, tr.fk_intended_reviewer AS pk_intended_reviewer, tr.xmin AS xmin_test_result, vutt.pk_test_org, vutt.pk_meta_test_type, epi.fk_health_issue AS pk_health_issue, rtr.fk_reviewer AS pk_last_reviewer FROM ((((test_result tr LEFT JOIN encounter cenc ON ((tr.fk_encounter = cenc.pk))) LEFT JOIN episode epi ON ((tr.fk_episode = epi.pk))) LEFT JOIN reviewed_test_results rtr ON ((tr.pk = rtr.fk_reviewed_row))) LEFT JOIN health_issue chi ON ((epi.fk_health_issue = chi.pk))), (v_unified_test_types vutt LEFT JOIN test_org cto ON ((vutt.pk_test_org = cto.pk))) WHERE (tr.fk_type = vutt.pk_test_type); ALTER TABLE clin.v_test_results OWNER TO "gm-dbo"; -- -- Name: VIEW v_test_results; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_test_results IS 'denormalized view over test_results joined with (possibly unified) test type and patient/episode/encounter keys'; -- -- Name: v_test_results_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_test_results_journal AS SELECT vtr.pk_patient, vtr.modified_when, vtr.clin_when, vtr.modified_by, vtr.soap_cat, COALESCE(((((((((((((((((((((((((((((vtr.unified_name || ' ('::text) || vtr.unified_abbrev) || COALESCE(((' [#'::text || vtr.unified_loinc) || ']'::text), ''::text)) || '): '::text) || vtr.unified_val) || ' '::text) || COALESCE(vtr.val_unit, ''::text)) || ' '::text) || COALESCE((('('::text || vtr.abnormality_indicator) || ')'::text), ''::text)) || ' '::text) || public._('Range: '::text)) || COALESCE((vtr.unified_target_min)::text, ''::text)) || ' - '::text) || COALESCE((vtr.unified_target_max)::text, ''::text)) || ' / '::text) || COALESCE(vtr.unified_target_range, ''::text)) || COALESCE(((' ('::text || vtr.norm_ref_group) || ')'::text), ''::text)) || ' '::text) || COALESCE(((public._('Assessment: '::text) || vtr.comment) || ' '::text), ''::text)) || COALESCE(((public._('Context: '::text) || vtr.note_test_org) || ' '::text), ''::text)) || COALESCE((((((((public._('Review by '::text) || vtr.last_reviewer) || ' @ '::text) || to_char(vtr.last_reviewed, 'YYYY-MM-DD HH24:MI'::text)) || ': '::text) || CASE WHEN vtr.is_technically_abnormal THEN (public._('abnormal'::text) || ', '::text) ELSE ''::text END) || CASE WHEN vtr.is_clinically_relevant THEN (public._('relevant'::text) || ' '::text) ELSE ''::text END) || COALESCE((('('::text || vtr.review_comment) || ') '::text), ' '::text)), ''::text)) || public._('Responsible clinician: '::text)) || vtr.responsible_reviewer) || ' '::text) || public._('Episode "'::text)) || vtr.episode) || '"'::text) || COALESCE(((public._(' in health issue "'::text) || vtr.health_issue) || '"'::text), ''::text)), 'faulty clin.v_test_results_journal definition'::text) AS narrative, vtr.pk_encounter, vtr.pk_episode, vtr.pk_health_issue, vtr.pk_test_result AS src_pk, 'clin.test_result'::text AS src_table, vtr.row_version FROM v_test_results vtr; ALTER TABLE clin.v_test_results_journal OWNER TO "gm-dbo"; -- -- Name: VIEW v_test_results_journal; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_test_results_journal IS 'formatting of v_test_results for inclusion in v_emr_journal'; -- -- Name: v_emr_journal; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_emr_journal AS ((((((((((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, 0 AS row_version FROM 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 FROM 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, 0 AS row_version FROM 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 FROM v_pat_episodes_journal) UNION ALL SELECT v_hx_family_journal.pk_patient, v_hx_family_journal.modified_when, v_hx_family_journal.clin_when, v_hx_family_journal.modified_by, v_hx_family_journal.soap_cat, v_hx_family_journal.narrative, v_hx_family_journal.pk_encounter, v_hx_family_journal.pk_episode, v_hx_family_journal.pk_health_issue, v_hx_family_journal.src_pk, v_hx_family_journal.src_table, 0 AS row_version FROM v_hx_family_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, 0 AS row_version FROM 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.fk_encounter AS pk_encounter, v_pat_allergy_state_journal.fk_episode AS 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 FROM 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 FROM v_test_results_journal) UNION ALL SELECT v_pat_hospital_stays_journal.pk_patient, v_pat_hospital_stays_journal.modified_when, v_pat_hospital_stays_journal.clin_when, v_pat_hospital_stays_journal.modified_by, v_pat_hospital_stays_journal.soap_cat, v_pat_hospital_stays_journal.narrative, v_pat_hospital_stays_journal.pk_encounter, v_pat_hospital_stays_journal.pk_episode, v_pat_hospital_stays_journal.pk_health_issue, v_pat_hospital_stays_journal.src_pk, v_pat_hospital_stays_journal.src_table, v_pat_hospital_stays_journal.row_version FROM v_pat_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, 0 AS row_version FROM blobs.v_doc_med_journal) UNION ALL SELECT v_pat_substance_intake_journal.pk_patient, v_pat_substance_intake_journal.modified_when, v_pat_substance_intake_journal.clin_when, v_pat_substance_intake_journal.modified_by, v_pat_substance_intake_journal.soap_cat, v_pat_substance_intake_journal.narrative, v_pat_substance_intake_journal.pk_encounter, v_pat_substance_intake_journal.pk_episode, v_pat_substance_intake_journal.pk_health_issue, v_pat_substance_intake_journal.src_pk, v_pat_substance_intake_journal.src_table, v_pat_substance_intake_journal.row_version FROM v_pat_substance_intake_journal) UNION ALL SELECT v_pat_procedures_journal.pk_patient, v_pat_procedures_journal.modified_when, v_pat_procedures_journal.clin_when, v_pat_procedures_journal.modified_by, v_pat_procedures_journal.soap_cat, v_pat_procedures_journal.narrative, v_pat_procedures_journal.pk_encounter, v_pat_procedures_journal.pk_episode, v_pat_procedures_journal.pk_health_issue, v_pat_procedures_journal.src_pk, v_pat_procedures_journal.src_table, v_pat_procedures_journal.row_version FROM v_pat_procedures_journal; ALTER TABLE clin.v_emr_journal OWNER TO "gm-dbo"; -- -- Name: VIEW v_emr_journal; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_emr_journal IS '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.'; -- -- Name: v_health_issues; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_health_issues AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chi.fk_encounter)) AS pk_patient, chi.pk AS pk_health_issue, chi.description, chi.laterality, chi.age_noted, chi.is_active, chi.clinically_relevant, chi.is_confidential, chi.is_cause_of_death, chi.fk_encounter AS pk_encounter, chi.modified_when, chi.modified_by, chi.row_version, chi.grouping, chi.diagnostic_certainty_classification, chi.xmin AS xmin_health_issue FROM health_issue chi; ALTER TABLE clin.v_health_issues OWNER TO "gm-dbo"; -- -- Name: vacc_indication; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE vacc_indication ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), id integer NOT NULL, description text NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.vacc_indication OWNER TO "gm-dbo"; -- -- Name: TABLE vacc_indication; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE vacc_indication IS 'definition of indications for vaccinations'; -- -- Name: COLUMN vacc_indication.description; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vacc_indication.description IS 'description of indication, eg "Measles", note that this does not have to be a scientific diagnosis, it is simply intended to be an agreed-upon, medically-comprehensible unique identifier for the indication'; -- -- Name: vaccine; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE vaccine ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, id_route integer DEFAULT 1 NOT NULL, trade_name text NOT NULL, short_name text NOT NULL, is_live boolean DEFAULT false NOT NULL, min_age interval NOT NULL, max_age interval DEFAULT '5555 years'::interval NOT NULL, comment text, CONSTRAINT vaccine_check CHECK ((((max_age >= min_age) AND (max_age <= '150 years'::interval)) OR (max_age = '5555 years'::interval))), CONSTRAINT vaccine_min_age_check CHECK (((min_age >= '00:00:01'::interval) AND (min_age <= '150 years'::interval))) ) INHERITS (audit.audit_fields); ALTER TABLE clin.vaccine OWNER TO "gm-dbo"; -- -- Name: TABLE vaccine; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE vaccine IS 'definition of a vaccine as available on the market'; -- -- Name: COLUMN vaccine.id_route; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccine.id_route IS 'route this vaccine is given'; -- -- Name: COLUMN vaccine.trade_name; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccine.trade_name IS 'full name the vaccine is traded under'; -- -- Name: COLUMN vaccine.short_name; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccine.short_name IS 'common, maybe practice-specific shorthand name for referring to this vaccine'; -- -- Name: COLUMN vaccine.is_live; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccine.is_live IS 'whether this is a live vaccine'; -- -- Name: COLUMN vaccine.min_age; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccine.min_age IS 'minimum age this vaccine is licensed for according to the information by the manufacturer'; -- -- Name: COLUMN vaccine.max_age; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccine.max_age IS 'maximum age this vaccine is licensed for according to the information by the manufacturer, use "5555 years" to indicate "no maximum age"'; -- -- Name: v_indications4vaccine; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_indications4vaccine AS SELECT v.trade_name, v.short_name, i.description AS indication, public._(i.description) AS l10n_indication, v.is_live, v.min_age, v.max_age, v.comment, v.pk AS pk_vaccine, v.id_route AS pk_route, i.id AS pk_vacc_indication FROM vaccine v, vacc_indication i, lnk_vaccine2inds lv2i WHERE ((v.pk = lv2i.fk_vaccine) AND (i.id = lv2i.fk_indication)); ALTER TABLE clin.v_indications4vaccine OWNER TO "gm-dbo"; -- -- Name: VIEW v_indications4vaccine; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_indications4vaccine IS 'lists indications for vaccines'; -- -- Name: v_keyword_expansions; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_keyword_expansions AS SELECT cke.pk AS pk_keyword_expansion, cke.fk_staff AS pk_staff, cke.keyword, cke.expansion, (cke.fk_staff IS NULL) AS public_expansion, (cke.fk_staff IS NOT NULL) AS private_expansion, cke.owner FROM keyword_expansion cke; ALTER TABLE clin.v_keyword_expansions OWNER TO "gm-dbo"; -- -- Name: VIEW v_keyword_expansions; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_keyword_expansions IS 'Just a slightly more convenient view over expansions.'; -- -- Name: v_most_recent_encounters; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_most_recent_encounters AS SELECT ce1.pk AS pk_encounter, ce1.fk_patient AS pk_patient, ce1.reason_for_encounter, ce1.assessment_of_encounter, et.description AS type, public._(et.description) AS l10n_type, ce1.started, ce1.last_affirmed, ce1.fk_type AS pk_type, ce1.fk_location AS pk_location FROM encounter ce1, encounter_type et WHERE ((ce1.fk_type = et.pk) AND (ce1.started = (SELECT max(ce2.started) AS max FROM encounter ce2 WHERE (ce2.last_affirmed = (SELECT max(ce3.last_affirmed) AS max FROM encounter ce3 WHERE (ce3.fk_patient = ce1.fk_patient))) LIMIT 1))); ALTER TABLE clin.v_most_recent_encounters OWNER TO "gm-dbo"; -- -- Name: VIEW v_most_recent_encounters; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_most_recent_encounters IS '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!)'; -- -- Name: v_pat_items; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_items AS 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_root_item cri, encounter cenc, 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)); ALTER TABLE clin.v_pat_items OWNER TO "gm-dbo"; -- -- Name: v_narrative4search; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_narrative4search AS (((((((((((((SELECT vpi.pk_patient, vpi.soap_cat, vpi.narrative, vpi.pk_encounter, vpi.pk_episode, vpi.pk_health_issue, vpi.pk_item AS src_pk, vpi.src_table FROM v_pat_items vpi WHERE ((vpi.src_table <> ALL (ARRAY['allergy'::text, 'test_result'::text, 'procedure'::text, 'substance_intake'::text])) AND (btrim(COALESCE(vpi.narrative, ''::text)) <> ''::text)) UNION ALL SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = csi.fk_encounter)) AS pk_patient, csi.soap_cat, ((COALESCE(csi.narrative, ''::text) || COALESCE((' '::text || csi.schedule), ''::text)) || COALESCE((' '::text || csi.aim), ''::text)) AS narrative, csi.fk_encounter AS pk_encounter, csi.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = csi.fk_episode)) AS pk_health_issue, csi.pk AS src_pk, 'clin.substance_intake' AS src_table FROM substance_intake csi) UNION ALL SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cpr.fk_encounter)) AS pk_patient, cpr.soap_cat, (COALESCE(cpr.narrative, ''::text) || COALESCE((' '::text || cpr.clin_where), ''::text)) AS narrative, cpr.fk_encounter AS pk_encounter, cpr.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = cpr.fk_episode)) AS pk_health_issue, cpr.pk AS src_pk, 'clin.procedure' AS src_table FROM procedure cpr) UNION ALL SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = ctr.fk_encounter)) AS pk_patient, ctr.soap_cat, ((((((((COALESCE(ctr.narrative, ''::text) || COALESCE((' '::text || ctr.val_alpha), ''::text)) || COALESCE((' '::text || ctr.val_unit), ''::text)) || COALESCE((' '::text || ctr.val_normal_range), ''::text)) || COALESCE((' '::text || ctr.val_target_range), ''::text)) || COALESCE((' '::text || ctr.norm_ref_group), ''::text)) || COALESCE((' '::text || ctr.note_test_org), ''::text)) || COALESCE((' '::text || ctr.material), ''::text)) || COALESCE((' '::text || ctr.material_detail), ''::text)) AS narrative, ctr.fk_encounter AS pk_encounter, ctr.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = ctr.fk_episode)) AS pk_health_issue, ctr.pk AS src_pk, 'clin.test_result' AS src_table FROM test_result ctr) UNION ALL SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = (SELECT test_result.fk_encounter FROM test_result WHERE (test_result.pk = crtr.fk_reviewed_row)))) AS pk_patient, 'o'::text AS soap_cat, crtr.comment AS narrative, (SELECT test_result.fk_encounter FROM test_result WHERE (test_result.pk = crtr.fk_reviewed_row)) AS pk_encounter, (SELECT test_result.fk_episode FROM test_result WHERE (test_result.pk = crtr.fk_reviewed_row)) AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = (SELECT test_result.fk_episode FROM test_result WHERE (test_result.pk = crtr.fk_reviewed_row)))) AS pk_health_issue, crtr.pk AS src_pk, 'clin.reviewed_test_results' AS src_table FROM reviewed_test_results crtr WHERE (btrim(COALESCE(crtr.comment, ''::text)) <> ''::text)) UNION ALL SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cas.fk_encounter)) AS pk_patient, 'o'::text AS soap_cat, cas.comment AS narrative, cas.fk_encounter AS pk_encounter, NULL::unknown AS pk_episode, NULL::unknown AS pk_health_issue, cas.pk AS src_pk, 'clin.allergy_state' AS src_table FROM allergy_state cas WHERE (btrim(COALESCE(cas.comment, ''::text)) <> ''::text)) UNION ALL SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = ca.fk_encounter)) AS pk_patient, ca.soap_cat, (((((COALESCE(ca.narrative, ''::text) || COALESCE((' '::text || ca.substance), ''::text)) || COALESCE((' '::text || ca.substance_code), ''::text)) || COALESCE((' '::text || ca.generics), ''::text)) || COALESCE((' '::text || ca.allergene), ''::text)) || COALESCE((' '::text || ca.atc_code), ''::text)) AS narrative, ca.fk_encounter AS pk_encounter, ca.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = ca.fk_episode)) AS pk_health_issue, ca.pk AS src_pk, 'clin.allergy' AS src_table FROM allergy ca) UNION ALL SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chi.fk_encounter)) AS pk_patient, 'a' AS soap_cat, chi.description AS narrative, chi.fk_encounter AS pk_encounter, NULL::unknown AS pk_episode, chi.pk AS pk_health_issue, chi.pk AS src_pk, 'clin.health_issue' AS src_table FROM health_issue chi WHERE (btrim(COALESCE(chi.description, ''::text)) <> ''::text)) UNION ALL SELECT cenc.fk_patient AS pk_patient, 's' AS soap_cat, (COALESCE(cenc.reason_for_encounter, ''::text) || COALESCE((' '::text || cenc.assessment_of_encounter), ''::text)) AS narrative, cenc.pk AS pk_encounter, NULL::unknown AS pk_episode, NULL::unknown AS pk_health_issue, cenc.pk AS src_pk, 'clin.encounter' AS src_table FROM encounter cenc WHERE ((btrim(COALESCE(cenc.reason_for_encounter, ''::text)) <> ''::text) OR (btrim(COALESCE(cenc.assessment_of_encounter, ''::text)) <> ''::text))) UNION ALL SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cep.fk_encounter)) AS pk_patient, 's' AS soap_cat, cep.description AS narrative, cep.fk_encounter AS pk_encounter, cep.pk AS pk_episode, cep.fk_health_issue AS pk_health_issue, cep.pk AS src_pk, 'clin.episode' AS src_table FROM episode cep WHERE (btrim(COALESCE(cep.description, ''::text)) <> ''::text)) UNION ALL SELECT vhxf.pk_patient, vhxf.soap_cat, ((((((public._(vhxf.relationship) || ' ('::text) || vhxf.relationship) || ') '::text) || vhxf.name_relative) || ': '::text) || vhxf.condition) AS narrative, vhxf.pk_encounter, vhxf.pk_episode, vhxf.pk_health_issue, vhxf.pk_hx_family_item AS src_pk, 'clin.hx_family_item' AS src_table FROM v_hx_family vhxf) UNION ALL SELECT vdm.pk_patient, 'o' AS soap_cat, ((((vdm.l10n_type || ' '::text) || COALESCE(vdm.ext_ref, ''::text)) || ' '::text) || COALESCE(vdm.comment, ''::text)) AS narrative, vdm.pk_encounter, vdm.pk_episode, vdm.pk_health_issue, vdm.pk_doc AS src_pk, 'blobs.doc_med' AS src_table FROM blobs.v_doc_med vdm) UNION ALL SELECT vo4d.pk_patient, 'o' AS soap_cat, vo4d.obj_comment AS narrative, vo4d.pk_encounter, vo4d.pk_episode, vo4d.pk_health_issue, vo4d.pk_obj AS src_pk, 'blobs.doc_obj' AS src_table FROM blobs.v_obj4doc_no_data vo4d WHERE (btrim(COALESCE(vo4d.obj_comment, ''::text)) <> ''::text)) UNION ALL SELECT vdd.pk_patient, 'o' AS soap_cat, vdd.description AS narrative, vdd.pk_encounter, vdd.pk_episode, vdd.pk_health_issue, vdd.pk_doc_desc AS src_pk, 'blobs.doc_desc' AS src_table FROM blobs.v_doc_desc vdd WHERE (btrim(COALESCE(vdd.description, ''::text)) <> ''::text)) UNION ALL SELECT vrdo.pk_patient, 's' AS soap_cat, vrdo.comment AS narrative, NULL::unknown AS pk_encounter, vrdo.pk_episode, vrdo.pk_health_issue, vrdo.pk_review_root AS src_pk, 'blobs.v_reviewed_doc_objects' AS src_table FROM blobs.v_reviewed_doc_objects vrdo WHERE (btrim(COALESCE(vrdo.comment, ''::text)) <> ''::text); ALTER TABLE clin.v_narrative4search OWNER TO "gm-dbo"; -- -- Name: VIEW v_narrative4search; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_narrative4search IS 'unformatted *complete* narrative for patients including health issue/episode/encounter descriptions, mainly for searching the narrative in context'; -- -- Name: v_pat_allergies; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_allergies AS SELECT a.pk AS pk_allergy, (SELECT encounter.fk_patient FROM 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, public._(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 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 allergy a, _enum_allergy_type at WHERE (at.pk = a.fk_type); ALTER TABLE clin.v_pat_allergies OWNER TO "gm-dbo"; -- -- Name: VIEW v_pat_allergies; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_pat_allergies IS 'denormalizes clin.allergy'; -- -- Name: v_pat_allergy_state; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_allergy_state AS SELECT (SELECT encounter.fk_patient FROM 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 allergy_state a; ALTER TABLE clin.v_pat_allergy_state OWNER TO "gm-dbo"; -- -- Name: v_pat_encounters; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_encounters AS SELECT cle.pk AS pk_encounter, cle.fk_patient AS pk_patient, cle.started, et.description AS type, public._(et.description) AS l10n_type, cle.reason_for_encounter, cle.assessment_of_encounter, cle.last_affirmed, cle.source_time_zone, (SELECT timezone((SELECT cle1.source_time_zone FROM encounter cle1 WHERE (cle1.pk = cle.pk)), cle.started) AS timezone) AS started_original_tz, (SELECT timezone((SELECT cle1.source_time_zone FROM encounter cle1 WHERE (cle1.pk = cle.pk)), cle.last_affirmed) AS timezone) AS last_affirmed_original_tz, cle.fk_location AS pk_location, cle.fk_type AS pk_type, cle.xmin AS xmin_encounter FROM encounter cle, encounter_type et WHERE (cle.fk_type = et.pk); ALTER TABLE clin.v_pat_encounters OWNER TO "gm-dbo"; -- -- Name: VIEW v_pat_encounters; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_pat_encounters IS 'Details on encounters.'; -- -- Name: v_pat_episodes; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_episodes AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cep.fk_encounter)) AS pk_patient, cep.description, cep.is_open AS episode_open, NULL::unknown AS health_issue, NULL::unknown AS issue_active, NULL::unknown AS issue_clinically_relevant, (SELECT min(cle.started) AS min FROM encounter cle WHERE (cle.pk = cep.fk_encounter) LIMIT 1) AS started_first, (SELECT max(cle.started) AS max FROM encounter cle WHERE (cle.pk = cep.fk_encounter) LIMIT 1) AS started_last, (SELECT max(cle.last_affirmed) AS max FROM 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::unknown AS pk_health_issue, cep.modified_when AS episode_modified_when, cep.modified_by AS episode_modified_by, cep.diagnostic_certainty_classification, cep.xmin AS xmin_episode FROM episode cep WHERE (cep.fk_health_issue IS NULL) UNION ALL SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cep.fk_encounter)) AS pk_patient, cep.description, 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 encounter cle WHERE (cle.pk = cep.fk_encounter) LIMIT 1) AS started_first, (SELECT max(cle.started) AS max FROM encounter cle WHERE (cle.pk = cep.fk_encounter) LIMIT 1) AS started_last, (SELECT max(cle.last_affirmed) AS max FROM 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, cep.xmin AS xmin_episode FROM episode cep, health_issue chi WHERE (cep.fk_health_issue = chi.pk); ALTER TABLE clin.v_pat_episodes OWNER TO "gm-dbo"; -- -- Name: v_pat_hospital_stays; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_hospital_stays AS SELECT chs.pk AS pk_hospital_stay, (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chs.fk_encounter)) AS pk_patient, chs.narrative AS hospital, chs.clin_when AS admission, chs.discharge, chs.soap_cat, (SELECT episode.description FROM episode WHERE (episode.pk = chs.fk_episode)) AS episode, (SELECT health_issue.description FROM health_issue WHERE (health_issue.pk = (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = chs.fk_episode)))) AS health_issue, chs.fk_encounter AS pk_encounter, chs.fk_episode AS pk_episode, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = chs.fk_episode)) AS pk_health_issue, chs.modified_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = chs.modified_by)), (('<'::text || (chs.modified_by)::text) || '>'::text)) AS modified_by, chs.row_version, chs.xmin AS xmin_hospital_stay FROM hospital_stay chs; ALTER TABLE clin.v_pat_hospital_stays OWNER TO "gm-dbo"; -- -- Name: v_pat_narrative; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_narrative AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cn.fk_encounter)) AS pk_patient, cn.clin_when AS date, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = cn.modified_by)), (('<'::text || (cn.modified_by)::text) || '>'::text)) AS provider, cn.soap_cat, cn.narrative, cn.pk_item, cn.pk AS pk_narrative, (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = cn.fk_episode)) AS pk_health_issue, cn.fk_episode AS pk_episode, cn.fk_encounter AS pk_encounter, cn.xmin AS xmin_clin_narrative FROM clin_narrative cn; ALTER TABLE clin.v_pat_narrative OWNER TO "gm-dbo"; -- -- Name: VIEW v_pat_narrative; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_pat_narrative IS 'patient narrative aggregated from all clin_root_item child tables; the narrative is unprocessed, denormalized context using v_pat_items is added'; -- -- Name: v_pat_procedures; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_procedures AS SELECT cpr.pk AS pk_procedure, (SELECT enc.fk_patient FROM encounter enc WHERE (enc.pk = cpr.fk_encounter)) AS pk_patient, cpr.soap_cat, cpr.clin_when, cpr.narrative AS performed_procedure, COALESCE((SELECT chs.narrative FROM hospital_stay chs WHERE (cpr.fk_hospital_stay = chs.pk)), cpr.clin_where) AS clin_where, (SELECT episode.description FROM episode WHERE (episode.pk = cpr.fk_episode)) AS episode, (SELECT health_issue.description FROM health_issue WHERE (health_issue.pk = (SELECT episode.fk_health_issue FROM episode WHERE (episode.pk = cpr.fk_episode)))) AS health_issue, cpr.modified_when, COALESCE((SELECT staff.short_alias FROM dem.staff WHERE (staff.db_user = cpr.modified_by)), (('<'::text || (cpr.modified_by)::text) || '>'::text)) AS modified_by, cpr.row_version, cpr.fk_encounter AS pk_encounter, cpr.fk_episode AS pk_episode, cpr.fk_hospital_stay AS pk_hospital_stay, (SELECT epi.fk_health_issue FROM episode epi WHERE (epi.pk = cpr.fk_episode)) AS pk_health_issue, cpr.xmin AS xmin_procedure FROM procedure cpr; ALTER TABLE clin.v_pat_procedures OWNER TO "gm-dbo"; -- -- Name: v_pat_substance_intake; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_pat_substance_intake AS SELECT csi.pk AS pk_substance_intake, (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = csi.fk_encounter)) AS pk_patient, csi.soap_cat, rbd.description AS brand, csi.preparation, rbd.atc_code AS atc_brand, rbd.external_code AS external_code_brand, rbd.external_code_type AS external_code_type_brand, ccs.description AS substance, csi.strength, ccs.atc_code AS atc_substance, csi.clin_when AS started, csi.intake_is_approved_of, csi.schedule, csi.duration, csi.discontinued, csi.discontinue_reason, csi.is_long_term, csi.aim, cep.description AS episode, csi.narrative AS notes, rbd.is_fake AS fake_brand, CASE WHEN (csi.discontinued IS NULL) THEN true ELSE false END AS is_currently_active, CASE WHEN (csi.discontinued IS NOT NULL) THEN true WHEN (csi.clin_when IS NULL) THEN CASE WHEN (csi.is_long_term IS TRUE) THEN false ELSE NULL::boolean END WHEN ((csi.clin_when > now()) IS TRUE) THEN true WHEN (((csi.clin_when + csi.duration) < now()) IS TRUE) THEN true WHEN (((csi.clin_when + csi.duration) > now()) IS TRUE) THEN false ELSE NULL::boolean END AS seems_inactive, csi.fk_brand AS pk_brand, ccs.pk AS pk_substance, csi.fk_encounter AS pk_encounter, csi.fk_episode AS pk_episode, cep.fk_health_issue AS pk_health_issue, csi.modified_when, csi.modified_by, csi.row_version, csi.xmin AS xmin_substance_intake FROM (((substance_intake csi LEFT JOIN ref.branded_drug rbd ON ((csi.fk_brand = rbd.pk))) LEFT JOIN consumed_substance ccs ON ((csi.fk_substance = ccs.pk))) LEFT JOIN episode cep ON ((csi.fk_episode = cep.pk))); ALTER TABLE clin.v_pat_substance_intake OWNER TO "gm-dbo"; -- -- Name: v_potential_problem_list; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_potential_problem_list AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cep.fk_encounter)) AS pk_patient, cep.description AS problem, 'episode' AS type, public._('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 FROM episode cep WHERE (cep.is_open IS FALSE) UNION SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chi.fk_encounter)) AS pk_patient, chi.description AS problem, 'issue' AS type, public._('health issue'::text) AS l10n_type, chi.is_active AS problem_active, false AS clinically_relevant, NULL::unknown AS pk_episode, chi.pk AS pk_health_issue, chi.diagnostic_certainty_classification FROM health_issue chi WHERE (chi.clinically_relevant IS FALSE); ALTER TABLE clin.v_potential_problem_list OWNER TO "gm-dbo"; -- -- Name: v_problem_list; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_problem_list AS SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = cep.fk_encounter)) AS pk_patient, cep.description AS problem, 'episode' AS type, public._('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 FROM episode cep WHERE (cep.is_open IS TRUE) UNION SELECT (SELECT encounter.fk_patient FROM encounter WHERE (encounter.pk = chi.fk_encounter)) AS pk_patient, chi.description AS problem, 'issue' AS type, public._('health issue'::text) AS l10n_type, chi.is_active AS problem_active, true AS clinically_relevant, NULL::unknown AS pk_episode, chi.pk AS pk_health_issue, chi.diagnostic_certainty_classification FROM health_issue chi WHERE (chi.clinically_relevant IS TRUE); ALTER TABLE clin.v_problem_list OWNER TO "gm-dbo"; -- -- Name: v_reviewed_items; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_reviewed_items AS SELECT (SELECT pg_class.relnamespace FROM pg_class WHERE (pg_class.oid = rr.tableoid)) AS src_schema, (SELECT pg_class.relname FROM pg_class WHERE (pg_class.oid = rr.tableoid)) AS src_table, rr.fk_reviewed_row AS pk_reviewed_row, rr.is_technically_abnormal, rr.clinically_relevant, (SELECT staff.short_alias FROM dem.staff WHERE (staff.pk = rr.fk_reviewer)) AS reviewer, rr.comment, rr.pk AS pk_review_root, rr.fk_reviewer AS pk_reviewer FROM review_root rr; ALTER TABLE clin.v_reviewed_items OWNER TO "gm-dbo"; -- -- Name: VIEW v_reviewed_items; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_reviewed_items IS 'denormalization of parent table of reviewed items'; -- -- Name: v_test_types; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_test_types AS SELECT ctt.pk AS pk_test_type, ctt.abbrev, ctt.name, ctt.loinc, ctt.code, ctt.coding_system, ctt.conversion_unit, ctt.comment AS comment_type, cto.internal_name AS internal_name_org, cto.comment AS comment_org, ctt.fk_test_org AS pk_test_org, cto.fk_org AS pk_org, cto.fk_adm_contact AS pk_adm_contact_org, cto.fk_med_contact AS pk_med_contact_org, ctt.xmin AS xmin_test_type FROM (test_type ctt LEFT JOIN test_org cto ON ((cto.pk = ctt.fk_test_org))); ALTER TABLE clin.v_test_types OWNER TO "gm-dbo"; -- -- Name: VIEW v_test_types; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_test_types IS 'denormalizes test types with test orgs'; -- -- Name: vaccination_course; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE vaccination_course ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_recommended_by integer, fk_indication integer NOT NULL, is_active boolean DEFAULT true NOT NULL, comment text ) INHERITS (audit.audit_fields); ALTER TABLE clin.vaccination_course OWNER TO "gm-dbo"; -- -- Name: TABLE vaccination_course; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE vaccination_course IS 'holds vaccination courses defined at a techno-medical level for a single indication and will in many cases represent a part of a "recommended multi-epitope schedule", note that one organization can indeed recommend several courses for one and the same indication - which then only differ in their constraints, PostgreSQL does not currently offer the best tools to enforce such constraints'; -- -- Name: COLUMN vaccination_course.fk_recommended_by; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_course.fk_recommended_by IS 'the source/organization which defined this course, can be used to differentiate several locale-dependant courses for the same indication and yet tell them apart'; -- -- Name: COLUMN vaccination_course.fk_indication; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_course.fk_indication IS 'vaccination indication this course is targeted at'; -- -- Name: COLUMN vaccination_course.is_active; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_course.is_active IS 'whether this course is active or not, if False: do not newly *start* patients on this course'; -- -- Name: COLUMN vaccination_course.comment; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_course.comment IS 'a free-text comment on this vaccination course'; -- -- Name: vaccination_schedule; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE vaccination_schedule ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, name text NOT NULL, comment text ) INHERITS (audit.audit_fields); ALTER TABLE clin.vaccination_schedule OWNER TO "gm-dbo"; -- -- Name: TABLE vaccination_schedule; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE vaccination_schedule IS 'This table holds schedules as recommended by some authority such as a Vaccination Council. There will be numerous schedules depending on locale, constraints, age group etc. These schedules may be single or multi-epitope depending on their definition. A schedule acts as a convenient handle aggregating possibly several vaccination courses under a common name.'; -- -- Name: COLUMN vaccination_schedule.name; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_schedule.name IS 'name of the schedule as defined by some authority'; -- -- Name: v_vaccination_courses_in_schedule; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_vaccination_courses_in_schedule AS SELECT cvs.name AS vaccination_schedule, cvc.is_active, cvc.fk_recommended_by AS pk_recommended_by, cvc.comment AS comment_course, cvs.comment AS comment_schedule, cvc.pk AS pk_vaccination_course, cvc.fk_indication AS pk_indication, cvs.pk AS pk_vaccination_schedule FROM vaccination_course cvc, vaccination_schedule cvs, lnk_vaccination_course2schedule clvc2s WHERE ((clvc2s.fk_course = cvc.pk) AND (clvc2s.fk_schedule = cvs.pk)); ALTER TABLE clin.v_vaccination_courses_in_schedule OWNER TO "gm-dbo"; -- -- Name: vaccination_definition; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE vaccination_definition ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), id integer NOT NULL, fk_course integer NOT NULL, is_booster boolean DEFAULT false NOT NULL, seq_no integer, min_age_due interval NOT NULL, max_age_due interval DEFAULT '01:32:35'::interval NOT NULL, min_interval interval, comment text, CONSTRAINT numbered_shot_xor_booster CHECK ((((is_booster IS TRUE) AND (seq_no IS NULL)) OR ((is_booster IS FALSE) AND (seq_no > 0)))), CONSTRAINT sensible_min_interval CHECK (((((min_interval IS NULL) AND (seq_no = 1)) OR (((min_interval IS NOT NULL) AND (min_interval > '00:00:00'::interval)) AND (is_booster IS TRUE))) OR (((min_interval IS NOT NULL) AND (min_interval > '00:00:00'::interval)) AND (seq_no > 1)))), CONSTRAINT vaccination_definition_check CHECK ((((max_age_due >= min_age_due) AND (max_age_due <= '150 years'::interval)) OR (max_age_due = '01:32:35'::interval))), CONSTRAINT vaccination_definition_min_age_due_check CHECK (((min_age_due >= '00:00:01'::interval) AND (min_age_due <= '150 years'::interval))) ) INHERITS (audit.audit_fields); ALTER TABLE clin.vaccination_definition OWNER TO "gm-dbo"; -- -- Name: TABLE vaccination_definition; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE vaccination_definition IS 'defines a given vaccination event for a particular course'; -- -- Name: COLUMN vaccination_definition.fk_course; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_definition.fk_course IS 'course to which this event belongs'; -- -- Name: COLUMN vaccination_definition.is_booster; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_definition.is_booster IS 'does this definition represent a booster, also set for quasi-booster courses such as Influenza'; -- -- Name: COLUMN vaccination_definition.seq_no; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_definition.seq_no IS 'sequence number for this vaccination event within a particular course, NULL if (is_booster == true)'; -- -- Name: COLUMN vaccination_definition.min_age_due; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_definition.min_age_due IS 'minimum age at which this shot is due'; -- -- Name: COLUMN vaccination_definition.max_age_due; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_definition.max_age_due IS 'maximum age at which this shot is due, if max_age_due = "5555 years": no maximum age'; -- -- Name: COLUMN vaccination_definition.min_interval; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_definition.min_interval IS 'if (is_booster == true): recommended interval for boostering id (is_booster == false): minimum interval after previous vaccination, NULL if seq_no == 1'; -- -- Name: v_vaccination_definitions4course; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_vaccination_definitions4course AS SELECT vcourse.pk AS pk_course, vind.description AS indication, public._(vind.description) AS l10n_indication, COALESCE(vcourse.comment, ''::text) AS course_comment, vcourse.is_active, vdef.id AS pk_vaccination_definition, vdef.is_booster, vdef.seq_no AS vacc_seq_no, vdef.min_age_due AS age_due_min, vdef.max_age_due AS age_due_max, vdef.min_interval, COALESCE(vdef.comment, ''::text) AS vacc_comment, vind.id AS pk_indication, vcourse.fk_recommended_by AS pk_recommended_by FROM vaccination_course vcourse, vacc_indication vind, vaccination_definition vdef WHERE ((vcourse.pk = vdef.fk_course) AND (vcourse.fk_indication = vind.id)) ORDER BY vind.description, vdef.seq_no; ALTER TABLE clin.v_vaccination_definitions4course OWNER TO "gm-dbo"; -- -- Name: VIEW v_vaccination_definitions4course; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_vaccination_definitions4course IS 'vaccination event definitions for all courses known to the system'; -- -- Name: vacc_route; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE vacc_route ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), id integer NOT NULL, abbreviation text NOT NULL, description text NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.vacc_route OWNER TO "gm-dbo"; -- -- Name: TABLE vacc_route; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE vacc_route IS 'definition of route via which vaccine is given, currently i.m. and p.o. only but may include "via genetically engineered food" etc in the future'; -- -- Name: v_vaccine; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_vaccine AS SELECT v.pk AS pk_vaccine, v.trade_name, v.short_name, vr.abbreviation AS route_abbreviation, vr.description AS route_description, public._(vr.description) AS l10n_route_description, v.is_live, v.min_age, v.max_age, v.comment, v.id_route AS pk_route FROM vaccine v, vacc_route vr WHERE (v.id_route = vr.id); ALTER TABLE clin.v_vaccine OWNER TO "gm-dbo"; -- -- Name: VIEW v_vaccine; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_vaccine IS 'denormalized data about vaccines'; -- -- Name: waiting_list; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE waiting_list ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_patient integer NOT NULL, registered timestamp with time zone DEFAULT now() NOT NULL, urgency integer DEFAULT 0 NOT NULL, list_position integer NOT NULL, comment text, area text, CONSTRAINT non_empty_area CHECK ((btrim(area) <> ''::text)), CONSTRAINT waiting_list_list_position_check CHECK ((list_position > 0)) ) INHERITS (audit.audit_fields); ALTER TABLE clin.waiting_list OWNER TO "gm-dbo"; -- -- Name: TABLE waiting_list; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE waiting_list IS 'aggregates all the patients currently waiting for an encounter'; -- -- Name: COLUMN waiting_list.fk_patient; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN waiting_list.fk_patient IS 'the waiting patient'; -- -- Name: COLUMN waiting_list.registered; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN waiting_list.registered IS 'when did the patient arrive (enter the waiting list, that is)'; -- -- Name: COLUMN waiting_list.urgency; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN waiting_list.urgency IS 'relative urgency, used by practices as they see fit, 0 - "standard" urgency < 0 - less urgent > 0 - more urgent'; -- -- Name: COLUMN waiting_list.list_position; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN waiting_list.list_position IS 'the currently assigned position of this patient on the waiting list'; -- -- Name: COLUMN waiting_list.comment; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN waiting_list.comment IS 'a free comment regarding this entry, NOT THE RFE !'; -- -- Name: COLUMN waiting_list.area; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN waiting_list.area IS 'an arbitrary value by which filtering waiting patients into zones becomes possible'; -- -- Name: v_waiting_list; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_waiting_list AS SELECT wl.list_position, wl.area AS waiting_zone, wl.urgency, i.title, n.firstnames, n.lastnames, n.preferred AS preferred_name, i.dob, i.gender, public._(i.gender) AS l10n_gender, wl.registered, (SELECT (now() - wl.registered)) AS waiting_time, (SELECT to_char(age(now(), wl.registered), 'TMDD HH24:MI'::text) AS to_char) AS waiting_time_formatted, wl.comment, i.pk AS pk_identity, n.id AS pk_name, i.pupic, wl.pk AS pk_waiting_list FROM waiting_list wl, dem.identity i, dem.names n WHERE ((((wl.fk_patient = i.pk) AND (wl.fk_patient = n.id_identity)) AND (i.deceased IS NULL)) AND (n.active IS TRUE)); ALTER TABLE clin.v_waiting_list OWNER TO "gm-dbo"; -- -- Name: v_your_keyword_expansions; Type: VIEW; Schema: clin; Owner: gm-dbo -- CREATE VIEW v_your_keyword_expansions AS SELECT DISTINCT ON (union_result.keyword) union_result.pk_keyword_expansion, union_result.pk_staff, union_result.keyword, union_result.expansion, union_result.public_expansion, union_result.private_expansion, union_result.owner FROM (SELECT cke.pk AS pk_keyword_expansion, cke.fk_staff AS pk_staff, cke.keyword, cke.expansion, false AS public_expansion, true AS private_expansion, cke.owner FROM keyword_expansion cke WHERE (cke.fk_staff = (SELECT staff.pk FROM dem.staff WHERE (staff.db_user = "current_user"()))) UNION ALL SELECT cke.pk AS pk_keyword_expansion, cke.fk_staff AS pk_staff, cke.keyword, cke.expansion, true AS public_expansion, false AS private_expansion, cke.owner FROM keyword_expansion cke WHERE (cke.fk_staff IS NULL) ORDER BY 6 DESC) union_result ORDER BY union_result.keyword; ALTER TABLE clin.v_your_keyword_expansions OWNER TO "gm-dbo"; -- -- Name: VIEW v_your_keyword_expansions; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON VIEW v_your_keyword_expansions IS 'View over the text expansions relevant to the current user: a private expansion set up for the current user overrides a public expansion of the same keyword.'; -- -- Name: vacc_indication_id_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE vacc_indication_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.vacc_indication_id_seq OWNER TO "gm-dbo"; -- -- Name: vacc_indication_id_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE vacc_indication_id_seq OWNED BY vacc_indication.id; -- -- Name: vacc_route_id_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE vacc_route_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.vacc_route_id_seq OWNER TO "gm-dbo"; -- -- Name: vacc_route_id_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE vacc_route_id_seq OWNED BY vacc_route.id; -- -- Name: vaccination; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE vaccination ( soap_cat text DEFAULT 'p'::text, id integer NOT NULL, fk_provider integer NOT NULL, fk_vaccine integer NOT NULL, site text DEFAULT 'not recorded'::text, batch_no text DEFAULT 'not recorded'::text NOT NULL, CONSTRAINT vaccination_soap_cat_check CHECK (((soap_cat IS NULL) OR ((((lower(soap_cat) = 's'::text) OR (lower(soap_cat) = 'o'::text)) OR (lower(soap_cat) = 'a'::text)) OR (lower(soap_cat) = 'p'::text)))) ) INHERITS (clin_root_item); ALTER TABLE clin.vaccination OWNER TO "gm-dbo"; -- -- Name: TABLE vaccination; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE vaccination IS 'holds vaccinations actually given'; -- -- Name: vaccination_course_constraint; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE vaccination_course_constraint ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, description text NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.vaccination_course_constraint OWNER TO "gm-dbo"; -- -- Name: TABLE vaccination_course_constraint; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON TABLE vaccination_course_constraint IS 'holds constraints which apply to a vaccination course'; -- -- Name: COLUMN vaccination_course_constraint.description; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccination_course_constraint.description IS 'description/label/name of the constraint'; -- -- Name: vaccination_course_constraint_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE vaccination_course_constraint_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.vaccination_course_constraint_pk_seq OWNER TO "gm-dbo"; -- -- Name: vaccination_course_constraint_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE vaccination_course_constraint_pk_seq OWNED BY vaccination_course_constraint.pk; -- -- Name: vaccination_course_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE vaccination_course_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.vaccination_course_pk_seq OWNER TO "gm-dbo"; -- -- Name: vaccination_course_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE vaccination_course_pk_seq OWNED BY vaccination_course.pk; -- -- Name: vaccination_definition_id_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE vaccination_definition_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.vaccination_definition_id_seq OWNER TO "gm-dbo"; -- -- Name: vaccination_definition_id_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE vaccination_definition_id_seq OWNED BY vaccination_definition.id; -- -- Name: vaccination_id_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE vaccination_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.vaccination_id_seq OWNER TO "gm-dbo"; -- -- Name: vaccination_id_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE vaccination_id_seq OWNED BY vaccination.id; -- -- Name: vaccination_schedule_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE vaccination_schedule_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.vaccination_schedule_pk_seq OWNER TO "gm-dbo"; -- -- Name: vaccination_schedule_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE vaccination_schedule_pk_seq OWNED BY vaccination_schedule.pk; -- -- Name: vaccine_batches; Type: TABLE; Schema: clin; Owner: gm-dbo; Tablespace: -- CREATE TABLE vaccine_batches ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_vaccine integer NOT NULL, batch_no text NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE clin.vaccine_batches OWNER TO "gm-dbo"; -- -- Name: COLUMN vaccine_batches.batch_no; Type: COMMENT; Schema: clin; Owner: gm-dbo -- COMMENT ON COLUMN vaccine_batches.batch_no IS 'serial # of a batch of a given vaccine that is awaiting usage in the fridge'; -- -- Name: vaccine_batches_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE vaccine_batches_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.vaccine_batches_pk_seq OWNER TO "gm-dbo"; -- -- Name: vaccine_batches_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE vaccine_batches_pk_seq OWNED BY vaccine_batches.pk; -- -- Name: vaccine_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE vaccine_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.vaccine_pk_seq OWNER TO "gm-dbo"; -- -- Name: vaccine_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE vaccine_pk_seq OWNED BY vaccine.pk; -- -- Name: waiting_list_pk_seq; Type: SEQUENCE; Schema: clin; Owner: gm-dbo -- CREATE SEQUENCE waiting_list_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE clin.waiting_list_pk_seq OWNER TO "gm-dbo"; -- -- Name: waiting_list_pk_seq; Type: SEQUENCE OWNED BY; Schema: clin; Owner: gm-dbo -- ALTER SEQUENCE waiting_list_pk_seq OWNED BY waiting_list.pk; SET search_path = de_de, pg_catalog; -- -- Name: beh_fall_typ; Type: TABLE; Schema: de_de; Owner: gm-dbo; Tablespace: -- CREATE TABLE beh_fall_typ ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, code text NOT NULL, kurzform text NOT NULL, name text NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE de_de.beh_fall_typ OWNER TO "gm-dbo"; -- -- Name: TABLE beh_fall_typ; Type: COMMENT; Schema: de_de; Owner: gm-dbo -- COMMENT ON TABLE beh_fall_typ IS 'Art des Behandlungsfalls (MuVo/Impfung/...)'; -- -- Name: beh_fall_typ_pk_seq; Type: SEQUENCE; Schema: de_de; Owner: gm-dbo -- CREATE SEQUENCE beh_fall_typ_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE de_de.beh_fall_typ_pk_seq OWNER TO "gm-dbo"; -- -- Name: beh_fall_typ_pk_seq; Type: SEQUENCE OWNED BY; Schema: de_de; Owner: gm-dbo -- ALTER SEQUENCE beh_fall_typ_pk_seq OWNED BY beh_fall_typ.pk; -- -- Name: behandlungsfall; Type: TABLE; Schema: de_de; Owner: gm-dbo; Tablespace: -- CREATE TABLE behandlungsfall ( pk integer NOT NULL, fk_patient integer NOT NULL, fk_falltyp integer NOT NULL, started date DEFAULT ('now'::text)::date NOT NULL, must_pay_prax_geb boolean DEFAULT true NOT NULL ); ALTER TABLE de_de.behandlungsfall OWNER TO "gm-dbo"; -- -- Name: behandlungsfall_pk_seq; Type: SEQUENCE; Schema: de_de; Owner: gm-dbo -- CREATE SEQUENCE behandlungsfall_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE de_de.behandlungsfall_pk_seq OWNER TO "gm-dbo"; -- -- Name: behandlungsfall_pk_seq; Type: SEQUENCE OWNED BY; Schema: de_de; Owner: gm-dbo -- ALTER SEQUENCE behandlungsfall_pk_seq OWNED BY behandlungsfall.pk; -- -- Name: kvk; Type: TABLE; Schema: de_de; Owner: gm-dbo; Tablespace: -- CREATE TABLE kvk ( pk integer NOT NULL, fk_patient integer NOT NULL, kk_name character varying(28) NOT NULL, kk_nummer character(7) NOT NULL, kvk_nummer character(5), mitgliedsnummer character varying(12) NOT NULL, mitgliedsstatus character varying(4) NOT NULL, zusatzstatus character varying(3), titel character varying(15), vorname character varying(28), namenszuatz character varying(15), familienname character varying(28) NOT NULL, geburtsdatum character(8) NOT NULL, strasse character varying(28), landescode character varying(3), plz character varying(7) NOT NULL, ort character varying(23) NOT NULL, gueltigkeit character(4), crc character(1) NOT NULL, is_valid_address boolean DEFAULT true, valid_since timestamp with time zone NOT NULL, presented timestamp with time zone[] NOT NULL, invalidated timestamp with time zone ); ALTER TABLE de_de.kvk OWNER TO "gm-dbo"; -- -- Name: TABLE kvk; Type: COMMENT; Schema: de_de; Owner: gm-dbo -- COMMENT ON TABLE kvk IS 'Speichert die Daten einer bestimmten KVK. Wir trennen die KVK-Daten von den Daten ueber Person, Wohnort, Kassenzugehoerigkeit, Mitgliedsstatus und Abrechnungsfaellen. Diese Daten werden jedoch a) als Vorgaben fuer die eigentlichen Personendaten und b) als gueltig fuer abrechnungstechnische Belange angesehen.'; -- -- Name: COLUMN kvk.invalidated; Type: COMMENT; Schema: de_de; Owner: gm-dbo -- COMMENT ON COLUMN kvk.invalidated IS 'Kann durchaus vor Ende von "Gueltigkeit" liegen. Zeitpunkt des Austritts aus der Krankenkasse. Beim Setzen dieses Feldes muss auch die Zuzahlungsbefreiung auf NULL gesetzt werden.'; -- -- Name: kvk_pk_seq; Type: SEQUENCE; Schema: de_de; Owner: gm-dbo -- CREATE SEQUENCE kvk_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE de_de.kvk_pk_seq OWNER TO "gm-dbo"; -- -- Name: kvk_pk_seq; Type: SEQUENCE OWNED BY; Schema: de_de; Owner: gm-dbo -- ALTER SEQUENCE kvk_pk_seq OWNED BY kvk.pk; -- -- Name: lab_test_gnr; Type: TABLE; Schema: de_de; Owner: gm-dbo; Tablespace: -- CREATE TABLE lab_test_gnr ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), id integer NOT NULL, id_test integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE de_de.lab_test_gnr OWNER TO "gm-dbo"; -- -- Name: TABLE lab_test_gnr; Type: COMMENT; Schema: de_de; Owner: gm-dbo -- COMMENT ON TABLE lab_test_gnr IS 'specific for Germany, GNR = GebuehrenordnungsNummeR = billing item, build index before lab import and drop afterwards, check against this table when importing, build table during import'; -- -- Name: COLUMN lab_test_gnr.id_test; Type: COMMENT; Schema: de_de; Owner: gm-dbo -- COMMENT ON COLUMN lab_test_gnr.id_test IS 'link to test in our practice'; -- -- Name: lab_test_gnr_id_seq; Type: SEQUENCE; Schema: de_de; Owner: gm-dbo -- CREATE SEQUENCE lab_test_gnr_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE de_de.lab_test_gnr_id_seq OWNER TO "gm-dbo"; -- -- Name: lab_test_gnr_id_seq; Type: SEQUENCE OWNED BY; Schema: de_de; Owner: gm-dbo -- ALTER SEQUENCE lab_test_gnr_id_seq OWNED BY lab_test_gnr.id; -- -- Name: payment_method; Type: TABLE; Schema: de_de; Owner: gm-dbo; Tablespace: -- CREATE TABLE payment_method ( pk integer NOT NULL, description text NOT NULL ); ALTER TABLE de_de.payment_method OWNER TO "gm-dbo"; -- -- Name: payment_method_pk_seq; Type: SEQUENCE; Schema: de_de; Owner: gm-dbo -- CREATE SEQUENCE payment_method_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE de_de.payment_method_pk_seq OWNER TO "gm-dbo"; -- -- Name: payment_method_pk_seq; Type: SEQUENCE OWNED BY; Schema: de_de; Owner: gm-dbo -- ALTER SEQUENCE payment_method_pk_seq OWNED BY payment_method.pk; -- -- Name: prax_geb_paid; Type: TABLE; Schema: de_de; Owner: gm-dbo; Tablespace: -- CREATE TABLE prax_geb_paid ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_fall integer NOT NULL, paid_amount numeric DEFAULT 0 NOT NULL, paid_when date DEFAULT ('now'::text)::date NOT NULL, paid_with integer NOT NULL ) INHERITS (audit.audit_fields); ALTER TABLE de_de.prax_geb_paid OWNER TO "gm-dbo"; -- -- Name: prax_geb_paid_pk_seq; Type: SEQUENCE; Schema: de_de; Owner: gm-dbo -- CREATE SEQUENCE prax_geb_paid_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE de_de.prax_geb_paid_pk_seq OWNER TO "gm-dbo"; -- -- Name: prax_geb_paid_pk_seq; Type: SEQUENCE OWNED BY; Schema: de_de; Owner: gm-dbo -- ALTER SEQUENCE prax_geb_paid_pk_seq OWNED BY prax_geb_paid.pk; -- -- Name: zuzahlungsbefreiung; Type: TABLE; Schema: de_de; Owner: gm-dbo; Tablespace: -- CREATE TABLE zuzahlungsbefreiung ( id integer NOT NULL, id_patient integer, medikamente date, heilmittel date, hilfsmittel date, presented timestamp with time zone DEFAULT now() NOT NULL ); ALTER TABLE de_de.zuzahlungsbefreiung OWNER TO "gm-dbo"; -- -- Name: zuzahlungsbefreiung_id_seq; Type: SEQUENCE; Schema: de_de; Owner: gm-dbo -- CREATE SEQUENCE zuzahlungsbefreiung_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE de_de.zuzahlungsbefreiung_id_seq OWNER TO "gm-dbo"; -- -- Name: zuzahlungsbefreiung_id_seq; Type: SEQUENCE OWNED BY; Schema: de_de; Owner: gm-dbo -- ALTER SEQUENCE zuzahlungsbefreiung_id_seq OWNED BY zuzahlungsbefreiung.id; SET search_path = dem, pg_catalog; -- -- Name: address; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE address ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), id integer NOT NULL, id_street integer NOT NULL, aux_street text, number text NOT NULL, subunit text, addendum text, lat_lon point ) INHERITS (audit.audit_fields); ALTER TABLE dem.address OWNER TO "gm-dbo"; -- -- Name: TABLE address; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE address IS 'an address aka a location, void of attached meaning such as type of address'; -- -- Name: COLUMN address.id_street; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN address.id_street IS 'the street this address is at from whence the urb is to be found, it thus indirectly references dem.urb(id)'; -- -- Name: COLUMN address.aux_street; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN address.aux_street IS 'additional street-level information which formatters would usually put on lines directly below the street line of an address, such as postal box directions in CA'; -- -- Name: COLUMN address.number; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN address.number IS 'number of the house'; -- -- Name: COLUMN address.subunit; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN address.subunit IS 'directions *below* the unit (eg.number) level, such as appartment number, room number, level, entrance or even verbal directions'; -- -- Name: COLUMN address.addendum; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN address.addendum IS 'any additional information that did not fit anywhere else'; -- -- Name: COLUMN address.lat_lon; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN address.lat_lon IS 'the exact location of this address in latitude-longtitude'; -- -- Name: address_id_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE address_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.address_id_seq OWNER TO "gm-dbo"; -- -- Name: address_id_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE address_id_seq OWNED BY address.id; -- -- Name: address_type; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE address_type ( id integer NOT NULL, name text NOT NULL ); ALTER TABLE dem.address_type OWNER TO "gm-dbo"; -- -- Name: address_type_id_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE address_type_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.address_type_id_seq OWNER TO "gm-dbo"; -- -- Name: address_type_id_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE address_type_id_seq OWNED BY address_type.id; -- -- Name: country; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE country ( id integer NOT NULL, code character(2) NOT NULL, name text NOT NULL, deprecated date, CONSTRAINT no_linebreaks CHECK ((((("position"(((COALESCE(code, ''::bpchar))::text || COALESCE(name, ''::text)), ' '::text) = 0) AND ("position"(((COALESCE(code, ''::bpchar))::text || COALESCE(name, ''::text)), ' '::text) = 0)) AND ("position"(((COALESCE(code, ''::bpchar))::text || COALESCE(name, ''::text)), ' '::text) = 0)) AND ("position"(((COALESCE(code, ''::bpchar))::text || COALESCE(name, ''::text)), ' '::text) = 0))) ); ALTER TABLE dem.country OWNER TO "gm-dbo"; -- -- Name: TABLE country; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE country IS 'countries coded per ISO 3166-1'; -- -- Name: COLUMN country.code; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN country.code IS 'international two character country code as per ISO 3166-1'; -- -- Name: COLUMN country.deprecated; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN country.deprecated IS 'date when this country ceased officially to exist (if applicable)'; -- -- Name: country_id_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE country_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.country_id_seq OWNER TO "gm-dbo"; -- -- Name: country_id_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE country_id_seq OWNED BY country.id; -- -- Name: enum_comm_types; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE enum_comm_types ( pk integer NOT NULL, description text NOT NULL ); ALTER TABLE dem.enum_comm_types OWNER TO "gm-dbo"; -- -- Name: enum_comm_types_id_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE enum_comm_types_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.enum_comm_types_id_seq OWNER TO "gm-dbo"; -- -- Name: enum_comm_types_id_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE enum_comm_types_id_seq OWNED BY enum_comm_types.pk; -- -- Name: enum_ext_id_types; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE enum_ext_id_types ( pk integer NOT NULL, name text, issuer text, context character(1) DEFAULT 'p'::bpchar, CONSTRAINT enum_ext_id_types_context_check CHECK (((((context = 'p'::bpchar) OR (context = 'o'::bpchar)) OR (context = 'c'::bpchar)) OR (context = 's'::bpchar))) ); ALTER TABLE dem.enum_ext_id_types OWNER TO "gm-dbo"; -- -- Name: TABLE enum_ext_id_types; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE enum_ext_id_types IS 'a list of all bureaucratic IDs/serial numbers/3rd party primary keys, etc.'; -- -- Name: COLUMN enum_ext_id_types.issuer; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN enum_ext_id_types.issuer IS 'the authority/system issuing the number'; -- -- Name: COLUMN enum_ext_id_types.context; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN enum_ext_id_types.context IS 'the context in which this number is used - p for ordinary persons - o for organisations - c for clinicians - s for staff in this clinic FIXME: is context really a property of *type* ?'; -- -- Name: enum_ext_id_types_pk_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE enum_ext_id_types_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.enum_ext_id_types_pk_seq OWNER TO "gm-dbo"; -- -- Name: enum_ext_id_types_pk_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE enum_ext_id_types_pk_seq OWNED BY enum_ext_id_types.pk; -- -- Name: gender_label; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE gender_label ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, tag text NOT NULL, label text NOT NULL, sort_weight integer NOT NULL, comment text NOT NULL, CONSTRAINT gender_label_tag_check CHECK ((((((tag = 'm'::text) OR (tag = 'f'::text)) OR (tag = 'h'::text)) OR (tag = 'tm'::text)) OR (tag = 'tf'::text))) ) INHERITS (audit.audit_fields); ALTER TABLE dem.gender_label OWNER TO "gm-dbo"; -- -- Name: TABLE gender_label; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE gender_label IS 'This table stores the genders known to GNUmed. FIXME: cross-check with CDA:administrative-gender-code'; -- -- Name: gender_label_pk_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE gender_label_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.gender_label_pk_seq OWNER TO "gm-dbo"; -- -- Name: gender_label_pk_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE gender_label_pk_seq OWNED BY gender_label.pk; -- -- Name: identity_pk_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE identity_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.identity_pk_seq OWNER TO "gm-dbo"; -- -- Name: identity_pk_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE identity_pk_seq OWNED BY identity.pk; -- -- Name: inbox_item_category; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE inbox_item_category ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, description text NOT NULL, is_user boolean DEFAULT true NOT NULL, CONSTRAINT inbox_item_category_description_check CHECK ((btrim(COALESCE(description, 'xxxDEFAULTxxx'::text)) <> ''::text)) ) INHERITS (audit.audit_fields); ALTER TABLE dem.inbox_item_category OWNER TO "gm-dbo"; -- -- Name: TABLE inbox_item_category; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE inbox_item_category IS 'Holds the various categories of messages that can show up in the provider inbox.'; -- -- Name: COLUMN inbox_item_category.description; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN inbox_item_category.description IS ' "clinical" "admin" "personal" ...'; -- -- Name: COLUMN inbox_item_category.is_user; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN inbox_item_category.is_user IS 'whether this category was added locally, as to be left alone by database upgrades'; -- -- Name: inbox_item_category_pk_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE inbox_item_category_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.inbox_item_category_pk_seq OWNER TO "gm-dbo"; -- -- Name: inbox_item_category_pk_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE inbox_item_category_pk_seq OWNED BY inbox_item_category.pk; -- -- Name: inbox_item_type; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE inbox_item_type ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_inbox_item_category integer NOT NULL, description text NOT NULL, is_user boolean DEFAULT true NOT NULL, CONSTRAINT inbox_item_type_description_check CHECK ((btrim(COALESCE(description, 'xxxDEFAULTxxx'::text)) <> ''::text)) ) INHERITS (audit.audit_fields); ALTER TABLE dem.inbox_item_type OWNER TO "gm-dbo"; -- -- Name: TABLE inbox_item_type; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE inbox_item_type IS 'Holds the various types of messages that can show up in the provider inbox.'; -- -- Name: COLUMN inbox_item_type.fk_inbox_item_category; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN inbox_item_type.fk_inbox_item_category IS 'The category of this item type.'; -- -- Name: COLUMN inbox_item_type.description; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN inbox_item_type.description IS 'the various types of inbox items'; -- -- Name: COLUMN inbox_item_type.is_user; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN inbox_item_type.is_user IS 'whether this type was added locally, as to be left alone by database upgrades'; -- -- Name: inbox_item_type_pk_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE inbox_item_type_pk_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.inbox_item_type_pk_seq OWNER TO "gm-dbo"; -- -- Name: inbox_item_type_pk_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE inbox_item_type_pk_seq OWNED BY inbox_item_type.pk; -- -- Name: lnk_identity2comm; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_identity2comm ( pk integer NOT NULL, fk_identity integer NOT NULL, fk_address integer, url text NOT NULL, fk_type integer NOT NULL, is_confidential boolean DEFAULT false NOT NULL, CONSTRAINT lnk_identity2comm_url_check CHECK ((btrim(url) <> ''::text)) ); ALTER TABLE dem.lnk_identity2comm OWNER TO "gm-dbo"; -- -- Name: lnk_identity2comm_id_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE lnk_identity2comm_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.lnk_identity2comm_id_seq OWNER TO "gm-dbo"; -- -- Name: lnk_identity2comm_id_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE lnk_identity2comm_id_seq OWNED BY lnk_identity2comm.pk; -- -- Name: lnk_identity2ext_id; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_identity2ext_id ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), id integer NOT NULL, id_identity integer NOT NULL, external_id text NOT NULL, fk_origin integer NOT NULL, comment text ) INHERITS (audit.audit_fields); ALTER TABLE dem.lnk_identity2ext_id OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_identity2ext_id; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE lnk_identity2ext_id IS 'link external IDs to GnuMed identities'; -- -- Name: COLUMN lnk_identity2ext_id.external_id; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN lnk_identity2ext_id.external_id IS 'textual representation of external ID which may be Social Security Number, patient ID of another EMR system, you-name-it'; -- -- Name: COLUMN lnk_identity2ext_id.fk_origin; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN lnk_identity2ext_id.fk_origin IS 'originating system'; -- -- Name: lnk_identity2ext_id_id_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE lnk_identity2ext_id_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.lnk_identity2ext_id_id_seq OWNER TO "gm-dbo"; -- -- Name: lnk_identity2ext_id_id_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE lnk_identity2ext_id_id_seq OWNED BY lnk_identity2ext_id.id; -- -- Name: lnk_identity2primary_doc; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_identity2primary_doc ( pk integer NOT NULL, fk_identity integer NOT NULL, fk_primary_doc integer NOT NULL ); ALTER TABLE dem.lnk_identity2primary_doc OWNER TO "gm-dbo"; -- -- Name: lnk_identity2primary_doc_pk_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE lnk_identity2primary_doc_pk_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.lnk_identity2primary_doc_pk_seq OWNER TO "gm-dbo"; -- -- Name: lnk_identity2primary_doc_pk_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE lnk_identity2primary_doc_pk_seq OWNED BY lnk_identity2primary_doc.pk; -- -- Name: lnk_job2person; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_job2person ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), pk integer NOT NULL, fk_identity integer NOT NULL, fk_occupation integer NOT NULL, activities text ) INHERITS (audit.audit_fields); ALTER TABLE dem.lnk_job2person OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_job2person; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE lnk_job2person IS 'linking (possibly several) jobs to a person'; -- -- Name: COLUMN lnk_job2person.activities; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN lnk_job2person.activities IS 'describes activities the person is usually carrying out when working at this job'; -- -- Name: lnk_job2person_id_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE lnk_job2person_id_seq INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.lnk_job2person_id_seq OWNER TO "gm-dbo"; -- -- Name: lnk_job2person_id_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE lnk_job2person_id_seq OWNED BY lnk_job2person.pk; -- -- Name: lnk_person_org_address; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_person_org_address ( id integer NOT NULL, id_identity integer, id_address integer, id_type integer DEFAULT 1, address_source text, id_org integer ); ALTER TABLE dem.lnk_person_org_address OWNER TO "gm-dbo"; -- -- Name: TABLE lnk_person_org_address; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON TABLE lnk_person_org_address IS 'a many-to-many pivot table describing the relationship between an organisation, a person, their work address and their occupation at that location. For patients id_org is NULL'; -- -- Name: COLUMN lnk_person_org_address.id_identity; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN lnk_person_org_address.id_identity IS 'identity to which the address belongs'; -- -- Name: COLUMN lnk_person_org_address.id_address; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN lnk_person_org_address.id_address IS 'address belonging to this identity (the branch of the organisation)'; -- -- Name: COLUMN lnk_person_org_address.id_type; Type: COMMENT; Schema: dem; Owner: gm-dbo -- COMMENT ON COLUMN lnk_person_org_address.id_type IS 'type of this address (like home, work, parents, holidays ...)'; -- -- Name: lnk_org2address; Type: VIEW; Schema: dem; Owner: gm-dbo -- CREATE VIEW lnk_org2address AS SELECT lnk_person_org_address.id_org, lnk_person_org_address.id_address FROM lnk_person_org_address; ALTER TABLE dem.lnk_org2address OWNER TO "gm-dbo"; -- -- Name: lnk_org2comm; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_org2comm ( id integer NOT NULL, id_org integer NOT NULL, url text, id_type integer, is_confidential boolean DEFAULT false NOT NULL ); ALTER TABLE dem.lnk_org2comm OWNER TO "gm-dbo"; -- -- Name: lnk_org2comm_id_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE lnk_org2comm_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.lnk_org2comm_id_seq OWNER TO "gm-dbo"; -- -- Name: lnk_org2comm_id_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-dbo -- ALTER SEQUENCE lnk_org2comm_id_seq OWNED BY lnk_org2comm.id; -- -- Name: lnk_org2ext_id; Type: TABLE; Schema: dem; Owner: gm-dbo; Tablespace: -- CREATE TABLE lnk_org2ext_id ( pk_audit integer DEFAULT nextval('audit.audit_fields_pk_audit_seq'::regclass), id integer NOT NULL, id_org integer NOT NULL, external_id text NOT NULL, fk_origin integer NOT NULL, comment text ) INHERITS (audit.audit_fields); ALTER TABLE dem.lnk_org2ext_id OWNER TO "gm-dbo"; -- -- Name: lnk_org2ext_id_id_seq; Type: SEQUENCE; Schema: dem; Owner: gm-dbo -- CREATE SEQUENCE lnk_org2ext_id_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; ALTER TABLE dem.lnk_org2ext_id_id_seq OWNER TO "gm-dbo"; -- -- Name: lnk_org2ext_id_id_seq; Type: SEQUENCE OWNED BY; Schema: dem; Owner: gm-db