<!-- BEGIN [% template.name %] -->
  [% META title = 'Resources &raquo; New/Relapsed Diagnoses' -%]

    [% # PROCESS dumper.tt dump = locations %]
    [% # PROCESS dumper.tt dump = results %]
    
	<h2 class="header">New / relapsed diagnoses</h2>

    [% IF locations %]
    <p class="indent bold">
        Please select a location and duration [or leave blank for default 7 days]:
    </p>
    
    <form action="[% app_url %]/resources/new_diagnoses" method="post" [% # 'post' to hide org_code %]
        name="new_diagnoses" id="new_diagnoses">
        <p class="indent">Location:
            <select name="org_code">
                [% IF locations.size > 1 %]
                    <option value="">-- select one --</option>
				[% END %]
                [% IF c.is_lab_staff %]
                    <option value="%" [% 'selected' IF
							c.query.param('org_code') == '%' %]>
                        All locations</option>
                [% END %]
                
                [% FOREACH location IN locations %]
                    <option value="[% location.value %]" [% 'selected' IF location.value
                        == c.query.param('org_code') %]>[% location.key %]
                    </option>
                [% END %]
            </select>
            for previous <input type="text" name="duration" size="3"
                value="[% c.query.param('duration') %]" /> days
        </p>
        <p class="indent">
            Include follow-up cases: <input type="checkbox" name="all_cases" value=1
                [% 'checked' IF c.query.param('all_cases') %] />            
            [% site.html.submit %]
        </p>
    </form>
    [% ELSE # new login 'hello' page %]
      <p class="indent bold">
        [% results.size ? 'F' : 'None f' %]or [% user.user_location.location_name %]
        over previous 7 days[% IF results.size; ':'; END %]
      </p>
    [% END %]
    
    [% IF results.size %]
        [% # site.html.back_button %]
        
    <p class="red indent">
        ** Please note a full written report will be issued for all cases **
    </p>
    
    <table class="indent outreachResults">
        <tr>
            <th scope="col">Lab No.</th>
            <th scope="col">Name</th>
            <th scope="col">DoB</th>
            <th scope="col">NHS No.</th>
            <th scope="col">Source</th>
            <th scope="col">Date</th>
            <th scope="col">Authorised</th>
            <th scope="col">Diagnosis</th>
            <th scope="col">Status</th>
        </tr>
        [% FOREACH data IN results; # PROCESS dumper.tt dump = data.as_tree;
            patient = data.patient_case.patient;
            report_status = data.request_report.status;
        %]
        <tr [% IF report_status == 'relapse' %] style="background: #fff8dc"[% END %]>
            <td>[% INCLUDE site/lab_number.tt want_url = 1 %]</td>
            <td>
                [% patient.last_name   | upper %],
                [% patient.first_name  | ucfirst %]
                [% patient.middle_name | ucfirst %]
            </td>
            <td>[% patient.dob.strftime('%d.%b.%Y') %]</td>
            <td>[% patient.nhs_number || site.html.grey_null %]</td>
            <td>
                [% INCLUDE site/display_name.tt
                location = data.patient_case.referral_source.display_name %]
            </td>
            <td>[% data.created_at.strftime('%d.%b.%Y') %]</td>
            <td>
				[% data.request_status.time.strftime('%d.%b.%Y') %]
            </td>
            <td>
               	[% diagnosis = data.request_report.diagnosis.name %]
				[% IF diagnosis.match('See comments') %]
					<span class="acronym" title="[% data.request_report.comment %]">
					[% diagnosis %]
					</span>
				[% ELSE %]
					[% diagnosis %]
				[% END %]
            </td>
            <td>[% report_status.remove('default').upper %]</td>
        </tr>
        [% END %]
    </table>
    
    [% ELSIF c.query.param('org_code') # have done a search %]
        <p class="info">No new / relapsed cases over selected duration</p>
    [% END %]
<!-- END [% template.name %] -->
