getRaportBetweenDatesNative()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 2
eloc 15
nc 2
nop 3
1
<?php
2
3
namespace Hospitalplugin\Entities;
4
5
use Hospitalplugin\DB\DoctrineBootstrap;
6
use Hospitalplugin\utils\Utils;
7
use Doctrine\DBAL\Schema\View;
8
use Doctrine\ORM\Query\ResultSetMapping;
9
10
class PatientRaportOptimized {
11
	/**
12
	 *
13
	 * @param unknown $wardId        	
14
	 * @param unknown $date        	
15
	 */
16
	public static function getRaport($wardId, $date) {
17
		$startDate = $date . '-01';
18
		$endDate = date ( "Y-m-t 23:59:59", strtotime ( $startDate ) );
19
		
20
		return PatientRaportOptimized::getRaportBetweenDatesNative ( $wardId, $startDate, $endDate );
0 ignored issues
show
Documentation introduced by
$startDate is of type string, but the function expects a object<Hospitalplugin\Entities\unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$endDate is of type string, but the function expects a object<Hospitalplugin\Entities\unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
21
	}
22
	private static function updateNativeRaport() {
23
		$em = DoctrineBootstrap::getEntityManager ();
24
		$conn = $em->getConnection ();
25
		// create report table
26
		$sql1 = "CREATE TABLE IF NOT EXISTS kategoria_view 
27
					(data DATETIME, oddzialId INT, kategoria INT, suma INT,
28
					PRIMARY KEY (data,oddzialId,kategoria));";
29
		// update view
30
		$sql2 = "INSERT INTO kategoria_view 
31
					SELECT 
32
						date( dataKategoryzacji ), 
33
						oddzialId, 
34
						kategoriaPacjenta, 
35
						count( kategoriaPacjenta )
36
				FROM 
37
					Patient p 
38
				WHERE
39
					dataKategoryzacji 
40
						BETWEEN 
41
							(IFNULL((SELECT 
42
										DATE_ADD(MAX(data), INTERVAL 1 day )
43
									FROM kategoria_view),
44
								'2014-06-01')) 
45
						AND
46
							DATE_ADD( CURDATE( ) , INTERVAL -1 day ) 
47
				GROUP BY 
48
					oddzialId, 
49
					date( dataKategoryzacji ) , 
50
					kategoriaPacjenta";
51
		// select
52
		try {
53
			$conn->query ( $sql1 );
54
			$conn->query ( $sql2 );
55
		} catch ( Exception $e ) {
0 ignored issues
show
Bug introduced by
The class Hospitalplugin\Entities\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
56
			// echo 'Caught exception: ', $e->getMessage(), "\n";
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
57
		}
58
	}
59
	/**
60
	 * 
61
	 * @param unknown $wardId
62
	 * @param unknown $startDate
63
	 * @param unknown $endDate
64
	 */
65
	public static function getRaportBetweenDatesNative($wardId, $startDate, $endDate) {
66
		$em = DoctrineBootstrap::getEntityManager ();
67
		PatientRaportOptimized::updateNativeRaport();
68
		$conn = $em->getConnection ();
69
		$sql3 = "SELECT kategoria, date(data) as data, suma FROM kategoria_view WHERE data between :data1 AND :data2 and oddzialId = :oddzialId";
70
		$stmt = $conn->prepare ( $sql3 );
71
		$stmt->execute ( array (
72
				'data1' => $startDate,
73
				'data2' => $endDate,
74
				'oddzialId' => $wardId 
75
		) );
76
		$result = $stmt->fetchAll();
77
		$table = array ();
78
		foreach ( $result as $row ) {
79
			$table [$row ['data']] [$row ['kategoria']] = $row ['suma'];
80
		}
81
		return $table;
82
	}
83
	
84
}