# WARNING: This file is autogenerated by FHIR Schema Codegen.
# https://github.com/fhir-schema/fhir-schema-codegen
# Any manual changes made to this file may be overwritten.

from __future__ import annotations
from pydantic import ConfigDict, Field
from typing import List as PyList, Literal

from fhirschemapy.R4B.domain_resource import DomainResource

from fhirschemapy.R4B.base import (
    Address,
    Attachment,
    BackboneElement,
    CodeableConcept,
    ContactPoint,
    HumanName,
    Identifier,
    Period,
    Reference,
)


class PatientCommunication(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    language: CodeableConcept = Field(alias="language", serialization_alias="language")
    preferred: bool | None = Field(
        None, alias="preferred", serialization_alias="preferred"
    )


class PatientContact(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    address: Address | None = Field(
        None, alias="address", serialization_alias="address"
    )
    gender: Literal["male", "female", "other", "unknown"] | None = Field(
        None, alias="gender", serialization_alias="gender"
    )
    name: HumanName | None = Field(None, alias="name", serialization_alias="name")
    organization: Reference | None = Field(
        None, alias="organization", serialization_alias="organization"
    )
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    relationship: PyList[CodeableConcept] | None = Field(
        None, alias="relationship", serialization_alias="relationship"
    )
    telecom: PyList[ContactPoint] | None = Field(
        None, alias="telecom", serialization_alias="telecom"
    )


class PatientLink(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    other: Reference = Field(alias="other", serialization_alias="other")
    type: Literal["replaced-by", "replaces", "refer", "seealso"] = Field(
        alias="type", serialization_alias="type"
    )


class Patient(DomainResource):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    resource_type: str = Field(
        default="Patient",
        alias="resourceType",
        serialization_alias="resourceType",
        frozen=True,
        pattern="Patient",
    )

    active: bool | None = Field(None, alias="active", serialization_alias="active")
    address: PyList[Address] | None = Field(
        None, alias="address", serialization_alias="address"
    )
    birth_date: str | None = Field(
        None, alias="birthDate", serialization_alias="birthDate"
    )
    communication: PyList[PatientCommunication] | None = Field(
        None, alias="communication", serialization_alias="communication"
    )
    contact: PyList[PatientContact] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    deceased_boolean: bool | None = Field(
        None, alias="deceasedBoolean", serialization_alias="deceasedBoolean"
    )
    deceased_date_time: str | None = Field(
        None, alias="deceasedDateTime", serialization_alias="deceasedDateTime"
    )
    gender: Literal["male", "female", "other", "unknown"] | None = Field(
        None, alias="gender", serialization_alias="gender"
    )
    general_practitioner: PyList[Reference] | None = Field(
        None, alias="generalPractitioner", serialization_alias="generalPractitioner"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    link: PyList[PatientLink] | None = Field(
        None, alias="link", serialization_alias="link"
    )
    managing_organization: Reference | None = Field(
        None, alias="managingOrganization", serialization_alias="managingOrganization"
    )
    marital_status: CodeableConcept | None = Field(
        None, alias="maritalStatus", serialization_alias="maritalStatus"
    )
    multiple_birth_boolean: bool | None = Field(
        None, alias="multipleBirthBoolean", serialization_alias="multipleBirthBoolean"
    )
    multiple_birth_integer: int | None = Field(
        None, alias="multipleBirthInteger", serialization_alias="multipleBirthInteger"
    )
    name: PyList[HumanName] | None = Field(
        None, alias="name", serialization_alias="name"
    )
    photo: PyList[Attachment] | None = Field(
        None, alias="photo", serialization_alias="photo"
    )
    telecom: PyList[ContactPoint] | None = Field(
        None, alias="telecom", serialization_alias="telecom"
    )

    def to_json(self, indent: int | None = None) -> str:
        return self.model_dump_json(
            exclude_unset=True, exclude_none=True, indent=indent
        )

    @classmethod
    def from_json(cls, json: str) -> Patient:
        return cls.model_validate_json(json)
