// FHIR Encounter Resource Prisma Schema
// Based on https://www.hl7.org/fhir/encounter.html

// Reusing composite types defined previously

model Encounter {
    id              String                    @id @map("_id")
    identifier      Identifier[]
    status          String // planned | arrived | triaged | in-progress | onleave | finished | cancelled
    statusHistory   EncounterStatusHistory[]
    class           Coding
    classHistory    EncounterClassHistory[]
    type            CodeableConcept[]
    serviceType     CodeableConcept?
    priority        CodeableConcept?
    subject         Reference? // Reference to Patient, Group, Device, etc.
    episodeOfCare   Reference[] // Reference to EpisodeOfCare
    basedOn         Reference[] // Reference to ServiceRequest
    participant     EncounterParticipant[]
    appointment     Reference[] // Reference to Appointment
    period          Period?
    length          Duration?
    reasonCode      CodeableConcept[]
    reasonReference Reference[] // Reference to Condition, Procedure, etc.
    diagnosis       EncounterDiagnosis[]
    account         Reference[] // Reference to Account
    hospitalization EncounterHospitalization?
    location        EncounterLocation[]
    serviceProvider Reference? // Reference to Organization
    partOf          Reference? // Reference to another Encounter
}

// Encounter-specific composite types

type EncounterStatusHistory {
    status String // planned | arrived | triaged | in-progress | onleave | finished | cancelled
    period Period
}

type EncounterClassHistory {
    class  Coding
    period Period
}

type EncounterParticipant {
    type       CodeableConcept[]
    period     Period?
    individual Reference? // Reference to Practitioner, PractitionerRole, RelatedPerson
}

type EncounterDiagnosis {
    condition Reference // Reference to Condition, Procedure
    use       CodeableConcept?
    rank      Int?
}

type EncounterHospitalization {
    preAdmissionIdentifier Identifier?
    origin                 Reference? // Reference to Location, Organization
    admitSource            CodeableConcept?
    reAdmission            CodeableConcept?
    dietPreference         CodeableConcept[]
    specialCourtesy        CodeableConcept[]
    specialArrangement     CodeableConcept[]
    destination            Reference? // Reference to Location, Organization
    dischargeDisposition   CodeableConcept?
}

type EncounterLocation {
    location     Reference // Reference to Location
    status       String? // planned | active | reserved | completed
    physicalType CodeableConcept?
    period       Period?
}
