[% content_only = 1 # no html wrappers %]

<!-- BEGIN [% component.name %] -->
<html>
<head>
  <title>[% extraction_type %] extraction worksheet</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link type="text/css" rel="stylesheet" href="/css/worksheet.css" />
</head>

<body>
    [% # PROCESS dumper.tt dump = function_name %]
    [% # PROCESS dumper.tt dump = lab_section %]
    [% # PROCESS dumper.tt dump = extraction_type %]
    [% # PROCESS dumper.tt dump = presentations %]
	[% # PROCESS dumper.tt dump = request_specimen_map %]
    [% # FOREACH r IN requests; PROCESS dumper.tt dump = r.as_tree; END %]

	[% IF c.query.param('print_labels'); # load flash messages:
		PROCESS site/status.tt; # need to jump back 2 pages, as print-labels reuse fails: %]
	  <p id="back">
		<input type="button" value="&lt;&lt; Back" onClick="history.go(-2);">
	  </p>
	[% ELSE; # extraction_type.match('DNA'); # now want labels for Trial RNA extraction
		USE url( app_url _ '/local_labels/print_xna_extraction_labels' ); %]
	  <form name="labels" action="[% url %]" method="post">
		<input type="hidden" name="function_name" value="[% function_name %]" />
		<input type="hidden" name="lab_section" value="[% lab_section %]" />
		<input type="hidden" name="extraction_type" value="[% extraction_type %]" />
		<p id="back">[% site.html.back_button %]
		  <span style="float:right">
			<input type="submit" class="button" value="Print labels" />
		  </span>
		</p>
	  </form>
	[%# ELSE # todo: comment out after above change %]
	  <!--<p id="back">[% site.html.back_button %]</p>-->
	[% END %]

  <h2>[% lab_section %] section [% extraction_type %] extraction worksheet</h2>

  <div class="bold indent">
    <p>Performed by: [% c.authen.username.upper %]</p>
    <p>Date: [% USE date(format = '%d.%m.%Y @ %H:%M', locale = 'en_GB');
	  date.format %]</p>
  </div>

  <table>
    <tr>
        <th>Lane</th>
        <th>HMDS ref</th>
        <th>Name</th>
        <th>Date</th>
        <th>Sample</th>
        <th>Screened</th>
		[% IF lab_section.match('trial') AND extraction_type.match('RNA');
			have_nanodrop_result = 1 %]
		  <th><div>Nanodrop</div><div>Result (ng/µl)</th>
		[% END %]
        <th>Comments</th>
    </tr>
    [% i = 0;
	  FOREACH data IN requests; # PROCESS dumper.tt dump = data.as_tree;
        patient = data.patient_case.patient;
        report  = data.as_tree.request_report; # as_tree to prevent tt lookup if empty

		specimens = request_specimen_map.item(data.id);
            # PROCESS dumper.tt dump = specimens;
		# force CHIM's to 3 lines:
		IF specimens.grep('CHIM').size; # is, or contains 'CHIM':
            specimens.push('CHIM','CHIM'); END;
		# split specimens into new line for each:
		FOREACH specimen IN specimens;
    %]
    <tr>
        <td align="right">[% i = i + 1; i %]</td>
        <td>[% PROCESS site/lab_number.tt want_url = 0 %]</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 %]</td>
        <td>[% presentations.item(data.id) %]</td>
		[% IF have_nanodrop_result %]<td class="empty10"></td>[% END %]
        <td class="empty25"></td>
    </tr>
  [% END; END; WHILE i < 12; # make up to 12 rows: %]
    <tr>
	  <td align="right">[% i = i + 1; i %]</td>
	  [% td = '<td></td>'; td.repeat(6); td.repeat(1) IF have_nanodrop_result %]
	</tr>
  [% END %]
  </table>

    <h4>Tube order checking</h4>

    <p class="indent">Tube order and alignment must be checked at all transfer
	  stages. Initial once done.
	</p>

	[% INCLUDE user_section %]

    <h4>Other / comments</h4>
</body>
</html>
<!-- END [% component.name %] -->
