2015-12-10 09:47:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: seekdasky
|
|
|
|
* Date: 10/12/15
|
|
|
|
* Time: 09:16
|
|
|
|
*/
|
|
|
|
class Patient
|
|
|
|
{
|
|
|
|
public function add($params){
|
2015-12-15 08:24:20 +00:00
|
|
|
if(StaticRepo::checkParam($params['date_naissance'],'Date')){
|
|
|
|
$params['num_secu'] = str_replace(' ','',$params['num_secu']);
|
|
|
|
$params['date_naissance'] = DateTime::createFromFormat('d/m/Y', $params['date_naissance']);
|
|
|
|
if(PatientRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom']),$params['adresse'],$params['adresse2'],$params['ville'],$params['code_postal'],
|
|
|
|
$params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !== FALSE){
|
|
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
|
|
|
|
$response = new Response();
|
|
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=creation");
|
|
|
|
$response->send();
|
|
|
|
}else{
|
|
|
|
Response::quickResponse(200, json_encode([
|
|
|
|
'status' => 'success',
|
|
|
|
'title' => 'Création effectuée!',
|
|
|
|
'message' => 'Le patient '.$params['prenom'].' '.$params['nom'].' a bien été créé.'
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
|
|
|
|
$response = new Response();
|
|
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
|
|
|
|
$response->send();
|
|
|
|
}else{
|
|
|
|
Response::quickResponse(200, json_encode([
|
|
|
|
'status' => 'error',
|
|
|
|
'title' => 'Erreur de création!'
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}else{
|
2015-12-15 08:24:20 +00:00
|
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
|
|
|
|
$response = new Response();
|
|
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
|
|
|
|
$response->send();
|
|
|
|
}else{
|
|
|
|
Response::quickResponse(200, json_encode([
|
|
|
|
'status' => 'error',
|
|
|
|
'title' => 'Erreur de paramètre',
|
|
|
|
'message' => 'Date incorrecte'
|
|
|
|
]));
|
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update($params){
|
2015-12-15 08:24:20 +00:00
|
|
|
if(StaticRepo::checkParam($params['date_naissance'],'Date')){
|
|
|
|
$params['num_secu'] = str_replace(' ','',$params['num_secu']);
|
|
|
|
$params['date_naissance'] = DateTime::createFromFormat('d/m/Y', $params['date_naissance']);
|
|
|
|
if(PatientRepo::update($params['id_patient'],$params['civilite'],strtolower($params['prenom']),strtolower($params['nom']),$params['adresse'],$params['adresse2'],$params['ville'],$params['cope_postal'],
|
|
|
|
$params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !==FALSE){
|
|
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
|
|
|
|
$response = new Response();
|
|
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=maj");
|
|
|
|
$response->send();
|
|
|
|
}else{
|
|
|
|
Response::quickResponse(200, json_encode([
|
|
|
|
'status' => 'success',
|
|
|
|
'title' => 'Modification effectuée!',
|
|
|
|
'message' => 'Le patient '.$params['prenom'].' '.$params['nom'].' a bien été modifié.'
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
|
|
|
|
$response = new Response();
|
|
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
|
|
|
|
$response->send();
|
|
|
|
}else{
|
|
|
|
Response::quickResponse(200, json_encode([
|
|
|
|
'status' => 'error',
|
|
|
|
'title' => 'Erreur de création!'
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}else{
|
2015-12-15 08:24:20 +00:00
|
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
|
|
|
|
$response = new Response();
|
|
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
|
|
|
|
$response->send();
|
|
|
|
}else{
|
|
|
|
Response::quickResponse(200, json_encode([
|
|
|
|
'status' => 'error',
|
|
|
|
'title' => 'Erreur de paramètre',
|
|
|
|
'message' => 'Date incorrecte'
|
|
|
|
]));
|
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($params){
|
|
|
|
if(PatientRepo::delete($params['id_patient']) !==FALSE){
|
2015-12-15 08:24:20 +00:00
|
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
|
|
|
|
$response = new Response();
|
|
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=supression");
|
|
|
|
$response->send();
|
|
|
|
}else{
|
|
|
|
Response::quickResponse(200, json_encode([
|
|
|
|
'status' => 'success',
|
|
|
|
'title' => 'Supression effectuée!',
|
|
|
|
'message' => 'Le patient a bien été supprimé.'
|
|
|
|
]));
|
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}else{
|
2015-12-15 08:24:20 +00:00
|
|
|
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
|
|
|
|
$response = new Response();
|
|
|
|
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
|
|
|
|
$response->send();
|
|
|
|
}else{
|
|
|
|
Response::quickResponse(200, json_encode([
|
|
|
|
'status' => 'error',
|
|
|
|
'title' => 'Erreur lors de la supression!'
|
|
|
|
]));
|
|
|
|
}
|
2015-12-10 09:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:16:09 +00:00
|
|
|
}
|