-- Name: audited_tables audited_tables_schema_key; Type: CONSTRAINT; Schema: audit; Owner: gm-dbo
--

ALTER TABLE ONLY audit.audited_tables
    ADD CONSTRAINT audited_tables_schema_key UNIQUE (schema, table_name);


--
-- Name: bill bill_bill_uniq_invoice_id; Type: CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill
    ADD CONSTRAINT bill_bill_uniq_invoice_id UNIQUE (invoice_id);


--
-- Name: bill_item bill_item_pkey; Type: CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill_item
    ADD CONSTRAINT bill_item_pkey PRIMARY KEY (pk);


--
-- Name: bill bill_pkey; Type: CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill
    ADD CONSTRAINT bill_pkey PRIMARY KEY (pk);


--
-- Name: lnk_enc_type2billable lnk_enc_type2billable_pkey; Type: CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.lnk_enc_type2billable
    ADD CONSTRAINT lnk_enc_type2billable_pkey PRIMARY KEY (pk);


--
-- Name: doc_desc doc_desc_doc_id_key; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_desc
    ADD CONSTRAINT doc_desc_doc_id_key UNIQUE (fk_doc, text);


--
-- Name: doc_desc doc_desc_pkey; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_desc
    ADD CONSTRAINT doc_desc_pkey PRIMARY KEY (pk);


--
-- Name: doc_med doc_med_pkey; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_med
    ADD CONSTRAINT doc_med_pkey PRIMARY KEY (pk);


--
-- Name: doc_obj doc_obj_pkey; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_obj
    ADD CONSTRAINT doc_obj_pkey PRIMARY KEY (pk);


--
-- Name: doc_type doc_type_name_key; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_type
    ADD CONSTRAINT doc_type_name_key UNIQUE (name);


--
-- Name: doc_type doc_type_pkey; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_type
    ADD CONSTRAINT doc_type_pkey PRIMARY KEY (pk);


--
-- Name: lnk_doc_med2episode lnk_doc_med2episode_fk_episode_key; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.lnk_doc_med2episode
    ADD CONSTRAINT lnk_doc_med2episode_fk_episode_key UNIQUE (fk_episode, fk_doc_med);


--
-- Name: lnk_doc_med2episode lnk_doc_med2episode_pkey; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.lnk_doc_med2episode
    ADD CONSTRAINT lnk_doc_med2episode_pkey PRIMARY KEY (pk);


--
-- Name: reviewed_doc_objs reviewed_doc_objs_fk_reviewed_row_key; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.reviewed_doc_objs
    ADD CONSTRAINT reviewed_doc_objs_fk_reviewed_row_key UNIQUE (fk_reviewed_row, fk_reviewer);


--
-- Name: reviewed_doc_objs reviewed_doc_objs_pkey; Type: CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.reviewed_doc_objs
    ADD CONSTRAINT reviewed_doc_objs_pkey PRIMARY KEY (pk);


--
-- Name: cfg_data cfg_data_pkey; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_data
    ADD CONSTRAINT cfg_data_pkey PRIMARY KEY (pk);


--
-- Name: cfg_item cfg_item_fk_template_key; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_item
    ADD CONSTRAINT cfg_item_fk_template_key UNIQUE (fk_template, owner, workplace, cookie);


--
-- Name: cfg_item cfg_item_pkey; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_item
    ADD CONSTRAINT cfg_item_pkey PRIMARY KEY (pk);


--
-- Name: cfg_numeric cfg_numeric_pkey; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_numeric
    ADD CONSTRAINT cfg_numeric_pkey PRIMARY KEY (pk);


--
-- Name: cfg_str_array cfg_str_array_pkey; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_str_array
    ADD CONSTRAINT cfg_str_array_pkey PRIMARY KEY (pk);


--
-- Name: cfg_string cfg_string_pkey; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_string
    ADD CONSTRAINT cfg_string_pkey PRIMARY KEY (pk);


--
-- Name: cfg_template cfg_template_pkey; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_template
    ADD CONSTRAINT cfg_template_pkey PRIMARY KEY (pk);


--
-- Name: cfg_type_enum cfg_type_enum_name_key; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_type_enum
    ADD CONSTRAINT cfg_type_enum_name_key UNIQUE (name);


--
-- Name: config config_pkey; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.config
    ADD CONSTRAINT config_pkey PRIMARY KEY (id);


--
-- Name: db_logon_banner db_logon_banner_singularizer_key; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.db_logon_banner
    ADD CONSTRAINT db_logon_banner_singularizer_key UNIQUE (singularizer);


--
-- Name: report_query report_query_label_key; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.report_query
    ADD CONSTRAINT report_query_label_key UNIQUE (label);


--
-- Name: report_query report_query_pkey; Type: CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.report_query
    ADD CONSTRAINT report_query_pkey PRIMARY KEY (pk);


--
-- Name: _enum_allergy_type _enum_allergy_type_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin._enum_allergy_type
    ADD CONSTRAINT _enum_allergy_type_pkey PRIMARY KEY (pk);


--
-- Name: _enum_allergy_type _enum_allergy_type_value_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin._enum_allergy_type
    ADD CONSTRAINT _enum_allergy_type_value_key UNIQUE (value);


--
-- Name: allergy allergy_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.allergy
    ADD CONSTRAINT allergy_pkey PRIMARY KEY (pk);


--
-- Name: allergy_state allergy_state_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.allergy_state
    ADD CONSTRAINT allergy_state_pkey PRIMARY KEY (pk);


--
-- Name: fhx_relation_type c_fhx_rel_type_uniq; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.fhx_relation_type
    ADD CONSTRAINT c_fhx_rel_type_uniq UNIQUE (description, is_genetic);


--
-- Name: clin_aux_note clin_aux_note_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_aux_note
    ADD CONSTRAINT clin_aux_note_pkey PRIMARY KEY (pk);


--
-- Name: clin_diag clin_diag_fk_narrative_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_diag
    ADD CONSTRAINT clin_diag_fk_narrative_key UNIQUE (fk_narrative);


--
-- Name: clin_diag clin_diag_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_diag
    ADD CONSTRAINT clin_diag_pkey PRIMARY KEY (pk);


--
-- Name: export_item clin_export_item_uniq_desc_per_pat; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.export_item
    ADD CONSTRAINT clin_export_item_uniq_desc_per_pat UNIQUE (fk_identity, description);


--
-- Name: export_item clin_export_item_uniq_fk_obj; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.export_item
    ADD CONSTRAINT clin_export_item_uniq_fk_obj UNIQUE (fk_doc_obj);


--
-- Name: external_care clin_ext_care_uniq_fk_issue_per_unit; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.external_care
    ADD CONSTRAINT clin_ext_care_uniq_fk_issue_per_unit UNIQUE (fk_health_issue, fk_org_unit);


--
-- Name: family_history clin_hx_family_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.family_history
    ADD CONSTRAINT clin_hx_family_pkey PRIMARY KEY (pk);


--
-- Name: clin_item_type clin_item_type_code_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_item_type
    ADD CONSTRAINT clin_item_type_code_key UNIQUE (code);


--
-- Name: clin_item_type clin_item_type_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_item_type
    ADD CONSTRAINT clin_item_type_pkey PRIMARY KEY (pk);


--
-- Name: clin_item_type clin_item_type_type_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_item_type
    ADD CONSTRAINT clin_item_type_type_key UNIQUE (type);


--
-- Name: lnk_code2aoe clin_lc2aoe_code_uniq_per_item; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2aoe
    ADD CONSTRAINT clin_lc2aoe_code_uniq_per_item UNIQUE (fk_generic_code, fk_item);


--
-- Name: lnk_code2episode clin_lc2epi_code_uniq_per_item; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2episode
    ADD CONSTRAINT clin_lc2epi_code_uniq_per_item UNIQUE (fk_generic_code, fk_item);


--
-- Name: lnk_code2fhx clin_lc2fhx_code_uniq_per_item; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2fhx
    ADD CONSTRAINT clin_lc2fhx_code_uniq_per_item UNIQUE (fk_generic_code, fk_item);


--
-- Name: lnk_code2h_issue clin_lc2h_issue_code_uniq_per_item; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2h_issue
    ADD CONSTRAINT clin_lc2h_issue_code_uniq_per_item UNIQUE (fk_generic_code, fk_item);


--
-- Name: lnk_code2narrative clin_lc2narr_code_uniq_per_item; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2narrative
    ADD CONSTRAINT clin_lc2narr_code_uniq_per_item UNIQUE (fk_generic_code, fk_item);


--
-- Name: lnk_code2procedure clin_lc2proc_code_uniq_per_item; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2procedure
    ADD CONSTRAINT clin_lc2proc_code_uniq_per_item UNIQUE (fk_generic_code, fk_item);


--
-- Name: lnk_code2rfe clin_lc2rfe_code_uniq_per_item; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2rfe
    ADD CONSTRAINT clin_lc2rfe_code_uniq_per_item UNIQUE (fk_generic_code, fk_item);


--
-- Name: lnk_code2tst_pnl clin_lc2tst_pnl_code_uniq_per_item; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2tst_pnl
    ADD CONSTRAINT clin_lc2tst_pnl_code_uniq_per_item UNIQUE (fk_generic_code, fk_item);


--
-- Name: clin_narrative clin_narrative_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_narrative
    ADD CONSTRAINT clin_narrative_pkey PRIMARY KEY (pk);


--
-- Name: patient clin_patient_uniq_fk_identity; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.patient
    ADD CONSTRAINT clin_patient_uniq_fk_identity UNIQUE (fk_identity);


--
-- Name: clin_root_item clin_root_item_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_root_item
    ADD CONSTRAINT clin_root_item_pkey PRIMARY KEY (pk_item);


--
-- Name: test_type clin_test_type_uniq_abbrev_per_org; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_type
    ADD CONSTRAINT clin_test_type_uniq_abbrev_per_org UNIQUE (fk_test_org, abbrev);


--
-- Name: test_type clin_test_type_uniq_name_per_org; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_type
    ADD CONSTRAINT clin_test_type_uniq_name_per_org UNIQUE (fk_test_org, name);


--
-- Name: encounter encounter_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.encounter
    ADD CONSTRAINT encounter_pkey PRIMARY KEY (pk);


--
-- Name: encounter_type encounter_type_description_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.encounter_type
    ADD CONSTRAINT encounter_type_description_key UNIQUE (description);


--
-- Name: encounter_type encounter_type_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.encounter_type
    ADD CONSTRAINT encounter_type_pkey PRIMARY KEY (pk);


--
-- Name: episode episode_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.episode
    ADD CONSTRAINT episode_pkey PRIMARY KEY (pk);


--
-- Name: export_item export_item_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.export_item
    ADD CONSTRAINT export_item_pkey PRIMARY KEY (pk);


--
-- Name: external_care external_care_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.external_care
    ADD CONSTRAINT external_care_pkey PRIMARY KEY (pk);


--
-- Name: fhx_relation_type fhx_relation_type_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.fhx_relation_type
    ADD CONSTRAINT fhx_relation_type_pkey PRIMARY KEY (pk);


--
-- Name: form_data form_data_fk_instance_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.form_data
    ADD CONSTRAINT form_data_fk_instance_key UNIQUE (fk_instance, fk_form_field);


--
-- Name: form_data form_data_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.form_data
    ADD CONSTRAINT form_data_pkey PRIMARY KEY (pk);


--
-- Name: form_instances form_instances_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.form_instances
    ADD CONSTRAINT form_instances_pkey PRIMARY KEY (pk);


--
-- Name: health_issue health_issue_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.health_issue
    ADD CONSTRAINT health_issue_pkey PRIMARY KEY (pk);


--
-- Name: hospital_stay hospital_stay_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.hospital_stay
    ADD CONSTRAINT hospital_stay_pkey PRIMARY KEY (pk);


--
-- Name: incoming_data_unmatchable incoming_data_unmatchable_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.incoming_data_unmatchable
    ADD CONSTRAINT incoming_data_unmatchable_pkey PRIMARY KEY (pk);


--
-- Name: incoming_data_unmatched incoming_data_unmatched_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.incoming_data_unmatched
    ADD CONSTRAINT incoming_data_unmatched_pkey PRIMARY KEY (pk);


--
-- Name: lab_request lab_request_fk_test_org_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lab_request
    ADD CONSTRAINT lab_request_fk_test_org_key UNIQUE (fk_test_org, request_id);


--
-- Name: lab_request lab_request_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lab_request
    ADD CONSTRAINT lab_request_pkey PRIMARY KEY (pk);


--
-- Name: lnk_code2aoe lnk_code2aoe_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2aoe
    ADD CONSTRAINT lnk_code2aoe_pkey PRIMARY KEY (pk);


--
-- Name: lnk_code2episode lnk_code2episode_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2episode
    ADD CONSTRAINT lnk_code2episode_pkey PRIMARY KEY (pk);


--
-- Name: lnk_code2fhx lnk_code2fhx_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2fhx
    ADD CONSTRAINT lnk_code2fhx_pkey PRIMARY KEY (pk);


--
-- Name: lnk_code2h_issue lnk_code2h_issue_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2h_issue
    ADD CONSTRAINT lnk_code2h_issue_pkey PRIMARY KEY (pk);


--
-- Name: lnk_code2item_root lnk_code2item_root_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2item_root
    ADD CONSTRAINT lnk_code2item_root_pkey PRIMARY KEY (pk_lnk_code2item);


--
-- Name: lnk_code2narrative lnk_code2narrative_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2narrative
    ADD CONSTRAINT lnk_code2narrative_pkey PRIMARY KEY (pk);


--
-- Name: lnk_code2procedure lnk_code2procedure_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2procedure
    ADD CONSTRAINT lnk_code2procedure_pkey PRIMARY KEY (pk);


--
-- Name: lnk_code2rfe lnk_code2rfe_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2rfe
    ADD CONSTRAINT lnk_code2rfe_pkey PRIMARY KEY (pk);


--
-- Name: lnk_code2tst_pnl lnk_code2tst_pnl_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2tst_pnl
    ADD CONSTRAINT lnk_code2tst_pnl_pkey PRIMARY KEY (pk);


--
-- Name: lnk_constraint2vacc_course lnk_constraint2vacc_course_fk_vaccination_course_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_constraint2vacc_course
    ADD CONSTRAINT lnk_constraint2vacc_course_fk_vaccination_course_key UNIQUE (fk_vaccination_course, fk_constraint);


--
-- Name: lnk_constraint2vacc_course lnk_constraint2vacc_course_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_constraint2vacc_course
    ADD CONSTRAINT lnk_constraint2vacc_course_pkey PRIMARY KEY (pk);


--
-- Name: lnk_loinc2test_panel lnk_loinc2test_panel_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_loinc2test_panel
    ADD CONSTRAINT lnk_loinc2test_panel_pkey PRIMARY KEY (pk);


--
-- Name: lnk_pat2vaccination_course lnk_pat2vaccination_course_fk_patient_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_pat2vaccination_course
    ADD CONSTRAINT lnk_pat2vaccination_course_fk_patient_key UNIQUE (fk_patient, fk_course);


--
-- Name: lnk_pat2vaccination_course lnk_pat2vaccination_course_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_pat2vaccination_course
    ADD CONSTRAINT lnk_pat2vaccination_course_pkey PRIMARY KEY (pk);


--
-- Name: lnk_substance2episode lnk_substance2episode_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_substance2episode
    ADD CONSTRAINT lnk_substance2episode_pkey PRIMARY KEY (pk);


--
-- Name: lnk_tst2norm lnk_tst2norm_id_test_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_tst2norm
    ADD CONSTRAINT lnk_tst2norm_id_test_key UNIQUE (id_test, id_norm);


--
-- Name: lnk_tst2norm lnk_tst2norm_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_tst2norm
    ADD CONSTRAINT lnk_tst2norm_pkey PRIMARY KEY (id);


--
-- Name: lnk_type2item lnk_type2item_fk_type_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_type2item
    ADD CONSTRAINT lnk_type2item_fk_type_key UNIQUE (fk_type, fk_item);


--
-- Name: lnk_type2item lnk_type2item_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_type2item
    ADD CONSTRAINT lnk_type2item_pkey PRIMARY KEY (pk);


--
-- Name: lnk_vaccination_course2schedule lnk_vaccination_course2schedule_fk_course_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_vaccination_course2schedule
    ADD CONSTRAINT lnk_vaccination_course2schedule_fk_course_key UNIQUE (fk_course);


--
-- Name: lnk_vaccination_course2schedule lnk_vaccination_course2schedule_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_vaccination_course2schedule
    ADD CONSTRAINT lnk_vaccination_course2schedule_pkey PRIMARY KEY (pk);


--
-- Name: patient patient_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.patient
    ADD CONSTRAINT patient_pkey PRIMARY KEY (pk);


--
-- Name: procedure procedure_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.procedure
    ADD CONSTRAINT procedure_pkey PRIMARY KEY (pk);


--
-- Name: review_root review_root_fk_reviewed_row_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.review_root
    ADD CONSTRAINT review_root_fk_reviewed_row_key UNIQUE (fk_reviewed_row, fk_reviewer);


--
-- Name: review_root review_root_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.review_root
    ADD CONSTRAINT review_root_pkey PRIMARY KEY (pk);


--
-- Name: reviewed_test_results reviewed_test_results_fk_reviewed_row_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.reviewed_test_results
    ADD CONSTRAINT reviewed_test_results_fk_reviewed_row_key UNIQUE (fk_reviewed_row, fk_reviewer);


--
-- Name: reviewed_test_results reviewed_test_results_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.reviewed_test_results
    ADD CONSTRAINT reviewed_test_results_pkey PRIMARY KEY (pk);


--
-- Name: soap_cat_ranks soap_cat_ranks_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.soap_cat_ranks
    ADD CONSTRAINT soap_cat_ranks_pkey PRIMARY KEY (pk);


--
-- Name: substance_intake substance_intake_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.substance_intake
    ADD CONSTRAINT substance_intake_pkey PRIMARY KEY (pk);


--
-- Name: suppressed_hint suppressed_hint_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.suppressed_hint
    ADD CONSTRAINT suppressed_hint_pkey PRIMARY KEY (pk);


--
-- Name: test_org test_org_fk_org_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_org
    ADD CONSTRAINT test_org_fk_org_key UNIQUE (fk_org_unit);


--
-- Name: test_org test_org_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_org
    ADD CONSTRAINT test_org_pkey PRIMARY KEY (pk);


--
-- Name: test_panel test_panel_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_panel
    ADD CONSTRAINT test_panel_pkey PRIMARY KEY (pk);


--
-- Name: test_result test_result_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_result
    ADD CONSTRAINT test_result_pkey PRIMARY KEY (pk);


--
-- Name: test_type test_type_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_type
    ADD CONSTRAINT test_type_pkey PRIMARY KEY (pk);


--
-- Name: meta_test_type test_type_unified_code_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.meta_test_type
    ADD CONSTRAINT test_type_unified_code_key UNIQUE (abbrev, name);


--
-- Name: meta_test_type test_type_unified_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.meta_test_type
    ADD CONSTRAINT test_type_unified_pkey PRIMARY KEY (pk);


--
-- Name: reviewed_test_results unique_review_per_row; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.reviewed_test_results
    ADD CONSTRAINT unique_review_per_row UNIQUE (fk_reviewed_row);


--
-- Name: vaccination_course_constraint vaccination_course_constraint_description_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination_course_constraint
    ADD CONSTRAINT vaccination_course_constraint_description_key UNIQUE (description);


--
-- Name: vaccination_course_constraint vaccination_course_constraint_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination_course_constraint
    ADD CONSTRAINT vaccination_course_constraint_pkey PRIMARY KEY (pk);


--
-- Name: vaccination_course vaccination_course_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination_course
    ADD CONSTRAINT vaccination_course_pkey PRIMARY KEY (pk);


--
-- Name: vaccination_definition vaccination_definition_fk_course_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination_definition
    ADD CONSTRAINT vaccination_definition_fk_course_key UNIQUE (fk_course, seq_no);


--
-- Name: vaccination_definition vaccination_definition_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination_definition
    ADD CONSTRAINT vaccination_definition_pkey PRIMARY KEY (id);


--
-- Name: vaccination vaccination_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination
    ADD CONSTRAINT vaccination_pkey PRIMARY KEY (pk);


--
-- Name: vaccination_schedule vaccination_schedule_name_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination_schedule
    ADD CONSTRAINT vaccination_schedule_name_key UNIQUE (name);


--
-- Name: vaccination_schedule vaccination_schedule_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination_schedule
    ADD CONSTRAINT vaccination_schedule_pkey PRIMARY KEY (pk);


--
-- Name: waiting_list waiting_list_list_position_key; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.waiting_list
    ADD CONSTRAINT waiting_list_list_position_key UNIQUE (list_position);


--
-- Name: waiting_list waiting_list_pkey; Type: CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.waiting_list
    ADD CONSTRAINT waiting_list_pkey PRIMARY KEY (pk);


--
-- Name: beh_fall_typ beh_fall_typ_code_key; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.beh_fall_typ
    ADD CONSTRAINT beh_fall_typ_code_key UNIQUE (code);


--
-- Name: beh_fall_typ beh_fall_typ_kurzform_key; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.beh_fall_typ
    ADD CONSTRAINT beh_fall_typ_kurzform_key UNIQUE (kurzform);


--
-- Name: beh_fall_typ beh_fall_typ_name_key; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.beh_fall_typ
    ADD CONSTRAINT beh_fall_typ_name_key UNIQUE (name);


--
-- Name: beh_fall_typ beh_fall_typ_pkey; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.beh_fall_typ
    ADD CONSTRAINT beh_fall_typ_pkey PRIMARY KEY (pk);


--
-- Name: kvk kvk_pkey; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.kvk
    ADD CONSTRAINT kvk_pkey PRIMARY KEY (pk);


--
-- Name: lab_test_gnr lab_test_gnr_pkey; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.lab_test_gnr
    ADD CONSTRAINT lab_test_gnr_pkey PRIMARY KEY (id);


--
-- Name: payment_method payment_method_description_key; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.payment_method
    ADD CONSTRAINT payment_method_description_key UNIQUE (description);


--
-- Name: payment_method payment_method_pkey; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.payment_method
    ADD CONSTRAINT payment_method_pkey PRIMARY KEY (pk);


--
-- Name: prax_geb_paid prax_geb_paid_pkey; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.prax_geb_paid
    ADD CONSTRAINT prax_geb_paid_pkey PRIMARY KEY (pk);


--
-- Name: zuzahlungsbefreiung zuzahlungsbefreiung_pkey; Type: CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.zuzahlungsbefreiung
    ADD CONSTRAINT zuzahlungsbefreiung_pkey PRIMARY KEY (id);


--
-- Name: address address_id_street_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.address
    ADD CONSTRAINT address_id_street_key UNIQUE (id_street, aux_street, number, subunit, addendum);


--
-- Name: address address_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.address
    ADD CONSTRAINT address_pkey PRIMARY KEY (id);


--
-- Name: address_type address_type_name_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.address_type
    ADD CONSTRAINT address_type_name_key UNIQUE (name);


--
-- Name: address_type address_type_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.address_type
    ADD CONSTRAINT address_type_pkey PRIMARY KEY (id);


--
-- Name: country country_code_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.country
    ADD CONSTRAINT country_code_key UNIQUE (code);


--
-- Name: country country_name_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.country
    ADD CONSTRAINT country_name_key UNIQUE (name);


--
-- Name: country country_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.country
    ADD CONSTRAINT country_pkey PRIMARY KEY (id);


--
-- Name: identity_tag dem_identity_tag_uniq_tag; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.identity_tag
    ADD CONSTRAINT dem_identity_tag_uniq_tag UNIQUE (fk_identity, fk_tag);


--
-- Name: org dem_org_uniq_desc; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org
    ADD CONSTRAINT dem_org_uniq_desc UNIQUE (description);


--
-- Name: praxis_branch dem_praxis_branch_uniq_fk_org_unit; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.praxis_branch
    ADD CONSTRAINT dem_praxis_branch_uniq_fk_org_unit UNIQUE (fk_org_unit);


--
-- Name: enum_comm_types enum_comm_types_description_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.enum_comm_types
    ADD CONSTRAINT enum_comm_types_description_key UNIQUE (description);


--
-- Name: enum_comm_types enum_comm_types_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.enum_comm_types
    ADD CONSTRAINT enum_comm_types_pkey PRIMARY KEY (pk);


--
-- Name: enum_ext_id_types enum_ext_id_types_name_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.enum_ext_id_types
    ADD CONSTRAINT enum_ext_id_types_name_key UNIQUE (name, issuer);


--
-- Name: enum_ext_id_types enum_ext_id_types_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.enum_ext_id_types
    ADD CONSTRAINT enum_ext_id_types_pkey PRIMARY KEY (pk);


--
-- Name: gender_label gender_label_label_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.gender_label
    ADD CONSTRAINT gender_label_label_key UNIQUE (label);


--
-- Name: gender_label gender_label_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.gender_label
    ADD CONSTRAINT gender_label_pkey PRIMARY KEY (pk);


--
-- Name: gender_label gender_label_tag_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.gender_label
    ADD CONSTRAINT gender_label_tag_key UNIQUE (tag);


--
-- Name: identity identity_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.identity
    ADD CONSTRAINT identity_pkey PRIMARY KEY (pk);


--
-- Name: identity_tag identity_tag_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.identity_tag
    ADD CONSTRAINT identity_tag_pkey PRIMARY KEY (pk);


--
-- Name: inbox_item_category inbox_item_category_description_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.inbox_item_category
    ADD CONSTRAINT inbox_item_category_description_key UNIQUE (description);


--
-- Name: inbox_item_category inbox_item_category_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.inbox_item_category
    ADD CONSTRAINT inbox_item_category_pkey PRIMARY KEY (pk);


--
-- Name: inbox_item_type inbox_item_type_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.inbox_item_type
    ADD CONSTRAINT inbox_item_type_pkey PRIMARY KEY (pk);


--
-- Name: inbox_item_type inbox_item_type_uniq_desc_cat; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.inbox_item_type
    ADD CONSTRAINT inbox_item_type_uniq_desc_cat UNIQUE (description, fk_inbox_item_category);


--
-- Name: lnk_identity2comm lnk_identity2comm_id_identity_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_identity2comm
    ADD CONSTRAINT lnk_identity2comm_id_identity_key UNIQUE (fk_identity, url);


--
-- Name: lnk_identity2comm lnk_identity2comm_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_identity2comm
    ADD CONSTRAINT lnk_identity2comm_pkey PRIMARY KEY (pk);


--
-- Name: lnk_identity2ext_id lnk_identity2ext_id_id_identity_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_identity2ext_id
    ADD CONSTRAINT lnk_identity2ext_id_id_identity_key UNIQUE (id_identity, external_id, fk_origin);


--
-- Name: lnk_identity2ext_id lnk_identity2ext_id_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_identity2ext_id
    ADD CONSTRAINT lnk_identity2ext_id_pkey PRIMARY KEY (id);


--
-- Name: lnk_job2person lnk_job2person_id_identity_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_job2person
    ADD CONSTRAINT lnk_job2person_id_identity_key UNIQUE (fk_identity, fk_occupation);


--
-- Name: lnk_job2person lnk_job2person_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_job2person
    ADD CONSTRAINT lnk_job2person_pkey PRIMARY KEY (pk);


--
-- Name: lnk_org_unit2comm lnk_org_unit2comm_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_org_unit2comm
    ADD CONSTRAINT lnk_org_unit2comm_pkey PRIMARY KEY (pk);


--
-- Name: lnk_org_unit2comm lnk_org_unit2comm_uniq_url; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_org_unit2comm
    ADD CONSTRAINT lnk_org_unit2comm_uniq_url UNIQUE (fk_org_unit, url, fk_type);


--
-- Name: lnk_org_unit2ext_id lnk_org_unit2ext_id_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_org_unit2ext_id
    ADD CONSTRAINT lnk_org_unit2ext_id_pkey PRIMARY KEY (pk);


--
-- Name: lnk_org_unit2ext_id lnk_org_unit2ext_id_uniq_id; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_org_unit2ext_id
    ADD CONSTRAINT lnk_org_unit2ext_id_uniq_id UNIQUE (fk_org_unit, external_id, fk_type);


--
-- Name: lnk_person2relative lnk_person2relative_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person2relative
    ADD CONSTRAINT lnk_person2relative_pkey PRIMARY KEY (id);


--
-- Name: lnk_person_org_address lnk_person_org_address_id_identity_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person_org_address
    ADD CONSTRAINT lnk_person_org_address_id_identity_key UNIQUE (id_identity, id_address);


--
-- Name: lnk_person_org_address lnk_person_org_address_id_org_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person_org_address
    ADD CONSTRAINT lnk_person_org_address_id_org_key UNIQUE (id_org, id_address);


--
-- Name: lnk_person_org_address lnk_person_org_address_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person_org_address
    ADD CONSTRAINT lnk_person_org_address_pkey PRIMARY KEY (id);


--
-- Name: marital_status marital_status_name_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.marital_status
    ADD CONSTRAINT marital_status_name_key UNIQUE (name);


--
-- Name: marital_status marital_status_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.marital_status
    ADD CONSTRAINT marital_status_pkey PRIMARY KEY (pk);


--
-- Name: name_gender_map name_gender_map_name_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.name_gender_map
    ADD CONSTRAINT name_gender_map_name_key UNIQUE (name);


--
-- Name: name_gender_map name_gender_map_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.name_gender_map
    ADD CONSTRAINT name_gender_map_pkey PRIMARY KEY (id);


--
-- Name: names names_id_identity_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.names
    ADD CONSTRAINT names_id_identity_key UNIQUE (id_identity, lastnames, firstnames);


--
-- Name: names names_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.names
    ADD CONSTRAINT names_pkey PRIMARY KEY (id);


--
-- Name: occupation occupation_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.occupation
    ADD CONSTRAINT occupation_pkey PRIMARY KEY (id);


--
-- Name: org_category org_category_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org_category
    ADD CONSTRAINT org_category_pkey PRIMARY KEY (pk);


--
-- Name: org org_pkey1; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org
    ADD CONSTRAINT org_pkey1 PRIMARY KEY (pk);


--
-- Name: org_unit org_unit_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org_unit
    ADD CONSTRAINT org_unit_pkey PRIMARY KEY (pk);


--
-- Name: org_unit org_unit_uniq_per_org; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org_unit
    ADD CONSTRAINT org_unit_uniq_per_org UNIQUE (fk_org, description);


--
-- Name: praxis_branch praxis_branch_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.praxis_branch
    ADD CONSTRAINT praxis_branch_pkey PRIMARY KEY (pk);


--
-- Name: message_inbox provider_inbox_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.message_inbox
    ADD CONSTRAINT provider_inbox_pkey PRIMARY KEY (pk);


--
-- Name: relation_types relation_types_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.relation_types
    ADD CONSTRAINT relation_types_pkey PRIMARY KEY (id);


