{% set absUrl = app.request.getSchemeAndHttpHost() ~ app.request.baseUrl|replace({'/app_dev.php': ''}) %}
{% set customBody = patientLetter.customBody|replace({'{{PATIENT-FIRSTNAME}}' :  patientLetter.patient.firstName, '{{PATIENT-FULLNAME}}' : patientLetter.patient.fullName, '{{PATIENT-GENDER}}' : patientLetter.patient.gender == 'Male' ? 'he' : 'she', '{{PATIENT-GENDER2}}' : patientLetter.patient.gender == 'Male' ? 'him' : 'her', '{{PATIENT-GENDER3}}' : patientLetter.patient.gender == 'Male' ? 'his' : 'her', '{{PATIENT-GENDER4}}' : patientLetter.patient.gender == 'Male' ? 'He' : 'She'}) %}
{% set userData = app.session.get('userData') %}
<!DOCTYPE html>
<html class="no-js" lang="en" dir="ltr">
<head>
	<meta charset="utf-8">
	<meta http-equiv="x-ua-compatible" content="ie=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>DSRC Letter</title>
</head>
<body style="font-family:'Arial'; font-size:18px;">
{% set receiverPhone = '' %}
{% set receiverFax = '' %}
{% if patientLetter.patientReferringProvider %}
    {% set rp = patientLetter.patientReferringProvider.referringProvider %}
    {% set patient = patientLetter.patient %}
    {% set receiverFullName = patientLetter.patientReferringProvider.referringProvider.honorific ~ ' ' ~ patientLetter.patientReferringProvider.referringProvider.fullName|title %}
    {% if patientLetter.patientReferringProvider.referringProvider.phoneNo is null or patientLetter.patientReferringProvider.referringProvider.phoneNo == '' %}

        {% for prhf in patient.patientReferringHealthFacilities %}
            {% for rhfp in rp.referringHealthFacilityProviders %}
                {% if prhf.referringHealthFacility.id == rhfp.referringHealthFacility.id %}
                    {% set receiverPhone = prhf.referringHealthFacility.phoneNo %}
                {% endif %}
            {% endfor %}
        {% endfor %}
    {% else %}
        {% set receiverPhone = patientLetter.patientReferringProvider.referringProvider.phoneNo %}
    {% endif %}
    {% if patientLetter.patientReferringProvider.referringProvider.faxNo is null or patientLetter.patientReferringProvider.referringProvider.faxNo == '' %}

        {% for prhf in patient.patientReferringHealthFacilities %}
            {% for rhfp in rp.referringHealthFacilityProviders %}
                {% if prhf.referringHealthFacility.id == rhfp.referringHealthFacility.id %}
                    {% set receiverFax = prhf.referringHealthFacility.faxNo %}
                {% endif %}
            {% endfor %}
        {% endfor %}
    {% else %}
        {% set receiverFax = patientLetter.patientReferringProvider.referringProvider.faxNo %}
    {% endif %}
{% endif %}
{% if patientLetter.patientReferringHealthFacility %}
    {% set receiverFullName = patientLetter.patientReferringHealthFacility.referringHealthFacility.description %}
    {% set receiverPhone = patientLetter.patientReferringHealthFacility.referringHealthFacility.phoneNo is null ? patientLetter.patientReferringHealthFacility.referringHealthFacility.phoneNoTwo : patientLetter.patientReferringHealthFacility.referringHealthFacility.phoneNo %}
    {% set receiverFax = patientLetter.patientReferringHealthFacility.referringHealthFacility.faxNo is null ? patientLetter.patientReferringHealthFacility.referringHealthFacility.faxNoTwo : patientLetter.patientReferringHealthFacility.referringHealthFacility.faxNo %}
{% endif %}
{% if patientLetter.patientInsurance %}
    {% set receiverFullName = patientLetter.patientInsurance.insurance.description %}
    {% set receiverPhone = patientLetter.patientInsurance.insurance.phoneNo is null ? patientLetter.patientInsurance.insurance.phoneNoTwo : patientLetter.patientInsurance.insurance.phoneNo %}
    {% set receiverFax = patientLetter.patientInsurance.insurance.faxNo is null ? patientLetter.patientInsurance.insurance.faxNoTwo : patientLetter.patientInsurance.insurance.faxNo %}
{% endif %}
{% set patientFullName = patientLetter.patient.fullName %}
{% set patientFirstName = patientLetter.patient.firstName %}
{% set patientLastName = patientLetter.patient.lastName %}
{% set patientTelNo = patientLetter.patient.phoneNo %}
{% set patient = patientLetter.patient %}

{% set faxCoverCustomBody = patientLetter.faxCoverCustomBody|replace({'{{RECEVIER-FULLNAME}}' :  receiverFullName, '{{PATIENT-FULLNAME}}' : patientFullName, '{{USERDATA-FULLNAME}}' : userData.fullName}) %}

