Skip to content

Commit

Permalink
0.4.4: MAR Implementation (#11)
Browse files Browse the repository at this point in the history
Fixed logic re: category 'once' doses treated like 'prn'
Implemented calculating if 'prn' dose is available
- If available, show in MAR view as "Available"
- Otherwise, show last dose given (within the time period)
  • Loading branch information
tanjera committed Apr 25, 2024
1 parent 6686667 commit 1911902
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
17 changes: 17 additions & 0 deletions base/app/Models/Chart/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,21 @@ public function textPeriodtype() : string
public static array $periodunits_text = [
'Minutes', 'Hours', 'Days', 'Weeks'
];
public function getPeriodMinutes() : int
{
switch ($this->period_unit) {
default:
case 'minute':
return $this->period_amount;

case 'hour':
return $this->period_amount * 60;

case 'day':
return $this->period_amount * 60 * 24;

case 'week':
return $this->period_amount * 60 * 24 * 7;
}
}
}
27 changes: 22 additions & 5 deletions base/resources/views/chart/mar/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,44 @@
$off_min = intval($at_time->format('i'));
$range_amount = 4;
$range_start = (clone $at_time)->sub(new \DateInterval('PT' . (($range_amount * 60) + $off_min) . 'M'));
$range_end = (clone $at_time)->add(new \DateInterval('PT' . ((($range_amount + 1) * 60) - $off_min) . 'M'));
$range_end = (clone $at_time)->add(new \DateInterval('PT' . ((($range_amount + 1) * 60) - $off_min - 1) . 'M59S'));
$order_doses = $doses->where('order', $order->id);
$range_doses = $doses->where('order', $order->id)
->whereBetween('due_at', [$range_start, $range_end]);
@endphp

@for($i = -$range_amount; $i <= $range_amount; $i++)
@php
$temp_dose = false;
$col_start = clone $at_time;
if ($i <= 0)
$col_start->sub(new \DateInterval('PT' . ((abs($i) * 60) + $off_min) . 'M'));
else
$col_start->add(new \DateInterval('PT' . (($i * 60) - $off_min) . 'M'));
$col_end = (clone $col_start)->add(new \DateInterval('PT1H'));
$col_end = (clone $col_start)->add(new \DateInterval('PT59M59S'));
if (count($range_doses) > 0)
$col_doses = $range_doses->whereBetween('due_at', [$col_start, $col_end]);
else
$col_doses = null;
else {
$col_doses = [];
if ($i == 0 && $order->status == 'active' && $order->period_type == 'prn'){
if (count($order_doses) == 0)
$temp_dose = true;
else {
$period_span = (clone $at_time)->sub(new DateInterval('PT' . $order->getPeriodMinutes() . 'M'));
if (count($order_doses->whereBetween('due_at', [$period_span, $at_time])) == 0)
$temp_dose = true;
}
}
}
@endphp

@if(!is_null($col_doses) && count($col_doses) > 0)
@if(count($col_doses) > 0 || $temp_dose == true)
@if($order->status != 'active')
<td class="border-1 border-gray text-center align-middle p-2" style="background: #ffe6ea">
@elseif($order->period_type == 'prn')
Expand All @@ -161,6 +175,9 @@
Auth::user()->adjustDateTime($col_doses->first()->due_at)->format("H:i") }}</p>
@elseif(count($col_doses) > 1)
{{ count($col_doses) }} Doses
@elseif($temp_dose == true)
<p>{{ $order->dose_amount . " " . $order->textDoseunit() . " " . $order->textRoute() }}</p>
<p>Available</p>
@endif

</span>
Expand Down

0 comments on commit 1911902

Please sign in to comment.