<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dis="http://www.kith.no/xmlstds/epikrise/2006-09-23" xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="dis xhtml">
	<xsl:import href="../../Felleskomponenter/funksjoner.xsl"/>
	<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
	<!--
Inngår i KITHs visningsfiler versjon 10

FORMÅL
XSLT for generering av html fra Epikrise v.1.1

ENDRINGER:
01.12.2010: Import av felles CSS-fil
07.01.2008: Første versjon

TODO/Svakheter:
* CodedComment og andre kode verdier som ikke er fastsatt i IG men baserer seg på eksterne kodeverk vil ikke vises med mindre teksten er med i DN-feltet
* Kodeverdiene er som kodet fra Epikrise 1.0-dokumentasjonen.

-->
	<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>Epikrise</title>
				<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
				<style type="text/css"><xsl:value-of select="document('../../Felleskomponenter/KITH-visning.css')" disable-output-escaping="yes" /></style>
			</head>
			<body>
				<xsl:apply-templates/>
			</body>
		</html>
	</xsl:template>
	<!-- Meldingshodet - avsender og mottaker-informasjon -->
	<xsl:template name="Header">
		<div class="Top">
			<div class="Header">
				<div class="HeaderContent">
					<div class="Caption">Avsender &#160;</div>
					<div class="Content"><xsl:apply-templates select="dis:ServProvider"/></div>
				</div>
				<xsl:choose>
					<xsl:when test="dis:Patient">
						<div class="HeaderContent">
							<div class="Caption">Pasient &#160;</div>
							<div class="Content"><xsl:apply-templates select="dis:Patient"/></div>
						</div>
					</xsl:when>
					<xsl:otherwise>
						<div class="HeaderContent">
							<div class="NoScreen">&#160;</div>
						</div>
					</xsl:otherwise>
				</xsl:choose>
				<div class="HeaderContent">
					<div class="Caption">Mottaker &#160;</div>
					<div class="Content"><xsl:apply-templates select="dis:Requester"/></div>
				</div>
				<xsl:choose>
					<xsl:when test="dis:CopyDest">
						<div class="HeaderContent">
							<div class="Caption">Kopimottaker(e) &#160;</div>
							<div class="Content"><xsl:apply-templates select="dis:CopyDest"/></div>
						</div>
					</xsl:when>
					<xsl:otherwise>
						<div class="HeaderContent">
							<div class="NoScreen">&#160;</div>
						</div>
					</xsl:otherwise>
				</xsl:choose>
			</div>
		</div>
	</xsl:template>
	<!-- Meldingshodet - Dokumentopplysninger -->
	<xsl:template name="Footer">
		<div class="Document">
			<h2>Dokumentinformasjon</h2>
			<div class="Box">
				<div class="Block">
					<div class="MainCaption">Melding sendt</div>
					<div class="MainContent"><xsl:call-template name="skrivUtDateTime"><xsl:with-param name="oppgittTid" select="../dis:GenDate/@V"/></xsl:call-template></div>
				</div>
				<div class="Block">
					<div class="MainCaption">Meldingsid</div>
					<div class="MainContent"><xsl:value-of select="../dis:MsgId"/></div>
				</div>
			</div>
		</div>
	</xsl:template>
	<xsl:template match="dis:Requester">
		<xsl:apply-templates select="dis:HCP"/>
	</xsl:template>
	<xsl:template match="dis:ServProvider">
		<xsl:apply-templates select="dis:HCP"/>
	</xsl:template>
	<xsl:template match="dis:Patient">
		<div><xsl:value-of select="dis:Name"/>&#160;<b><xsl:value-of select="dis:TypeOffId/@V"/>:&#160;</b><xsl:value-of select="substring(dis:OffId, 1,6)"/>&#160;<xsl:value-of select="substring(dis:OffId, 7)"/>&#160;</div>
		<xsl:if test="dis:DateOfDeath"><div><b>Dødsdato:&#160;</b><xsl:value-of select="dis:DateOfDeath/@V"/>&#160;</div></xsl:if>
		<xsl:apply-templates select="dis:Address"/>
	</xsl:template>
	<xsl:template match="dis:HCPerson">
		<div><xsl:value-of select="dis:Name"/>&#160;</div>
		<xsl:apply-templates select="dis:Address"/>
	</xsl:template>
	<xsl:template match="dis:HCP">
		<xsl:apply-templates select="dis:Inst"/>
		<xsl:apply-templates select="dis:HCProf"/>
		<xsl:apply-templates select="dis:Address"/>
	</xsl:template>
	<xsl:template match="dis:Inst">
		<xsl:apply-templates select="dis:HCPerson"/>
		<div><div class="NoPrint"><b>Institusjon:&#160;</b></div><xsl:value-of select="dis:Name"/></div>
		<xsl:for-each select="dis:Dept"><div><div class="NoPrint">-&#160;</div><xsl:value-of select="dis:Name"/>&#160;</div></xsl:for-each>
	</xsl:template>
	<xsl:template match="dis:HCProf">
		<div><xsl:if test="dis:Type"><xsl:value-of select="dis:Type/@DN"/>&#160;</xsl:if><xsl:value-of select="dis:Name"/></div>
	</xsl:template>
	<xsl:template match="dis:CopyDest">
		<xsl:apply-templates select="dis:HCP"/>
	</xsl:template>
	<xsl:template match="dis:Address">
		<xsl:if test="dis:Type">
			<div class="NoPrint">&#160;<b><xsl:choose><xsl:when test="dis:Type/@DN"><xsl:value-of select="dis:Type/@DN"/>:&#160;</xsl:when><xsl:otherwise>Adresse:&#160;</xsl:otherwise></xsl:choose></b></div>
		</xsl:if>
		<xsl:if test="dis:StreetAdr">
			<div><xsl:value-of select="dis:StreetAdr"/></div>
		</xsl:if>
		<xsl:if test="dis:PostalCode or dis:City">
			<xsl:if test="dis:StreetAdr">
				<div class="NoPrint">,</div>
			</xsl:if>
			<div><xsl:value-of select="dis:PostalCode"/>&#160;<xsl:value-of select="dis:City"/></div>
		</xsl:if>
		<xsl:if test="dis:CityDistr">
			<div class="NoPrint">,</div>
			<div><xsl:value-of select="dis:CityDistr/@DN"/></div>
		</xsl:if>
		<xsl:if test="dis:County">
			<div class="NoPrint">,</div>
			<div><xsl:value-of select="dis:County/@DN"/></div>
		</xsl:if>
		<xsl:if test="dis:Country">
			<div class="NoPrint">,</div>
			<div><xsl:value-of select="dis:Country/@DN"/></div>
		</xsl:if>
		<xsl:for-each select="dis:TeleAddress">
			<div class="NoPrint">&#160;</div>
			<xsl:apply-templates select="."/>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="dis:TeleAddress">
		<xsl:if test="starts-with(@V, &quot;tel:&quot;) or starts-with(@V, &quot;callto:&quot;)">
			<div><b>Telefon:</b>&#160;<xsl:value-of select="substring-after(@V, &quot;:&quot;)"/>&#160;</div>
		</xsl:if>
		<xsl:if test="starts-with(@V, &quot;fax:&quot;)">
			<div><b>Faks:</b>&#160;<xsl:value-of select="substring-after(@V, &quot;:&quot;)"/>&#160;</div>
		</xsl:if>
		<xsl:if test="starts-with(@V, &quot;mailto:&quot;)">
			<div><b>e-post:</b>&#160;<xsl:value-of select="substring-after(@V, &quot;:&quot;)"/>&#160;</div>
		</xsl:if>
	</xsl:template>
	<xsl:template match="dis:Event">
		<xsl:apply-templates select="dis:InfItem"/>
		<!-- Struktur for å samle medisin-informasjon -->
		<xsl:if test="dis:InfItem/dis:Medication">
			<h3>Legemidler</h3>
			<table width="100%">
				<tbody>
					<tr>
						<td>
							<table width="100%">
								<tbody>
									<tr>
										<th width="20%">Legemiddel</th>
										<th width="10%">Styrke</th>
										<th width="15%">Dosering</th>
										<th width="20%">Status</th>
										<th width="10%">Planlagt varighet</th>
										<th width="15%">Kommentar</th>
									</tr>
									<xsl:for-each select="dis:InfItem/dis:Medication">
										<tr>
											<td>
												<xsl:value-of select="dis:DrugId/@DN"/>
												<xsl:value-of select="dis:DrugId/@OT"/>
											</td>
											<td>
												<xsl:value-of select="dis:UnitDose/@V"/>
												<xsl:value-of select="dis:UnitDose/@U"/>
											</td>
											<td>
												<xsl:value-of select="dis:DosageText"/>
												<!-- <xsl:if test="dis:DosageCoded">(Kodet: <xsl:value-of select="dis:DosageCoded/@DN"/>)</xsl:if> -->
											</td>
											<td>
												<xsl:apply-templates select="dis:Status"/>
											</td>
											<td>
												<xsl:value-of select="dis:IntendedDuration/@V"/>
												<xsl:value-of select="dis:IntendedDuration/@U"/>
											</td>
											<td>
												<xsl:value-of select="dis:Comment"/>
											</td>
										</tr>
										<xsl:if test="../dis:StartDateTime or ../dis:EndDateTime or ../dis:OrgDate">
											<tr>
												<th>Starttidspunkt</th>
												<td>
													<xsl:value-of select="../dis:StartDateTime/@V"/>
												</td>
												<th>Sluttidspunkt</th>
												<td>
													<xsl:value-of select="../dis:EndDateTime/@V"/>
												</td>
												<th>Tidspunkt for opprinnelse</th>
												<td>
													<xsl:value-of select="../dis:OrgDate/@V"/>
												</td>
											</tr>
										</xsl:if>
										<!--<xsl:if test="dis:Comment">
											<tr>
												<th>Kommentar</th>
												<td colspan="6">
													<xsl:apply-templates select="dis:Comment"/>
												</td>
											</tr>
										</xsl:if>-->
										<xsl:if test="../dis:Origin">
											<tr>
												<th>Opphav til opplysningen</th>
												<td colspan="5">
													<xsl:apply-templates select="../dis:Origin/dis:HCP"/>
												</td>
											</tr>
										</xsl:if>
										<xsl:for-each select="../dis:RelHCProvider">
											<tr>
												<th colspan="2">Tilknyttet klinisk tjenesteyter - <xsl:apply-templates select="/dis:Relation"/>
												</th>
												<td colspan="4">
													<xsl:apply-templates select="dis:HCP"/>
												</td>
											</tr>
										</xsl:for-each>
									</xsl:for-each>
								</tbody>
							</table>
						</td>
					</tr>
				</tbody>
			</table>
		</xsl:if>
		<xsl:apply-templates select="dis:Comment"/>
		<h2>
			<xsl:choose>
				<xsl:when test="dis:PlannedEvent">Planlagt&#160;</xsl:when>
				<xsl:otherwise>Rapportert&#160;</xsl:otherwise>
			</xsl:choose>hendelse</h2>
		<table width="100%">
			<tbody>
				<tr>
					<th colspan="6">Informasjon om hendelsen - <xsl:apply-templates select="dis:ServType"/>
					</th>
				</tr>
				<tr>
					<xsl:if test="dis:Service/dis:Id">
						<th>Identifikasjon/Spesifikasjon</th>
						<td>
							<xsl:value-of select="dis:Service/dis:ServId/@DN"/>
						</td>
					</xsl:if>
					<xsl:if test="dis:Service/dis:MedSpeciality">
						<th>Medisinsk spesialitet</th>
						<td>
							<xsl:value-of select="dis:Service/dis:MedSpeciality/@DN"/>
						</td>
					</xsl:if>
					<xsl:if test="dis:Service/dis:AdmCat">
						<th>Pasientadministrativ type tjeneste</th>
						<td>
							<xsl:apply-templates select="dis:Service/dis:AdmCat"/>
						</td>
					</xsl:if>
					<th>Mottaker av tjenesten</th>
					<td>
						<xsl:apply-templates select="dis:Recipient"/>
					</td>
				</tr>
				<xsl:for-each select="dis:ReportedEvent">
					<tr>
						<th>Startdato</th>
						<td>
							<xsl:value-of select="dis:StartDateTime/@V"/>
						</td>
						<th>Sluttdato</th>
						<td>
							<xsl:value-of select="dis:EndDateTime/@V"/>
						</td>
					</tr>
				</xsl:for-each>
				<tr>
					<th>Utskrivningsmåte</th>
					<td>
						<xsl:apply-templates select="dis:AdmOutcome"/>
					</td>
					<th>Hastegrad</th>
					<td>
						<xsl:apply-templates select="dis:Priority"/>
					</td>
					<th>Forventet varighet</th>
					<td>
						<xsl:value-of select="dis:ExpDuration/@V"/>&#160;<xsl:value-of select="dis:ExpDuration/@U"/>
					</td>
				</tr>
				<xsl:for-each select="dis:PlannedEvent">
					<tr>
						<th>Planleggingstrinn</th>
						<td>
							<xsl:apply-templates select="dis:PlanningStage"/>
						</td>
						<th>Status for planen</th>
						<td>
							<xsl:choose>
								<xsl:when test="dis:StatusOfPlan/@V='1'">Foreslått</xsl:when>
								<xsl:otherwise>Bestilt</xsl:otherwise>
							</xsl:choose>
						</td>
					</tr>
					<xsl:if test="dis:PlanComment">
						<tr>
							<th>Kommentar til status</th>
							<td>
								<xsl:value-of select="dis:PlanComment"/>
							</td>
						</tr>
					</xsl:if>
					<tr>
						<th>Planleggingstidspunkt</th>
						<td>
							<xsl:value-of select="dis:PlanningDate/@V"/>
						</td>
						<th>Planlagt tidspunkt</th>
						<td>
							<xsl:value-of select="dis:ScheduledDate/@V"/>
						</td>
						<th>Råd gitt til</th>
						<td>
							<xsl:apply-templates select="dis:AdviceSentTo"/>
						</td>
					</tr>
					<tr>
						<th>Forventet ventetid</th>
						<td>
							<xsl:value-of select="dis:ExpectedDelay/@V"/>&#160;<xsl:value-of select="dis:ExpectedDelay/@U"/>
						</td>
						<th>Kommentar til ventetid</th>
						<td>
							<xsl:value-of select="dis:CommentExpDuration"/>
						</td>
					</tr>
					<xsl:if test="dis:Preparation">
						<tr>
							<th>Instruksjon</th>
							<td>
								<xsl:value-of select="dis:Preparation"/>
							</td>
						</tr>
					</xsl:if>
					<xsl:if test="dis:Advice">
						<tr>
							<th>Råd til pasient</th>
							<td>
								<xsl:value-of select="dis:Advice"/>
							</td>
						</tr>
					</xsl:if>
					<xsl:for-each select="dis:TransportArr">
						<tr>
							<th colspan="6">Pasienttransportforberedelse</th>
						</tr>
						<tr>
							<th>Ansvarlig</th>
							<td>
								<xsl:apply-templates select="dis:Responsibility"/>
							</td>
							<th>Status</th>
							<td>
								<xsl:apply-templates select="dis:Status"/>
							</td>
						</tr>
						<tr>
							<th>Behov for ledsagelse</th>
							<td>
								<xsl:apply-templates select="dis:EscortRequired"/>
							</td>
						</tr>
						<tr>
							<th>Kommentar</th>
							<td>
								<xsl:value-of select="dis:Comment"/>
							</td>
						</tr>
					</xsl:for-each>
				</xsl:for-each>
				<!-- Planned event -->
				<xsl:for-each select="dis:EventLocation">
					<tr>
						<th colspan="6">
							<xsl:choose>
								<xsl:when test="dis:Role">
									<xsl:apply-templates select="dis:Role"/>
								</xsl:when>
								<xsl:otherwise>Sted</xsl:otherwise>
							</xsl:choose>
						</th>
					</tr>
					<tr>
						<th>Sted</th>
						<td>
							<xsl:apply-templates select="dis:Location/dis:Inst"/>
							<br/>
							<xsl:apply-templates select="dis:Location/dis:Address"/>
						</td>
						<xsl:if test="dis:Location/dis:SubLocation">
							<th>
								<xsl:apply-templates select="dis:Type"/>
							</th>
							<td>
								<xsl:value-of select="dis:Location/dis:SubLocation/dis:Place"/>
							</td>
						</xsl:if>
					</tr>
					<tr>
						<th>Starttidspunkt</th>
						<td>
							<xsl:value-of select="dis:StartDateTime/@V"/>
						</td>
						<th>Sluttidspunkt</th>
						<td>
							<xsl:value-of select="dis:EndDateTime/@V"/>
						</td>
					</tr>
				</xsl:for-each>
				<!-- eventlocation -->
			</tbody>
		</table>
		<!--</xsl:if>-->
		<xsl:if test="dis:CodedComment">
			<h3>Kodede kommentarer til hendelsen</h3>
			<xsl:for-each select="dis:CodedComment">
				<!-- Støttes kun hvis DN er oppgitt -->
				Kode:&#160;<xsl:value-of select="dis:Concept/@DN"/>
				<br/>
				Modifikatorer:<br/>
				<xsl:for-each select="dis:Modifier">
					<xsl:choose>
						<xsl:when test="dis:Name/@V='S'">ICD10 stjernekode:&#160;</xsl:when>
						<xsl:otherwise>ICD10 ATC-kode:&#160;</xsl:otherwise>
					</xsl:choose>
					<xsl:value-of select="dis:Value/@DN"/>
				</xsl:for-each>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>
	<xsl:template match="dis:InfItem">
		<xsl:if test="not(dis:Medication)">
			<!-- Medication håndteres samlet i Event -->
			<h3>
				<xsl:apply-templates select="dis:Type"/>
			</h3>
			<table width="100%">
				<tbody>
					<xsl:if test="dis:StartDateTime or dis:EndDateTime or dis:OrgDate">
						<tr>
							<th>Starttidspunkt</th>
							<td>
								<xsl:value-of select="dis:StartDateTime/@V"/>
							</td>
							<th>Sluttidspunkt</th>
							<td>
								<xsl:value-of select="dis:EndDateTime/@V"/>
							</td>
							<th>Tidspunkt for opprinnelse</th>
							<td>
								<xsl:value-of select="dis:OrgDate/@V"/>
							</td>
						</tr>
					</xsl:if>
					<tr>
						<td colspan="6">
							<xsl:apply-templates select="dis:Observation"/>
							<xsl:apply-templates select="dis:ResultItem"/>
						</td>
						<!-- nested table med infitem'et -->
					</tr>
					<xsl:if test="dis:Origin">
						<tr>
							<th>Opphav til opplysningen</th>
							<td colspan="5">
								<xsl:apply-templates select="dis:Origin/dis:HCP"/>
							</td>
						</tr>
					</xsl:if>
					<xsl:for-each select="dis:RelHCProvider">
						<tr>
							<th colspan="2">Tilknyttet klinisk tjenesteyter - <xsl:apply-templates select="dis:Relation"/>
							</th>
							<td colspan="4">
								<xsl:apply-templates select="dis:HCP"/>
							</td>
						</tr>
					</xsl:for-each>
				</tbody>
			</table>
		</xsl:if>
	</xsl:template>
	<xsl:template match="dis:Observation">
		<table width="100%">
			<tbody>
				<xsl:if test="dis:Description">
					<tr>
						<td>
							<xsl:apply-templates select="dis:Description"/>
						</td>
					</tr>
				</xsl:if>
				<xsl:if test="dis:Comment">
					<!--<tr>
						<th>Kommentar</th>
					</tr>-->
					<tr>
						<td>
							<b>Kommentar</b>
							<br/>
							<xsl:value-of select="dis:Comment"/>
						</td>
					</tr>
				</xsl:if>
				<xsl:if test="dis:CodedDescr">
					<tr>
						<td>
							<xsl:apply-templates select="dis:CodedDescr"/>
						</td>
					</tr>
				</xsl:if>
			</tbody>
		</table>
	</xsl:template>
	<xsl:template match="dis:Observation/dis:CodedDescr">
		<xsl:value-of select="dis:Concept/@V"/>&#160;-&#160;<xsl:value-of select="dis:Concept/@DN"/>
		<xsl:for-each select="dis:Modifier">,&#160;
			<xsl:choose>
				<xsl:when test="dis:Name/@V='S'">ICD10 stjernekode:&#160;</xsl:when>
				<xsl:otherwise>ICD10 ATC-kode:&#160; </xsl:otherwise>
			</xsl:choose>
			<xsl:value-of select="dis:Value/@DN"/>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="dis:ResultItem">
		<table>
			<tbody>
				<tr>
					<th>Undersøkelsesresultat - <xsl:apply-templates select="dis:ServType"/>
						<xsl:if test="dis:InvDate"> - <xsl:value-of select="dis:InvDate/@V"/>
						</xsl:if>
					</th>
				</tr>
				<tr>
					<th>Undersøkelse</th>
					<td>
						<xsl:value-of select="dis:ClinInv/dis:Id/@DN"/>
						<xsl:value-of select="dis:ClinInv/dis:Id/@OT"/>
					</td>
				</tr>
				<tr>
					<th>Resultat</th>
					<td>
						<xsl:apply-templates/>
					</td>
				</tr>
			</tbody>
		</table>
	</xsl:template>
	<xsl:template match="dis:TextResult/dis:Result">
		<b>
			<xsl:apply-templates select="dis:Heading"/>
		</b>
		<br/>
		<xsl:apply-templates select="dis:TextResultValue"/>
		<br/>
		<xsl:value-of select="dis:TextCode/@DN"/>
	</xsl:template>
	<xsl:template match="dis:Interval">
		Intervall: <xsl:value-of select="dis:Low/@V"/>
		<xsl:value-of select="dis:Low/@U"/> - <xsl:value-of select="dis:High/@V"/>
		<xsl:value-of select="dis:Low/@U"/>
	</xsl:template>
	<xsl:template match="dis:NumResult">
		<xsl:apply-templates select="dis:ArithmeticComp"/>&#160;<xsl:value-of select="dis:NumResultValue/@V"/>&#160;<xsl:value-of select="dis:NumResultValue/@U"/>
	</xsl:template>
	<xsl:template match="dis:DateResult">
		<xsl:value-of select="dis:DateResultValue/@V"/>
	</xsl:template>
	<xsl:template match="dis:Comment | dis:ReasonAsText">
		<xsl:if test="dis:Heading">
			<h3>
				<xsl:apply-templates select="dis:Heading"/>
			</h3>
		</xsl:if>
		<table>
			<tr>
				<td>
					<xsl:if test="dis:TextResultValue">
						<xsl:apply-templates select="dis:TextResultValue"/>
					</xsl:if>
					<xsl:for-each select="dis:TextCode">
						<p>Kode: <xsl:value-of select="./@V"/>&#160;-&#160;<xsl:value-of select="./@DN"/>
						</p>
					</xsl:for-each>
				</td>
			</tr>
		</table>
	</xsl:template>
	<xsl:template match="dis:Message">
		<!-- utelater meldingsid og kommunikasjonsinformasjon -->
		<xsl:apply-templates select="dis:ServRprt"/>
	</xsl:template>
	<xsl:template match="dis:ServRprt">
		<xsl:call-template name="Header"/>
		<div class="Document">
			<h1>Epikrise<xsl:if test="dis:SrvType/@DN"> - <xsl:value-of select="dis:SrvType/@DN"/>
				</xsl:if>
			</h1>
			<table width="100%">
				<tbody>
					<tr>
						<th width="12.5%">Status</th>
						<td width="12.5%">
							<xsl:apply-templates select="dis:ServType"/> - <xsl:apply-templates select="dis:Status"/>
						</td>
						<th width="12.5%">Utstedt</th>
						<td width="12.5%">
							<xsl:call-template name="skrivUtDateTime">
								<xsl:with-param name="oppgittTid" select="dis:IssueDate/@V"/>
							</xsl:call-template>
						</td>
						<th width="12.5%">Godkjent</th>
						<td width="12.5%">
							<xsl:call-template name="skrivUtDateTime">
								<xsl:with-param name="oppgittTid" select="dis:ApprDate/@V"/>
							</xsl:call-template>
						</td>
						<th width="12.5%">Hastegrad</th>
						<td width="12.5%">
							<xsl:apply-templates select="dis:Priority"/>
						</td>
					</tr>
					<tr>
						<th>Type epikrise</th>
						<td colspan="7">
							<xsl:value-of select="dis:MsgDescr"/>
						</td>
					</tr>
				</tbody>
			</table>
			<xsl:apply-templates select="dis:Event"/>
			<xsl:if test="dis:Patient/dis:DateOfDeath | dis:Patient/dis:MaritalStatus | dis:Patient/dis:AdditionalId | dis:Patient/dis:PatientPrecaution |dis:Patient/dis:Sex">
				<h2>Øvrig pasientinformasjon</h2>
				<xsl:for-each select="dis:Patient">
					<table width="100%">
						<tbody>
							<tr>
								<th colspan="10">Pasientinformasjon</th>
							</tr>
							<tr>
								<th width="10%">Navn</th>
								<td width="10%">
									<xsl:value-of select="dis:Name"/>
								</td>
								<th width="10%">Kjønn</th>
								<td width="10%">
									<xsl:apply-templates select="dis:Sex"/>
								</td>
								<th width="10%">Fødselsdato</th>
								<td width="10%">
									<xsl:value-of select="dis:DateOfBirth/@V"/>
								</td>
								<xsl:if test="dis:DateOfDeath">
									<th width="10%">Dødsdato</th>
									<td width="10%">
										<xsl:value-of select="dis:DateOfDeath/@V"/>
									</td>
								</xsl:if>
								<th width="10%">Sivilstatus</th>
								<td width="10%">
									<xsl:apply-templates select="dis:MaritalStatus"/>
								</td>
							</tr>
							<xsl:if test="dis:AdditionalId">
								<tr>
									<th>Andre identifikatorer</th>
								</tr>
								<xsl:for-each select="dis:AdditionalID">
									<tr>
										<th>
											<xsl:value-of select="dis:Type/@V"/>
										</th>
										<td>
											<xsl:value-of select="dis:Id"/>
										</td>
									</tr>
								</xsl:for-each>
							</xsl:if>
							<xsl:if test="dis:PatientPrecaution">
								<tr>
									<th colspan="8">Advarsel til tjenesteyter</th>
								</tr>
								<xsl:for-each select="dis:PatientPrecaution">
									<tr>
										<th>Advarsel</th>
										<td colspan="3">
											<xsl:value-of select="dis:Precaution"/>
										</td>
										<th>Gyldig fra</th>
										<td>
											<xsl:value-of select="dis:StartDateTime/@V"/>&#160;</td>
										<th>Gyldig til</th>
										<td>
											<xsl:value-of select="dis:EndDateTime/@V"/>&#160;</td>
									</tr>
								</xsl:for-each>
							</xsl:if>
						</tbody>
					</table>
					<br/>
				</xsl:for-each>
			</xsl:if>
			<xsl:if test="dis:Patient/dis:PatRelHCP">
				<h2>Pasientrelatert helsetjenesteyter</h2>
				<table width="100%">
					<tbody>
						<xsl:for-each select="dis:Patient/dis:PatRelHCP">
							<tr>
								<th width="10%">Rolle</th>
								<td width="20%">
									<xsl:choose>
										<xsl:when test="dis:Relation/@DN"><xsl:value-of select="dis:Relation/@DN"/></xsl:when>
										<xsl:otherwise><xsl:value-of select="dis:Relation/@V"/></xsl:otherwise>
									</xsl:choose>
								</td>
								<th width="10%">Person/enhet</th>
								<td width="20%">
									<xsl:apply-templates select="dis:HCP"/>
								</td>
								<th width="10%">Fra dato</th>
								<td width="10%">
									<xsl:value-of select="dis:StartDateTime/@V"/>
								</td>
								<th width="10%">Til dato</th>
								<td width="10%">
									<xsl:value-of select="dis:EndDateTime/@V"/>
								</td>
							</tr>
						</xsl:for-each>
					</tbody>
				</table>
				<br/>
			</xsl:if>
			<xsl:if test="dis:PatientRelParty">
				<h2>Pasientrelatert part</h2>
				<table>
					<tbody>
						<tr>
							<th colspan="6">Pasientrelatert part</th>
						</tr>
						<xsl:for-each select="dis:PatientRelParty">
							<tr>
								<th>Relasjon</th>
								<td>
									<xsl:apply-templates select="dis:Relation"/>
								</td>
								<th>Navn</th>
								<td>
									<xsl:value-of select="dis:Name"/>
								</td>
								<th>Offentlig id</th>
								<td>
									<xsl:value-of select="dis:RelPartyOffId"/>
								</td>
							</tr>
						</xsl:for-each>
					</tbody>
				</table>
				<br/>
			</xsl:if>
			<xsl:if test="dis:ServReq">
				<h2>Opprinnelig henvisning</h2>
				<table width="100%">
					<tbody>
						<tr>
							<th width="12%">Utstedt dato</th>
							<td width="12%">
								<xsl:value-of select="dis:ServReq/dis:IssueDate/@V"/>
							</td>
							<th width="12%">Mottatt dato</th>
							<td width="12%">
								<xsl:value-of select="dis:ServReq/dis:ReceiptDate/@V"/>
							</td>
							<th width="12%">Kommentar</th>
							<td width="12%">
								<xsl:value-of select="dis:ServReq/dis:ReqComment"/>
							</td>
							<th width="12%">Beskrivelse</th>
							<td width="16%">
								<xsl:apply-templates select="dis:ServReq/dis:MsgDescr"/>
							</td>
						</tr>
						<xsl:if test="dis:ServReq/dis:ReasonAsText">
							<tr>
								<td>
									<xsl:apply-templates select="dis:ServReq/dis:ReasonAsText"/>
								</td>
							</tr>
						</xsl:if>
						<xsl:if test="dis:ServReq/dis:Diagnosis">
							<tr>
								<th colspan="8">Henvisningsdiagnose(r)</th>
							</tr>
							<tr>
								<td colspan="8">
									<xsl:apply-templates select="dis:ServReq/dis:Diagnosis"/>
								</td>
							</tr>
						</xsl:if>
					</tbody>
				</table>
			</xsl:if>
		</div>
		<xsl:call-template name="Footer"/>
	</xsl:template>
	<xsl:template match="dis:TextResultValue | dis:Description">
		<xsl:choose>
			<xsl:when test="count(.//*) >=1">
				<xsl:copy-of select="node()"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="line-breaks">
					<xsl:with-param name="text">
						<xsl:value-of select="."/>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Diagnosis">
			Kode:&#160;<xsl:value-of select="dis:Concept/@V"/> - Kodetekst: <xsl:value-of select="dis:Concept/@DN"/>
		<xsl:if test="dis:Modifier">	Modifikatorer:<br/>
			<xsl:for-each select="dis:Modifier">
				<xsl:choose>
					<xsl:when test="dis:Name/@V='S'">ICD10 stjernekode:&#160;</xsl:when>
					<xsl:otherwise>ICD10 ATC-kode:&#160;</xsl:otherwise>
				</xsl:choose>
				<xsl:value-of select="dis:Value/@DN"/>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>
	<!-- Funksjoner for kodeverk -->
	<xsl:template match="dis:ServType">
		<xsl:choose>
			<xsl:when test="@V='N'">Ny</xsl:when>
			<xsl:when test="@V='M'">Endring</xsl:when>
			<xsl:when test="@V='C'">Kansellering</xsl:when>
			<xsl:when test="@V='A'">Tillegg</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:ServRprt/dis:Status">
		<xsl:choose>
			<xsl:when test="@V='A'">Tillegg til rapport</xsl:when>
			<xsl:when test="@V='F'">Endelig rapport</xsl:when>
			<xsl:when test="@V='P'">Foreløpig rapport</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:ServRprt/dis:Priority">
		<xsl:choose>
			<xsl:when test="@V='DATO'">Innen dato/klokkeslett</xsl:when>
			<xsl:when test="@V='NORM'">Normal</xsl:when>
			<xsl:when test="@V='OHJELP'">Øyeblikkelig hjelp</xsl:when>
			<xsl:when test="@V='TEL'">Besvares pr. telefon</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Patient/dis:Sex">
		<xsl:choose>
			<xsl:when test="@V='1'">Mann</xsl:when>
			<xsl:when test="@V='2'">Kvinne</xsl:when>
			<xsl:when test="@V='9'">Ikke spesifisert</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:PatientRelParty/dis:Relation">
		<xsl:choose>
			<xsl:when test="@V='FAR'">Far</xsl:when>
			<xsl:when test="@V='MOR'">Mor</xsl:when>
			<xsl:when test="@V='SØN'">Sønn</xsl:when>
			<xsl:when test="@V='DTR'">Datter</xsl:when>
			<xsl:when test="@V='BBN'">Barnebarn</xsl:when>
			<xsl:when test="@V='ASL'">Annen slektning</xsl:when>
			<xsl:when test="@V='VEN'">Venn</xsl:when>
			<xsl:when test="@V='KOL'">Arbeidskollega</xsl:when>
			<xsl:when test="@V='NBO'">Nabo</xsl:when>
			<xsl:when test="@V='ARE'">Annen relasjon</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Event/dis:Recipient">
		<xsl:choose>
			<xsl:when test="@V='1'">Pasienten selv</xsl:when>
			<xsl:when test="@V='2'">Pasienten og pårørende</xsl:when>
			<xsl:when test="@V='9'">Pasient og barn</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Service/dis:AdmCat">
		<xsl:choose>
			<xsl:when test="@V='1'">Heldøgnsopphold (7 dager i uken)</xsl:when>
			<xsl:when test="@V='2'">Dagbehandling</xsl:when>
			<xsl:when test="@V='3'">Poliklinisk omsorg</xsl:when>
			<xsl:when test="@V='4'">Telekonsultasjon</xsl:when>
			<xsl:when test="@V='5'">Konsultasjon</xsl:when>
			<xsl:when test="@V='6'">Telefonkonsultasjon</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Event/dis:Priority">
		<xsl:choose>
			<xsl:when test="@V='0'">Umiddelbart</xsl:when>
			<xsl:when test="@V='1'">Innen 24 timer</xsl:when>
			<xsl:when test="@V='180'">Innen 6 måneder</xsl:when>
			<xsl:when test="@V='2'">Innen 2 døgn</xsl:when>
			<xsl:when test="@V='30'">Innen en måned</xsl:when>
			<xsl:when test="@V='7'">Innen en uke</xsl:when>
			<xsl:when test="@V='90'">Innen 3 måneder</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Event/dis:AdmOutcome">
		<xsl:choose>
			<xsl:when test="@V='1'">Vanlig bosted, arbeidssted mv.</xsl:when>
			<xsl:when test="@V='2'">Som død</xsl:when>
			<xsl:when test="@V='3'">Annen institusjon (inklusiv psykiatrisk avd. ved egen inst.)</xsl:when>
			<xsl:when test="@V='4'">Sykehus i utlandet</xsl:when>
			<xsl:when test="@V='6'">Annet</xsl:when>
			<xsl:when test="@V='9'">Annen somatisk avdeling ved egen institusjon</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:PlannedEvent/dis:PlanningStage">
		<xsl:choose>
			<xsl:when test="@V='1'">Foreslått</xsl:when>
			<xsl:when test="@V='2'">Bestillt</xsl:when>
			<xsl:when test="@V='3'">Avtalt</xsl:when>
			<xsl:when test="@V='4'">Utsatt</xsl:when>
			<xsl:when test="@V='6'">Kansellert</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:PlannedEvent/dis:AdviceSentTo">
		<xsl:choose>
			<xsl:when test="@V='1'">Til pasienten direkte</xsl:when>
			<xsl:when test="@V='2'">Til pasientens lege</xsl:when>
			<xsl:when test="@V='3'">Til pårørende</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:TransportArr/dis:Responsibility">
		<xsl:choose>
			<xsl:when test="@V='1'">Henvisende instans</xsl:when>
			<xsl:when test="@V='2'">Tjenesteyter</xsl:when>
			<xsl:when test="@V='3'">Pasienten selv</xsl:when>
			<xsl:when test="@V='4'">Pårørende</xsl:when>
			<xsl:when test="@V='9'">Uspesifisert</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:TransportArr/dis:Status">
		<xsl:choose>
			<xsl:when test="@V='1'">Foreslått</xsl:when>
			<xsl:when test="@V='2'">Bestilt</xsl:when>
			<xsl:when test="@V='3'">Tildelt</xsl:when>
			<xsl:when test="@V='9'">Ikke kjent</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:TransportArr/dis:EscortRequired">
		<xsl:choose>
			<xsl:when test="@V='1'">Trenger ledsager</xsl:when>
			<xsl:when test="@V='2'">Blir ledsaget</xsl:when>
			<xsl:when test="@V='3'">Klarer seg alene</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:EventLocation/dis:Role">
		<xsl:choose>
			<xsl:when test="@V='1'">Oppholdssted</xsl:when>
			<xsl:when test="@V='2'">Innlagt fra</xsl:when>
			<xsl:when test="@V='3'">Utskrevet til</xsl:when>
			<xsl:when test="@V='4'">Sted for hendelse</xsl:when>
			<xsl:when test="@V='5'">Skadested</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:SubLocation/dis:Type">
		<xsl:choose>
			<xsl:when test="@V='1'">Seksjon</xsl:when>
			<xsl:when test="@V='2'">Sengepost</xsl:when>
			<xsl:when test="@V='3'">Rom</xsl:when>
			<xsl:when test="@V='4'">Seng</xsl:when>
			<xsl:when test="@V='5'">Operasjonsstue</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Comment/dis:Heading">
		<xsl:choose>
			<xsl:when test="@V='TB'">Tilbakemelding (uspes.)</xsl:when>
			<xsl:when test="@V='TS'">Tidligere sykdom</xsl:when>
			<xsl:when test="@V='ME'">Medisinering</xsl:when>
			<xsl:when test="@V='LR'">Laboratorieresultat</xsl:when>
			<xsl:when test="@V='ÅI'">Årsak til innleggelse</xsl:when>
			<xsl:when test="@V='FA'">Familie/sosialt</xsl:when>
			<xsl:when test="@V='FU'">Funn og undersøkelsesresultater</xsl:when>
			<xsl:when test="@V='FO'">Forløp og behandling</xsl:when>
			<xsl:when test="@V='UP'">Ubesvarte prøver</xsl:when>
			<xsl:when test="@V='HJ'">Funksjonsnivå/hjelpetiltak</xsl:when>
			<xsl:when test="@V='VU'">Vurdering</xsl:when>
			<xsl:when test="@V='OP'">Planer for videre oppfølging</xsl:when>
			<xsl:when test="@V='SY'">Sykmelding</xsl:when>
			<xsl:when test="@V='IP'">Informasjon til pasient/pårørende</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:InfItem/dis:Type">
		<xsl:choose>
			<xsl:when test="@V='H'">Hoveddiagnose</xsl:when>
			<xsl:when test="@V='B'">Bidiagnose</xsl:when>
			<xsl:when test="@V='MEDB'">Legemiddelopplysning</xsl:when>
			<xsl:when test="@V='OPIN'">Inngrep/operasjon</xsl:when>
			<xsl:when test="@V='MPRS'">Medisinsk prosedyre</xsl:when>
			<xsl:when test="@V='PRS'">Andre prosedyrer</xsl:when>
			<xsl:when test="@V='PROG'">Prognose</xsl:when>
			<xsl:when test="@V='ANAM'">Sykehistorie</xsl:when>
			<xsl:when test="@V='CAVE'">Cave-opplysninger</xsl:when>
			<xsl:when test="@V='NB'">NB-opplysninger</xsl:when>
			<xsl:when test="@V='GBEH'">Tidligere gynekologisk behandling</xsl:when>
			<xsl:when test="@V='GOPL'">Gynekologiske opplysninger</xsl:when>
			<xsl:when test="@V='OPPL'">Klinisk opplysning (uspes.)</xsl:when>
			<xsl:when test="@V='SYKM'">Opplysninger om sykemelding</xsl:when>
			<xsl:when test="@V='SYMP'">Symptom</xsl:when>
			<xsl:when test="@V='TIDBL'">Tidligere behandling</xsl:when>
			<xsl:when test="@V='TB'">Tidligere behandling</xsl:when>
			<xsl:when test="@V='US'">Tidligere undersøkelse</xsl:when>
			<xsl:when test="@V='SM'">Smitte</xsl:when>
			<xsl:when test="@V='FUNN'">Funn/undersøkelsesresultat</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:RelHCProvider/dis:Relation">
		<xsl:choose>
			<xsl:when test="@V='ANL'">Anestesist</xsl:when>
			<xsl:when test="@V='AUT'">Dokumentgodkjenner</xsl:when>
			<xsl:when test="@V='BLE'">Behandlende lege</xsl:when>
			<xsl:when test="@V='ISS'">Dokumentutsteder</xsl:when>
			<xsl:when test="@V='OPL'">Operatør</xsl:when>
			<xsl:when test="@V='REG'">Person som har registrert opplysningen</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Medication/dis:Status">
		<xsl:choose>
			<xsl:when test="@V='1'">Inntatt</xsl:when>
			<xsl:when test="@V='2'">Forskrevet</xsl:when>
			<xsl:when test="@V='3'">Anbefalt å innta</xsl:when>
			<xsl:when test="@V='4'">Anbefalt å slutte å innta</xsl:when>
			<xsl:when test="@V='5'">Benyttes sporadisk</xsl:when>
			<xsl:when test="@V='6'">Benyttes regelmessig</xsl:when>
			<xsl:when test="@V='10'">Allergisk ovenfor</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Result/dis:Heading">
		<xsl:choose>
			<xsl:when test="@V='ME'">Medisinering</xsl:when>
			<xsl:when test="@V='LR'">Laboratorieresultat</xsl:when>
			<xsl:when test="@V='FU'">Funn og undersøkelsesresultater</xsl:when>
			<xsl:when test="@V='VU'">Vurdering</xsl:when>
			<xsl:when test="@V='OP'">Planer for videre oppfølging</xsl:when>
			<xsl:when test="@V='IP'">Informasjon til pasient/pårørende</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:NumResult/dis:ArithmeticComp">
		<xsl:choose>
			<xsl:when test="@V='EQ'">Lik</xsl:when>
			<xsl:when test="@V='GE'">Større eller lik</xsl:when>
			<xsl:when test="@V='GT'">Større</xsl:when>
			<xsl:when test="@V='LE'">Mindre eller lik</xsl:when>
			<xsl:when test="@V='LT'">Mindre</xsl:when>
			<xsl:when test="@V='NE'">Forskjellig</xsl:when>
			<xsl:when test="@V='MG'">Mye større</xsl:when>
			<xsl:when test="@V='ML'">Mye mindre</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dis:Patient/dis:MaritalStatus">
		<xsl:choose>
			<xsl:when test="@V='1'">Ugift</xsl:when>
			<xsl:when test="@V='2'">Gift</xsl:when>
			<xsl:when test="@V='3'">Enke(mann)</xsl:when>
			<xsl:when test="@V='4'">Separert</xsl:when>
			<xsl:when test="@V='5'">Skilt</xsl:when>
			<xsl:when test="@V='6'">Registrert partnerskap</xsl:when>
			<xsl:when test="@V='7'">Ukjent</xsl:when>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

