<?xml version="1.0" encoding="UTF-8"?>
<!--

Stylesheet for birthEpicrisis templates
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:urn="urn:hl7-org:v3" xmlns:ext="urn:hl7-EE-DL-Ext:v1">
	<!--

	Main epicrisis template which includes content rows
	-->
	<xsl:template name="structuredBody.birthEpicrisis" match="urn:structuredBody" mode="birthEpicrisis">
		
		<xsl:if test="../../urn:recordTarget/urn:realmCode[@code='PAT']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="../../urn:recordTarget[urn:realmCode/@code='PAT']/urn:patientRole/urn:patient" mode="child"/>
				</td>
			</tr>
		</xsl:if>

		<xsl:if test="../../urn:recordTarget/urn:realmCode[@code='GUARD']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="../../urn:recordTarget[urn:realmCode/@code='GUARD']/urn:patientRole/urn:patient" mode="mother"/>
				</td>
			</tr>
		</xsl:if>

		<xsl:if test="../../urn:recordTarget/urn:patientRole/urn:patient/ext:asPatientOfOtherProvider">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="../../urn:recordTarget/urn:patientRole/urn:patient/ext:asPatientOfOtherProvider/ext:providerOrganization" mode="practitioner"/>
				</td>
			</tr>
		</xsl:if>
		
		<!-- suunaja-->
		<xsl:if test="../../urn:componentOf/urn:encompassingEncounter/urn:encounterParticipant[@typeCode='REF']/urn:assignedEntity">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="../../urn:componentOf/urn:encompassingEncounter/urn:encounterParticipant[@typeCode='REF']/urn:assignedEntity" mode="refattender"/>
				</td>
			</tr>
		</xsl:if>		
		
		<!-- saatekiri/tellimus-->
		<xsl:if test="../../urn:inFulfillmentOf/urn:order">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="../../urn:inFulfillmentOf/urn:order" mode="reference"/>
				</td>
			</tr>
		</xsl:if>
		<xsl:if test="../../urn:componentOf/urn:encompassingEncounter">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="../../urn:componentOf/urn:encompassingEncounter" mode="encompassingEncounter">
						<xsl:with-param name="encounterType" select="'birth'"/>
					</xsl:apply-templates>
				</td>
			</tr>
		</xsl:if>
		<xsl:if test="urn:component/urn:section[urn:code/@code='DEATH']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='DEATH']" mode="death"/>

				</td>
			</tr>
		</xsl:if>

		<xsl:if test="urn:component/urn:section[urn:code/@code='PRGN']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='PRGN']" mode="prgnEncounter"/>
				</td>
			</tr>
		</xsl:if>
		<xsl:if test="urn:component/urn:section[urn:code/@code='BIRTH']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='BIRTH']" mode="birthData"/>
				</td>
			</tr>
		</xsl:if>
		<xsl:if test="urn:component/urn:section[urn:code/@code='DGN']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='DGN']" mode="epicrisisDiagnoses"/>
				</td>
			</tr>
		</xsl:if>

		<xsl:if test="urn:component/urn:section[urn:code/@code='BSTATE']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='BSTATE']" mode="info"/>
				</td>
			</tr>
		</xsl:if>
		
		<xsl:if test="urn:component/urn:section[urn:code/@code='MANA']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='MANA']" mode="tests"/>
				</td>
			</tr>
		</xsl:if>

		<xsl:if test="urn:component/urn:section[urn:code/@code='BANA']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='BANA']" mode="tests"/>
				</td>
			</tr>
		</xsl:if>
		
		
		
		<xsl:if test="urn:component/urn:section[urn:code/@code='IMM']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='IMM']" mode="immunization">
						<xsl:with-param name="ageGroup" select="'All'"/>
					</xsl:apply-templates>
				</td>
			</tr>
		</xsl:if>

		<xsl:if test="urn:component/urn:section[urn:code/@code='SUM']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='SUM']" mode="text"/>
				</td>
			</tr>
		</xsl:if>
		<xsl:if test="urn:component/urn:section[urn:code/@code='BLEAVESTATE']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='BLEAVESTATE']" mode="bLeaveState"/>
				</td>
			</tr>
		</xsl:if>
		<xsl:if test="urn:component/urn:section[urn:code/@code='SPEC']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='SPEC']" mode="info"/>
				</td>
			</tr>
		</xsl:if>
		<xsl:if test="urn:component/urn:section[urn:code/@code='DOC']">
			<tr>
				<td class="tableBlock">
					<xsl:apply-templates select="urn:component/urn:section[urn:code/@code='DOC']" mode="documents"/>
				</td>
			</tr>
		</xsl:if>

	</xsl:template>
</xsl:stylesheet>
