forked from dokaptur/dkm-healthcare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbprojekt.dbs
420 lines (420 loc) · 19 KB
/
dbprojekt.dbs
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<?xml version="1.0" encoding="UTF-8" ?>
<project name="dkm-healthcare" id="Project46912" database="PostgreSQL" >
<schema name="dkm-healthcare" schemaname="dkm-healthcare" defo="y" >
<table name="aptekarze" />
<table name="lekarze" >
<column name="id_lekarz" type="char" length="11" jt="1" mandatory="y" />
<column name="prawa" type="bool" jt="-7" mandatory="y" >
<defo>'true'</defo>
</column>
<index name="pk_lekarze" unique="PRIMARY_KEY" >
<column name="id_lekarz" />
</index>
<fk name="fk_lekarze" to_schema="dkm-healthcare" to_table="osoby" delete_action="cascade" update_action="cascade" >
<fk_column name="id_lekarz" pk="pesel" />
</fk>
</table>
<table name="lekarze_placowki" >
<column name="id_lekarz" type="char" length="11" jt="1" mandatory="y" />
<column name="id_placowka" type="numeric" jt="2" mandatory="y" />
<index name="idx_lekarz_placowki" unique="PRIMARY_KEY" >
<column name="id_lekarz" />
<column name="id_placowka" />
</index>
<index name="pk_lekarz_placowki" unique="UNIQUE" >
<column name="id_placowka" />
</index>
<index name="idx_lekarz_placowki_0" unique="NORMAL" >
<column name="id_lekarz" />
</index>
<fk name="fk_lekarz_placowki" to_schema="dkm-healthcare" to_table="placowki" delete_action="cascade" update_action="cascade" >
<fk_column name="id_placowka" pk="id_placowka" />
</fk>
<fk name="fk_lekarz_placowki_0" to_schema="dkm-healthcare" to_table="lekarze" delete_action="cascade" update_action="cascade" >
<fk_column name="id_lekarz" pk="id_lekarz" />
</fk>
</table>
<table name="lekarze_specjalizacje" >
<column name="id_lekarz" type="char" length="11" jt="1" mandatory="y" />
<column name="id_spec" type="integer" jt="4" mandatory="y" />
<index name="idx_lekarz_specjalizacja" unique="PRIMARY_KEY" >
<column name="id_lekarz" />
<column name="id_spec" />
</index>
<index name="idx_lekarz_specjalizacja_0" unique="NORMAL" >
<column name="id_lekarz" />
</index>
<index name="idx_lekarz_specjalizacja_1" unique="NORMAL" >
<column name="id_spec" />
</index>
<fk name="fk_lekarz_specjalizacja_0" to_schema="dkm-healthcare" to_table="specjalizacje" delete_action="cascade" update_action="cascade" >
<fk_column name="id_spec" pk="id_spec" />
</fk>
<fk name="fk_lekarz_specjalizacja" to_schema="dkm-healthcare" to_table="lekarze" delete_action="cascade" update_action="cascade" >
<fk_column name="id_lekarz" pk="id_lekarz" />
</fk>
</table>
<table name="osoby" >
<column name="pesel" type="char" length="11" jt="1" mandatory="y" />
<column name="haslo" type="char" length="32" jt="1" mandatory="y" />
<column name="n" type="integer" jt="4" mandatory="y" >
<defo>1</defo>
</column>
<column name="n_iteracja" type="char" length="32" jt="1" />
<column name="imie" type="varchar" length="20" jt="12" mandatory="y" />
<column name="nazwisko" type="varchar" length="50" jt="12" mandatory="y" />
<column name="data_urodzenia" type="date" jt="91" mandatory="y" />
<column name="adres" type="text" jt="12" />
<column name="aptekarz" type="bool" jt="-7" />
<column name="admin" type="bool" jt="-7" mandatory="y" >
<defo>'false'</defo>
</column>
<column name="email" type="text" jt="12" />
<index name="pk_osoby" unique="PRIMARY_KEY" >
<column name="pesel" />
</index>
</table>
<table name="osoby_alergie" >
<column name="pesel" type="char" length="11" jt="1" mandatory="y" />
<column name="alergia" type="text" jt="12" />
<index name="pk_osoby_alerigie" unique="PRIMARY_KEY" >
<column name="pesel" />
</index>
<fk name="fk_osoby_alerigie" to_schema="dkm-healthcare" to_table="osoby" delete_action="cascade" update_action="cascade" >
<fk_column name="pesel" pk="pesel" />
</fk>
</table>
<table name="osoby_info" >
<column name="pesel" type="char" length="11" jt="1" mandatory="y" />
<column name="lekarz rodzinny" type="char" length="11" jt="1" />
<column name="historia_modyfikacja" type="date" jt="91" mandatory="y" >
<defo>current_date</defo>
</column>
<column name="info" type="text" jt="12" />
<index name="pk_osoby_info" unique="PRIMARY_KEY" >
<column name="pesel" />
</index>
<index name="idx_osoby_info" unique="NORMAL" >
<column name="lekarz rodzinny" />
</index>
<constraint name="ck_1" >
<string>pesel != lekarz_rodzinny</string>
</constraint>
<fk name="fk_osoby_info" to_schema="dkm-healthcare" to_table="osoby" delete_action="cascade" update_action="cascade" >
<fk_column name="pesel" pk="pesel" />
</fk>
<fk name="fk_osoby_info_0" to_schema="dkm-healthcare" to_table="lekarze" delete_action="setNull" update_action="cascade" >
<fk_column name="lekarz rodzinny" pk="id_lekarz" />
</fk>
</table>
<table name="osoby_leki" >
<column name="pesel" type="char" length="11" jt="1" mandatory="y" />
<column name="lek" type="text" jt="12" />
<index name="pk_osoby_leki" unique="PRIMARY_KEY" >
<column name="pesel" />
</index>
<fk name="fk_osoby_leki" to_schema="dkm-healthcare" to_table="osoby" delete_action="cascade" update_action="cascade" >
<fk_column name="pesel" pk="pesel" />
</fk>
</table>
<table name="pacjenci_specjalisci" >
<column name="pesel" type="char" length="11" jt="1" mandatory="y" />
<column name="id_lekarz" type="char" length="11" jt="1" mandatory="y" />
<index name="idx_pacjenci_specjalisci" unique="PRIMARY_KEY" >
<column name="pesel" />
<column name="id_lekarz" />
</index>
<index name="pk_pacjenci_specjalisci" unique="UNIQUE" >
<column name="pesel" />
</index>
<index name="idx_pacjenci_specjalisci_0" unique="UNIQUE" >
<column name="id_lekarz" />
</index>
<constraint name="ck_0" >
<string>pesel != id_lekarz</string>
</constraint>
<fk name="fk_pacjenci_specjalisci" to_schema="dkm-healthcare" to_table="lekarze" delete_action="cascade" update_action="cascade" >
<fk_column name="id_lekarz" pk="id_lekarz" />
</fk>
<fk name="fk_pacjenci_specjalisci_0" to_schema="dkm-healthcare" to_table="osoby" delete_action="cascade" update_action="cascade" >
<fk_column name="pesel" pk="pesel" />
</fk>
</table>
<table name="pacjent_l" />
<table name="placowki" >
<column name="id_placowka" type="numeric" jt="2" mandatory="y" />
<column name="typ" type="text" jt="12" mandatory="y" />
<column name="nazwa" type="text" jt="12" mandatory="y" />
<column name="adres" type="text" jt="12" mandatory="y" />
<column name="miasto" type="text" jt="12" mandatory="y" />
<column name="nr_tel" type="numeric" jt="2" mandatory="y" />
<index name="pk_placowki" unique="PRIMARY_KEY" >
<column name="id_placowka" />
</index>
<constraint name="typ_check" >
<string>typ in ('poradnia', 'szpital', 'przychodnia')</string>
</constraint>
</table>
<table name="placowki_zabiegi" >
<column name="id_placowka" type="numeric" jt="2" mandatory="y" />
<column name="id_zabieg" type="integer" jt="4" mandatory="y" />
<index name="idx_placowki_zabiegi" unique="PRIMARY_KEY" >
<column name="id_placowka" />
<column name="id_zabieg" />
</index>
<index name="idx_placowki_zabiegi_0" unique="NORMAL" >
<column name="id_placowka" />
</index>
<index name="idx_placowki_zabiegi_1" unique="NORMAL" >
<column name="id_zabieg" />
</index>
<fk name="fk_placowki_zabiegi" to_schema="dkm-healthcare" to_table="placowki" delete_action="cascade" update_action="cascade" >
<fk_column name="id_placowka" pk="id_placowka" />
</fk>
<fk name="fk_placowki_zabiegi_0" to_schema="dkm-healthcare" to_table="zabiegi" delete_action="cascade" update_action="cascade" >
<fk_column name="id_zabieg" pk="id_zabieg" />
</fk>
</table>
<table name="recepty" >
<column name="numer" type="numeric" jt="2" mandatory="y" >
<defo>'nextval('seq_nr_recepty')'</defo>
</column>
<column name="pesel" type="char" length="11" jt="1" mandatory="y" />
<column name="id_lekarz" type="char" length="11" jt="1" />
<column name="zrealizowana_przez" type="char" length="11" jt="1" />
<column name="lek" type="text" jt="12" mandatory="y" />
<column name="data_waznosci" type="date" jt="91" >
<defo>current_date + interval '3 month'</defo>
</column>
<column name="zrealizowana" type="bool" jt="-7" mandatory="y" >
<defo>'false'</defo>
</column>
<index name="pk_recepty" unique="PRIMARY_KEY" >
<column name="numer" />
</index>
<index name="idx_recepty" unique="NORMAL" >
<column name="id_lekarz" />
</index>
<index name="idx_recepty_0" unique="NORMAL" >
<column name="pesel" />
</index>
<index name="idx_recepty_1" unique="NORMAL" >
<column name="zrealizowana_przez" />
</index>
<fk name="fk_recepty" to_schema="dkm-healthcare" to_table="osoby" delete_action="cascade" update_action="cascade" >
<fk_column name="pesel" pk="pesel" />
</fk>
<fk name="fk_recepty_0" to_schema="dkm-healthcare" to_table="lekarze" delete_action="setNull" update_action="cascade" >
<fk_column name="id_lekarz" pk="id_lekarz" />
</fk>
<fk name="fk_recepty_1" to_schema="dkm-healthcare" to_table="osoby" delete_action="setNull" update_action="cascade" >
<fk_column name="zrealizowana_przez" pk="pesel" />
</fk>
</table>
<table name="skierowania" >
<column name="numer" type="numeric" jt="2" mandatory="y" >
<defo>'nextval('seq_nr_skier')'</defo>
</column>
<column name="pesel" type="char" length="11" jt="1" mandatory="y" />
<column name="id_lekarz" type="char" length="11" jt="1" />
<column name="id_zabieg" type="integer" jt="4" mandatory="y" />
<column name="zrealizowany" type="bool" jt="-7" mandatory="y" >
<defo>'false'</defo>
</column>
<index name="pk_skierowania" unique="PRIMARY_KEY" >
<column name="numer" />
</index>
<index name="idx_skierowania" unique="NORMAL" >
<column name="pesel" />
</index>
<index name="idx_skierowania_0" unique="NORMAL" >
<column name="id_lekarz" />
</index>
<index name="idx_skierowania_1" unique="NORMAL" >
<column name="id_zabieg" />
</index>
<fk name="fk_skierowania_1" to_schema="dkm-healthcare" to_table="zabiegi" delete_action="cascade" update_action="cascade" >
<fk_column name="id_zabieg" pk="id_zabieg" />
</fk>
<fk name="fk_skierowania" to_schema="dkm-healthcare" to_table="osoby" delete_action="cascade" update_action="cascade" >
<fk_column name="pesel" pk="pesel" />
</fk>
<fk name="fk_skierowania_0" to_schema="dkm-healthcare" to_table="lekarze" delete_action="setNull" update_action="cascade" >
<fk_column name="id_lekarz" pk="id_lekarz" />
</fk>
</table>
<table name="specjalizacje" >
<column name="nazwa" type="text" jt="12" mandatory="y" />
<column name="id_spec" type="integer" jt="4" mandatory="y" />
<index name="pk_specjalizacje" unique="PRIMARY_KEY" >
<column name="id_spec" />
</index>
</table>
<table name="zabiegi" >
<column name="id_zabieg" type="integer" jt="4" mandatory="y" >
<defo>'nextval('seq_id_zabieg')'</defo>
</column>
<column name="nazwa" type="text" jt="12" mandatory="y" />
<index name="pk_zabiegi" unique="PRIMARY_KEY" >
<column name="id_zabieg" />
</index>
</table>
<view name="historia_powiadomienia" >
<view_script><![CDATA[SELECT imie,nazwisko,email FROM "dkm-healthcare".osoby natural join "dkm-healthcare".osoby_info
where historia_modyfikacja=current_date order by pesel;]]></view_script>
<column name="email" type="text" />
<column name="imie" type="varchar" />
<column name="nazwisko" type="varchar" />
</view>
<view name="recepty_powiadomienia_5" >
<view_script><![CDATA[SELECT imie,nazwisko,email, numer as "recepta" FROM "dkm-healthcare".osoby natural join "dkm-healthcare".recepty
where zrealizowana=false and email is not null and
extract(day from age(data_waznosci, current_date))=5 order by pesel;]]></view_script>
<column name="email" type="text" />
<column name="imie" type="varchar" />
<column name="nazwisko" type="varchar" />
<column name="recepta" type="numeric" />
</view>
<view name="recepty_powiadomienia_dzis" >
<view_script><![CDATA[SELECT imie,nazwisko,email, numer as "recepta" FROM "dkm-healthcare".osoby natural join "dkm-healthcare".recepty
where zrealizowana=false and email is not null and
data_waznosci=current_date order by pesel;]]></view_script>
<column name="email" type="text" />
<column name="imie" type="varchar" />
<column name="nazwisko" type="varchar" />
<column name="recepta" type="numeric" />
</view>
<view name="zabiegi_info" >
<view_script><![CDATA[SELECT z.nazwa, id_zabieg ,adres, miasto, nr_tel from "dkm-healthcare".zabiegi z natural join "dkm-healthcare".placowki_zabiegi
join "dkm-healthcare".placowki p using (id_placowka) order by id_zabieg;]]></view_script>
<column name="adres" type="text" />
<column name="id_zabieg" type="serial" />
<column name="miasto" type="text" />
<column name="nazwa" type="text" />
<column name="nr_tel" type="numeric" />
</view>
<sequence name="seq_id_zabieg" start="1" suffix="increment by 1" />
<sequence name="seq_nr_recepty" start="1" suffix="increment by 1" />
<sequence name="seq_nr_skier" start="1" suffix="increment by 1" />
<trigger name="add_osoba_info" id="Trigger3195256" isSystem="false" >
<string><![CDATA[create trigger add_osoba_info after insert on osoby for row
execute procedure add_osoba_info();]]></string>
</trigger>
<trigger name="change_pesel_check" id="Trigger3454664" isSystem="false" >
<string><![CDATA[create trigger change_pesel_check before update on osoby for row
execute procedure change_pesel_check();]]></string>
</trigger>
<trigger name="pesel_check" id="Trigger2056020" isSystem="false" >
<string><![CDATA[create trigger pesel_check before insert on osoby
for each row execute procedure pesel_check();
]]></string>
</trigger>
<trigger name="recepty_check" id="Trigger2579310" isSystem="false" >
<string><![CDATA[create trigger recepty_check before insert on recepty for row
execute procedure recepty_check();]]></string>
</trigger>
<trigger name="skier_check" id="Trigger2426865" isSystem="false" >
<string><![CDATA[create trigger skier_check before insert on skierowania for row
execute procedure skier_check();]]></string>
</trigger>
<trigger name="zabieg_check" id="Trigger2709646" isSystem="false" >
<string><![CDATA[create trigger zabieg_check before insert on zabiegi for row
execute procedure zabiegi_check();]]></string>
</trigger>
<function name="add_osoba_info" id="Function2845147" isSystem="false" >
<string><![CDATA[create or replace function add_osoba_info() returns trigger as $$
begin
insert into osoby_info(pesel) values (new.pesel);
return new;
end;
$$ language plpgsql;]]></string>
</function>
<function name="change_pesel_check" id="Function3353531" isSystem="false" >
<string><![CDATA[create or replace function change_pesel_check() returns trigger as $$
begin
new.pesel=old.pesel;
return new;
end;
$$ language plpgsql;]]></string>
</function>
<function name="getchar" id="Function1869974" isSystem="false" >
<string><![CDATA[create or replace function getchar(pesel char(11), i integer) returns integer as $$
begin
return cast(substr(pesel, i, 1) as integer);
end;
$$ language pgplsql;]]></string>
</function>
<function name="pesel_check" id="Function1989459" isSystem="false" >
<string><![CDATA[create or replace function pesel_check() returns trigger as
$$
begin
if (1 * getchar(new.pesel, 1) + 3 * getchar(new.pesel, 2) + 7 * getchar(new.pesel, 3) + 9 * getchar(new.pesel, 4) + 1 * getchar(new.pesel, 5) + 3 * getchar(new.pesel, 6) + 7 * getchar(new.pesel, 7) + 9 * getchar(new.pesel, 8) + 1 * getchar(new.pesel, 9) + 3 * getchar(new.pesel, 10) + getchar(new.pesel, 11)) % 10 = 0 then
return new;
else
return null;
end if;
end;
$$ language plpgsql;]]></string>
</function>
<function name="recepty_check" id="Function2535139" isSystem="false" >
<string><![CDATA[create or replace function recepty_check() returns trigger as $$
declare
x numeric := nextval('seq_nr_recepty');
begin
while x in (select numer from recepty) loop
x = nextval('seq_nr_recepty');
end loop;
new.numer=x;
return new;
end;
$$ language plpqsql;]]></string>
</function>
<function name="skier_check" id="Function2163187" isSystem="false" >
<string><![CDATA[create or replace function skier_check() returns trigger as $$
declare
x numeric := nextval('seq_nr_skier');
begin
while x in (select numer from skierowania) loop
x = nextval('seq_nr_skier');
end loop;
new.numer=x;
return new;
end;
$$ language plpqsql;]]></string>
</function>
<function name="zabiegi_check" id="Function2644246" isSystem="false" >
<string><![CDATA[create or replace function zabiegi_check() returns trigger as $$
declare
x numeric := nextval('seq_id_zabieg');
begin
while x in (select id_zabieg from zabiegi) loop
x = nextval('seq_id_zabieg');
end loop;
new.id_zabieg=x;
return new;
end;
$$ language plpqsql;]]></string>
</function>
</schema>
<connector name="PostgreSQL" database="PostgreSQL" driver_class="org.postgresql.Driver" driver_jar="postgresql-9.2-1003.jdbc3.jar" host="localhost" port="5432" instance="dkm" user="dudu" schema_mapping="" />
<layout id="Layout46916" name="dkm-healthcare" show_relation_columns="y" >
<entity schema="dkm-healthcare" name="specjalizacje" color="a8c4ef" x="555" y="630" />
<entity schema="dkm-healthcare" name="placowki_zabiegi" color="a8c4ef" x="1185" y="60" />
<entity schema="dkm-healthcare" name="placowki" color="a8c4ef" x="1020" y="195" />
<entity schema="dkm-healthcare" name="lekarze" color="a8c4ef" x="645" y="75" />
<entity schema="dkm-healthcare" name="recepty" color="a8c4ef" x="780" y="480" />
<entity schema="dkm-healthcare" name="zabiegi" color="a8c4ef" x="990" y="45" />
<entity schema="dkm-healthcare" name="skierowania" color="a8c4ef" x="420" y="390" />
<entity schema="dkm-healthcare" name="pacjenci_specjalisci" color="a8c4ef" x="435" y="255" />
<entity schema="dkm-healthcare" name="lekarze_placowki" color="a8c4ef" x="795" y="285" />
<entity schema="dkm-healthcare" name="lekarze_specjalizacje" color="a8c4ef" x="345" y="585" />
<entity schema="dkm-healthcare" name="recepty_powiadomienia_5" color="a8c4ef" x="1005" y="510" />
<entity schema="dkm-healthcare" name="zabiegi_info" color="a8c4ef" x="1200" y="495" />
<entity schema="dkm-healthcare" name="recepty_powiadomienia_dzis" color="a8c4ef" x="1005" y="645" />
<entity schema="dkm-healthcare" name="osoby_leki" color="a8c4ef" x="210" y="645" />
<entity schema="dkm-healthcare" name="osoby_alergie" color="a8c4ef" x="60" y="660" />
<entity schema="dkm-healthcare" name="historia_powiadomienia" color="a8c4ef" x="1050" y="390" />
<entity schema="dkm-healthcare" name="osoby" color="a8c4ef" x="45" y="75" />
<entity schema="dkm-healthcare" name="osoby_info" color="a8c4ef" x="60" y="510" />
</layout>
</project>