-
Notifications
You must be signed in to change notification settings - Fork 143
/
sormas_schema.sql
13701 lines (11171 loc) · 694 KB
/
sormas_schema.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
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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- If a DB update was performed, insert a new line with a comment to the table SCHEMA_VERSION.
-- Example: INSERT INTO schema_version (version_number, comment) VALUES (1, 'Init database');
-- #1
CREATE TABLE schema_version
(
version_number integer NOT NULL,
changedate timestamp without time zone NOT NULL DEFAULT now(),
comment character varying(255),
CONSTRAINT schema_version_pkey PRIMARY KEY (version_number )
)
WITH (
OIDS=FALSE
);
ALTER TABLE schema_version OWNER TO sormas_user;
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
--
-- TOC entry 483 (class 2612 OID 11574)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres
--
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- TOC entry 142 (class 1259 OID 341910)
-- Name: cases; Type: TABLE; Schema: public; Owner: sormas_user; Tablespace:
--
CREATE TABLE cases (
id bigint NOT NULL,
casestatus character varying(255),
changedate timestamp without time zone NOT NULL,
confirmeddate timestamp without time zone,
creationdate timestamp without time zone NOT NULL,
description character varying(512),
disease character varying(255),
investigateddate timestamp without time zone,
negativedate timestamp without time zone,
nocasedate timestamp without time zone,
postivedate timestamp without time zone,
recovereddate timestamp without time zone,
reportdate timestamp without time zone,
suspectdate timestamp without time zone,
uuid character varying(36) NOT NULL,
caseofficer_id bigint,
casesupervisor_id bigint,
contactofficer_id bigint,
contactsupervisor_id bigint,
healthfacility_id bigint,
illlocation_id bigint,
reportinguser_id bigint,
surveillanceofficer_id bigint,
surveillancesupervisor_id bigint,
person_id bigint NOT NULL
);
ALTER TABLE cases OWNER TO sormas_user;
--
-- TOC entry 148 (class 1259 OID 341964)
-- Name: community; Type: TABLE; Schema: public; Owner: sormas_user; Tablespace:
--
CREATE TABLE community (
id bigint NOT NULL,
changedate timestamp without time zone NOT NULL,
creationdate timestamp without time zone NOT NULL,
name character varying(255),
uuid character varying(36) NOT NULL,
district_id bigint NOT NULL
);
ALTER TABLE community OWNER TO sormas_user;
--
-- TOC entry 147 (class 1259 OID 341957)
-- Name: district; Type: TABLE; Schema: public; Owner: sormas_user; Tablespace:
--
CREATE TABLE district (
id bigint NOT NULL,
changedate timestamp without time zone NOT NULL,
creationdate timestamp without time zone NOT NULL,
name character varying(255),
uuid character varying(36) NOT NULL,
region_id bigint NOT NULL
);
ALTER TABLE district OWNER TO sormas_user;
--
-- TOC entry 151 (class 1259 OID 342106)
-- Name: entity_seq; Type: SEQUENCE; Schema: public; Owner: sormas_user
--
CREATE SEQUENCE entity_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE entity_seq OWNER TO sormas_user;
--
-- TOC entry 149 (class 1259 OID 341971)
-- Name: facility; Type: TABLE; Schema: public; Owner: sormas_user; Tablespace:
--
CREATE TABLE facility (
id bigint NOT NULL,
changedate timestamp without time zone NOT NULL,
creationdate timestamp without time zone NOT NULL,
name character varying(255),
publicownership boolean,
type character varying(255),
uuid character varying(36) NOT NULL,
location_id bigint
);
ALTER TABLE facility OWNER TO sormas_user;
--
-- TOC entry 144 (class 1259 OID 341930)
-- Name: location; Type: TABLE; Schema: public; Owner: sormas_user; Tablespace:
--
CREATE TABLE location (
id bigint NOT NULL,
address character varying(255),
changedate timestamp without time zone NOT NULL,
city character varying(255),
creationdate timestamp without time zone NOT NULL,
details character varying(255),
latitude double precision,
longitude double precision,
uuid character varying(36) NOT NULL,
community_id bigint,
district_id bigint,
region_id bigint
);
ALTER TABLE location OWNER TO sormas_user;
--
-- TOC entry 143 (class 1259 OID 341920)
-- Name: person; Type: TABLE; Schema: public; Owner: sormas_user; Tablespace:
--
CREATE TABLE person (
id bigint NOT NULL,
approximateage integer,
approximateagetype integer,
birthdate date,
burialconductor character varying(255),
burialdate date,
changedate timestamp without time zone NOT NULL,
creationdate timestamp without time zone NOT NULL,
dead boolean,
deathdate date,
firstname character varying(255) NOT NULL,
lastname character varying(255) NOT NULL,
occupationdetails character varying(255),
occupationtype character varying(255),
phone character varying(255),
presentcondition integer,
sex character varying(255),
uuid character varying(36) NOT NULL,
address_id bigint,
buriallocation_id bigint,
deathlocation_id bigint,
occupationfacility_id bigint
);
ALTER TABLE person OWNER TO sormas_user;
--
-- TOC entry 146 (class 1259 OID 341950)
-- Name: region; Type: TABLE; Schema: public; Owner: sormas_user; Tablespace:
--
CREATE TABLE region (
id bigint NOT NULL,
changedate timestamp without time zone NOT NULL,
creationdate timestamp without time zone NOT NULL,
name character varying(255),
uuid character varying(36) NOT NULL
);
ALTER TABLE region OWNER TO sormas_user;
--
-- TOC entry 150 (class 1259 OID 341981)
-- Name: userroles; Type: TABLE; Schema: public; Owner: sormas_user; Tablespace:
--
CREATE TABLE userroles (
user_id bigint NOT NULL,
userrole character varying(255) NOT NULL
);
ALTER TABLE userroles OWNER TO sormas_user;
--
-- TOC entry 145 (class 1259 OID 341940)
-- Name: users; Type: TABLE; Schema: public; Owner: sormas_user; Tablespace:
--
CREATE TABLE users (
id bigint NOT NULL,
aktiv boolean NOT NULL,
changedate timestamp without time zone NOT NULL,
creationdate timestamp without time zone NOT NULL,
firstname character varying(255) NOT NULL,
lastname character varying(255) NOT NULL,
password character varying(64) NOT NULL,
phone character varying(255),
seed character varying(16) NOT NULL,
useremail character varying(255),
username character varying(255) NOT NULL,
uuid character varying(36) NOT NULL,
address_id bigint,
associatedofficer_id bigint,
region_id bigint
);
ALTER TABLE users OWNER TO sormas_user;
--
-- TOC entry 1732 (class 2606 OID 341917)
-- Name: cases_pkey; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY cases
ADD CONSTRAINT cases_pkey PRIMARY KEY (id);
--
-- TOC entry 1734 (class 2606 OID 341919)
-- Name: cases_uuid_key; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY cases
ADD CONSTRAINT cases_uuid_key UNIQUE (uuid);
--
-- TOC entry 1756 (class 2606 OID 341968)
-- Name: community_pkey; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY community
ADD CONSTRAINT community_pkey PRIMARY KEY (id);
--
-- TOC entry 1758 (class 2606 OID 341970)
-- Name: community_uuid_key; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY community
ADD CONSTRAINT community_uuid_key UNIQUE (uuid);
--
-- TOC entry 1752 (class 2606 OID 341961)
-- Name: district_pkey; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY district
ADD CONSTRAINT district_pkey PRIMARY KEY (id);
--
-- TOC entry 1754 (class 2606 OID 341963)
-- Name: district_uuid_key; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY district
ADD CONSTRAINT district_uuid_key UNIQUE (uuid);
--
-- TOC entry 1760 (class 2606 OID 341978)
-- Name: facility_pkey; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY facility
ADD CONSTRAINT facility_pkey PRIMARY KEY (id);
--
-- TOC entry 1762 (class 2606 OID 341980)
-- Name: facility_uuid_key; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY facility
ADD CONSTRAINT facility_uuid_key UNIQUE (uuid);
--
-- TOC entry 1740 (class 2606 OID 341937)
-- Name: location_pkey; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY location
ADD CONSTRAINT location_pkey PRIMARY KEY (id);
--
-- TOC entry 1742 (class 2606 OID 341939)
-- Name: location_uuid_key; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY location
ADD CONSTRAINT location_uuid_key UNIQUE (uuid);
--
-- TOC entry 1736 (class 2606 OID 341927)
-- Name: person_pkey; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY person
ADD CONSTRAINT person_pkey PRIMARY KEY (id);
--
-- TOC entry 1738 (class 2606 OID 341929)
-- Name: person_uuid_key; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY person
ADD CONSTRAINT person_uuid_key UNIQUE (uuid);
--
-- TOC entry 1748 (class 2606 OID 341954)
-- Name: region_pkey; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY region
ADD CONSTRAINT region_pkey PRIMARY KEY (id);
--
-- TOC entry 1750 (class 2606 OID 341956)
-- Name: region_uuid_key; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY region
ADD CONSTRAINT region_uuid_key UNIQUE (uuid);
--
-- TOC entry 1764 (class 2606 OID 341985)
-- Name: unq_userroles_0; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY userroles
ADD CONSTRAINT unq_userroles_0 UNIQUE (user_id, userrole);
--
-- TOC entry 1744 (class 2606 OID 341947)
-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
--
-- TOC entry 1746 (class 2606 OID 341949)
-- Name: users_uuid_key; Type: CONSTRAINT; Schema: public; Owner: sormas_user; Tablespace:
--
ALTER TABLE ONLY users
ADD CONSTRAINT users_uuid_key UNIQUE (uuid);
--
-- TOC entry 1765 (class 2606 OID 341986)
-- Name: fk_cases_caseofficer_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_caseofficer_id FOREIGN KEY (caseofficer_id) REFERENCES users(id);
--
-- TOC entry 1769 (class 2606 OID 342006)
-- Name: fk_cases_casesupervisor_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_casesupervisor_id FOREIGN KEY (casesupervisor_id) REFERENCES users(id);
--
-- TOC entry 1770 (class 2606 OID 342011)
-- Name: fk_cases_contactofficer_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_contactofficer_id FOREIGN KEY (contactofficer_id) REFERENCES users(id);
--
-- TOC entry 1768 (class 2606 OID 342001)
-- Name: fk_cases_contactsupervisor_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_contactsupervisor_id FOREIGN KEY (contactsupervisor_id) REFERENCES users(id);
--
-- TOC entry 1772 (class 2606 OID 342021)
-- Name: fk_cases_healthfacility_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_healthfacility_id FOREIGN KEY (healthfacility_id) REFERENCES facility(id);
--
-- TOC entry 1773 (class 2606 OID 342026)
-- Name: fk_cases_illlocation_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_illlocation_id FOREIGN KEY (illlocation_id) REFERENCES location(id);
--
-- TOC entry 1767 (class 2606 OID 341996)
-- Name: fk_cases_person_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_person_id FOREIGN KEY (person_id) REFERENCES person(id);
--
-- TOC entry 1766 (class 2606 OID 341991)
-- Name: fk_cases_reportinguser_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_reportinguser_id FOREIGN KEY (reportinguser_id) REFERENCES users(id);
--
-- TOC entry 1774 (class 2606 OID 342031)
-- Name: fk_cases_surveillanceofficer_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_surveillanceofficer_id FOREIGN KEY (surveillanceofficer_id) REFERENCES users(id);
--
-- TOC entry 1771 (class 2606 OID 342016)
-- Name: fk_cases_surveillancesupervisor_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY cases
ADD CONSTRAINT fk_cases_surveillancesupervisor_id FOREIGN KEY (surveillancesupervisor_id) REFERENCES users(id);
--
-- TOC entry 1786 (class 2606 OID 342091)
-- Name: fk_community_district_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY community
ADD CONSTRAINT fk_community_district_id FOREIGN KEY (district_id) REFERENCES district(id);
--
-- TOC entry 1785 (class 2606 OID 342086)
-- Name: fk_district_region_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY district
ADD CONSTRAINT fk_district_region_id FOREIGN KEY (region_id) REFERENCES region(id);
--
-- TOC entry 1787 (class 2606 OID 342096)
-- Name: fk_facility_location_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY facility
ADD CONSTRAINT fk_facility_location_id FOREIGN KEY (location_id) REFERENCES location(id);
--
-- TOC entry 1779 (class 2606 OID 342056)
-- Name: fk_location_community_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY location
ADD CONSTRAINT fk_location_community_id FOREIGN KEY (community_id) REFERENCES community(id);
--
-- TOC entry 1781 (class 2606 OID 342066)
-- Name: fk_location_district_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY location
ADD CONSTRAINT fk_location_district_id FOREIGN KEY (district_id) REFERENCES district(id);
--
-- TOC entry 1780 (class 2606 OID 342061)
-- Name: fk_location_region_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY location
ADD CONSTRAINT fk_location_region_id FOREIGN KEY (region_id) REFERENCES region(id);
--
-- TOC entry 1778 (class 2606 OID 342051)
-- Name: fk_person_address_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY person
ADD CONSTRAINT fk_person_address_id FOREIGN KEY (address_id) REFERENCES location(id);
--
-- TOC entry 1776 (class 2606 OID 342041)
-- Name: fk_person_buriallocation_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY person
ADD CONSTRAINT fk_person_buriallocation_id FOREIGN KEY (buriallocation_id) REFERENCES location(id);
--
-- TOC entry 1775 (class 2606 OID 342036)
-- Name: fk_person_deathlocation_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY person
ADD CONSTRAINT fk_person_deathlocation_id FOREIGN KEY (deathlocation_id) REFERENCES location(id);
--
-- TOC entry 1777 (class 2606 OID 342046)
-- Name: fk_person_occupationfacility_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY person
ADD CONSTRAINT fk_person_occupationfacility_id FOREIGN KEY (occupationfacility_id) REFERENCES facility(id);
--
-- TOC entry 1788 (class 2606 OID 342101)
-- Name: fk_userroles_user_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY userroles
ADD CONSTRAINT fk_userroles_user_id FOREIGN KEY (user_id) REFERENCES users(id);
--
-- TOC entry 1783 (class 2606 OID 342076)
-- Name: fk_users_address_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY users
ADD CONSTRAINT fk_users_address_id FOREIGN KEY (address_id) REFERENCES location(id);
--
-- TOC entry 1784 (class 2606 OID 342081)
-- Name: fk_users_associatedofficer_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY users
ADD CONSTRAINT fk_users_associatedofficer_id FOREIGN KEY (associatedofficer_id) REFERENCES users(id);
--
-- TOC entry 1782 (class 2606 OID 342071)
-- Name: fk_users_region_id; Type: FK CONSTRAINT; Schema: public; Owner: sormas_user
--
ALTER TABLE ONLY users
ADD CONSTRAINT fk_users_region_id FOREIGN KEY (region_id) REFERENCES region(id);
--
-- TOC entry 1881 (class 0 OID 0)
-- Dependencies: 5
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--
ALTER TABLE person ADD COLUMN phoneowner character varying(255);
INSERT INTO schema_version (version_number, comment) VALUES (1, 'Init database');
-- 2016-09-27; #55; sszczesny
ALTER TABLE person DROP COLUMN birthdate;
ALTER TABLE person ADD COLUMN birthdate_dd integer;
ALTER TABLE person ADD COLUMN birthdate_mm integer;
ALTER TABLE person ADD COLUMN birthdate_yyyy integer;
INSERT INTO schema_version (version_number, comment) VALUES (2, 'Split person birthdate year, month, day');
-- 2016-10-04; #58
CREATE TABLE symptoms (
id bigint not null,
abdominalpain varchar(255),
anorexiaappetiteloss varchar(255),
bleedingvagina varchar(255),
changedate timestamp not null,
chestpain varchar(255),
comaunconscious varchar(255),
confuseddisoriented varchar(255),
conjunctivitis varchar(255),
cough varchar(255),
creationdate timestamp not null,
diarrhea varchar(255),
difficultybreathing varchar(255),
difficultyswallowing varchar(255),
digestedbloodvomit varchar(255),
epistaxis varchar(255),
eyepainlightsensitive varchar(255),
fever varchar(255),
gumsbleeding varchar(255),
headache varchar(255),
hematemesis varchar(255),
hematuria varchar(255),
hemoptysis varchar(255),
hiccups varchar(255),
injectionsitebleeding varchar(255),
intensefatigueweakness varchar(255),
jaundice varchar(255),
jointpain varchar(255),
melena varchar(255),
musclepain varchar(255),
otherhemorrhagic varchar(255),
otherhemorrhagictext varchar(255),
othernonhemorrhagic varchar(255),
othernonhemorrhagicsymptoms varchar(255),
petechiae varchar(255),
skinrash varchar(255),
sorethroat varchar(255),
onsetdate timestamp without time zone,
temperature real,
temperaturesource varchar(255),
unexplainedbleeding varchar(255),
uuid varchar(36) not null unique,
vomitingnausea varchar(255),
PRIMARY KEY (id));
ALTER TABLE symptoms OWNER TO sormas_user;
ALTER TABLE cases ADD COLUMN symptoms_id bigint;
ALTER TABLE cases ADD CONSTRAINT fk_cases_symptoms_id FOREIGN KEY (symptoms_id) REFERENCES symptoms (id) ON UPDATE NO ACTION ON DELETE NO ACTION;
INSERT INTO schema_version (version_number, comment) VALUES (3, 'Symptoms');
-- 2016-10-14; #63
CREATE TABLE task (
id bigint not null,
assigneereply varchar(512),
changedate timestamp not null,
creationdate timestamp not null,
creatorcomment varchar(512),
duedate timestamp,
perceivedstart timestamp,
statuschangedate timestamp,
taskcontext varchar(255),
taskstatus varchar(255),
tasktype varchar(255),
uuid varchar(36) not null unique,
assigneeuser_id bigint,
caze_id bigint,
creatoruser_id bigint,
PRIMARY KEY (id));
ALTER TABLE task OWNER TO sormas_user;
ALTER TABLE task ADD CONSTRAINT fk_task_caze_id FOREIGN KEY (caze_id) REFERENCES cases (id);
ALTER TABLE task ADD CONSTRAINT fk_task_creatoruser_id FOREIGN KEY (creatoruser_id) REFERENCES users (id);
ALTER TABLE task ADD CONSTRAINT fk_task_assigneeuser_id FOREIGN KEY (assigneeuser_id) REFERENCES users (id);
INSERT INTO schema_version (version_number, comment) VALUES (4, 'Task');
-- 2016-10-18; #63 additions
ALTER TABLE task ADD COLUMN priority varchar(255);
ALTER TABLE task ADD COLUMN suggestedstart timestamp;
DELETE FROM task;
INSERT INTO schema_version (version_number, comment) VALUES (5, 'Task priority & suggested start');
-- 2016-10-25; #78 disease config
UPDATE cases SET disease='EVD' WHERE disease='EBOLA';
ALTER TABLE symptoms DROP COLUMN difficultyswallowing;
ALTER TABLE symptoms DROP COLUMN intensefatigueweakness;
ALTER TABLE symptoms RENAME othernonhemorrhagicsymptoms TO othernonhemorrhagicsymptomstext;
ALTER TABLE symptoms RENAME othernonhemorrhagic TO othernonhemorrhagicsymptoms;
ALTER TABLE symptoms RENAME otherhemorrhagictext TO otherhemorrhagicsymptomstext;
ALTER TABLE symptoms RENAME otherhemorrhagic TO otherhemorrhagicsymptoms;
ALTER TABLE symptoms RENAME vomitingnausea TO vomiting;
ALTER TABLE symptoms ADD COLUMN chills character varying(255);
ALTER TABLE symptoms ADD COLUMN dehydration character varying(255);
ALTER TABLE symptoms ADD COLUMN fatigueweakness character varying(255);
ALTER TABLE symptoms ADD COLUMN highbloodpressure character varying(255);
ALTER TABLE symptoms ADD COLUMN kopliksspots character varying(255);
ALTER TABLE symptoms ADD COLUMN lethargy character varying(255);
ALTER TABLE symptoms ADD COLUMN lowbloodpressure character varying(255);
ALTER TABLE symptoms ADD COLUMN nausea character varying(255);
ALTER TABLE symptoms ADD COLUMN neckstiffness character varying(255);
ALTER TABLE symptoms ADD COLUMN oedema character varying(255);
ALTER TABLE symptoms ADD COLUMN onsetsymptom character varying(255);
ALTER TABLE symptoms ADD COLUMN otitismedia character varying(255);
ALTER TABLE symptoms ADD COLUMN refusalfeedordrink character varying(255);
ALTER TABLE symptoms ADD COLUMN runnynose character varying(255);
ALTER TABLE symptoms ADD COLUMN seizures character varying(255);
ALTER TABLE symptoms ADD COLUMN sepsis character varying(255);
ALTER TABLE symptoms ADD COLUMN swollenlymphnodes character varying(255);
ALTER TABLE symptoms ADD COLUMN symptomatic boolean;
INSERT INTO schema_version (version_number, comment) VALUES (6, 'EBOLA -> EVD; Symptoms');
-- 2016-11-08; case + user: replaced supervisor references with regional references #90
ALTER TABLE public.cases DROP COLUMN casesupervisor_id;
ALTER TABLE public.cases DROP COLUMN contactsupervisor_id;
ALTER TABLE public.cases DROP COLUMN surveillancesupervisor_id;
ALTER TABLE public.cases ADD COLUMN region_id bigint;
ALTER TABLE public.cases ADD COLUMN district_id bigint;
ALTER TABLE public.cases ADD COLUMN community_id bigint;
ALTER TABLE public.cases ADD CONSTRAINT fk_cases_region_id FOREIGN KEY (region_id) REFERENCES public.region (id) ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE public.cases ADD CONSTRAINT fk_cases_district_id FOREIGN KEY (district_id) REFERENCES public.district (id) ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE public.cases ADD CONSTRAINT fk_cases_community_id FOREIGN KEY (community_id) REFERENCES public.community (id) ON UPDATE NO ACTION ON DELETE NO ACTION;
UPDATE public.cases SET region_id=(SELECT id FROM public.region LIMIT 1);
ALTER TABLE public.users ADD COLUMN district_id bigint;
ALTER TABLE public.users ADD CONSTRAINT fk_users_district_id FOREIGN KEY (district_id) REFERENCES public.district (id) ON UPDATE NO ACTION ON DELETE NO ACTION;
UPDATE public.users SET region_id=(SELECT id FROM public.region LIMIT 1);
INSERT INTO schema_version (version_number, comment) VALUES (7, 'Case + User: replaced supervisor references with regional references');
-- 2016-11-10; Contact #85
CREATE TABLE contact (
id bigint not null,
changedate timestamp not null,
contactproximity varchar(255),
contactstatus varchar(255),
creationdate timestamp not null,
lastcontactdate timestamp,
reportdatetime timestamp not null,
uuid varchar(36) not null unique,
caze_id bigint not null,
person_id bigint not null,
reportinguser_id bigint not null,
primary key (id));
ALTER TABLE contact ADD CONSTRAINT fk_contact_person_id FOREIGN KEY (person_id) REFERENCES person (id);
ALTER TABLE contact ADD CONSTRAINT fk_contact_caze_id FOREIGN KEY (caze_id) REFERENCES cases (id);
ALTER TABLE contact ADD CONSTRAINT fk_contact_reportinguser_id FOREIGN KEY (reportinguser_id) REFERENCES users (id);
ALTER TABLE public.cases ALTER COLUMN reportdate SET NOT NULL;
ALTER TABLE public.cases ALTER COLUMN reportinguser_id SET NOT NULL;
INSERT INTO schema_version (version_number, comment) VALUES (8, 'Contact; Cases report not null');
-- 2016-11-15; Contact #85
ALTER TABLE contact ADD COLUMN description varchar(512);
INSERT INTO schema_version (version_number, comment) VALUES (9, 'Contact.description');
-- 2016-11-16; Contact #85
ALTER TABLE contact ADD COLUMN contactofficer_id bigint;
ALTER TABLE contact ADD CONSTRAINT fk_contact_contactofficer_id FOREIGN KEY (contactofficer_id) REFERENCES users (id);
ALTER TABLE contact OWNER TO sormas_user;
INSERT INTO schema_version (version_number, comment) VALUES (10, 'Contact.contactOfficer + OWNER');
-- 2016-11-29; Contact Visits backend #10
ALTER TABLE contact DROP COLUMN contactstatus;
ALTER TABLE contact ADD COLUMN contactclassification varchar(255);
ALTER TABLE contact ADD COLUMN followupstatus varchar(255);
ALTER TABLE contact ADD COLUMN followupuntil timestamp;
CREATE TABLE visit (
id bigint not null,
uuid varchar(36) not null unique,
changedate timestamp not null,
creationdate timestamp not null,
person_id bigint not null,
visituser_id bigint not null,
visitremarks character varying(512),
disease character varying(255),
visitdatetime timestamp not null,
visitstatus character varying(255),
symptoms_id bigint,
primary key (id));
ALTER TABLE visit OWNER TO sormas_user;
ALTER TABLE visit ADD CONSTRAINT fk_visit_symptoms_id FOREIGN KEY (symptoms_id) REFERENCES symptoms (id) ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE visit ADD CONSTRAINT fk_visit_person_id FOREIGN KEY (person_id) REFERENCES person (id);
ALTER TABLE visit ADD CONSTRAINT fk_visit_visituser_id FOREIGN KEY (visituser_id) REFERENCES users (id);
INSERT INTO schema_version (version_number, comment) VALUES (11, 'visit, contact classification, follow-up status, follow-up until');
-- 2016-12-15; Assign tasks to a contact #53
ALTER TABLE task ADD COLUMN contact_id bigint;
ALTER TABLE task ADD CONSTRAINT fk_task_contact_id FOREIGN KEY (contact_id) REFERENCES contact (id);
INSERT INTO schema_version (version_number, comment) VALUES (12, 'Contact added to task');
-- 2016-12-14 Split CaseStatus to CaseClassification and InvestigationStatus #40
ALTER TABLE cases ADD COLUMN caseclassification character varying(255) DEFAULT 'POSSIBLE' NOT NULL;
ALTER TABLE cases ADD COLUMN investigationstatus character varying(255) DEFAULT 'PENDING' NOT NULL;
ALTER TABLE cases DROP COLUMN casestatus;
INSERT INTO schema_version (version_number, comment) VALUES (13, 'Split CaseStatus to CaseClassification and InvestigationStatus');
-- 2016-12-16 Update symptoms #41
ALTER TABLE symptoms DROP COLUMN comaunconscious;
ALTER TABLE symptoms DROP COLUMN epistaxis;
ALTER TABLE symptoms DROP COLUMN hematemesis;
ALTER TABLE symptoms DROP COLUMN hematuria;
ALTER TABLE symptoms DROP COLUMN jaundice;
ALTER TABLE symptoms DROP COLUMN melena;
ALTER TABLE symptoms DROP COLUMN petechiae;
ALTER TABLE symptoms DROP COLUMN chills;
ALTER TABLE symptoms DROP COLUMN highbloodpressure;
ALTER TABLE symptoms DROP COLUMN lethargy;
ALTER TABLE symptoms DROP COLUMN lowbloodpressure;
ALTER TABLE symptoms DROP COLUMN oedema;
ALTER TABLE symptoms DROP COLUMN sepsis;
ALTER TABLE symptoms DROP COLUMN swollenlymphnodes;
ALTER TABLE symptoms ADD COLUMN bloodinstool character varying(255);
ALTER TABLE symptoms ADD COLUMN nosebleeding character varying(255);
ALTER TABLE symptoms ADD COLUMN bloodyblackstool character varying(255);
ALTER TABLE symptoms ADD COLUMN redbloodvomit character varying(255);
ALTER TABLE symptoms ADD COLUMN coughingblood character varying(255);
ALTER TABLE symptoms ADD COLUMN skinbruising character varying(255);
ALTER TABLE symptoms ADD COLUMN bloodurine character varying(255);
ALTER TABLE symptoms ADD COLUMN alteredconsciousness character varying(255);
ALTER TABLE symptoms ADD COLUMN throbocytopenia character varying(255);
ALTER TABLE symptoms ADD COLUMN hearingloss character varying(255);
ALTER TABLE symptoms ADD COLUMN shock character varying(255);
ALTER TABLE symptoms ADD COLUMN symptomscomments character varying(255);
INSERT INTO schema_version (version_number, comment) VALUES (14, 'Update symptoms');
-- 2017-01-05 Event backend #63
CREATE TABLE events (
id bigint not null,
uuid varchar(36) not null unique,
changedate timestamp not null,
creationdate timestamp not null,
eventtype varchar(255) not null,
eventstatus varchar(255) not null,
eventdesc varchar(512) not null,
eventdate timestamp,
reportdatetime timestamp not null,
reportinguser_id bigint not null,
location_id bigint,
typeofplace varchar(255) not null,
srcfirstname varchar(512) not null,
srclastname varchar(512) not null,
srctelno varchar(512) not null,
srcemail varchar(512),
primary key(id));
ALTER TABLE events OWNER TO sormas_user;
ALTER TABLE events ADD CONSTRAINT fk_events_reportinguser_id FOREIGN KEY (reportinguser_id) REFERENCES users (id);
ALTER TABLE events ADD CONSTRAINT fk_events_location_id FOREIGN KEY (location_id) REFERENCES location (id);
CREATE TABLE eventparticipant (
id bigint not null,
uuid varchar(36) not null unique,
changedate timestamp not null,
creationdate timestamp not null,
event_id bigint,
person_id bigint,
kindofinvolvement varchar(255),
primary key(id));
ALTER TABLE eventparticipant OWNER TO sormas_user;
ALTER TABLE eventparticipant ADD CONSTRAINT fk_eventparticipant_event_id FOREIGN KEY (event_id) REFERENCES events (id);
ALTER TABLE eventparticipant ADD CONSTRAINT fk_eventparticipant_person_id FOREIGN KEY (person_id) REFERENCES person (id);
INSERT INTO schema_version (version_number, comment) VALUES (15, 'events, eventparticipant');
-- 2017-01-06 Renaming #63
ALTER TABLE events RENAME location_id TO eventlocation_id;
INSERT INTO schema_version (version_number, comment) VALUES (16, 'renamed eventlocation');
-- 2017-01-10 Update events #63
ALTER TABLE events ADD COLUMN disease character varying(255);
ALTER TABLE events ADD COLUMN surveillanceofficer_id bigint;
INSERT INTO schema_version (version_number, comment) VALUES (17, 'update events');
-- 2017-01-11 Update events with type of place text #63
ALTER TABLE events ADD COLUMN typeofplacetext character varying(255);
INSERT INTO schema_version (version_number, comment) VALUES (18, 'update events with type of place text');
-- 2017-01-12 Assign tasks to an event #65
ALTER TABLE task ADD COLUMN event_id bigint;
ALTER TABLE task ADD CONSTRAINT fk_task_event_id FOREIGN KEY (event_id) REFERENCES events (id);
INSERT INTO schema_version (version_number, comment) VALUES (19, 'Event added to task');
-- 2017-01-17 Change kind of involvement to involvement description #66
ALTER TABLE eventparticipant DROP COLUMN kindofinvolvement;
ALTER TABLE eventparticipant ADD COLUMN involvementdescription varchar(255);
INSERT INTO schema_version (version_number, comment) VALUES (20, 'Involvement description instead of Kind of involvement');
-- 2017-01-20 Add relation to case to contact #75
ALTER TABLE contact ADD COLUMN relationtocase varchar(255);
INSERT INTO schema_version (version_number, comment) VALUES (21, 'Add relation to case to contact');
-- 2017-01-23 Add nickname and mother's maiden name to person #19
ALTER TABLE person ADD COLUMN nickname varchar(255);
ALTER TABLE person ADD COLUMN mothersmaidenname varchar(255);
INSERT INTO schema_version (version_number, comment) VALUES (22, 'Add nickname and mothers maiden name to person');
-- 2017-01-26 add health facility to user (informant) #49
ALTER TABLE users ADD COLUMN healthfacility_id bigint;
ALTER TABLE users ADD CONSTRAINT fk_users_healthfacility_id FOREIGN KEY (healthfacility_id) REFERENCES facility(id);
INSERT INTO schema_version (version_number, comment) VALUES (23, 'Add health facility to users (informant)');
-- 2017-01-30 Sample and SampleTest backend #106
CREATE TABLE samples(
id bigint not null,
uuid varchar(36) not null unique,
changedate timestamp not null,
creationdate timestamp not null,
associatedcase_id bigint not null,
samplecode varchar(512),
sampledatetime timestamp not null,
reportdatetime timestamp not null,
reportinguser_id bigint not null,
samplematerial varchar(255) not null,