<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- File name SmiVaccinationsRapport.xsd -->
<!-- Version "v1.1 2013-09-19". minsta antal tecken i obligatoriska fält och obligatoriska huvudelement = 1. Minst en notification i filen. -->
<!-- Version "v1.2 2014-03-20". 3 nya vaccin (de 3 sista i vaccinlistan). -->
<!-- Version "v3.0 2017-02-24". nya NPLId (de sista i listan). -->
<!-- Version "v3.1 2018-01-29". nya NPLId (de sista i listan) och produkt. -->
<!-- Version "v3.2 2018-06-12". Licenser produkt: Boostrix (licensläkemedel),diTekiBooster (Tdap Szczepionka SSI),diTekiBooster (TdaP-IMMUN),20150206000039  -->
<!-- Version "v3.3 2018-08-07". ny sätt att skriva tetanus "Tetanus vaccine"  -->
<!-- Version "v4.1 2019-01". Organisationnr blir obligatoriska, vaccinprodukt och nplid listor ersätts med fritext   -->
<!-- Version "v4.2 2020-10". Utöka antal teckenken för kontakt telefon till 80 (LimitedString)   -->
<!-- Version "v4.3 2020-11-13". Dosnr lags in i vaccinType för covid-19 vaccination som optional  -->
<!-- Version "v4.4 2020-12-14". Friviliga kommunkod municipalityScbCode enligt scb format för vårdenheten(ex. 0181 för Södertälje)  -->
<!-- Version "v4.5 2021-04-23". Dosnr max uppdateras till 99 detta för att inte blockera vaccination  -->
<!-- Version "v4.6 2021-06-16". increase NotNullShortLimitedString from 20 to 40 (use for UUID as annat patientID)  -->
<!-- Version "v4.7 2022-04-27". Added new data type "NotNullLimitedString12Digits" (primarely for careGiverOrganisationNumber)  -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:annotation>
        <xsd:documentation xml:lang="se">
            Denna fil fungerar som validering [XML Schema (.xsd)] för
            xmlfiler som skall skickas till Vaccinatiosnregistret. En exportfil som
            skall skickas till Vaccinatiosnregistret kommer att valideras mot detta
            xml-schema innan parsning. Det rekomenderas att validera
            filen innan sändning för bättre felhantering.
        </xsd:documentation>
    </xsd:annotation>

    <!-- ************************************************** -->
    <!-- *********** Global Type Definitions ************** -->
    <!-- ************************************************** -->
        
	<!-- ******************* LimitedString4Digits ****************** -->
    <xsd:simpleType name="LimitedString4Digits">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                En sträng, max min 4 digits chars.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
        	<xsd:pattern value="[0-9]{4}"/> 
        </xsd:restriction>
    </xsd:simpleType>	
	
	<!-- ******************* NotNullLimitedString12Digits ****************** -->
    <xsd:simpleType name="NotNullLimitedString12Digits">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                En sträng, max 12 tecken lång.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
        	<xsd:minLength value="1"/>
            <xsd:maxLength value="12"/>
        </xsd:restriction>
    </xsd:simpleType>	
		
     <!-- ******************* ShortLimitedString ****************** -->
    <xsd:simpleType name="ShortLimitedString">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                En sträng, max 20 tecken lång.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
        	<xsd:minLength value="0"/>
            <xsd:maxLength value="20"/>
        </xsd:restriction>
    </xsd:simpleType>

    <!-- ******************* LimitedString ****************** -->
    <xsd:simpleType name="LimitedString">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                En sträng, max 80 tecken lång.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
        	<xsd:minLength value="0"/>
            <xsd:maxLength value="80"/>
        </xsd:restriction>
    </xsd:simpleType>

    <!-- ******************* LongLimitedString ****************** -->
    <xsd:simpleType name="LongLimitedString">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                En sträng, max 255 tecken lång.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
        	<xsd:minLength value="0"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    
    <!-- ******************* NotNullShortLimitedString ****************** -->
    <xsd:simpleType name="NotNullShortLimitedString">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                En sträng, max 40 tecken lång.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
        	<xsd:minLength value="1"/>
            <xsd:maxLength value="40"/>
        </xsd:restriction>
    </xsd:simpleType>

    <!-- ******************* NotNullLimitedString ****************** -->
    <xsd:simpleType name="NotNullLimitedString">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                En sträng, max 80 tecken lång.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
        	<xsd:minLength value="1"/>
            <xsd:maxLength value="80"/>
        </xsd:restriction>
    </xsd:simpleType>

    <!-- ******************* NotNullLongLimitedString ****************** -->
    <xsd:simpleType name="NotNullLongLimitedString">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                En sträng, max 255 tecken lång.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
        	<xsd:minLength value="1"/>
            <xsd:maxLength value="255"/>
        </xsd:restriction>
    </xsd:simpleType>

  
    <!-- ******************* SmiVaccinationsRapport****************** -->
    <xsd:element name="smiVaccinationsReport" type="SmiVaccinationsReportType">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                Rootelementet i xml-dokumentet. Varje rapportfil (XML-fil)
                måste innehålla ett och endast ett sådant element.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:element>

    <xsd:complexType name="SmiVaccinationsReportType">
        <xsd:sequence>
            <!--Information om när rapportfilen skapades-->
            <xsd:element name="dateTimeCreated" type="xsd:dateTime"
                minOccurs="1" maxOccurs="1"/>
            <!--Information om data ursprung-->
            <xsd:element name="originalSystem" type="OriginalSystemType"
                minOccurs="1" maxOccurs="1"/>
            <!--Information om _en_vaccin_ anmälan. -->
            <!--om flera anmälningar skall rapporteras, så -->
            <!--listas flera vaccinNotification efter varandra.-->
            <xsd:element name="vaccinNotification" type="VaccinNotificationType"
                minOccurs="1" maxOccurs="unbounded"/>           
        </xsd:sequence>
    </xsd:complexType>

    <!-- ******************* OriginalSystemType****************** -->
    <xsd:complexType name="OriginalSystemType">
        <xsd:sequence>
            <!--Från vilket journalssystem har rapporten skapats? -->          
            <xsd:element name="systemName" type="LimitedString"
                minOccurs="1" maxOccurs="1"/>
            <!--Information om kommersiella produkten för journalsystemet.-->
            <xsd:element name="systemProduct" type="SystemProductType"
                minOccurs="0" maxOccurs="1"/>
             <!--Information om kontaktuppgifter till systemansvarig-->
            <xsd:element name="systemContact" type="ContactInformationType"
                 minOccurs="1" maxOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType>

    <!-- ******************* Vaccin anmälan ****************** -->
    <xsd:complexType name="VaccinNotificationType">
        <xsd:sequence>
        	<!-- Information om vaccin data -->
        	<xsd:element name="vaccinInfo" type="VaccinInfoType"
        		minOccurs="0" maxOccurs="1"/>
        	<!-- Status, anmälan eller makulering -->
        	<xsd:element name="vaccinStatus" type="VaccinStatusType"
        		minOccurs="1" maxOccurs="1"/>                       
            <!--Information om den vaccinerade patienten.-->
            <xsd:element name="patient" type="PatientType"
                minOccurs="1" maxOccurs="1"/>
            <!--Information om vaccinet.-->
            <xsd:element name="vaccin" type="VaccinType"
                minOccurs="1" maxOccurs="1"/>
         <!--Information om vårdgivare.-->
            <xsd:element name="careGiver" type="CareGiverType"
                minOccurs="1" maxOccurs="1"/>
         <!--Vaccination datum.-->
            <xsd:element name="vaccinDate" type="xsd:date"
                minOccurs="1" maxOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType>
      
    <!-- ******************* SystemProductType****************** -->
    <xsd:complexType name="SystemProductType">
        <xsd:sequence>
            <!--Produktnamn.-->
            <xsd:element name="productName" type="LimitedString"
                minOccurs="1" maxOccurs="1"/>
            <!--Eventuellt versionsnummer.-->
            <xsd:element name="productVersion" type="LimitedString"
                minOccurs="0" maxOccurs="1"/>          
        </xsd:sequence>
    </xsd:complexType>

    <!-- ******************* ContactInformationType****************** -->
    <xsd:complexType name="ContactInformationType">
        <xsd:sequence>
            <!--Kontaktnamn.-->
            <xsd:element name="contactName" type="LimitedString"
                minOccurs="0" maxOccurs="1"/>
            <!--Epost adress.-->
            <xsd:element name="contactEmail" type="LimitedString"
                minOccurs="0" maxOccurs="1"/>          
              <!--Telefon.-->
            <xsd:element name="contactTelephone" type="LimitedString"
                minOccurs="0" maxOccurs="1"/>          
        </xsd:sequence>
    </xsd:complexType>
    
     <!-- ******************* VaccinInfoType ****************** -->
    <xsd:complexType name="VaccinInfoType">
        <xsd:sequence>
        	 <!--Identifikation av vaccin data i ursprungliga systemet. -->
            <xsd:element name="uniqueReference" type="LimitedString"
                minOccurs="0" maxOccurs="1"/>
            <!--Information om vårdenheten som äger vaccin data.-->
            <xsd:element name="careUnit" type="CareUnitType"
                minOccurs="0" maxOccurs="1"/>  
            <!-- Information om vacciantören -->
            <xsd:element name="vaccinator" type="ContactInformationType"
            	minOccurs="0" maxOccurs="1"/>
            </xsd:sequence>
    </xsd:complexType>

 	<!-- ******************* VaccinStatusType ****************** -->
	<xsd:simpleType name="VaccinStatusType">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                 Två värden godkänns:
                0) Anmälan
                1) Makulering                
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:nonNegativeInteger">
            <xsd:enumeration value="0"/>
            <xsd:enumeration value="1"/>                         
        </xsd:restriction>
    </xsd:simpleType>

     <!-- ******************* CareUnitType****************** -->
    <xsd:complexType name="CareUnitType">
        <xsd:sequence>
            <!--Vårdenhetsnamn.-->
            <xsd:element name="careUnitName" type="LongLimitedString" minOccurs="1" maxOccurs="1"/>
			<!-- friviliga kommun kode enligt SCB format 4 digit -->
			<xsd:element name="municipalityScbCode" type="LimitedString4Digits" minOccurs="0" maxOccurs="1"/>
             <!--VårdenhetsId i rapporterande system.-->
            <xsd:element name="careUnitId" type="LimitedString"
                minOccurs="0" maxOccurs="1"/>
            <!--(Reserverad för Folkhälsomyndigheten)Vårdenhets registreringsId hos Folkhälsomyndigheten.-->
            <xsd:element name="careUnitSmiId" type="LimitedString"
                minOccurs="0" maxOccurs="1"/>
            <!--kontakt uppgifter.-->
            <xsd:element name="careUnitContact" type="ContactInformationType"
                minOccurs="0" maxOccurs="1"/>          
        </xsd:sequence>
    </xsd:complexType>


    <!-- ******************* Patient ****************** -->
    <xsd:complexType name="PatientType">
        <xsd:sequence>
            <!--Information för att identifiera patienten. -->
            <!--Tillåtna typer är personnummer, samordningsnummer och reservkod.-->
            <xsd:element name="patientId" type="NotNullShortLimitedString"
                minOccurs="1" maxOccurs="1"/>
            <!--PatientId typ.-->
            <xsd:element name="patientIdType" type="IdType"
                minOccurs="1" maxOccurs="1"/>
            </xsd:sequence>
    </xsd:complexType>

    <xsd:simpleType name="IdType">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
                 Fyra olika format godkänns:
                0) (Personnummer) 12 siffror och 13 tecken ('-' avgränsare), exempel: "19671208-1123".
                1) (samordningsnummer) Formatet (YY)YYMMDD-XXXX där DD är ett tal mellan 61-91 och där kontrollsiffran stämmer på samma vis som för personnummer.
                2) (Reservkod)  
                3) (annat nummer) Övriga format (max 15 tecken).             
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:nonNegativeInteger">
              <xsd:enumeration value="0"/>
            <xsd:enumeration value="1"/>
            <xsd:enumeration value="2"/>
            <xsd:enumeration value="3"/>          
        </xsd:restriction>
    </xsd:simpleType>

	<!-- ******************* SmallPositivInt ****************** -->
    <xsd:simpleType name="SmallPositiveIntType">
        <xsd:annotation>
            <xsd:documentation xml:lang="se">
               Dosnummer för den administrera vaccinationen
                0 ska används för alla barn vaccination som ingår i den allmänt program
                1-99 för pandemi vaccination (ex: Covid)
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:nonNegativeInteger">
            <xsd:minInclusive value="0" />
            <xsd:maxInclusive value="99" />
        </xsd:restriction>
    </xsd:simpleType>
	
      <!-- ******************* VaccinType****************** -->
    <xsd:complexType name="VaccinType">
        <xsd:sequence>
        	<xsd:choice>
           		 <!--Vaccinnamn.-->
           		 <xsd:element name="vaccinName" type="NotNullLimitedString"/>           
            	 <!--Vaccin NPL Id.-->
           		 <xsd:element name="NPLId" type="NotNullLimitedString"/>	
            </xsd:choice>
            <!--Satsnummer.-->
            <xsd:element name="batchNumber" type="LimitedString" minOccurs="1" maxOccurs="1"/> 
			<!-- DoseNumber (0 ska används för barn vaccination, 1 till 10  för pandemi (ex.: Covid19)) -->
            <xsd:element name="doseNumber" type="SmallPositiveIntType" minOccurs="0" maxOccurs="1" />			
        </xsd:sequence>
    </xsd:complexType>
     <!-- ******************* CareGiverType****************** -->
    <xsd:complexType name="CareGiverType">
        <xsd:sequence>
			<!--Vårdgivare skattverket organistation number -->
            <xsd:element name="careGiverOrganisationNumber" type="NotNullLimitedString12Digits" minOccurs="1" maxOccurs="1"/>
            <!--Vårgivarenamn.-->
            <xsd:element name="careGiverName" type="NotNullLongLimitedString" minOccurs="1" maxOccurs="1"/>         
            <!--Vårdgivare HSAId.-->
            <xsd:element name="careGiverHSAId" type="LimitedString" minOccurs="0" maxOccurs="1"/>
            <!--kontakt uppgifter.-->
            <xsd:element name="careGiverContact" type="ContactInformationType" minOccurs="0" maxOccurs="1"/>          
        </xsd:sequence>
    </xsd:complexType>
	<!-- ******************* Vaccination datum( när personen blivit vaccinerad )****************** -->
  	<xsd:simpleType name="VaccinDateType">
  		<xsd:restriction base="xsd:date">
  			<xsd:minInclusive value="2013-01-01"/>
  		</xsd:restriction>
  	</xsd:simpleType>
    
  
</xsd:schema>
