<!-- 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 %]

   [% # INCLUDE dumper.tt dump = report_map %]
 
    <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' %] name="do_merge">
	
   <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 entry IN records; # PROCESS dumper.tt dump = entry;
		 patient  = entry.patient;
		 report   = entry.request.request_report; # PROCESS dumper.tt dump = report.as_tree;
		 location = patient.patient_case.referral_source.display_name; # for display_name.tt 
	 %]
	 <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>
		  [% INCLUDE site/display_name.tt %]
		 </td>
		 <td>[% patient.patient_case.unit_number %]</td>
         
        [% data = entry.request; IF data; # will not be if patient orphan %]
		 <td>[% INCLUDE site/lab_number.tt want_url = 1; %]</td>
		 <td>[% report.diagnosis.name || site.html.grey_null %]</td>
		 <td>[% # set span colour for age of report:
          		delta_report = entry.request.delta_report; # delta_report;
                IF ! delta_report; class = 'red'; # not reported, or reported today
				ELSIF delta_report == 1; class = 'orange'; # last working day
				ELSE; class = 'normal'; END;
            %]
			<span class="[% class %]">
				[% report.created_at.strftime('%d.%b.%Y') %]
			</span>
		 </td>
        [% ELSE %]
         <td colspan="3" align="center">
          -------- patient ID has no associated requests --------
         </td>
        [% END %]
	 </tr>
	 [% END %]
	</table>
	
   [% IF patients.size > 1 # need at least 2 unqiue patients to merge %]
    <p class="title">Unique patient entries:</p>

	<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; # 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>[% patient.patient_case.unit_number %]</td>
		 <th>[% entry.count %]</th>
		 <td>
			<label><input type="radio" name="[% patient.patient_case.id %]" value="from"></label>
		</td>
		 <td>
			<label><input type="radio" name="[% patient.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 %]