	[%
      IF is_results_entry;
        # META title = 'Worklist';
		my.meta_title = "Worklist &raquo; Data Entry &raquo; ${lab_section.section_name}";
      ELSE; # format for printing:
        skip_wrappers = 1;
      END;
    %]
    
<!-- BEGIN [% template.name %] -->	
    [% # PROCESS dumper.tt dump = c.stash.errs %]
    [% # PROCESS dumper.tt dump = user_list %]
    [% # PROCESS dumper.tt dump = request_options_map %]
    [% # PROCESS dumper.tt dump = status_options_map %]
    [% # PROCESS dumper.tt dump = outstanding_investigations %]
    [% # PROCESS dumper.tt dump = lab_section.as_tree %]
    [% # PROCESS dumper.tt dump = c.query.param('lab_test_id') %]

  <p class="classname">[% site.html.back_button %]</p>
  
  [% title = is_results_entry ? 'data entry' : 'worksheet' %]
  <h3>[% lab_section.section_name _ ' ' _ title %]</h3>  

  [% IF dfv_errors %]
        <p class="error">[% c.config('msg').dfv_errors %]</p>
    [% END %]

  [% worklist_update_status_dfv_js %]

  [% IF is_results_entry %]
  <form action="[% app_url %]/worklist/update_results/[% lab_section.id %]"
      [% worklist_update_status_onsubmit %] method="post" name="update_results"
        id="update_results">
    <input type="hidden" name="results_entry" value="1" />
	<input type="hidden" name="query_params"
            value="[% c.query.self_url # preserve for possible redirect %]" />
    [% INCLUDE worklist/snippets/data_entry.tt %]
  [% ELSE %]
    <p class="spacer"></p>
  [% END %]  

  <div class="indent">
	[% # build args for url_links:
        args = [];
        results_entry = ( c.query.param('results_entry') || is_results_entry );
        
        args.push( 'status_option_id=' _ c.query.param('status_option_id') );
        args.push( 'results_entry='	_ results_entry );
        
        FOREACH test_id IN c.query.param('lab_test_id'); # can be multiple
            args.push( 'lab_test_id=' _ test_id );
        END;
	%]
    <table>
    [% IF is_results_entry %]
      <tr>
        <td colspan="10" align="right" class="borderless">
          <input type="button" name="CheckAll" value="Select all"
            onClick="checkAll(document.update_results.request_lab_test_id)">
          <input type="button" name="UnCheckAll" value="Clear all"
            onClick="uncheckAll(document.update_results.request_lab_test_id)">                    
        </td>
      </tr>
    [% END %]
      <tr>
        <td class="borderless"></td>		
        <th>
		  <a href="[% app_url %]/worklist/display/[% lab_section.id %]?[%
            args.join(';') %];sort_by=lab_number">Lab No</a>		  
		</th>
        <th>Name</th>
        <th>Date</th>
        <th>Sample</th>
        <th>Source</th>
        
        [% IF worklist_cols.item(lab_section.section_name).headers; # override default
            FOREACH h IN worklist_cols.item(lab_section.section_name).headers %]
            <th>[% h %]</th>
            [% END %]
        [% ELSE %]
            <th>Presentation</th>
            <th>
                <a href="[% app_url %]/worklist/display/[% lab_section.id %]?[%
                    args.join(';') %];sort_by=lab_tests">Investigation</a>
            </th>
        [% END %]
        
        <th>Status</th>
		[% IF is_results_entry %]
		  <th>Done</th>
		[% ELSIF section_has_test_details %]
		  <th>Notes</th>
		[% END %]
      </tr>
      
      [% FOREACH entry IN outstanding_investigations; # PROCESS dumper.tt dump = entry %]
        [% PROCESS worklist/snippets/row.tt type = 'investigation' %]  
      [% END %]
    </table>
  </div>
  
  <p>
	[% site.html.back_button %]
	[% IF is_results_entry; site.html.submit; ' '; site.html.reset; END %]
  </p>
  
  [% IF is_results_entry %]
  </form>
  [% END %]
<!-- END [% template.name %] -->	

