<tal:report
  i18n:domain="senaite.health"
  define="model python:view.model;
          laboratory view/laboratory;
          client model/Client;
          contact model/Contact;
          patient model/Patient;
          doctor model/Doctor;
	  physician model/Physician;
          accredited_symbol string:★;
          outofrange_symbol string:⚠;
          footer python:view.get_footer_text();
          report_options python:options.get('report_options', {});
          attachments_per_row python:int(report_options.get('attachments_per_row', 2));
          attachments_per_row python:attachments_per_row<1 and 1 or attachments_per_row;
          page_width options/page_width|nothing;
          page_height options/page_height|nothing;
          content_width options/content_width|nothing;
          content_height options/content_height|nothing;">

  <!-- Custom Report Controls -->
  <div id="controls" class="noprint">
    <div i18n:translate="" class="text-secondary mb-2">Custom Report Options</div>
    <!-- Attachments per row -->
    <div class="mb-3">
      <div class="input-group">
        <div class="input-group-prepend">
          <label class="input-group-text" for="attachments_per_row" i18n:translate="">
            Attachments per Row
          </label>
        </div>
        <input tal:attributes="value attachments_per_row"
               type="number"
               class="form-control"
               name="attachments_per_row"
               min="1"/>
      </div>
      <small class="form-text text-muted" i18n:translate="">
        Number of attachments rendered within one row per Sample
      </small>
    </div>
  </div>

  <script type="text/javascript">
   console.info("####################################Valer Impress##################################");
   window.options = "<tal:t replace='options'/>";
   console.log(window.options);
   console.info("######################################################################");
  </script>

  <tal:css>
    <style type="text/css">
     .report * { font: 9pt; }
     .report h1 { font-size: 140%; }
     .report h2 { font-size: 120%; }
     .report h3 { font-size: 110%; }
     .report .font-size-140 { font-size: 140%; }
     .report .font-size-120 { font-size: 120%; }
     .report .font-size-100 { font-size: 100%; }
     .report .colon-after:after { content: ":"; }
     .report address { margin: 1rem 0; }
     .report table.noborder td, .report table.noborder th { border: none; }
     .report table.nopadding td { padding: 0; }
     .report table td.label { padding-right: 0.3rem; font-weight: bold; }
     .report table { border-color: black; }
     .report table td, .report table th {}
     .report table th {}
     .report table.range-table td { padding: 0 0.3rem 0 0; border: none; }
     .report .section-header h1 { font-size: 175%; }
     .report .section-header img.logo { height: 100px; margin: 20px 0; }
     .report .barcode-hri { margin-top: -0.25em; font-size: 8pt; }
     .report .section-footer table td { border: none; }
     .report .section-footer {
       position: fixed;
       left: -20mm;
       bottom: -20mm;
       margin-left: 20mm;
       margin-top: 10mm;
       height: 20mm;
       width: 100%;
       text-align: left;
       font-size: 9pt;
     }
     .report .section-footer #footer-line {
       width: 100%;
       height: 2mm;
       border-top: 1px solid black;
     }

     <tal:block condition="python:content_width and content_height">
     <tal:block condition="python:all([content_width, content_height])"
                   define="cw python:float(content_width);
                           ch python:float(content_height);">
     /* Ensure that the images stay within the borders */
     .report .section-attachments img {
       max-width: <tal:t replace="python:'{:.2f}mm'.format(cw / attachments_per_row)"/>;
       max-height: <tal:t replace="python:'{:.2f}mm'.format(ch * 0.75)"/>;
     }
     .report .section-resultsinterpretation img {
       max-width: <tal:t replace="python:'{:.2f}mm'.format(cw)"/>;
       max-height: <tal:t replace="python:'{:.2f}mm'.format(ch * 0.75)"/>;
     }
     </tal:block>
     @page {
       @bottom-right {
         vertical-align: top;
         margin-top: 2mm;
         font-size: 9pt;
         content: "<tal:t i18n:translate=''>Page</tal:t> " counter(page) " <tal:t i18n:translate=''>of</tal:t> " counter(pages);
       }
     }
    </style>
  </tal:css>

  <!-- HEADER -->
  <tal:render condition="python:True" define="laboratory python:view.laboratory;">
    <div class="row section-header no-gutters">
      <!-- Header Table -->
      <div class="w-100">
        <table class="w-100 noborder">
          <colgroup>
            <col style="width:100%"/>
          </colgroup>
          <tr>
            <!-- Header Left -->
            <td class="align-middle text-center" style="color: blue;">
              <h1 i18n:translate="" tal:content="laboratory/Name">Lab Name</h1>
            </td>
          </tr>
          <tr>
            <td class="align-middle text-center" style="font-size:9pt;">
              26-19 FRANCIS LEWIS BLVD, FLUSHING, NY 11358
              <!--
               <span tal:content="laboratory/PhysicalAddress/address">Lab Street and Number</span>,
              <span tal:content="laboratory/PhysicalAddress/state">Lab State</span>,
              <span tal:content="laboratory/PhysicalAddress/zip">Lab ZIP</span>
              -->
            </td>
          </tr>
          <tr>
            <td class="align-middle text-center" style="font-size:9pt;">
              <span><b>Phone:</b> +1 (718) 213-6274,</span> 
              <span>&nbsp;&nbsp;</span>
              <span><b>Fax:</b> +1 (888) 377-1244</span>
              <!--
              <span i18n:translate="">Phone</span>
              <span tal:content="laboratory/Phone">Lab Phone Number</span> &nbsp;&nbsp;&nbsp;
              <span i18n:translate="">Fax</span>
              <span tal:content="laboratory/Fax">Lab Fax Number</span>
              -->
            </td>
          </tr>
          <tr>
            <td>
              &nbsp;
            </td>
          </tr>
        </table>
      </div>
    </div>
  </tal:render>
  <!-- /HEADER -->

  
    <!-- Clear Floats
         https://github.com/Kozea/WeasyPrint/issues/36
    -->
  

 <!-- Patient , Doctor, Speciment Detail Blocks -->
<div class="row section-info no-gutters">
    <div class="w-100">
      <!-- Client Info -->
      <table class="table table-sm table-condensed w-100" style="font-size:7pt;">
        <colgroup>
          <!-- Client Address -->
          <col style="width: 33%;">
          <!-- Lab Address -->
          <col style="width: 37%">
          <!-- Accreditation Logo -->
          <col style="width: 30%">
        </colgroup>
        <tr>
          <!-- PATIENT DETAILS-->
          <td style="width:33%;border:2px solid black;">
            <table style="width:100%;">
              <tr>
                <td colspan="2" style="border:none;">
                  <div style="background-color:lightblue;"><span><b>Patient Information</b></span></div>
                </td>
              </tr>
              <tr>
                 <td colspan="2" style="border:none;">
                    <span tal:content="patient/Title" style="font-weight: bold"> </span>
                </td>
              </tr>
              <tr>
                <td colspan="2" style="border:none;">
                   <span><b>Age/Sex:</b></span>
                   <span tal:content="python: model.get_patient_age(patient.getBirthDate())">Age in years </span>
		   <span tal:content="python: model.get_patient_gender(patient.getGender())">Gender</span>
                </td>
	      </tr>
	      <tr>
                <td colspan="2" style="border:none;">
                  <span><b>DOB:</b></span>
                   <span tal:condition="python:patient.getBirthDate()" tal:content="python:model.format_the_date(patient.getBirthDate())"> Patient DoB</span>
                </td>
              </tr>
              <tr>
                 <td colspan="2" style="border:none;">
                   <span><b>Phone:</b></span>
                   <span tal:content="patient/HomePhone|Nothing">1234567890</span>
                </td>
              </tr>
              <tr>
                 <td colspan="2" style="border:none;">
                   <span><b>Chart#:</b></span>
                   <span tal:content="patient/ClientPatientID">Client Patient ID</span>
                </td>
              </tr>
                <tr>
                 <td colspan="2" style="border:none;">
                   <span>&nbsp;</span>
                </td>
              </tr>
            </table>
          </td>
          
          <!-- Physician Details -->
          <td style="width:37%;border:2px solid black;">
             <table style="width:100%;">
              <tr>
                <td colspan="2" style="border:none;">
                  <div style="background-color:lightblue;"><span><b>Physician Information</b></span></div>
                </td>
              </tr>
              <tr>
                 <td colspan="2" style="border:none;">
                   <span tal:content="doctor/Title" style="font-weight: bold">YENFENG CHEN Physician, P.C</span>
                </td>
              </tr>
              <tr>
                 <td colspan="2" style="border:none;">
                   167-07 Powells Cove blvd, 24
                   <!--<span tal:replace="doctor/PhysicalAddress/address|nothing">5517 7th Avenue</span>-->
                   <span>&nbsp;</span>
                </td>
              </tr>
              <tr>
                 <td colspan="2" style="border:none;">
                   Whitestone, NY 11357
                   <!--
                   <span tal:replace="doctor/PhysicalAddress/city|nothing">BROOKLYN, NY</span>
                   <span tal:replace="doctor/PhysicalAddress/city|nothing">11220</span>
                    -->
                   <span>&nbsp;</span>
                </td>
              </tr>
              <tr>
                 <td style="border:none;">
                   <span><b>Tel#:</b></span>
                   <span tal:content="doctor/HomePhone|Nothing">(718)871-8255<</span>
               </td>
                <td style="border:none;">
                   <span><b>Fax#:</b></span>
                   <span tal:content="doctor/BusinessFax|Nothing">(718)871-8255<</span>

               </td>
              </tr>
              <tr>
                 <td style="border:none;">
                   <span><b>Referring Physician:</b></span>
                </td>
                <td style="border:none;">
                   <span tal:content="physician/Title">YENFENG CHEN Physician, P.C</span>                
		</td>
              </tr>
            </table>
          </td>
          <!-- Specimen information -->
          <td style="width:30%;border:2px solid black;">
             <table style="width:100%;">
              <tr>
                <td colspan="2" style="border:none;">
                  <div style="background-color:lightblue;"><span><b>Specimen Information</b></span><div>
                </td>
              </tr>
              <tr>
                 <td style="border:none;">
                   <span><b>Accession#:</b></span>
                </td>
                <td style="border:none;">
                   <span tal:content="model/getId">123456789</span>
                </td>
              </tr>
              <tr>
                 <td style="border:none;">
                   <span><b>Date Collected:</b></span>
                </td>
                <td style="border:none;">
                   <span tal:content="python:model.format_the_date(model.DateSampled)">11/12/2020</span>
                </td>
              </tr>
              <tr>
                 <td style="border:none;">
                   <span><b>Date Received:</b></span>
                </td>
                <td style="border:none;">
                   <span tal:content="python:model.format_the_date(model.DateReceived)">11/12/2020</span>
                </td>
              </tr>
              <tr>
                 <td style="border:none;">
                   <span><b>Date Reported:</b></span>
                </td>
                <td style="border:none;">
                   <span tal:content="python:model.format_the_date(model.DatePublished) if model.DatePublished else model.format_the_date(model.get_curr_date_time())">11/12/2020</span>
                </td>
              </tr>
                <tr>
                <td colspan="2" style="border:none;">
                   <span>&nbsp;</span>
                </td>
                </tr>
           </table>
          </td>
        </tr>
