<?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/henvisning/2005-07-08" 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="yes" 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 Henvisning v.1.0

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

-->
	<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>Henvisning</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:Requester"/></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:ServProvider"/></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 and (dis:PostalCode or dis:City)">
			<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:if>
	</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:Message">
		<!-- utelater meldingsid og kommunikasjonsinformasjon -->
		<xsl:apply-templates select="dis:ServReq"/>
	</xsl:template>
	<xsl:template match="dis:ServReq">
		<xsl:call-template name="Header"/>
		<div class="Document">
			<h1>Henvisning</h1>
			<table width="95%">
				<tbody>
					<tr>
						<th width="12.5%">Status</th>
						<td width="12.5%">
							<xsl:value-of select="dis:ServType/@DN"/>
						</td>
						<th width="12.5%">Utstedt</th>
						<td width="12.5%">
							<xsl:value-of select="dis:IssueDate/@V"/>
						</td>
						<th width="12.5%">Betalingskategori</th>
						<td width="12.5%">
							<xsl:value-of select="dis:PaymentCat/@DN"/>
						</td>
						<th width="12.5%">Type henvisning</th>
						<td width="12.5%">
							<xsl:value-of select="dis:MsgDescr/@DN"/>
						</td>
					</tr>
					<xsl:if test="dis:ReqComment">
						<tr>
							<th>Kommentar</th>
							<td colspan="5">
								<xsl:value-of select="dis:ReqComment"/>
							</td>
						</tr>
					</xsl:if>
				</tbody>
			</table>
			<xsl:for-each select="dis:ReqServ">
				<table width="95%">
					<tbody>
						<xsl:if test="dis:Service">
							<tr>
								<th colspan="6">Rekvirert tjeneste</th>
							</tr>
							<xsl:if test="dis:Service/dis:ServId/@DN or dis:Service/dis:MedSpeciality/@DN or dis:Service/dis:AdmCat/@DN">
								<tr>
									<th>Tjeneste</th>
									<td width="15%">
										<xsl:value-of select="dis:Service/dis:ServId/@DN"/>
									</td>
									<th>Medisinsk spesialitet</th>
									<td width="15%">
										<xsl:value-of select="dis:Service/dis:MedSpeciality/@DN"/>
									</td>
									<th>Type tjeneste</th>
									<td width="15%">
										<xsl:value-of select="dis:Service/dis:AdmCat/@DN"/>
									</td>
								</tr>
							</xsl:if>
						</xsl:if>
						<xsl:if test="dis:Priority or dis:Purpose or dis:ReqDate">
							<xsl:choose>
								<xsl:when test="dis:ReqDate">
									<tr>
										<th width="12.5%">Hastegrad</th>
										<td width="12.5%">
											<xsl:value-of select="dis:Priority/@DN"/>
										</td>
										<th width="12.5%">Formål</th>
										<td width="12.5%">
											<xsl:value-of select="dis:Purpose/@DN"/>
										</td>
										<th width="12.5%">Ønsket starttidspunkt</th>
										<td width="37.5%">
											<xsl:value-of select="dis:ReqDate"/>
										</td>
									</tr>
								</xsl:when>
								<xsl:otherwise>
									<tr>
										<th width="12.5%">Hastegrad</th>
										<td width="37.5%">
											<xsl:value-of select="dis:Priority/@DN"/>
										</td>
										<th width="12.5%">Formål</th>
										<td width="37.5%">
											<xsl:value-of select="dis:Purpose/@DN"/>
										</td>
									</tr>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:if>
						<xsl:if test="dis:Comment">
							<tr>
								<th>Kommentar</th>
								<td colspan="5">
									<xsl:value-of select="dis:Comment"/>
								</td>
							</tr>
						</xsl:if>
					</tbody>
				</table>
			</xsl:for-each>
			<h2>Diagnoser</h2>
			<xsl:apply-templates select="dis:Diagnosis"/>
			<xsl:if test="dis:Patient/dis:InfItem[dis:Type/@V='CAVE']">
				<xsl:apply-templates select="dis:Patient/dis:InfItem[dis:Type/@V='CAVE']"/>
			</xsl:if>
			<h2>Årsak til henvisningen</h2>
			<xsl:apply-templates select="dis:ReasonAsText"/>
			<xsl:if test="dis:Comment">
				<h2>Kommentar til henvisningen</h2>
				<xsl:for-each select="dis:Comment">
					<h3>
						<xsl:value-of select="dis:Heading/@DN"/>
					</h3>
					<p>
						<xsl:value-of select="dis:TextResultValue"/>
					</p>
					<xsl:for-each select="dis:CodedComment">
						<p>Kode: <xsl:value-of select="./@V"/>&#160;-&#160;<xsl:value-of select="./@DN"/>
						</p>
					</xsl:for-each>
				</xsl:for-each>
			</xsl:if>
			<xsl:apply-templates select="dis:Patient" mode="full"/>
		</div>
		<xsl:call-template name="Footer"/>
	</xsl:template>
	<xsl:template match="dis:ServReq/dis:Diagnosis">
		<table>
			<tbody>
				<tr>
					<td>
						<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:when test="dis:Name/@V='A'">ATC-kode:&#160;</xsl:when>
								<xsl:otherwise>Ukjent kode:&#160;</xsl:otherwise>
							</xsl:choose>
							<xsl:value-of select="dis:Value/@V"/>&#160;-&#160;<xsl:value-of select="dis:Value/@DN"/>
						</xsl:for-each>
					</td>
				</tr>
			</tbody>
		</table>
	</xsl:template>
	<xsl:template match="dis:ServReq/dis:ReasonAsText">
		<xsl:if test="dis:Heading">
			<h3>
				<xsl:value-of select="dis:Heading/@DN"/>
			</h3>
		</xsl:if>
		<table>
			<tr>
				<td>
					<xsl:if test="dis:TextResultValue">
						<xsl:call-template name="line-breaks">
							<xsl:with-param name="text" select="dis:TextResultValue"/>
						</xsl:call-template>
					</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:Patient" mode="full">
		<xsl:apply-templates select="dis:InfItem"/>
		<!-- Viser overskifter og tekst -->
		<!-- Struktur for å samle medisin-informasjon -->
		<xsl:if test="dis:InfItem/dis:Medication">
			<h3>Legemidler</h3>
			<table width="95%">
				<tbody>
					<!--<tr>
					<th colspan="8">Medikament</th>
				</tr>-->
					<tr>
						<!--<td>&#160;</td>-->
						<td>
							<table width="100%">
								<tbody>
									<tr>
										<th width="20%">Legemiddel</th>
										<th width="10%">Styrke</th>
										<th width="30%">Dosering</th>
										<th width="20%">Status</th>
										<th width="20%">Planlagt varighet</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"/>
											</td>
											<td>
												<xsl:value-of select="dis:Status/@DN"/>
											</td>
											<td>
												<xsl:value-of select="dis:IntendedDuration/@V"/>
												<xsl:value-of select="dis:IntendedDuration/@U"/>
											</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:value-of select="dis:Comment"/>
												</td>
											</tr>
										</xsl:if>
									</xsl:for-each>
								</tbody>
							</table>
						</td>
					</tr>
				</tbody>
			</table>
		</xsl:if>
		<!-- slutt struktur for å samle medisineringsinformsajon-->
		<!-- Øvrig pasientinformasjon i tabell -->
		<br/>
		<h2>Øvrig pasientinformasjon</h2>
		<table width="95%">
			<tbody>
				<!--<tr>
					<th colspan="10">Øvrig pasientinformasjon</th>
				</tr>-->
				<tr>
					<th>Navn</th>
					<td width="15%">
						<xsl:value-of select="dis:Name"/>
					</td>
					<th>Kjønn</th>
					<td width="15%">
						<xsl:apply-templates select="dis:Sex"/>
					</td>
					<th>Fødselsdato</th>
					<td width="15%">
						<xsl:value-of select="dis:DateOfBirth/@V"/>
					</td>
					<th>Dødsdato</th>
					<td width="15%">
						<xsl:value-of select="dis:DateOfDeath/@V"/>
					</td>
				</tr>
				<tr>
					<th>
						<xsl:choose>
							<xsl:when test="dis:TypeOffId/@DN">
								<xsl:value-of select="dis:TypeOffId/@DN"/>
							</xsl:when>
							<xsl:otherwise>ID-nr.</xsl:otherwise>
						</xsl:choose>
					</th>
					<td colspan="2">
						<xsl:apply-templates select="dis:OffId"/>
					</td>
					<th>Refusjonsgrunnlag</th>
					<td colspan="4">
						<xsl:value-of select="dis:BasisForHealthServices/@DN"/>
					</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>
					<tr>
						<th colspan="3">Advarsel</th>
						<th>Gyldig fra</th>
						<th>Gyldig til</th>
					</tr>
					<xsl:for-each select="dis:PatientPrecaution">
						<tr>
							<td>
								<xsl:value-of select="dis:Precaution"/>
							</td>
							<td>
								<xsl:value-of select="dis:StartDateTime/@V"/>&#160;</td>
							<td>
								<xsl:value-of select="dis:EndDateTime/@V"/>&#160;</td>
						</tr>
					</xsl:for-each>
				</xsl:if>
				<xsl:for-each select="dis:Consent">
					<tr>
						<th>Samtykke</th>
						<td>
							<xsl:value-of select="dis:ConsentStatus/@DN"/>
						</td>
						<th>Samtykkedato</th>
						<td>
							<xsl:value-of select="dis:ConsentDate"/>
						</td>
						<th>Merknad</th>
						<td colspan="3">
							<xsl:value-of select="dis:Merknad"/>
						</td>
					</tr>
				</xsl:for-each>
				<xsl:for-each select="dis:NeedTranslator">
					<tr>
						<th>Tolkebehov</th>
						<td>
							<xsl:if test="dis:IsDeaf/@V='true'">Døv</xsl:if>
							<xsl:if test="dis:IsBlind/@V='true'">Blind</xsl:if>
							<xsl:value-of select="dis:Language/@DN"/>
						</td>
						<th>Tolk</th>
						<td>
							<xsl:value-of select="dis:PreferredTranslator"/>
						</td>
						<th>Behov oppørt dato</th>
						<td>
							<xsl:value-of select="dis:TranslatorEndDate"/>
						</td>
						<th>Merknad</th>
						<td>
							<xsl:value-of select="dis:Note"/>
						</td>
					</tr>
				</xsl:for-each>
				<xsl:if test="dis:CareSituation">
					<tr>
						<th colspan="8">Omsorgssituasjon</th>
					</tr>
					<tr>
						<th>Foreldreansvar</th>
						<td>
							<xsl:value-of select="dis:CareSituation/dis:CustodyType/@DN"/>
							<xsl:value-of select="dis:CareSituation/dis:CustodyOwner"/>
						</td>
						<th>Type omsorgssituasjon</th>
						<td>
							<xsl:value-of select="dis:CareSituation/dis:CareSituationType/@DN"/>
						</td>
						<th>Hjemmespråk</th>
						<td>
							<xsl:value-of select="dis:CareSituation/dis:NativeLanguage/@DN"/>
						</td>
					</tr>
					<tr>
						<td colspan="4">
							<xsl:call-template name="line-breaks">
								<xsl:with-param name="text" select="dis:CareSituation/dis:Description"/>
							</xsl:call-template>
						</td>
					</tr>
				</xsl:if>
			</tbody>
		</table>
		<br/>
		<xsl:if test="dis:PatRelHCP">
			<h2>Pasientrelatert helsetjenesteyter</h2>
			<table width="90%">
				<tbody>
					<xsl:for-each select="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%">Navn</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:PatRelnst">
			<h2>Pasientrelatert institusjon</h2>
			<table>
				<tbody>
					<tr>
						<th colspan="8">Pasientrelatert institusjoner</th>
					</tr>
					<xsl:for-each select="dis:PatRelInst">
						<tr>
							<th>Navn</th>
							<td>
								<xsl:value-of select="dis:NameInst"/>
							</td>
							<th>Kontaktperson</th>
							<td>
								<xsl:value-of select="dis:ContactPerson"/>
							</td>
							<th>Arbeidstid</th>
							<td>
								<xsl:value-of select="dis:WorkingTime"/>
							</td>
							<th>Adresse</th>
							<td>
								<xsl:value-of select="dis:Address"/>
							</td>
						</tr>
					</xsl:for-each>
				</tbody>
			</table>
			<br/>
		</xsl:if>
		<xsl:if test="dis:PatientRelperson">
			<h2>Pasientrelatert person</h2>
			<table>
				<tbody>
					<xsl:for-each select="dis:PatientRelperson">
						<tr>
							<th colspan="6">Pasientrelatert part</th>
						</tr>
						<tr>
							<th>Relasjon/beskrivelse</th>
							<td>
								<xsl:apply-templates select="dis:Relation"/>&#160;<xsl:value-of select="dis:Description"/>
								<xsl:value-of select="dis:Occupation/@DN"/>
								<xsl:value-of select="dis:Role"/>
							</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>
						<tr>
							<th>Fødselsdato</th>
							<td>
								<xsl:value-of select="dis:DateOfBirth"/>
							</td>
							<th>Kjønn</th>
							<td>
								<xsl:value-of select="dis:Sex/@DN"/>
							</td>
							<th>Etnisk tilhørighet</th>
							<td>
								<xsl:value-of select="dis:EthnicBelonging/@DN"/>
							</td>
						</tr>
						<xsl:for-each select="dis:Consent">
							<tr>
								<th>Samtykke</th>
								<td>
									<xsl:value-of select="dis:ConsentStatus/@DN"/>
								</td>
								<th>Samtykkedato</th>
								<td>
									<xsl:value-of select="dis:ConsentDate"/>
								</td>
								<th>Merknad</th>
								<td colspan="3">
									<xsl:value-of select="dis:Merknad"/>
								</td>
							</tr>
						</xsl:for-each>
						<tr>
							<th>Adresse</th>
							<td colspan="5">
								<xsl:apply-templates select="dis:Address"/>
							</td>
						</tr>
					</xsl:for-each>
				</tbody>
			</table>
			<br/>
		</xsl:if>
	</xsl:template>
	<xsl:template match="dis:PatientRelperson/dis:Relation">
		<xsl:if test="dis:Guardien/@V='true'">Verge - </xsl:if>
		<xsl:value-of select="dis:RelationCode/@DN"/>
		<xsl:if test="dis:Description">&#160;<xsl:value-of select="dis:Description"/>
		</xsl:if>
	</xsl:template>
	<xsl:template match="dis:InfItem">
		<xsl:if test="not(dis:Medication)">
			<!-- Medication og CAVE håndteres samlet i Event -->
			<h3>
				<xsl:value-of select="dis:Type/@DN"/>
			</h3>
			<xsl:if test="dis:StartDateTime or dis:EndDateTime or dis:OrgDate">
				<table width="95%">
					<tbody>
						<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>
					</tbody>
				</table>
			</xsl:if>
			<xsl:apply-templates select="dis:Observation"/>
			<xsl:apply-templates select="dis:ResultItem"/>
		</xsl:if>
	</xsl:template>
	<xsl:template match="dis:Observation">
		<table width="95%">
			<tbody>
				<xsl:if test="dis:Description">
					<tr>
						<td>
							<xsl:call-template name="line-breaks">
								<xsl:with-param name="text" select="dis:Description"/>
							</xsl:call-template>
						</td>
					</tr>
				</xsl:if>
				<xsl:if test="dis:Comment">
					<tr>
						<th>Kommentar</th>
					</tr>
					<tr>
						<td>
							<xsl:call-template name="line-breaks">
								<xsl:with-param name="text" select="dis:Comment"/>
							</xsl:call-template>
						</td>
					</tr>
				</xsl:if>
			</tbody>
		</table>
	</xsl:template>
	<xsl:template match="dis:ResultItem">
		<table width="50%">
			<tbody>
				<tr>
					<th colspan="6">Undersøkelsesresultat
					<xsl:if test="dis:ServType">
						- <xsl:apply-templates select="dis:ServType/@DN"/>
						</xsl:if>
						<xsl:if test="dis:InvDate"> - <xsl:value-of select="dis:InvDate/@V"/>
						</xsl:if>
					</th>
				</tr>
				<tr>
					<th width="10%">Undersøkelse</th>
					<td width="15%">
						<xsl:apply-templates select="dis:ClinInv"/>
					</td>
					<th width="10%">Avviksmarkør</th>
					<td width="15%">
						<xsl:choose>
							<xsl:when test="dis:DevResultInd">
								<xsl:value-of select="dis:DevResultInd/@DN"/>
							</xsl:when>
							<xsl:otherwise>Ingen</xsl:otherwise>
						</xsl:choose>
					</td>
					<th width="10%">Resultat</th>
					<td width="40">
						<xsl:apply-templates select="dis:TextResult"/>
						<xsl:apply-templates select="dis:NumResult"/>
						<xsl:apply-templates select="dis:DateResult"/>
						<xsl:apply-templates select="dis:Interval"/>
					</td>
				</tr>
				<xsl:for-each select="dis:Comment">
					<tr>
						<th>Kommentar</th>
						<td colspan="3">
							<xsl:value-of select="."/>
						</td>
					</tr>
				</xsl:for-each>
			</tbody>
		</table>
	</xsl:template>
	<xsl:template match="dis:ClinInv">
		<xsl:value-of select="dis:Id/@DN"/>
		<xsl:value-of select="dis:Id/@OT"/>
		<xsl:for-each select="dis:Spec">&#160;-&#160;<xsl:value-of select="@DN"/>
			<xsl:value-of select="@OT"/>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="dis:TextResult">
		<xsl:apply-templates/>
	</xsl:template>
	<xsl:template match="dis:TextResult/dis:Result">
		<b>
			<xsl:apply-templates select="dis:Heading"/>
		</b>
		<br/>
		<xsl:value-of 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:value-of select="dis:ArithmeticComp/@DN"/>&#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">
		<xsl:if test="dis:Heading">	
			<h3>
				<xsl:apply-templates select="dis:Heading"/>
			</h3>
		</xsl:if>
		<p>
			<xsl:call-template name="line-breaks">
				<xsl:with-param name="text" select="dis:TextResultValue"/>
			</xsl:call-template>
		</p>
	</xsl:template>
	<!-- Hack for å få til linjeskift - for bruk ved datatypen ST eller string -->
	<!--	<xsl:call-template name="line-breaks"><xsl:with-param name="text" select="dia:TekstNotatInnhold"></xsl:with-param>  </xsl:call-template> -->
	<xsl:template name="line-breaks">
		<xsl:param name="text"/>
		<xsl:choose>
			<xsl:when test="contains($text,'&#10;')">
				<xsl:value-of select="substring-before($text,'&#10;')"/>
				<br/>
				<xsl:call-template name="line-breaks">
					<xsl:with-param name="text" select="substring-after($text,'&#10;')"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$text"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

