<!-- BEGIN admin/patient/merge/list.tt -->
	 [% IF patients.size == 1 # need > 1 patient to perform merge %]
		  <p class="warning">Only found 1 patient so cannot perform a merge:</p>
	 [% END %]

    <p class="spacer"></p>
	
   <form method="post" action="[% app_url %]/admin/patient_merge/do_merge"
	 [% INCLUDE site/snippets/disable_form_resubmission.tt
		 name = 'confirm' value = 'Go' %]>
	
   <p class="title">All records:
	[% div_name = 'all_records'; INCLUDE site/snippets/toggleview.tt %]
   </p>
   
    [% class = c.query.param('sort_by') ? 'itemhidden' : 'visible' %]
    <table id="[% div_name %]" class="[% class %]">		
	 <tr>
		 <th>id</th>
		 <th>Name</th>
		 <th>DoB</th>
		 <th>NHS No</th>
		 <th>M/F</th>
		 <th>Location</th>
		 <th>Unit No</th>
		 <th>Lab No</th>
		 <!-- <th>Registered</th> // clutter -->
		 <th>Diagnosis</th>
		 <th>Reported</th>
	 </tr>
	 [% FOREACH data IN records; # PROCESS dumper.tt dump = data.as_tree;
		 report  = report_map.item(data.id).request_report;
		 patient = data.patient_case.patient;
	 %]
	 <tr>
		 <td>[% patient.id %]</td>
		 <td class="bkgd_light_yellow">
			 [% patient.last_name   | upper %],
			 [% patient.first_name  | ucfirst %]
			 [% patient.middle_name | ucfirst %]
		 </td>
		 <td class="bkgd_light_yellow">[% patient.dob.strftime('%d.%b.%Y') %]</td>
		 <td class="bkgd_light_yellow">[% patient.nhs_number || site.html.grey_null %]</td>
		 <td class="bkgd_light_yellow">[% patient.gender || 'U' %]</td>
		 <td>
		  [% SET location = data.patient_case.referral_source.display_name;
			INCLUDE site/display_name.tt %]
		 </td>
		 <td>[% data.patient_case.unit_number %]</td>
		 <td>[% INCLUDE site/lab_number.tt want_url = 1 %]</td>
		 <!-- <td>[% data.created_at.strftime('%d.%b.%Y') %]</td> -->
		 <td>[% report.diagnosis.name %]</td>
		 <td>[% # set span colour for age of report:
          		age_of_report = report_map.item(data.id).age_of_report;
                IF ! age_of_report; class = 'red'; # not reported, or reported today
				ELSIF age_of_report == 1; class = 'orange'; # last working day
				ELSE; class = 'normal'; END;
            %]
			<span class="[% class %]">
				[% report.created_at.strftime('%d.%b.%Y') %]
			</span>
		 </td>
	 </tr>
	 [% END %]
	</table>
	
   [% IF patients.size > 1 # need at least 2 unqiue patients to merge %]
    <p class="title">Unique patient entries:</hp>

	<table class="indent">
	 <tr>
	  [% PROCESS admin/patient/merge/search_link.tt skip_sort_by = 1 # or get multiple %]
		 <th><a href="[% search_link %]">id</a></th>
		 <th><a href="[% search_link %];sort_by=name">Name</a></th>
		 <th><a href="[% search_link %];sort_by=dob">DoB</a></th>
		 <th><a href="[% search_link %];sort_by=nhs_number">NHS No</a></th>
		 <th>M/F</th>
		 <th><a href="[% search_link %];sort_by=unit_number">Unit No</a></th>
		 <th><a href="[% search_link %];sort_by=count">Freq.</a></th>
		 <th colspan="2" align="center">
			<span class="acronym" title="FROM">A</span> &#187;
			<span class="acronym" title="TO">B</span></th>
	 </tr>
	[% FOREACH entry IN patients; # PROCESS dumper.tt dump = entry;
		patient = entry.patient_case.patient; # PROCESS dumper.tt dump = patient;
	%]
	 <tr>
		 <td>[% patient.id %]</td>
		 <td class="bkgd_light_yellow">
			 [% patient.last_name   | upper %],
			 [% patient.first_name  | ucfirst %]
			 [% patient.middle_name | ucfirst %]
		 </td>
		 <td class="bkgd_light_yellow">[% patient.dob.strftime('%d.%b.%Y') %]</td>
		 <td class="bkgd_light_yellow">[% patient.nhs_number || site.html.grey_null %]</td>
		 <td class="bkgd_light_yellow">[% patient.gender %]</td>
		 <td>[% entry.patient_case.unit_number %]</td>
		 <th>[% entry.count %]</th>
		 <td>
			<label><input type="radio" name="[% entry.patient_case.id %]" value="from"></label>
		</td>
		 <td>
			<label><input type="radio" name="[% entry.patient_case.id %]" value="to"></label>
		 </td>
	 </tr>
	[% END %]
	</table>
   
    <p class="indent">
		<span class="highlight">Proceed to confirmation:</span>
		<input type="submit" class="button" name="confirm" value="Go" id="confirm" />
		[% site.html.reset %]
	</p>
  </form>
  [% END %]