</table>
    </div>
  </div>
        
            
      
  <!-- ALERTS -->
  <tal:render condition="python:True">
    <div class="row section-alerts no-gutters">
      <div class="w-100 mb-2">
        <div class="alert alert-danger" tal:condition="model/is_invalid">
          <div i18n:translate="">This Sample has been invalidated due to erroneously published results</div>
          <tal:invalidreport tal:define="child model/Retest"
                             tal:condition="child">
            <span i18n:translate="">This Sample has been replaced by</span>
            <a tal:attributes="href child/absolute_url"
               tal:content="child/getId"></a>
          </tal:invalidreport>
        </div>
        <div class="alert alert-info" tal:condition="model/is_provisional">
          <div i18n:translate="">Provisional report</div>
        </div>
      </div>
    </div>
  </tal:render>

  <!-- PATIENT INFO -->
  
  <!-- Sample Information -->
  


  <!-- RESULTS -->
  <tal:render condition="python:True">
    <div class="row section-results no-gutters">
      <div class="w-100">
        <!-- Point of Capture -->
        <tal:poc define="analyses_by_poc python:view.get_analyses_by_poc(model);"
                 repeat="poc analyses_by_poc">

          <!-- Analysis Category -->
          <tal:categories_in_poc define="categories_by_poc python:view.get_categories_by_poc(model)"
                                 repeat="category python:view.sort_items(categories_by_poc.get(poc))">

            <!-- Analysis in POC and Category -->
            <table class="table table-sm table-condensed">
              <colgroup>
                <!-- Category -->
                <col style="width: 37%;">
                <!-- Result -->
                <col style="width: 28%">
                <!-- Range -->
                <col style="width: 20%">
                <!-- Unit -->
                <col style="width: 10%">
                <!-- Out of Range -->
                <col style="width: 5%">
              </colgroup>
              <thead>
             
                <tr  class="font-weight-bold" >
                  <th class="analysis">
                    <span class="text-left">Test Name</span>
                  </th>
                  <th class="text-left result">
                    <span i18n:translate="">Result</span>
                  </th>
                  <th class="specs">
                    <span i18n:translate="">Normal Range</span>
                  </th>
                  <th class="text-left unit">
                    <span i18n:translate="">Units</span>
                  </th>
                  <th class="outofrange">
                    <span i18n:translate=""></span>
                  </th>
                </tr>           
              </thead>
                  <!--
                <tr>
                  <td colspan="5" class="text-left">
                      <span tal:content="category/Title">Category</span>
                  </td>
                </tr>      
                -->
              <tbody>
                <tal:analyses tal:repeat="analysis python:view.get_analyses_by(model, poc=poc, category=category)">
                  <tr>
                    <td class="analysis">
                      <span class="text-success"
                            tal:content="accredited_symbol"
                            style="font-family:Lucida Console, Courier, monospace;"
                            tal:condition="analysis/Accredited">
                      </span>
                      <span tal:condition="not:analysis/ScientificName">
                        <span class="font-weight-normal" tal:content="analysis/title"></span>
                      </span>
                      <span tal:condition="analysis/ScientificName">
                        <span class="font-italic" tal:content="analysis/title"></span>
                      </span>
                    </td>
                    <td class="text-left">
                      
                      <span class="result" tal:condition="python:model.is_out_of_range(analysis)" style="color:red;font-weight:bold" tal:content="structure python:model.get_formatted_result(analysis)">23</span>
                      <span class="result" tal:condition="python:not model.is_out_of_range(analysis)" tal:content="structure python:model.get_formatted_result(analysis)">23</span>
                      
                    </td>
                   
                    <td class="specs">
                      <span tal:condition="analysis/Uncertainty"
                            tal:content="structure python:model.get_formatted_uncertainty(analysis)"></span>
                      <span tal:content="python:'(RT)' if model.is_retest(analysis) else ''"></span>
                      <span tal:content="python:model.get_formatted_specs(analysis)">50 - 60</span>
                    </td>
                     <td class="text-left text-muted font-italic">
                      <span class="units" tal:content="structure python:model.get_formatted_unit(analysis)"></span>
                    </td>
                    <td class="text-center align-middle">
                      <span tal:condition="python:model.is_out_of_range(analysis)"
                            class="font-weight-light">
                        <span class="outofrange text-danger"
                              style="font-family:Lucida Console, Courier, monospace;"
                              tal:content="outofrange_symbol">
                        </span>
                      </span>
                    </td>
                  </tr>
                </tal:analyses>
              </tbody>
              <tfoot tal:define="category_comments python:category.Comments">
                <tr tal:condition="category_comments">
                  <td colspan="3">
                    <div class="category_comments"
                         tal:content="category_comments">
                      Category Comments
                    </div>
                  </td>
                </tr>
		<tr tal:condition="python: model.get_category_description(category)">
                  <td colspan="3">
                    <div style="font-size: 8pt; font-style: italic;" 
                         tal:content="python: model.get_category_description(category)">
                      Category Description
                    </div>
                  </td>
                </tr>
		
              </tfoot>
            </table>
          </tal:categories_in_poc>
        </tal:poc>
      </div>
    </div>
  </tal:render>

  <!--  RESULTS INTERPRETATION -->
  <tal:render condition="python:True">
    <div class="row section-resultsinterpretation no-gutters"
         tal:define="ris python:model.get_resultsinterpretation();
                     has_ri python:any(map(lambda r: r.get('richtext'), ris));">
      <div class="" tal:condition="has_ri">
        <h1 i18n:translate="">Remarks</h1>

        <tal:ri repeat="ri ris">
        <!-- <h2 tal:condition="ri/richtext|nothing" tal:content="ri/title|nothing">Department</h2> -->
          <div class="text-info" tal:content="structure ri/richtext|nothing"></div>
        </tal:ri>
      </div>
    </div>
  </tal:render>
  
  <!-- QC RESULTS -->
  <tal:render condition="python:True"
              define="qcanalyses python:model.getQCAnalyses(['verified', 'published']);">
    <div class="row section-results no-gutters" tal:condition="qcanalyses">
      <div class="small">
        <h1 i18n:translate="">QC Results</h1>
      </div>
    </div>
  </tal:render>

  <!--  REMARKS -->
  <tal:render condition="python:True">
    <div class="row section-remarks no-gutters" tal:condition="model/Remarks">
      <div class="small">
        <h1 i18n:translate="">Remarks</h1>
        <table>
          <div tal:repeat="item model/Remarks" style="border-style:solid; border-width: 1px; padding: 10px;">
            <h2 tal:content="item/content">content</h2>
            <div style="display: flex; flex-direction:row;">
              <div tal:content="item/user_id">user_id</div>
              <div tal:content="item/created">created</div>
            </div>
          </div>
        </table>
