1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
-- ==============================================================
-- GNUmed database schema change script
--
-- License: GPL v2 or later
-- Author: Karsten Hilbert
--
-- ==============================================================
-- $Id: v9-clin-coded_phrase.sql,v 1.1 2008-01-27 21:06:00 ncq Exp $
-- $Revision: 1.1 $
-- --------------------------------------------------------------
\set ON_ERROR_STOP 1
-- --------------------------------------------------------------
\unset ON_ERROR_STOP
drop function audit.ft_del_coded_narrative() cascade;
drop function audit.ft_upd_coded_narrative() cascade;
drop function audit.ft_ins_coded_narrative() cascade;
\set ON_ERROR_STOP 1
select audit.add_table_for_audit('clin', 'coded_phrase');
delete from audit.audited_tables where schema = 'clin' and table_name = 'coded_narrative';
comment on table clin.coded_phrase is
'associates codes with text snippets
which may be in use in clinical tables';
comment on column clin.coded_phrase.term is
'the text snippet that is to be coded';
comment on column clin.coded_phrase.code is
'the code in the coding system';
comment on column clin.coded_phrase.xfk_coding_system is
'the coding system used to code the text snippet';
\unset ON_ERROR_STOP
drop view clin.v_coded_phrases cascade;
\set ON_ERROR_STOP 1
create view clin.v_coded_phrases as
select
term,
code,
xfk_coding_system as coding_system
from
clin.coded_phrase
union
select
term,
code,
coding_system
from
ref.v_coded_terms
;
grant select on clin.v_coded_phrases to group "gm-doctors";
\unset ON_ERROR_STOP
drop function clin.add_coded_term(text, text, text) cascade;
\set ON_ERROR_STOP 1
create or replace function clin.add_coded_phrase(text, text, text) returns boolean as '
declare
_term alias for $1;
_code alias for $2;
_system alias for $3;
_tmp text;
begin
select into _tmp 1 from clin.coded_phrase where
term = _term
and code = _code
and xfk_coding_system = _system;
if found then
return True;
end if;
insert into clin.coded_phrase (term, code, xfk_coding_system)
values (_term, _code, _system);
return True;
end;' language 'plpgsql';
-- --------------------------------------------------------------
select gm.log_script_insertion('$RCSfile: v9-clin-coded_phrase.sql,v $', '$Revision: 1.1 $');
-- ==============================================================
-- $Log: v9-clin-coded_phrase.sql,v $
-- Revision 1.1 2008-01-27 21:06:00 ncq
-- - new
--
--
|