{% 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; margin: 0 auto; box-shadow:3px 1px 10px 1px;">
	<div style="border: none;">
		<div style="color: #ED226D; font-size: 22px;"><strong>HSAT LOAN AGREEMENT</strong></div>
		<div style="margin-bottom: 25px; margin-top: 25px;">Date: {{ hsatLoan.date|default('')|date('F j, Y') }}</div>
		<div style="width: 100%; float: left; margin-top: 50px;">
			<div style="float: left; width: 50%;">
				<div>Full Name: {{ patientFullName }}</div>
				<div>Date of Birth: {{ dateOfBirth }}</div>
				<div>Health Care No.: {{ patientLetter.patient.personalHealthNo|default('') }}</div>
			</div>
			<div style="float: right; width: 50%;">
				<div>&nbsp;</div>
				<div style="display: inline-block;">
					<input type="checkbox" {{ patientLetter.patient.gender == 'Male' ? 'checked' : '' }}>&nbsp;Male
					<input type="checkbox" {{ patientLetter.patient.gender == 'Female' ? 'checked' : '' }}>&nbsp;Female
					<input type="checkbox" {{ patientLetter.patient.gender == 'null' ? 'checked' : '' }}>&nbsp;Undeclared
				</div>
				<div>Phone: {{ patientLetter.patient.phoneNo|default('') }}</div>
			</div>
		</div>
		<div style="width: 100%; float: left; margin-top: 50px; border:1px solid #ED226D; box-sizing: border-box; padding: 10px;">
			<div style="margin-bottom: 10px;"><input type="checkbox" {{ hsatLoan.isHsatDevice == true ? 'checked' : '' }}>&nbsp;<strong>Home Sleep Apnea Testing Device</strong></div>
			<div>ATTENTION: Equipment must be returned by 11:00 AM the next day unless other arrangements have been made. Equipment returned late without notice will be charged $50 a day.</div>
			<p>Driver's License: {{ hsatLoan.driversLicense }}</p>
			<strong>Credit Card Information:</strong>
			<div>Credit Card Number: {{ hsatLoan.ccNo }}</div>
			<div style="display: inline-block">
				<div>Exp: {{ hsatLoan.ccExp }}</div>
				<div>CCV: {{ hsatLoan.ccCCV }}</div>
			</div>
		</div>
		<div style="margin-top: 50px; float: left;">
			<div style="display: inline-block">
				<div><input type="checkbox" style="margin-right: 5px;" {{ hsatLoan.termOne == true ? 'checked' : '' }}> I, hereby understand that the equipment checked above belongs to Freedom Respiratory & Sleep Centre Inc.</div>
			</div>
			<div style="display: inline-block">
				<div><input type="checkbox" style="margin-right: 5px;" {{ hsatLoan.termTwo == true ? 'checked' : '' }}> I understand that i am responsible for any loss or damages that have occurred.</div>
			</div>
			<div style="display: inline-block">
				<div><input type="checkbox" style="margin-right: 5px;" {{ hsatLoan.termThree == true ? 'checked' : '' }}> I agree to pay the fee, as well as leave a credit card number with expiry date and security code as security</div>
			</div>
		</div>
		<div style="margin-top: 50px; float: left;">
			<div style="margin-top: 10px;">Patient's Signature ______________________</div>
			<div style="margin-top: 10px;">Clinician's Signature ______________________</div>
		</div>
	</div>
</div>
</body>
</html>