# The shapes of the Cascade vocabulary, https://ns.cascadeprotocol.org/cascade#.
#
# Licensed Apache-2.0 AND CC-BY-4.0, as NOTICE says.

@prefix cascade: <https://ns.cascadeprotocol.org/cascade#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix oa: <http://www.w3.org/ns/oa#> .
@prefix obo: <http://purl.obolibrary.org/obo/> .
@prefix org: <http://www.w3.org/ns/org#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix pav: <http://purl.org/pav/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix semapv: <https://w3id.org/semapv/vocab/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix solid: <http://www.w3.org/ns/solid/terms#> .
@prefix sssom: <https://w3id.org/sssom/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# The person

cascade:PatientProfileShape a sh:NodeShape ;
    sh:targetClass cascade:PatientProfile ;
    sh:targetSubjectsOf cascade:dateOfBirth , foaf:givenName , foaf:familyName , foaf:name ,
        cascade:administrativeGender , cascade:deceased , cascade:dateOfDeath ;

    sh:property [
        sh:path cascade:dateOfBirth ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A date of birth is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:administrativeGender ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ( "male" "female" "other" "unknown" ) ;
        sh:message "An administrative gender is one code of FHIR R4's AdministrativeGender: male, female, other or unknown. A C-CDA code is mapped into them by C-CDA on FHIR's concept map, never written as its source gave it."@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:deceased ;
        sh:datatype xsd:boolean ;
        sh:maxCount 1 ;
        sh:message "Whether the person has died is one xsd:boolean."@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:dateOfDeath ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A date of death is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as a date of birth is."@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path foaf:givenName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "foaf:givenName must be a single non-empty string. The cardinality is a deliberate 1: a second given name goes in foaf:name, which carries the whole name as one string."@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path foaf:familyName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "foaf:familyName must be a single non-empty string."@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path foaf:name ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "foaf:name must be a single non-empty string: the whole name as one string, which is what IPS Patient.name.text carries."@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:sourceRecordId ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:severity sh:Violation
    ] ;

    sh:or (
        [ sh:path cascade:dateOfDeath ; sh:maxCount 0 ]
        [ sh:path cascade:deceased ; sh:not [ sh:hasValue false ] ]
    ) ;
    sh:message "A time of death is a death: a version that holds a date of death does not say the person has not died."@en ;
    sh:severity sh:Violation .

# Allergies, conditions, vaccinations and lab results

cascade:AllergyOrIntoleranceShape a sh:NodeShape ;
    sh:targetClass cascade:AllergyOrIntolerance ;
    sh:targetSubjectsOf cascade:allergenName , cascade:allergenCode , cascade:reactionManifestationText , cascade:reactionManifestationCode ,
        cascade:allergySeverity , cascade:allergyCategory , cascade:allergyType , cascade:allergyCriticality ;

    sh:property [
        sh:path cascade:allergenName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "An allergy states at most one non-empty allergenName"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:reactionManifestationText ;
        sh:datatype xsd:string ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:allergySeverity ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("mild" "moderate" "severe") ;
        sh:message "Allergy severity must be one of the FHIR R4 AllergyIntoleranceSeverity codes: mild, moderate, severe"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:allergyCategory ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("food" "medication" "environment" "biologic") ;
        sh:message "Allergy category must be one of the FHIR R4 AllergyIntoleranceCategory codes: food, medication, environment, biologic"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:onsetDate ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "An onset date is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:sourceRecordId ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:clinicalStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("active" "inactive" "resolved") ;
        sh:message "Allergy clinical status should be one of the FHIR R4 AllergyIntolerance clinical status codes: active, inactive, resolved. A repudiated record is entered-in-error on cascade:verificationStatus, which is a different element"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:verificationStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("unconfirmed" "confirmed" "refuted" "entered-in-error") ;
        sh:message "Allergy verification status should be one of the FHIR R4 AllergyIntolerance verification status codes: unconfirmed, confirmed, refuted, entered-in-error"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:allergenCode ;
        sh:nodeKind sh:IRI ;
        sh:message "Allergen code should be an IRI in the code system's own IRI space (for example http://snomed.info/id/373270004 or https://ns.cascadeprotocol.org/codes/rxnorm/7980), carrying one FHIR R4 AllergyIntolerance.code.coding per value. The IPS value set is allergies-intolerances-uv-ips"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:reactionManifestationCode ;
        sh:nodeKind sh:IRI ;
        sh:message "Manifestation code should be an IRI in the code system's own IRI space (for example http://snomed.info/id/247472004 for hives), carrying one FHIR R4 AllergyIntolerance.reaction.manifestation.coding per value. The IPS value set is allergy-reaction-uv-ips"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:allergyType ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("allergy" "intolerance") ;
        sh:message "Allergy type should be one of the FHIR R4 AllergyIntoleranceType codes: allergy, intolerance"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:allergyCriticality ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("low" "high" "unable-to-assess") ;
        sh:message "Allergy criticality should be one of the FHIR R4 AllergyIntoleranceCriticality codes: low, high, unable-to-assess. An observed reaction's severity is a different element and belongs on cascade:allergySeverity"@en ;
        sh:severity sh:Warning
    ] .

cascade:ProblemOrDiagnosisShape a sh:NodeShape ;
    sh:targetClass cascade:ProblemOrDiagnosis ;
    sh:targetSubjectsOf cascade:conditionName , cascade:conditionCode , cascade:conditionCategory , cascade:abatementDate ,
        cascade:conditionCodeInOtherSystem ;

    sh:property [
        sh:path cascade:conditionName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A condition states at most one non-empty conditionName"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:clinicalStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("active" "recurrence" "relapse" "inactive" "remission" "resolved") ;
        sh:message "Condition status must be one of the FHIR R4 ConditionClinicalStatusCodes: active, recurrence, relapse, inactive, remission, resolved"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:verificationStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("unconfirmed" "provisional" "differential" "confirmed" "refuted" "entered-in-error") ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:onsetDate ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "An onset date is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:abatementDate ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "An abatement date is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:conditionCategory ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("problem-list-item" "encounter-diagnosis") ;
        sh:message "Condition category should be one of the two FHIR R4 condition-category codes: problem-list-item, encounter-diagnosis (https://hl7.org/fhir/R4/valueset-condition-category.html). C-CDA section words such as \"diagnosis\" or \"problem\" are not members of this value set."@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:conditionCodeInOtherSystem ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:not cascade:LiteralTypedByAnXsdOrRdfDatatypeShape ;
        sh:message "A condition code in another system is a non-empty literal typed by its system's URI, never a plain or language-tagged string or another XSD or RDF datatype, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:conditionCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape ;
        sh:message "A condition code in another system is typed by the URI the system table gives its system, never by urn:oid: or URN:OID: and an OID in the table, or by a URI the table reads as another"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:conditionCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByAListedSystemUriShape ;
        sh:message "A condition code in a system the vocabulary lists a code IRI form for is a cascade:conditionCode IRI, never a literal typed by that system's URI"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:conditionCode ;
        sh:node cascade:CodeInAListedSystemShape ;
        sh:message "A condition code is a code IRI of a code system the vocabulary lists, in that system's form, one per coding the source gave; a NullFlavor or data absent reason is no code, it is a value absent for a reason"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:sourceRecordId ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:severity sh:Violation
    ] .

cascade:VaccinationShape a sh:NodeShape ;
    sh:targetClass cascade:Vaccination ;
    sh:targetSubjectsOf cascade:vaccineName , cascade:vaccineCode , cascade:vaccinationOccurrenceTime , cascade:vaccineLotNumber ,
        cascade:vaccineDoseQuantityText , cascade:vaccinationRouteText , cascade:vaccinationBodySiteText ;

    sh:property [
        sh:path cascade:vaccineName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "An immunization states at most one non-empty vaccineName"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:vaccinationOccurrenceTime ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A vaccination occurrence time is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:workflowStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("completed" "entered-in-error" "not-done") ;
        sh:message "Immunization status must be one of the FHIR R4 ImmunizationStatusCodes: completed, entered-in-error, not-done"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:vaccineCode ;
        sh:node cascade:CvxCodeShape ;
        sh:message "A vaccine code is a CVX code's IRI, one for each CVX coding the source gives"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:vaccineLotNumber ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:message "Immunization must not carry more than one vaccineLotNumber; a lot number identifies a single administered dose"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:vaccineDoseQuantityText ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:vaccinationRouteText ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:vaccinationBodySiteText ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:sourceRecordId ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:severity sh:Violation
    ] .

