|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PatientCRUD |
|
5
|
|
|
* |
|
6
|
|
|
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
|
7
|
|
|
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
|
8
|
|
|
* |
|
9
|
|
|
* Permission is hereby granted to use or copy this program |
|
10
|
|
|
* for any purpose, provided the above notices are retained on all copies. |
|
11
|
|
|
* Permission to modify the code and to distribute modified code is granted, |
|
12
|
|
|
* provided the above notices are retained, and a notice that the code was |
|
13
|
|
|
* modified is included with the above copyright notice. |
|
14
|
|
|
* |
|
15
|
|
|
* @category Wp |
|
16
|
|
|
* @package Punction |
|
17
|
|
|
* @author Andrzej Marcinkowski <[email protected]> |
|
18
|
|
|
* @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz |
|
19
|
|
|
* @license MIT http://opensource.org/licenses/MIT |
|
20
|
|
|
* @version 1.0 $Format:%H$ |
|
21
|
|
|
* @link http:// |
|
22
|
|
|
* @since File available since Release 1.0.0 |
|
23
|
|
|
* PHP Version 5 |
|
24
|
|
|
*/ |
|
25
|
|
|
namespace Hospitalplugin\Entities; |
|
26
|
|
|
|
|
27
|
|
|
use Hospitalplugin\DB\DoctrineBootstrap; |
|
28
|
|
|
use Hospitalplugin\Entities\Patient; |
|
29
|
|
|
use Hospitalplugin\Entities\PatientDeleted; |
|
30
|
|
|
use Hospitalplugin\Entities\PatientFactory; |
|
31
|
|
|
use Hospitalplugin\utils\Utils; |
|
32
|
|
|
|
|
33
|
|
|
class PatientCRUD { |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* getPatients |
|
37
|
|
|
* |
|
38
|
|
|
* @param int $day |
|
39
|
|
|
* dayOfTheMonth |
|
40
|
|
|
* @param int $month |
|
41
|
|
|
* month |
|
42
|
|
|
* |
|
43
|
|
|
* @return Patient array |
|
44
|
|
|
*/ |
|
45
|
|
|
public static function getPatients($month = null, $day = null, $wardId = 0) { |
|
46
|
|
|
return PatientCRUD::getPatientsDateRange ( Utils::getStartDate ( $month, $day ), Utils::getEndDate ( $month, $day ), $wardId ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* getPatientsDateRange |
|
51
|
|
|
* |
|
52
|
|
|
* TODO(AM) testy na przypadki graniczne - pacjenci z data przed polnoca, po polnocy, godzina przed obecna, po obecnej |
|
53
|
|
|
* |
|
54
|
|
|
* @param int $day |
|
|
|
|
|
|
55
|
|
|
* dayOfTheMonth |
|
56
|
|
|
* @param int $month |
|
|
|
|
|
|
57
|
|
|
* month |
|
58
|
|
|
* |
|
59
|
|
|
* @return Patient array |
|
60
|
|
|
*/ |
|
61
|
|
|
public static function getPatientsDateRange($date1, $date2, $wardId = 0) { |
|
62
|
|
|
$entityManager = ( object ) DoctrineBootstrap::getEntityManager (); |
|
63
|
|
|
$params = array ( |
|
64
|
|
|
'from' => $date1, |
|
65
|
|
|
'to' => $date2, |
|
66
|
|
|
'oddzialId' => $wardId |
|
67
|
|
|
); |
|
68
|
|
|
$q = $entityManager->createQuery ( 'select p FROM Hospitalplugin\Entities\Patient p WHERE p.dataKategoryzacji BETWEEN :from AND :to and p.oddzialId = :oddzialId ORDER BY p.name' )->setParameters ( $params )->setFirstResult ( 0 )->setMaxResults ( 1000 ); |
|
69
|
|
|
$patients = $q->getResult (); |
|
70
|
|
|
return $patients; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* getPatient |
|
75
|
|
|
* |
|
76
|
|
|
* @param $id $id |
|
|
|
|
|
|
77
|
|
|
* int |
|
78
|
|
|
* |
|
79
|
|
|
* @return Patient Patient |
|
80
|
|
|
*/ |
|
81
|
|
|
public static function getPatient($id, $type = '') { |
|
82
|
|
|
$entityManager = ( object ) DoctrineBootstrap::getEntityManager (); |
|
83
|
|
|
$type = 'Hospitalplugin\Entities\Patient' . $type; |
|
84
|
|
|
$patient = $entityManager->getRepository ( $type )->findOneBy ( array ( |
|
85
|
|
|
'id' => $id |
|
86
|
|
|
) ); |
|
87
|
|
|
return Utils::cast ( $type, ( object ) $patient, 0 ); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* setPatientCategories |
|
92
|
|
|
* |
|
93
|
|
|
* @param Patient $obj |
|
94
|
|
|
* |
|
95
|
|
|
* @return Patient |
|
96
|
|
|
*/ |
|
97
|
|
|
public static function setPatientCategories($obj, $type) { |
|
98
|
|
|
$entityManager = DoctrineBootstrap::getEntityManager (); |
|
99
|
|
|
$patient = PatientCRUD::getPatient ( $obj->id, $type ); |
|
100
|
|
|
foreach ( get_object_vars ( $obj ) as $key => $value ) { |
|
101
|
|
|
call_user_func ( array ( |
|
102
|
|
|
$patient, |
|
103
|
|
|
'set' . ucwords ( $key ) |
|
104
|
|
|
), $value ); |
|
105
|
|
|
} |
|
106
|
|
|
$entityManager->merge ( $patient ); |
|
107
|
|
|
$entityManager->flush (); |
|
108
|
|
|
return $patient; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* setPatientCategories |
|
113
|
|
|
* |
|
114
|
|
|
* @param Patient $obj |
|
|
|
|
|
|
115
|
|
|
* |
|
116
|
|
|
* @return Patient |
|
117
|
|
|
*/ |
|
118
|
|
|
public static function createPatient($type, $name, $pesel) { |
|
119
|
|
|
$entityManager = DoctrineBootstrap::getEntityManager (); |
|
120
|
|
|
$type = 'Hospitalplugin\Entities\Patient' . $type; |
|
121
|
|
|
$patient = new $type (); |
|
122
|
|
|
$patient->setName ( $name ); |
|
123
|
|
|
$patient->setPesel ( $pesel ); |
|
124
|
|
|
$entityManager->persist ( $patient ); |
|
125
|
|
|
$entityManager->flush (); |
|
126
|
|
|
return $patient; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* deletePatient |
|
131
|
|
|
* |
|
132
|
|
|
* @param $id $id |
|
|
|
|
|
|
133
|
|
|
* int |
|
134
|
|
|
*/ |
|
135
|
|
|
public static function deletePatient($id, $userId = 0) { |
|
136
|
|
|
$entityManager = ( object ) DoctrineBootstrap::getEntityManager (); |
|
137
|
|
|
$type = 'Hospitalplugin\Entities\Patient'; |
|
138
|
|
|
$patient = $entityManager->getRepository ( $type )->findOneBy ( array ( |
|
139
|
|
|
'id' => $id |
|
140
|
|
|
) ); |
|
141
|
|
|
$entityManager->remove ( $patient ); |
|
142
|
|
|
$log = strval($patient); |
|
143
|
|
|
$audit = new PatientDeleted(); |
|
144
|
|
|
$audit->deletedAt = new \DateTime (); |
|
145
|
|
|
$audit->deletedByUserId = $userId; |
|
146
|
|
|
$audit->log = $log; |
|
147
|
|
|
$entityManager->persist ( $audit ); |
|
148
|
|
|
$entityManager->flush (); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
?> |
|
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.