Implémentation du Fetch des données pour prendre un RDV (uniquement humaines)

This commit is contained in:
xdrm-brackets 2015-12-08 08:50:30 +01:00
parent 94f438a102
commit 9fe7bae29c
6 changed files with 92 additions and 52 deletions

View File

@ -41,22 +41,21 @@ if(!Authentification::checkUser(0)){
<!-- FIL D'ARIANE -->
<div id='BREADCRUMB'><a href='Dashboard.php'>Accueil</a> <a href='Consultations.php'>Consultations</a></a> </div>
<article data-title="Saisir un rendez-vous">
<div>
<select id='newRDVPatient'>
<option value='*'>Patients:</option>
<?php $patients = json_decode( file_get_contents('Docs/PatientExemple.json') );
foreach($patients as $PATIENT)
echo "<option value='".$PATIENT->Id."' data-medecin='".$PATIENT->MedecinTraitant."'>".$PATIENT->Nom." ".$PATIENT->Prenom."</option>";
<?php
foreach(PatientRepo::getAll() as $PATIENT)
echo "<option value='".$PATIENT['Id']."' data-medecin='".$PATIENT['MedecinTraitant']."'>".$PATIENT['Nom']." ".$PATIENT['Prenom']."</option>";
?>
</select>Choix du patient
</div><div>
<select id='newRDVMedecin'>
<option value='*'>Medecins:</option>
<?php $medecins = json_decode( file_get_contents('Docs/MedecinExemple.json') );
foreach($medecins as $MEDECIN)
echo "<option value='".$MEDECIN->Id."'>".$MEDECIN->Nom." ".$MEDECIN->Prenom."</option>";
<?php
foreach(MedecinRepo::getAll() as $MEDECIN)
echo "<option value='".$MEDECIN['Id']."'>".$MEDECIN['Nom']." ".$MEDECIN['Prenom']."</option>";
?>
</select>Le médecin traitant se selectionne par défaut
</div>

View File

@ -276,6 +276,13 @@ body{
-webkit-appearance: none;
-ms-appearance: none;
-o-appearance: none;
/* animation */
transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
}
/* <SELECT> <OPTION> */
@ -293,6 +300,10 @@ body{
-o-appearance: none;
}
/* .associated */
#CONTAINER > article select.associated{
border-color: #f09108;
}
/* <INPUT> */
#CONTAINER > article input{
@ -304,13 +315,6 @@ body{
/* border */
border: 1px solid #e5e5e5;
/* animation */
transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
}
/* @focus */

View File

@ -7,3 +7,14 @@ NodeList.prototype.indexOf = HTMLCollection.prototype.indexOf = function(searche
// si on a rien trouvé, on retourne -1
return -1;
};
function addClass(el, pClass){
if( el.className.length > 0 && el.className != pClass ) el.className = el.className + ' ' + pClass;
else el.className = pClass;
}
function remClass(el, pClass){
if( el.className.indexOf(pClass) > -1 ) // si la class de l'élement contient la classe à enlever
el.className = el.className.substr(0, el.className.indexOf(pClass)) + '' + el.className.substr(el.className.indexOf(pClass)+pClass.length);
}

View File

@ -7,17 +7,27 @@ var newRDVMedecin = document.getElementById('newRDVMedecin');
===============================================================*/
if( newRDVPatient != null && newRDVMedecin != null ){
// on selectionne dynamiquement le médecin traitant associé
/* [1] On selectionne dynamiquement le médecin traitant associé
=======================================================================*/
newRDVPatient.addEventListener('change', function(e){
var value = e.target.value;
var child = document.querySelector("#newRDVPatient > option[value='"+value+"'][data-medecin]");
var child = document.querySelector("#newRDVPatient > option[value='"+newRDVPatient.value+"'][data-medecin]");
// on selectionne le medecin associé
newRDVMedecin.value = child.dataset.medecin;
addClass(newRDVMedecin, 'associated');
}, false);
// [1] On met en valeur le médecin traitant associé (class=associated)
// =======================================================================
newRDVMedecin.addEventListener('change', function(e){
var child = document.querySelector("#newRDVPatient > option[value='"+newRDVPatient.value+"'][data-medecin]");
if( newRDVMedecin.value == child.dataset.medecin ) // si c'est le medecin traitant, on met en valeur l'association
addClass(newRDVMedecin, 'associated');
else
remClass(newRDVMedecin, 'associated');
}, false);
}

