[% # INCLUDE dumper.tt dump = data.packs;
USE today = DateTime(today = 1); # INCLUDE dumper.tt dump = today;
USE format; USE year_as_yy = format('%02d');
%]
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title">Your current pack status</h4>
</div>
<div class="panel-body">
[% current = data.packs.first; # INCLUDE dumper.tt dump = current %]
[% IF current.request_status.match('complete') %]
[% # if pack_due on or after today:
IF current.pack_due AND current.pack_due >= today %]
<span class="text-success">
Next assessment is due on [% current.pack_due.strftime('%d.%b.%Y') %]
</span>
[% # if pack_due before today and pack_sent before today:
ELSIF current.pack_sent AND current.pack_sent < today;
# INCLUDE dumper.tt dump = current.pack_sent name = 'pre';
delta_pack_sent = current.pack_sent.delta_days(today).delta_days;
class = delta_pack_sent > 7 ? 'danger' : 'success';
# INCLUDE dumper.tt dump = delta_pack_sent; %]
<span class="text-[% class %]">
A pack was sent on [% current.pack_sent.strftime('%d.%b.%Y') %]
[[% delta_pack_sent %] days ago]
[% IF class.match('danger') %] but has not been received. Please
call us to discuss.[% END %]
</span>
[% ELSIF current.pack_due AND NOT current.pack_sent # pack due before today and pack not sent: %]
<span class="text-danger">Pack was due for dispatch on
[% current.pack_due.strftime('%d.%b.%Y') %] but has not been sent.
Please call us to discuss.
</span>
[% ELSE # ? no pack_due date ? %]
<span class="text-success">[% current.outcome.ucfirst %]</span>
<!-- pack_due: [% current.pack_due.strftime('%d.%b.%Y') %]
pack_sent: [% current.pack_sent.strftime('%d.%b.%Y') %]
-->
[% END %]
[% ELSIF current.section_data_count > 1 %]
<span class="text-success">
A pack was received on [% current.registered.strftime('%d.%b.%Y') %] and
initial results indicate that no urgent action is required. It may take
three weeks to obtain all the laboratory test results but we will contact
your GP if there are any issues.
</span>
[% ELSIF current.request_status.match('new|screened') %]
<span class="text-success">
A pack was received on [% current.registered.strftime('%d.%b.%Y') %] and
laboratory tests have been initiated.
</span>
[% ELSE %]<span class="text-danger">** UNKNOWN RECORD STATUS - CHECK DETAILS **</span>
[% END %]
</div>
</div>
<div class="indent">
<button class="btn btn-primary" type="button" data-toggle="collapse"
data-target="#recentpacks" aria-expanded="false"
aria-controls="recentpacks">view details of your [% data.packs.size %] most
recent pack[% 's' IF data.packs.size > 1 %]
</button>
</div>
<div class="collapse" id="recentpacks">
<div class="indent well">
<table class="table table-striped table-condensed indent packs">
<tr>
<th>Pack</th>
<th>Received</th>
<th>Lab number</th>
<th>Action</th>
<th>Pack sent</th>
</tr>
[% FOREACH entry IN data.packs.reverse; # because data collected in reverse order
NEXT IF entry.option.match('dead'); # oops
%]
<tr class="[% loop.last ? 'text-success bold' : 'normal' %]">
<td>#[% loop.count %]</td>
<td>[% entry.registered.strftime('%d.%b.%Y') %]</td>
<td>[% entry.request_number %]/[%# use String(entry.year - 2000); # gives .t error!!
String.format('%02d') %][% year_as_yy(entry.year - 2000) %]
</td>
<td>
[%
IF entry.option.match('month'); 'next pack ';
IF loop.last AND entry.pack_due AND NOT entry.pack_sent;
entry.outcome = ' due out ' _ entry.pack_due.strftime('%d.%b.%Y');
ELSIF NOT entry.outcome.match('immediate'); 'in '; END;
END;
entry.outcome;
%]
</td>
<td>
[% # INCLUDE dumper.tt name = loop.count dump = entry.pack_due >= date;
IF entry.option.match('clinic_return'); '[not required]';
ELSIF entry.pack_due AND entry.pack_due >= today;
'[ due '; entry.pack_due.strftime('%d.%b.%Y'); ' ]';
ELSIF entry.pack_sent;
entry.pack_sent.strftime('%d.%b.%Y');
END;
%]
</td>
</tr>
[% END %]
</table>
</div>
</div>