Recherche Patient/Medecin

This commit is contained in:
xdrm-brackets 2015-12-23 00:04:57 +01:00
parent 4c10c45038
commit 3962c7036b
13 changed files with 253 additions and 55 deletions

View File

@ -25,7 +25,7 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<script type='text/javascript' src='js/lib/API.js'></script>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/input-checker.js'></script>
<script type='text/javascript' src='js/lib/input-checker.js'></script>
</head>
<body>
@ -35,7 +35,7 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<div>
<h3>Oups!</h3>
<p>Certains champs sont incorrects. Veuillez réessayer.</p>
<input type='button' value='Fermer'>
<a href='#'><input type='button' value='Fermer'></a>
</div>
</div>

View File

@ -11,7 +11,7 @@ $managerTitle = (isset($_GET['title'])) ? $_GET['title'] : 'Oups!';
$managerMessage = (isset($_GET['message'])) ? $_GET['message'] : 'Erreur interne!';
// on récupère la liste des médecins si donnée
$medecinsSearch = ( isset($_GET['medecins']) ) ? json_decode($_GET['medecins'], true) : [];
$medecinsSearch = ( isset($_GET['medecins']) ) ? json_decode(base64_decode($_GET['medecins']), true) : [];
?>
@ -32,7 +32,7 @@ $medecinsSearch = ( isset($_GET['medecins']) ) ? json_decode($_GET['medecins'],
<script type='text/javascript' src='js/lib/API.js'></script>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/input-checker.js'></script>
<script type='text/javascript' src='js/lib/input-checker.js'></script>
</head>
<body>
@ -42,7 +42,7 @@ $medecinsSearch = ( isset($_GET['medecins']) ) ? json_decode($_GET['medecins'],
<div>
<h3><?php echo $managerTitle; ?></h3>
<p><?php echo $managerMessage; ?></p>
<input type='button' value='Fermer'>
<a href='?medecins=<?php echo base64_encode(json_encode($medecinsSearch)); ?>'><input type='button' value='Fermer'></a>
</div>
</div>
@ -82,7 +82,7 @@ $medecinsSearch = ( isset($_GET['medecins']) ) ? json_decode($_GET['medecins'],
<input type='submit' id='sbCherche' value='Lancer la recherche'>
</form><br>
<h3>Résultats:</h3><br>
<table id='searchResult'>
<table id='searchResultMedecin'>
<?php
// pour chaque médecin

View File

@ -5,8 +5,13 @@ if(!Authentification::checkUser(0)){
die();
};
// formattage $_GET['type']
$answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
/* REPONSE DU MANAGER */
$managerStatus = (isset($_GET['status'])) ? $_GET['status'] : null;
$managerTitle = (isset($_GET['title'])) ? $_GET['title'] : 'Oups!';
$managerMessage = (isset($_GET['message'])) ? $_GET['message'] : 'Erreur interne!';
// on récupère la liste des médecins si donnée
$patientsSearch = ( isset($_GET['patients']) ) ? json_decode(base64_decode($_GET['patients']), true) : [];
?>
@ -27,17 +32,17 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<script type='text/javascript' src='js/lib/API.js'></script>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/input-checker.js'></script>
<script type='text/javascript' src='js/lib/input-checker.js'></script>
</head>
<body>
<!-- BARRE DE NOTIFICATIONS -->
<div id='NOTIFBAR'>
<div id='NOTIFBAR' class='<?php echo ($managerStatus!=null) ? 'active '.$managerStatus : $managerStatus; ?>'>
<div></div>
<div>
<h3>Oups!</h3>
<p>Certains champs sont incorrects. Veuillez réessayer.</p>
<input type='button' value='Fermer'>
<h3><?php echo $managerTitle; ?></h3>
<p><?php echo $managerMessage; ?></p>
<a href='?patients=<?php echo base64_encode(json_encode($patientsSearch)); ?>'><input type='button' value='Fermer'></a>
</div>
</div>
@ -56,25 +61,53 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
</nav>
<!-- CONTAINER DE LA PAGE -->
<section id='CONTAINER'>
<!-- FIL D'ARIANE -->
<div id='BREADCRUMB'><a href='Dashboard.php'>Accueil</a> <a href='Patients.php'>Gestion des Patients</a></a> </div>
<?php if( $answerType != null ){
echo '<span>';
switch($answerType){
case 'creation': echo 'Patient créé.'; break;
case 'error': echo 'Une erreur est survenue.'; break;
default: echo 'rien à déclarer ? Non!'; break;
}
echo '</span>';
}
/*************************************/
<?php/********************************/
/* CONSULTER LES PATIENTS */
/*************************************/ ?>
<article data-title="Rechercher un patient">
<form method='POST' action='managers/'>
<br><h4>Recherche par nom et/ou prénom:</h4>
<input type='text' id='srPrenom' name='prenom' placeholder='Prénom' value=''><br>
<input type='text' id='srNom' name='nom' placeholder='NOM' value=''><br>
<br>
<input type='hidden' name='command' value='Patient:search'>
<input type='submit' id='sbCherche' value='Lancer la recherche'>
</form><br>
<h3>Résultats:</h3><br>
<table id='searchResultPatient'><tbody>
<?php
// pour chaque médecin
foreach($patientsSearch as $PAT){ if( isset($PAT['Civilite']) && isset($PAT['Prenom']) && isset($PAT['Nom']) && isset($PAT['DateNaissance']) && isset($PAT['NumSecuriteSociale'])){
echo '<tr>';
echo '<td>'.(($PAT['Civilite']=='M')?'Monsieur':'Madame').'</td>';
echo '<td>'.$PAT['Prenom'].'</td>';
echo '<td>'.strtoupper($PAT['Nom']).'</td>';
echo '<td>'.$PAT['DateNaissance'].'</td>';
echo '<td>'.$PAT['NumSecuriteSociale'].'</td>';
echo '</tr>';
}}
?>
</tbody></table>
</article>
<?php/********************************/
/* AJOUTER UN PATIENT */
/*************************************/ ?>
<article data-title="Ajouter un patient">

View File

@ -434,6 +434,7 @@ body{
/* border */
border: 1px solid #f09108;
}
#CONTAINER > article[data-title]:before{
@ -732,3 +733,39 @@ input[type=radio]:checked + label:before{
/* TABLEAU DE RESULTAT DE RECHERCHE */
#CONTAINER > article table{
/* position */
width: 100%;
/* border */
border-spacing: 0;
}
#CONTAINER > article table > tbody,
#CONTAINER > article table > tbody > tr{
/* position */
width: 100%;
}
#CONTAINER > article table td{
/* position */
max-width: calc( 100% / 5% );
padding: .5em 0;
/* border */
border-bottom: 1px solid #cacaca;
}
#CONTAINER > article table#searchResultMedecin td{
/* position */
max-width: calc( 100% / 3% );
padding: .5em 0;
/* border */
border-bottom: 1px solid #cacaca;
}

