# Canonical DSP read contract — $graphql at Encounter scope.
# POST [fhir-base]/Encounter/{id}/$graphql
# Content-Type: application/json
# Body: { "query": "<below>" }

query DspEncounter($id: ID!) {
  Encounter(id: $id) {
    id
    status
    class { code display }
    period { start end }
    subject { resource { ... on Patient { id identifier { system value } name { family given } } } }
    extension(url: "https://dsp-fhir.org/StructureDefinition/dsp-payload-version") {
      extension { url valueInteger valueCode valueString }
    }
    Composition: _revinclude(type: "Composition", field: "encounter") {
      id
      type { coding { system code display } }
      section { title code { coding { system code display } } text { status div } }
    }
    Condition: _revinclude(type: "Condition", field: "encounter") {
      id
      code { coding { system code display } text }
      clinicalStatus { coding { code } }
      extension(url: "https://dsp-fhir.org/StructureDefinition/dsp-confidence-score") { valueDecimal }
      extension(url: "https://dsp-fhir.org/StructureDefinition/dsp-transcript-turn-ref") {
        transcript: extension(url: "transcript") { valueReference { reference } }
        turn:       extension(url: "turn")       { valueInteger }
      }
    }
    MedicationRequest: _revinclude(type: "MedicationRequest", field: "encounter") {
      id medicationCodeableConcept { coding { system code display } text } dosageInstruction { text }
    }
    ServiceRequest: _revinclude(type: "ServiceRequest", field: "encounter") {
      id category { coding { system code display } } code { coding { system code display } text }
    }
  }
}
