{% 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>Somnus 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.getReferringProviderFullName|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 %}
{% if patientLetter.specialist %}
	{% set receiverFullName = patientLetter.specialist.fullName|title %}
	{% set receiverPhone = patientLetter.specialist.phoneNo is null ? patientLetter.specialist.phoneNoTwo : patientLetter.specialist.phoneNo %}
	{% set receiverFax = patientLetter.specialist.faxNo is null ? patientLetter.specialist.faxNoTwo : patientLetter.specialist.faxNo %}
{% endif %}
{% set patientFullName = patientLetter.patient.fullName %}
{% set patientFirstName = patientLetter.patient.firstName %}
{% set patientLastName = patientLetter.patient.lastName %}
{% set patient = patientLetter.patient %}
{% set dateOfBirth = patientLetter.patient.birthDate|date('F j, Y') %}

{% 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/SomnusTemplate/fax_cover.wkpdf.twig' with {patientLetter: patientLetter} %}#}
{#<div style="page-break-before: always"></div>#}
<div style="width:768px; position: relative; padding:0px; font-size: 20px; margin: 0 auto; box-shadow:3px 1px 10px 1px;">
	<div style="border: none; width: 100%;">
		<div style="width: 100%; float: left;">
			<div style="width: 70%; float: left;">
				<h3><strong>CPAP THERAPY PRESCRIPTION</strong></h3>
			</div>
			<div style="width: 30%; float: right;">
				<div>Please fax back to:</div>
				<h3><strong>1-833-490-1315</strong></h3>
			</div>
		</div>
		<div style="margin-top: 5%; float: left; width: 100%">
			<table style="width: 100%;">
				<tr>
					<th width="20%;"></th>
					<th width="5%"></th>
					<th width="65%"></th>
				</tr>
				<tr>
					<td>Patient Name</td>
					<td>:</td>
					<td>{{ patientFullName }}</td>
				</tr>
				<tr>
					<td>PHN</td>
					<td>:</td>
					<td>{{ patientLetter.patient.personalHealthNo|default('') }}</td>
				</tr>
				<tr>
					<td>Date of Birth</td>
					<td>:</td>
					<td>{{ patientLetter.patient.birthDate|date('m/d/Y') }}</td>
				</tr>
			</table>
		</div>
		<div style="width: 100%; margin-top: 5%; float: left;">
			<div>Diagnosis: {{ prescription.diagnosis|default('') }} <br>
				<span style="font-size: 12px;">Left untreated, this diagnosis can have serious health effects.</span>
			</div>
			<div style="margin-bottom: 5px;">AHI: {{ prescription.ahi|default('') }} <br>
				<span style="font-size: 12px;">Number of Apneas and/or Hypopneas per hour of sleep</span>
			</div>
			<div style="margin-bottom: 5px;">ODI: {{ prescription.rdi|default('') }} <br>
				<span style="font-size: 12px;">Oxygen desaturation index per hour of sleep</span>
			</div>
			<div>Lowest Oxygen: {{ prescription.lowestOxygen|default('') }}</div>
		</div>
		<div style="width: 100%; margin-top: 10%; float: left;">
			<div>
				CPAP Pressure therapy range {{ prescription.cpapPressureTherapyRange }} cmH<sub>2</sub>0 with heated humidifier.
			</div>
		</div>
		<div style="width: 100%; margin-top: 5%; float: left;">
			<div>
				<input type="checkbox" {{ prescription.isMayTitratePressure == 1 ? 'checked' : '' }}> May titrate pressure as necessary.
			</div>
			<div>
				<input type="checkbox" {{ prescription.isMaySwitchFixedPressure == 1 ? 'checked' : '' }}> May switch to fixed pressure as recommended by Sleep Physician.
			</div>
		</div>
		<div style="width: 100%; margin-top: 5%; float: left;">
			<table>
				<tr>
					<td>Clinic Stamp (CPSID)</td>
					<td>:</td>
					<td>{{ prescription.clinicStamp|default('') }}</td>
				</tr>
				{# empty space #}
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td>Prescribing Physician Signature</td>
					<td>:</td>
					<td>_________________________________</td>
				</tr>
				{# empty space #}
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td>Prescribing Physician</td>
					<td>:</td>
					<td>{{ prescription.prescribingPhysician }} ,M.D.</td>
				</tr>
			</table>
		</div>
		<div style="width: 100%; margin-top: 10%; float: left;">
			<div>Date: {{ prescription.date|date('m/d/Y') }}</div>
		</div>
	</div>
</div>
</body>
</html>