<?xml version="1.0" encoding="UTF-8"?>
<!--  ==========================================================================
	This is the schema definition for a "General Form Request" process encoded
	in XML. The content basically is a filled out and Base64 encoded PDF form as 
	well as the extracted list of all PDF tokens (variable name/variable value pairs). 

	Furthermore, relevant subsets of the tokens are joined to form structured 
	addresses of a defined semantical meaning.

	The request is sent via 1 or more intermediates to the final recipient. It is 
	the intermediate's responsibility to route the request to another intermediate
	until it can be delivered to the final recipient.

	Upon receiving the request the recipient can respond by [0,n] "General Form 
	Response" objects to the topmost object reference - and only to that object!

	This xmlForm project is normative for the electronic form 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) 2011 TMR AG
	All Rights Reserved.
   ==========================================================================  -->
<schema targetNamespace="http://www.forum-datenaustausch.ch/form" 
	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:form="http://www.forum-datenaustausch.ch/form" 
	elementFormDefault="qualified" attributeFormDefault="unqualified">

<!-- =======================================================================
	import for 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="stringType1_3">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="3"/>
		</restriction>
	</simpleType>
	
	<simpleType name="stringType1_9">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="9"/>
		</restriction>
	</simpleType>
	
	<simpleType name="stringType1_25">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="25"/>
		</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_70">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="70"/>
		</restriction>
	</simpleType>
	
	<simpleType name="stringType1_100">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="100"/>
		</restriction>
	</simpleType>
	
	<simpleType name="stringType1_255">
		<restriction base="string">
			<minLength value="1"/>
			<maxLength value="255"/>
		</restriction>
	</simpleType>

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

	<simpleType name="stringType0_700">
		<restriction base="string">
			<minLength value="0"/>
			<maxLength value="700"/>
		</restriction>
	</simpleType>

	<!--  EAN number -->
	<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="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="form:stringType1_35"/>
			<element name="givenname" type="form:stringType1_35" minOccurs="0"/>
			<element name="subaddressing" type="form:stringType1_35" minOccurs="0"/>
			<element name="postal" type="form:postalAddressType"/>
			<element name="telecom" type="form:telecomAddressType" minOccurs="0"/>
			<element name="online" type="form:onlineAddressType" minOccurs="0"/>
		</sequence>
		<attribute name="salutation" type="form:stringType1_35"/>
		<attribute name="title" type="form:stringType1_35"/>
	</complexType>
	
	<complexType name="companyType">
		<sequence>
			<element name="companyname" type="form:stringType1_35"/>
			<element name="department" type="form:stringType1_35" minOccurs="0"/>
			<element name="subaddressing" type="form:stringType1_35" minOccurs="0"/>
			<element name="postal" type="form:postalAddressType"/>
			<element name="telecom" type="form:telecomAddressType" minOccurs="0"/>
			<element name="online" type="form:onlineAddressType" minOccurs="0"/>
		</sequence>
	</complexType>
	
	<complexType name="postalAddressType">
		<sequence>
			<element name="pobox" type="form:stringType1_35" minOccurs="0"/>
			<element name="street" type="form:stringType1_35" minOccurs="0"/>
			<element name="zip" type="form:zipType"/>
			<element name="city" type="form:stringType1_35"/>
		</sequence>
	</complexType>

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

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

	<complexType name="onlineAddressType">
		<sequence>
			<element name="email" maxOccurs="3">
				<simpleType>
					<restriction base="form: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="baseAddressType">
		<choice>
			<element name="company" type="form:companyType"/>
			<element name="person" type="form:personType"/>
		</choice>
		<attribute name="ean" type="form:eanPartyType" use="required"/>
		<attribute name="zsr" type="form:zsrPartyType"/>
		<attribute name="specialty" type="form:stringType1_350"/>
	</complexType>

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

	<complexType name="genericAddressType">
		<choice>
			<element name="company" type="form:companyType"/>
			<element name="person" type="form:personType"/>
		</choice>
		<attribute name="ean" type="form:eanPartyType"/>
		<attribute name="zsr" type="form:zsrPartyType"/>
		<attribute name="nif" type="form:nifPartyType"/>
		<attribute name="reg_number" type="form:stringType1_35"/>
		<attribute name="specialty" type="form:stringType1_350"/>
		<attribute name="address_role_type" use="required">
			<simpleType>
				<restriction base="NMTOKEN">
					<enumeration value="producer"/>
					<enumeration value="consumer"/>
					<enumeration value="guarantor"/>
					<enumeration value="provider"/>
					<enumeration value="referrer"/>
					<enumeration value="insurance"/>
					<enumeration value="employer"/>
					<enumeration value="other"/>
				</restriction>
			</simpleType>
		</attribute>
		<attribute name="address_role_name" type="form:stringType1_35"/>
	</complexType>
			
<!-- =======================================================================
	processing definitions (might be expanded by intermediates)
 ======================================================================= -->
	<complexType name="processingType">
		<sequence>
			<element name="transport" type="form:transportType"/>
		</sequence>
	</complexType>
	
	<complexType name="transportType">
		<sequence>
			<element name="via" maxOccurs="unbounded">
				<complexType>
					<attribute name="via" type="form:eanPartyType" use="required"/>
					<attribute name="sequence_id" type="unsignedShort" use="required"/>
				</complexType>
			</element>
		</sequence>
		<attribute name="from" type="form:eanPartyType" use="required"/>
		<attribute name="to" type="form:eanPartyType" use="required"/>
	</complexType>
	
