<!-- BEGIN [% component.name %] -->
    <table class="table table-bordered table-striped demographics">
      <thead>
        <tr class="highlight">
          <td colspan="2">
            [% url_args = 'last_name=' _ patient.last_name _ ';first_name=' _
              patient.first_name _ ';middle_name=' _ patient.middle_name
            %]
            <h4 class="text-center">
              <a href="[% app_url %]/search/do_search?[% url_args | url %]">
                [% format_firstname(patient) || patient.first_name.ucfirst %]
                [% patient.middle_name.ucfirst IF patient.middle_name %]
                [% patient.last_name.upper %]
              </a>
            </h4>
          </td>
        </tr>
      </thead>

      <tbody>
        <!-- dob -->
        <tr>
          <td>
            [% url_args = 'dob_day=' _ patient.dob.strftime('%d') _ ';dob_month=' _
              patient.dob.strftime('%m') _ ';dob_year=' _ patient.dob.strftime('%Y')
            %]
            <span class="pull-right">
              <a href="[% app_url %]/search/do_search?[% url_args | url %]">DoB</a>
            </span>
          </td>
          <td>
            <span class="bold">
              [% IF patient.dob;
                  age_now = calculate_age(patient.dob, c.time_now);
                  age_at_req = calculate_age(patient.dob, data.created_at) %]
                <span class="[% acronym_class %]"
                    title="age at registration = [% age_at_req
                      %]; age now = [% age_now %]">
                  [% patient.dob.strftime('%d.%b.%Y') %]
                </span>
              [% ELSE; site.html.grey_null; END %]
            </span>
          </td>
        </tr>

        <!-- NHS number -->
        [% class = [];
          IF patient.nhs_number;
            url_args = 'nhs_number=' _ patient.nhs_number;
          ELSE;
            presentation = request_data.request_initial_screen.screen.description;
            trial_name   = request_data.request_trial.trial.trial_name;
            exemptions   = report_data_maps.nhs_number_exempt; # INCLUDE dumper.tt dump = exemptions;

            IF # one of exempted categories:
                exemptions.presentation.item(presentation) OR
                exemptions.clinical_trial.item(trial_name) OR
                exemptions.last_name.item(patient.last_name); # eg donor
              nhs_number_exempt = 1;
            END;
          END;

          UNLESS nhs_number_exempt;
            formatted_nhs_number = INCLUDE site/snippets/nhs_number.tt
              nhs_number = patient.nhs_number;
              # INCLUDE dumper.tt dump = formatted_nhs_number;
        %]
        <tr>
          [% UNLESS formatted_nhs_number.match('NULL') %]
            <td>
              <span class="pull-right">
              [% IF patient.nhs_number %]
                <a href="[% app_url %]/search/do_search?[% url_args | url %]">
                  NHS No</a>
              [% ELSE; 'NHS No'; END %]
              </span>
            </td>
            <td class="nowrap">
              <span class="bold">[% formatted_nhs_number %]</span>
            </td>
          [% ELSE # no NHS number & not exempt: %]
            <td colspan="2">
              <span class="label label-important">
                PLEASE USE THE NHS NUMBER
              </span>
            </td>
          [% END %]
        </tr>
        [% END %]

        <!-- unit number -->
        <tr>
          <td>
            <span class="pull-right">
              [% IF data.patient_case.unit_number;
                  url_args = 'unit_number=' _ data.patient_case.unit_number %]
                <a href="[% app_url %]/search/do_search?[% url_args | url %]">Unit No</a>
              [% ELSE %]
                Unit No
              [% END %]
            </span>
          </td>
          <td>[% data.patient_case.unit_number || site.html.grey_null %]</td>
        </tr>

        <!-- referral source -->
        <tr>
          <td>
            <span class="pull-right">Source</span>
          </td>
          <td>
            [% IF is_gp; 'GP practice';
                ELSE;
                  location = data.patient_case.referral_source.display_name;
                  IF is_print_request; location;
                  ELSE; PROCESS site/display_name.tt; END;
              END %]
          </td>
        </tr>

        <!-- referrer -->
        [%
          department = data.referrer_department.hospital_department;
          referrer   = data.referrer_department.referrer;
        %]
        <tr>
          [% IF referrer.name == 'cc' %]
            <td><span class="pull-right warning">Copy&nbsp;to</span></td>
            <td></td>
          [% ELSIF NOT is_gp %]
          <td><span class="pull-right">Referrer</span></td>
          <td>
            <span [% IF department %]class="[% acronym_class %]" title="[%
              department.display_name %]"[% END %]>[% referrer.name %]
            </span>
          </td>
          [% END %]
        </tr>

        <!-- HMDS ref -->
        <tr>
          <td><span class="pull-right">Lab No</span></td>
          <td>
            [% PROCESS site/snippets/lab_number.tt want_url = 0 # expects request object 'data' %]
          </td>
        </tr>
      </tbody>
    </table>
<!-- END [% component.name %] -->
