{% 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.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 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; margin: 0 auto; box-shadow:3px 1px 10px 1px;">
	<div style="border: none;">
		<div style="color: #ED226D; font-size: 22px;"><strong>ACKNOWLEDGEMENT OF REFERRAL</strong></div>
		<div style="margin-top:12px; height: 150px; width:100%;">
			<div style="width: 100%; border:1px solid #ED226D; float: left; box-sizing: border-box; padding: 10px;">
				<div style="width: 50%; height: 230px; float: left; box-sizing: border-box; padding-right: 5px;">
					<p style="margin-bottom: 5px;">TO:</p>
					<div style="width: 100%; height: 100%; box-sizing: border-box; padding:10px;">
						<table>
							<tr>
								<td style="width: 15%;">Attention</td>
								<td style="width: 2%;">:</td>
								<td style="width: 83%;">{{ patientLetter.attention != '' or patientLetter.attention is not null ? patientLetter.attention : receiverFullName }}</td>
							</tr>
							<tr>
								<td style="width: 15%;">Re</td>
								<td style="width: 2%;">:</td>
								<td style="width: 83%;">{{ patientLetter.recipient != '' or patientLetter.recipient is not null ? patientLetter.recipient : patientFullName }}</td>
							</tr>
							<tr>
								<td style="width: 15%;">Date</td>
								<td style="width: 2%;">:</td>
								<td style="width: 83%;">{{ patientLetter.date != '' or patientLetter.date != null ? patientLetter.date|date('F j, Y') : patientLetter.createdAt|date('F j, Y') }}</td>
							</tr>
							<tr>
								<td style="width: 15%;">Phone</td>
								<td style="width: 2%;">:</td>
								<td style="width: 83%;">{{ patientLetter.phoneNo != '' or patientLetter.phoneNo is not null ? patientLetter.phoneNo : receiverPhone }}</td>
							</tr>
							<tr>
								<td style="width: 15%;">Fax</td>
								<td style="width: 2%;">:</td>
								<td style="width: 83%;">{{ patientLetter.faxNo != '' or patientLetter.faxNo is not null ? patientLetter.faxNo : receiverFax }}</td>
							</tr>
						</table>
					</div>
				</div>
				<div style="width: 50%; height: 150px; float: right; box-sizing: border-box; padding-left: 5px;">
					<p style="margin-bottom: 5px;">FROM:</p>
					<div style="width: 100%; height: 100%; box-sizing: border-box; padding:10px;">
						<table>
							<tr>
								<td style="width: 40%;">Name</td>
								<td style="width: 60%;">: {{ patientLetter.name != '' or patientLetter.name is not null ? patientLetter.name : userData.fullName }}</td>
							</tr>
							<tr>
								<td style="width: 45%;"># of Pages (incl. cover)</td>
								{#<td style="width: 60%;">: {{ patientLetter.page != '' or patientLetter.page is not null ? patientLetter.page : '2' }}</td>#}
								<td style="width: 55%;">: {{ patientLetter.estimatedPage }}</td>
							</tr>
							<tr>
								<td style="width: 40%;">CC</td>
								{#<td style="width: 60%;">: {{ patientLetter.carbonCopy != '' or patientLetter.carbonCopy is not null ? patientLetter.carbonCopy : '_______' }}</td>#}
								<td style="width: 60%;">: {{ patientLetter.getPatientLetterCcDescAsString }}</td>
							</tr>
						</table>
					</div>
				</div>
			</div>
		</div>
		<div style="margin-top: 10%; float: left">
			{{ customBody|raw }}
			{#<div style="margin-bottom: 60px;">Dear Dr. _____________________</div>#}
			{#<div style="margin-bottom: 60px;">#}
				{#<p>We have received your referral. We are currently doing our best to contact and book the patient for Home Sleep Apnea Testing (HSAT)/Sleep Medicine Consultation.</p>#}
				{#<p>We will be sending an Appointment Notice once the patient has been booked.</p>#}
				{#<p>Thank you.</p>#}
			{#</div>#}
			{#<strong>CPAP Pros</strong>#}
		</div>
	</div>
</div>
</body>
</html>