<!-- =======================================================================
	prolog definitions for defining the chain of involved/used software
 ======================================================================= -->
	<complexType name="prologType">
		<sequence>
			<element name="package" type="form:softwareType" minOccurs="0"/>
			<element name="generator" type="form:softwareType"/>
		</sequence>
	</complexType>

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

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

<!-- =======================================================================
	reference object: definition for the reference triple of an object
 ======================================================================= -->
	<complexType name="objectType">
		<attribute name="request_timestamp" type="unsignedLong" use="required"/>
		<attribute name="request_date" type="dateTime" use="required"/>
		<attribute name="request_id" type="form:stringType1_35" use="required"/>
	</complexType>

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

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

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

	<complexType name="ivgLawType">
		<attribute name="case_id">
			<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="form:stringType1_35"/>
		<attribute name="ssn" type="form:ssnPartyType"/>
		<attribute name="nif" type="form:nifPartyType"/>
	</complexType>

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

	<!--  law = ORG ("Obligationenrecht" for self-paying patients e.g. dentist's invoices!)  -->
	<complexType name="orgLawType">
		<attribute name="insured_id" type="form:stringType1_35"/>
		<attribute name="case_id" type="form:stringType1_35"/>
		<attribute name="case_date" type="dateTime"/>
		<attribute name="contract_number" type="form:stringType1_35"/>
	</complexType>
	
	<complexType name="tokensType">
		<sequence maxOccurs="unbounded">
			<choice>
				<element name="string_token" type="form:stringTokenType"/>
				<element name="int_token" type="form:intTokenType"/>
				<element name="float_token" type="form:floatTokenType"/>
				<element name="date_token" type="form:dateTokenType"/>
				<element name="boolean_token" type="form:booleanTokenType"/>
			</choice>
		</sequence>
	</complexType>

	<complexType name="stringTokenType">
		<attribute name="name" type="form:stringType1_100" use="required"/>
		<attribute name="value" type="form:stringType0_700"/>
	</complexType>

	<complexType name="intTokenType">
		<attribute name="name" type="form:stringType1_100" use="required"/>
		<attribute name="value" type="int"/>
	</complexType>

	<complexType name="floatTokenType">
		<attribute name="name" type="form:stringType1_100" use="required"/>
		<attribute name="value" type="float"/>
	</complexType>

	<complexType name="dateTokenType">
		<attribute name="name" type="form:stringType1_100" use="required"/>
		<attribute name="value" type="dateTime"/>
	</complexType>


	<complexType name="booleanTokenType">
		<attribute name="name" type="form:stringType1_100" use="required"/>
		<attribute name="value" type="boolean"/>
	</complexType>

	<complexType name="dataType">
		<sequence>
			<element name="pdf_data" type="form:pdfDataType"/>
			<element name="pdf_file" type="form:pdfFileType"/>
		</sequence>
		<attribute name="pdf_form_oid" type="form:stringType1_255"/>
		<attribute name="pdf_form_version" type="unsignedInt"/>
	</complexType>

	<complexType name="pdfDataType">
		<sequence>
			<element name="address" type="form:genericAddressType" minOccurs="0" maxOccurs="unbounded"/>
			<choice minOccurs="0">
				<element name="kvg" type="form:kvgLawType"/>
				<element name="vvg" type="form:vvgLawType"/>
				<element name="uvg" type="form:uvgLawType"/>
				<element name="ivg" type="form:ivgLawType"/>
				<element name="mvg" type="form:mvgLawType"/>
				<element name="org" type="form:orgLawType"/>
			</choice>
			<element name="tokens" type="form:tokensType"/>
		</sequence>
	</complexType>

	<complexType name="pdfFileType">
		<sequence>
			<element name="base64" type="base64Binary"/>
		</sequence>
		<attribute name="filename" type="form:stringType1_255" use="required"/>
		<attribute name="mimeType" type="form:stringType1_35" fixed="application/pdf"/>
		<attribute name="viewer" type="anyURI" default="http://get.adobe.com/de/reader/"/>
	</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="form:prologType"/>

			<element name="producer" type="form:baseAddressType"/>
			<element name="consumer" type="form:baseAddressType"/>
			<element name="patient" type="form:patientAddressType" minOccurs="0"/>
			<element name="data" type="form:dataType"/>
		</sequence>
		<attribute name="role_title" type="form: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 form request object plus the sensitive data 
	regarding data privacy
	This element and subelements therein can be signed
 ======================================================================= -->
	<complexType name="payloadType">
		<sequence>
			<choice minOccurs="0">
				<element name="credit_ref" type="form:objectType"/>
				<element name="invoice_ref" type="form:objectType"/>
				<element name="reminder_ref" type="form:objectType"/>
				<element name="mcd_ref" type="form:objectType"/>
				<element name="form_ref" type="form:objectType"/>
				<element name="notification_ref" type="form:objectType"/>
			</choice>
			<element name="form" type="form:objectType"/>
			<choice>
				<element name="body" type="form:bodyType"/>
				<element ref="xenc:EncryptedData"/>
			</choice>
		</sequence>
		<attribute name="storno" type="boolean" default="false"/>
		<attribute name="copy" type="boolean" default="false"/>
	</complexType>
		
<!-- =======================================================================
     =======================================================================
	Here starts the request with its root element
 =======================================================================
 ======================================================================= -->
	<element name="request" type="form:requestType"/>


	<complexType name="requestType">
		<sequence>
			<element name="processing" type="form:processingType"/>
			<element name="payload" type="form: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>
	</complexType>
</schema>
