# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ..core.datetime_utils import serialize_datetime
from .interpretation_item import InterpretationItem
from .observation_effective_date_time import ObservationEffectiveDateTime
from .observation_issued import ObservationIssued
from .reference_range_item import ReferenceRangeItem
from .value_quantity import ValueQuantity
from .value_range import ValueRange
from .vital_core_providers_lab_test_labs_schemas_results_fhir_code import (
    VitalCoreProvidersLabTestLabsSchemasResultsFhirCode,
)

try:
    import pydantic.v1 as pydantic  # type: ignore
except ImportError:
    import pydantic  # type: ignore


class Observation(pydantic.BaseModel):
    resource_type: str = pydantic.Field(alias="resourceType")
    status: str
    code: VitalCoreProvidersLabTestLabsSchemasResultsFhirCode
    effective_date_time: ObservationEffectiveDateTime = pydantic.Field(alias="effectiveDateTime")
    issued: ObservationIssued
    value_quantity: typing.Optional[ValueQuantity] = pydantic.Field(alias="valueQuantity")
    value_range: typing.Optional[ValueRange] = pydantic.Field(alias="valueRange")
    value_string: typing.Optional[str] = pydantic.Field(alias="valueString")
    interpretation: typing.List[InterpretationItem]
    reference_range: typing.List[ReferenceRangeItem] = pydantic.Field(alias="referenceRange")

    def json(self, **kwargs: typing.Any) -> str:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().json(**kwargs_with_defaults)

    def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().dict(**kwargs_with_defaults)

    class Config:
        frozen = True
        smart_union = True
        allow_population_by_field_name = True
        json_encoders = {dt.datetime: serialize_datetime}
