[5e4f0d7] | 1 |
|
---|
| 2 | drop schema if exists project cascade;
|
---|
| 3 |
|
---|
| 4 | create schema project;
|
---|
| 5 |
|
---|
| 6 | drop table if exists bolnica cascade;
|
---|
| 7 | drop table if exists bolnica_telefonski_broevi cascade;
|
---|
| 8 | drop table if exists covek cascade;
|
---|
| 9 | drop table if exists doktor cascade;
|
---|
| 10 | drop table if exists lekovi cascade;
|
---|
| 11 | drop table if exists oddel cascade;
|
---|
| 12 | drop table if exists pacient cascade;
|
---|
| 13 | drop table if exists pregled cascade;
|
---|
| 14 | drop table if exists recepta cascade;
|
---|
| 15 | drop table if exists rezervacija cascade;
|
---|
| 16 | drop table if exists specijalnost cascade;
|
---|
| 17 | drop table if exists telefonski_broevi cascade;
|
---|
| 18 | drop table if exists termin cascade;
|
---|
| 19 | drop table if exists transakcija cascade;
|
---|
| 20 | drop table if exists upat cascade;
|
---|
| 21 |
|
---|
| 22 | -- Covek (covek_id, e-mail, password, ime, prezime, EMBG)
|
---|
| 23 |
|
---|
| 24 | create table covek(
|
---|
| 25 | covek_id serial,
|
---|
| 26 | email varchar (50) not null unique,
|
---|
| 27 | pass varchar (50) not null,
|
---|
| 28 | ime varchar (50) not null,
|
---|
| 29 | prezime varchar (50) not null,
|
---|
| 30 | embg char (13) not null unique,
|
---|
| 31 | constraint pk_covek_id primary key (covek_id),
|
---|
| 32 | constraint ck_pass check (length (pass) >= 8)
|
---|
| 33 | );
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | -- Telefonski_br (covek_id*(Covek), telefonski_br)
|
---|
| 38 |
|
---|
| 39 | create table telefonski_broevi(
|
---|
| 40 | covek_broj_id integer,
|
---|
| 41 | telefonski_broj varchar (30),
|
---|
| 42 | constraint pk_telefonski_broj primary key (covek_broj_id, telefonski_broj),
|
---|
| 43 | constraint fk_telefonski_br_covek foreign key (covek_broj_id) references covek(covek_id)
|
---|
| 44 | );
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | --Specijalnost (spec_id, naziv)
|
---|
| 48 |
|
---|
| 49 | create table specijalnost(
|
---|
| 50 | spec_id serial,
|
---|
| 51 | naziv varchar (100) not null,
|
---|
| 52 | constraint pk_spec_id primary key (spec_id)
|
---|
| 53 | );
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | -- Bolnica (bolnica_id, naziv, smetka_bolnica, grad, broj, ulica)
|
---|
| 58 |
|
---|
| 59 | create table bolnica(
|
---|
| 60 | bolnica_id serial,
|
---|
| 61 | naziv varchar (100) not null,
|
---|
| 62 | grad varchar (20) not null,
|
---|
| 63 | broj integer not null,
|
---|
| 64 | ulica varchar (100) not null,
|
---|
| 65 | smetka_bolnica varchar (100) not null unique,
|
---|
| 66 | constraint pk_bolnica_id primary key (bolnica_id)
|
---|
| 67 | );
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | -- Bolnica_telefonski_br (bolnica_id*(Bolnica), telefonski_br)
|
---|
| 72 |
|
---|
| 73 | create table bolnica_telefonski_broevi(
|
---|
| 74 | bolnica_id integer,
|
---|
| 75 | telefonski_br_bolnica varchar (30),
|
---|
| 76 | constraint pk_telefonski_broj_bolnica primary key (bolnica_id, telefonski_br_bolnica),
|
---|
| 77 | constraint fk_telefonski_br_bolnica foreign key (bolnica_id) references bolnica(bolnica_id)
|
---|
| 78 | );
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | --Oddel (bolnica_id*(Bolnica), oddel_id, naziv, spec_id*(Specijalnost))
|
---|
| 83 |
|
---|
| 84 | create table oddel(
|
---|
| 85 | bolnica_id integer,
|
---|
| 86 | oddel_id serial,
|
---|
| 87 | naziv varchar (100) not null,
|
---|
| 88 | spec_id integer,
|
---|
| 89 | constraint pk_oddel_id primary key (bolnica_id, oddel_id),
|
---|
| 90 | constraint fk_oddel_id foreign key (bolnica_id) references bolnica(bolnica_id),
|
---|
| 91 | constraint fk_specijalnot_vo_oddel foreign key (spec_id) references specijalnost(spec_id)
|
---|
| 92 | );
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | -- Doktor (doktor_id*(Covek), br_licenca, opis, spec_id*(Specijalnost), (bolnica_id, oddel_id)*(Oddel))
|
---|
| 97 |
|
---|
| 98 | create table Doktor(
|
---|
| 99 | doktor_id integer,
|
---|
| 100 | br_licenca integer not null,
|
---|
| 101 | opis varchar (50),
|
---|
| 102 | spec_id integer,
|
---|
| 103 | oddel_id integer not null,
|
---|
| 104 | bolnica_id integer,
|
---|
| 105 | constraint pk_doktor_id primary key (doktor_id),
|
---|
| 106 | constraint fk_covek_id foreign key (doktor_id) references covek(covek_id),
|
---|
| 107 | constraint fk_doktor_specijalnost foreign key (spec_id) references specijalnost(spec_id),
|
---|
| 108 | constraint fk_doktor_raboti_oddel foreign key (bolnica_id, oddel_id) references oddel(bolnica_id, oddel_id)
|
---|
| 109 | );
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | -- Termin (doktor_id*(Doktor), termin_id, vreme)
|
---|
| 114 |
|
---|
| 115 | create table Termin(
|
---|
| 116 | termin_id serial,
|
---|
| 117 | doktor_id integer,
|
---|
| 118 | vreme timestamp not null,
|
---|
| 119 | constraint pk_termin primary key (doktor_id, termin_id),
|
---|
| 120 | constraint fk_doktor_id foreign key (doktor_id) references doktor(doktor_id)
|
---|
| 121 | );
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | -- Pacient (covek_pacient_id*(Covek), pacient_id)
|
---|
| 126 |
|
---|
| 127 | create table pacient(
|
---|
| 128 | covek_pacient_id integer,
|
---|
| 129 | pacient_id integer not null,
|
---|
| 130 | constraint pk_pacient_covek_id primary key (covek_pacient_id),
|
---|
| 131 | constraint fk_pacient_covek_id foreign key (covek_pacient_id) references covek(covek_id)
|
---|
| 132 | );
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | -- Pregled (pregled_id, vreme, doktor_id*(Doktor), covek_pacient_id*(Pacient))
|
---|
| 137 |
|
---|
| 138 | create table pregled (
|
---|
| 139 | pregled_id serial,
|
---|
| 140 | vreme timestamp not null,
|
---|
| 141 | doktor_id integer,
|
---|
| 142 | covek_pacient_id integer not null,
|
---|
| 143 | constraint pk_pregled_id primary key (pregled_id),
|
---|
| 144 | constraint fk_doktor_pregleduva foreign key (doktor_id) references doktor(doktor_id),
|
---|
| 145 | constraint fk_odi_na_prelged foreign key (covek_pacient_id) references pacient(covek_pacient_id)
|
---|
| 146 | );
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | -- Upat (upat_id, dijagnoza, covek_pacient_id*(Pacient), pregled_id*(Pregled), oddel_id*(Oddel))
|
---|
| 151 |
|
---|
| 152 | create table upat (
|
---|
| 153 | upat_id serial,
|
---|
| 154 | dijagnoza varchar (150) not null,
|
---|
| 155 | covek_pacient_id integer not null,
|
---|
| 156 | pregled_id integer,
|
---|
| 157 | bolnica_id integer not null,
|
---|
| 158 | oddel_id integer not null,
|
---|
| 159 | constraint pk_upat_id primary key (upat_id),
|
---|
| 160 | constraint fk_pacinet_dobiva_upat foreign key (covek_pacient_id) references pacient(covek_pacient_id),
|
---|
| 161 | constraint fk_se_dobiva_upat_od_prelged foreign key (pregled_id) references pregled(pregled_id),
|
---|
| 162 | constraint fk_izdaden_za_oddel foreign key (bolnica_id, oddel_id) references oddel(bolnica_id, oddel_id)
|
---|
| 163 | );
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | -- Rezervacija (rezervacija_id, upat_id*(Upat), termin_id*(Termin))
|
---|
| 168 |
|
---|
| 169 | create table rezervacija (
|
---|
| 170 | rezervacija_id serial,
|
---|
| 171 | upat_id integer,
|
---|
| 172 | termin_id integer not null,
|
---|
| 173 | doktor_id integer not null,
|
---|
| 174 | constraint pk_rezervacija_id primary key (rezervacija_id),
|
---|
| 175 | constraint fk_upat_rezervacija foreign key (upat_id) references upat(upat_id),
|
---|
| 176 | constraint fk_rezervacija_vo_termin foreign key (doktor_id, termin_id) references termin(doktor_id, termin_id)
|
---|
| 177 | );
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 |
|
---|
| 181 | --Transakcija (tran_id, suma, smetka_bolnica, rezervacija_id*(Rezervacija))
|
---|
| 182 |
|
---|
| 183 | create table transakcija (
|
---|
| 184 | tran_id serial,
|
---|
| 185 | suma integer not null,
|
---|
| 186 | smetka_bolnica varchar (100) not null,
|
---|
| 187 | rezervacija_id integer,
|
---|
| 188 | constraint pk_tran_id primary key (tran_id),
|
---|
| 189 | constraint fk_transakcija_rezervacija foreign key (rezervacija_id) references rezervacija(rezervacija_id)
|
---|
| 190 | );
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | -- Lekovi (lek_id, ime_lek, genericko_ime)
|
---|
| 195 |
|
---|
| 196 | create table lekovi (
|
---|
| 197 | lek_id serial,
|
---|
| 198 | ime_lek varchar (100) not null,
|
---|
| 199 | genericko_ime varchar (100) not null,
|
---|
| 200 | constraint pk_lek_id primary key (lek_id)
|
---|
| 201 | );
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | -- Recepta (recepta_id, datum_izdavanje, datum_vaznost, datum_kupuvanje, pregled_id*(Pregled), lek_id*(Lekovi), doktor_id*(Doktor), covek_pacient_id*(Pacient))
|
---|
| 206 |
|
---|
| 207 | create table recepta (
|
---|
| 208 | recepta_id serial,
|
---|
| 209 | datum_izdavanje timestamp not null,
|
---|
| 210 | datum_vaznost timestamp not null,
|
---|
| 211 | datum_kupuvanje timestamp,
|
---|
| 212 | pregled_id integer,
|
---|
| 213 | lek_id integer not null,
|
---|
| 214 | doktor_id integer not null,
|
---|
| 215 | covek_pacient_id integer not null,
|
---|
| 216 | constraint pk_recepta_id primary key (recepta_id),
|
---|
| 217 | constraint fk_recepta_od_pregled foreign key (pregled_id) references pregled(pregled_id),
|
---|
| 218 | constraint fk_lek_od_recepta foreign key (lek_id) references lekovi(lek_id),
|
---|
| 219 | constraint fk_doktor_prepisuva_recepta foreign key (doktor_id) references doktor(doktor_id),
|
---|
| 220 | constraint fk_recepta_pacient foreign key (covek_pacient_id) references pacient(covek_pacient_id)
|
---|
| 221 | );
|
---|
| 222 |
|
---|