{
  "resourceType": "http://hl7.org/fhir/uv/sql-on-fhir/StructureDefinition/ViewDefinition",
  "resource": "Bundle",
  "id": "ViewDefinition-Middelengebruik",
  "title": "Middelengebruik",
  "select": [
    {
      "column": [
        {
          "path": "meta.extension('http://hl7.org/fhir/4.0/StructureDefinition/extension-Meta.source').valueUri",
          "name": "Bron",          
          "type": "string",
          "tag": [ { "name": "Zib element", "value": "nvt" } ],
          "description": "Lookup adhv uri (AGB-Z of OID) <code>&lt;adressering-base&gt;/Organization?identifier=&lt;meta.tag.code&gt;</code> en gebruik dan <code>Organization.name</code>"
        },
        {
          "path": "issued",
          "name": "Datum",          
          "type": "dateTime",
          "tag": [ { "name": "Zib element", "value": "WaarnemingGebruik" } ],
          "description": "Datum van de vaststelling van het gebruik."
        },
        {
          "path": "iif(effectivePeriod.start.exists() and effectivePeriod.end.exists(), effectivePeriod.start.toString()+' tot '+effectivePeriod.end.toString(), iif(effectivePeriod.start.exists(), 'vanaf '+effectivePeriod.start.toString(), iif(effectivePeriod.end.exists(), 'tot '+effectivePeriod.end.toString(), 'vanaf '+effectiveDateTime.toString())))",
          "name": "Gebruiksperiode",
          "type": "string",
          "tag": [ { "name": "Zib element", "value": "WaarnemingGebruik" } ],
          "description": "EffectivePeriod is voorgeschreven in de ZIB, maar in veel gevallen zal de data geen periode bevatten. In die gevallen is de datum van vaststelling bepalend voor interpretatie."
        },
        {
          "path": "code.text | code.coding[0].display",
          "name": "Soort gebruik",
          "type": "string",
          "tag": [ { "name": "Zib element", "value": "NVT" } ],
          "description": "Code van de ZIB voor middelengebruik"
        },
        {
          "path": "valueCodeableConcept.coding[0].display",
          "name": "Status",
          "type": "string",
          "tag": [ { "name": "Zib element", "value": "Status" } ],
          "description": "Indicatie of in het heden of verleden sprake is (geweest) van middelengebruik."
        },
        {
          "path": "iif(component.where(code.coding.where(code='410675002').exists()).valueCodeableConcept.exists(), component.where(code.coding.where(code='410942007').exists() or code.coding.where(code='53661000146106').exists()).valueCodeableConcept.coding[0].display + ' ' + component.where(code.coding.where(code='410675002').exists()).valueCodeableConcept.coding[0].display, component.where(code.coding.where(code='410942007').exists() or code.coding.where(code='53661000146106').exists()).valueCodeableConcept.coding[0].display)",
          "name": "Middel",
          "type": "string",
          "tag": [ { "name": "Zib element", "value": "Middel" } ],
          "description": "Soort middel en toedieningsvorm"
        },
        {
          "path": "iif(component.where(code.coding.where(code='401201003').exists()).exists(), component.where(code.coding.where(code='266918002').exists() or code.coding.where(code='228390007').exists() or code.coding.where(code='160573003').exists()).valueQuantity.value.toString()+' '+component.where(code.coding.where(code='266918002').exists() or code.coding.where(code='228390007').exists() or code.coding.where(code='160573003').exists()).valueQuantity.unit+' ('+component.where(code.coding.where(code='401201003').exists()).valueQuantity.value.toString()+' '+component.where(code.coding.where(code='401201003').exists()).valueQuantity.unit+')', component.where(code.coding.where(code='266918002').exists() or code.coding.where(code='228390007').exists() or code.coding.where(code='160573003').exists()).valueQuantity.value.toString()+' '+component.where(code.coding.where(code='266918002').exists() or code.coding.where(code='228390007').exists() or code.coding.where(code='160573003').exists()).valueQuantity.unit)",
          "name": "Hoeveelheid",
          "type": "string",
          "tag": [ { "name": "Zib element", "value": "Hoeveelheid" } ],
          "description": "Het aantal eenheden (glazen, sigaretten, pillen, shots etc.) per dag, week, maand of jaar of de freqentie van gebruik."
        },
        {
          "path": "comment | note.text",
          "name": "+Toelichting",
          "type": "string",
          "tag": [ { "name": "Zib element", "value": "Toelichting" } ]
        }
      ],
      "forEach": "entry.resource.where(resourceType='Observation' and (code.coding.where(system='http://snomed.info/sct' and (code='228273003' or code='228366006' or code='365980008')).exists() or code.coding.where(system='http://loinc.org' and (code='11331-6' or code='72166-2' or code='11343-1')).exists() or code.coding.where(system='https://referentiemodel.nhg.org/tabellen/nhg-tabel-45-diagnostische-bepalingen' and (code='1739' or code='1591' or code='2418' or code='2419' or code='2420' or code='2421' or code='2422' or code='3022')).exists()))"
    }
  ]
}