{% set referringPhysicianFullName = '' %}
{% set referringPhysicianPhone = '' %}
{% set referringPhysicianFax = '' %}
{% set referringPhysicianClinic = '' %}
{% set referringPhysicianClinicAddress = '' %}
{% if patientLetter.patientReferringProvider %}

	{% set referringPhysicianPhone = patientLetter.patientReferringProvider.referringProvider.phoneNo is null ? patientLetter.patientReferringProvider.referringProvider.phoneNoTwo : patientLetter.patientReferringProvider.referringProvider.phoneNo %}
	{% set referringPhysicianFax = patientLetter.patientReferringProvider.referringProvider.faxNo is null ? patientLetter.patientReferringProvider.referringProvider.faxNoTwo : patientLetter.patientReferringProvider.referringProvider.faxNo %}
	{% set referringPhysicianFullName = patientLetter.patientReferringProvider.referringProvider.honorific ~ ' ' ~ patientLetter.patientReferringProvider.referringProvider.fullName|title %}
	{% for referringClinic in patientLetter.patient.patientReferringHealthFacilities %}
		{% if (referringClinic.endDate == null and referringClinic.startDate != null) or referringClinic.endDate|date('m/d/Y') > 'now'|date('m/d/Y')  %}
			{% set receiverClinic = referringClinic.referringHealthFacility.description|default('') %}
			{% set receiverClinicAddress = referringClinic.referringHealthFacility.getReferringAffiliateAddress|default('') %}
		{% endif %}
	{% endfor %}
{% endif %}

