Impfverwaltung anpassen

This commit is contained in:
2026-03-30 21:52:10 +02:00
parent 091702c2a2
commit 6360af272a
3 changed files with 117 additions and 77 deletions
+90 -70
View File
@@ -120,21 +120,11 @@ function workflowLoadWaitRowsForPlan(PDO $pdo, int $impfstoffId, int $planId): a
FROM warteliste w
WHERE w.checked = 1
AND (w.impfstoff = :iid OR w.impfstoff = 0)
AND (
EXISTS (
SELECT 1
FROM warteliste_zeitraum wz
WHERE wz.warteid = w.warteid
AND wz.zeitraum_id = :zid
)
OR (
NOT EXISTS (
SELECT 1
FROM warteliste_zeitraum wz_none
WHERE wz_none.warteid = w.warteid
)
AND (w.zeitraum_id = :zid OR w.zeitraum_id IS NULL)
)
AND EXISTS (
SELECT 1
FROM warteliste_zeitraum wz
WHERE wz.warteid = w.warteid
AND wz.zeitraum_id = :zid
)
ORDER BY w.date_created ASC, w.warteid ASC");
$stW->execute([
@@ -145,6 +135,26 @@ function workflowLoadWaitRowsForPlan(PDO $pdo, int $impfstoffId, int $planId): a
return $stW->fetchAll(PDO::FETCH_ASSOC);
}
function workflowCountStrictWaitersForPlan(PDO $pdo, int $impfstoffId, int $planId): int
{
$stW = $pdo->prepare("SELECT COUNT(DISTINCT w.userid)
FROM warteliste w
WHERE w.checked = 1
AND (w.impfstoff = :iid OR w.impfstoff = 0)
AND EXISTS (
SELECT 1
FROM warteliste_zeitraum wz
WHERE wz.warteid = w.warteid
AND wz.zeitraum_id = :zid
)");
$stW->execute([
'iid' => $impfstoffId,
'zid' => $planId,
]);
return (int)$stW->fetchColumn();
}
function workflowAddWartelisteEntry(
PDO $pdo,
int $personId,
@@ -665,6 +675,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$rules = [];
$plans = [];
$configuredImpfstoffe = [];
$configuredImpfstoffNames = [];
$eligible = [];
$personResults = [];
$waitRows = [];
@@ -700,6 +711,7 @@ try {
foreach ($rules as $r) {
$iid = (int)$r['impfstoff_id'];
$configuredImpfstoffNames[$iid] = (string)$r['impfname'];
if (!isset($planExistsForImpfstoff[$iid])) {
continue;
}
@@ -721,7 +733,7 @@ try {
}
$planId = (int)$plan['zeitraum_id'];
$planWaitCounts[$iid][$planId] = workflowCountWaitersForPlan($pdo, $iid, $planId);
$planWaitCounts[$iid][$planId] = workflowCountStrictWaitersForPlan($pdo, $iid, $planId);
if ($planWaitCounts[$iid][$planId] >= $dosen) {
$hasEligiblePlan = true;
}
@@ -893,7 +905,7 @@ try {
<?php if (!empty($w['zeitraum_labels'])): ?>
<?php echo implode('<br>', array_map('esc', $w['zeitraum_labels'])); ?>
<?php else: ?>
<?php echo esc((string)$w['impfenzeitraum']); ?>
<?php echo esc(impfLimitLabelLength((string)$w['impfenzeitraum'], 50)); ?>
<?php endif; ?>
</td>
<td>
@@ -953,52 +965,58 @@ try {
<?php endif; ?>
<?php endif; ?>
<form method="post" class="form-inline">
<form method="post">
<input type="hidden" name="aktion" value="add_waitlist_existing">
<input type="hidden" name="person_search" value="<?php echo esc($personSearch); ?>">
<label>Patient</label>
<select class="form-control" name="wl_person_id" required <?php echo empty($personResults) ? 'disabled' : ''; ?>>
<option value="">Bitte wählen</option>
<?php foreach ($personResults as $p): ?>
<?php
$pid = (int)$p['person_id'];
$selected = ((int)($_POST['wl_person_id'] ?? 0) === $pid) ? 'selected' : '';
$personLabel = trim((string)$p['nachname'] . ', ' . (string)$p['vorname']) . ' | ' . (string)$p['geburtstag'] . ' | ' . (string)$p['email'];
?>
<option value="<?php echo $pid; ?>" <?php echo $selected; ?>><?php echo esc($personLabel); ?></option>
<?php endforeach; ?>
</select>
<div class="form-group" style="display:block; margin-bottom:10px;">
<label>Patient</label>
<select class="form-control" name="wl_person_id" required <?php echo empty($personResults) ? 'disabled' : ''; ?>>
<option value="">Bitte wählen</option>
<?php foreach ($personResults as $p): ?>
<?php
$pid = (int)$p['person_id'];
$selected = ((int)($_POST['wl_person_id'] ?? 0) === $pid) ? 'selected' : '';
$personLabel = trim((string)$p['nachname'] . ', ' . (string)$p['vorname']) . ' | ' . (string)$p['geburtstag'] . ' | ' . (string)$p['email'];
?>
<option value="<?php echo $pid; ?>" <?php echo $selected; ?>><?php echo esc($personLabel); ?></option>
<?php endforeach; ?>
</select>
</div>
<label style="margin-left:10px;">Impfstoff</label>
<select class="form-control" name="wl_impfstoff_id" id="existing_impfstoff">
<option value="0" <?php echo ((int)($_POST['wl_impfstoff_id'] ?? 0) === 0) ? 'selected' : ''; ?>>Keine Vorgabe</option>
<?php foreach ($configuredImpfstoffe as $r): ?>
<?php
$iid = (int)$r['impfstoff_id'];
$selected = ((int)($_POST['wl_impfstoff_id'] ?? 0) === $iid) ? 'selected' : '';
?>
<option value="<?php echo $iid; ?>" <?php echo $selected; ?>>
<?php echo esc($r['impfname'] . ' (Dosen: ' . $r['dosen_pro_flasche'] . ')'); ?>
</option>
<?php endforeach; ?>
</select>
<div class="form-group" style="display:block; margin-bottom:10px;">
<label>Impfstoff</label>
<select class="form-control" name="wl_impfstoff_id" id="existing_impfstoff">
<option value="0" <?php echo ((int)($_POST['wl_impfstoff_id'] ?? 0) === 0) ? 'selected' : ''; ?>>Keine Vorgabe</option>
<?php foreach ($configuredImpfstoffe as $r): ?>
<?php
$iid = (int)$r['impfstoff_id'];
$selected = ((int)($_POST['wl_impfstoff_id'] ?? 0) === $iid) ? 'selected' : '';
?>
<option value="<?php echo $iid; ?>" <?php echo $selected; ?>>
<?php echo esc($r['impfname'] . ' (Dosen: ' . $r['dosen_pro_flasche'] . ')'); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<label style="margin-left:10px;">Zeitfenster</label>
<?php $selectedExistingPlanIds = impfNormalizeZeitraumIds($_POST['wl_plan_ids'] ?? ($_POST['wl_plan_id'] ?? [])); ?>
<select class="form-control" name="wl_plan_ids[]" id="existing_plan" multiple size="6">
<?php foreach ($plans as $p): ?>
<?php
$planId = (int)$p['zeitraum_id'];
$selected = in_array($planId, $selectedExistingPlanIds, true) ? 'selected' : '';
$impfstoffeCsv = implode(',', $p['impfstoff_id_list']);
$impfstoffeText = empty($p['impfstoff_name_list']) ? 'ohne Impfstoff' : implode(', ', $p['impfstoff_name_list']);
?>
<option value="<?php echo $planId; ?>" data-impfstoffe="<?php echo esc($impfstoffeCsv); ?>" <?php echo $selected; ?>>
<?php echo esc(workflowPlanLabel($p) . ' | Impfstoffe: ' . $impfstoffeText); ?>
</option>
<?php endforeach; ?>
</select>
<div class="form-group" style="display:block;">
<label>Zeitfenster</label>
<?php $selectedExistingPlanIds = impfNormalizeZeitraumIds($_POST['wl_plan_ids'] ?? ($_POST['wl_plan_id'] ?? [])); ?>
<select class="form-control" name="wl_plan_ids[]" id="existing_plan" multiple size="6">
<?php foreach ($plans as $p): ?>
<?php
$planId = (int)$p['zeitraum_id'];
$selected = in_array($planId, $selectedExistingPlanIds, true) ? 'selected' : '';
$impfstoffeCsv = implode(',', $p['impfstoff_id_list']);
$optionLabel = workflowPlanLabel($p);
?>
<option value="<?php echo $planId; ?>" data-impfstoffe="<?php echo esc($impfstoffeCsv); ?>" <?php echo $selected; ?>>
<?php echo esc($optionLabel); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="workflow-action-row">
<button class="btn btn-primary" type="submit" <?php echo empty($personResults) ? 'disabled' : ''; ?>>
Zur Warteliste hinzufügen
@@ -1083,10 +1101,10 @@ try {
$planId = (int)$p['zeitraum_id'];
$selected = in_array($planId, $selectedNewPlanIds, true) ? 'selected' : '';
$impfstoffeCsv = implode(',', $p['impfstoff_id_list']);
$impfstoffeText = empty($p['impfstoff_name_list']) ? 'ohne Impfstoff' : implode(', ', $p['impfstoff_name_list']);
$optionLabel = workflowPlanLabel($p);
?>
<option value="<?php echo $planId; ?>" data-impfstoffe="<?php echo esc($impfstoffeCsv); ?>" <?php echo $selected; ?>>
<?php echo esc(workflowPlanLabel($p) . ' | Impfstoffe: ' . $impfstoffeText); ?>
<?php echo esc($optionLabel); ?>
</option>
<?php endforeach; ?>
</select>
@@ -1114,7 +1132,7 @@ try {
<div class="panel panel-default">
<div class="panel-heading"><strong>Konkretes Impfevent erstellen</strong></div>
<div class="panel-body">
<p>Es werden nur Impfstoffe angeboten, bei denen die bestätigte Warteliste mindestens eine Flasche füllt.</p>
<p>Es werden nur Impfstoffe und Zeiträume angeboten, bei denen die bestätigte Warteliste mindestens eine Flasche füllt und die Wartenden diesen Zeitraum auch ausdrücklich gewählt haben.</p>
<form method="post" class="form-inline" style="margin-bottom:14px;">
<input type="hidden" name="aktion" value="create_event">
@@ -1130,13 +1148,17 @@ try {
<select class="form-control" name="plan_id" id="event_plan" required>
<option value="">Bitte wählen</option>
<?php foreach ($plans as $p): ?>
<?php
$impfstoffeCsv = implode(',', $p['impfstoff_id_list']);
$impfstoffeText = empty($p['impfstoff_name_list']) ? 'ohne Impfstoff' : implode(', ', $p['impfstoff_name_list']);
?>
<option value="<?php echo (int)$p['zeitraum_id']; ?>" data-impfstoffe="<?php echo esc($impfstoffeCsv); ?>">
<?php echo esc(workflowPlanLabel($p) . ' | Impfstoffe: ' . $impfstoffeText); ?>
</option>
<?php foreach (($p['impfstoff_id_list'] ?? []) as $planImpfstoffId): ?>
<?php
$waiterCount = (int)($planWaitCounts[(int)$planImpfstoffId][(int)$p['zeitraum_id']] ?? 0);
if ($waiterCount <= 0) {
continue;
}
?>
<option value="<?php echo (int)$p['zeitraum_id']; ?>" data-impfstoffe="<?php echo esc((string)$planImpfstoffId); ?>">
<?php echo esc(workflowPlanLabel($p) . ' | Impfstoff: ' . ($configuredImpfstoffNames[(int)$planImpfstoffId] ?? 'Unbekannt') . ' | Wartende: ' . $waiterCount); ?>
</option>
<?php endforeach; ?>
<?php endforeach; ?>
</select>
@@ -1287,5 +1309,3 @@ try {
</div>
<?php include __DIR__ . "/templates/footer.inc.php"; ?>
+6 -1
View File
@@ -289,6 +289,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($aktion === 'add_zeitraum') {
$bezeichnung = trim((string)($_POST['bezeichnung'] ?? ''));
if (function_exists('mb_substr')) {
$bezeichnung = mb_substr($bezeichnung, 0, 50, 'UTF-8');
} else {
$bezeichnung = substr($bezeichnung, 0, 50);
}
$wochentag = (int)($_POST['wochentag'] ?? 0);
$start = trim((string)($_POST['start'] ?? ''));
$ende = trim((string)($_POST['ende'] ?? ''));
@@ -608,7 +613,7 @@ $rules = $stRules->fetchAll(PDO::FETCH_ASSOC);
<form method="post" class="form-inline" style="margin-bottom:12px;">
<input type="hidden" name="aktion" value="add_zeitraum">
<label>Bezeichnung</label>
<input class="form-control" type="text" name="bezeichnung" placeholder="z. B. Mittwoch Vormittag">
<input class="form-control" type="text" name="bezeichnung" maxlength="50" placeholder="z. B. Mittwoch Vormittag">
<label style="margin-left:10px;">Wochentag</label>
<select class="form-control" name="wochentag" required>
<option value="1">Montag</option>