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
+47 -27
View File
@@ -120,22 +120,12 @@ function workflowLoadWaitRowsForPlan(PDO $pdo, int $impfstoffId, int $planId): a
FROM warteliste w FROM warteliste w
WHERE w.checked = 1 WHERE w.checked = 1
AND (w.impfstoff = :iid OR w.impfstoff = 0) AND (w.impfstoff = :iid OR w.impfstoff = 0)
AND ( AND EXISTS (
EXISTS (
SELECT 1 SELECT 1
FROM warteliste_zeitraum wz FROM warteliste_zeitraum wz
WHERE wz.warteid = w.warteid WHERE wz.warteid = w.warteid
AND wz.zeitraum_id = :zid 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)
)
)
ORDER BY w.date_created ASC, w.warteid ASC"); ORDER BY w.date_created ASC, w.warteid ASC");
$stW->execute([ $stW->execute([
'iid' => $impfstoffId, 'iid' => $impfstoffId,
@@ -145,6 +135,26 @@ function workflowLoadWaitRowsForPlan(PDO $pdo, int $impfstoffId, int $planId): a
return $stW->fetchAll(PDO::FETCH_ASSOC); 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( function workflowAddWartelisteEntry(
PDO $pdo, PDO $pdo,
int $personId, int $personId,
@@ -665,6 +675,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$rules = []; $rules = [];
$plans = []; $plans = [];
$configuredImpfstoffe = []; $configuredImpfstoffe = [];
$configuredImpfstoffNames = [];
$eligible = []; $eligible = [];
$personResults = []; $personResults = [];
$waitRows = []; $waitRows = [];
@@ -700,6 +711,7 @@ try {
foreach ($rules as $r) { foreach ($rules as $r) {
$iid = (int)$r['impfstoff_id']; $iid = (int)$r['impfstoff_id'];
$configuredImpfstoffNames[$iid] = (string)$r['impfname'];
if (!isset($planExistsForImpfstoff[$iid])) { if (!isset($planExistsForImpfstoff[$iid])) {
continue; continue;
} }
@@ -721,7 +733,7 @@ try {
} }
$planId = (int)$plan['zeitraum_id']; $planId = (int)$plan['zeitraum_id'];
$planWaitCounts[$iid][$planId] = workflowCountWaitersForPlan($pdo, $iid, $planId); $planWaitCounts[$iid][$planId] = workflowCountStrictWaitersForPlan($pdo, $iid, $planId);
if ($planWaitCounts[$iid][$planId] >= $dosen) { if ($planWaitCounts[$iid][$planId] >= $dosen) {
$hasEligiblePlan = true; $hasEligiblePlan = true;
} }
@@ -893,7 +905,7 @@ try {
<?php if (!empty($w['zeitraum_labels'])): ?> <?php if (!empty($w['zeitraum_labels'])): ?>
<?php echo implode('<br>', array_map('esc', $w['zeitraum_labels'])); ?> <?php echo implode('<br>', array_map('esc', $w['zeitraum_labels'])); ?>
<?php else: ?> <?php else: ?>
<?php echo esc((string)$w['impfenzeitraum']); ?> <?php echo esc(impfLimitLabelLength((string)$w['impfenzeitraum'], 50)); ?>
<?php endif; ?> <?php endif; ?>
</td> </td>
<td> <td>
@@ -953,10 +965,11 @@ try {
<?php endif; ?> <?php endif; ?>
<?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="aktion" value="add_waitlist_existing">
<input type="hidden" name="person_search" value="<?php echo esc($personSearch); ?>"> <input type="hidden" name="person_search" value="<?php echo esc($personSearch); ?>">
<div class="form-group" style="display:block; margin-bottom:10px;">
<label>Patient</label> <label>Patient</label>
<select class="form-control" name="wl_person_id" required <?php echo empty($personResults) ? 'disabled' : ''; ?>> <select class="form-control" name="wl_person_id" required <?php echo empty($personResults) ? 'disabled' : ''; ?>>
<option value="">Bitte wählen</option> <option value="">Bitte wählen</option>
@@ -969,8 +982,10 @@ try {
<option value="<?php echo $pid; ?>" <?php echo $selected; ?>><?php echo esc($personLabel); ?></option> <option value="<?php echo $pid; ?>" <?php echo $selected; ?>><?php echo esc($personLabel); ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div>
<label style="margin-left:10px;">Impfstoff</label> <div class="form-group" style="display:block; margin-bottom:10px;">
<label>Impfstoff</label>
<select class="form-control" name="wl_impfstoff_id" id="existing_impfstoff"> <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> <option value="0" <?php echo ((int)($_POST['wl_impfstoff_id'] ?? 0) === 0) ? 'selected' : ''; ?>>Keine Vorgabe</option>
<?php foreach ($configuredImpfstoffe as $r): ?> <?php foreach ($configuredImpfstoffe as $r): ?>
@@ -983,8 +998,10 @@ try {
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div>
<label style="margin-left:10px;">Zeitfenster</label> <div class="form-group" style="display:block;">
<label>Zeitfenster</label>
<?php $selectedExistingPlanIds = impfNormalizeZeitraumIds($_POST['wl_plan_ids'] ?? ($_POST['wl_plan_id'] ?? [])); ?> <?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"> <select class="form-control" name="wl_plan_ids[]" id="existing_plan" multiple size="6">
<?php foreach ($plans as $p): ?> <?php foreach ($plans as $p): ?>
@@ -992,13 +1009,14 @@ try {
$planId = (int)$p['zeitraum_id']; $planId = (int)$p['zeitraum_id'];
$selected = in_array($planId, $selectedExistingPlanIds, true) ? 'selected' : ''; $selected = in_array($planId, $selectedExistingPlanIds, true) ? 'selected' : '';
$impfstoffeCsv = implode(',', $p['impfstoff_id_list']); $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; ?>> <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> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div>
<div class="workflow-action-row"> <div class="workflow-action-row">
<button class="btn btn-primary" type="submit" <?php echo empty($personResults) ? 'disabled' : ''; ?>> <button class="btn btn-primary" type="submit" <?php echo empty($personResults) ? 'disabled' : ''; ?>>
Zur Warteliste hinzufügen Zur Warteliste hinzufügen
@@ -1083,10 +1101,10 @@ try {
$planId = (int)$p['zeitraum_id']; $planId = (int)$p['zeitraum_id'];
$selected = in_array($planId, $selectedNewPlanIds, true) ? 'selected' : ''; $selected = in_array($planId, $selectedNewPlanIds, true) ? 'selected' : '';
$impfstoffeCsv = implode(',', $p['impfstoff_id_list']); $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; ?>> <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> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
@@ -1114,7 +1132,7 @@ try {
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"><strong>Konkretes Impfevent erstellen</strong></div> <div class="panel-heading"><strong>Konkretes Impfevent erstellen</strong></div>
<div class="panel-body"> <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;"> <form method="post" class="form-inline" style="margin-bottom:14px;">
<input type="hidden" name="aktion" value="create_event"> <input type="hidden" name="aktion" value="create_event">
@@ -1130,14 +1148,18 @@ try {
<select class="form-control" name="plan_id" id="event_plan" required> <select class="form-control" name="plan_id" id="event_plan" required>
<option value="">Bitte wählen</option> <option value="">Bitte wählen</option>
<?php foreach ($plans as $p): ?> <?php foreach ($plans as $p): ?>
<?php foreach (($p['impfstoff_id_list'] ?? []) as $planImpfstoffId): ?>
<?php <?php
$impfstoffeCsv = implode(',', $p['impfstoff_id_list']); $waiterCount = (int)($planWaitCounts[(int)$planImpfstoffId][(int)$p['zeitraum_id']] ?? 0);
$impfstoffeText = empty($p['impfstoff_name_list']) ? 'ohne Impfstoff' : implode(', ', $p['impfstoff_name_list']); if ($waiterCount <= 0) {
continue;
}
?> ?>
<option value="<?php echo (int)$p['zeitraum_id']; ?>" data-impfstoffe="<?php echo esc($impfstoffeCsv); ?>"> <option value="<?php echo (int)$p['zeitraum_id']; ?>" data-impfstoffe="<?php echo esc((string)$planImpfstoffId); ?>">
<?php echo esc(workflowPlanLabel($p) . ' | Impfstoffe: ' . $impfstoffeText); ?> <?php echo esc(workflowPlanLabel($p) . ' | Impfstoff: ' . ($configuredImpfstoffNames[(int)$planImpfstoffId] ?? 'Unbekannt') . ' | Wartende: ' . $waiterCount); ?>
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
<?php endforeach; ?>
</select> </select>
<label style="margin-left:10px;">Konkretes Datum</label> <label style="margin-left:10px;">Konkretes Datum</label>
@@ -1287,5 +1309,3 @@ try {
</div> </div>
<?php include __DIR__ . "/templates/footer.inc.php"; ?> <?php include __DIR__ . "/templates/footer.inc.php"; ?>
+6 -1
View File
@@ -289,6 +289,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($aktion === 'add_zeitraum') { if ($aktion === 'add_zeitraum') {
$bezeichnung = trim((string)($_POST['bezeichnung'] ?? '')); $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); $wochentag = (int)($_POST['wochentag'] ?? 0);
$start = trim((string)($_POST['start'] ?? '')); $start = trim((string)($_POST['start'] ?? ''));
$ende = trim((string)($_POST['ende'] ?? '')); $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;"> <form method="post" class="form-inline" style="margin-bottom:12px;">
<input type="hidden" name="aktion" value="add_zeitraum"> <input type="hidden" name="aktion" value="add_zeitraum">
<label>Bezeichnung</label> <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> <label style="margin-left:10px;">Wochentag</label>
<select class="form-control" name="wochentag" required> <select class="form-control" name="wochentag" required>
<option value="1">Montag</option> <option value="1">Montag</option>
+21 -6
View File
@@ -87,6 +87,26 @@ if (!function_exists('impfWeekdayName')) {
} }
} }
if (!function_exists('impfLimitLabelLength')) {
function impfLimitLabelLength(string $text, int $maxLength = 50): string
{
$text = trim($text);
if ($text === '') {
return $text;
}
if (function_exists('mb_strimwidth')) {
return rtrim(mb_strimwidth($text, 0, $maxLength, '...', 'UTF-8'));
}
if (strlen($text) <= $maxLength) {
return $text;
}
return rtrim(substr($text, 0, max(0, $maxLength - 3))) . '...';
}
}
if (!function_exists('impfWorkflowEnsureTables')) { if (!function_exists('impfWorkflowEnsureTables')) {
function impfWorkflowEnsureTables(PDO $pdo): void function impfWorkflowEnsureTables(PDO $pdo): void
{ {
@@ -336,12 +356,7 @@ if (!function_exists('impfZeitraumLabel')) {
$zeitText .= ' (' . $ortText . ')'; $zeitText .= ' (' . $ortText . ')';
} }
$bezeichnung = trim((string)($zeitraum['bezeichnung'] ?? '')); return impfLimitLabelLength($zeitText, 50);
if ($includeName && $bezeichnung !== '') {
return $bezeichnung . ': ' . $zeitText;
}
return $zeitText;
} }
} }