cascade:LaboratoryTestResultShape a sh:NodeShape ;
    sh:targetClass cascade:LaboratoryTestResult ;
    sh:targetSubjectsOf cascade:testName , cascade:testCode , cascade:testCodeInOtherSystem , cascade:resultValueText , cascade:resultUnitText ,
        cascade:referenceRangeText , cascade:resultClinicallyRelevantTime ;

    sh:property [
        sh:path cascade:testName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A lab result states at most one non-empty test name"@en
    ] ;

    sh:property [
        sh:path cascade:testCode ;
        sh:nodeKind sh:IRI ;
        sh:message "A test code is a code IRI, one per coding the source gave"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:testCodeInOtherSystem ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:not cascade:LiteralTypedByAnXsdOrRdfDatatypeShape ;
        sh:message "A test code in another system is a non-empty literal typed by its system's URI, never a plain or language-tagged string or another XSD or RDF datatype, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:testCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape ;
        sh:message "A test code in another system is typed by the URI the system table gives its system, never by urn:oid: or URN:OID: and an OID in the table, or by a URI the table reads as another"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:testCodeInOtherSystem ;
        sh:not [ sh:or ( [ sh:datatype <http://loinc.org> ] [ sh:datatype <http://snomed.info/sct> ] ) ] ;
        sh:message "A LOINC or SNOMED CT test code is a cascade:testCode IRI, never a literal typed by http://loinc.org or http://snomed.info/sct"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:resultValueText ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:message "Lab result must not carry more than one resultValueText; two readings of the same analyte are two records"@en
    ] ;

    sh:property [
        sh:path cascade:resultUnitText ;
        sh:datatype xsd:string ;
        sh:maxCount 1
    ] ;

    sh:property [
        sh:path cascade:referenceRangeText ;
        sh:datatype xsd:string ;
        sh:maxCount 1
    ] ;

    sh:property [
        sh:path cascade:resultClinicallyRelevantTime ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A result's clinically relevant time is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en
    ] ;

    sh:property [
        sh:path dct:identifier ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:message "A lab result's business identifier is a non-empty literal, whose datatype names the identifier system, or a plain string when no system is stated."@en
    ] ;

    sh:property [
        sh:path cascade:workflowStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("registered" "preliminary" "final" "amended" "corrected" "cancelled" "entered-in-error" "unknown") ;
        sh:message "Lab result status should be one of the ObservationStatus codes: registered, preliminary, final, amended, corrected, cancelled, entered-in-error, unknown"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path prov:wasAttributedTo ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A lab result's version is attributed to at most one organization, the one its performer names, by the IRI of its cascade:Organization record"@en
    ] ;

    sh:property [
        sh:path cascade:sourceRecordId ;
        sh:datatype xsd:string ;
        sh:maxCount 1
    ] .

# Procedures and medications

cascade:MedicalProcedureShape a sh:NodeShape ;
    sh:targetClass cascade:MedicalProcedure ;
    sh:targetSubjectsOf cascade:procedureName , cascade:procedureDate , cascade:procedureCode , cascade:procedureCodeInOtherSystem ;

    sh:property [
        sh:path cascade:procedureName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "Procedure name must be a single non-empty string"@en
    ] ;

    sh:property [
        sh:path cascade:procedureDate ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A procedure date is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en
    ] ;

    sh:property [
        sh:path cascade:workflowStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("preparation" "in-progress" "not-done" "on-hold" "stopped" "completed" "entered-in-error" "unknown")
    ] ;

    sh:property [
        sh:path cascade:procedureCode ;
        sh:node cascade:CodeInAListedSystemShape ;
        sh:message "A procedure code is a code IRI of a code system the vocabulary lists, in that system's form, one per coding the source gave; a NullFlavor or data absent reason is no code, it is a value absent for a reason"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:procedureCodeInOtherSystem ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:not cascade:LiteralTypedByAnXsdOrRdfDatatypeShape ;
        sh:message "A procedure code in another system is a non-empty literal typed by its system's URI, never a plain or language-tagged string or another XSD or RDF datatype, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:procedureCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape ;
        sh:message "A procedure code in another system is typed by the URI the system table gives its system, never by urn:oid: or URN:OID: and an OID in the table, or by a URI the table reads as another"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:procedureCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByAListedSystemUriShape ;
        sh:message "A procedure code in a system the vocabulary lists a code IRI form for is a cascade:procedureCode IRI, never a literal typed by that system's URI"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:sourceRecordId ;
        sh:datatype xsd:string ;
        sh:maxCount 1
    ] .

cascade:PrescribedOrReportedMedicationShape a sh:NodeShape ;
    sh:targetClass cascade:PrescribedOrReportedMedication ;
    sh:targetSubjectsOf cascade:drugName , cascade:rxNormCode , cascade:ndcCode , cascade:medicationCodeInOtherSystem , cascade:userSelectedCode ,
        cascade:prescribedOrReported , cascade:dosageInstructionText , cascade:medicationUseStartDate , cascade:medicationUseEndDate ,
        cascade:prescriptionWrittenDate , cascade:medicationRequestIntent , cascade:courseOfTherapyType ,
        cascade:numberOfRepeatsAllowed , cascade:expectedSupplyDuration , cascade:dispenseRequestValidityPeriodStart ,
        cascade:dispenseRequestValidityPeriodEnd , cascade:structuredDosage ;

    sh:property [
        sh:path [ sh:inversePath prov:specializationOf ] ;
        sh:node [
            sh:property [
                sh:path cascade:prescribedOrReported ;
                sh:minCount 1 ;
                sh:maxCount 1
            ]
        ] ;
        sh:message "Every version of a medication states once whether it came from a prescription or from a list of what the person takes"@en
    ] ;

    sh:property [
        sh:path cascade:prescribedOrReported ;
        sh:datatype xsd:string ;
        sh:in ("prescribed" "reportedUse") ;
        sh:message "A medication's prescribedOrReported is \"prescribed\", from a prescription, or \"reportedUse\", from a list of what the person takes"@en
    ] ;

    sh:property [
        sh:path cascade:drugName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A medication states at most one non-empty drug name"@en
    ] ;

    sh:property [
        sh:path cascade:rxNormCode ;
        sh:nodeKind sh:IRI ;
        sh:message "An RxNorm code should be an IRI in RxNorm's own IRI space, for example https://ns.cascadeprotocol.org/codes/rxnorm/314076"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:ndcCode ;
        sh:nodeKind sh:IRI ;
        sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/ndc11/[0-9]{11}$" ;
        sh:message "An NDC is Cascade's 11-digit IRI, https://ns.cascadeprotocol.org/codes/ndc11/ and 11 digits; the 10-digit hyphenated form is normalised by the adapter, never kept"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:medicationCodeInOtherSystem ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:not cascade:LiteralTypedByAnXsdOrRdfDatatypeShape ;
        sh:message "A medication code in another system is a non-empty literal typed by its system's URI, never a plain or language-tagged string or another XSD or RDF datatype, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:medicationCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape ;
        sh:message "A medication code in another system is typed by the URI the system table gives its system, never by urn:oid: or URN:OID: and an OID in the table, or by a URI the table reads as another"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:medicationCodeInOtherSystem ;
        sh:not [ sh:or ( [ sh:datatype <http://www.nlm.nih.gov/research/umls/rxnorm> ] [ sh:datatype <http://hl7.org/fhir/sid/ndc> ] ) ] ;
        sh:message "An RxNorm or NDC medication code is a cascade:rxNormCode or cascade:ndcCode IRI, never a literal typed by http://www.nlm.nih.gov/research/umls/rxnorm or http://hl7.org/fhir/sid/ndc"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:userSelectedCode ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A medication marks at most one code as the one its source chose"@en
    ] ;

    sh:property [
        sh:path cascade:dosageInstructionText ;
        sh:datatype xsd:string ;
        sh:maxCount 1
    ] ;

    sh:property [
        sh:path cascade:workflowStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1
    ] ;

    sh:property [
        sh:path cascade:medicationUseStartDate ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A medication use start date is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en
    ] ;

    sh:property [
        sh:path cascade:medicationUseEndDate ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A medication use end date is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en
    ] ;

    sh:property [
        sh:path cascade:prescriptionWrittenDate ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A medication states at most one date its prescription was written, which is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote, as FHIR RDF types a date: a year or a month is never padded to a day, nor a day given a time; an untyped or xsd:string literal is none of them."@en
    ] ;

    sh:property [
        sh:path cascade:medicationRequestIntent ;
        sh:datatype xsd:string ;
        sh:in ("proposal" "plan" "order" "original-order" "reflex-order" "filler-order" "instance-order" "option") ;
        sh:maxCount 1 ;
        sh:message "A medication states at most one request intent, one of FHIR's MedicationRequest.intent codes: proposal, plan, order, original-order, reflex-order, filler-order, instance-order or option"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:courseOfTherapyType ;
        sh:datatype xsd:string ;
        sh:in ("continuous" "acute" "seasonal") ;
        sh:maxCount 1 ;
        sh:message "A medication states at most one course of therapy, a code of FHIR's medicationrequest-course-of-therapy: continuous, acute or seasonal"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:numberOfRepeatsAllowed ;
        sh:datatype xsd:integer ;
        sh:minInclusive 0 ;
        sh:maxCount 1 ;
        sh:message "A medication states at most one number of repeats allowed, an xsd:integer of 0 or more"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:expectedSupplyDuration ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:node cascade:DurationQuantityShape ;
        sh:message "A medication states at most one expected supply duration, a quantity node of its version in a UCUM unit of time"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:dispenseRequestValidityPeriodStart ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A medication states at most one start of its dispensing window, which is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:dispenseRequestValidityPeriodEnd ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A medication states at most one end of its dispensing window, which is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:structuredDosage ;
        sh:nodeKind sh:IRI ;
        sh:message "A medication's structured dosage is a node of its version, <version>#dosage-n"@en ;
        sh:severity sh:Violation
    ] ;

    sh:property [
        sh:path cascade:sourceRecordId ;
        sh:datatype xsd:string ;
        sh:maxCount 1
    ] .

cascade:StructuredDosageShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:dosageDoseQuantity , cascade:dosageRepeatFrequency , cascade:dosageRepeatPeriod , cascade:dosageRepeatPeriodUnit ,
        cascade:dosageBoundsPeriodStart , cascade:dosageBoundsPeriodEnd , cascade:dosageRouteCode , cascade:dosageRouteCodeInOtherSystem ;
    sh:property [
        sh:path cascade:dosageDoseQuantity ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A dosage states at most one dose quantity, a quantity node of its version"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dosageRepeatFrequency ;
        sh:datatype xsd:integer ;
        sh:minInclusive 1 ;
        sh:maxCount 1 ;
        sh:message "A dosage states at most one frequency, an xsd:integer of 1 or more"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dosageRepeatPeriod ;
        sh:datatype xsd:decimal ;
        sh:maxCount 1 ;
        sh:message "A dosage states at most one period, an xsd:decimal"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dosageRepeatPeriodUnit ;
        sh:datatype xsd:string ;
        sh:in ("s" "min" "h" "d" "wk" "mo" "a") ;
        sh:maxCount 1 ;
        sh:message "A dosage states at most one period unit, one of FHIR's units of time: s, min, h, d, wk, mo or a"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dosageBoundsPeriodStart ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A dosage states at most one start of its bounds, which is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dosageBoundsPeriodEnd ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A dosage states at most one end of its bounds, which is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dosageRouteCode ;
        sh:nodeKind sh:IRI ;
        sh:node cascade:SnomedCtCodeShape ;
        sh:message "A dosage's route code is a SNOMED CT code IRI, http://snomed.info/id/ and the concept id"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dosageRouteCodeInOtherSystem ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:not cascade:LiteralTypedByAnXsdOrRdfDatatypeShape ;
        sh:message "A route code in another system is a non-empty literal typed by its system's URI, never a plain or language-tagged string or another XSD or RDF datatype, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dosageRouteCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape ;
        sh:message "A route code in another system is typed by the URI the system table gives its system, never by urn:oid: or URN:OID: and an OID in the table, or by a URI the table reads as another"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dosageRouteCodeInOtherSystem ;
        sh:not [ sh:or ( [ sh:datatype <http://snomed.info/sct> ] ) ] ;
        sh:message "A SNOMED CT route code is a cascade:dosageRouteCode IRI, never a literal typed by http://snomed.info/sct"@en ;
        sh:severity sh:Violation
    ] .

# Genetic variants and their interpretations

cascade:GeneticVariantFindingShape a sh:NodeShape ;
    sh:targetClass cascade:GeneticVariantFinding ;
    sh:targetSubjectsOf cascade:hgvsCodingDnaExpression , cascade:clinvarVariationId , cascade:geneSymbol ;

    sh:property [
        sh:path cascade:workflowStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("registered" "preliminary" "final" "amended" "corrected" "cancelled" "entered-in-error" "unknown") ;
        sh:message "A genetic variant finding's status should be one of the FHIR R4 ObservationStatus codes: registered, preliminary, final, amended, corrected, cancelled, entered-in-error, unknown"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path [ sh:inversePath prov:specializationOf ] ;
        sh:node [
            sh:property [
                sh:path cascade:hgvsCodingDnaExpression ;
                sh:maxCount 1
            ]
        ] ;
        sh:message "Every version of a variant states at most one HGVS coding expression: only an entry of the variants view takes every member's"@en
    ] ;

    sh:property [
        sh:path [ sh:inversePath prov:specializationOf ] ;
        sh:node [
            sh:property [
                sh:path cascade:clinvarVariationId ;
                sh:maxCount 1
            ]
        ] ;
        sh:message "Every version of a variant states at most one ClinVar VariationID: only an entry of the variants view takes every member's"@en
    ] ;

    sh:property [
        sh:path [ sh:inversePath prov:specializationOf ] ;
        sh:node [
            sh:property [
                sh:path cascade:geneSymbol ;
                sh:maxCount 1
            ]
        ] ;
        sh:message "Every version of a variant states at most one gene symbol: only an entry of the variants view takes every member's"@en
    ] ;

    sh:property [
        sh:path cascade:hgvsCodingDnaExpression ;
        sh:datatype xsd:string ;
        sh:pattern "^((NM|NG|XM|NC)_[0-9]+\\.[0-9]+|LRG_[0-9]+(t[0-9]+)?):c\\.\\S+$" ;
        sh:message "An HGVS coding expression is in the normal form: a reference sequence with its version (NM_000249.3, NG_, XM_, NC_ or LRG_), a colon and c., then the change, with no gene in parentheses and no protein change"@en
    ] ;

    sh:property [
        sh:path cascade:clinvarVariationId ;
        sh:datatype xsd:string ;
        sh:pattern "^[1-9][0-9]*$" ;
        sh:message "A ClinVar VariationID is the digits alone with no leading zero (90011, not VCV000090011)"@en
    ] ;

    sh:property [
        sh:path cascade:geneSymbol ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:message "A gene symbol is a non-empty string"@en
    ] .

cascade:VariantInterpretationShape a sh:NodeShape ;
    sh:targetClass cascade:VariantInterpretation ;
    sh:targetSubjectsOf cascade:acmgClassification , cascade:subjectVariant , cascade:variantInterpretationDate , cascade:objectCondition , cascade:acmgEvidenceCode ;

    sh:property [
        sh:path cascade:workflowStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("registered" "preliminary" "final" "amended" "corrected" "cancelled" "entered-in-error" "unknown") ;
        sh:message "A variant interpretation's status should be one of the FHIR R4 ObservationStatus codes: registered, preliminary, final, amended, corrected, cancelled, entered-in-error, unknown"@en ;
        sh:severity sh:Warning
    ] ;

    sh:property [
        sh:path cascade:acmgClassification ;
        sh:nodeKind sh:IRI ;
        sh:in ( cascade:Pathogenic cascade:LikelyPathogenic cascade:UncertainSignificance cascade:LikelyBenign cascade:Benign ) ;
        sh:maxCount 1 ;
        sh:message "A variant interpretation states at most one ACMG classification, one of cascade:Pathogenic, LikelyPathogenic, UncertainSignificance, LikelyBenign and Benign; a report whose answer is not one of the five states none"@en
    ] ;

    sh:property [
        sh:path cascade:subjectVariant ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A variant interpretation is about at most one variant, named by the variant record's IRI (its urn:uuid: record name, resolved like cascade:patient), never a version; the record is one in the same document, since a urn:uuid names a record within one document only"@en
    ] ;

    sh:property [
        sh:path cascade:objectCondition ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A variant interpretation has at most one object, the condition its statement is about, named by the IRI of a cascade:ProblemOrDiagnosis record in the same document"@en
    ] ;

    sh:property [
        sh:path cascade:acmgEvidenceCode ;
        sh:datatype xsd:string ;
        sh:pattern "^(?:no_criteria_met|((?:PVS1)(?:_(?:not_met|(?:strong|moderate|supporting)))?|(?:PS[1-4]|BS[1-4])(?:_(?:not_met|(?:very_strong|moderate|supporting)))?|BA1(?:_not_met)?|(?:PM[1-6])(?:_(?:not_met|(?:very_strong|strong|supporting)))?|(PP[1-5]|BP[1-7])(?:_(?:not_met|very_strong|strong|moderate))?))$" ;
        sh:message "An ACMG evidence code is written as VA-spec's ACMG 2015 profile writes an evidence outcome (e.g. PM2, PS3_moderate, PS3_not_met)"@en
    ] ;

    sh:property [
        sh:path cascade:variantInterpretationDate ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] ) ;
        sh:maxCount 1 ;
        sh:message "An interpretation date is one xsd:gYear, xsd:gYearMonth or xsd:date, the day the interpretation was issued, or the year or the month where its source wrote no day, with no time"@en
    ] ;

    sh:property [
        sh:path prov:wasAttributedTo ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A variant interpretation's version is attributed to at most one lab, named by the IRI of its cascade:Organization record"@en
    ] .

# Reports, notes and documents

cascade:DiagnosticReportShape a sh:NodeShape ;
    sh:targetClass cascade:DiagnosticReport ;
    sh:targetSubjectsOf cascade:reportCode , cascade:reportCodeInOtherSystem , cascade:reportName , cascade:reportCategory ,
        cascade:reportEffectiveTime , cascade:reportIssuedTime , cascade:reportConclusion , cascade:reportConclusionCode ;
    sh:property [
        sh:path cascade:reportIssuedTime ;
        sh:datatype xsd:dateTime ;
        sh:maxCount 1 ;
        sh:message "A report states at most one time it was issued, an xsd:dateTime, as FHIR's instant is"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportCode ;
        sh:nodeKind sh:IRI ;
        sh:or ( cascade:LoincCodeShape cascade:SnomedCtCodeShape ) ;
        sh:message "A report code is a LOINC or SNOMED CT code IRI, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportCodeInOtherSystem ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:not cascade:LiteralTypedByAnXsdOrRdfDatatypeShape ;
        sh:message "A report code in another system is a non-empty literal typed by its system's URI, never a plain or language-tagged string or another XSD or RDF datatype, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape ;
        sh:message "A report code in another system is typed by the URI the system table gives its system, never by urn:oid: or URN:OID: and an OID in the table, or by a URI the table reads as another"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportCodeInOtherSystem ;
        sh:not [ sh:or ( [ sh:datatype <http://loinc.org> ] [ sh:datatype <http://snomed.info/sct> ] ) ] ;
        sh:message "A LOINC or SNOMED CT report code is a cascade:reportCode IRI, never a literal typed by http://loinc.org or http://snomed.info/sct"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A report states at most one non-empty name"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportCategory ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:not cascade:LiteralTypedByAnXsdOrRdfDatatypeShape ;
        sh:message "A report category is a non-empty literal typed by its system's URI, never a plain or language-tagged string or another XSD or RDF datatype, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportCategory ;
        sh:not cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape ;
        sh:message "A report category is typed by the URI the system table gives its system, never by urn:oid: or URN:OID: and an OID in the table, or by a URI the table reads as another"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportEffectiveTime ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A report's effective time is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportConclusion ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A report states at most one non-empty conclusion"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reportConclusionCode ;
        sh:node cascade:CodeShape ;
        sh:message "A report's conclusion code is a code IRI of one of the code systems' forms, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path obo:RO_0002351 ;
        sh:nodeKind sh:IRI ;
        sh:message "A report's result is named by the result record's IRI (its urn:uuid: record name, resolved like cascade:patient), never a version"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:workflowStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("registered" "partial" "preliminary" "final" "amended" "corrected" "appended" "cancelled" "entered-in-error" "unknown") ;
        sh:message "A report's status should be one of the FHIR R4 DiagnosticReportStatus codes: registered, partial, preliminary, final, amended, corrected, appended, cancelled, entered-in-error, unknown"@en ;
        sh:severity sh:Warning
    ] , [
        sh:path prov:wasAttributedTo ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A report's version is attributed to at most one organization, the one its performer names, by the IRI of its cascade:Organization record"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:attachment ;
        sh:nodeKind sh:IRI ;
        sh:pattern "#attachment-[1-9][0-9]*$" ;
        sh:message "A report's attachment is the node <version>#attachment-n of its version, n its 1-based position in the source"@en ;
        sh:severity sh:Violation
    ] .

cascade:ClinicalNoteOrDocumentShape a sh:NodeShape ;
    sh:targetClass cascade:ClinicalNoteOrDocument ;
    sh:targetSubjectsOf cascade:noteOrDocumentTypeCode , cascade:noteOrDocumentTypeCodeInOtherSystem , cascade:noteOrDocumentTypeName ,
        cascade:noteOrDocumentTitle , cascade:noteOrDocumentDate , cascade:noteOrDocumentContentStatus ,
        cascade:noteOrDocumentMasterIdentifier ;
    sh:property [
        sh:path cascade:noteOrDocumentContentStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("preliminary" "final" "amended" "entered-in-error") ;
        sh:message "A note or document's content status should be one of the FHIR R4 CompositionStatus codes: preliminary, final, amended, entered-in-error"@en ;
        sh:severity sh:Warning
    ] , [
        sh:path cascade:noteOrDocumentTypeCode ;
        sh:nodeKind sh:IRI ;
        sh:node cascade:LoincCodeShape ;
        sh:message "A note or document's type is a LOINC code IRI, one per LOINC coding the source gave"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:noteOrDocumentTypeCodeInOtherSystem ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:not cascade:LiteralTypedByAnXsdOrRdfDatatypeShape ;
        sh:message "A note or document's type in another system is a non-empty literal typed by its system's URI, never a plain or language-tagged string or another XSD or RDF datatype, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:noteOrDocumentTypeCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape ;
        sh:message "A note or document's type in another system is typed by the URI the system table gives its system, never by urn:oid: or URN:OID: and an OID in the table, or by a URI the table reads as another"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:noteOrDocumentTypeCodeInOtherSystem ;
        sh:not [ sh:or ( [ sh:datatype <http://loinc.org> ] ) ] ;
        sh:message "A LOINC note type is a cascade:noteOrDocumentTypeCode IRI, never a literal typed by http://loinc.org"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:noteOrDocumentMasterIdentifier ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:maxCount 1 ;
        sh:message "A note or document states at most one master identifier, a non-empty literal whose datatype names the identifier's system, or a plain string when no system is stated"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:noteOrDocumentTypeName ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A note or document states at most one non-empty type name"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:noteOrDocumentTitle ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A note or document states at most one non-empty title"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:noteOrDocumentDate ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A note or document's date is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:workflowStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ("current" "superseded" "entered-in-error") ;
        sh:message "A note or document's status should be one of the FHIR R4 DocumentReferenceStatus codes: current, superseded, entered-in-error"@en ;
        sh:severity sh:Warning
    ] , [
        sh:path prov:wasAttributedTo ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A note or document's version is attributed to at most one organization, the one its author names, by the IRI of its cascade:Organization record"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:attachment ;
        sh:nodeKind sh:IRI ;
        sh:pattern "#attachment-[1-9][0-9]*$" ;
        sh:message "A note or document's attachment is the node <version>#attachment-n of its version, n its 1-based position in the source"@en ;
        sh:severity sh:Violation
    ] .

cascade:MedicationDispenseShape a sh:NodeShape ;
    sh:targetClass cascade:MedicationDispense ;
    sh:targetSubjectsOf cascade:authorizingPrescription , cascade:dispensePreparedTime , cascade:dispenseHandedOverTime ,
        cascade:dispenseQuantity , cascade:dispenseDaysSupply ;
    sh:property [
        sh:path cascade:workflowStatus ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:message "A medication dispense states at most one status"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:workflowStatus ;
        sh:in ("preparation" "in-progress" "cancelled" "on-hold" "completed" "entered-in-error" "stopped" "declined" "unknown") ;
        sh:message "A medication dispense's status should be a code of FHIR R4's MedicationDispense.status"@en ;
        sh:severity sh:Warning
    ] , [
        sh:path cascade:authorizingPrescription ;
        sh:nodeKind sh:IRI ;
        sh:message "A medication dispense names the prescription it fills by the IRI of that prescription's medication record"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dispensePreparedTime ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A medication dispense states at most one time it was prepared, which is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dispenseHandedOverTime ;
        sh:or ( [ sh:datatype xsd:gYear ] [ sh:datatype xsd:gYearMonth ] [ sh:datatype xsd:date ] [ sh:datatype xsd:dateTime ] ) ;
        sh:maxCount 1 ;
        sh:message "A medication dispense states at most one time it was handed over, which is one xsd:gYear, xsd:gYearMonth, xsd:date or xsd:dateTime, typed by the precision its source wrote"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dispenseQuantity ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A medication dispense states at most one quantity dispensed, a quantity node of its version"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:dispenseDaysSupply ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:node cascade:DurationQuantityShape ;
        sh:message "A medication dispense states at most one days' supply, a quantity node of its version in a UCUM unit of time"@en ;
        sh:severity sh:Violation
    ] .

cascade:AttachmentShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:attachmentContentType , cascade:attachmentTitle , cascade:attachmentUrl ;
    sh:property [
        sh:path cascade:attachmentContentType ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "An attachment states at most one non-empty media type"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:attachmentTitle ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "An attachment states at most one non-empty title"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:attachmentUrl ;
        sh:datatype xsd:anyURI ;
        sh:maxCount 1 ;
        sh:message "An attachment states at most one address, an xsd:anyURI as its source wrote it"@en ;
        sh:severity sh:Violation
    ] .

cascade:NarrativeTextShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:narrativeText ;
    sh:property [
        sh:path cascade:narrativeText ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A version states at most one narrative text, a non-empty string: its text as its source wrote it, in document order"@en ;
        sh:severity sh:Violation
    ] .

cascade:VersionWithReasonShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:reasonCondition , cascade:reasonCode , cascade:reasonCodeInOtherSystem ;
    sh:property [
        sh:path cascade:reasonCondition ;
        sh:nodeKind sh:IRI ;
        sh:message "A version names a condition it was given for by the IRI of that condition's record, one for each the source named"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reasonCode ;
        sh:node cascade:CodeInAListedSystemShape ;
        sh:message "A reason code is a code IRI of a code system the vocabulary lists, in that system's form, one per coding the source gave; a NullFlavor or data absent reason is no code"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reasonCodeInOtherSystem ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:not cascade:LiteralTypedByAnXsdOrRdfDatatypeShape ;
        sh:message "A reason code in another system is a non-empty literal typed by its system's URI, never a plain or language-tagged string or another XSD or RDF datatype, one per coding the source gave"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reasonCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape ;
        sh:message "A reason code in another system is typed by the URI the system table gives its system, never by urn:oid: or URN:OID: and an OID in the table, or by a URI the table reads as another"@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:reasonCodeInOtherSystem ;
        sh:not cascade:LiteralTypedByAListedSystemUriShape ;
        sh:message "A reason code in a system the vocabulary lists a code IRI form for is a cascade:reasonCode IRI, never a literal typed by that system's URI"@en ;
        sh:severity sh:Violation
    ] .

# Records

cascade:SourceUrlShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:sourceUrl ;
    sh:property [
        sh:path cascade:sourceUrl ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A record has one source address, an IRI."@en ;
        sh:severity sh:Violation
    ] .

cascade:ServerRecordNameShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:sourceUrl ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "A record's name, unless it is an organization's, is the one cascade:RecordFromServerNamingRule gives its source address: expected {?expected}."@en ;
        sh:severity sh:Violation ;
        sh:select """SELECT $this ?expected WHERE {
  $this <https://ns.cascadeprotocol.org/cascade#sourceUrl> ?url .
  FILTER NOT EXISTS { $this a <https://ns.cascadeprotocol.org/cascade#Organization> }
  FILTER (ISIRI(?url))
  BIND (STR(?url) AS ?address)
  BIND ("^([Hh][Tt][Tt][Pp][Ss]?)://([A-Za-z0-9.-]+)(:[1-9][0-9]{0,4})?((/[^/?#%]+)*)/([A-Z][A-Za-z]*)/([A-Za-z0-9.-]{1,64})$" AS ?read)
  FILTER (REGEX(?address, ?read))
  BIND (REPLACE(?address, ?read, "$3") AS ?port)
  FILTER (!REGEX(REPLACE(?address, ?read, "$4"), "(^|/)[.][.]?(/|$)") && !REGEX(REPLACE(?address, ?read, "$7"), "^[.]+$"))
  FILTER (!CONTAINS(?address, "\u007F"))
  FILTER (?port = "" || <http://www.w3.org/2001/XMLSchema#integer>(SUBSTR(?port, 2)) <= 65535)
  BIND (LCASE(REPLACE(?address, ?read, "$1")) AS ?scheme)
  BIND (CONCAT(?scheme, "://", LCASE(REPLACE(?address, ?read, "$2")),
               IF(?port = "" || (?scheme = "http" && ?port = ":80") || (?scheme = "https" && ?port = ":443"), "", ?port),
               REPLACE(?address, ?read, "$4")) AS ?input1)
  BIND (REPLACE(?address, ?read, "$6") AS ?input2)
  BIND (REPLACE(?address, ?read, "$7") AS ?input3)
  BIND (SHA256(CONCAT("90c60849-c5ef-4ca6-bfb8-8662bd07d2b5|https://ns.cascadeprotocol.org/cascade#RecordFromServerNamingRule",
                       "|", REPLACE(REPLACE(?input1, "%", "%25"), "\\\\|", "%7C"),
                       "|", REPLACE(REPLACE(?input2, "%", "%25"), "\\\\|", "%7C"),
                       "|", REPLACE(REPLACE(?input3, "%", "%25"), "\\\\|", "%7C"))) AS ?hash)
  BIND (REPLACE(REPLACE(REPLACE(REPLACE(SUBSTR(?hash, 17, 1), "[048c]", "8"), "[159d]", "9"), "[26ae]", "a"), "[37bf]", "b")
        AS ?variant)
  BIND (IRI(CONCAT("urn:uuid:", SUBSTR(?hash, 1, 8), "-", SUBSTR(?hash, 9, 4), "-8", SUBSTR(?hash, 14, 3), "-", ?variant,
                   SUBSTR(?hash, 18, 3), "-", SUBSTR(?hash, 21, 12))) AS ?name)
  BIND (?name AS ?expected)
  FILTER ($this != ?expected)
}""" ] .

cascade:OrganizationRecordNameShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:sourceUrl ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "An organization record's name is the one cascade:OrganizationNamingRule gives its source address, its server, Organization and its id: expected {?expected}."@en ;
        sh:severity sh:Violation ;
        sh:select """SELECT $this ?expected WHERE {
  $this <https://ns.cascadeprotocol.org/cascade#sourceUrl> ?url .
  FILTER EXISTS { $this a <https://ns.cascadeprotocol.org/cascade#Organization> }
  FILTER (ISIRI(?url))
  BIND (STR(?url) AS ?address)
  BIND ("^([Hh][Tt][Tt][Pp][Ss]?)://([A-Za-z0-9.-]+)(:[1-9][0-9]{0,4})?((/[^/?#%]+)*)/([A-Z][A-Za-z]*)/([A-Za-z0-9.-]{1,64})$" AS ?read)
  FILTER (REGEX(?address, ?read))
  BIND (REPLACE(?address, ?read, "$3") AS ?port)
  FILTER (!REGEX(REPLACE(?address, ?read, "$4"), "(^|/)[.][.]?(/|$)") && !REGEX(REPLACE(?address, ?read, "$7"), "^[.]+$"))
  FILTER (!CONTAINS(?address, "\u007F"))
  FILTER (?port = "" || <http://www.w3.org/2001/XMLSchema#integer>(SUBSTR(?port, 2)) <= 65535)
  BIND (LCASE(REPLACE(?address, ?read, "$1")) AS ?scheme)
  BIND (CONCAT(?scheme, "://", LCASE(REPLACE(?address, ?read, "$2")),
               IF(?port = "" || (?scheme = "http" && ?port = ":80") || (?scheme = "https" && ?port = ":443"), "", ?port),
               REPLACE(?address, ?read, "$4")) AS ?input1)
  BIND (REPLACE(?address, ?read, "$6") AS ?input2)
  BIND (REPLACE(?address, ?read, "$7") AS ?input3)
  BIND (SHA256(CONCAT("90c60849-c5ef-4ca6-bfb8-8662bd07d2b5|https://ns.cascadeprotocol.org/cascade#OrganizationNamingRule",
                       "|", REPLACE(REPLACE(?input1, "%", "%25"), "\\\\|", "%7C"),
                       "|", REPLACE(REPLACE(?input2, "%", "%25"), "\\\\|", "%7C"),
                       COALESCE(CONCAT("|", REPLACE(REPLACE(?input3, "%", "%25"), "\\\\|", "%7C")), ""))) AS ?hash)
  BIND (REPLACE(REPLACE(REPLACE(REPLACE(SUBSTR(?hash, 17, 1), "[048c]", "8"), "[159d]", "9"), "[26ae]", "a"), "[37bf]", "b")
        AS ?variant)
  BIND (IRI(CONCAT("urn:uuid:", SUBSTR(?hash, 1, 8), "-", SUBSTR(?hash, 9, 4), "-8", SUBSTR(?hash, 14, 3), "-", ?variant,
                   SUBSTR(?hash, 18, 3), "-", SUBSTR(?hash, 21, 12))) AS ?name)
  BIND (?name AS ?expected)
  FILTER ($this != ?expected)
}""" ] .

cascade:ServerShape a sh:NodeShape ;
    sh:targetClass cascade:Server ;
    sh:targetSubjectsOf cascade:selfAssertedBaseUrl , cascade:authorizationEndpoint , cascade:serverSoftwareName ,
        cascade:serverSoftwareVersion , cascade:connectClientId ;
    sh:property [
        sh:path cascade:selfAssertedBaseUrl ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:message "A server version has at most one self-asserted base URL, a string."@en
    ] ;
    sh:property [
        sh:path cascade:authorizationEndpoint ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:message "A server version has at most one authorization endpoint, a string."@en
    ] ;
    sh:property [
        sh:path cascade:serverSoftwareName ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:maxCount 1 ;
        sh:message "A server version has at most one software name, a non-empty string."@en
    ] ;
    sh:property [
        sh:path cascade:serverSoftwareVersion ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:maxCount 1 ;
        sh:message "A server version has at most one software version, a non-empty string."@en
    ] ;
    sh:property [
        sh:path cascade:connectClientId ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:maxCount 1 ;
        sh:message "A server version has at most one client id, a non-empty string."@en
    ] ;
    sh:property [
        sh:path cascade:patient ;
        sh:maxCount 0 ;
        sh:message "A server's record names no patient: it is never the subject's."@en
    ] .

cascade:ServerNameShape a sh:NodeShape ;
    sh:targetClass cascade:Server ;
    sh:property [
        sh:path cascade:serverBaseUrl ;
        sh:minCount 1 ;
        sh:message "A server's record states the base URL it is named by."@en
    ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "A server's record states its base URL normalised, and its name is the one cascade:ServerNamingRule gives that base: expected {?expected}."@en ;
        sh:severity sh:Violation ;
        sh:select """SELECT $this ?expected WHERE {
  $this <https://ns.cascadeprotocol.org/cascade#serverBaseUrl> ?address .
  BIND ("^([Hh][Tt][Tt][Pp][Ss]?)://([A-Za-z0-9.-]+)(:[1-9][0-9]{0,4})?((/[^/?#%]+)*)$" AS ?read)
  BIND (REPLACE(?address, ?read, "$3") AS ?port)
  BIND (REGEX(?address, ?read) && !REGEX(REPLACE(?address, ?read, "$4"), "(^|/)[.][.]?(/|$)")
        && !CONTAINS(?address, "\u007F")
        && (?port = "" || <http://www.w3.org/2001/XMLSchema#integer>(SUBSTR(?port, 2)) <= 65535) AS ?normalisable)
  BIND (LCASE(REPLACE(?address, ?read, "$1")) AS ?scheme)
  BIND (CONCAT(?scheme, "://", LCASE(REPLACE(?address, ?read, "$2")),
               IF(?port = "" || (?scheme = "http" && ?port = ":80") || (?scheme = "https" && ?port = ":443"), "", ?port),
               REPLACE(?address, ?read, "$4")) AS ?input1)
  BIND (SHA256(CONCAT("90c60849-c5ef-4ca6-bfb8-8662bd07d2b5|https://ns.cascadeprotocol.org/cascade#ServerNamingRule",
                       "|", REPLACE(REPLACE(?input1, "%", "%25"), "\\\\|", "%7C"))) AS ?hash)
  BIND (REPLACE(REPLACE(REPLACE(REPLACE(SUBSTR(?hash, 17, 1), "[048c]", "8"), "[159d]", "9"), "[26ae]", "a"), "[37bf]", "b")
        AS ?variant)
  BIND (IRI(CONCAT("urn:uuid:", SUBSTR(?hash, 1, 8), "-", SUBSTR(?hash, 9, 4), "-8", SUBSTR(?hash, 14, 3), "-", ?variant,
                   SUBSTR(?hash, 18, 3), "-", SUBSTR(?hash, 21, 12))) AS ?name)
  BIND (IF(?normalisable, STR(?name), "none, since the rule cannot read the base") AS ?expected)
  FILTER (!?normalisable || ?address != ?input1 || $this != ?name)
}""" ] .

cascade:OrganizationShape a sh:NodeShape ;
    sh:targetClass cascade:Organization ;
    sh:targetSubjectsOf foaf:name , cascade:organizationAddress , org:identifier ;
    sh:property [
        sh:path foaf:name ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:maxCount 1 ;
        sh:message "An organization version has at most one name, a non-empty string."@en
    ] ;
    sh:property [
        sh:path cascade:organizationAddress ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:message "An organization address is a non-empty string."@en
    ] ;
    sh:property [
        sh:path org:identifier ;
        sh:nodeKind sh:Literal ;
        sh:minLength 1 ;
        sh:message "An organization identifier is a non-empty literal, whose datatype names the identifier system."@en
    ] ;
    sh:property [
        sh:path cascade:patient ;
        sh:maxCount 0 ;
        sh:message "An organization's record names no patient: it is never the subject's."@en
    ] .

cascade:ServerBaseUrlShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:serverBaseUrl ;
    sh:property [
        sh:path cascade:serverBaseUrl ;
        sh:datatype xsd:string ;
        sh:message "A server's record or a document states each base URL as a string."@en ;
        sh:severity sh:Violation
    ] .

cascade:AnsweredAsOfShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:answeredAsOf ;
    sh:property [
        sh:path cascade:answeredAsOf ;
        sh:datatype xsd:dateTime ;
        sh:maxCount 1 ;
        sh:message "A document says one instant its source answered as of, an xsd:dateTime."@en ;
        sh:severity sh:Violation
    ] .

cascade:DocumentScopeShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:answersForRecordClass , cascade:refusedForRecordClass ;
    sh:property [
        sh:path cascade:answersForRecordClass ;
        sh:nodeKind sh:IRI ;
        sh:message "A document names each class of record its source answered a search for by the class's IRI."@en ;
        sh:severity sh:Violation
    ] ;
    sh:property [
        sh:path cascade:refusedForRecordClass ;
        sh:nodeKind sh:IRI ;
        sh:message "A document names each class of record its source refused a search for by the class's IRI."@en ;
        sh:severity sh:Violation
    ] .

cascade:LaboratoryTestResultValueShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:resultValueKind , cascade:resultQuantity , cascade:resultRatioNumerator ,
        cascade:resultRatioDenominator , cascade:resultValueRangeLow , cascade:resultValueRangeHigh , cascade:resultValueCode ,
        cascade:resultValueText , cascade:referenceRangeLow , cascade:referenceRangeHigh , cascade:resultInterpretationCode ;
    sh:property [
        sh:path cascade:resultValueKind ;
        sh:maxCount 1 ;
        sh:in ( cascade:QuantityResultValue cascade:RatioResultValue cascade:RangeResultValue cascade:CodedResultValue cascade:TextResultValue ) ;
        sh:message "A lab result's value is of one kind: cascade:QuantityResultValue, cascade:RatioResultValue, cascade:RangeResultValue, cascade:CodedResultValue or cascade:TextResultValue."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:resultQuantity ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A lab result has at most one quantity as its value, a node of its version."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:resultRatioNumerator ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A ratio has at most one numerator, a quantity node of its version."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:resultRatioDenominator ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A ratio has at most one denominator, a quantity node of its version."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:resultValueRangeLow ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:node cascade:BoundQuantityShape ;
        sh:message "A range has at most one low bound, a quantity node of its version with no comparator."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:resultValueRangeHigh ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:node cascade:BoundQuantityShape ;
        sh:message "A range has at most one high bound, a quantity node of its version with no comparator."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:resultValueCode ;
        sh:node cascade:CodeShape ;
        sh:message "A coded result's answer is a code IRI of one of the code systems' forms."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:referenceRangeLow ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:node cascade:BoundQuantityShape ;
        sh:message "A reference range has at most one low bound, a quantity node of its version with no comparator: its bounds are inside it (FHIR SimpleQuantity, sqty-1)."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:referenceRangeHigh ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:node cascade:BoundQuantityShape ;
        sh:message "A reference range has at most one high bound, a quantity node of its version with no comparator: its bounds are inside it (FHIR SimpleQuantity, sqty-1)."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:resultInterpretationCode ;
        sh:nodeKind sh:IRI ;
        sh:message "A lab result's interpretation is a code IRI, one for each flag its source gave."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:resultInterpretationCode ;
        sh:node cascade:ObservationInterpretationCodeShape ;
        sh:message "A lab result's interpretation should be a code of HL7 v3 ObservationInterpretation, as its source gave it: H, L, A, N and the others HL7 Terminology lists."@en ;
        sh:severity sh:Warning
    ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "A lab result's value is held only by the properties of its kind: {?property} is not one of {?kind}'s."@en ;
        sh:severity sh:Violation ;
        sh:select """SELECT $this ?kind ?property WHERE {
  $this ?property ?value ; <https://ns.cascadeprotocol.org/cascade#resultValueKind> ?kind .
  FILTER ((?property = <https://ns.cascadeprotocol.org/cascade#resultQuantity>
           && ?kind != <https://ns.cascadeprotocol.org/cascade#QuantityResultValue>)
          || (?property IN (<https://ns.cascadeprotocol.org/cascade#resultRatioNumerator>,
                            <https://ns.cascadeprotocol.org/cascade#resultRatioDenominator>)
              && ?kind != <https://ns.cascadeprotocol.org/cascade#RatioResultValue>)
          || (?property IN (<https://ns.cascadeprotocol.org/cascade#resultValueRangeLow>,
                            <https://ns.cascadeprotocol.org/cascade#resultValueRangeHigh>)
              && ?kind != <https://ns.cascadeprotocol.org/cascade#RangeResultValue>)
          || (?property = <https://ns.cascadeprotocol.org/cascade#resultValueCode>
              && ?kind != <https://ns.cascadeprotocol.org/cascade#CodedResultValue>))
}"""
    ] , [
        a sh:SPARQLConstraint ;
        sh:message "A lab result's version that holds a value says which kind it is, by cascade:resultValueKind: it holds {?property} and no kind."@en ;
        sh:severity sh:Violation ;
        sh:select """SELECT $this ?property WHERE {
  $this ?property ?value .
  FILTER (?property IN (<https://ns.cascadeprotocol.org/cascade#resultQuantity>, <https://ns.cascadeprotocol.org/cascade#resultRatioNumerator>,
                        <https://ns.cascadeprotocol.org/cascade#resultRatioDenominator>, <https://ns.cascadeprotocol.org/cascade#resultValueRangeLow>,
                        <https://ns.cascadeprotocol.org/cascade#resultValueRangeHigh>, <https://ns.cascadeprotocol.org/cascade#resultValueCode>,
                        <https://ns.cascadeprotocol.org/cascade#resultValueText>))
  FILTER NOT EXISTS { $this <https://ns.cascadeprotocol.org/cascade#resultValueKind> ?kind }
  FILTER NOT EXISTS { $this <https://ns.cascadeprotocol.org/cascade#entryMember> ?member }
}"""
    ] .

cascade:QuantityShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:decimalValue , cascade:writtenValue , cascade:quantityComparator , cascade:ucumUnit ,
        cascade:unitText ;
    sh:property [
        sh:path cascade:decimalValue ;
        sh:datatype xsd:decimal ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:pattern "^(-?[1-9][0-9]*|-?0\\.[0-9]*[1-9]|-?[1-9][0-9]*\\.[0-9]*[1-9]|0)$" ;
        sh:message "A quantity has one decimal value, an xsd:decimal in XSD's canonical form: a number two runtimes write alike, whatever form the source wrote it in."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:writtenValue ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:pattern "^[+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][+-]?[0-9]+)?$" ;
        sh:message "A quantity has one written value, the number as the source wrote it: digits, an optional sign, point and exponent."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:quantityComparator ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:in ( "<" "<=" ">=" ">" ) ;
        sh:message "A quantity has at most one comparator, one of <, <=, >= and >: = is written as none, and ~, <> and ad are refused, since no rule can compare them."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:ucumUnit ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A quantity has at most one UCUM unit, a non-empty string."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:ucumUnit ;
        sh:pattern "^[!-~]+$" ;
        sh:message "A UCUM code is printable ASCII with no space; this one is likely not UCUM, though its source said it was."@en ;
        sh:severity sh:Warning
    ] , [
        sh:path cascade:unitText ;
        sh:datatype xsd:string ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A quantity has at most one unit text, a non-empty string."@en ;
        sh:severity sh:Violation
    ] .

cascade:DurationQuantityShape a sh:NodeShape ;
    sh:property [
        sh:path cascade:ucumUnit ;
        sh:minCount 1 ;
        sh:in ("s" "min" "h" "d" "wk" "mo" "a") ;
        sh:message "A duration's unit is one of the seven codes of FHIR Timing's UnitsOfTime, s, min, h, d, wk, mo or a, each a UCUM expression of time, as FHIR's Duration requires (drt-1)"@en ;
        sh:severity sh:Violation
    ] .

cascade:BoundQuantityShape a sh:NodeShape ;
    sh:property [
        sh:path cascade:quantityComparator ;
        sh:maxCount 0 ;
        sh:message "A bound carries no comparator: a range's bounds are inside it (FHIR SimpleQuantity, sqty-1)."@en ;
        sh:severity sh:Violation
    ] .

cascade:PaddedDateTimeShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:paddedDateTimeProperty , cascade:timeAsWritten ;
    sh:property [
        sh:path cascade:paddedDateTimeProperty ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:in ( cascade:dateOfBirth cascade:dateOfDeath cascade:onsetDate cascade:abatementDate cascade:vaccinationOccurrenceTime cascade:resultClinicallyRelevantTime
                cascade:procedureDate cascade:medicationUseStartDate cascade:medicationUseEndDate cascade:prescriptionWrittenDate
                cascade:dispenseRequestValidityPeriodStart cascade:dispenseRequestValidityPeriodEnd cascade:dosageBoundsPeriodStart cascade:dosageBoundsPeriodEnd
                cascade:reportEffectiveTime cascade:noteOrDocumentDate cascade:dispensePreparedTime cascade:dispenseHandedOverTime ) ;
        sh:message "A padded time names the one property that holds it, a property whose value may be a time."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:timeAsWritten ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:minLength 1 ;
        sh:message "A padded time keeps one non-empty string, the time exactly as its source wrote it."@en ;
        sh:severity sh:Violation
    ] .

cascade:VersionWithPaddedDateTimeShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:paddedDateTime ;
    sh:property [
        sh:path cascade:paddedDateTime ;
        sh:nodeKind sh:IRI ;
        sh:message "A version's padded time is a node of the version."@en ;
        sh:severity sh:Violation
    ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "A padded time is the node <version>#padded- and its property's local name, or, of a view's entry or a member's values in a view, whose IRIs have a fragment already, <entry>-padded- and the local name; and its subject holds one xsd:dateTime under that property: {?node} is not."@en ;
        sh:severity sh:Violation ;
        sh:select """SELECT $this ?node WHERE {
  $this <https://ns.cascadeprotocol.org/cascade#paddedDateTime> ?node .
  OPTIONAL { ?node <https://ns.cascadeprotocol.org/cascade#paddedDateTimeProperty> ?property }
  FILTER (!BOUND(?property)
          || STR(?node) != CONCAT(STR($this), IF(CONTAINS(STR($this), "#"), "-padded-", "#padded-"), REPLACE(STR(?property), "^.*[#/]", ""))
          || NOT EXISTS { $this ?property ?time .
                          FILTER (isLiteral(?time) && DATATYPE(?time) = <http://www.w3.org/2001/XMLSchema#dateTime>) })
}"""
    ] .

cascade:ValueAbsentForReasonShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:absentValueProperty , cascade:absentReasonCode ;
    sh:property [
        sh:path cascade:absentValueProperty ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:in ( cascade:dateOfBirth cascade:dateOfDeath cascade:onsetDate cascade:abatementDate cascade:vaccinationOccurrenceTime cascade:resultClinicallyRelevantTime
                cascade:procedureDate cascade:medicationUseStartDate cascade:medicationUseEndDate cascade:prescriptionWrittenDate
                cascade:dispenseRequestValidityPeriodStart cascade:dispenseRequestValidityPeriodEnd cascade:dosageBoundsPeriodStart cascade:dosageBoundsPeriodEnd
                cascade:reportEffectiveTime cascade:reportIssuedTime cascade:noteOrDocumentDate cascade:dispensePreparedTime cascade:dispenseHandedOverTime
                cascade:resultValueKind cascade:administrativeGender cascade:conditionCode cascade:procedureCode ) ;
        sh:message "A value absent for a reason names the one property it stands for, a date, a lab result's value kind, an administrative gender or a condition's or a procedure's code."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:absentReasonCode ;
        sh:minCount 1 ;
        sh:or ( cascade:DataAbsentReasonCodeShape cascade:NullFlavorCodeShape ) ;
        sh:message "A value absent for a reason gives at least one reason, each a code of FHIR's data absent reasons or of HL7 v3 NullFlavor, as its source gave it."@en ;
        sh:severity sh:Violation
    ] .

cascade:VersionWithValueAbsentForReasonShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:valueAbsentForReason ;
    sh:property [
        sh:path cascade:valueAbsentForReason ;
        sh:nodeKind sh:IRI ;
        sh:message "A version's value absent for a reason is a node of the version."@en ;
        sh:severity sh:Violation
    ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "A value absent for a reason is the node <version>#absent- and its property's local name, or, of a node whose IRI has a fragment already, such as a structured dosage, <node>-absent- and the local name; and stands only where its subject holds no value for that property: {?node} is not."@en ;
        sh:severity sh:Violation ;
        sh:select """SELECT $this ?node WHERE {
  $this <https://ns.cascadeprotocol.org/cascade#valueAbsentForReason> ?node .
  OPTIONAL { ?node <https://ns.cascadeprotocol.org/cascade#absentValueProperty> ?property }
  FILTER (!BOUND(?property)
          || STR(?node) != CONCAT(STR($this), IF(CONTAINS(STR($this), "#"), "-absent-", "#absent-"), REPLACE(STR(?property), "^.*[#/]", ""))
          || EXISTS { $this ?property ?value })
}"""
    ] .

cascade:DataAbsentReasonCodeShape a sh:NodeShape ;
    sh:in ( <https://ns.cascadeprotocol.org/codes/data-absent-reason/unknown> <https://ns.cascadeprotocol.org/codes/data-absent-reason/asked-unknown>
            <https://ns.cascadeprotocol.org/codes/data-absent-reason/temp-unknown> <https://ns.cascadeprotocol.org/codes/data-absent-reason/not-asked>
            <https://ns.cascadeprotocol.org/codes/data-absent-reason/asked-declined> <https://ns.cascadeprotocol.org/codes/data-absent-reason/masked>
            <https://ns.cascadeprotocol.org/codes/data-absent-reason/not-applicable> <https://ns.cascadeprotocol.org/codes/data-absent-reason/unsupported>
            <https://ns.cascadeprotocol.org/codes/data-absent-reason/as-text> <https://ns.cascadeprotocol.org/codes/data-absent-reason/error>
            <https://ns.cascadeprotocol.org/codes/data-absent-reason/not-a-number> <https://ns.cascadeprotocol.org/codes/data-absent-reason/negative-infinity>
            <https://ns.cascadeprotocol.org/codes/data-absent-reason/positive-infinity> <https://ns.cascadeprotocol.org/codes/data-absent-reason/not-performed>
            <https://ns.cascadeprotocol.org/codes/data-absent-reason/not-permitted> ) .

cascade:NullFlavorCodeShape a sh:NodeShape ;
    sh:in ( <https://ns.cascadeprotocol.org/codes/nullflavor/NI> <https://ns.cascadeprotocol.org/codes/nullflavor/NP> <https://ns.cascadeprotocol.org/codes/nullflavor/NAV>
            <https://ns.cascadeprotocol.org/codes/nullflavor/DER> <https://ns.cascadeprotocol.org/codes/nullflavor/OTH> <https://ns.cascadeprotocol.org/codes/nullflavor/UNC>
            <https://ns.cascadeprotocol.org/codes/nullflavor/INV> <https://ns.cascadeprotocol.org/codes/nullflavor/MSK> <https://ns.cascadeprotocol.org/codes/nullflavor/NA>
            <https://ns.cascadeprotocol.org/codes/nullflavor/UNK> <https://ns.cascadeprotocol.org/codes/nullflavor/NINF> <https://ns.cascadeprotocol.org/codes/nullflavor/PINF>
            <https://ns.cascadeprotocol.org/codes/nullflavor/ASKU> <https://ns.cascadeprotocol.org/codes/nullflavor/NASK> <https://ns.cascadeprotocol.org/codes/nullflavor/NAVU>
            <https://ns.cascadeprotocol.org/codes/nullflavor/QS> <https://ns.cascadeprotocol.org/codes/nullflavor/TRC> ) .

cascade:ObservationInterpretationCodeShape a sh:NodeShape ;
    sh:in ( <https://ns.cascadeprotocol.org/codes/observationinterpretation/EX> <https://ns.cascadeprotocol.org/codes/observationinterpretation/HM> <https://ns.cascadeprotocol.org/codes/observationinterpretation/OBX>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/CAR> <https://ns.cascadeprotocol.org/codes/observationinterpretation/Carrier> <https://ns.cascadeprotocol.org/codes/observationinterpretation/B>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/D> <https://ns.cascadeprotocol.org/codes/observationinterpretation/U> <https://ns.cascadeprotocol.org/codes/observationinterpretation/W>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/%3C> <https://ns.cascadeprotocol.org/codes/observationinterpretation/%3E> <https://ns.cascadeprotocol.org/codes/observationinterpretation/AC>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/IE> <https://ns.cascadeprotocol.org/codes/observationinterpretation/QCF> <https://ns.cascadeprotocol.org/codes/observationinterpretation/TOX>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/A> <https://ns.cascadeprotocol.org/codes/observationinterpretation/N> <https://ns.cascadeprotocol.org/codes/observationinterpretation/I>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/MS> <https://ns.cascadeprotocol.org/codes/observationinterpretation/NCL> <https://ns.cascadeprotocol.org/codes/observationinterpretation/NS>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/R> <https://ns.cascadeprotocol.org/codes/observationinterpretation/S> <https://ns.cascadeprotocol.org/codes/observationinterpretation/VS>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/AA> <https://ns.cascadeprotocol.org/codes/observationinterpretation/H> <https://ns.cascadeprotocol.org/codes/observationinterpretation/L>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/HH> <https://ns.cascadeprotocol.org/codes/observationinterpretation/LL> <https://ns.cascadeprotocol.org/codes/observationinterpretation/HX>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/LX> <https://ns.cascadeprotocol.org/codes/observationinterpretation/H%3E> <https://ns.cascadeprotocol.org/codes/observationinterpretation/HU>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/E> <https://ns.cascadeprotocol.org/codes/observationinterpretation/L%3C> <https://ns.cascadeprotocol.org/codes/observationinterpretation/LU>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/ND> <https://ns.cascadeprotocol.org/codes/observationinterpretation/IND> <https://ns.cascadeprotocol.org/codes/observationinterpretation/NEG>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/POS> <https://ns.cascadeprotocol.org/codes/observationinterpretation/EXP> <https://ns.cascadeprotocol.org/codes/observationinterpretation/UNE>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/DET> <https://ns.cascadeprotocol.org/codes/observationinterpretation/SYN-R> <https://ns.cascadeprotocol.org/codes/observationinterpretation/NR>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/RR> <https://ns.cascadeprotocol.org/codes/observationinterpretation/WR> <https://ns.cascadeprotocol.org/codes/observationinterpretation/SDD>
            <https://ns.cascadeprotocol.org/codes/observationinterpretation/SYN-S> ) .

cascade:PatientShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:patient ;
    sh:property [
        sh:path cascade:patient ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A version is about one patient record, named by its IRI."@en ;
        sh:severity sh:Violation
    ] .

cascade:RevisionShape a sh:NodeShape ;
    sh:targetClass cascade:Revision ;
    sh:property [
        sh:path cascade:revisionOf ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A revision is of exactly one record."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:version ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A revision sets exactly one version."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:generatedAtTime ;
        sh:datatype xsd:dateTime ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A revision carries its arrival time, one xsd:dateTime."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:observedAsOf ;
        sh:datatype xsd:dateTime ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A revision carries when its source was observed saying its state, one xsd:dateTime."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path pav:lastUpdateOn ;
        sh:datatype xsd:dateTime ;
        sh:pattern "(Z|[+-]((0[0-9]|1[0-3]):[0-5][0-9]|14:00))$" ;
        sh:message "A revision's source change time is an xsd:dateTime that states its time zone."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:wasRevisionOf ;
        sh:nodeKind sh:IRI ;
        sh:message "A revision names each earlier revision it follows, the record's heads it saw, by its IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path oa:hasSelector ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A revision has at most one selector, its own node <revision>#selector."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path oa:hasSource ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A revision names at most one source, the document its arrival came from."@en ;
        sh:severity sh:Violation
    ] .

cascade:CurrentRevisionShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:currentRevision ;
    sh:property [
        sh:path cascade:currentRevision ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A record has at most one current revision."@en ;
        sh:severity sh:Violation
    ] .

cascade:RecordSubjectShape a sh:NodeShape ;
    sh:targetClass cascade:Record ;
    sh:property [
        sh:path cascade:subject ;
        sh:nodeKind sh:IRI ;
        sh:message "A record's subject is the IRI of the person it is counted as being about."@en ;
        sh:severity sh:Violation
    ] .

cascade:SubjectShape a sh:NodeShape ;
    sh:targetClass cascade:Subject ;
    sh:closed true ;
    sh:ignoredProperties ( rdf:type ) ;
    sh:message "A subject holds no data: what is known about the person lives in profiles."@en ;
    sh:severity sh:Violation .

cascade:ReferenceSeriesShape a sh:NodeShape ;
    sh:targetClass cascade:ReferenceSeries ;
    sh:property [
        sh:path rdfs:label ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A reference series has one name."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path [ sh:inversePath prov:specializationOf ] ;
        sh:minCount 1 ;
        sh:node cascade:ReferenceVersionShape ;
        sh:message "A reference series has at least one version, and each version names its own label and at most one version it replaces."@en ;
        sh:severity sh:Violation
    ], [
        sh:path cascade:tableKind ;
        sh:in ( cascade:VaccineGroups cascade:CodeNames cascade:RetiredCodes cascade:ProductIngredients cascade:BrandGenerics cascade:DrugProducts cascade:CodeConversions cascade:VariantClassifications cascade:PanelMembers cascade:DrugClasses cascade:ValueSetExpansions ) ;
        sh:maxCount 1 ;
        sh:message "A reference series is of at most one table kind, one the vocabulary declares."@en ;
        sh:severity sh:Violation
    ] ;
    sh:or (
        [ sh:path cascade:tableKind ; sh:not [ sh:hasValue cascade:ValueSetExpansions ] ]
        [ sh:path [ sh:inversePath prov:specializationOf ] ;
          sh:node [ sh:property [ sh:path cascade:expandedValueSet ; sh:minCount 1 ] ] ]
    ) ;
    sh:message "Each version of a value set expansions series names the value set it expands with cascade:expandedValueSet, so a version with no member still says what it checked."@en ;
    sh:severity sh:Violation .

cascade:ReferenceVersionShape a sh:NodeShape ;
    sh:property [ sh:path pav:version ; sh:datatype xsd:string ; sh:minCount 1 ; sh:maxCount 1 ] ,
                [ sh:path prov:wasRevisionOf ; sh:nodeKind sh:IRI ; sh:maxCount 1 ] ,
                [ sh:path cascade:coversGene ; sh:datatype xsd:string ; sh:minLength 1 ;
                  sh:message "A version covers genes by their symbols, each a non-empty plain string"@en ] ,
                [ sh:path cascade:expandedValueSet ; sh:nodeKind sh:IRI ; sh:maxCount 1 ;
                  sh:message "A version names the one value set it expands, an IRI"@en ] ,
                [ sh:path cascade:valueSetDefinitionVersion ; sh:datatype xsd:string ; sh:minLength 1 ; sh:maxCount 1 ;
                  sh:message "A version gives its value set's definition version once, a non-empty plain string"@en ] ,
                [ sh:path cascade:expansionMembersWithoutCodeIriLeftOutCount ; sh:datatype xsd:integer ; sh:minInclusive 0 ; sh:maxCount 1 ;
                  sh:message "A version counts the members it left out for having no code IRI once, a non-negative xsd:integer"@en ] .

cascade:MappingRowShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:class owl:Axiom ;
    sh:closed true ;
    sh:ignoredProperties ( rdf:type ) ;
    sh:message "A mapping row is an owl:Axiom named by an IRI, its record_id, holding only its source, property, target, justification and cardinality."@en ;
    sh:severity sh:Violation ;
    sh:property [
        sh:path owl:annotatedSource ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A mapping row maps one subject code, an IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedProperty ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A mapping row has one predicate."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedTarget ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A mapping row maps to one object code, an IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path sssom:mapping_justification ;
        sh:in ( semapv:ManualMappingCuration semapv:MappingChaining ) ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A mapping row is justified as a publisher's curated row or a chain of the publisher's relationships."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path sssom:mapping_cardinality ;
        sh:in ( "1:1" "1:n" "n:1" "n:n" ) ;
        sh:maxCount 1 ;
        sh:message "A mapping row's cardinality is one of 1:1, 1:n, n:1 or n:n, as SSSOM writes them."@en ;
        sh:severity sh:Violation
    ] .

cascade:VaccineGroupRowShape a sh:NodeShape ;
    sh:node cascade:MappingRowShape ;
    sh:property [
        sh:path owl:annotatedSource ;
        sh:node cascade:CvxCodeShape ;
        sh:message "A vaccine group row maps a CVX code."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedProperty ;
        sh:hasValue obo:RO_0002350 ;
        sh:message "A vaccine group row puts its code in a group with obo:RO_0002350, member of."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedTarget ;
        sh:node cascade:CvxCodeShape ;
        sh:message "A vaccine group is named by its own CVX code."@en ;
        sh:severity sh:Violation
    ] .

cascade:ProductIngredientRowShape a sh:NodeShape ;
    sh:node cascade:MappingRowShape ;
    sh:property [
        sh:path owl:annotatedSource ;
        sh:node cascade:RxNormCodeShape ;
        sh:message "A product ingredient row maps an RxNorm code."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedProperty ;
        sh:in ( obo:RO_0002248 cascade:hasPreciseIngredient ) ;
        sh:message "A product ingredient row gives its code its ingredient with obo:RO_0002248, has active ingredient, or a precise ingredient with cascade:hasPreciseIngredient."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedTarget ;
        sh:node cascade:RxNormCodeShape ;
        sh:message "A product ingredient row maps to an RxNorm code."@en ;
        sh:severity sh:Violation
    ] .

cascade:PanelMemberRowShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:class owl:Axiom ;
    sh:closed true ;
    sh:ignoredProperties ( rdf:type ) ;
    sh:message "A panel member row is an owl:Axiom named by an IRI, its record_id, holding only its panel, obo:RO_0002351, its member, its justification, its sequence and at most one requirement."@en ;
    sh:severity sh:Violation ;
    sh:property [
        sh:path owl:annotatedSource ;
        sh:node cascade:LoincCodeShape ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A panel member row has one panel, a LOINC code."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedProperty ;
        sh:hasValue obo:RO_0002351 ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A panel member row gives its panel its member with obo:RO_0002351, has member."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedTarget ;
        sh:node cascade:LoincCodeShape ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A panel member row has one member, a LOINC code."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path sssom:mapping_justification ;
        sh:hasValue semapv:ManualMappingCuration ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A panel member row is justified as the publisher's curated row."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:panelSequence ;
        sh:datatype xsd:integer ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A panel member row has one sequence, an xsd:integer."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:observationRequiredInPanel ;
        sh:datatype xsd:string ;
        sh:minLength 1 ;
        sh:maxCount 1 ;
        sh:message "A panel member row has at most one requirement, a non-empty plain string as LOINC writes it."@en ;
        sh:severity sh:Violation
    ] .

cascade:DrugClassRowShape a sh:NodeShape ;
    sh:node cascade:MappingRowShape , cascade:DrugClassFormShape ;
    sh:property [
        sh:path owl:annotatedSource ;
        sh:node cascade:RxNormCodeShape ;
        sh:message "A drug class row maps an RxNorm code."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedProperty ;
        sh:in ( cascade:establishedPharmacologicClass cascade:mechanismOfActionClass cascade:physiologicEffectClass cascade:chemicalStructureClass ) ;
        sh:message "A drug class row gives its code its class with cascade:establishedPharmacologicClass, cascade:mechanismOfActionClass, cascade:physiologicEffectClass or cascade:chemicalStructureClass."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path sssom:mapping_justification ;
        sh:hasValue semapv:ManualMappingCuration ;
        sh:message "A drug class row is justified as the publisher's curated row."@en ;
        sh:severity sh:Violation
    ] .

cascade:ValueSetExpansionRowShape a sh:NodeShape ;
    rdfs:comment "The URL is written exactly as the source's ValueSet.url gives it; an https: variant is another name."@en ;
    rdfs:seeAlso <https://hl7.org/fhir/R4/valueset-definitions.html#ValueSet.expansion.contains> , <https://hl7.org/fhir/R4/valueset-definitions.html#ValueSet.url> ;
    sh:node cascade:MappingRowShape ;
    sh:property [
        sh:path owl:annotatedSource ;
        sh:node cascade:CodeShape ;
        sh:message "A value set expansion row maps a code, an IRI of one of the code systems' forms."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedProperty ;
        sh:hasValue obo:RO_0002350 ;
        sh:message "A value set expansion row puts its code in its value set with obo:RO_0002350, member of."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedTarget ;
        sh:pattern "^https?://[^#|]+$" ;
        sh:message "A value set is named by its canonical URL, an http or https IRI holding neither # nor |, written as the source's ValueSet.url gives it. This is Cascade's rule, one value set one name, not FHIR's: cnl-1 is an R5 warning and R5 allows urn:oid:. A urn:oid: value set from VSAC is written http://cts.nlm.nih.gov/fhir/ValueSet/<OID>."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path sssom:mapping_justification ;
        sh:hasValue semapv:ManualMappingCuration ;
        sh:message "A value set expansion row is justified as a manually curated mapping (semapv:ManualMappingCuration), as every row of this kind is whatever the publisher computed it from."@en ;
        sh:severity sh:Violation
    ] .

cascade:DrugClassFormShape a sh:NodeShape ;
    sh:or (
        [ sh:property [ sh:path owl:annotatedTarget ; sh:node cascade:MedrtCodeShape ] ]
        [ sh:property [ sh:path owl:annotatedProperty ; sh:hasValue cascade:chemicalStructureClass ] ,
                      [ sh:path owl:annotatedTarget ; sh:node cascade:MeshCodeShape ] ]
    ) ;
    sh:message "A drug class row maps to a MED-RT code, or, with cascade:chemicalStructureClass, to a MeSH code."@en ;
    sh:severity sh:Violation .

cascade:BrandGenericRowShape a sh:NodeShape ;
    sh:node cascade:MappingRowShape ;
    sh:property [
        sh:path owl:annotatedSource ;
        sh:node cascade:RxNormCodeShape ;
        sh:message "A brand generic row maps an RxNorm code."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedProperty ;
        sh:hasValue skos:broadMatch ;
        sh:message "A brand generic row puts its brand under its generic with skos:broadMatch."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedTarget ;
        sh:node cascade:RxNormCodeShape ;
        sh:message "A brand generic row maps to an RxNorm code."@en ;
        sh:severity sh:Violation
    ] .

cascade:CodeConversionRowShape a sh:NodeShape ;
    sh:node cascade:MappingRowShape , cascade:CodeConversionFormShape ;
    sh:property [
        sh:path owl:annotatedSource ;
        sh:node cascade:CodeShape ;
        sh:message "A code conversion row maps a code, an IRI of a code system's form."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path owl:annotatedTarget ;
        sh:node cascade:CodeShape ;
        sh:message "A code conversion row maps to a code, an IRI of a code system's form."@en ;
        sh:severity sh:Violation
    ] .

cascade:CodeConversionFormShape a sh:NodeShape ;
    sh:or (
        [ sh:property [ sh:path owl:annotatedProperty ; sh:hasValue dct:isReplacedBy ] ,
                      [ sh:path sssom:mapping_cardinality ; sh:minCount 1 ] ]
        [ sh:property [ sh:path owl:annotatedProperty ; sh:hasValue skos:exactMatch ] ,
                      [ sh:path sssom:mapping_cardinality ; sh:maxCount 0 ] ]
    ) ;
    sh:message "A code conversion row says its code is replaced by the code it converts to, with dct:isReplacedBy, and gives its cardinality; a row of the earlier form pairs them with skos:exactMatch and gives none."@en ;
    sh:severity sh:Violation .

# sh:datatype also checks the lexical form, so a literal ill-formed for its datatype, such as "A12"^^xsd:integer or a
# code led by a digit typed xsd:Name, xsd:NCName, xsd:ID, xsd:IDREF, xsd:ENTITY, xsd:QName or xsd:NOTATION, fails the
# sh:or and passes the sh:not that uses it; core SHACL cannot refuse it, and no adapter writes one.
cascade:LiteralTypedByAnXsdOrRdfDatatypeShape a sh:NodeShape ;
    sh:or (
        [ sh:datatype xsd:string ]
        [ sh:datatype xsd:boolean ]
        [ sh:datatype xsd:decimal ]
        [ sh:datatype xsd:integer ]
        [ sh:datatype xsd:double ]
        [ sh:datatype xsd:float ]
        [ sh:datatype xsd:date ]
        [ sh:datatype xsd:time ]
        [ sh:datatype xsd:dateTime ]
        [ sh:datatype xsd:dateTimeStamp ]
        [ sh:datatype xsd:gYear ]
        [ sh:datatype xsd:gMonth ]
        [ sh:datatype xsd:gDay ]
        [ sh:datatype xsd:gYearMonth ]
        [ sh:datatype xsd:gMonthDay ]
        [ sh:datatype xsd:duration ]
        [ sh:datatype xsd:yearMonthDuration ]
        [ sh:datatype xsd:dayTimeDuration ]
        [ sh:datatype xsd:byte ]
        [ sh:datatype xsd:short ]
        [ sh:datatype xsd:int ]
        [ sh:datatype xsd:long ]
        [ sh:datatype xsd:unsignedByte ]
        [ sh:datatype xsd:unsignedShort ]
        [ sh:datatype xsd:unsignedInt ]
        [ sh:datatype xsd:unsignedLong ]
        [ sh:datatype xsd:positiveInteger ]
        [ sh:datatype xsd:nonNegativeInteger ]
        [ sh:datatype xsd:negativeInteger ]
        [ sh:datatype xsd:nonPositiveInteger ]
        [ sh:datatype xsd:hexBinary ]
        [ sh:datatype xsd:base64Binary ]
        [ sh:datatype xsd:anyURI ]
        [ sh:datatype xsd:language ]
        [ sh:datatype xsd:normalizedString ]
        [ sh:datatype xsd:token ]
        [ sh:datatype xsd:NMTOKEN ]
        [ sh:datatype xsd:Name ]
        [ sh:datatype xsd:NCName ]
        [ sh:datatype xsd:NMTOKENS ]
        [ sh:datatype xsd:ID ]
        [ sh:datatype xsd:IDREF ]
        [ sh:datatype xsd:ENTITY ]
        [ sh:datatype xsd:QName ]
        [ sh:datatype xsd:NOTATION ]
        [ sh:datatype xsd:IDREFS ]
        [ sh:datatype xsd:ENTITIES ]
        [ sh:datatype xsd:anyAtomicType ]
        [ sh:datatype xsd:anySimpleType ]
        [ sh:datatype rdf:langString ]
        [ sh:datatype rdf:HTML ]
        [ sh:datatype rdf:XMLLiteral ]
        [ sh:datatype rdf:JSON ]
        [ sh:datatype rdf:PlainLiteral ]
    ) .

cascade:LiteralTypedByASystemsOidOrNonPreferredUriShape a sh:NodeShape ;
    sh:or (
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.1> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.1> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.96> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.96> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.88> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.88> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.69> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.69> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.12> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.12> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.12.292> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.12.292> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.4.9> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.4.9> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.90> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.90> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.103> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.103> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.104> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.104> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.42> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.42> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.2> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.2> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.285> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.285> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.4> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.4> ]
        [ sh:datatype <urn:oid:2.16.840.1.113883.6.13> ]
        [ sh:datatype <URN:OID:2.16.840.1.113883.6.13> ]
        [ sh:datatype <http://terminology.hl7.org/CodeSystem/icd10CM> ]
        [ sh:datatype <http://terminology.hl7.org/CodeSystem/icd9cm> ]
        [ sh:datatype <https://www.cms.gov/Medicare/Coding/HCPCSReleaseCodeSets> ]
        [ sh:datatype <http://terminology.hl7.org/CodeSystem/icd10PCS> ]
        [ sh:datatype <http://terminology.hl7.org/CodeSystem/CD2> ]
    ) .

cascade:LiteralTypedByAListedSystemUriShape a sh:NodeShape ;
    sh:or (
        [ sh:datatype <http://hl7.org/fhir/sid/cvx> ]
        [ sh:datatype <http://www.nlm.nih.gov/research/umls/rxnorm> ]
        [ sh:datatype <http://hl7.org/fhir/sid/ndc> ]
        [ sh:datatype <http://hl7.org/fhir/sid/icd-10-cm> ]
        [ sh:datatype <http://snomed.info/sct> ]
        [ sh:datatype <http://loinc.org> ]
        [ sh:datatype <http://va.gov/terminology/medrt> ]
        [ sh:datatype <https://www.nlm.nih.gov/mesh> ]
        [ sh:datatype <http://fdasis.nlm.nih.gov> ]
        [ sh:datatype <http://www.ama-assn.org/go/cpt> ]
        [ sh:datatype <http://hl7.org/fhir/sid/icd-9-cm> ]
        [ sh:datatype <http://varnomen.hgvs.org> ]
        [ sh:datatype <http://www.ncbi.nlm.nih.gov/clinvar> ]
        [ sh:datatype <http://terminology.hl7.org/CodeSystem/data-absent-reason> ]
        [ sh:datatype <http://terminology.hl7.org/CodeSystem/v3-NullFlavor> ]
        [ sh:datatype <http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation> ] ) .

cascade:CodeInAListedSystemShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^(https://ns\\.cascadeprotocol\\.org/codes/cvx/|https://ns\\.cascadeprotocol\\.org/codes/rxnorm/|https://ns\\.cascadeprotocol\\.org/codes/ndc11/|https://ns\\.cascadeprotocol\\.org/codes/icd10cm/|http://snomed\\.info/id/|http://loinc\\.org/rdf/|https://ns\\.cascadeprotocol\\.org/codes/medrt/|http://id\\.nlm\\.nih\\.gov/mesh/|https://identifiers\\.org/unii:|https://ns\\.cascadeprotocol\\.org/codes/cpt/|https://ns\\.cascadeprotocol\\.org/codes/icd9cm/|https://ns\\.cascadeprotocol\\.org/codes/hgvs/|https://identifiers\\.org/clinvar:|https://ns\\.cascadeprotocol\\.org/codes/data-absent-reason/|https://ns\\.cascadeprotocol\\.org/codes/nullflavor/|https://ns\\.cascadeprotocol\\.org/codes/observationinterpretation/).+$" ;
    sh:not [ sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/(data-absent-reason|nullflavor)/" ] ;
    sh:and (
        [ sh:or ( [ sh:not [ sh:pattern "^http://snomed\\.info/id/" ] ] cascade:SnomedCtCodeShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/icd10cm/" ] ] cascade:IcdTenCmCodeWithOrWithoutItsPointShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/cpt/" ] ] cascade:CptCodeShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/cvx/" ] ] cascade:CvxCodeShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/rxnorm/" ] ] cascade:RxNormCodeShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/ndc11/" ] ] cascade:NdcCodeShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^http://loinc\\.org/rdf/" ] ] cascade:LoincCodeShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/medrt/" ] ] cascade:MedrtCodeShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^http://id\\.nlm\\.nih\\.gov/mesh/" ] ] cascade:MeshCodeShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^https://identifiers\\.org/clinvar:" ] ] cascade:ClinVarCodeShape ) ]
        [ sh:or ( [ sh:not [ sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/hgvs/" ] ] cascade:HgvsCodeShape ) ]
    ) .

cascade:IcdTenCmCodeWithOrWithoutItsPointShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/icd10cm/[A-Z][0-9A-Z]{2}(\\.?[0-9A-Z]{1,4})?$" .

cascade:CptCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/cpt/[0-9]{4}[0-9FTU]$" .

cascade:CodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:or ( cascade:CvxCodeShape cascade:NdcCodeShape cascade:IcdTenCmCodeShape cascade:RxNormCodeShape cascade:SnomedCtCodeShape cascade:LoincCodeShape cascade:ClinVarCodeShape cascade:MedrtCodeShape cascade:MeshCodeShape ) ;
    sh:message "A code is an IRI of one of the code systems' forms."@en ;
    sh:severity sh:Violation .

cascade:MatcherRuleShape a sh:NodeShape ;
    sh:in ( cascade:SameCodeRule cascade:SameCodeAndDateRule cascade:SameMappedCodeRule cascade:SameMappedCodeAndDateRule
            cascade:SameMedicationCodeRule cascade:SameResultRule cascade:SameConvertedCodeRule cascade:SameCodeAndPeriodRule
            cascade:SameBrandGenericRule cascade:SameProductCodeRule cascade:SameVariationRule cascade:SameVariationThroughTableRule
            cascade:SameSelfAssertedBaseUrlAndAuthorizationEndpointOnOneHostRule cascade:DifferentResultValuesRule
            cascade:DifferentResultUnitsRule cascade:SameResultOnOneDayRule
            cascade:SameBusinessIdentifierAndTestCodeWithinOneOrganizationRule
            cascade:SameNoteTypeAndTextGrownWithinOneOrganizationRule cascade:SameNoteTypeAndTextRule
            cascade:SameNoteOrDocumentMasterIdentifierRule ) ;
    sh:message "A matcher rule is one of the 20 cascade:MatcherRule terms."@en ;
    sh:severity sh:Violation .

cascade:CvxCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/cvx/(0[1-9]|[1-9][0-9]{1,2})$" .

cascade:NdcCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/ndc11/[0-9]{11}$" .

cascade:IcdTenCmCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/icd10cm/[A-Z][0-9A-Z]{2}(\\.[0-9A-Z]{1,4})?$" .

cascade:RxNormCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/rxnorm/[0-9]+$" .

cascade:SnomedCtCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^http://snomed\\.info/id/[0-9]+$" .

cascade:LoincCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^http://loinc\\.org/rdf/[A-Za-z0-9]+-[0-9]$" .

cascade:ClinVarCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^https://identifiers\\.org/clinvar:[1-9][0-9]*$" .

cascade:MedrtCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/medrt/N[0-9]{10}$" .

cascade:MeshCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^http://id\\.nlm\\.nih\\.gov/mesh/[CDMQ][0-9]+$" .

cascade:HgvsCodeShape a sh:NodeShape ;
    sh:nodeKind sh:IRI ;
    sh:pattern "^https://ns\\.cascadeprotocol\\.org/codes/hgvs/NM_[0-9]+\\.[0-9]+%3Ac\\.([A-Za-z0-9._~-]|%[0-9A-F]{2})+$" .

cascade:CodeNameRowShape a sh:NodeShape ;
    sh:node cascade:CodeShape ;
    sh:closed true ;
    sh:message "A code names row holds only the code's labels and notation."@en ;
    sh:severity sh:Violation ;
    sh:property [
        sh:path skos:prefLabel ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A code has one preferred name."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path skos:altLabel ;
        sh:datatype xsd:string ;
        sh:disjoint skos:prefLabel ;
        sh:message "A code's other names are plain strings, none its preferred name."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path skos:notation ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A code has one notation, the code as its publisher writes it."@en ;
        sh:severity sh:Violation
    ] .

cascade:RetiredCodeRowShape a sh:NodeShape ;
    sh:node cascade:CodeShape ;
    sh:closed true ;
    sh:message "A retired codes row holds only that the code is retired and what replaces it."@en ;
    sh:severity sh:Violation ;
    sh:property [
        sh:path owl:deprecated ;
        sh:hasValue true ;
        sh:maxCount 1 ;
        sh:message "A retired codes row says its code is retired: owl:deprecated true."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path dct:isReplacedBy ;
        sh:node cascade:CodeShape ;
        sh:message "A retired code is replaced by codes, each an IRI of a code system's form."@en ;
        sh:severity sh:Violation
    ] .

cascade:DrugProductRowShape a sh:NodeShape ;
    sh:node cascade:RxNormCodeShape ;
    sh:closed true ;
    sh:message "A drug products row holds only the code's term type."@en ;
    sh:severity sh:Violation ;
    sh:property [
        sh:path cascade:termType ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:in ( "SCD" "SBD" "GPCK" "BPCK" ) ;
        sh:message "A drug product's term type is one of SCD, SBD, GPCK or BPCK."@en ;
        sh:severity sh:Violation
    ] .

cascade:VariantClassificationRowShape a sh:NodeShape ;
    sh:node cascade:ClinVarCodeShape , cascade:SubmitterCountShape ;
    sh:closed true ;
    sh:message "A variant classification row holds only its variation's HGVS expressions, classification concepts, review status, date last evaluated and submitter count."@en ;
    sh:severity sh:Violation ;
    sh:property [
        sh:path cascade:hgvsExpression ;
        sh:node cascade:HgvsCodeShape ;
        sh:message "A variant classification row is found by coding NM_ expressions, each the cascade:HGVS IRI with the expression percent-encoded."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path ( cascade:hgvsExpression [ sh:inversePath cascade:hgvsExpression ] ) ;
        sh:maxCount 1 ;
        sh:message "An expression finds one row: an expression of this row is on another row too."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:clinvarClassification ;
        sh:in ( cascade:Pathogenic cascade:LikelyPathogenic cascade:UncertainSignificance cascade:LikelyBenign cascade:Benign
                cascade:ClinVarConflicting cascade:ClinVarConflictingData cascade:ClinVarPathogenicLowPenetrance
                cascade:ClinVarLikelyPathogenicLowPenetrance cascade:ClinVarVusHigh cascade:ClinVarVusMid cascade:ClinVarVusLow
                cascade:ClinVarEstablishedRiskAllele cascade:ClinVarLikelyRiskAllele cascade:ClinVarUncertainRiskAllele
                cascade:ClinVarDrugResponse cascade:ClinVarRiskFactor cascade:ClinVarAssociation cascade:ClinVarProtective
                cascade:ClinVarConfersSensitivity cascade:ClinVarAffects cascade:ClinVarOther cascade:ClinVarNotProvided
                cascade:ClinVarCombinationOnly cascade:ClinVarNoClassificationsFromUnflaggedRecords
                cascade:ClinVarNoClassificationForTheSingleVariant ) ;
        sh:message "A classification is a concept of cascade:ClinVarClassifications."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:clinvarReviewStatus ;
        sh:in ( cascade:ClinVarPracticeGuideline cascade:ClinVarExpertPanel cascade:ClinVarMultipleSubmittersNoConflicts
                cascade:ClinVarConflictingClassifications cascade:ClinVarSingleSubmitter cascade:ClinVarNoAssertionCriteria
                cascade:ClinVarNoClassificationProvided cascade:ClinVarNoClassificationForTheSingleVariant
                cascade:ClinVarNoClassificationsFromUnflaggedRecords ) ;
        sh:maxCount 1 ;
        sh:message "A row has at most one review status, a concept of cascade:ClinVarReviewStatuses."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:lastEvaluated ;
        sh:datatype xsd:date ;
        sh:maxCount 1 ;
        sh:message "The day last evaluated is one xsd:date."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:contributingSubmitterCount ;
        sh:datatype xsd:integer ;
        sh:minInclusive 0 ;
        sh:maxCount 1 ;
        sh:message "The contributing submitters are counted once, a non-negative xsd:integer."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:submitterCount ;
        sh:datatype xsd:integer ;
        sh:minInclusive 0 ;
        sh:maxCount 1 ;
        sh:message "The submitters are counted once, a non-negative xsd:integer."@en ;
        sh:severity sh:Violation
    ] .

cascade:SubmitterCountShape a sh:NodeShape ;
    sh:not [ sh:property [ sh:path cascade:contributingSubmitterCount ; sh:minCount 1 ] ,
                         [ sh:path cascade:submitterCount ; sh:minCount 1 ] ] ;
    sh:message "A row holds the count of contributing submitters or the count of submitters, never both, so it says which it has."@en ;
    sh:severity sh:Violation .

cascade:PlacementShape a sh:NodeShape ;
    sh:targetClass cascade:Placement ;
    sh:xone (
        [ sh:path solid:instance ; sh:minCount 1 ]
        [ sh:path solid:instanceContainer ; sh:minCount 1 ]
        [ sh:path cascade:filedWith ; sh:minCount 1 ]
    ) ;
    sh:message "A placement names exactly one of a file, a folder, or the property whose value's folder it files with."@en ;
    sh:severity sh:Violation ;
    sh:property [
        sh:path solid:instance ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1
    ] , [
        sh:path solid:instanceContainer ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1
    ] , [
        sh:path cascade:filedWith ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1
    ] , [
        sh:path solid:forClass ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1
    ] , [
        sh:path cascade:forSubjectsOf ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1
    ] , [
        sh:path cascade:subfolderPrefixLength ;
        sh:datatype xsd:integer ;
        sh:minInclusive 1 ;
        sh:maxCount 1
    ] , [
        sh:path cascade:writtenByQueryPath ;
        sh:datatype xsd:string ;
        sh:maxCount 1
    ] , [
        sh:path cascade:writtenAlways ;
        sh:datatype xsd:boolean ;
        sh:maxCount 1
    ] , [
        sh:path cascade:holdsRecords ;
        sh:datatype xsd:boolean ;
        sh:maxCount 1
    ] , [
        sh:path cascade:storesBytes ;
        sh:datatype xsd:boolean ;
        sh:maxCount 1
    ] , [
        sh:path cascade:holdsFilesInArchivesOfMediaType ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1
    ] , [
        sh:path cascade:holdsRequirementsForReadingAPod ;
        sh:datatype xsd:boolean ;
        sh:maxCount 1
    ] .

# Judgments

cascade:JudgmentShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:property [
        sh:path cascade:verdict ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:in ( cascade:Same cascade:Different cascade:Erroneous cascade:About cascade:NotAbout cascade:Before
                cascade:Acknowledged cascade:ClockDiscounted ) ;
        sh:message "A judgment gives one verdict: cascade:Same, cascade:Different, cascade:Erroneous, cascade:About, cascade:NotAbout, cascade:Before, cascade:Acknowledged or cascade:ClockDiscounted. A retraction is no judgment but an activity."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:hadMember ;
        sh:nodeKind sh:IRI ;
        sh:message "A judgment's members are records, documents, revisions or activities, named by their IRIs."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:generatedAtTime ;
        sh:datatype xsd:dateTime ;
        sh:maxCount 1 ;
        sh:message "A judgment carries at most one time it was made, an xsd:dateTime."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:wasAttributedTo ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:or ( [ sh:class prov:Person ] [ sh:class prov:SoftwareAgent ] ) ;
        sh:message "A judgment has one author, a prov:Person or a prov:SoftwareAgent, named by its IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:wasDerivedFrom ;
        sh:nodeKind sh:IRI ;
        sh:message "A judgment names what it came from by IRI, with prov:wasDerivedFrom: versions it saw, reference versions it applied."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:used ;
        sh:maxCount 0 ;
        sh:message "A judgment is an entity: it names what it came from with prov:wasDerivedFrom, and prov:used is an activity's."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path dct:replaces ;
        sh:class cascade:Judgment ;
        sh:message "A judgment replaces only judgments."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:matcherRule ;
        sh:node cascade:MatcherRuleShape ;
        sh:maxCount 1 ;
        sh:message "A judgment names at most one matcher rule, one of the 20 cascade:MatcherRule terms."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:justification ;
        sh:maxCount 1 ;
        sh:in ( cascade:SameCode cascade:SameCodeAndDate cascade:SameMappedCode cascade:SameMappedCodeAndDate cascade:SameMedicationCode cascade:SameProductCode cascade:SameResult cascade:SameConvertedCode cascade:SameCodeAndPeriod cascade:SameBrandGeneric cascade:SameVariation cascade:SameVariationThroughTable cascade:SameSelfAssertedBaseUrlAndAuthorizationEndpointOnOneHost cascade:SameResultOnOneDay cascade:SameBusinessIdentifierAndTestCodeWithinOneOrganization cascade:SameNoteTypeAndTextGrownWithinOneOrganization cascade:SameNoteTypeAndText cascade:SameNoteOrDocumentMasterIdentifier ) ;
        sh:message "A judgment gives at most one justification: cascade:SameCode, cascade:SameCodeAndDate, cascade:SameMappedCode, cascade:SameMappedCodeAndDate, cascade:SameMedicationCode, cascade:SameProductCode, cascade:SameResult, cascade:SameConvertedCode, cascade:SameCodeAndPeriod, cascade:SameBrandGeneric, cascade:SameVariation, cascade:SameVariationThroughTable, cascade:SameSelfAssertedBaseUrlAndAuthorizationEndpointOnOneHost, cascade:SameResultOnOneDay, cascade:SameBusinessIdentifierAndTestCodeWithinOneOrganization, cascade:SameNoteTypeAndTextGrownWithinOneOrganization, cascade:SameNoteTypeAndText or cascade:SameNoteOrDocumentMasterIdentifier."@en ;
        sh:severity sh:Violation
    ] .

cascade:AboutVerdictShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path cascade:verdict ; sh:hasValue cascade:About ] ]
        [ sh:property [ sh:path cascade:subject ; sh:minCount 1 ] ,
                      [ sh:path cascade:basis ; sh:minCount 1 ] ,
                      [ sh:path prov:hadMember ; sh:minCount 1 ; sh:maxCount 1 ] ]
    ) ;
    sh:message "An About judgment names one member, a subject and a basis."@en ;
    sh:severity sh:Violation .

cascade:NotAboutVerdictShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path cascade:verdict ; sh:hasValue cascade:NotAbout ] ]
        [ sh:property [ sh:path cascade:subject ; sh:minCount 1 ] ,
                      [ sh:path prov:hadMember ; sh:minCount 1 ; sh:maxCount 1 ] ,
                      [ sh:path prov:wasAttributedTo ; sh:class prov:Person ] ]
    ) ;
    sh:message "A NotAbout is a person's: it names one member and a subject."@en ;
    sh:severity sh:Violation .

cascade:MachineBasisShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:property [ sh:path cascade:basis ; sh:minCount 1 ;
                                 sh:in ( cascade:SameDemographics cascade:PortalAuthenticated cascade:RelatedPersonConnection ) ] ] ]
        [ sh:property [ sh:path prov:wasAttributedTo ; sh:minCount 1 ; sh:class prov:SoftwareAgent ; sh:not [ sh:class prov:Person ] ] ]
    ) ;
    sh:message "A judgment whose basis is cascade:SameDemographics, cascade:PortalAuthenticated or cascade:RelatedPersonConnection is a software agent's: it is attributed to an agent typed prov:SoftwareAgent and never prov:Person, and a person's About has the basis cascade:OwnerStatement."@en ;
    sh:severity sh:Violation .

cascade:AboutShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:property [ sh:path cascade:verdict ; sh:hasValue cascade:About ] ]
        [ sh:property [ sh:path cascade:verdict ; sh:hasValue cascade:NotAbout ] , [ sh:path cascade:basis ; sh:maxCount 0 ] ]
        [ sh:property [ sh:path cascade:subject ; sh:maxCount 0 ] , [ sh:path cascade:basis ; sh:maxCount 0 ] ]
    ) ;
    sh:message "Only an About or a NotAbout judgment names a subject, and only an About gives a basis."@en ;
    sh:severity sh:Violation ;
    sh:property [
        sh:path cascade:subject ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:disjoint prov:wasAttributedTo ;
        sh:message "An About or a NotAbout judgment names exactly one subject, which is never its author."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:basis ;
        sh:maxCount 1 ;
        sh:in ( cascade:PortalAuthenticated cascade:RelatedPersonConnection cascade:SameDemographics cascade:OwnerStatement ) ;
        sh:message "An About judgment gives exactly one basis: cascade:PortalAuthenticated, cascade:RelatedPersonConnection, cascade:SameDemographics or cascade:OwnerStatement."@en ;
        sh:severity sh:Violation
    ] .

cascade:RetractionByPersonOrReleaseShape a sh:NodeShape ;
    sh:targetSubjectsOf prov:invalidated ;
    sh:xone (
        [ sh:path prov:wasAssociatedWith ; sh:minCount 1 ]
        [ sh:path prov:used ; sh:minCount 1 ;
          sh:node [ sh:property [ sh:path cascade:matcherRuleDeclaredWrong ; sh:minCount 1 ; sh:node cascade:MatcherRuleShape ] ] ]
    ) ;
    sh:message "A retraction is made either by a person (prov:wasAssociatedWith) or by a release, prov:used: a rule list version that declares a matcher rule wrong; not both and not neither."@en ;
    sh:severity sh:Violation .

cascade:RetractionShape a sh:NodeShape ;
    sh:targetSubjectsOf prov:invalidated ;
    sh:class prov:Activity ;
    sh:not [ sh:class cascade:Judgment ] ;
    sh:message "A retraction is a prov:Activity, and no judgment."@en ;
    sh:severity sh:Violation ;
    sh:property [
        sh:path prov:invalidated ;
        sh:nodeKind sh:IRI ;
        sh:or ( [ sh:class cascade:Judgment ] [ sh:class cascade:MatcherJudgmentAssertion ] ) ;
        sh:message "A retraction invalidates judgments or assertions, named by their IRIs."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:startedAtTime ;
        sh:datatype xsd:dateTime ;
        sh:maxCount 1 ;
        sh:message "A person's retraction carries at most one time it was made, an xsd:dateTime; a release's carries none."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:wasAssociatedWith ;
        sh:nodeKind sh:IRI ;
        sh:class prov:Person ;
        sh:maxCount 1 ;
        sh:message "A person's retraction names the person who made it, a prov:Person, by its IRI; a release's names none."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:hadMember ;
        sh:maxCount 0 ;
        sh:message "A retraction names only what it invalidates: no members, no replacement, no verdict, no justification."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path dct:replaces ;
        sh:maxCount 0 ;
        sh:message "A retraction names only what it invalidates: no members, no replacement, no verdict, no justification."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:verdict ;
        sh:maxCount 0 ;
        sh:message "A retraction names only what it invalidates: no members, no replacement, no verdict, no justification."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:justification ;
        sh:maxCount 0 ;
        sh:message "A retraction names only what it invalidates: no members, no replacement, no verdict, no justification."@en ;
        sh:severity sh:Violation
    ] .

cascade:VerdictMembersShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path cascade:verdict ; sh:minCount 1 ] ]
        [ sh:path prov:hadMember ; sh:minCount 1 ]
    ) ;
    sh:message "A judgment that gives a verdict judges at least one member."@en ;
    sh:severity sh:Violation .

cascade:SetVerdictShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path cascade:verdict ; sh:minCount 1 ; sh:in ( cascade:Same cascade:Different ) ] ]
        [ sh:path prov:hadMember ; sh:minCount 2 ]
    ) ;
    sh:message "A Same or a Different judges a set of at least two records."@en ;
    sh:severity sh:Violation .

# A judgment and what it names are filed apart, so the sh:class of this shape and the next holds over the pod's union of
# files, never over a judgment's file alone.
cascade:JudgmentNamesNoFindingShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:property [
        sh:path prov:hadMember ;
        sh:not [ sh:class cascade:FindingForReview ] ;
        sh:message "A judgment never names a finding for review, whose name the pod derives: an answer to one names what it is about."@en ;
        sh:severity sh:Violation
    ] .

cascade:AcknowledgedShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:and ( [ sh:not [ sh:path cascade:verdict ; sh:hasValue cascade:Acknowledged ] ]
                   [ sh:path cascade:answersWarningOfKind ; sh:maxCount 0 ] ) ]
        [ sh:property [ sh:path cascade:verdict ; sh:hasValue cascade:Acknowledged ] ,
                      [ sh:path cascade:answersWarningOfKind ; sh:minCount 1 ; sh:maxCount 1 ;
                        sh:in ( cascade:MatcherJudgmentsNoLongerReached cascade:SourceReportedOlderStates cascade:ClockBehind
                                cascade:DifferentResultValuesAtOneInstant cascade:DifferentResultUnitsAtOneInstant ) ] ,
                      [ sh:path prov:hadMember ;
                        sh:not [ sh:or ( [ sh:class cascade:Revision ] [ sh:class cascade:Judgment ]
                                         [ sh:class cascade:MatcherJudgmentAssertion ]
                                         [ sh:path prov:specializationOf ; sh:minCount 1 ] ) ] ] ;
                      sh:or ( [ sh:not [ sh:path cascade:answersWarningOfKind ; sh:minCount 1 ;
                                         sh:in ( cascade:MatcherJudgmentsNoLongerReached cascade:DifferentResultValuesAtOneInstant
                                                 cascade:DifferentResultUnitsAtOneInstant ) ] ]
                              [ sh:path prov:hadMember ; sh:minCount 2 ; sh:maxCount 2 ] ) ]
    ) ;
    sh:message "An Acknowledged names the kind of warning it answers and, as its members, what that warning is about: records, documents or acts, never a version, a revision, a judgment or a matcher judgment assertion; one of a pair kind names exactly the pair's two records. No other judgment names a kind of warning."@en ;
    sh:severity sh:Violation .

cascade:ClockDiscountedShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path cascade:verdict ; sh:hasValue cascade:ClockDiscounted ] ]
        [ sh:property [ sh:path prov:hadMember ; sh:minCount 1 ; sh:maxCount 1 ; sh:class prov:Activity ] ,
                      [ sh:path prov:wasAttributedTo ; sh:class prov:Person ] ]
    ) ;
    sh:message "A ClockDiscounted is a person's, and its one member is an act."@en ;
    sh:severity sh:Violation .

cascade:BeforeVerdictShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path cascade:verdict ; sh:hasValue cascade:Before ] ]
        [ sh:property [ sh:path prov:hadMember ; sh:minCount 2 ; sh:maxCount 2 ] ,
                      [ sh:path cascade:earlierMember ; sh:nodeKind sh:IRI ; sh:minCount 1 ; sh:maxCount 1 ] ,
                      [ sh:path prov:wasAttributedTo ; sh:class prov:Person ] ]
    ) ;
    sh:message "A Before is a person's: it judges two revisions and names the earlier of them."@en ;
    sh:severity sh:Violation .

cascade:EarlierMemberShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:earlierMember ;
    sh:property [
        sh:path cascade:verdict ;
        sh:hasValue cascade:Before ;
        sh:message "Only a Before judgment names an earlier member."@en ;
        sh:severity sh:Violation
    ] .

cascade:JustificationShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:justification ;
    sh:property [
        sh:path cascade:verdict ;
        sh:hasValue cascade:Same ;
        sh:message "Only a Same judgment gives a justification."@en ;
        sh:severity sh:Violation
    ] .

cascade:MachineSameShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:and (
            [ sh:path prov:wasAttributedTo ; sh:minCount 1 ; sh:class prov:SoftwareAgent ]
            [ sh:path cascade:verdict ; sh:hasValue cascade:Same ]
        ) ] ]
        [ sh:property [ sh:path cascade:justification ; sh:minCount 1 ] ,
                      [ sh:path cascade:matcherRule ; sh:node cascade:MatcherRuleShape ; sh:minCount 1 ; sh:maxCount 1 ] ,
                      [ sh:path prov:wasDerivedFrom ; sh:minCount 1 ] ,
                      [ sh:path prov:generatedAtTime ; sh:maxCount 0 ] ]
    ) ;
    sh:message "A matcher judgment that is a Same gives its justification and the one matcher rule that made it, names what it came from (prov:wasDerivedFrom), and carries no time."@en ;
    sh:severity sh:Violation .

cascade:PersonJudgmentShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path prov:wasAttributedTo ; sh:minCount 1 ; sh:class prov:Person ] ]
        [ sh:property [ sh:path ( prov:wasGeneratedBy prov:qualifiedAssociation ) ; sh:minCount 1 ; sh:maxCount 2 ;
                        sh:node cascade:PersonJudgmentAssociationShape ;
                        sh:qualifiedValueShape cascade:PersonJudgmentAuthorAssociationShape ;
                        sh:qualifiedMinCount 1 ; sh:qualifiedMaxCount 1 ] ,
                      [ sh:path prov:generatedAtTime ; sh:minCount 1 ] ]
    ) ;
    sh:message "A person's judgment carries the time it was made and names the role its author acted in, in one association of the act that generated it, whose agent is the author; the act's only other association is the model's that proposed it."@en ;
    sh:severity sh:Violation .

cascade:PersonJudgmentDerivedFromNoVersionShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path prov:wasAttributedTo ; sh:minCount 1 ; sh:class prov:Person ] ]
        [ sh:path prov:wasDerivedFrom ;
          sh:not [ sh:or ( [ sh:path prov:specializationOf ; sh:minCount 1 ] [ sh:path cascade:revisionOf ; sh:minCount 1 ] ) ] ]
    ) ;
    sh:message "A person's judgment names the documents its members were shown from (prov:wasDerivedFrom), never a version or a revision, which the pod derives."@en ;
    sh:severity sh:Violation .

