{% set absUrl = app.request.getSchemeAndHttpHost() ~ app.request.baseUrl|replace({'/app_dev.php': ''}) %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="{{ absUrl ~ asset('bundles/rxconnexion/admin/css/report/report_wkpdf.css') }}" />
    <style>
        table { table-layout: fixed; }
        table th, table td { overflow: hidden; }
    </style>
</head>
<body>
<h2><strong>{{ page_title }}</strong></h2>
<table class="report-data" width="140%">
    <thead class="header">
    <tr>
        <th style="width: 7%;">Referral ID</th>
        <th style="width: 13%;">Staff</th>
        <th style="width: 10%;">Referral Date</th>
        <th style="width: 10%;">Received Date</th>
        <th style="width: 10%;">Patient</th>
        <th style="width: 10%;">Services</th>
        <th style="width: 10%;">Branch</th>
        <th style="width: 15%;">Referring Affiliate</th>
        <th style="width: 15%;">Referring Physician</th>
        <th style="width: 15%;">Encounter Type</th>
        <th style="width: 15%;">Encounter Status</th>
        <th style="width: 10%;">Letter Type</th>
        <th style="width: 10%;">Letter Status</th>
        <th style="width: 10%;">Agent</th>
        <th style="width: 50%;">Notes</th>
    </tr>
    </thead>
    <tbody>
    {% set totalCount = 0 %}
    {% for record in records.referral %}
        {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
        {% set totalCount = totalCount + 1 %}
        <tr class="{{ trC }}">
            <td style=" overflow:hidden;">{{ record.referralId }}</td>
            <td style=" overflow:hidden;">{{ record.accountUser }}</td>
            <td style=" overflow:hidden;">{{ record.referral_date }}</td>
            <td style=" overflow:hidden;">{{ record.receive_date }}</td>
            <td><a href="{{ path('patient_detail', {patient_id : record.patientId|base64Encode}) }}" target="_blank">{{ record.patient }}</a></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.branch }}</td>
            <td>{{ record.referring_affiliate }}</td>
            <td>{{ record.referring_physician }}</td>
            <td>{{ record.chartType }}</td>
            <td>{{ record.chartStatus }}</td>
            <td>{{ record.letterType }}</td>
            <td>{{ record.letterStatus }}</td>
            <td>{{ record.sales_agent|raw }}</td>
            <td>{{ record.note|raw }}</td>
        </tr>
    {% endfor %}
</table>
<div>Total Records: {{ totalCount }}</div>
<hr>
<h5 class="report-header" style=" width:275%">Referral - Referring Physician</h5>
<table class="report-data" width="50%">
    <thead class="header">
    <tr>
        <th>Referring Physician</th>
        <th>Count</th>
    </tr>
    </thead>
    <tbody>
    {% set totalCount = 0 %}
    {% for record in records.referralCount %}
        {% set trC = loop.index > 1 and loop.index % 2 == 0 ? 'even' : 'odd' %}
        {% set totalCount = totalCount + 1 %}
        <tr class="{{ trC }}">
            <td style=" overflow:hidden;">{{ record.referringProvider }}</td>
            <td style=" overflow:hidden;">{{ record.referralCount }}</td>
        </tr>
    {% endfor %}
</table>
<div>Total Records: {{ totalCount }}</div>
</body>
</html>