<!-- BEGIN [% template.name %] -->
    [% META title = 'Chimerism worksheet' %]
    
    [% # INCLUDE dumper.tt dump = requests %]

  <h2>Chimerism worksheet select</h2>

  <form method="get" action="[% app_url %]/data-import/chimerism_prep"
		name="worksheet" id="worksheet">

  <div class="indent">
	[% IF requests.size %]
	  <table>
        <tr>
            <td colspan="8" align="right" class="borderless">
                <input type="button" name="CheckAll" value="Select all"
                  onClick="checkAll(document.worksheet.request_id)">
                <input type="button" name="UnCheckAll" value="Clear all"
                  onClick="uncheckAll(document.worksheet.request_id)">
            </td>
        </tr>
		<tr>
			<td class="borderless"></td>
			<th>HMDS ref</th>
			<th>Name</th>
			<th>Date</th>
			<th>Sample</th>
			<th>Screened</th>
			<th>Select</th>
		</tr>
		[%
		  i = 0; # row counter
          seen = {}; # to enable unique entries

		  FOREACH entry IN requests; # PROCESS dumper.tt dump = entry.as_tree;
			data = entry.request; # for lab_number.tt
			patient = data.patient_case.patient;
			# only want unique requests, so skip if already seen:
 	        NEXT IF seen.${data.id};
			seen.${data.id} = 1; # for unique entries
		%]
		<tr>
			<td align="right">[% i = i + 1; i %]</td>
			<td>[% INCLUDE site/lab_number.tt want_url = 1
			  query_modifiers = [ '_return=1' ] %]</td>
			<td>
				[% patient.last_name | upper %],
				[% format_firstname(patient) || patient.first_name | ucfirst %]
			</td>
			<td>[% data.created_at.strftime('%d.%m.%Y') %]</td>
			<td>
                [% specimen_map.item(data.id).sample_code.join %]
                [% INCLUDE site/snippets/doi.tt IF request_options_map.item(data.id).doi %]
            </td>
			<td>[% data.request_initial_screen.screen.description %]</td>
			<td align="right">
				[% INCLUDE site/lab_number.tt want_url = 0 %]
				<input type="checkbox" name="request_id" value="[% data.id %]" />
			</td>
		</tr>
		[% END %]
		<tr>
		  <td colspan="2" class="borderless">[% site.html.back_button %]</td>
		  <td colspan="6" class="borderless" align="right">
		    [% site.html.submit %]
		  </td>
		</tr>
	  </table>
	[% ELSE %]
	  <p class="info">No chimerism requests.</p>
	  <p>[% site.html.back_button %]</p>
	[% END %]
  </div>
  </form>
<!-- END [% template.name %] -->