cascade:PersonJudgmentReplacesNoMatcherJudgmentShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path prov:wasAttributedTo ; sh:minCount 1 ; sh:class prov:Person ] ]
        [ sh:path dct:replaces ; sh:not [ sh:path cascade:matcherRule ; sh:minCount 1 ] ]
    ) ;
    sh:message "A person's judgment never replaces a matcher's, which carries cascade:matcherRule: a person states Same or Different over the records."@en ;
    sh:severity sh:Violation .

cascade:RetractionInvalidatesNoMatcherJudgmentShape a sh:NodeShape ;
    sh:targetSubjectsOf prov:invalidated ;
    sh:property [
        sh:path prov:invalidated ;
        sh:not [ sh:path cascade:matcherRule ; sh:minCount 1 ] ;
        sh:message "A retraction never invalidates a matcher's judgment, which carries cascade:matcherRule: a person states Different over its records, and a release retracts an assertion."@en ;
        sh:severity sh:Violation
    ] .

cascade:ModelProposedJudgmentShape a sh:NodeShape ;
    sh:targetClass cascade:Judgment ;
    sh:or (
        [ sh:not [ sh:path ( prov:wasGeneratedBy prov:qualifiedAssociation prov:hadRole ) ; sh:hasValue cascade:ModelProposerRole ] ]
        [ sh:path prov:wasAttributedTo ; sh:class prov:Person ]
    ) ;
    sh:message "A judgment a model proposed is the person's who said yes to it: its author is a prov:Person, never the model."@en ;
    sh:severity sh:Violation .

cascade:ModelProposedActShape a sh:NodeShape ;
    sh:targetSubjectsOf prov:qualifiedAssociation ;
    sh:or (
        [ sh:not [ sh:path ( prov:qualifiedAssociation prov:hadRole ) ; sh:hasValue cascade:ModelProposerRole ] ]
        [ sh:path prov:qualifiedAssociation ;
          sh:qualifiedValueShape [ sh:property [ sh:path prov:hadRole ; sh:hasValue cascade:PatientRole ] ,
                                               [ sh:path prov:agent ; sh:minCount 1 ; sh:class prov:Person ] ] ;
          sh:qualifiedMinCount 1 ]
    ) ;
    sh:message "An act a model proposed names the person who said yes to it: an association in cascade:PatientRole whose agent is a prov:Person."@en ;
    sh:severity sh:Violation .

cascade:ModelProposerAssociationShape a sh:NodeShape ;
    sh:targetObjectsOf prov:qualifiedAssociation ;
    sh:or (
        [ sh:not [ sh:path prov:hadRole ; sh:hasValue cascade:ModelProposerRole ] ]
        [ sh:path prov:agent ; sh:nodeKind sh:IRI ; sh:minCount 1 ; sh:maxCount 1 ; sh:class prov:SoftwareAgent ]
    ) ;
    sh:message "The model that proposed an act is its association's one agent, a prov:SoftwareAgent named by its IRI."@en ;
    sh:severity sh:Violation .

cascade:OneModelProposerShape a sh:NodeShape ;
    sh:targetSubjectsOf prov:qualifiedAssociation ;
    sh:property [ sh:path prov:qualifiedAssociation ;
                  sh:qualifiedValueShape [ sh:property [ sh:path prov:hadRole ; sh:hasValue cascade:ModelProposerRole ] ] ;
                  sh:qualifiedMaxCount 1 ] ;
    sh:message "An act names at most one association in cascade:ModelProposerRole: the one model that proposed it."@en ;
    sh:severity sh:Violation .

cascade:PersonRetractionAuthorShape a sh:NodeShape ;
    sh:targetSubjectsOf prov:invalidated ;
    sh:not [ sh:path prov:qualifiedAssociation ;
             sh:qualifiedValueShape [ sh:property [ sh:path prov:hadRole ; sh:hasValue cascade:PatientRole ] ;
                                      sh:not [ sh:path ( [ sh:inversePath prov:qualifiedAssociation ] prov:wasAssociatedWith ) ;
                                               sh:equals prov:agent ] ] ;
             sh:qualifiedMinCount 1 ] ;
    sh:message "The person a retraction names in cascade:PatientRole is the person it is prov:wasAssociatedWith."@en ;
    sh:severity sh:Violation .

cascade:MatcherJudgmentAssertionShape a sh:NodeShape ;
    sh:targetClass cascade:MatcherJudgmentAssertion ;
    sh:property [
        sh:path cascade:assertedJudgment ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "An assertion asserts one judgment, named by its IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:assertedUnderRuleListVersion ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "An assertion is under one version of the rule list, named by its IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:generatedAtTime ;
        sh:maxCount 0 ;
        sh:message "An assertion carries no time: the run that wrote it is known from its snapshot."@en ;
        sh:severity sh:Violation
    ] .