--
-- Name: staff staff_db_user_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.staff
    ADD CONSTRAINT staff_db_user_key UNIQUE (db_user);


--
-- Name: staff staff_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.staff
    ADD CONSTRAINT staff_pkey PRIMARY KEY (pk);


--
-- Name: staff staff_short_alias_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.staff
    ADD CONSTRAINT staff_short_alias_key UNIQUE (short_alias);


--
-- Name: region state_code_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.region
    ADD CONSTRAINT state_code_key UNIQUE (code, country);


--
-- Name: region state_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.region
    ADD CONSTRAINT state_pkey PRIMARY KEY (pk);


--
-- Name: street street_id_urb_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.street
    ADD CONSTRAINT street_id_urb_key UNIQUE (id_urb, name, postcode);


--
-- Name: street street_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.street
    ADD CONSTRAINT street_pkey PRIMARY KEY (id);


--
-- Name: urb urb_id_state_key; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.urb
    ADD CONSTRAINT urb_id_state_key UNIQUE (fk_region, postcode, name);


--
-- Name: urb urb_pkey; Type: CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.urb
    ADD CONSTRAINT urb_pkey PRIMARY KEY (id);


--
-- Name: access_log access_log_pkey; Type: CONSTRAINT; Schema: gm; Owner: gm-dbo
--

ALTER TABLE ONLY gm.access_log
    ADD CONSTRAINT access_log_pkey PRIMARY KEY (pk);


--
-- Name: schema_revision gm_schema_revision_filename_key; Type: CONSTRAINT; Schema: gm; Owner: gm-dbo
--

ALTER TABLE ONLY gm.schema_revision
    ADD CONSTRAINT gm_schema_revision_filename_key UNIQUE (filename, version);


--
-- Name: schema_revision gm_schema_revision_pkey; Type: CONSTRAINT; Schema: gm; Owner: gm-dbo
--

ALTER TABLE ONLY gm.schema_revision
    ADD CONSTRAINT gm_schema_revision_pkey PRIMARY KEY (pk);


--
-- Name: notifying_tables notifying_tables_pkey; Type: CONSTRAINT; Schema: gm; Owner: gm-dbo
--

ALTER TABLE ONLY gm.notifying_tables
    ADD CONSTRAINT notifying_tables_pkey PRIMARY KEY (pk);


--
-- Name: curr_lang curr_lang_pkey; Type: CONSTRAINT; Schema: i18n; Owner: gm-dbo
--

ALTER TABLE ONLY i18n.curr_lang
    ADD CONSTRAINT curr_lang_pkey PRIMARY KEY (pk);


--
-- Name: curr_lang curr_lang_user_key; Type: CONSTRAINT; Schema: i18n; Owner: gm-dbo
--

ALTER TABLE ONLY i18n.curr_lang
    ADD CONSTRAINT curr_lang_user_key UNIQUE (db_user);


--
-- Name: keys keys_orig_key; Type: CONSTRAINT; Schema: i18n; Owner: gm-dbo
--

ALTER TABLE ONLY i18n.keys
    ADD CONSTRAINT keys_orig_key UNIQUE (orig);


--
-- Name: keys keys_pkey; Type: CONSTRAINT; Schema: i18n; Owner: gm-dbo
--

ALTER TABLE ONLY i18n.keys
    ADD CONSTRAINT keys_pkey PRIMARY KEY (pk);


--
-- Name: translations translations_lang_key; Type: CONSTRAINT; Schema: i18n; Owner: gm-dbo
--

ALTER TABLE ONLY i18n.translations
    ADD CONSTRAINT translations_lang_key UNIQUE (lang, orig);


--
-- Name: translations translations_pkey; Type: CONSTRAINT; Schema: i18n; Owner: gm-dbo
--

ALTER TABLE ONLY i18n.translations
    ADD CONSTRAINT translations_pkey PRIMARY KEY (pk);


--
-- Name: basic_unit basic_unit_name_long_key; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.basic_unit
    ADD CONSTRAINT basic_unit_name_long_key UNIQUE (name_long);


--
-- Name: basic_unit basic_unit_name_short_key; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.basic_unit
    ADD CONSTRAINT basic_unit_name_short_key UNIQUE (name_short);


--
-- Name: basic_unit basic_unit_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.basic_unit
    ADD CONSTRAINT basic_unit_pkey PRIMARY KEY (pk);


--
-- Name: form_field_types form_field_types_name_key; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_field_types
    ADD CONSTRAINT form_field_types_name_key UNIQUE (name);


--
-- Name: form_field_types form_field_types_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_field_types
    ADD CONSTRAINT form_field_types_pkey PRIMARY KEY (pk);


--
-- Name: form_fields form_fields_fk_form_key; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_fields
    ADD CONSTRAINT form_fields_fk_form_key UNIQUE (fk_form, long_name);


--
-- Name: form_fields form_fields_fk_form_key1; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_fields
    ADD CONSTRAINT form_fields_fk_form_key1 UNIQUE (fk_form, template_placeholder);


--
-- Name: form_fields form_fields_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_fields
    ADD CONSTRAINT form_fields_pkey PRIMARY KEY (pk);


--
-- Name: form_job_queue form_job_queue_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_job_queue
    ADD CONSTRAINT form_job_queue_pkey PRIMARY KEY (pk);


--
-- Name: form_job_targets form_job_targets_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_job_targets
    ADD CONSTRAINT form_job_targets_pkey PRIMARY KEY (pk);


--
-- Name: form_job_targets form_job_targets_target_key; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_job_targets
    ADD CONSTRAINT form_job_targets_target_key UNIQUE (target);


--
-- Name: form_print_defs form_print_defs_fk_form_key; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_print_defs
    ADD CONSTRAINT form_print_defs_fk_form_key UNIQUE (fk_form);


--
-- Name: form_print_defs form_print_defs_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_print_defs
    ADD CONSTRAINT form_print_defs_pkey PRIMARY KEY (pk);


--
-- Name: gm_client_db_match gm_client_db_match_client_version_key; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.gm_client_db_match
    ADD CONSTRAINT gm_client_db_match_client_version_key UNIQUE (client_version, client_type, db_identity_hash);


--
-- Name: gm_client_db_match gm_client_db_match_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.gm_client_db_match
    ADD CONSTRAINT gm_client_db_match_pkey PRIMARY KEY (pk);


--
-- Name: housekeeping_todo housekeeping_todo_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.housekeeping_todo
    ADD CONSTRAINT housekeeping_todo_pkey PRIMARY KEY (pk);


--
-- Name: test_norm test_norm_fk_ref_src_key; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.test_norm
    ADD CONSTRAINT test_norm_fk_ref_src_key UNIQUE (fk_ref_src, data);


--
-- Name: test_norm test_norm_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.test_norm
    ADD CONSTRAINT test_norm_pkey PRIMARY KEY (pk);


--
-- Name: unit unit_pkey; Type: CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.unit
    ADD CONSTRAINT unit_pkey PRIMARY KEY (pk);


--
-- Name: atc atc_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.atc
    ADD CONSTRAINT atc_pkey PRIMARY KEY (pk);


--
-- Name: auto_hint auto_hint_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.auto_hint
    ADD CONSTRAINT auto_hint_pkey PRIMARY KEY (pk);


--
-- Name: billable billable_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.billable
    ADD CONSTRAINT billable_pkey PRIMARY KEY (pk);


--
-- Name: vaccine clin_vaccine_uniq_brand; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.vaccine
    ADD CONSTRAINT clin_vaccine_uniq_brand UNIQUE (fk_drug_product);


--
-- Name: coda coda_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.coda
    ADD CONSTRAINT coda_pkey PRIMARY KEY (pk);


--
-- Name: code_thesaurus_root code_thesaurus_root_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.code_thesaurus_root
    ADD CONSTRAINT code_thesaurus_root_pkey PRIMARY KEY (pk_thesaurus);


--
-- Name: coding_system_root coding_system_root_fk_data_source_key; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.coding_system_root
    ADD CONSTRAINT coding_system_root_fk_data_source_key UNIQUE (fk_data_source, code);


--
-- Name: coding_system_root coding_system_root_fk_data_source_key1; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.coding_system_root
    ADD CONSTRAINT coding_system_root_fk_data_source_key1 UNIQUE (fk_data_source, term);


--
-- Name: coding_system_root coding_system_root_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.coding_system_root
    ADD CONSTRAINT coding_system_root_pkey PRIMARY KEY (pk_coding_system);


--
-- Name: data_source data_source_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.data_source
    ADD CONSTRAINT data_source_pkey PRIMARY KEY (pk);


--
-- Name: data_source data_source_version_key; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.data_source
    ADD CONSTRAINT data_source_version_key UNIQUE (version, name_long);


--
-- Name: data_source data_source_version_key1; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.data_source
    ADD CONSTRAINT data_source_version_key1 UNIQUE (version, name_short);


--
-- Name: document_type document_type_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.document_type
    ADD CONSTRAINT document_type_pkey PRIMARY KEY (pk);


--
-- Name: dose dose_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.dose
    ADD CONSTRAINT dose_pkey PRIMARY KEY (pk);


--
-- Name: form_types form_types_name_key; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.form_types
    ADD CONSTRAINT form_types_name_key UNIQUE (name);


--
-- Name: form_types form_types_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.form_types
    ADD CONSTRAINT form_types_pkey PRIMARY KEY (pk);


--
-- Name: icd10 icd10_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icd10
    ADD CONSTRAINT icd10_pkey PRIMARY KEY (pk);


--
-- Name: icd9 icd9_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icd9
    ADD CONSTRAINT icd9_pkey PRIMARY KEY (pk);


--
-- Name: icpc_chapter icpc_chapter_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc_chapter
    ADD CONSTRAINT icpc_chapter_pkey PRIMARY KEY (pk);


--
-- Name: icpc_component icpc_component_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc_component
    ADD CONSTRAINT icpc_component_pkey PRIMARY KEY (pk);


--
-- Name: icpc icpc_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc
    ADD CONSTRAINT icpc_pkey PRIMARY KEY (pk);


--
-- Name: icpc_thesaurus icpc_thesaurus_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc_thesaurus
    ADD CONSTRAINT icpc_thesaurus_pkey PRIMARY KEY (pk);


--
-- Name: keyword_expansion keyword_expansion_fk_staff_key; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.keyword_expansion
    ADD CONSTRAINT keyword_expansion_fk_staff_key UNIQUE (fk_staff, keyword);


--
-- Name: keyword_expansion keyword_expansion_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.keyword_expansion
    ADD CONSTRAINT keyword_expansion_pkey PRIMARY KEY (pk);


--
-- Name: lnk_dose2drug lnk_dose2drug_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.lnk_dose2drug
    ADD CONSTRAINT lnk_dose2drug_pkey PRIMARY KEY (pk);


--
-- Name: lnk_loinc2substance lnk_loinc2substance_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.lnk_loinc2substance
    ADD CONSTRAINT lnk_loinc2substance_pkey PRIMARY KEY (pk);


--
-- Name: loinc loinc_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.loinc
    ADD CONSTRAINT loinc_pkey PRIMARY KEY (pk);


--
-- Name: ops ops_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.ops
    ADD CONSTRAINT ops_pkey PRIMARY KEY (pk);


--
-- Name: other_code other_code_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.other_code
    ADD CONSTRAINT other_code_pkey PRIMARY KEY (pk);


--
-- Name: papersizes papersizes_name_key; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.papersizes
    ADD CONSTRAINT papersizes_name_key UNIQUE (name);


--
-- Name: papersizes papersizes_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.papersizes
    ADD CONSTRAINT papersizes_pkey PRIMARY KEY (pk);


--
-- Name: paperwork_templates paperwork_templates_gnumed_revision_key; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.paperwork_templates
    ADD CONSTRAINT paperwork_templates_gnumed_revision_key UNIQUE (gnumed_revision, external_version, name_long);


--
-- Name: paperwork_templates paperwork_templates_name_long_key; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.paperwork_templates
    ADD CONSTRAINT paperwork_templates_name_long_key UNIQUE (name_long, name_short);


--
-- Name: paperwork_templates paperwork_templates_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.paperwork_templates
    ADD CONSTRAINT paperwork_templates_pkey PRIMARY KEY (pk);


--
-- Name: auto_hint ref_auto_hint_uniq_query; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.auto_hint
    ADD CONSTRAINT ref_auto_hint_uniq_query UNIQUE (query);


--
-- Name: auto_hint ref_auto_hint_uniq_title; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.auto_hint
    ADD CONSTRAINT ref_auto_hint_uniq_title UNIQUE (title);


--
-- Name: icpc_chapter ref_icpc_chapter_unique_desc; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc_chapter
    ADD CONSTRAINT ref_icpc_chapter_unique_desc UNIQUE (description);


--
-- Name: icpc_component ref_icpc_component_unique_desc; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc_component
    ADD CONSTRAINT ref_icpc_component_unique_desc UNIQUE (description);


--
-- Name: icpc_chapter ref_icpc_unique_chapter; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc_chapter
    ADD CONSTRAINT ref_icpc_unique_chapter UNIQUE (chapter);


--
-- Name: icpc ref_icpc_unique_code_ext; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc
    ADD CONSTRAINT ref_icpc_unique_code_ext UNIQUE (code, code_extension);


--
-- Name: icpc_component ref_icpc_unique_component; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc_component
    ADD CONSTRAINT ref_icpc_unique_component UNIQUE (component);


--
-- Name: tag_image ref_tag_image_uniq_desc; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.tag_image
    ADD CONSTRAINT ref_tag_image_uniq_desc UNIQUE (description);


--
-- Name: drug_product substance_brand_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.drug_product
    ADD CONSTRAINT substance_brand_pkey PRIMARY KEY (pk);


--
-- Name: substance substance_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.substance
    ADD CONSTRAINT substance_pkey PRIMARY KEY (pk);


--
-- Name: tag_image tag_image_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.tag_image
    ADD CONSTRAINT tag_image_pkey PRIMARY KEY (pk);


--
-- Name: vacc_route vacc_route_abbreviation_key; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.vacc_route
    ADD CONSTRAINT vacc_route_abbreviation_key UNIQUE (abbreviation);


--
-- Name: vacc_route vacc_route_description_key; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.vacc_route
    ADD CONSTRAINT vacc_route_description_key UNIQUE (description);


--
-- Name: vacc_route vacc_route_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.vacc_route
    ADD CONSTRAINT vacc_route_pkey PRIMARY KEY (id);


--
-- Name: vaccine vaccine_pkey; Type: CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.vaccine
    ADD CONSTRAINT vaccine_pkey PRIMARY KEY (pk);


--
-- Name: lab_request lab_request_fk_test_org_key; Type: CONSTRAINT; Schema: staging; Owner: gm-dbo
--

ALTER TABLE ONLY staging.lab_request
    ADD CONSTRAINT lab_request_fk_test_org_key UNIQUE (fk_test_org, request_id);


--
-- Name: lab_request lab_request_pkey; Type: CONSTRAINT; Schema: staging; Owner: gm-dbo
--

ALTER TABLE ONLY staging.lab_request
    ADD CONSTRAINT lab_request_pkey PRIMARY KEY (pk);


--
-- Name: lnk_vacc_ind2subst_dose lnk_vacc_ind2subst_dose_fk_indication_fk_dose_key; Type: CONSTRAINT; Schema: staging; Owner: gm-dbo
--

ALTER TABLE ONLY staging.lnk_vacc_ind2subst_dose
    ADD CONSTRAINT lnk_vacc_ind2subst_dose_fk_indication_fk_dose_key UNIQUE (fk_indication, fk_dose);


--
-- Name: lnk_vacc_ind2subst_dose lnk_vacc_ind2subst_dose_fk_indication_is_live_key; Type: CONSTRAINT; Schema: staging; Owner: gm-dbo
--

ALTER TABLE ONLY staging.lnk_vacc_ind2subst_dose
    ADD CONSTRAINT lnk_vacc_ind2subst_dose_fk_indication_is_live_key UNIQUE (fk_indication, is_live);


--
-- Name: test_result test_result_pkey; Type: CONSTRAINT; Schema: staging; Owner: gm-dbo
--

ALTER TABLE ONLY staging.test_result
    ADD CONSTRAINT test_result_pkey PRIMARY KEY (pk);


--
-- Name: idx_au_referral_fk_encounter; Type: INDEX; Schema: au; Owner: gm-dbo
--

CREATE INDEX idx_au_referral_fk_encounter ON au.referral USING btree (fk_encounter);


--
-- Name: idx_au_referral_fk_episode; Type: INDEX; Schema: au; Owner: gm-dbo
--

CREATE INDEX idx_au_referral_fk_episode ON au.referral USING btree (fk_episode);


--
-- Name: idx_bill_bill_item_fk_bill; Type: INDEX; Schema: bill; Owner: gm-dbo
--

CREATE INDEX idx_bill_bill_item_fk_bill ON bill.bill_item USING btree (fk_bill);


--
-- Name: idx_bill_bill_item_fk_billable; Type: INDEX; Schema: bill; Owner: gm-dbo
--

CREATE INDEX idx_bill_bill_item_fk_billable ON bill.bill_item USING btree (fk_billable);


--
-- Name: idx_lnk_enc_type2billable_fk_billable; Type: INDEX; Schema: bill; Owner: gm-dbo
--

CREATE INDEX idx_lnk_enc_type2billable_fk_billable ON bill.lnk_enc_type2billable USING btree (fk_billable);


--
-- Name: idx_lnk_enc_type2billable_fk_encounter_type; Type: INDEX; Schema: bill; Owner: gm-dbo
--

CREATE INDEX idx_lnk_enc_type2billable_fk_encounter_type ON bill.lnk_enc_type2billable USING btree (fk_encounter_type);


--
-- Name: idx_doc_desc_fk_doc; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_doc_desc_fk_doc ON blobs.doc_desc USING btree (fk_doc);


--
-- Name: idx_doc_med_fk_encounter; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_doc_med_fk_encounter ON blobs.doc_med USING btree (fk_encounter);


--
-- Name: idx_doc_med_fk_episode; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_doc_med_fk_episode ON blobs.doc_med USING btree (fk_episode);


--
-- Name: idx_doc_med_fk_hospital_stay; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_doc_med_fk_hospital_stay ON blobs.doc_med USING btree (fk_hospital_stay);


--
-- Name: idx_doc_med_fk_org_unit; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_doc_med_fk_org_unit ON blobs.doc_med USING btree (fk_org_unit);


--
-- Name: idx_doc_med_fk_type; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_doc_med_fk_type ON blobs.doc_med USING btree (fk_type);


--
-- Name: idx_doc_obj_fk_doc; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_doc_obj_fk_doc ON blobs.doc_obj USING btree (fk_doc);


--
-- Name: idx_doc_obj_fk_intended_reviewer; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_doc_obj_fk_intended_reviewer ON blobs.doc_obj USING btree (fk_intended_reviewer);


--
-- Name: idx_rev_doc_objs_fk_reviewed_row; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_rev_doc_objs_fk_reviewed_row ON blobs.reviewed_doc_objs USING btree (fk_reviewed_row);


--
-- Name: idx_rev_doc_objs_fk_reviewer; Type: INDEX; Schema: blobs; Owner: gm-dbo
--

CREATE INDEX idx_rev_doc_objs_fk_reviewer ON blobs.reviewed_doc_objs USING btree (fk_reviewer);


--
-- Name: idx_c_lc2aoe_fk_item; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_c_lc2aoe_fk_item ON clin.lnk_code2aoe USING btree (fk_item);


--
-- Name: idx_c_lc2epi_fk_item; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_c_lc2epi_fk_item ON clin.lnk_code2episode USING btree (fk_item);


--
-- Name: idx_c_lc2fhx_fk_item; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_c_lc2fhx_fk_item ON clin.lnk_code2fhx USING btree (fk_item);


--
-- Name: idx_c_lc2iss_fk_item; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_c_lc2iss_fk_item ON clin.lnk_code2h_issue USING btree (fk_item);


--
-- Name: idx_c_lc2narr_fk_item; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_c_lc2narr_fk_item ON clin.lnk_code2narrative USING btree (fk_item);


--
-- Name: idx_c_lc2proc_fk_item; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_c_lc2proc_fk_item ON clin.lnk_code2procedure USING btree (fk_item);


--
-- Name: idx_c_lc2rfe_fk_item; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_c_lc2rfe_fk_item ON clin.lnk_code2rfe USING btree (fk_item);


--
-- Name: idx_c_lc2tp_fk_item; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_c_lc2tp_fk_item ON clin.lnk_code2tst_pnl USING btree (fk_item);


--
-- Name: idx_c_subst_int_fk_drug_comp; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_c_subst_int_fk_drug_comp ON clin.substance_intake USING btree (fk_drug_component);


--
-- Name: idx_clin_allergy_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_allergy_fk_encounter ON clin.allergy USING btree (fk_encounter);


--
-- Name: idx_clin_allergy_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_allergy_fk_episode ON clin.allergy USING btree (fk_episode);


--
-- Name: idx_clin_clin_aux_note_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_clin_aux_note_fk_encounter ON clin.clin_aux_note USING btree (fk_encounter);


--
-- Name: idx_clin_clin_aux_note_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_clin_aux_note_fk_episode ON clin.clin_aux_note USING btree (fk_episode);


--
-- Name: idx_clin_clin_narrative_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_clin_narrative_fk_encounter ON clin.clin_narrative USING btree (fk_encounter);


--
-- Name: idx_clin_clin_narrative_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_clin_narrative_fk_episode ON clin.clin_narrative USING btree (fk_episode);


--
-- Name: idx_clin_encounter_fk_location; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_encounter_fk_location ON clin.encounter USING btree (fk_location);


--
-- Name: idx_clin_family_history_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_family_history_fk_encounter ON clin.family_history USING btree (fk_encounter);


--
-- Name: idx_clin_family_history_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_family_history_fk_episode ON clin.family_history USING btree (fk_episode);


--
-- Name: idx_clin_form_instances_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_form_instances_fk_encounter ON clin.form_instances USING btree (fk_encounter);


--
-- Name: idx_clin_form_instances_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_form_instances_fk_episode ON clin.form_instances USING btree (fk_episode);


--
-- Name: idx_clin_hospital_stay_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_hospital_stay_fk_encounter ON clin.hospital_stay USING btree (fk_encounter);


--
-- Name: idx_clin_hospital_stay_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_hospital_stay_fk_episode ON clin.hospital_stay USING btree (fk_episode);


--
-- Name: idx_clin_lab_request_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_lab_request_fk_encounter ON clin.lab_request USING btree (fk_encounter);


--
-- Name: idx_clin_lab_request_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_lab_request_fk_episode ON clin.lab_request USING btree (fk_episode);


--
-- Name: idx_clin_procedure_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_procedure_fk_encounter ON clin.procedure USING btree (fk_encounter);


--
-- Name: idx_clin_procedure_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_procedure_fk_episode ON clin.procedure USING btree (fk_episode);


--
-- Name: idx_clin_substance_intake_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_substance_intake_fk_encounter ON clin.substance_intake USING btree (fk_encounter);


--
-- Name: idx_clin_substance_intake_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_substance_intake_fk_episode ON clin.substance_intake USING btree (fk_episode);


--
-- Name: idx_clin_test_result_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_test_result_fk_encounter ON clin.test_result USING btree (fk_encounter);


--
-- Name: idx_clin_test_result_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_test_result_fk_episode ON clin.test_result USING btree (fk_episode);


--
-- Name: idx_clin_vaccination_clin_when; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_vaccination_clin_when ON clin.vaccination USING btree (clin_when);


--
-- Name: idx_clin_vaccination_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_vaccination_fk_encounter ON clin.vaccination USING btree (fk_encounter);


--
-- Name: idx_clin_vaccination_fk_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_vaccination_fk_episode ON clin.vaccination USING btree (fk_episode);


--
-- Name: idx_clin_vaccination_fk_provider; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_vaccination_fk_provider ON clin.vaccination USING btree (fk_provider);


--
-- Name: idx_clin_vaccination_fk_vaccine; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_clin_vaccination_fk_vaccine ON clin.vaccination USING btree (fk_vaccine);


--
-- Name: idx_clnarr_unique; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_clnarr_unique ON clin.clin_narrative USING btree (fk_encounter, fk_episode, soap_cat, modified_by, md5(narrative));


--
-- Name: idx_cri_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_cri_encounter ON clin.clin_root_item USING btree (fk_encounter);


--
-- Name: idx_cri_episode; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_cri_episode ON clin.clin_root_item USING btree (fk_episode);


--
-- Name: idx_encounter_affirmed; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_encounter_affirmed ON clin.encounter USING btree (last_affirmed);


--
-- Name: idx_encounter_modified_by; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_encounter_modified_by ON clin.encounter USING btree (modified_by);


--
-- Name: idx_encounter_started; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_encounter_started ON clin.encounter USING btree (started);


--
-- Name: idx_episode_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_episode_fk_encounter ON clin.episode USING btree (fk_encounter);


--
-- Name: idx_episode_issue; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_episode_issue ON clin.episode USING btree (fk_health_issue);


--
-- Name: idx_episode_modified_by; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_episode_modified_by ON clin.episode USING btree (modified_by);


--
-- Name: idx_episode_with_issue; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_episode_with_issue ON clin.episode USING btree (fk_health_issue) WHERE (fk_health_issue IS NOT NULL);


--
-- Name: INDEX idx_episode_with_issue; Type: COMMENT; Schema: clin; Owner: gm-dbo
--

COMMENT ON INDEX clin.idx_episode_with_issue IS 'index episodes with associated health issue by their issue';


--
-- Name: idx_episode_without_issue; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_episode_without_issue ON clin.episode USING btree (fk_health_issue) WHERE (fk_health_issue IS NULL);


--
-- Name: INDEX idx_episode_without_issue; Type: COMMENT; Schema: clin; Owner: gm-dbo
--

COMMENT ON INDEX clin.idx_episode_without_issue IS 'index episodes without associated health issue';


--
-- Name: idx_external_care_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_external_care_fk_encounter ON clin.external_care USING btree (fk_encounter);


--
-- Name: idx_external_care_fk_health_issue; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_external_care_fk_health_issue ON clin.external_care USING btree (fk_health_issue);


--
-- Name: idx_external_care_fk_org_unit; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_external_care_fk_org_unit ON clin.external_care USING btree (fk_org_unit);


--
-- Name: idx_health_issue_modified_by; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_health_issue_modified_by ON clin.health_issue USING btree (modified_by);


--
-- Name: idx_ll2tp_uniq_l_per_p; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ll2tp_uniq_l_per_p ON clin.lnk_loinc2test_panel USING btree (fk_test_panel, loinc);


--
-- Name: idx_narrative_modified_by; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_narrative_modified_by ON clin.clin_narrative USING btree (modified_by);


--
-- Name: idx_narrative_soap_cat; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_narrative_soap_cat ON clin.clin_narrative USING btree (soap_cat) WHERE (soap_cat = ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text]));


--
-- Name: idx_pat_per_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_pat_per_encounter ON clin.encounter USING btree (fk_patient);


--
-- Name: idx_rtr_fk_reviewer; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_rtr_fk_reviewer ON clin.reviewed_test_results USING btree (fk_reviewer);


--
-- Name: idx_suppressed_hint_fk_encounter; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_suppressed_hint_fk_encounter ON clin.suppressed_hint USING btree (fk_encounter);


--
-- Name: idx_suppressed_hint_fk_hint; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_suppressed_hint_fk_hint ON clin.suppressed_hint USING btree (fk_hint);


--
-- Name: idx_test_result_fk_type; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_test_result_fk_type ON clin.test_result USING btree (fk_type);


--
-- Name: idx_test_result_status; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_test_result_status ON clin.test_result USING btree (status);


--
-- Name: idx_test_result_unit; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_test_result_unit ON clin.test_result USING btree (val_unit);


--
-- Name: idx_test_type_fk_meta_test_type; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_test_type_fk_meta_test_type ON clin.test_type USING btree (fk_meta_test_type);


--
-- Name: idx_test_type_fk_test_org; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_test_type_fk_test_org ON clin.test_type USING btree (fk_test_org);


--
-- Name: idx_test_type_loinc; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE INDEX idx_test_type_loinc ON clin.test_type USING btree (loinc) WHERE (loinc IS NOT NULL);


--
-- Name: idx_uniq_open_epi_per_issue; Type: INDEX; Schema: clin; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_uniq_open_epi_per_issue ON clin.episode USING btree (is_open, fk_health_issue) WHERE ((fk_health_issue IS NOT NULL) AND is_open);


--
-- Name: idx_dem_address_id_street; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_address_id_street ON dem.address USING btree (id_street);


--
-- Name: idx_dem_identity_fk_emergency_contact; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_identity_fk_emergency_contact ON dem.identity USING btree (fk_emergency_contact);


--
-- Name: idx_dem_identity_fk_marital_status; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_identity_fk_marital_status ON dem.identity USING btree (fk_marital_status);


--
-- Name: idx_dem_identity_fk_primary_provider; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_identity_fk_primary_provider ON dem.identity USING btree (fk_primary_provider);


--
-- Name: idx_dem_names_active_names; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_names_active_names ON dem.names USING btree (id_identity, active) WHERE (active IS TRUE);


--
-- Name: idx_dem_names_firstnames; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_names_firstnames ON dem.names USING btree (firstnames);


--
-- Name: idx_dem_names_firstnames_lower; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_names_firstnames_lower ON dem.names USING btree (lower(firstnames));


--
-- Name: idx_dem_names_firstnames_trgm; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_names_firstnames_trgm ON dem.names USING gin (firstnames pgtrgm.gin_trgm_ops);


--
-- Name: idx_dem_names_id_identity; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_names_id_identity ON dem.names USING btree (id_identity);


--
-- Name: idx_dem_names_lastnames; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_names_lastnames ON dem.names USING btree (lastnames);


--
-- Name: idx_dem_names_lastnames_lower; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_names_lastnames_lower ON dem.names USING btree (lower(lastnames));


--
-- Name: idx_dem_names_lastnames_trgm; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_names_lastnames_trgm ON dem.names USING gin (lastnames pgtrgm.gin_trgm_ops);


--
-- Name: idx_dem_org_category_description; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_dem_org_category_description ON dem.org_category USING btree (lower(description));


--
-- Name: idx_dem_org_fk_category; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_org_fk_category ON dem.org USING btree (fk_category);


--
-- Name: idx_dem_org_unit_fk_address; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_org_unit_fk_address ON dem.org_unit USING btree (fk_address);


--
-- Name: idx_dem_org_unit_fk_category; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_org_unit_fk_category ON dem.org_unit USING btree (fk_category);


--
-- Name: idx_dem_state_code_country; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_dem_state_code_country ON dem.region USING btree (lower(code), country);


--
-- Name: idx_dem_state_country_code; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_state_country_code ON dem.region USING btree (country);


--
-- Name: idx_dem_street_id_urb; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_street_id_urb ON dem.street USING btree (id_urb);


