|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hospitalplugin\utils; |
|
4
|
|
|
|
|
5
|
|
|
use Hospitalplugin\Entities\InfectionsCRUD; |
|
6
|
|
|
use Hospitalplugin\Entities\Infections; |
|
7
|
|
|
use Hospitalplugin\Entities\PatientRaport; |
|
8
|
|
|
use Hospitalplugin\Entities\WardCRUD; |
|
9
|
|
|
|
|
10
|
|
|
class ExcelExportPunction { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* |
|
14
|
|
|
* @param unknown $id |
|
15
|
|
|
*/ |
|
16
|
|
|
private static function getData($id, $type) { |
|
17
|
|
|
$raport = PatientRaport::getRaportBetweenDates ( $id, $type, '2014-06-01', (new \DateTime ())->format ( "Y-m-d" ) ); |
|
|
|
|
|
|
18
|
|
|
return $raport; |
|
19
|
|
|
} |
|
20
|
|
|
/** |
|
21
|
|
|
* |
|
22
|
|
|
* @param unknown $objPHPExcel |
|
23
|
|
|
* @param unknown $cols |
|
24
|
|
|
*/ |
|
25
|
|
|
private static function printHeaders($objPHPExcel, $cols) { |
|
26
|
|
|
$count = 1; |
|
27
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 0, 2, "Data" ); |
|
28
|
|
|
foreach ( $cols as $col ) { |
|
29
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( $count ++, 2, sprintf ( "%7s", $col ) ); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
/** |
|
33
|
|
|
*/ |
|
34
|
|
|
private static function printData($objPHPExcel, $data, $type) { |
|
35
|
|
|
$row = 3; |
|
36
|
|
|
$lastColumn = 1; |
|
37
|
|
|
$colNumberOfPatients = ExcelExport::getColumnLetter ( 1 ); |
|
38
|
|
|
$indexes = PatientRaport::getIndexes ( $type ); |
|
39
|
|
|
foreach ( $data as $rowKey => $rowValue ) { |
|
40
|
|
|
// 1 col: date |
|
41
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 0, $row, json_encode ( $rowKey ) ); |
|
42
|
|
|
$count = 1; |
|
43
|
|
|
// 2-5 cols: N1 N2 N3 N0 |
|
44
|
|
|
foreach ( $indexes as $index ) { |
|
45
|
|
|
$value = isset ( $rowValue [$index] ) ? $rowValue [$index] : "0"; |
|
46
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( $count ++, $row, $value ); |
|
47
|
|
|
} |
|
48
|
|
|
// 6 col: num of categorized (N = N1+N2+N3) |
|
49
|
|
|
$colHighestCategory = ExcelExport::getColumnLetter ( $count - 2 ); |
|
50
|
|
|
$colNumberOfPatients = ExcelExport::getColumnLetter ( $count ); |
|
51
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( $count ++, $row, '=SUM(B' . $row . ':' . $colHighestCategory . $row . ')' ); |
|
52
|
|
|
$tpb = PatientRaport::getTpb ( $type ); |
|
53
|
|
|
// 7-11 tpb1, tpb2, tpb3, 0 (no-cat), 2 (add) |
|
|
|
|
|
|
54
|
|
|
foreach ( $tpb as $tpbn ) { |
|
|
|
|
|
|
55
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( $count ++, $row, $tpbn ); |
|
56
|
|
|
} |
|
57
|
|
|
// 9-11: Tpb1*N1,Tpb2*N2,Tpb3*N3+2xN |
|
58
|
|
|
$tpbSize = count ( $tpb ); |
|
59
|
|
|
foreach ( $tpb as $tpbn ) { |
|
|
|
|
|
|
60
|
|
|
$col1Letter = ExcelExport::getColumnLetter ( $count - 2 * $tpbSize ); |
|
61
|
|
|
$col2Letter = ExcelExport::getColumnLetter ( $count - $tpbSize ); |
|
62
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( $count ++, $row, '=' . $col1Letter . $row . "*" . $col2Letter . $row ); |
|
63
|
|
|
} |
|
64
|
|
|
// SUM Tpb |
|
65
|
|
|
$col3Letter = ExcelExport::getColumnLetter ( $count - $tpbSize ); |
|
66
|
|
|
$col4Letter = ExcelExport::getColumnLetter ( $count - 1 ); |
|
67
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( $count ++, $row, '=SUM(' . $col3Letter . $row . ":" . $col4Letter . $row . ")" ); |
|
68
|
|
|
$row ++; |
|
69
|
|
|
$lastColumn = $count - 1; |
|
70
|
|
|
} |
|
71
|
|
|
// number of categorization days |
|
72
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 1, 1, '=COUNTIFS(' . $colNumberOfPatients . '3:' . $colNumberOfPatients . ($row - 1) . ',">0")' ); |
|
73
|
|
|
// sum |
|
74
|
|
|
$col5Letter = ExcelExport::getColumnLetter ( $lastColumn ); |
|
75
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 2, 1, '=SUM(' . $col5Letter . '3:' . $col5Letter . ($row - 1) . ')/60' ); |
|
76
|
|
|
return $row; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* |
|
81
|
|
|
* @param unknown $objPHPExcel |
|
82
|
|
|
*/ |
|
83
|
|
|
static function fillSummary($objPHPExcel) { |
|
|
|
|
|
|
84
|
|
|
ExcelExport::newSheet ( $objPHPExcel, 0 ); |
|
85
|
|
|
ExcelExport::printTitle ( $objPHPExcel, "Raport" ); |
|
|
|
|
|
|
86
|
|
|
$sheetCount = $objPHPExcel->getSheetCount (); |
|
87
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'A2', 'Oddz.' ); |
|
88
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'B2', 'Dni' ); |
|
89
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'C2', 'Tpb' ); |
|
90
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'D2', 'Tśpb' ); |
|
91
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'E2', 'Tśpc*' ); |
|
92
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'F2', 'Tśpc**' ); |
|
93
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'G2', 'Td***' ); |
|
94
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'H2', 'Le*' ); |
|
95
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'I2', 'Le**' ); |
|
96
|
|
|
for($i = 1; $i < $sheetCount; $i ++) { |
|
97
|
|
|
$loadedSheetNames = $objPHPExcel->getSheetNames (); |
|
98
|
|
|
foreach ( $loadedSheetNames as $sheetIndex => $loadedSheetName ) { |
|
99
|
|
|
if ($sheetIndex == 0) { |
|
100
|
|
|
continue; |
|
101
|
|
|
} |
|
102
|
|
|
$row = $sheetIndex + 2; |
|
103
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'A' . $row, "='" . $loadedSheetName . "'!A1" ); |
|
104
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'B' . $row, "='" . $loadedSheetName . "'!B1" ); |
|
105
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValue ( 'C' . $row, "='" . $loadedSheetName . "'!C1" ); |
|
106
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 3, $row, "=IF(C" . $row . ">0,C" . $row . "/B" . $row . ",0)" ); |
|
107
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 4, $row, "=D" . $row . "*110%" ); |
|
108
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 5, $row, "=D" . $row . "*125%" ); |
|
109
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 6, $row, "1531" ); |
|
110
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 7, $row, "=IF(E" . $row . ">0,E" . $row . "*365/G" . $row . ",\"-\")" ); |
|
111
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 8, $row, "=IF(F" . $row . ">0,F" . $row . "*365/G" . $row . ",\"-\")" ); |
|
112
|
|
|
} |
|
113
|
|
|
$objPHPExcel->getActiveSheet ()->getStyle ( 'C3:I100' )->getNumberFormat ()->setFormatCode ( '#,##0.0' ); |
|
114
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 0, $row + 1, "* Czas pielęgnacji pośredniej jako 10% czasu pielęgnacji bezpośredniej" ); |
|
|
|
|
|
|
115
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 0, $row + 2, "** Czas pielęgnacji pośredniej jako 25% czasu pielęgnacji bezpośredniej" ); |
|
116
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 0, $row + 3, "*** Czas dyspozycyjny - propozycja z Rozporządzenia MZ: 202 dni x 7,58 h" ); |
|
117
|
|
|
ExcelExport::styleActiveSheet ( $objPHPExcel ); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
static function fillData($objPHPExcel) { |
|
|
|
|
|
|
121
|
|
|
// no time limit for this script |
|
122
|
|
|
set_time_limit ( 0 ); |
|
123
|
|
|
$time_start = microtime ( true ); |
|
124
|
|
|
// remove first default sheet |
|
125
|
|
|
$objPHPExcel->removeSheetByIndex ( 0 ); |
|
126
|
|
|
// get wards |
|
127
|
|
|
$wards = WardCRUD::getWardsArray (); |
|
128
|
|
|
foreach ( $wards as $ward ) { |
|
129
|
|
|
ExcelExport::newSheet ( $objPHPExcel ); |
|
130
|
|
|
$wardName = $ward->name . " (" . $ward->getTypOddzialu () . ")"; |
|
131
|
|
|
ExcelExport::printTitle ( $objPHPExcel, $wardName ); |
|
|
|
|
|
|
132
|
|
|
$data = ExcelExportPunction::getData ( $ward->id, $ward->getTypOddzialu () ); |
|
133
|
|
|
$cols = PatientRaport::getColumns ( $ward->getTypOddzialu () ); |
|
134
|
|
|
ExcelExportPunction::printHeaders ( $objPHPExcel, $cols ); |
|
|
|
|
|
|
135
|
|
|
ExcelExportPunction::printData ( $objPHPExcel, $data, $ward->getTypOddzialu () ); |
|
136
|
|
|
ExcelExport::styleActiveSheet ( $objPHPExcel ); |
|
137
|
|
|
} |
|
138
|
|
|
ExcelExportPunction::fillSummary ( $objPHPExcel ); |
|
139
|
|
|
$objPHPExcel->getActiveSheet ()->setCellValueByColumnAndRow ( 0, 100, "summary " . ($time_start - microtime ( true )) . " s" ); |
|
140
|
|
|
} |
|
141
|
|
|
} |
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: