<!-- BEGIN [% template.name %] -->
    [% META title = 'Chimerism data' %]

    [% # PROCESS dumper.tt dump = data %]
    
    <h2>Chimerism data summary</h2>
    
    [% IF data.size;
		USE math = format('%.0f');
		i = 0;
	%]
    <form action="[% app_url %]/data-import/do_chimerism" method="post"
		name="chimerism" id="chimerism">
      <table class="indent">
        <tr>
            <td class="borderless"></td>
            <th scope="col">LabNo</th>
            <th scope="col">Name</th>
            <th scope="col">Baseline</th>
            <th scope="col">Marker</th>
            <th scope="col">Donor</th>
			<th scope="col">Patient</th>
            <th scope="col">Result</th>
            <th scope="col">Ref</th>
            <th scope="col">Import</th>
            <td class="borderless" colspan="2"></td>
        </tr>
        [% FOREACH request IN data; # INCLUDE dumper.tt dump = request;
			FOREACH set IN request.value; # INCLUDE dumper.tt dump = set;
				row = set.value; # INCLUDE dumper.tt dump = row;
				baseline_data = row.${'baseline chimerism data'};
				result = [];
					result.push(row.id);
					result.push(row.labno);
					result.push(row.test);
					result.push(baseline_data);
					result.push(row.marker_ref);
			%]			
        <tr>
            <td>[% i = i + 1; i %]</td>
			<td>[% row.labno %]</td>
			<td>[% row.name %]</td>
            <td>[% baseline_data %]</td>
            <td>[% row.test %]</td>
            <td>[% row.donor_result UNLESS row.donor_result == 1
					AND NOT row.patient_result # ie patient == 0 %]</td>
            <td>[% row.patient_result %]</td>
            <td>[% # need patient or donor > 0 otherwise division by zero:
                IF row.donor_result OR row.patient_result;
					val = math( row.donor_result /
					( row.donor_result + row.patient_result ) * 100 );
					result.push(val); val; '%';
				END %]
			</td>
			<td>[% row.marker_ref %]</td>
			[% IF row.data_ok == 2 OR baseline_data %]
			<td align="right">
				[% row.labno %]
				<input type="checkbox" name="result"
					value="[% result.join('~') %]" />
			</td>
			[% ELSE %]
				<td align="center">
					<span class="red acronym" title="data error">X</span>
				</td>
			[% END %]
        </tr>
        [% END; END %]
        <tr>
            <td colspan="6" align="right" class="borderless">
                <input type="button" name="CheckAll" value="Select all"
                  onClick="checkAll(document.chimerism.result)">
                <input type="button" name="UnCheckAll" value="Clear all"
                  onClick="uncheckAll(document.chimerism.result)">
                [% site.html.submit %]
            </td>
        </tr>
      </table>
    </form>
	[% END %]
<!-- END [% template.name %] -->