<div style="width:768px; position: relative; padding:0px; margin: 0 auto; box-shadow:3px 1px 10px 1px;">
	<div style="width: 100%; height: 35px; background-color: #f0f0f0; box-sizing: border-box; padding:8px; position: relative;">
		<p style="margin:0; font-size: 18px; float: left;"><strong>SPECIALIST REFERRAL FORM</strong></p>
	</div>
	<hr style="margin: 0; height: 4px; background-color: #1676a9; margin-top:3px; margin-bottom: 10px;">
	<div style="width: 100%; float: left; border: 1px solid; padding: 5px; height: 75px;">
		{% set receiverClinic = '' %}
		{% set receiverClinicAddress = '' %}
		{% set referringPhysicianPhoneNo = '' %}
		{% set referringPhysicianFaxNo = '' %}
		{% if patientLetter.patientReferringProvider %}

			{% set receiverFullName = patientLetter.patientReferringProvider.referringProvider.fullName %}
			{% set referringPhysicianPhoneNo = patientLetter.patientReferringProvider.referringProvider.phoneNo is null ? patientLetter.patientReferringProvider.referringProvider.phoneNoTwo : patientLetter.patientReferringProvider.referringProvider.phoneNo %}
			{% set referringPhysicianFaxNo = patientLetter.patientReferringProvider.referringProvider.faxNo is null ? patientLetter.patientReferringProvider.referringProvider.faxNoTwo : patientLetter.patientReferringProvider.referringProvider.faxNo %}
			{% set receiverFullName = patientLetter.patientReferringProvider.referringProvider.honorific ~ ' ' ~ patientLetter.patientReferringProvider.referringProvider.fullName|title %}
			{% for referringClinic in patientLetter.patient.patientReferringHealthFacilities %}
				{% if (referringClinic.endDate == null and referringClinic.startDate != null) or referringClinic.endDate|date('m/d/Y') > 'now'|date('m/d/Y')  %}
					{% set receiverClinic = referringClinic.referringHealthFacility.description|default('') %}
					{% set receiverClinicAddress = referringClinic.referringHealthFacility.getReferringAffiliateAddress|default('') %}
				{% endif %}
			{% endfor %}
		{% endif %}

		<div style="width: 50%; float: left;">
			<p>Referring Doctor: {{ referringPhysicianFullName|default('') }}</p>
			<p>Clinic: {{ receiverClinic }}</p>
		</div>
		<div style="width: 50%; float: right;">
			<p>Tel: {{ receiverPhone|default('') }}</p>
			<p>Fax: {{ receiverFax|default('') }}</p>
		</div>
	</div>
	<div style="width: 100%; float: left;">
		<p>Dear {{ referringPhysicianFullName|default('') }} Thank you for your referral. As part of our service, we offer direct or indirect consultation or additional testing as needed.</p>
	</div>
	<div style="width: 100%; float: left; border: 1px solid; padding: 5px; height: 75px;">
		<div style="width: 50%; float: left;">
			<p>RE: Patient's Name: {{ patientLastName }}, {{ patientFirstName }}</p>
			<p>Tel: {{ patientLetterSpecialistReferral.contactNo|default('') }}</p>
		</div>
		<div style="width: 50%; float: right;">
			<p>PHN: {{ patientLetter.patient.personalHealthNo|default('N/A') }}</p>
			<p>DOB: {{ patientLetter.patient.birthdate|date('F j, Y') }}</p>
		</div>
	</div>
	<div style="width: 100%; float: left;">
		<p>Based on the <input type="checkbox" style="margin-right: 5px;" {{ patientLetterSpecialistReferral.isAssessment|default('') == true ? 'checked' : '' }}> &nbsp; Assessment <input type="checkbox" {{ patientLetterSpecialistReferral.isResult|default('') == true ? 'checked' : '' }}> &nbsp; Results <input type="checkbox" {{ patientLetterSpecialistReferral.isRecommendation|default('') == true ? 'checked' : '' }}> &nbsp; Recommendations</p>
	</div>
	<div style="width: 100%; float: left;">
		<p><strong>HSAT Completed:</strong> <input type="checkbox" style="margin-right: 5px;" {{ patientLetterSpecialistReferral.isHsatCompleted|default('') == true ? 'checked' : '' }}> &nbsp; YES <input type="checkbox" {{ patientLetterSpecialistReferral.isHsatCompleted|default('') == true ? '' : 'checked' }}> &nbsp; NO &nbsp; Date: {{ patientLetterSpecialistReferral.hsatCompletedDateAsString|default('') }} &nbsp; <strong>Level 1 PSG Completed:</strong> <input type="checkbox" style="margin-right: 5px;" {{ patientLetterSpecialistReferral.isLevelOnePsgCompleted|default('') == true ? 'checked' : '' }}> &nbsp; YES <input type="checkbox" {{ patientLetterSpecialistReferral.isLevelOnePsgCompleted|default('') == true ? '' : 'checked' }}> &nbsp; NO</p>
	</div>
	<div style="width: 100%; border: solid 1px; float: left; padding: 2px; height: 75px;">
		<strong>NOTES</strong>
		<div style="margin-left: 5px; margin-top: 2px; font-size: 15px;">{{ patientLetterSpecialistReferral.note|default('')|raw }}</div>
	</div>
	<div style="width: 100%; float: left;">
		<div><strong>Reason for Referral to Specialist:</strong></div>
		<div style="width: 49%; float: left; font-size: 15px;">
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isOsa|default('') == true ? 'checked' : '' }}> &nbsp; Severe Obstructive Sleep Apnea (OSA)</p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isRefusedCpap|default('') == true ? 'checked' : '' }}> &nbsp; Intolerance / Failed / Refused CPAP</p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isMildOsa|default('') == true ? 'checked' : '' }}> &nbsp; Mild OSA, unable to explain symptoms</p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isNormalHsat|default('') == true ? 'checked' : '' }}> &nbsp; Normal HSAT with Signifcant Symptoms / Snoring</p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isReassess|default('') == true ? 'checked' : '' }}> &nbsp; Reassess indication for Study</p>
		</div>
		<div style="width: 49%; float: right; font-size: 15px;">
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isComplexSleep|default('') == true ? 'checked' : '' }}> &nbsp; Complex sleep patient</p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isComplexTitration|default('') == true ? 'checked' : '' }}> &nbsp; Complex Titration (High Pressure)</p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isIncreaseBmChfOcpd|default('') == true ? 'checked' : '' }}> &nbsp; High Risk Patient with an increased BMI, CHF, COPD</p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isNonRespiratorySleepDisorder|default('') == true ? 'checked' : '' }}> &nbsp; High Probability of Non-Respiratory Sleep Disorder</p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isRequestingOralAppliance|default('') == true ? 'checked' : '' }}> &nbsp; Patient requesting oral appliance</p>
		</div>
	</div>
	<div style="width: 100%; float: left;">
		<div><strong>Recommended Specialist/Testing:</strong></div>
		<div style="width: 40%; float: left; font-size: 15px;">
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isSleepPhysician|default('') == true ? 'checked' : '' }}> &nbsp; Sleep Physician </p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isRespirologist|default('') == true ? 'checked' : '' }}> &nbsp; Respirologist</p>
		</div>
		<div style="width: 60%; float: right; font-size: 15px;">
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isInternalMedicine|default('') == true ? 'checked' : '' }}> &nbsp; Internal Medicine (Diabetes, Obesity, Thyroid) Edmonton only</p>
			<p><input type="checkbox" {{ patientLetterSpecialistReferral.isDentalConsultation|default('') == true ? 'checked' : '' }}> &nbsp; Dental Consultation</p>
		</div>
	</div>
	<div>Based on the type of Specialist recommended and reason, I agree for my patient to be seen and tested as required.</div>
	<div style="width: 100%; height: 100px; float: left; padding: 2px;">
		<div style="width: 60%; border: solid 1px; height: 100px; float: left; padding: 2px;">
			<strong>COMMENT:</strong>
			<div style="margin-left: 5px; margin-top: 2px;">{{ patientLetterSpecialistReferral.comment|default('') }}</div>
		</div>
		<div style="width: 39%; height: 100px; float: left; padding: 2px;">
			<div style="text-align: center;">
				<div><strong>Stamp</strong></div>
				<div>(Please provide PRAC ID)</div>
				<div style="height: 20px;"></div>
			</div>
			<div style="margin-left: 5px;">Referring Physician Signature:</div>
			<div style="margin-left: 5px;">______________________________</div>
		</div>

	</div>
</div>
</body>
</html>