<!-- BEGIN [% template.name %] -->
[% content_only = 1 # no html wrappers %]

<html>
<head>
  <title>Plasma storage 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 = trial_number_map %]
    [% # PROCESS dumper.tt dump = function_name %]
    [% # 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;
		USE url( app_url _ '/local_worklist/plasma_storage_labels' ); %]
	  <form name="labels" action="[% url %]" method="post">
		<input type="hidden" name="function_name" value="[% function_name %]" />
		<p id="back">[% site.html.back_button %]
		  <span style="float:right">
			<input type="submit" class="button" value="Print labels" />
		  </span>
		</p>
	  </form>
	[% END %]

  <h2>Plasma storage 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>Trial ID</th>
        <th>Name</th>
        <th>Date taken</th>
        <th>Date received</th>
        <th>Sample</th>
        <th>Screened</th>
    </tr>
    [% i = 0; lab_numbers = []; # for 'Tubes collected' table
	  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;
		FOREACH specimen IN specimens;
    %]
    <tr>
        <td align="right">[% i = i + 1; i %]</td>
        <td>
		  [% lab_number = PROCESS site/lab_number.tt want_url = 0;
			  lab_numbers.push(lab_number); lab_number %]
        </td>
        <td>[% trial_number_map.item(patient.id) || 'NONE' %]</td>
        <td>
            [% patient.last_name | upper %],
            [% format_firstname(patient) || patient.first_name | ucfirst %]
        </td>
        <td>
            [% specimen_date.${data.id}.strftime('%d.%m.%Y') %]
        </td>
        <td>
            [% data.created_at.strftime('%d.%m.%Y') %]
        </td>
        <td>[% specimen %]</td>
        <td>[% presentations.item(data.id) %]</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(7); %]
	</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>

	<table class="indent">
	  <tr>
		<td class="borderless"></td>
		<th>Sample transfer</th>
		<th><div>Eppendorf</div><div>labelling</div></th>
		<th><div>FluidX</div><div>labelling</div></th>
	  </tr>
	  <tr>
		<td class="label">Performed by:</td><td></td><td></td><td></td>
	  </tr>
	  <tr>
		<td class="label">Checked by:</td><td></td><td></td><td></td>
	  </tr>
	</table>

    <h4>Tubes collected</h4>

  <table>
    <tr>
        <th>Lane</th>
        <th>HMDS ref</th>
        <th>Streck tube</th>
        <th><div># Eppendorfs</div><div>collected</div></th>
        <th><div># FluidX tubes</div><div>collected</div></th>
        <th><div>Total plasma</div><div>volume (ml)</div></th>
        <th>Haemolysis / Comments</th>
    </tr>
    [% td = '<td></td>'; i = 0; WHILE i < 6; # make up to 12 rows: %]
    <tr>
	  <td align="right">[% (i * 2) + 1 %]</td>
      <td>[% lab_numbers.$i %]</td>
      <td align="middle">[% '1' IF lab_numbers.$i %]</td>
	  [% td.repeat(4); %]
	</tr>
    <tr>
	  <td align="right">[% (i * 2) + 2 %]</td>
      <td>[% lab_numbers.$i %]</td>
      <td align="middle">[% '2' IF lab_numbers.$i %]</td>
	  [% td.repeat(4); i = i + 1; %]
	</tr>
    [% END %]
  </table>

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