-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathv9_migration.sql
63 lines (55 loc) · 2.03 KB
/
v9_migration.sql
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
CREATE TABLE ehr.originating_system_item_ids (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() ,
id_value TEXT, -- identifier value
issuer TEXT, -- authority responsible for the identification (ex. France ASIP, LDAP server etc.)
assigner TEXT, -- assigner of the identifier
type_name TEXT, -- coding origin f.ex. INS-C, INS-A, NHS etc.
feeder_audit_id UUID not null -- entity identified with this identifier
);
CREATE TABLE ehr.feeder_system_item_ids (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() ,
id_value TEXT, -- identifier value
issuer TEXT, -- authority responsible for the identification (ex. France ASIP, LDAP server etc.)
assigner TEXT, -- assigner of the identifier
type_name TEXT, -- coding origin f.ex. INS-C, INS-A, NHS etc.
feeder_audit_id UUID not null -- entity identified with this identifier
);
CREATE TABLE ehr.originating_system_audit (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() ,
system_id TEXT,
location UUID,
subject UUID,
provider UUID,
time TIMESTAMP,
time_tz TEXT,
version_id TEXT
);
CREATE TABLE ehr.feeder_system_audit (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() ,
system_id TEXT,
location UUID,
subject UUID,
provider UUID,
time TIMESTAMP,
time_tz TEXT,
version_id TEXT
);
-- CREATE TABLE ehr.originating_system_audit (LIKE ehr.feeder_audit_details);
-- CREATE TABLE ehr.feeder_system_audit (LIKE ehr.feeder_audit_details);
CREATE TABLE ehr.feeder_audit (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4() ,
composition_id UUID REFERENCES ehr.composition(id),
originating_system_audit UUID REFERENCES ehr.originating_system_audit(id) ON DELETE CASCADE ,
original_content BYTEA,
feeder_system_audit UUID REFERENCES ehr.feeder_system_audit(id) ON DELETE CASCADE
);
ALTER TABLE ehr.originating_system_item_ids
ADD CONSTRAINT feeder_audit_fk
FOREIGN KEY (feeder_audit_id)
REFERENCES ehr.feeder_audit(id)
ON DELETE CASCADE;
ALTER TABLE ehr.feeder_system_item_ids
ADD CONSTRAINT feeder_audit_fk
FOREIGN KEY (feeder_audit_id)
REFERENCES ehr.feeder_audit(id)
ON DELETE CASCADE;