[% skip_wrappers = 1 %]
<!-- BEGIN [% component.name %] -->
    [% # PROCESS dumper.tt dump = panel_probes %]
    [% # PROCESS dumper.tt dump = fish_data %]

    [%
        patient = data.patient_case.patient;
        report  = data.as_tree.request_report; # as_tree to prevent tt lookup if empty
    %]

    <h2 align="center">
        FISH worksheet [% PROCESS site/lab_number.tt want_url = 0 %]
    </h2>

    <table id="pid">
      <tr>
        <th>Name</th>
        <th>DoB</th>
        <th>ID No.</th>
        <th>Date</th>
        <th>Source</th>
        <th>Clinician</th>
        <th>Specimen</th>
      </tr>

      <tr>
        <td>
            [% patient.last_name | upper %],
            [% format_firstname(patient) || patient.first_name | ucfirst %]
        </td>
        <td>[% patient.dob.strftime('%d.%b.%Y') %]</td>
        <td>[% patient.nhs_number || data.patient_case.unit_number %]</td>
        <td>[% data.created_at.strftime('%d.%b.%Y') %]</td>
        <td>
            [% location = data.patient_case.referral_source.display_name;
                PROCESS site/display_name.tt %]
        </td>
        <td>[% data.referrer_department.referrer.name %]</td>
        <td>
            [% specimen_map.item(data.id).sample_code.join(', ') %]
            [% INCLUDE site/snippets/doi.tt IF request_options_map.item(data.id).doi %]
        </td>
      </tr>
    </table>

	<div id='report'>
		<p><u>Flow results</u>: [% result_summaries.item(data.id) %]</p>
		<p><u>Request details</u>: [% report.clinical_details %]</p>
		<p><u>Specimen quality</u>: [% report.specimen_quality %]</p>
		<p>
            <u>Reported as</u>: <strong>[% report.diagnosis.name %]</strong>
            <!-- on <strong>{{ReportDate}}</strong> -->
        </p>
	</div>

    [% BLOCK row %]
        <tr>
            <td class="probe">[% probe %]</td>
            <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
        </tr>
    [% END %]

    <table id="probes">
        <tr>
            <th id="col-one">Probe</th>
            <th id="col-two">Slide quality</th>
            <th id="col-three">FISH result</th>
            <th id="col-four">Interpretation</th>
            <th id="col-five">FISH quality</th>
        </tr>

        [%
            unique_probes = {}; # initialise hash for probes:

            FOREACH entry IN fish_data.item(data.id); # PROCESS dumper.tt dump = entry;
                NEXT IF entry.status.description.match('complete');
                probe = entry.lab_test; # INCLUDE dumper.tt dump = probe.test_name;
                NEXT IF probe.test_name.match('^h_and_e_fish$');

                # IF probe.test_name.match('^fish$'); # no longer in use
                    # all_probes.push('FISH'); # generic FISH request
                    # unique_probes.FISH = 1;
                IF probe.test_type.match('test'); # just add test name
                    # all_probes.push(probe.field_label);
                    label = probe.field_label;
                    unique_probes.${label} = 1;
                ELSIF probe.test_type.match('panel'); # add panel probe-set:
                    # FOREACH pp IN panel_probes.item(probe.field_label);  # using db table now
                    FOREACH pp IN panel_probes.item(probe.test_name);
                        # all_probes.push(pp);
                        unique_probes.${pp} = 1;
                    END;
                END;
            END; # PROCESS dumper.tt dump = unique_probes;
            all_probes = natural_sort(unique_probes.keys); # PROCESS dumper.tt dump = all_probes;

            FOREACH probe IN all_probes; PROCESS row; END;
            FILTER repeat(3); PROCESS row probe = ''; END; # 3 empty rows
        %]
    </table>

    <div class="emptyBox">

    </div>

    <table class="footer">
        <tr>
            <td>Reported by:</td>
            <td class="empty30"></td>
            <td colspan="2">FISH Batch no:</td>
            <td colspan="2" class="empty30"></td>
        </tr>
        <tr>
            <td>Checked by:</td>
            <td class="empty30"></td>
            <td>PC/MW:</td>
            <td class="empty10"></td>
            <td>Enzyme:</td>
            <td class="empty10"></td>
        </tr>
    </table>

    <h3 align="center">
        [% PROCESS site/lab_number.tt want_url = 0 %] ::
        [% patient.last_name | upper %]
    </h3>
<!-- END [% component.name %] -->
