# 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.base import (
    Annotation,
    BackboneElement,
    CodeableConcept,
    Identifier,
    Period,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    basis: str | None = Field(None, alias="basis", serialization_alias="basis")
    item_codeable_concept: CodeableConcept | None = Field(
        None, alias="itemCodeableConcept", serialization_alias="itemCodeableConcept"
    )
    item_reference: Reference | None = Field(
        None, alias="itemReference", serialization_alias="itemReference"
    )


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

    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    item: PyList[Reference] | None = Field(
        None, alias="item", serialization_alias="item"
    )


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

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

    assessor: Reference | None = Field(
        None, alias="assessor", serialization_alias="assessor"
    )
    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    date: str | None = Field(None, alias="date", serialization_alias="date")
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    effective_date_time: str | None = Field(
        None, alias="effectiveDateTime", serialization_alias="effectiveDateTime"
    )
    effective_period: Period | None = Field(
        None, alias="effectivePeriod", serialization_alias="effectivePeriod"
    )
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    finding: PyList[ClinicalImpressionFinding] | None = Field(
        None, alias="finding", serialization_alias="finding"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    investigation: PyList[ClinicalImpressionInvestigation] | None = Field(
        None, alias="investigation", serialization_alias="investigation"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    previous: Reference | None = Field(
        None, alias="previous", serialization_alias="previous"
    )
    problem: PyList[Reference] | None = Field(
        None, alias="problem", serialization_alias="problem"
    )
    prognosis_codeable_concept: PyList[CodeableConcept] | None = Field(
        None,
        alias="prognosisCodeableConcept",
        serialization_alias="prognosisCodeableConcept",
    )
    prognosis_reference: PyList[Reference] | None = Field(
        None, alias="prognosisReference", serialization_alias="prognosisReference"
    )
    protocol: PyList[str] | None = Field(
        None, alias="protocol", serialization_alias="protocol"
    )
    status: Literal["in-progress", "completed", "entered-in-error"] = Field(
        alias="status", serialization_alias="status"
    )
    status_reason: CodeableConcept | None = Field(
        None, alias="statusReason", serialization_alias="statusReason"
    )
    subject: Reference = Field(alias="subject", serialization_alias="subject")
    summary: str | None = Field(None, alias="summary", serialization_alias="summary")
    supporting_info: PyList[Reference] | None = Field(
        None, alias="supportingInfo", serialization_alias="supportingInfo"
    )

    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) -> ClinicalImpression:
        return cls.model_validate_json(json)
