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

<!-- BEGIN [% template.name %] -->
    [% # PROCESS dumper.tt dump = data %]
    
    <h2>Request turnaround times by specimen [[% title %]]:</h2>
    
    [% PROCESS site/date_constraints.tt
        func_name = 'get_page'
        target_url = app_url _ '/audit/turnaround/average'
        query_args = 'order_by=' _ c.query.param('order_by')
    %]

    [% IF data.size; using_auth = 0; # to determine if authorisation stage in use
      FOREACH entry IN data; # PROCESS dumper.tt dump = entry.delta_authorise; 
        IF entry.delta_authorise; using_auth = 1; LAST; END;
      END; # PROCESS dumper.tt dump = using_auth;
    %]
    <table class="indent">
        <tr>
            <th><a href="[% this_url %]?order_by=type">Specimen</a></th>
            <th><a href="[% this_url %]?order_by=totals">Total</a></td>
            <th [% IF using_auth %]colspan="2"[% END %]>
                <div>
                    <span class='acronym'
                          title='time from registration, in number of week days'>
                        Delta days:
                    </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'>
                    <a href="[% this_url %]?order_by=delta_r2a">R &#187; A</a>
                </span>
            </th>
            [% END %]
            <td class="borderless">
                <span class="info">&#171; click col. headers to sort</span>
            </td>
        </tr>
        
        [%
            USE math = format('%.1f');

            FOREACH entry IN data; # array
                specimen = entry.type;
                delta_report = entry.delta_report / entry.count;
                IF using_auth;
                  delta_auth = entry.delta_authorise / entry.count;
                END;
        %]
        <tr>
            <td align="right">[% specimen %]</td>
            <td>[% entry.count %]</td>
            <td align="center">[% math(delta_report) %]</td>
            [% IF using_auth %]
            <td align="center">[% math(delta_auth) %]</td>
            <td>+[% math(delta_auth - delta_report) %]</td>
            [% END %]
            <td class="borderless"></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 %] -->
