Add zeitraum_id to warteliste and update related queries; enhance impfWorkflow functions

This commit is contained in:
2026-03-20 19:48:56 +01:00
parent 8d40855402
commit 780da7913a
4 changed files with 123 additions and 17 deletions
+45 -8
View File
@@ -172,11 +172,12 @@ function workflowAddWartelisteEntry(
$hash = md5('admin-warte-' . $personId . '-' . microtime(true) . '-' . random_int(1000, 9999));
$checkedValue = ($checked === 0) ? 0 : 1;
$letzteValue = ($impfart === 1) ? null : ($letzteImpfung ?: null);
$zeitraumIdValue = ($planId > 0) ? $planId : null;
$stInsert = $pdo->prepare("INSERT INTO warteliste
(userid, checked, hash, impfenangebot, impfstoff, Patientenart, Impfaufklaerung, WeitereFragen, impfart, impfenmit, letzteimpfung, impfenzeitraum, date_created)
(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, NOW())");
(:userid, :checked, :hash, 1, :impfstoff, :patientenart, 0, 0, :impfart, '', :letzteimpfung, :impfenzeitraum, :zeitraum_id, NOW())");
$stInsert->execute([
'userid' => $personId,
'checked' => $checkedValue,
@@ -186,6 +187,7 @@ function workflowAddWartelisteEntry(
'impfart' => $impfart,
'letzteimpfung' => $letzteValue,
'impfenzeitraum' => $zeitraum,
'zeitraum_id' => $zeitraumIdValue,
]);
$personName = trim((string)$person['vorname'] . ' ' . (string)$person['nachname']);
@@ -233,15 +235,35 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} else {
$dosen = (int)$rule['dosen_pro_flasche'];
$stCount = $pdo->prepare("SELECT COUNT(*) FROM warteliste WHERE checked = 1 AND (impfstoff = :iid OR impfstoff = 0)");
$stCount->execute(['iid' => $impfstoffId]);
$stCount = $pdo->prepare("SELECT COUNT(*)
FROM warteliste
WHERE checked = 1
AND (impfstoff = :iid OR impfstoff = 0)
AND (zeitraum_id = :zid OR zeitraum_id IS NULL)");
$stCount->execute([
'iid' => $impfstoffId,
'zid' => $planId,
]);
$wartende = (int)$stCount->fetchColumn();
if ($wartende < $dosen) {
$error = "Nicht genug bestätigte Warteteilnehmer: {$wartende} von {$dosen}.";
} else {
$stDup = $pdo->prepare("SELECT timeid FROM timeslots WHERE date = :date AND start = :start AND impfstoff = :iid LIMIT 1");
$stDup->execute(['date' => $datum, 'start' => $plan['start'], 'iid' => $impfstoffId]);
$stDup = $pdo->prepare("SELECT timeid
FROM timeslots
WHERE date = :date
AND start = :start
AND ende = :ende
AND impfortid = :oid
AND impfstoff = :iid
LIMIT 1");
$stDup->execute([
'date' => $datum,
'start' => $plan['start'],
'ende' => $plan['ende'],
'oid' => (int)$plan['impfortid'],
'iid' => $impfstoffId,
]);
if ($stDup->fetch()) {
$error = "Für diesen Impfstoff existiert am gewählten Datum/Zeit bereits ein Event.";
@@ -266,10 +288,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stW = $pdo->prepare("SELECT warteid, userid, hash, impfart, Impfaufklaerung, WeitereFragen, letzteimpfung
FROM warteliste
WHERE checked = 1 AND (impfstoff = :iid OR impfstoff = 0)
WHERE checked = 1
AND (impfstoff = :iid OR impfstoff = 0)
AND (zeitraum_id = :zid OR zeitraum_id IS NULL)
ORDER BY date_created ASC, warteid ASC
LIMIT :lim");
$stW->bindValue(':iid', $impfstoffId, PDO::PARAM_INT);
$stW->bindValue(':zid', $planId, PDO::PARAM_INT);
$stW->bindValue(':lim', $dosen, PDO::PARAM_INT);
$stW->execute();
$warteRows = $stW->fetchAll(PDO::FETCH_ASSOC);
@@ -518,6 +543,7 @@ try {
COALESCE((SELECT COUNT(*) FROM warteliste w WHERE w.checked = 1 AND (w.impfstoff = r.impfstoff_id OR w.impfstoff = 0)),0) AS wartende
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)
ORDER BY i.impfname");
$stRules->execute();
$rules = $stRules->fetchAll(PDO::FETCH_ASSOC);
@@ -561,7 +587,7 @@ try {
$personResults = $stPersons->fetchAll(PDO::FETCH_ASSOC);
}
$stWait = $pdo->prepare("SELECT w.warteid, w.userid, w.checked, w.impfstoff, w.impfart, w.impfenzeitraum, w.letzteimpfung, w.date_created,
$stWait = $pdo->prepare("SELECT w.warteid, w.userid, w.checked, w.impfstoff, w.impfart, w.impfenzeitraum, w.zeitraum_id, w.letzteimpfung, w.date_created,
p.vorname, p.nachname, p.geburtstag, p.email, p.tele,
i.impfname
FROM warteliste w
@@ -573,6 +599,17 @@ try {
$stWait->execute();
$waitRows = $stWait->fetchAll(PDO::FETCH_ASSOC);
foreach ($waitRows as &$waitRow) {
$zeitraumId = (int)($waitRow['zeitraum_id'] ?? 0);
if ($zeitraumId > 0) {
$zeitraum = impfLoadZeitraumById($pdo, $zeitraumId, true);
if ($zeitraum) {
$waitRow['impfenzeitraum'] = $zeitraum['label'];
}
}
}
unset($waitRow);
$stUpcoming = $pdo->prepare("SELECT ts.timeid, ts.date, ts.start, ts.ende, ts.impfdosen,
i.impfname, o.anzeigename, o.adresse,
it.terminid, it.checked, it.behandelt, it.impfart,
+12 -7
View File
@@ -296,32 +296,37 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($wochentag < 1 || $wochentag > 7 || $start === '' || $ende === '' || $impfortId <= 0) {
$error = "Bitte Zeitraum vollstaendig ausfuellen.";
} elseif ($ende <= $start) {
$error = "Die Endzeit muss nach der Startzeit liegen.";
} else {
$startSql = $start . ':00';
$endeSql = $ende . ':00';
$stExisting = $pdo->prepare("SELECT zeitraum_id
$stExisting = $pdo->prepare("SELECT zeitraum_id, bezeichnung
FROM impf_zeitraum
WHERE bezeichnung = :bezeichnung
AND wochentag = :wochentag
WHERE wochentag = :wochentag
AND start = :start
AND ende = :ende
AND impfortid = :impfortid
LIMIT 1");
$stExisting->execute([
'bezeichnung' => $bezeichnung,
'wochentag' => $wochentag,
'start' => $startSql,
'ende' => $endeSql,
'impfortid' => $impfortId,
]);
$existingId = (int)($stExisting->fetchColumn() ?: 0);
$existingRow = $stExisting->fetch(PDO::FETCH_ASSOC) ?: null;
$existingId = (int)($existingRow['zeitraum_id'] ?? 0);
if ($existingId > 0) {
$stUpdate = $pdo->prepare("UPDATE impf_zeitraum
SET aktiv = 1
SET bezeichnung = :bezeichnung,
aktiv = 1
WHERE zeitraum_id = :zid");
$stUpdate->execute(['zid' => $existingId]);
$stUpdate->execute([
'bezeichnung' => $bezeichnung,
'zid' => $existingId,
]);
$message = "Zeitraum wurde reaktiviert.";
} else {
$st = $pdo->prepare("INSERT INTO impf_zeitraum (bezeichnung, wochentag, start, ende, impfortid, aktiv)