{% set userData = app.session.get('userData') %}
<style>
    #patientLetter_addCc_btn{
        cursor: pointer;
        color: gray;
    }
    .patientLetter_removeCc_btn{
        cursor: pointer;
        color: #cc4b37;
        float: right;
    }
</style>
<form method="POST" id="form-patientLetter" enctype="multipart/form-data">
    <h5>{{ page_title }}</h5>
    <div id="flash-messages-content-modal"></div>
    <div class="row max-width-initial">
        <div class="large-12 columns">
            <div class="row">
                <div class="large-12 columns">
                    <span style="font-weight: bold;">Recipient:</span>
                    <div class="row">
                        <div class="large-6 columns">
                            {{ form_label(form.affiliate_type) }}
                            {{ form_widget(form.affiliate_type) }}
                        </div>
                        <div class="large-6 columns">
                            <div id="affiliate-Referring-Provider" class="hide">
                                {{ form_label(form.patient_referring_provider_desc) }}
                                {{ form_widget(form.patient_referring_provider_desc) }}
                                {{ form_widget(form.patient_referring_provider) }}
                            </div>
                            <div id="affiliate-Referring-HealthFacility" class="hide">
                                {{ form_label(form.patient_referring_health_facility_desc) }}
                                {{ form_widget(form.patient_referring_health_facility_desc) }}
                                {{ form_widget(form.patient_referring_health_facility) }}
                            </div>
                            <div id="affiliate-Insurance" class="hide">
                                {{ form_label(form.patient_insurance_desc) }}
                                {{ form_widget(form.patient_insurance_desc) }}
                                {{ form_widget(form.patient_insurance) }}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="large-12 columns">
                    <span style="font-weight: bold;">CC: <span id="patientLetter_addCc_btn"><i class="fa fa-plus-circle"></i></span></span>
                    <div id="cc_container">
                        {% for pl_cc in form.patientLetterCcs %}
                            <div class="cc_row row" data-idx="{{ loop.index0 }}">
                                <div class="cc_col1 small-6 columns"  data-idx="{{ loop.index0 }}">
                                    <label for="patient_letter_cc_affiliate_type_{{ loop.index0 }}">Affiliate</label>
                                    <select name="patient_letter[patientLetterCcs][{{ loop.index0 }}][affiliate_type]" id="patient_letter_cc_affiliate_type_{{ loop.index0 }}" data-idx="{{ loop.index0 }}">
                                        <option value="Insurance" {{ pl_cc.vars.value.affiliateType == 'Insurance' ? 'selected' : '' }}>Insurance</option>
                                        <option value="Referring Provider" {{ pl_cc.vars.value.affiliateType == 'Referring Provider' ? 'selected' : '' }}>Referring Provider</option>
                                    </select>
                                </div>
                                <div class="cc_col2 small-6 columns"  data-idx="{{ loop.index0 }}">
                                   <span class="patientLetter_removeCc_btn" data-idx="{{ loop.index0 }}"><i class="fa fa-times-circle"></i></span> <label for="patientLetter_patientLetterCc_{{ loop.index0 }}_patient_insurance_desc" class="hidden-cc-{{ loop.index0 }} {{ pl_cc.vars.value.affiliateType == 'Insurance' ? '' : 'hide' }}" id="patientLetter_patientLetterCc_{{ loop.index0 }}_patient_insurance_label">Insurance</label>
                                    <input value="{{ pl_cc.vars.value.patientInsurance.insurance.description|default('') }}" type="text" name="patient_letter[patientLetterCcs][{{ loop.index0 }}][patient_insurance_desc]" id="patientLetter_patientLetterCc_{{ loop.index0 }}_patient_insurance_desc" class="patientLetter_patientLetterCc_patient_insurance_desc hidden-cc-{{ loop.index0 }} {{ pl_cc.vars.value.affiliateType == 'Insurance' ? '' : 'hide' }}">
                                    <input value="{{ pl_cc.vars.value.patientInsurance.id|default('') }}" type="hidden" name="patient_letter[patientLetterCcs][{{ loop.index0 }}][patient_insurance]" id="patientLetter_patientLetterCc_{{ loop.index0 }}_patient_insurance">

                                    <label for="patientLetter_patientLetterCc_{{ loop.index0 }}_patient_referring_provider_desc" class="{{ pl_cc.vars.value.affiliateType == 'Referring Provider' ? '' : 'hide' }} hidden-cc-{{ loop.index0 }}" id="patientLetter_patientLetterCc_{{ loop.index0 }}_patient_referring_provider_label">Referring Provider</label>
                                    <input value="{{ pl_cc.vars.value.patientReferringProvider.referringProvider.fullName|default('') }}" type="text" name="patient_letter[patientLetterCcs][{{ loop.index0 }}][patient_referring_provider_desc]" id="patientLetter_patientLetterCc_{{ loop.index0 }}_patient_referring_provider_desc" class="patientLetter_patientLetterCc_patient_referring_provider_desc hidden-cc-{{ loop.index0 }} {{ pl_cc.vars.value.affiliateType == 'Referring Provider' ? '' : 'hide' }}">
                                    <input value="{{ pl_cc.vars.value.patientReferringProvider.id|default('') }}" type="hidden" name="patient_letter[patientLetterCcs][{{ loop.index0 }}][patient_referring_provider]" id="patientLetter_patientLetterCc_{{ loop.index0 }}_patient_referring_provider">

                                    <input value="{{ pl_cc.vars.value.id }}" type="hidden" name="patient_letter[patientLetterCcs][{{ loop.index0 }}][id]" id="patientLetter_patientLetterCc_{{ loop.index0 }}_id">
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                </div>
                <div class="large-12 columns">
                    <label class="required" for="patient_letter_letter_type">Letter Type</label>
                    <select id="patient_letter_letter_type" name="patientLetterType[letter_type]">
                        <option value=""></option>
                        {% for lt in letterTypes %}
                            <option value="{{ lt.letter_type }}" {{ form.vars.value.letterType == lt.letter_type ? 'selected' : '' }}>{{ lt.letter_type }}</option>
                        {% endfor %}
                    </select>
                    {#{{ form_label(form.letter_type) }}#}
                    {#{{ form_widget(form.letter_type) }}#}
                </div>
                <div class="large-12 columns">
                    {{ form_label(form.accountUser_fullName) }}
                    {{ form_widget(form.accountUser_fullName) }}
                    {{ form_widget(form.accountUser) }}
                </div>
                <div class="large-12 columns {{ action != 'n' ? '' : 'hide' }}">
                    {{ form_label(form.patientLetterStatus) }}
                    {{ form_widget(form.patientLetterStatus) }}
                </div>
                <div class="large-12 columns">
                    {{ form_label(form.custom_body) }}
                    {{ form_widget(form.custom_body) }}
                </div>
                <div class="large-12 columns" style="margin-top: 5%">
                    {{ form_label(form.faxCoverSelection) }}
                    {{ form_widget(form.faxCoverSelection) }}
                </div>
                <div class="large-12 columns" >
                    {{ form_label(form.faxBranchSelection) }}
                    {{ form_widget(form.faxBranchSelection) }}
                </div>
                {% if action == 'u' %}
                    <div class="large-6 columns">
                        {{ form_label(form.attention) }}
                        {{ form_widget(form.attention) }}
                    </div>
                    <div class="large-6 columns">
                        {{ form_label(form.recipient) }}
                        {{ form_widget(form.recipient) }}
                    </div>
                    <div class="large-6 columns">
                        {{ form_label(form.date) }}
                        {{ form_widget(form.date) }}
                    </div>
                    <div class="large-6 columns">
                        {{ form_label(form.phone_no) }}
                        {{ form_widget(form.phone_no) }}
                    </div>
                    <div class="large-6 columns">
                        {{ form_label(form.fax_no) }}
                        {{ form_widget(form.fax_no) }}
                    </div>
                    <div class="large-6 columns">
                        {{ form_label(form.name) }}
                        {{ form_widget(form.name) }}
                    </div>
                    <div class="large-6 columns">
                        <i class="fa fa-info-circle" style="float: left;padding-right: 5px;margin-top: 3px;cursor: help" title="Please enter the correct page count here if the system's Page Count didn't match the correct pages of the letter"></i>
                        {{ form_label(form.page) }}
                        {{ form_widget(form.page) }}
                    </div>
                    <div class="large-6 columns">
                        {#{{ form_label(form.carbon_copy) }}#}
                        {#{{ form_widget(form.carbon_copy) }}#}
                    </div>
                {% endif %}
                    <div class="large-12 columns" id="faxCoverCustomBody">
                        {{ form_label(form.fax_cover_custom_body) }}
                        {{ form_widget(form.fax_cover_custom_body) }}
                    </div>
                {#<div class="large-12 columns" style="margin-top: 2%">#}
                    {#<input style="margin:10px;" type="file" class="pdfOnly" name="form[file1]" accept="application/pdf">#}
                    {#<input style="margin:10px;" type="file" class="pdfOnly" name="form[file2]" accept="application/pdf">#}
                {#</div>#}
                <div class="large-12 columns prescriptionForm {{ patientLetter.letterType != 'Prescription' ? 'hide' : '' }}" style="margin-top: 10px;">
                    <h5>Prescription Form</h5>
                    <div class="large-6 columns">
                        <label for="date_of_study">Date of Study:</label>
                        <input type="text" id="date_of_study" class="date" name="prescription[dateOfStudy]" value="{{ patientLetterPrescription.dateOfStudyAsString|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="interpretation_completed_doctor">Interpretation Completed by Dr.</label>
                        <input type="text" id="interpretation_completed_doctor" name="prescription[interpretationCompletedDoctor]" value="{{ patientLetterPrescription.interpretationCompletedDoctor|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="finding_consistent">Findings Consistent With</label>
                        <input type="text" id="finding_consistent" name="prescription[findingConsistent]" value="{{ patientLetterPrescription.findingConsistent|default('') }}">
                    </div>
                    <div class="large-12 columns">
                        <span>Recommentation</span>
                        <textarea name="prescription[recommendation]" id="patient_prescription_recommendation_textarea" maxlength="2000">{{ patientLetterPrescription.recommendation|default('') }}</textarea>
                    </div>
                    <div class="large-6 columns">
                        <label for="ahi">AHI</label>
                        <input type="text" id="ahi" name="prescription[ahi]" value="{{ patientLetterPrescription.ahi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="rdi">RDI</label>
                        <input type="text" id="rdi" name="prescription[rdi]" value="{{ patientLetterPrescription.rdi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_theraphy">CPAP Therapy</label>
                        <input type="checkbox" id="is_cpap_theraphy" name="prescription[isCpapTheraphy]" {{ patientLetterPrescription.isCpapTheraphy|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_one">CPAP Therapy Value From</label>
                        <input type="text" id="is_cpap_therapy_value_one" name="prescription[cpap_therapy_value_one]" value="{{ patientLetterPrescription.cpapTheraphyOne|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_two">CPAP Therapy Value To</label>
                        <input type="text" id="is_cpap_therapy_value_two" name="prescription[cpap_therapy_value_two]" value="{{ patientLetterPrescription.cpapTheraphyTwo|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_three">CPAP Therapy Value 3</label>
                        <input type="text" id="is_cpap_therapy_value_three" name="prescription[cpap_therapy_value_three]" value="{{ patientLetterPrescription.cpapTheraphyThree|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_level_one_psg">Referral to Sleep Specialist / Level 1 PSG</label>
                        <input type="checkbox" id="is_level_one_psg" name="prescription[isLevelOnePsg]" {{ patientLetterPrescription.isReferralToSleepSpecialist|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns">
                        <label for="is_oral_appliance">Oral Appliance</label>
                        <input type="checkbox" id="is_oral_appliance" name="prescription[isOralAppliance]" {{ patientLetterPrescription.isOralAppliance|default('') == true ? 'checked' : '' }}>
                    </div>
                </div>
                <div class="large-12 columns generalPrescriptionFrsi {{ patientLetter.letterType != 'General Prescription (FRSC)' ? 'hide' : '' }}" style="margin-top: 10px;">
                    <h5>General Prescription Form (FRSC)</h5>
                    <div class="large-6 columns">
                        <label for="gp_date_of_study">Date of Study:</label>
                        <input type="text" id="gp_date_of_study" class="date" name="generalPrescriptionFrsi[dateOfStudy]" value="{{ generalPrescriptionFrsi.dateOfStudyAsString|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="gp_interpretation_completed_doctor">Interpretation Completed by Dr.</label>
                        <input type="text" id="gp_interpretation_completed_doctor" name="generalPrescriptionFrsi[interpretationCompletedDoctor]" value="{{ generalPrescriptionFrsi.interpretationCompletedDoctor|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="finding_consistent">Findings Consistent With</label>
                        <input type="text" id="finding_consistent" name="generalPrescriptionFrsi[findingConsistent]" value="{{ generalPrescriptionFrsi.findingConsistent|default('') }}">
                    </div>
                    <div class="large-12 columns">
                        <span>Recommendation</span>
                        <textarea name="generalPrescriptionFrsi[recommendation]" id="patient_general_prescription_frsi_recommendation_textarea" maxlength="2000">{{ generalPrescriptionFrsi.recommendation|default('') }}</textarea>
                    </div>
                    <div class="large-6 columns">
                        <label for="ahi">AHI</label>
                        <input type="text" id="ahi" name="generalPrescriptionFrsi[ahi]" value="{{ generalPrescriptionFrsi.ahi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="rdi">RDI</label>
                        <input type="text" id="rdi" name="generalPrescriptionFrsi[rdi]" value="{{ generalPrescriptionFrsi.rdi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_theraphy">CPAP Therapy</label>
                        <input type="checkbox" id="is_cpap_theraphy" name="generalPrescriptionFrsi[isCpapTheraphy]" {{ generalPrescriptionFrsi.isCpapTheraphy|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_one">CPAP Therapy Value From</label>
                        <input type="text" id="is_cpap_therapy_value_one" name="generalPrescriptionFrsi[cpap_therapy_value_one]" value="{{ generalPrescriptionFrsi.cpapTheraphyOne|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_two">CPAP Therapy Value To</label>
                        <input type="text" id="is_cpap_therapy_value_two" name="generalPrescriptionFrsi[cpap_therapy_value_two]" value="{{ generalPrescriptionFrsi.cpapTheraphyTwo|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_three">CPAP Therapy Value 3</label>
                        <input type="text" id="is_cpap_therapy_value_three" name="generalPrescriptionFrsi[cpap_therapy_value_three]" value="{{ generalPrescriptionFrsi.cpapTheraphyThree|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_level_one_psg">Referral to Sleep Specialist / Level 1 PSG</label>
                        <input type="checkbox" id="is_level_one_psg" name="generalPrescriptionFrsi[isLevelOnePsg]" {{ generalPrescriptionFrsi.isReferralToSleepSpecialist|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns">
                        <label for="is_oral_appliance">Oral Appliance</label>
                        <input type="checkbox" id="is_oral_appliance" name="generalPrescriptionFrsi[isOralAppliance]" {{ generalPrescriptionFrsi.isOralAppliance|default('') == true ? 'checked' : '' }}>
                    </div>
                </div>
                <div class="large-12 columns prescriptionFrsiForm {{ patientLetter.letterType != 'Prescription (FRSC)' ? 'hide' : '' }}" style="margin-top: 10px;">
                    <h5>Prescription (FRSC) Form</h5>
                    <div class="large-6 columns">
                        <label for="interpretation_completed_doctor">Interpreting Doctor</label>
                        <input type="text" id="frsi_interpretation_completed_doctor" name="prescription_frsi[interpretationCompletedDoctor]" value="{{ patientLetterPrescriptionFrsi.interpretationCompletedDoctor|default('') }}">
                    </div>
                    <div class="large-12 columns">
                        <span>Recommendation</span>
                        <textarea name="prescription_frsi[recommendation]" id="patient_prescription_frsi_recommendation_textarea" maxlength="2000">{{ patientLetterPrescriptionFrsi.recommendation|default('')|raw }}</textarea>
                    </div>
                    <div class="large-6 columns">
                        <label for="date">Date</label>
                        <input type="text" id="frsi_date" class="date" name="prescription_frsi[date]" value="{{ patientLetterPrescriptionFrsi.date|default('')|date('m/d/Y') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="diagnosis">Diagnosis</label>
                        <input type="text" id="frsi_diagnosis" name="prescription_frsi[diagnosis]" value="{{ patientLetterPrescriptionFrsi.diagnosis|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="ahi">AHI</label>
                        <input type="text" id="frsi_ahi" name="prescription_frsi[ahi]" value="{{ patientLetterPrescriptionFrsi.ahi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="rdi">RDI</label>
                        <input type="text" id="frsi_rdi" name="prescription_frsi[rdi]" value="{{ patientLetterPrescriptionFrsi.rdi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_theraphy">CPAP Therapy</label>
                        <input type="checkbox" id="frsi_is_cpap_theraphy" name="prescription_frsi[isCpapTheraphy]" {{ patientLetterPrescriptionFrsi.isCpapTheraphy|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_one">CPAP Therapy Value (Auto) From</label>
                        <input type="text" id="frsi_is_cpap_therapy_value_one" name="prescription_frsi[cpap_therapy_value_one]" value="{{ patientLetterPrescriptionFrsi.cpapTheraphyOne|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_two">CPAP Therapy Value (Auto) To</label>
                        <input type="text" id="frsi_is_cpap_therapy_value_two" name="prescription_frsi[cpap_therapy_value_two]" value="{{ patientLetterPrescriptionFrsi.cpapTheraphyTwo|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_three">CPAP Therapy Value (Fixed)</label>
                        <input type="text" id="frsi_is_cpap_therapy_value_three" name="prescription_frsi[cpap_therapy_value_three]" value="{{ patientLetterPrescriptionFrsi.cpapTheraphyThree|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_level_one_psg">Referral to Sleep Doctor</label>
                        <input type="checkbox" id="frsi_frsi_is_level_one_psg" name="prescription_frsi[isLevelOnePsg]" {{ patientLetterPrescriptionFrsi.isReferralToSleepSpecialist|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns">
                        <label for="is_oral_appliance">Oral Appliance</label>
                        <input type="checkbox" id="frsi_is_oral_appliance" name="prescription_frsi[isOralAppliance]" {{ patientLetterPrescriptionFrsi.isOralAppliance|default('') == true ? 'checked' : '' }}>
                    </div>
                </div>
                <div class="large-12 columns prescriptionFrsiV2Form {{ patientLetter.letterType != 'Prescription (FRSC) v2' ? 'hide' : '' }}" style="margin-top: 10px;">
                    <h5>Prescription (FRSC) V2 Form</h5>
                    <div class="large-6 columns">
                        <label for="interpretation_completed_doctor">Interpreting Doctor</label>
                        <input type="text" id="frsi_interpretation_completed_doctor" name="prescription_frsi_v2[interpretationCompletedDoctor]" value="{{ patientLetterPrescriptionFrsiV2.interpretingPhysician|default('') }}">
                    </div>
                    <div class="large-12 columns">
                        <span>Recommendation</span>
                        <textarea name="prescription_frsi_v2[recommendation]" id="patient_prescription_frsi_v2_recommendation_textarea" maxlength="2000">{{ patientLetterPrescriptionFrsiV2.recommendation|default('')|raw }}</textarea>
                    </div>
                    <div class="large-6 columns">
                        <label for="frsi_v2_date">Date</label>
                        <input type="text" id="frsi_v2_date" class="date" name="prescription_frsi_v2[date]" value="{{ patientLetterPrescriptionFrsiV2.date|default('')|date('m/d/Y') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="osa">OSA</label>
                        <input type="text" id="frsi_osa" name="prescription_frsi_v2[osa]" value="{{ patientLetterPrescriptionFrsiV2.osa|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="ahi">AHI</label>
                        <input type="text" id="frsi_ahi" name="prescription_frsi_v2[ahi]" value="{{ patientLetterPrescriptionFrsiV2.ahi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="rdi">RDI</label>
                        <input type="text" id="frsi_rdi" name="prescription_frsi_v2[rdi]" value="{{ patientLetterPrescriptionFrsiV2.rdi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_one">CPAP Therapy Value (Auto) From</label>
                        <input type="text" id="frsi_is_cpap_therapy_value_one" name="prescription_frsi_v2[cpap_therapy_value_one]" value="{{ patientLetterPrescriptionFrsiV2.cpapTheraphyOne|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_two">CPAP Therapy Value (Auto) To</label>
                        <input type="text" id="frsi_is_cpap_therapy_value_two" name="prescription_frsi_v2[cpap_therapy_value_two]" value="{{ patientLetterPrescriptionFrsiV2.cpapTheraphyTwo|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_three">CPAP Therapy Value (Fixed)</label>
                        <input type="text" id="frsi_is_cpap_therapy_value_three" name="prescription_frsi_v2[cpap_therapy_value_three]" value="{{ patientLetterPrescriptionFrsiV2.cpapTheraphyThree|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_level_one_psg">Referral to Sleep Specialist</label>
                        <input type="checkbox" id="frsi_frsi_is_level_one_psg" name="prescription_frsi_v2[referralToSleepSpecialist]" {{ patientLetterPrescriptionFrsiV2.isReferralToSleepSpecialist|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns"></div>
                </div>
                <div class="large-12 columns aliceNightOneForm {{ patientLetter.letterType != 'Alice Night One (FRSC)' ? 'hide' : '' }}" style="margin-top: 10px;">
                    <h5>Alice Night One (FRSC) Form</h5>
                    <div class="large-6 columns">
                        <label for="interpretation_completed_doctor">Interpreting Doctor</label>
                        <input type="text" id="frsi_interpretation_completed_doctor" name="alice_night_one[interpretationCompletedDoctor]" value="{{ patientLetterAliceNightOne.interpretingPhysician|default('') }}">
                    </div>
                    <div class="large-12 columns">
                        <span>Recommendation</span>
                        <textarea name="alice_night_one[recommendation]" id="alice_night_one_recommendation_textarea" maxlength="2000">{{ patientLetterAliceNightOne.recommendation|default('')|raw }}</textarea>
                    </div>
                    <div class="large-6 columns">
                        <label for="frsi_v2_date">Date</label>
                        <input type="text" id="frsi_v2_date" class="date" name="alice_night_one[date]" value="{{ patientLetterAliceNightOne.date|default('')|date('m/d/Y') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="osa">OSA</label>
                        <input type="text" id="frsi_osa" name="alice_night_one[osa]" value="{{ patientLetterAliceNightOne.osa|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="ahi">AHI</label>
                        <input type="text" id="frsi_ahi" name="alice_night_one[ahi]" value="{{ patientLetterAliceNightOne.ahi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_one">CPAP Therapy Value (Auto) From</label>
                        <input type="text" id="frsi_is_cpap_therapy_value_one" name="alice_night_one[cpap_therapy_value_one]" value="{{ patientLetterAliceNightOne.cpapTheraphyOne|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_two">CPAP Therapy Value (Auto) To</label>
                        <input type="text" id="frsi_is_cpap_therapy_value_two" name="alice_night_one[cpap_therapy_value_two]" value="{{ patientLetterAliceNightOne.cpapTheraphyTwo|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_three">CPAP Therapy Value (Fixed)</label>
                        <input type="text" id="frsi_is_cpap_therapy_value_three" name="alice_night_one[cpap_therapy_value_three]" value="{{ patientLetterAliceNightOne.cpapTheraphyThree|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_level_one_psg">Referral to Sleep Specialist</label>
                        <input type="checkbox" id="frsi_frsi_is_level_one_psg" name="alice_night_one[referralToSleepSpecialist]" {{ patientLetterAliceNightOne.isReferralToSleepSpecialist|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns"></div>
                </div>
                <div class="large-12 columns prescriptionPssForm {{ patientLetter.letterType != 'Prescription (PSS)' ? 'hide' : '' }}" style="margin-top: 10px;">
                    <h5>Prescription (PSS) Form</h5>
                    <div class="large-6 columns">
                        <label for="interpretation_completed_doctor">Interpreting Doctor</label>
                        <input type="text" id="pss_interpretation_completed_doctor" name="prescription_pss[interpretationCompletedDoctor]" value="{{ patientLetterPrescriptionPss.interpretationCompletedDoctor|default('') }}">
                    </div>
                    <div class="large-12 columns">
                        <span>Recommendation</span>
                        <textarea name="prescription_pss[recommendation]" id="patient_prescription_pss_recommendation_textarea" maxlength="2000">{{ patientLetterPrescriptionPss.recommendation|default('')|raw }}</textarea>
                    </div>
                    <div class="large-6 columns">
                        <label for="date">Date</label>
                        <input type="text" id="pss_date" class="date" name="prescription_pss[date]" value="{{ patientLetterPrescriptionPss.date|default('')|date('m/d/Y') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="diagnosis">Diagnosis</label>
                        <input type="text" id="pss_diagnosis" name="prescription_pss[diagnosis]" value="{{ patientLetterPrescriptionPss.diagnosis|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="ahi">AHI</label>
                        <input type="text" id="pss_ahi" name="prescription_pss[ahi]" value="{{ patientLetterPrescriptionPss.ahi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="rdi">RDI</label>
                        <input type="text" id="pss_rdi" name="prescription_pss[rdi]" value="{{ patientLetterPrescriptionPss.rdi|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_theraphy">CPAP Therapy</label>
                        <input type="checkbox" id="pss_is_cpap_theraphy" name="prescription_pss[isCpapTheraphy]" {{ patientLetterPrescriptionPss.isCpapTheraphy|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_one">CPAP Therapy Value (Auto) From</label>
                        <input type="text" id="pss_is_cpap_therapy_value_one" name="prescription_pss[cpap_therapy_value_one]" value="{{ patientLetterPrescriptionPss.cpapTheraphyOne|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_two">CPAP Therapy Value (Auto) To</label>
                        <input type="text" id="pss_is_cpap_therapy_value_two" name="prescription_pss[cpap_therapy_value_two]" value="{{ patientLetterPrescriptionPss.cpapTheraphyTwo|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_cpap_therapy_value_three">CPAP Therapy Value (Fixed)</label>
                        <input type="text" id="pss_is_cpap_therapy_value_three" name="prescription_pss[cpap_therapy_value_three]" value="{{ patientLetterPrescriptionPss.cpapTheraphyThree|default('') }}">
                    </div>
                    <div class="large-6 columns">
                        <label for="is_level_one_psg">Referral to Sleep Doctor</label>
                        <input type="checkbox" id="pss_is_level_one_psg" name="prescription_pss[isLevelOnePsg]" {{ patientLetterPrescriptionPss.isReferralToSleepSpecialist|default('') == true ? 'checked' : '' }}>
                    </div>
                    <div class="large-6 columns">
                        <label for="is_oral_appliance">Oral Appliance</label>
                        <input type="checkbox" id="pss_is_oral_appliance" name="prescription_pss[isOralAppliance]" {{ patientLetterPrescriptionPss.isOralAppliance|default('') == true ? 'checked' : '' }}>
                    </div>
                </div>
                <div class="large-12 columns specialistReferralForm {{ patientLetter.letterType != 'Specialist Referral' ? 'hide' : '' }}" style="margin-top: 10px;">
                    <h5>Specialist Referral Form</h5>
                    <div class="large-12 columns">
                        <div class="large-6 columns">
                            <label for="tel_no">Tel. no.</label>
                            <input type="text" id="tel_no" class="" name="specialistReferral[contactNo]" value="{{ patientLetterSpecialistReferral.contactNo|default('') }}">
                        </div>
                        <div class="large-6 columns">
                            <label for="is_assessment">Assessment</label>
                            <input type="checkbox" id="is_assessment" class="" name="specialistReferral[isAssessment]" {{ patientLetterSpecialistReferral.isAssessment|default('') == true ? 'checked' : '' }}>
                        </div>
                    </div>
                    <div class="large-12 columns">
                        <div class="large-6 columns">
                            <label for="is_result">Result</label>
                            <input type="checkbox" id="is_result" class="" name="specialistReferral[isResult]" {{ patientLetterSpecialistReferral.isResult|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div class="large-6 columns">
                            <label for="is_recommendation">Recommendation</label>
                            <input type="checkbox" id="is_recommendation" class="" name="specialistReferral[isRecommendation]" {{ patientLetterSpecialistReferral.isRecommendation|default('') == true ? 'checked' : '' }}>
                        </div>
                    </div>
                    <div class="large-12 columns">
                        <div class="large-6 columns">
                            <label for="is_hsat_completed">HSAT Completed</label>
                            <input type="checkbox" id="is_hsat_completed" class="" name="specialistReferral[isHsatCompleted]" {{ patientLetterSpecialistReferral.isHsatCompleted|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div class="large-6 columns">
                            <label for="hsat_completed_date">HSAT Completed Date</label>
                            <input type="text" id="hsat_completed_date" class="date" name="specialistReferral[hsatCompletedDate]" value="{{  patientLetterSpecialistReferral.hsatCompletedDateAsString|default('') }}">
                        </div>
                    </div>
                    <div class="large-12 columns">
                        <div class="large-6 columns">
                            <label for="is_level_one_psg_completed">Level 1 PSG Completed</label>
                            <input type="checkbox" id="is_level_one_psg_completed" class="" name="specialistReferral[isLevelOnePsgCompleted]" {{ patientLetterSpecialistReferral.isLevelOnePsgCompleted|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div class="large-12 columns">
                            <span>Notes</span>
                            <textarea id="patient_specialist_referral_note_textarea" name="specialistReferral[note]">{{ patientLetterSpecialistReferral.note|default('') }}</textarea>
                        </div>
                    </div>
                    <h6>Reason for Referral to Specialist:</h6>
                    <div class="large-6 columns">
                        <div>
                            <label for="is_osa">Severe Obstructive Sleep Apnea (OSA)</label>
                            <input type="checkbox" id="is_osa" class="" name="specialistReferral[isOsa]" value="" {{ patientLetterSpecialistReferral.isOsa|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_refused_cpap">Intolerance / Failed / Refused CPAP</label>
                            <input type="checkbox" id="is_refused_cpap" class="" name="specialistReferral[is_refused_cpap]" {{ patientLetterSpecialistReferral.isRefusedCpap|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_mild_osa">Mild OSA, unable to explain symptoms</label>
                            <input type="checkbox" id="is_mild_osa" class="" name="specialistReferral[is_mild_osa]" {{ patientLetterSpecialistReferral.isMildOsa|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_normal_hsat">Normal HSAT with Signifcant Symptoms / Snoring</label>
                            <input type="checkbox" id="is_normal_hsat" class="" name="specialistReferral[is_normal_hsat]" {{ patientLetterSpecialistReferral.isNormalHsat|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_reassess">Reassess indication for Study</label>
                            <input type="checkbox" id="is_reassess" class="" name="specialistReferral[is_reassess]" {{ patientLetterSpecialistReferral.isReassess|default('') == true ? 'checked' : '' }}>
                        </div>
                    </div>
                    <div class="large-6 columns">
                        <div>
                            <label for="is_complex_sleep">Complex sleep patient</label>
                            <input type="checkbox" id="is_complex_sleep" class="" name="specialistReferral[is_complex_sleep]" {{ patientLetterSpecialistReferral.isComplexSleep|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_complex_titration">Complex Titration (High Pressure)</label>
                            <input type="checkbox" id="is_complex_titration" class="" name="specialistReferral[is_complex_titration]" {{ patientLetterSpecialistReferral.isComplexTitration|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_increase_bm_chf_ocpd">High Risk Patient with an increased BMI, CHF, COPD</label>
                            <input type="checkbox" id="is_increase_bm_chf_ocpd" class="" name="specialistReferral[is_increase_bm_chf_ocpd]" {{ patientLetterSpecialistReferral.isIncreaseBmChfOcpd|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_non_respiratory_sleep_disorder">High Probability of Non-Respiratory Sleep Disorder</label>
                            <input type="checkbox" id="is_non_respiratory_sleep_disorder" class="" name="specialistReferral[is_non_respiratory_sleep_disorder]" {{ patientLetterSpecialistReferral.isNonRespiratorySleepDisorder|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_requesting_oral_appliance">Patient requesting oral appliance</label>
                            <input type="checkbox" id="is_requesting_oral_appliance" class="" name="specialistReferral[is_requesting_oral_appliance]" {{ patientLetterSpecialistReferral.isRequestingOralAppliance|default('') == true ? 'checked' : '' }}>
                        </div>
                    </div>
                    <h6>Recommended Specialist/Testing:</h6>
                    <div class="large-6 columns">
                        <div>
                            <label for="is_sleep_physician">Sleep Physician</label>
                            <input type="checkbox" id="is_sleep_physician" class="" name="specialistReferral[is_sleep_physician]" {{ patientLetterSpecialistReferral.isSleepPhysician|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_respirologist">Respirologist</label>
                            <input type="checkbox" id="is_respirologist" class="" name="specialistReferral[is_respirologist]" {{ patientLetterSpecialistReferral.isRespirologist|default('') == true ? 'checked' : '' }}>
                        </div>
                    </div>
                    <div class="large-6 columns">
                        <div>
                            <label for="is_internal_medicine">Internal Medicine (Diabetes, Obesity, Thyroid) Edmonton only</label>
                            <input type="checkbox" id="is_internal_medicine" class="" name="specialistReferral[is_internal_medicine]" {{ patientLetterSpecialistReferral.isInternalMedicine|default('') == true ? 'checked' : '' }}>
                        </div>
                        <div>
                            <label for="is_dental_consultation">Dental Consultation</label>
                            <input type="checkbox" id="is_dental_consultation" class="" name="specialistReferral[is_dental_consultation]" {{ patientLetterSpecialistReferral.isDentalConsultation|default('') == true ? 'checked' : '' }}>
                        </div>
                    </div>
                    <div class="large-12 columns">
                        <span>Comment</span>
                        <textarea name="specialistReferral[comment]">{{ patientLetterSpecialistReferral.comment|default('') }}</textarea>
                    </div>
                </div>
                <div class="large-12 columns refusalCareForm {{ patientLetter.letterType != 'Refusal of Care Against Medical Advice (FRSC)' ? 'hide' : '' }}" style="margin-top: 10px;">
                    <h5>Refusal of Care Against Medical Advice (FRSC) Form</h5>
                    <div class="row">
                        <div class="large-6 columns">
                            <label for="patient_statement_name">Patient Statement Name</label>
                            <input type="text" id="patient_statement_name" class="" name="refusalCare[patientStatementName]" value="{{ patientLetterRefusalCare.name|default('') }}">
                        </div>
                        <div class="large-6 columns">
                            <label for="patient_statement_date">Patient Statement Date</label>
                            <input type="text" id="patient_statement_date" class="date" name="refusalCare[patientStatementDate]" value="{{ patientLetterRefusalCare.patientStatementAsString|default('') }}">
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-12 columns">
                            <span>Patient Statement</span>
                            <textarea name="refusalCare[patientStatement]" id="patient_statement_textarea" maxlength="2000">{{ patientLetterRefusalCare.patientStatement|default('')|raw }}</textarea>
                        </div>
                    </div>
                    <div class="row">
                        <div class="large-6 columns">
                            <label for="witness_info_name">Witness Info Name</label>
                            <input type="text" id="witness_info_name" class="" name="refusalCare[witnessInfoName]" value="{{ patientLetterRefusalCare.witnessInfoName|default('') }}">
                        </div>
                        <div class="large-6 columns">
                            <label for="witness_info_date">Witness Info Date</label>
                            <input type="text" id="witness_info_date" class="date" name="refusalCare[witnessInfoDate]" value="{{ patientLetterRefusalCare.getWitnessInfoDateAsString|default('') }}">
                        </div>
                    </div>
                </div>
                <div class="large-12 columns" style="margin-top: 2%">
                    <h5>Attachments(s) <a href="javascript:void(0)" id="href-new-file-field"><i class="fa fa-plus"></i></a></h5>
                    <p class="form-hint-text">Upload file(s) below</p>
                    <div id="file-field-container">
                        {% if patientLetter %}
                            {% for key,plf in patientLetter.patientLetterFiles %}
                                {% if plf.isDeleted != true %}
                                    <div class="input-group no-margin-bottom">
                                        <input type="hidden" name="otherForm[files][{{ key }}]" value="{{ plf.idencoded }}" />
                                        <a href="{{ path('patient_letter_file_download', {id: plf.idencoded}) }}">{{ plf.filedesc }}</a>
                                        <div class="input-group-button">
                                            <button type="button" class="button secondary file-field-remove"><i class="fa fa-remove"></i></button>
                                        </div>
                                    </div>
                                {% endif %}
                            {% endfor %}
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>
    <hr>
    <div class="row-max-width-initial">
        <div class="small-12 columns no-padding-right">
            <div class="button-container clearfix text-right">
                {#{% if action == 'n' and (userData.type == 'Super Admin' or 'Admin Patient Letter New' in userData.accesses) %}#}
                    <a href="javascript:void(0)" class="button just-continue href-patient-letter-action float-right" data-axn="{{ action }}"
                       data-message="Are you sure you want to save this information?"
                       style="margin-left: 10px; margin-right: 0;"
                    >Save</a>
                {#{% endif %}#}
                {% if action == 'u' and (userData.type == 'Super Admin' or 'Admin Patient Letter Delete' in userData.accesses) %}
                    <a href="javascript:void(0)" class="ask-continue button alert href-patient-letter-action float-right" data-axn="d"
                       data-message="Are you sure you want to delete this record?"
                       style="margin-left: 10px; margin-right: 0;"
                    >Delete</a>
                {% endif %}
                <a href="javascript:void(0)" class="button secondary" data-close style="margin-left: 10px; margin-right: 0;">Close</a>
            </div>
        </div>
    </div>
    {{ form_widget(form.action) }}
    {{ form_widget(form.id) }}
    {{ form_widget(form.patient) }}
    {{ form_widget(form._token) }}
</form>
<script language="javascript">
    //<![CDATA[

    jQ('.pdfOnly').on('change', function() {
        var value = jQ(this).val(),
            file = value.toLowerCase(),
            extension = file.substring(file.lastIndexOf('.') + 1);

        if (jQ.inArray(extension, ['pdf','PDF']) == -1) {
            jQ(this).focus().val('');
            alert('WARNING: Only PDF file is allowed.');
        }

    });

    jQ(document).ready(function(){
        let patient_letter_form = {
            settings: {},
            init: function() {
                patient_letter_form.bindElements();
                patient_letter_form.fileField_arrangeIndexes();
                patient_letter_form.fileField_bindRemove();
            },
            bindElements: function() {
                jQ('#href-new-file-field').unbind('click').bind('click', this.newFileField);
            },
            newFileField: function() {
                var div_ig = jQ('<div/>'),
                    div_igb = jQ('<div/>'),
                    btn = jQ('<button/>'),
                    input_file = jQ('<input/>');

                div_ig.addClass('input-group').addClass('no-margin-bottom');
                div_igb.addClass('input-group-button');
                btn.attr('type', 'button').addClass('button secondary').addClass('file-field-remove').html('<i class="fa fa-remove"></i>');
                input_file.attr({
                    type:'file',
                    accept : 'application/pdf'
                }).addClass('input-group-field');

                div_igb.append(btn);
                div_ig.append(input_file).append(div_igb);

                jQ('#file-field-container').append(div_ig);

                patient_letter_form.fileField_arrangeIndexes();
                patient_letter_form.fileField_bindRemove();
            },
            fileField_arrangeIndexes: function() {
                jQ('#file-field-container .input-group').each(function(key){
                    jQ(this).attr('id', 'file-field-input-group-' + key).data('key', key);
                    jQ(this).find('input[type=file]').attr('name', 'files[' + key + ']');
                    jQ(this).find('button').data('key', key);
                });
            },
            fileField_bindRemove: function() {
                jQ('.file-field-remove').unbind('click').bind('click', function(){
                    jQ('#file-field-input-group-' + jQ(this).data('key')).remove();
                    patient_letter_form.fileField_arrangeIndexes();
                });
            },
        };

        patient_letter_form.init();

    });


    //]]>
</script>