--
-- Name: idx_dem_street_id_urb_name_postcode; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_dem_street_id_urb_name_postcode ON dem.street USING btree (id_urb, lower(name), lower(postcode));


--
-- Name: idx_dem_urb_id_state; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_dem_urb_id_state ON dem.urb USING btree (fk_region);


--
-- Name: idx_dem_urb_id_state_postcode_name; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_dem_urb_id_state_postcode_name ON dem.urb USING btree (fk_region, lower(postcode), lower(name));


--
-- Name: idx_identity_dob_ymd; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_identity_dob_ymd ON dem.identity USING btree (dem.date_trunc_utc('day'::text, dob));


--
-- Name: INDEX idx_identity_dob_ymd; Type: COMMENT; Schema: dem; Owner: gm-dbo
--

COMMENT ON INDEX dem.idx_identity_dob_ymd IS 'When searching for patients per DOB this will usually
	 happen with no more precision than "day". Need to
	 normalize to UTC zone, however.';


--
-- Name: idx_lnk_pers2rel; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_lnk_pers2rel ON dem.lnk_person2relative USING btree (id_identity, id_relation_type);


--
-- Name: idx_msg_inbox_fk_patient; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_msg_inbox_fk_patient ON dem.message_inbox USING btree (fk_patient);


--
-- Name: idx_msg_inbox_fk_staff; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_msg_inbox_fk_staff ON dem.message_inbox USING btree (fk_staff);


--
-- Name: idx_names_last_first; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_names_last_first ON dem.names USING btree (lastnames, firstnames);


--
-- Name: idx_state_names; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_state_names ON dem.region USING btree (name);


--
-- Name: idx_street_names; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_street_names ON dem.street USING btree (name);


--
-- Name: idx_street_zips; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_street_zips ON dem.street USING btree (postcode);


--
-- Name: idx_uniq_act_name; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_uniq_act_name ON dem.names USING btree (id_identity) WHERE (active = true);


--
-- Name: idx_urb_names; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_urb_names ON dem.urb USING btree (name);


--
-- Name: idx_urb_zips; Type: INDEX; Schema: dem; Owner: gm-dbo
--

CREATE INDEX idx_urb_zips ON dem.urb USING btree (postcode);


--
-- Name: idx_orig; Type: INDEX; Schema: i18n; Owner: gm-dbo
--

CREATE INDEX idx_orig ON i18n.translations USING btree (orig);


--
-- Name: idx_branded_drug_uniq_brand_w_code; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_branded_drug_uniq_brand_w_code ON ref.drug_product USING btree (description, preparation, external_code, external_code_type) WHERE (external_code IS NOT NULL);


--
-- Name: idx_c_vaccine_id_route; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_c_vaccine_id_route ON ref.vaccine USING btree (id_route);


--
-- Name: idx_dose_uniq_row; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_dose_uniq_row ON ref.dose USING btree (fk_substance, amount, unit, dose_unit);


--
-- Name: idx_drug_data_source; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_drug_data_source ON ref.drug_product USING btree (fk_data_source);


--
-- Name: idx_drug_description; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_drug_description ON ref.drug_product USING btree (description);


--
-- Name: idx_drug_ext_code; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_drug_ext_code ON ref.drug_product USING btree (external_code);


--
-- Name: idx_drug_product_uniq_product_no_code; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_drug_product_uniq_product_no_code ON ref.drug_product USING btree (description, preparation, is_fake) WHERE (external_code IS NULL);


--
-- Name: idx_ld2d_dose_uniq_per_drug_product; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ld2d_dose_uniq_per_drug_product ON ref.lnk_dose2drug USING btree (fk_dose, fk_drug_product);


--
-- Name: idx_ll2s_uniq_l_per_s; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ll2s_uniq_l_per_s ON ref.lnk_loinc2substance USING btree (fk_substance, loinc);


--
-- Name: idx_ref_atc_code_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_atc_code_unique_per_system ON ref.atc USING btree (fk_data_source, lower(code));


--
-- Name: idx_ref_atc_fk_data_src; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_atc_fk_data_src ON ref.atc USING btree (fk_data_source);


--
-- Name: idx_ref_atc_term_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_atc_term_unique_per_system ON ref.atc USING btree (fk_data_source, lower(code), lower(term));


--
-- Name: idx_ref_billable_code_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_billable_code_unique_per_system ON ref.billable USING btree (fk_data_source, lower(code));


--
-- Name: idx_ref_billable_fk_data_src; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_billable_fk_data_src ON ref.billable USING btree (fk_data_source);


--
-- Name: idx_ref_billable_term_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_billable_term_unique_per_system ON ref.billable USING btree (fk_data_source, lower(code), lower(term));


--
-- Name: idx_ref_coda_code_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_coda_code_unique_per_system ON ref.coda USING btree (fk_data_source, lower(code));


--
-- Name: idx_ref_coda_fk_data_src; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_coda_fk_data_src ON ref.coda USING btree (fk_data_source);


--
-- Name: idx_ref_coda_term_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_coda_term_unique_per_system ON ref.coda USING btree (fk_data_source, lower(code), lower(term));


--
-- Name: idx_ref_data_source_lang; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_data_source_lang ON ref.data_source USING btree (lang);


--
-- Name: idx_ref_icd10_code_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_icd10_code_unique_per_system ON ref.icd10 USING btree (fk_data_source, lower(code));


--
-- Name: idx_ref_icd10_fk_data_src; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_icd10_fk_data_src ON ref.icd10 USING btree (fk_data_source);


--
-- Name: idx_ref_icd10_term_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_icd10_term_unique_per_system ON ref.icd10 USING btree (fk_data_source, lower(code), lower(term));


--
-- Name: idx_ref_icd9_code_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_icd9_code_unique_per_system ON ref.icd9 USING btree (fk_data_source, lower(code));


--
-- Name: idx_ref_icd9_fk_data_src; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_icd9_fk_data_src ON ref.icd9 USING btree (fk_data_source);


--
-- Name: idx_ref_icd9_term_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_icd9_term_unique_per_system ON ref.icd9 USING btree (fk_data_source, lower(code), lower(term));


--
-- Name: idx_ref_icpc_chapter; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_icpc_chapter ON ref.icpc USING btree (fk_chapter);


--
-- Name: idx_ref_icpc_code; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_icpc_code ON ref.icpc USING btree (code);


--
-- Name: idx_ref_icpc_code_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_icpc_code_unique_per_system ON ref.icpc USING btree (fk_data_source, lower(code));


--
-- Name: idx_ref_icpc_component; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_icpc_component ON ref.icpc USING btree (fk_component);


--
-- Name: idx_ref_icpc_fk_data_src; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_icpc_fk_data_src ON ref.icpc USING btree (fk_data_source);


--
-- Name: idx_ref_icpc_pk_coding_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_icpc_pk_coding_system ON ref.icpc USING btree (pk_coding_system);


--
-- Name: idx_ref_icpc_term; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_icpc_term ON ref.icpc USING btree (term);


--
-- Name: idx_ref_icpc_term_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_icpc_term_unique_per_system ON ref.icpc USING btree (fk_data_source, lower(code), lower(term));


--
-- Name: idx_ref_loinc_code_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_loinc_code_unique_per_system ON ref.loinc USING btree (fk_data_source, lower(code));


--
-- Name: idx_ref_loinc_fk_data_src; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_loinc_fk_data_src ON ref.loinc USING btree (fk_data_source);


--
-- Name: idx_ref_loinc_term_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_loinc_term_unique_per_system ON ref.loinc USING btree (fk_data_source, lower(code), lower(term));


--
-- Name: idx_ref_ops_code_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_ops_code_unique_per_system ON ref.ops USING btree (fk_data_source, lower(code));


--
-- Name: idx_ref_ops_fk_data_src; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_ops_fk_data_src ON ref.ops USING btree (fk_data_source);


--
-- Name: idx_ref_ops_term_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_ops_term_unique_per_system ON ref.ops USING btree (fk_data_source, lower(code), lower(term));


--
-- Name: idx_ref_other_code_code_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_other_code_code_unique_per_system ON ref.other_code USING btree (fk_data_source, lower(code));


--
-- Name: idx_ref_other_code_fk_data_src; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_ref_other_code_fk_data_src ON ref.other_code USING btree (fk_data_source);


--
-- Name: idx_ref_other_code_term_unique_per_system; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_ref_other_code_term_unique_per_system ON ref.other_code USING btree (fk_data_source, lower(code), lower(term));


--
-- Name: idx_substance_atc; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE INDEX idx_substance_atc ON ref.substance USING btree (atc);


--
-- Name: idx_substance_desc; Type: INDEX; Schema: ref; Owner: gm-dbo
--

CREATE UNIQUE INDEX idx_substance_desc ON ref.substance USING btree (description);


--
-- Name: lab_request_fk_episode_key; Type: INDEX; Schema: staging; Owner: gm-dbo
--

CREATE INDEX lab_request_fk_episode_key ON staging.lab_request USING btree (fk_episode);


--
-- Name: test_result_fk_episode_key; Type: INDEX; Schema: staging; Owner: gm-dbo
--

CREATE INDEX test_result_fk_episode_key ON staging.test_result USING btree (fk_episode);


--
-- Name: test_result_fk_type_key; Type: INDEX; Schema: staging; Owner: gm-dbo
--

CREATE INDEX test_result_fk_type_key ON staging.test_result USING btree (fk_type);


--
-- Name: audit_fields audit_fields_no_del; Type: RULE; Schema: audit; Owner: gm-dbo
--

CREATE RULE audit_fields_no_del AS
    ON DELETE TO audit.audit_fields DO INSTEAD NOTHING;


--
-- Name: audit_fields audit_fields_no_ins; Type: RULE; Schema: audit; Owner: gm-dbo
--

CREATE RULE audit_fields_no_ins AS
    ON INSERT TO audit.audit_fields DO INSTEAD NOTHING;


--
-- Name: audit_fields audit_fields_no_upd; Type: RULE; Schema: audit; Owner: gm-dbo
--

CREATE RULE audit_fields_no_upd AS
    ON UPDATE TO audit.audit_fields DO INSTEAD NOTHING;


--
-- Name: audit_trail audit_trail_no_del; Type: RULE; Schema: audit; Owner: gm-dbo
--

CREATE RULE audit_trail_no_del AS
    ON DELETE TO audit.audit_trail DO INSTEAD NOTHING;


--
-- Name: audit_trail audit_trail_no_ins; Type: RULE; Schema: audit; Owner: gm-dbo
--

CREATE RULE audit_trail_no_ins AS
    ON INSERT TO audit.audit_trail DO INSTEAD NOTHING;


--
-- Name: audit_trail audit_trail_no_upd; Type: RULE; Schema: audit; Owner: gm-dbo
--

CREATE RULE audit_trail_no_upd AS
    ON UPDATE TO audit.audit_trail DO INSTEAD NOTHING;


--
-- Name: clin_root_item clin_ritem_no_del; Type: RULE; Schema: clin; Owner: gm-dbo
--

CREATE RULE clin_ritem_no_del AS
    ON DELETE TO clin.clin_root_item DO INSTEAD  SELECT clin.f_protect_clin_root_item() AS f_protect_clin_root_item;


--
-- Name: clin_root_item clin_ritem_no_ins; Type: RULE; Schema: clin; Owner: gm-dbo
--

CREATE RULE clin_ritem_no_ins AS
    ON INSERT TO clin.clin_root_item DO INSTEAD  SELECT clin.f_protect_clin_root_item() AS f_protect_clin_root_item;


--
-- Name: identity r_del_identity; Type: RULE; Schema: dem; Owner: gm-dbo
--

CREATE RULE r_del_identity AS
    ON DELETE TO dem.identity DO INSTEAD  UPDATE dem.identity SET deleted = true
  WHERE (identity.pk = old.pk);


--
-- Name: referral tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: au; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON au.referral FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: referral zt_del_referral; Type: TRIGGER; Schema: au; Owner: gm-dbo
--

CREATE TRIGGER zt_del_referral BEFORE DELETE ON au.referral FOR EACH ROW EXECUTE FUNCTION audit.ft_del_referral();


--
-- Name: referral zt_ins_referral; Type: TRIGGER; Schema: au; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_referral BEFORE INSERT ON au.referral FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_referral();


--
-- Name: referral zt_upd_referral; Type: TRIGGER; Schema: au; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_referral BEFORE UPDATE ON au.referral FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_referral();


--
-- Name: bill_item tr_prevent_empty_bills; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_prevent_empty_bills AFTER DELETE OR UPDATE ON bill.bill_item DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION bill.trf_prevent_empty_bills();


--
-- Name: bill tr_prevent_mislinked_bills; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE TRIGGER tr_prevent_mislinked_bills BEFORE INSERT OR UPDATE ON bill.bill FOR EACH ROW EXECUTE FUNCTION bill.trf_prevent_mislinked_bills();


--
-- Name: bill zt_del_bill; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE TRIGGER zt_del_bill BEFORE DELETE ON bill.bill FOR EACH ROW EXECUTE FUNCTION audit.ft_del_bill();


--
-- Name: bill_item zt_del_bill_item; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE TRIGGER zt_del_bill_item BEFORE DELETE ON bill.bill_item FOR EACH ROW EXECUTE FUNCTION audit.ft_del_bill_item();


--
-- Name: bill zt_ins_bill; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_bill BEFORE INSERT ON bill.bill FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_bill();


--
-- Name: bill_item zt_ins_bill_item; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_bill_item BEFORE INSERT ON bill.bill_item FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_bill_item();


--
-- Name: bill zt_upd_bill; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_bill BEFORE UPDATE ON bill.bill FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_bill();


--
-- Name: bill_item zt_upd_bill_item; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_bill_item BEFORE UPDATE ON bill.bill_item FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_bill_item();


--
-- Name: bill zzz_tr_announce_bill_bill_del; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_bill_bill_del AFTER DELETE ON bill.bill DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=bill.bill::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: bill zzz_tr_announce_bill_bill_ins_upd; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_bill_bill_ins_upd AFTER INSERT OR UPDATE ON bill.bill DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=bill.bill::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: bill_item zzz_tr_announce_bill_bill_item_del; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_bill_bill_item_del AFTER DELETE ON bill.bill_item DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=bill.bill_item::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: bill_item zzz_tr_announce_bill_bill_item_ins_upd; Type: TRIGGER; Schema: bill; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_bill_bill_item_ins_upd AFTER INSERT OR UPDATE ON bill.bill_item DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=bill.bill_item::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: lnk_doc_med2episode tr_do_not_duplicate_primary_episode_in_link_table; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER tr_do_not_duplicate_primary_episode_in_link_table BEFORE INSERT OR UPDATE ON blobs.lnk_doc_med2episode FOR EACH ROW EXECUTE FUNCTION blobs.trf_do_not_duplicate_primary_episode_in_link_table();


--
-- Name: doc_obj tr_mark_unreviewed_on_doc_obj_update; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER tr_mark_unreviewed_on_doc_obj_update AFTER UPDATE ON blobs.doc_obj FOR EACH ROW EXECUTE FUNCTION blobs.trf_mark_unreviewed_on_doc_obj_update();


--
-- Name: doc_med tr_remove_primary_episode_from_link_table; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER tr_remove_primary_episode_from_link_table AFTER INSERT OR UPDATE ON blobs.doc_med FOR EACH ROW EXECUTE FUNCTION blobs.trf_remove_primary_episode_from_link_table();


--
-- Name: doc_med tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON blobs.doc_med FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: doc_obj tr_set_default_intended_reviewer; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER tr_set_default_intended_reviewer BEFORE INSERT OR UPDATE ON blobs.doc_obj FOR EACH ROW EXECUTE FUNCTION blobs.trf_set_intended_reviewer();


--
-- Name: doc_obj tr_verify_page_number; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER tr_verify_page_number BEFORE INSERT OR UPDATE ON blobs.doc_obj FOR EACH ROW EXECUTE FUNCTION blobs.trf_verify_page_number();


--
-- Name: doc_desc zt_del_doc_desc; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER zt_del_doc_desc BEFORE DELETE ON blobs.doc_desc FOR EACH ROW EXECUTE FUNCTION audit.ft_del_doc_desc();


--
-- Name: doc_med zt_del_doc_med; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER zt_del_doc_med BEFORE DELETE ON blobs.doc_med FOR EACH ROW EXECUTE FUNCTION audit.ft_del_doc_med();


--
-- Name: doc_desc zt_ins_doc_desc; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_doc_desc BEFORE INSERT ON blobs.doc_desc FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_doc_desc();


--
-- Name: doc_med zt_ins_doc_med; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_doc_med BEFORE INSERT ON blobs.doc_med FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_doc_med();


--
-- Name: doc_desc zt_upd_doc_desc; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_doc_desc BEFORE UPDATE ON blobs.doc_desc FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_doc_desc();


--
-- Name: doc_med zt_upd_doc_med; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_doc_med BEFORE UPDATE ON blobs.doc_med FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_doc_med();


--
-- Name: doc_med zzz_tr_announce_blobs_doc_med_del; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_blobs_doc_med_del AFTER DELETE ON blobs.doc_med DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=blobs.doc_med::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: doc_med zzz_tr_announce_blobs_doc_med_ins_upd; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_blobs_doc_med_ins_upd AFTER INSERT OR UPDATE ON blobs.doc_med DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=blobs.doc_med::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: doc_obj zzz_tr_announce_blobs_doc_obj_del; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_blobs_doc_obj_del AFTER DELETE ON blobs.doc_obj DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=blobs.doc_obj::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: doc_obj zzz_tr_announce_blobs_doc_obj_ins_upd; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_blobs_doc_obj_ins_upd AFTER INSERT OR UPDATE ON blobs.doc_obj DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=blobs.doc_obj::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: doc_type zzz_tr_announce_blobs_doc_type_del; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_blobs_doc_type_del AFTER DELETE ON blobs.doc_type DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=blobs.doc_type::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: doc_type zzz_tr_announce_blobs_doc_type_ins_upd; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_blobs_doc_type_ins_upd AFTER INSERT OR UPDATE ON blobs.doc_type DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=blobs.doc_type::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: reviewed_doc_objs zzz_tr_announce_blobs_reviewed_doc_objs_del; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_blobs_reviewed_doc_objs_del AFTER DELETE ON blobs.reviewed_doc_objs DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=blobs.reviewed_doc_objs::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: reviewed_doc_objs zzz_tr_announce_blobs_reviewed_doc_objs_ins_upd; Type: TRIGGER; Schema: blobs; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_blobs_reviewed_doc_objs_ins_upd AFTER INSERT OR UPDATE ON blobs.reviewed_doc_objs DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=blobs.reviewed_doc_objs::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: report_query zt_del_report_query; Type: TRIGGER; Schema: cfg; Owner: gm-dbo
--

CREATE TRIGGER zt_del_report_query BEFORE DELETE ON cfg.report_query FOR EACH ROW EXECUTE FUNCTION audit.ft_del_report_query();


--
-- Name: report_query zt_ins_report_query; Type: TRIGGER; Schema: cfg; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_report_query BEFORE INSERT ON cfg.report_query FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_report_query();


--
-- Name: report_query zt_upd_report_query; Type: TRIGGER; Schema: cfg; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_report_query BEFORE UPDATE ON cfg.report_query FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_report_query();


--
-- Name: episode tr_activate_issue_on_opening_episode; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_activate_issue_on_opening_episode AFTER INSERT OR UPDATE ON clin.episode FOR EACH ROW WHEN (((new.fk_health_issue IS NOT NULL) AND (new.is_open IS TRUE))) EXECUTE FUNCTION clin.trf_activate_issue_on_opening_episode();


--
-- Name: external_care tr_clin_ext_care_uniq_issue_per_enc_and_unit_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_clin_ext_care_uniq_issue_per_enc_and_unit_ins_upd AFTER INSERT OR UPDATE ON clin.external_care DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((new.fk_health_issue IS NULL)) EXECUTE FUNCTION clin.trf_check_ext_care_uniq_issue_per_enc_and_unit_ins_upd();


--
-- Name: vaccination_definition tr_del_booster_must_have_base_immunity; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_del_booster_must_have_base_immunity AFTER DELETE ON clin.vaccination_definition FOR EACH ROW EXECUTE FUNCTION clin.f_del_booster_must_have_base_immunity();


--
-- Name: substance_intake tr_del_intake_document_deleted; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_del_intake_document_deleted BEFORE DELETE ON clin.substance_intake FOR EACH ROW EXECUTE FUNCTION clin.trf_del_intake_document_deleted();


--
-- Name: substance_intake tr_del_intake_must_unlink_all_drug_components; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_del_intake_must_unlink_all_drug_components AFTER DELETE ON clin.substance_intake DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION clin.trf_del_intake_must_unlink_all_drug_components();


--
-- Name: allergy_state tr_ensure_one_allergy_state_per_patient; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ensure_one_allergy_state_per_patient BEFORE INSERT OR UPDATE ON clin.allergy_state FOR EACH ROW EXECUTE FUNCTION clin.trf_ensure_one_allergy_state_per_patient();


--
-- Name: vaccination_definition tr_ins_booster_must_have_base_immunity; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_booster_must_have_base_immunity BEFORE INSERT ON clin.vaccination_definition FOR EACH ROW EXECUTE FUNCTION clin.f_ins_booster_must_have_base_immunity();


--
-- Name: lnk_code2aoe tr_ins_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_lc2sth_fk_generic_code BEFORE INSERT ON clin.lnk_code2aoe FOR EACH ROW EXECUTE FUNCTION clin.trf_ins_lc2sth_fk_generic_code();


--
-- Name: lnk_code2episode tr_ins_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_lc2sth_fk_generic_code BEFORE INSERT ON clin.lnk_code2episode FOR EACH ROW EXECUTE FUNCTION clin.trf_ins_lc2sth_fk_generic_code();


--
-- Name: lnk_code2fhx tr_ins_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_lc2sth_fk_generic_code BEFORE INSERT ON clin.lnk_code2fhx FOR EACH ROW EXECUTE FUNCTION clin.trf_ins_lc2sth_fk_generic_code();


--
-- Name: lnk_code2h_issue tr_ins_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_lc2sth_fk_generic_code BEFORE INSERT ON clin.lnk_code2h_issue FOR EACH ROW EXECUTE FUNCTION clin.trf_ins_lc2sth_fk_generic_code();


--
-- Name: lnk_code2narrative tr_ins_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_lc2sth_fk_generic_code BEFORE INSERT ON clin.lnk_code2narrative FOR EACH ROW EXECUTE FUNCTION clin.trf_ins_lc2sth_fk_generic_code();


--
-- Name: lnk_code2procedure tr_ins_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_lc2sth_fk_generic_code BEFORE INSERT ON clin.lnk_code2procedure FOR EACH ROW EXECUTE FUNCTION clin.trf_ins_lc2sth_fk_generic_code();


--
-- Name: lnk_code2rfe tr_ins_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_lc2sth_fk_generic_code BEFORE INSERT ON clin.lnk_code2rfe FOR EACH ROW EXECUTE FUNCTION clin.trf_ins_lc2sth_fk_generic_code();


--
-- Name: lnk_code2tst_pnl tr_ins_lc2tp_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_lc2tp_fk_generic_code BEFORE INSERT ON clin.lnk_code2tst_pnl FOR EACH ROW EXECUTE FUNCTION clin.trf_ins_lc2sth_fk_generic_code();


--
-- Name: export_item tr_ins_upd_export_item_normalize_fk_identity; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_ins_upd_export_item_normalize_fk_identity BEFORE INSERT OR UPDATE ON clin.export_item FOR EACH ROW WHEN ((new.fk_doc_obj IS NOT NULL)) EXECUTE FUNCTION clin.trf_ins_upd_export_item_normalize_fk_identity();


--
-- Name: substance_intake tr_insert_intake_links_all_drug_components; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_insert_intake_links_all_drug_components AFTER INSERT ON clin.substance_intake FOR EACH ROW EXECUTE FUNCTION clin.trf_insert_intake_links_all_drug_components();


--
-- Name: substance_intake tr_insert_intake_prevent_duplicate_component_links; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_insert_intake_prevent_duplicate_component_links BEFORE INSERT ON clin.substance_intake FOR EACH ROW EXECUTE FUNCTION clin.trf_ins_intake_prevent_duplicate_component_links();


--
-- Name: test_result tr_invalidate_review_on_result_change; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_invalidate_review_on_result_change AFTER UPDATE ON clin.test_result FOR EACH ROW EXECUTE FUNCTION clin.trf_invalidate_review_on_result_change();


--
-- Name: procedure tr_normalize_proc_is_ongoing; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_normalize_proc_is_ongoing BEFORE INSERT OR UPDATE ON clin.procedure FOR EACH ROW WHEN ((new.clin_end IS NOT NULL)) EXECUTE FUNCTION clin.trf_normalize_proc_is_ongoing();


--
-- Name: reviewed_test_results tr_notify_reviewer_of_review_change; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_notify_reviewer_of_review_change BEFORE UPDATE ON clin.reviewed_test_results FOR EACH ROW EXECUTE FUNCTION clin.trf_notify_reviewer_of_review_change();


--
-- Name: lnk_type2item tr_rfi_type2item; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_rfi_type2item AFTER INSERT OR UPDATE ON clin.lnk_type2item FOR EACH ROW EXECUTE FUNCTION public.f_rfi_type2item();


