|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
Copyright (C) 2018-2020 KANOUN Salim |
|
4
|
|
|
This program is free software; you can redistribute it and/or modify |
|
5
|
|
|
it under the terms of the Affero GNU General Public v.3 License as published by |
|
6
|
|
|
the Free Software Foundation; |
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10
|
|
|
Affero GNU General Public Public for more details. |
|
11
|
|
|
You should have received a copy of the Affero GNU General Public Public along |
|
12
|
|
|
with this program; if not, write to the Free Software Foundation, Inc., |
|
13
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Acces data of Visit Type table |
|
18
|
|
|
*/ |
|
19
|
|
|
Class Visit_Type { |
|
20
|
|
|
|
|
21
|
|
|
public $id; |
|
22
|
|
|
public $groupId; |
|
23
|
|
|
public $name; |
|
24
|
|
|
public $tableReviewSpecificName; |
|
25
|
|
|
public $visitOrder; |
|
26
|
|
|
public $localFormNeeded; |
|
27
|
|
|
public $qcNeeded; |
|
28
|
|
|
public $reviewNeeded; |
|
29
|
|
|
public $optionalVisit; |
|
30
|
|
|
public $limitLowDays; |
|
31
|
|
|
public $limitUpDays; |
|
32
|
|
|
public $anonProfile; |
|
33
|
|
|
public $dicomConstraints; |
|
34
|
|
|
|
|
35
|
|
|
public $linkpdo; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct(PDO $linkpdo, int $visitTypeId) { |
|
38
|
|
|
|
|
39
|
|
|
$this->linkpdo=$linkpdo; |
|
40
|
|
|
$visitTypeQuery=$this->linkpdo->prepare('SELECT * FROM visit_type WHERE id = :visitTypeId'); |
|
41
|
|
|
$visitTypeQuery->execute(array('visitTypeId' => $visitTypeId)); |
|
42
|
|
|
$visitType=$visitTypeQuery->fetch(PDO::FETCH_ASSOC); |
|
43
|
|
|
|
|
44
|
|
|
$this->id=$visitType['id']; |
|
45
|
|
|
$this->groupId=$visitType['group_id']; |
|
46
|
|
|
$this->name=$visitType['name']; |
|
47
|
|
|
$this->tableReviewSpecificName=$visitType['table_review_specific']; |
|
48
|
|
|
$this->visitOrder=$visitType['visit_order']; |
|
49
|
|
|
$this->localFormNeeded=$visitType['local_form_needed']; |
|
50
|
|
|
$this->qcNeeded=$visitType['qc_needed']; |
|
51
|
|
|
$this->reviewNeeded=$visitType['review_needed']; |
|
52
|
|
|
$this->optionalVisit=$visitType['optional']; |
|
53
|
|
|
$this->limitLowDays=$visitType['limit_low_days']; |
|
54
|
|
|
$this->limitUpDays=$visitType['limit_up_days']; |
|
55
|
|
|
$this->anonProfile=$visitType['anon_profile']; |
|
56
|
|
|
$this->dicomConstraints = $visitType['dicom_constraints']; |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public static function getVisitTypeByName($groupId, String $visitName, PDO $linkpdo) : Visit_Type { |
|
61
|
|
|
$visitTypeQuery=$linkpdo->prepare('SELECT id FROM visit_type WHERE group_id = :groupId AND name= :name'); |
|
62
|
|
|
$visitTypeQuery->execute(array('groupId' => $groupId, 'name'=>$visitName)); |
|
63
|
|
|
$visitTypeId=$visitTypeQuery->fetch(PDO::FETCH_COLUMN); |
|
64
|
|
|
return new Visit_Type($linkpdo, $visitTypeId); |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getDicomContraintsArray(){ |
|
69
|
|
|
return $this->dicomConstraints !=null ? json_decode($this->dicomConstraints) : null; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Return name of specific table of this visit type |
|
74
|
|
|
* @return array |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getSpecificFormColumn() : Array { |
|
77
|
|
|
$visitsTypeColumnQuery=$this->linkpdo->prepare('SELECT `COLUMN_NAME` |
|
78
|
|
|
FROM `INFORMATION_SCHEMA`.`COLUMNS` |
|
79
|
|
|
WHERE `TABLE_NAME`="'.$this->tableReviewSpecificName.'"'); |
|
80
|
|
|
$visitsTypeColumnQuery->execute(); |
|
81
|
|
|
$columnsSpecific=$visitsTypeColumnQuery->fetchAll(PDO::FETCH_COLUMN); |
|
82
|
|
|
|
|
83
|
|
|
return $columnsSpecific; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Return name and type of the specific table of this visit |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getSpecificTableInputType() : Array { |
|
91
|
|
|
$query=$this->linkpdo->prepare('SELECT COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME="'.$this->tableReviewSpecificName.'"'); |
|
92
|
|
|
$query->execute(); |
|
93
|
|
|
$datas=$query->fetchAll(PDO::FETCH_ASSOC); |
|
94
|
|
|
|
|
95
|
|
|
return $datas; |
|
96
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getVisitGroup() : Visit_Group{ |
|
100
|
|
|
return new Visit_Group($this->linkpdo, $this->groupId); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public static function createVisitType(string $studyName, Visit_Group $visitGroup, String $visitName, int $order, int $limitLowDays, int $limitUpDays, bool $localFormNeed, bool $qcNeeded, bool $reviewNeeded, bool $optional, String $anonProfile, ?array $dicomConstraints, PDO $linkpdo) { |
|
104
|
|
|
|
|
105
|
|
|
$req=$linkpdo->prepare('INSERT INTO visit_type (group_id, name, table_review_specific, visit_order, local_form_needed, qc_needed, review_needed, optional, limit_low_days, limit_up_days, anon_profile, dicom_constraints) |
|
106
|
|
|
VALUES(:groupId, :visitName, :tableSpecific, :order, :localFormNeeded, :qcNeeded, :reviewNeeded, :optional, :limitLowDays, :limitUpDays, :anonProfile, :dicomConstraints)'); |
|
107
|
|
|
|
|
108
|
|
|
$tableSpecificName=$visitGroup->groupModality."_".$studyName."_".$visitName; |
|
109
|
|
|
|
|
110
|
|
|
$req->execute(array('groupId' => $visitGroup->groupId, |
|
111
|
|
|
'visitName'=>$visitName, |
|
112
|
|
|
'tableSpecific'=>$tableSpecificName, |
|
113
|
|
|
'order'=>intval($order), |
|
114
|
|
|
'localFormNeeded'=>intval($localFormNeed), |
|
115
|
|
|
'qcNeeded'=>intval($qcNeeded), |
|
116
|
|
|
'reviewNeeded'=>intval($reviewNeeded), |
|
117
|
|
|
'optional'=>intval($optional), |
|
118
|
|
|
'limitLowDays'=>intval($limitLowDays), |
|
119
|
|
|
'limitUpDays'=>intval($limitUpDays), |
|
120
|
|
|
'anonProfile'=>$anonProfile, |
|
121
|
|
|
'dicomConstraints'=>json_encode($dicomConstraints) |
|
122
|
|
|
)); |
|
123
|
|
|
|
|
124
|
|
|
//Create specific table of the visit for form with relation with the review table |
|
125
|
|
|
$req=$linkpdo->prepare(' CREATE TABLE '.$tableSpecificName.' (id_review integer(11) NOT NULL, PRIMARY KEY (id_review)); |
|
126
|
|
|
ALTER TABLE '.$tableSpecificName.' ADD FOREIGN KEY fk_idReview (id_review) REFERENCES reviews(id_review); |
|
127
|
|
|
ALTER TABLE '.$tableSpecificName.' ADD PRIMARY KEY (`id_review`); '); |
|
128
|
|
|
|
|
129
|
|
|
$req->execute(); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
} |