feat: suivre la température pendant les tournées
This commit is contained in:
parent
68590eddbb
commit
d35434c522
15 changed files with 129 additions and 23 deletions
|
|
@ -704,6 +704,21 @@ trait AnimalBrowseActions
|
|||
$weightsStmt->execute([':id' => $id]);
|
||||
$weights = $weightsStmt->fetchAll();
|
||||
|
||||
$temperaturesStmt = $db->prepare("
|
||||
SELECT measured_at, value FROM (
|
||||
SELECT noted_at AS measured_at, temperature_c AS value
|
||||
FROM medical_notes
|
||||
WHERE animal_id = :medical_id AND temperature_c IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT observation.checked_at AS measured_at, observation.temperature_c AS value
|
||||
FROM care_round_observations observation
|
||||
WHERE observation.animal_id = :round_id AND observation.temperature_c IS NOT NULL
|
||||
)
|
||||
ORDER BY datetime(measured_at) ASC
|
||||
");
|
||||
$temperaturesStmt->execute([':medical_id' => $id, ':round_id' => $id]);
|
||||
$temperatures = $temperaturesStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$stmt = $db->prepare("
|
||||
SELECT value
|
||||
FROM measurements
|
||||
|
|
@ -952,6 +967,7 @@ trait AnimalBrowseActions
|
|||
'adopters' => $adopters,
|
||||
'death' => $death,
|
||||
'weights' => $weights,
|
||||
'temperatures' => $temperatures,
|
||||
'lastWeight' => $lastWeight,
|
||||
'prevWeight' => $prevWeight,
|
||||
'photos' => $photos,
|
||||
|
|
|
|||
|
|
@ -139,6 +139,18 @@ final class CareRoundsController
|
|||
$value = (string) ($_POST[$field] ?? $opts[0]);
|
||||
$values[$field] = in_array($value, $opts, true) ? $value : $opts[0];
|
||||
}
|
||||
$temperatureInput = str_replace(',', '.', trim((string) ($_POST['temperature_c'] ?? '')));
|
||||
if (!is_numeric($temperatureInput)) {
|
||||
http_response_code(400);
|
||||
echo h(t('care.invalid_temperature'));
|
||||
return;
|
||||
}
|
||||
$temperature = (float) $temperatureInput;
|
||||
if ($temperature < 30 || $temperature > 45) {
|
||||
http_response_code(400);
|
||||
echo h(t('care.invalid_temperature'));
|
||||
return;
|
||||
}
|
||||
$db->prepare(
|
||||
'UPDATE care_rounds SET performed_by_user_id=COALESCE(performed_by_user_id,:user) WHERE id=:id',
|
||||
)->execute([':user' => Auth::id(), ':id' => $roundId]);
|
||||
|
|
@ -220,7 +232,7 @@ final class CareRoundsController
|
|||
$db->beginTransaction();
|
||||
try {
|
||||
$stmt = $db->prepare(
|
||||
"INSERT INTO care_round_observations(round_id,animal_id,food,water,urine,stool,general_state,comment,alert_signature) VALUES(:round,:animal,:food,:water,:urine,:stool,:general,:comment,:signature) ON CONFLICT(round_id,animal_id) DO UPDATE SET food=excluded.food,water=excluded.water,urine=excluded.urine,stool=excluded.stool,general_state=excluded.general_state,comment=excluded.comment,alert_signature=excluded.alert_signature,checked_at=datetime('now')",
|
||||
"INSERT INTO care_round_observations(round_id,animal_id,food,water,urine,stool,general_state,temperature_c,comment,alert_signature) VALUES(:round,:animal,:food,:water,:urine,:stool,:general,:temperature,:comment,:signature) ON CONFLICT(round_id,animal_id) DO UPDATE SET food=excluded.food,water=excluded.water,urine=excluded.urine,stool=excluded.stool,general_state=excluded.general_state,temperature_c=excluded.temperature_c,comment=excluded.comment,alert_signature=excluded.alert_signature,checked_at=datetime('now')",
|
||||
);
|
||||
$stmt->execute([
|
||||
':round' => $roundId,
|
||||
|
|
@ -230,6 +242,7 @@ final class CareRoundsController
|
|||
':urine' => $values['urine'],
|
||||
':stool' => $values['stool'],
|
||||
':general' => $values['general_state'],
|
||||
':temperature' => $temperature,
|
||||
':comment' => $comment ?: null,
|
||||
':signature' => $signature,
|
||||
]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue