191 lines
7.4 KiB
PHP
Executable File
191 lines
7.4 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: seekdasky
|
|
* Date: 02/12/15
|
|
* Time: 12:36
|
|
*/
|
|
class PatientRepo
|
|
{
|
|
public static function getById($id){
|
|
if(!StaticRepo::checkParam($id,'Numeric')){return false;}
|
|
|
|
$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){
|
|
|
|
$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' || StaticRepo::checkParam($medecinTraitant, 'Numeric'));
|
|
if( !$correctTypes ) return false;
|
|
|
|
$dateNaissance = strtotime($dateNaissance);
|
|
$dateNaissance = Date('o-m-d', $dateNaissance);
|
|
|
|
$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,
|
|
'dateNaissance' => $dateNaissance,
|
|
'lieuNaissance' => $lieuNaissance,
|
|
'numSecu' => $numSecu,
|
|
'medecin' => $medecinTraitant
|
|
]);
|
|
|
|
//PDO renvoie un ID sous forme de char, on transtype
|
|
$id = StaticRepo::getConnexion()->lastInsertId();
|
|
settype($id,'integer');
|
|
|
|
if($result)return $id;
|
|
else return false;
|
|
|
|
}
|
|
|
|
public static function update(
|
|
$id,
|
|
$civilite,
|
|
$prenom,
|
|
$nom,
|
|
$adresse,
|
|
$adresse2,
|
|
$ville,
|
|
$codePostal,
|
|
$dateNaissance,
|
|
$lieuNaissance,
|
|
$numSecu,
|
|
$medecinTraitant ){
|
|
|
|
$correctTypes = StaticRepo::checkParam($id, 'Numeric');
|
|
$correctTypes = $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 == '' || $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, 'Numeric') );
|
|
if( !$correctTypes ) return false;
|
|
|
|
|
|
// on enlève les espaces du numéro de sécu
|
|
$numSecu = str_replace(' ', '', $numSecu);
|
|
// on met la date de naissance au bon format
|
|
$dateNaissance = DateTime::createFromFormat('d/m/Y', $dateNaissance)->format('Y-m-d 00:00:00');
|
|
|
|
$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]);
|
|
//PDO renvoie un ID sous forme de char, on transtype
|
|
$id = StaticRepo::getConnexion()->lastInsertId();
|
|
|
|
settype($id,'integer');
|
|
|
|
if($result) return $id;
|
|
else return false;
|
|
|
|
}
|
|
|
|
public static function delete($idPatient){
|
|
|
|
// 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]);
|
|
|
|
}
|
|
|
|
public static function updateMedecinTraitant($idPatient,$idMedecin){
|
|
|
|
if(!StaticRepo::checkParam($idPatient,'Integer') && !StaticRepo::checkParam($idMedecin,'Integer')){return false;}
|
|
|
|
$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){
|
|
|
|
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 Id, Civilite, Nom, Prenom, DATE_FORMAT(DateNaissance, '%d/%m/%Y') as 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');
|
|
|
|
return StaticRepo::delNumeric( $req->fetchAll() );
|
|
|
|
}
|
|
|
|
}
|