<!-- BEGIN [% template.name %] -->
  [% META title = 'Worklist &raquo; Recruitment Report' -%]
    [% # INCLUDE dumper.tt dump = s.as_tree FOREACH s IN screens %]

   <h3 class="header">Genomics recruitment progress report</h3>

	[% addcss = [ 'jquery.datetimepicker.css' ]  %]
	<script type="text/javascript" src="/js/jquery.datetimepicker.js"></script>
	<script type="text/javascript">
	  $( function(){ jQuery('.datepicker').datetimepicker(
		  { timepicker: false, format: 'd-m-Y' });
	  });
	</script>

    <form action="[% app_url %]/local_worklist">
        <input type="hidden" name="function_name" value="[% c.query.param('function_name') %]" />
        <p class="indent">1)<span class="info">select disease type</span>
            <select name="disease_type">
                <option value="">--</option>
                <option value="rd" [% 'selected'
                    IF c.query.param('disease_type').match('rd') %]>Rare disease</option>
                <option value="all_cancer" [% 'selected'
                    IF c.query.param('disease_type').match('all_cancer') %]>Cancer (all)</option>
                [% FOREACH s IN screens;
                    NEXT IF s.description.match('Rare disease') %]
                    <option value="[% s.description %]" [% 'selected'
                        IF c.query.param('disease_type').match(s.description) %]>[% s.description %]</option>
                [% END %]
                %]
            </select> (optional; default 'all')
        </p>
        <p class="indent">2)<span class="info">select GMC centre</span>
            <select name="organisation">
                <option value="">--</option>
                <option value="leeds" [% 'selected'
                    IF c.query.param('organisation').match('leeds') %]>Leeds</option>
                <option value="sheffield" [% 'selected'
                    IF c.query.param('organisation').match('sheffield') %]>Sheffield</option>
            </select> (optional; default 'all')
        </p>
        <p class="indent">3)<span class="info">select dates</span>
          <b>from</b>
            <input type="text" name="date_begin" placeholder="dd-mm-yyyy"
              value="[% c.query.param('date_begin') || dates.begin %]"
              class="datepicker" />
          <b>to</b>
            <input type="text" name="date_end" placeholder="dd-mm-yyyy"
              value="[% c.query.param('date_end') || dates.end %]"
              class="datepicker" />
          <input type="submit" name="action" value='Display' />
          [% IF reports.size # need to display at least once %]
            OR <input type="submit" name="action" value='Export' />
          [% END %]
        </p>
    </form>

    [% IF reports.size; # INCLUDE dumper.tt dump = reports %]
        <table class="report">
            <tr>
                <td class="borderless"></td>
            <!-- // overspills rhs page margin
                <th class="rotate"><div><span>Lab number</span></div></th>
                <th class="rotate"><div><span>Name</span></div></th>
                <th class="rotate"><div><span>NHS number</span></div></th>
                <th class="rotate"><div><span>Participant ID</span></div></th>
                <th class="rotate"><div><span>Presentation</span></div></th>
                <th class="rotate"><div><span>Family ID</span></div></th>
                <th class="rotate"><div><span>Source</span></div></th>
                <th class="rotate"><div><span>Participant type</span></div></th>
                <th class="rotate"><div><span>Registered</span></div></th>
                <th class="rotate"><div><span>Consent given</span></div></th>
                <th class="rotate"><div><span>Blood taken</span></div></th>
                <th class="rotate"><div><span>OMICS taken</span></div></th>
                <th class="rotate"><div><span>Blood DNA QC</span></div></th>
                <th class="rotate"><div><span>Tumour resected</span></div></th>
                <th class="rotate"><div><span>Tumour type</span></div></th>
                <th class="rotate"><div><span>Tumour DNA QC</span></div></th>
                <th class="rotate"><div><span>DNA dispatched</span></div></th>
                <th class="rotate"><div><span>OMICS dispatched</span></div></th>
                <th class="rotate"><div><span>Consent withdrawn</span></div></th>
            -->
                <th>Lab number</th>
                <th>Name</th>
                <th>NHS number</th>
                <th>Participant ID</th>
                <th>Presentation</th>
                [% UNLESS c.query.param('disease_type').match('[Cc]ancer') %]
                  <th>Family ID</th>
                [% END %]
                <th>Source</th>
                [% UNLESS c.query.param('disease_type').match('[Cc]ancer') %]
                  <th>Participant type</th>
                [% END %]
                <th>Registered</th>
                <th>Consent given</th>
                <th>Blood taken</th>
                <th>OMICS taken</th>
                <th>Blood DNA QC</th>
                [% UNLESS c.query.param('disease_type').match('rd') %]
                  <th>Tumour resected</th>
                  <th>Tumour type</th>
                  <th>Tumour DNA QC</th>
                [% END %]
                <th>DNA dispatched</th>
                <th>OMICS dispatched</th>
                <th>Consent withdrawn</th>
            </tr>
        [% FOREACH data IN reports; # INCLUDE dumper.tt dump = data;
            # filters:
            IF c.query.param('organisation');
                NEXT IF c.query.param('organisation').match('leeds')
                    AND data.organisation.match('SHEFFIELD');
                 NEXT IF c.query.param('organisation').match('sheffield')
                    AND NOT data.organisation.match('SHEFFIELD');
            END;
            IF c.query.param('disease_type');
                IF c.query.param('disease_type').match('all_cancer');
                    NEXT IF data.presentation.match('Rare disease');
                ELSIF c.query.param('disease_type').match('rd');
                    NEXT UNLESS data.presentation.match('Rare disease');
                ELSE; # must be specific cancer:
                    NEXT UNLESS c.query.param('disease_type').match(data.presentation);
                END;
            END;

            disease_type = data.presentation.match('Rare disease') ? 'rd' : 'cancer';
        %]
            <tr>
                <td>[% i = ( i || 0 ) + 1; i %]</td>
                <td>[% PROCESS site/lab_number.tt want_url=1 %]</td>
                <td>[% data.last_name.upper %], [% data.first_name.ucfirst %]</td>
                <td>[% data.nhs_number %]</td>
                <td>[% data.unit_number %]</td>
                <td>[% data.presentation %]</td>
                [% UNLESS c.query.param('disease_type').match('[Cc]ancer') %]
                  <td>
                    [% disease_type.match('rd') ? data.family_id : 'N/A' %]
                  </td>
                [% END %]
                <td>[% data.location %]</td>
                [% UNLESS c.query.param('disease_type').match('[Cc]ancer') %]
                  <td>
                    [% IF disease_type.match('rd');
                        IF data.family_id;
                            data.unit_number == data.family_id
                                ? 'Proband' : 'Relative';
                        ELSE; 'UNKNOWN'; END; ELSE; 'N/A';
                    END %]
                  </td>
                [% END %]
                <td>[% data.registered %]</td>
                <td>[% data.consent_date %]</td>
                <td>[% data.sample_taken %]</td>
                <td align="center">
                    [% (data.paxgene_rna + data.sst + data.pst + data.ccft_dna)
                         ? 'Y' : 'N' %]
                </td>
                <td>[% data.blood_summary_qc %]</td>
                [% UNLESS c.query.param('disease_type').match('rd') %]
                    <td>[% data.tumour_sample_taken %]</td>
                    <td>[% data.clinic_sample_type %]</td>
                    <td>[% data.tumour_summary_qc %]</td>
                [% END %]
                <td>[% data.dna_dispatched %]</td>
                <td>[% data.omics_dispatched %]</td>
                <td>[% data.withdrawal_option %]</td>
            </tr>
        [% END %]
        </table>
    [% ELSIF c.query.param('date_begin') %]
        <p class="warning indent">No data for selected interval</p>
    [% END %]
<!-- END [% template.name %] -->
