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

import datetime as dt
import typing

from .....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .....core.request_options import RequestOptions
from ....claims.types.claim_status import ClaimStatus
from ....commons.types.encounter_external_id import EncounterExternalId
from ....commons.types.encounter_id import EncounterId
from ....commons.types.page_token import PageToken
from ....commons.types.work_queue_id import WorkQueueId
from ....encounters_universal.types.universal_encounter_create import UniversalEncounterCreate
from ....encounters_universal.types.universal_encounter_create_from_pre_encounter import (
    UniversalEncounterCreateFromPreEncounter,
)
from ....encounters_universal.types.universal_encounter_update import UniversalEncounterUpdate
from ....tags.types.tag_id import TagId
from .raw_client import AsyncRawV4Client, RawV4Client
from .types.billable_status_type import BillableStatusType
from .types.encounter import Encounter
from .types.encounter_create import EncounterCreate
from .types.encounter_create_from_pre_encounter import EncounterCreateFromPreEncounter
from .types.encounter_owner_of_next_action_type import EncounterOwnerOfNextActionType
from .types.encounter_page import EncounterPage
from .types.encounter_sort_options import EncounterSortOptions
from .types.encounter_update import EncounterUpdate
from .types.responsible_party_type import ResponsiblePartyType

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class V4Client:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawV4Client(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawV4Client:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawV4Client
        """
        return self._raw_client

    def get_all(
        self,
        *,
        limit: typing.Optional[int] = None,
        claim_status: typing.Optional[ClaimStatus] = None,
        sort: typing.Optional[EncounterSortOptions] = None,
        page_token: typing.Optional[PageToken] = None,
        date_of_service_min: typing.Optional[dt.date] = None,
        date_of_service_max: typing.Optional[dt.date] = None,
        primary_payer_names: typing.Optional[str] = None,
        search_term: typing.Optional[str] = None,
        external_id: typing.Optional[EncounterExternalId] = None,
        diagnoses_updated_since: typing.Optional[dt.datetime] = None,
        tag_ids: typing.Optional[typing.Union[TagId, typing.Sequence[TagId]]] = None,
        work_queue_id: typing.Optional[WorkQueueId] = None,
        billable_status: typing.Optional[BillableStatusType] = None,
        responsible_party: typing.Optional[ResponsiblePartyType] = None,
        owner_of_next_action: typing.Optional[EncounterOwnerOfNextActionType] = None,
        patient_external_id: typing.Optional[str] = None,
        include_merged_patient_data: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EncounterPage:
        """
        Parameters
        ----------
        limit : typing.Optional[int]
            Maximum number of entities per page, defaults to 100.

        claim_status : typing.Optional[ClaimStatus]
            Indicates the current status of an insurance claim within the billing process.

        sort : typing.Optional[EncounterSortOptions]
            Defaults to created_at:desc.

        page_token : typing.Optional[PageToken]

        date_of_service_min : typing.Optional[dt.date]
            Date formatted as YYYY-MM-DD; eg: 2019-08-25.

        date_of_service_max : typing.Optional[dt.date]
            Date formatted as YYYY-MM-DD; eg: 2019-08-25.

        primary_payer_names : typing.Optional[str]
            Comma delimited string.

        search_term : typing.Optional[str]
            Filter by any of the following fields: encounter_id, claim_id, patient external_id,
            patient date of birth, patient first name, patient last name,
            or encounter external id.

        external_id : typing.Optional[EncounterExternalId]
            Filter to an exact match on encounter external_id, if one exists.

        diagnoses_updated_since : typing.Optional[dt.datetime]
            ISO 8601 timestamp; ideally in UTC (although not required): 2019-08-24T14:15:22Z.

        tag_ids : typing.Optional[typing.Union[TagId, typing.Sequence[TagId]]]
            Filter by name of tags on encounters.

        work_queue_id : typing.Optional[WorkQueueId]

        billable_status : typing.Optional[BillableStatusType]
            Defines if the Encounter is to be billed by Candid to the responsible_party. Examples for when this should be set to NOT_BILLABLE include if the Encounter has not occurred yet or if there is no intention of ever billing the responsible_party.

        responsible_party : typing.Optional[ResponsiblePartyType]
            Defines the party to be billed with the initial balance owed on the claim. Use SELF_PAY if you intend to bill self pay/cash pay.

        owner_of_next_action : typing.Optional[EncounterOwnerOfNextActionType]
            The party who is responsible for taking the next action on an Encounter, as defined by ownership of open Tasks.

        patient_external_id : typing.Optional[str]
            The patient ID from the external EMR platform for the patient

        include_merged_patient_data : typing.Optional[bool]
            If true and patient_external_id is set, then also include the encounters of all alternative patients.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EncounterPage

        Examples
        --------
        import datetime

        from candid import CandidApiClient
        from candid.resources.claims import ClaimStatus
        from candid.resources.encounters.resources.v_4 import EncounterSortOptions

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.encounters.v_4.get_all(
            limit=100,
            claim_status=ClaimStatus.BILLER_RECEIVED,
            sort=EncounterSortOptions.CREATED_AT_ASC,
            page_token="eyJ0b2tlbiI6IjEiLCJwYWdlX3Rva2VuIjoiMiJ9",
            date_of_service_min=datetime.date.fromisoformat(
                "2019-08-24",
            ),
            date_of_service_max=datetime.date.fromisoformat(
                "2019-08-25",
            ),
            primary_payer_names="Medicare,Medicaid",
            search_term="doe",
            external_id="123456",
            diagnoses_updated_since=datetime.datetime.fromisoformat(
                "2019-08-24 14:15:22+00:00",
            ),
        )
        """
        _response = self._raw_client.get_all(
            limit=limit,
            claim_status=claim_status,
            sort=sort,
            page_token=page_token,
            date_of_service_min=date_of_service_min,
            date_of_service_max=date_of_service_max,
            primary_payer_names=primary_payer_names,
            search_term=search_term,
            external_id=external_id,
            diagnoses_updated_since=diagnoses_updated_since,
            tag_ids=tag_ids,
            work_queue_id=work_queue_id,
            billable_status=billable_status,
            responsible_party=responsible_party,
            owner_of_next_action=owner_of_next_action,
            patient_external_id=patient_external_id,
            include_merged_patient_data=include_merged_patient_data,
            request_options=request_options,
        )
        return _response.data

    def get(self, encounter_id: EncounterId, *, request_options: typing.Optional[RequestOptions] = None) -> Encounter:
        """
        Parameters
        ----------
        encounter_id : EncounterId

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import uuid

        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.encounters.v_4.get(
            encounter_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._raw_client.get(encounter_id, request_options=request_options)
        return _response.data

    def create_universal(
        self, *, request: UniversalEncounterCreate, request_options: typing.Optional[RequestOptions] = None
    ) -> Encounter:
        """
        Notice: The UB-04 Data File, 2025, is copyrighted by American Hospital Association (AHA), Chicago, Illinois.
        No portion of the THE UB-04 Data File, may be reproduced, stored in a retrieval system, or transmitted,
        in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior
        express, written consent of AHA.

        Parameters
        ----------
        request : UniversalEncounterCreate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import datetime

        from candid import CandidApiClient
        from candid.resources.commons import (
            State,
            StreetAddressLongZip,
            StreetAddressShortZip,
        )
        from candid.resources.encounter_providers.resources.v_2 import BillingProvider
        from candid.resources.encounters.resources.v_4 import (
            BillableStatusType,
            EncounterSubmissionExpectation,
            ResponsiblePartyType,
        )
        from candid.resources.encounters_universal import UniversalEncounterCreate
        from candid.resources.individual import Gender, PatientCreate

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.encounters.v_4.create_universal(
            request=UniversalEncounterCreate(
                billing_provider=BillingProvider(
                    address=StreetAddressLongZip(
                        zip_plus_four_code="zip_plus_four_code",
                        address_1="address1",
                        city="city",
                        state=State.AA,
                        zip_code="zip_code",
                    ),
                    tax_id="tax_id",
                    npi="npi",
                ),
                submission_expectation=EncounterSubmissionExpectation.TARGET_PROFESSIONAL,
                patient=PatientCreate(
                    external_id="external_id",
                    date_of_birth=datetime.date.fromisoformat(
                        "2023-01-15",
                    ),
                    address=StreetAddressShortZip(
                        address_1="address1",
                        city="city",
                        state=State.AA,
                        zip_code="zip_code",
                    ),
                    first_name="first_name",
                    last_name="last_name",
                    gender=Gender.MALE,
                ),
                responsible_party=ResponsiblePartyType.INSURANCE_PAY,
                external_id="external_id",
                patient_authorized_release=True,
                benefits_assigned_to_provider=True,
                provider_accepts_assignment=True,
                billable_status=BillableStatusType.BILLABLE,
            ),
        )
        """
        _response = self._raw_client.create_universal(request=request, request_options=request_options)
        return _response.data

    def create(self, *, request: EncounterCreate, request_options: typing.Optional[RequestOptions] = None) -> Encounter:
        """
        Parameters
        ----------
        request : EncounterCreate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import datetime

        from candid import CandidApiClient
        from candid.resources.commons import (
            FacilityTypeCode,
            State,
            StreetAddressLongZip,
            StreetAddressShortZip,
        )
        from candid.resources.diagnoses import DiagnosisCreate, DiagnosisTypeCode
        from candid.resources.encounter_providers.resources.v_2 import (
            BillingProvider,
            RenderingProvider,
        )
        from candid.resources.encounters.resources.v_4 import (
            BillableStatusType,
            EncounterCreate,
            ResponsiblePartyType,
        )
        from candid.resources.individual import Gender, PatientCreate

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.encounters.v_4.create(
            request=EncounterCreate(
                billing_provider=BillingProvider(
                    address=StreetAddressLongZip(
                        zip_plus_four_code="zip_plus_four_code",
                        address_1="address1",
                        city="city",
                        state=State.AA,
                        zip_code="zip_code",
                    ),
                    tax_id="tax_id",
                    npi="npi",
                ),
                diagnoses=[
                    DiagnosisCreate(
                        code_type=DiagnosisTypeCode.ABF,
                        code="code",
                    ),
                    DiagnosisCreate(
                        code_type=DiagnosisTypeCode.ABF,
                        code="code",
                    ),
                ],
                place_of_service_code=FacilityTypeCode.PHARMACY,
                rendering_provider=RenderingProvider(
                    npi="npi",
                ),
                patient=PatientCreate(
                    external_id="external_id",
                    date_of_birth=datetime.date.fromisoformat(
                        "2023-01-15",
                    ),
                    address=StreetAddressShortZip(
                        address_1="address1",
                        city="city",
                        state=State.AA,
                        zip_code="zip_code",
                    ),
                    first_name="first_name",
                    last_name="last_name",
                    gender=Gender.MALE,
                ),
                responsible_party=ResponsiblePartyType.INSURANCE_PAY,
                external_id="external_id",
                patient_authorized_release=True,
                benefits_assigned_to_provider=True,
                provider_accepts_assignment=True,
                billable_status=BillableStatusType.BILLABLE,
            ),
        )
        """
        _response = self._raw_client.create(request=request, request_options=request_options)
        return _response.data

    def create_from_pre_encounter_patient_universal(
        self,
        *,
        request: UniversalEncounterCreateFromPreEncounter,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Encounter:
        """
        Create an encounter from a pre-encounter patient and appointment. This endpoint is intended to be used by consumers who are managing
        patients and appointments in the pre-encounter service and is currently under development. Consumers who are not taking advantage
        of the pre-encounter service should use the standard create endpoint.

        The endpoint will create an encounter from the provided fields, pulling information from the provided patient and appointment objects
        where applicable. In particular, the following fields are populated from the patient and appointment objects:
          - Patient
          - Referring Provider
          - Subscriber Primary
          - Subscriber Secondary
          - Referral Number
          - Responsible Party
          - Guarantor

        Utilizing this endpoint opts you into automatic updating of the encounter when the patient or appointment is updated, assuming the
        encounter has not already been submitted or adjudicated.

        Notice: The UB-04 Data File, 2025, is copyrighted by American Hospital Association (AHA), Chicago, Illinois.
        No portion of the THE UB-04 Data File, may be reproduced, stored in a retrieval system, or transmitted,
        in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior
        express, written consent of AHA.

        Parameters
        ----------
        request : UniversalEncounterCreateFromPreEncounter

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import uuid

        from candid import CandidApiClient
        from candid.resources.commons import State, StreetAddressLongZip
        from candid.resources.encounter_providers.resources.v_2 import BillingProvider
        from candid.resources.encounters.resources.v_4 import (
            BillableStatusType,
            EncounterSubmissionExpectation,
        )
        from candid.resources.encounters_universal import (
            UniversalEncounterCreateFromPreEncounter,
        )

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.encounters.v_4.create_from_pre_encounter_patient_universal(
            request=UniversalEncounterCreateFromPreEncounter(
                submission_expectation=EncounterSubmissionExpectation.TARGET_PROFESSIONAL,
                pre_encounter_patient_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                pre_encounter_appointment_ids=[
                    uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    ),
                    uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    ),
                ],
                billing_provider=BillingProvider(
                    address=StreetAddressLongZip(
                        zip_plus_four_code="zip_plus_four_code",
                        address_1="address1",
                        city="city",
                        state=State.AA,
                        zip_code="zip_code",
                    ),
                    tax_id="tax_id",
                    npi="npi",
                ),
                external_id="external_id",
                patient_authorized_release=True,
                benefits_assigned_to_provider=True,
                provider_accepts_assignment=True,
                billable_status=BillableStatusType.BILLABLE,
            ),
        )
        """
        _response = self._raw_client.create_from_pre_encounter_patient_universal(
            request=request, request_options=request_options
        )
        return _response.data

    def create_from_pre_encounter_patient(
        self, *, request: EncounterCreateFromPreEncounter, request_options: typing.Optional[RequestOptions] = None
    ) -> Encounter:
        """
        Create an encounter from a pre-encounter patient and appointment. This endpoint is intended to be used by consumers who are managing
        patients and appointments in the pre-encounter service and is currently under development. Consumers who are not taking advantage
        of the pre-encounter service should use the standard create endpoint.

        The endpoint will create an encounter from the provided fields, pulling information from the provided patient and appointment objects
        where applicable. In particular, the following fields are populated from the patient and appointment objects:
          - Patient
          - Referring Provider
          - Subscriber Primary
          - Subscriber Secondary
          - Referral Number
          - Responsible Party
          - Guarantor

        Utilizing this endpoint opts you into automatic updating of the encounter when the patient or appointment is updated, assuming the
        encounter has not already been submitted or adjudicated.

        Parameters
        ----------
        request : EncounterCreateFromPreEncounter

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import uuid

        from candid import CandidApiClient
        from candid.resources.commons import (
            FacilityTypeCode,
            State,
            StreetAddressLongZip,
        )
        from candid.resources.diagnoses import DiagnosisCreate, DiagnosisTypeCode
        from candid.resources.encounter_providers.resources.v_2 import (
            BillingProvider,
            RenderingProvider,
        )
        from candid.resources.encounters.resources.v_4 import (
            BillableStatusType,
            EncounterCreateFromPreEncounter,
        )

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.encounters.v_4.create_from_pre_encounter_patient(
            request=EncounterCreateFromPreEncounter(
                rendering_provider=RenderingProvider(
                    npi="npi",
                ),
                place_of_service_code=FacilityTypeCode.PHARMACY,
                diagnoses=[
                    DiagnosisCreate(
                        code_type=DiagnosisTypeCode.ABF,
                        code="code",
                    ),
                    DiagnosisCreate(
                        code_type=DiagnosisTypeCode.ABF,
                        code="code",
                    ),
                ],
                pre_encounter_patient_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                pre_encounter_appointment_ids=[
                    uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    ),
                    uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    ),
                ],
                billing_provider=BillingProvider(
                    address=StreetAddressLongZip(
                        zip_plus_four_code="zip_plus_four_code",
                        address_1="address1",
                        city="city",
                        state=State.AA,
                        zip_code="zip_code",
                    ),
                    tax_id="tax_id",
                    npi="npi",
                ),
                external_id="external_id",
                patient_authorized_release=True,
                benefits_assigned_to_provider=True,
                provider_accepts_assignment=True,
                billable_status=BillableStatusType.BILLABLE,
            ),
        )
        """
        _response = self._raw_client.create_from_pre_encounter_patient(request=request, request_options=request_options)
        return _response.data

    def update_universal(
        self,
        encounter_id: EncounterId,
        *,
        request: UniversalEncounterUpdate,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Encounter:
        """
        Notice: The UB-04 Data File, 2025, is copyrighted by American Hospital Association (AHA), Chicago, Illinois.
        No portion of the THE UB-04 Data File, may be reproduced, stored in a retrieval system, or transmitted,
        in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior
        express, written consent of AHA.

        Parameters
        ----------
        encounter_id : EncounterId

        request : UniversalEncounterUpdate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import uuid

        from candid import CandidApiClient
        from candid.resources.encounters_universal import UniversalEncounterUpdate

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.encounters.v_4.update_universal(
            encounter_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
            request=UniversalEncounterUpdate(),
        )
        """
        _response = self._raw_client.update_universal(encounter_id, request=request, request_options=request_options)
        return _response.data

    def update(
        self,
        encounter_id: EncounterId,
        *,
        request: EncounterUpdate,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Encounter:
        """
        Parameters
        ----------
        encounter_id : EncounterId

        request : EncounterUpdate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import uuid

        from candid import CandidApiClient
        from candid.resources.encounters.resources.v_4 import EncounterUpdate

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.encounters.v_4.update(
            encounter_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
            request=EncounterUpdate(),
        )
        """
        _response = self._raw_client.update(encounter_id, request=request, request_options=request_options)
        return _response.data


class AsyncV4Client:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawV4Client(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawV4Client:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawV4Client
        """
        return self._raw_client

    async def get_all(
        self,
        *,
        limit: typing.Optional[int] = None,
        claim_status: typing.Optional[ClaimStatus] = None,
        sort: typing.Optional[EncounterSortOptions] = None,
        page_token: typing.Optional[PageToken] = None,
        date_of_service_min: typing.Optional[dt.date] = None,
        date_of_service_max: typing.Optional[dt.date] = None,
        primary_payer_names: typing.Optional[str] = None,
        search_term: typing.Optional[str] = None,
        external_id: typing.Optional[EncounterExternalId] = None,
        diagnoses_updated_since: typing.Optional[dt.datetime] = None,
        tag_ids: typing.Optional[typing.Union[TagId, typing.Sequence[TagId]]] = None,
        work_queue_id: typing.Optional[WorkQueueId] = None,
        billable_status: typing.Optional[BillableStatusType] = None,
        responsible_party: typing.Optional[ResponsiblePartyType] = None,
        owner_of_next_action: typing.Optional[EncounterOwnerOfNextActionType] = None,
        patient_external_id: typing.Optional[str] = None,
        include_merged_patient_data: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EncounterPage:
        """
        Parameters
        ----------
        limit : typing.Optional[int]
            Maximum number of entities per page, defaults to 100.

        claim_status : typing.Optional[ClaimStatus]
            Indicates the current status of an insurance claim within the billing process.

        sort : typing.Optional[EncounterSortOptions]
            Defaults to created_at:desc.

        page_token : typing.Optional[PageToken]

        date_of_service_min : typing.Optional[dt.date]
            Date formatted as YYYY-MM-DD; eg: 2019-08-25.

        date_of_service_max : typing.Optional[dt.date]
            Date formatted as YYYY-MM-DD; eg: 2019-08-25.

        primary_payer_names : typing.Optional[str]
            Comma delimited string.

        search_term : typing.Optional[str]
            Filter by any of the following fields: encounter_id, claim_id, patient external_id,
            patient date of birth, patient first name, patient last name,
            or encounter external id.

        external_id : typing.Optional[EncounterExternalId]
            Filter to an exact match on encounter external_id, if one exists.

        diagnoses_updated_since : typing.Optional[dt.datetime]
            ISO 8601 timestamp; ideally in UTC (although not required): 2019-08-24T14:15:22Z.

        tag_ids : typing.Optional[typing.Union[TagId, typing.Sequence[TagId]]]
            Filter by name of tags on encounters.

        work_queue_id : typing.Optional[WorkQueueId]

        billable_status : typing.Optional[BillableStatusType]
            Defines if the Encounter is to be billed by Candid to the responsible_party. Examples for when this should be set to NOT_BILLABLE include if the Encounter has not occurred yet or if there is no intention of ever billing the responsible_party.

        responsible_party : typing.Optional[ResponsiblePartyType]
            Defines the party to be billed with the initial balance owed on the claim. Use SELF_PAY if you intend to bill self pay/cash pay.

        owner_of_next_action : typing.Optional[EncounterOwnerOfNextActionType]
            The party who is responsible for taking the next action on an Encounter, as defined by ownership of open Tasks.

        patient_external_id : typing.Optional[str]
            The patient ID from the external EMR platform for the patient

        include_merged_patient_data : typing.Optional[bool]
            If true and patient_external_id is set, then also include the encounters of all alternative patients.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EncounterPage

        Examples
        --------
        import asyncio
        import datetime

        from candid import AsyncCandidApiClient
        from candid.resources.claims import ClaimStatus
        from candid.resources.encounters.resources.v_4 import EncounterSortOptions

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.encounters.v_4.get_all(
                limit=100,
                claim_status=ClaimStatus.BILLER_RECEIVED,
                sort=EncounterSortOptions.CREATED_AT_ASC,
                page_token="eyJ0b2tlbiI6IjEiLCJwYWdlX3Rva2VuIjoiMiJ9",
                date_of_service_min=datetime.date.fromisoformat(
                    "2019-08-24",
                ),
                date_of_service_max=datetime.date.fromisoformat(
                    "2019-08-25",
                ),
                primary_payer_names="Medicare,Medicaid",
                search_term="doe",
                external_id="123456",
                diagnoses_updated_since=datetime.datetime.fromisoformat(
                    "2019-08-24 14:15:22+00:00",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_all(
            limit=limit,
            claim_status=claim_status,
            sort=sort,
            page_token=page_token,
            date_of_service_min=date_of_service_min,
            date_of_service_max=date_of_service_max,
            primary_payer_names=primary_payer_names,
            search_term=search_term,
            external_id=external_id,
            diagnoses_updated_since=diagnoses_updated_since,
            tag_ids=tag_ids,
            work_queue_id=work_queue_id,
            billable_status=billable_status,
            responsible_party=responsible_party,
            owner_of_next_action=owner_of_next_action,
            patient_external_id=patient_external_id,
            include_merged_patient_data=include_merged_patient_data,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self, encounter_id: EncounterId, *, request_options: typing.Optional[RequestOptions] = None
    ) -> Encounter:
        """
        Parameters
        ----------
        encounter_id : EncounterId

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import asyncio
        import uuid

        from candid import AsyncCandidApiClient

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.encounters.v_4.get(
                encounter_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(encounter_id, request_options=request_options)
        return _response.data

    async def create_universal(
        self, *, request: UniversalEncounterCreate, request_options: typing.Optional[RequestOptions] = None
    ) -> Encounter:
        """
        Notice: The UB-04 Data File, 2025, is copyrighted by American Hospital Association (AHA), Chicago, Illinois.
        No portion of the THE UB-04 Data File, may be reproduced, stored in a retrieval system, or transmitted,
        in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior
        express, written consent of AHA.

        Parameters
        ----------
        request : UniversalEncounterCreate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import asyncio
        import datetime

        from candid import AsyncCandidApiClient
        from candid.resources.commons import (
            State,
            StreetAddressLongZip,
            StreetAddressShortZip,
        )
        from candid.resources.encounter_providers.resources.v_2 import BillingProvider
        from candid.resources.encounters.resources.v_4 import (
            BillableStatusType,
            EncounterSubmissionExpectation,
            ResponsiblePartyType,
        )
        from candid.resources.encounters_universal import UniversalEncounterCreate
        from candid.resources.individual import Gender, PatientCreate

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.encounters.v_4.create_universal(
                request=UniversalEncounterCreate(
                    billing_provider=BillingProvider(
                        address=StreetAddressLongZip(
                            zip_plus_four_code="zip_plus_four_code",
                            address_1="address1",
                            city="city",
                            state=State.AA,
                            zip_code="zip_code",
                        ),
                        tax_id="tax_id",
                        npi="npi",
                    ),
                    submission_expectation=EncounterSubmissionExpectation.TARGET_PROFESSIONAL,
                    patient=PatientCreate(
                        external_id="external_id",
                        date_of_birth=datetime.date.fromisoformat(
                            "2023-01-15",
                        ),
                        address=StreetAddressShortZip(
                            address_1="address1",
                            city="city",
                            state=State.AA,
                            zip_code="zip_code",
                        ),
                        first_name="first_name",
                        last_name="last_name",
                        gender=Gender.MALE,
                    ),
                    responsible_party=ResponsiblePartyType.INSURANCE_PAY,
                    external_id="external_id",
                    patient_authorized_release=True,
                    benefits_assigned_to_provider=True,
                    provider_accepts_assignment=True,
                    billable_status=BillableStatusType.BILLABLE,
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_universal(request=request, request_options=request_options)
        return _response.data

    async def create(
        self, *, request: EncounterCreate, request_options: typing.Optional[RequestOptions] = None
    ) -> Encounter:
        """
        Parameters
        ----------
        request : EncounterCreate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import asyncio
        import datetime

        from candid import AsyncCandidApiClient
        from candid.resources.commons import (
            FacilityTypeCode,
            State,
            StreetAddressLongZip,
            StreetAddressShortZip,
        )
        from candid.resources.diagnoses import DiagnosisCreate, DiagnosisTypeCode
        from candid.resources.encounter_providers.resources.v_2 import (
            BillingProvider,
            RenderingProvider,
        )
        from candid.resources.encounters.resources.v_4 import (
            BillableStatusType,
            EncounterCreate,
            ResponsiblePartyType,
        )
        from candid.resources.individual import Gender, PatientCreate

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.encounters.v_4.create(
                request=EncounterCreate(
                    billing_provider=BillingProvider(
                        address=StreetAddressLongZip(
                            zip_plus_four_code="zip_plus_four_code",
                            address_1="address1",
                            city="city",
                            state=State.AA,
                            zip_code="zip_code",
                        ),
                        tax_id="tax_id",
                        npi="npi",
                    ),
                    diagnoses=[
                        DiagnosisCreate(
                            code_type=DiagnosisTypeCode.ABF,
                            code="code",
                        ),
                        DiagnosisCreate(
                            code_type=DiagnosisTypeCode.ABF,
                            code="code",
                        ),
                    ],
                    place_of_service_code=FacilityTypeCode.PHARMACY,
                    rendering_provider=RenderingProvider(
                        npi="npi",
                    ),
                    patient=PatientCreate(
                        external_id="external_id",
                        date_of_birth=datetime.date.fromisoformat(
                            "2023-01-15",
                        ),
                        address=StreetAddressShortZip(
                            address_1="address1",
                            city="city",
                            state=State.AA,
                            zip_code="zip_code",
                        ),
                        first_name="first_name",
                        last_name="last_name",
                        gender=Gender.MALE,
                    ),
                    responsible_party=ResponsiblePartyType.INSURANCE_PAY,
                    external_id="external_id",
                    patient_authorized_release=True,
                    benefits_assigned_to_provider=True,
                    provider_accepts_assignment=True,
                    billable_status=BillableStatusType.BILLABLE,
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(request=request, request_options=request_options)
        return _response.data

    async def create_from_pre_encounter_patient_universal(
        self,
        *,
        request: UniversalEncounterCreateFromPreEncounter,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Encounter:
        """
        Create an encounter from a pre-encounter patient and appointment. This endpoint is intended to be used by consumers who are managing
        patients and appointments in the pre-encounter service and is currently under development. Consumers who are not taking advantage
        of the pre-encounter service should use the standard create endpoint.

        The endpoint will create an encounter from the provided fields, pulling information from the provided patient and appointment objects
        where applicable. In particular, the following fields are populated from the patient and appointment objects:
          - Patient
          - Referring Provider
          - Subscriber Primary
          - Subscriber Secondary
          - Referral Number
          - Responsible Party
          - Guarantor

        Utilizing this endpoint opts you into automatic updating of the encounter when the patient or appointment is updated, assuming the
        encounter has not already been submitted or adjudicated.

        Notice: The UB-04 Data File, 2025, is copyrighted by American Hospital Association (AHA), Chicago, Illinois.
        No portion of the THE UB-04 Data File, may be reproduced, stored in a retrieval system, or transmitted,
        in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior
        express, written consent of AHA.

        Parameters
        ----------
        request : UniversalEncounterCreateFromPreEncounter

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import asyncio
        import uuid

        from candid import AsyncCandidApiClient
        from candid.resources.commons import State, StreetAddressLongZip
        from candid.resources.encounter_providers.resources.v_2 import BillingProvider
        from candid.resources.encounters.resources.v_4 import (
            BillableStatusType,
            EncounterSubmissionExpectation,
        )
        from candid.resources.encounters_universal import (
            UniversalEncounterCreateFromPreEncounter,
        )

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.encounters.v_4.create_from_pre_encounter_patient_universal(
                request=UniversalEncounterCreateFromPreEncounter(
                    submission_expectation=EncounterSubmissionExpectation.TARGET_PROFESSIONAL,
                    pre_encounter_patient_id=uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    ),
                    pre_encounter_appointment_ids=[
                        uuid.UUID(
                            "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                        ),
                        uuid.UUID(
                            "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                        ),
                    ],
                    billing_provider=BillingProvider(
                        address=StreetAddressLongZip(
                            zip_plus_four_code="zip_plus_four_code",
                            address_1="address1",
                            city="city",
                            state=State.AA,
                            zip_code="zip_code",
                        ),
                        tax_id="tax_id",
                        npi="npi",
                    ),
                    external_id="external_id",
                    patient_authorized_release=True,
                    benefits_assigned_to_provider=True,
                    provider_accepts_assignment=True,
                    billable_status=BillableStatusType.BILLABLE,
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_from_pre_encounter_patient_universal(
            request=request, request_options=request_options
        )
        return _response.data

    async def create_from_pre_encounter_patient(
        self, *, request: EncounterCreateFromPreEncounter, request_options: typing.Optional[RequestOptions] = None
    ) -> Encounter:
        """
        Create an encounter from a pre-encounter patient and appointment. This endpoint is intended to be used by consumers who are managing
        patients and appointments in the pre-encounter service and is currently under development. Consumers who are not taking advantage
        of the pre-encounter service should use the standard create endpoint.

        The endpoint will create an encounter from the provided fields, pulling information from the provided patient and appointment objects
        where applicable. In particular, the following fields are populated from the patient and appointment objects:
          - Patient
          - Referring Provider
          - Subscriber Primary
          - Subscriber Secondary
          - Referral Number
          - Responsible Party
          - Guarantor

        Utilizing this endpoint opts you into automatic updating of the encounter when the patient or appointment is updated, assuming the
        encounter has not already been submitted or adjudicated.

        Parameters
        ----------
        request : EncounterCreateFromPreEncounter

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import asyncio
        import uuid

        from candid import AsyncCandidApiClient
        from candid.resources.commons import (
            FacilityTypeCode,
            State,
            StreetAddressLongZip,
        )
        from candid.resources.diagnoses import DiagnosisCreate, DiagnosisTypeCode
        from candid.resources.encounter_providers.resources.v_2 import (
            BillingProvider,
            RenderingProvider,
        )
        from candid.resources.encounters.resources.v_4 import (
            BillableStatusType,
            EncounterCreateFromPreEncounter,
        )

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.encounters.v_4.create_from_pre_encounter_patient(
                request=EncounterCreateFromPreEncounter(
                    rendering_provider=RenderingProvider(
                        npi="npi",
                    ),
                    place_of_service_code=FacilityTypeCode.PHARMACY,
                    diagnoses=[
                        DiagnosisCreate(
                            code_type=DiagnosisTypeCode.ABF,
                            code="code",
                        ),
                        DiagnosisCreate(
                            code_type=DiagnosisTypeCode.ABF,
                            code="code",
                        ),
                    ],
                    pre_encounter_patient_id=uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    ),
                    pre_encounter_appointment_ids=[
                        uuid.UUID(
                            "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                        ),
                        uuid.UUID(
                            "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                        ),
                    ],
                    billing_provider=BillingProvider(
                        address=StreetAddressLongZip(
                            zip_plus_four_code="zip_plus_four_code",
                            address_1="address1",
                            city="city",
                            state=State.AA,
                            zip_code="zip_code",
                        ),
                        tax_id="tax_id",
                        npi="npi",
                    ),
                    external_id="external_id",
                    patient_authorized_release=True,
                    benefits_assigned_to_provider=True,
                    provider_accepts_assignment=True,
                    billable_status=BillableStatusType.BILLABLE,
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_from_pre_encounter_patient(
            request=request, request_options=request_options
        )
        return _response.data

    async def update_universal(
        self,
        encounter_id: EncounterId,
        *,
        request: UniversalEncounterUpdate,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Encounter:
        """
        Notice: The UB-04 Data File, 2025, is copyrighted by American Hospital Association (AHA), Chicago, Illinois.
        No portion of the THE UB-04 Data File, may be reproduced, stored in a retrieval system, or transmitted,
        in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior
        express, written consent of AHA.

        Parameters
        ----------
        encounter_id : EncounterId

        request : UniversalEncounterUpdate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import asyncio
        import uuid

        from candid import AsyncCandidApiClient
        from candid.resources.encounters_universal import UniversalEncounterUpdate

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.encounters.v_4.update_universal(
                encounter_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                request=UniversalEncounterUpdate(),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_universal(
            encounter_id, request=request, request_options=request_options
        )
        return _response.data

    async def update(
        self,
        encounter_id: EncounterId,
        *,
        request: EncounterUpdate,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Encounter:
        """
        Parameters
        ----------
        encounter_id : EncounterId

        request : EncounterUpdate

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Encounter

        Examples
        --------
        import asyncio
        import uuid

        from candid import AsyncCandidApiClient
        from candid.resources.encounters.resources.v_4 import EncounterUpdate

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.encounters.v_4.update(
                encounter_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                request=EncounterUpdate(),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(encounter_id, request=request, request_options=request_options)
        return _response.data
