[% META title = 'Patient &raquo; Edit Unit Number' -%]

  <h2 class="header">Edit patient unit number</h2>

	[% # PROCESS dumper.tt dump = data.as_tree %]
	[% # PROCESS dumper.tt dump = requests_count %]
    [% # PROCESS dumper.tt dump = patient_case_count %]

    [% patient_case_dfv_js %]

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

    <p>
        <strong>Patient demographic data:</strong>
        [ <a href="[% app_url %]/patient/register_edit_patient/[% data.patient.id %]">Edit</a> ]
    </p>

    <div class="indent" style="text-align: center">
    <table>
	    <tr>
	        <th>Last Name</th>
	        <th>First Name(s)</th>
	        <th>Gender</th>
	        <th>D.o.B</th>
	        <th>NHS Number</th>
	        <th>Location</th>
	    </tr>
	    <tr>
	        <td>[% data.patient.last_name | upper %]</td>
	        <td>
                <span>[% data.patient.first_name  | ucfirst %]</span>
                <span>[% data.patient.middle_name | ucfirst %]</span>
            </td>
	        <td>[% data.patient.gender || 'U' %]</td>
	        <td>[% data.patient.dob.strftime('%d.%b.%Y') || site.html.grey_null %]</td>
	        <td>[% data.patient.nhs_number || site.html.grey_null %]</td>
	        <td>[% PROCESS site/display_name.tt location = data.referral_source.display_name %]</td>
	    </tr>
	</table>
    </div>

    <p class="spacer"></p>

    [% PROCESS site/autosuggest.tt %]
	<form action="[% app_url %]/patient/update_case/[% data.id %]" method="post" name="edit_case"
		id="edit_case" [% patient_case_onsubmit %]>

        <table class="indent">
            <tr>
                <td class="label">Unit/case number:</td>
                <td class="content">
                    <input class="field" type="text" name="unit_number" size="12"
                        [% site.html.on_focus %] value="[% data.unit_number %]" />
                    [% error_unit_number %]
                </td>
            </tr>
            <tr>
                <td class="label">Location:</td>
                <td class="search_bar">
				<input style="width: 300px" type="text" id="location_name"
                    name="_location_name" value="[% data.referral_source.display_name %]" />
                    <input type="hidden" id="source_id" name="referral_source_id" />
                    [% IF error_referral_source_id %]
                        [% error_referral_source_id %]
                    [% ELSE %]
                        [ <a href="[% app_url %]/config/referral-sources">new</a> ]
                    [% END %]
                </td>
            </tr>
            </tr>
          </table>

		[% IF requests_count %]
			<p class="bold">
				Number of existing records affected by this change =
					<span class="highlight">[% requests_count %]</span>
			</p>
		[% END %]

		<p class="center">
		    [% IF c.user_can('delete_record')
                AND patient_case_count > 1 # can't delete patient case if it's the only 1
                AND ! requests_count %]
              [ <a href="[% app_url %]/patient/delete_case/[% data.id %]">DELETE CASE</a> ]
		    [% END %]
			[% site.html.submit %]
			[% site.html.reset %]
		</p>

	</form>
