    [% META title = 'Registration &raquo; Patient Search' -%]

<!-- BEGIN register/select_patient.tt -->
 	[% # PROCESS dumper.tt dump = patients %]
 	[% # PROCESS dumper.tt dump = results.cases_map %]

	<p>
		[% # 06register.t requires next line to output to single line:
			n = total_count; %]
		Found <b>[% n %]</b> record[% IF n != 1 %]s[% END %] matching <b>[% search_term %]</b>
		[ <a href="[% app_url %]/patient">NEW PATIENT</a> ]
	</p>

	<div class="indent">
        <table>
            <tr>
                <th>
				[% q = c.query;
					IF c.user_can('patient_merge') AND (
						q.param('last_name') OR q.param('unit_number') OR q.param('year')
					);
				%]
					<a href="[% app_url %]/admin/patient_merge/search?last_name=[%
						q.param('last_name') %];first_name=[% q.param('first_name')
						%];unit_number=[% q.param('unit_number') %];year=[% q.param('year')
						%];month=[% q.param('month') %];day=[% q.param('day') %]"
						target="_blank">
							<span class="acronym" title="merge patients">id</span>
					</a>
				[% ELSE %]id
				[% END %]					
				</th>
                <th>LastName</th>
                <th>FirstName(s)</th>
                <th>Sex</th>
                <th>D.o.B</th>
                <th>NHS No.</th>
                <td class="borderless">&nbsp;</td>
                <td class="borderless">&nbsp;</td>				
			</tr>

		[%
			patients  = results.patients;
			cases_map = results.cases_map;
		
			FOREACH patient IN patients; # PROCESS dumper.tt dump = patient;
		%]
            <tr>
                <td>[% patient.id %]</td>
                <td class="bkgd_light_yellow">
					[% patient.last_name | upper %]
				</td>
                <td class="bkgd_light_yellow">
                    <span>
						[% patient.first_name  | ucfirst %]
						[% patient.middle_name | ucfirst %]
					</span>
                </td>
                <td align="center" class="bkgd_light_yellow">
					[% patient.gender || site.html.grey_null %]
				</td>
                <td class="bkgd_light_yellow">
					[% patient.dob.strftime('%d.%b.%Y') || site.html.grey_null %]
				</td>
                <td class="bkgd_light_yellow">
					[% nhs_number  = patient.nhs_number; INCLUDE site/nhs_number.tt %]
				</td>
                <td>
					[% IF c.user_can('edit_pid') %]
					<a class="href" href="[% app_url %]/patient/register_edit_patient/[% patient.id %]">
						<img class="href" src="/images/edit.jpg" alt="Edit" title="Edit patient" />
					</a>
					[% ELSE %]
						<img src="/images/edit.jpg" alt="Edit" />
					[% END %]
				</td>
                <td>
					<a class="href" alt="Select" title = "Select patient"
					   href="[% app_url %]/patient/select_patient/[% patient.id %]">
						<img class="href" src="/images/select.png" alt="Select" />
					</a>
				</td>
			</tr>
			
			<tr class="bold borderless">
				<td></td>
				<td colspan="5">
					<span class="italic-title">referral details</span>
					[% div_name = 'ID' _ patient.id;
						INCLUDE site/snippets/toggleview.tt %]
					<ol class="itemhidden" id="[% div_name %]">
					  [% FOREACH case IN cases_map.item(patient.id) %]
						<li class="register">
							[% location = case.referral_source.display_name;
								INCLUDE site/display_name.tt %] ::
							[% case.unit_number || site.html.grey_null %]
						</li>
					  [% END %]
					</ol>
				</td>
				<td colspan="3"></td>				
            </tr>

		[% END %]
        </table>

	</div>
	[% PROCESS site/cgi_pager.tt %]
<!-- END register/select_patient.tt -->
