<!-- BEGIN hmrn/data/chronologies.tt -->
    <h3 class="header">Chronological data:</h3>

    [% 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 ['diagnosed' '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_chronology/[% data.id
		%]/[% patient.id %]" name="chronologies" id="chronologies">
    
    [% dates = hmrn_data.chronology %]
    <table class="indent">
        <tr>
            <td class="label">Date of diagnosis:</td>
            <td class="content">
                <input type="text" name="diagnosed" class="validate[ajax[ajaxDate]]" 
                    id="diagnosed" value="[% dates.diagnosed.strftime('%d.%b.%Y') %]" />
				[% error_diagnosed %]
            </td>
        </tr>        
        <tr>
            <td class="label">Age at diagnosis:
			</td>
            <td class="content">
                [% age = calculate_age(patient.dob,dates.diagnosed) %]
                <input type="text" value="[% age || '[ check null date(s) ]' %]"
					[% 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="[% 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="[% 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="[% dates.deceased.strftime('%d.%b.%Y') %]" />
				[% error_deceased %]
            </td>
        </tr>
        <tr>
            <td class="label" style="vertical-align: top">
                MDT meeting dates [[% dates.mdt_dates.size || 0 %]]:
            </td>
            <td class="content">
                [% FOREACH entry IN dates.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>[% ( dates.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>
		[% INCLUDE hmrn_submit %]
    </table>
    </form>
<!-- END hmrn/data/chronologies.tt -->
