{% extends '@RxConnexion/Admin/content.html.twig' %}
{% set userData = app.session.get('userData') %}
{% block content %}
    <form method="POST" action="{{ path('patient_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.account) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.account) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.patient_type_desc) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.patient_type_desc) }}
                        {{ form_widget(form.patient_type) }}
                    </div>
                </div>
                <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.received_date) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.received_date) }}
                    </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.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 referredByName {{ form.vars.value.source.description|default('') == 'Referred By' ? '' : 'hide' }}">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.referred_by_name) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.referred_by_name) }}
                    </div>
                </div>
                {#<div class=" row" style="font-size: .875rem;">#}
                    {#<div class="large-3 large-text-right columns">#}
                        {#Referred By#}
                    {#</div>#}
                    {#<div class="large-9 columns">#}
                        {#<input type="text" id="referredBy_text" value="{{ form.vars.value.referredBy|default('') }}">#}
                    {#</div>#}
                {#</div>#}
                {#<div class="row hide">#}
                    {#<div class="large-3 large-text-right columns">#}
                        {#{{ form_label(form.referredBy) }}#}
                    {#</div>#}
                    {#<div class="large-9 columns">#}
                        {#{{ form_widget(form.referredBy) }}#}
                    {#</div>#}
                {#</div>#}
                {#<div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.alberta_health_card_no) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.alberta_health_card_no) }}
                    </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.health_facility_desc) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.health_facility_desc) }}
                        {{ form_widget(form.health_facility) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.primary_provider_fullName) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.primary_provider_fullName) }}
                        {{ form_widget(form.primary_provider) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-12 large columns" style="padding-left: 10%;">
                        {% if userData.type == 'Super Admin' %}
                            {{ form_widget(form.is_test_patient) }}
                            {{ form_label(form.is_test_patient) }}
                        {% endif %}
                        {{ form_widget(form.is_endorsed) }}
                        {{ form_label(form.is_endorsed) }}
                        {{ form_widget(form.endorsed_by, { 'attr': {'style': 'display:none;'}}) }}
                        {{ form_widget(form.is_active) }}
                        {{ form_label(form.is_active) }}
                        {{ form_widget(form.is_referral) }}
                        {{ form_label(form.is_referral) }}
                        {{ form_widget(form.is_duplicate) }}
                        {{ form_label(form.is_duplicate) }}
                        {{ form_widget(form.is_specialist) }}
                        {{ form_label(form.is_specialist) }}
                        {{ form_widget(form.isNotCountAsReferral) }}
                        {{ form_label(form.isNotCountAsReferral) }}

                    </div>
                    <div class="large-1 columns">

                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                    </div>
                    <div class="large-9 columns">


                    </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 class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.geo_lat) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.geo_lat) }}
                    </div>
                </div>
                <div class="row">
                    <div class="large-3 large-text-right columns">
                        {{ form_label(form.geo_long) }}
                    </div>
                    <div class="large-9 columns">
                        {{ form_widget(form.geo_long) }}
                    </div>
                </div>
            </div>
            <div class="large-12 columns {{ action == 'u' ? 'hide' : '' }}" style="padding-top: 20px; padding-bottom: 20px;">
                <h5>Services</h5>
                {% if form.patientServices is not empty %}
                    {% for ps_form in form.patientServices %}
                        <div class="row">
                            <div class="large-1 large-text-right columns">
                                {{ form_widget(ps_form.is_checked) }}
                                {{ form_widget(ps_form.id) }}
                                {{ form_widget(ps_form.service) }}

                            </div>
                            <div class="large-11 columns">
                                {{ form_label(ps_form.is_checked) }}
                            </div>
                        </div>
                    {% endfor %}
                {% else %}
                    <li>No Services</li>
                {% endif %}
            </div>
            <div class="large-12 columns" style="padding-top: 20px;">
                <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="xxlarge-12 xlarge-12 large-12 medium-12 small-12 columns">
                        <label style="margin:10px;">Upload Photo</label>
                        <input style="margin:10px;" type="file" name="form[photo]" accept="image/*">
                    </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 Patient 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 %}
                    {% if fromDetail %}
                        <a href="{{ path('patient_detail', {patient_id: id}) }}" class="button secondary">Back</a>
                    {% else %}
                        <a href="{{ path('patient') }}" class="button secondary">Back</a>
                    {% endif %}
                </div>
            </div>
        </div>
        {{ form_widget(form.action) }}
        {{ form_widget(form.id) }}
        {{ form_widget(form._token) }}
    </form>
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script>
        //<![CDATA[
        patient_form.settings.account_autocomplete_url = '{{ path('account_autocomplete') }}';
        patient_form.settings.account_user_autocomplete_url = '{{ path('account_user_active_autocomplete') }}';
        patient_form.settings.city_autocomplete_url = '{{ path('city_autocomplete') }}';
        patient_form.settings.patient_type_autocomplete_url = '{{ path('patient_type_autocomplete') }}';
        patient_form.settings.postalCode_autocomplete_url = '{{ path('postal_code_autocomplete') }}';
        patient_form.settings.referring_health_facility_autocomplete_url = '{{ path('referring_health_facility_autocomplete') }}';
        patient_form.settings.referring_provider_autocomplete_url = '{{ path('referring_provider_autocomplete') }}';
        patient_form.settings.health_facility_autocomplete_url = '{{ path('health_facility_autocomplete') }}';
        patient_form.settings.primary_provider_autocomplete_url = '{{ path('provider_autocomplete') }}';
        patient_form.settings.patient_autocomplete_url = '{{ path('patient_autocomplete') }}';
        jQ(document).ready(function(){
            patient_form.init();
        });
        //]]>
    </script>
{% endblock %}