private function findLegalSessionsFromLegalFolderIdOrderedByDateDesc($legalFolderId) { return LegalSession::where('legal_folder_id', '=', $legalFolderId)->orderBy('legal_date', 'desc')->get(); }
public function getFoldersUsageHistory($benefiter_id) { $usageHistory = []; // find the benefiter from id $benefiter = Benefiter::find($benefiter_id); // fetch from basic folder history $basicFolderHistory = BasicFolderHistory::where('benefiter_id', '=', $benefiter_id)->get(); // fetch from medical visit $medicalVisitsHistory = medical_visits::where('benefiter_id', '=', $benefiter_id)->get(); // fetch from legal folder $legalFolderService = new LegalFolderService(); $legalFolder = $legalFolderService->findLegalFolderFromBenefiterId($benefiter_id); $legalFolderHistory = null; if ($legalFolder != null) { $legalFolderHistory = LegalSession::where('legal_folder_id', '=', $legalFolder->id)->get(); } // fetch from psychosocial folder $socialFolderService = new SocialFolderService(); $psychosocialHistory = PsychosocialSession::where('social_folder_id', '=', $socialFolderService->getSocialFolderFromBenefiterId($benefiter_id)->id)->get(); // fetch all users from DB $users = User::get()->toArray(); // fetch all locations from DB $locations = medical_location_lookup::get()->toArray(); // fetch all user roles and subroles $roles = Users_roles::get()->toArray(); $subroles = Users_subroles::get()->toArray(); // check if there are some users and locations in the DB, else return an empty array if (!empty($users) and !empty($locations) and $benefiter != null) { // push all basic folder history to the usageHistory array as AllFoldersUsageHistory objects if (!empty($basicFolderHistory)) { $this->pushAllBasicInfoFolderHistoryToUsageHistoryArray($basicFolderHistory, $benefiter, $roles, $users, $locations, $usageHistory); } // push all medical visits history to the usageHistory array as AllFoldersUsageHistory objects if (!empty($medicalVisitsHistory)) { $this->pushAllMedicalVisitsHistoryToUsageHistoryArray($medicalVisitsHistory, $benefiter, $roles, $subroles, $users, $locations, $usageHistory); } // push all legal folder history to the usageHistory array as AllFoldersUsageHistory objects if (!empty($legalFolderHistory)) { $this->pushAllLegalFolderHistoryToUsageHistoryArray($legalFolderHistory, $benefiter, $roles, $users, $locations, $usageHistory); } // push all psychosocial sessions history to the usageHistory array as AllFoldersUsageHistory objects if (!empty($psychosocialHistory)) { $this->pushAllPsychosocialFolderHistoryToUsageHistoryArray($psychosocialHistory, $benefiter, $roles, $users, $locations, $usageHistory); } // order usageHistory array by date usort($usageHistory, array($this, "orderUsageHistoryArrayByDate")); } return $usageHistory; }