{% set absUrl = app.request.getSchemeAndHttpHost() ~ app.request.baseUrl|replace({'/app_dev.php': ''}) %}
{% set customBody = patientLetter.customBody|replace({'{{PATIENT-FIRSTNAME}}' :  patientLetter.patient.firstName, '{{PATIENT-FULLNAME}}' : patientLetter.patient.fullName, '{{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 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 %}
<div style="width:768px; height: 882px; position: relative; padding:0px; margin: 0 auto; box-shadow:3px 1px 10px 1px;">
	<div style="width:100%; height: 100px; text-align: left; position: relative;">
		<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: auto; text-align:left;margin-top: 70px;">#}
	<h2 style="text-align: center; margin-top:40px; padding-right: 40px;">Fax Cover Sheet</h2>
	<div style="margin-top:20px; height: 150px; width:100%;">
		<div style="width: 50%; height: 150px; float: left; box-sizing: border-box; padding-right: 5px;">
			<p>TO:</p>
			<div style="width: 100%; height: 100%; border:1px solid #000; box-sizing: border-box; padding:10px;">
				<table>
					<tr>
						<td style="width: 15%;">ATTN</td>
						<td style="width: 2%;">:</td>
						<td style="width: 83%;">{{ receiverFullName }}</td>
					</tr>
					<tr>
						<td style="width: 15%;">RE</td>
						<td style="width: 2%;">:</td>
						<td style="width: 83%;">{{ patientFullName }}</td>
					</tr>
					<tr>
						<td style="width: 15%;">Date</td>
						<td style="width: 2%;">:</td>
						<td style="width: 83%;">{{ 'now'|date('F j, Y') }}</td>
					</tr>
					<tr>
						<td style="width: 15%;">Phone</td>
						<td style="width: 2%;">:</td>
						<td style="width: 83%;">{{ receiverPhone }}</td>
					</tr>
					<tr>
						<td style="width: 15%;">Fax</td>
						<td style="width: 2%;">:</td>
						<td style="width: 83%;">{{ receiverFax }}</td>
					</tr>
				</table>
			</div>
		</div>
		<div style="width: 50%; height: 150px; float: right; box-sizing: border-box; padding-left: 5px;">
			<p>FROM:</p>
			<div style="width: 100%; height: 100%; border:1px solid #000; box-sizing: border-box; padding:10px;">
				<table>
					<tr>
						<td style="width: 40%;">Name</td>
						<td style="width: 60%;">: {{ userData.fullName }}</td>
					</tr>
					<tr>
						<td style="width: 40%;">Pages</td>
						<td style="width: 60%;">: 2</td>
					</tr>
					<tr>
						<td style="width: 40%;">CC</td>
						<td style="width: 60%;">:___________</td>
					</tr>
				</table>
			</div>
		</div>
	</div>
    {% set faxCoverSelection = patientLetter.faxCoverSelection|split(',') %}
	<div style="width:100%; height: 70px; margin-top: 80px; box-sizing: border-box; padding:20px; border:1px solid #000;">
		<div style="width: 100%; height: 100%;">
			<input type="checkbox" id="urgent" style="height: 18px; width:18px;" {{ 1 in faxCoverSelection ? 'checked' : '' }}><label style="font-size: 18px; margin-right:40px;"><strong>Urgent</strong></label>
			<input type="checkbox" id="urgent" style="height: 18px; width:18px;" {{ 2 in faxCoverSelection ? 'checked' : '' }}><label style="font-size: 18px; margin-right:40px;"><strong>For Review</strong></label>
			<input type="checkbox" id="urgent" style="height: 18px; width:18px;" {{ 3 in faxCoverSelection ? 'checked' : '' }}><label style="font-size: 18px; margin-right:40px;"><strong>Please Comment</strong></label>
			<input type="checkbox" id="urgent" style="height: 18px; width:18px;" {{ 4 in faxCoverSelection ? 'checked' : '' }}><label style="font-size: 18px; margin-right:40px;"><strong>Please Reply</strong></label>
		</div>
	</div>
	<div style="width: 100%; height: auto; margin-top:25px; border: 1px solid #000; box-sizing: border-box; padding:20px;">
		<p><strong>Notes:</strong></p>
		<p>Good day, {{ receiverFullName }}.</p>
		<p>Thank you for your referral.</p>
		<p>Please find attached letter regarding your patient {{ patientFullName }}.</p>
		<p>Kind regards,</p>
		<br>
		<p style="margin:0;">{{ userData.fullName }}</p>
		<p style="margin:0;">Dynamic Sleep Respiratory Care</p>
	</div>
	<p style="font-size: 10px;">"This Facsimile transmission contains information which is confidential and/or privileged. This information is intended for use only by the addressee indicated above. If you are not the intended recipient, please be advised that any disclosure, copying, distribution or use of the contents of this information is stricly prohibited, and that any misdirected or improperly received information must be returned to this company immediately. Your cooperation in phoning us of erroneous receipt is requested."</p>
	<!-- <div style="height: 400px; position: relative;"></div>
	<div style="width: 100%; height: 60px; color:#717171;">
		<div style="width:20%; float: left; font-size: 12px;">
			<p style="margin:0;"><strong>EDMONTON NORTH</strong></p>
			<p style="margin:0;">Mira Health Clinic</p>
			<p style="margin:0;">Unit 108, 1190-111 Ave.</p>
			<p style="margin:0;">Edmonton, Alberta</p>
			<p style="margin:0;">T5G 3G6asdasdasdad</p>
		</div>
		<div style="width:20%; float: left; font-size: 12px;">
			<p style="margin:0;"><strong>EDMONTON SOUTH</strong></p>
			<p style="margin:0;">Millwoods</p>
			<p style="margin:0;">6570 28 Ave NW</p>
			<p style="margin:0;">Edmonton, Alberta</p>
			<p style="margin:0;">T6L 6N3</p>
		</div>
		<div style="width:20%; float: left; font-size: 12px;">
			<p style="margin:0;"><strong>CALGARY NORTH</strong></p>
			<p style="margin:0;">Bldg. 107, 12 Ave. NW</p>
			<p style="margin:0;">Calgary, Alberta</p>
			<p style="margin:0;">T2M 0C4</p>
		</div>
		<div style="width:20%; float: left; font-size: 12px;">
			<p style="margin:0;"><strong>CALGARY SOUTH</strong></p>
			<p style="margin:0;">#44, 6130-1A Street</p>
			<p style="margin:0;">Calgary, Alberta</p>
			<p style="margin:0;">T2H 0G3</p>
		</div>
		<div style="width:20%; float: left; font-size: 12px;">
			<p style="margin:0;"><strong>SHERWOOD PARK</strong></p>
			<p style="margin:0;">Unit 168, 150 Chippewa Road</p>
			<p style="margin:0;">Sherwood Park, Alberta</p>
			<p style="margin:0;">T8A 6A</p>
		</div>
	</div> -->
    {#</div>#}
</div>

<!------ 2ND PAGE ------>

<div style="width:768px; height: 882px; 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>
		<br>
		<br>
		<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: auto; text-align:left;margin-top: 70px;">
            {% if patientLetter.patientReferringProvider %}
                {# {% 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 %}
				<p style="margin:2px">{{ receiverFullName }} </p>
				<p style="margin:2px">{{ patientLetter.patientReferringProvider.referringProvider.address }}</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 %}
		</div>
		<div style="width: 100%; height: auto; text-align:left;margin-top: 30px;">
			<p style="margin:2px">{{ 'now'|date('F j, Y') }}</p>
		</div>
		<div style="width: 100%; height: auto; text-align:left;margin-top: 30px;">
			<p style="margin:2px">Patient Name: {{ patientLastName }}, {{ patientFirstName }}</p>
			<p style="margin:2px">Date of Birth: {{ patientLetter.patient.birthdate|date('F j, Y') }}</p>
			<p style="margin:2px">PHN: {{ patientLetter.patient.personalHealthNo|default('N/A') }}</p>
		</div>
		<div style="width: 100%; height: auto; text-align:left;margin-top: 30px;">
			<p style="margin:2px">Dear {{ receiverFullName }},</p>
		</div>
        {{ customBody|raw }}
		<div style="width: 100%; height: auto; text-align:left;margin-top: 20px;">
			<p style="margin:2px">Thank you for your continued support.</p>
		</div>
		<div style="width: 100%; height: auto; text-align:left;margin-top: 20px;">
			<p style="margin:2px">Sincerely,</p>
		</div>
		<div style="width: 100%; height: auto; text-align:left; padding-top:15px;">
			{% if patientLetter.patientLetterStatus.description == 'Approved'%}
			<img src="{{ app.request.getSchemeAndHttpHost() ~ asset('bundles/rxconnexion/admin/images/jessie.PNG') }}" style="width: 30%; position: absolute;" />
			{% endif %}
			<p style="margin:2px; margin-top:50px;">Jesse Tallon, BHSc, RRT, PSGT.</p>
			<!-- <p style="margin:2px">{{ userData.fullName }}</p> -->
			<p style="margin:2px">Dynamic Sleep & Respiratory Care</p>			
		</div>
		
	</div>
	<!-- <div style="height: 520px; position: relative;"></div>	
	<div style="width: 100%; height: 60px; color:#717171; position: fixed;">
			<div style="width:20%; float: left; font-size: 12px;">
				<p style="margin:0;"><strong>EDMONTON NORTH</strong></p>
				<p style="margin:0;">Mira Health Clinic</p>
				<p style="margin:0;">Unit 108, 1190-111 Ave.</p>
				<p style="margin:0;">Edmonton, Alberta</p>
				<p style="margin:0;">T5G 3G6</p>
			</div>
			<div style="width:20%; float: left; font-size: 12px;">
				<p style="margin:0;"><strong>EDMONTON SOUTH</strong></p>
				<p style="margin:0;">Millwoods</p>
				<p style="margin:0;">6570 28 Ave NW</p>
				<p style="margin:0;">Edmonton, Alberta</p>
				<p style="margin:0;">T6L 6N3</p>
			</div>
			<div style="width:19%; float: left; font-size: 12px;">
				<p style="margin:0;"><strong>CALGARY NORTH</strong></p>
				<p style="margin:0;">Bldg. 107, 12 Ave. NW</p>
				<p style="margin:0;">Calgary, Alberta</p>
				<p style="margin:0;">T2M 0C4</p>
			</div>
			<div style="width:19%; float: left; font-size: 12px;">
				<p style="margin:0;"><strong>CALGARY SOUTH</strong></p>
				<p style="margin:0;">#44, 6130-1A Street</p>
				<p style="margin:0;">Calgary, Alberta</p>
				<p style="margin:0;">T2H 0G3</p>
			</div>
			<div style="width:22%; float: left; font-size: 12px;">
				<p style="margin:0;"><strong>SHERWOOD PARK</strong></p>
				<p style="margin:0;">Unit 168, 150 Chippewa Road</p>
				<p style="margin:0;">Sherwood Park, Alberta</p>
				<p style="margin:0;">T8A 6A</p>
			</div>
		</div> -->
</div>

<!------ ATTACHMENTS ------>
{#{% if patientLetter.photoDesc is not null or patientLetter.photoDesc != '' %}
<div style="width:766px; height: 1056px; padding:50px; margin: 0 auto; margin-top: 20px; box-shadow:3px 1px 10px 1px;">
	<img src="{{ absUrl ~ patientLetter.getPhotoWebPath }}" style="width: 50%;"/>
    {% if patientLetter.photoDesc2 is not null or patientLetter.photoDesc2 != '' %}
		<img src="{{ absUrl ~ patientLetter.getPhotoWebPath2 }}" style="width: 50%;"/>
    {% endif %}
</div>
{% endif %}#}
</body>
</html>