{% extends '@RxConnexion/Admin/content.html.twig' %}
{% block content %}
    <form method="POST" action="{{ path('referral_form', {action: action, id: id}) }}" enctype="multipart/form-data">
        <div class="row max-width-initial">
            <div class="large-6 columns">
                <h5>Basic information</h5>
                <p class="form-hint-text">Enter basic information below</p>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.referral_date) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.referral_date) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.receiveDate) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.receiveDate) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.first_name) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.first_name) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.middle_name) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.middle_name) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.last_name) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.last_name) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.birth_date) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.birth_date) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.gender) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.gender) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.personal_health_no) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.personal_health_no) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.source) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.source) }}
                    </div>
                </div>
                <div class="row referredByText {{ form.vars.value.source.description|default('') == 'Referred By Patient' ? '' : 'hide' }}">
                    <div class="large-3 large-text-right columns">
                        {{ form_widget(form.referredBy) }}
                        {{ form_label(form.referredByPatient_fullName) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.referredByPatient_fullName) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.healthFacility_desc) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.healthFacility_desc) }}
                        {{ form_widget(form.healthFacility) }}
                    </div>
                </div>
            </div>
            <div class="large-6 columns">
                <h5>Address information</h5>
                <p class="form-hint-text">Enter address information below</p>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.street) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.street) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.city_desc) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.city_desc) }}
                        {{ form_widget(form.city) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.postalCode_desc) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.postalCode_desc) }}
                        {{ form_widget(form.postalCode) }}
                    </div>
                </div>
            </div>
            <div class="large-12 columns" style="padding-top: 20px; padding-bottom: 20px;">
                <h5>Services</h5>
                {% if form.referralServices is not empty %}
                    {% for rs_form in form.referralServices %}
                        <div class="row">
                            <div class="large-1 large-text-right columns">
                                {{ form_widget(rs_form.is_checked) }}
                                {{ form_widget(rs_form.id) }}
                                {{ form_widget(rs_form.service) }}

                            </div>
                            <div class="large-11 columns">
                                {{ form_label(rs_form.is_checked) }}
                            </div>
                        </div>
                    {% endfor %}
                {% else %}
                    <li>No Services</li>
                {% endif %}
            </div>
            <div class="large-12 columns">
                <h5>Contact information</h5>
                <p class="form-hint-text">Enter contact information below</p>
                <div class="row">
                    <div class="xxlarge-4 xlarge-4 large-4 medium-4 small-12 columns">
                        {{ form_label(form.mobile_no) }}
                        {{ form_widget(form.mobile_no) }}
                        {{ form_widget(form.mobile_no_two) }}
                        {{ form_widget(form.mobile_no_three) }}
                    </div>
                    <div class="xxlarge-4 xlarge-4 large-4 medium-4 small-12 columns">
                        {{ form_label(form.phone_no) }}
                        {{ form_widget(form.phone_no) }}
                        {{ form_widget(form.phone_no_two) }}
                        {{ form_widget(form.phone_no_three) }}
                    </div>
                    <div class="xxlarge-4 xlarge-4 large-4 medium-4 small-12 columns">
                        {{ form_label(form.email) }}
                        {{ form_widget(form.email) }}
                        {{ form_widget(form.email_two) }}
                        {{ form_widget(form.email_three) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-6 columns">
                        <h5>Referring Affiliate <a href="javascript:void(0)" data-open="modal-referringHealthFacility"><i class="fa fa-search"></i></a></h5>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringHealthFacility.description) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringHealthFacility.description) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringHealthFacility.phone_no) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringHealthFacility.phone_no) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringHealthFacility.fax_no) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringHealthFacility.fax_no) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringHealthFacility.city_desc) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringHealthFacility.city_desc) }}
                                {{ form_widget(form.referringHealthFacility.city) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringHealthFacility.street) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringHealthFacility.street) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringHealthFacility.postalCode_desc) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringHealthFacility.postalCode_desc) }}
                                {{ form_widget(form.referringHealthFacility.postalCode) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringHealthFacility_id) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringHealthFacility_id) }}
                            </div>
                        </div>
                    </div>
                    <div class="large-6 columns">
                        <h5>Referring Physician <a href="javascript:void(0)" data-open="modal-referringProvider"><i class="fa fa-search"></i></a></h5>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.first_name) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.first_name) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.middle_name) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.middle_name) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.last_name) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.last_name) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.honorific) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.honorific) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.gender) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.gender) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.phone_no) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.phone_no) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.fax_no) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.fax_no) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.city_desc) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.city_desc) }}
                                {{ form_widget(form.referringProvider.city) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.street) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.street) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider.postalCode_desc) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider.postalCode_desc) }}
                                {{ form_widget(form.referringProvider.postalCode) }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.referringProvider_id) }}
                            </div>
                            <div class="large-8 columns">
                                {{ form_widget(form.referringProvider_id) }}
                            </div>
                        </div>
                    </div>
                </div>
                {% if action != 'u' %}
                <div class="row">
                    <div class="large-6 columns">
                    {% if faxTranId != 0  %}
                        <h5>Fax</h5>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                {{ form_label(form.fax_tran_id) }}
                            </div>
                            <div class="large-4 columns">
                                {{ form_widget(form.fax_tran_id) }}
                            </div>
                            <div class="large-4 columns" style="padding-left:0px;">
                                <a href="javascript:void(0)" class="button secondary expanded href-view-fax" data-sFaxDetailsID="{{ faxTranId }}" data-sDirection="IN">View Fax</a>
                            </div>
                        </div>
                    {% elseif faxTranId == 0 %}
                        <h5>Referral Form</h5>
                        <div class="row">
                            <div class="large-4 large-text-right columns">
                                <label style="margin:10px;">Upload File (PDF)</label>
                            </div>
                            <div class="large-8 columns">
                                <input style="margin:10px;" type="file" accept="application/pdf" name="form[file]">
                            </div>
                        </div>
                    {% endif %}
                    </div>
                </div>
                {% endif %}
                <div class="row">
                    <div class="xxlarge-12 xlarge-12 large-12 medium-12 small-12 columns">
                        {{ form_label(form.note) }}
                        {{ form_widget(form.note) }}
                    </div>
                </div>
            </div>
            <div class="small-12 columns">
                <hr class="max-width-initial">
                <div class="button-container">
                    <button type="submit" class="button just-continue" name="action" value="{{ action }}"
                            data-message="Are you sure you want to save this information?"
                    >Save</button>
                    {% if action == 'u' and (userData.type == 'Super Admin' or 'Admin Referral Delete' in userData.accesses) %}
                        <button type="submit" class="ask-continue button alert" name="action" value="d"
                                data-message="Are you sure you want to delete this record?"
                        >Delete</button>
                    {% endif %}
                    <a href="{{ path('referral') }}" class="button secondary">Back</a>
                </div>
            </div>
        </div>
        {{ form_widget(form.fax_tran) }}
        {{ form_widget(form.action) }}
        {{ form_widget(form.id) }}
        {{ form_widget(form._token) }}
    </form>
    <div class="reveal large" id="modal-referringProvider" data-reveal>
        <br />
        <h5>Referring Physician</h5>
        <br />
        <div>
            <table class="display responsive" id="referringProvider-datalist" width="100%">
                <thead>
                <tr>
                    <th>Full Name</th>
                    <th>Address</th>
                    <th>Phone No(s).</th>
                    <th>Mobile No(s).</th>
                    <th>Email(s)</th>
                </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="reveal large" id="modal-referringHealthFacility" data-reveal>
        <br />
        <h5>Referring Affiliate</h5>
        <br />
        <div>
            <table class="display responsive" id="referringHealthFacility-datalist" width="100%">
                <thead>
                <tr>
                    <th>Company</th>
                    <th>Branch</th>
                    <th>Description</th>
                    <th>Address</th>
                    <th>Phone No(s).</th>
                    <th>Mobile No(s).</th>
                    <th>Email(s)</th>
                </tr>
                </thead>
                <tbody></tbody>
            </table>
        </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[
        referral_form.settings.city_autocomplete_url = '{{ path('city_autocomplete') }}';
        referral_form.settings.postalCode_autocomplete_url = '{{ path('postal_code_autocomplete') }}';
        referral_form.settings.healthFacility_autocomplete_url = '{{ path('health_facility_autocomplete') }}';
        referral_form.settings.referringProvider_autocomplete_url = '{{ path('referring_provider_autocomplete') }}';
        referral_form.settings.referringProviderHealthFacility_autocomplete_url= '{{ path('referring_provider_health_facility_autocomplete') }}';
        referral_form.settings.referringProvider_ajax_listUrl = '{{ path('referring_provider_ajax_list_for_referral_form') }}';
        referral_form.settings.referringHealthFacility_ajax_listUrl = '{{ path('referring_health_facility_ajax_list_for_referral') }}';
        referral_form.settings.faxPreviewUrl = '{{ path('fax_view', {"id":faxTranId,"sDirection": 'IN'}) }}';
        referral_form.settings.patient_autocomplete_url = '{{ path('patient_autocomplete') }}';
        {#referral_form.settings.sFaxDetailsID = '{{ faxTranId }}';#}
        // referral_form.settings.sDirection = 'IN';
        jQ(document).ready(function(){
            referral_form.init();
            CKEDITOR.replace('referral_note');
        });
        //]]>
    </script>
{% endblock %}