<?xml version="1.0" encoding="UTF-8"?>
<!--  ==========================================================================
   This is the schema definition for a "General Invoice Request" process encoded
   in XML. The content is either an invoice or a reminder generated by a health care 
   provider. The request is sent via 1 or more intermediates to the final recipient. 

	Upon receiving the request the recipient can respond by [0,n] "General Invoice 
	Response" messages!

	This XML project is normative for the electronic invoice/reminder 
	process in Switzerland.

	Permission to use, and distribute this schema and its accompanying documentation 
	for any purpose and without fee is hereby granted in perpetuity, provided that 
	the above copyright notice and this paragraph appear in all copies and this schema 
	file is not altered.
	The copyright holders make no representation about the suitability of the schema
	for any purpose.

	It is provided "as is" without expressed or implied warranty.

	Copyright (c) 2010 Forum Datenaustausch, http://www.forum-datenaustausch.ch
	All Rights Reserved.
   ==========================================================================  -->
<schema targetNamespace="http://www.forum-datenaustausch.ch/invoice" 
	xmlns="http://www.w3.org/2001/XMLSchema" 
	xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
	xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
	xmlns:invoice="http://www.forum-datenaustausch.ch/invoice" 
	elementFormDefault="qualified" attributeFormDefault="unqualified">

<!-- =======================================================================
	import fo encryption and signature schema definitions as local files
	in fact MSXML4.0 has a problem with network loaded schema definitions
	and there is a significant time impact of always loading these schemas 
	from W3C.
	
	W3C locations:
	   	http://www.w3c.org/TR/xmlenc-core/xenc-schema.xsd
  		http://www.w3c.org/TR/xmldsig-core/xmldsig-core-schema.xsd
 ======================================================================= -->
   <import namespace="http://www.w3.org/2000/09/xmldsig#" 
   		   schemaLocation="xmldsig-core-schema.xsd"/>
   <import namespace="http://www.w3.org/2001/04/xmlenc#" 
   		   schemaLocation="xenc-schema.xsd"/>

<!-- =======================================================================
	General data type definitions
 ======================================================================= -->
	<simpleType name="nonEmptyStringType">
		<restriction base="string">
			<minLength value="1"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_3">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="3"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_6">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="6"/>
		</restriction>
	</simpleType>
	
	<simpleType name="stringType1_9">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="9"/>
		</restriction>
	</simpleType>
	
	<simpleType name="stringType1_10">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="10"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_12">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="12"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_15">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="15"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_25">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="25"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_30">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="30"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_35">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="35"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_50">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="50"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_64">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="64"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_70">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="70"/>
		</restriction>
	</simpleType>
	
	<simpleType name="stringType1_80">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="80"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_100">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="100"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_350">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="350"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType0_350">
		<restriction base="string">
			<maxLength value="350"/>
		</restriction>
	</simpleType>

	<simpleType name="stringType1_700">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="700"/>
		</restriction>
	</simpleType>

	<!--  EAN, ZSR, NIF and SSN numbers -->
	<simpleType name="eanPartyType">
		<restriction base="string">
			<pattern value="([0-9]{13})"/>
		</restriction>
	</simpleType>
	<simpleType name="zsrPartyType">
		<restriction base="string">
			<pattern value="([A-Z][0-9]{6})"/>
		</restriction>
	</simpleType>
	<simpleType name="unionPartyType">
		<union memberTypes="invoice:eanPartyType invoice:zsrPartyType"/>
	</simpleType>
	<simpleType name="nifPartyType">
		<restriction base="string">
			<pattern value="[0-9]{1,7}"/>
		</restriction>
	</simpleType>
	<simpleType name="ssnPartyType">
		<restriction base="string">
			<pattern value="[0-9]{4,10}|[1-9][0-9]{10}|756[0-9]{10}"/>
		</restriction>
	</simpleType>
	
