  [% META title = 'Admin &raquo; Diagnosis Context Warnings' -%]
<!-- BEGIN admin/config/diagnosiscontextwarnings/default.tt -->  
  [% # PROCESS dumper.tt dump = c.stash.errs %]

	[% # diagnostic_category_dfv_js %]

	[% PROCESS admin/request_nav.tt page = 'diagnostic-categories' %]
	
	<h2 align="center">Diagnosis Context Warnings</h2>

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

	[% # PROCESS dumper.tt dump = dfv_errors %]
	[% # PROCESS dumper.tt dump = context_warning_opts %]
	[% # PROCESS dumper.tt dump = diagnosis_context_warnings %]
	[% # PROCESS dumper.tt dump = diagnoses %]

	[% IF diagnosis_context_warnings.size %]
		<table class="indent">
			<tr>
				<td></td>
				<th scope="col">Diagnosis</th>
				<th scope="col">Context warning</th>
			</tr>
		[% FOREACH entry IN diagnosis_context_warnings;
				# PROCESS dumper.tt dump = entry.context_warning.id;
			class = diagnoses.item(entry.key).active.match('yes')
				? 'normal' : 'grey';
		%]
			<tr class="[% class %]">
				<td>[% loop.count %]</td>
				<td>[% entry.key %]</td>
				<td>
          [% this_warning = entry.value.context_warning.description | html %]
					[% IF this_warning.length > 80 %]
					<span class="acronym" title="[% this_warning %]">
						[% this_warning | truncate(80) %]
					</span>
					[% ELSE %]
					 [% this_warning | html %]
					[% END %]					
				</td>
				<td>
          [<a href="[% app_url
            %]/config/diagnosis-context-warnings/edit_diagnosis_context_warning/[%
              entry.value.id %]">
            edit
          </a>]
        </td>
			</tr>
		[% END %]
		</table>
	[% END %]

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

 	[% diagnosis_context_dfv_js %]

	<div class="[% dfv_errors ? 'visible' : 'itemhidden' %]" id="[% div_name %]">
		<div class="indent">
      
      <p class="title">
		[% div_name = 'newcontext'; INCLUDE site/snippets/toggleview.tt %]
		Add/edit context warnings
      </p>
      <div class="[% dfv_errors ? 'visible' : 'itemhidden' %]" id="[% div_name %]">
        <form method="get" name="contextWarning" id="contextWarning"
          action="[% app_url %]/config/diagnosis-context-warnings/update_context_warning">
        <hr />
        <table class="indent">
          <tr>
            <td></td>
            <th scope="col">Context warning</th>
            <th scope="col">Active</th>
          </tr>
          [% FOREACH entry IN context_warning_opts %]
            <tr>
              <td>[% loop.count %]</td>
              <td>
                <input type="text" value="[% entry.description %]" size="100"
                  [% site.html.disabled %]" />
              </td>
              <td align="center">
                <select name="active" [% site.html.disabled %]>
                  <option value="">[% entry.is_active %]</option>
                </select>
              </td>
              <td>
                [<a href="[% app_url
                  %]/config/diagnosis-context-warnings/edit_context_warning/[%
                    entry.id %]">
                  edit
                </a>]
              </td>
            </tr>
          [% END %]
        </table>
        <p class="title">New:
		  <input type="hidden" name="is_active" value="yes" />
          <input type="text" name="description" size="100"
              value="[% c.query.param('description') %]" />
              [% error_description %]
            [% site.html.submit %]            
        </p>
        </form>
        <hr />
      </div>
      
	  [% IF context_warning_opts.size %]
      <form method="get" name="diagnosis-context-warning" id="diagnosis-context-warning"
        action="[% app_url %]/config/diagnosis-context-warnings/update_diagnosis_context_warning"
       [% diagnosis_context_onsubmit %]>

      <p class="title">
        Select diagnosis:
        <select name="diagnosis_id">
          <option value=""></option>
          [% FOREACH entry IN diagnoses.keys.sort; # skip ones already allocated:
              NEXT IF diagnosis_context_warnings.item(entry);
              NEXT UNLESS diagnoses.item(entry).active.match('yes'); %]
            <option value="[% diagnoses.item(entry).id %]">[% entry %]</option>
          [% END %]
          </select>
      </p>

      <p class="title">
        Select warning:
        <select name="context_warning_id">
          <option value=""></option>
          [% FOREACH entry IN context_warning_opts;
            NEXT UNLESS  entry.is_active.match('yes'); %]
            <option value="[% entry.id %]">[% entry.description %]</option>
          [% END %]
          </select>
      </p>

      <p class="indent">[% site.html.submit %]</p>
      </form>    
		[% END %]
    </div>
  </div>
 <!-- END admin/config/diagnosiscontextwarnings/default.tt -->  
