salimkanoun /
GaelO
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | Copyright (C) 2018-2020 KANOUN Salim |
||
| 5 | This program is free software; you can redistribute it and/or modify |
||
| 6 | it under the terms of the Affero GNU General Public v.3 License as published by |
||
| 7 | the Free Software Foundation; |
||
| 8 | This program is distributed in the hope that it will be useful, |
||
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 11 | Affero GNU General Public Public for more details. |
||
| 12 | You should have received a copy of the Affero GNU General Public Public along |
||
| 13 | with this program; if not, write to the Free Software Foundation, Inc., |
||
| 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||
| 15 | */ |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Access Data to Visit Group |
||
| 19 | */ |
||
| 20 | |||
| 21 | class Visit_Group |
||
| 22 | { |
||
| 23 | |||
| 24 | public $groupId; |
||
| 25 | public $studyName; |
||
| 26 | public $groupModality; |
||
| 27 | |||
| 28 | public $linkpdo; |
||
| 29 | |||
| 30 | const GROUP_MODALITY_PET="PT"; |
||
| 31 | const GROUP_MODALITY_CT="CT"; |
||
| 32 | const GROUP_MODALITY_MR="MR"; |
||
| 33 | const GROUP_MODALITY_RTSTRUCT = "RTSTRUCT"; |
||
| 34 | |||
| 35 | public function __construct(PDO $linkpdo, int $groupId) |
||
| 36 | { |
||
| 37 | |||
| 38 | $this->linkpdo=$linkpdo; |
||
| 39 | $visitGroupQuery=$this->linkpdo->prepare('SELECT * FROM visit_group WHERE id = :groupId'); |
||
| 40 | $visitGroupQuery->execute(array('groupId' => $groupId)); |
||
| 41 | |||
| 42 | $visitGroupData=$visitGroupQuery->fetch(PDO::FETCH_ASSOC); |
||
| 43 | |||
| 44 | if (empty($visitGroupData)) { |
||
| 45 | throw new Exception('No Visit Group Found'); |
||
| 46 | } |
||
| 47 | |||
| 48 | $this->groupId=$visitGroupData['id']; |
||
| 49 | $this->studyName=$visitGroupData['study']; |
||
| 50 | $this->groupModality=$visitGroupData['group_modality']; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Get Visit Type object from Visit Name in this group |
||
| 55 | */ |
||
| 56 | public function getVisitType(String $visitName): Visit_Type |
||
| 57 | { |
||
| 58 | return Visit_Type::getVisitTypeByName($this->groupId, $visitName, $this->linkpdo); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Return all visit type of the current visit group |
||
| 63 | */ |
||
| 64 | public function getAllVisitTypesOfGroup(): array |
||
| 65 | { |
||
| 66 | |||
| 67 | $allVisitsType=$this->linkpdo->prepare('SELECT id FROM visit_type WHERE group_id= :groupId ORDER BY visit_order'); |
||
| 68 | $allVisitsType->execute(array('groupId' => $this->groupId)); |
||
| 69 | $allVisits=$allVisitsType->fetchall(PDO::FETCH_COLUMN); |
||
| 70 | |||
| 71 | $visitTypeArray=[]; |
||
| 72 | foreach ($allVisits as $visitTypeId) { |
||
| 73 | $visitTypeArray[]=new Visit_Type($this->linkpdo, $visitTypeId); |
||
| 74 | } |
||
| 75 | |||
| 76 | return $visitTypeArray; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Get iterator for Visit Type in this group |
||
| 81 | */ |
||
| 82 | public function getAllVisitTypesOfGroupIterator(): Visit_Type_Iterator |
||
| 83 | { |
||
| 84 | return new Visit_Type_Iterator($this->getAllVisitTypesOfGroup()); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Get Study Visit manager of this group |
||
| 89 | */ |
||
| 90 | public function getStudyVisitManager(): Group_Visit_Manager |
||
| 91 | { |
||
| 92 | $studyObject=new Study($this->studyName, $this->linkpdo); |
||
| 93 | return new Group_Visit_Manager($studyObject, $this, $this->linkpdo); |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Get study Object of this group |
||
| 98 | */ |
||
| 99 | public function getStudy(): Study |
||
| 100 | { |
||
| 101 | return new Study($this->studyName, $this->linkpdo); |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Create a new Visit Group |
||
| 106 | */ |
||
| 107 | public static function createVisitGroup(String $studyName, String $groupModality, PDO $linkpdo): Visit_Group |
||
| 108 | { |
||
| 109 | |||
| 110 | $req=$linkpdo->prepare('INSERT INTO visit_group (study, group_modality) |
||
| 111 | VALUES(:studyName, :groupModality)'); |
||
| 112 | |||
| 113 | $req->execute(array( |
||
| 114 | 'studyName' => $studyName, |
||
| 115 | 'groupModality' => $groupModality |
||
| 116 | )); |
||
| 117 | |||
| 118 | $idGroup=$linkpdo->lastInsertId(); |
||
| 119 | |||
| 120 | return new Visit_Group($linkpdo, $idGroup); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 121 | } |
||
| 122 | } |
||
| 123 |