# 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 ...billing_notes.resources.v_2.types.billing_note_base import BillingNoteBase
from ...claim_submission.resources.v_1.types.external_claim_submission_create import ExternalClaimSubmissionCreate
from ...custom_schemas.resources.v_1.types.schema_instance import SchemaInstance
from ...encounter_providers.resources.v_2.types.initial_referring_provider import InitialReferringProvider
from ...encounter_providers.resources.v_2.types.referring_provider import ReferringProvider
from ...encounter_providers.resources.v_2.types.supervising_provider import SupervisingProvider
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_base import EncounterBase
from ...encounters.resources.v_4.types.epsdt_referral import EpsdtReferral
from ...encounters.resources.v_4.types.patient_history_category import PatientHistoryCategory
from ...encounters.resources.v_4.types.prior_authorization_number import PriorAuthorizationNumber
from ...encounters.resources.v_4.types.responsible_party_type import ResponsiblePartyType
from ...guarantor.resources.v_1.types.guarantor_create import GuarantorCreate
from ...individual.types.patient_create import PatientCreate
from ...individual.types.subscriber_create import SubscriberCreate
from ...property_and_casualty.resources.v_1.types.property_casualty_patient_identifier_create import (
    PropertyCasualtyPatientIdentifierCreate,
)
from ...related_causes.resources.v_1.types.related_causes_information_create import RelatedCausesInformationCreate
from ...service_facility.types.encounter_service_facility_base import EncounterServiceFacilityBase
from ...tags.types.tag_id import TagId


class UniversalEncounterCreateBase(EncounterBase):
    patient: PatientCreate = pydantic.Field()
    """
    Contains the identification information of the individual receiving medical services.
    """

    referring_provider: typing.Optional[ReferringProvider] = 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.
    """

    initial_referring_provider: typing.Optional[InitialReferringProvider] = 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
    """

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

    service_facility: typing.Optional[EncounterServiceFacilityBase] = 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
    """

    subscriber_primary: typing.Optional[SubscriberCreate] = pydantic.Field(default=None)
    """
    Subscriber_primary is required when responsible_party is INSURANCE_PAY (i.e. when the claim should be billed to insurance).
    These are not required fields when responsible_party is SELF_PAY (i.e. when the claim should be billed to the patient).
    However, if you collect this for patients, even self-pay, we recommend including it when sending encounters to Candid.
    Note: Cash Pay is no longer a valid payer_id in v4, please use responsible party to define self-pay claims.
    """

    subscriber_secondary: typing.Optional[SubscriberCreate] = pydantic.Field(default=None)
    """
    Please always include this when you have it, even for self-pay claims.
    """

    subscriber_tertiary: typing.Optional[SubscriberCreate] = pydantic.Field(default=None)
    """
    Please always include this when you have it, even for self-pay claims.
    """

    prior_authorization_number: typing.Optional[PriorAuthorizationNumber] = pydantic.Field(default=None)
    """
    Box 23 on the CMS-1500 claim form or Form Locator 63 on a UB-04 claim form.
    """

    responsible_party: ResponsiblePartyType = pydantic.Field()
    """
    Defines the party to be billed with the initial balance owed on the claim.
    """

    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.
    """

    billing_notes: typing.Optional[typing.List[BillingNoteBase]] = pydantic.Field(default=None)
    """
    Spot to store misc, human-readable, notes about this encounter to be used
    in the billing process.
    """

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

    external_claim_submission: typing.Optional[ExternalClaimSubmissionCreate] = pydantic.Field(default=None)
    """
    To be included for claims that have been submitted outside of Candid.
    Candid supports posting remits and payments to these claims and working them in-platform (e.g. editing, resubmitting).
    """

    tag_ids: typing.Optional[typing.List[TagId]] = pydantic.Field(default=None)
    """
    Names of tags that should be on the encounter.
    """

    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.
    """

    referral_number: typing.Optional[str] = pydantic.Field(default=None)
    """
    Refers to REF*9F on the 837p and 837i. Value cannot be greater than 50 characters.
    """

    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
    """

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

    secondary_payer_carrier_code: typing.Optional[str] = pydantic.Field(default=None)
    """
    When Medicaid is billed as the secondary payer the Carrier Code is used to identify the primary payer. This is required for certain states.
    """

    related_causes_information: typing.Optional[RelatedCausesInformationCreate] = 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[PropertyCasualtyPatientIdentifierCreate] = 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
