2015-12-10 09:47:30 +00:00
|
|
|
<?php
|
2015-12-23 16:50:25 +00:00
|
|
|
function customCompression($input, $compression){
|
|
|
|
if( $compression ) return strtr(base64_encode(addslashes(gzcompress(serialize($input),9))), '+/=', '-_,');
|
|
|
|
else return unserialize(gzuncompress(stripslashes(base64_decode(strtr($input, '-_,', '+/=')))));
|
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: seekdasky
|
|
|
|
* Date: 10/12/15
|
|
|
|
* Time: 09:16
|
|
|
|
*/
|
|
|
|
class Patient
|
|
|
|
{
|
|
|
|
public function add($params){
|
2015-12-26 10:42:52 +00:00
|
|
|
if( StaticRepo::checkParam($params['date_naissance'], 'Date') ){
|
|
|
|
$params['num_secu'] = str_replace(' ', '', $params['num_secu']);
|
2015-12-15 08:24:20 +00:00
|
|
|
$params['date_naissance'] = DateTime::createFromFormat('d/m/Y', $params['date_naissance']);
|
2015-12-26 10:42:52 +00:00
|
|
|
if( PatientRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom']),$params['adresse'],$params['adresse2'],$params['ville'],$params['code_postal'],
|
2015-12-15 08:24:20 +00:00
|
|
|
$params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !== FALSE){
|
2015-12-22 18:35:35 +00:00
|
|
|
$_status = 'success';
|
|
|
|
$_title = 'Création effectuée!';
|
|
|
|
$_message = 'Le patient <strong>'.$params['prenom'].' '.$params['nom'].'</strong> a bien été créé.';
|
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
|
|
else{
|
2015-12-15 08:24:20 +00:00
|
|
|
$response = new Response();
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
2015-12-15 08:24:20 +00:00
|
|
|
$response->send();
|
2015-12-17 08:53:09 +00:00
|
|
|
}
|
|
|
|
}else{
|
2015-12-22 18:35:35 +00:00
|
|
|
$_status = 'error';
|
|
|
|
$_title = 'Erreur de création!';
|
|
|
|
$_message = 'Certains champs étaient incorrects. Réessayez!';
|
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
|
|
else{
|
2015-12-17 08:53:09 +00:00
|
|
|
$response = new Response();
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
2015-12-17 08:53:09 +00:00
|
|
|
$response->send();
|
2015-12-15 08:24:20 +00:00
|
|
|
}
|
2015-12-22 18:35:35 +00:00
|
|
|
|
2015-12-15 08:24:20 +00:00
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}else{
|
2015-12-22 18:35:35 +00:00
|
|
|
$_status = 'error';
|
|
|
|
$_title = 'Erreur de création!';
|
|
|
|
$_message = 'Le format de la date est incorrect. Réessayez!';
|
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
|
|
else{
|
2015-12-17 08:53:09 +00:00
|
|
|
$response = new Response();
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
2015-12-17 08:53:09 +00:00
|
|
|
$response->send();
|
2015-12-15 08:24:20 +00:00
|
|
|
}
|
2015-12-22 18:35:35 +00:00
|
|
|
|
2015-12-10 09:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-22 23:04:57 +00:00
|
|
|
public function search($params){
|
|
|
|
|
|
|
|
/* RECHERCHE REUSSIE */
|
|
|
|
if( ($patList=PatientRepo::search(strtolower($params['nom']), strtolower($params['prenom']))) !== FALSE ){
|
|
|
|
$_status = 'success';
|
|
|
|
$_title = 'Recherche effectuée!';
|
|
|
|
$_message = '<strong>'.count($patList).'</strong> patient(s) trouvé(s)!';
|
|
|
|
$_patients = $patList;
|
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message, 'patients' => $_patients ]));
|
|
|
|
else{
|
|
|
|
$response = new Response();
|
2015-12-23 16:50:25 +00:00
|
|
|
// $response->write("patients=".$compressed_json);
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message.'&patients='.customCompression( json_encode($_patients), true));
|
2015-12-22 23:04:57 +00:00
|
|
|
$response->send();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$_status = 'error';
|
|
|
|
$_title = 'Erreur lors de la recherche!';
|
|
|
|
$_message = 'Certains champs étaient incorrects. Réessayez!';
|
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
|
|
else{
|
|
|
|
$response = new Response();
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
2015-12-22 23:04:57 +00:00
|
|
|
$response->send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 09:47:30 +00:00
|
|
|
public function update($params){
|
2016-01-03 17:43:41 +00:00
|
|
|
if( isset($params['id_patient'])
|
|
|
|
&& isset($params['civilite'])
|
|
|
|
&& isset($params['prenom'])
|
|
|
|
&& isset($params['nom'])
|
|
|
|
&& isset($params['adresse'])
|
|
|
|
&& isset($params['adresse2'])
|
|
|
|
&& isset($params['ville'])
|
|
|
|
&& isset($params['code_postal'])
|
|
|
|
&& isset($params['date_naissance'])
|
|
|
|
&& isset($params['lieu_naissance'])
|
|
|
|
&& isset($params['num_secu'])
|
|
|
|
&& isset($params['id_medecin']) ){
|
|
|
|
|
|
|
|
if( PatientRepo::update($params['id_patient'],
|
|
|
|
$params['civilite'],
|
|
|
|
strtolower($params['prenom']),
|
|
|
|
strtoupper($params['nom']),
|
|
|
|
$params['adresse'],
|
|
|
|
$params['adresse2'],
|
|
|
|
$params['ville'],
|
|
|
|
$params['code_postal'],
|
|
|
|
$params['date_naissance'],
|
|
|
|
$params['lieu_naissance'],
|
|
|
|
$params['num_secu'],
|
|
|
|
$params['id_medecin']) !== FALSE ){
|
2015-12-22 18:35:35 +00:00
|
|
|
|
2016-01-03 17:43:41 +00:00
|
|
|
$_status = 'success';
|
|
|
|
$_title = 'Modification effectuée!';
|
2015-12-22 18:35:35 +00:00
|
|
|
$_message = 'Le patient <strong>'.$params['prenom'].' '.$params['nom'].'</strong> a bien été modifié.';
|
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
|
|
else{
|
2015-12-15 08:24:20 +00:00
|
|
|
$response = new Response();
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
2015-12-15 08:24:20 +00:00
|
|
|
$response->send();
|
2015-12-17 08:53:09 +00:00
|
|
|
}
|
2015-12-22 18:35:35 +00:00
|
|
|
|
2015-12-17 08:53:09 +00:00
|
|
|
}else{
|
2015-12-22 18:35:35 +00:00
|
|
|
$_status = 'error';
|
|
|
|
$_title = 'Erreur de modification!';
|
|
|
|
$_message = 'Certains champs étaient incorrects. Réessayez!';
|
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
|
|
else{
|
2015-12-17 08:53:09 +00:00
|
|
|
$response = new Response();
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
2015-12-17 08:53:09 +00:00
|
|
|
$response->send();
|
2015-12-15 08:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}else{
|
2015-12-22 18:35:35 +00:00
|
|
|
$_status = 'error';
|
2016-01-03 17:43:41 +00:00
|
|
|
$_title = 'Erreur de paramètres!';
|
|
|
|
$_message = 'Certains champs sont incorrects. Réessayez!';
|
2015-12-22 18:35:35 +00:00
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
|
|
else{
|
2015-12-17 08:53:09 +00:00
|
|
|
$response = new Response();
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
2015-12-17 08:53:09 +00:00
|
|
|
$response->send();
|
2015-12-15 08:24:20 +00:00
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($params){
|
2015-12-26 10:42:52 +00:00
|
|
|
if( PatientRepo::delete($params['id_patient']) !== FALSE ){
|
2015-12-22 18:35:35 +00:00
|
|
|
|
2015-12-26 10:42:52 +00:00
|
|
|
$_status = 'success';
|
|
|
|
$_title = 'Patient supprimé!';
|
2015-12-22 18:35:35 +00:00
|
|
|
$_message = 'Le patient a bien été supprimé de la base de données!';
|
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
|
|
else{
|
2015-12-15 08:24:20 +00:00
|
|
|
$response = new Response();
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
2015-12-15 08:24:20 +00:00
|
|
|
$response->send();
|
2015-12-17 08:53:09 +00:00
|
|
|
}
|
2015-12-22 18:35:35 +00:00
|
|
|
|
2015-12-17 08:53:09 +00:00
|
|
|
}else{
|
2015-12-26 10:42:52 +00:00
|
|
|
$_status = 'error';
|
|
|
|
$_title = 'Erreur de suppression!';
|
2015-12-22 18:35:35 +00:00
|
|
|
$_message = 'Erreur lors de la suppression. Réessayez!';
|
|
|
|
|
|
|
|
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )
|
|
|
|
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
|
|
|
|
else{
|
2015-12-17 08:53:09 +00:00
|
|
|
$response = new Response();
|
2015-12-26 12:05:56 +00:00
|
|
|
$response->setHeader('Location', 'http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
|
2015-12-17 08:53:09 +00:00
|
|
|
$response->send();
|
2015-12-15 08:24:20 +00:00
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:16:09 +00:00
|
|
|
}
|