PREFIX sx: <http://www.w3.org/ns/shex#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

[] a sx:Schema ;
    sx:shapes (<http://a.example/#Observation> <http://a.example/#Vital> <http://a.example/#PostureVital> <http://a.example/#ReclinedVital> <http://a.example/#BP> <http://a.example/#PostureBP> <http://a.example/#ReclinedBP> <http://a.example/#Pulse> <http://a.example/#PosturePulse> <http://a.example/#ReclinedPulse> <http://a.example/#Posture> <http://a.example/#Reclined>) .

<http://a.example/#Observation> a sx:ShapeDecl ; sx:shapeExpr [ a sx:Shape ;
sx:expression [ a sx:EachOf;
    sx:expressions ( [ a sx:TripleConstraint ;
            sx:predicate <http://hl7.org/ns/fhir#code> ;
            sx:min 0;
            sx:max 1
        ]
        [ a sx:TripleConstraint ;
            sx:predicate <http://hl7.org/ns/fhir#component>  ;
            sx:valueExpr [ a sx:Shape ;
                sx:expression [ a sx:EachOf;
                    sx:expressions ( [ a sx:TripleConstraint ;
                            sx:predicate <http://hl7.org/ns/fhir#code>
                        ]
                        [ a sx:TripleConstraint ;
                            sx:predicate <http://hl7.org/ns/fhir#value>
                        ]
                    )
                ]
            ];
            sx:min 0;
            sx:max -1
        ]
    )
] ] .

<http://a.example/#Vital> a sx:ShapeDecl ;
    sx:abstract true ;
    sx:shapeExpr [ a sx:ShapeAnd ;
        sx:shapeExprs (
            <http://a.example/#Observation>
            [ a sx:Shape ]
        )
    ] .

<http://a.example/#PostureVital> a sx:ShapeDecl ;
    sx:abstract true ;
    sx:shapeExpr [ a sx:ShapeAnd ;
        sx:shapeExprs (
            <http://a.example/#Vital>
            [ a sx:Shape ;
                sx:extends (<http://a.example/#Posture>)
            ]
        )
    ] .

<http://a.example/#ReclinedVital> a sx:ShapeDecl ;
    sx:abstract true ;
    sx:shapeExpr [ a sx:ShapeAnd ;
        sx:shapeExprs (
            <http://a.example/#PostureVital>
            [ a sx:Shape ;
                sx:extends (<http://a.example/#Reclined>)
            ]
        )
    ] .

<http://a.example/#BP> a sx:ShapeDecl ; sx:shapeExpr [ a sx:ShapeAnd ;
    sx:shapeExprs (
        [ a sx:Shape ;
            sx:extends (<http://a.example/#Vital>)
        ]
        [ a sx:Shape ;
            sx:expression [ a sx:EachOf;
                sx:expressions ( [ a sx:TripleConstraint ;
                        sx:predicate <http://hl7.org/ns/fhir#component>  ;
                        sx:valueExpr [ a sx:Shape ;
                            sx:expression [ a sx:TripleConstraint ;
                                sx:predicate <http://hl7.org/ns/fhir#code>  ;
                                sx:valueExpr [ a sx:NodeConstraint ;
                                    sx:values ("systolic")
                                ]
                            ]
                        ]
                    ]
                    [ a sx:TripleConstraint ;
                        sx:predicate <http://hl7.org/ns/fhir#component>  ;
                        sx:valueExpr [ a sx:Shape ;
                            sx:expression [ a sx:TripleConstraint ;
                                sx:predicate <http://hl7.org/ns/fhir#code>  ;
                                sx:valueExpr [ a sx:NodeConstraint ;
                                    sx:values ("diastolic")
                                ]
                            ]
                        ]
                    ]
                )
            ]
        ]
    ) ] .

<http://a.example/#PostureBP> a sx:ShapeDecl ; sx:shapeExpr [ a sx:Shape ;
    sx:extends (<http://a.example/#BP> <http://a.example/#PostureVital>) ] .

<http://a.example/#ReclinedBP> a sx:ShapeDecl ; sx:shapeExpr [ a sx:Shape ;
    sx:extends (<http://a.example/#BP> <http://a.example/#ReclinedVital>) ] .

<http://a.example/#Pulse> a sx:ShapeDecl ; sx:shapeExpr [ a sx:ShapeAnd ;
    sx:shapeExprs (
        [ a sx:Shape ;
            sx:extends (<http://a.example/#Vital>)
        ]
        [ a sx:Shape ;
            sx:expression [ a sx:TripleConstraint ;
                sx:predicate <http://hl7.org/ns/fhir#code>  ;
                sx:valueExpr [ a sx:NodeConstraint ;
                    sx:values ("pulse")
                ]
            ]
        ]
    ) ] .

<http://a.example/#PosturePulse> a sx:ShapeDecl ; sx:shapeExpr [ a sx:Shape ;
    sx:extends (<http://a.example/#Pulse> <http://a.example/#PostureVital>) ] .

<http://a.example/#ReclinedPulse> a sx:ShapeDecl ; sx:shapeExpr [ a sx:Shape ;
    sx:extends (<http://a.example/#Pulse> <http://a.example/#ReclinedVital>) ] .

<http://a.example/#Posture> a sx:ShapeDecl ; sx:shapeExpr [ a sx:Shape ; sx:expression [ a sx:TripleConstraint ;
    sx:predicate <http://hl7.org/ns/fhir#component>  ;
    sx:valueExpr [ a sx:Shape ;
        sx:expression [ a sx:TripleConstraint ;
            sx:predicate <http://hl7.org/ns/fhir#code>  ;
            sx:valueExpr [ a sx:NodeConstraint ;
                sx:values ("posture")
            ]
        ]
    ]
] ] .

<http://a.example/#Reclined> a sx:ShapeDecl ; sx:shapeExpr [ a sx:ShapeAnd ;
    sx:shapeExprs (
        <http://a.example/#Posture>
        [ a sx:Shape ;
            sx:expression [ a sx:TripleConstraint ;
                sx:predicate <http://hl7.org/ns/fhir#component>  ;
                sx:valueExpr [ a sx:Shape ;
                    sx:expression [ a sx:EachOf;
                        sx:expressions ( [ a sx:TripleConstraint ;
                                sx:predicate <http://hl7.org/ns/fhir#code>  ;
                                sx:valueExpr [ a sx:NodeConstraint ;
                                    sx:values ("posture")
                                ]
                            ]
                            [ a sx:TripleConstraint ;
                                sx:predicate <http://hl7.org/ns/fhir#value>  ;
                                sx:valueExpr [ a sx:NodeConstraint ;
                                    sx:values ("reclined")
                                ]
                            ]
                        )
                    ]
                ]
            ]
        ]
    ) ] .

