<!-- BEGIN [% template.name %] -->
  [% META title = 'Worklist &raquo; Histology Blocks' -%]

    [% # PROCESS dumper.tt dump = specimen_map %]
    [% # PROCESS dumper.tt dump = requests %]
    [% # PROCESS dumper.tt dump = block_refs_map %]
    [% # PROCESS dumper.tt dump = c.session.param('UserProfile') %]

  <h3 class="header">Histology blocks worklist</h3>

  [% # define some data structures:
    headers = [ 'LabNo' 'Name' 'Date' 'Sample' 'Source' 'BlockRef' 'Done' ];
  %]

  [% IF requests.size %]
  <form method="post" action="[% app_url %]/local_worklist_histology/blocks_data_update">

    [% IF csrf_token; PROCESS site/csrf.tt; END %]

	[% meta_data = c.get_meta_data('RequestExternalRef');
        max_length = meta_data.column('status').length; %]

    <div class="indent title printHide">
      Reference: <input type="text" name="reference" size="16" maxlength="[% max_length %]"
        [% INCLUDE site/limit_text.tt input_name = 'reference' %] />
       <span>[% PROCESS site/countdown.tt %]</span>
    </div>

    [% FOREACH pair IN requests;
        year = pair.key; %]

      <p class="bold">YEAR: [% year %]</span>
        [% div_name = year; INCLUDE site/snippets/toggleview.tt %]
      </p>

      <div class="itemhidden" id="[% year %]">
        <table class="indent">
          <tr>
            [% FOREACH item IN headers %]
              <th>[% item %]</th>
            [% END %]
            <td class="borderless"></td>
          </tr>
          [%
            FOREACH entry IN pair.value; # PROCESS dumper.tt dump = data.as_tree;
              patient = entry.request.patient_case.patient;
              data = entry.request; # for lab_number.tt
			  specimen = specimen_map.item(data.id).sample_code.join(', ');
			  NEXT UNLESS specimen.match('(B|S)L|HS'); # only want block/slide
          %]
            <tr>
              <td>[% INCLUDE site/lab_number.tt want_url = 1 %] [% # data.id %]</td>
              <td>
                [% patient.last_name  | upper %],
                [% patient.first_name | ucfirst %] [% patient.middle_name | ucfirst %]
              </td>
              <td>[% data.created_at.strftime('%d.%m.%Y') %]</td>
              <td>[% specimen %]</td>
              <td>[% data.patient_case.referral_source.display_name | html %]</td>
              <td>[% block_refs_map.item(data.id) | html %]</td>
              <td align="center">
                <input type="checkbox" name="request_id" value="[% data.id %]"
                  class="printHide" />
              </td>
            </tr>
          [% END %]
        </table>
      </div>
    [% END %]
    <p class="indent">[% site.html.submit %]</p>
  </form>

  [% ELSE %]
    <p class="info indent">No outstanding histology blocks</p>
  [% END %]
<!-- END [% template.name %] -->