cascade:FindingForReviewShape a sh:NodeShape ;
    sh:targetClass cascade:FindingForReview ;
    sh:property [
        sh:path oa:hasBody ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:in ( cascade:MatcherJudgmentsNoLongerReached cascade:SourceReportedOlderStates cascade:ClockBehind
                cascade:DifferentResultValuesAtOneInstant cascade:DifferentResultUnitsAtOneInstant ) ;
        sh:message "A finding for review gives one kind, its oa:hasBody: cascade:MatcherJudgmentsNoLongerReached, cascade:SourceReportedOlderStates, cascade:ClockBehind, cascade:DifferentResultValuesAtOneInstant or cascade:DifferentResultUnitsAtOneInstant."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path oa:motivatedBy ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:hasValue oa:classifying ;
        sh:message "A finding for review is motivated by oa:classifying: it classifies its targets as its kind."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path oa:hasTarget ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:message "A finding for review is about at least one thing, its oa:hasTarget, named by its IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:noLongerReachedUnderRuleListVersion ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A finding names at most one rule list version that no longer reaches its matcher judgments, by its IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:contradictedEarlierRevision ;
        sh:nodeKind sh:IRI ;
        sh:message "A finding names each earlier revision its source contradicts by its IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:writerClockBehindByAtLeastDays ;
        sh:datatype xsd:integer ;
        sh:minInclusive 1 ;
        sh:maxCount 1 ;
        sh:message "A finding names at most one number of days a writer's clock was behind, a whole number of at least one."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:wasGeneratedBy ;
        sh:maxCount 0 ;
        sh:message "A finding for review names no act, so two writers file one: the act that filed it is known from its snapshot."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:generatedAtTime ;
        sh:maxCount 0 ;
        sh:message "A finding for review carries no time, so two writers file one: the act that filed it is known from its snapshot."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:used ;
        sh:maxCount 0 ;
        sh:message "A finding for review is an entity: it names the versions it was made from with prov:wasDerivedFrom, and prov:used is an activity's."@en ;
        sh:severity sh:Violation
    ] .

