Recherche et suppression des patients/médecins

This commit is contained in:
xdrm-brackets 2015-12-26 11:42:52 +01:00
parent 4375083dc3
commit 67288b94bb
11 changed files with 147 additions and 42 deletions

View File

@ -92,13 +92,29 @@ $medecinsSearch = ( isset($_GET['medecins']) ) ? json_decode( customCompression(
<?php
// pour chaque médecin
foreach($medecinsSearch as $MED){ if( isset($MED['Civilite']) && isset($MED['Prenom']) && isset($MED['Nom']) ){
foreach($medecinsSearch as $MED){ if( isset($MED['Id']) && isset($MED['Civilite']) && isset($MED['Prenom']) && isset($MED['Nom']) ){
echo '<tr>';
echo '<td>'.(($MED['Civilite']=='M')?'Monsieur':'Madame').'</td>';
echo '<td>'.$MED['Prenom'].'</td>';
echo '<td>'.strtoupper($MED['Nom']).'</td>';
// début modification
echo "<td><form class='updMedecin' action='managers/' method='POST'>";
echo "<input type='hidden' name='command' value='Medecin:update'>";
echo "<input type='hidden' name='id_medecin' value='".$MED['Id']."'>";
echo "<input type='submit' value=''>";
echo '</form></td>';
// fin modification
// début suppression
echo "<td><form class='delMedecin' action='managers/' method='POST'>";
echo "<input type='hidden' name='command' value='Medecin:delete'>";
echo "<input type='hidden' name='id_medecin' value='".$MED['Id']."'>";
echo "<input type='submit' value=''>";
echo '</form></td>';
// fin suppression
echo '</tr>';
}}

View File

@ -91,7 +91,7 @@ $patientsSearch = ( isset($_GET['patients']) ) ? json_decode( customCompression(
<?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'])){
foreach($patientsSearch as $PAT){ if( isset($PAT['Id']) && 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>';
@ -100,6 +100,22 @@ $patientsSearch = ( isset($_GET['patients']) ) ? json_decode( customCompression(
echo '<td>'.$PAT['DateNaissance'].'</td>';
echo '<td>'.$PAT['NumSecuriteSociale'].'</td>';
// début modification
echo "<td><form class='updPatient' action='managers/' method='POST'>";
echo "<input type='hidden' name='command' value='Patient:update'>";
echo "<input type='hidden' name='id_patient' value='".$PAT['Id']."'>";
echo "<input type='submit' value=''>";
echo '</form></td>';
// fin modification
// début suppression
echo "<td><form class='delPatient' action='managers/' method='POST'>";
echo "<input type='hidden' name='command' value='Patient:delete'>";
echo "<input type='hidden' name='id_patient' value='".$PAT['Id']."'>";
echo "<input type='submit' value=''>";
echo '</form></td>';
// fin suppression
echo '</tr>';
}}

View File

@ -754,8 +754,7 @@ input[type=radio]:checked + label:before{
#CONTAINER > article table td{
/* position */
max-width: calc( 100% / 5% );
padding: .5em 0;
max-width: calc( 100% / 6% );
/* border */
border-bottom: 1px solid #cacaca;
@ -763,9 +762,37 @@ input[type=radio]:checked + label:before{
#CONTAINER > article table#searchResultMedecin td{
/* position */
max-width: calc( 100% / 3% );
padding: .5em 0;
max-width: calc( 100% / 5% );
/* border */
border-bottom: 1px solid #cacaca;
}
/* Suppression champ de recherche (patient/médecin/consultation) */
#CONTAINER > article .delPatient input[type=submit],
#CONTAINER > article .delMedecin input[type=submit]{
/* position */
padding: .5em 1em;
/* border */
border: 0;
/* background */
background-image: url(../src/svg/invalid.svg);
background-position: center center;
}
/* Modification champ de recherche (patient/médecin/consultation) */
#CONTAINER > article .updPatient input[type=submit],
#CONTAINER > article .updMedecin input[type=submit]{
/* position */
padding: .5em 1em;
/* border */
border: 0;
/* background */
background-image: url(../src/svg/edit.svg);
background-position: center center;
}

View File

@ -157,6 +157,21 @@ function displayFoundMedecins(foundMedecins){
content += '<td>'+ ((foundMedecins[i].Civilite=='M')?'Monsieur':'Madame') + '</td>';
content += '<td>'+ foundMedecins[i].Prenom + '</td>';
content += '<td>'+ foundMedecins[i].Nom.toUpperCase() + '</td>';
// début modification
content += "<td><form class='updMedecin' action='managers/' method='POST'>";
content += "<input type='hidden' name='command' value='Medecin:update'>";
content += "<input type='hidden' name='id_medecin' value='"+foundMedecins[i].Id+"'>";
content += "<input type='submit' value=''>";
content += '</form></td>';
// fin modification
// début suppression
content += "<td><form class='delMedecin' action='managers/' method='POST'>";
content += "<input type='hidden' name='command' value='Medecin:delete'>";
content += "<input type='hidden' name='id_medecin' value='"+foundMedecins[i].Id+"'>";
content += "<input type='submit' value=''>";
content += '</form></td>';
// fin suppression
content += '</tr>';
}

View File

@ -238,6 +238,21 @@ function displayFoundPatients(foundPatients){
content += '<td>'+ foundPatients[i].Nom.toUpperCase() + '</td>';
content += '<td>'+ foundPatients[i].DateNaissance + '</td>';
content += '<td>'+ foundPatients[i].NumSecuriteSociale + '</td>';
// début modification
content += "<td><form class='updPatient' action='managers/' method='POST'>";
content += "<input type='hidden' name='command' value='Patient:update'>";
content += "<input type='hidden' name='id_patient' value='"+foundPatients[i].Id+"'>";
content += "<input type='submit' value=''>";
content += '</form></td>';
// fin modification
// début suppression
content += "<td><form class='delPatient' action='managers/' method='POST'>";
content += "<input type='hidden' name='command' value='Patient:delete'>";
content += "<input type='hidden' name='id_patient' value='"+foundPatients[i].Id+"'>";
content += "<input type='submit' value=''>";
content += '</form></td>';
// fin suppression
content += '</tr>';
}

View File

@ -76,29 +76,34 @@ class Medecin
}
public function delete($params){
if(MedecinRepo::delete($params['id_medecin']) !==FALSE){
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'success',
'title' => 'Médecin supprimé!',
'message' => ''
]));
}else{
if( MedecinRepo::delete($params['id_medecin']) !== FALSE ){
$_status = 'success';
$_title = 'Médecin supprimé!';
$_message = 'Le médecin 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{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}else{
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'error',
'title' => 'Erreur lors de la supression!'
]));
}else{
$_status = 'error';
$_title = 'Erreur de suppression!';
$_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{
$response = new Response();
$response->setHeader('Location','http://'.$_SERVER['HTTP_HOST'].'/Medecins.php?status='.$_status.'&title='.$_title.'&message='.$_message);
$response->send();
}
}
}

View File

@ -13,10 +13,10 @@ function customCompression($input, $compression){
class Patient
{
public function add($params){
if(StaticRepo::checkParam($params['date_naissance'],'Date')){
$params['num_secu'] = str_replace(' ','',$params['num_secu']);
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'],
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){
$_status = 'success';
$_title = 'Création effectuée!';
@ -139,10 +139,10 @@ class Patient
}
public function delete($params){
if(PatientRepo::delete($params['id_patient']) !==FALSE){
if( PatientRepo::delete($params['id_patient']) !== FALSE ){
$_status = 'success';
$_title = 'Patient supprimé!';
$_status = 'success';
$_title = 'Patient supprimé!';
$_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' )
@ -154,8 +154,8 @@ class Patient
}
}else{
$_status = 'error';
$_title = 'Erreur de suppression!';
$_status = 'error';
$_title = 'Erreur de suppression!';
$_message = 'Erreur lors de la suppression. Réessayez!';
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' )

View File

@ -132,6 +132,10 @@ class StaticRepo{
$checker = $checker && !is_null($variable) && is_int($variable) && $variable<pow(2, 32);
break;
case 'Numeric':
$checker = $checker && !is_null($variable) && is_numeric($variable);
break;
case 'SmallInteger':
$checker = $checker && !is_null($variable) && is_int($variable) && $variable<pow(2, 16);
break;

View File

@ -11,7 +11,7 @@ class MedecinRepo
public static function getById($id){
if(!StaticRepo::checkParam($id,'Integer')){return false;}
if(!StaticRepo::checkParam($id, 'Numeric')) return false;
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM Medecin WHERE Id = :id');
$req->execute(['id' => $id]);
@ -21,22 +21,26 @@ class MedecinRepo
public static function add($civilite,$prenom,$nom){
if(!StaticRepo::checkParam($civilite,'Civilite') && !StaticRepo::checkParam($prenom,'String45') && !StaticRepo::checkParam($nom,'String45')){return false;}
if(!StaticRepo::checkParam($civilite,'Civilite') && !StaticRepo::checkParam($prenom,'String45') && !StaticRepo::checkParam($nom,'String45')) return false;
$req = StaticRepo::getConnexion()->prepare('INSERT INTO Medecin VALUES (DEFAULT,:civilite,:prenom,:nom)');
$result = $req->execute(['civilite' => $civilite,
'nom' => $nom,
'prenom' => $prenom]);
'prenom' => $prenom
]);
//PDO renvoie un ID sous forme de char, on transtype
$id = StaticRepo::getConnexion()->lastInsertId();
settype($id,'integer');
if($result){return $id;}
else{return false;}
settype($id, 'integer');
if($result) return $id;
else return false;
}
public static function delete($idMedecin){
if(!StaticRepo::checkParam($idMedecin,'Integer')){return false;}
if(!StaticRepo::checkParam($idMedecin,'Numeric')) return false;
$req = StaticRepo::getConnexion()->prepare('DELETE FROM Medecin WHERE Id = :id');
return $req->execute(['id' => $idMedecin]);
@ -50,7 +54,7 @@ class MedecinRepo
$optPrenom = ( $prenom != 'null' && StaticRepo::checkParam($prenom,'String45') ) ? '%'.$prenom.'%' : '%';
$optNom = ( $nom != 'null' && StaticRepo::checkParam($nom, 'String45') ) ? '%'.$nom.'%' : '%';
$req = StaticRepo::getConnexion()->query("SELECT *
$req = StaticRepo::getConnexion()->query("SELECT Id, Civilite, Prenom, Nom
FROM Medecin
WHERE Nom LIKE '".$optNom."'
AND Prenom LIKE '".$optPrenom."'
@ -62,7 +66,7 @@ class MedecinRepo
public static function getPatients($idMedecin){
if(!StaticRepo::checkParam($idMedecin,'Integer')){return false;}
if(!StaticRepo::checkParam($idMedecin,'Numeric')) return false;
$req = StaticRepo::getConnexion()->prepare('SELECT Patient.* FROM Patient,Medecin
WHERE Medecin.Id = :id

View File

@ -28,11 +28,11 @@ class PatientRepo
$correctTypes = $correctTypes && StaticRepo::checkParam($codePostal,'String');
$correctTypes = $correctTypes && StaticRepo::checkParam($dateNaissance,'Date');
$correctTypes = $correctTypes && StaticRepo::checkParam($lieuNaissance,'String50');
$correctTypes = $correctTypes && ( $medecinTraitant == 'null' || StaticRepo::checkParam($medecinTraitant, 'Integer') );
$correctTypes = $correctTypes && ( $medecinTraitant == 'null' || StaticRepo::checkParam($medecinTraitant, 'Numeric') );
if( !$correctTypes ) return false;
$dateNaissance = strtotime($dateNaissance);
$dateNaissance = Date('o-m-d',$dateNaissance);
$dateNaissance = Date('o-m-d', $dateNaissance);
$req = StaticRepo::getConnexion()->prepare("INSERT INTO Patient
VALUES(DEFAULT,
@ -107,10 +107,12 @@ class PatientRepo
public static function delete($idPatient){
if(!StaticRepo::checkParam($idPatient,'Integer')){ return false;}
// si format erroné, retourne FALSE
if( !StaticRepo::checkParam($idPatient, 'Numeric') ) return false;
$req = StaticRepo::getConnexion()->prepare('DELETE FROM Patient WHERE Patient.Id = :id');
return $req->execute(['id' => $idPatient]);
return $req->execute([':id' => $idPatient]);
}
@ -132,7 +134,7 @@ class PatientRepo
$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
$req = StaticRepo::getConnexion()->query("SELECT Id, Civilite, Nom, Prenom, DateNaissance, NumSecuriteSociale
FROM Patient
WHERE Nom LIKE '".$optNom."'
AND Prenom LIKE '".$optPrenom."'

1
src/svg/edit.svg Executable file
View File

@ -0,0 +1 @@
<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg enable-background="new 0 0 128 128" height="128px" id="Layer_1" version="1.1" viewBox="0 0 128 128" width="128px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M123.315,16L112.003,4.686C108.878,1.563,104.78,0,100.687,0s-8.188,1.563-11.313,4.686l-68.69,68.689 C17.563,76.5,8.004,88.586,8,92.68L0,128l35.313-8c0,0,16.188-9.563,19.313-12.688l68.69-68.687 C129.562,32.375,129.562,22.243,123.315,16z M10.605,117.398l5.195-22.953c0.074-0.328,0.129-0.664,0.16-0.992 c0.016-0.047,0.059-0.117,0.078-0.164l18.09,18.094c-0.605,0.367-1.215,0.734-1.813,1.094L10.605,117.398z M48.984,101.641 c-0.906,0.859-4.039,2.977-7.867,5.414L20.391,86.328c2.125-2.914,4.492-5.844,5.949-7.297l51.722-51.718l22.625,22.625 L48.984,101.641z M117.659,32.969l-11.316,11.313L83.718,21.657l11.316-11.313C96.542,8.829,98.55,8,100.687,8 s4.148,0.836,5.66,2.344l11.313,11.313c1.512,1.508,2.34,3.516,2.34,5.656C119.999,29.446,119.167,31.461,117.659,32.969z" fill="#546E7A"/></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB