  [% META title = 'Admin &raquo; Lab Tests View' -%]
<!-- BEGIN [% template.name %] -->
    [%
        # INCLUDE dumper.tt dump = lab_sections;
        i = 0; # row counter
        url = app_url _ '/resources/list_all_lab_tests';
        active_only = c.query.param('active_only');
        lab_section_id = c.query.param('lab_section_id');
    %]
    
    [% IF lab_tests.size %]
        <p class="header">Lab tests view</p>
        
        [% IF lab_sections.size %]
          <form action="[% url %]" method="post" name="form">
            <p>
                <span class="bold">Show only</span>:
                active <input type="checkbox" name="active_only" value=1
                  [% 'checked' IF active_only %] />
                <select name="lab_section_id" id="lab_section_id" onchange="submit()">
                    <option value="">----</option>
                    [% FOREACH s IN lab_sections %]
                        <option [% 'selected' IF s.id == lab_section_id %]
                            value="[% s.id %]">[% s.section_name %]</option>
                    [% END %]
                </select>
                [% site.html.go_btn %]
            </p>
          </form>
        [% END %]

        <table class="indent">
            <tr>
                <td class="borderless"></td>
                <th><a href="[% url %]?sort_by=field_label">Test Label</a></th>
                <th><a href="[% url %]?sort_by=test_name">Test Name</a></th>
                <th><a href="[% url %]?sort_by=test_type">Test Type</a></th>
                <th>Active</th>
                <th>
                [% UNLESS lab_section_id %]
                    <a href="[% url %]?sort_by=lab_section.section_name">Lab Section</a>
                [% ELSE %]Lab Section[% END %]
                </th>
            </tr>
            [%
                WHILE ( test = lab_tests.next );
                  NEXT IF active_only AND NOT test.is_active.match('yes');
                  IF lab_section_id; # not used by app, just skip entries:
                    NEXT UNLESS test.lab_section_id == lab_section_id;
                  END;
            %]
                <tr class="[% test.is_active.match('no') ? 'grey' : 'normal' %]">
                    <td align="right">[% i = i + 1; i %]</td>
                    <td>[% test.field_label %]</td>
                    <td>[% test.test_name %]</td>
                    <td>[% test.test_type %]</td>
                    <td>[% test.is_active %]</td>
                    <td>[% test.lab_section.section_name %]</td>
                </tr>
            [% END %]
        </table>
    [% ELSE %]
        <p class="warning">No lab tests configured</p>
    [% END %]
<!-- END [% template.name %] -->
