[% META title = 'Patient &raquo; Select patient case' -%]

<!-- BEGIN patient/select_patient.tt -->

	[% # PROCESS dumper.tt dump = patient_cases %]
	[% # PROCESS dumper.tt dump = patient %]
	[% # PROCESS dumper.tt dump = pas_query %]
	[% # PROCESS dumper.tt dump = pds_query %]
	
	[% PROCESS patient/pas.tt IF pas_query %]
	[% PROCESS patient/pds.tt IF pds_query %]

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

	<p>
        <strong>Patient demographic data
			[% IF pas_query.match(messages.pas_verified) %]
				<span class="info">[PAS verified]</span>
			[% END %]
		</strong>
    </p>

    <div class="indent" style="text-align: center">
		<table>
			<tr>
				<th>id</th>
				<th>Last Name</th>
				<th>First Name(s)</th>
				<th>Gender</th>
				<th>D.o.B</th>
				<th>NHS Number</th>
				<td class="borderless">&nbsp;</td>
			</tr>
			<tr>
				<td>[% patient.id %]</td>
				<td>[% patient.last_name | upper %]</td>
				<td>
					<span>
						[% patient.first_name | ucfirst %]
						[% patient.middle_name | ucfirst %]
					</span>
				</td>
				<td>
					[% IF patient.gender.match('M|F') %]
						[% patient.gender %]
					[% ELSE %]
						<span class="red">U</span>
					[% END %]
				</td>
				<td>[% patient.dob.strftime('%d.%b.%Y') || site.html.grey_null %]</td>
				<td>[% INCLUDE site/nhs_number.tt nhs_number = patient.nhs_number %]</td>
				<td>
					<a class="href" href="[% app_url %]/patient/register_edit_patient/[% patient.id %]">
						<img class="href" src="/images/edit.jpg" alt="Edit" title="Edit patient">
					</a>
				</td>
			</tr>
		</table>
    </div>

	[% IF clinical_trials.size %]
      <p class="indent">
        <span class="warning">Patient also has clinical trial request(s):</span>
	  </p>
	  <ul class="indent">
        [% FOREACH trial IN clinical_trials %]
          <li><a href="[% app_url %]/search/do_search?patient_id=[% patient.id
            %];trial_id=[% trial.key %];_return=1">[% trial.value.trial_name %]</a>
            [[% trial.value.trial_number %]]
		  </li>
        [% END %]
      </ul>
	[% END %]

	<p>[% site.html.back_button %]</p>

	<h2 class="header">Select patient case:</h2>

	[% # PROCESS dumper.tt dump = patient_cases %]

	<div class="indent">
		<table class="patient_select">
			<tr>
				<th>&nbsp;</th>
				<th colspan="2">Location / Unit Number</th>
			</tr>
		[% FOREACH case IN patient_cases %]
			[% SET location = case.referral_source.display_name %]
			<tr>
				<td>[% loop.count %].</td>
				<td>[% PROCESS site/display_name.tt %]</td>
				<td>[% case.unit_number %]</td>
				<td>
					<a class="href" href="[% app_url %]/patient/edit_case/[% case.id %]">
						<img class="href" src="/images/edit.jpg" alt="Edit" title="Edit case">
					</a>
				</td>
				<td>
					<a class="href" href="[% app_url %]/request/add_new/[% case.id %]">
						<img class="href" src="/images/add.png" alt="New" title="New request">
					</a>
				</td>
			</tr>
		[% END %]

		</table>
	</div>

	[% PROCESS site/autosuggest.tt
        optional_params = [ "is_active=1" ] %]

	<h2 class="header">Add new location / unit number:</h2>

    [% new_location_dfv_js %]

    <form action="[% app_url %]/patient/add_new_location/[% patient.id %]" method="post"
		name="add_new" id="add_new" [% new_location_onsubmit %]>

    <div class="indent">
      <table>
        <tr>
            <td class="label">Unit Number:</td>
            <td class="content">
                <input class="field" type="text" name="unit_number" size="12"
                    [% site.html.on_focus %] value="" />
                [% error_unit_number %]
            </td>
        </tr>
        <tr>
            <td class="label">Location:</td>
			<td class="search_bar">
				<input style="width: 300px" type="text" id="location_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>
			<td class="borderless" colspan="2" align="center">
				[% site.html.submit %]
				<!-- [% site.html.reset %] // doesn't remove ajax #source_id -->
			</td>
		</tr>
      </table>
    </div>

    </form>
<!-- END patient/select_patient.tt -->
