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


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

    comment: str | None = Field(None, alias="comment", serialization_alias="comment")
    link: Reference = Field(alias="link", serialization_alias="link")


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

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

    based_on: PyList[Reference] | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    category: PyList[CodeableConcept] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    conclusion: str | None = Field(
        None, alias="conclusion", serialization_alias="conclusion"
    )
    conclusion_code: PyList[CodeableConcept] | None = Field(
        None, alias="conclusionCode", serialization_alias="conclusionCode"
    )
    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"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    imaging_study: PyList[Reference] | None = Field(
        None, alias="imagingStudy", serialization_alias="imagingStudy"
    )
    issued: str | None = Field(None, alias="issued", serialization_alias="issued")
    media: PyList[DiagnosticReportMedia] | None = Field(
        None, alias="media", serialization_alias="media"
    )
    performer: PyList[Reference] | None = Field(
        None, alias="performer", serialization_alias="performer"
    )
    presented_form: PyList[Attachment] | None = Field(
        None, alias="presentedForm", serialization_alias="presentedForm"
    )
    result: PyList[Reference] | None = Field(
        None, alias="result", serialization_alias="result"
    )
    results_interpreter: PyList[Reference] | None = Field(
        None, alias="resultsInterpreter", serialization_alias="resultsInterpreter"
    )
    specimen: PyList[Reference] | None = Field(
        None, alias="specimen", serialization_alias="specimen"
    )
    status: Literal[
        "registered",
        "partial",
        "final",
        "amended",
        "cancelled",
        "entered-in-error",
        "unknown",
        "preliminary",
        "corrected",
        "appended",
    ] = Field(alias="status", serialization_alias="status")
    subject: Reference | None = Field(
        None, 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) -> DiagnosticReport:
        return cls.model_validate_json(json)
