app/Http/Controllers/UtilityController.php
/**
     * Calculates the statistics of a clinic.
     * In order to calculate stats, at least one patient have to be registered
     *
     * @param $clinic
     * @return array
     */
Calculates the statistics of a clinic.
In order to calculate stats, at least one patient have to be registered

@param $clinic
@return array
Calculates the statistics of a clinic . In order to calculate stats at least one patient have to be registered @param $clinic @return array
private function calcClinicStats($clinic) {
        $stats = [
            'visits' => [
                'm' => [],
                'c' => []
            ]
        ];
        $date       = date('Y-m-d H:i:s', strtotime("-6 months"));
        $patientIds = [];
        if (count($patientIds) > 0) {
            $patientIds = implode(",", $patientIds);
            $query      = "SELECT MONTH(created_at) AS m,COUNT(*) AS c FROM `prescriptions` WHERE `patient_id`
                    IN (" . $patientIds . ") AND `created_at` > :d GROUP BY MONTH(created_at)";
            $pdo        = DB::connection()->getPdo();
            $statement  = $pdo->prepare($query);
            $statement->bindParam('d', $date, \PDO::PARAM_STR);
            $statement->execute();
            $visits = $statement->fetchAll();
            foreach ($visits as $result) {
                $dateObj                = \DateTime::createFromFormat('!m', $result['m']);
                $stats['visits']['m'][] = $dateObj->format('F');
                $stats['visits']['c'][] = $result['c'];
            }
        }
        return $stats;
    }
private function calcClinicStats ( $ clinic ) { $ stats = [ 'visits' => [ 'm' => [ ] , 'c' => [ ] ] ] ; $ date = date ( 'Y-m-d H:i:s' , strtotime ( " -6 months " ) ) ; $ patientIds = [ ] ; if ( count ( $ patientIds ) > 0 ) { $ patientIds = implode ( " , " , $ patientIds ) ; $ query = " SELECT MONTH(created_at) AS m,COUNT(*) AS c FROM `prescriptions` WHERE `patient_id`
                    IN ( " . $ patientIds . " ) AND `created_at` > :d GROUP BY MONTH(created_at) " ; $ pdo = DB :: connection ( ) -> getPdo ( ) ; $ statement = $ pdo -> prepare ( $ query ) ; $ statement -> bindParam ( 'd' , $ date , \ PDO :: PARAM_STR ) ; $ statement -> execute ( ) ; $ visits = $ statement -> fetchAll ( ) ; foreach ( $ visits as $ result ) { $ dateObj = \ DateTime :: createFromFormat ( '!m' , $ result [ 'm' ] ) ; $ stats [ 'visits' ] [ 'm' ] [ ] = $ dateObj -> format ( 'F' ) ; $ stats [ 'visits' ] [ 'c' ] [ ] = $ result [ 'c' ] ; } } return $ stats ; }
Calculates the statistics of a clinic.
Calculates the statistics of a clinic .
//        $patientIds = $clinic->patients()->lists('id')->toArray();