salimkanoun /
GaelO
| 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 of a dicom study in database |
||
| 18 | */ |
||
| 19 | |||
| 20 | Class Study_Details { |
||
| 21 | private $linkpdo; |
||
| 22 | public $studyUID; |
||
| 23 | public $idVisit; |
||
| 24 | public $uploaderUsername; |
||
| 25 | public $uploadDate; |
||
| 26 | |||
| 27 | public $studyAcquisitionDate; |
||
| 28 | public $studyAcquisitionTime; |
||
| 29 | public $studyAcquisitionDateTime; |
||
| 30 | public $studyOrthancId; |
||
| 31 | public $studyDescription; |
||
| 32 | public $patientOrthancId; |
||
| 33 | public $patientName; |
||
| 34 | public $patientId; |
||
| 35 | |||
| 36 | public $nbOfSeries; |
||
| 37 | public $diskSize; |
||
| 38 | public $uncompressedDiskSize; |
||
| 39 | public $deleted; |
||
| 40 | public $numberOfInstances; |
||
| 41 | |||
| 42 | public static function getStudyObjectByUID(string $studyUID, PDO $linkpdo) { |
||
| 43 | |||
| 44 | $studyQuery=$linkpdo->prepare('SELECT study_orthanc_id FROM orthanc_studies |
||
| 45 | WHERE study_uid=:studyUID' ); |
||
| 46 | |||
| 47 | $studyQuery->execute(array( |
||
| 48 | "studyUID" => $studyUID |
||
| 49 | )); |
||
| 50 | |||
| 51 | $orthancID=$studyQuery->fetch(PDO::FETCH_COLUMN); |
||
| 52 | |||
| 53 | return new Study_Details($orthancID, $linkpdo); |
||
| 54 | |||
| 55 | } |
||
| 56 | |||
| 57 | public function __construct($studyOrthancId, $linkpdo) { |
||
| 58 | $this->linkpdo=$linkpdo; |
||
| 59 | $this->studyOrthancId=$studyOrthancId; |
||
| 60 | |||
| 61 | $studyQuery=$this->linkpdo->prepare('SELECT * FROM orthanc_studies |
||
| 62 | WHERE study_orthanc_id=:studyOrthancID' ); |
||
| 63 | |||
| 64 | $studyQuery->execute(array( |
||
| 65 | "studyOrthancID" => $this->studyOrthancId |
||
| 66 | )); |
||
| 67 | |||
| 68 | $studyData=$studyQuery->fetch(PDO::FETCH_ASSOC); |
||
| 69 | |||
| 70 | $this->studyAcquisitionDate=$studyData['acquisition_date']; |
||
| 71 | $this->studyAcquisitionTime=$studyData['acquisition_time']; |
||
| 72 | $this->studyAcquisitionDateTime=$studyData['acquisition_datetime']; |
||
| 73 | $this->studyUID=$studyData['study_uid']; |
||
| 74 | $this->studyDescription=$studyData['study_description']; |
||
| 75 | $this->patientOrthancId=$studyData['patient_orthanc_id']; |
||
| 76 | $this->patientName=$studyData['patient_name']; |
||
| 77 | $this->patientId=$studyData['patient_id']; |
||
| 78 | $this->nbOfSeries=$studyData['number_of_series']; |
||
| 79 | $this->diskSize=$studyData['disk_size']; |
||
| 80 | $this->uncompressedDiskSize=$studyData['uncompressed_disk_size']; |
||
| 81 | $this->numberOfInstances=$studyData['number_of_instances']; |
||
| 82 | $this->deleted=$studyData['deleted']; |
||
| 83 | $this->idVisit=$studyData['id_visit']; |
||
| 84 | |||
| 85 | $this->uploaderUsername=$studyData['uploader']; |
||
| 86 | $this->uploadDate=$studyData['upload_date']; |
||
| 87 | |||
| 88 | } |
||
| 89 | |||
| 90 | public function getChildSeries() { |
||
| 91 | |||
| 92 | $idFetcher=$this->linkpdo->prepare("SELECT orthanc_series.series_orthanc_id FROM orthanc_series, orthanc_studies |
||
| 93 | WHERE orthanc_series.study_orthanc_id=orthanc_studies.study_orthanc_id |
||
| 94 | AND orthanc_studies.study_orthanc_id=:studyOrthancID"); |
||
| 95 | |||
| 96 | $idFetcher->execute(array( |
||
| 97 | "studyOrthancID" => $this->studyOrthancId |
||
| 98 | )); |
||
| 99 | |||
| 100 | $orthancSeriesIDs=$idFetcher->fetchAll(PDO::FETCH_COLUMN); |
||
| 101 | |||
| 102 | $childSeriesObject=[]; |
||
| 103 | foreach ($orthancSeriesIDs as $orthancSerieID) { |
||
| 104 | $childSeriesObject[]=new Series_Details($orthancSerieID, $this->linkpdo); |
||
| 105 | } |
||
| 106 | |||
| 107 | return $childSeriesObject; |
||
| 108 | |||
| 109 | } |
||
| 110 | |||
| 111 | public function changeDeletionStatus($deleted) { |
||
| 112 | |||
| 113 | //Activate only if no other activated study |
||
| 114 | if ($deleted == false && $this->isExistingActivatedStudyForVisit() == true) { |
||
|
0 ignored issues
–
show
|
|||
| 115 | throw new Exception("already existing activated study"); |
||
| 116 | } |
||
| 117 | |||
| 118 | $changeStatusUpload=$this->linkpdo->prepare('UPDATE orthanc_studies SET deleted = :deleted WHERE id_visit = :idvisit AND study_orthanc_id=:studyOrthancID'); |
||
| 119 | $changeStatusUpload->execute(array('idvisit'=> $this->idVisit, |
||
| 120 | 'studyOrthancID'=>$this->studyOrthancId, 'deleted'=>intval($deleted))); |
||
| 121 | |||
| 122 | //reactivate all series of this study |
||
| 123 | $childSeries=$this->getChildSeries(); |
||
| 124 | foreach ($childSeries as $serie) { |
||
| 125 | $serie->changeDeletionStatus(false); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | private function isExistingActivatedStudyForVisit() { |
||
| 130 | |||
| 131 | $studyQuery=$this->linkpdo->prepare('SELECT study_orthanc_id FROM orthanc_studies |
||
| 132 | WHERE orthanc_studies.id_visit=:idVisit AND deleted=0; |
||
| 133 | '); |
||
| 134 | $studyQuery->execute(array('idVisit' => $this->idVisit)); |
||
| 135 | |||
| 136 | $dataStudies=$studyQuery->fetchAll(PDO::FETCH_COLUMN); |
||
| 137 | |||
| 138 | if (empty($dataStudies)) { |
||
| 139 | return false; |
||
| 140 | } else { |
||
| 141 | return true; |
||
| 142 | } |
||
| 143 | |||
| 144 | } |
||
| 145 | } |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.