{% extends '@RxConnexion/Admin/global.html.twig' %}
{% block body %}
    <div class="row max-width-initial">
        <div class="large-11 columns">
            <form method="GET" action="{{ path('patient_6_months_follow_up') }}">
                <div class="large-4 columns">
                    <div class="input-group">
                        <label class="input-group-label">Branch</label>
                        <select class="input-group-field" name="branch[]" multiple size="4">
                            <option value='All'>All</option>
                            {% for h in healthFacilities %}
                                <option value={{ h.id }} {{ h.id == branch ? 'selected' : '' }}>{{ h.description }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="large-2 columns">
                    <div class="input-group">
                        <label class="input-group-label">Month </label>
                        <select class="input-group-field" name="month">
                            <option value="" selected>All</option>
                            {% for month in monthFilter %}
                                <option value="{{ month.value }}" {{ getMonth == month.value ? 'selected' : '' }}>{{ month.display }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="input-group">
                        <label class="input-group-label">Year </label>
                        <select class="input-group-field" name="year">
                            <option value="" selected>All</option>
                            {% for year in yearFilter %}
                                <option value="{{ year.value }}" {{ getYear == year.value ? 'selected' : '' }}>{{ year.display }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="large-4 columns">
                    <div class="input-group">
                        <label class="input-group-label">Encounter Type</label>
                        <select class="input-group-field" name="encounterTypes[]" multiple size="4">
                            <option value='All'>All</option>
                            {% for ct in encounterTypes %}
                                <option value={{ ct.id }}>{{ ct.description }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="large-2 columns">
                    <button type="submit" class="button just-continue" value=""
                            data-message="Are you sure you want to save this information?"
                    >Apply filter</button>
                </div>
            </form>
            <form method="POST" action="{{ path('patient_6_months_follow_up_export_to_excel') }}">
                <button style="margin-left:1%" type="submit" class="button just-continue" value=""
                        data-message="Are you sure you want to save this information?"
                >Export To Excel</button>
            </form>
        </div>
        <div class="large-1 columns" style="border: 1px solid; margin-bottom: 20px;">
            <p><strong>Summary</strong></p>
            {% for summary in summaries %}
                <p style="margin-bottom: 0px;">{{ summary.summaryCount }}</p>
            {% endfor %}
        </div>
    </div>
    <div class="large-12 columns">
        <h5 class="report-header">{{ page_title }}</h5>
    </div>
    <div class="large-12 columns">
        <table class="report-data" width="125%">
            <thead class="header">
            <tr>
                <th style="width: 5%;">Branch</th>
                <th style="width: 5%;">Patient</th>
                <th style="width: 5%;">Latest 6 Months Follow-up Date</th>
                <th style="width: 5%;">Latest 6 Months Follow-up Status</th>
                <th style="width: 5%;">Latest CPAP Setup Date</th>
                <th style="width: 5%;">Latest CPAP Setup Status</th>
                <th style="width: 5%;">Latest CPAP Setup Sold Date</th>
                <th style="width: 5%;">Latest CPAP Setup Sold Status</th>
                <th style="width: 5%;">Latest CPAP End Eval Date</th>
                <th style="width: 5%;">Latest CPAP End Eval Status</th>
                <th style="width: 5%;">Primary Clinician</th>
                <th style="width: 10%;">Next 6 months Follow up date</th>
                <th style="width: 20%;">Latest Notes</th>
                <th style="width: 5%;">Action</th>
            </tr>
            </thead>
            <tbody>
            {% for record in records %}
                <tr>
                    <td>{{ record.healthFacility }}</td>
                    <td style="color: {{ record.noteInterval == 'red' or record.note|raw == '' ? 'red' : '' }}"><a href="{{ path('patient_detail', {patient_id : record.patientId|base64Encode, tab: 'c'}) }}" target="_blank">{{ record.fullName }}</a></td>
                    <td>{{ record.sixMonthFFdate }}</td>
                    <td>{{ record.sixMonthFFstatus }}</td>
                    <td>{{ record.cpapSetupDate }}</td>
                    <td>{{ record.cpapSetupStatus }}</td>
                    <td>{{ record.cpapSetupSoldDate }}</td>
                    <td>{{ record.cpapSetupSoldStatus }}</td>
                    <td>{{ record.cpaEndEvalDate }}</td>
                    <td>{{ record.cpapEndEvalStatus }}</td>
                    <td>{{ record.primaryProviderName }}</td>
                    <td>{{ record.sixMonthFromCpap }}</td>
                    <td>{{ record.note|raw }}</td>
                    <td><a href="#" class="href-update-form" data-action="u" data-id="{{ record.patientChartId }}">Update</a></td>
                </tr>
            {% endfor %}
            <tr>
                <td colspan="7">Total: {{ records|length|number_format(0, '.', ',') }}</td>
            </tr>
        </table>
    </div>
    <div class="reveal" id="modal-small" data-reveal>
        <div id="modal-content" style="padding: 10px;"></div>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script>
        //<![CDATA[
        var dashboard_report = {
            settings: {
                updateFormUrl: null,
                saveUrl: null,
            },
            init: function() {
                dashboard_report.bindUpdateForm();
            },
            bindUpdateForm: function() {
                if(jQ('.href-update-form').length > 0) {

                    jQ('.href-update-form').unbind('click').bind('click', function(){

                        var requestName = 'patientChartReportStatus',
                            modal = jQ('#modal-small'),
                            modalContent = jQ('#modal-content');

                        global.ajaxCancel(requestName);

                        var settings = {
                            url: dashboard_report.settings.updateFormUrl + '/' + jQ(this).data('action') + '/' + jQ(this).data('id'),
                            type: 'GET',
                            beforeSend: function() {
                                modalContent.html('').addClass('has-loading');
                                modal.foundation('open');
                            },
                            success: function(json) {
                                modal.foundation('close');
                                modalContent.removeClass('has-loading').html(json.html);
                                modal.foundation('open');
                                global.bindFormSubmitted();
                                dashboard_report.bindUpdateFormAction()
                            }
                        };

                        global.ajax(settings, requestName);
                    });
                }
            },
            bindUpdateFormAction: function() {
                jQ('.href-update-is-done-action').unbind('click').bind('click', function () {
                    var requestName = 'patientChartReportStatusFormAction',
                        _form = jQ('#form-patient_chart_update_is_done'),
                        modal = jQ('#modal-small'),
                        axn = jQ(this).data('axn');
                    _form.find('.form-action').val(axn);

                    global.formSubmitted();
                    global.ajaxCancel(requestName);

                    var settings = {
                        url: dashboard_report.settings.saveUrl,
                        type: 'POST',
                        data: _form.serialize(),
                        success: function (json) {
                            if (json.success) {
                                location.reload();
                                // modal.foundation('close');
                                // global.parseFlashMessages(global.settings.vars.flashMessagesContentId, 'success', json.successMessages);
                            } else {
                                global.formSubmittedReverse();
                                global.parseFlashMessages('#flash-messages-content-modal', 'alert', json.errorMessages);
                            }
                        }
                    };

                    global.ajax(settings, requestName);
                });
            },
        };
        dashboard_report.settings.updateFormUrl = '{{ path("patient_chart_update_is_done") }}';
        dashboard_report.settings.saveUrl = '{{ path("patient_chart_update_is_done_save") }}';
        dashboard_report.init();
        //]]>
    </script>
{% endblock %}