<!-- =======================================================================
	address definitions for persons and companies
 ======================================================================= -->
	<complexType name="personType">
		<sequence>
			<element name="familyname" type="invoice:stringType1_35"/>
			<element name="givenname" type="invoice:stringType1_35"/>
			<element name="subaddressing" type="invoice:stringType1_35" minOccurs="0"/>
			<element name="postal" type="invoice:postalAddressType"/>
			<element name="telecom" type="invoice:telecomAddressType" minOccurs="0"/>
			<element name="online" type="invoice:onlineAddressType" minOccurs="0"/>
		</sequence>
		<attribute name="salutation" type="invoice:stringType1_35"/>
		<attribute name="title" type="invoice:stringType1_35"/>
	</complexType>
	
	<complexType name="companyType">
		<sequence>
			<element name="companyname" type="invoice:stringType1_35"/>
			<element name="department" type="invoice:stringType1_35" minOccurs="0"/>
			<element name="subaddressing" type="invoice:stringType1_35" minOccurs="0"/>
			<element name="postal" type="invoice:postalAddressType"/>
			<element name="telecom" type="invoice:telecomAddressType" minOccurs="0"/>
			<element name="online" type="invoice:onlineAddressType" minOccurs="0"/>
		</sequence>
	</complexType>
	
	<complexType name="postalAddressType">
		<sequence>
			<element name="pobox" type="invoice:stringType1_35" minOccurs="0"/>
			<element name="street" type="invoice:stringType1_35" minOccurs="0"/>
			<element name="zip" type="invoice:zipType"/>
			<element name="city" type="invoice:stringType1_35"/>
		</sequence>
	</complexType>

	<complexType name="zipType">
		<simpleContent>
			<extension base="invoice:stringType1_9">
				<attribute name="statecode" type="invoice:stringType1_9"/>
				<attribute name="countrycode" type="invoice:stringType1_3" default="CH"/>
			</extension>
		</simpleContent>
	</complexType>

	<complexType name="telecomAddressType">
		<sequence>
			<element name="phone" type="invoice:stringType1_25" maxOccurs="3"/>
			<element name="fax" type="invoice:stringType1_25" minOccurs="0" maxOccurs="3"/>
		</sequence>
	</complexType>

	<complexType name="onlineAddressType">
		<sequence>
			<element name="email" maxOccurs="3">
				<simpleType>
					<restriction base="invoice:stringType1_70">
						<pattern value=".+@.+"/>
					</restriction>
				</simpleType>
			</element>
			<element name="url" minOccurs="0" maxOccurs="3">
				<simpleType>
					<restriction base="anyURI">
						<minLength value="1"/>
						<maxLength value="100"/>
					</restriction>
				</simpleType>
			</element>
		</sequence>
	</complexType>
	
<!-- =======================================================================
	address definitions for specific roles possibly augmented with further data
 ======================================================================= -->
	<complexType name="billerAddressType">
		<choice>
			<element name="company" type="invoice:companyType"/>
			<element name="person" type="invoice:personType"/>
		</choice>
		<attribute name="ean_party" type="invoice:eanPartyType" use="required"/>
		<attribute name="zsr" type="invoice:zsrPartyType"/>
		<attribute name="specialty" type="invoice:stringType1_350"/>
	</complexType>

	<complexType name="providerAddressType">
		<choice>
			<element name="company" type="invoice:companyType"/>
			<element name="person" type="invoice:personType"/>
		</choice>
		<attribute name="ean_party" type="invoice:eanPartyType" use="required"/>
		<attribute name="zsr" type="invoice:zsrPartyType" use="required"/>
		<attribute name="specialty" type="invoice:stringType1_350"/>
	</complexType>


	<complexType name="insuranceAddressType">
		<choice>
			<element name="company" type="invoice:companyType"/>
			<element name="person" type="invoice:personType"/>
		</choice>
		<attribute name="ean_party" type="invoice:eanPartyType" use="required"/>
	</complexType>


	<complexType name="patientAddressType">
		<sequence>
			<element name="person" type="invoice:personType"/>
			<element name="card" minOccurs="0">
				<complexType>
					<attribute name="card_id" type="invoice:stringType1_35" use="required"/>
					<attribute name="expiry_date" type="dateTime" use="required"/>
					<attribute name="validation_date" type="dateTime"/>
					<attribute name="validation_id" type="invoice:stringType1_35"/>
					<attribute name="validation_server" type="invoice:stringType1_35"/>
				</complexType>
			</element>
		</sequence>
		<attribute name="gender" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="male"/>
					<enumeration value="female"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="birthdate" type="dateTime" use="required"/>
		<attribute name="ssn" type="invoice:ssnPartyType"/>
	</complexType>

	<!--  guarantor's address role 
		Note: in fact this role is the legal representative of the patient, e.g. it is himself, the parents or in seldom
			  cases another person or institution.
			  
			  In a printout the receiver address role is either the guarantor or the insurance depending on the
			  tiers case
	-->

	<complexType name="guarantorAddressType">
		<choice>
			<element name="company" type="invoice:companyType"/>
			<element name="person" type="invoice:personType"/>
		</choice>
	</complexType>


	<complexType name="referrerAddressType">
		<choice>
			<element name="company" type="invoice:companyType"/>
			<element name="person" type="invoice:personType"/>
		</choice>
		<attribute name="ean_party" type="invoice:eanPartyType"/>
		<attribute name="zsr" type="invoice:zsrPartyType"/>
		<attribute name="specialty" type="invoice:stringType1_350"/>
	</complexType>

	<complexType name="employerAddressType">
		<choice>
			<element name="company" type="invoice:companyType"/>
			<element name="person" type="invoice:personType"/>
		</choice>
		<attribute name="ean_party" type="invoice:eanPartyType"/>
		<attribute name="reg_number" type="invoice:stringType1_35"/>
	</complexType>

	<complexType name="esrAddressType">
		<choice>
			<element name="company" type="invoice:companyType"/>
			<element name="person" type="invoice:personType"/>
		</choice>
	</complexType>
	
