{% set absUrl = app.request.getSchemeAndHttpHost() ~ app.request.baseUrl|replace({'/app_dev.php': ''}) %}
{% set userData = app.session.get('userData') %}
<!DOCTYPE html>
<html>
<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>Email</title>
</head>
<body style="font-family:'Arial'; font-size:13px;">
{% set referringProvider = '' %}
{% if patient.patientReferringProviders %}
	{% for prp in patient.patientReferringProviders %}
		{% if prp.endDate >= 'now'|date('Y-m-d') or prp.endDate == '' %}
			{% if prp.isDeleted == 0 %}
				{% set referringProvider = prp.referringProvider.fullName %}
			{% endif %}
		{% endif %}
	{% endfor %}
{% endif %}
{% set referringHealthFacility = '' %}
{% if patient.patientReferringHealthFacilities %}
	{% for prhf in patient.patientReferringHealthFacilities %}
		{% if prhf.endDate >= 'now'|date('Y-m-d') or prhf.endDate == '' %}
			{% if prhf.isDeleted == 0 %}
				{% set referringHealthFacility = prhf.referringHealthFacility.description %}
			{% endif %}
		{% endif %}
	{% endfor %}
{% endif %}
{% set patientFullName = patient.fullName %}
{% set patientFirstName = patient.firstName %}
{% set patientLastName = patient.lastName %}
{% set patientReferralDate = patient.referralDate|date('m/d/Y') %}
{% set patientReceiveDate = patient.receivedDate|date('m/d/Y') %}
{% set patient = patient %}

{% set emailBody = patientEmail.customBody|replace({
	'{{PATIENT-REFERRING-PHYSICIAN}}' :  referringProvider,
	'{{PATIENT-REFERRING-AFFILIATE}}' :  referringHealthFacility,
	'{{PATIENT-REFERRAL-DATE}}' :  patientReferralDate,
	'{{PATIENT-RECEIVED-DATE}}' :  patientReceiveDate,
	'{{PATIENT-FULLNAME}}' : patientFullName,
	'{{PATIENT-FIRSTNAME}}' :  patient.firstName,
	'{{PATIENT-LASTNAME}}' :  patient.lastName,
	'{{USERDATA-FULLNAME}}' : userData.fullName,
	'{{DATE-TODAY}}' : 'now'|date('m/d/Y'),
	'{{DATE-CREATED}}' : patient.createdAt|date('m/d/Y'),
	'{{PATIENT-PHN}}' : patient.personalHealthNo|default(''),
	'{{PATIENT-DOB}}' :	patient.birthDate|date('m/d/Y'),
	'{{PATIENT-GENDER}}' : patient.gender == 'Male' ? 'he' : 'she',
	'{{PATIENT-GENDER2}}' : patient.gender == 'Male' ? 'him' : 'her',
	'{{PATIENT-GENDER3}}' : patient.gender == 'Male' ? 'his' : 'her',
	'{{PATIENT-GENDER4}}' : patient.gender == 'Male' ? 'He' : 'She'
})
%}

<div>
	{{ emailBody|raw }}
</div>
</body>
</html>