# 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,
    Range,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    outcome: CodeableConcept | None = Field(
        None, alias="outcome", serialization_alias="outcome"
    )
    probability_decimal: float | None = Field(
        None, alias="probabilityDecimal", serialization_alias="probabilityDecimal"
    )
    probability_range: Range | None = Field(
        None, alias="probabilityRange", serialization_alias="probabilityRange"
    )
    qualitative_risk: CodeableConcept | None = Field(
        None, alias="qualitativeRisk", serialization_alias="qualitativeRisk"
    )
    rationale: str | None = Field(
        None, alias="rationale", serialization_alias="rationale"
    )
    relative_risk: float | None = Field(
        None, alias="relativeRisk", serialization_alias="relativeRisk"
    )
    when_period: Period | None = Field(
        None, alias="whenPeriod", serialization_alias="whenPeriod"
    )
    when_range: Range | None = Field(
        None, alias="whenRange", serialization_alias="whenRange"
    )


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

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

    based_on: Reference | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    basis: PyList[Reference] | None = Field(
        None, alias="basis", serialization_alias="basis"
    )
    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    condition: Reference | None = Field(
        None, alias="condition", serialization_alias="condition"
    )
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    method: CodeableConcept | None = Field(
        None, alias="method", serialization_alias="method"
    )
    mitigation: str | None = Field(
        None, alias="mitigation", serialization_alias="mitigation"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    occurrence_date_time: str | None = Field(
        None, alias="occurrenceDateTime", serialization_alias="occurrenceDateTime"
    )
    occurrence_period: Period | None = Field(
        None, alias="occurrencePeriod", serialization_alias="occurrencePeriod"
    )
    parent: Reference | None = Field(None, alias="parent", serialization_alias="parent")
    performer: Reference | None = Field(
        None, alias="performer", serialization_alias="performer"
    )
    prediction: PyList[RiskAssessmentPrediction] | None = Field(
        None, alias="prediction", serialization_alias="prediction"
    )
    reason_code: PyList[CodeableConcept] | None = Field(
        None, alias="reasonCode", serialization_alias="reasonCode"
    )
    reason_reference: PyList[Reference] | None = Field(
        None, alias="reasonReference", serialization_alias="reasonReference"
    )
    status: Literal[
        "registered",
        "preliminary",
        "final",
        "amended",
        "cancelled",
        "entered-in-error",
        "unknown",
        "corrected",
    ] = Field(alias="status", serialization_alias="status")
    subject: Reference = Field(alias="subject", serialization_alias="subject")

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