gnumed_v18=# \d clin.substance_intake
                                              Table "clin.substance_intake"
        Column         |           Type           |
  Modifiers
-----------------------+--------------------------+-----------------------------
------------------------------------------
 pk_audit              | integer                  | not null default nextval('au
dit.audit_fields_pk_audit_seq'::regclass)
 row_version           | integer                  | not null default 0
 modified_when         | timestamp with time zone | not null default now()
 modified_by           | name                     | not null default "current_us
er"()
 pk_item               | integer                  | not null default nextval('cl
in.clin_root_item_pk_item_seq'::regclass)
 clin_when             | timestamp with time zone | not null default now()
 fk_encounter          | integer                  | not null
 fk_episode            | integer                  | not null
 narrative             | text                     |
 soap_cat              | text                     | default 'p'::text
 pk                    | integer                  | not null default nextval('cl
in.substance_intake_pk_seq'::regclass)
 fk_substance          | integer                  |
 preparation           | text                     |
 schedule              | text                     |
 aim                   | text                     |
 duration              | interval                 |
 intake_is_approved_of | boolean                  | not null
 is_long_term          | boolean                  |
 discontinued          | timestamp with time zone |
 discontinue_reason    | text                     |
 fk_drug_component     | integer                  |
Indexes:
    "substance_intake_pkey" PRIMARY KEY, btree (pk)
    "idx_c_subst_int_fk_drug_comp" btree (fk_drug_component)
    "idx_fk_substance_curr_med" btree (fk_substance)
Check constraints:
    "clin_root_item_sane_soap_cat" CHECK (soap_cat IS NULL OR (lower(soap_cat) =
 ANY (ARRAY['s'::text, 'o'::text, 'a'::text, 'p'::text, 'u'::text])))
    "clin_subst_intake_either_drug_or_substance" CHECK (fk_drug_component IS NUL
L AND fk_substance IS NOT NULL OR fk_drug_component IS NOT NULL AND fk_substance
 IS NULL)
    "clin_subst_intake_sane_prep" CHECK (fk_drug_component IS NULL AND preparati
on IS NOT NULL OR fk_drug_component IS NOT NULL AND preparation IS NULL)
    "discontinued_after_started" CHECK (clin_when IS NULL OR discontinued IS NUL
L OR discontinued >= clin_when AND discontinued <= now())
    "medication_is_plan" CHECK (soap_cat = 'p'::text)
    "sane_aim" CHECK (gm.is_null_or_non_empty_string(aim) IS TRUE)
    "sane_discontinue_reason" CHECK (discontinued IS NULL AND discontinue_reason
 IS NULL OR discontinued IS NOT NULL AND gm.is_null_or_non_empty_string(disconti
nue_reason) IS TRUE)
    "sane_fk_episode" CHECK (intake_is_approved_of IS FALSE OR intake_is_approve
d_of IS TRUE AND fk_episode IS NOT NULL)
    "sane_schedule" CHECK (gm.is_null_or_non_empty_string(schedule) IS TRUE)
Foreign-key constraints:
    "substance_intake_fk_drug_component_fkey" FOREIGN KEY (fk_drug_component) RE
FERENCES ref.lnk_substance2brand(pk) ON UPDATE RESTRICT ON DELETE RESTRICT
    "substance_intake_fk_substance_fkey" FOREIGN KEY (fk_substance) REFERENCES r
ef.consumable_substance(pk) ON UPDATE CASCADE ON DELETE CASCADE
Referenced by:
    TABLE "clin.lnk_substance2episode" CONSTRAINT "lnk_substance2episode_fk_subs
tance_fkey" FOREIGN KEY (fk_substance) REFERENCES clin.substance_intake(pk) ON U
PDATE CASCADE ON DELETE RESTRICT
Triggers:
    tr_delete_intake_document_deleted BEFORE DELETE ON clin.substance_intake FOR
 EACH ROW EXECUTE PROCEDURE clin.trf_delete_intake_document_deleted()
    tr_delete_intake_turns_other_components_into_substances AFTER DELETE ON clin
.substance_intake FOR EACH ROW EXECUTE PROCEDURE clin.trf_delete_intake_turns_ot
her_components_into_substances()
    tr_insert_intake_links_all_drug_components AFTER INSERT ON clin.substance_in
take FOR EACH ROW EXECUTE PROCEDURE clin.trf_insert_intake_links_all_drug_compon
ents()
    tr_insert_intake_prevent_duplicate_component_links BEFORE INSERT ON clin.sub
stance_intake FOR EACH ROW EXECUTE PROCEDURE clin.trf_insert_intake_prevent_dupl
icate_component_links()
    tr_insert_update_intake_prevent_duplicate_substance_links AFTER INSERT OR UP
DATE ON clin.substance_intake DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE
 PROCEDURE clin.trf_insert_update_intake_prevent_duplicate_substance_links()
    tr_narrative_mod AFTER INSERT OR DELETE OR UPDATE ON clin.substance_intake D
EFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE clin.trf_announce_n
arrative_mod()
    tr_sanity_check_enc_epi_insert BEFORE INSERT ON clin.substance_intake FOR EA
CH ROW EXECUTE PROCEDURE clin.trf_sanity_check_enc_epi_insert()
    tr_sanity_check_substance_episode BEFORE INSERT OR UPDATE ON clin.substance_
intake FOR EACH ROW EXECUTE PROCEDURE clin.trf_sanity_check_substance_episode()
    tr_substance_intake_mod AFTER INSERT OR DELETE OR UPDATE ON clin.substance_i
ntake DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE clin.trf_ann
ounce_substance_intake_mod()
    tr_undiscontinue_unsets_reason BEFORE INSERT OR UPDATE ON clin.substance_int
ake FOR EACH ROW EXECUTE PROCEDURE clin.trf_undiscontinue_unsets_reason()
    tr_update_intake_must_link_all_drug_components AFTER UPDATE ON clin.substanc
e_intake DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE clin.trf_u
pdate_intake_must_link_all_drug_components()
    tr_update_intake_updates_all_drug_components AFTER UPDATE ON clin.substance_
intake DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE PROCEDURE clin.trf_upd
ate_intake_updates_all_drug_components()
    zt_del_substance_intake BEFORE DELETE ON clin.substance_intake FOR EACH ROW
EXECUTE PROCEDURE audit.ft_del_substance_intake()
    zt_ins_substance_intake BEFORE INSERT ON clin.substance_intake FOR EACH ROW
EXECUTE PROCEDURE audit.ft_ins_substance_intake()
    zt_upd_substance_intake BEFORE UPDATE ON clin.substance_intake FOR EACH ROW
EXECUTE PROCEDURE audit.ft_upd_substance_intake()
Inherits: clin.clin_root_item