{% 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 referringHealthFacility = '' %}
{% set referringHealthFacilityPhoneNo = '' %}
{% set referringHealthFacilityFaxNo = '' %}
{% for prhf in patientLetter.patient.patientReferringHealthFacilities %}
	{% if prhf.startDate >= 'now'|date('Y-m-d') and (prhf.endDate is null or prhf.endDate >= 'now'|date('Y-m-d')) %}
		{% set referringHealthFacility = prhf.referringHealthFacility.description %}
		{% set referringHealthFacilityPhoneNo = prhf.referringHealthFacility.phoneNo %}
		{% set referringHealthFacilityFaxNo = prhf.referringHealthFacility.faxNo %}
	{% endif %}
{% endfor %}

{% set referringProvider = '' %}
{% set rpPhoneNo = '' %}
{% for prp in patientLetter.patient.patientReferringProviders %}
	{% if prp.startDate >= 'now'|date('Y-m-d') and (prp.endDate is null or prp.endDate >= 'now'|date('Y-m-d')) %}
		{% set referringProvider = prp.referringProvider.fullName %}
		{% set rpPhoneNo = prp.referringProvider.phoneNo %}
	{% endif %}
{% endfor %}
{% 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 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>PATIENT REFERRAL STATUS</strong></div>

		<div style="width: 100%; float: left; margin-top: 50px;">
			<div style="margin-bottom: 30px;">Date: {{ hsatLoan.date|default('')|date('F j, Y') }}</div>
			<div style="float: left; width: 50%; margin-bottom: 30px;">
				<div>Referring Physician: {{ referringProvider }}</div>
				<div>Clinic Name: {{ referringHealthFacility }}</div>
			</div>
			<div style="float: right; width: 50%; margin-bottom: 30px;">
				<div>Phone: {{ referringHealthFacilityPhoneNo|default('') }}</div>
				<div>Fax: {{ referringHealthFacilityFaxNo }}</div>
			</div>
		</div>
		<strong>Thank you for referring you patient to our sleep clinic. Below is an update regarding their referral status.</strong>
		<div style="width: 100%; float: left; margin-top: 50px;">
			<div style="float: left; width: 50%;">
				<div>Name of Patient: {{ patientFullName }}</div>
				<div>Date of Birth: {{ dateOfBirth }}</div>
			</div>
			<div style="float: right; width: 50%;">
				<div>Phone: {{ patientLetter.patient.phoneNo }}</div>
				<div>PHN: {{ patientLetter.patient.personalHealthNo|default('') }}</div>
			</div>
		</div>
		<div style="width: 100%; float: left; margin-top: 50px; margin-bottom: 40px; border:1px solid #ED226D; box-sizing: border-box; padding: 10px;">
			<div style="margin-bottom: 30px;">
				<div><input type="checkbox" {{ patientReferralStatus.isDeclined == 1 ? 'checked' : '' }}> <strong>Patient Declined Referral</strong></div>
				<div>We have phoned and informed the patient of your referral and have discussed the reason why the test needs to be done; however they have declined to proceed with the test. We are now closing the referral from our active lists. If the patient is still interested, please do not hesitate to send us a new referral.</div>
			</div>
			<div style="margin-bottom: 30px;">
				<div><input type="checkbox" {{ patientReferralStatus.isUnableToContact == 1 ? 'checked' : '' }}> <strong>Unable to Contact Patient</strong></div>
				<div>We would like to inform you that despite efforts contact the patient to book for the sleep study, they are not returning our phone calls. We have made at least 5 attempts to contact the patient at various times of the day and week and left messages on their voice mail to return our call. If the patient visits your clinic, please remind them to contact the sleep clinic to arrange an appointment for the sleep study</div>
			</div>
			<div style="margin-bottom: 30px;">
				<div><input type="checkbox" {{ patientReferralStatus.isMissedAppointment == 1 ? 'checked' : '' }}> <strong>Missed Appointment</strong></div>
				<div>The patient failed to attend a confirmed scheduled appointment on {{ patientReferralStatus.missedAppointmentDateAsString|date('F j, Y') }} To re-book this appointment if still required, please contact our sleep clinic.</div>
			</div>
		</div>
		<div>
			<div style="text-align: center">
				<span>If you have any question, please do not hesitate to contact us</span>
			</div>
		</div>
	</div>
</div>
</body>
</html>