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

import datetime as dt
import typing

import pydantic
from ....core.pydantic_utilities import IS_PYDANTIC_V2
from ...commons.types.facility_type_code import FacilityTypeCode
from ...commons.types.street_address_long_zip import StreetAddressLongZip
from ...custom_schemas.resources.v_1.types.schema_instance import SchemaInstance
from ...encounter_providers.resources.v_2.types.billing_provider_update import BillingProviderUpdate
from ...encounter_providers.resources.v_2.types.initial_referring_provider_update import InitialReferringProviderUpdate
from ...encounter_providers.resources.v_2.types.referring_provider_update import ReferringProviderUpdate
from ...encounter_providers.resources.v_2.types.rendering_provider_update import RenderingProviderUpdate
from ...encounter_providers.resources.v_2.types.supervising_provider_update import SupervisingProviderUpdate
from ...encounters.resources.v_4.types.claim_supplemental_information import ClaimSupplementalInformation
from ...encounters.resources.v_4.types.clinical_note_category_create import ClinicalNoteCategoryCreate
from ...encounters.resources.v_4.types.encounter_optional import EncounterOptional
from ...encounters.resources.v_4.types.epsdt_referral import EpsdtReferral
from ...encounters.resources.v_4.types.medication import Medication
from ...guarantor.resources.v_1.types.guarantor_update import GuarantorUpdate
from ...individual.types.patient_update import PatientUpdate
from ...individual.types.subscriber_create import SubscriberCreate
from ...property_and_casualty.resources.v_1.types.property_casualty_patient_identifier_update import (
    PropertyCasualtyPatientIdentifierUpdate,
)
from ...related_causes.resources.v_1.types.related_causes_information_update import RelatedCausesInformationUpdate
from ...service_facility.types.encounter_service_facility_update import EncounterServiceFacilityUpdate