<!-- =======================================================================
	service record definitions
 ======================================================================= -->
	<complexType name="servicesType">
		<choice maxOccurs="unbounded">
			<element name="record_tarmed" type="invoice:recordTarmedType"/>
			<element name="record_drg" type="invoice:recordDRGType"/>
			<element name="record_lab" type="invoice:recordLabType"/>
			<element name="record_migel" type="invoice:recordMigelType"/>
			<element name="record_paramed" type="invoice:recordParamedType"/>
			<element name="record_drug" type="invoice:recordDrugType"/>
			<element name="record_other" type="invoice:recordOtherType"/>
		</choice>
	</complexType>

	<complexType name="recordTarmedType">
		<attribute name="record_id" use="required">
			<simpleType>
				<restriction base="int">
					<minInclusive value="1"/>
					<maxInclusive value="999999999"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="tariff_type" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="[0-9A-Z]{3}"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="code" type="invoice:stringType1_30" use="required"/>
		<attribute name="ref_code" type="invoice:stringType1_30"/>
		<attribute name="name" type="invoice:stringType1_350" use="required"/>
		<attribute name="session" default="1">
			<simpleType>
				<restriction base="int">
					<minInclusive value="1"/>
					<maxInclusive value="999999"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="quantity" type="double" use="required"/>
		<attribute name="date_begin" type="dateTime" use="required"/>
		<attribute name="date_end" type="dateTime"/>
		<attribute name="provider_id" type="invoice:unionPartyType" use="required"/>
		<attribute name="responsible_id" type="invoice:unionPartyType" use="required"/>
		<attribute name="billing_role" default="both">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="mt"/>
					<enumeration value="tt"/>
					<enumeration value="both"/>
					<enumeration value="none"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="medical_role" default="self_employed">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="self_employed"/>
					<enumeration value="employee"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="body_location" default="none">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="none"/>
					<enumeration value="left"/>
					<enumeration value="right"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="treatment" default="ambulatory">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="ambulatory"/>
					<enumeration value="stationary"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="unit_mt" use="required">
			<simpleType>
				<restriction base="double">
					<minInclusive value="0.0"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="unit_factor_mt" use="required">
			<simpleType>
				<restriction base="double">
					<minExclusive value="0.0"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="scale_factor_mt" type="double" default="1.0"/>
		<attribute name="external_factor_mt" default="1.0">
			<simpleType>
				<restriction base="double">
					<minInclusive value="0.0"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="amount_mt" type="double" default="0.0"/>
		<attribute name="unit_tt" use="required">
			<simpleType>
				<restriction base="double">
					<minInclusive value="0.0"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="unit_factor_tt" use="required">
			<simpleType>
				<restriction base="double">
					<minExclusive value="0.0"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="scale_factor_tt" type="double" default="1.0"/>
		<attribute name="external_factor_tt" default="1.0">
			<simpleType>
				<restriction base="double">
					<minInclusive value="0.0"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="amount_tt" type="double" default="0.0"/>
		<attribute name="amount" type="double" use="required"/>
		<attribute name="vat_rate" default="0.0">
			<simpleType>
				<restriction base="double">
					<minInclusive value="0"/>
					<maxInclusive value="100"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="validate" type="boolean" default="false"/>
		<attribute name="obligation" type="boolean" default="true"/>
		<attribute name="section_code" type="invoice:stringType1_6"/>
		<attribute name="remark" type="invoice:stringType1_350"/>
		<attribute name="service_attributes" type="unsignedInt" default="0"/>
	</complexType>

	<complexType name="recordServiceType">
		<attribute name="record_id" use="required">
			<simpleType>
				<restriction base="int">
					<minInclusive value="1"/>
					<maxInclusive value="999999999"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="code" type="invoice:stringType1_30" use="required"/>
		<attribute name="ref_code" type="invoice:stringType1_30"/>
		<attribute name="name" type="invoice:stringType1_350" use="required"/>
		<attribute name="session" default="1">
			<simpleType>
				<restriction base="int">
					<minInclusive value="1"/>
					<maxInclusive value="999999"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="quantity" type="double" use="required"/>
		<attribute name="date_begin" type="dateTime" use="required"/>
		<attribute name="date_end" type="dateTime"/>
		<attribute name="provider_id" type="invoice:unionPartyType" use="required"/>
		<attribute name="responsible_id" type="invoice:unionPartyType" use="required"/>
		<attribute name="unit" use="required">
			<simpleType>
				<restriction base="double">
					<minInclusive value="0.0"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="unit_factor" default="1.0">
			<simpleType>
				<restriction base="double">
					<minExclusive value="0.0"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="external_factor" default="1.0">
			<simpleType>
				<restriction base="double">
					<minInclusive value="0.0"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="amount" type="double" use="required"/>
		<attribute name="vat_rate" default="0">
			<simpleType>
				<restriction base="double">
					<minInclusive value="0"/>
					<maxInclusive value="100"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="validate" type="boolean" default="false"/>
		<attribute name="obligation" type="boolean" default="true"/>
		<attribute name="section_code" type="invoice:stringType1_6"/>
		<attribute name="remark" type="invoice:stringType1_350"/>
		<attribute name="service_attributes" type="unsignedInt" default="0"/>
	</complexType>

	<complexType name="recordDRGType">
		<complexContent>
			<extension base="invoice:recordServiceType">
				<attribute name="tariff_type" use="required">
					<simpleType>
						<restriction base="string">
							<pattern value="[0-9A-Z]{3}"/>
						</restriction>
					</simpleType>
				</attribute>
			</extension>
		</complexContent>
	</complexType>

	<complexType name="recordDrugType">
		<complexContent>
			<extension base="invoice:recordServiceType">
				<sequence>
					<element name="xtra_drug" minOccurs="0">
						<complexType>
							<attribute name="indicated" type="boolean"/>
							<attribute name="iocm_category">
								<simpleType>
									<restriction base="NMTOKEN">
										<enumeration value="A"/>
										<enumeration value="B"/>
										<enumeration value="C"/>
										<enumeration value="D"/>
										<enumeration value="E"/>
									</restriction>
								</simpleType>
							</attribute>
							<attribute name="delivery" default="first">
								<simpleType>
									<restriction base="NMTOKEN">
										<enumeration value="first"/>
										<enumeration value="repeated"/>
										<enumeration value="permanent"/>
									</restriction>
								</simpleType>
							</attribute>
							<attribute name="regulation_attributes" type="unsignedInt" default="0"/>
							<attribute name="limitation" type="boolean"/>
						</complexType>
					</element>
				</sequence>
				<attribute name="tariff_type" use="required">
					<simpleType>
						<restriction base="string">
							<pattern value="[0-9A-Z]{3}"/>
						</restriction>
					</simpleType>
				</attribute>
			</extension>
		</complexContent>
	</complexType>

	<complexType name="recordLabType">
		<complexContent>
			<extension base="invoice:recordServiceType">
				<attribute name="tariff_type" use="required">
					<simpleType>
						<restriction base="string">
							<pattern value="[0-9A-Z]{3}"/>
						</restriction>
					</simpleType>
				</attribute>
			</extension>
		</complexContent>
	</complexType>

	<complexType name="recordMigelType">
		<complexContent>
			<extension base="invoice:recordServiceType">
				<attribute name="tariff_type" use="required">
					<simpleType>
						<restriction base="string">
							<pattern value="[0-9A-Z]{3}"/>
						</restriction>
					</simpleType>
				</attribute>
			</extension>
		</complexContent>
	</complexType>

	<complexType name="recordParamedType">
		<complexContent>
			<extension base="invoice:recordServiceType">
				<attribute name="tariff_type" use="required">
					<simpleType>
						<restriction base="string">
							<pattern value="[0-9A-Z]{3}"/>
						</restriction>
					</simpleType>
				</attribute>
			</extension>
		</complexContent>
	</complexType>

	<complexType name="recordOtherType">
		<complexContent>
			<extension base="invoice:recordServiceType">
				<attribute name="tariff_type" use="required">
					<simpleType>
						<restriction base="string">
							<pattern value="[0-9A-Z]{3}"/>
						</restriction>
					</simpleType>
				</attribute>
			</extension>
		</complexContent>
	</complexType>

