projet-php/repositories/repos/PatientRepo.php

80 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
* Created by PhpStorm.
* User: seekdasky
* Date: 02/12/15
* Time: 12:36
*/
class PatientRepo
{
// private $connexion;
// public function __construct(){
// StaticRepo::getConnexion() = StaticRepo::getConnexion();
// }
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 );
}
public static function add($civilite,$prenom,$nom,$adresse,$adresse2,$ville,$codePostal,$dateNaissance,$lieuNaissance,$numSecu,$medecinTraitant = null){
2015-12-03 11:25:02 +00:00
$dateNaissance = strtotime($dateNaissance);
$dateNaissance = Date('o-m-d',$dateNaissance);
2015-12-03 11:00:22 +00:00
$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' => StaticRepo::getConnexion()->lastInsertId()];}
else{return false;}
}
public static function delete($idPatient){
$req = StaticRepo::getConnexion()->prepare('DELETE FROM Patient WHERE Id = :id');
return $req->execute(['id' => $idPatient]);
}
public static function updateMedecinTraitant($idPatient,$idMedecin){
$req = StaticRepo::getConnexion()->prepare('UPDATE Patient SET MedecinTraitant = :medecin WHERE Id = :id');
return $req->execute(['medecin' => $idMedecin, 'id' => $idPatient]);
}
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());
}
public static function getAll(){
$req = StaticRepo::getConnexion()->query('SELECT * FROM Patient ORDER BY nom, prenom ASC');
return StaticRepo::delNumeric( $req->fetchAll() );
}
}