<!-- BEGIN [% component.name %] -->
    [% # FOREACH r IN requests; PROCESS dumper.tt dump = r.as_tree; END %]
    [% # PROCESS dumper.tt dump = specimen_map %]
	[% # PROCESS dumper.tt dump = restrict_request_map %]
	[% # PROCESS dumper.tt dump = test_names %]
	[% # PROCESS dumper.tt dump = function_name %]
	[% # PROCESS dumper.tt dump = c.query %]

    [% i = 0; BLOCK row;
        data = entry.request; # for lab_number.tt
		IF restrict_request_map;
		  NEXT UNLESS restrict_request_map.${data.id};
		END;
		location = data.patient_case.referral_source.display_name
		patient  = data.patient_case.patient;
		# want to split specimens into new line for each:
		specimens = specimen_map.item(data.id).sample_code;
		FOREACH specimen IN specimens;
    %]
	  <tr>
        <td>[% i = i + 1; i %]</td>
        <td>
          [% PROCESS site/lab_number.tt want_url = 1 %]
        </td>
        [% class = request_options_map.item(data.id).urgent ? 'red' : 'normal' %]
        <td class="[% class %]">
          [% patient.last_name   | upper %],
          [% patient.first_name  | ucfirst %]
          [% patient.middle_name | ucfirst %]
        </td>
		<td>[% data.created_at.strftime('%d.%m.%Y') %]</td>
        <td>
            [% specimen # specimen_map.item(data.id).sample_code.join(', ') %]
            [% INCLUDE site/snippets/doi.tt IF request_options_map.item(data.id).doi %]
        </td>
		<td>[% PROCESS site/display_name.tt %]</td>
        <td>
          [% IF data.request_initial_screen %]
            [% data.request_initial_screen.screen.description | html %]
          [% ELSE %]
            [% site.html.grey_null %]
          [% END %]
		</td>
        <td>[% entry.lab_test.field_label %]
		  [% '[P]' IF entry.lab_test.test_type.match('panel') %]
        </td>
        <td align="center">
            <input type="checkbox" name="request_specimen"
                value="[% data.id %]~[% specimen # request_specimen lacks 'id' !! %]" />
        </td>
      </tr>
    [% END; END %]

    <p class="classname">[% site.html.back_button %]</p>

    <h3>Print [% lab_section %] section [% 'Automated ' IF automated_extraction;
        extraction_type.upper %] extraction worksheets</h3>

	[% IF NOT test_names.size # allows filtering on any co-selected lab-tests %]
	<form method="post" action="">
	  <input type="hidden" name="function_name" value="[% function_name %]" />
	  <p class="bold">Optional select one or more tests:</p>
		<div id="multi">
		  <div class="indent">
			<select multiple size="[% IF lab_tests.size > 8; 6; END %]"
				name="lab_test_id">
			[% FOREACH test IN lab_tests %]
			  <option value="[% test.id %]">[% test.field_label | html %]</option>
			[% END %]
			</select>
			[% site.html.submit %]
		  </div>
		</div>
	</form>
	[% ELSE %]
      <p class="bold indent">Selected test(s):</p>
	  <ul class="indent">[% FOREACH t IN test_names %]<li>[% t %]</li>[% END %]</ul>
	[% END %]

    <form action="[% app_url %]/local_worklist/xna_extraction_worksheet"
		method="post" name="worksheet" id="worksheet">
	  <input type="hidden" name="extraction_type" value="[% extraction_type %]" />
	  <input type="hidden" name="function_name" value="[% function_name %]" />
	  <input type="hidden" name="lab_section" value="[% lab_section %]" />
	  <input type="hidden" name="automated_extraction" value="[% automated_extraction %]" />
    <table>
        <tr>
            <td colspan="9" align="right" class="borderless">
                <input type="button" name="CheckAll" value="Select all"
                  onClick="checkAll(document.worksheet.request_specimen)">
                <input type="button" name="UnCheckAll" value="Clear all"
                  onClick="uncheckAll(document.worksheet.request_specimen)">
            </td>
        </tr>
      <tr>
        <td class="borderless"></td>
        <th>Lab No</th>
        <th>Name</th>
        <th>Date</th>
        <th>Sample</th>
        <th>Source</th>
		<th>Presentation</th>
		<th>Investigation</th>
		<th>Print</th>
      </tr>

      [% FOREACH entry IN requests; PROCESS row; END %]
    </table>
    <p class="indent">
    <!--
      <input type="button" name="CheckAll" value="Select all"
        onClick="checkAll(document.fish_worksheets.request_id)">
    -->
      <input type="button" name="UnCheckAll" value="Clear all"
        onClick="uncheckAll(document.worksheet.request_specimen)">
        [% site.html.submit %]
    </p>
    </form>

<!-- END [% component.name %] -->
