[% META title = 'Resources &raquo; Stats &amp; Audit &raquo; Revised Diagnoses' %]

<!-- BEGIN [% template.name %] -->
    [% # PROCESS dumper.tt dump = user_counts %]
    [% # PROCESS dumper.tt dump = specimen_map %]
    
    <h3>
        Diagnosis revisions for cases reported [% title %], sorted by
        [% c.query.param('sort_by') %]:
    </h3>

    [% PROCESS site/date_constraints.tt
        func_name = 'get_page'
        target_url = app_url _ '/audit/revised_diagnoses/'
        query_args = 'sort_by=' _ c.query.param('sort_by')
    %]
    
    [% BLOCK row %]
        <div class="indent">
            [% INCLUDE site/lab_number.tt data = entry want_url = 1 %]
            [[% specimen_map.item(entry.id).sample_code.join(', ') %]]:
            [% entry.revised_diagnosis %] ([% entry.reporter | upper %]) 
            <span class="blue">&#187;</span>
            [% entry.current_diagnosis %] ([% entry.reviser | upper %])
        </div>
    [% END %]
    
    [% IF rev_count; USE math = format('%.1f'); %]
        <h3>Frequency of revised diagnoses:
            [% math(rev_count / total_count * 100) %]%
            [[% rev_count %] of [% total_count %] total]</h3>
        
        [% IF sort_by.match('date'); # array:
            FOREACH entry IN revisions; INCLUDE row; END %]
            
        [% ELSE; # PROCESS dumper.tt dump = revisions;
           FOREACH entry IN revisions;
                username = entry.key;
                results  = entry.value %]
            <p class="bold">
                [% user_details.item(username).first_name | ucfirst %]
                [% user_details.item(username).last_name  | upper %]
                [[% math(results.size / user_counts.item(username) * 100) %]%
                    of [% user_counts.item(username) %] reported]
            </p>
            [% FOREACH entry IN results; INCLUDE row; END %]
            [% END %]
        [% END %]
    [% ELSE %]
        <p class="info indent">no data for time period specified</p>
    [% END %]
    
    <p class="indent">[% site.html.back_button %]</p>
<!-- END [% template.name %] -->
