<!-- BEGIN hmrn/data/patient_summary.tt  -->
    [% # PROCESS dumper.tt dump = demographic_data %]
    [% # PROCESS dumper.tt dump = practice_gps %]
    [% # PROCESS dumper.tt dump = unknown_gp_id %]
    [% # PROCESS dumper.tt dump = c.stash.errs %]

	<script type="text/javascript">
		$(document).ready(function() {
			$("#demographics").validationEngine()
		})
	</script>

	<table>
		<tr class="borderless">
			<td>
				[% site.html.back_button %]
			</td>
			<td align="center">
				Diagnosis: <span id="hmrn_diagnosis">
					[% report_data.diagnosis.name || 'Unreported request' %]
					[[% report_data.diagnosis.icdo3 || 'non-ICDO3' %]]
				</span>
			</td>
			<td align="center">
				<a href="[% app_url %]/hmrn_data/view_history/[% patient.id %]">History</a>
			</td>
		</tr>
	</table>

	[% IF hmrn_data.all_diagnoses.size;
		other_diagnoses = [];
		FOREACH entry IN hmrn_data.all_diagnoses;
			NEXT IF entry == report_data.diagnosis.name; # skip same diag
			other_diagnoses.push(entry);
		END;
		IF other_diagnoses.size;
	%]
	<p class="info" style="margin-bottom: 0">Other (ICDO3) diagnoses:</p>
		[% FOREACH d IN other_diagnoses %]
			<div class="indent">[% d %]</div>
		[% END %]
	[% END; END %]
	
    <h3 class="header">Patient summary:</h3>
	
    <table class="indent">
      <tr>
        <th>Name</th>
        <th>DoB</th>
        <th>
			[% IF patient.nhs_number %]
				NHS number
			[% ELSE %]
				Unit number
          [% END %]
        </th>
        <th>Lab No.</th>
        <th>Reported</th>
        <th>Source</th>
        <th>Referrer</th>
      </tr>
	  
      <tr>
        <td>
          [% patient.last_name   | upper %],
          [% patient.first_name  | ucfirst %]
          [% patient.middle_name | ucfirst %]
		  [[% patient.gender %]]
        </td>
        <td>
          [% patient.dob.strftime('%d.%b.%Y') || site.html.grey_null %]
        </td>
        <td>
			[%
				IF patient.nhs_number;
					PROCESS site/nhs_number.tt nhs_number = patient.nhs_number;
				ELSE; data.patient_case.unit_number || site.html.grey_null;
				END;
			%]
        </td>
        <td>
          [% PROCESS site/lab_number.tt want_url = 1 # expects request object 'data' %]
        </td>
        <td>[% request_history.reported.time.strftime('%d.%b.%Y') %]</td>              
        <td>
          [% location = data.patient_case.referral_source.display_name %]
          [% PROCESS site/display_name.tt %]
        </td>
		<td>
			[% data.referrer_department.referrer.name %]
		</td>
	  </tr>
	</table>
	
    <h3 class="header">Demographic data:</h3>
	
    <form method="get" action="[% app_url %]/hmrn_data/edit_demographics/[% data.id %]/[% patient.id %]"
		name="demographics" id="demographics">
	
    <table class="indent">
		<tr>
			<td class="label">Address at diagnosis:</td>
			<td class="content">
				<textarea name="address" rows="1" cols="40"
					class="expand20-200">[% demographic_data.address %]</textarea>
			</td>
		</tr>
		<tr>
			<td class="label">Post code:</td>
			<td class="content">
				<input type="text" name="post_code" size="12" class="validate[required,ajax[ajaxPostCode]]"
					id="post_code" value="[% demographic_data.post_code %]" />
                [% error_post_code %]
                [% IF demographic_data.post_code != demographic_data.post_code_at_diagnosis %]
                    <span class="red">at diagnosis</span>:
                    <input type="text" name="post_code_at_diagnosis" size="12"
                        value="[% demographic_data.post_code_at_diagnosis %]" />
                    [% IF user_can_enter_data AND hmrn_data.is_in_outreach # can't edit demographics: %]
                    [<a href="[% app_url %]/hmrn_data/edit_post_code/[% data.id
                            %]/[% patient.id %]?post_code_at_diagnosis=[%
                            demographic_data.post_code_at_diagnosis | uri %]">
                        edit
                    </a>]
                    [% END %]
                [% END %]
			</td>
		</tr>
        
        [% is_editable = user_can_enter_data AND ! hmrn_data.is_in_outreach
            ? 1 : 0 # can't edit GP & practice details if patient also in Outreach %]
        
		<tr>
			<td class="label">GP practice:</td>			
			<td class="content">
                [% IF demographic_data.practice %]
				<input type="text" style="width: 600px" [% site.html.readonly %]
					value="[% demographic_data.practice.display_name %]" />
                    [% IF is_editable %]
					<a href="[% app_url %]/hmrn_data/edit_practice/[% data.id %]/[%
                            patient.id %]">
						edit
					</a>
                    [% END %]
                [% ELSE %]
                    [% PROCESS site/autosuggest.tt %]
                    <input type="text" name="practice_name" id="location_name"			
        				style="width: 600px" />
        			<input type="hidden" id="source_id" name="practice_id" />                
                [% END %]
                
                [% IF is_editable;
                    INCLUDE site/popup.tt height=300, width=850, top=50 %]
                <a class="nav" href="[% app_url %]/hmrn/find_practice"
                    onclick="return popup(this.href);">
                    <img class="href" src="/images/question.gif"
                        title="find practice by GP" />
                </a>
			[% END %]
			[% IF error_practice_id; error_practice_id; END %]
			</td>
		</tr>
        
        [% IF demographic_data.practice_id # required to load GP's: %]
		<tr>
			<td class="label">GP:</td>			
            <td>
              <select name="gp_id" [% site.html.disabled UNLESS is_editable %]>
                <option value="">--select one--</option>
              [% FOREACH gp IN practice_gps;
                id   = gp.first;
                name = gp.last;
              %]
                <option value="[% id %]" [% 'selected' IF id == demographic_data.gp_id %]>
                  [% name %]
                </option>
              [% END %]
                <option disabled>---------------</option>
                <option value="[% unknown_gp_id %]"
                    [% 'selected' IF demographic_data.gp_id == unknown_gp_id %]>
                  [ unknown ]
                </option>
              </select>
              [% IF class == 'red' %]
                  <span class="red">[ non-participant practice ]</span>
              [% END %]
            </td>
        </tr>
        [% END %]
        
        <tr>
			<td class="label">Status:</td>			
			<td class="content">
				<select name="status" [% site.html.disabled UNLESS is_editable %]>
					[% FOREACH entry IN ['alive' 'dead'] %]
					<option value="[% entry %]"
						[% 'selected' IF entry == demographic_data.status %]>
						[% entry %]
					</option>
					[% END %]
				</select>
				[% IF user_can_enter_data AND (
					( demographic_data.status.match('deceased') AND ! hmrn_data.event_dates.deceased )
						OR
					( hmrn_data.event_dates.deceased AND demographic_data.status.match('alive') )
				) %]
				<span class="red">
					&#171; doesn't correspond to "date of death" entry in chronologies section
				</span>
				[% END %]
			</td>
		</tr>
		[% IF hmrn_data.is_in_outreach AND user_can_enter_data %]
		<tr class="borderless">
			<td align="center" colspan="2">
				<span class="warning">
					[patient is in Outreach program - cannot edit demographic details here]
				</span>					
			</td>
		</tr>
		[% ELSE; INCLUDE hmrn_submit; END %]
	</table>
	</form>
<!-- END hmrn/data/patient_summary.tt  -->