# A finding and the matcher judgments it names are filed apart, so its targets' sh:class holds over the pod's union of files, never
# over the finding's file alone.
cascade:MatcherJudgmentsNoLongerReachedShape a sh:NodeShape ;
    sh:targetClass cascade:FindingForReview ;
    sh:or (
        [ sh:not [ sh:path oa:hasBody ; sh:hasValue cascade:MatcherJudgmentsNoLongerReached ] ]
        [ sh:property [ sh:path cascade:noLongerReachedUnderRuleListVersion ; sh:minCount 1 ] ,
                      [ sh:path oa:hasTarget ; sh:class cascade:Judgment ] ]
    ) ;
    sh:message "A finding of matcher judgments no longer reached names the rule list version that no longer reaches them, and its targets are the matcher's judgments."@en ;
    sh:severity sh:Violation .

cascade:SourceReportedOlderStatesShape a sh:NodeShape ;
    sh:targetClass cascade:FindingForReview ;
    sh:or (
        [ sh:not [ sh:path oa:hasBody ; sh:hasValue cascade:SourceReportedOlderStates ] ]
        [ sh:property [ sh:path cascade:contradictedEarlierRevision ; sh:minCount 1 ; sh:class cascade:Revision ] ,
                      [ sh:path oa:hasTarget ; sh:class cascade:Revision ] ]
    ) ;
    sh:message "A finding of a source that reported older states names the earlier revisions it contradicts, and its targets are the revisions holding the older states."@en ;
    sh:severity sh:Violation .

