<!-- BEGIN hmrn/data/chronologies.tt -->
    <h3 class="header">Event data:</h3>
	[% # PROCESS dumper.tt dump = hmrn_data.event_dates %]
	
    [% IF # provide a name="error" for internal anchor:
        error_first_appointment ||
        error_palliative_care   ||
        error_diagnosed         ||
        error_deceased          ||
        error_mdt_date        
    %]<a name="error"><span>&nbsp;</span></a>[% END %]

    [% IF not_using_validationEngine_jquery # then use 'basic' jquery val %]
    <script type="text/javascript"> 
	    $(document).ready(function() { 
	      $("#chronologies").validate({ 
            rules: {
				[% FOREACH date IN ['diagnosis' 'first_appointment' 'palliative_care'
					'deceased' 'mdt_date'] %]
					[% date %]: { remote: "[% app_url %]/ajax/check_date_valid" },
				[% END %]
            },
          });
        });
    </script>
    [% ELSE %]
	<script type="text/javascript">
		$(document).ready(function() {
			$("#chronologies").validationEngine()
		})
	</script>
    [% END %]
    
    <form method="get" action="[% app_url %]/hmrn_data/edit_event_data/[% data.id
		%]/[% patient.id %]" name="chronologies" id="chronologies">
    
    [% event_dates = hmrn_data.event_dates %]
    <table class="indent">
        <tr>
            <td class="label">Date of diagnosis:</td>
            <td class="content">
                <input type="text" name="diagnosis" class="validate[ajax[ajaxDate]]" 
                    id="diagnosis" value="[% event_dates.diagnosis.strftime('%d.%b.%Y') %]" />
				[% error_diagnosis %]
            </td>
        </tr>        
        <tr>
            <td class="label">Age at diagnosis:</td>
            [%
                age = calculate_age(patient.dob, event_dates.diagnosis);
				class = event_dates.diagnosis AND ( NOT age OR age < 0 OR age > 100 )
					? 'highlight' : 'normal'; # eg if default date (1000-01-01)
			%]
            <td class="content">
                <input type="text" value="[% age || '[ check null date(s) ]' %]"
					class="[% class %]" [% site.html.readonly %] />
            </td>
        </tr>
        <tr>
            <td class="label">First haem. appointment:</td>
            <td class="content">
                <input type="text" name="first_appointment" id="first_appointment"
					class="validate[ajax[ajaxDate]]"
					value="[% event_dates.first_appointment.strftime('%d.%b.%Y') %]" />
				[% error_first_appointment %]
            </td>
        </tr>
        <tr>
            <td class="label">Palliative referral date:</td>
            <td class="content">
                <input type="text" name="palliative_care" class="validate[ajax[ajaxDate]]" 
                    id="palliative_care" value="[% event_dates.palliative_care.strftime('%d.%b.%Y') %]" />
				[% error_palliative_care %]
            </td>
        </tr>
        <tr>
            <td class="label">Date of death:</td>
            <td class="content">
                <input type="text" name="deceased" id="deceased" class="validate[ajax[ajaxDate]]" 
					value="[% event_dates.deceased.strftime('%d.%b.%Y') %]" />
				[% error_deceased %]
            </td>
        </tr>
        <tr>
            <td class="label" style="vertical-align: top">
                MDT meeting dates [[% hmrn_data.mdt_dates.size || 0 %]]:
            </td>
            <td class="content">
                [% FOREACH entry IN hmrn_data.mdt_dates %]
                <div>
                    [% loop.count %].
                    <span style="font-family: monospace">
                        [% entry.date.strftime('%d.%b.%Y') %]
                    </span>
                    [% IF user_can_enter_data %]
                    [<a href="[% app_url %]/hmrn_data/edit_mdt_date/[% data.id %]/[%
						entry.id %]">edit</a>]
                    [% END %]
                </div>                
                [% END %]
                [% IF user_can_enter_data %]
                <p>[% ( hmrn_data.mdt_dates.size || 0 ) + 1 %].
                    <input type="text" name="mdt_date" class="validate[ajax[ajaxDate]]"
                        id="mdt_date" size="10" />
					[% IF error_mdt_date; error_mdt_date; ELSE %]
						&#171; new
					[% END %]
                </p>
                [% END %]
            </td>
        </tr>
		[% IF hmrn_data.event_dates.size;
			  INCLUDE hmrn_submit delete_section = 'patient_event';
			ELSE; INCLUDE hmrn_submit; END %]
    </table>
    </form>
<!-- END hmrn/data/chronologies.tt -->
