# 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,
    ContactDetail,
    Identifier,
    Period,
    Reference,
    RelatedArtifact,
    UsageContext,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    certainty_subcomponent: (
        PyList[RiskEvidenceSynthesisCertaintyCertaintySubcomponent] | None
    ) = Field(
        None, alias="certaintySubcomponent", serialization_alias="certaintySubcomponent"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    rating: PyList[CodeableConcept] | None = Field(
        None, alias="rating", serialization_alias="rating"
    )


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

    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    rating: PyList[CodeableConcept] | None = Field(
        None, alias="rating", serialization_alias="rating"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    denominator_count: int | None = Field(
        None, alias="denominatorCount", serialization_alias="denominatorCount"
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    numerator_count: int | None = Field(
        None, alias="numeratorCount", serialization_alias="numeratorCount"
    )
    precision_estimate: (
        PyList[RiskEvidenceSynthesisRiskEstimatePrecisionEstimate] | None
    ) = Field(None, alias="precisionEstimate", serialization_alias="precisionEstimate")
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")
    unit_of_measure: CodeableConcept | None = Field(
        None, alias="unitOfMeasure", serialization_alias="unitOfMeasure"
    )
    value: float | None = Field(None, alias="value", serialization_alias="value")


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

    from_: float | None = Field(None, alias="from", serialization_alias="from")
    level: float | None = Field(None, alias="level", serialization_alias="level")
    to: float | None = Field(None, alias="to", serialization_alias="to")
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    number_of_participants: int | None = Field(
        None, alias="numberOfParticipants", serialization_alias="numberOfParticipants"
    )
    number_of_studies: int | None = Field(
        None, alias="numberOfStudies", serialization_alias="numberOfStudies"
    )


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

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

    approval_date: str | None = Field(
        None, alias="approvalDate", serialization_alias="approvalDate"
    )
    author: PyList[ContactDetail] | None = Field(
        None, alias="author", serialization_alias="author"
    )
    certainty: PyList[RiskEvidenceSynthesisCertainty] | None = Field(
        None, alias="certainty", serialization_alias="certainty"
    )
    contact: PyList[ContactDetail] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    copyright: str | None = Field(
        None, alias="copyright", serialization_alias="copyright"
    )
    date: str | None = Field(None, alias="date", serialization_alias="date")
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    editor: PyList[ContactDetail] | None = Field(
        None, alias="editor", serialization_alias="editor"
    )
    effective_period: Period | None = Field(
        None, alias="effectivePeriod", serialization_alias="effectivePeriod"
    )
    endorser: PyList[ContactDetail] | None = Field(
        None, alias="endorser", serialization_alias="endorser"
    )
    exposure: Reference | None = Field(
        None, alias="exposure", serialization_alias="exposure"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    jurisdiction: PyList[CodeableConcept] | None = Field(
        None, alias="jurisdiction", serialization_alias="jurisdiction"
    )
    last_review_date: str | None = Field(
        None, alias="lastReviewDate", serialization_alias="lastReviewDate"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    outcome: Reference = Field(alias="outcome", serialization_alias="outcome")
    population: Reference = Field(alias="population", serialization_alias="population")
    publisher: str | None = Field(
        None, alias="publisher", serialization_alias="publisher"
    )
    related_artifact: PyList[RelatedArtifact] | None = Field(
        None, alias="relatedArtifact", serialization_alias="relatedArtifact"
    )
    reviewer: PyList[ContactDetail] | None = Field(
        None, alias="reviewer", serialization_alias="reviewer"
    )
    risk_estimate: RiskEvidenceSynthesisRiskEstimate | None = Field(
        None, alias="riskEstimate", serialization_alias="riskEstimate"
    )
    sample_size: RiskEvidenceSynthesisSampleSize | None = Field(
        None, alias="sampleSize", serialization_alias="sampleSize"
    )
    status: Literal["draft", "active", "retired", "unknown"] = Field(
        alias="status", serialization_alias="status"
    )
    study_type: CodeableConcept | None = Field(
        None, alias="studyType", serialization_alias="studyType"
    )
    synthesis_type: CodeableConcept | None = Field(
        None, alias="synthesisType", serialization_alias="synthesisType"
    )
    title: str | None = Field(None, alias="title", serialization_alias="title")
    topic: PyList[CodeableConcept] | None = Field(
        None, alias="topic", serialization_alias="topic"
    )
    url: str | None = Field(None, alias="url", serialization_alias="url")
    use_context: PyList[UsageContext] | None = Field(
        None, alias="useContext", serialization_alias="useContext"
    )
    version: str | None = Field(None, alias="version", serialization_alias="version")

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