[% content_only = 1 # no html wrappers %]
<!DOCTYPE html>
<html>
<head>
[% USE date(format = '%d/%m/%Y') %]
  <!-- BEGIN [% template.name %] -->
  <title>FISH Custom worksheet</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link type="text/css" rel="stylesheet" href="/css/worksheet.css" />
  <style type="text/css">
	td, th { font-weight: bold; border-color: #00f; } /* all td */
        .result { text-align: center; color: green;font-size: 150%;}
        .reported { text-align: center; color: indigo; background: cyan;}
        .checked { text-align: center; color: red;background: pink;}
        .probe { text-align: center; color: indigo;background: khaki;}
        #probes td.textbox { height: 10em;}
        .template_name {color: indigo; text-align: center;}
        .user_info { color:blue;}
        .warning { color: red;}
        .probe_result { text-align: left;}
        .probe_result thead tr th { background: LightBlue; padding: 0 1em 0 1em }
        .probe_result tbody tr td { height:2em;}
        .probe_result caption { font-weight: bold;}
        tr.ticktotals { background: #f5f5f5;}
        .ticktotals td { text-align: center; font-weight: bold;}
        .ticktotals td.first { text-align: left;}
    @media print {
	td, th, p, div { font-size: 8pt } /* override default 7pt */
	}
  </style>
</head>

<body>
    [% # PROCESS dumper.tt dump = gross_description %]
    [% # PROCESS dumper.tt dump = result_summaries %]
    [% # PROCESS dumper.tt dump = specimen_map %]
    [% # PROCESS dumper.tt dump = panel_probes %]
    [% # PROCESS dumper.tt dump = fish_data %]
    [% # PROCESS dumper.tt dump = requests %]

  <p id="back">[% site.html.back_button %]</p>
      <div style="page-break-after: always">
        [% template_file = "worklist/local/fish/templates/$fish_template" %]
        [% PROCESS $template_file %]
    [% #  PROCESS dumper.tt dump = columns %]
    <h2 class="template_name">
        [%  fish_template.remove('.tt') | replace('positive', '+') |ucfirst %] Worksheet
        [% col_counter = columns.size + 5; # slideno,hmdsno,patientname,1streported,checked 
           col_counter_last_index = col_counter - 1 
         %]
    </h2>
      <table id="probes">
          <thead>
              <tr class="user_info">
                  <th colspan = "2">[% date.format %]</th>
                  <!-- <th> &nbsp;[% col_counter  #TODO remove debugging%]</th> -->
                  <th> &nbsp;</th>
                  <th colspan = "5">Batch No:</th>
                  <th colspan = "[% col_counter - 8 %]">Initials:</th>
              </tr>
            <tr>
                <td colspan = "[% col_counter %]" style="padding:0">&nbsp;</td>
              </tr>

            <tr>
            <th>&nbsp;</th>
            <th> &nbsp; </th>
            <th> &nbsp; </th>
            [% FOREACH col IN columns %]
            <th class="probe"> [% col.label %] </th>
            [% END %]
            <th></th>
            <th></th>
            </tr>

            <tr>
              <td class="warning" colspan = "[% col_counter %]">RECORD THE PROBE VIAL NUMBER BELOW IF THE SAME FOR THE WHOLE
                  BATCH. IF A NEW VIAL IS OPENED RECORD ON INDIVIDUAL
                  CASES.</td>
            </tr>

            <tr>
            <th>Slide No. </th>
            <th> HMDS Number </th>
            <th> Patient Name </th>
            [% FOREACH col IN columns %]
            <th class="probe">Probe lot no.<br />&nbsp;</th>
            [% END %]
            <th class="reported">1st Reported</th>
            <th class="checked">Checked</th>
            </tr>

          </thead>
          <tbody>
            [% tick_totals = [];
            FOREACH t IN [0 .. col_counter_last_index];
              tick_totals.$t = 0;
            END;
            %]
            [% FOREACH r IN template_data.keys.sort %]
            <tr>
                [% FOREACH request_search IN requests  # find the correct request details %]
                    [% IF request_search.id == r ;
                        request = request_search %]
                    [% END #if %]
                [% END # foreach request_search %]
                <td>[% loop.count %]</td>
                <td> [% PROCESS site/snippets/lab_number.tt data = request; # expects request object 'data' %]
                </td>
                <!-- extra patient td's -->
                <td>[% request.patient_case.patient.last_name %]</td>
            [% FOREACH col IN columns %]
                <td class="result">
                [% tick_counter = 0 %]
                [% col_to_td_position = loop.index + 3; # 3 columns before the probe cols%]
                
                    [% # dont tick if any tests are in col.skip - but check its not overriden by another test
                    IF not col.exists('dont_skip') OR not template_data.$r.grep('^' _ col.dont_skip.first _ '$').size;
                      skip_counter = 0;
                      FOREACH skip IN col.skip;
                        IF template_data.$r.grep('^' _ skip _ '$').size;
                          skip_counter = skip_counter + 1;
                        END;
                      END;
                      IF skip_counter > 0;
                        NEXT;
                      END;
                    END %]
                      
                    [% FOREACH test IN col.tests %]
                    [% # PROCESS dumper.tt dump = template_data.$r %]
                    [% # PROCESS dumper.tt dump = test %]
                    [% # PROCESS dumper.tt dump = template_data.$r.grep('^' _ test _ '$') %]

                    [% IF template_data.$r.grep('^' _ test _ '$').size;
                    tick_counter = tick_counter + 1;
                    END %]
                [% END # foreach test%]
                    [%  # PROCESS dumper.tt dump = tick_counter %]
                    [%#  PROCESS dumper.tt dump = col.tests.size %]
                [% IF (( col.logical == 'AND' ) && ( col.tests.size == tick_counter )) ||
                      (( col.logical != 'AND' ) && ( tick_counter > 0  )) %]
                        &#10004;
                        [% tick_totals.$col_to_td_position = tick_totals.$col_to_td_position+1 %]
                [% END #if %]
                </td>
            [% END # foreach col%]
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            </tr>
        [% END # foreach r %]

    [% #  PROCESS dumper.tt dump = col_counter %]
        <tr class="ticktotals">
            <td class="first"> Totals </td>
            [%- FOREACH col IN [1 .. col_counter_last_index ]  %]
            <td>[% IF tick_totals.$col > 0 ;
                tick_totals.$col ;
                END %]
            </td>
            [% END %]
        </tr>
        <tr class="ticktotals">
            <td class="first"> No. of failures </td>
            [%- FOREACH col IN [1 .. col_counter_last_index ]  %]
            <td>&nbsp;</td>
            [% END %]
        </tr>
        <tr><td colspan="[% col_counter %]">General Comments:</td></tr>
        <tr><td colspan="[% col_counter %]" class="textbox"></td></tr>
    </tbody>
    </table>
    <br>
    <table class="probe_result">
        <caption>Probes For Acceptance:</caption>
        <thead>
            <tr>
                <th>Probe Name</th>
                <th>Probe No.</th>
                <th>Reporter.</th>
                <th>Acceptable Y/N</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </tbody>
    </table>
      </div> 
</body>
</html>
<!-- END [% template.name %] -->

