med: add time override

This commit is contained in:
ゆめ 2022-11-16 20:09:07 -06:00
parent da5f974e68
commit b49830aaef
3 changed files with 52 additions and 8 deletions

View file

@ -66,11 +66,6 @@
<script>
(function () {
"use struct";
const dateInZone = (zone) => {
if (zone)
return new Date(new Date().toLocaleString("en-US", { timeZone: zone }));
return new Date()
}
const timeInZone = (zone) => {
const date = dateInZone(zone);
var h = date.getHours(); // 0 - 23
@ -87,7 +82,7 @@
</p>${zone ? "" : "<hr>"}
`
}
const zones = ["", "America/Los_Angeles", "America/New_York",
const zones = ["", "America/Los_Angeles", "America/New_York", "America/Chicago",
"Asia/Tokyo", "Asia/Shanghai", "UTC"]
let update = () => {
var date = new Date();

View file

@ -55,6 +55,20 @@
<div class="col-auto">
<input type="number" class="form-control" id="dosage">
</div>
<div class="col-auto">
<label for="time" class="form-label">Time Override: </label>
</div>
<div class="col-auto">
<div class="input-group">
<span class="input-group-text">
<input type="checkbox" class="form-check-input"
id="time-override">
</span>
<input type="datetime-local" class="form-control" id="time">
</div>
</div>
<div class="col-auto">
<input type="submit" class="btn btn-primary mt-2" value="Submit">
</div>
@ -262,6 +276,7 @@
medTakeForm.onsubmit = e => {
e.preventDefault();
let dosage = medTakeForm.querySelector("input#dosage").value
let time = medTakeForm.querySelector("input#time").value
if (confirm("Really Submit?"))
$.ajax({
url: "/api/health/meds/compliance/log",
@ -270,7 +285,7 @@
data: JSON.stringify({
med_keyname: medKeyName(med.name),
actual: {
time: dayjs().format(),
time: dayjs(time || undefined).format(),
dose: parseInt(dosage)
},
}),
@ -319,7 +334,35 @@
}
medTakeForm.querySelector("input#dosage").value = data.expected.dose
medTakeForm.querySelector("input#time").onkeyup =
medTakeForm.querySelector("input#time").onchange =
e => {
const target = e.target
if (target.validity.badInput || dayjs(target.value) > dayjs()) {
target.classList.add("text-danger")
target.classList.remove("text-success")
medTakeForm.querySelector("input[type=submit]").disabled = true
} else if (target.value == "") {
target.classList.remove("text-danger")
target.classList.remove("text-success")
medTakeForm.querySelector("input[type=submit]").disabled = false
} else if (dayjs(target.value).isValid()) {
target.classList.remove("text-danger")
target.classList.add("text-success")
medTakeForm.querySelector("input[type=submit]").disabled = false
}
}
medTakeForm.querySelector("input#time-override").onchange = e => {
const target = e.target
if (target.checked) {
medTakeForm.querySelector("input#time").disabled = false
medTakeForm.querySelector("input#time").value = dayjs().format("YYYY-MM-DDTHH:mm")
} else {
medTakeForm.querySelector("input#time").value = null
medTakeForm.querySelector("input#time").disabled = true
}
medTakeForm.querySelector("input#time").dispatchEvent(new CustomEvent("change"))
}
$.ajax({
url: "/api/health/meds/compliance/med/" + medKeyName(med.name) + "/log",
type: "GET",

View file

@ -11,4 +11,10 @@ function labelTimeElement(tag, time) {
tag.setAttribute("data-bs-toggle", "tooltip");
tag.setAttribute("data-bs-title", time.format("L LT"));
new bootstrap.Tooltip(tag);
}
function dateInZone(zone) {
if (zone)
return new Date(new Date().toLocaleString("en-US", { timeZone: zone }));
return new Date()
}