2015-12-02 12:31:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: seekdasky
|
|
|
|
* Date: 02/12/15
|
|
|
|
* Time: 12:36
|
|
|
|
*/
|
|
|
|
class PatientRepo
|
|
|
|
{
|
2015-12-08 07:50:30 +00:00
|
|
|
public static function getById($id){
|
2015-12-10 10:46:29 +00:00
|
|
|
if(!StaticRepo::checkParam($id,'Integer')){return false;}
|
2015-12-10 09:56:06 +00:00
|
|
|
|
2015-12-08 07:50:30 +00:00
|
|
|
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM Patient WHERE Id = :id');
|
2015-12-02 12:31:37 +00:00
|
|
|
$req->execute(['id' => $id]);
|
2015-12-08 08:31:47 +00:00
|
|
|
return StaticRepo::delNumeric( $req->fetch(), true );
|
2015-12-02 12:31:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-08 07:50:30 +00:00
|
|
|
public static function add($civilite,$prenom,$nom,$adresse,$adresse2,$ville,$codePostal,$dateNaissance,$lieuNaissance,$numSecu,$medecinTraitant = null){
|
2015-12-17 07:56:42 +00:00
|
|
|
|
2015-12-15 08:19:59 +00:00
|
|
|
$correctTypes = StaticRepo::checkParam($civilite,'Civilite');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($prenom,'String45');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($nom,'String45');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($adresse,'String255');
|
2015-12-17 07:56:42 +00:00
|
|
|
$correctTypes = $correctTypes && ( $adresse2 == 'null' || $adresse2 === null || StaticRepo::checkParam($adresse2, 'String255') );
|
2015-12-15 08:19:59 +00:00
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($ville,'String50');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($codePostal,'String');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($dateNaissance,'Date');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($lieuNaissance,'String50');
|
2015-12-17 07:56:42 +00:00
|
|
|
$correctTypes = $correctTypes && ( $medecinTraitant == 'null' || $medecinTraitant === null ||StaticRepo::checkParam($medecinTraitant, 'Integer') );
|
2015-12-15 08:19:59 +00:00
|
|
|
if( !$correctTypes ) return false;
|
2015-12-10 10:46:29 +00:00
|
|
|
|
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
|
|
|
|
2015-12-15 08:19:59 +00:00
|
|
|
$req = StaticRepo::getConnexion()->prepare("INSERT INTO Patient
|
|
|
|
VALUES(DEFAULT,
|
|
|
|
:civilite,
|
|
|
|
:nom,
|
|
|
|
:prenom,
|
|
|
|
:adresse,
|
|
|
|
:adresse2,
|
|
|
|
:ville,
|
|
|
|
:codePostal,
|
|
|
|
:dateNaissance,
|
|
|
|
:lieuNaissance,
|
|
|
|
:numSecu,
|
|
|
|
:medecin
|
|
|
|
)");
|
|
|
|
$result = $req->execute([
|
|
|
|
'civilite' => $civilite,
|
|
|
|
'nom' => $nom,
|
|
|
|
'prenom' => $prenom,
|
|
|
|
'adresse' => $adresse,
|
|
|
|
'adresse2' => (strlen($adresse2)>0) ? $adresse2 : NULL,
|
|
|
|
'ville' => $ville,
|
|
|
|
'codePostal' => $codePostal,
|
2015-12-08 08:31:47 +00:00
|
|
|
'dateNaissance' => $dateNaissance,
|
|
|
|
'lieuNaissance' => $lieuNaissance,
|
2015-12-15 08:19:59 +00:00
|
|
|
'numSecu' => $numSecu,
|
|
|
|
'medecin' => $medecinTraitant
|
|
|
|
]);
|
|
|
|
|
2015-12-10 10:46:29 +00:00
|
|
|
//PDO renvoie un ID sous forme de char, on transtype
|
|
|
|
$id = StaticRepo::getConnexion()->lastInsertId();
|
|
|
|
settype($id,'integer');
|
2015-12-15 08:19:59 +00:00
|
|
|
|
|
|
|
if($result)return $id;
|
|
|
|
else return false;
|
2015-12-10 09:47:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function update($id,$civilite,$prenom,$nom,$adresse,$adresse2,$ville,$codePostal,$dateNaissance,$lieuNaissance,$numSecu,$medecinTraitant){
|
2015-12-10 10:46:29 +00:00
|
|
|
|
2015-12-17 07:56:42 +00:00
|
|
|
$correctTypes = StaticRepo::checkParam($civilite,'Civilite');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($prenom,'String45');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($nom,'String45');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($adresse,'String255');
|
|
|
|
$correctTypes = $correctTypes && ( $adresse2 == 'null' || $adresse2 === null || StaticRepo::checkParam($adresse2, 'String255') );
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($ville,'String50');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($codePostal,'String');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($dateNaissance,'Date');
|
|
|
|
$correctTypes = $correctTypes && StaticRepo::checkParam($lieuNaissance,'String50');
|
|
|
|
$correctTypes = $correctTypes && ( $medecinTraitant == 'null' || $medecinTraitant === null ||StaticRepo::checkParam($medecinTraitant, 'Integer') );
|
|
|
|
if( !$correctTypes ) return false;
|
2015-12-10 10:46:29 +00:00
|
|
|
|
2015-12-10 09:47:30 +00:00
|
|
|
$dateNaissance = strtotime($dateNaissance);
|
|
|
|
$dateNaissance = Date('o-m-d',$dateNaissance);
|
|
|
|
|
|
|
|
$req = StaticRepo::getConnexion()->prepare('UPDATE Patient SET Civilite=:civilite,Nom=:nom,Prenom=:prenom,Adresse=:adresse,Adresse2=:adresse2,Ville=:ville,
|
|
|
|
CodePostal=:codePostal,DateNaissance=:dateNaissance,LieuNaissance=:lieuNaissance,NumSecuriteSociale=:numSecu,MedecinTraitant=:medecin WHERE Id=:id;');
|
|
|
|
$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,
|
|
|
|
'id' => $id]);
|
2015-12-10 10:46:29 +00:00
|
|
|
//PDO renvoie un ID sous forme de char, on transtype
|
|
|
|
$id = StaticRepo::getConnexion()->lastInsertId();
|
|
|
|
settype($id,'integer');
|
|
|
|
if($result){return $id;}
|
2015-12-08 08:31:47 +00:00
|
|
|
else{return false;}
|
2015-12-02 12:31:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-08 07:50:30 +00:00
|
|
|
public static function delete($idPatient){
|
2015-12-02 12:31:37 +00:00
|
|
|
|
2015-12-10 10:46:29 +00:00
|
|
|
if(!StaticRepo::checkParam($idPatient,'Integer')){ return false;}
|
2015-12-10 09:56:06 +00:00
|
|
|
|
2015-12-09 12:36:30 +00:00
|
|
|
$req = StaticRepo::getConnexion()->prepare('DELETE FROM Patient WHERE Patient.Id = :id');
|
2015-12-08 07:50:30 +00:00
|
|
|
return $req->execute(['id' => $idPatient]);
|
2015-12-03 09:43:27 +00:00
|
|
|
|
2015-12-02 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 07:50:30 +00:00
|
|
|
public static function updateMedecinTraitant($idPatient,$idMedecin){
|
2015-12-03 09:43:27 +00:00
|
|
|
|
2015-12-10 10:46:29 +00:00
|
|
|
if(!StaticRepo::checkParam($idPatient,'Integer') && !StaticRepo::checkParam($idMedecin,'Integer')){return false;}
|
2015-12-10 09:56:06 +00:00
|
|
|
|
2015-12-08 07:50:30 +00:00
|
|
|
$req = StaticRepo::getConnexion()->prepare('UPDATE Patient SET MedecinTraitant = :medecin WHERE Id = :id');
|
|
|
|
return $req->execute(['medecin' => $idMedecin, 'id' => $idPatient]);
|
2015-12-02 12:31:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-08 07:50:30 +00:00
|
|
|
public static function search($nom,$prenom){
|
2015-12-03 09:43:27 +00:00
|
|
|
|
2015-12-10 10:46:29 +00:00
|
|
|
if(!StaticRepo::checkParam($prenom,'String45') && !StaticRepo::checkParam($nom,'String45')){return false;}
|
|
|
|
|
2015-12-08 07:50:30 +00:00
|
|
|
$req = StaticRepo::getConnexion()->prepare('SELECT * FROM Patient WHERE Nom LIKE :nom AND Prenom LIKE :prenom');
|
|
|
|
$req->execute(['nom' => $nom, 'prenom' => $prenom]);
|
2015-12-08 08:31:47 +00:00
|
|
|
return StaticRepo::delNumeric($req->fetchAll());
|
2015-12-03 09:43:27 +00:00
|
|
|
|
2015-12-02 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 07:50:30 +00:00
|
|
|
public static function getAll(){
|
|
|
|
|
|
|
|
$req = StaticRepo::getConnexion()->query('SELECT * FROM Patient ORDER BY nom, prenom ASC');
|
|
|
|
|
|
|
|
return StaticRepo::delNumeric( $req->fetchAll() );
|
2015-12-03 09:43:27 +00:00
|
|
|
|
2015-12-02 12:31:37 +00:00
|
|
|
}
|
|
|
|
|
2015-12-03 09:43:27 +00:00
|
|
|
}
|