<!--        <div class="text-info" tal:content="structure model/Remarks"></div> -->
      </div>
    </div>
  </tal:render>

  <!-- ATTACHMENTS -->
  <tal:render condition="python:True">
    <div class="row section-attachments no-gutters">
      <tal:attachment tal:define="attachments python:model.get_sorted_attachments('r');">
        <h2 i18n:translate=""
            tal:condition="attachments">
          Attachments for <span tal:replace="model/getId"/>
        </h2>
        <table class="table w-100" tal:condition="attachments">
          <colgroup tal:condition="python:len(attachments) > 1">
            <col tal:repeat="col python:range(attachments_per_row)"
                  tal:attributes="style python:'width:{}%'.format(100/attachments_per_row)">
          </colgroup>
          <tr tal:repeat="chunk python:view.group_into_chunks(attachments, attachments_per_row)">
            <td class="align-bottom"
                style="border:none;padding-left:0;"
                tal:repeat="attachment chunk">
              <figure class="figure">
                <img class="figure-img img-fluid"
                     tal:attributes="src string:${attachment/absolute_url}/AttachmentFile;"/>
                <figcaption class="figure-caption pt-2">
                  <div class="att_for">
                    <span i18n:translate="">Attachment for</span>
                    <span tal:content="attachment/getTextTitle|model/getId"/>
                  </div>
                  <div class="att_keys">
                    <span tal:content="attachment/AttachmentKeys"/>
                  </div>
                  <div class="att_filename">
                    <span i18n:translate="">Filename:</span>
                    <span tal:content="attachment/AttachmentFile/filename"/>
                  </div>
                </figcaption>
              </figure>
            </td>
          </tr>
        </table>
      </tal:attachment>
    </div>
  </tal:render>

  <!--  SIGNATURES -->
  

  <!-- DISCREETER -->
  <tal:render condition="python:True"
              define="laboratory python:view.laboratory;
                      contact model/Contact">
    <div class="row section-discreeter no-gutters">
      <div class="w-100 text-muted font-weight-light small">
        <div class="discreeter-outofrange">
          <span class="outofrange text-danger"
                style="font-family:Lucida Console, Courier, monospace;"
                tal:content="outofrange_symbol">
          </span>
          <span i18n:translate="">Result out of client specified range.</span>
        </div>
        <div class="discreeter-not-invoiced"
             tal:condition="model/InvoiceExclude"
             i18n:translate="">
          Not invoiced
        </div>
        <div class="discreeter-methods"
             tal:condition="laboratory/LaboratoryAccredited">
          <span class="accredited-symbol text-success"
                style="font-family: Lucida Console, Courier, monospace;"
                tal:content="accredited_symbol">
          </span>
          <span class="" i18n:translate="">
            Methods included in the
            <tal:block replace="laboratory/AccreditationBody" i18n:name="accreditation_body"/>
            schedule of Accreditation for this Laboratory. Analysis remarks are not
            accredited
          </span>
        </div>
        <div class="discreeter-disclaimer"
             i18n:translate="">
