{
  "resourceType": "StructureDefinition",
  "id": "HVOLocation",
  "url": "http://electronichealth.se/fhir/hvo/StructureDefinition/HVOLocation",
  "version": "0.1.0",
  "name": "HVOLocation",
  "status": "draft",
  "description": "Location profile for HVO",
  "fhirVersion": "5.0.0",
  "mapping": [
    {
      "identity": "HVOLocationToHVOPlatsLogical",
      "uri": "HVOPlatsLogical"
    }
  ],
  "kind": "resource",
  "abstract": false,
  "type": "Location",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Location",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "Location.id",
        "path": "Location.id",
        "mustSupport": true
      },
      {
        "id": "Location.extension",
        "path": "Location.extension",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "url"
            }
          ],
          "ordered": false,
          "rules": "open"
        },
        "min": 1
      },
      {
        "id": "Location.extension:period",
        "path": "Location.extension",
        "sliceName": "period",
        "min": 1,
        "max": "1",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://electronichealth.se/fhir/hvo/StructureDefinition/HVOLocationPeriodExtension"
            ]
          }
        ],
        "mustSupport": true
      },
      {
        "id": "Location.extension:period.url",
        "path": "Location.extension.url",
        "mustSupport": true
      },
      {
        "id": "Location.extension:period.value[x]",
        "path": "Location.extension.value[x]",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "Location.extension:period.value[x].start",
        "path": "Location.extension.value[x].start",
        "min": 1,
        "constraint": [
          {
            "key": "hvo-dateTime-2",
            "human": "DateTime should be submitted without timestamp",
            "source": "http://electronichealth.se/fhir/hvo/StructureDefinition/HVOLocation",
            "severity": "error",
            "expression": "$this.toString().contains('T') = false"
          }
        ],
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "giltigFrom"
          }
        ]
      },
      {
        "id": "Location.extension:period.value[x].end",
        "path": "Location.extension.value[x].end",
        "constraint": [
          {
            "key": "hvo-dateTime-2",
            "human": "DateTime should be submitted without timestamp",
            "source": "http://electronichealth.se/fhir/hvo/StructureDefinition/HVOLocation",
            "severity": "error",
            "expression": "$this.toString().contains('T') = false"
          }
        ],
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "giltigTom"
          }
        ]
      },
      {
        "id": "Location.extension:positionSweref",
        "path": "Location.extension",
        "sliceName": "positionSweref",
        "min": 0,
        "max": "1",
        "type": [
          {
            "code": "Extension",
            "profile": [
              "http://electronichealth.se/fhir/hvo/StructureDefinition/HVOSweref99PositionExtension"
            ]
          }
        ],
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "harPosition(HVOPositionLogical)"
          }
        ]
      },
      {
        "id": "Location.extension:positionSweref.extension:longitude",
        "path": "Location.extension.extension",
        "sliceName": "longitude",
        "mustSupport": true
      },
      {
        "id": "Location.extension:positionSweref.extension:latitude",
        "path": "Location.extension.extension",
        "sliceName": "latitude",
        "mustSupport": true
      },
      {
        "id": "Location.identifier",
        "path": "Location.identifier",
        "slicing": {
          "discriminator": [
            {
              "type": "value",
              "path": "system"
            }
          ],
          "rules": "open",
          "ordered": false,
          "description": "Slice on value based on the type code value"
        },
        "max": "1",
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "id"
          }
        ]
      },
      {
        "id": "Location.identifier:municipality",
        "path": "Location.identifier",
        "sliceName": "municipality",
        "short": "Identifier when Location is a municipality (sv: kommun)",
        "min": 0,
        "max": "1",
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "kommunkod"
          }
        ]
      },
      {
        "id": "Location.identifier:municipality.system",
        "path": "Location.identifier.system",
        "min": 1,
        "patternUri": "dummy.se/identifier/hvo-municipalities-scb",
        "mustSupport": true
      },
      {
        "id": "Location.identifier:municipality.value",
        "path": "Location.identifier.value",
        "min": 1,
        "mustSupport": true,
        "binding": {
          "strength": "required",
          "valueSet": "http://electronichealth.se/hvo/ValueSet/hvo-municipalities-scb"
        }
      },
      {
        "id": "Location.identifier:county",
        "path": "Location.identifier",
        "sliceName": "county",
        "short": "Identifier when Location is a county (sv: län)",
        "min": 0,
        "max": "1",
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "lanskod"
          }
        ]
      },
      {
        "id": "Location.identifier:county.system",
        "path": "Location.identifier.system",
        "min": 1,
        "patternUri": "dummy.se/identifier/hvo-counties-scb",
        "mustSupport": true
      },
      {
        "id": "Location.identifier:county.value",
        "path": "Location.identifier.value",
        "min": 1,
        "mustSupport": true,
        "binding": {
          "strength": "required",
          "valueSet": "http://electronichealth.se/hvo/ValueSet/hvo-counties-scb"
        }
      },
      {
        "id": "Location.status",
        "path": "Location.status",
        "min": 1,
        "mustSupport": true,
        "binding": {
          "strength": "required",
          "valueSet": "http://hl7.org/fhir/ValueSet/location-status"
        },
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "status"
          }
        ]
      },
      {
        "id": "Location.name",
        "path": "Location.name",
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "namn"
          }
        ]
      },
      {
        "id": "Location.description",
        "path": "Location.description",
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "beskrivning"
          }
        ]
      },
      {
        "id": "Location.type",
        "path": "Location.type",
        "short": "Code for functionality of location.",
        "mustSupport": true,
        "binding": {
          "strength": "required",
          "valueSet": "http://electronichealth.se/hvo/ValueSet/hvo-location-functionality"
        },
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "funktion"
          }
        ]
      },
      {
        "id": "Location.type.coding",
        "path": "Location.type.coding",
        "min": 1,
        "max": "1",
        "mustSupport": true
      },
      {
        "id": "Location.type.coding.system",
        "path": "Location.type.coding.system",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "Location.type.coding.code",
        "path": "Location.type.coding.code",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "Location.address",
        "path": "Location.address",
        "mustSupport": true
      },
      {
        "id": "Location.address.type",
        "path": "Location.address.type",
        "min": 1,
        "fixedCode": "physical",
        "mustSupport": true
      },
      {
        "id": "Location.address.line",
        "path": "Location.address.line",
        "short": "A line in an address, according to Swedish standard SS 637003:2015.\r\n For example: \r\nBacken Norrgården 1B, \r\nHedesunda, Gävle.\r\nThis repeating element order: The order in which lines should appear in an address label",
        "min": 1,
        "constraint": [
          {
            "key": "hvo-address-line-1",
            "human": "A line in an address should have max length of 128 characters",
            "source": "http://electronichealth.se/fhir/hvo/StructureDefinition/HVOLocation",
            "severity": "warning",
            "expression": "$this.length() <= 128"
          }
        ],
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "adressrad"
          }
        ]
      },
      {
        "id": "Location.form",
        "path": "Location.form",
        "mustSupport": true,
        "binding": {
          "strength": "required",
          "valueSet": "http://hl7.org/fhir/ValueSet/location-physical-type"
        },
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "typ"
          }
        ]
      },
      {
        "id": "Location.form.coding",
        "path": "Location.form.coding",
        "min": 1,
        "max": "1",
        "mustSupport": true
      },
      {
        "id": "Location.form.coding.system",
        "path": "Location.form.coding.system",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "Location.form.coding.code",
        "path": "Location.form.coding.code",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "Location.position",
        "path": "Location.position",
        "mustSupport": true
      },
      {
        "id": "Location.position.longitude",
        "path": "Location.position.longitude",
        "mustSupport": true
      },
      {
        "id": "Location.position.latitude",
        "path": "Location.position.latitude",
        "mustSupport": true
      },
      {
        "id": "Location.partOf",
        "path": "Location.partOf",
        "type": [
          {
            "code": "Reference",
            "targetProfile": [
              "http://electronichealth.se/fhir/hvo/StructureDefinition/HVOLocation"
            ],
            "extension": [
              {
                "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-hierarchy",
                "valueBoolean": true
              }
            ]
          }
        ],
        "mustSupport": true,
        "mapping": [
          {
            "identity": "HVOLocationToHVOPlatsLogical",
            "map": "delAv(HVOPlatsLogical)"
          }
        ]
      }
    ]
  }
}