<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mh="http://www.kith.no/xmlstds/msghead/2006-05-24" xmlns:fk1="http://www.kith.no/xmlstds/felleskomponent1" xmlns:dia="http://www.kith.no/xmlstds/dialog/2006-10-11" xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="fk1 dia mh xhtml">
	<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"/>
	
	<!--
Visningsfil for Dialogmeldingen.
Inngår i KITHs visningsfiler versjon 10

01.12.2010: Import av felles CSS-fil
16-10-2008: css-fix for mye info i avsender/mottaker
15-10-2007: Første versjon


MERK
Viser kun navn og roller for kontaktpersoner i selve dialogmeldingen, ikke adresser, kjønn, nasjonalitet osv. 
Bygger på visningsfil for hodemeldingen - denne må være tilstede.

-->
	<xsl:include href="../../Hodemelding/v1.2/Hodemelding2html.xsl"/>
	<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>Dialogmelding</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>
	<xsl:template match="dia:Dialogmelding">
		<div class="Content">
			<!--<h1>Dialogmelding</h1>-->
			<xsl:if test="dia:SakstypeKodet or dia:Sakstype">
				<b>Sakstype:</b>&#160;[Kode: <xsl:value-of select="dia:SakstypeKodet/@DN"/>]&#160;
		</xsl:if>
			<xsl:apply-templates/>
		</div>
		<!--Content-->
	</xsl:template>
	<xsl:template match="dia:Sakstype">
		<xsl:apply-templates/>
		<br/>
	</xsl:template>
	<xsl:template match="dia:Foresporsel">
		<!--<h1>Forespørsel</h1>-->
		<table width="100%">
			<tbody>
				<tr>
					<th width="20%">Type forespørsel</th>
					<td width="80%" colspan="5">
						<xsl:value-of select="dia:TypeForesp/@DN"/>
					</td>
				</tr>
				<xsl:if test="dia:Hastegrad">
					<tr>
						<th width="20%">Hastegrad</th>
						<td width="80%" colspan="5">
							<xsl:value-of select="dia:Hastegrad/@DN"/>
						</td>
					</tr>
				</xsl:if>
				<xsl:if test="dia:Formål or dia:Begrunnelse">
					<tr>
						<th width="20%">Formål (kodet)</th>
						<td width="80%" colspan="5">
							<xsl:value-of select="dia:Formål/@DN"/>
						</td>
					</tr>
					<tr>
						<th width="20%">Utdyping av formål</th>
						<td width="80%" colspan="5">
							<xsl:choose>
								<xsl:when test="count(dia:Begrunnelse/*) &lt; 1">
									<xsl:call-template name="line-breaks">
										<xsl:with-param name="text" select="dia:Sporsmal"/>
									</xsl:call-template>
								</xsl:when>
								<xsl:otherwise>
									<xsl:for-each select="dia:Begrunnelse">
										<xsl:apply-templates/>
									</xsl:for-each>
								</xsl:otherwise>
							</xsl:choose>
							<!--<xsl:value-of select="dia:Begrunnelse"/>-->
						</td>
					</tr>
				</xsl:if>
				<xsl:if test="dia:typeJournalinfo or dia:FraDato or dia:TilDato">
					<tr>
						<th>Type journalinformasjon</th>
						<td>
							<xsl:value-of select="dia:TypeJournalinfo/@DN"/>
						</td>
						<th>Fra dato</th>
						<td>
							<xsl:value-of select="dia:FraDato"/>
						</td>
						<th>Til dato</th>
						<td>
							<xsl:value-of select="dia:TilDato"/>
						</td>
					</tr>
				</xsl:if>
				<tr>
					<th width="20%">Spørsmål</th>
					<td width="80%" colspan="5">
						<xsl:choose>
							<xsl:when test="count(dia:DiaSporsmal/*) &lt; 1">
								<xsl:call-template name="line-breaks">
									<xsl:with-param name="text" select="dia:Sporsmal"/>
								</xsl:call-template>
							</xsl:when>
							<xsl:otherwise>
								<xsl:for-each select="dia:Sporsmal">
									<xsl:apply-templates/>
								</xsl:for-each>
							</xsl:otherwise>
						</xsl:choose>
					</td>
				</tr>
				<xsl:apply-templates select="dia:RollerRelatertNotat"/>
			</tbody>
		</table>
	</xsl:template>
	<!-- *** Sjekker type melding oppgitt i Hodemelding for å kunne skrive ut Forespørsel, Svar på Forespørsel, Notat eller Avvik  ***-->
	<xsl:template match="dia:Dialogmelding">
		<h1>
			<xsl:value-of select="../../../../mh:MsgInfo/mh:Type/@DN"/>
		</h1>
		<xsl:if test="../../../mh:ContentDescription">
			<table>
					<tr>
						<th width="20%">Beskrivelse</th>
						<td><xsl:value-of select="../../../mh:ContentDescription"/></td>
					</tr>
			</table>
		</xsl:if>
		<xsl:apply-templates/>
	</xsl:template>
	<xsl:template match="dia:Notat">
		<!--<h1>Notat</h1>-->
		<table width="100%">
			<tbody>
				<xsl:if test="dia:TemaKodet">
					<tr>
						<th>Tema kodet:</th>
						<td colspan="2">
							<xsl:value-of select="dia:TemaKodet/@DN"/>
							<xsl:value-of select="dia:TemaKodet/@OT"/>
						</td>
					</tr>
				</xsl:if>
				<xsl:if test="dia:Tema">
					<tr>
						<xsl:choose>
							<xsl:when test="./../../../../../mh:MsgInfo/mh:Type/@V='DIALOG_AVVIK'">
								<th width="20%">Type avvik</th>
							</xsl:when>
							<xsl:otherwise>
								<th width="20%">Tema</th>
							</xsl:otherwise>
						</xsl:choose>
						<td colspan="2">
							<xsl:value-of select="dia:Tema"/>
						</td>
					</tr>
				</xsl:if>
				<tr>
					<th width="20%">Innhold</th>
					<td colspan="2">
						<xsl:choose>
							<xsl:when test="count(dia:TekstNotatInnhold/*) &lt; 1">
								<xsl:call-template name="line-breaks">
									<xsl:with-param name="text" select="dia:TekstNotatInnhold"/>
								</xsl:call-template>
							</xsl:when>
							<xsl:otherwise>
								<xsl:for-each select="dia:TekstNotatInnhold">
									<xsl:apply-templates/>
								</xsl:for-each>
							</xsl:otherwise>
						</xsl:choose>
					</td>
				</tr>
				<xsl:if test="dia:Merknad">
					<!--<tr>
						<th colspan="3">Merknad</th>
					</tr>-->
					<tr>
						<th width="20%">Merknad</th>
						<td colspan="2">
							<xsl:choose>
								<xsl:when test="count(dia:Merknad/*) &lt; 1">
									<xsl:call-template name="line-breaks">
										<xsl:with-param name="text" select="dia:Merknad"/>
									</xsl:call-template>
								</xsl:when>
								<xsl:otherwise>
									<xsl:for-each select="dia:Merknad">
										<xsl:apply-templates/>
									</xsl:for-each>
								</xsl:otherwise>
							</xsl:choose>
							<!--<xsl:value-of select="dia:Merknad"/>-->
						</td>
					</tr>
				</xsl:if>
				<xsl:if test="dia:DatoNotat">
					<tr>
						<th>Dato for notat</th>
						<td colspan="2">
							<xsl:value-of select="dia:DatoNotat"/>
						</td>
					</tr>
				</xsl:if>
				<xsl:apply-templates select="dia:RollerRelatertNotat"/>
			</tbody>
		</table>
		<!--*** Dette er svar på en forespørsel *** -->
		<xsl:if test="./../../../../../mh:MsgInfo/mh:Type/@V='DIALOG_SVAR'">
			<div style="margin-left: 0%;">
				<h2>Opprinnelig forespørsel</h2>
				<xsl:apply-templates select="dia:Foresporsel"/>
			</div>
		</xsl:if>
	</xsl:template>
	<!-- the identity template - kopierer ut xhmlt-formatering -->
	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="dia:RollerRelatertNotat">
		<tr>
			<td>&#160;</td>
		</tr>
		<tr>
			<xsl:choose>
				<xsl:when test="dia:RolleNotat or dia:RoleToPatient">
					<th width="20%">
						<xsl:value-of select="dia:RolleNotat/@DN"/>
						<xsl:if test="dia:RolleNotat and dia:RoleToPatient"> / </xsl:if>
						<xsl:value-of select="dia:RoleToPatient/@DN"/>
					</th>
				</xsl:when>
				<xsl:otherwise>
					<th width="20%">Kontaktperson</th>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:apply-templates select="dia:HealthcareProfessional"/>
		</tr>
	</xsl:template>
	<xsl:template match="dia:Person" name="dia:Person">
		<tr>
			<td>
				<xsl:value-of select="fk1:GivenName"/>&#160;<xsl:value-of select="fk1:MiddleName"/>&#160;<xsl:value-of select="fk1:FamilyName"/>
			</td>
		</tr>
	</xsl:template>
	<xsl:template match="dia:HealthcareProfessional" name="dia:HealthcareProfessional">
		<td colspan="3">
			<xsl:if test="dia:RoleToPatient">
				<xsl:value-of select="dia:RoleToPatient/@DN"/>&#160;<xsl:value-of select="dia:TypeHealthcareProfessional/@DN"/>&#160;
				</xsl:if>
			<xsl:value-of select="dia:GivenName"/>&#160;<xsl:value-of select="dia:MiddleName"/>&#160;<xsl:value-of select="dia:FamilyName"/>
			<!--<xsl:if test="dia:Ident">
					<br/>
					<xsl:value-of select="dia:Ident/fk1:TypeId/@V"/>: <xsl:value-of select="dia:Ident/fk1:Id"/>
				</xsl:if> -->
			<xsl:if test="dia:Address">
				<br/>
				<xsl:apply-templates select="dia:Address"/>
			</xsl:if>
			<xsl:for-each select="dia:TeleCom">
				<br/>
				<xsl:if test="fk1:TypeTelecom">
					<xsl:value-of select="fk1:TypeTelecom/@DN"/>: &#160;		
					</xsl:if>
				<xsl:value-of select="fk1:TeleAddress/@V"/>
			</xsl:for-each>
		</td>
	</xsl:template>
	<xsl:template match="dia:Address">
		<xsl:if test="fk1:TypeAddress">
			<xsl:value-of select="fk1:TypeAddress/@DN"/>:<br/>
		</xsl:if>
		<xsl:if test="fk1:StreetAdr">
			<xsl:value-of select="fk1:StreetAdr"/>
			<br/>
		</xsl:if>
		<xsl:if test="fk1:Postbox">
			<xsl:value-of select="fk1:Postbox"/>
			<br/>
		</xsl:if>
		<xsl:if test="fk1:PostalCode">
			<xsl:value-of select="fk1:PostalCode"/>&#xA0;</xsl:if>
		<xsl:if test="fk1:City">
			<xsl:value-of select="fk1:City"/>
			<br/>
		</xsl:if>
		<xsl:if test="fk1:County">
			<xsl:value-of select="fk1:County/@DN"/>
			<br/>
		</xsl:if>
		<xsl:if test="fk1:Country">
			<xsl:value-of select="fk1:Country/@DN"/>
			<br/>
		</xsl:if>
	</xsl:template>
	<xsl:template match="fk1:TeleCom">
		<xsl:if test="fk1:TypeTeleCom">
			<xsl:value-of select="fk1:TypeTelecom/@DN"/>:&#xA0;</xsl:if>
		<xsl:value-of select="fk1:TeleAddress/@V"/>
		<br/>
	</xsl:template>
	<xsl:template match="fk1:Ident">
		<xsl:value-of select="fk1:TypeId/@DN"/>:&#160;<xsl:value-of select="fk1:Id"/>
		<br/>
	</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>
	<!-- Funksjon for å slå opp kodeverdi i kodeliste , variabelen $KodeVerdier må være definert - funksjonen er foreløbig ikke i bruk-->
	<!-- <xsl:template name="CVtoText"> -->
	<!-- må motta et element som er en CV og har S og V definert-->
	<!-- <xsl:param name="CV"/> 
	<xsl:variable name="S" select="substring($CV//@S, 21)"/>
	<xsl:variable name="V" select="$CV//@V"/>
	<xsl:value-of select="$KodeVerdier/dataroot/KodeVerdier[KODELISTEID=$S and KODE=$V]/LANGTNAVN"/>
</xsl:template>
-->
</xsl:stylesheet>

