PREFIX : <http://hl7.org/fhir/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
BASE <http://schema.example/>
PREFIX sx: <http://www.w3.org/ns/shex#>

[]
  a sx:Schema ;
  sx:start <ObservationShape> ;
  sx:shapes (
    <ObservationShape>
    <PatientShape>
 ) .

<ObservationShape>                 # An Observation has:
  a sx:ShapeDecl ;
  sx:shapeExpr [
    a sx:Shape ;
    sx:expression [
      a sx:EachOf ;
      sx:expressions (
        [                             #   status in this value set
          a sx:TripleConstraint ;
          sx:predicate :status ;
          sx:valueExpr [
            a sx:NodeConstraint ;
            sx:values (
              "preliminary"
              "final"
            )
          ]
        ]
        [                             #   a subject matching <PatientShape>.
          a sx:TripleConstraint ;
          sx:predicate :subject ;
          sx:valueExpr <PatientShape>
        ]
      )
    ]
  ] .

<PatientShape>                     # A Patient has:
  a sx:ShapeDecl ;
  sx:shapeExpr [
    a sx:Shape ;
    sx:expression [
      a sx:EachOf ;
      sx:expressions (
        [                             #   one or more names
          a sx:TripleConstraint ;
          sx:max -1 ;
          sx:min 0 ;
          sx:predicate :name ;
          sx:valueExpr [
            a sx:NodeConstraint ;
            sx:datatype xsd:string
          ]
        ]
        [                             #   and an optional birthdate.
          a sx:TripleConstraint ;
          sx:max 1 ;
          sx:min 0 ;
          sx:predicate :birthdate ;
          sx:valueExpr [
            a sx:NodeConstraint ;
            sx:datatype xsd:date
          ]
        ]
      )
    ]
  ] .