This test has been validated at NOVINO PATHOLOGY but has not been reviewed by the FDA. Negative results do not rule out SARS-CoV-2 infection, particularly in those who have been in contact with the virus. Follow-up testing with a molecular diagnostic should be considered to rule out infection in these individuals. Results from antibody testing should not be used as the sole basis to diagnose or exclude SARS-CoV-2 infection or to inform infection status. Positive results may be due to past or present
infection with non-SARS-CoV-2 coronavirus strains, such as coronavirus HKU1, NL63, OC43, or 229E.
        </div>
        
        <div tal:define="confidence_level laboratory/Confidence"
             tal:condition="confidence_level" i18n:translate="">
          Test results are at a <tal:block replace="confidence_level" i18n:name="lab_confidence"/>% confidence level
        </div>
      </div>
    </div>
  </tal:render>

  <!-- CUSTOM FOOTER -->
  <tal:render condition="python:footer">
    <div class="row section-footer no-gutters">
      <!-- Footer Line -->
      <div id="footer-line"></div>
      <div tal:replace="structure footer"/>
    </div>
  </tal:render>

  <!-- DEFAULT FOOTER -->
  <tal:render condition="python:not footer"
              define="laboratory python:view.laboratory;">
    <div class="row section-footer no-gutters">
      <!-- Footer Line -->
      <div id="footer-line"></div>
      <table class="w-100">
        <tr>
          <td>
            <div>
              
            </div>
            <div>
             
            </div>
          </td>
        </tr>
      </table>
    </div>
  </tal:render>

</tal:report>