class UniversalEncounterUpdateBase(EncounterOptional):
    epsdt_referral: typing.Optional[EpsdtReferral] = pydantic.Field(default=None)
    """
    Refers to Box 24H on the CMS1500 form and Loop 2300 CRC - EPSDT Referral on the 837P and 837i form
    """

    clinical_notes: typing.Optional[typing.List[ClinicalNoteCategoryCreate]] = pydantic.Field(default=None)
    """
    Holds a collection of clinical observations made by healthcare providers during patient encounters. Please note that medical records for appeals should be sent using the Encounter Attachments API.
    """

    claim_supplemental_information: typing.Optional[typing.List[ClaimSupplementalInformation]] = pydantic.Field(
        default=None
    )
    """
    Refers to Loop 2300 - Segment PWK on the 837P and 837i form. No more than 10 entries are permitted.
    """

    schema_instances: typing.Optional[typing.List[SchemaInstance]] = pydantic.Field(default=None)
    """
    Key-value pairs that must adhere to a schema created via the Custom Schema API. Multiple schema
    instances cannot be created for the same schema on an encounter. Updating schema instances utilizes PUT
    semantics, so the schema instances on the encounter will be set to whatever inputs are provided. If null
    is provided as an input, then the encounter's schema instances will be cleared.
    """

    existing_medications: typing.Optional[typing.List[Medication]] = pydantic.Field(default=None)
    """
    Existing medications that should be on the encounter.
    Note all current existing medications on encounter will be overridden with this list.
    """

    guarantor: typing.Optional[GuarantorUpdate] = pydantic.Field(default=None)
    """
    Personal and contact info for the guarantor of the patient responsibility.
    """

    subscriber_primary: typing.Optional[SubscriberCreate] = pydantic.Field(default=None)
    """
    Contains details of the primary insurance subscriber.
    """

    subscriber_secondary: typing.Optional[SubscriberCreate] = pydantic.Field(default=None)
    """
    Contains details of the secondary insurance subscriber.
    """

    subscriber_tertiary: typing.Optional[SubscriberCreate] = pydantic.Field(default=None)
    """
    Contains details of the tertiary insurance subscriber.
    """

    pay_to_address: typing.Optional[StreetAddressLongZip] = pydantic.Field(default=None)
    """
    Specifies the address to which payments for the claim should be sent.
    """

    initial_referring_provider: typing.Optional[InitialReferringProviderUpdate] = pydantic.Field(default=None)
    """
    The second iteration of Loop ID-2310 on an 837P form. Use code "P3 - Primary Care Provider" in this loop to
    indicate the initial referral from the primary care provider or whatever provider wrote the initial referral for this patient's episode of care being billed/reported in this transaction.
    Not used in an 837i claim
    """

    referring_provider: typing.Optional[ReferringProviderUpdate] = pydantic.Field(default=None)
    """
    The final provider who referred the services that were rendered.
    All physicians who order services or refer Medicare beneficiaries must
    report this data.
    """

    patient: typing.Optional[PatientUpdate] = pydantic.Field(default=None)
    """
    Contains the identification information of the individual receiving medical services.
    """

    rendering_provider: typing.Optional[RenderingProviderUpdate] = pydantic.Field(default=None)
    """
    The rendering provider is the practitioner -- physician, nurse practitioner, etc. -- performing the service.
    For telehealth services, the rendering provider performs the visit, asynchronous communication, or other service. The rendering provider address should generally be the same as the service facility address.
    """

    service_facility: typing.Optional[EncounterServiceFacilityUpdate] = pydantic.Field(default=None)
    """
    Encounter Service facility is typically the location a medical service was rendered, such as a provider office or hospital. For telehealth, service facility can represent the provider's location when the service was delivered (e.g., home), or the location where an in-person visit would have taken place, whichever is easier to identify. If the provider is in-network, service facility may be defined in payer contracts. Box 32 on the CMS-1500 claim form. There is no equivalent on the paper UB-04 claim form, but this field is equivalent to Loop 2310E Service Facility Location details on an 837i form, and is used when this is different to the entity identified as the Billing Provider. Note that for an in-network claim to be successfully adjudicated, the service facility address listed
    """

    supervising_provider: typing.Optional[SupervisingProviderUpdate] = pydantic.Field(default=None)
    """
    Required when the rendering provider is supervised by a physician. If not required by this implementation guide, do not send.
    """

    billing_provider: typing.Optional[BillingProviderUpdate] = pydantic.Field(default=None)
    """
    The billing provider is the provider or business entity submitting the claim. Billing provider may be, but is not necessarily, the same person/NPI as the rendering provider. From a payer's perspective, this represents the person or entity being reimbursed. When a contract exists with the target payer, the billing provider should be the entity contracted with the payer. In some circumstances, this will be an individual provider. In that case, submit that provider's NPI and the tax ID (TIN) that the provider gave to the payer during contracting. In other cases, the billing entity will be a medical group. If so, submit the group NPI and the group's tax ID. Box 33 on the CMS-1500 claim or Form Locator 1 on a UB-04 claim form.
    """

    place_of_service_code_as_submitted: typing.Optional[FacilityTypeCode] = pydantic.Field(default=None)
    """
    Box 24B on the CMS-1500 claim form. 837p Loop2300, CLM-05-1. This box is not used on a UB-04 or 837i claim form. 02 for telemedicine, 11 for in-person. Full list [here](https://www.cms.gov/Medicare/Coding/place-of-service-codes/Place_of_Service_Code_Set).
    """

    related_causes_information: typing.Optional[RelatedCausesInformationUpdate] = pydantic.Field(default=None)
    """
    Corresponds to box 10a on the CMS-1500 (Loop 2300 on 837)
    """

    property_casualty_claim_number: typing.Optional[str] = pydantic.Field(default=None)
    """
    837p Loop2010 REF02, CMS1500 Box 11b
    """

    accident_date: typing.Optional[dt.date] = pydantic.Field(default=None)
    """
    837p Loop2300 DTP*439, CMS1500 Box 15
    """

    property_casualty_patient_identifier: typing.Optional[PropertyCasualtyPatientIdentifierUpdate] = pydantic.Field(
        default=None
    )
    """
    Patient identifier for Property and Casualty claims
    837p Loop 2010CA
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
