  [% META title = 'Admin &raquo; Diagnoses' -%]
<!-- BEGIN [% template.title %] -->
  
  [% # PROCESS dumper.tt dump = diagnoses %]
  [% # PROCESS dumper.tt dump = categories %]
  [% # PROCESS dumper.tt dump = sub_categories %]

	[% diagnosis_dfv_js %]

	[% PROCESS admin/request_nav.tt page = 'diagnoses' %]

	<h2 align="center">Diagnoses</h2>

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

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

    <p class="title">
		[% div_name = 'new'; INCLUDE site/snippets/toggleview.tt %]
		Add new entry
	</p>

	<div class="[% dfv_errors ? 'visible' : 'itemhidden' %]" id="[% div_name %]">

        <form method="get" action="[% app_url %]/config/diagnoses/update"
            name="new_diagnoses" id="new_diagnoses" [% diagnosis_onsubmit %]>
            <div class="indent">
                <table>
                    <tr>
                        <td class="label">Diagnosis:</td>
                        <td>
						  [% PROCESS site/ajax_input.tt field = 'name'
							  id = "new_diagnosis" size = 60 %]
                            [% error_name %]
                        </td>
                    </tr>
            
                    <tr>
                        <td class="label">Diagnostic category:</td>
                        <td>
                            <select name="diagnostic_category_id">
                                <option value="">-- select one --</option>
                            [% FOREACH entry IN categories;
                                NEXT UNLESS entry.category_type.match('main') %]
                                <option value="[% entry.id %]"
                                    [% 'selected' IF entry.id ==
                                        c.query.param('diagnostic_category_id') %]>
                                    [% entry.description | html %]
                                </option>
                            [% END %]
                            </select>
							[% IF error_diagnostic_category_id %]
							  [% error_diagnostic_category_id %]
							[% ELSE %]
							  [ <a href="[% app_url %]/config/diagnostic-categories">
								new</a> ]
							[% END %]
                        </td>
                    </tr>
            
                    <tr>
                        <td class="label">Sub-category:</td>
                        <td>
                            <select name="sub_category_id">
                                <option value="">--</option>
                            [% FOREACH entry IN categories;
                                NEXT UNLESS entry.category_type.match('sub') %]
                                <option value="[% entry.id %]"
                                    [% 'selected' IF entry.id ==
                                        c.query.param('sub_category_id') %]>
                                    [% entry.description | html %]
                                </option>
                            [% END %]
                            </select>
							[% IF error_sub_category_id %]
							  [% error_sub_category_id %]
							[% ELSE %]
                                [ optional ]
							  [ <a href="[% app_url %]/config/diagnostic-categories">
								new</a> ]
							[% END %]
                        </td>
                    </tr>
            
                    <tr>
                        <td class="label">ICDO3:</td>
                        <td>
                            <input type="text" name="icdo3" size="6"
								value="[% c.query.param('icdo3') %]" />
							[% IF error_icdo3; error_icdo3; ELSE %]
								[ optional; required if exists ]
                            [% END %]
                        </td>
                    </tr>
            
                    <tr>
                        <td class="label">Active:</td>
                        <td class="content">
                            <select name="active" [% site.html.onfocus %]>
                            [% FOREACH option IN ['yes', 'no'] %]
                                <option value="[% option %]">[% option %]</option>
                            [% END %]
                            </select>
                            [% error_active %]
                        </td>
                    </tr>
                    
                    <tr>
                        <td class="borderless" colspan="2" align="center">[% site.html.submit %]</td>
                    </tr>
                </table>
            </div>
        </form>
    </div>
    
	<p class="spacer">&nbsp;</p>

	[% IF diagnoses.size # only empty if new db %]
	<div class="[% dfv_errors ? 'itemhidden' : 'visible' %]">
        [% PROCESS site/page_count.tt %]

		<table>
			<tr>
				<th></th>
				<th>
                    <a href="[% url_with_path %]?sort_by=name">Diagnosis</a>
                </th>
				<th>
                    <a href="[% url_with_path %]">Category</a>
                </th>
				<th><span class="acronym" title="sub-category">Sub</span></th>
				<th>
                    <a href="[% url_with_path %]?sort_by=icdo3">ICDO3</a>
                </th>
				<th>
                    Active
                </th>
			</tr>

			[% FOREACH d IN diagnoses %][% # PROCESS dumper.tt dump = d %]
			<tr>
				<td>
                    [% IF cgi_pager; cgi_pager.first_pos_displayed + loop.count - 1; ELSE; loop.count; END %]
                </td>
				<td>
					<input type="text" size="60" name="name" value="[% d.name | html %]"
						[% site.html.disabled %] />
				</td>
				<td>
					<input type="text" size="20" name="category"
                           value="[% d.diagnostic_category.description | html %]"
                        [% site.html.disabled %] />
				</td>
				<td>
					<input type="text" size="10" name="sub-category"
                           value="[% sub_categories.item(d.icdo3) %]"
                        [% site.html.disabled %] />
				</td>
				<td>
					<input type="text" size="6" name="icdo3" value="[% d.icdo3 | html %]"
                        [% site.html.disabled %] />
				</td>
				<td>
					<select name="active" [% site.html.disabled %]>
					[% FOREACH option IN ['yes', 'no'] %]
						 <option value="[% option %]" [% 'selected' IF option == d.active %]>
							[% option %]
						</option>
					[% END %]
					</select>
				</td>
				<td align="center">
					<a href="[% app_url %]/config/diagnoses/edit/[% d.id %]">Edit</a>
				</td>
			 </tr>
			[% END %]

		</table>
	</div>
	[% END %]

    [% PROCESS site/cgi_pager.tt %]
<!-- END [% template.title %] -->
