// FHIR Patient Resource as Prisma Model
// Based on https://www.hl7.org/fhir/patient.html
// Using the previously defined composite types

// First including all the composite types needed for Patient resource
// (Abbreviated - in production you would include the full definitions from the previous schema)

// PatientCommunication type
type PatientCommunication {
    language  CodeableConcept
    preferred Boolean?
}

// PatientContact type
type PatientContact {
    relationship CodeableConcept[]
    name         HumanName?
    telecom      ContactPoint[]
    address      Address?
    gender       String? // male | female | other | unknown
    organization Reference?
    period       Period?
}

// PatientLink type
type PatientLink {
    other Reference
    type  String // replaced-by | replaces | refer | seealso
}

// Main Patient Model
model Patient {
    id           String @id @default(auto()) @map("_id") @db.ObjectId
    resourceType String @default("Patient")

    // Metadata
    meta          Json?
    implicitRules String?
    language      String?

    // Identifiers and administrative information
    identifier Identifier[] // An identifier for this patient
    active     Boolean? // Whether this patient's record is in active use

    // Name, gender, birth, deceased
    name             HumanName[] // A name associated with the patient
    telecom          ContactPoint[] // A contact detail for the individual
    gender           String? // male | female | other | unknown
    birthDate        DateTime? // The date of birth for the individual
    deceasedBoolean  Boolean? // Indicates if the individual is deceased or not
    deceasedDateTime DateTime? // Indicates if the individual is deceased or not

    // Address information
    address Address[] // An address for the individual

    // Patient demographic information
    maritalStatus        CodeableConcept? // Marital (civil) status of a patient
    multipleBirthBoolean Boolean? // Whether patient is part of a multiple birth
    multipleBirthInteger Int? // Whether patient is part of a multiple birth
    photo                Attachment[] // Image of the patient

    // Contact information
    contact PatientContact[] // A contact party (e.g. guardian, partner, friend) for the patient

    // Care provider and communications
    communication        PatientCommunication[] // A language which may be used to communicate with the patient
    generalPractitioner  Reference[] // Patient's nominated primary care provider
    managingOrganization Reference? // Organization that is the custodian of the patient record

    // Link to other patient records
    link PatientLink[] // Link to another patient resource that concerns the same actual person

    // Extension mechanism
    extension Json? // Additional information not captured in other defined elements

    // Required for most models
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}
