|
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 Patient data |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
class Patient { |
|
21
|
|
|
|
|
22
|
|
|
public $patient; |
|
23
|
|
|
private $linkpdo; |
|
24
|
|
|
public $patientCode; |
|
25
|
|
|
public $patientFirstName; |
|
26
|
|
|
public $patientLastName; |
|
27
|
|
|
public $patientGender; |
|
28
|
|
|
public $patientBirthDateUS; |
|
29
|
|
|
public $patientBirthDate; |
|
30
|
|
|
public $patientRegistrationDate; |
|
31
|
|
|
public $patientInvestigatorName; |
|
32
|
|
|
public $patientCenter; |
|
33
|
|
|
public $patientStudy; |
|
34
|
|
|
public $patientWithdraw; |
|
35
|
|
|
public $patientWithdrawReason; |
|
36
|
|
|
public $patientWithdrawDate; |
|
37
|
|
|
public $patientWithdrawDateString; |
|
38
|
|
|
|
|
39
|
|
|
const PATIENT_WITHDRAW="withdraw"; |
|
40
|
|
|
|
|
41
|
|
|
function __construct($patientCode, PDO $linkpdo) { |
|
42
|
|
|
$this->patient=$patientCode; |
|
43
|
|
|
$this->linkpdo=$linkpdo; |
|
44
|
|
|
|
|
45
|
|
|
$queryPatientsData=$this->linkpdo->prepare('SELECT * FROM patients WHERE code = :patient'); |
|
46
|
|
|
$queryPatientsData->execute(array('patient' => $this->patient)); |
|
47
|
|
|
$dataPatient=$queryPatientsData->fetch(PDO::FETCH_ASSOC); |
|
48
|
|
|
|
|
49
|
|
|
if (empty($dataPatient)) { |
|
50
|
|
|
throw new Exception("Non Existing Patient"); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$this->patientCode=$dataPatient['code']; |
|
54
|
|
|
$this->patientFirstName=$dataPatient['first_name']; |
|
55
|
|
|
$this->patientLastName=$dataPatient['last_name']; |
|
56
|
|
|
$this->patientGender=$dataPatient['gender']; |
|
57
|
|
|
$this->patientBirthDateUS=sprintf("%02d", $dataPatient['birth_month']).'-'.sprintf("%02d", $dataPatient['birth_day']).'-'.$dataPatient['birth_year']; |
|
58
|
|
|
$this->patientBirthDate=sprintf("%02d", $dataPatient['birth_year']).'-'.sprintf("%02d", $dataPatient['birth_month']).'-'.$dataPatient['birth_day']; |
|
59
|
|
|
$this->patientRegistrationDate=$dataPatient['registration_date']; |
|
60
|
|
|
$this->patientInvestigatorName=$dataPatient['investigator_name']; |
|
61
|
|
|
$this->patientCenter=$dataPatient['center']; |
|
62
|
|
|
$this->patientStudy=$dataPatient['study']; |
|
63
|
|
|
$this->patientWithdraw=$dataPatient['withdraw']; |
|
64
|
|
|
$this->patientWithdrawReason=$dataPatient['withdraw_reason']; |
|
65
|
|
|
$this->patientWithdrawDate=new DateTimeImmutable($dataPatient['withdraw_date']); |
|
66
|
|
|
$this->patientWithdrawDateString=$dataPatient['withdraw_date']; |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getImmutableRegistrationDate() : DateTimeImmutable { |
|
71
|
|
|
return new DateTimeImmutable($this->patientRegistrationDate); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* get Patient's Center Object |
|
76
|
|
|
* @return Center |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getPatientCenter() : Center { |
|
79
|
|
|
$centerObject=new Center($this->linkpdo, $this->patientCenter); |
|
80
|
|
|
return $centerObject; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Update withdraw status |
|
85
|
|
|
* @param bool $withdraw |
|
86
|
|
|
* @param string $withdrawDate |
|
87
|
|
|
* @param string $withdrawReason |
|
88
|
|
|
*/ |
|
89
|
|
|
public function changeWithdrawStatus(bool $withdraw, ?string $withdrawDate, ?string $withdrawReason) { |
|
90
|
|
|
|
|
91
|
|
|
$insertion=$this->linkpdo->prepare('UPDATE patients |
|
92
|
|
|
SET withdraw = :withdraw, |
|
93
|
|
|
withdraw_date = :withdraw_date, |
|
94
|
|
|
withdraw_reason = :withdraw_reason |
|
95
|
|
|
WHERE patients.code = :patient'); |
|
96
|
|
|
|
|
97
|
|
|
$insertion->execute(array('withdraw'=>intval($withdraw), |
|
98
|
|
|
'withdraw_date' => $withdrawDate, |
|
99
|
|
|
'withdraw_reason' => $withdrawReason, |
|
100
|
|
|
'patient' => $this->patient)); |
|
101
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Update patient data |
|
106
|
|
|
* @param $initials |
|
107
|
|
|
* @param $gender |
|
108
|
|
|
* @param $birthDate |
|
109
|
|
|
* @param $registrationDate |
|
110
|
|
|
* @param $investigator |
|
111
|
|
|
* @param $centerCode |
|
112
|
|
|
*/ |
|
113
|
|
|
public function editPatientDetails($initials, $gender, $birthDate, $registrationDate, $investigator, $centerCode) { |
|
114
|
|
|
$insertion=$this->linkpdo->prepare("UPDATE patients |
|
115
|
|
|
SET first_name = :firstName, |
|
116
|
|
|
last_name = :lastName, |
|
117
|
|
|
gender = :gender, |
|
118
|
|
|
birth_year=:year, |
|
119
|
|
|
birth_month=:month, |
|
120
|
|
|
birth_day=:day, |
|
121
|
|
|
registration_date=:registrationDate, |
|
122
|
|
|
investigator_name=:investigator, |
|
123
|
|
|
center=:centerCode |
|
124
|
|
|
WHERE patients.code = :patient"); |
|
125
|
|
|
|
|
126
|
|
|
$insertion->execute(array('firstName'=>$initials[1], |
|
127
|
|
|
'lastName'=>$initials[0], |
|
128
|
|
|
'gender'=>strtoupper($gender[0]), |
|
129
|
|
|
'year'=>substr($birthDate, 0, 4), |
|
130
|
|
|
'month'=>substr($birthDate, 5, 2), |
|
131
|
|
|
'day'=>substr($birthDate, 8, 2), |
|
132
|
|
|
'registrationDate' => $registrationDate, |
|
133
|
|
|
'investigator' => $investigator, |
|
134
|
|
|
'centerCode'=>$centerCode, |
|
135
|
|
|
'patient' => $this->patient)); |
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function editPatientRegistrationDate($registrationDate) { |
|
141
|
|
|
$insertion=$this->linkpdo->prepare("UPDATE patients |
|
142
|
|
|
SET registration_date=:registrationDate |
|
143
|
|
|
WHERE patients.code = :patient"); |
|
144
|
|
|
|
|
145
|
|
|
$insertion->execute(array( |
|
146
|
|
|
'registrationDate' => $registrationDate, |
|
147
|
|
|
'patient' => $this->patient)); |
|
148
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Return visit Manage to manage patient's visit status |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getPatientVisitManager(Visit_Group $visitGroupObject) { |
|
156
|
|
|
//Look if specific patient visit manager exists for this study |
|
157
|
|
|
$specificObjectFile=$_SERVER["DOCUMENT_ROOT"].'/data/form/'.$this->patientStudy.'/Poo/'.$this->patientStudy."_Patient_Visit_Manager.php"; |
|
158
|
|
|
|
|
159
|
|
|
if (is_file($specificObjectFile)) { |
|
160
|
|
|
require_once($specificObjectFile); |
|
161
|
|
|
$objectName=$this->patientStudy."_Patient_Visit_Manager"; |
|
162
|
|
|
return new $objectName($this, $visitGroupObject, $this->linkpdo); |
|
163
|
|
|
}else { |
|
164
|
|
|
return new Patient_Visit_Manager($this, $visitGroupObject, $this->linkpdo); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function getAllPossibleVisitGroup() : Array { |
|
170
|
|
|
|
|
171
|
|
|
$patientStudy=$this->getPatientStudy(); |
|
172
|
|
|
$possibleStudyGroups=$patientStudy->getAllPossibleVisitGroups(); |
|
173
|
|
|
|
|
174
|
|
|
return $possibleStudyGroups; |
|
175
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Return visits created for this patient without group filter |
|
180
|
|
|
*/ |
|
181
|
|
|
public function getAllCreatedPatientsVisits(bool $deletedVisits=false) : Array |
|
182
|
|
|
{ |
|
183
|
|
|
$possibleStudyGroups=$this->getAllPossibleVisitGroup(); |
|
184
|
|
|
|
|
185
|
|
|
$visitsObjectArray=[]; |
|
186
|
|
|
|
|
187
|
|
|
foreach ($possibleStudyGroups as $studyGroup) { |
|
188
|
|
|
$createdVisits=$this->getPatientVisitManager($studyGroup)->getCreatedPatientsVisits($deletedVisits); |
|
189
|
|
|
array_push($visitsObjectArray, ...$createdVisits); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
return $visitsObjectArray; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Return visits uploaded for this patient without group filter |
|
198
|
|
|
*/ |
|
199
|
|
|
public function getAllQcDonePatientsVisits(bool $deletedVisits=false) : Array |
|
200
|
|
|
{ |
|
201
|
|
|
$possibleStudyGroups=$this->getAllPossibleVisitGroup(); |
|
202
|
|
|
|
|
203
|
|
|
$visitsObjectArray=[]; |
|
204
|
|
|
|
|
205
|
|
|
foreach ($possibleStudyGroups as $studyGroup) { |
|
206
|
|
|
$createdVisits=$this->getPatientVisitManager($studyGroup)->getQcDonePatientsVisits($deletedVisits); |
|
207
|
|
|
array_push($visitsObjectArray, ...$createdVisits); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
return $visitsObjectArray; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function getAllVisitToCreate() : array { |
|
214
|
|
|
|
|
215
|
|
|
$possiblevisitsGroups=$this->getAllPossibleVisitGroup(); |
|
216
|
|
|
|
|
217
|
|
|
$visitsObjectArray=[]; |
|
218
|
|
|
|
|
219
|
|
|
foreach ($possiblevisitsGroups as $visitGroup) { |
|
220
|
|
|
try { |
|
221
|
|
|
$availableVisits=$this->getPatientVisitManager($visitGroup)->getAvailableVisitsToCreate(); |
|
222
|
|
|
}catch (Exception $e) { |
|
223
|
|
|
$availableVisits=array($e->getMessage()); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
$visitsObjectArray [$visitGroup->groupModality]['visitsName']=$availableVisits; |
|
227
|
|
|
$visitsObjectArray [$visitGroup->groupModality]['groupId']=$visitGroup->groupId; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
return $visitsObjectArray; |
|
231
|
|
|
|
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
public function isMissingVisit() { |
|
235
|
|
|
|
|
236
|
|
|
$modalitiesMissingVisits=$this->getMissingVisitModalities(); |
|
237
|
|
|
|
|
238
|
|
|
$isMissingSomeVisits=(sizeof($modalitiesMissingVisits) > 0); |
|
239
|
|
|
|
|
240
|
|
|
return $isMissingSomeVisits; |
|
241
|
|
|
|
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
public function getMissingVisitModalities() { |
|
245
|
|
|
|
|
246
|
|
|
$possiblevisitsGroups=$this->getAllPossibleVisitGroup(); |
|
247
|
|
|
|
|
248
|
|
|
$visitsMissingGroupsArray=[]; |
|
249
|
|
|
|
|
250
|
|
|
foreach ($possiblevisitsGroups as $visitGroup) { |
|
251
|
|
|
$missingVisit=$this->getPatientVisitManager($visitGroup)->isMissingVisit(); |
|
252
|
|
|
if ($missingVisit) { |
|
253
|
|
|
$visitsMissingGroupsArray[]=$visitGroup->groupModality; |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
return $visitsMissingGroupsArray; |
|
258
|
|
|
|
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
public function getPatientStudy() : Study { |
|
262
|
|
|
return new Study($this->patientStudy, $this->linkpdo); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
} |