Implement CRUD operations for patients
This commit is contained in:
@@ -30,17 +30,22 @@ function createPatient($pdo, $data) {
|
||||
return "Paciente creado con éxito";
|
||||
}
|
||||
|
||||
function editPatient($pdo, string $attr, string $param, string $id) {
|
||||
$query = "UPDATE paciente SET ? = ? WHERE documento_identificativo = ?";
|
||||
$pdo->prepare($query)->execute([$attr, $param, $id]);
|
||||
function editPatient($pdo, $data, $id) {
|
||||
$query = "UPDATE paciente SET nombre=?, apellido=?, fecha_de_nacimiento=?, documento_identificativo=?,
|
||||
tipo_documento=?, direccion=?, localidad=?, provincia=?, pais=? WHERE id=?";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$data["nombre"], $data["apellido"], $data["fecha_de_nacimiento"],
|
||||
$data["documento_identificativo"], $data["tipo_documento"], $data["direccion"],
|
||||
$data["localidad"], $data["provincia"], $data["pais"], $id]);
|
||||
return "Paciente modificado con éxito";
|
||||
}
|
||||
|
||||
function deletePatient($pdo, string $id) {
|
||||
$check = "SELECT * FROM informes where paciente = ?";
|
||||
$result = $pdo->prepare($check)->execute([$id]);
|
||||
$result = $pdo->prepare($check);
|
||||
$result->execute([$id]);
|
||||
if($result->columnCount() == 0){
|
||||
$statement = "DELETE FROM paciente where document_identificado = ?";
|
||||
$statement = "DELETE FROM paciente where id=?";
|
||||
$pdo->prepare($statement)->execute([$id]);
|
||||
return "El paciente se ha eliminado correctamente";
|
||||
}
|
||||
@@ -75,7 +80,6 @@ function editUser($pdo, $data, $id) {
|
||||
$query = "UPDATE usuario SET nombre=?, usuario=?, contraseña=?, rol=?, correo=? WHERE id=?";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$data["nombre"], $data["usuario"], $data["contraseña"], $data["rol"], $data["correo"], $id]);
|
||||
$result->debugDumpParams;
|
||||
return "Usuario modificado con éxito";
|
||||
}
|
||||
|
||||
@@ -115,4 +119,27 @@ function findUser($pdo, $input) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
function listPatients($pdo) {
|
||||
$query = "SELECT * from paciente";
|
||||
$result = $pdo->query($query)->fetchAll();
|
||||
return $result;
|
||||
}
|
||||
|
||||
function fetchPatientData($pdo, string $id) {
|
||||
$query = "SELECT * FROM paciente WHERE id=?";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$id]);
|
||||
$data = $result->fetch();
|
||||
return $data;
|
||||
}
|
||||
|
||||
function findPatient($pdo, $input) {
|
||||
$input = "%$input%";
|
||||
$query = "SELECT * FROM paciente WHERE nombre LIKE ? OR apellido LIKE ? OR documento_identificativo LIKE ?";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$input, $input, $input]);
|
||||
$data = $result->fetchAll();
|
||||
return $data;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user