<!-- =======================================================================
	definitions regarding the applied law
 ======================================================================= -->
	<complexType name="kvgLawType">
		<attribute name="insured_id" type="invoice:stringType1_35"/>
		<attribute name="case_id" type="invoice:stringType1_35"/>
		<attribute name="case_date" type="dateTime"/>
		<attribute name="contract_number" type="invoice:stringType1_35"/>
	</complexType>

	<complexType name="vvgLawType">
		<attribute name="insured_id" type="invoice:stringType1_35"/>
		<attribute name="case_id" type="invoice:stringType1_35"/>
		<attribute name="case_date" type="dateTime"/>
		<attribute name="contract_number" type="invoice:stringType1_35"/>
	</complexType>

	<complexType name="uvgLawType">
		<attribute name="insured_id" type="invoice:stringType1_35"/>
		<attribute name="case_id" type="invoice:stringType1_35"/>
		<attribute name="case_date" type="dateTime"/>
		<attribute name="contract_number" type="invoice:stringType1_35"/>
		<attribute name="ssn" type="invoice:ssnPartyType"/>
	</complexType>

	<complexType name="ivgLawType">
		<attribute name="case_id" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="([0-9]{14}|[0-9]{10}|[0-9]{9}|[0-9]{6})"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="case_date" type="dateTime"/>
		<attribute name="contract_number" type="invoice:stringType1_35"/>
		<attribute name="ssn" type="invoice:ssnPartyType" use="required"/>
		<attribute name="nif" type="invoice:nifPartyType"/>
	</complexType>

	<complexType name="mvgLawType">
		<attribute name="insured_id" type="invoice:stringType1_35"/>
		<attribute name="case_id" type="invoice:stringType1_35"/>
		<attribute name="case_date" type="dateTime"/>
		<attribute name="contract_number" type="invoice:stringType1_35"/>
		<attribute name="ssn" type="invoice:ssnPartyType" use="required"/>
	</complexType>

	<!--  law = ORG ("Obligationenrecht" for self-paying patients e.g. dentist's invoices!)  -->
	<complexType name="orgLawType">
		<attribute name="insured_id" type="invoice:stringType1_35"/>
		<attribute name="case_id" type="invoice:stringType1_35"/>
		<attribute name="case_date" type="dateTime"/>
		<attribute name="contract_number" type="invoice:stringType1_35"/>
	</complexType>
	
<!-- =======================================================================
	diagnosis coding definitions
 ======================================================================= -->
	<complexType name="diagnosisType">
		<simpleContent>
			<extension base="invoice:stringType0_350">
				<attribute name="type" default="by_contract">
					<simpleType>
						<restriction base="NMTOKEN">
							<enumeration value="ICD"/>
							<enumeration value="cantonal"/>
							<enumeration value="DRG"/>
							<enumeration value="by_contract"/>
							<enumeration value="freetext"/>
							<enumeration value="birthdefect"/>
							<enumeration value="ICPC"/>
						</restriction>
					</simpleType>
				</attribute>
				<attribute name="code" type="invoice:stringType1_12"/>
			</extension>
		</simpleContent>
	</complexType>

<!-- =======================================================================
	detailed treatment information definitions
 ======================================================================= -->
	<complexType name="treatmentType">
		<sequence>
			<element name="diagnosis" type="invoice:diagnosisType" minOccurs="0" maxOccurs="unbounded"/>
			<element name="xtra_hospital" type="invoice:xtraHospitalType" minOccurs="0"/>
		</sequence>
		<attribute name="date_begin" type="dateTime" use="required"/>
		<attribute name="date_end" type="dateTime" use="required"/>
		<attribute name="canton" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="AG"/>
					<enumeration value="AI"/>
					<enumeration value="AR"/>
					<enumeration value="BE"/>
					<enumeration value="BL"/>
					<enumeration value="BS"/>
					<enumeration value="FR"/>
					<enumeration value="GE"/>
					<enumeration value="GL"/>
					<enumeration value="GR"/>
					<enumeration value="JU"/>
					<enumeration value="LU"/>
					<enumeration value="NE"/>
					<enumeration value="NW"/>
					<enumeration value="OW"/>
					<enumeration value="SG"/>
					<enumeration value="SH"/>
					<enumeration value="SO"/>
					<enumeration value="SZ"/>
					<enumeration value="TI"/>
					<enumeration value="TG"/>
					<enumeration value="UR"/>
					<enumeration value="VD"/>
					<enumeration value="VS"/>
					<enumeration value="ZG"/>
					<enumeration value="ZH"/>
					<enumeration value="LI"/>
					<enumeration value="A"/>
					<enumeration value="D"/>
					<enumeration value="F"/>
					<enumeration value="I"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="reason" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="disease"/>
					<enumeration value="accident"/>
					<enumeration value="maternity"/>
					<enumeration value="prevention"/>
					<enumeration value="birthdefect"/>
					<enumeration value="unknown"/>
				</restriction>
			</simpleType>
		</attribute>
	</complexType>

<!-- =======================================================================
	additional data definitions for hospitals
 ======================================================================= -->
	<complexType name="xtraHospitalType">
		<choice>
			<element name="ambulatory" type="invoice:xtraAmbulatoryType"/>
			<element name="stationary" type="invoice:xtraStationaryType"/>
		</choice>
	</complexType>
	
	<complexType name="xtraAmbulatoryType">
		<attribute name="hospitalization_type">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="regular"/>
					<enumeration value="emergency"/>
					<enumeration value="welfare"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="hospitalization_mode">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="cantonal"/>
					<enumeration value="noncantonal_indicated"/>
					<enumeration value="noncantonal_nonindicated"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="class">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="private"/>
					<enumeration value="semi_private"/>
					<enumeration value="general"/>
					<enumeration value="hospital_comfort"/>
					<enumeration value="md_free_choice"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="section_major" type="invoice:stringType1_6"/>
	</complexType>
	
	<complexType name="xtraStationaryType">
		<attribute name="hospitalization_date" type="dateTime" use="required"/>
		<attribute name="treatment_days" type="duration" use="required"/>
		<attribute name="hospitalization_type" default="regular">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="regular"/>
					<enumeration value="emergency"/>
					<enumeration value="welfare"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="hospitalization_mode" default="cantonal">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="cantonal"/>
					<enumeration value="noncantonal_indicated"/>
					<enumeration value="noncantonal_nonindicated"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="class" default="general">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="private"/>
					<enumeration value="semi_private"/>
					<enumeration value="general"/>
					<enumeration value="hospital_comfort"/>
					<enumeration value="md_free_choice"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="section_major" type="invoice:stringType1_6"/>
		<attribute name="has_expense_loading" type="boolean" default="true"/>
		<attribute name="admission_type" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="normal"/>
					<enumeration value="relocated"/>
					<enumeration value="unknown"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="discharge_type" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="normal"/>
					<enumeration value="relocated"/>
					<enumeration value="deceased"/>
					<enumeration value="aborted"/>
					<enumeration value="unknown"/>
				</restriction>
			</simpleType>
		</attribute>
	</complexType>
	
<!-- =======================================================================
	TP and TG data definitions
 ======================================================================= -->
	<complexType name="garantType">
		<sequence>
			<element name="biller" type="invoice:billerAddressType"/>
			<element name="provider" type="invoice:providerAddressType"/>
			<element name="insurance" type="invoice:insuranceAddressType" minOccurs="0"/>
			<element name="patient" type="invoice:patientAddressType"/>
			<element name="guarantor" type="invoice:guarantorAddressType"/>
			<element name="referrer" type="invoice:referrerAddressType" minOccurs="0"/>
			<element name="employer" type="invoice:employerAddressType" minOccurs="0"/>
		</sequence>
		<attribute name="payment_period" type="duration"/>
	</complexType>

	<complexType name="payantType">
		<sequence>
			<element name="biller" type="invoice:billerAddressType"/>
			<element name="provider" type="invoice:providerAddressType"/>
			<element name="insurance" type="invoice:insuranceAddressType"/>
			<element name="patient" type="invoice:patientAddressType"/>
			<element name="guarantor" type="invoice:guarantorAddressType"/>
			<element name="referrer" type="invoice:referrerAddressType" minOccurs="0"/>
			<element name="employer" type="invoice:employerAddressType" minOccurs="0"/>
		</sequence>
		<attribute name="payment_period" type="duration"/>
	</complexType>
	
<!-- =======================================================================
	ESR (5|9|red) payment definitions
 ======================================================================= -->
	<complexType name="esr5Type">
		<sequence>
			<element name="bank" type="invoice:esrAddressType" minOccurs="0"/>
		</sequence>
		<attribute name="type" default="15">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="15plus"/>
					<enumeration value="15"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="participant_number" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="[0-9]{5}"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="reference_number" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="[0-9]{5} [0-9]{5} [0-9]{5}"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="coding_line" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="(&lt;[0-9]{2}0001[0-9]{9}&gt; [0-9]{15}\+ [0-9]{5}&gt;|[0-9]{15}\+ [0-9]{5}&gt;)"/>
				</restriction>
			</simpleType>
		</attribute>
	</complexType>

	<complexType name="esr9Type">
		<sequence>
			<element name="bank" type="invoice:esrAddressType" minOccurs="0"/>
		</sequence>
		<attribute name="type" default="16or27">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="16or27plus"/>
					<enumeration value="16or27"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="participant_number" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="01-[1-9][0-9]{0,5}-[0-9]"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="reference_number" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="([0-9] [0-9]{5} [0-9]{5} [0-9]{5}|[0-9]{2} [0-9]{5} [0-9]{5} [0-9]{5} [0-9]{5} [0-9]{5})"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="coding_line" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="(01[0-9]{11}&gt;[0-9]{16}\+ [0-9]{9}&gt;|042&gt;[0-9]{16}\+ [0-9]{9}&gt;|01[0-9]{11}&gt;[0-9]{27}\+ [0-9]{9}&gt;|042&gt;[0-9]{27}\+ [0-9]{9}&gt;)"/>
				</restriction>
			</simpleType>
		</attribute>
	</complexType>

	<complexType name="esrRedType">
		<sequence>
			<element name="bank" type="invoice:esrAddressType" minOccurs="0"/>
			<element name="payment_reason" type="invoice:stringType1_35" minOccurs="0" maxOccurs="4"/>
		</sequence>
		<attribute name="payment_to" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="postal_account"/>
					<enumeration value="bank_account"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="esr_attributes" type="unsignedInt" default="0"/>
		<attribute name="post_account" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="[0-9]{2}-[0-9]{1,4}-[0-9]"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="iban">
			<simpleType>
				<restriction base="string">
					<pattern value="CH[0-9]{19}"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="reference_number">
			<simpleType>
				<restriction base="string">
					<pattern value="[0-9]{10}"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="coding_line1" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="([0-9]{27}\+ 07[0-9]{7}&gt;|[0-9]{9}&gt;)"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="coding_line2" use="required">
			<simpleType>
				<restriction base="string">
					<pattern value="[0-9]{9}&gt;"/>
				</restriction>
			</simpleType>
		</attribute>
	</complexType>
	
<!-- =======================================================================
	data type definitions regarding the involved money & vats
 ======================================================================= -->
	<complexType name="vatRateType">
		<attribute name="vat_rate" use="required">
			<simpleType>
				<restriction base="double">
					<minInclusive value="0"/>
					<maxInclusive value="100"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="amount" type="double" use="required"/>
		<attribute name="vat" type="double" use="required"/>
	</complexType>

	<complexType name="vatType">
		<sequence>
			<element name="vat_rate" type="invoice:vatRateType" maxOccurs="unbounded"/>
		</sequence>
		<attribute name="vat_number" type="invoice:stringType1_15"/>
		<attribute name="vat" type="double" use="required"/>
	</complexType>
	
	<complexType name="balanceType">
		<sequence>
			<element name="vat" type="invoice:vatType"/>
		</sequence>
		<attribute name="currency" type="string" fixed="CHF"/>
		<attribute name="amount" type="double" use="required"/>
		<attribute name="amount_reminder" type="double" default="0"/>
		<attribute name="amount_prepaid" type="double" default="0"/>
		<attribute name="amount_due" type="double" use="required"/>
		<attribute name="amount_obligations" type="double" default="0"/>
	</complexType>
		
<!-- =======================================================================
	processing definitions (might be expanded by intermediates)
 ======================================================================= -->
	<complexType name="processingType">
		<sequence>
			<element name="transport" type="invoice:transportType"/>
			<element name="validations" type="invoice:validationsType" minOccurs="0"/>
			<element name="demand" minOccurs="0">
				<complexType>
					<attribute name="tc_demand_id" type="long" use="required"/>
					<attribute name="tc_token" type="invoice:stringType1_100" use="required"/>
					<attribute name="insurance_demand_date" type="dateTime" use="required"/>
					<attribute name="insurance_demand_id" type="invoice:stringType1_35"/>
				</complexType>
			</element>
		</sequence>
		<attribute name="print_at_intermediate" type="boolean" default="false"/>
		<attribute name="print_patient_copy" type="boolean" default="false"/>
	</complexType>
	
	<complexType name="transportType">
		<sequence>
			<element name="via" maxOccurs="unbounded">
				<complexType>
					<attribute name="via" type="invoice:eanPartyType" use="required"/>
					<attribute name="sequence_id" type="unsignedShort" use="required"/>
				</complexType>
			</element>
		</sequence>
		<attribute name="from" type="invoice:eanPartyType" use="required"/>
		<attribute name="to" type="invoice:eanPartyType" use="required"/>
	</complexType>
	

	<complexType name="validationsType">
		<sequence>
			<element name="validation" type="invoice:validationType" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="validationType">
		<sequence>
			<element name="validation_result" type="invoice:validationResultType" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>

		<attribute name="originator" type="invoice:stringType1_100" use="required"/>
		<attribute name="remark" type="invoice:stringType1_350" use="required"/>
		<attribute name="status" type="unsignedShort" use="required"/>
	</complexType>

	<complexType name="validationResultType">
		<attribute name="remark" type="invoice:stringType1_350"/>
		<attribute name="record_id">
			<simpleType>
				<restriction base="int">
					<minInclusive value="1"/>
					<maxInclusive value="999999999"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="cost_unit" type="invoice:stringType1_35"/>
		<attribute name="status" type="unsignedShort" use="required"/>
	</complexType>

<!-- =======================================================================
	prolog definitions for defining the chain of involved/used software
 ======================================================================= -->
	<complexType name="prologType">
		<sequence>
			<element name="package" type="invoice:softwareType" minOccurs="0"/>
			<element name="generator" type="invoice:softwareType"/>
		</sequence>
	</complexType>

	<complexType name="softwareType">
		<sequence>
			<element name="depends_on" type="invoice:dependsOnType" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
		<attribute name="name" type="invoice:stringType1_50" use="required"/>
		<attribute name="copyright" type="invoice:stringType1_50"/>
		<attribute name="description" type="invoice:stringType1_50"/>
		<attribute name="version" type="unsignedInt"/>
		<attribute name="id" type="unsignedInt" default="0"/>
	</complexType>

	<complexType name="dependsOnType">
		<attribute name="name" type="invoice:stringType1_50" use="required"/>
		<attribute name="copyright" type="invoice:stringType1_50"/>
		<attribute name="description" type="invoice:stringType1_50"/>
		<attribute name="version" type="unsignedInt"/>
		<attribute name="id" type="unsignedInt" default="0"/>
	</complexType>

<!-- =======================================================================
	credit object: definition for a back reference to a credit request
 ======================================================================= -->
	<complexType name="creditType">
		<attribute name="request_timestamp" type="unsignedLong" use="required"/>
		<attribute name="request_date" type="dateTime" use="required"/>
		<attribute name="request_id" type="invoice:stringType1_35" use="required"/>
	</complexType>
	
<!-- =======================================================================
	invoice object: definition for defining/referencing an invoice
 ======================================================================= -->
	<complexType name="invoiceType">
		<attribute name="request_timestamp" type="unsignedLong" use="required"/>
		<attribute name="request_date" type="dateTime" use="required"/>
		<attribute name="request_id" type="invoice:stringType1_35" use="required"/>
		<attribute name="request_patient_id" type="invoice:stringType1_35"/>
	</complexType>
	
<!-- =======================================================================
	reminder object: definition for defining/referencing a reminder
 ======================================================================= -->
	<complexType name="reminderType">
		<attribute name="request_timestamp" type="unsignedLong" use="required"/>
		<attribute name="request_date" type="dateTime" use="required"/>
		<attribute name="request_id" type="invoice:stringType1_35" use="required"/>
		<attribute name="reminder_level" default="1">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="1"/>
					<enumeration value="2"/>
					<enumeration value="3"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="reminder_text" type="invoice:stringType1_700"/>
	</complexType>

<!-- =======================================================================
	document(s) data definitions
	this is either OFFLINE=REMOTE or INLINE=INCLUDED in the infoset
 ======================================================================= -->
	<complexType name="documentsType">
		<sequence>
			<element name="document" type="invoice:documentType" minOccurs="1" maxOccurs="unbounded"/>
		</sequence>
		<attribute name="number" type="unsignedLong" use="required"/>
	</complexType>

	<complexType name="documentType">
		<choice>
			<element name="base64" type="base64Binary"/>
			<element name="url" type="anyURI"/>
		</choice>
		<attribute name="filename" type="invoice:nonEmptyStringType" use="required"/>
		<attribute name="mimeType" type="invoice:nonEmptyStringType" use="required"/>
		<attribute name="viewer" type="anyURI"/>
	</complexType>

<!-- =======================================================================
	body definition with all sensitive data regarding data privacy
	This element and subelements therein can be encrypted 
 ======================================================================= -->
	<complexType name="bodyType">
		<sequence>
			<element name="prolog" type="invoice:prologType"/>
			<element name="remark" type="invoice:stringType1_350" minOccurs="0"/>
			<element name="balance" type="invoice:balanceType"/>
			<choice>
				<element name="esr5" type="invoice:esr5Type"/>
				<element name="esr9" type="invoice:esr9Type"/>
				<element name="esrRed" type="invoice:esrRedType"/>
			</choice>
			<choice>
				<element name="tiers_garant" type="invoice:garantType"/>
				<element name="tiers_payant" type="invoice:payantType"/>
			</choice>
			<choice>
				<element name="kvg" type="invoice:kvgLawType"/>
				<element name="vvg" type="invoice:vvgLawType"/>
				<element name="uvg" type="invoice:uvgLawType"/>
				<element name="ivg" type="invoice:ivgLawType"/>
				<element name="mvg" type="invoice:mvgLawType"/>
				<element name="org" type="invoice:orgLawType"/>
			</choice>
			<element name="treatment" type="invoice:treatmentType"/>
			<element name="services" type="invoice:servicesType"/>
			<element name="documents" type="invoice:documentsType" minOccurs="0"/>
		</sequence>
		<attribute name="role_title" type="invoice:stringType1_35"/>
		<attribute name="role" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="physician"/>
					<enumeration value="physiotherapist"/>
					<enumeration value="chiropractor"/>
					<enumeration value="ergotherapist"/>
					<enumeration value="nutritionist"/>
					<enumeration value="midwife"/>
					<enumeration value="logotherapist"/>
					<enumeration value="hospital"/>
					<enumeration value="pharmacist"/>
					<enumeration value="dentist"/>
					<enumeration value="labtechnician"/>
					<enumeration value="dentaltechnician"/>
					<enumeration value="othertechnician"/>
					<enumeration value="psychologist"/>
					<enumeration value="wholesaler"/>
					<enumeration value="nursingstaff"/>
					<enumeration value="transport"/>
					<enumeration value="druggist"/>
					<enumeration value="naturopathicdoctor"/>
					<enumeration value="naturopathictherapist"/>
					<enumeration value="other"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="place" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="practice"/>
					<enumeration value="hospital"/>
					<enumeration value="lab"/>
					<enumeration value="association"/>
					<enumeration value="company"/>
				</restriction>
			</simpleType>
		</attribute>
	</complexType>
	
<!-- =======================================================================
	payload definitions with the chain of object references (credit, invoice, 
	and reminder) plus the sensitive data regarding data privacy
	This element and subelements therein can be signed
 ======================================================================= -->
	<complexType name="payloadType">
		<sequence>
			<element name="credit" type="invoice:creditType" minOccurs="0"/>
			<element name="invoice" type="invoice:invoiceType"/>
			<element name="reminder" type="invoice:reminderType" minOccurs="0"/>
			<choice>
				<element name="body" type="invoice:bodyType"/>
				<element ref="xenc:EncryptedData"/>
			</choice>
		</sequence>
		<attribute name="type" default="invoice">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="invoice"/>
					<enumeration value="reminder"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="storno" type="boolean" default="false"/>
		<attribute name="copy" type="boolean" default="false"/>
		<attribute name="credit_advice" type="boolean" default="false"/>
	</complexType>
		
<!-- =======================================================================
     =======================================================================
	Here starts the request with its root element
 =======================================================================
 ======================================================================= -->
	<element name="request" type="invoice:requestType"/>


	<complexType name="requestType">
		<sequence>
			<element name="processing" type="invoice:processingType"/>
			<element name="payload" type="invoice:payloadType"/>
			<element ref="ds:Signature" minOccurs="0"/>
		</sequence>
		<attribute name="language" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="de"/>
					<enumeration value="fr"/>
					<enumeration value="it"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="modus" default="production">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="production"/>
					<enumeration value="test"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="validation_status" type="long"/>
	</complexType>
</schema>
