med: add time override
This commit is contained in:
parent
da5f974e68
commit
b49830aaef
3 changed files with 52 additions and 8 deletions
|
@ -66,11 +66,6 @@
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
"use struct";
|
"use struct";
|
||||||
const dateInZone = (zone) => {
|
|
||||||
if (zone)
|
|
||||||
return new Date(new Date().toLocaleString("en-US", { timeZone: zone }));
|
|
||||||
return new Date()
|
|
||||||
}
|
|
||||||
const timeInZone = (zone) => {
|
const timeInZone = (zone) => {
|
||||||
const date = dateInZone(zone);
|
const date = dateInZone(zone);
|
||||||
var h = date.getHours(); // 0 - 23
|
var h = date.getHours(); // 0 - 23
|
||||||
|
@ -87,7 +82,7 @@
|
||||||
</p>${zone ? "" : "<hr>"}
|
</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"]
|
"Asia/Tokyo", "Asia/Shanghai", "UTC"]
|
||||||
let update = () => {
|
let update = () => {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
|
|
|
@ -55,6 +55,20 @@
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<input type="number" class="form-control" id="dosage">
|
<input type="number" class="form-control" id="dosage">
|
||||||
</div>
|
</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">
|
<div class="col-auto">
|
||||||
<input type="submit" class="btn btn-primary mt-2" value="Submit">
|
<input type="submit" class="btn btn-primary mt-2" value="Submit">
|
||||||
</div>
|
</div>
|
||||||
|
@ -262,6 +276,7 @@
|
||||||
medTakeForm.onsubmit = e => {
|
medTakeForm.onsubmit = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let dosage = medTakeForm.querySelector("input#dosage").value
|
let dosage = medTakeForm.querySelector("input#dosage").value
|
||||||
|
let time = medTakeForm.querySelector("input#time").value
|
||||||
if (confirm("Really Submit?"))
|
if (confirm("Really Submit?"))
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/api/health/meds/compliance/log",
|
url: "/api/health/meds/compliance/log",
|
||||||
|
@ -270,7 +285,7 @@
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
med_keyname: medKeyName(med.name),
|
med_keyname: medKeyName(med.name),
|
||||||
actual: {
|
actual: {
|
||||||
time: dayjs().format(),
|
time: dayjs(time || undefined).format(),
|
||||||
dose: parseInt(dosage)
|
dose: parseInt(dosage)
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
@ -319,7 +334,35 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
medTakeForm.querySelector("input#dosage").value = data.expected.dose
|
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({
|
$.ajax({
|
||||||
url: "/api/health/meds/compliance/med/" + medKeyName(med.name) + "/log",
|
url: "/api/health/meds/compliance/med/" + medKeyName(med.name) + "/log",
|
||||||
type: "GET",
|
type: "GET",
|
||||||
|
|
|
@ -12,3 +12,9 @@ function labelTimeElement(tag, time) {
|
||||||
tag.setAttribute("data-bs-title", time.format("L LT"));
|
tag.setAttribute("data-bs-title", time.format("L LT"));
|
||||||
new bootstrap.Tooltip(tag);
|
new bootstrap.Tooltip(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dateInZone(zone) {
|
||||||
|
if (zone)
|
||||||
|
return new Date(new Date().toLocaleString("en-US", { timeZone: zone }));
|
||||||
|
return new Date()
|
||||||
|
}
|
Loading…
Reference in a new issue