@prefix fhir: <http://hl7.org/fhir/> .
@prefix loinc: <https://loinc.org/rdf/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# - resource -------------------------------------------------------------------

<http://hl7.org/fhir/Consent/consent-example-CDA> a fhir:Consent ;
  fhir:nodeRole fhir:treeRoot ;
  fhir:id [ fhir:v "consent-example-CDA"] ; # 
  fhir:identifier ( [
     fhir:system [
       fhir:v "urn:oid:2.16.840.1.113883.3.72.5.9.1"^^xsd:anyURI ;
       fhir:l <urn:oid:2.16.840.1.113883.3.72.5.9.1>
     ] ;
     fhir:value [ fhir:v "494e0c7a-a69e-4fb4-9d02-6aae747790d7" ]
  ] ) ; # The patient opts in to sharing CDA documents from a specific author to a specific recipient for a limited period, consent GUID generated by application
  fhir:status [ fhir:v "active"] ; # 
  fhir:category ( [
     fhir:coding ( [
       fhir:system [
         fhir:v "http://terminology.hl7.org/CodeSystem/consentcategorycodes"^^xsd:anyURI ;
         fhir:l <http://terminology.hl7.org/CodeSystem/consentcategorycodes>
       ] ;
       fhir:code [ fhir:v "npp" ]
     ] )
  ] ) ; # 
  fhir:subject [
     fhir:l <http://hl7.org/fhir/Patient/pat2> ;
     fhir:reference [ fhir:v "Patient/pat2" ]
  ] ; # one of the stock examples
  fhir:date [ fhir:v "2018-12-28"^^xsd:date] ; # 
  fhir:grantee ( [
     fhir:l <http://hl7.org/fhir/Patient/pat2> ;
     fhir:reference [ fhir:v "Patient/pat2" ]
  ] ) ; # author is patient themselves, and they sign
  fhir:controller ( [
     fhir:l <http://hl7.org/fhir/Organization/f001> ;
     fhir:reference [ fhir:v "Organization/f001" ]
  ] ) ; # this consent relates to sharing data with a specific recipient
  fhir:regulatoryBasis ( [
     fhir:coding ( [
       fhir:system [
         fhir:v "http://terminology.hl7.org/CodeSystem/v3-ActCode"^^xsd:anyURI ;
         fhir:l <http://terminology.hl7.org/CodeSystem/v3-ActCode>
       ] ;
       fhir:code [ fhir:v "INFA" ]
     ] )
  ] ) ; # This Consent would be the machine usable version of a Contract resource where the original language and signatures are located, <sourceReference>
#    <reference value="Contract/pcd-example-notAuthor"/>
#  </sourceReference>
  fhir:decision [ fhir:v "permit"] ; # A base denial of access to Dr. F001 but allows for sharing CDA documents of type Discharge Summary + Summarization of Episode Note from a specific author for a limited period
  fhir:provision ( [
     fhir:period [
       fhir:start [ fhir:v "2018-10-10"^^xsd:date ] ;
       fhir:end [ fhir:v "2019-10-10"^^xsd:date ]
     ] ;
     fhir:actor ( [
       fhir:role [
         fhir:coding ( [
           fhir:system [
             fhir:v "http://terminology.hl7.org/CodeSystem/v3-ParticipationType"^^xsd:anyURI ;
             fhir:l <http://terminology.hl7.org/CodeSystem/v3-ParticipationType>
           ] ;
           fhir:code [ fhir:v "PRCP" ]
         ] )
       ] ;
       fhir:reference [
         fhir:l <http://hl7.org/fhir/Practitioner/f001> ;
         fhir:reference [ fhir:v "Practitioner/f001" ]
       ] # Stock practitioner
     ] ) ;
     fhir:provision ( [
       fhir:actor ( [
         fhir:role [
           fhir:coding ( [
             fhir:system [
               fhir:v "http://terminology.hl7.org/CodeSystem/v3-ParticipationType"^^xsd:anyURI ;
               fhir:l <http://terminology.hl7.org/CodeSystem/v3-ParticipationType>
             ] ;
             fhir:code [ fhir:v "AUT" ]
           ] )
         ] ;
         fhir:reference [
           fhir:l <http://hl7.org/fhir/Practitioner/xcda-author> ;
           fhir:reference [ fhir:v "Practitioner/xcda-author" ]
         ]
       ] ) ;
       fhir:documentType ( [
         fhir:system [
           fhir:v "urn:ietf:bcp:13"^^xsd:anyURI ;
           fhir:l <urn:ietf:bcp:13>
         ] ;
         fhir:code [ fhir:v "application/hl7-cda+xml" ]
       ] ) ; # CDA documents
       fhir:code ( [
         a loinc:34133-9 ;
         fhir:coding ( [
           fhir:system [
             fhir:v "http://loinc.org"^^xsd:anyURI ;
             fhir:l <http://loinc.org>
           ] ;
           fhir:code [ fhir:v "34133-9" ]
         ] )
       ] [
         a loinc:18842-5 ;
         fhir:coding ( [
           fhir:system [
             fhir:v "http://loinc.org"^^xsd:anyURI ;
             fhir:l <http://loinc.org>
           ] ;
           fhir:code [ fhir:v "18842-5" ]
         ] )
       ] ) # code rules
     ] )
  ] ) . # 

<http://hl7.org/fhir/Patient/pat2> a fhir:Patient .

<http://hl7.org/fhir/Organization/f001> a fhir:Organization .

<http://hl7.org/fhir/Practitioner/f001> a fhir:Practitioner .

<http://hl7.org/fhir/Practitioner/xcda-author> a fhir:Practitioner .

# -------------------------------------------------------------------------------------

