[% META title = 'Patient &raquo; Merge Patients &raquo; Confirm' -%]

<!-- BEGIN admin/patient/merge/confirm.tt -->

	[% # PROCESS dumper.tt dump = merge_from %]
	[% # PROCESS dumper.tt dump = merge_to.as_tree %]
	[% # PROCESS dumper.tt dump = c.session.param('_patient_merge_data') %]

    <h2 class="header">Confirm Patient Merge</h2>
    
	[% BLOCK arrow %]<td class="label"> &#187; </td>[% END %]
	
   <form method="post" action="[% app_url %]/admin/patient_merge/do_merge"
	 [% INCLUDE site/snippets/disable_form_resubmission.tt
		name = 'change' value = 'Merging' %]>
    <table class="indent">
        <tr>
            <td class="borderless" align="right"><strong>Merge</strong>:</td>
            <th colspan="[% merge_from.size %]">From</th>
            <td class="borderless"></td>
            <th>To</th>
        </tr>
        <tr>
            <td class="label">Patient ID:</td>
            [% FOREACH from IN merge_from %]
                <td>[% from.patient.id %]</td>
            [% END %]
            [% INCLUDE arrow %]
            <td>[% merge_to.patient.id %]</td>
        </tr>
        <tr>
            <td class="label">Last Name:</td>
            [% FOREACH from IN merge_from;
				class = from.patient.last_name != merge_to.patient.last_name
				? 'orange bkgd_light_yellow' : 'normal'
			%]
                <td class="[% class %]">[% from.patient.last_name | upper %]</td>
            [% END %]
            [% INCLUDE arrow %]
            <td>[% merge_to.patient.last_name | upper %]</td>
        </tr>
        <tr>
            <td class="label">First Name:</td>
            [% FOREACH from IN merge_from;
				class = from.patient.first_name != merge_to.patient.first_name
				? 'orange bkgd_light_yellow' : 'normal'
			%]
                <td class="[% class %]">[% from.patient.first_name | ucfirst %]</td>
            [% END %]
            [% INCLUDE arrow %]
            <td>[% merge_to.patient.first_name | ucfirst %]</td>
        </tr>
        [% have_middle_name = []; # only show middle name row if have any:
            FOREACH from IN merge_from; NEXT UNLESS from.patient.middle_name;
                have_middle_name.push(from.patient.middle_name); END;
            IF merge_to.patient.middle_name; have_middle_name.push(merge_to.patient.middle_name); END;
            IF have_middle_name.size; # in either 'from' list or 'to':
        %]
        <tr>
            <td class="label">Middle Name:</td>
            [% FOREACH from IN merge_from;
				class = from.patient.middle_name != merge_to.patient.middle_name
				? 'orange bkgd_light_yellow' : 'normal'
			%]
                <td class="[% class %]">[% from.patient.middle_name | ucfirst %]</td>
            [% END %]
            [% INCLUDE arrow %]
            <td>[% merge_to.patient.middle_name | ucfirst %]</td>
        </tr>
        [% END %]
        <tr>
            <td class="label">DoB:</td>
            [% FOREACH from IN merge_from;
				class = from.patient.dob != merge_to.patient.dob
				? 'orange bkgd_light_yellow' : 'normal'
			%]
                <td class="[% class %]">
					[% from.patient.dob.strftime('%d.%b.%Y') || site.html.grey_null %]
				</td>
            [% END %]
            [% INCLUDE arrow %]
            <td>[% merge_to.patient.dob.strftime('%d.%b.%Y') || site.html.grey_null %]</td>
        </tr>
        <tr>
            <td class="label">NHS number:</td>
            [% FOREACH from IN merge_from;
				class = from.patient.nhs_number != merge_to.patient.nhs_number
				? 'orange bkgd_light_yellow' : 'normal'
			%]
                <td class="[% class %]">
					[% from.patient.nhs_number || site.html.grey_null %]
				</td>
            [% END %]
            [% INCLUDE arrow %]
            <td>[% merge_to.patient.nhs_number || site.html.grey_null %]</td>
        </tr>
        <tr>
            <td class="label">Gender:</td>
            [% FOREACH from IN merge_from;
				class = from.patient.gender != merge_to.patient.gender
				? 'orange bkgd_light_yellow' : 'normal'
			%]
                <td class="[% class %]">[% from.patient.gender || 'U' %]</td>
            [% END %]
            [% INCLUDE arrow %]
            <td>[% merge_to.patient.gender || 'U' %]</td>
        </tr>
		
		[% # if any diffs between unit_numbers, offer choice of merge:
			unit_number_diff = 0;
			FOREACH from IN merge_from;
				IF from.unit_number != merge_to.unit_number;
					unit_number_diff = unit_number_diff + 1;
				END;
			END;
			IF unit_number_diff;
		%]
			<tr class="borderless">
				<td colspan="[% merge_from.size + 2 %]" align="right">
					Merge patient only:
					<input type="radio" name="scope" value="patient" />
				</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td class="label">Unit number:</td>
				[% FOREACH from IN merge_from;
					class = from.unit_number != merge_to.unit_number
					? 'orange bkgd_light_yellow' : 'normal'
				%]
					<td class="[% class %]">[% from.unit_number || site.html.grey_null %]</td>
				[% END %]
				[% INCLUDE arrow %]
				<td>[% merge_to.unit_number || site.html.grey_null %]</td>
			</tr>
			<tr class="borderless">
				<td colspan="[% merge_from.size + 2 %]" align="right">
					Merge patient AND unit number:
					<input type="radio" name="scope" value="unit_no" />
				</td>
				<td>&nbsp;</td>
			</tr>
		[% END %]
    </table>
    
    <p class="classname">
        [% # site.html.back_button %]
		<span class="highlight">
			I AM ABSOLUTELY CERTAIN I WANT TO PERFORM THIS <strong>IRREVERSIBLE</strong>
			MERGE:</span>	
        [% FOREACH p IN merge_from %]
            <input type="hidden" name="[% p.id %]" value="from" />
        [% END %]
		<input type="hidden" name="[% merge_to.id %]" value="to" />
		<input type="hidden" name="confirm_merge" value="1" />
        
		<input type="submit" class="button" name="change" value="Change" id="change" />
		[% PROCESS admin/patient/merge/search_link.tt %]
        <a href="[% search_link %]">CANCEL</a>        
 	</p>
   </form>
<!-- END admin/patient/merge/confirm.tt -->
