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


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

    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    measure_score: Quantity | None = Field(
        None, alias="measureScore", serialization_alias="measureScore"
    )
    population: PyList[MeasureReportGroupPopulation] | None = Field(
        None, alias="population", serialization_alias="population"
    )
    stratifier: PyList[MeasureReportGroupStratifier] | None = Field(
        None, alias="stratifier", serialization_alias="stratifier"
    )


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

    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    count: int | None = Field(None, alias="count", serialization_alias="count")
    subject_results: Reference | None = Field(
        None, alias="subjectResults", serialization_alias="subjectResults"
    )


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

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


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

    component: PyList[MeasureReportGroupStratifierStratumComponent] | None = Field(
        None, alias="component", serialization_alias="component"
    )
    measure_score: Quantity | None = Field(
        None, alias="measureScore", serialization_alias="measureScore"
    )
    population: PyList[MeasureReportGroupStratifierStratumPopulation] | None = Field(
        None, alias="population", serialization_alias="population"
    )
    value: CodeableConcept | None = Field(
        None, alias="value", serialization_alias="value"
    )


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

    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    value: CodeableConcept = Field(alias="value", serialization_alias="value")


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

    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    count: int | None = Field(None, alias="count", serialization_alias="count")
    subject_results: Reference | None = Field(
        None, alias="subjectResults", serialization_alias="subjectResults"
    )


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

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

    date: str | None = Field(None, alias="date", serialization_alias="date")
    evaluated_resource: PyList[Reference] | None = Field(
        None, alias="evaluatedResource", serialization_alias="evaluatedResource"
    )
    group: PyList[MeasureReportGroup] | None = Field(
        None, alias="group", serialization_alias="group"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    improvement_notation: CodeableConcept | None = Field(
        None, alias="improvementNotation", serialization_alias="improvementNotation"
    )
    measure: str = Field(alias="measure", serialization_alias="measure")
    period: Period = Field(alias="period", serialization_alias="period")
    reporter: Reference | None = Field(
        None, alias="reporter", serialization_alias="reporter"
    )
    status: Literal["complete", "pending", "error"] = Field(
        alias="status", serialization_alias="status"
    )
    subject: Reference | None = Field(
        None, alias="subject", serialization_alias="subject"
    )
    type: Literal["individual", "subject-list", "summary", "data-collection"] = Field(
        alias="type", serialization_alias="type"
    )

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