<!-- BEGIN outreach/data_summary.tt -->
  [% # manipulate some immunology params:
    immunology = outreach.immunology;
    
    IF immunology.electrophoresis.result.match('Isotype undetermined');
      immunology.electrophoresis.result = '';
    END;
  
    FOREACH param IN ['IgG' 'IgA' 'IgM'];
      IF immunology.item(param).result;
        IF immunology.item(param).result * 100 == immunology.item(param).default * 100;
          immunology.item(param).result = '';
        END;
      END;
    END;
    
    IF immunology.paraprotein.result;
      IF immunology.paraprotein.result * 100 == immunology.paraprotein.default * 100;
        IF immunology.electrophoresis.result.match('Ig');
          immunology.paraprotein.result = 'Unquantifiable';
        ELSIF immunology.electrophoresis.result.match('No paraprotein');
          immunology.paraprotein.result = '';
        ELSE;
          immunology.paraprotein.result = 'N/K';
        END;
      END;
    END;
    
    IF outreach.flow_cytometry.cd19_neg_pc.result;
      IF outreach.flow_cytometry.cd19_neg_pc.result < 0.001;
        outreach.flow_cytometry.cd19_neg_pc.result = '< 0.001';
      ELSE;
        outreach.flow_cytometry.cd19_neg_pc.result = 
          sig_figs(outreach.flow_cytometry.cd19_neg_pc.result);
      END;
    END;
    
    IF outreach.calculated.abnormal_b_cells.result;
      IF outreach.calculated.abnormal_b_cells.result < 0.01;
        outreach.calculated.abnormal_b_cells.result = '< 0.01';
      ELSE;
        outreach.calculated.abnormal_b_cells.result = 
          sig_figs(outreach.calculated.abnormal_b_cells.result);
      END;
    END;
    
    # total B cells calculated so doesn't get value from default_and_ranges table:
    outreach.calculated.total_b_cells.units = outreach.haematology.wbc.units;
    outreach.calculated.total_b_cells.param_name = 'total_b_cells';
    outreach.calculated.total_b_cells.field_label = 'Total B';
    
    # abnormal B cells calculated so doesn't get value from default_and_ranges table:
    outreach.calculated.neoplastic_b_cells.units = outreach.haematology.wbc.units;
    outreach.calculated.neoplastic_b_cells.param_name = 'neoplastic_b_cells';
    outreach.calculated.neoplastic_b_cells.field_label = 'Abnormal B';
    
    # PROCESS dumper.tt dump = outreach.calculated;
  %]
  
  [% BLOCK rows;
    patient_id = request_data.patient_case.patient_id;    
    
    # if param carries default value, set to N/K:    
    IF is_numerical(param.result) AND param.default # AND param.result
        AND 100 * param.result == 100 * param.default; # PROCESS dumper.tt dump = param;
            param.result = 'N/K'; # PROCESS dumper.tt dump = param;
    END;
        
	IF is_numerical(param.result); # no maths funcs unless numerical:
    	IF
            ( param.lower_flag && param.result < param.lower_flag ) OR
            ( param.upper_flag && param.result > param.upper_flag );
            highlight_class = 'rangeFlag'; # stronger highlight
        ELSIF 
            ( param.lower_limit && param.result < param.lower_limit ) OR
            ( param.upper_limit && param.result > param.upper_limit );
            highlight_class = 'bold'; # weaker highlight
		END;
        
        result_sig_figs = sig_figs(param.result);
    END; %]
  
    <tr>
      <td align="right">
        [% IF skip_url; param.field_label;
            ELSE; var = param.param_name; %]
        <a href="[% app_url %]/chart/outreach_param/[% var %]/[% patient_id %]"
            onclick="return popup(this.href);">
          <span class="acronym" title="chart">[% param.field_label %]</span>			
        </a>
        [% END %]
      </td>
      <td class="[% highlight_class || 'normal' %]" align="center">
          [% result_sig_figs || param.result # to 3 sig figs if is_numerical() %]
      </td>
      <td align="center">
        [% IF param.lower_limit; 10 * param.lower_limit / 10; END %] -
        [% IF param.upper_limit; 10 * param.upper_limit / 10; END %]
      </td>
      <td>
        [% param.units.replace('10/9', '10<span class="superscript">9</span>') %]
      </td>
      <td style="border: none">
        [% UNLESS skip_url %]
        <a href="[% app_url %]/outreach/data_table/[% var %]/[% patient_id %]"
            target="_new"><img src="/images/table-icon.png" />
        [% END %]
      </td>
    </tr>
  [% END %]
  
  [% PROCESS site/popup.tt height=280, width=420, top=250 %]

	<table class="indent borderless">
    <tr>
      <td valign="top">
        <table class="outreachResults">
          <tr>
            <th scope="col">Param</th>
            <th scope="col">Result</th>
            <th scope="col">Range</th>
            <th scope="col">Units</th>
          </tr>          
          [%
            INCLUDE rows param = outreach.haematology.hb;
            INCLUDE rows param = outreach.haematology.wbc;
            INCLUDE rows param = outreach.haematology.plts;
            INCLUDE rows param = outreach.haematology.lymphs;
            INCLUDE rows param = outreach.calculated.total_b_cells;
            INCLUDE rows param = outreach.calculated.neoplastic_b_cells;
            INCLUDE rows param = outreach.flow_cytometry.cd19_neg_pc;
          %]
        </table>
      </td>
      
      <td width="10"></td>
      
      <td valign="top">
        <table class="outreachResults">
          <tr>
            <th scope="col">Param</th>
            <th scope="col">Result</th>
            <th scope="col">Range</th>
            <th scope="col">Units</th>
          </tr>
          [%
            INCLUDE rows param = outreach.biochemistry.creatinine;
            INCLUDE rows param = outreach.biochemistry.calcium;
            INCLUDE rows param = outreach.immunology.IgA;
            INCLUDE rows param = outreach.immunology.IgG;
            INCLUDE rows param = outreach.immunology.IgM;
            INCLUDE rows param = outreach.immunology.electrophoresis skip_url = 1;
            INCLUDE rows param = outreach.immunology.paraprotein;
          %]
        </table>
      </td>
    </tr>

  </table>
<!-- END outreach/data_summary.tt -->