--
-- Name: allergy tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.allergy FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: clin_aux_note tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.clin_aux_note FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: clin_narrative tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.clin_narrative FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: clin_root_item tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.clin_root_item FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: family_history tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.family_history FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: form_instances tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.form_instances FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: hospital_stay tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.hospital_stay FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: lab_request tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.lab_request FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: procedure tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.procedure FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: substance_intake tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.substance_intake FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: test_result tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.test_result FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: vaccination tr_sanity_check_enc_epi_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_epi_ins_upd BEFORE INSERT OR UPDATE ON clin.vaccination FOR EACH ROW WHEN ((new.fk_episode IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_epi_ins_upd('fk_encounter', 'fk_episode');


--
-- Name: external_care tr_sanity_check_enc_issue_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_sanity_check_enc_issue_ins_upd AFTER INSERT OR UPDATE ON clin.external_care DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((new.fk_health_issue IS NOT NULL)) EXECUTE FUNCTION clin.trf_sanity_check_enc_issue_ins_upd();


--
-- Name: episode tr_sanity_check_enc_vs_issue_on_epi; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_enc_vs_issue_on_epi BEFORE INSERT OR UPDATE ON clin.episode FOR EACH ROW EXECUTE FUNCTION clin.trf_sanity_check_enc_vs_issue_on_epi();


--
-- Name: procedure tr_sanity_check_procedure_episode; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sanity_check_procedure_episode BEFORE INSERT OR UPDATE ON clin.procedure FOR EACH ROW EXECUTE FUNCTION clin.trf_sanity_check_procedure_episode();


--
-- Name: suppressed_hint tr_sanity_check_uniq_hint_per_pat_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_sanity_check_uniq_hint_per_pat_ins_upd AFTER INSERT OR UPDATE ON clin.suppressed_hint DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION clin.trf_sanity_check_uniq_hint_per_pat_ins_upd();


--
-- Name: encounter tr_set_encounter_timezone; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_set_encounter_timezone BEFORE INSERT OR UPDATE ON clin.encounter FOR EACH ROW EXECUTE FUNCTION public.f_set_encounter_timezone();


--
-- Name: allergy tr_sync_allergic_state_on_allergies_modified; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_sync_allergic_state_on_allergies_modified AFTER INSERT OR DELETE ON clin.allergy FOR EACH ROW EXECUTE FUNCTION clin.trf_sync_allergic_state_on_allergies_modified();


--
-- Name: substance_intake tr_undiscontinue_unsets_reason; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_undiscontinue_unsets_reason BEFORE INSERT OR UPDATE ON clin.substance_intake FOR EACH ROW EXECUTE FUNCTION clin.trf_undiscontinue_unsets_reason();


--
-- Name: lnk_vaccination_course2schedule tr_unique_indication_in_schedule; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_unique_indication_in_schedule BEFORE INSERT OR UPDATE ON clin.lnk_vaccination_course2schedule FOR EACH ROW EXECUTE FUNCTION clin.trf_unique_indication_in_schedule();


--
-- Name: vaccination_definition tr_upd_booster_must_have_base_immunity; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_booster_must_have_base_immunity AFTER UPDATE ON clin.vaccination_definition FOR EACH ROW EXECUTE FUNCTION clin.f_upd_booster_must_have_base_immunity();


--
-- Name: substance_intake tr_upd_intake_must_link_all_drug_components; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_upd_intake_must_link_all_drug_components AFTER UPDATE ON clin.substance_intake DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((new.fk_drug_component IS DISTINCT FROM old.fk_drug_component)) EXECUTE FUNCTION clin.trf_upd_intake_must_link_all_drug_components();


--
-- Name: substance_intake tr_upd_intake_updates_all_drug_components; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_upd_intake_updates_all_drug_components AFTER UPDATE ON clin.substance_intake DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((pg_trigger_depth() = 0)) EXECUTE FUNCTION clin.trf_upd_intake_updates_all_drug_components();


--
-- Name: lnk_code2aoe tr_upd_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_lc2sth_fk_generic_code BEFORE UPDATE ON clin.lnk_code2aoe FOR EACH ROW EXECUTE FUNCTION clin.trf_upd_lc2sth_fk_generic_code();


--
-- Name: lnk_code2episode tr_upd_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_lc2sth_fk_generic_code BEFORE UPDATE ON clin.lnk_code2episode FOR EACH ROW EXECUTE FUNCTION clin.trf_upd_lc2sth_fk_generic_code();


--
-- Name: lnk_code2fhx tr_upd_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_lc2sth_fk_generic_code BEFORE UPDATE ON clin.lnk_code2fhx FOR EACH ROW EXECUTE FUNCTION clin.trf_upd_lc2sth_fk_generic_code();


--
-- Name: lnk_code2h_issue tr_upd_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_lc2sth_fk_generic_code BEFORE UPDATE ON clin.lnk_code2h_issue FOR EACH ROW EXECUTE FUNCTION clin.trf_upd_lc2sth_fk_generic_code();


--
-- Name: lnk_code2narrative tr_upd_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_lc2sth_fk_generic_code BEFORE UPDATE ON clin.lnk_code2narrative FOR EACH ROW EXECUTE FUNCTION clin.trf_upd_lc2sth_fk_generic_code();


--
-- Name: lnk_code2procedure tr_upd_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_lc2sth_fk_generic_code BEFORE UPDATE ON clin.lnk_code2procedure FOR EACH ROW EXECUTE FUNCTION clin.trf_upd_lc2sth_fk_generic_code();


--
-- Name: lnk_code2rfe tr_upd_lc2sth_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_lc2sth_fk_generic_code BEFORE UPDATE ON clin.lnk_code2rfe FOR EACH ROW EXECUTE FUNCTION clin.trf_upd_lc2sth_fk_generic_code();


--
-- Name: lnk_code2tst_pnl tr_upd_lc2tp_fk_generic_code; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_lc2tp_fk_generic_code BEFORE UPDATE ON clin.lnk_code2tst_pnl FOR EACH ROW EXECUTE FUNCTION clin.trf_upd_lc2sth_fk_generic_code();


--
-- Name: substance_intake tr_update_intake_prevent_duplicate_component_links; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER tr_update_intake_prevent_duplicate_component_links AFTER UPDATE ON clin.substance_intake FOR EACH ROW WHEN ((new.fk_drug_component IS DISTINCT FROM old.fk_drug_component)) EXECUTE FUNCTION clin.trf_upd_intake_prevent_duplicate_component_links();


--
-- Name: allergy zt_del_allergy; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_allergy BEFORE DELETE ON clin.allergy FOR EACH ROW EXECUTE FUNCTION audit.ft_del_allergy();


--
-- Name: allergy_state zt_del_allergy_state; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_allergy_state BEFORE DELETE ON clin.allergy_state FOR EACH ROW EXECUTE FUNCTION audit.ft_del_allergy_state();


--
-- Name: clin_aux_note zt_del_clin_aux_note; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_clin_aux_note BEFORE DELETE ON clin.clin_aux_note FOR EACH ROW EXECUTE FUNCTION audit.ft_del_clin_aux_note();


--
-- Name: clin_diag zt_del_clin_diag; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_clin_diag BEFORE DELETE ON clin.clin_diag FOR EACH ROW EXECUTE FUNCTION audit.ft_del_clin_diag();


--
-- Name: clin_item_type zt_del_clin_item_type; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_clin_item_type BEFORE DELETE ON clin.clin_item_type FOR EACH ROW EXECUTE FUNCTION audit.ft_del_clin_item_type();


--
-- Name: clin_narrative zt_del_clin_narrative; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_clin_narrative BEFORE DELETE ON clin.clin_narrative FOR EACH ROW EXECUTE FUNCTION audit.ft_del_clin_narrative();


--
-- Name: encounter zt_del_encounter; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_encounter BEFORE DELETE ON clin.encounter FOR EACH ROW EXECUTE FUNCTION audit.ft_del_encounter();


--
-- Name: episode zt_del_episode; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_episode BEFORE DELETE ON clin.episode FOR EACH ROW EXECUTE FUNCTION audit.ft_del_episode();


--
-- Name: external_care zt_del_external_care; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_external_care BEFORE DELETE ON clin.external_care FOR EACH ROW EXECUTE FUNCTION audit.ft_del_external_care();


--
-- Name: family_history zt_del_family_history; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_family_history BEFORE DELETE ON clin.family_history FOR EACH ROW EXECUTE FUNCTION audit.ft_del_family_history();


--
-- Name: fhx_relation_type zt_del_fhx_relation_type; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_fhx_relation_type BEFORE DELETE ON clin.fhx_relation_type FOR EACH ROW EXECUTE FUNCTION audit.ft_del_fhx_relation_type();


--
-- Name: form_data zt_del_form_data; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_form_data BEFORE DELETE ON clin.form_data FOR EACH ROW EXECUTE FUNCTION audit.ft_del_form_data();


--
-- Name: form_instances zt_del_form_instances; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_form_instances BEFORE DELETE ON clin.form_instances FOR EACH ROW EXECUTE FUNCTION audit.ft_del_form_instances();


--
-- Name: health_issue zt_del_health_issue; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_health_issue BEFORE DELETE ON clin.health_issue FOR EACH ROW EXECUTE FUNCTION audit.ft_del_health_issue();


--
-- Name: hospital_stay zt_del_hospital_stay; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_hospital_stay BEFORE DELETE ON clin.hospital_stay FOR EACH ROW EXECUTE FUNCTION audit.ft_del_hospital_stay();


--
-- Name: incoming_data_unmatchable zt_del_incoming_data_unmatchable; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_incoming_data_unmatchable BEFORE DELETE ON clin.incoming_data_unmatchable FOR EACH ROW EXECUTE FUNCTION audit.ft_del_incoming_data_unmatchable();


--
-- Name: incoming_data_unmatched zt_del_incoming_data_unmatched; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_incoming_data_unmatched BEFORE DELETE ON clin.incoming_data_unmatched FOR EACH ROW EXECUTE FUNCTION audit.ft_del_incoming_data_unmatched();


--
-- Name: lab_request zt_del_lab_request; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lab_request BEFORE DELETE ON clin.lab_request FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lab_request();


--
-- Name: lnk_code2aoe zt_del_lnk_code2aoe; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_code2aoe BEFORE DELETE ON clin.lnk_code2aoe FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_code2aoe();


--
-- Name: lnk_code2episode zt_del_lnk_code2episode; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_code2episode BEFORE DELETE ON clin.lnk_code2episode FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_code2episode();


--
-- Name: lnk_code2fhx zt_del_lnk_code2fhx; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_code2fhx BEFORE DELETE ON clin.lnk_code2fhx FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_code2fhx();


--
-- Name: lnk_code2h_issue zt_del_lnk_code2h_issue; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_code2h_issue BEFORE DELETE ON clin.lnk_code2h_issue FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_code2h_issue();


--
-- Name: lnk_code2narrative zt_del_lnk_code2narrative; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_code2narrative BEFORE DELETE ON clin.lnk_code2narrative FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_code2narrative();


--
-- Name: lnk_code2procedure zt_del_lnk_code2procedure; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_code2procedure BEFORE DELETE ON clin.lnk_code2procedure FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_code2procedure();


--
-- Name: lnk_code2rfe zt_del_lnk_code2rfe; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_code2rfe BEFORE DELETE ON clin.lnk_code2rfe FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_code2rfe();


--
-- Name: lnk_code2tst_pnl zt_del_lnk_code2tst_pnl; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_code2tst_pnl BEFORE DELETE ON clin.lnk_code2tst_pnl FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_code2tst_pnl();


--
-- Name: lnk_constraint2vacc_course zt_del_lnk_constraint2vacc_course; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_constraint2vacc_course BEFORE DELETE ON clin.lnk_constraint2vacc_course FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_constraint2vacc_course();


--
-- Name: lnk_loinc2test_panel zt_del_lnk_loinc2test_panel; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_loinc2test_panel BEFORE DELETE ON clin.lnk_loinc2test_panel FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_loinc2test_panel();


--
-- Name: lnk_pat2vaccination_course zt_del_lnk_pat2vaccination_course; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_pat2vaccination_course BEFORE DELETE ON clin.lnk_pat2vaccination_course FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_pat2vaccination_course();


--
-- Name: lnk_tst2norm zt_del_lnk_tst2norm; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_tst2norm BEFORE DELETE ON clin.lnk_tst2norm FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_tst2norm();


--
-- Name: lnk_type2item zt_del_lnk_type2item; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_type2item BEFORE DELETE ON clin.lnk_type2item FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_type2item();


--
-- Name: lnk_vaccination_course2schedule zt_del_lnk_vaccination_course2schedule; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_vaccination_course2schedule BEFORE DELETE ON clin.lnk_vaccination_course2schedule FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_vaccination_course2schedule();


--
-- Name: patient zt_del_patient; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_patient BEFORE DELETE ON clin.patient FOR EACH ROW EXECUTE FUNCTION audit.ft_del_patient();


--
-- Name: procedure zt_del_procedure; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_procedure BEFORE DELETE ON clin.procedure FOR EACH ROW EXECUTE FUNCTION audit.ft_del_procedure();


--
-- Name: substance_intake zt_del_substance_intake; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_substance_intake BEFORE DELETE ON clin.substance_intake FOR EACH ROW EXECUTE FUNCTION audit.ft_del_substance_intake();


--
-- Name: suppressed_hint zt_del_suppressed_hint; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_suppressed_hint BEFORE DELETE ON clin.suppressed_hint FOR EACH ROW EXECUTE FUNCTION audit.ft_del_suppressed_hint();


--
-- Name: test_org zt_del_test_org; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_test_org BEFORE DELETE ON clin.test_org FOR EACH ROW EXECUTE FUNCTION audit.ft_del_test_org();


--
-- Name: test_panel zt_del_test_panel; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_test_panel BEFORE DELETE ON clin.test_panel FOR EACH ROW EXECUTE FUNCTION audit.ft_del_test_panel();


--
-- Name: test_result zt_del_test_result; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_test_result BEFORE DELETE ON clin.test_result FOR EACH ROW EXECUTE FUNCTION audit.ft_del_test_result();


--
-- Name: test_type zt_del_test_type; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_test_type BEFORE DELETE ON clin.test_type FOR EACH ROW EXECUTE FUNCTION audit.ft_del_test_type();


--
-- Name: vaccination zt_del_vaccination; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_vaccination BEFORE DELETE ON clin.vaccination FOR EACH ROW EXECUTE FUNCTION audit.ft_del_vaccination();


--
-- Name: vaccination_course zt_del_vaccination_course; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_vaccination_course BEFORE DELETE ON clin.vaccination_course FOR EACH ROW EXECUTE FUNCTION audit.ft_del_vaccination_course();


--
-- Name: vaccination_course_constraint zt_del_vaccination_course_constraint; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_vaccination_course_constraint BEFORE DELETE ON clin.vaccination_course_constraint FOR EACH ROW EXECUTE FUNCTION audit.ft_del_vaccination_course_constraint();


--
-- Name: vaccination_definition zt_del_vaccination_definition; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_vaccination_definition BEFORE DELETE ON clin.vaccination_definition FOR EACH ROW EXECUTE FUNCTION audit.ft_del_vaccination_definition();


--
-- Name: vaccination_schedule zt_del_vaccination_schedule; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_vaccination_schedule BEFORE DELETE ON clin.vaccination_schedule FOR EACH ROW EXECUTE FUNCTION audit.ft_del_vaccination_schedule();


--
-- Name: waiting_list zt_del_waiting_list; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_del_waiting_list BEFORE DELETE ON clin.waiting_list FOR EACH ROW EXECUTE FUNCTION audit.ft_del_waiting_list();


--
-- Name: allergy zt_ins_allergy; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_allergy BEFORE INSERT ON clin.allergy FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_allergy();


--
-- Name: allergy_state zt_ins_allergy_state; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_allergy_state BEFORE INSERT ON clin.allergy_state FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_allergy_state();


--
-- Name: clin_aux_note zt_ins_clin_aux_note; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_clin_aux_note BEFORE INSERT ON clin.clin_aux_note FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_clin_aux_note();


--
-- Name: clin_diag zt_ins_clin_diag; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_clin_diag BEFORE INSERT ON clin.clin_diag FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_clin_diag();


--
-- Name: clin_item_type zt_ins_clin_item_type; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_clin_item_type BEFORE INSERT ON clin.clin_item_type FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_clin_item_type();


--
-- Name: clin_narrative zt_ins_clin_narrative; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_clin_narrative BEFORE INSERT ON clin.clin_narrative FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_clin_narrative();


--
-- Name: encounter zt_ins_encounter; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_encounter BEFORE INSERT ON clin.encounter FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_encounter();


--
-- Name: episode zt_ins_episode; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_episode BEFORE INSERT ON clin.episode FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_episode();


--
-- Name: external_care zt_ins_external_care; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_external_care BEFORE INSERT ON clin.external_care FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_external_care();


--
-- Name: family_history zt_ins_family_history; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_family_history BEFORE INSERT ON clin.family_history FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_family_history();


--
-- Name: fhx_relation_type zt_ins_fhx_relation_type; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_fhx_relation_type BEFORE INSERT ON clin.fhx_relation_type FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_fhx_relation_type();


--
-- Name: form_data zt_ins_form_data; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_form_data BEFORE INSERT ON clin.form_data FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_form_data();


--
-- Name: form_instances zt_ins_form_instances; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_form_instances BEFORE INSERT ON clin.form_instances FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_form_instances();


--
-- Name: health_issue zt_ins_health_issue; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_health_issue BEFORE INSERT ON clin.health_issue FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_health_issue();


--
-- Name: hospital_stay zt_ins_hospital_stay; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_hospital_stay BEFORE INSERT ON clin.hospital_stay FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_hospital_stay();


--
-- Name: incoming_data_unmatchable zt_ins_incoming_data_unmatchable; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_incoming_data_unmatchable BEFORE INSERT ON clin.incoming_data_unmatchable FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_incoming_data_unmatchable();


--
-- Name: incoming_data_unmatched zt_ins_incoming_data_unmatched; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_incoming_data_unmatched BEFORE INSERT ON clin.incoming_data_unmatched FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_incoming_data_unmatched();


--
-- Name: lab_request zt_ins_lab_request; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lab_request BEFORE INSERT ON clin.lab_request FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lab_request();


--
-- Name: lnk_code2aoe zt_ins_lnk_code2aoe; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_code2aoe BEFORE INSERT ON clin.lnk_code2aoe FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_code2aoe();


--
-- Name: lnk_code2episode zt_ins_lnk_code2episode; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_code2episode BEFORE INSERT ON clin.lnk_code2episode FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_code2episode();


--
-- Name: lnk_code2fhx zt_ins_lnk_code2fhx; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_code2fhx BEFORE INSERT ON clin.lnk_code2fhx FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_code2fhx();


--
-- Name: lnk_code2h_issue zt_ins_lnk_code2h_issue; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_code2h_issue BEFORE INSERT ON clin.lnk_code2h_issue FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_code2h_issue();


--
-- Name: lnk_code2narrative zt_ins_lnk_code2narrative; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_code2narrative BEFORE INSERT ON clin.lnk_code2narrative FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_code2narrative();


--
-- Name: lnk_code2procedure zt_ins_lnk_code2procedure; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_code2procedure BEFORE INSERT ON clin.lnk_code2procedure FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_code2procedure();


--
-- Name: lnk_code2rfe zt_ins_lnk_code2rfe; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_code2rfe BEFORE INSERT ON clin.lnk_code2rfe FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_code2rfe();


--
-- Name: lnk_code2tst_pnl zt_ins_lnk_code2tst_pnl; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_code2tst_pnl BEFORE INSERT ON clin.lnk_code2tst_pnl FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_code2tst_pnl();


--
-- Name: lnk_constraint2vacc_course zt_ins_lnk_constraint2vacc_course; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_constraint2vacc_course BEFORE INSERT ON clin.lnk_constraint2vacc_course FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_constraint2vacc_course();


--
-- Name: lnk_loinc2test_panel zt_ins_lnk_loinc2test_panel; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_loinc2test_panel BEFORE INSERT ON clin.lnk_loinc2test_panel FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_loinc2test_panel();


--
-- Name: lnk_pat2vaccination_course zt_ins_lnk_pat2vaccination_course; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_pat2vaccination_course BEFORE INSERT ON clin.lnk_pat2vaccination_course FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_pat2vaccination_course();


--
-- Name: lnk_tst2norm zt_ins_lnk_tst2norm; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_tst2norm BEFORE INSERT ON clin.lnk_tst2norm FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_tst2norm();


--
-- Name: lnk_type2item zt_ins_lnk_type2item; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_type2item BEFORE INSERT ON clin.lnk_type2item FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_type2item();


--
-- Name: lnk_vaccination_course2schedule zt_ins_lnk_vaccination_course2schedule; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_vaccination_course2schedule BEFORE INSERT ON clin.lnk_vaccination_course2schedule FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_vaccination_course2schedule();


--
-- Name: patient zt_ins_patient; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_patient BEFORE INSERT ON clin.patient FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_patient();


--
-- Name: procedure zt_ins_procedure; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_procedure BEFORE INSERT ON clin.procedure FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_procedure();


--
-- Name: substance_intake zt_ins_substance_intake; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_substance_intake BEFORE INSERT ON clin.substance_intake FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_substance_intake();


--
-- Name: suppressed_hint zt_ins_suppressed_hint; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_suppressed_hint BEFORE INSERT ON clin.suppressed_hint FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_suppressed_hint();


--
-- Name: test_org zt_ins_test_org; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_test_org BEFORE INSERT ON clin.test_org FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_test_org();


--
-- Name: test_panel zt_ins_test_panel; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_test_panel BEFORE INSERT ON clin.test_panel FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_test_panel();


--
-- Name: test_result zt_ins_test_result; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_test_result BEFORE INSERT ON clin.test_result FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_test_result();


--
-- Name: test_type zt_ins_test_type; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_test_type BEFORE INSERT ON clin.test_type FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_test_type();


--
-- Name: vaccination zt_ins_vaccination; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_vaccination BEFORE INSERT ON clin.vaccination FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_vaccination();


--
-- Name: vaccination_course zt_ins_vaccination_course; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_vaccination_course BEFORE INSERT ON clin.vaccination_course FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_vaccination_course();


--
-- Name: vaccination_course_constraint zt_ins_vaccination_course_constraint; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_vaccination_course_constraint BEFORE INSERT ON clin.vaccination_course_constraint FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_vaccination_course_constraint();


--
-- Name: vaccination_definition zt_ins_vaccination_definition; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_vaccination_definition BEFORE INSERT ON clin.vaccination_definition FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_vaccination_definition();


--
-- Name: vaccination_schedule zt_ins_vaccination_schedule; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_vaccination_schedule BEFORE INSERT ON clin.vaccination_schedule FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_vaccination_schedule();


--
-- Name: waiting_list zt_ins_waiting_list; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_waiting_list BEFORE INSERT ON clin.waiting_list FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_waiting_list();


--
-- Name: allergy zt_upd_allergy; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_allergy BEFORE UPDATE ON clin.allergy FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_allergy();


--
-- Name: allergy_state zt_upd_allergy_state; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_allergy_state BEFORE UPDATE ON clin.allergy_state FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_allergy_state();


--
-- Name: clin_aux_note zt_upd_clin_aux_note; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_clin_aux_note BEFORE UPDATE ON clin.clin_aux_note FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_clin_aux_note();


--
-- Name: clin_diag zt_upd_clin_diag; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_clin_diag BEFORE UPDATE ON clin.clin_diag FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_clin_diag();


--
-- Name: clin_item_type zt_upd_clin_item_type; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_clin_item_type BEFORE UPDATE ON clin.clin_item_type FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_clin_item_type();


--
-- Name: clin_narrative zt_upd_clin_narrative; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_clin_narrative BEFORE UPDATE ON clin.clin_narrative FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_clin_narrative();


--
-- Name: encounter zt_upd_encounter; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_encounter BEFORE UPDATE ON clin.encounter FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_encounter();


--
-- Name: episode zt_upd_episode; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_episode BEFORE UPDATE ON clin.episode FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_episode();


--
-- Name: external_care zt_upd_external_care; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_external_care BEFORE UPDATE ON clin.external_care FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_external_care();


--
-- Name: family_history zt_upd_family_history; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_family_history BEFORE UPDATE ON clin.family_history FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_family_history();


--
-- Name: fhx_relation_type zt_upd_fhx_relation_type; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_fhx_relation_type BEFORE UPDATE ON clin.fhx_relation_type FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_fhx_relation_type();


--
-- Name: form_data zt_upd_form_data; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_form_data BEFORE UPDATE ON clin.form_data FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_form_data();


--
-- Name: form_instances zt_upd_form_instances; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_form_instances BEFORE UPDATE ON clin.form_instances FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_form_instances();


--
-- Name: health_issue zt_upd_health_issue; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_health_issue BEFORE UPDATE ON clin.health_issue FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_health_issue();


--
-- Name: hospital_stay zt_upd_hospital_stay; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_hospital_stay BEFORE UPDATE ON clin.hospital_stay FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_hospital_stay();


--
-- Name: incoming_data_unmatchable zt_upd_incoming_data_unmatchable; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_incoming_data_unmatchable BEFORE UPDATE ON clin.incoming_data_unmatchable FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_incoming_data_unmatchable();


--
-- Name: incoming_data_unmatched zt_upd_incoming_data_unmatched; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_incoming_data_unmatched BEFORE UPDATE ON clin.incoming_data_unmatched FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_incoming_data_unmatched();


--
-- Name: lab_request zt_upd_lab_request; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lab_request BEFORE UPDATE ON clin.lab_request FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lab_request();


--
-- Name: lnk_code2aoe zt_upd_lnk_code2aoe; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_code2aoe BEFORE UPDATE ON clin.lnk_code2aoe FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_code2aoe();


--
-- Name: lnk_code2episode zt_upd_lnk_code2episode; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_code2episode BEFORE UPDATE ON clin.lnk_code2episode FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_code2episode();


--
-- Name: lnk_code2fhx zt_upd_lnk_code2fhx; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_code2fhx BEFORE UPDATE ON clin.lnk_code2fhx FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_code2fhx();


--
-- Name: lnk_code2h_issue zt_upd_lnk_code2h_issue; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_code2h_issue BEFORE UPDATE ON clin.lnk_code2h_issue FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_code2h_issue();


--
-- Name: lnk_code2narrative zt_upd_lnk_code2narrative; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_code2narrative BEFORE UPDATE ON clin.lnk_code2narrative FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_code2narrative();


--
-- Name: lnk_code2procedure zt_upd_lnk_code2procedure; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_code2procedure BEFORE UPDATE ON clin.lnk_code2procedure FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_code2procedure();


--
-- Name: lnk_code2rfe zt_upd_lnk_code2rfe; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_code2rfe BEFORE UPDATE ON clin.lnk_code2rfe FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_code2rfe();


--
-- Name: lnk_code2tst_pnl zt_upd_lnk_code2tst_pnl; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_code2tst_pnl BEFORE UPDATE ON clin.lnk_code2tst_pnl FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_code2tst_pnl();


--
-- Name: lnk_constraint2vacc_course zt_upd_lnk_constraint2vacc_course; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_constraint2vacc_course BEFORE UPDATE ON clin.lnk_constraint2vacc_course FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_constraint2vacc_course();


--
-- Name: lnk_loinc2test_panel zt_upd_lnk_loinc2test_panel; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_loinc2test_panel BEFORE UPDATE ON clin.lnk_loinc2test_panel FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_loinc2test_panel();


--
-- Name: lnk_pat2vaccination_course zt_upd_lnk_pat2vaccination_course; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_pat2vaccination_course BEFORE UPDATE ON clin.lnk_pat2vaccination_course FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_pat2vaccination_course();


--
-- Name: lnk_tst2norm zt_upd_lnk_tst2norm; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_tst2norm BEFORE UPDATE ON clin.lnk_tst2norm FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_tst2norm();


--
-- Name: lnk_type2item zt_upd_lnk_type2item; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_type2item BEFORE UPDATE ON clin.lnk_type2item FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_type2item();


--
-- Name: lnk_vaccination_course2schedule zt_upd_lnk_vaccination_course2schedule; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_vaccination_course2schedule BEFORE UPDATE ON clin.lnk_vaccination_course2schedule FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_vaccination_course2schedule();


--
-- Name: patient zt_upd_patient; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_patient BEFORE UPDATE ON clin.patient FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_patient();


--
-- Name: procedure zt_upd_procedure; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_procedure BEFORE UPDATE ON clin.procedure FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_procedure();


--
-- Name: substance_intake zt_upd_substance_intake; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_substance_intake BEFORE UPDATE ON clin.substance_intake FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_substance_intake();


--
-- Name: suppressed_hint zt_upd_suppressed_hint; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_suppressed_hint BEFORE UPDATE ON clin.suppressed_hint FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_suppressed_hint();


--
-- Name: test_org zt_upd_test_org; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_test_org BEFORE UPDATE ON clin.test_org FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_test_org();


--
-- Name: test_panel zt_upd_test_panel; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_test_panel BEFORE UPDATE ON clin.test_panel FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_test_panel();


--
-- Name: test_result zt_upd_test_result; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_test_result BEFORE UPDATE ON clin.test_result FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_test_result();


--
-- Name: test_type zt_upd_test_type; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_test_type BEFORE UPDATE ON clin.test_type FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_test_type();


--
-- Name: vaccination zt_upd_vaccination; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_vaccination BEFORE UPDATE ON clin.vaccination FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_vaccination();


--
-- Name: vaccination_course zt_upd_vaccination_course; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_vaccination_course BEFORE UPDATE ON clin.vaccination_course FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_vaccination_course();


--
-- Name: vaccination_course_constraint zt_upd_vaccination_course_constraint; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_vaccination_course_constraint BEFORE UPDATE ON clin.vaccination_course_constraint FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_vaccination_course_constraint();


--
-- Name: vaccination_definition zt_upd_vaccination_definition; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_vaccination_definition BEFORE UPDATE ON clin.vaccination_definition FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_vaccination_definition();


--
-- Name: vaccination_schedule zt_upd_vaccination_schedule; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_vaccination_schedule BEFORE UPDATE ON clin.vaccination_schedule FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_vaccination_schedule();


--
-- Name: waiting_list zt_upd_waiting_list; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_waiting_list BEFORE UPDATE ON clin.waiting_list FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_waiting_list();


--
-- Name: allergy zzz_tr_announce_clin_allergy_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_allergy_del AFTER DELETE ON clin.allergy DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.allergy::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: allergy zzz_tr_announce_clin_allergy_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_allergy_ins_upd AFTER INSERT OR UPDATE ON clin.allergy DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.allergy::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: allergy_state zzz_tr_announce_clin_allergy_state_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_allergy_state_del AFTER DELETE ON clin.allergy_state DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.allergy_state::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: allergy_state zzz_tr_announce_clin_allergy_state_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_allergy_state_ins_upd AFTER INSERT OR UPDATE ON clin.allergy_state DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.allergy_state::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: clin_narrative zzz_tr_announce_clin_clin_narrative_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_clin_narrative_del AFTER DELETE ON clin.clin_narrative DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.clin_narrative::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: clin_narrative zzz_tr_announce_clin_clin_narrative_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_clin_narrative_ins_upd AFTER INSERT OR UPDATE ON clin.clin_narrative DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.clin_narrative::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: clin_root_item zzz_tr_announce_clin_clin_root_item_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_clin_root_item_del AFTER DELETE ON clin.clin_root_item DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.clin_root_item::PK name=pk_item', 'select $1.pk_item', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: clin_root_item zzz_tr_announce_clin_clin_root_item_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_clin_root_item_ins_upd AFTER INSERT OR UPDATE ON clin.clin_root_item DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.clin_root_item::PK name=pk_item', 'select $1.pk_item', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: encounter zzz_tr_announce_clin_encounter_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_encounter_del AFTER DELETE ON clin.encounter DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.encounter::PK name=pk', 'select $1.pk', 'select $1.fk_patient');


--
-- Name: encounter zzz_tr_announce_clin_encounter_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_encounter_ins_upd AFTER INSERT OR UPDATE ON clin.encounter DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.encounter::PK name=pk', 'select $1.pk', 'select $1.fk_patient');


--
-- Name: episode zzz_tr_announce_clin_episode_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_episode_del AFTER DELETE ON clin.episode DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.episode::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: episode zzz_tr_announce_clin_episode_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_episode_ins_upd AFTER INSERT OR UPDATE ON clin.episode DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.episode::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: export_item zzz_tr_announce_clin_export_item_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_export_item_del AFTER DELETE ON clin.export_item DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.export_item::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: export_item zzz_tr_announce_clin_export_item_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_export_item_ins_upd AFTER INSERT OR UPDATE ON clin.export_item DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.export_item::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: external_care zzz_tr_announce_clin_external_care_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_external_care_del AFTER DELETE ON clin.external_care DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.external_care::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: external_care zzz_tr_announce_clin_external_care_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_external_care_ins_upd AFTER INSERT OR UPDATE ON clin.external_care DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.external_care::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: family_history zzz_tr_announce_clin_family_history_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_family_history_del AFTER DELETE ON clin.family_history DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.family_history::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: family_history zzz_tr_announce_clin_family_history_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_family_history_ins_upd AFTER INSERT OR UPDATE ON clin.family_history DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.family_history::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: health_issue zzz_tr_announce_clin_health_issue_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_health_issue_del AFTER DELETE ON clin.health_issue DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.health_issue::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: health_issue zzz_tr_announce_clin_health_issue_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_health_issue_ins_upd AFTER INSERT OR UPDATE ON clin.health_issue DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.health_issue::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: hospital_stay zzz_tr_announce_clin_hospital_stay_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_hospital_stay_del AFTER DELETE ON clin.hospital_stay DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.hospital_stay::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: hospital_stay zzz_tr_announce_clin_hospital_stay_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_hospital_stay_ins_upd AFTER INSERT OR UPDATE ON clin.hospital_stay DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.hospital_stay::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: lnk_code2aoe zzz_tr_announce_clin_lnk_code2aoe_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2aoe_del AFTER DELETE ON clin.lnk_code2aoe DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.lnk_code2aoe::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2aoe zzz_tr_announce_clin_lnk_code2aoe_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2aoe_ins_upd AFTER INSERT OR UPDATE ON clin.lnk_code2aoe DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.lnk_code2aoe::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2episode zzz_tr_announce_clin_lnk_code2episode_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2episode_del AFTER DELETE ON clin.lnk_code2episode DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.lnk_code2episode::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2episode zzz_tr_announce_clin_lnk_code2episode_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2episode_ins_upd AFTER INSERT OR UPDATE ON clin.lnk_code2episode DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.lnk_code2episode::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2fhx zzz_tr_announce_clin_lnk_code2fhx_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2fhx_del AFTER DELETE ON clin.lnk_code2fhx DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.lnk_code2fhx::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2fhx zzz_tr_announce_clin_lnk_code2fhx_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2fhx_ins_upd AFTER INSERT OR UPDATE ON clin.lnk_code2fhx DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.lnk_code2fhx::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2h_issue zzz_tr_announce_clin_lnk_code2h_issue_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2h_issue_del AFTER DELETE ON clin.lnk_code2h_issue DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.lnk_code2h_issue::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2h_issue zzz_tr_announce_clin_lnk_code2h_issue_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2h_issue_ins_upd AFTER INSERT OR UPDATE ON clin.lnk_code2h_issue DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.lnk_code2h_issue::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2narrative zzz_tr_announce_clin_lnk_code2narrative_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2narrative_del AFTER DELETE ON clin.lnk_code2narrative DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.lnk_code2narrative::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2narrative zzz_tr_announce_clin_lnk_code2narrative_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2narrative_ins_upd AFTER INSERT OR UPDATE ON clin.lnk_code2narrative DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.lnk_code2narrative::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2procedure zzz_tr_announce_clin_lnk_code2procedure_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2procedure_del AFTER DELETE ON clin.lnk_code2procedure DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.lnk_code2procedure::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2procedure zzz_tr_announce_clin_lnk_code2procedure_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2procedure_ins_upd AFTER INSERT OR UPDATE ON clin.lnk_code2procedure DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.lnk_code2procedure::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2rfe zzz_tr_announce_clin_lnk_code2rfe_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2rfe_del AFTER DELETE ON clin.lnk_code2rfe DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.lnk_code2rfe::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2rfe zzz_tr_announce_clin_lnk_code2rfe_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2rfe_ins_upd AFTER INSERT OR UPDATE ON clin.lnk_code2rfe DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.lnk_code2rfe::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2tst_pnl zzz_tr_announce_clin_lnk_code2tst_pnl_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2tst_pnl_del AFTER DELETE ON clin.lnk_code2tst_pnl DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.lnk_code2tst_pnl::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_code2tst_pnl zzz_tr_announce_clin_lnk_code2tst_pnl_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_code2tst_pnl_ins_upd AFTER INSERT OR UPDATE ON clin.lnk_code2tst_pnl DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.lnk_code2tst_pnl::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_loinc2test_panel zzz_tr_announce_clin_lnk_loinc2test_panel_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_loinc2test_panel_del AFTER DELETE ON clin.lnk_loinc2test_panel DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.lnk_loinc2test_panel::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_loinc2test_panel zzz_tr_announce_clin_lnk_loinc2test_panel_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_lnk_loinc2test_panel_ins_upd AFTER INSERT OR UPDATE ON clin.lnk_loinc2test_panel DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.lnk_loinc2test_panel::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: patient zzz_tr_announce_clin_patient_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_patient_del AFTER DELETE ON clin.patient DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.patient::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: patient zzz_tr_announce_clin_patient_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_patient_ins_upd AFTER INSERT OR UPDATE ON clin.patient DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.patient::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: procedure zzz_tr_announce_clin_procedure_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_procedure_del AFTER DELETE ON clin.procedure DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.procedure::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: procedure zzz_tr_announce_clin_procedure_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_procedure_ins_upd AFTER INSERT OR UPDATE ON clin.procedure DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.procedure::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: reviewed_test_results zzz_tr_announce_clin_reviewed_test_results_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_reviewed_test_results_del AFTER DELETE ON clin.reviewed_test_results DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.reviewed_test_results::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: reviewed_test_results zzz_tr_announce_clin_reviewed_test_results_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_reviewed_test_results_ins_upd AFTER INSERT OR UPDATE ON clin.reviewed_test_results DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.reviewed_test_results::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: substance_intake zzz_tr_announce_clin_substance_intake_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_substance_intake_del AFTER DELETE ON clin.substance_intake DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.substance_intake::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: substance_intake zzz_tr_announce_clin_substance_intake_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_substance_intake_ins_upd AFTER INSERT OR UPDATE ON clin.substance_intake DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.substance_intake::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: suppressed_hint zzz_tr_announce_clin_suppressed_hint_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_suppressed_hint_del AFTER DELETE ON clin.suppressed_hint DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.suppressed_hint::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: suppressed_hint zzz_tr_announce_clin_suppressed_hint_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_suppressed_hint_ins_upd AFTER INSERT OR UPDATE ON clin.suppressed_hint DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.suppressed_hint::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: test_panel zzz_tr_announce_clin_test_panel_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_test_panel_del AFTER DELETE ON clin.test_panel DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.test_panel::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: test_panel zzz_tr_announce_clin_test_panel_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_test_panel_ins_upd AFTER INSERT OR UPDATE ON clin.test_panel DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.test_panel::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: test_result zzz_tr_announce_clin_test_result_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_test_result_del AFTER DELETE ON clin.test_result DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.test_result::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: test_result zzz_tr_announce_clin_test_result_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_test_result_ins_upd AFTER INSERT OR UPDATE ON clin.test_result DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.test_result::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: vaccination zzz_tr_announce_clin_vaccination_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_vaccination_del AFTER DELETE ON clin.vaccination DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.vaccination::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: vaccination zzz_tr_announce_clin_vaccination_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_vaccination_ins_upd AFTER INSERT OR UPDATE ON clin.vaccination DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.vaccination::PK name=pk', 'select $1.pk', 'select fk_patient from clin.encounter where pk = $1.fk_encounter limit 1');


--
-- Name: waiting_list zzz_tr_announce_clin_waiting_list_del; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_waiting_list_del AFTER DELETE ON clin.waiting_list DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=clin.waiting_list::PK name=pk', 'select $1.pk', 'select $1.fk_patient');


--
-- Name: waiting_list zzz_tr_announce_clin_waiting_list_ins_upd; Type: TRIGGER; Schema: clin; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_clin_waiting_list_ins_upd AFTER INSERT OR UPDATE ON clin.waiting_list DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=clin.waiting_list::PK name=pk', 'select $1.pk', 'select $1.fk_patient');


--
-- Name: beh_fall_typ zt_del_beh_fall_typ; Type: TRIGGER; Schema: de_de; Owner: gm-dbo
--

CREATE TRIGGER zt_del_beh_fall_typ BEFORE DELETE ON de_de.beh_fall_typ FOR EACH ROW EXECUTE FUNCTION audit.ft_del_beh_fall_typ();


--
-- Name: lab_test_gnr zt_del_lab_test_gnr; Type: TRIGGER; Schema: de_de; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lab_test_gnr BEFORE DELETE ON de_de.lab_test_gnr FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lab_test_gnr();


--
-- Name: prax_geb_paid zt_del_prax_geb_paid; Type: TRIGGER; Schema: de_de; Owner: gm-dbo
--

CREATE TRIGGER zt_del_prax_geb_paid BEFORE DELETE ON de_de.prax_geb_paid FOR EACH ROW EXECUTE FUNCTION audit.ft_del_prax_geb_paid();


--
-- Name: beh_fall_typ zt_ins_beh_fall_typ; Type: TRIGGER; Schema: de_de; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_beh_fall_typ BEFORE INSERT ON de_de.beh_fall_typ FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_beh_fall_typ();


--
-- Name: lab_test_gnr zt_ins_lab_test_gnr; Type: TRIGGER; Schema: de_de; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lab_test_gnr BEFORE INSERT ON de_de.lab_test_gnr FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lab_test_gnr();


--
-- Name: prax_geb_paid zt_ins_prax_geb_paid; Type: TRIGGER; Schema: de_de; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_prax_geb_paid BEFORE INSERT ON de_de.prax_geb_paid FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_prax_geb_paid();


--
-- Name: beh_fall_typ zt_upd_beh_fall_typ; Type: TRIGGER; Schema: de_de; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_beh_fall_typ BEFORE UPDATE ON de_de.beh_fall_typ FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_beh_fall_typ();


--
-- Name: lab_test_gnr zt_upd_lab_test_gnr; Type: TRIGGER; Schema: de_de; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lab_test_gnr BEFORE UPDATE ON de_de.lab_test_gnr FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lab_test_gnr();


--
-- Name: prax_geb_paid zt_upd_prax_geb_paid; Type: TRIGGER; Schema: de_de; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_prax_geb_paid BEFORE UPDATE ON de_de.prax_geb_paid FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_prax_geb_paid();


--
-- Name: names tr_d_n_assert_unique_named_identity; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_d_n_assert_unique_named_identity AFTER INSERT OR UPDATE ON dem.names DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION dem.assert_unique_named_identity();


--
-- Name: identity tr_ins_d_i_assert_unique_named_identity; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_ins_d_i_assert_unique_named_identity AFTER INSERT ON dem.identity DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION dem.assert_unique_named_identity();


--
-- Name: identity tr_normalize_time_in_dob; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER tr_normalize_time_in_dob BEFORE INSERT OR UPDATE ON dem.identity FOR EACH ROW EXECUTE FUNCTION dem.trf_normalize_time_in_dob();


--
-- Name: identity tr_null_empty_title; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER tr_null_empty_title BEFORE INSERT OR UPDATE ON dem.identity FOR EACH ROW EXECUTE FUNCTION dem.trf_null_empty_title();


--
-- Name: staff tr_prevent_deletion_of_in_use_staff; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER tr_prevent_deletion_of_in_use_staff BEFORE DELETE ON dem.staff FOR EACH ROW EXECUTE FUNCTION dem.trf_prevent_deletion_of_in_use_staff();


--
-- Name: praxis_branch tr_prevent_multiple_praxi; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER tr_prevent_multiple_praxi BEFORE INSERT OR UPDATE ON dem.praxis_branch FOR EACH ROW EXECUTE FUNCTION dem.trf_prevent_multiple_praxi();


--
-- Name: names tr_protect_active_name_of_person; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_protect_active_name_of_person AFTER DELETE OR UPDATE ON dem.names DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION dem.trf_protect_active_name_of_person();


--
-- Name: identity tr_upd_d_i_assert_unique_named_identity; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_upd_d_i_assert_unique_named_identity AFTER UPDATE ON dem.identity DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((new.comment IS DISTINCT FROM old.comment)) EXECUTE FUNCTION dem.assert_unique_named_identity();


--
-- Name: address zt_del_address; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_address BEFORE DELETE ON dem.address FOR EACH ROW EXECUTE FUNCTION audit.ft_del_address();


--
-- Name: gender_label zt_del_gender_label; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_gender_label BEFORE DELETE ON dem.gender_label FOR EACH ROW EXECUTE FUNCTION audit.ft_del_gender_label();


--
-- Name: identity zt_del_identity; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_identity BEFORE DELETE ON dem.identity FOR EACH ROW EXECUTE FUNCTION audit.ft_del_identity();


--
-- Name: identity_tag zt_del_identity_tag; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_identity_tag BEFORE DELETE ON dem.identity_tag FOR EACH ROW EXECUTE FUNCTION audit.ft_del_identity_tag();


--
-- Name: inbox_item_category zt_del_inbox_item_category; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_inbox_item_category BEFORE DELETE ON dem.inbox_item_category FOR EACH ROW EXECUTE FUNCTION audit.ft_del_inbox_item_category();


--
-- Name: inbox_item_type zt_del_inbox_item_type; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_inbox_item_type BEFORE DELETE ON dem.inbox_item_type FOR EACH ROW EXECUTE FUNCTION audit.ft_del_inbox_item_type();


--
-- Name: lnk_identity2ext_id zt_del_lnk_identity2ext_id; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_identity2ext_id BEFORE DELETE ON dem.lnk_identity2ext_id FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_identity2ext_id();


--
-- Name: lnk_job2person zt_del_lnk_job2person; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_job2person BEFORE DELETE ON dem.lnk_job2person FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_job2person();


--
-- Name: lnk_org_unit2comm zt_del_lnk_org_unit2comm; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_org_unit2comm BEFORE DELETE ON dem.lnk_org_unit2comm FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_org_unit2comm();


--
-- Name: lnk_org_unit2ext_id zt_del_lnk_org_unit2ext_id; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_org_unit2ext_id BEFORE DELETE ON dem.lnk_org_unit2ext_id FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_org_unit2ext_id();


--
-- Name: lnk_person2relative zt_del_lnk_person2relative; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_person2relative BEFORE DELETE ON dem.lnk_person2relative FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_person2relative();


--
-- Name: message_inbox zt_del_message_inbox; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_message_inbox BEFORE DELETE ON dem.message_inbox FOR EACH ROW EXECUTE FUNCTION audit.ft_del_message_inbox();


--
-- Name: occupation zt_del_occupation; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_occupation BEFORE DELETE ON dem.occupation FOR EACH ROW EXECUTE FUNCTION audit.ft_del_occupation();


--
-- Name: org zt_del_org; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_org BEFORE DELETE ON dem.org FOR EACH ROW EXECUTE FUNCTION audit.ft_del_org();


--
-- Name: org_unit zt_del_org_unit; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_org_unit BEFORE DELETE ON dem.org_unit FOR EACH ROW EXECUTE FUNCTION audit.ft_del_org_unit();


--
-- Name: praxis_branch zt_del_praxis_branch; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_praxis_branch BEFORE DELETE ON dem.praxis_branch FOR EACH ROW EXECUTE FUNCTION audit.ft_del_praxis_branch();


--
-- Name: region zt_del_region; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_region BEFORE DELETE ON dem.region FOR EACH ROW EXECUTE FUNCTION audit.ft_del_region();


--
-- Name: relation_types zt_del_relation_types; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_relation_types BEFORE DELETE ON dem.relation_types FOR EACH ROW EXECUTE FUNCTION audit.ft_del_relation_types();


--
-- Name: staff zt_del_staff; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_staff BEFORE DELETE ON dem.staff FOR EACH ROW EXECUTE FUNCTION audit.ft_del_staff();


--
-- Name: street zt_del_street; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_street BEFORE DELETE ON dem.street FOR EACH ROW EXECUTE FUNCTION audit.ft_del_street();


--
-- Name: urb zt_del_urb; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_del_urb BEFORE DELETE ON dem.urb FOR EACH ROW EXECUTE FUNCTION audit.ft_del_urb();


--
-- Name: address zt_ins_address; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_address BEFORE INSERT ON dem.address FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_address();


--
-- Name: gender_label zt_ins_gender_label; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_gender_label BEFORE INSERT ON dem.gender_label FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_gender_label();


--
-- Name: identity zt_ins_identity; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_identity BEFORE INSERT ON dem.identity FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_identity();


--
-- Name: identity_tag zt_ins_identity_tag; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_identity_tag BEFORE INSERT ON dem.identity_tag FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_identity_tag();


--
-- Name: inbox_item_category zt_ins_inbox_item_category; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_inbox_item_category BEFORE INSERT ON dem.inbox_item_category FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_inbox_item_category();


--
-- Name: inbox_item_type zt_ins_inbox_item_type; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_inbox_item_type BEFORE INSERT ON dem.inbox_item_type FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_inbox_item_type();


--
-- Name: lnk_identity2ext_id zt_ins_lnk_identity2ext_id; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_identity2ext_id BEFORE INSERT ON dem.lnk_identity2ext_id FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_identity2ext_id();


--
-- Name: lnk_job2person zt_ins_lnk_job2person; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_job2person BEFORE INSERT ON dem.lnk_job2person FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_job2person();


--
-- Name: lnk_org_unit2comm zt_ins_lnk_org_unit2comm; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_org_unit2comm BEFORE INSERT ON dem.lnk_org_unit2comm FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_org_unit2comm();


--
-- Name: lnk_org_unit2ext_id zt_ins_lnk_org_unit2ext_id; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_org_unit2ext_id BEFORE INSERT ON dem.lnk_org_unit2ext_id FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_org_unit2ext_id();


--
-- Name: lnk_person2relative zt_ins_lnk_person2relative; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_person2relative BEFORE INSERT ON dem.lnk_person2relative FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_person2relative();


--
-- Name: message_inbox zt_ins_message_inbox; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_message_inbox BEFORE INSERT ON dem.message_inbox FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_message_inbox();


--
-- Name: occupation zt_ins_occupation; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_occupation BEFORE INSERT ON dem.occupation FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_occupation();


--
-- Name: org zt_ins_org; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_org BEFORE INSERT ON dem.org FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_org();


--
-- Name: org_unit zt_ins_org_unit; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_org_unit BEFORE INSERT ON dem.org_unit FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_org_unit();


--
-- Name: praxis_branch zt_ins_praxis_branch; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_praxis_branch BEFORE INSERT ON dem.praxis_branch FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_praxis_branch();


--
-- Name: region zt_ins_region; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_region BEFORE INSERT ON dem.region FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_region();


--
-- Name: relation_types zt_ins_relation_types; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_relation_types BEFORE INSERT ON dem.relation_types FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_relation_types();


--
-- Name: staff zt_ins_staff; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_staff BEFORE INSERT ON dem.staff FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_staff();


--
-- Name: street zt_ins_street; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_street BEFORE INSERT ON dem.street FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_street();


--
-- Name: urb zt_ins_urb; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_urb BEFORE INSERT ON dem.urb FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_urb();


--
-- Name: address zt_upd_address; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_address BEFORE UPDATE ON dem.address FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_address();


--
-- Name: gender_label zt_upd_gender_label; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_gender_label BEFORE UPDATE ON dem.gender_label FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_gender_label();


--
-- Name: identity zt_upd_identity; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_identity BEFORE UPDATE ON dem.identity FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_identity();


--
-- Name: identity_tag zt_upd_identity_tag; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_identity_tag BEFORE UPDATE ON dem.identity_tag FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_identity_tag();


--
-- Name: inbox_item_category zt_upd_inbox_item_category; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_inbox_item_category BEFORE UPDATE ON dem.inbox_item_category FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_inbox_item_category();


--
-- Name: inbox_item_type zt_upd_inbox_item_type; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_inbox_item_type BEFORE UPDATE ON dem.inbox_item_type FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_inbox_item_type();


--
-- Name: lnk_identity2ext_id zt_upd_lnk_identity2ext_id; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_identity2ext_id BEFORE UPDATE ON dem.lnk_identity2ext_id FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_identity2ext_id();


--
-- Name: lnk_job2person zt_upd_lnk_job2person; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_job2person BEFORE UPDATE ON dem.lnk_job2person FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_job2person();


--
-- Name: lnk_org_unit2comm zt_upd_lnk_org_unit2comm; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_org_unit2comm BEFORE UPDATE ON dem.lnk_org_unit2comm FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_org_unit2comm();


--
-- Name: lnk_org_unit2ext_id zt_upd_lnk_org_unit2ext_id; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_org_unit2ext_id BEFORE UPDATE ON dem.lnk_org_unit2ext_id FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_org_unit2ext_id();


--
-- Name: lnk_person2relative zt_upd_lnk_person2relative; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_person2relative BEFORE UPDATE ON dem.lnk_person2relative FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_person2relative();


--
-- Name: message_inbox zt_upd_message_inbox; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_message_inbox BEFORE UPDATE ON dem.message_inbox FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_message_inbox();


--
-- Name: occupation zt_upd_occupation; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_occupation BEFORE UPDATE ON dem.occupation FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_occupation();


--
-- Name: org zt_upd_org; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_org BEFORE UPDATE ON dem.org FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_org();


--
-- Name: org_unit zt_upd_org_unit; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_org_unit BEFORE UPDATE ON dem.org_unit FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_org_unit();


--
-- Name: praxis_branch zt_upd_praxis_branch; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_praxis_branch BEFORE UPDATE ON dem.praxis_branch FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_praxis_branch();


--
-- Name: region zt_upd_region; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_region BEFORE UPDATE ON dem.region FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_region();


--
-- Name: relation_types zt_upd_relation_types; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_relation_types BEFORE UPDATE ON dem.relation_types FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_relation_types();


--
-- Name: staff zt_upd_staff; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_staff BEFORE UPDATE ON dem.staff FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_staff();


--
-- Name: street zt_upd_street; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_street BEFORE UPDATE ON dem.street FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_street();


--
-- Name: urb zt_upd_urb; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_urb BEFORE UPDATE ON dem.urb FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_urb();


--
-- Name: identity zzz_tr_announce_dem_identity_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_identity_del AFTER DELETE ON dem.identity DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.identity::PK name=pk', 'select $1.pk', 'select $1.pk');


--
-- Name: identity zzz_tr_announce_dem_identity_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_identity_ins_upd AFTER INSERT OR UPDATE ON dem.identity DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.identity::PK name=pk', 'select $1.pk', 'select $1.pk');


--
-- Name: identity_tag zzz_tr_announce_dem_identity_tag_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_identity_tag_del AFTER DELETE ON dem.identity_tag DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.identity_tag::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: identity_tag zzz_tr_announce_dem_identity_tag_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_identity_tag_ins_upd AFTER INSERT OR UPDATE ON dem.identity_tag DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.identity_tag::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: lnk_identity2comm zzz_tr_announce_dem_lnk_identity2comm_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_lnk_identity2comm_del AFTER DELETE ON dem.lnk_identity2comm DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.lnk_identity2comm::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: lnk_identity2comm zzz_tr_announce_dem_lnk_identity2comm_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_lnk_identity2comm_ins_upd AFTER INSERT OR UPDATE ON dem.lnk_identity2comm DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.lnk_identity2comm::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: lnk_identity2ext_id zzz_tr_announce_dem_lnk_identity2ext_id_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_lnk_identity2ext_id_del AFTER DELETE ON dem.lnk_identity2ext_id DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.lnk_identity2ext_id::PK name=id', 'select $1.id', 'select $1.id_identity');


--
-- Name: lnk_identity2ext_id zzz_tr_announce_dem_lnk_identity2ext_id_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_lnk_identity2ext_id_ins_upd AFTER INSERT OR UPDATE ON dem.lnk_identity2ext_id DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.lnk_identity2ext_id::PK name=id', 'select $1.id', 'select $1.id_identity');


--
-- Name: lnk_job2person zzz_tr_announce_dem_lnk_job2person_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_lnk_job2person_del AFTER DELETE ON dem.lnk_job2person DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.lnk_job2person::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: lnk_job2person zzz_tr_announce_dem_lnk_job2person_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_lnk_job2person_ins_upd AFTER INSERT OR UPDATE ON dem.lnk_job2person DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.lnk_job2person::PK name=pk', 'select $1.pk', 'select $1.fk_identity');


--
-- Name: lnk_org_unit2comm zzz_tr_announce_dem_lnk_org_unit2comm_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_lnk_org_unit2comm_del AFTER DELETE ON dem.lnk_org_unit2comm DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.lnk_org_unit2comm::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_org_unit2comm zzz_tr_announce_dem_lnk_org_unit2comm_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_lnk_org_unit2comm_ins_upd AFTER INSERT OR UPDATE ON dem.lnk_org_unit2comm DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.lnk_org_unit2comm::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: message_inbox zzz_tr_announce_dem_message_inbox_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_message_inbox_del AFTER DELETE ON dem.message_inbox DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.message_inbox::PK name=pk', 'select $1.pk', 'select $1.fk_patient');


--
-- Name: message_inbox zzz_tr_announce_dem_message_inbox_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_message_inbox_ins_upd AFTER INSERT OR UPDATE ON dem.message_inbox DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.message_inbox::PK name=pk', 'select $1.pk', 'select $1.fk_patient');


--
-- Name: names zzz_tr_announce_dem_names_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_names_del AFTER DELETE ON dem.names DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.names::PK name=id', 'select $1.id', 'select $1.id_identity');


--
-- Name: names zzz_tr_announce_dem_names_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_names_ins_upd AFTER INSERT OR UPDATE ON dem.names DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.names::PK name=id', 'select $1.id', 'select $1.id_identity');


--
-- Name: org zzz_tr_announce_dem_org_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_org_del AFTER DELETE ON dem.org DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.org::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: org zzz_tr_announce_dem_org_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_org_ins_upd AFTER INSERT OR UPDATE ON dem.org DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.org::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: org_unit zzz_tr_announce_dem_org_unit_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_org_unit_del AFTER DELETE ON dem.org_unit DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.org_unit::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: org_unit zzz_tr_announce_dem_org_unit_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_org_unit_ins_upd AFTER INSERT OR UPDATE ON dem.org_unit DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.org_unit::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: praxis_branch zzz_tr_announce_dem_praxis_branch_del; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_praxis_branch_del AFTER DELETE ON dem.praxis_branch DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=dem.praxis_branch::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: praxis_branch zzz_tr_announce_dem_praxis_branch_ins_upd; Type: TRIGGER; Schema: dem; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_dem_praxis_branch_ins_upd AFTER INSERT OR UPDATE ON dem.praxis_branch DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=dem.praxis_branch::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: access_log zt_del_access_log; Type: TRIGGER; Schema: gm; Owner: gm-dbo
--

CREATE TRIGGER zt_del_access_log BEFORE DELETE ON gm.access_log FOR EACH ROW EXECUTE FUNCTION audit.ft_del_access_log();


--
-- Name: access_log zt_ins_access_log; Type: TRIGGER; Schema: gm; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_access_log BEFORE INSERT ON gm.access_log FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_access_log();


--
-- Name: access_log zt_upd_access_log; Type: TRIGGER; Schema: gm; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_access_log BEFORE UPDATE ON gm.access_log FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_access_log();


--
-- Name: drug_product tr_assert_product_has_components; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_assert_product_has_components AFTER INSERT OR UPDATE ON ref.drug_product DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION ref.trf_assert_product_has_components();


--
-- Name: lnk_dose2drug tr_del_assert_product_keeps_components; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_del_assert_product_keeps_components AFTER DELETE ON ref.lnk_dose2drug DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION ref.trf_assert_product_keeps_components();


--
-- Name: atc tr_del_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_del_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.atc FOR EACH ROW EXECUTE FUNCTION ref.trf_del_ref_code_tbl_check_backlink();


--
-- Name: coda tr_del_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_del_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.coda FOR EACH ROW EXECUTE FUNCTION ref.trf_del_ref_code_tbl_check_backlink();


--
-- Name: icd10 tr_del_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_del_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.icd10 FOR EACH ROW EXECUTE FUNCTION ref.trf_del_ref_code_tbl_check_backlink();


--
-- Name: icd9 tr_del_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_del_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.icd9 FOR EACH ROW EXECUTE FUNCTION ref.trf_del_ref_code_tbl_check_backlink();


--
-- Name: icpc tr_del_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_del_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.icpc FOR EACH ROW EXECUTE FUNCTION ref.trf_del_ref_code_tbl_check_backlink();


--
-- Name: loinc tr_del_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_del_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.loinc FOR EACH ROW EXECUTE FUNCTION ref.trf_del_ref_code_tbl_check_backlink();


--
-- Name: ops tr_del_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_del_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.ops FOR EACH ROW EXECUTE FUNCTION ref.trf_del_ref_code_tbl_check_backlink();


--
-- Name: other_code tr_del_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_del_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.other_code FOR EACH ROW EXECUTE FUNCTION ref.trf_del_ref_code_tbl_check_backlink();


--
-- Name: lnk_dose2drug tr_ins_upd_assert_dose_unit_across_drug_components; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_ins_upd_assert_dose_unit_across_drug_components AFTER INSERT OR UPDATE ON ref.lnk_dose2drug DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION ref.trf_ins_upd_assert_dose_unit_across_drug_components();


--
-- Name: paperwork_templates tr_protect_template_data; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_protect_template_data BEFORE UPDATE ON ref.paperwork_templates FOR EACH ROW EXECUTE FUNCTION ref.trf_protect_template_data();


--
-- Name: dose tr_upd_assert_dose_unit_in_multi_component_drugs; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_upd_assert_dose_unit_in_multi_component_drugs AFTER UPDATE ON ref.dose DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((new.dose_unit IS DISTINCT FROM old.dose_unit)) EXECUTE FUNCTION ref.trf_upd_assert_dose_unit_in_multi_component_drugs();


--
-- Name: lnk_dose2drug tr_upd_assert_product_keeps_components; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER tr_upd_assert_product_keeps_components AFTER UPDATE ON ref.lnk_dose2drug DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((new.fk_drug_product IS DISTINCT FROM old.fk_drug_product)) EXECUTE FUNCTION ref.trf_assert_product_keeps_components();


--
-- Name: atc tr_upd_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.atc FOR EACH ROW EXECUTE FUNCTION ref.trf_upd_ref_code_tbl_check_backlink();


--
-- Name: coda tr_upd_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.coda FOR EACH ROW EXECUTE FUNCTION ref.trf_upd_ref_code_tbl_check_backlink();


--
-- Name: icd10 tr_upd_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.icd10 FOR EACH ROW EXECUTE FUNCTION ref.trf_upd_ref_code_tbl_check_backlink();


--
-- Name: icd9 tr_upd_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.icd9 FOR EACH ROW EXECUTE FUNCTION ref.trf_upd_ref_code_tbl_check_backlink();


--
-- Name: icpc tr_upd_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.icpc FOR EACH ROW EXECUTE FUNCTION ref.trf_upd_ref_code_tbl_check_backlink();


--
-- Name: loinc tr_upd_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.loinc FOR EACH ROW EXECUTE FUNCTION ref.trf_upd_ref_code_tbl_check_backlink();


--
-- Name: ops tr_upd_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.ops FOR EACH ROW EXECUTE FUNCTION ref.trf_upd_ref_code_tbl_check_backlink();


--
-- Name: other_code tr_upd_ref_code_tbl_check_backlink; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER tr_upd_ref_code_tbl_check_backlink BEFORE UPDATE ON ref.other_code FOR EACH ROW EXECUTE FUNCTION ref.trf_upd_ref_code_tbl_check_backlink();


--
-- Name: auto_hint zt_del_auto_hint; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_auto_hint BEFORE DELETE ON ref.auto_hint FOR EACH ROW EXECUTE FUNCTION audit.ft_del_auto_hint();


--
-- Name: data_source zt_del_data_source; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_data_source BEFORE DELETE ON ref.data_source FOR EACH ROW EXECUTE FUNCTION audit.ft_del_data_source();


--
-- Name: dose zt_del_dose; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_dose BEFORE DELETE ON ref.dose FOR EACH ROW EXECUTE FUNCTION audit.ft_del_dose();


--
-- Name: drug_product zt_del_drug_product; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_drug_product BEFORE DELETE ON ref.drug_product FOR EACH ROW EXECUTE FUNCTION audit.ft_del_drug_product();


--
-- Name: lnk_dose2drug zt_del_lnk_dose2drug; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_dose2drug BEFORE DELETE ON ref.lnk_dose2drug FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_dose2drug();


--
-- Name: lnk_loinc2substance zt_del_lnk_loinc2substance; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_lnk_loinc2substance BEFORE DELETE ON ref.lnk_loinc2substance FOR EACH ROW EXECUTE FUNCTION audit.ft_del_lnk_loinc2substance();


--
-- Name: paperwork_templates zt_del_paperwork_templates; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_paperwork_templates BEFORE DELETE ON ref.paperwork_templates FOR EACH ROW EXECUTE FUNCTION audit.ft_del_paperwork_templates();


--
-- Name: substance zt_del_substance; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_substance BEFORE DELETE ON ref.substance FOR EACH ROW EXECUTE FUNCTION audit.ft_del_substance();


--
-- Name: tag_image zt_del_tag_image; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_tag_image BEFORE DELETE ON ref.tag_image FOR EACH ROW EXECUTE FUNCTION audit.ft_del_tag_image();


--
-- Name: vacc_route zt_del_vacc_route; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_vacc_route BEFORE DELETE ON ref.vacc_route FOR EACH ROW EXECUTE FUNCTION audit.ft_del_vacc_route();


--
-- Name: vaccine zt_del_vaccine; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_del_vaccine BEFORE DELETE ON ref.vaccine FOR EACH ROW EXECUTE FUNCTION audit.ft_del_vaccine();


--
-- Name: auto_hint zt_ins_auto_hint; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_auto_hint BEFORE INSERT ON ref.auto_hint FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_auto_hint();


--
-- Name: data_source zt_ins_data_source; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_data_source BEFORE INSERT ON ref.data_source FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_data_source();


--
-- Name: dose zt_ins_dose; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_dose BEFORE INSERT ON ref.dose FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_dose();


--
-- Name: drug_product zt_ins_drug_product; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_drug_product BEFORE INSERT ON ref.drug_product FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_drug_product();


--
-- Name: lnk_dose2drug zt_ins_lnk_dose2drug; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_dose2drug BEFORE INSERT ON ref.lnk_dose2drug FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_dose2drug();


--
-- Name: lnk_loinc2substance zt_ins_lnk_loinc2substance; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_lnk_loinc2substance BEFORE INSERT ON ref.lnk_loinc2substance FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_lnk_loinc2substance();


--
-- Name: paperwork_templates zt_ins_paperwork_templates; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_paperwork_templates BEFORE INSERT ON ref.paperwork_templates FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_paperwork_templates();


--
-- Name: substance zt_ins_substance; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_substance BEFORE INSERT ON ref.substance FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_substance();


--
-- Name: tag_image zt_ins_tag_image; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_tag_image BEFORE INSERT ON ref.tag_image FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_tag_image();


--
-- Name: vacc_route zt_ins_vacc_route; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_vacc_route BEFORE INSERT ON ref.vacc_route FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_vacc_route();


--
-- Name: vaccine zt_ins_vaccine; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_ins_vaccine BEFORE INSERT ON ref.vaccine FOR EACH ROW EXECUTE FUNCTION audit.ft_ins_vaccine();


--
-- Name: auto_hint zt_upd_auto_hint; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_auto_hint BEFORE UPDATE ON ref.auto_hint FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_auto_hint();


--
-- Name: data_source zt_upd_data_source; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_data_source BEFORE UPDATE ON ref.data_source FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_data_source();


--
-- Name: dose zt_upd_dose; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_dose BEFORE UPDATE ON ref.dose FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_dose();


--
-- Name: drug_product zt_upd_drug_product; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_drug_product BEFORE UPDATE ON ref.drug_product FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_drug_product();


--
-- Name: lnk_dose2drug zt_upd_lnk_dose2drug; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_dose2drug BEFORE UPDATE ON ref.lnk_dose2drug FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_dose2drug();


--
-- Name: lnk_loinc2substance zt_upd_lnk_loinc2substance; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_lnk_loinc2substance BEFORE UPDATE ON ref.lnk_loinc2substance FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_lnk_loinc2substance();


--
-- Name: paperwork_templates zt_upd_paperwork_templates; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_paperwork_templates BEFORE UPDATE ON ref.paperwork_templates FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_paperwork_templates();


--
-- Name: substance zt_upd_substance; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_substance BEFORE UPDATE ON ref.substance FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_substance();


--
-- Name: tag_image zt_upd_tag_image; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_tag_image BEFORE UPDATE ON ref.tag_image FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_tag_image();


--
-- Name: vacc_route zt_upd_vacc_route; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_vacc_route BEFORE UPDATE ON ref.vacc_route FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_vacc_route();


--
-- Name: vaccine zt_upd_vaccine; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE TRIGGER zt_upd_vaccine BEFORE UPDATE ON ref.vaccine FOR EACH ROW EXECUTE FUNCTION audit.ft_upd_vaccine();


--
-- Name: auto_hint zzz_tr_announce_ref_auto_hint_del; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_auto_hint_del AFTER DELETE ON ref.auto_hint DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=ref.auto_hint::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: auto_hint zzz_tr_announce_ref_auto_hint_ins_upd; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_auto_hint_ins_upd AFTER INSERT OR UPDATE ON ref.auto_hint DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=ref.auto_hint::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: billable zzz_tr_announce_ref_billable_del; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_billable_del AFTER DELETE ON ref.billable DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=ref.billable::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: billable zzz_tr_announce_ref_billable_ins_upd; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_billable_ins_upd AFTER INSERT OR UPDATE ON ref.billable DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=ref.billable::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: dose zzz_tr_announce_ref_dose_del; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_dose_del AFTER DELETE ON ref.dose DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=ref.dose::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: dose zzz_tr_announce_ref_dose_ins_upd; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_dose_ins_upd AFTER INSERT OR UPDATE ON ref.dose DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=ref.dose::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: drug_product zzz_tr_announce_ref_drug_product_del; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_drug_product_del AFTER DELETE ON ref.drug_product DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=ref.drug_product::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: drug_product zzz_tr_announce_ref_drug_product_ins_upd; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_drug_product_ins_upd AFTER INSERT OR UPDATE ON ref.drug_product DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=ref.drug_product::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_dose2drug zzz_tr_announce_ref_lnk_dose2drug_del; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_lnk_dose2drug_del AFTER DELETE ON ref.lnk_dose2drug DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=ref.lnk_dose2drug::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_dose2drug zzz_tr_announce_ref_lnk_dose2drug_ins_upd; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_lnk_dose2drug_ins_upd AFTER INSERT OR UPDATE ON ref.lnk_dose2drug DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=ref.lnk_dose2drug::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_loinc2substance zzz_tr_announce_ref_lnk_loinc2substance_del; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_lnk_loinc2substance_del AFTER DELETE ON ref.lnk_loinc2substance DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=ref.lnk_loinc2substance::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: lnk_loinc2substance zzz_tr_announce_ref_lnk_loinc2substance_ins_upd; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_lnk_loinc2substance_ins_upd AFTER INSERT OR UPDATE ON ref.lnk_loinc2substance DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=ref.lnk_loinc2substance::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: substance zzz_tr_announce_ref_substance_del; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_substance_del AFTER DELETE ON ref.substance DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=ref.substance::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: substance zzz_tr_announce_ref_substance_ins_upd; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_substance_ins_upd AFTER INSERT OR UPDATE ON ref.substance DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=ref.substance::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: tag_image zzz_tr_announce_ref_tag_image_del; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_tag_image_del AFTER DELETE ON ref.tag_image DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_del('operation=DELETE::table=ref.tag_image::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: tag_image zzz_tr_announce_ref_tag_image_ins_upd; Type: TRIGGER; Schema: ref; Owner: gm-dbo
--

CREATE CONSTRAINT TRIGGER zzz_tr_announce_ref_tag_image_ins_upd AFTER INSERT OR UPDATE ON ref.tag_image DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION gm.trf_announce_table_ins_upd('table=ref.tag_image::PK name=pk', 'select $1.pk', '<NULL>');


--
-- Name: referral referral_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: au; Owner: gm-dbo
--

ALTER TABLE ONLY au.referral
    ADD CONSTRAINT referral_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: referral referral_fk_episode_fkey; Type: FK CONSTRAINT; Schema: au; Owner: gm-dbo
--

ALTER TABLE ONLY au.referral
    ADD CONSTRAINT referral_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: referral referral_fk_form_fkey; Type: FK CONSTRAINT; Schema: au; Owner: gm-dbo
--

ALTER TABLE ONLY au.referral
    ADD CONSTRAINT referral_fk_form_fkey FOREIGN KEY (fk_form) REFERENCES clin.form_instances(pk);


--
-- Name: referral referral_fk_referee_fkey; Type: FK CONSTRAINT; Schema: au; Owner: gm-dbo
--

ALTER TABLE ONLY au.referral
    ADD CONSTRAINT referral_fk_referee_fkey FOREIGN KEY (fk_referee) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: bill bill_fk_doc_fkey; Type: FK CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill
    ADD CONSTRAINT bill_fk_doc_fkey FOREIGN KEY (fk_doc) REFERENCES blobs.doc_med(pk) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- Name: bill bill_fk_receiver_address_fkey; Type: FK CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill
    ADD CONSTRAINT bill_fk_receiver_address_fkey FOREIGN KEY (fk_receiver_address) REFERENCES dem.lnk_person_org_address(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: bill bill_fk_receiver_identity_fkey; Type: FK CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill
    ADD CONSTRAINT bill_fk_receiver_identity_fkey FOREIGN KEY (fk_receiver_identity) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: bill_item bill_item_fk_billable_fkey; Type: FK CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill_item
    ADD CONSTRAINT bill_item_fk_billable_fkey FOREIGN KEY (fk_billable) REFERENCES ref.billable(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: bill_item bill_item_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill_item
    ADD CONSTRAINT bill_item_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: bill_item bill_item_fk_provider_fkey; Type: FK CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill_item
    ADD CONSTRAINT bill_item_fk_provider_fkey FOREIGN KEY (fk_provider) REFERENCES dem.staff(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: bill_item fk_bill_item_fk_bill; Type: FK CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.bill_item
    ADD CONSTRAINT fk_bill_item_fk_bill FOREIGN KEY (fk_bill) REFERENCES bill.bill(pk) ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED;


--
-- Name: lnk_enc_type2billable lnk_enc_type2billable_fk_billable_fkey; Type: FK CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.lnk_enc_type2billable
    ADD CONSTRAINT lnk_enc_type2billable_fk_billable_fkey FOREIGN KEY (fk_billable) REFERENCES ref.billable(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_enc_type2billable lnk_enc_type2billable_fk_encounter_type_fkey; Type: FK CONSTRAINT; Schema: bill; Owner: gm-dbo
--

ALTER TABLE ONLY bill.lnk_enc_type2billable
    ADD CONSTRAINT lnk_enc_type2billable_fk_encounter_type_fkey FOREIGN KEY (fk_encounter_type) REFERENCES clin.encounter_type(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: doc_desc doc_desc_doc_id_fkey; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_desc
    ADD CONSTRAINT doc_desc_doc_id_fkey FOREIGN KEY (fk_doc) REFERENCES blobs.doc_med(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: doc_med doc_med_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_med
    ADD CONSTRAINT doc_med_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: doc_med doc_med_fk_episode_fkey; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_med
    ADD CONSTRAINT doc_med_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: doc_med doc_med_type_fkey; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_med
    ADD CONSTRAINT doc_med_type_fkey FOREIGN KEY (fk_type) REFERENCES blobs.doc_type(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: doc_obj doc_obj_fk_doc_fkey; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_obj
    ADD CONSTRAINT doc_obj_fk_doc_fkey FOREIGN KEY (fk_doc) REFERENCES blobs.doc_med(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: doc_obj doc_obj_fk_intended_reviewer_fkey; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_obj
    ADD CONSTRAINT doc_obj_fk_intended_reviewer_fkey FOREIGN KEY (fk_intended_reviewer) REFERENCES dem.staff(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: doc_med fk_blobs_doc_med_dem_org_unit_pk; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.doc_med
    ADD CONSTRAINT fk_blobs_doc_med_dem_org_unit_pk FOREIGN KEY (fk_org_unit) REFERENCES dem.org_unit(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_doc_med2episode lnk_doc_med2episode_fk_doc_med_fkey; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.lnk_doc_med2episode
    ADD CONSTRAINT lnk_doc_med2episode_fk_doc_med_fkey FOREIGN KEY (fk_doc_med) REFERENCES blobs.doc_med(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_doc_med2episode lnk_doc_med2episode_fk_episode_fkey; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.lnk_doc_med2episode
    ADD CONSTRAINT lnk_doc_med2episode_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: reviewed_doc_objs reviewed_doc_objs_fk_reviewed_row_fkey; Type: FK CONSTRAINT; Schema: blobs; Owner: gm-dbo
--

ALTER TABLE ONLY blobs.reviewed_doc_objs
    ADD CONSTRAINT reviewed_doc_objs_fk_reviewed_row_fkey FOREIGN KEY (fk_reviewed_row) REFERENCES blobs.doc_obj(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: cfg_data cfg_data_fk_item_fkey; Type: FK CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_data
    ADD CONSTRAINT cfg_data_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES cfg.cfg_item(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: cfg_item cfg_item_fk_template_fkey; Type: FK CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_item
    ADD CONSTRAINT cfg_item_fk_template_fkey FOREIGN KEY (fk_template) REFERENCES cfg.cfg_template(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: cfg_numeric cfg_numeric_fk_item_fkey; Type: FK CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_numeric
    ADD CONSTRAINT cfg_numeric_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES cfg.cfg_item(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: cfg_str_array cfg_str_array_fk_item_fkey; Type: FK CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_str_array
    ADD CONSTRAINT cfg_str_array_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES cfg.cfg_item(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: cfg_string cfg_string_fk_item_fkey; Type: FK CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_string
    ADD CONSTRAINT cfg_string_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES cfg.cfg_item(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: cfg_template cfg_template_type_fkey; Type: FK CONSTRAINT; Schema: cfg; Owner: gm-dbo
--

ALTER TABLE ONLY cfg.cfg_template
    ADD CONSTRAINT cfg_template_type_fkey FOREIGN KEY (type) REFERENCES cfg.cfg_type_enum(name);


--
-- Name: allergy allergy_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.allergy
    ADD CONSTRAINT allergy_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: allergy allergy_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.allergy
    ADD CONSTRAINT allergy_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: allergy allergy_id_type_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.allergy
    ADD CONSTRAINT allergy_id_type_fkey FOREIGN KEY (fk_type) REFERENCES clin._enum_allergy_type(pk);


--
-- Name: allergy_state allergy_state_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.allergy_state
    ADD CONSTRAINT allergy_state_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk);


--
-- Name: clin_aux_note clin_aux_note_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_aux_note
    ADD CONSTRAINT clin_aux_note_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: clin_aux_note clin_aux_note_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_aux_note
    ADD CONSTRAINT clin_aux_note_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: clin_diag clin_diag_fk_narrative_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_diag
    ADD CONSTRAINT clin_diag_fk_narrative_fkey FOREIGN KEY (fk_narrative) REFERENCES clin.clin_narrative(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: family_history clin_hx_family_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.family_history
    ADD CONSTRAINT clin_hx_family_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: family_history clin_hx_family_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.family_history
    ADD CONSTRAINT clin_hx_family_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_loinc2test_panel clin_ll2tp_fk_test_panel; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_loinc2test_panel
    ADD CONSTRAINT clin_ll2tp_fk_test_panel FOREIGN KEY (fk_test_panel) REFERENCES clin.test_panel(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: clin_narrative clin_narrative_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_narrative
    ADD CONSTRAINT clin_narrative_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: clin_narrative clin_narrative_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_narrative
    ADD CONSTRAINT clin_narrative_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: clin_root_item clin_root_item_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_root_item
    ADD CONSTRAINT clin_root_item_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: clin_root_item clin_root_item_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.clin_root_item
    ADD CONSTRAINT clin_root_item_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: substance_intake clin_substance_intake_fk_drug_component; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.substance_intake
    ADD CONSTRAINT clin_substance_intake_fk_drug_component FOREIGN KEY (fk_drug_component) REFERENCES ref.lnk_dose2drug(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: encounter encounter_fk_location_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.encounter
    ADD CONSTRAINT encounter_fk_location_fkey FOREIGN KEY (fk_location) REFERENCES dem.org_unit(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: encounter encounter_fk_type_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.encounter
    ADD CONSTRAINT encounter_fk_type_fkey FOREIGN KEY (fk_type) REFERENCES clin.encounter_type(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: episode episode_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.episode
    ADD CONSTRAINT episode_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: episode episode_fk_health_issue_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.episode
    ADD CONSTRAINT episode_fk_health_issue_fkey FOREIGN KEY (fk_health_issue) REFERENCES clin.health_issue(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: family_history family_history_fk_relation_type_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.family_history
    ADD CONSTRAINT family_history_fk_relation_type_fkey FOREIGN KEY (fk_relation_type) REFERENCES clin.fhx_relation_type(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: encounter fk_clin_encounter_fk_patient; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.encounter
    ADD CONSTRAINT fk_clin_encounter_fk_patient FOREIGN KEY (fk_patient) REFERENCES clin.patient(fk_identity) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: export_item fk_clin_export_item_fk_doc_obj; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.export_item
    ADD CONSTRAINT fk_clin_export_item_fk_doc_obj FOREIGN KEY (fk_doc_obj) REFERENCES blobs.doc_obj(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: export_item fk_clin_export_item_fk_identity; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.export_item
    ADD CONSTRAINT fk_clin_export_item_fk_identity FOREIGN KEY (fk_identity) REFERENCES clin.patient(fk_identity) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: external_care fk_clin_ext_care_fk_health_issue; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.external_care
    ADD CONSTRAINT fk_clin_ext_care_fk_health_issue FOREIGN KEY (fk_health_issue) REFERENCES clin.health_issue(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: external_care fk_clin_ext_care_fk_org_unit; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.external_care
    ADD CONSTRAINT fk_clin_ext_care_fk_org_unit FOREIGN KEY (fk_org_unit) REFERENCES dem.org_unit(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: external_care fk_clin_external_care_fk_encounter; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.external_care
    ADD CONSTRAINT fk_clin_external_care_fk_encounter FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: patient fk_clin_patient_fk_identity; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.patient
    ADD CONSTRAINT fk_clin_patient_fk_identity FOREIGN KEY (fk_identity) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: suppressed_hint fk_clin_suppressed_hint_fk_encounter; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.suppressed_hint
    ADD CONSTRAINT fk_clin_suppressed_hint_fk_encounter FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: suppressed_hint fk_clin_suppressed_hint_fk_hint; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.suppressed_hint
    ADD CONSTRAINT fk_clin_suppressed_hint_fk_hint FOREIGN KEY (fk_hint) REFERENCES ref.auto_hint(pk) ON UPDATE RESTRICT ON DELETE CASCADE;


--
-- Name: incoming_data_unmatched fk_incoming_data_unmatched_fk_identity_disambiguated; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.incoming_data_unmatched
    ADD CONSTRAINT fk_incoming_data_unmatched_fk_identity_disambiguated FOREIGN KEY (fk_identity_disambiguated) REFERENCES clin.patient(fk_identity) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_pat2vaccination_course fk_lnk_pat2vaccination_course_fk_patient; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_pat2vaccination_course
    ADD CONSTRAINT fk_lnk_pat2vaccination_course_fk_patient FOREIGN KEY (fk_patient) REFERENCES clin.patient(fk_identity) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: form_data form_data_fk_form_field_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.form_data
    ADD CONSTRAINT form_data_fk_form_field_fkey FOREIGN KEY (fk_form_field) REFERENCES public.form_fields(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: form_data form_data_fk_instance_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.form_data
    ADD CONSTRAINT form_data_fk_instance_fkey FOREIGN KEY (fk_instance) REFERENCES clin.form_instances(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: form_instances form_instances_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.form_instances
    ADD CONSTRAINT form_instances_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: form_instances form_instances_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.form_instances
    ADD CONSTRAINT form_instances_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: form_instances form_instances_fk_form_def_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.form_instances
    ADD CONSTRAINT form_instances_fk_form_def_fkey FOREIGN KEY (fk_form_def) REFERENCES ref.paperwork_templates(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: health_issue health_issue_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.health_issue
    ADD CONSTRAINT health_issue_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: hospital_stay hospital_stay_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.hospital_stay
    ADD CONSTRAINT hospital_stay_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: hospital_stay hospital_stay_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.hospital_stay
    ADD CONSTRAINT hospital_stay_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: hospital_stay hospital_stay_fk_org_unit_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.hospital_stay
    ADD CONSTRAINT hospital_stay_fk_org_unit_fkey FOREIGN KEY (fk_org_unit) REFERENCES dem.org_unit(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: incoming_data_unmatched incoming_data_unmatched_fk_provider_disambiguated_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.incoming_data_unmatched
    ADD CONSTRAINT incoming_data_unmatched_fk_provider_disambiguated_fkey FOREIGN KEY (fk_provider_disambiguated) REFERENCES dem.staff(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lab_request lab_request_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lab_request
    ADD CONSTRAINT lab_request_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lab_request lab_request_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lab_request
    ADD CONSTRAINT lab_request_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lab_request lab_request_fk_requestor_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lab_request
    ADD CONSTRAINT lab_request_fk_requestor_fkey FOREIGN KEY (fk_requestor) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lab_request lab_request_fk_test_org_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lab_request
    ADD CONSTRAINT lab_request_fk_test_org_fkey FOREIGN KEY (fk_test_org) REFERENCES clin.test_org(pk);


--
-- Name: lnk_code2aoe lnk_code2aoe_fk_item_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2aoe
    ADD CONSTRAINT lnk_code2aoe_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_code2episode lnk_code2episode_fk_item_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2episode
    ADD CONSTRAINT lnk_code2episode_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_code2fhx lnk_code2fhx_fk_item_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2fhx
    ADD CONSTRAINT lnk_code2fhx_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES clin.family_history(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_code2h_issue lnk_code2h_issue_fk_item_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2h_issue
    ADD CONSTRAINT lnk_code2h_issue_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES clin.health_issue(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_code2narrative lnk_code2narrative_fk_item_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2narrative
    ADD CONSTRAINT lnk_code2narrative_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES clin.clin_narrative(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_code2procedure lnk_code2procedure_fk_item_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2procedure
    ADD CONSTRAINT lnk_code2procedure_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES clin.procedure(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_code2rfe lnk_code2rfe_fk_item_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2rfe
    ADD CONSTRAINT lnk_code2rfe_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_code2tst_pnl lnk_code2tst_pnl_fk_item_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_code2tst_pnl
    ADD CONSTRAINT lnk_code2tst_pnl_fk_item_fkey FOREIGN KEY (fk_item) REFERENCES clin.test_panel(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_constraint2vacc_course lnk_constraint2vacc_course_fk_constraint_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_constraint2vacc_course
    ADD CONSTRAINT lnk_constraint2vacc_course_fk_constraint_fkey FOREIGN KEY (fk_constraint) REFERENCES clin.vaccination_course_constraint(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_constraint2vacc_course lnk_constraint2vacc_course_fk_vaccination_course_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_constraint2vacc_course
    ADD CONSTRAINT lnk_constraint2vacc_course_fk_vaccination_course_fkey FOREIGN KEY (fk_vaccination_course) REFERENCES clin.vaccination_course(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_pat2vaccination_course lnk_pat2vaccination_course_fk_course_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_pat2vaccination_course
    ADD CONSTRAINT lnk_pat2vaccination_course_fk_course_fkey FOREIGN KEY (fk_course) REFERENCES clin.vaccination_course(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_substance2episode lnk_substance2episode_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_substance2episode
    ADD CONSTRAINT lnk_substance2episode_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_substance2episode lnk_substance2episode_fk_substance_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_substance2episode
    ADD CONSTRAINT lnk_substance2episode_fk_substance_fkey FOREIGN KEY (fk_substance) REFERENCES clin.substance_intake(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_tst2norm lnk_tst2norm_id_test_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_tst2norm
    ADD CONSTRAINT lnk_tst2norm_id_test_fkey FOREIGN KEY (id_test) REFERENCES clin.test_type(pk);


--
-- Name: lnk_type2item lnk_type2item_fk_type_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_type2item
    ADD CONSTRAINT lnk_type2item_fk_type_fkey FOREIGN KEY (fk_type) REFERENCES clin.clin_item_type(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_vaccination_course2schedule lnk_vaccination_course2schedule_fk_course_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_vaccination_course2schedule
    ADD CONSTRAINT lnk_vaccination_course2schedule_fk_course_fkey FOREIGN KEY (fk_course) REFERENCES clin.vaccination_course(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_vaccination_course2schedule lnk_vaccination_course2schedule_fk_schedule_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.lnk_vaccination_course2schedule
    ADD CONSTRAINT lnk_vaccination_course2schedule_fk_schedule_fkey FOREIGN KEY (fk_schedule) REFERENCES clin.vaccination_schedule(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: procedure procedure_fk_doc_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.procedure
    ADD CONSTRAINT procedure_fk_doc_fkey FOREIGN KEY (fk_doc) REFERENCES blobs.doc_med(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: procedure procedure_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.procedure
    ADD CONSTRAINT procedure_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: procedure procedure_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.procedure
    ADD CONSTRAINT procedure_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: procedure procedure_fk_hospital_stay_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.procedure
    ADD CONSTRAINT procedure_fk_hospital_stay_fkey FOREIGN KEY (fk_hospital_stay) REFERENCES clin.hospital_stay(pk);


--
-- Name: procedure procedure_fk_org_unit_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.procedure
    ADD CONSTRAINT procedure_fk_org_unit_fkey FOREIGN KEY (fk_org_unit) REFERENCES dem.org_unit(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: review_root review_root_fk_reviewer_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.review_root
    ADD CONSTRAINT review_root_fk_reviewer_fkey FOREIGN KEY (fk_reviewer) REFERENCES dem.staff(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: reviewed_test_results reviewed_test_results_fk_reviewed_row_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.reviewed_test_results
    ADD CONSTRAINT reviewed_test_results_fk_reviewed_row_fkey FOREIGN KEY (fk_reviewed_row) REFERENCES clin.test_result(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: reviewed_test_results reviewed_test_results_fk_reviewer_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.reviewed_test_results
    ADD CONSTRAINT reviewed_test_results_fk_reviewer_fkey FOREIGN KEY (fk_reviewer) REFERENCES dem.staff(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: substance_intake substance_intake_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.substance_intake
    ADD CONSTRAINT substance_intake_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: substance_intake substance_intake_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.substance_intake
    ADD CONSTRAINT substance_intake_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: test_org test_org_fk_adm_contact_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_org
    ADD CONSTRAINT test_org_fk_adm_contact_fkey FOREIGN KEY (fk_adm_contact) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: test_org test_org_fk_med_contact_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_org
    ADD CONSTRAINT test_org_fk_med_contact_fkey FOREIGN KEY (fk_med_contact) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: test_org test_org_fk_org_unit_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_org
    ADD CONSTRAINT test_org_fk_org_unit_fkey FOREIGN KEY (fk_org_unit) REFERENCES dem.org_unit(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: test_result test_result_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_result
    ADD CONSTRAINT test_result_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: test_result test_result_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_result
    ADD CONSTRAINT test_result_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: test_result test_result_fk_intended_reviewer_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_result
    ADD CONSTRAINT test_result_fk_intended_reviewer_fkey FOREIGN KEY (fk_intended_reviewer) REFERENCES dem.staff(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: test_result test_result_fk_request_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_result
    ADD CONSTRAINT test_result_fk_request_fkey FOREIGN KEY (fk_request) REFERENCES clin.lab_request(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: test_result test_result_fk_type_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_result
    ADD CONSTRAINT test_result_fk_type_fkey FOREIGN KEY (fk_type) REFERENCES clin.test_type(pk);


--
-- Name: test_type test_type_fk_meta_test_type_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_type
    ADD CONSTRAINT test_type_fk_meta_test_type_fkey FOREIGN KEY (fk_meta_test_type) REFERENCES clin.meta_test_type(pk);


--
-- Name: test_type test_type_fk_test_org_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.test_type
    ADD CONSTRAINT test_type_fk_test_org_fkey FOREIGN KEY (fk_test_org) REFERENCES clin.test_org(pk);


--
-- Name: vaccination_definition vaccination_definition_fk_course_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination_definition
    ADD CONSTRAINT vaccination_definition_fk_course_fkey FOREIGN KEY (fk_course) REFERENCES clin.vaccination_course(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: vaccination vaccination_fk_encounter_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination
    ADD CONSTRAINT vaccination_fk_encounter_fkey FOREIGN KEY (fk_encounter) REFERENCES clin.encounter(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: vaccination vaccination_fk_episode_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination
    ADD CONSTRAINT vaccination_fk_episode_fkey FOREIGN KEY (fk_episode) REFERENCES clin.episode(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: vaccination vaccination_fk_provider_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination
    ADD CONSTRAINT vaccination_fk_provider_fkey FOREIGN KEY (fk_provider) REFERENCES dem.staff(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: vaccination vaccination_fk_vaccine_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.vaccination
    ADD CONSTRAINT vaccination_fk_vaccine_fkey FOREIGN KEY (fk_vaccine) REFERENCES ref.vaccine(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: waiting_list waiting_list_fk_patient_fkey; Type: FK CONSTRAINT; Schema: clin; Owner: gm-dbo
--

ALTER TABLE ONLY clin.waiting_list
    ADD CONSTRAINT waiting_list_fk_patient_fkey FOREIGN KEY (fk_patient) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: kvk kvk_fk_patient_fkey; Type: FK CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.kvk
    ADD CONSTRAINT kvk_fk_patient_fkey FOREIGN KEY (fk_patient) REFERENCES dem.identity(pk);


--
-- Name: lab_test_gnr lab_test_gnr_id_test_fkey; Type: FK CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.lab_test_gnr
    ADD CONSTRAINT lab_test_gnr_id_test_fkey FOREIGN KEY (id_test) REFERENCES clin.test_type(pk);


--
-- Name: prax_geb_paid prax_geb_paid_paid_with_fkey; Type: FK CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.prax_geb_paid
    ADD CONSTRAINT prax_geb_paid_paid_with_fkey FOREIGN KEY (paid_with) REFERENCES de_de.payment_method(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: zuzahlungsbefreiung zuzahlungsbefreiung_id_patient_fkey; Type: FK CONSTRAINT; Schema: de_de; Owner: gm-dbo
--

ALTER TABLE ONLY de_de.zuzahlungsbefreiung
    ADD CONSTRAINT zuzahlungsbefreiung_id_patient_fkey FOREIGN KEY (id_patient) REFERENCES dem.identity(pk);


--
-- Name: address address_id_street_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.address
    ADD CONSTRAINT address_id_street_fkey FOREIGN KEY (id_street) REFERENCES dem.street(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: urb fk_dem_urb_dem_region_pk; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.urb
    ADD CONSTRAINT fk_dem_urb_dem_region_pk FOREIGN KEY (fk_region) REFERENCES dem.region(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: identity identity_fk_emergency_contact_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.identity
    ADD CONSTRAINT identity_fk_emergency_contact_fkey FOREIGN KEY (fk_emergency_contact) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: identity identity_fk_marital_status_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.identity
    ADD CONSTRAINT identity_fk_marital_status_fkey FOREIGN KEY (fk_marital_status) REFERENCES dem.marital_status(pk);


--
-- Name: identity identity_fk_primary_provider_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.identity
    ADD CONSTRAINT identity_fk_primary_provider_fkey FOREIGN KEY (fk_primary_provider) REFERENCES dem.staff(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: identity identity_gender_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.identity
    ADD CONSTRAINT identity_gender_fkey FOREIGN KEY (gender) REFERENCES dem.gender_label(tag) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: identity_tag identity_tag_fk_identity_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.identity_tag
    ADD CONSTRAINT identity_tag_fk_identity_fkey FOREIGN KEY (fk_identity) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: identity_tag identity_tag_fk_tag_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.identity_tag
    ADD CONSTRAINT identity_tag_fk_tag_fkey FOREIGN KEY (fk_tag) REFERENCES ref.tag_image(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: inbox_item_type inbox_item_type_fk_inbox_item_category_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.inbox_item_type
    ADD CONSTRAINT inbox_item_type_fk_inbox_item_category_fkey FOREIGN KEY (fk_inbox_item_category) REFERENCES dem.inbox_item_category(pk);


--
-- Name: lnk_identity2comm lnk_identity2comm_id_address_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_identity2comm
    ADD CONSTRAINT lnk_identity2comm_id_address_fkey FOREIGN KEY (fk_address) REFERENCES dem.address(id) ON UPDATE SET NULL ON DELETE SET NULL;


--
-- Name: lnk_identity2comm lnk_identity2comm_id_identity_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_identity2comm
    ADD CONSTRAINT lnk_identity2comm_id_identity_fkey FOREIGN KEY (fk_identity) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_identity2comm lnk_identity2comm_id_type_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_identity2comm
    ADD CONSTRAINT lnk_identity2comm_id_type_fkey FOREIGN KEY (fk_type) REFERENCES dem.enum_comm_types(pk);


--
-- Name: lnk_identity2ext_id lnk_identity2ext_id_fk_origin_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_identity2ext_id
    ADD CONSTRAINT lnk_identity2ext_id_fk_origin_fkey FOREIGN KEY (fk_origin) REFERENCES dem.enum_ext_id_types(pk);


--
-- Name: lnk_identity2ext_id lnk_identity2ext_id_id_identity_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_identity2ext_id
    ADD CONSTRAINT lnk_identity2ext_id_id_identity_fkey FOREIGN KEY (id_identity) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_job2person lnk_job2person_fk_identity_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_job2person
    ADD CONSTRAINT lnk_job2person_fk_identity_fkey FOREIGN KEY (fk_identity) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_job2person lnk_job2person_fk_occupation_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_job2person
    ADD CONSTRAINT lnk_job2person_fk_occupation_fkey FOREIGN KEY (fk_occupation) REFERENCES dem.occupation(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_org_unit2comm lnk_org_unit2comm_fk_org_unit_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_org_unit2comm
    ADD CONSTRAINT lnk_org_unit2comm_fk_org_unit_fkey FOREIGN KEY (fk_org_unit) REFERENCES dem.org_unit(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_org_unit2comm lnk_org_unit2comm_fk_type_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_org_unit2comm
    ADD CONSTRAINT lnk_org_unit2comm_fk_type_fkey FOREIGN KEY (fk_type) REFERENCES dem.enum_comm_types(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_org_unit2ext_id lnk_org_unit2ext_id_fk_org_unit_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_org_unit2ext_id
    ADD CONSTRAINT lnk_org_unit2ext_id_fk_org_unit_fkey FOREIGN KEY (fk_org_unit) REFERENCES dem.org_unit(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_org_unit2ext_id lnk_org_unit2ext_id_fk_type_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_org_unit2ext_id
    ADD CONSTRAINT lnk_org_unit2ext_id_fk_type_fkey FOREIGN KEY (fk_type) REFERENCES dem.enum_ext_id_types(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_person2relative lnk_person2relative_id_identity_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person2relative
    ADD CONSTRAINT lnk_person2relative_id_identity_fkey FOREIGN KEY (id_identity) REFERENCES dem.identity(pk);


--
-- Name: lnk_person2relative lnk_person2relative_id_relation_type_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person2relative
    ADD CONSTRAINT lnk_person2relative_id_relation_type_fkey FOREIGN KEY (id_relation_type) REFERENCES dem.relation_types(id);


--
-- Name: lnk_person2relative lnk_person2relative_id_relative_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person2relative
    ADD CONSTRAINT lnk_person2relative_id_relative_fkey FOREIGN KEY (id_relative) REFERENCES dem.identity(pk);


--
-- Name: lnk_person_org_address lnk_person_org_address_id_address_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person_org_address
    ADD CONSTRAINT lnk_person_org_address_id_address_fkey FOREIGN KEY (id_address) REFERENCES dem.address(id);


--
-- Name: lnk_person_org_address lnk_person_org_address_id_identity_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person_org_address
    ADD CONSTRAINT lnk_person_org_address_id_identity_fkey FOREIGN KEY (id_identity) REFERENCES dem.identity(pk);


--
-- Name: lnk_person_org_address lnk_person_org_address_id_type_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.lnk_person_org_address
    ADD CONSTRAINT lnk_person_org_address_id_type_fkey FOREIGN KEY (id_type) REFERENCES dem.address_type(id);


--
-- Name: message_inbox message_inbox_fk_patient_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.message_inbox
    ADD CONSTRAINT message_inbox_fk_patient_fkey FOREIGN KEY (fk_patient) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: names names_id_identity_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.names
    ADD CONSTRAINT names_id_identity_fkey FOREIGN KEY (id_identity) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: org org_fk_category_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org
    ADD CONSTRAINT org_fk_category_fkey FOREIGN KEY (fk_category) REFERENCES dem.org_category(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: org org_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org
    ADD CONSTRAINT org_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: org_unit org_unit_fk_address_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org_unit
    ADD CONSTRAINT org_unit_fk_address_fkey FOREIGN KEY (fk_address) REFERENCES dem.address(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: org_unit org_unit_fk_category_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org_unit
    ADD CONSTRAINT org_unit_fk_category_fkey FOREIGN KEY (fk_category) REFERENCES dem.org_category(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: org_unit org_unit_fk_org_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.org_unit
    ADD CONSTRAINT org_unit_fk_org_fkey FOREIGN KEY (fk_org) REFERENCES dem.org(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: message_inbox provider_inbox_fk_inbox_item_type_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.message_inbox
    ADD CONSTRAINT provider_inbox_fk_inbox_item_type_fkey FOREIGN KEY (fk_inbox_item_type) REFERENCES dem.inbox_item_type(pk);


--
-- Name: message_inbox provider_inbox_fk_staff_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.message_inbox
    ADD CONSTRAINT provider_inbox_fk_staff_fkey FOREIGN KEY (fk_staff) REFERENCES dem.staff(pk);


--
-- Name: relation_types relation_types_inverse_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.relation_types
    ADD CONSTRAINT relation_types_inverse_fkey FOREIGN KEY (inverse) REFERENCES dem.relation_types(id);


--
-- Name: staff staff_fk_identity_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.staff
    ADD CONSTRAINT staff_fk_identity_fkey FOREIGN KEY (fk_identity) REFERENCES dem.identity(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: region state_country_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.region
    ADD CONSTRAINT state_country_fkey FOREIGN KEY (country) REFERENCES dem.country(code);


--
-- Name: street street_id_urb_fkey; Type: FK CONSTRAINT; Schema: dem; Owner: gm-dbo
--

ALTER TABLE ONLY dem.street
    ADD CONSTRAINT street_id_urb_fkey FOREIGN KEY (id_urb) REFERENCES dem.urb(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: form_fields form_fields_fk_form_fkey; Type: FK CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_fields
    ADD CONSTRAINT form_fields_fk_form_fkey FOREIGN KEY (fk_form) REFERENCES ref.paperwork_templates(pk);


--
-- Name: form_fields form_fields_fk_type_fkey; Type: FK CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_fields
    ADD CONSTRAINT form_fields_fk_type_fkey FOREIGN KEY (fk_type) REFERENCES public.form_field_types(pk);


--
-- Name: form_job_queue form_job_queue_fk_form_instance_fkey; Type: FK CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_job_queue
    ADD CONSTRAINT form_job_queue_fk_form_instance_fkey FOREIGN KEY (fk_form_instance) REFERENCES clin.form_instances(pk);


--
-- Name: form_job_queue form_job_queue_fk_job_target_fkey; Type: FK CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_job_queue
    ADD CONSTRAINT form_job_queue_fk_job_target_fkey FOREIGN KEY (fk_job_target) REFERENCES public.form_job_targets(pk);


--
-- Name: form_print_defs form_print_defs_fk_papersize_fkey; Type: FK CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.form_print_defs
    ADD CONSTRAINT form_print_defs_fk_papersize_fkey FOREIGN KEY (fk_papersize) REFERENCES ref.papersizes(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: unit unit_fk_basic_unit_fkey; Type: FK CONSTRAINT; Schema: public; Owner: gm-dbo
--

ALTER TABLE ONLY public.unit
    ADD CONSTRAINT unit_fk_basic_unit_fkey FOREIGN KEY (fk_basic_unit) REFERENCES public.basic_unit(pk);


--
-- Name: atc atc_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.atc
    ADD CONSTRAINT atc_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: billable billable_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.billable
    ADD CONSTRAINT billable_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: drug_product branded_drug_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.drug_product
    ADD CONSTRAINT branded_drug_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: coda coda_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.coda
    ADD CONSTRAINT coda_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: coding_system_root coding_system_root_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.coding_system_root
    ADD CONSTRAINT coding_system_root_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: icd10 icd10_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icd10
    ADD CONSTRAINT icd10_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: icd9 icd9_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icd9
    ADD CONSTRAINT icd9_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: icpc icpc_fk_chapter_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc
    ADD CONSTRAINT icpc_fk_chapter_fkey FOREIGN KEY (fk_chapter) REFERENCES ref.icpc_chapter(chapter) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: icpc icpc_fk_component_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc
    ADD CONSTRAINT icpc_fk_component_fkey FOREIGN KEY (fk_component) REFERENCES ref.icpc_component(component) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: icpc icpc_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc
    ADD CONSTRAINT icpc_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: icpc_thesaurus icpc_thesaurus_fk_code_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.icpc_thesaurus
    ADD CONSTRAINT icpc_thesaurus_fk_code_fkey FOREIGN KEY (fk_code) REFERENCES ref.icpc(pk_coding_system) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: keyword_expansion keyword_expansion_fk_staff_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.keyword_expansion
    ADD CONSTRAINT keyword_expansion_fk_staff_fkey FOREIGN KEY (fk_staff) REFERENCES dem.staff(pk);


--
-- Name: loinc loinc_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.loinc
    ADD CONSTRAINT loinc_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: ops ops_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.ops
    ADD CONSTRAINT ops_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: other_code other_code_fk_data_source_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.other_code
    ADD CONSTRAINT other_code_fk_data_source_fkey FOREIGN KEY (fk_data_source) REFERENCES ref.data_source(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: paperwork_templates paperwork_templates_fk_template_type_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.paperwork_templates
    ADD CONSTRAINT paperwork_templates_fk_template_type_fkey FOREIGN KEY (fk_template_type) REFERENCES ref.form_types(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: dose ref_dose_fk_substance; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.dose
    ADD CONSTRAINT ref_dose_fk_substance FOREIGN KEY (fk_substance) REFERENCES ref.substance(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_dose2drug ref_ld2d_fk_dose; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.lnk_dose2drug
    ADD CONSTRAINT ref_ld2d_fk_dose FOREIGN KEY (fk_dose) REFERENCES ref.dose(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_dose2drug ref_ld2d_fk_drug_product; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.lnk_dose2drug
    ADD CONSTRAINT ref_ld2d_fk_drug_product FOREIGN KEY (fk_drug_product) REFERENCES ref.drug_product(pk) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: lnk_loinc2substance ref_ll2s_fk_substance; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.lnk_loinc2substance
    ADD CONSTRAINT ref_ll2s_fk_substance FOREIGN KEY (fk_substance) REFERENCES ref.substance(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: vaccine ref_vaccine_fk_drug_product; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.vaccine
    ADD CONSTRAINT ref_vaccine_fk_drug_product FOREIGN KEY (fk_drug_product) REFERENCES ref.drug_product(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: vaccine vaccine_id_route_fkey; Type: FK CONSTRAINT; Schema: ref; Owner: gm-dbo
--

ALTER TABLE ONLY ref.vaccine
    ADD CONSTRAINT vaccine_id_route_fkey FOREIGN KEY (id_route) REFERENCES ref.vacc_route(id);


--
-- Name: lab_request lab_request_fk_test_org_fkey; Type: FK CONSTRAINT; Schema: staging; Owner: gm-dbo
--

ALTER TABLE ONLY staging.lab_request
    ADD CONSTRAINT lab_request_fk_test_org_fkey FOREIGN KEY (fk_test_org) REFERENCES clin.test_org(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: lnk_vacc_ind2subst_dose lnk_vacc_ind2subst_dose_fk_dose_fkey; Type: FK CONSTRAINT; Schema: staging; Owner: gm-dbo
--

ALTER TABLE ONLY staging.lnk_vacc_ind2subst_dose
    ADD CONSTRAINT lnk_vacc_ind2subst_dose_fk_dose_fkey FOREIGN KEY (fk_dose) REFERENCES ref.dose(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: test_result test_result_fk_request_fkey; Type: FK CONSTRAINT; Schema: staging; Owner: gm-dbo
--

ALTER TABLE ONLY staging.test_result
    ADD CONSTRAINT test_result_fk_request_fkey FOREIGN KEY (fk_request) REFERENCES staging.lab_request(pk) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- Name: SCHEMA au; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA au TO "gm-doctors";


--
-- Name: SCHEMA audit; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA audit TO "gm-doctors";


--
-- Name: SCHEMA bill; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA bill TO "gm-doctors";


--
-- Name: SCHEMA blobs; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA blobs TO "gm-doctors";
GRANT USAGE ON SCHEMA blobs TO "gm-staff";


--
-- Name: SCHEMA cfg; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA cfg TO "gm-doctors";
GRANT USAGE ON SCHEMA cfg TO "gm-staff";


--
-- Name: SCHEMA clin; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA clin TO "gm-doctors";
GRANT USAGE ON SCHEMA clin TO "gm-staff";


--
-- Name: SCHEMA de_de; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA de_de TO "gm-doctors";


--
-- Name: SCHEMA dem; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA dem TO "gm-doctors";
GRANT USAGE ON SCHEMA dem TO "gm-staff";


--
-- Name: SCHEMA gm; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA gm TO "gm-doctors";
GRANT USAGE ON SCHEMA gm TO "gm-staff";


--
-- Name: SCHEMA i18n; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA i18n TO "gm-public";


--
-- Name: SCHEMA pgtrgm; Type: ACL; Schema: -; Owner: postgres
--

GRANT USAGE ON SCHEMA pgtrgm TO "gm-dbo";


--
-- Name: SCHEMA ref; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA ref TO "gm-doctors";
GRANT USAGE ON SCHEMA ref TO "gm-staff";


--
-- Name: SCHEMA staging; Type: ACL; Schema: -; Owner: gm-dbo
--

GRANT USAGE ON SCHEMA staging TO "gm-doctors";


--
-- Name: FUNCTION get_dob(integer); Type: ACL; Schema: clin; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION clin.get_dob(integer) FROM PUBLIC;
GRANT ALL ON FUNCTION clin.get_dob(integer) TO "gm-public";


--
-- Name: FUNCTION get_dod(integer); Type: ACL; Schema: clin; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION clin.get_dod(integer) FROM PUBLIC;
GRANT ALL ON FUNCTION clin.get_dod(integer) TO "gm-public";


--
-- Name: FUNCTION is_null_or_non_empty_string(text); Type: ACL; Schema: gm; Owner: gm-dbo
--

GRANT ALL ON FUNCTION gm.is_null_or_non_empty_string(text) TO "gm-public";


--
-- Name: TABLE audit_fields; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE audit.audit_fields TO "gm-doctors";


--
-- Name: TABLE auto_hint; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.auto_hint TO "gm-public";


--
-- Name: TABLE v_auto_hints; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_auto_hints TO "gm-staff";


--
-- Name: FUNCTION remove_old_empty_encounters(integer); Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT ALL ON FUNCTION clin.remove_old_empty_encounters(integer) TO "gm-staff";


--
-- Name: FUNCTION remove_old_empty_encounters(integer, interval); Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT ALL ON FUNCTION clin.remove_old_empty_encounters(integer, interval) TO "gm-staff";


--
-- Name: FUNCTION add_user_to_permission_group(name, name); Type: ACL; Schema: gm; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION gm.add_user_to_permission_group(name, name) FROM PUBLIC;


--
-- Name: FUNCTION create_user(name, text); Type: ACL; Schema: gm; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION gm.create_user(name, text) FROM PUBLIC;


--
-- Name: FUNCTION disable_user(name); Type: ACL; Schema: gm; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION gm.disable_user(name) FROM PUBLIC;


--
-- Name: FUNCTION drop_user(name); Type: ACL; Schema: gm; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION gm.drop_user(name) FROM PUBLIC;


--
-- Name: FUNCTION get_users(); Type: ACL; Schema: gm; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION gm.get_users() FROM PUBLIC;


--
-- Name: FUNCTION get_users(name); Type: ACL; Schema: gm; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION gm.get_users(name) FROM PUBLIC;


--
-- Name: FUNCTION log_access2emr(text); Type: ACL; Schema: gm; Owner: gm-dbo
--

GRANT ALL ON FUNCTION gm.log_access2emr(text) TO "gm-public";
GRANT ALL ON FUNCTION gm.log_access2emr(text) TO "gm-staff";


--
-- Name: FUNCTION log_other_access(text); Type: ACL; Schema: gm; Owner: gm-dbo
--

GRANT ALL ON FUNCTION gm.log_other_access(text) TO "gm-public";


--
-- Name: FUNCTION nullify_empty_string(text); Type: ACL; Schema: gm; Owner: gm-dbo
--

GRANT ALL ON FUNCTION gm.nullify_empty_string(text) TO "gm-public";


--
-- Name: FUNCTION transfer_users(text); Type: ACL; Schema: gm; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION gm.transfer_users(text) FROM PUBLIC;


--
-- Name: FUNCTION transfer_users(text, text); Type: ACL; Schema: gm; Owner: gm-dbo
--

REVOKE ALL ON FUNCTION gm.transfer_users(text, text) FROM PUBLIC;


--
-- Name: TABLE clin_root_item; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.clin_root_item TO "gm-doctors";


--
-- Name: TABLE referral; Type: ACL; Schema: au; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE au.referral TO "gm-doctors";


--
-- Name: SEQUENCE audit_fields_pk_audit_seq; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE audit.audit_fields_pk_audit_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE audit.audit_fields_pk_audit_seq TO "gm-staff";


--
-- Name: TABLE audit_trail; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT ON TABLE audit.audit_trail TO "gm-doctors";


--
-- Name: SEQUENCE audit_trail_pk_audit_seq; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT ON SEQUENCE audit.audit_trail_pk_audit_seq TO "gm-doctors";


--
-- Name: COLUMN log_bill.invoice_id; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT(invoice_id) ON TABLE audit.log_bill TO "gm-doctors";


--
-- Name: TABLE log_clin_narrative; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT ON TABLE audit.log_clin_narrative TO "gm-doctors";


--
-- Name: TABLE log_consumed_substance; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT ON TABLE audit.log_consumed_substance TO "gm-doctors";


--
-- Name: TABLE log_encounter; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT ON TABLE audit.log_encounter TO "gm-doctors";


--
-- Name: TABLE log_episode; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT ON TABLE audit.log_episode TO "gm-doctors";


--
-- Name: TABLE log_health_issue; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT ON TABLE audit.log_health_issue TO "gm-doctors";


--
-- Name: TABLE staff; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.staff TO "gm-doctors";
GRANT SELECT ON TABLE dem.staff TO "gm-staff";


--
-- Name: TABLE access_log; Type: ACL; Schema: gm; Owner: gm-dbo
--

GRANT INSERT ON TABLE gm.access_log TO "gm-public";


--
-- Name: TABLE v_audit_trail; Type: ACL; Schema: audit; Owner: gm-dbo
--

GRANT SELECT ON TABLE audit.v_audit_trail TO "gm-doctors";


--
-- Name: TABLE bill; Type: ACL; Schema: bill; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE bill.bill TO "gm-doctors";
GRANT SELECT ON TABLE bill.bill TO "gm-public";


--
-- Name: TABLE bill_item; Type: ACL; Schema: bill; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE bill.bill_item TO "gm-doctors";
GRANT SELECT ON TABLE bill.bill_item TO "gm-public";


--
-- Name: SEQUENCE bill_item_pk_seq; Type: ACL; Schema: bill; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE bill.bill_item_pk_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE bill.bill_item_pk_seq TO "gm-public";


--
-- Name: SEQUENCE bill_pk_seq; Type: ACL; Schema: bill; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE bill.bill_pk_seq TO "gm-public";


--
-- Name: TABLE lnk_enc_type2billable; Type: ACL; Schema: bill; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE bill.lnk_enc_type2billable TO "gm-doctors";
GRANT SELECT ON TABLE bill.lnk_enc_type2billable TO "gm-public";


--
-- Name: SEQUENCE lnk_enc_type2billable_pk_seq; Type: ACL; Schema: bill; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE bill.lnk_enc_type2billable_pk_seq TO "gm-public";


--
-- Name: TABLE encounter; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.encounter TO "gm-doctors";
GRANT SELECT,UPDATE ON TABLE clin.encounter TO "gm-staff";


--
-- Name: COLUMN encounter.fk_patient; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT INSERT(fk_patient) ON TABLE clin.encounter TO "gm-staff";


--
-- Name: COLUMN encounter.fk_type; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT INSERT(fk_type) ON TABLE clin.encounter TO "gm-staff";


--
-- Name: COLUMN encounter.fk_location; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT INSERT(fk_location) ON TABLE clin.encounter TO "gm-staff";


--
-- Name: TABLE coding_system_root; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.coding_system_root TO "gm-doctors";


--
-- Name: TABLE billable; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.billable TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.billable TO "gm-doctors";


--
-- Name: TABLE data_source; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.data_source TO "gm-doctors";


--
-- Name: TABLE v_bill_items; Type: ACL; Schema: bill; Owner: gm-dbo
--

GRANT SELECT ON TABLE bill.v_bill_items TO "gm-doctors";


--
-- Name: TABLE v_bills; Type: ACL; Schema: bill; Owner: gm-dbo
--

GRANT SELECT ON TABLE bill.v_bills TO "gm-doctors";


--
-- Name: TABLE doc_desc; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE blobs.doc_desc TO "gm-doctors";


--
-- Name: SEQUENCE doc_desc_pk_seq; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE blobs.doc_desc_pk_seq TO "gm-doctors";


--
-- Name: TABLE doc_med; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT,INSERT,UPDATE ON TABLE blobs.doc_med TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE blobs.doc_med TO "gm-staff";


--
-- Name: SEQUENCE doc_med_pk_seq; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE blobs.doc_med_pk_seq TO "gm-doctors";


--
-- Name: TABLE doc_obj; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE blobs.doc_obj TO "gm-doctors";
GRANT SELECT ON TABLE blobs.doc_obj TO "gm-staff";


--
-- Name: SEQUENCE doc_obj_pk_seq; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE blobs.doc_obj_pk_seq TO "gm-doctors";


--
-- Name: TABLE doc_type; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT INSERT,DELETE,UPDATE ON TABLE blobs.doc_type TO "gm-doctors";
GRANT SELECT ON TABLE blobs.doc_type TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE blobs.doc_type TO "gm-staff";


--
-- Name: SEQUENCE doc_type_pk_seq; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE blobs.doc_type_pk_seq TO "gm-doctors";


--
-- Name: TABLE lnk_doc_med2episode; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE blobs.lnk_doc_med2episode TO "gm-doctors";


--
-- Name: TABLE review_root; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.review_root TO "gm-doctors";


--
-- Name: TABLE reviewed_doc_objs; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE blobs.reviewed_doc_objs TO "gm-doctors";


--
-- Name: TABLE episode; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.episode TO "gm-doctors";


--
-- Name: TABLE health_issue; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.health_issue TO "gm-doctors";


--
-- Name: TABLE org; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.org TO "gm-doctors";


--
-- Name: TABLE org_unit; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.org_unit TO "gm-doctors";


--
-- Name: TABLE v_doc_med; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_doc_med TO "gm-doctors";


--
-- Name: TABLE v_doc_desc; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_doc_desc TO "gm-doctors";


--
-- Name: TABLE encounter_type; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.encounter_type TO "gm-doctors";
GRANT SELECT ON TABLE clin.encounter_type TO "gm-staff";


--
-- Name: TABLE v_doc_med_journal; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_doc_med_journal TO "gm-doctors";


--
-- Name: TABLE document_type; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.document_type TO "gm-doctors";


--
-- Name: TABLE v_doc_type; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_doc_type TO "gm-public";


--
-- Name: TABLE v_obj4doc_no_data; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_obj4doc_no_data TO "gm-doctors";


--
-- Name: TABLE v_latest_mugshot; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_latest_mugshot TO "gm-doctors";


--
-- Name: TABLE v_reviewed_doc_objects; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_reviewed_doc_objects TO "gm-doctors";


--
-- Name: TABLE v_unreviewed_docs; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_unreviewed_docs TO "gm-staff";


--
-- Name: TABLE v_unreviewed_docs_summary; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_unreviewed_docs_summary TO "gm-staff";


--
-- Name: TABLE inbox_item_category; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.inbox_item_category TO "gm-public";


--
-- Name: TABLE inbox_item_type; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.inbox_item_type TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.inbox_item_type TO "gm-public";


--
-- Name: TABLE names; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.names TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.names TO "gm-staff";


--
-- Name: TABLE v_inbox_item_type; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_inbox_item_type TO "gm-public";


--
-- Name: TABLE v_unreviewed_docs_inbox; Type: ACL; Schema: blobs; Owner: gm-dbo
--

GRANT SELECT ON TABLE blobs.v_unreviewed_docs_inbox TO "gm-staff";


--
-- Name: TABLE cfg_data; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.cfg_data TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_data TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_data TO "gm-staff";


--
-- Name: TABLE cfg_item; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.cfg_item TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_item TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_item TO "gm-staff";


--
-- Name: SEQUENCE cfg_item_pk_seq; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE cfg.cfg_item_pk_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE cfg.cfg_item_pk_seq TO "gm-staff";


--
-- Name: TABLE cfg_numeric; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.cfg_numeric TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_numeric TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_numeric TO "gm-staff";


--
-- Name: SEQUENCE cfg_numeric_pk_seq; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE cfg.cfg_numeric_pk_seq TO "gm-public";


--
-- Name: TABLE cfg_str_array; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.cfg_str_array TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_str_array TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_str_array TO "gm-staff";


--
-- Name: SEQUENCE cfg_str_array_pk_seq; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE cfg.cfg_str_array_pk_seq TO "gm-public";


--
-- Name: TABLE cfg_string; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.cfg_string TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_string TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_string TO "gm-staff";


--
-- Name: SEQUENCE cfg_string_pk_seq; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE cfg.cfg_string_pk_seq TO "gm-public";


--
-- Name: TABLE cfg_template; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.cfg_template TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_template TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_template TO "gm-staff";


--
-- Name: SEQUENCE cfg_template_pk_seq; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE cfg.cfg_template_pk_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE cfg.cfg_template_pk_seq TO "gm-staff";


--
-- Name: TABLE cfg_type_enum; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.cfg_type_enum TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.cfg_type_enum TO "gm-doctors";
GRANT SELECT ON TABLE cfg.cfg_type_enum TO "gm-staff";


--
-- Name: TABLE config; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.config TO "gm-public";


--
-- Name: TABLE db_logon_banner; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.db_logon_banner TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE cfg.db_logon_banner TO "gm-doctors";


--
-- Name: TABLE report_query; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE cfg.report_query TO "gm-doctors";


--
-- Name: SEQUENCE report_query_pk_seq; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE cfg.report_query_pk_seq TO "gm-doctors";


--
-- Name: TABLE v_cfg_options; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.v_cfg_options TO "gm-public";


--
-- Name: TABLE v_cfg_opts_data; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.v_cfg_opts_data TO "gm-public";


--
-- Name: TABLE v_cfg_opts_numeric; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.v_cfg_opts_numeric TO "gm-public";


--
-- Name: TABLE v_cfg_opts_str_array; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.v_cfg_opts_str_array TO "gm-public";


--
-- Name: TABLE v_cfg_opts_string; Type: ACL; Schema: cfg; Owner: gm-dbo
--

GRANT SELECT ON TABLE cfg.v_cfg_opts_string TO "gm-public";


--
-- Name: TABLE _enum_allergy_type; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin._enum_allergy_type TO "gm-doctors";


--
-- Name: SEQUENCE _enum_allergy_type_id_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin._enum_allergy_type_id_seq TO "gm-doctors";


--
-- Name: TABLE allergy; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.allergy TO "gm-doctors";


--
-- Name: TABLE allergy_state; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.allergy_state TO "gm-doctors";
GRANT SELECT ON TABLE clin.allergy_state TO "gm-staff";


--
-- Name: COLUMN allergy_state.has_allergy; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT INSERT(has_allergy) ON TABLE clin.allergy_state TO "gm-staff";


--
-- Name: COLUMN allergy_state.fk_encounter; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT INSERT(fk_encounter) ON TABLE clin.allergy_state TO "gm-staff";


--
-- Name: TABLE clin_narrative; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.clin_narrative TO "gm-doctors";


--
-- Name: TABLE external_care; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.external_care TO "gm-doctors";


--
-- Name: TABLE family_history; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.family_history TO "gm-doctors";


--
-- Name: TABLE fhx_relation_type; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.fhx_relation_type TO "gm-doctors";


--
-- Name: TABLE hospital_stay; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.hospital_stay TO "gm-doctors";


--
-- Name: TABLE lnk_code2item_root; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_code2item_root TO "gm-public";


--
-- Name: TABLE lnk_code2aoe; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_code2aoe TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE clin.lnk_code2aoe TO "gm-doctors";


--
-- Name: TABLE lnk_code2episode; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_code2episode TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE clin.lnk_code2episode TO "gm-doctors";


--
-- Name: TABLE lnk_code2fhx; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_code2fhx TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE clin.lnk_code2fhx TO "gm-doctors";


--
-- Name: TABLE lnk_code2h_issue; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_code2h_issue TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE clin.lnk_code2h_issue TO "gm-doctors";


--
-- Name: TABLE lnk_code2procedure; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_code2procedure TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE clin.lnk_code2procedure TO "gm-doctors";


--
-- Name: TABLE lnk_code2rfe; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_code2rfe TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE clin.lnk_code2rfe TO "gm-doctors";


--
-- Name: TABLE lnk_loinc2test_panel; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_loinc2test_panel TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.lnk_loinc2test_panel TO "gm-doctors";


--
-- Name: TABLE meta_test_type; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.meta_test_type TO "gm-doctors";


--
-- Name: TABLE patient; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.patient TO "gm-doctors";


--
-- Name: TABLE procedure; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.procedure TO "gm-doctors";


--
-- Name: TABLE reviewed_test_results; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,UPDATE ON TABLE clin.reviewed_test_results TO "gm-doctors";


--
-- Name: TABLE substance_intake; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.substance_intake TO "gm-doctors";


--
-- Name: TABLE suppressed_hint; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.suppressed_hint TO "gm-staff";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.suppressed_hint TO "gm-doctors";


--
-- Name: TABLE test_org; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.test_org TO "gm-doctors";


--
-- Name: TABLE test_panel; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.test_panel TO "gm-public";


--
-- Name: TABLE test_result; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.test_result TO "gm-doctors";


--
-- Name: TABLE test_type; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.test_type TO "gm-doctors";


--
-- Name: TABLE v_edc_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_edc_journal TO "gm-doctors";


--
-- Name: TABLE v_external_care_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_external_care_journal TO "gm-doctors";


--
-- Name: TABLE v_family_history_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_family_history_journal TO "gm-doctors";


--
-- Name: TABLE identity; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,UPDATE ON TABLE dem.identity TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.identity TO "gm-staff";


--
-- Name: TABLE v_health_issues_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_health_issues_journal TO "gm-doctors";


--
-- Name: TABLE v_hospital_stays_journal_multi_day_adm; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_hospital_stays_journal_multi_day_adm TO "gm-doctors";


--
-- Name: TABLE v_hospital_stays_journal_multi_day_dis; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_hospital_stays_journal_multi_day_dis TO "gm-doctors";


--
-- Name: TABLE v_hospital_stays_journal_no_discharge; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_hospital_stays_journal_no_discharge TO "gm-doctors";


--
-- Name: TABLE v_hospital_stays_journal_one_day; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_hospital_stays_journal_one_day TO "gm-doctors";


--
-- Name: TABLE v_hospital_stays_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_hospital_stays_journal TO "gm-doctors";


--
-- Name: TABLE v_pat_allergies_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_allergies_journal TO "gm-doctors";


--
-- Name: TABLE v_pat_allergy_state_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_allergy_state_journal TO "gm-doctors";


--
-- Name: TABLE v_pat_encounters_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_encounters_journal TO "gm-doctors";


--
-- Name: TABLE v_pat_episodes_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_episodes_journal TO "gm-doctors";


--
-- Name: TABLE v_pat_narrative_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_narrative_journal TO "gm-doctors";


--
-- Name: TABLE v_procedures_at_hospital_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_procedures_at_hospital_journal TO "gm-doctors";


--
-- Name: TABLE v_procedures_not_at_hospital_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_procedures_not_at_hospital_journal TO "gm-doctors";


--
-- Name: TABLE v_procedures_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_procedures_journal TO "gm-doctors";


--
-- Name: TABLE message_inbox; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.message_inbox TO "gm-doctors";


--
-- Name: TABLE v_reminders_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_reminders_journal TO "gm-doctors";


--
-- Name: TABLE dose; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.dose TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE ref.dose TO "gm-doctors";


--
-- Name: TABLE drug_product; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.drug_product TO "gm-doctors";


--
-- Name: TABLE lnk_dose2drug; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.lnk_dose2drug TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE ref.lnk_dose2drug TO "gm-doctors";


--
-- Name: TABLE substance; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.substance TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE ref.substance TO "gm-doctors";


--
-- Name: TABLE v_substance_intake_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_substance_intake_journal TO "gm-doctors";


--
-- Name: TABLE v_suppressed_hints_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_suppressed_hints_journal TO "gm-doctors";


--
-- Name: TABLE v_test_types4test_panel; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_test_types4test_panel TO "gm-public";


--
-- Name: TABLE v_test_types; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_test_types TO "gm-doctors";


--
-- Name: TABLE v_test_results; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_test_results TO "gm-doctors";


--
-- Name: TABLE v_test_results_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_test_results_journal TO "gm-doctors";


--
-- Name: TABLE vaccination; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.vaccination TO "gm-doctors";


--
-- Name: TABLE vaccine; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.vaccine TO "gm-doctors";


--
-- Name: TABLE v_vaccinations_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_vaccinations_journal TO "gm-doctors";


--
-- Name: TABLE v_emr_journal; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_emr_journal TO "gm-doctors";


--
-- Name: TABLE _view_emr_journal_without_suppressed_hints; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin._view_emr_journal_without_suppressed_hints TO "gm-staff";


--
-- Name: SEQUENCE allergy_id_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.allergy_id_seq TO "gm-doctors";


--
-- Name: SEQUENCE allergy_state_id_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.allergy_state_id_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE clin.allergy_state_id_seq TO "gm-public";


--
-- Name: TABLE clin_aux_note; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.clin_aux_note TO "gm-doctors";


--
-- Name: SEQUENCE clin_aux_note_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.clin_aux_note_pk_seq TO "gm-doctors";


--
-- Name: TABLE clin_diag; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.clin_diag TO "gm-doctors";


--
-- Name: SEQUENCE clin_diag_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.clin_diag_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE clin_hx_family_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT ALL ON SEQUENCE clin.clin_hx_family_pk_seq TO "gm-doctors";


--
-- Name: TABLE clin_item_type; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.clin_item_type TO "gm-doctors";


--
-- Name: SEQUENCE clin_item_type_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.clin_item_type_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE clin_narrative_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.clin_narrative_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE clin_root_item_pk_item_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.clin_root_item_pk_item_seq TO "gm-doctors";


--
-- Name: SEQUENCE encounter_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.encounter_pk_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE clin.encounter_pk_seq TO "gm-staff";


--
-- Name: SEQUENCE encounter_type_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.encounter_type_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE episode_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.episode_pk_seq TO "gm-doctors";


--
-- Name: TABLE export_item; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.export_item TO "gm-staff";


--
-- Name: SEQUENCE export_item_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.export_item_pk_seq TO "gm-staff";


--
-- Name: SEQUENCE external_care_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.external_care_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE fhx_relation_type_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.fhx_relation_type_pk_seq TO "gm-doctors";


--
-- Name: TABLE form_data; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.form_data TO "gm-doctors";


--
-- Name: SEQUENCE form_data_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.form_data_pk_seq TO "gm-doctors";


--
-- Name: TABLE form_instances; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.form_instances TO "gm-doctors";


--
-- Name: SEQUENCE form_instances_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.form_instances_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE health_issue_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.health_issue_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE hospital_stay_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT ALL ON SEQUENCE clin.hospital_stay_pk_seq TO "gm-doctors";


--
-- Name: TABLE incoming_data_unmatchable; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.incoming_data_unmatchable TO "gm-doctors";


--
-- Name: SEQUENCE incoming_data_unmatchable_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT ALL ON SEQUENCE clin.incoming_data_unmatchable_pk_seq TO "gm-doctors";


--
-- Name: TABLE incoming_data_unmatched; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.incoming_data_unmatched TO "gm-doctors";


--
-- Name: SEQUENCE incoming_data_unmatched_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.incoming_data_unmatched_pk_seq TO "gm-doctors";


--
-- Name: TABLE lab_request; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.lab_request TO "gm-doctors";


--
-- Name: SEQUENCE lab_request_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.lab_request_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_code2aoe_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_code2aoe_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_code2episode_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_code2episode_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_code2fhx_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_code2fhx_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_code2h_issue_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_code2h_issue_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_code2item_root_pk_lnk_code2item_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_code2item_root_pk_lnk_code2item_seq TO "gm-public";


--
-- Name: TABLE lnk_code2narrative; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_code2narrative TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE clin.lnk_code2narrative TO "gm-doctors";


--
-- Name: SEQUENCE lnk_code2narrative_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_code2narrative_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_code2procedure_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_code2procedure_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_code2rfe_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_code2rfe_pk_seq TO "gm-doctors";


--
-- Name: TABLE lnk_code2tst_pnl; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.lnk_code2tst_pnl TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE clin.lnk_code2tst_pnl TO "gm-doctors";


--
-- Name: SEQUENCE lnk_code2tst_pnl_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_code2tst_pnl_pk_seq TO "gm-doctors";


--
-- Name: TABLE lnk_constraint2vacc_course; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.lnk_constraint2vacc_course TO "gm-doctors";


--
-- Name: SEQUENCE lnk_constraint2vacc_course_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.lnk_constraint2vacc_course_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_loinc2test_panel_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.lnk_loinc2test_panel_pk_seq TO "gm-doctors";


--
-- Name: TABLE lnk_pat2vaccination_course; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.lnk_pat2vaccination_course TO "gm-doctors";


--
-- Name: SEQUENCE lnk_pat2vaccination_course_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.lnk_pat2vaccination_course_pk_seq TO "gm-doctors";


--
-- Name: TABLE lnk_substance2episode; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.lnk_substance2episode TO "gm-doctors";


--
-- Name: SEQUENCE lnk_substance2episode_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT ALL ON SEQUENCE clin.lnk_substance2episode_pk_seq TO "gm-doctors";


--
-- Name: TABLE lnk_tst2norm; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.lnk_tst2norm TO "gm-doctors";


--
-- Name: SEQUENCE lnk_tst2norm_id_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.lnk_tst2norm_id_seq TO "gm-doctors";


--
-- Name: TABLE lnk_type2item; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.lnk_type2item TO "gm-doctors";


--
-- Name: SEQUENCE lnk_type2item_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.lnk_type2item_pk_seq TO "gm-doctors";


--
-- Name: TABLE lnk_vaccination_course2schedule; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.lnk_vaccination_course2schedule TO "gm-doctors";


--
-- Name: SEQUENCE lnk_vaccination_course2schedule_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.lnk_vaccination_course2schedule_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE patient_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.patient_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE procedure_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT ALL ON SEQUENCE clin.procedure_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE review_root_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.review_root_pk_seq TO "gm-doctors";


--
-- Name: TABLE soap_cat_ranks; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.soap_cat_ranks TO "gm-doctors";


--
-- Name: SEQUENCE substance_intake_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.substance_intake_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE suppressed_hint_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.suppressed_hint_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE test_org_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.test_org_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE test_panel_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE clin.test_panel_pk_seq TO "gm-public";


--
-- Name: SEQUENCE test_result_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.test_result_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE test_type_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.test_type_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE test_type_unified_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.test_type_unified_pk_seq TO "gm-doctors";


--
-- Name: TABLE v_candidate_diagnoses; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_candidate_diagnoses TO "gm-doctors";


--
-- Name: TABLE marital_status; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.marital_status TO "gm-doctors";


--
-- Name: TABLE v_all_persons; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_all_persons TO "gm-public";


--
-- Name: TABLE v_export_items; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_export_items TO "gm-staff";


--
-- Name: TABLE v_external_care; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_external_care TO "gm-doctors";


--
-- Name: TABLE v_family_history; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_family_history TO "gm-doctors";


--
-- Name: TABLE v_health_issues; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_health_issues TO "gm-doctors";


--
-- Name: TABLE v_hospital_stays; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_hospital_stays TO "gm-doctors";


--
-- Name: TABLE v_incoming_data_unmatched; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_incoming_data_unmatched TO "gm-doctors";


--
-- Name: TABLE v_linked_codes; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_linked_codes TO "gm-public";


--
-- Name: TABLE v_most_recent_encounters; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_most_recent_encounters TO "gm-doctors";


--
-- Name: COLUMN v_most_recent_encounters.pk_encounter; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT(pk_encounter) ON TABLE clin.v_most_recent_encounters TO "gm-staff";


--
-- Name: COLUMN v_most_recent_encounters.pk_patient; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT(pk_patient) ON TABLE clin.v_most_recent_encounters TO "gm-staff";


--
-- Name: COLUMN v_most_recent_encounters.last_affirmed; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT(last_affirmed) ON TABLE clin.v_most_recent_encounters TO "gm-staff";


--
-- Name: TABLE v_narrative; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_narrative TO "gm-doctors";


--
-- Name: TABLE v_pat_allergies; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_allergies TO "gm-doctors";
GRANT SELECT ON TABLE clin.v_pat_allergies TO "gm-staff";


--
-- Name: TABLE v_pat_allergy_state; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_allergy_state TO "gm-doctors";
GRANT SELECT ON TABLE clin.v_pat_allergy_state TO "gm-staff";


--
-- Name: TABLE v_pat_encounters; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_encounters TO "gm-doctors";


--
-- Name: TABLE v_pat_episodes; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_episodes TO "gm-doctors";


--
-- Name: TABLE v_pat_items; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_items TO "gm-doctors";


--
-- Name: TABLE v_pat_vaccs4indication; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_vaccs4indication TO "gm-doctors";


--
-- Name: TABLE v_pat_last_vacc4indication; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_pat_last_vacc4indication TO "gm-doctors";


--
-- Name: TABLE v_potential_problem_list; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_potential_problem_list TO "gm-doctors";


--
-- Name: TABLE v_problem_list; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_problem_list TO "gm-doctors";


--
-- Name: TABLE v_procedures_at_hospital; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_procedures_at_hospital TO "gm-doctors";


--
-- Name: TABLE v_procedures_not_at_hospital; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_procedures_not_at_hospital TO "gm-doctors";


--
-- Name: TABLE v_procedures; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_procedures TO "gm-doctors";


--
-- Name: TABLE v_reviewed_items; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_reviewed_items TO "gm-doctors";


--
-- Name: TABLE v_subst_intake4narr_search; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_subst_intake4narr_search TO "gm-doctors";


--
-- Name: TABLE lnk_loinc2substance; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.lnk_loinc2substance TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.lnk_loinc2substance TO "gm-doctors";


--
-- Name: TABLE v_substance_intakes; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_substance_intakes TO "gm-doctors";


--
-- Name: TABLE v_suppressed_hints; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_suppressed_hints TO "gm-doctors";


--
-- Name: TABLE v_test_orgs; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_test_orgs TO "gm-public";


--
-- Name: TABLE v_test_panels; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_test_panels TO "gm-doctors";


--
-- Name: TABLE vaccination_course; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.vaccination_course TO "gm-doctors";


--
-- Name: TABLE vaccination_schedule; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.vaccination_schedule TO "gm-doctors";


--
-- Name: TABLE v_vaccination_courses_in_schedule; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_vaccination_courses_in_schedule TO "gm-doctors";


--
-- Name: TABLE v_vaccinations; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_vaccinations TO "gm-doctors";


--
-- Name: TABLE waiting_list; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.waiting_list TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.waiting_list TO "gm-staff";


--
-- Name: TABLE v_waiting_list; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT ON TABLE clin.v_waiting_list TO "gm-public";


--
-- Name: TABLE vaccination_course_constraint; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.vaccination_course_constraint TO "gm-doctors";


--
-- Name: SEQUENCE vaccination_course_constraint_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.vaccination_course_constraint_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE vaccination_course_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.vaccination_course_pk_seq TO "gm-doctors";


--
-- Name: TABLE vaccination_definition; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE clin.vaccination_definition TO "gm-doctors";


--
-- Name: SEQUENCE vaccination_definition_id_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.vaccination_definition_id_seq TO "gm-doctors";


--
-- Name: SEQUENCE vaccination_id_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.vaccination_id_seq TO "gm-doctors";


--
-- Name: SEQUENCE vaccination_schedule_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.vaccination_schedule_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE waiting_list_pk_seq; Type: ACL; Schema: clin; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE clin.waiting_list_pk_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE clin.waiting_list_pk_seq TO "gm-public";


--
-- Name: TABLE address; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT INSERT,DELETE,UPDATE ON TABLE dem.address TO "gm-doctors";
GRANT SELECT ON TABLE dem.address TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE dem.address TO "gm-staff";


--
-- Name: SEQUENCE address_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.address_id_seq TO "gm-public";


--
-- Name: TABLE address_type; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT INSERT,DELETE,UPDATE ON TABLE dem.address_type TO "gm-doctors";
GRANT SELECT ON TABLE dem.address_type TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE dem.address_type TO "gm-staff";


--
-- Name: SEQUENCE address_type_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.address_type_id_seq TO "gm-public";


--
-- Name: TABLE country; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT INSERT,DELETE,UPDATE ON TABLE dem.country TO "gm-doctors";
GRANT SELECT ON TABLE dem.country TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE dem.country TO "gm-staff";


--
-- Name: SEQUENCE country_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.country_id_seq TO "gm-public";


--
-- Name: TABLE enum_comm_types; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.enum_comm_types TO "gm-doctors";
GRANT SELECT ON TABLE dem.enum_comm_types TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE dem.enum_comm_types TO "gm-staff";


--
-- Name: SEQUENCE enum_comm_types_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.enum_comm_types_id_seq TO "gm-public";


--
-- Name: TABLE enum_ext_id_types; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.enum_ext_id_types TO "gm-doctors";
GRANT SELECT ON TABLE dem.enum_ext_id_types TO "gm-staff";


--
-- Name: SEQUENCE enum_ext_id_types_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.enum_ext_id_types_pk_seq TO "gm-doctors";


--
-- Name: TABLE gender_label; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.gender_label TO "gm-doctors";


--
-- Name: SEQUENCE gender_label_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.gender_label_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE identity_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.identity_pk_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE dem.identity_pk_seq TO "gm-staff";


--
-- Name: TABLE identity_tag; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.identity_tag TO "gm-doctors";


--
-- Name: SEQUENCE identity_tag_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.identity_tag_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE inbox_item_category_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,USAGE ON SEQUENCE dem.inbox_item_category_pk_seq TO "gm-public";


--
-- Name: SEQUENCE inbox_item_type_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.inbox_item_type_pk_seq TO "gm-doctors";
GRANT SELECT,USAGE ON SEQUENCE dem.inbox_item_type_pk_seq TO "gm-public";


--
-- Name: TABLE lnk_identity2comm; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.lnk_identity2comm TO "gm-doctors";
GRANT SELECT ON TABLE dem.lnk_identity2comm TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE dem.lnk_identity2comm TO "gm-staff";


--
-- Name: SEQUENCE lnk_identity2comm_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.lnk_identity2comm_id_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE dem.lnk_identity2comm_id_seq TO "gm-public";


--
-- Name: TABLE lnk_identity2ext_id; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.lnk_identity2ext_id TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.lnk_identity2ext_id TO "gm-staff";


--
-- Name: SEQUENCE lnk_identity2ext_id_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.lnk_identity2ext_id_id_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE dem.lnk_identity2ext_id_id_seq TO "gm-public";


--
-- Name: TABLE lnk_job2person; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.lnk_job2person TO "gm-doctors";


--
-- Name: SEQUENCE lnk_job2person_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.lnk_job2person_id_seq TO "gm-doctors";


--
-- Name: TABLE lnk_org_unit2comm; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.lnk_org_unit2comm TO "gm-public";


--
-- Name: SEQUENCE lnk_org_unit2comm_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.lnk_org_unit2comm_pk_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE dem.lnk_org_unit2comm_pk_seq TO "gm-staff";


--
-- Name: TABLE lnk_org_unit2ext_id; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.lnk_org_unit2ext_id TO "gm-public";


--
-- Name: SEQUENCE lnk_org_unit2ext_id_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.lnk_org_unit2ext_id_pk_seq TO "gm-staff";


--
-- Name: TABLE lnk_person_org_address; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.lnk_person_org_address TO "gm-doctors";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.lnk_person_org_address TO "gm-staff";


--
-- Name: TABLE lnk_person2address; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.lnk_person2address TO "gm-doctors";


--
-- Name: TABLE lnk_person2relative; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.lnk_person2relative TO "gm-doctors";


--
-- Name: SEQUENCE lnk_person2relative_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.lnk_person2relative_id_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_person_org_address_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.lnk_person_org_address_id_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE dem.lnk_person_org_address_id_seq TO "gm-staff";


--
-- Name: TABLE name_gender_map; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.name_gender_map TO "gm-public";


--
-- Name: SEQUENCE names_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.names_id_seq TO "gm-doctors";
GRANT USAGE ON SEQUENCE dem.names_id_seq TO "gm-staff";


--
-- Name: TABLE occupation; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.occupation TO "gm-doctors";


--
-- Name: SEQUENCE occupation_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.occupation_id_seq TO "gm-doctors";


--
-- Name: TABLE org_category; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.org_category TO "gm-doctors";


--
-- Name: SEQUENCE org_category_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.org_category_id_seq TO "gm-doctors";


--
-- Name: SEQUENCE org_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.org_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE org_unit_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.org_unit_pk_seq TO "gm-doctors";


--
-- Name: TABLE praxis_branch; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.praxis_branch TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE dem.praxis_branch TO "gm-doctors";


--
-- Name: SEQUENCE praxis_branch_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.praxis_branch_pk_seq TO "gm-public";


--
-- Name: SEQUENCE provider_inbox_pk_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE dem.provider_inbox_pk_seq TO "gm-doctors";


--
-- Name: TABLE region; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT INSERT,DELETE,UPDATE ON TABLE dem.region TO "gm-doctors";
GRANT SELECT ON TABLE dem.region TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE dem.region TO "gm-staff";


--
-- Name: TABLE relation_types; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE dem.relation_types TO "gm-doctors";


--
-- Name: SEQUENCE state_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.state_id_seq TO "gm-public";


--
-- Name: TABLE street; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT INSERT,DELETE,UPDATE ON TABLE dem.street TO "gm-doctors";
GRANT SELECT ON TABLE dem.street TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE dem.street TO "gm-staff";


--
-- Name: SEQUENCE street_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.street_id_seq TO "gm-public";


--
-- Name: TABLE urb; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT INSERT,DELETE,UPDATE ON TABLE dem.urb TO "gm-doctors";
GRANT SELECT ON TABLE dem.urb TO "gm-public";
GRANT INSERT,DELETE,UPDATE ON TABLE dem.urb TO "gm-staff";


--
-- Name: SEQUENCE urb_id_seq; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE dem.urb_id_seq TO "gm-public";


--
-- Name: TABLE v_active_persons; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_active_persons TO "gm-public";


--
-- Name: TABLE v_address; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_address TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_address TO "gm-public";


--
-- Name: TABLE v_basic_address; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_basic_address TO "gm-public";


--
-- Name: TABLE v_deleted_persons; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_deleted_persons TO "gm-doctors";


--
-- Name: TABLE v_external_ids4identity; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_external_ids4identity TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_external_ids4identity TO "gm-staff";


--
-- Name: TABLE v_external_ids4org_unit; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_external_ids4org_unit TO "gm-staff";


--
-- Name: TABLE v_gender_labels; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_gender_labels TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_gender_labels TO "gm-staff";


--
-- Name: TABLE tag_image; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.tag_image TO "gm-doctors";
GRANT SELECT ON TABLE ref.tag_image TO "gm-staff";


--
-- Name: TABLE v_identity_tags; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_identity_tags TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_identity_tags TO "gm-staff";


--
-- Name: TABLE v_message_inbox; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_message_inbox TO "gm-doctors";


--
-- Name: TABLE v_org_unit_comms; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_org_unit_comms TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_org_unit_comms TO "gm-staff";


--
-- Name: TABLE v_org_units; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_org_units TO "gm-public";


--
-- Name: TABLE v_org_units_no_praxis_check; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_org_units_no_praxis_check TO "gm-public";


--
-- Name: TABLE v_orgs; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_orgs TO "gm-public";


--
-- Name: TABLE v_pat_addresses; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_pat_addresses TO "gm-doctors";


--
-- Name: TABLE v_person_comms; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_person_comms TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_person_comms TO "gm-staff";


--
-- Name: TABLE v_person_jobs; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_person_jobs TO "gm-doctors";


--
-- Name: TABLE v_person_names; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_person_names TO "gm-public";


--
-- Name: TABLE v_persons; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_persons TO "gm-public";


--
-- Name: TABLE v_praxis_branches; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_praxis_branches TO "gm-public";


--
-- Name: TABLE v_region; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_region TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_region TO "gm-public";


--
-- Name: TABLE v_staff; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_staff TO "gm-public";


--
-- Name: TABLE v_urb; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_urb TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_urb TO "gm-public";


--
-- Name: TABLE v_street; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_street TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_street TO "gm-public";


--
-- Name: TABLE v_zip2street; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_zip2street TO "gm-public";


--
-- Name: TABLE v_uniq_zipped_urbs; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_uniq_zipped_urbs TO "gm-doctors";
GRANT SELECT ON TABLE dem.v_uniq_zipped_urbs TO "gm-public";


--
-- Name: TABLE v_zip2data; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_zip2data TO "gm-public";


--
-- Name: TABLE v_zip2urb; Type: ACL; Schema: dem; Owner: gm-dbo
--

GRANT SELECT ON TABLE dem.v_zip2urb TO "gm-public";


--
-- Name: SEQUENCE access_log_pk_seq; Type: ACL; Schema: gm; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE gm.access_log_pk_seq TO "gm-public";


--
-- Name: TABLE schema_revision; Type: ACL; Schema: gm; Owner: gm-dbo
--

GRANT SELECT ON TABLE gm.schema_revision TO "gm-public";


--
-- Name: TABLE notifying_tables; Type: ACL; Schema: gm; Owner: gm-dbo
--

GRANT SELECT ON TABLE gm.notifying_tables TO "gm-doctors";
GRANT SELECT ON TABLE gm.notifying_tables TO "gm-staff";


--
-- Name: TABLE curr_lang; Type: ACL; Schema: i18n; Owner: gm-dbo
--

GRANT SELECT ON TABLE i18n.curr_lang TO "gm-public";


--
-- Name: TABLE keys; Type: ACL; Schema: i18n; Owner: gm-dbo
--

GRANT SELECT ON TABLE i18n.keys TO "gm-public";


--
-- Name: TABLE translations; Type: ACL; Schema: i18n; Owner: gm-dbo
--

GRANT SELECT ON TABLE i18n.translations TO "gm-public";


--
-- Name: TABLE v_missing_translations; Type: ACL; Schema: i18n; Owner: gm-dbo
--

GRANT SELECT ON TABLE i18n.v_missing_translations TO "gm-public";


--
-- Name: TABLE basic_unit; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT ON TABLE public.basic_unit TO "gm-public";


--
-- Name: TABLE form_job_queue; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT ON TABLE public.form_job_queue TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.form_job_queue TO "gm-doctors";


--
-- Name: SEQUENCE form_job_queue_pk_seq; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE public.form_job_queue_pk_seq TO "gm-doctors";


--
-- Name: TABLE form_job_targets; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT ON TABLE public.form_job_targets TO "gm-public";


--
-- Name: TABLE form_print_defs; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT ON TABLE public.form_print_defs TO "gm-public";


--
-- Name: TABLE gm_client_db_match; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT ON TABLE public.gm_client_db_match TO "gm-public";


--
-- Name: TABLE housekeeping_todo; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT,INSERT ON TABLE public.housekeeping_todo TO "gm-public";
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.housekeeping_todo TO "gm-doctors";


--
-- Name: SEQUENCE housekeeping_todo_pk_seq; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT ON SEQUENCE public.housekeeping_todo_pk_seq TO "gm-public";
GRANT SELECT,UPDATE ON SEQUENCE public.housekeeping_todo_pk_seq TO "gm-doctors";


--
-- Name: TABLE test_norm; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT ON TABLE public.test_norm TO "gm-public";


--
-- Name: TABLE unit; Type: ACL; Schema: public; Owner: gm-dbo
--

GRANT SELECT ON TABLE public.unit TO "gm-public";


--
-- Name: TABLE atc; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.atc TO "gm-doctors";


--
-- Name: TABLE atc_staging; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.atc_staging TO "gm-doctors";


--
-- Name: SEQUENCE billable_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE ref.billable_pk_seq TO "gm-public";


--
-- Name: TABLE coda; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.coda TO "gm-public";


--
-- Name: TABLE code_thesaurus_root; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.code_thesaurus_root TO "gm-doctors";


--
-- Name: SEQUENCE coding_system_root_pk_coding_system_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE ref.coding_system_root_pk_coding_system_seq TO "gm-doctors";


--
-- Name: SEQUENCE data_source_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE ref.data_source_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE dose_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE ref.dose_pk_seq TO "gm-public";


--
-- Name: TABLE form_types; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.form_types TO "gm-doctors";


--
-- Name: SEQUENCE form_types_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE ref.form_types_pk_seq TO "gm-doctors";


--
-- Name: TABLE icd10; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.icd10 TO "gm-public";


--
-- Name: TABLE icd9; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.icd9 TO "gm-public";


--
-- Name: TABLE icpc; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.icpc TO "gm-doctors";


--
-- Name: TABLE icpc_chapter; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.icpc_chapter TO "gm-doctors";


--
-- Name: TABLE icpc_component; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.icpc_component TO "gm-doctors";


--
-- Name: TABLE icpc_thesaurus; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.icpc_thesaurus TO "gm-doctors";


--
-- Name: TABLE keyword_expansion; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.keyword_expansion TO "gm-doctors";


--
-- Name: SEQUENCE keyword_expansion_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE ref.keyword_expansion_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE lnk_dose2drug_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE ref.lnk_dose2drug_pk_seq TO "gm-public";


--
-- Name: SEQUENCE lnk_loinc2substance_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE ref.lnk_loinc2substance_pk_seq TO "gm-doctors";


--
-- Name: TABLE loinc; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.loinc TO "gm-doctors";


--
-- Name: SEQUENCE loinc_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE ref.loinc_pk_seq TO "gm-doctors";


--
-- Name: TABLE ops; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.ops TO "gm-public";


--
-- Name: TABLE other_code; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.other_code TO "gm-public";


--
-- Name: TABLE papersizes; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.papersizes TO "gm-public";


--
-- Name: TABLE paperwork_templates; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE ref.paperwork_templates TO "gm-doctors";


--
-- Name: SEQUENCE paperwork_templates_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE ref.paperwork_templates_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE substance_brand_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE ref.substance_brand_pk_seq TO "gm-doctors";


--
-- Name: SEQUENCE substance_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT USAGE ON SEQUENCE ref.substance_pk_seq TO "gm-public";


--
-- Name: SEQUENCE tag_image_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE ref.tag_image_pk_seq TO "gm-doctors";


--
-- Name: TABLE v_atc; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_atc TO "gm-public";


--
-- Name: TABLE v_billables; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_billables TO "gm-public";


--
-- Name: TABLE v_coded_terms; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_coded_terms TO "gm-public";


--
-- Name: TABLE v_substances; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_substances TO "gm-public";


--
-- Name: TABLE v_substance_doses; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_substance_doses TO "gm-public";


--
-- Name: TABLE v_drug_components; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_drug_components TO "gm-public";


--
-- Name: TABLE v_drug_products; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_drug_products TO "gm-doctors";


--
-- Name: TABLE v_generic_codes; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_generic_codes TO "gm-public";


--
-- Name: TABLE v_icpc; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_icpc TO "gm-doctors";


--
-- Name: TABLE v_icpc_thesaurus; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_icpc_thesaurus TO "gm-doctors";


--
-- Name: TABLE vacc_route; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.vacc_route TO "gm-public";


--
-- Name: TABLE v_indications4vaccine; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_indications4vaccine TO "gm-public";


--
-- Name: TABLE v_keyword_expansions; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_keyword_expansions TO "gm-doctors";


--
-- Name: TABLE v_lnk_loincs2substances; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_lnk_loincs2substances TO "gm-public";


--
-- Name: TABLE v_paperwork_templates; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_paperwork_templates TO "gm-doctors";


--
-- Name: TABLE v_tag_images_no_data; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_tag_images_no_data TO "gm-doctors";
GRANT SELECT ON TABLE ref.v_tag_images_no_data TO "gm-public";


--
-- Name: TABLE v_vaccines; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_vaccines TO "gm-public";


--
-- Name: TABLE v_your_keyword_expansions; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT ON TABLE ref.v_your_keyword_expansions TO "gm-doctors";


--
-- Name: SEQUENCE vaccine_pk_seq; Type: ACL; Schema: ref; Owner: gm-dbo
--

GRANT SELECT,UPDATE ON SEQUENCE ref.vaccine_pk_seq TO "gm-doctors";


--
-- Name: TABLE lab_request; Type: ACL; Schema: staging; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE staging.lab_request TO "gm-doctors";


--
-- Name: TABLE test_result; Type: ACL; Schema: staging; Owner: gm-dbo
--

GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE staging.test_result TO "gm-doctors";


--
--

