{% extends '@RxConnexion/Admin/global.html.twig' %}
{% block body %}
    <h5 class="report-header" style="width: 650%;">{{ page_title }}</h5>
    <table class="report-data" width="650%">
        <thead class="header">
        <tr>
            <th>Referral Date</th>
            <th>Received Date</th>
            <th>Type of Fax</th>
            <th>Received From</th>
            <th>Patient Name</th>
            <th>Affiliation</th>
            <th>Physician</th>
            <th>Patient Services</th>
            <th>Previous Branch</th>
            <th>Branch</th>
            <th>Acknowledgement Letter Date</th>
            <th>Acknowledgement Letter Status</th>
            <th>Link To Letter</th>
            <th>Count of Days</th>
            <th>Intro Phone Call Date</th>
            <th>Intro Phone Call Status</th>
            <th>Intro Phone Call Notes</th>
            <th>Count of Days</th>
            <th>HSAT Date</th>
            <th>HSAT Status</th>
            <th>HSAT Notes</th>
            <th>Appointment Notice</th>
            <th>Count of Days</th>
            <th>Refusal/ Declined/ No Book Letters Date</th>
            <th>Refusal/ Declined/ No Book Letter Type</th>
            <th>Refusal/ Declined/ No Book Letters Status</th>
            <th>Link To Letter</th>
            <th>HSAT Repeat Date</th>
            <th>HSAT Repeat Status</th>
            <th>HSAT Repeat Notes</th>
            <th>Count of Days</th>
            <th>HSAT Results Interpretation</th>
            <th>HSAT Results Interpretation Status</th>
            <th>HSAT Result Interpretation Notes</th>
            <th>Count of Days</th>
            <th>Test Result</th>
            <th>Prescription Date</th>
            <th>Prescription Status</th>
            <th>Prescription Notes</th>
            <th>Count of Days</th>
            <th>Result Letters Date</th>
            <th>Result Letter Type</th>
            <th>Result Letters Status</th>
            <th>Link To Letter</th>
            <th>Count of Days</th>
            <th>Letter Assign to Date</th>
            <th>Letter Assign to Status</th>
            <th>Notes</th>
            <th>Quotation Date</th>
            <th>Quotation Status</th>
            <th>Quotation Notes</th>
            <th>Count of Days</th>
            <th>Insurance</th>
            <th>CPAP Trial Date</th>
            <th>CPAP Trial Status</th>
            <th>CPAP Trial Notes</th>
            <th>CPAP Setup and Sold</th>
            <th>CPAP Setup and Sold Status</th>
            <th>CPAP Setup and Sold Notes</th>
            <th>Count of Days</th>
            <th>CPAP Letters Date</th>
            <th>CPAP Letter Type</th>
            <th>CPAP Letters Status</th>
            <th>Link To Letter</th>
            <th>Invoice Date</th>
            <th>Invoice Number</th>
            <th>Invoice Status</th>
            <th>Count of Days</th>
            <th>Last Care Call Date</th>
            <th>Last Care Call Status</th>
            <th>Last Care Call Notes</th>
            <th>6 Months Follow-up Date</th>
            <th>6 Months Follow-up Status</th>
            <th>6 months Follow-up Notes</th>
            <th>Count of Days</th>
            <th>Last 6 months Follow-up</th>
            <th>Next 6 months Follow-up</th>
            <th>Letters Date</th>
            <th>Letters Type</th>
            <th>Letters Status</th>
            <th>Link To Letter</th>
            <th>Invoice Date (Latest)</th>
            <th>Invoice Number (Latest)</th>
            <th>Invoice Status (Latest)</th>
        </tr>
        </thead>
        <tbody>
        {% set totalCount = 0 %}
        {% for record in records %}
            {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
            {% set totalCount = totalCount + 1 %}
            <tr class="{{ trC }}">
                <td>{{ record.referralDate }}</td>
                <td>{{ record.receiveDate }}</td>
                <td>{{ record.fax_category }}</td>
                <td>
                    {% if record.faxId != '' %}
                        <div>
                            {{ record.receivedFax ? record.receivedFax : '8332624798' }} (<a href="{{ path('fax_view', {id:record.faxId|default('null')}) }}" target="_blank">View</a>)
                        </div>
                    {% endif %}
                </td>
                <td><a href="{{ path('patient_detail', {patient_id:record.id|base64Encode}) }}" target="_blank">{{ record.full_name }}</a></td>
                <td>{{ record.referringHealthFacility }}</td>
                <td>{{ record.referringProvider }}</td>
                <td>
                    {% set ps_split = record.patientServices|split(',') %}
                    {% for ps in ps_split %}
                        {% set patientService = ps|split('|') %}
                        <div>{{ patientService[1]|default('') }}</div>
                    {% endfor %}
                </td>
                <td>{{ record.prevHealthFacility }}</td>
                <td>{{ record.healthFacility }}</td>
                <td>{{ record.ackDate }}</td>
                <td>{{ record.ackStatus }}</td>
                <td>
                    {% if record.ackLetterType != 'null' and record.ackLetterType != '' %}
                        <a href="{{ path('patient_letter_preview', {patientLetter_id : record.ackId|default('null')|base64Encode, letter_type:record.ackLetterType|default('null')}) }}" target="_blank">Preview</a>
                    {% endif %}
                </td>
                <td>N/A</td>
                <td>{{ record.ipcChartDate }}</td>
                <td>{{ record.ipcChartStatus }}</td>
                <td>{{ record.ipcNote }}</td>
                <td>N/A</td>
                <td>{{ record.hsatChartDate }}</td>
                <td>{{ record.hsatChartStatus }}</td>
                <td>{{ record.hsatNote }}</td>
                <td>{{ record.appointmentNoticeFaxDate }}</td>
                <td>N/A</td>
                <td>{{ record.rdnDate }}</td>
                <td>{{ record.rdnLetterType }}</td>
                <td>{{ record.rdnStatus }}</td>
                <td>
                    {% if record.rdnLetterType != 'null' and record.rdnLetterType != '' %}
                        <a href="{{ path('patient_letter_preview', {patientLetter_id : record.rdnId|default('null')|base64Encode, letter_type:record.rdnLetterType|default('null')}) }}" target="_blank">Preview</a>
                    {% endif %}
                </td>
                <td>{{ record.hrdChartDate }}</td>
                <td>{{ record.hrdChartStatus }}</td>
                <td>{{ record.hrdNote }}</td>
                <td>N/A</td>
                <td>{{ record.hriChartDate }}</td>
                <td>{{ record.hriChartStatus }}</td>
                <td>{{ record.hriNote }}</td>
                <td>N/A</td>
                <td>
                    {% if record.ptFileId != 'null' and record.ptFileId != '' %}
                        <div>
                            {{ record.fileName }} (<a href="{{ path('patient_file_download', {patientFile_id : record.ptFileId|default('null')|base64Encode}) }}">Download</a>)
                        </div>
                    {% endif %}
                </td>
                <td>{{ record.preChartDate }}</td>
                <td>{{ record.preChartStatus }}</td>
                <td>{{ record.preNote }}</td>
                <td>N/A</td>
                <td>{{ record.rlDate }}</td>
                <td>{{ record.rlLetterType }}</td>
                <td>{{ record.rlStatus }}</td>
                <td>
                    {% if record.rlLetterType != 'null' and record.rlLetterType != '' %}
                        <a href="{{ path('patient_letter_preview', {patientLetter_id : record.rlId|default('null')|base64Encode, letter_type:record.rlLetterType|default('null')}) }}" target="_blank">Preview</a>
                    {% endif %}
                </td>
                <td>N/A</td>
                <td>{{ record.pl_asDate }}</td>
                <td>{{ record.pl_asStatus }}</td>
                <td>N/A</td>
                <td>{{ record.quoChartDate }}</td>
                <td>{{ record.quoChartStatus }}</td>
                <td>{{ record.quoNote }}</td>
                <td>N/A</td>
                <td>{{ record.insuranceDesc }}</td>
                <td>{{ record.cpap_tChartDate }}</td>
                <td>{{ record.cpap_tChartStatus }}</td>
                <td>{{ record.cpap_tNote }}</td>
                <td>{{ record.cpap_ssChartDate }}</td>
                <td>{{ record.cpap_ssChartStatus }}</td>
                <td>{{ record.cpap_ssNote }}</td>
                <td>N/A</td>
                <td>{{ record.cpap_plDate }}</td>
                <td>{{ record.cpap_plLetterType }}</td>
                <td>{{ record.cpap_plStatus }}</td>
                <td>
                    {% if record.cpap_plLetterType != 'null' and record.cpap_plLetterType != '' %}
                        <a href="{{ path('patient_letter_preview', {patientLetter_id : record.cpap_plId|default('null')|base64Encode, letter_type:record.cpap_plLetterType|default('null')}) }}" target="_blank">Preview</a>
                    {% endif %}
                </td>
                <td>{{ record.billingDate }}</td>
                <td>{{ record.invoice_no }}</td>
                <td>{{ record.billing_status }}</td>
                <td>N/A</td>
                <td>{{ record.pc_lccChartDate }}</td>
                <td>{{ record.cs_lccChartStatus }}</td>
                <td>{{ record.cs_lccNote }}</td>
                <td>{{ record.six_ffChartDate }}</td>
                <td>{{ record.six_ffChartStatus }}</td>
                <td>{{ record.cs_six_ffNote }}</td>
                <td>N/A</td>
                <td>{{ record.latestSixFFDate }}</td>
                <td>{{ record.sixFFDateSixMonth }}</td>
                <td>{{ record.l_plDate }}</td>
                <td>{{ record.l_plLetterType }}</td>
                <td>{{ record.l_plStatus }}</td>
                <td>
                    {% if record.l_plLetterType != 'null' and record.l_plLetterType != '' %}
                        <a href="{{ path('patient_letter_preview', {patientLetter_id : record.l_plId|default('null')|base64Encode, letter_type:record.l_plLetterType|default('null')}) }}" target="_blank">Preview</a>
                    {% endif %}
                </td>
                <td>{{ record.latestBillingDate }}</td>
                <td>{{ record.latestInvoice }}</td>
                <td>{{ record.latestBillingStatus }}</td>
            </tr>
        {% endfor %}
    </table>
    <div>Total Records: {{ totalCount }}</div>
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script>
        //<![CDATA[
        jQ(document).ready(function(){
            report_preview.init();
        });
        //]]>
    </script>
{% endblock %}