cascade:ClockBehindShape a sh:NodeShape ;
    sh:targetClass cascade:FindingForReview ;
    sh:or (
        [ sh:not [ sh:path oa:hasBody ; sh:hasValue cascade:ClockBehind ] ]
        [ sh:property [ sh:path cascade:writerClockBehindByAtLeastDays ; sh:minCount 1 ] ,
                      [ sh:path oa:hasTarget ; sh:class cascade:Revision ] ]
    ) ;
    sh:message "A finding of a clock behind names how many days behind, and its targets are revisions."@en ;
    sh:severity sh:Violation .

cascade:FindingOfTwoLabResultsShape a sh:NodeShape ;
    sh:targetClass cascade:FindingForReview ;
    sh:or (
        [ sh:not [ sh:property [ sh:path oa:hasBody ; sh:minCount 1 ;
                                 sh:in ( cascade:DifferentResultValuesAtOneInstant cascade:DifferentResultUnitsAtOneInstant ) ] ] ]
        [ sh:property [ sh:path oa:hasTarget ; sh:minCount 2 ; sh:maxCount 2 ; sh:class cascade:LaboratoryTestResult ] ,
                      [ sh:path prov:wasDerivedFrom ; sh:nodeKind sh:IRI ; sh:minCount 2 ; sh:maxCount 2 ] ,
                      [ sh:path cascade:noLongerReachedUnderRuleListVersion ; sh:maxCount 0 ] ]
    ) ;
    sh:message "A finding of different result values or units at one instant names two lab results and the two versions it compared, and no rule list version."@en ;
    sh:severity sh:Violation .

cascade:DocumentImportShape a sh:NodeShape ;
    sh:targetClass cascade:DocumentImport ;
    sh:property [
        sh:path prov:startedAtTime ;
        sh:datatype xsd:dateTime ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "An import states the one time it started, an xsd:dateTime."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path prov:used ;
        sh:minCount 1 ;
        sh:message "An import that is written kept a document, and names each it kept with prov:used."@en ;
        sh:severity sh:Violation
    ] .

cascade:HandEntrySessionShape a sh:NodeShape ;
    sh:targetClass cascade:HandEntrySession ;
    sh:property [
        sh:path prov:startedAtTime ;
        sh:datatype xsd:dateTime ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "An entry session states the one time it started, an xsd:dateTime."@en ;
        sh:severity sh:Violation
    ] .

cascade:ConnectToServerShape a sh:NodeShape ;
    sh:targetClass cascade:ConnectToServer ;
    sh:property [
        sh:path prov:startedAtTime ;
        sh:datatype xsd:dateTime ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A connect states the one time it started, an xsd:dateTime."@en ;
        sh:severity sh:Violation
    ] .

cascade:MatcherRunShape a sh:NodeShape ;
    sh:targetClass cascade:MatcherRun ;
    sh:property [
        sh:path prov:wasInformedBy ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A matcher run is informed by at most one act, the import, entry session or sync whose records it takes."@en ;
        sh:severity sh:Violation
    ] .

cascade:SyncFromAnotherWriterShape a sh:NodeShape ;
    sh:targetClass cascade:SyncFromAnotherWriter ;
    sh:property [
        sh:path prov:wasInformedBy ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:message "A sync is informed by at least one act, each act other than a sync that the writer held unmerged when it wrote it."@en ;
        sh:severity sh:Violation
    ] .

cascade:SnapshotShape a sh:NodeShape ;
    sh:targetClass cascade:Snapshot ;
    sh:property [
        sh:path prov:wasGeneratedBy ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A snapshot is generated by one act, named by its IRI."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:firstParentSnapshot ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A snapshot has at most one first parent, the writer's previous snapshot."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:mergedParentSnapshot ;
        sh:nodeKind sh:IRI ;
        sh:message "A snapshot's merged parents are snapshots, named by their IRIs."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:setHash ;
        sh:datatype xsd:string ;
        sh:pattern "^[0-9a-f]{64}$" ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A snapshot carries one set hash, 64 lower-case hexadecimal digits."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:fileAddedToSet ;
        sh:datatype xsd:string ;
        sh:minCount 1 ;
        sh:message "A snapshot names each file of the set its act wrote by its path relative to the pod, its act's own file among them."@en ;
        sh:severity sh:Violation
    ] .

cascade:RuleListVersionRowShape a sh:NodeShape ;
    sh:targetSubjectsOf cascade:rowOfRuleListVersion ;
    sh:property [
        sh:path cascade:rowOfRuleListVersion ;
        sh:nodeKind sh:IRI ;
        sh:maxCount 1 ;
        sh:message "A row described in a pod belongs to one rule list version."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:matcherRule ;
        sh:node cascade:MatcherRuleShape ;
        sh:minCount 1 ;
        sh:message "A row described in a pod gives its matcher rule, one of the 20 cascade:MatcherRule terms."@en ;
        sh:severity sh:Violation
    ] , [
        sh:path cascade:queryHash ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:message "A row described in a pod gives the one query hash of its rule."@en ;
        sh:severity sh:Violation
    ] .

cascade:PersonJudgmentAssociationShape a sh:NodeShape ;
    sh:property [ sh:path prov:agent ; sh:nodeKind sh:IRI ; sh:minCount 1 ; sh:maxCount 1 ] ,
                [ sh:path prov:hadRole ; sh:minCount 1 ; sh:maxCount 1 ; sh:in ( cascade:PatientRole cascade:ModelProposerRole ) ] .

cascade:PersonJudgmentAuthorAssociationShape a sh:NodeShape ;
    sh:property [ sh:path prov:hadRole ; sh:hasValue cascade:PatientRole ] ,
                [ sh:path ( [ sh:inversePath prov:qualifiedAssociation ] [ sh:inversePath prov:wasGeneratedBy ] prov:wasAttributedTo ) ;
                  sh:equals prov:agent ] .

cascade:DocumentRoleAttributionShape a sh:NodeShape ;
    sh:targetSubjectsOf prov:wasGeneratedBy ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "A document's author and custodian, named by an association of the act that generated it, are each the object of its prov:wasAttributedTo: {?agent} is not."@en ;
        sh:severity sh:Violation ;
        sh:select """SELECT $this ?agent WHERE {
  $this <http://www.w3.org/ns/prov#wasGeneratedBy>/<http://www.w3.org/ns/prov#qualifiedAssociation> ?association .
  ?association <http://www.w3.org/ns/prov#agent> ?agent ;
                <http://www.w3.org/ns/prov#hadRole> ?role .
  FILTER (?role IN (<https://ns.cascadeprotocol.org/cascade#AuthorRole>, <https://ns.cascadeprotocol.org/cascade#CustodianRole>))
  FILTER NOT EXISTS { $this <http://www.w3.org/ns/prov#wasAttributedTo> ?agent }
}""" ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "A document's prov:wasAttributedTo never names a party that only transmitted it: {?agent} does."@en ;
        sh:severity sh:Violation ;
        sh:select """SELECT $this ?agent WHERE {
  $this <http://www.w3.org/ns/prov#wasAttributedTo> ?agent .
  $this <http://www.w3.org/ns/prov#wasGeneratedBy>/<http://www.w3.org/ns/prov#qualifiedAssociation> ?association .
  ?association <http://www.w3.org/ns/prov#agent> ?agent ;
                <http://www.w3.org/ns/prov#hadRole> <https://ns.cascadeprotocol.org/cascade#TransmitterRole> .
  FILTER NOT EXISTS {
    $this <http://www.w3.org/ns/prov#wasGeneratedBy>/<http://www.w3.org/ns/prov#qualifiedAssociation> ?other .
    ?other <http://www.w3.org/ns/prov#agent> ?agent ;
           <http://www.w3.org/ns/prov#hadRole> ?role .
    FILTER (?role IN (<https://ns.cascadeprotocol.org/cascade#AuthorRole>, <https://ns.cascadeprotocol.org/cascade#CustodianRole>))
  }
}""" ] .
