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
|
|
|
* Access data for a study |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
Class Study { |
21
|
|
|
|
22
|
|
|
private $linkpdo; |
23
|
|
|
public $study; |
24
|
|
|
public $patientCodePrefix; |
25
|
|
|
|
26
|
|
|
public function __construct(String $study, PDO $linkpdo) { |
27
|
|
|
|
28
|
|
|
$this->linkpdo=$linkpdo; |
29
|
|
|
$connecter=$this->linkpdo->prepare('SELECT * FROM studies WHERE name=:study'); |
30
|
|
|
$connecter->execute(array( |
31
|
|
|
"study" => $study, |
32
|
|
|
)); |
33
|
|
|
$result=$connecter->fetch(PDO::FETCH_ASSOC); |
34
|
|
|
|
35
|
|
|
$this->study=$result['name']; |
36
|
|
|
$this->patientCodePrefix=$result['patient_code_prefix']; |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getPatientsLinkedToUserCenters($username) |
42
|
|
|
{ |
43
|
|
|
$patients=$this->linkpdo->prepare(' SELECT patients.code |
44
|
|
|
FROM patients |
45
|
|
|
WHERE patients.center IN (SELECT affiliated_centers.center |
46
|
|
|
FROM affiliated_centers |
47
|
|
|
WHERE affiliated_centers.username = :username |
48
|
|
|
UNION |
49
|
|
|
SELECT users.center |
50
|
|
|
FROM users |
51
|
|
|
WHERE users.username = :username) |
52
|
|
|
AND study = :study |
53
|
|
|
GROUP BY patients.code'); |
54
|
|
|
|
55
|
|
|
$patients->execute(array( |
56
|
|
|
'username' => $username, |
57
|
|
|
'study' => $this->study |
58
|
|
|
)); |
59
|
|
|
|
60
|
|
|
$patientsCodes=$patients->fetchAll(PDO::FETCH_COLUMN); |
61
|
|
|
|
62
|
|
|
$patientObjectsArray=[]; |
63
|
|
|
|
64
|
|
|
foreach ($patientsCodes as $patientCode) { |
65
|
|
|
$patientObjectsArray[]=new Patient($patientCode, $this->linkpdo); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $patientObjectsArray; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getAllCreatedVisits(bool $deleted=false) { |
72
|
|
|
|
73
|
|
|
$possibleStudyGroups=$this->getAllPossibleVisitGroups(); |
74
|
|
|
|
75
|
|
|
$visitsObjectArray=[]; |
76
|
|
|
|
77
|
|
|
foreach ($possibleStudyGroups as $studyGroup) { |
78
|
|
|
$createdVisits=$studyGroup->getStudyVisitManager()->getCreatedVisits($deleted); |
79
|
|
|
array_push($visitsObjectArray, ...$createdVisits); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $visitsObjectArray; |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getAllAwaitingUploadImagingVisit() { |
87
|
|
|
|
88
|
|
|
$possibleStudyGroups=$this->getAllPossibleVisitGroups(); |
89
|
|
|
$visitsObjectArray=[]; |
90
|
|
|
|
91
|
|
|
foreach ($possibleStudyGroups as $studyGroup) { |
92
|
|
|
if (in_array($studyGroup->groupModality, array(Visit_Group::GROUP_MODALITY_CT, Visit_Group::GROUP_MODALITY_MR, Visit_Group::GROUP_MODALITY_PET, Visit_Group::GROUP_MODALITY_RTSTRUCT))) { |
93
|
|
|
$awaitingUploadVisits=$studyGroup->getStudyVisitManager()->getAwaitingUploadVisit(); |
94
|
|
|
array_push($visitsObjectArray, ...$awaitingUploadVisits); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $visitsObjectArray; |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getAllAwaitingReviewImagingVisit($username=null) { |
105
|
|
|
|
106
|
|
|
$possibleStudyGroups=$this->getAllPossibleVisitGroups(); |
107
|
|
|
$visitsObjectArray=[]; |
108
|
|
|
|
109
|
|
|
foreach ($possibleStudyGroups as $studyGroup) { |
110
|
|
|
if (in_array($studyGroup->groupModality, array(Visit_Group::GROUP_MODALITY_CT, Visit_Group::GROUP_MODALITY_MR, Visit_Group::GROUP_MODALITY_PET, Visit_Group::GROUP_MODALITY_RTSTRUCT))) { |
111
|
|
|
$awaitingReviewVisits=$studyGroup->getStudyVisitManager()->getAwaitingReviewVisit($username); |
112
|
|
|
array_push($visitsObjectArray, ...$awaitingReviewVisits); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $visitsObjectArray; |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getAllUploadedImagingVisits() { |
123
|
|
|
|
124
|
|
|
$possibleStudyGroups=$this->getAllPossibleVisitGroups(); |
125
|
|
|
$visitsObjectArray=[]; |
126
|
|
|
|
127
|
|
|
foreach ($possibleStudyGroups as $studyGroup) { |
128
|
|
|
if (in_array($studyGroup->groupModality, array(Visit_Group::GROUP_MODALITY_CT, Visit_Group::GROUP_MODALITY_MR, Visit_Group::GROUP_MODALITY_PET, Visit_Group::GROUP_MODALITY_RTSTRUCT))) { |
129
|
|
|
$uploadedVisits=$studyGroup->getStudyVisitManager()->getUploadedVisits(); |
130
|
|
|
array_push($visitsObjectArray, ...$uploadedVisits); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return $visitsObjectArray; |
137
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function isHavingAwaitingReviewImagingVisit($username=null) { |
141
|
|
|
$awaitingVisits=$this->getAllAwaitingReviewImagingVisit($username); |
142
|
|
|
$havingAwaitingReview=(sizeof($awaitingVisits) > 0); |
143
|
|
|
return $havingAwaitingReview; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
|
148
|
|
|
public function getAllPossibleVisitGroups() { |
149
|
|
|
|
150
|
|
|
$allGroupsType=$this->linkpdo->prepare('SELECT id FROM visit_group WHERE study = :study'); |
151
|
|
|
$allGroupsType->execute(array('study' => $this->study)); |
152
|
|
|
$allGroupsIds=$allGroupsType->fetchall(PDO::FETCH_COLUMN); |
153
|
|
|
|
154
|
|
|
$visitGroupArray=[]; |
155
|
|
|
foreach ($allGroupsIds as $groupId) { |
156
|
|
|
$visitGroupArray[]=new Visit_Group($this->linkpdo, $groupId); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
return $visitGroupArray; |
160
|
|
|
|
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function getSpecificGroup(String $groupModality) : Visit_Group { |
164
|
|
|
|
165
|
|
|
$groupQuery=$this->linkpdo->prepare('SELECT id FROM visit_group WHERE study = :study AND group_modality=:groupModality'); |
166
|
|
|
$groupQuery->execute(array('study' => $this->study, 'groupModality'=> $groupModality)); |
167
|
|
|
$groupId=$groupQuery->fetch(PDO::FETCH_COLUMN); |
168
|
|
|
|
169
|
|
|
return new Visit_Group($this->linkpdo, $groupId); |
170
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function getStudySpecificGroupManager(String $groupModality) : Group_Visit_Manager { |
174
|
|
|
|
175
|
|
|
$visitGroup=$this->getSpecificGroup($groupModality); |
176
|
|
|
|
177
|
|
|
return new Group_Visit_Manager($this, $visitGroup, $this->linkpdo); |
178
|
|
|
|
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function getReviewManager() : Study_Review_Manager { |
182
|
|
|
return new Study_Review_Manager($this); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function getExportStudyData() : Export_Study_Data{ |
186
|
|
|
return new Export_Study_Data($this); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function getAllPatientsInStudy() { |
190
|
|
|
$allPatientQuery=$this->linkpdo->prepare('SELECT code FROM patients WHERE study = :study'); |
191
|
|
|
$allPatientQuery->execute(array('study' => $this->study)); |
192
|
|
|
$allPatients=$allPatientQuery->fetchall(PDO::FETCH_COLUMN); |
193
|
|
|
|
194
|
|
|
$patientObjectArray=[]; |
195
|
|
|
foreach ($allPatients as $patient) { |
196
|
|
|
$patientObjectArray[]=new Patient($patient, $this->linkpdo); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
return $patientObjectArray; |
200
|
|
|
|
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function getDocumentation(String $role) { |
204
|
|
|
if ($role == User::SUPERVISOR) { |
205
|
|
|
$documentationQuery=$this->linkpdo->prepare("SELECT id_documentation FROM documentation |
206
|
|
|
WHERE study = :study"); |
207
|
|
|
|
208
|
|
|
}else { |
209
|
|
|
$documentationQuery=$this->linkpdo->prepare("SELECT id_documentation FROM documentation |
210
|
|
|
WHERE study = :study |
211
|
|
|
AND ".$role."= 1 AND deleted=0"); |
212
|
|
|
|
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
$documentationQuery->execute(array('study' => $this->study)); |
216
|
|
|
$documentationAnswers=$documentationQuery->fetchAll(PDO::FETCH_COLUMN); |
217
|
|
|
|
218
|
|
|
$documentationObjects=[]; |
219
|
|
|
foreach ($documentationAnswers as $documentationId) { |
220
|
|
|
$documentationObjects[]=new Documentation($this->linkpdo, $documentationId); |
221
|
|
|
} |
222
|
|
|
return $documentationObjects; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Return userObject array for all users having role in the study |
227
|
|
|
* @return User[] |
228
|
|
|
*/ |
229
|
|
|
public function getUsersWithRoleInStudy() { |
230
|
|
|
$req=$this->linkpdo->prepare('SELECT DISTINCT users.username FROM roles,users |
231
|
|
|
WHERE roles.username=users.username |
232
|
|
|
AND roles.study=:study'); |
233
|
|
|
$req->execute(array('study' => $this->study)); |
234
|
|
|
$answers=$req->fetchAll(PDO::FETCH_COLUMN); |
235
|
|
|
|
236
|
|
|
$usersObjects=[]; |
237
|
|
|
foreach ($answers as $username) { |
238
|
|
|
$usersObjects[]=new User($username, $this->linkpdo); |
239
|
|
|
} |
240
|
|
|
return $usersObjects; |
241
|
|
|
|
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function getUsersByRoleInStudy(String $role) { |
245
|
|
|
$req=$this->linkpdo->prepare('SELECT username FROM roles |
246
|
|
|
WHERE study=:study AND name=:role '); |
247
|
|
|
$req->execute(array('study' => $this->study, 'role'=>$role)); |
248
|
|
|
$answers=$req->fetchAll(PDO::FETCH_COLUMN); |
249
|
|
|
|
250
|
|
|
$usersObjects=[]; |
251
|
|
|
foreach ($answers as $username) { |
252
|
|
|
$usersObjects[]=new User($username, $this->linkpdo); |
253
|
|
|
} |
254
|
|
|
return $usersObjects; |
255
|
|
|
|
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function getAllRolesByUsers() { |
259
|
|
|
$roles_query=$this->linkpdo->prepare('SELECT * FROM roles WHERE study=:study'); |
260
|
|
|
$roles_query->execute(array('study'=>$this->study)); |
261
|
|
|
$definedRoles=$roles_query->fetchall(PDO::FETCH_ASSOC); |
262
|
|
|
|
263
|
|
|
foreach ($definedRoles as $role) { |
264
|
|
|
$rolesList[$role['username']][]=$role['name']; |
265
|
|
|
} |
266
|
|
|
return $rolesList; |
|
|
|
|
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
public function getStatistics(String $modality) { |
270
|
|
|
return new Statistics($this, $modality); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function changeStudyActivation(bool $activated) { |
274
|
|
|
$req=$this->linkpdo->prepare('UPDATE studies SET |
275
|
|
|
active = :active |
276
|
|
|
WHERE name = :study'); |
277
|
|
|
$req->execute(array('study'=> $this->study, 'active'=>intval($activated))); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
public function isOriginalOrthancNeverKnown($anonFromOrthancStudyId) { |
281
|
|
|
|
282
|
|
|
$connecter=$this->linkpdo->prepare('SELECT Study_Orthanc_ID FROM visits |
283
|
|
|
INNER JOIN visit_type ON |
284
|
|
|
(visit_type.id=visits.visit_type_id |
285
|
|
|
AND visit_type.group_id IN (SELECT id FROM visit_group WHERE study = :study)) |
286
|
|
|
INNER JOIN orthanc_studies ON (orthanc_studies.id_visit=visits.id_visit) |
287
|
|
|
AND orthanc_studies.Anon_From_Orthanc_ID=:Anon_From_Orthanc_ID |
288
|
|
|
AND orthanc_studies.deleted=0 |
289
|
|
|
AND visits.deleted=0' |
290
|
|
|
); |
291
|
|
|
$connecter->execute(array( |
292
|
|
|
"study" => $this->study, |
293
|
|
|
"Anon_From_Orthanc_ID"=>$anonFromOrthancStudyId |
294
|
|
|
)); |
295
|
|
|
$result=$connecter->fetchAll(PDO::FETCH_COLUMN); |
296
|
|
|
|
297
|
|
|
if (count($result) > 0) return false; else return true; |
298
|
|
|
|
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
public static function createStudy(string $studyName, $patientCodePrefix, PDO $linkpdo) { |
302
|
|
|
|
303
|
|
|
$req=$linkpdo->prepare('INSERT INTO studies (name, patient_code_prefix) VALUES(:studyName, :patientCodePrefix) '); |
304
|
|
|
|
305
|
|
|
$req->execute(array( |
306
|
|
|
'studyName' => $studyName, |
307
|
|
|
'patientCodePrefix' => $patientCodePrefix |
308
|
|
|
)); |
309
|
|
|
|
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
} |