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


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

    body_site: Coding | None = Field(
        None, alias="bodySite", serialization_alias="bodySite"
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    endpoint: PyList[Reference] | None = Field(
        None, alias="endpoint", serialization_alias="endpoint"
    )
    instance: PyList[ImagingStudySeriesInstance] | None = Field(
        None, alias="instance", serialization_alias="instance"
    )
    laterality: Coding | None = Field(
        None, alias="laterality", serialization_alias="laterality"
    )
    modality: Coding = Field(alias="modality", serialization_alias="modality")
    number: int | None = Field(None, alias="number", serialization_alias="number")
    number_of_instances: int | None = Field(
        None, alias="numberOfInstances", serialization_alias="numberOfInstances"
    )
    performer: PyList[ImagingStudySeriesPerformer] | None = Field(
        None, alias="performer", serialization_alias="performer"
    )
    specimen: PyList[Reference] | None = Field(
        None, alias="specimen", serialization_alias="specimen"
    )
    started: str | None = Field(None, alias="started", serialization_alias="started")
    uid: str = Field(alias="uid", serialization_alias="uid")


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

    number: int | None = Field(None, alias="number", serialization_alias="number")
    sop_class: Coding = Field(alias="sopClass", serialization_alias="sopClass")
    title: str | None = Field(None, alias="title", serialization_alias="title")
    uid: str = Field(alias="uid", serialization_alias="uid")


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

    actor: Reference = Field(alias="actor", serialization_alias="actor")
    function: CodeableConcept | None = Field(
        None, alias="function", serialization_alias="function"
    )


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

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

    based_on: PyList[Reference] | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    endpoint: PyList[Reference] | None = Field(
        None, alias="endpoint", serialization_alias="endpoint"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    interpreter: PyList[Reference] | None = Field(
        None, alias="interpreter", serialization_alias="interpreter"
    )
    location: Reference | None = Field(
        None, alias="location", serialization_alias="location"
    )
    modality: PyList[Coding] | None = Field(
        None, alias="modality", serialization_alias="modality"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    number_of_instances: int | None = Field(
        None, alias="numberOfInstances", serialization_alias="numberOfInstances"
    )
    number_of_series: int | None = Field(
        None, alias="numberOfSeries", serialization_alias="numberOfSeries"
    )
    procedure_code: PyList[CodeableConcept] | None = Field(
        None, alias="procedureCode", serialization_alias="procedureCode"
    )
    procedure_reference: Reference | None = Field(
        None, alias="procedureReference", serialization_alias="procedureReference"
    )
    reason_code: PyList[CodeableConcept] | None = Field(
        None, alias="reasonCode", serialization_alias="reasonCode"
    )
    reason_reference: PyList[Reference] | None = Field(
        None, alias="reasonReference", serialization_alias="reasonReference"
    )
    referrer: Reference | None = Field(
        None, alias="referrer", serialization_alias="referrer"
    )
    series: PyList[ImagingStudySeries] | None = Field(
        None, alias="series", serialization_alias="series"
    )
    started: str | None = Field(None, alias="started", serialization_alias="started")
    status: Literal[
        "registered", "available", "cancelled", "entered-in-error", "unknown"
    ] = 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) -> ImagingStudy:
        return cls.model_validate_json(json)
