{% extends '@RxConnexion/Admin/global.html.twig' %}
{% block body %}
    <h3 class="report-header"><strong>{{ page_title }}</strong> From: {{ date_from }} To: {{ date_to }}</h3>

    {% if type == 'rhf' %}
        <table class="report-data" width="100%">
            <thead class="header">
            <tr>
                <th>Encounter ID</th>
                <th>Staff</th>
                <th>Encounter Date</th>
                <th>Referring Affiliate</th>
                <th>Company</th>
                <th>Branch</th>
                <th>Marketing Staff</th>
                <th>Encounter Type</th>
                <th>Status</th>
                <th>Note</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 }}">
                <tr>
                    <td><a href="{{ path('referring_health_facility_chart_form', {referring_health_facility_id : record.referringHealthFacilityId|base64Encode, id: record.encounterId|base64Encode}) }}" target="_blank">{{ record.encounterId }}</a></td>
                    <td>{{ record.accountUser }}</td>
                    <td>{{ record.encounterDate }}</td>
                    <td><a href="{{ path('referring_health_facility_detail', {referringHealthFacility_id : record.referringHealthFacilityId|base64Encode}) }}" target="_blank">{{ record.referringHealthFacilityDesc }}</a></td>
                    <td>{{ record.companyDesc }}</td>
                    <td>{{ record.branch }}</td>
                    <td>{{ record.marketingStaffName }}</td>
                    <td>{{ record.encounterType }}</td>
                    <td>{{ record.encounterStatus }}</td>
                    <td>
                        {% set n_split = record.notes|split(',') %}
                        {% for note in n_split %}
                            {% set rpNote = note|split('|') %}
                            <div>{{ rpNote[1]|default('')|raw }}</div>
                        {% endfor %}
                    </td>
                </tr>
            {% endfor %}
        </table>
    {% endif %}

    {% if type == 'rp' %}
        <table class="report-data" width="100%">
            <thead class="header">
            <tr>
                <th>Encounter ID</th>
                <th>Staff</th>
                <th>Encounter Date</th>
                <th>Referring Physician</th>
                <th>Company</th>
                <th>Branch</th>
                <th>Marketing Staff</th>
                <th>Encounter Type</th>
                <th>Status</th>
                <th>Note</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 }}">
                <tr>
                    <td><a href="{{ path('referring_provider_chart_form', {referring_provider_id : record.referringProviderId|base64Encode, id: record.encounterId|base64Encode}) }}" target="_blank">{{ record.encounterId }}</a></td>
                    <td>{{ record.accountUser }}</td>
                    <td>{{ record.encounterDate }}</td>
                    <td><a href="{{ path('referring_provider_detail', {referringProvider_id : record.referringProviderId|base64Encode}) }}" target="_blank">{{ record.referringProviderDesc }}</a></td>
                    <td>{{ record.companyDesc }}</td>
                    <td>{{ record.branch }}</td>
                    <td>{{ record.marketingStaffName }}</td>
                    <td>{{ record.encounterType }}</td>
                    <td>{{ record.encounterStatus }}</td>
                    <td>
                        {% set n_split = record.notes|split(',') %}
                        {% for note in n_split %}
                            {% set rpNote = note|split('|') %}
                            <div>{{ rpNote[1]|default('')|raw }}</div>
                        {% endfor %}
                    </td>
                </tr>
            {% endfor %}
        </table>
    {% endif %}

    <div>Total Records: {{ totalCount }}</div>
    <br>
    <h3>Summary</h3>
    <div style="border: 1px solid; padding: 20px; margin: 10px;">
        <ul>
            {% for key,et in summary.encounterTypes %}
                <li>
                    {{ key }}
                    <ul>
                        {% for key2,es in et %}
                            <li>
                                {{ key2 }}: {{ es }}
                            </li>
                        {% endfor %}
                    </ul>
                </li>
            {% endfor %}
        </ul>
    </div>
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script>
        //<![CDATA[
        jQ(document).ready(function(){
            report_preview.init();
        });
        //]]>
    </script>
{% endblock %}