Example #1
0
 public function getReport_medical_visits_vs_date()
 {
     // in order to count the visits per month the only thing we have to do is to fetch all available medical visits
     // and count the medical visit dates with the same month.
     $results = array();
     $months = array();
     // get all medical visits
     $medical_visits = medical_visits::get();
     // for each visit remove the day part of the string (last three characters) and create a new array.
     foreach ($medical_visits as $visit) {
         $time = strtotime($visit['medical_visit_date']);
         $current_month = date('Y-m', $time);
         array_push($months, $current_month);
     }
     // for the new date array count for duplicities and create the necessary data pair.
     $array_duplicities = array_count_values($months);
     foreach ($array_duplicities as $key => $per_month_count) {
         $medical_result = ['per_month_date' => $key, 'visits_per_month' => $per_month_count];
         array_push($results, $medical_result);
     }
     // Order results by date (ascending)
     foreach ($results as $key => $part) {
         $sort[$key] = strtotime($part['per_month_date']);
     }
     array_multisort($sort, SORT_ASC, $results);
     // return array with time_period => number of medical visits
     return $results;
 }
 public function count_medical_visits_for_a_benefiter($id)
 {
     $medical_visits_number = medical_visits::where('benefiter_id', $id)->count();
     return $medical_visits_number;
 }
Example #3
0
 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;
 }