[% META title = 'Request &raquo; Edit' %]

<!-- BEGIN request/edit.tt -->
    [% # PROCESS dumper.tt dump = record_count %]
    [% # PROCESS dumper.tt dump = patient_cases %]
    [% # PROCESS dumper.tt dump = c.stash.errs %]
    [% # PROCESS dumper.tt dump = request_data.has_optional %]
    [% # PROCESS dumper.tt dump = request_data.data.request_initial_screen.screen %]
	
    [%
		SET patient = request_data.data.patient_case.patient;
		SET data    = request_data.data;
	%]        

	[% # load appropriate autosuggest.tt:
		IF want_request_data; # need 'referrer' autosuggest
			PROCESS site/autosuggest.tt 
				varname         = 'referrer_name'
				param_id        = 'referrer_id'
				param_name      = 'referrer_name'
				method_name     = 'get_clinicians'
				optional_params = [ "source_id=${data.patient_case.referral_source_id}" ]
				watermark       = 'no';
		ELSE; # need 'location' autosuggest
			PROCESS site/autosuggest.tt
                optional_params = [ "is_active=1" ]
                watermark = 'no';
		END;
	%]

	[% update_request_dfv_js %]

	<h2 class="header">Edit request details</h2>

    [% IF dfv_errors %]
        <p class="error">[% c.cfg('msg').dfv_errors %]</p>
    [% END %]

	[% INCLUDE site/snippets/help.tt file = 'editrequest' %]
	
    <p class="title">Patient demographic data:
        [% IF c.user_can('edit_pid') %]
        [<a class="href"
			href="[% app_url %]/patient/edit_patient/[% patient.id %]/[% data.id %]">edit</a>]
	    [% END %]
	</p>
    
    <div class="indent" style="text-align: center">
    <table>
	    <tr>
	        <th>Lab Number</th>
	        <th>Last Name</th>
	        <th>First Name(s)</th>
	        <th>Gender</th>
	        <th>D.o.B</th>
	        <th>NHS Number</th>
	    </tr>
	    <tr>
			<td>[% PROCESS site/lab_number.tt want_url = 1 %]</td>
	        <td>[% patient.last_name | upper %]</td>
	        <td>
                <span>
					[% patient.first_name  | ucfirst %]
					[% patient.middle_name | ucfirst %]
				</span>
            </td>
	        <td>[% patient.gender || 'U' %]</td>
	        <td>[% patient.dob.strftime('%d.%b.%Y') || site.html.grey_null %]</td>
	        <td>[% PROCESS site/nhs_number.tt nhs_number = patient.nhs_number %]</td>
	    </tr>
	</table>
    </div>

    <form method="post" action="[% app_url %]/request/update/[% data.id %]"
		name="_update_request" id="_update_request" [% update_request_onsubmit %]>
		
	[% IF data.request_initial_screen %]
		<p class="classname"><strong>Initial screen:</strong>
			[% data.request_initial_screen.screen.description %]
			[% IF c.user_can('edit_pid') %]
			<strong>
				[<a href="[% app_url %]/screen/edit/[% data.id %]">edit</a>]
			</strong>
			[% END %]
		</p>
	[% END %]
		
[% IF want_request_data %]
		[% # hidden flag for Validate() & Request::update() to signal it's request data: %]
		<input type="hidden" name="_request_data" value=1 />
		
	<p class="title">
		Patient case data: 
		[% IF c.user_can('edit_pid') # link back to default page: %]
			[<a href="[% app_url %]/request/edit/[% data.id %]">edit</a>]
		[% END %]
		[% div_name = 'case'; INCLUDE site/snippets/toggleview.tt %]
	</p>
	
	<div class="itemhidden" id="[% div_name %]">	
		[% PROCESS request/edit/display_case_data.tt # display case data only %]		
	</div>
	
	<div id="request_edit">
		<p class="title">Request data:</p>
		
		[% PROCESS request/edit/edit_request_data.tt %]
	
		[% PROCESS request/request_options.tt %]
		[% PROCESS request/request_consent.tt %]	
	</div>
	
[% ELSE %]
	<p class="title">
		Request data:
		[% IF c.user_can('edit_pid') # link to edit request details: %]
			[<a href="[% app_url %]/request/edit_request/[% data.id %]">edit</a>]
		[% END %]
		[% div_name = 'request'; INCLUDE site/snippets/toggleview.tt %]
	</p>
	
	<div class="itemhidden" id="[% div_name %]">		
		[% PROCESS request/edit/display_request_data.tt # just display request data %]
	</div>
	
	<div id="request_edit">
		[% PROCESS request/edit/edit_case_data.tt %]			
	</div>
[% END %]
	
	[% PROCESS site/reason_for_change.tt %]
	
	</form>
	
    [% # PROCESS dumper.tt dump = data %]
<!-- END request/edit.tt -->
