<!-- BEGIN outreach/demographics.tt -->
  [% demographics = outreach.demographics;
    # PROCESS dumper.tt dump = demographics %]

    [% PROCESS site/autosuggest.tt %]
    <script type="text/javascript">
      <!--
        function make_blank() {
          document.demographic.practice_name.value = "";
        }
      -->
    </script>

  <form method="post" enctype="multipart/form-data" name="demographic" id="demographic"
      action="[% app_url %]/outreach/demographics/[% request_data.id %]/[% patient_id %]">

	<table class="indent borderless">
		<tr>
			<td rowspan="2" valign="top"><b>Address</b>: [% errs.address %]</td>
			<td rowspan="2">
				<textarea name="address" cols="25" rows="2">[% demographics.address %]</textarea>
			</td>
      
			<td><b>Post code</b>: [% errs.post_code %]</td>
			<td>
				<input type="text" name="post_code" size="12"
                    value="[% demographics.post_code %]" id="is_valid_post_code"
                    onChange="do_ajax(['is_valid_post_code'], ['bad_postcode']); return true;"
                />
                <span class="ajax_error"><em id="bad_postcode"></em></span>
			</td>
			
            [% class = demographics.dispatch_to != 'home' ? 'red' : 'normal' %]
            <td class="[% class %]"><b>Dispatch to:</b> [% errs.dispatch_to %]</td>
			<td>
                [% IF ! demographics.dispatch_to; demographics.dispatch_to = 'home'; END %]
				<select name="dispatch_to">
					<option value="">&nbsp;</option>
					[% FOREACH entry IN [ 'GP' 'home' 'alternate'] %]
					<option [% 'selected' IF entry == demographics.dispatch_to %]
                        value="[% entry %]">[% entry %]</option>
					[% END %]
				</select>
			</td>      
		</tr>

		<tr>
			<td><b>Telephone</b>: [% errs.telephone_no %]</td>
			<td>
				<input type="text" name="contact_number" size="15"
          value="[% demographics.contact_number %]" />
			</td>

        [% class = demographics.status == 'dead' ? 'red' : 'normal' %]
      <td class="[% class %]" align="right"><b>Status:</b></td>
			<td>        
				<select name="status">
					[% FOREACH entry IN [ 'alive' 'dead' ] %]
            <option [% 'selected' IF entry == demographics.status %] value="[% entry %]">
              [% entry %]
            </option>
					[% END %]
				</select>
			</td>
		</tr>

    <tr>
        [% class = demographics.non_participant_practices.item(demographics.practice_id)
            ? 'red' : 'normal' # flag non-participant practice %]
      <td class="[% class %]"><b>Practice</b>:</td>
      <td colspan="5">
        <input type="text" name="practice_name" id="location_name"
          value="[% demographics.display_name %]"
          style="width: 600px" onclick="make_blank();" />
        <input type="hidden" id="source_id" name="practice_id"
            value="[% demographics.practice_id %]" />
        [% IF 1; fname = 'find_gp_popup'; # already have spell-check popup
            INCLUDE site/popup.tt height=300, width=850, top=50 %]
            <a class="nav" href="[% app_url %]/hmrn/find_practice"
                onclick="return [% fname %](this.href);">
                <img class="href" src="/images/question.gif"
                    title="find practice by GP" />
            </a>
        [% END %]
      </td>
    </tr>

    <tr>
      <td class="[% class %]" align="right"><b>GP</b>:</td>
      <td>
        <select name="gp_id">
          <option value="">--select one--</option>
        [% FOREACH gp IN demographics.practitioners;
          id   = gp.first;
          name = gp.last;
        %]
          <option value="[% id %]" [% 'selected' IF id == demographics.gp_id %]>
            [% name %]
          </option>
        [% END %]
          <option disabled>---------------</option>
          <option value="[% demographics.unknown_gp_id %]"
                [% 'selected' IF demographics.gp_id == demographics.unknown_gp_id
                    OR ! demographics.practitioners.size # is a required field %]>
            [ unlisted ]
          </option>
        </select>
        [% IF class == 'red' %]
            <span class="red">[ non-participant practice ]</span>
        [% END %]
      </td>
      
      <td><b>Blood tube:</b></td>
      <td colspan="2">
        [% # demographics.tube_type only supplied if practice override in place:
            override = demographics.tube_type ? 1 : 0; 
            default_tube_type = tube_type(demographics.post_code); # callback
        %]
        <select name="tube_type" [% site.html.disabled %]>
            <option selected>
              [% demographics.tube_type || default_tube_type %]
            </option>
        </select>
        [% IF override %]
            <span class="red">&#171; practice override</span>
        [% END %]
		[% IF c.user_can('edit_outreach_data') %]
			[<a href="[% app_url %]/config/outreach-practices/edit/[%
                demographics.practice_id %]" target="_blank">edit</a>]
		[% END %]
      </td>
      <td class="borderless">[% INCLUDE outreach_submit require_reset = 1 %]</td>
    </tr>
	</table>

	</form>

	[% IF demographics.dispatch_to.match('alternate') %]
  <form method="post" enctype="multipart/form-data"
      action="[% app_url %]/outreach/alternate_address/[% request_data.id %]/[% patient_id %]">
    <div style="background-color: #ffc; padding:2px; border: dotted 1px #f00;">
    <table class="indent borderless">
      <tr>
        <td><b>Alternate<br />address</b>:</td>
        <td>
          <textarea name="address" cols="25"
            rows="2">[% demographics.alternate_address %]</textarea>
        </td>
        <td><b>Post code</b>:</td>
        <td>
          <input type="text" value="[% demographics.alternate_post_code %]"
            name="post_code" size="12" />
        </td>
        <td class="borderless">[% INCLUDE outreach_submit %]</td>
      </tr>
    </table>
    </div>
	</form>
	[% END %]
<!-- END outreach/demographics.tt -->
