	<!-- start patient/pas.tt -->
    [% messages = c.messages('demographics') %]
        [% # PROCESS dumper.tt dump = pas_query %]

    [% IF is_code_ref(pas_query).match('ARRAY') # strings processed below %]
	
		[% SET pat_no_max_length = 0 %]

		[% FOREACH q IN pas_query # work out maximum case_number length %]
            [% DEFAULT q.unit_number = 0 # or get "argument isn't numeric" error %]
			[% IF q.unit_number.length > pat_no_max_length;
				pat_no_max_length = q.unit_number.length; END %]
		[% END %][% # pat_no_max_length %]

		[% SET spacer = '0' # string not integer %]

	<div id="pas">
		<h4>PAS found the following new/changed details:</h4>

		[% FOREACH query IN pas_query %]
		<p class="pas">
			[% SET no_of_spacers = pat_no_max_length - query.unit_number.length %]
			<span class="hide_spacer"><!-- DON'T LINE BREAK NEXT LINE: -->
			[% spacer.repeat(no_of_spacers) %]</span><strong>[% query.unit_number %]
            </strong> =

			[% FOREACH field IN [ 'last_name' 'first_name' 'dob' 'nhs_number' ] %]
                [%
                    IF field == 'dob'; # patient.dob = DateTime object
                        a = patient.dob.ymd;
                    ELSE;
                        a = patient.$field | lower;
                    END;
                %]

				[% b = query.$field | lower %]

				[% IF a != b # highlight it %]
					<span class="pas">[% query.$field || '[NULL]' %]</span>
				[% ELSE %]
					[% query.$field || '[NULL]' %]
				[% END %]

				[% IF loop.next %] :: [% END %]
			[% END %]
		</p>
		[% END %]
		
		[% SET path_info = c.query.url(path_info = 1) %]
		[% IF path_info.match('patient/add_new') # only relevant for _check_new_patient() %]
			<p class="bold">
				You need confirm new patient details are correct to proceed:
				<input type="checkbox" name="_pas_confirmed" value="1" />
			</p>
		[% END %]
	</div>

	[% ELSIF NOT ( pas_query.match(messages.pas_verified) # goes in select_patient.tt
		OR c.query.param('_skip_pas') ) # have already been there
	%]
        [% IF pas_query.match(messages.pas_insufficient_info) %]
            <p class="warning">[% pas_query %] -
                <a href="[% app_url %]/pas/search/[% patient.id %]">
                    <span class="more-pas">GET SOME MORE</a></span>
            </p>
        [% ELSIF pas_query.match(messages.pas_no_matches) %]
            <p class="warning">[% pas_query %] -
				[% IF patient %]
					<a href="[% app_url %]/pas/search/[% patient.id %]">
				[% ELSE;
					params = [];
					FOREACH entry IN ['last_name' 'first_name' 'nhs_number'
						'unit_number' 'year' 'month' 'day' 'referral_source_id'];
						params.push(entry _ '=' _ c.query.param(entry));
					END;
				%]
					<a href="[% app_url %]/pas/search?[% params.join(';') %]">
				[% END %]
                    <span class="more-pas">FIND SOME</span>
				</a>
            </p>
        [% ELSIF messages.pas_query # other known pas messages %]
            <p class="warning">[% messages.pas_query %]</p>

        [% ELSE # default catch-all %]
            <p class="warning">[% pas_query %]</p>
        [% END %]
	[% END %]
    <!-- end patient/pas.tt -->