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

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from .errors.bad_request_error import BadRequestError
from .errors.failed_dependency_error import FailedDependencyError
from .errors.forbidden_error import ForbiddenError
from .errors.internal_server_error import InternalServerError
from .errors.unauthorized_error import UnauthorizedError
from .types.create_multi_response import CreateMultiResponse
from .types.create_request_resource import CreateRequestResource
from .types.document_request_file_type import DocumentRequestFileType
from .types.document_request_resource import DocumentRequestResource
from .types.fhir_resource import FhirResource
from .types.lang2fhir_upload_profile_response import Lang2FhirUploadProfileResponse
from .types.search_response import SearchResponse

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


class RawLang2FhirClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def create(
        self,
        *,
        version: str,
        resource: CreateRequestResource,
        text: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[FhirResource]:
        """
        Converts natural language text into a structured FHIR resource

        Parameters
        ----------
        version : str
            FHIR version to use

        resource : CreateRequestResource
            Type of FHIR resource to create. Use 'auto' for automatic resource type detection, or specify a supported US Core profile. Recommended to use the supported US Core Profiles for validated results but you can also use any custom profile you've uploaded (if you're a develop or launch customer)

        text : str
            Natural language text to convert

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

        Returns
        -------
        HttpResponse[FhirResource]
            Successfully created FHIR resource
        """
        _response = self._client_wrapper.httpx_client.request(
            "lang2fhir/create",
            method="POST",
            json={
                "version": version,
                "resource": resource,
                "text": text,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FhirResource,
                    parse_obj_as(
                        type_=FhirResource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create_multi(
        self,
        *,
        text: str,
        version: typing.Optional[str] = OMIT,
        provider: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[CreateMultiResponse]:
        """
        Analyzes natural language text and extracts multiple FHIR resources, returning them as a transaction Bundle.
        Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types from the text.
        Resources are linked with proper references (e.g., Conditions reference the Patient).

        Parameters
        ----------
        text : str
            Natural language text containing multiple clinical concepts to extract

        version : typing.Optional[str]
            FHIR version to use

        provider : typing.Optional[str]
            Optional FHIR provider name for provider-specific profiles

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

        Returns
        -------
        HttpResponse[CreateMultiResponse]
            Successfully extracted FHIR resources
        """
        _response = self._client_wrapper.httpx_client.request(
            "lang2fhir/create/multi",
            method="POST",
            json={
                "text": text,
                "version": version,
                "provider": provider,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CreateMultiResponse,
                    parse_obj_as(
                        type_=CreateMultiResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def search(
        self, *, text: str, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[SearchResponse]:
        """
        Converts natural language text into FHIR search parameters.
        Automatically identifies the appropriate FHIR resource type and generates valid search query parameters.

        Supported resource types include: AllergyIntolerance, Appointment, CarePlan, CareTeam, Condition,
        Coverage, Device, DiagnosticReport, DocumentReference, Encounter, Goal, Immunization, Location,
        Medication, MedicationRequest, Observation, Organization, Patient, PlanDefinition, Practitioner,
        PractitionerRole, Procedure, Provenance, Questionnaire, QuestionnaireResponse, RelatedPerson,
        Schedule, ServiceRequest, Slot, and Specimen.

        Parameters
        ----------
        text : str
            Natural language text to convert into FHIR search parameters.
            The system will automatically identify the appropriate resource type and generate valid search parameters.

            Examples:
            - "Appointments between March 2-9, 2025" → Appointment search with date range
            - "Patients with diabetes" → Condition search with code parameter
            - "Active medication requests for metformin" → MedicationRequest search
            - "Lab results for creatinine" → DiagnosticReport search
            - "Dr. Smith's schedule" → Practitioner or Schedule search

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

        Returns
        -------
        HttpResponse[SearchResponse]
            Successfully generated FHIR search parameters
        """
        _response = self._client_wrapper.httpx_client.request(
            "lang2fhir/search",
            method="POST",
            json={
                "text": text,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SearchResponse,
                    parse_obj_as(
                        type_=SearchResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 424:
                raise FailedDependencyError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def upload_profile(
        self, *, version: str, resource: str, profile: str, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[Lang2FhirUploadProfileResponse]:
        """
        Upload a custom FHIR StructureDefinition profile for use with the lang2fhir service

        Parameters
        ----------
        version : str
            FHIR version that this profile implements

        resource : str
            Name for the custom resource profile (will be converted to lowercase)

        profile : str
            Base64 encoded JSON string of the FHIR StructureDefinition profile

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

        Returns
        -------
        HttpResponse[Lang2FhirUploadProfileResponse]
            Profile successfully uploaded
        """
        _response = self._client_wrapper.httpx_client.request(
            "lang2fhir/profile/upload",
            method="POST",
            json={
                "version": version,
                "resource": resource,
                "profile": profile,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Lang2FhirUploadProfileResponse,
                    parse_obj_as(
                        type_=Lang2FhirUploadProfileResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def document(
        self,
        *,
        version: str,
        resource: DocumentRequestResource,
        content: str,
        file_type: DocumentRequestFileType,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[FhirResource]:
        """
        Extracts text from a document (PDF or image) and converts it into a structured FHIR resource

        Parameters
        ----------
        version : str
            FHIR version to use

        resource : DocumentRequestResource
            Type of FHIR resource to create (questionnaire and US Core questionnaireresponse profiles currently supported)

        content : str
            Base64 encoded file content

        file_type : DocumentRequestFileType
            MIME type of the file

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

        Returns
        -------
        HttpResponse[FhirResource]
            Successfully created FHIR resource from document
        """
        _response = self._client_wrapper.httpx_client.request(
            "lang2fhir/document",
            method="POST",
            json={
                "version": version,
                "resource": resource,
                "content": content,
                "fileType": file_type,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FhirResource,
                    parse_obj_as(
                        type_=FhirResource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawLang2FhirClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def create(
        self,
        *,
        version: str,
        resource: CreateRequestResource,
        text: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[FhirResource]:
        """
        Converts natural language text into a structured FHIR resource

        Parameters
        ----------
        version : str
            FHIR version to use

        resource : CreateRequestResource
            Type of FHIR resource to create. Use 'auto' for automatic resource type detection, or specify a supported US Core profile. Recommended to use the supported US Core Profiles for validated results but you can also use any custom profile you've uploaded (if you're a develop or launch customer)

        text : str
            Natural language text to convert

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

        Returns
        -------
        AsyncHttpResponse[FhirResource]
            Successfully created FHIR resource
        """
        _response = await self._client_wrapper.httpx_client.request(
            "lang2fhir/create",
            method="POST",
            json={
                "version": version,
                "resource": resource,
                "text": text,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FhirResource,
                    parse_obj_as(
                        type_=FhirResource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create_multi(
        self,
        *,
        text: str,
        version: typing.Optional[str] = OMIT,
        provider: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[CreateMultiResponse]:
        """
        Analyzes natural language text and extracts multiple FHIR resources, returning them as a transaction Bundle.
        Automatically detects Patient, Condition, MedicationRequest, Observation, and other resource types from the text.
        Resources are linked with proper references (e.g., Conditions reference the Patient).

        Parameters
        ----------
        text : str
            Natural language text containing multiple clinical concepts to extract

        version : typing.Optional[str]
            FHIR version to use

        provider : typing.Optional[str]
            Optional FHIR provider name for provider-specific profiles

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

        Returns
        -------
        AsyncHttpResponse[CreateMultiResponse]
            Successfully extracted FHIR resources
        """
        _response = await self._client_wrapper.httpx_client.request(
            "lang2fhir/create/multi",
            method="POST",
            json={
                "text": text,
                "version": version,
                "provider": provider,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CreateMultiResponse,
                    parse_obj_as(
                        type_=CreateMultiResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def search(
        self, *, text: str, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[SearchResponse]:
        """
        Converts natural language text into FHIR search parameters.
        Automatically identifies the appropriate FHIR resource type and generates valid search query parameters.

        Supported resource types include: AllergyIntolerance, Appointment, CarePlan, CareTeam, Condition,
        Coverage, Device, DiagnosticReport, DocumentReference, Encounter, Goal, Immunization, Location,
        Medication, MedicationRequest, Observation, Organization, Patient, PlanDefinition, Practitioner,
        PractitionerRole, Procedure, Provenance, Questionnaire, QuestionnaireResponse, RelatedPerson,
        Schedule, ServiceRequest, Slot, and Specimen.

        Parameters
        ----------
        text : str
            Natural language text to convert into FHIR search parameters.
            The system will automatically identify the appropriate resource type and generate valid search parameters.

            Examples:
            - "Appointments between March 2-9, 2025" → Appointment search with date range
            - "Patients with diabetes" → Condition search with code parameter
            - "Active medication requests for metformin" → MedicationRequest search
            - "Lab results for creatinine" → DiagnosticReport search
            - "Dr. Smith's schedule" → Practitioner or Schedule search

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

        Returns
        -------
        AsyncHttpResponse[SearchResponse]
            Successfully generated FHIR search parameters
        """
        _response = await self._client_wrapper.httpx_client.request(
            "lang2fhir/search",
            method="POST",
            json={
                "text": text,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    SearchResponse,
                    parse_obj_as(
                        type_=SearchResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 424:
                raise FailedDependencyError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def upload_profile(
        self, *, version: str, resource: str, profile: str, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[Lang2FhirUploadProfileResponse]:
        """
        Upload a custom FHIR StructureDefinition profile for use with the lang2fhir service

        Parameters
        ----------
        version : str
            FHIR version that this profile implements

        resource : str
            Name for the custom resource profile (will be converted to lowercase)

        profile : str
            Base64 encoded JSON string of the FHIR StructureDefinition profile

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

        Returns
        -------
        AsyncHttpResponse[Lang2FhirUploadProfileResponse]
            Profile successfully uploaded
        """
        _response = await self._client_wrapper.httpx_client.request(
            "lang2fhir/profile/upload",
            method="POST",
            json={
                "version": version,
                "resource": resource,
                "profile": profile,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Lang2FhirUploadProfileResponse,
                    parse_obj_as(
                        type_=Lang2FhirUploadProfileResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def document(
        self,
        *,
        version: str,
        resource: DocumentRequestResource,
        content: str,
        file_type: DocumentRequestFileType,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[FhirResource]:
        """
        Extracts text from a document (PDF or image) and converts it into a structured FHIR resource

        Parameters
        ----------
        version : str
            FHIR version to use

        resource : DocumentRequestResource
            Type of FHIR resource to create (questionnaire and US Core questionnaireresponse profiles currently supported)

        content : str
            Base64 encoded file content

        file_type : DocumentRequestFileType
            MIME type of the file

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

        Returns
        -------
        AsyncHttpResponse[FhirResource]
            Successfully created FHIR resource from document
        """
        _response = await self._client_wrapper.httpx_client.request(
            "lang2fhir/document",
            method="POST",
            json={
                "version": version,
                "resource": resource,
                "content": content,
                "fileType": file_type,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    FhirResource,
                    parse_obj_as(
                        type_=FhirResource,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
