|
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 ); |
|
|
|
|
|
|
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 ) { |
|
|
|
|
|
|
56
|
|
|
// echo 'Caught exception: ', $e->getMessage(), "\n"; |
|
|
|
|
|
|
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
|
|
|
} |
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: