| Total Complexity | 45 |
| Total Lines | 321 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Statistics often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Statistics, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class Statistics { |
||
| 20 | |||
| 21 | public $studyObject; |
||
| 22 | private $studyVisitManager; |
||
| 23 | |||
| 24 | public function __construct(Study $study, String $modalityType) { |
||
| 25 | $this->studyObject=$study; |
||
| 26 | $this->studyVisitManager=$this->studyObject->getStudySpecificGroupManager($modalityType); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * List review one by one with user and date |
||
| 31 | * @return array |
||
| 32 | */ |
||
| 33 | public function getReviewsDate() { |
||
| 34 | $reviewdetailsMap=$this->studyObject->getReviewManager()->getReviewsDetailsByVisit(); |
||
| 35 | |||
| 36 | $result=[]; |
||
| 37 | |||
| 38 | foreach ($reviewdetailsMap as $visitType=>$details) { |
||
| 39 | $review=[]; |
||
| 40 | foreach ($details['reviewDetailsArray'] as $detail) { |
||
| 41 | $review['username']=$detail['user']; |
||
| 42 | $review['date']=$detail['date']; |
||
| 43 | $result[]=$review; |
||
| 44 | |||
| 45 | } |
||
| 46 | } |
||
| 47 | return $result; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Provide uploadedFraction of patient in position 0 and upload delay in position 1 |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | public function getUploadFractionAndDelay() { |
||
| 61 | |||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Return the uploaded fraction of patients |
||
| 66 | * @param array $allPatientStatus |
||
| 67 | * @return array |
||
| 68 | */ |
||
| 69 | private function getUploadedFraction($allPatientStatus) { |
||
| 89 | |||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Calculate upload delay (from declared visit date and upload date) |
||
| 94 | * @param array $allPatientStatus |
||
| 95 | * @return array |
||
| 96 | */ |
||
| 97 | private function getUploadDelay($allPatientStatus) { |
||
| 98 | |||
| 99 | $resultArray=[]; |
||
| 100 | |||
| 101 | foreach ($allPatientStatus as $visitType => $patients) { |
||
| 102 | foreach ($patients as $patientCode=>$patientDetails) { |
||
| 103 | |||
| 104 | if ($patientDetails['status'] == Patient_Visit_Manager::DONE && $patientDetails['state_investigator_form'] == Patient_Visit_Manager::DONE) { |
||
| 105 | |||
| 106 | $acquisitionDate=new DateTimeImmutable($patientDetails['acquisition_date']); |
||
| 107 | $uploadDate=new DateTimeImmutable($patientDetails['upload_date']); |
||
| 108 | $uploadDelay=($uploadDate->getTimestamp()-$acquisitionDate->getTimestamp())/(3600*24); |
||
| 109 | $visit['uploadDelay']=$uploadDelay; |
||
| 110 | $visit['acquisitionCompliancy']=$patientDetails['compliancy']; |
||
| 111 | $visit['visitType']=$visitType; |
||
| 112 | $visit['idVisit']=$patientDetails['id_visit']; |
||
| 113 | $visit['center']=$patientDetails['center']; |
||
| 114 | $visit['country']=$patientDetails['country']; |
||
| 115 | $resultArray[]=$visit; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | return $resultArray; |
||
| 121 | |||
| 122 | |||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Return QC time (in days) for each visit (from upload date to QC) |
||
| 127 | * @return array |
||
| 128 | */ |
||
| 129 | public function getQCTime() { |
||
| 130 | |||
| 131 | $uploadedVisitArray=$this->studyVisitManager->getUploadedVisits(); |
||
| 132 | |||
| 133 | $responseDelayArray=[]; |
||
| 134 | |||
| 135 | foreach ($uploadedVisitArray as $visit) { |
||
| 136 | $responseQcArrayDetails=[]; |
||
| 137 | if ($visit->qcStatus != Visit::QC_NOT_DONE) { |
||
| 138 | $uploadDate=new DateTimeImmutable($visit->uploadDate); |
||
| 139 | $qcDate=new DateTimeImmutable($visit->controlDate); |
||
| 140 | $qcDelay=($qcDate->getTimestamp()-$uploadDate->getTimestamp())/(3600*24); |
||
| 141 | |||
| 142 | if ($visit->correctiveActionDate == null) { |
||
| 143 | $hasCorrectiveAction=false; |
||
| 144 | }else { |
||
| 145 | $hasCorrectiveAction=true; |
||
| 146 | } |
||
| 147 | |||
| 148 | $responseQcArrayDetails['idVisit']=$visit->id_visit; |
||
| 149 | $responseQcArrayDetails['qcDelay']=$qcDelay; |
||
| 150 | $responseQcArrayDetails['hasCorrectiveAction']=$hasCorrectiveAction; |
||
| 151 | } |
||
| 152 | $responseDelayArray[]=$responseQcArrayDetails; |
||
| 153 | } |
||
| 154 | |||
| 155 | return $responseDelayArray; |
||
| 156 | |||
| 157 | } |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Output the time to reach the review conclusion (from QC date to Review Done status) |
||
| 161 | * @return array[] |
||
| 162 | */ |
||
| 163 | public function getConclusionTime() { |
||
| 164 | |||
| 165 | $uploadedVisitArray=$this->studyVisitManager->getUploadedVisits(); |
||
| 166 | |||
| 167 | $responseDelayArray=[]; |
||
| 168 | |||
| 169 | foreach ($uploadedVisitArray as $visit) { |
||
| 170 | if ($visit->reviewStatus == Visit::REVIEW_DONE) { |
||
| 171 | $qcDate=new DateTimeImmutable($visit->controlDate); |
||
| 172 | $conclusionDate=new DateTimeImmutable($visit->reviewConclusionDate); |
||
| 173 | $conclusionDelay=($conclusionDate->getTimestamp()-$qcDate->getTimestamp())/(3600*24); |
||
| 174 | |||
| 175 | $responseConclusionArrayDetails['idVisit']=$visit->id_visit; |
||
| 176 | $responseConclusionArrayDetails['conclusionDelay']=$conclusionDelay; |
||
| 177 | |||
| 178 | $responseDelayArray[]=$responseConclusionArrayDetails; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | return $responseDelayArray; |
||
| 183 | |||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Return all review status for each visit |
||
| 188 | * @return array |
||
| 189 | */ |
||
| 190 | public function getReviewStatus() { |
||
| 191 | |||
| 192 | $uploadedVisitArray=$this->studyVisitManager->getUploadedVisits(); |
||
| 193 | |||
| 194 | $responseReviewArray=[]; |
||
| 195 | |||
| 196 | foreach ($uploadedVisitArray as $visit) { |
||
| 197 | $responseReviewArrayElement=[]; |
||
| 198 | if ($visit->statusDone == Visit::DONE) { |
||
| 199 | $responseReviewArrayElement['status']=$visit->reviewStatus; |
||
| 200 | if ($visit->reviewStatus == Visit::DONE) { |
||
| 201 | $responseReviewArrayElement['visitType']=$visit->visitType; |
||
| 202 | $responseReviewArrayElement['conclusionValue']=$visit->reviewConclusion; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | $responseReviewArray[]=$responseReviewArrayElement; |
||
| 206 | } |
||
| 207 | |||
| 208 | return $responseReviewArray; |
||
| 209 | |||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Return array of each visit's QC status |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getQcStatus() { |
||
| 241 | |||
| 242 | } |
||
| 243 | |||
| 244 | |||
| 245 | /** |
||
| 246 | * Return array of delay between injection time and acquisition time. |
||
| 247 | * Will only return the first PET series found for each visit |
||
| 248 | * @return array|number |
||
| 249 | */ |
||
| 250 | public function getAcquisitionPetDelay() { |
||
| 283 | |||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Return specific data of all reviews |
||
| 288 | * @return array[] |
||
| 289 | */ |
||
| 290 | public function getReviewData() { |
||
| 340 | } |
||
| 341 | |||
| 344 |