View File

@ -1,5 +1,6 @@
var notifBar = document.getElementById('NOTIFBAR');
notifBar.children[1].children[2].addEventListener('click', function(e){
notifBar.children[1].children[2].addEventListener('click', function(e){
e.preventDefault();
remClass(notifBar, 'active');
}, false);

View File

@ -83,7 +83,7 @@ function notif(pType, pTitle, pMessage){
var pTitle = (arguments.length>1) ? pTitle : null;
var pMessage = (arguments.length>2) ? pMessage : null;
var index = ['error', 'success', 'info'].indexOf(pType)
var index = ['error', 'success', 'info'].indexOf(pType);
if( index == -1 ) return false; // si pType incorrect, on quitte

View File

@ -1,5 +1,6 @@
var notifBar = document.getElementById('NOTIFBAR');
notifBar.children[1].children[2].addEventListener('click', function(e){
notifBar.children[1].children[2].addEventListener('click', function(e){
e.preventDefault();
remClass(notifBar, 'active');
}, false);
@ -128,9 +129,9 @@ sbCherche.addEventListener('click', function(e){
notif(e.status, e.title, e.message);
if( e.hasOwnProperty('medecins') )
displaySearchedMedecins(e.medecins);
displayFoundMedecins(e.medecins);
else
displaySearchedMedecins([]);
displayFoundMedecins([]);
if( e.status == 'success' ) // on vide le formulaire si on a 'success'
sbCreer.parentNode.reset();
@ -147,8 +148,8 @@ sbCherche.addEventListener('click', function(e){
////////////////////////////////////////////
// AFFICHAGE DES MEDECINS DE LA RECHERCHE //
////////////////////////////////////////////
function displaySearchedMedecins(foundMedecins){
var container = document.getElementById('searchResult');
function displayFoundMedecins(foundMedecins){
var container = document.getElementById('searchResultMedecin');
var content = '<table>';
for( var i = 0 ; i < foundMedecins.length ; i++ ){

View File

@ -1,5 +1,6 @@
var notifBar = document.getElementById('NOTIFBAR');
notifBar.children[1].children[2].addEventListener('click', function(e){
notifBar.children[1].children[2].addEventListener('click', function(e){
e.preventDefault();
remClass(notifBar, 'active');
}, false);
@ -160,4 +161,89 @@ sbCreer.addEventListener('click', function(e){
}else{ // sinon on affiche l'erreur
notif('error', 'Oups!', 'Certains champs sont requis ou incorrects.');
}
}, false);
}, false);
/* RECHERCHE DE MEDECINS */
var srPrenom = document.getElementById('srPrenom');
var srNom = document.getElementById('srNom');
var sbCherche = document.getElementById('sbCherche');
//////////////////////////////
// PRENOM & NOM (VARCHAR 45)//
//////////////////////////////
srPrenom.addEventListener('keyup', function(e){ checkVARCHAR(e.target, 1, 45, true); }, false);
srNom.addEventListener('keyup', function(e){ checkVARCHAR(e.target, 1, 45, true); }, false);
//////////////
// SUBMIT() //
//////////////
sbCherche.addEventListener('click', function(e){
e.preventDefault(); // on annule le submit()
var correctNom = srNom.className.indexOf('validated') > -1 && srNom.value.length > 0;
var correctPrenom = srPrenom.className.indexOf('validated') > -1 && srPrenom.value.length > 0;
if( correctPrenom || correctNom ){ // si tout es ok uniquement, on submit()
var request = {
prenom: (correctPrenom) ? srPrenom.value : null,
nom: (correctNom) ? srNom.value : null
};
API.send('Patient:search', request, function(e){
if( e.status != 'success' )
notif(e.status, e.title, e.message);
if( e.hasOwnProperty('patients') )
displayFoundPatients(e.patients);
else
displayFoundPatients([]);
if( e.status == 'success' ) // on vide le formulaire si on a 'success'
sbCreer.parentNode.reset();
}, false);
}else // sinon on affiche l'erreur
notif('error', 'Oups!', 'Certains champs sont requis ou incorrects.');
}, false);
////////////////////////////////////////////
// AFFICHAGE DES MEDECINS DE LA RECHERCHE //
////////////////////////////////////////////
function displayFoundPatients(foundPatients){
var container = document.getElementById('searchResultPatient');
var content = '<table>';
for( var i = 0 ; i < foundPatients.length ; i++ ){
content += '<tr>';
content += '<td>'+ ((foundPatients[i].Civilite=='M')?'Monsieur':'Madame') + '</td>';
content += '<td>'+ foundPatients[i].Prenom + '</td>';
content += '<td>'+ foundPatients[i].Nom.toUpperCase() + '</td>';
content += '<td>'+ foundPatients[i].DateNaissance + '</td>';
content += '<td>'+ foundPatients[i].NumSecuriteSociale + '</td>';
content += '</tr>';
}
content += '</table>';
// on vide le container
container.innerHTML = content;
}

View File

@ -54,7 +54,7 @@ class Medecin
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message, 'medecins' => $_medecins ]));
else{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message.'&medecins='.json_encode($_medecins));
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message.'&medecins='.base64_encode(json_encode($_medecins)));
$response->send();
}
}else{
@ -62,13 +62,9 @@ class Medecin
$_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' => 'error',
'title' => 'Oups!',
'message' => 'Aucun médecin trouvé.'
]));
}else{
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();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();

View File

@ -22,7 +22,7 @@ class Patient
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
else{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}else{
@ -34,7 +34,7 @@ class Patient
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
else{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
@ -48,13 +48,44 @@ class Patient
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
else{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
}
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();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message.'&patients='.base64_encode(json_encode($_patients)));
$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();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
}
public function update($params){
if(StaticRepo::checkParam($params['date_naissance'],'Date')){
$params['num_secu'] = str_replace(' ','',$params['num_secu']);
@ -70,7 +101,7 @@ class Patient
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
else{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
@ -83,7 +114,7 @@ class Patient
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
else{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
@ -96,7 +127,7 @@ class Patient
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
else{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
@ -113,7 +144,7 @@ class Patient
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
else{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
@ -126,7 +157,7 @@ class Patient
Response::quickResponse(200, json_encode([ 'status' => $_status, 'title' => $_title, 'message' => $_message ]));
else{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Patients.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}

View File

@ -3,6 +3,9 @@
"add":{"method": "add",
"role": 0,
"strict": false},
"search":{"method":"search",
"role":0,
"strict":false},
"delete":{"method": "delete",
"role": 0,
"strict": false},

View File

@ -123,16 +123,26 @@ class PatientRepo
}
public static function search($nom,$prenom){
if(!StaticRepo::checkParam($prenom,'String45') && !StaticRepo::checkParam($nom,'String45')){return false;}
public static function search($nom, $prenom){
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM Patient WHERE Nom LIKE :nom AND Prenom LIKE :prenom');
$req->execute(['nom' => $nom, 'prenom' => $prenom]);
return StaticRepo::delNumeric($req->fetchAll());
if( !StaticRepo::checkParam($prenom,'String45') && !StaticRepo::checkParam($nom,'String45') ) return false;
// on définit les valeurs (peuvent être nulles)
$optPrenom = ( $prenom != 'null' && StaticRepo::checkParam($prenom,'String45') ) ? '%'.$prenom.'%' : '%';
$optNom = ( $nom != 'null' && StaticRepo::checkParam($nom, 'String45') ) ? '%'.$nom.'%' : '%';
$req = StaticRepo::getConnexion()->query("SELECT Civilite, Nom, Prenom, DateNaissance, NumSecuriteSociale
FROM Patient
WHERE Nom LIKE '".$optNom."'
AND Prenom LIKE '".$optPrenom."'
ORDER BY Nom, Prenom ASC");
return StaticRepo::delNumeric( $req->fetchAll() );
}
public static function getAll(){
$req = StaticRepo::getConnexion()->query('SELECT * FROM Patient ORDER BY nom, prenom ASC');