-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy path0000-00-00-schema.sql
2240 lines (2000 loc) · 102 KB
/
0000-00-00-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
-- ********************************
-- Core tables
-- ********************************
CREATE TABLE `Project` (
`ProjectID` INT(10) unsigned NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NULL,
`Alias` char(4) NOT NULL,
`recruitmentTarget` INT(6) Default NULL,
PRIMARY KEY (`ProjectID`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Project` (Name,Alias) VALUES ('loris','LORI');
CREATE TABLE `subproject` (
`SubprojectID` int(10) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
`useEDC` boolean,
`WindowDifference` enum('optimal', 'battery'),
`RecruitmentTarget` int(10) unsigned,
PRIMARY KEY (SubprojectID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores Subprojects used in Loris';
INSERT INTO subproject (title, useEDC, WindowDifference) VALUES
('Control', false, 'optimal'),
('Experimental', false, 'optimal');
CREATE TABLE `project_subproject_rel` (
`ProjectSubprojectRelID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ProjectID` int(10) unsigned NOT NULL,
`SubprojectID` int(10) unsigned NOT NULL,
PRIMARY KEY (`ProjectSubprojectRelID`),
CONSTRAINT `UK_project_subproject_rel_ProjectID_SubprojectID` UNIQUE KEY (ProjectID, SubprojectID),
CONSTRAINT `FK_project_subproject_rel_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `Project` (`ProjectID`) ON DELETE CASCADE,
CONSTRAINT `FK_project_subproject_rel_SubprojectID` FOREIGN KEY (`SubprojectID`) REFERENCES `subproject` (`SubprojectID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `psc` (
`CenterID` integer unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(150) NOT NULL DEFAULT '',
`PSCArea` varchar(150) DEFAULT NULL,
`Address` varchar(150) DEFAULT NULL,
`City` varchar(150) DEFAULT NULL,
`StateID` tinyint(2) unsigned DEFAULT NULL,
`ZIP` varchar(12) DEFAULT NULL,
`Phone1` varchar(12) DEFAULT NULL,
`Phone2` varchar(12) DEFAULT NULL,
`Contact1` varchar(150) DEFAULT NULL,
`Contact2` varchar(150) DEFAULT NULL,
`Alias` char(3) NOT NULL DEFAULT '',
`MRI_alias` varchar(4) NOT NULL DEFAULT '',
`Account` varchar(8) DEFAULT NULL,
`Study_site` enum('N','Y') DEFAULT 'Y',
PRIMARY KEY (`CenterID`),
UNIQUE KEY `Name` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `psc` (Name, Alias, Study_site) VALUES ('Data Coordinating Center','DCC', 'Y');
CREATE TABLE `language` (
`language_id` integer unsigned NOT NULL AUTO_INCREMENT,
`language_code` varchar(255) NOT NULL,
`language_label` varchar(255) NOT NULL,
PRIMARY KEY (`language_id`),
UNIQUE KEY (`language_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO language (language_code, language_label) VALUES
('en-CA', 'English');
CREATE TABLE `users` (
`ID` int(10) unsigned NOT NULL auto_increment,
`UserID` varchar(255) NOT NULL default '',
`Password` varchar(255) default NULL,
`Real_name` varchar(255) default NULL,
`First_name` varchar(255) default NULL,
`Last_name` varchar(255) default NULL,
`Degree` varchar(255) default NULL,
`Position_title` varchar(255) default NULL,
`Institution` varchar(255) default NULL,
`Department` varchar(255) default NULL,
`Address` varchar(255) default NULL,
`City` varchar(255) default NULL,
`State` varchar(255) default NULL,
`Zip_code` varchar(255) default NULL,
`Country` varchar(255) default NULL,
`Phone` varchar(15) default NULL,
`Fax` varchar(255) default NULL,
`Email` varchar(255) NOT NULL default '',
`Privilege` tinyint(1) NOT NULL default '0',
`PSCPI` enum('Y','N') NOT NULL default 'N',
`DBAccess` varchar(10) NOT NULL default '',
`Active` enum('Y','N') NOT NULL default 'Y',
`Password_hash` varchar(255) default NULL,
`PasswordChangeRequired` tinyint(1) NOT NULL default 0,
`Pending_approval` enum('Y','N') default 'Y',
`Doc_Repo_Notifications` enum('Y','N') default 'N',
`language_preference` integer unsigned default NULL,
`active_from` date default NULL,
`active_to` date default NULL,
`account_request_date` date default NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `Email` (`Email`),
UNIQUE KEY `UserID` (`UserID`),
CONSTRAINT `FK_users_2` FOREIGN KEY (`language_preference`) REFERENCES `language` (`language_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `users` (ID,UserID,Real_name,First_name,Last_name,Email,Privilege,PSCPI,DBAccess,Active,Pending_approval,PasswordChangeRequired)
VALUES (1,'admin','Admin account','Admin','account','admin@example.com',0,'N','','Y','N',0);
CREATE TABLE `user_psc_rel` (
`UserID` int(10) unsigned NOT NULL,
`CenterID` integer unsigned NOT NULL,
PRIMARY KEY (`UserID`,`CenterID`),
KEY `FK_user_psc_rel_2` (`CenterID`),
CONSTRAINT `FK_user_psc_rel_2` FOREIGN KEY (`CenterID`) REFERENCES `psc` (`CenterID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_user_psc_rel_1` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO user_psc_rel (UserID, CenterID) SELECT 1, CenterID FROM psc;
CREATE TABLE `user_project_rel` (
`UserID` int(10) unsigned NOT NULL,
`ProjectID` int(10) unsigned NOT NULL,
PRIMARY KEY (`UserID`,`ProjectID`),
CONSTRAINT `FK_user_project_rel_UserID` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_user_project_rel_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `Project` (`ProjectID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO user_project_rel (UserID, ProjectID) SELECT 1, ProjectID FROM Project;
CREATE TABLE `caveat_options` (
`ID` int(6),
`Description` varchar(255),
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `candidate` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`CandID` int(6) NOT NULL DEFAULT '0',
`PSCID` varchar(255) NOT NULL DEFAULT '',
`ExternalID` varchar(255) DEFAULT NULL,
`DoB` date DEFAULT NULL,
`DoD` date DEFAULT NULL,
`EDC` date DEFAULT NULL,
`Sex` enum('Male','Female','Other') DEFAULT NULL,
`RegistrationCenterID` integer unsigned NOT NULL DEFAULT '0',
`RegistrationProjectID` int(10) unsigned DEFAULT NULL,
`Ethnicity` varchar(255) DEFAULT NULL,
`Active` enum('Y','N') NOT NULL DEFAULT 'Y',
`Date_active` date DEFAULT NULL,
`RegisteredBy` varchar(255) DEFAULT NULL,
`UserID` varchar(255) NOT NULL DEFAULT '',
`Date_registered` date DEFAULT NULL,
`flagged_caveatemptor` enum('true','false') DEFAULT 'false',
`flagged_reason` int(6) DEFAULT NULL,
`flagged_other` varchar(255) DEFAULT NULL,
`flagged_other_status` enum('not_answered') DEFAULT NULL,
`Testdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`Entity_type` enum('Human','Scanner') NOT NULL DEFAULT 'Human',
`ProbandSex` enum('Male','Female','Other') DEFAULT NULL,
`ProbandDoB` date DEFAULT NULL,
PRIMARY KEY (`CandID`),
UNIQUE KEY `ID` (`ID`),
UNIQUE KEY `ExternalID` (`ExternalID`),
KEY `FK_candidate_1` (`RegistrationCenterID`),
KEY `CandidateActive` (`Active`),
KEY `FK_candidate_2_idx` (`flagged_reason`),
KEY `PSCID` (`PSCID`),
CONSTRAINT `FK_candidate_1` FOREIGN KEY (`RegistrationCenterID`) REFERENCES `psc` (`CenterID`),
CONSTRAINT `FK_candidate_2` FOREIGN KEY (`flagged_reason`) REFERENCES `caveat_options` (`ID`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `FK_candidate_RegistrationProjectID` FOREIGN KEY (`RegistrationProjectID`) REFERENCES `Project` (`ProjectID`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `session` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`CandID` int(6) NOT NULL DEFAULT '0',
`CenterID` integer unsigned NOT NULL,
`ProjectID` int(10) unsigned DEFAULT NULL,
`VisitNo` smallint(5) unsigned DEFAULT NULL,
`Visit_label` varchar(255) NOT NULL,
`SubprojectID` int(10) unsigned DEFAULT NULL,
`Submitted` enum('Y','N') NOT NULL DEFAULT 'N',
`Current_stage` enum('Not Started','Screening','Visit','Approval','Subject','Recycling Bin') NOT NULL DEFAULT 'Not Started',
`Date_stage_change` date DEFAULT NULL,
`Screening` enum('Pass','Failure','Withdrawal','In Progress') DEFAULT NULL,
`Date_screening` date DEFAULT NULL,
`Visit` enum('Pass','Failure','Withdrawal','In Progress') DEFAULT NULL,
`Date_visit` date DEFAULT NULL,
`Approval` enum('In Progress','Pass','Failure') DEFAULT NULL,
`Date_approval` date DEFAULT NULL,
`Active` enum('Y','N') NOT NULL DEFAULT 'Y',
`Date_active` date DEFAULT NULL,
`RegisteredBy` varchar(255) DEFAULT NULL,
`UserID` varchar(255) NOT NULL DEFAULT '',
`Date_registered` date DEFAULT NULL,
`Testdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`Hardcopy_request` enum('-','N','Y') NOT NULL DEFAULT '-',
`BVLQCStatus` enum('Complete') DEFAULT NULL,
`BVLQCType` enum('Visual','Hardcopy') DEFAULT NULL,
`BVLQCExclusion` enum('Excluded','Not Excluded') DEFAULT NULL,
`QCd` enum('Visual','Hardcopy') DEFAULT NULL,
`Scan_done` enum('N','Y') DEFAULT NULL,
`MRIQCStatus` enum('','Pass','Fail') NOT NULL DEFAULT '',
`MRIQCPending` enum('Y','N') NOT NULL DEFAULT 'N',
`MRIQCFirstChangeTime` datetime DEFAULT NULL,
`MRIQCLastChangeTime` datetime DEFAULT NULL,
`MRICaveat` enum('true','false') NOT NULL DEFAULT 'false',
`languageID` integer unsigned DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `session_candVisit` (`CandID`,`VisitNo`),
KEY `FK_session_2` (`CenterID`),
KEY `SessionSubproject` (`SubprojectID`),
KEY `SessionActive` (`Active`),
CONSTRAINT `FK_session_1` FOREIGN KEY (`CandID`) REFERENCES `candidate` (`CandID`),
CONSTRAINT `FK_session_2` FOREIGN KEY (`CenterID`) REFERENCES `psc` (`CenterID`),
CONSTRAINT `FK_session_3` FOREIGN KEY (`SubprojectID`) REFERENCES `subproject` (`SubprojectID`),
CONSTRAINT `FK_session_4` FOREIGN KEY (`languageID`) REFERENCES `language` (`language_id`),
CONSTRAINT `FK_session_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `Project` (`ProjectID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Table holding session information';
CREATE TABLE `session_status` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`SessionID` int(10) unsigned NOT NULL,
`Name` varchar(64) NOT NULL,
`Value` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `session_status_index` (`SessionID`,`Name`),
CONSTRAINT `fk_session_status_1` FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used if SupplementalSessionStatus configSettings is true';
CREATE TABLE `test_subgroups` (
`ID` int(11) unsigned NOT NULL auto_increment,
`Subgroup_name` varchar(255) default NULL,
`group_order` tinyint(4) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO test_subgroups (Subgroup_name) VALUES ('Instruments'),('Imaging');
CREATE TABLE `test_names` (
`ID` int(10) unsigned NOT NULL auto_increment,
`Test_name` varchar(255) default NULL,
`Full_name` varchar(255) default NULL,
`Sub_group` int(11) unsigned default NULL,
`IsDirectEntry` boolean default NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `Test_name` (`Test_name`),
KEY `FK_test_names_1` (`Sub_group`),
CONSTRAINT `FK_test_names_1` FOREIGN KEY (`Sub_group`) REFERENCES `test_subgroups` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `instrument_subtests` (
`ID` int(11) NOT NULL auto_increment,
`Test_name` varchar(255) NOT NULL default '',
`Subtest_name` varchar(255) NOT NULL default '',
`Description` varchar(255) NOT NULL default '',
`Order_number` int(11) NOT NULL default '0',
UNIQUE KEY `unique_index` (`Test_name`, `Subtest_name`),
PRIMARY KEY (`ID`),
KEY `FK_instrument_subtests_1` (`Test_name`),
CONSTRAINT `FK_instrument_subtests_1` FOREIGN KEY (`Test_name`) REFERENCES `test_names` (`Test_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `flag` (
`ID` int(10) unsigned NOT NULL auto_increment,
`SessionID` int(10) unsigned NOT NULL default '0',
`Test_name` varchar(255) NOT NULL default '',
`CommentID` varchar(255) NOT NULL default '',
`Data_entry` enum('In Progress','Complete') default NULL,
`Administration` enum('None','Partial','All') default NULL,
`Validity` enum('Questionable','Invalid','Valid') default NULL,
`Exclusion` enum('Fail','Pass') default NULL,
`Flag_status` enum('P','Y','N','F') default NULL,
`UserID` varchar(255) default NULL,
`Testdate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`Data` TEXT default NULL,
PRIMARY KEY (`CommentID`),
KEY `Status` (`Flag_status`),
KEY `flag_ID` (`ID`),
KEY `flag_SessionID` (`SessionID`),
KEY `flag_Test_name` (`Test_name`),
KEY `flag_Exclusion` (`Exclusion`),
KEY `flag_Data_entry` (`Data_entry`),
KEY `flag_Validity` (`Validity`),
KEY `flag_Administration` (`Administration`),
KEY `flag_UserID` (`UserID`),
CONSTRAINT `FK_flag_1` FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_flag_2` FOREIGN KEY (`Test_name`) REFERENCES `test_names` (`Test_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `history` (
`id` int(11) NOT NULL auto_increment,
`tbl` varchar(255) NOT NULL default '',
`col` varchar(255) NOT NULL default '',
`old` text,
`new` text,
`primaryCols` text,
`primaryVals` text,
`changeDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`userID` varchar(255) NOT NULL default '',
`type` char(1),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='This table keeps track of ongoing changes in the database. ';
CREATE TABLE `test_battery` (
`ID` int(10) unsigned NOT NULL auto_increment,
`Test_name` varchar(255) NOT NULL default '',
`AgeMinDays` int(10) unsigned default NULL,
`AgeMaxDays` int(10) unsigned default NULL,
`Active` enum('Y','N') NOT NULL default 'Y',
`Stage` varchar(255) default NULL,
`SubprojectID` int(11) default NULL,
`Visit_label` varchar(255) default NULL,
`CenterID` int(11) default NULL,
`firstVisit` enum('Y','N') default NULL,
`instr_order` tinyint(4) default NULL,
PRIMARY KEY (`ID`),
KEY `age_test` (`AgeMinDays`,`AgeMaxDays`,`Test_name`),
KEY `FK_test_battery_1` (`Test_name`),
CONSTRAINT `FK_test_battery_1` FOREIGN KEY (`Test_name`) REFERENCES `test_names` (`Test_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `Visit_Windows` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Visit_label` varchar(255) DEFAULT NULL,
`WindowMinDays` int(11) DEFAULT NULL,
`WindowMaxDays` int(11) DEFAULT NULL,
`OptimumMinDays` int(11) DEFAULT NULL,
`OptimumMaxDays` int(11) DEFAULT NULL,
`WindowMidpointDays` int(11) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ********************************
-- tarchive tables
-- ********************************
CREATE TABLE `tarchive` (
`DicomArchiveID` varchar(255) NOT NULL default '',
`PatientID` varchar(255) NOT NULL default '',
`PatientName` varchar(255) NOT NULL default '',
`PatientDoB` date default NULL,
`PatientSex` varchar(255) default NULL,
`neurodbCenterName` varchar(255) default NULL,
`CenterName` varchar(255) NOT NULL default '',
`LastUpdate` datetime default NULL,
`DateAcquired` date default NULL,
`DateFirstArchived` datetime default NULL,
`DateLastArchived` datetime default NULL,
`AcquisitionCount` int(11) NOT NULL default '0',
`NonDicomFileCount` int(11) NOT NULL default '0',
`DicomFileCount` int(11) NOT NULL default '0',
`md5sumDicomOnly` varchar(255) default NULL,
`md5sumArchive` varchar(255) default NULL,
`CreatingUser` varchar(255) NOT NULL default '',
`sumTypeVersion` tinyint(4) NOT NULL default '0',
`tarTypeVersion` tinyint(4) default NULL,
`SourceLocation` varchar(255) NOT NULL default '',
`ArchiveLocation` varchar(255) default NULL,
`ScannerManufacturer` varchar(255) NOT NULL default '',
`ScannerModel` varchar(255) NOT NULL default '',
`ScannerSerialNumber` varchar(255) NOT NULL default '',
`ScannerSoftwareVersion` varchar(255) NOT NULL default '',
`SessionID` int(10) unsigned default NULL,
`uploadAttempt` tinyint(4) NOT NULL default '0',
`CreateInfo` text,
`AcquisitionMetadata` longtext NOT NULL,
`TarchiveID` int(11) NOT NULL auto_increment,
`DateSent` datetime DEFAULT NULL,
`PendingTransfer` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`TarchiveID`),
KEY `SessionID` (`SessionID`),
CONSTRAINT `FK_tarchive_sessionID`
FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tarchive_series` (
`TarchiveSeriesID` int(11) NOT NULL auto_increment,
`TarchiveID` int(11) NOT NULL default '0',
`SeriesNumber` int(11) NOT NULL default '0',
`SeriesDescription` varchar(255) default NULL,
`SequenceName` varchar(255) default NULL,
`EchoTime` double default NULL,
`RepetitionTime` double default NULL,
`InversionTime` double default NULL,
`SliceThickness` double default NULL,
`PhaseEncoding` varchar(255) default NULL,
`NumberOfFiles` int(11) NOT NULL default '0',
`SeriesUID` varchar(255) default NULL,
`Modality` ENUM ('MR', 'PT') default NULL,
PRIMARY KEY (`TarchiveSeriesID`),
KEY `TarchiveID` (`TarchiveID`),
CONSTRAINT `tarchive_series_ibfk_1` FOREIGN KEY (`TarchiveID`) REFERENCES `tarchive` (`TarchiveID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tarchive_files` (
`TarchiveFileID` int(11) NOT NULL auto_increment,
`TarchiveID` int(11) NOT NULL default '0',
`TarchiveSeriesID` INT(11) DEFAULT NULL,
`SeriesNumber` int(11) default NULL,
`FileNumber` int(11) default NULL,
`EchoNumber` int(11) default NULL,
`SeriesDescription` varchar(255) default NULL,
`Md5Sum` varchar(255) NOT NULL,
`FileName` varchar(255) NOT NULL,
PRIMARY KEY (`TarchiveFileID`),
KEY `TarchiveID` (`TarchiveID`),
KEY `TarchiveSeriesID` (`TarchiveSeriesID`),
CONSTRAINT `tarchive_files_ibfk_1` FOREIGN KEY (`TarchiveID`) REFERENCES `tarchive` (`TarchiveID`) ON DELETE CASCADE,
CONSTRAINT `tarchive_files_TarchiveSeriesID_fk` FOREIGN KEY (`TarchiveSeriesID`) REFERENCES `tarchive_series` (`TarchiveSeriesID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ********************************
-- HRRT PET archive tables
-- ********************************
CREATE TABLE `hrrt_archive` (
`HrrtArchiveID` INT(11) NOT NULL AUTO_INCREMENT,
`SessionID` INT(10) unsigned DEFAULT NULL,
`EcatFileCount` INT(11) NOT NULL DEFAULT '0',
`NonEcatFileCount` INT(11) NOT NULL DEFAULT '0',
`DateAcquired` DATE DEFAULT NULL,
`DateArchived` DATETIME DEFAULT NULL,
`PatientName` VARCHAR(50) NOT NULL DEFAULT '',
`CenterName` VARCHAR(50) NOT NULL DEFAULT '',
`CreatingUser` VARCHAR(50) NOT NULL DEFAULT '',
`Blake2bArchive` VARCHAR(255) DEFAULT NULL,
`ArchiveLocation` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`HrrtArchiveID`),
KEY `patNam` (`CenterName`(10),`PatientName`(30)),
KEY `FK_hrrt_archive_sessionID` (`SessionID`),
CONSTRAINT `FK_hrrt_archive_sessionID`
FOREIGN KEY (`SessionID`)
REFERENCES `session` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `hrrt_archive_files` (
`HrrtArchiveFileID` INT(11) NOT NULL AUTO_INCREMENT,
`HrrtArchiveID` INT(11) NOT NULL DEFAULT '0',
`Blake2bHash` VARCHAR(255) NOT NULL,
`FileName` VARCHAR(255) NOT NULL,
PRIMARY KEY (`HrrtArchiveFileID`),
KEY `HrrtArchiveID` (`HrrtArchiveID`),
CONSTRAINT `hrrt_archive_files_ibfk_1`
FOREIGN KEY (`HrrtArchiveID`)
REFERENCES `hrrt_archive` (`HrrtArchiveID`)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ********************************
-- Imaging tables
-- ********************************
CREATE TABLE `ImagingFileTypes` (
`type` varchar(12) NOT NULL PRIMARY KEY,
`description` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `ImagingFileTypes` (type, description) VALUES
('mnc', 'MINC file'),
('obj', 'MNI BIC imaging format for a surface'),
('xfm', 'MNI BIC linear transformation matrix file'),
('vertstat', 'MNI BIC imaging format for a field on a surface (e.g. cortical thickness)'),
('xml', 'XML file'),
('txt', 'text file'),
('nii', 'NIfTI file'),
('nrrd', 'NRRD file format (used by DTIPrep)'),
('grid_0', 'MNI BIC non-linear field for non-linear transformation');
CREATE TABLE `mri_processing_protocol` (
`ProcessProtocolID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ProtocolFile` varchar(255) NOT NULL DEFAULT '',
`FileType` varchar(12) DEFAULT NULL,
`Tool` varchar(255) NOT NULL DEFAULT '',
`InsertTime` int(10) unsigned NOT NULL DEFAULT '0',
`md5sum` varchar(32) DEFAULT NULL,
PRIMARY KEY (`ProcessProtocolID`),
CONSTRAINT `FK_mri_processing_protocol_FileTypes` FOREIGN KEY (`FileType`) REFERENCES `ImagingFileTypes`(`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `mri_scanner` (
`ID` int(11) unsigned NOT NULL auto_increment,
`Manufacturer` varchar(255) default NULL,
`Model` varchar(255) default NULL,
`Serial_number` varchar(255) default NULL,
`Software` varchar(255) default NULL,
`CandID` int(11) default NULL,
PRIMARY KEY (`ID`),
KEY `FK_mri_scanner_1` (`CandID`),
CONSTRAINT `FK_mri_scanner_1` FOREIGN KEY (`CandID`) REFERENCES `candidate` (`CandID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SET @OLD_SQL_MODE=@@SQL_MODE;
SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';
INSERT INTO `mri_scanner` (ID) VALUES (0);
SET SQL_MODE=@OLD_SQL_MODE;
CREATE TABLE `mri_scan_type` (
`ID` int(11) unsigned NOT NULL auto_increment,
`Scan_type` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8;
INSERT INTO `mri_scan_type` VALUES
(40,'fMRI'),
(41,'flair'),
(44,'t1'),
(45,'t2'),
(46,'pd'),
(47,'mrs'),
(48,'dti'),
(49,'t1relx'),
(50,'dct2e1'),
(51,'dct2e2'),
(52,'scout'),
(53,'tal_msk'),
(54,'cocosco_cls'),
(55,'clean_cls'),
(56,'em_cls'),
(57,'seg'),
(58,'white_matter'),
(59,'gray_matter'),
(60,'csf_matter'),
(61,'nlr_masked'),
(62,'pve'),
(999,'unknown'),
(1000,'NA');
CREATE TABLE `files` (
`FileID` int(10) unsigned NOT NULL auto_increment,
`SessionID` int(10) unsigned NOT NULL default '0',
`File` varchar(255) NOT NULL default '',
`SeriesUID` varchar(64) DEFAULT NULL,
`EchoTime` double DEFAULT NULL,
`CoordinateSpace` varchar(255) default NULL,
`OutputType` varchar(255) NOT NULL default '',
`AcquisitionProtocolID` int(10) unsigned default NULL,
`FileType` varchar(12) default NULL,
`InsertedByUserID` varchar(255) NOT NULL default '',
`InsertTime` int(10) unsigned NOT NULL default '0',
`SourcePipeline` varchar(255),
`PipelineDate` date,
`SourceFileID` int(10) unsigned DEFAULT '0',
`ProcessProtocolID` int(11) unsigned,
`Caveat` tinyint(1) default NULL,
`TarchiveSource` int(11) default NULL,
`HrrtArchiveID` int(11) default NULL,
`ScannerID` int(10) unsigned default NULL,
`AcqOrderPerModality` int(11) default NULL,
`AcquisitionDate` date default NULL,
PRIMARY KEY (`FileID`),
KEY `file` (`File`),
KEY `sessionid` (`SessionID`),
KEY `outputtype` (`OutputType`),
KEY `filetype_outputtype` (`FileType`,`OutputType`),
KEY `AcquiIndex` (`AcquisitionProtocolID`,`SessionID`),
KEY `scannerid` (`ScannerID`),
KEY `tarchivesource` (`TarchiveSource`),
KEY `FK_files_HrrtArchiveID_1` (`HrrtArchiveID`),
CONSTRAINT `FK_files_2` FOREIGN KEY (`AcquisitionProtocolID`) REFERENCES `mri_scan_type` (`ID`),
CONSTRAINT `FK_files_1` FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`),
CONSTRAINT `FK_files_3` FOREIGN KEY (`SourceFileID`) REFERENCES `files` (`FileID`),
CONSTRAINT `FK_files_4` FOREIGN KEY (`ProcessProtocolID`) REFERENCES `mri_processing_protocol` (`ProcessProtocolID`),
CONSTRAINT `FK_files_FileTypes` FOREIGN KEY (`FileType`) REFERENCES `ImagingFileTypes`(`type`),
CONSTRAINT `FK_files_scannerID` FOREIGN KEY (`ScannerID`) REFERENCES `mri_scanner` (`ID`),
CONSTRAINT `FK_files_TarchiveID` FOREIGN KEY (`TarchiveSource`) REFERENCES `tarchive` (`TarchiveID`),
CONSTRAINT `FK_files_HrrtArchiveID` FOREIGN KEY (`HrrtArchiveID`) REFERENCES `hrrt_archive` (`HrrtArchiveID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `files_intermediary` (
`IntermedID` int(11) NOT NULL AUTO_INCREMENT,
`Output_FileID` int(10) unsigned NOT NULL,
`Input_FileID` int(10) unsigned NOT NULL,
`Tool` varchar(255) NOT NULL,
PRIMARY KEY (`IntermedID`),
KEY `FK_files_intermediary_1` (`Output_FileID`),
KEY `FK_files_intermediary_2` (`Input_FileID`),
CONSTRAINT `FK_files_intermediary_1` FOREIGN KEY (`Output_FileID`) REFERENCES `files` (`FileID`),
CONSTRAINT `FK_files_intermediary_2` FOREIGN KEY (`Input_FileID`) REFERENCES `files` (`FileID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `files_qcstatus` (
`FileQCID` int(11) auto_increment,
`FileID` int(10) UNSIGNED UNIQUE NULL,
`SeriesUID` varchar(64) DEFAULT NULL,
`EchoTime` double DEFAULT NULL,
`QCStatus` enum('Pass', 'Fail'),
`QCFirstChangeTime` int(10) unsigned,
`QCLastChangeTime` int(10) unsigned,
`Selected` enum('true', 'false') DEFAULT NULL,
PRIMARY KEY (`FileQCID`),
KEY (`FileID`),
CONSTRAINT `FK_filesqcstatus_FileID`
FOREIGN KEY (`FileID`) REFERENCES `files` (`FileID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `mri_protocol_group` (
`MriProtocolGroupID` INT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL UNIQUE,
PRIMARY KEY (`MriProtocolGroupID`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `mri_protocol_group` (`Name`) VALUES('Default MRI protocol group');
CREATE TABLE `mri_protocol` (
`ID` int(11) unsigned NOT NULL auto_increment,
`Center_name` varchar(4) NOT NULL default '',
`ScannerID` int(10) unsigned NOT NULL default '0',
`Scan_type` int(10) unsigned NOT NULL default '0',
`TR_min` DECIMAL(10,4) DEFAULT NULL,
`TR_max` DECIMAL(10,4) DEFAULT NULL,
`TE_min` DECIMAL(10,4) DEFAULT NULL,
`TE_max` DECIMAL(10,4) DEFAULT NULL,
`TI_min` DECIMAL(10,4) DEFAULT NULL,
`TI_max` DECIMAL(10,4) DEFAULT NULL,
`slice_thickness_min` DECIMAL(9,4) DEFAULT NULL,
`slice_thickness_max` DECIMAL(9,4) DEFAULT NULL,
`xspace_min` int(4) DEFAULT NULL,
`xspace_max` int(4) DEFAULT NULL,
`yspace_min` int(4) DEFAULT NULL,
`yspace_max` int(4) DEFAULT NULL,
`zspace_min` int(4) DEFAULT NULL,
`zspace_max` int(4) DEFAULT NULL,
`xstep_min` DECIMAL(9,4) DEFAULT NULL,
`xstep_max` DECIMAL(9,4) DEFAULT NULL,
`ystep_min` DECIMAL(9,4) DEFAULT NULL,
`ystep_max` DECIMAL(9,4) DEFAULT NULL,
`zstep_min` DECIMAL(9,4) DEFAULT NULL,
`zstep_max` DECIMAL(9,4) DEFAULT NULL,
`time_min` int(4) DEFAULT NULL,
`time_max` int(4) DEFAULT NULL,
`image_type` varchar(255) default NULL,
`series_description_regex` varchar(255) default NULL,
`MriProtocolGroupID` INT(4) UNSIGNED NOT NULL,
PRIMARY KEY (`ID`),
KEY `FK_mri_protocol_1` (`ScannerID`),
CONSTRAINT `FK_mri_protocol_1` FOREIGN KEY (`ScannerID`) REFERENCES `mri_scanner` (`ID`),
CONSTRAINT `FK_mri_protocol_group_ID_1` FOREIGN KEY (`MriProtocolGroupID`) REFERENCES `mri_protocol_group` (`MriProtocolGroupID`)
) ENGINE=InnoDB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8;
INSERT INTO mri_protocol (Center_name,Scan_type,TR_min,TR_max,TE_min,
TE_max,time_min,time_max,MriProtocolGroupID) VALUES
('ZZZZ',48,8000,14000,80,130,0,200,(SELECT MriProtocolGroupID FROM mri_protocol_group WHERE Name='Default MRI protocol group')),
('ZZZZ',40,1900,2700,10,30,0,500,(SELECT MriProtocolGroupID FROM mri_protocol_group WHERE Name='Default MRI protocol group')),
('ZZZZ',44,2000,2500,2,5,NULL,NULL,(SELECT MriProtocolGroupID FROM mri_protocol_group WHERE Name='Default MRI protocol group')),
('ZZZZ',45,3000,9000,100,550,NULL,NULL,(SELECT MriProtocolGroupID FROM mri_protocol_group WHERE Name='Default MRI protocol group'));
CREATE TABLE `mri_protocol_group_target` (
`MriProtocolGroupTargetID` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`MriProtocolGroupID` INT(4) UNSIGNED NOT NULL,
`ProjectID` INT(10) UNSIGNED DEFAULT NULL,
`SubprojectID` INT(10) UNSIGNED DEFAULT NULL,
`Visit_label` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`MriProtocolGroupTargetID`),
CONSTRAINT `FK_mri_protocol_group_target_1` FOREIGN KEY (`MriProtocolGroupID`) REFERENCES `mri_protocol_group` (`MriProtocolGroupID`),
CONSTRAINT `FK_mri_protocol_group_target_2` FOREIGN KEY (`ProjectID`) REFERENCES `Project` (`ProjectID`),
CONSTRAINT `FK_mri_protocol_group_target_3` FOREIGN KEY (`SubprojectID`) REFERENCES `subproject` (`SubprojectID`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `mri_protocol_group_target` (`MriProtocolGroupID`, `ProjectID`, `SubprojectID`, `Visit_label`)
VALUES((SELECT MriProtocolGroupID FROM mri_protocol_group WHERE Name='Default MRI protocol group'), NULL, NULL, NULL);
CREATE TABLE `mri_upload` (
`UploadID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`UploadedBy` varchar(255) NOT NULL DEFAULT '',
`UploadDate` DateTime DEFAULT NULL,
`UploadLocation` varchar(255) NOT NULL DEFAULT '',
`DecompressedLocation` varchar(255) NOT NULL DEFAULT '',
`InsertionComplete` tinyint(1) NOT NULL DEFAULT '0',
`Inserting` tinyint(1) DEFAULT NULL,
`PatientName` varchar(255) NOT NULL DEFAULT '',
`number_of_mincInserted` int(11) DEFAULT NULL,
`number_of_mincCreated` int(11) DEFAULT NULL,
`TarchiveID` int(11) DEFAULT NULL,
`SessionID` int(10) unsigned DEFAULT NULL,
`IsCandidateInfoValidated` tinyint(1) DEFAULT NULL,
`IsTarchiveValidated` tinyint(1) NOT NULL DEFAULT '0',
`IsPhantom` enum('N','Y') NOT NULL DEFAULT 'N',
PRIMARY KEY (`UploadID`),
KEY (`SessionID`),
KEY (`TarchiveID`),
CONSTRAINT `FK_mriupload_SessionID`
FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`),
CONSTRAINT `FK_mriupload_TarchiveID`
FOREIGN KEY (`TarchiveID`) REFERENCES `tarchive` (`TarchiveID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `mri_upload_rel` (
`UploadRelID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`UploadID` INT(10) UNSIGNED NOT NULL,
`HrrtArchiveID` INT(11) DEFAULT NULL,
PRIMARY KEY (`UploadRelID`),
KEY `FK_mriuploadrel_UploadID` (`UploadID`),
KEY `FK_mriuploadrel_HrrtArchiveID` (`HrrtArchiveID`),
CONSTRAINT `FK_mriuploadrel_UploadID`
FOREIGN KEY (`UploadID`)
REFERENCES `mri_upload` (`UploadID`),
CONSTRAINT `FK_mriuploadrel_HrrtArchiveID`
FOREIGN KEY (`HrrtArchiveID`)
REFERENCES `hrrt_archive` (`HrrtArchiveID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `mri_protocol_checks_group` (
`MriProtocolChecksGroupID` INT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL UNIQUE,
PRIMARY KEY (`MriProtocolChecksGroupID`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `mri_protocol_checks_group` (`Name`) VALUES('Default MRI protocol checks group');
CREATE TABLE `mri_protocol_checks` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Scan_type` int(11) unsigned DEFAULT NULL,
`Severity` enum('warning','exclude') DEFAULT NULL,
`Header` varchar(255) DEFAULT NULL,
`ValidMin` decimal(10,4) DEFAULT NULL,
`ValidMax` decimal(10,4) DEFAULT NULL,
`ValidRegex` varchar(255) DEFAULT NULL,
`MriProtocolChecksGroupID` INT(4) UNSIGNED NOT NULL,
PRIMARY KEY (`ID`),
KEY (`Scan_type`),
CONSTRAINT `FK_mriProtocolChecks_ScanType`
FOREIGN KEY (`Scan_type`) REFERENCES `mri_scan_type` (`ID`),
CONSTRAINT `FK_mri_protocol_checks_group_ID_1`
FOREIGN KEY (`MriProtocolChecksGroupID`) REFERENCES `mri_protocol_checks_group` (`MriProtocolChecksGroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `mri_protocol_checks_group_target` (
`MriProtocolChecksGroupTargetID` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`MriProtocolChecksGroupID` INT(4) UNSIGNED NOT NULL,
`ProjectID` INT(10) UNSIGNED DEFAULT NULL,
`SubprojectID` INT(10) UNSIGNED DEFAULT NULL,
`Visit_label` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY(`MriProtocolChecksGroupTargetID`),
CONSTRAINT `FK_mri_protocol_checks_group_target_1` FOREIGN KEY (`MriProtocolChecksGroupID`) REFERENCES `mri_protocol_checks_group` (`MriProtocolChecksGroupID`),
CONSTRAINT `FK_mri_protocol_checks_group_target_2` FOREIGN KEY (`ProjectID`) REFERENCES `Project` (`ProjectID`),
CONSTRAINT `FK_mri_protocol_checks_group_target_3` FOREIGN KEY (`SubprojectID`) REFERENCES `subproject` (`SubprojectID`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `mri_protocol_checks_group_target` (`MriProtocolChecksGroupID`, `ProjectID`, `SubprojectID`, `Visit_label`)
VALUES((SELECT MriProtocolChecksGroupID FROM mri_protocol_checks_group WHERE Name='Default MRI protocol checks group'), NULL, NULL, NULL);
-- ********************************
-- BIDS tables
-- ********************************
CREATE TABLE `bids_category` (
`BIDSCategoryID` int(3) UNSIGNED NOT NULL AUTO_INCREMENT,
`BIDSCategoryName` varchar(10) NOT NULL UNIQUE,
PRIMARY KEY (`BIDSCategoryID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `bids_category` (BIDSCategoryName) VALUES
('anat'),
('func'),
('dwi'),
('fmap');
CREATE TABLE `bids_scan_type_subcategory` (
`BIDSScanTypeSubCategoryID` int(3) UNSIGNED NOT NULL AUTO_INCREMENT,
`BIDSScanTypeSubCategory` varchar(100) NOT NULL UNIQUE,
PRIMARY KEY (`BIDSScanTypeSubCategoryID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `bids_scan_type_subcategory` (BIDSScanTypeSubCategory) VALUES
('task-rest');
CREATE TABLE `bids_scan_type` (
`BIDSScanTypeID` int(3) UNSIGNED NOT NULL AUTO_INCREMENT,
`BIDSScanType` varchar(100) NOT NULL UNIQUE,
PRIMARY KEY (`BIDSScanTypeID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `bids_scan_type` (BIDSScanType) VALUES
('bold'),
('FLAIR'),
('T1w'),
('T2w'),
('dwi');
CREATE TABLE `bids_mri_scan_type_rel` (
`MRIScanTypeID` int(10) UNSIGNED NOT NULL,
`BIDSCategoryID` int(3) UNSIGNED DEFAULT NULL,
`BIDSScanTypeSubCategoryID` int(3) UNSIGNED DEFAULT NULL,
`BIDSScanTypeID` int(3) UNSIGNED DEFAULT NULL,
`BIDSEchoNumber` int(3) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`MRIScanTypeID`),
KEY `FK_bids_mri_scan_type_rel` (`MRIScanTypeID`),
CONSTRAINT `FK_bids_mri_scan_type_rel` FOREIGN KEY (`MRIScanTypeID`) REFERENCES `mri_scan_type` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_bids_category` FOREIGN KEY (`BIDSCategoryID`) REFERENCES `bids_category`(`BIDSCategoryID`),
CONSTRAINT `FK_bids_scan_type_subcategory` FOREIGN KEY (`BIDSScanTypeSubCategoryID`) REFERENCES `bids_scan_type_subcategory` (`BIDSScanTypeSubCategoryID`),
CONSTRAINT `FK_bids_scan_type` FOREIGN KEY (`BIDSScanTypeID`) REFERENCES `bids_scan_type` (`BIDSScanTypeID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Default schema scan types; make some of them named in a BIDS compliant manner
INSERT INTO bids_mri_scan_type_rel
(MRIScanTypeID, BIDSCategoryID, BIDSScanTypeSubCategoryID, BIDSScanTypeID, BIDSEchoNumber)
VALUES
(
(SELECT ID FROM mri_scan_type WHERE Scan_type = 'flair'),
(SELECT BIDSCategoryID FROM bids_category WHERE BIDSCategoryName='anat'),
NULL,
(SELECT BIDSScanTypeID FROM bids_scan_type WHERE BIDSSCanType='FLAIR'),
NULL
),
(
(SELECT ID FROM mri_scan_type WHERE Scan_type = 'fMRI'),
(SELECT BIDSCategoryID FROM bids_category WHERE BIDSCategoryName='func'),
(SELECT BIDSScanTypeSubCategoryID FROM bids_scan_type_subcategory WHERE BIDSScanTypeSubCategory='task-rest'),
(SELECT BIDSScanTypeID FROM bids_scan_type WHERE BIDSSCanType='bold'),
NULL
),
(
(SELECT ID FROM mri_scan_type WHERE Scan_type = 't1'),
(SELECT BIDSCategoryID FROM bids_category WHERE BIDSCategoryName='anat'),
NULL,
(SELECT BIDSScanTypeID FROM bids_scan_type WHERE BIDSSCanType='T1w'),
NULL
),
(
(SELECT ID FROM mri_scan_type WHERE Scan_type = 't2'),
(SELECT BIDSCategoryID FROM bids_category WHERE BIDSCategoryName='anat'),
NULL,
(SELECT BIDSScanTypeID FROM bids_scan_type WHERE BIDSSCanType='T2w'),
NULL
),
(
(SELECT ID FROM mri_scan_type WHERE Scan_type = 'dti'),
(SELECT BIDSCategoryID FROM bids_category WHERE BIDSCategoryName='dwi'),
NULL,
(SELECT BIDSScanTypeID FROM bids_scan_type WHERE BIDSSCanType='dwi'),
NULL
);
-- ********************************
-- MRI violations tables
-- ********************************
CREATE TABLE `MRICandidateErrors` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`TimeRun` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`SeriesUID` varchar(64) DEFAULT NULL,
`TarchiveID` int(11) DEFAULT NULL,
`MincFile` varchar(255) DEFAULT NULL,
`PatientName` varchar(255) DEFAULT NULL,
`Reason` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `FK_tarchive_MRICandidateError_1`
FOREIGN KEY (`TarchiveID`) REFERENCES `tarchive` (`TarchiveID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `mri_violations_log` (
`LogID` int(11) NOT NULL AUTO_INCREMENT,
`TimeRun` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`SeriesUID` varchar(64) DEFAULT NULL,
`TarchiveID` int(11) DEFAULT NULL,
`MincFile` varchar(255) DEFAULT NULL,
`PatientName` varchar(255) DEFAULT NULL,
`CandID` int(6) DEFAULT NULL,
`Visit_label` varchar(255) DEFAULT NULL,
`CheckID` int(11) DEFAULT NULL,
`Scan_type` int(11) unsigned DEFAULT NULL,
`Severity` enum('warning','exclude') DEFAULT NULL,
`Header` varchar(255) DEFAULT NULL,
`Value` varchar(255) DEFAULT NULL,
`ValidRange` varchar(255) DEFAULT NULL,
`ValidRegex` varchar(255) DEFAULT NULL,
`MriProtocolChecksGroupID` INT(4) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`LogID`),
CONSTRAINT `FK_tarchive_mriViolationsLog_1`
FOREIGN KEY (`TarchiveID`) REFERENCES `tarchive` (`TarchiveID`),
CONSTRAINT `FK_mri_checks_group_1`
FOREIGN KEY (`MriProtocolChecksGroupID`) REFERENCES `mri_protocol_checks_group` (`MriProtocolChecksGroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `violations_resolved` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`hash` varchar(255) NOT NULL,
`ExtID` bigint(20) NOT NULL,
`TypeTable` varchar(255) DEFAULT NULL,
`User` varchar(255) DEFAULT NULL,
`ChangeDate` datetime DEFAULT NULL,
`Resolved` enum('unresolved', 'reran', 'emailed', 'inserted', 'rejected', 'inserted_flag', 'other') DEFAULT 'unresolved',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `mri_protocol_violated_scans` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`CandID` int(6),
`PSCID` varchar(255),
`TarchiveID` int(11),
`time_run` datetime,
`series_description` varchar(255) DEFAULT NULL,
`minc_location` varchar(255),
`PatientName` varchar(255) DEFAULT NULL,
`TR_range` varchar(255) DEFAULT NULL,
`TE_range` varchar(255) DEFAULT NULL,
`TI_range` varchar(255) DEFAULT NULL,
`slice_thickness_range` varchar(255) DEFAULT NULL,
`xspace_range` varchar(255) DEFAULT NULL,
`yspace_range` varchar(255) DEFAULT NULL,
`zspace_range` varchar(255) DEFAULT NULL,
`xstep_range` varchar(255) DEFAULT NULL,
`ystep_range` varchar(255) DEFAULT NULL,
`zstep_range` varchar(255) DEFAULT NULL,
`time_range` varchar(255) DEFAULT NULL,
`SeriesUID` varchar(64) DEFAULT NULL,
`image_type` varchar(255) default NULL,
`MriProtocolGroupID` INT(4) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `TarchiveID` (`TarchiveID`),
CONSTRAINT `FK_mri_violated_1` FOREIGN KEY (`TarchiveID`) REFERENCES `tarchive` (`TarchiveID`),
CONSTRAINT `FK_mri_violated_2` FOREIGN KEY (`MriProtocolGroupID`) REFERENCES `mri_protocol_group` (`MriProtocolGroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ********************************
-- document_repository tables
-- ********************************
CREATE TABLE `document_repository_categories` (
`id` int(3) unsigned NOT NULL AUTO_INCREMENT,
`category_name` varchar(255) DEFAULT NULL,
`parent_id` int(3) DEFAULT '0',
`comments` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `document_repository` (
`record_id` int(11) NOT NULL AUTO_INCREMENT,
`PSCID` varchar(255) DEFAULT NULL,
`Instrument` varchar(255) DEFAULT NULL,
`visitLabel` varchar(255) DEFAULT NULL,
`Date_taken` date DEFAULT NULL,
`Date_uploaded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`Data_dir` varchar(255) DEFAULT NULL,
`File_name` varchar(255) DEFAULT NULL,
`File_type` varchar(20) DEFAULT NULL,
`version` varchar(20) DEFAULT NULL,
`File_size` bigint(20) unsigned DEFAULT NULL,
`uploaded_by` varchar(255) DEFAULT NULL,
`For_site` int(2) DEFAULT NULL,
`comments` text,
`multipart` enum('Yes','No') DEFAULT NULL,
`EARLI` tinyint(1) DEFAULT '0',
`hide_video` tinyint(1) DEFAULT '0',
`File_category` int(3) unsigned DEFAULT NULL,
PRIMARY KEY (`record_id`),
KEY `fk_document_repository_1_idx` (`File_category`),
CONSTRAINT `fk_document_repository_1` FOREIGN KEY (`File_category`) REFERENCES `document_repository_categories` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ********************************
-- Notification tables
-- ********************************
CREATE TABLE `notification_types` (
`NotificationTypeID` int(11) NOT NULL auto_increment,
`Type` varchar(255) NOT NULL default '',
`private` tinyint(1) default '0',
`Description` text,
PRIMARY KEY (`NotificationTypeID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `notification_types` (Type,private,Description) VALUES
('mri new study',0,'New studies processed by the MRI upload handler'),
('mri new series',0,'New series processed by the MRI upload handler'),
('mri upload handler emergency',1,'MRI upload handler emergencies'),
('mri staging required',1,'New studies received by the MRI upload handler that require staging'),
('mri invalid study',0,'Incorrectly labelled studies received by the MRI upload handler'),
('hardcopy request',0,'Hardcopy requests'),
('visual bvl qc',0,'Timepoints selected for visual QC'),
('mri qc status',0,'MRI QC Status change'),
('minc insertion',1,'Insertion of a MINC file into the MRI tables (files/parameter_file)'),
('tarchive loader',1,'calls specific Insertion Scripts'),
('tarchive validation',1,'Validation of the dicoms After uploading'),