[% content_only = 1 # no html wrappers %]
<!-- BEGIN [% template.name %] -->
<!doctype html>
<html lang='en'>
  <head>
    <link type="text/css" rel="stylesheet" href="/css/wgs-referral-form.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  </head>
  <body>
    [% IF requests.size AND NOT c.stash.render_pdf %]
      <p class="printInfo printHide">ENSURE PRINT BACKGROUND COLOURS SETTING IS
        ON AND PAGE MARGINS ARE SET TO ZERO IN PRINTER SETUP</p>
      <p class="indent printHide">[% site.html.back_button %]</p>
    [% END %]

    [% # INCLUDE dumper.tt dump = t FOREACH t IN ngis_tests %]

    [% IF requests.size; # requests is array of hashrefs; request_specimen
        # & results_summary are arrays (because many-to-one):
        FOREACH r IN requests; # INCLUDE dumper.tt dump = r;
          # reset local vars (as we're in a loop):
          sample_dispatched = '';
          haemonc_category  = '';
          result_summary    = '';
          result_date       = '';

          patient = r.patient_case.patient;
          # germline requests use WGS as (sole) sample_type:
          is_germline = r.request_specimen.0.specimen.sample_code.match('WGS');

          # get results_summary (from original_diagnosis 'test' if germline):
          result_summary = is_germline
            ? r.wgs_section_results.original_diagnosis
            : r.results_summary.0.results_summary;

          # sample_dispatched:
          sample_dispatched = r.wgs_section_results.sample_type;

          # ngis test codes:
          FOREACH t IN ngis_tests; # INCLUDE dumper.tt dump = t;
            # TODO: how to link ngis_test_code to results_summary ?
          END;
    %]
      <p class="rightAlign">Version 1.12</p>

      <div class="wgs pageBreakAfter">
        <table border=0>
            <tr class="borderless">
            [% img_src = c.stash.render_pdf ? 'http://localhost/images' : '/images' %]
                <td class="bold" style="width:60%">
                    <div>Genomic Medicine Service</div>
                    <div>Whole Genome Sequencing (WGS) Test Request</div>
                    <div>PLEASE DO NOT USE FOR NON-WGS TESTS</div>
                </td>
                <td style="width:110px">
                    <img src="[% img_src %]/wgs_cancer.png" />
                </td>
                <td style="width:140px">
                    <img src="[% img_src %]/nhs.png" />
                </td>
            </tr>
        </table>

        <div class="spacer-5"></div>

        <table border=0>
            <tr>
                <td colspan="2">Requesting organisation:
                    [% r.patient_case.referral_source.display_name %]
                </td>
            </tr>
            <tr>
                <td style="width:70%">GLH laboratory to receive sample:
                    YNEGLH Leeds Central Lab
                </td>
                <td>Test Required<br />Whole Genome Sequencing</td>
            </tr>
        </table>

        <div class="spacer-5"></div>

        <table border=0>
            <tr>
                <td colspan="2" class="patientName">Patient first name:
                    [% patient.first_name.ucfirst %]
                </td>
                <td>
                    <div>Ethnicity (please tick on page 2)</div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="patientName">Patient last name:
                    [% patient.last_name.upper %]
                </td>
                <td rowspan="2">
                    <div>Test Directory Clinical Indication &amp; code</div>
                    <!-- <div>(cancer type and reason for testing)</div> -->
                    [% # TODO: this should be derived from ngis_lab_test data
                           IF result_summary.match('myeloid'); 'M80.1';
                        ELSIF result_summary.match('lymphoblastic'); 'M91.1';
                        ELSIF result_summary.match('blastic plasmacytoid'); 'M90.1';
                        END;
                    %]
                </td>
            </tr>
            <tr>
                <td><div>Date of birth</div><div>[% patient.dob.dmy('/') %]</div></td>
                <td>
                    <div>Hospital number</div>
                    <div>[% r.patient_case.unit_number %]</div>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div>Gender</div>
                    <div>
                        <input type="checkbox"
                                [% 'checked' IF patient.gender.match('M') %] />
                            Male
                        <input type="checkbox"
                                [% 'checked' IF patient.gender.match('F') %] />
                            Female
                        <input type="checkbox"
                                [% 'checked' IF patient.gender.match('U') %]/>
                            Other / Unknown
                    </div>
                </td>
                <td>
                    <div>Presentation status</div>
                    <div class="small">
                        <input type="checkbox" /> First diagnosis
                        <input type="checkbox" /> Recurrence/relapse
                        <input type="checkbox" /> Unknown
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2" id="nhsNum">
                    <div>NHS number (or postcode if not known)</div>
                    <div>[% INCLUDE site/nhs_number.tt
                        nhs_number = patient.nhs_number; %]</div>
                    [% IF NOT patient.nhs_number %]
                      <div>Reason NHS number not available:</div>
                      <div class="small">
                        <input type="checkbox" /> Patient is a foreign national
                        <input type="checkbox" /> Other (provide reason)
                      </div>
                    [% END %]
                </td>
                <td id="additionalInfo">
                    <div>Additional clinical information (if relevant)</div>
                    <div class="grey">eg previous tumours, molecular testing,
                        and relevant treatment history with dates</div>
                </td>
            </tr>
        </table>

        <div class="spacer-5"></div>

        <table border=0 class="compact">
            <tr>
                <th colspan="4" class="header">Solid tumour requests only</th>
            </tr>
            <tr>
                <td id="tumourType" rowspan="2">
                    <div><input type="checkbox" /> Primary</div>
                    <div><input type="checkbox" /> Metastatic</div>
                    <div><input type="checkbox" /> Lymphoma</div>
                    <div><input type="checkbox" /> Unknown</div>
                </td>
                <td id="labId">
                    <div>Histopathology lab ID</div>
                    <div class="spacer-20"></div>
                </td>
                <td colspan="2">
                    <div>Additional tumour information (if relevant)</div>
                    <div class="grey">eg site of metastasis (if metastatic), or
                        unknown primary</div>
                </td>
            </tr>
            <tr>
                <td>
                    <div>Date of this diagnosis</div>
                    <div class="grey">dd/mm/yyyy</div>
                </td>
                <td>Tumour topography</td>
                <td>Tumour morphology</td>
            </tr>
        </table>

        <table border=0 class="compact">
          [% # get haem-onc results (not germline samples):
            IF is_germline; # 'result summary: ' _ result_summary;
                # reset local vars (may have been set by previous req in loop)
                collection_date = '';
                sample_type     = '';
            ELSE;
                result_date = r.results_summary.0.time.dmy('/');
                IF result_summary.match('myeloid');
                    haemonc_category = 'AML';
                ELSIF result_summary.match('lymphoblastic');
                    haemonc_category = 'ALL';
                ELSE;
                    haemonc_category = 'other';
                END; # 'haemonc_category:' _ haemonc_category;
            END;
          %]
            <tr>
                <th colspan="3" class="header">Haemato-oncology liquid tumour
                    requests only
                </th>
            </tr>
            <tr>
                <td>
                    <input type="checkbox"
                        [% 'checked' IF haemonc_category.match('AML') %] /> AML
                    <input type="checkbox"
                        [% 'checked' IF haemonc_category.match('ALL') %] /> ALL
                    <input type="checkbox"
                        [% 'checked' IF haemonc_category.match('other') %] />
                        Other (please specify)
                        [% result_summary IF haemonc_category.match('other') %]
                </td>
                <td>
                    <div>Local sample ID</div>
                    <div>[% UNLESS is_germline; INCLUDE site/lab_number.tt data = r;
                        END %]</div>
                </td>
                <td>
                    <div>Date of this diagnosis</div>
                    <div>[% result_date %]</div>
                </td>
            </tr>
        </table>

        <table border=0 class="compact">
          [% # not for germline samples:
            IF is_germline;
                # reset local vars (may have been set by previous req in loop)
                collection_date = '';
                sample_type     = '';
            ELSE;
                collection_date = r.request_specimen_detail.specimen_date;
                sample_type = sample_dispatched.match('blood|marrow|tissue')
                    ? sample_dispatched : 'other';
            END;
          %]
            <tr>
                <th colspan="5" class="header">Complete for tumour samples</th>
            </tr>
            <tr>
                <td colspan="5">
                    <input type="checkbox"
                        [% 'checked' IF sample_type.match('tissue') %] />
                        Fresh frozen tumour
                    <input type="checkbox"
                        [% 'checked' IF sample_type.match('marrow') %] />
                        Bone marrow
                    <input type="checkbox"
                        [% 'checked' IF sample_type.match('blood') %]/>
                        Blood (EDTA)
                    <input type="checkbox"
                        [% 'checked' IF sample_type.match('other') %]/>
                        Other (please specify):
                        [% sample_dispatched IF sample_type.match('other') %]
                </td>
            </tr>
            <tr>
                <td colspan="5">% malignant nuclei / blasts or equivalent
                    in this sample <span class="grey">(refer to sample handling
                    guidance)</span> must be provided below
                </td>
            </tr>
            <tr class="small">
                <td>Local sample tube ID</td>
                <td>Collection date / time</td>
                <td>% malignant nuclei / blasts</td>
                <td>nucleated cell count</td>
                <td>volume required</td>
            </tr>
            <tr class="small">
                <td><div class="spacer-15"></div></td>
                <td>[% collection_date.strftime('%d/%m/%Y %H:%M') %]</td>
                <td></td>
                <td class="grey rightAlign">x10<sup>9</sup>/L</td>
                <td class="grey rightAlign">&micro;L</td>
            </tr>
            <!-- // do we need 2 rows ?
            <tr><td><div class="spacer-15"></div></td><td></td><td></td><td></td><td></td></tr>
            -->
        </table>

        <table border=0 class="compact">
          [% IF is_germline; # only for germline samples:
                collection_date = r.request_specimen_detail.specimen_date;
                sample_type = sample_dispatched.match('blood|saliva|fibroblast|skin')
                ? sample_dispatched : 'other';
            ELSE;
                # reset local vars (may have been set by previous req in loop)
                collection_date = '';
                sample_type     = '';
            END;
          %]
           <tr>
                <th colspan="4" class="header">Complete for germline samples</th>
            </tr>
            <tr>
                <td colspan="4">
                    <input type="checkbox"
                        [% 'checked' IF sample_type.match('blood') %] />
                        Blood (EDTA)
                    <input type="checkbox"
                        [% 'checked' IF sample_type.match('saliva') %] />
                        Saliva
                    <input type="checkbox"
                        [% 'checked' IF sample_type.match('fibroblast') %] />
                        Fibroblasts
                    <input type="checkbox"
                        [% 'checked' IF sample_type.match('skin') %] />
                        Skin biopsy
                    <input type="checkbox"
                        [% 'checked' IF sample_type.match('other') %]/>
                        Other (please specify):
                        [% sample_dispatched IF sample_type.match('other') %]
                </td>
            </tr>
            <tr>
                <td>Local sample ID</td>
                <td>Collection date / time</td>
                <td>Sample volume if applicable</td>
                <td style="width:30%">Comments</td>
            </tr>
            <tr>
                <td>
                    <div class="spacer-15">[% IF is_germline;
                        INCLUDE site/lab_number.tt data = r; END %]
                    </div>
                </td>
                <td>[% collection_date.strftime('%d/%m/%Y %H:%M') %]</td>
                <td></td> <td></td>
            </tr>
        </table>

        <div class="spacer-5"></div>

        <table border=0 class="compact">
            <tr>
                <th colspan="2" class="header">Consultant details</th>
            </tr>
            <tr>
                <td id="referrer">
                    <div>Responsible consultant:
                        [% r.referrer_department.referrer.name %]
                    </div>
                    <div>Department:
                        [% r.referrer_department.hospital_department.display_name %]
                    </div>
                    <div>Phone:</div>
                    <div>Email:</div>
                </td>
                <td>
                    <div>Main contact (if different from responsible consultant)</div>
                    <div>Name:</div>
                    <div>Department:</div>
                    <div>Phone:</div>
                    <div>Email:</div>
                </td>
            </tr>
        </table>

        <div class="spacer-15"></div>

        <div class="indent"><input type="checkbox" />
            I have attached a copy of the Record of Discussion form
        </div>
        <div class="indent"><input type="checkbox" />
            Patient conversation taken place, Record of Discussion form to follow
        </div>
      </div>

    <!-- page 2 -->
      <div class="wgs [% UNLESS loop.last; 'pageBreakAfter'; END %]">
        <table border=0>
            <tr>
                <th class="borderless">
                    [% patient.first_name.ucfirst %] [% patient.last_name.upper %]
                    :: [% patient.dob.dmy('/') %]
                    :: [% patient.nhs_number OR r.patient_case.unit_number %]
                    (page 2 of 2)
                </th>
            </tr>
        </table>

        <h4 class="indent">Ethnicity - Please tick the relevant self defined
            ethnicity code below</h4>

        <table border=0 class="compact">
            <tr class="header">
                <th>White</th>
                <th>Mixed</th>
                <th>Asian or Asian British</th>
                <th>Black or Black British</th>
                <th>Other Ethnic Group</th>
            </tr>
            <tr>
                <td>A <input type="checkbox" /> British</td>
                <td>D <input type="checkbox" /> White and Black Caribbean </td>
                <td>H <input type="checkbox" /> Indian</td>
                <td>M <input type="checkbox" /> Caribbean</td>
                <td>R <input type="checkbox" /> Chinese </td>
            </tr>
            <tr>
                <td>B <input type="checkbox" /> Irish</td>
                <td>E <input type="checkbox" /> White and Black African</td>
                <td>I <input type="checkbox" /> Pakistani</td>
                <td>N <input type="checkbox" /> African</td>
                <td>S <input type="checkbox" /> Any other ethnic group</td>
            </tr>
            <tr>
                <td>C <input type="checkbox" /> Any other White background</td>
                <td>F <input type="checkbox" /> White and Asian</td>
                <td>J <input type="checkbox" /> Bangladeshi</td>
                <td>O <input type="checkbox" /> Any other Black background</td>
                <td></td>
            </tr>
            <tr>
                <td></td>
                <td>G <input type="checkbox" /> Any other mixed background</td>
                <td>L <input type="checkbox" /> Any other Asian background</td>
                <td></td>
                <td>Z <input type="checkbox" /> Not stated</td>
            </tr>
        </table>

        <h5>Additional local identifiers - please use the table below, these
            will also be displayed in the interpretation panel</h5>

        <table border=0 class="compact">
            <tr class="header">
                <th colspan="3">Type - O (Test order/Case ID), P (local
                    patient ID), S (local sample identifier)
                </th>
            </tr>
            <tr class="header">
                <th>Organisation</th>
                <th>Type</th>
                <th>Identifier</th>
            </tr>
            <tr> <td><div class="spacer-15"></div></td> <td></td> <td></td> </tr>
            <tr> <td><div class="spacer-15"></div></td> <td></td> <td></td> </tr>
            <tr> <td><div class="spacer-15"></div></td> <td></td> <td></td> </tr>
            <tr> <td><div class="spacer-15"></div></td> <td></td> <td></td> </tr>
            <tr> <td><div class="spacer-15"></div></td> <td></td> <td></td> </tr>
            <tr> <td><div class="spacer-15"></div></td> <td></td> <td></td> </tr>
        </table>
      </div>
    [% END; ELSE # no requests: %]
        <h3 class="indent info">No outstanding WGS requests</h3>
        <p class="indent">[% site.html.back_button %]</p>
    [% END %]
  </body>
</html>
<!-- END [% template.name %] -->
