{% set absUrl = app.request.getSchemeAndHttpHost() ~ app.request.baseUrl|replace({'/app_dev.php': ''}) %}
{% 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;">
{% 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 == '' %}
        {% set receiverPhone = '' %}
        {% 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 == '' %}
        {% set receiverFax = '' %}
        {% 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 patient = patientLetter.patient %}

{% set faxCoverCustomBody = patientLetter.faxCoverCustomBody|replace({
	'{{RECEVIER-FULLNAME}}' :  receiverFullName,
	'{{PATIENT-FULLNAME}}' : patientFullName,
	'{{PATIENT-FIRSTNAME}}' :  patientLetter.patient.firstName,
	'{{PATIENT-LASTNAME}}' :  patientLetter.patient.lastName,
	'{{USERDATA-FULLNAME}}' : userData.fullName,
	'{{DATE-TODAY}}' : 'now'|date('m/d/Y'),
	'{{DATE-CREATED}}' : patientLetter.createdAt|date('m/d/Y'),
	'{{PATIENT-PHN}}' : patientLetter.patient.personalHealthNo|default(''),
	'{{PATIENT-DOB}}' : patientLetter.patient.birthDate|date('m/d/Y'),
	'{{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 customBody = patientLetter.customBody|replace({
	'{{RECEVIER-FULLNAME}}' :  receiverFullName,
	'{{PATIENT-FULLNAME}}' : patientFullName,
	'{{PATIENT-FIRSTNAME}}' :  patientLetter.patient.firstName,
	'{{PATIENT-LASTNAME}}' :  patientLetter.patient.lastName,
	'{{USERDATA-FULLNAME}}' : userData.fullName,
	'{{DATE-TODAY}}' : 'now'|date('m/d/Y'),
	'{{DATE-CREATED}}' : patientLetter.createdAt|date('m/d/Y'),
	'{{PATIENT-PHN}}' : patientLetter.patient.personalHealthNo|default(''),
	'{{PATIENT-DOB}}' : patientLetter.patient.birthDate|date('m/d/Y'),
	'{{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'
})
%}
<!------ 1ST PAGE ------>
{% include '@RxConnexion/Patient/FaxTemplate/PerfectSleepTemplate/pss_fax_cover.wkpdf.twig' with {patientLetter: patientLetter} %}
<div style="page-break-before: always"></div>
<!------ 2ND PAGE ------>
<div style="width:768px; position: relative; padding:0px; margin: 0 auto; box-shadow:3px 1px 10px 1px;">
	<div style="border: none;">
		{#<div style="width:100%; height: 80px; text-align: left; position: relative; margin-top:500px;">#}
		{#<div style="width: 40%; float: left;">#}
		{#<img src="{{ app.request.getSchemeAndHttpHost() ~ asset('bundles/rxconnexion/admin/images/dynamiclogo.jpg') }}" style="width: 100%;"/>#}
		{#</div>#}
		{#<div style="float: right; height: 100%; width: 60%;">#}
		{#<div style="float: left; width: 60%; height: 100%; text-align: right;">#}
		{#{% set faxBranchSelection = patientLetter.faxBranchSelection|split(',') %}#}
		{#<div style="width: 100%; height: 100%;">#}
		{#<input type="checkbox" id="add" style="height: 15px; width:15px;" {{ 1 in faxBranchSelection ? 'checked' : '' }}><label style="font-size: 13px;"><strong style="margin-right: 20px;">Edmonton North Fax : 780-757-1210</strong></label>#}
		{#<br>#}
		{#<input type="checkbox" id="add" style="height: 15px; width:15px;" {{ 2 in faxBranchSelection ? 'checked' : '' }}><label style="font-size: 13px;"><strong style="margin-right: 18px;">Edmonton South Fax : 780-757-1491</strong></label>#}
		{#<br>#}
		{#<input type="checkbox" id="add" style="height: 15px; width:15px;" {{ 3 in faxBranchSelection ? 'checked' : '' }}><label style="font-size: 13px;"><strong style="margin-right: 19px;">Sherwood Park Fax &ensp;: 780-570-0046</strong></label>#}
		{#<br>#}
		{#<input type="checkbox" id="add" style="height: 15px; width:15px;" {{ 4 in faxBranchSelection ? 'checked' : '' }}><label style="font-size: 13px;"><strong style="margin-right: 20px;">Calgary North Fax&ensp;&emsp;: 403-220-0038</strong></label>#}
		{#<br>#}
		{#<input type="checkbox" id="add" style="height: 15px; width:15px;" {{ 5 in faxBranchSelection ? 'checked' : '' }}><label style="font-size: 13px;"><strong style="margin-right: 21px;">Calgary South Fax&ensp;&emsp;: 780-300-0640</strong></label>#}
		{#</div>#}
		{#</div>#}
		{#<div style="float: right; width: 40%; height: 100%;">#}
		{#<img src="{{ app.request.getSchemeAndHttpHost() ~ asset('bundles/rxconnexion/admin/images/bbc.JPG') }}" style="width: 100%; height: auto;"/>#}
		{#</div>#}
		{#</div>#}
		{#</div>#}
		{#<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>PATIENT LETTER</strong></p>#}
		{#<p style="margin:0; font-size: 18px; float: right;"><strong>1 833 DYNA SLEEP</strong></p>#}
		{#</div>#}
		{#<hr style="margin: 0; height: 4px; background-color: #1676a9; margin-top:3px; margin-bottom: 20px;">#}
		<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>PATIENT LETTER</strong></p>
			<p style="margin:0; font-size: 18px; float: right;"><strong></strong></p>
		</div>
		<hr style="margin: 0; height: 4px; background-color: #6F71B3; margin-top:3px; margin-bottom: 20px;">
		<div style="margin-bottom: 40px;"></div>
		{% if patientLetter.patientReferringProvider %}
			{% set receiverClinic = '' %}
			{% set receiverClinicAddress = '' %}
			{% set receiverFullName = patientLetter.patientReferringProvider.referringProvider.fullName %}
			{% set receiverPhone = patientLetter.patientReferringProvider.referringProvider.phoneNo is null ? patientLetter.patientReferringProvider.referringProvider.phoneNoTwo : patientLetter.patientReferringProvider.referringProvider.phoneNo %}
			{% set receiverFax = 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 %}
			<p style="margin:2px">{{ receiverFullName|default('') }} </p>
			<p style="margin:2px">{{ receiverClinic|default('') }} </p>
			<p style="margin:2px">{{ receiverClinicAddress|raw }}</p>
		{% 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 %} #}
			{#<p style="margin:2px">{{ receiverFullName }} </p>#}
			{#<p style="margin:2px">{{ patientLetter.patientReferringHealthFacility.referringHealthFacility.address }}</p>#}
		{% 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 %} #}
			{#<p style="margin:2px">{{ receiverFullName }} </p>#}
			{#<p style="margin:2px">{{ patientLetter.patientInsurance.insurance.address }}</p>#}
		{% endif %}
		{{ customBody|raw }}
		<br>
		<div style="width: 100%; height: auto; text-align:left;margin-top: 20px;">
			<p style="margin:2px">Sincerely,</p>
		</div>
		{% include '@RxConnexion/Patient/FaxTemplate/PerfectSleepTemplate/pss_signature.html.twig' with {patientLetter: patientLetter} %}

	</div>
</div>
<div style="page-break-before: always"></div>
<div style="width:768px; position: relative; padding:0px; margin: 0 auto; box-shadow:3px 1px 10px 1px;">
	<h3 style="text-align: center;  border:1px solid #6F71B3; margin-left: 60px; margin-right: 60px; box-sizing: border-box; margin-top:55px; padding-right: 40px;">{{ page_title|default('PRESCRIPTION') }}</h3>
	<div style="margin-top:12px; height: 150px; width:100%; font-size: 13px;">
		<p>Date: {{ prescriptionPss.date|date('m/d/Y') }}</p>
		<p>Full Name: {{ patientLastName~' ,'~patientFirstName }}</p>
		<div style="float: left; width: 100%;">
			<span style="width: 40%; float: left;">Address: {{ patientLetter.patient.street }}</span>
			<span style="width: 20%; float: left;">City: {{ patientLetter.patient.city.description|default('') }}</span>
			<span style="width: 20%; float: left;">Province: {{ patientLetter.patient.city.province.description|default('') }}</span>
			<span style="width: 20%; float: left;">Postal: {{ patientLetter.patient.postalCode.description }}</span>
		</div>
		<div style="float: left">
			<p>Date of Birth: {{ patientLetter.patient.birthDate|date('m/d/y') }}</p>
			<p>Physician: {{ receiverFullName }}</p>
			<p>Phone: {{ patientLetter.patient.phoneNo }}</p>
		</div>
		<div style="float: right">
			<div style="float: right">
				<span><input type="checkbox" {{ patientLetter.patient.gender == 'Male' ? 'checked' : '' }}>&nbsp; Male</span>
				<span><input type="checkbox" {{ patientLetter.patient.gender == 'Female' ? 'checked' : '' }}>&nbsp; Female</span>
				<span><input type="checkbox" {{ patientLetter.patient.gender == 'null' ? 'checked' : '' }}>&nbsp; Undeclared</span>
				<p>ULI/PHN: {{ patientLetter.patient.personalHealthNo }}</p>
				<p>Fax: {{ receiverFax }}</p>
			</div>
		</div>
	</div>
	<div style="width: 100%; height: 150px; box-sizing: border-box; padding-top:10px; float: left; font-size: 15px; padding-left: 10px; padding-right: 10px;">
		<div style="text-align: center; margin-bottom: 5px;">
			<div style="font-size: 10px;">
				<strong style="font-size: 15px;">Diagnosis:{{ prescriptionPss.diagnosis|default('_____________') }} Obstructive Sleep Apnea</strong>
			</div>
		</div>
		<div style="width: 100%; text-align: center; float: left; font-size: 10px;">
			<div style="width: 45%; text-align: center; float: left; border: 1px solid #6F71B3; box-sizing: border-box; margin-left: 40px;">
				<div style="margin-bottom: 10px;">AHI (Apnea-Hyponea Index)</div>
				<strong style="font-size: 28px;">{{ prescriptionPss.ahi|default('0') }}</strong>
			</div>
			<div style="width: 45%; float: right; text-align: center; border: 1px solid #6F71B3; box-sizing: border-box;">
				<div style="margin-bottom: 10px;">RDI (Respiratory Disturbance Index)</div>
				<strong style="font-size: 28px;">{{ prescriptionPss.rdi|default('0') }}</strong>
			</div>
		</div>
		<div style="width: 100%; height: 75px;"></div>
		<div style="width: 100%; float: left; font-size: 10px;">
			<div style="width: 20%; float: left; text-align: center;">
				<strong>Legend of Classification of AHI/RDI Severity</strong>
			</div>
			<div style="width: 20%; float: left; text-align: center;">
				<div>0 - 5 Normal Range</div>
				<div>5 - 15 Mild Sleep Apnea</div>
			</div>
			<div style="width: 20%; float: left; text-align: center;">
				<div>15-30 Moderate Sleep Apnea</div>
				<div>> 30 Severe Sleep Apnea</div>
			</div>
			<div style="width: 20%; float: left; text-align: center;">
				<div>AHI - Apnea-hypopnea Index</div>
				<div>Number of Apneas and/or</div>
				<div>Hypopneas per hour of sleep</div>
			</div>
			<div style="width: 20%; float: left; text-align: center;">
				<div>RDI = Respiratory</div>
				<div>Disturbance Index</div>
				<div>(Includes AHI & RERA's)</div>
			</div>
		</div>
	</div>

	{% set recommendation = prescriptionPss.recommendation|replace({
		'{{RECEVIER-FULLNAME}}' :  receiverFullName,
		'{{PATIENT-FULLNAME}}' : patientFullName,
		'{{PATIENT-FIRSTNAME}}' :  patientLetter.patient.firstName,
		'{{PATIENT-LASTNAME}}' :  patientLetter.patient.lastName,
		'{{USERDATA-FULLNAME}}' : userData.fullName,
		'{{DATE-TODAY}}' : 'now'|date('m/d/Y'),
		'{{DATE-CREATED}}' : patientLetter.createdAt|date('m/d/Y'),
		'{{PATIENT-PHN}}' : patientLetter.patient.personalHealthNo|default(''),
		'{{PATIENT-DOB}}' : patientLetter.patient.birthDate|date('m/d/Y'),
		'{{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',
		'{{INTERPRETATION-DOCTOR}}' : prescriptionPss.interpretationCompletedDoctor|default('')
	})
	%}

	<div style="width: 100%; height: 315px; border: 1px solid #6F71B3; box-sizing: border-box; margin-top: 5px; padding-top:10px; float: left; font-size: 15px; padding-left: 10px; padding-right: 10px;">
		<div style="margin-bottom: 15px;">
			<div style="font-size: 12px;">
				<strong style="margin-bottom: 10px;">Interpretation & Recommendation</strong>
				<div style="height: 163px;">
					{{ recommendation|default('')|raw }}
				</div>
			</div>
		</div>
	</div>
	<div style="width: 100%; float: left; font-size: 12px;">
		<p><strong>PHYSICIAN USE ONLY</strong></p>
		<div>
			<div><input type="checkbox" {{ prescriptionPss.isCpapTheraphy|default('') == true ? 'checked' : '' }}> CPAP Therapy (Auto) <u>{{ prescriptionPss.cpapTheraphyOne|default('_________') }}</u> cmH<sub>2</sub>0 to <u>{{ prescriptionPss.cpapTheraphyTwo|default('_________') }}</u> cmH<sub>2</sub>0</div>
			<div style="margin-top: 14px; margin-left: 15px;">(Fixed) <u>{{ prescriptionPss.cpapTheraphyThree|default('______________') }}</u> cmH<sub>2</sub>0</div>
			<div style="margin-top: 14px;"><input type="checkbox" {{ prescriptionPss.isReferralToSleepSpecialist|default('') == true ? 'checked' : '' }}> Referral to Sleep Doctor</div>
			<div style="margin-top: 14px;"><input type="checkbox" {{ prescriptionPss.isOralAppliance|default('') == true ? 'checked' : '' }}> Oral Appliance</div>
		</div>
	</div>
	<div style="width: 100%; float: left; font-size: 12px;">
		<div style="width: 50%; float: left;">
			<p>Referring Doctor: {{ receiverFullName }}</p>
			<p>Doctor's Signature:</p>
			<p>Date:</p>
		</div>
		<div style="width: 50%; float: right;">
			<p>Stamp</p>
		</div>
	</div>
</div>
</body>
</html>