View File

@ -53,4 +53,12 @@ class MedecinRepo
return StaticRepo::delNumeric($req->fetchAll());
}
public static function getAll(){
$req = StaticRepo::getConnexion()->query('SELECT * FROM Medecin ORDER BY nom, prenom ASC');
return StaticRepo::delNumeric( $req->fetchAll() );
}
}

View File

@ -8,63 +8,71 @@
*/
class PatientRepo
{
private $connexion;
// private $connexion;
public function __construct(){
$this->connexion = StaticRepo::getConnexion();
}
// public function __construct(){
// StaticRepo::getConnexion() = StaticRepo::getConnexion();
// }
public function getById($id){
$req = $this->connexion->prepare('SELECT * FROM Patient WHERE Id = :id');
public static function getById($id){
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM Patient WHERE Id = :id');
$req->execute(['id' => $id]);
return StaticRepo::delNumeric( $req->fetch(), true );
return StaticRepo::delNumeric( $req->fetch(), true );
}
public function add($civilite,$prenom,$nom,$adresse,$adresse2,$ville,$codePostal,$dateNaissance,$lieuNaissance,$numSecu,$medecinTraitant = null){
public static function add($civilite,$prenom,$nom,$adresse,$adresse2,$ville,$codePostal,$dateNaissance,$lieuNaissance,$numSecu,$medecinTraitant = null){
$dateNaissance = strtotime($dateNaissance);
$dateNaissance = Date('o-m-d',$dateNaissance);
$req = $this->connexion->prepare('INSERT INTO Patient VALUES (:civilite,:nom,:prenom,:adresse,:adresse2,:ville,:codePostal,:dateNaissance,:lieuNaissance,:numSecu,DEFAULT,:medecin)');
$req = StaticRepo::getConnexion()->prepare('INSERT INTO Patient VALUES (:civilite,:nom,:prenom,:adresse,:adresse2,:ville,:codePostal,:dateNaissance,:lieuNaissance,:numSecu,DEFAULT,:medecin)');
$result = $req->execute(['civilite' => $civilite,
'nom' => $nom,
'prenom' => $prenom,
'adresse' => $adresse,
'adresse2' => $adresse2,
'ville' => $ville,
'codePostal' => $codePostal,
'dateNaissance' => $dateNaissance,
'lieuNaissance' => $lieuNaissance,
'numSecu' => $numSecu,
'medecin' => $medecinTraitant ]);
if($result){return ['id' => $this->connexion->lastInsertId()];}
else{return false;}
'nom' => $nom,
'prenom' => $prenom,
'adresse' => $adresse,
'adresse2' => $adresse2,
'ville' => $ville,
'codePostal' => $codePostal,
'dateNaissance' => $dateNaissance,
'lieuNaissance' => $lieuNaissance,
'numSecu' => $numSecu,
'medecin' => $medecinTraitant ]);
if($result){return ['id' => StaticRepo::getConnexion()->lastInsertId()];}
else{return false;}
}
public function delete($idPatient){
public static function delete($idPatient){
$req = $this->connexion->prepare('DELETE FROM Patient WHERE Id = :id');
return $req->execute(['id' => $idPatient]);
$req = StaticRepo::getConnexion()->prepare('DELETE FROM Patient WHERE Id = :id');
return $req->execute(['id' => $idPatient]);
}
public function updateMedecinTraitant($idPatient,$idMedecin){
public static function updateMedecinTraitant($idPatient,$idMedecin){
$req = $this->connexion->prepare('UPDATE Patient SET MedecinTraitant = :medecin WHERE Id = :id');
return $req->execute(['medecin' => $idMedecin,
'id' => $idPatient]);
$req = StaticRepo::getConnexion()->prepare('UPDATE Patient SET MedecinTraitant = :medecin WHERE Id = :id');
return $req->execute(['medecin' => $idMedecin, 'id' => $idPatient]);
}
public function search($nom,$prenom){
public static function search($nom,$prenom){
$req = $this->connexion->prepare('SELECT * FROM Patient WHERE Nom LIKE :nom AND Prenom LIKE :prenom');
$req->execute(['nom' => $nom,
'prenom' => $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());
return StaticRepo::delNumeric($req->fetchAll());
}
public static function getAll(){
$req = StaticRepo::getConnexion()->query('SELECT * FROM Patient ORDER BY nom, prenom ASC');
return StaticRepo::delNumeric( $req->fetchAll() );
}