[% META title = 'Resources &raquo; Stats &amp; Audit &raquo; Turnaround times by specimen' %]

<!-- BEGIN [% template.name %] -->
    [% # PROCESS dumper.tt dump = data %]

    <h2>Non-trial request turnaround times (95 percentile) by specimen:</h2>

    [% PROCESS site/date_constraints.tt
        func_name = 'get_page'
        target_url = app_url _ '/audit/turnaround/percentile'
        restricted = { # too slow to allow these:
            no_constraint = 1,
            all_since     = 1,
        }
    %]

    <p class="indent title">[% title | upper %]</p>

    [% IF data.size; using_auth = 0; # to determine if authorisation stage in use
      FOREACH entry IN data; # PROCESS dumper.tt dump = entry.value;
        IF entry.value.delta_authorise; using_auth = 1; LAST; END;
      END; # PROCESS dumper.tt dump = using_auth;
    %]
    <table class="indent">
        <caption></caption>
        <tr>
            <th>Specimen</th>
            <th><div>Total</div><div>Reported</div></td>
            <th [% IF using_auth %]colspan="2"[% END %]>
                <div>
                    <span class='acronym'
                          title='time from registration, in number of week days'>
                        Delta days (95%):
                    </span>
                </div>
                <div>
                    <a href="[% this_url %]?order_by=delta_report">Report</a>
                    [% IF using_auth %]
                    | <a href="[% this_url %]?order_by=delta_auth">Auth'n</a>
                    [% END %]
                </div>
            </th>
            [% IF using_auth %]
            <th>
                <span class='acronym' title='report to authorisation difference'>
                    R &#187; A</span>
            </th>
            [% END %]
            <td class="borderless"></td>
        </tr>

        [%
            FOREACH entry IN data; # PROCESS dumper.tt dump = entry;
                specimen = entry.key;
                count = entry.value.count;
                delta_report = entry.value.delta_report;
                delta_auth = entry.value.delta_authorise;
       %]
        <tr class="[% count < 20 ? 'grey' : 'normal' %]">
            <td align="right">
                <a href="[%
                    c.query.self_url.replace(
                        'turnaround/percentile',
                        "turnaround_chart/${specimen}"
                    ) %]">[% specimen %]</a>
            </td>
            <td align="center">[% count %]</td>
            <td align="center">[% delta_report OR site.html.grey_null %]</td>
            [% IF using_auth %]
            <td align="center">[% delta_auth OR site.html.grey_null %]</td>
            <td>[% IF delta_auth AND delta_report;
                '+'; delta_auth - delta_report; ELSE; site.html.grey_null; END %]
            </td>
            [% END %]
            <td class="borderless">
                [% IF c.user_can('report') %]
                <a href="[%
                    c.query.self_url.replace(
                        'turnaround/percentile',
                        "turnaround_data/${specimen}"
                    ) %]" class="image"><img src="/images/table-icon.png" /></a>
                [% END %]
            </td>
        </tr>
        [% END %]
    </table>
    [% ELSE %]
        <p class="info indent">no data for time period specified</p>
    [% END %]

    <p class="indent">[% site.html.back_button %]</p>
<!-- END [% template.name %] -->
