Enhance waitlist functionality: update queries to count distinct users, add new impfwarteliste.php page, and improve form handling in functions.impfen.inc.php
This commit is contained in:
@@ -358,3 +358,145 @@ if (!function_exists('impfGetZeitraeumeByImpfstoff')) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('impfGetWartelistenFormOptions')) {
|
||||
function impfGetWartelistenFormOptions(PDO $pdo): array
|
||||
{
|
||||
$impfstoffe = [];
|
||||
$zeitfenster = [];
|
||||
|
||||
$stImpfstoffe = $pdo->prepare("SELECT r.impfstoff_id, i.impfname
|
||||
FROM impfstoff_workflow r
|
||||
INNER JOIN impfstoff i ON i.impfid = r.impfstoff_id
|
||||
WHERE (i.aktiv = 1 OR i.aktivwarteliste = 1 OR i.aktivtermin = 1 OR i.aktivgrippe = 1)
|
||||
AND r.dosen_pro_flasche > 0
|
||||
ORDER BY i.impfname");
|
||||
$stImpfstoffe->execute();
|
||||
foreach ($stImpfstoffe->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$impfstoffe[(int)$row['impfstoff_id']] = (string)$row['impfname'];
|
||||
}
|
||||
|
||||
$zeitraeumeByImpfstoff = impfGetZeitraeumeByImpfstoff($pdo, true);
|
||||
foreach ($zeitraeumeByImpfstoff as $impfstoffId => $zeitraeume) {
|
||||
if (!isset($impfstoffe[$impfstoffId])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($zeitraeume as $zeitraum) {
|
||||
if (!isset($zeitfenster[$impfstoffId])) {
|
||||
$zeitfenster[$impfstoffId] = [];
|
||||
}
|
||||
$zeitfenster[$impfstoffId][] = [
|
||||
'id' => (int)$zeitraum['zeitraum_id'],
|
||||
'label' => (string)$zeitraum['label'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array_keys($impfstoffe) as $impfstoffId) {
|
||||
if (empty($zeitfenster[$impfstoffId])) {
|
||||
unset($impfstoffe[$impfstoffId]);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'impfstoffe' => $impfstoffe,
|
||||
'zeitfenster' => $zeitfenster,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('impfCreateWaitlistEntryForPerson')) {
|
||||
function impfCreateWaitlistEntryForPerson(
|
||||
PDO $pdo,
|
||||
int $personId,
|
||||
int $impfstoffId,
|
||||
int $zeitraumId,
|
||||
int $impfart,
|
||||
?string $letzteImpfung = null,
|
||||
int $checked = 1
|
||||
): array {
|
||||
if ($personId <= 0) {
|
||||
return [false, 'Keine gueltige Person uebergeben.', null];
|
||||
}
|
||||
if ($impfstoffId <= 0) {
|
||||
return [false, 'Bitte einen Impfstoff auswaehlen.', null];
|
||||
}
|
||||
if ($zeitraumId <= 0) {
|
||||
return [false, 'Bitte ein Zeitfenster auswaehlen.', null];
|
||||
}
|
||||
if ($impfart < 1 || $impfart > 4) {
|
||||
return [false, 'Bitte eine gueltige Impfungsart auswaehlen.', null];
|
||||
}
|
||||
|
||||
$letzteImpfung = $letzteImpfung !== null ? trim($letzteImpfung) : null;
|
||||
if ($impfart === 1) {
|
||||
$letzteImpfung = null;
|
||||
} elseif ($letzteImpfung === null || $letzteImpfung === '') {
|
||||
return [false, 'Bitte das Datum der letzten Impfung angeben.', null];
|
||||
} elseif (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $letzteImpfung)) {
|
||||
return [false, 'Das Datum der letzten Impfung ist ungueltig.', null];
|
||||
}
|
||||
|
||||
$stPerson = $pdo->prepare("SELECT person_id, patientenart, vorname, nachname
|
||||
FROM persons
|
||||
WHERE person_id = :pid
|
||||
LIMIT 1");
|
||||
$stPerson->execute(['pid' => $personId]);
|
||||
$person = $stPerson->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$person) {
|
||||
return [false, 'Die Person wurde nicht gefunden.', null];
|
||||
}
|
||||
|
||||
$zeitraum = impfLoadZeitraumById($pdo, $zeitraumId, true);
|
||||
if (!$zeitraum) {
|
||||
return [false, 'Das ausgewaehlte Zeitfenster ist nicht mehr verfuegbar.', null];
|
||||
}
|
||||
if (!in_array($impfstoffId, $zeitraum['impfstoff_id_list'] ?? [], true)) {
|
||||
return [false, 'Impfstoff und Zeitfenster passen nicht zusammen.', null];
|
||||
}
|
||||
|
||||
$stDup = $pdo->prepare("SELECT warteid
|
||||
FROM warteliste
|
||||
WHERE userid = :uid
|
||||
AND checked IN (0, 1)
|
||||
AND impfstoff = :impfstoff
|
||||
AND COALESCE(zeitraum_id, 0) = :zeitraum_id
|
||||
AND impfart = :impfart
|
||||
LIMIT 1");
|
||||
$stDup->execute([
|
||||
'uid' => $personId,
|
||||
'impfstoff' => $impfstoffId,
|
||||
'zeitraum_id' => $zeitraumId,
|
||||
'impfart' => $impfart,
|
||||
]);
|
||||
if ($stDup->fetchColumn()) {
|
||||
return [false, 'Diese Anfrage ist fuer diese Person bereits auf der aktiven Warteliste vorhanden.', null];
|
||||
}
|
||||
|
||||
$patientenart = ((int)($person['patientenart'] ?? 0) === 1) ? 1 : 0;
|
||||
$hash = bin2hex(random_bytes(16));
|
||||
$checkedValue = ($checked === 0) ? 0 : 1;
|
||||
|
||||
$stInsert = $pdo->prepare("INSERT INTO warteliste
|
||||
(userid, checked, hash, impfenangebot, impfstoff, Patientenart, Impfaufklaerung, WeitereFragen, impfart, impfenmit, letzteimpfung, impfenzeitraum, zeitraum_id, date_created)
|
||||
VALUES
|
||||
(:userid, :checked, :hash, 1, :impfstoff, :patientenart, 0, 0, :impfart, '', :letzteimpfung, :impfenzeitraum, :zeitraum_id, NOW())");
|
||||
$stInsert->execute([
|
||||
'userid' => $personId,
|
||||
'checked' => $checkedValue,
|
||||
'hash' => $hash,
|
||||
'impfstoff' => $impfstoffId,
|
||||
'patientenart' => $patientenart,
|
||||
'impfart' => $impfart,
|
||||
'letzteimpfung' => $letzteImpfung,
|
||||
'impfenzeitraum' => (string)$zeitraum['label'],
|
||||
'zeitraum_id' => $zeitraumId,
|
||||
]);
|
||||
|
||||
$warteid = (int)$pdo->lastInsertId();
|
||||
$personName = trim((string)$person['vorname'] . ' ' . (string)$person['nachname']);
|
||||
|
||||
return [true, 'Wartelistenplatz fuer ' . $personName . ' wurde gespeichert.', $warteid];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user