[% content_only = 1 # no html wrappers %]

  [%
	data    = request.data; # PROCESS dumper.tt dump = data;
	patient = data.patient_case.patient;
	history = request.history;
  %]  

  [% # PROCESS dumper.tt dump = request.all_results %]
  
<html>
<head>
  <title>
    [% patient.last_name   | upper %],
    [% patient.first_name  | ucfirst %]
    [% patient.middle_name | ucfirst %]
    [[% PROCESS site/lab_number.tt; want_url=0 %]]
  </title>
    <style type="text/css">
    <!--/* <![CDATA[ */    
            body { margin: 0; padding: 25px 5px; border: solid 1px #000; }
            h2 { color: #00f; text-align: center }
            td { vertical-align: top; padding: 2px 5px; font-family: verdana, sans-serif; font-size: small }
            #left { width: 50% }
            td.label { text-align: right; font-weight: bold;  }
            @media print {
                #back { display: none }
            }    
    /* ]]> */-->
    </style>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
  <h2>
    [% PROCESS site/lab_number.tt %]
    DRAFT REPORT:
    [% patient.last_name   | upper %],
    [% patient.first_name  | ucfirst %]
    [% patient.middle_name | ucfirst %]    
  </h2>
   
  <table>
    <tr>
      <td id="left">
        <table>
          <tr>
            <td class="label">Location:</td>
            <td>[% data.patient_case.referral_source.display_name %]</td>
          </tr>
          <tr>
            <td class="label">Clinician:</td>
            <td>[% data.referrer_department.referrer.name %]</td>
          </tr>
          <tr>
            <td class="label"> DoB:</td>
            <td>[% patient.dob.strftime('%d.%b.%Y') %]</td>
          </tr>
          <tr>
            <td class="label"> ID:</td>
            <td>
              [% IF patient.nhs_number %]
                [% PROCESS site/nhs_number.tt nhs_number = patient.nhs_number %]
                [% IF data.patient_case.unit_number %]
                  [[% data.patient_case.unit_number %]]
                [% END %]
              [% ELSE %]
                [% data.patient_case.unit_number || 'unknown' %]				
              [% END %]                
            </td>
          </tr>
          <tr>
            <td class="label">Received:</td>
            <td>[% data.created_at.strftime('%d.%b.%Y') %]</td>
          </tr>
        </table>
      </td>
      <td>
        <table>
          <tr>
            <td class="label">Specimen:</td>
            <td>[% request.specimen_map.item(data.id).description.join('; ') %]</td>
          </tr>
          <tr>
            <td class="label">Quality:</td>
            <td>[% data.request_report.specimen_quality %]</td>
          </tr>
          <tr>
            <td class="label">Description:</td>
            <td>[% data.request_gross_description.detail %]</td>
          </tr>
          <tr>
            <td class="label">Details:</td>
            <td>[% symbolise(data.request_report.clinical_details) %]</td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  <br />
  
  <table>
	[% FOREACH section IN request.all_results;
    NEXT UNLESS section.value.has_result_summary.match('yes');
		section_result_summary = request.result_summaries.item(section.key);
		
		test_results = [ ]; # reset array
		FOREACH t IN section.value.test;
		  NEXT UNLESS t.value.result;
		  result = t.key _ '<sup>' _ t.value.result _ '</sup>';
		  test_results.push(result);
		END;		
	  %]
	  
	  [% # skip unless results summary or test results:
		NEXT UNLESS section_result_summary || test_results.size %]
    <tr>
      <td class="label">[% section.key %]:</td>
      <td>
        [% IF test_results.size; test_results.join(' '); END %]
        [% section_result_summary.results_summary | html %]
      </td>
    </tr>
  [% END %]
  </table>
  
  <table>
    <tr>
      <td class="label">Comment:</td>
      <td>
        [%
          raw_comment = line_break(data.request_report.comment);
          symbolise(raw_comment) | html_line_break;
        %]
      </td>
    </tr>
    <tr>
      <td class="label">Diagnosis:</td>
      <td>
        [% data.request_report.diagnosis.name | html %]
        [[% history.reported.user.first_name | ucfirst %]
        [% history.reported.user.last_name  | ucfirst %]
        on [% history.reported.time.strftime('%d.%b.%Y at %H:%M') %]]
      </td>
    </tr>
  </table>
  
  <p align="center" id="back">[% site.html.back_button %]</p>
</body>
</html>