Skip to content

Appointment

appointment_dto

AppointmentDTO

Bases: BaseModel

Data Transfer Object for creating or updating an appointment.

Attributes:

Name Type Description
practitioner_reference str

Reference to the practitioner. Serialized as practitionerReference.

patient_reference str

Reference to the patient. Serialized as patientReference.

appointment_start_time datetime

Start time of the appointment. Serialized as start.

appointment_end_time datetime

End time of the appointment. Serialized as end.

priority Optional[AppointmentPriority]

Appointment priority (e.g., EMERGENCY). Serialized as priority.

organization_id Optional[str]

Organization identifier. Serialized as organizationId.

slot Optional[str]

Slot identifier. Serialized as slot.

appointment_reference Optional[str]

Unique appointment reference. Serialized as reference.

ResourceType

Bases: BaseModel

Represents the core resource structure for an appointment.

Attributes:

Name Type Description
appointment_reference str

Unique appointment reference. Serialized as reference.

practitioner_reference str

Reference to the practitioner. Serialized as practitionerReference.

patient_reference str

Reference to the patient. Serialized as patientReference.

slot str

Slot identifier. Serialized as slot.

priority str

Appointment priority. Serialized as priority.

appointment_start_time str

Start time of the appointment. Serialized as start.

appointment_end_time str

End time of the appointment. Serialized as end.

organization_id str

Organization identifier. Serialized as organizationId.

CreateAppointmentResponeType

Bases: BaseModel

Represents the response after creating an appointment.

Attributes:

Name Type Description
type str

Response type/status.

message str

Informational message about the operation.

validationErrors Optional[list[Any]]

List of validation errors, if any.

resource ResourceType

The created appointment resource.

fhirProfileId Optional[str]

FHIR profile identifier (excluded from serialization).

GetAppointmentResponse

Bases: BaseModel

Represents a paginated response for appointment queries.

Attributes:

Name Type Description
type str

Response type/status.

message str

Informational message about the operation.

request_resource Optional[list[ResourceType]]

List of appointment resources. Serialized as requestResource.

total_records Optional[int]

Total number of records. Serialized as totalNumberOfRecords.

next_page Optional[str]

Link or token for the next page. Serialized as nextPageLink.

AppointmentResponse

Bases: BaseModel

Represents the response for a single appointment query.

Attributes:

Name Type Description
type str

Response type/status.

message str

Informational message about the operation.

request_resource Optional[ResourceType]

The appointment resource. Serialized as requestResource.

total_records Optional[int]

Total number of records. Serialized as totalNumberOfRecords.

next_page Optional[str]

Link or token for the next page. Serialized as nextPageLink.

UpdateAppointmentDTO

Bases: BaseModel

Data Transfer Object for updating an appointment.

Attributes:

Name Type Description
appointment_start_time Optional[datetime]

Updated start time. Serialized as start.

appointment_end_time Optional[datetime]

Updated end time. Serialized as end.

priority Optional[AppointmentPriority]

Updated priority.

slot Optional[str]

Updated slot identifier. Serialized as slot.

Appointment

Appointment(config: ClientConfig)

Bases: BaseService

AppointmentService provides a high-level interface for managing appointments within the EHR system.

This service abstracts the underlying API calls, enabling SDK users to seamlessly create, retrieve, update, and delete appointments. It ensures consistent error handling, logging, and data validation, making it easier for developers to integrate appointment management into their applications.

Key Features

  • Validates input data using Pydantic models (AppointmentDTO, UpdateAppointmentDTO, etc.)
  • Handles all CRUD operations for appointment resources.
  • Supports advanced filtering and pagination.
  • Provides robust error handling and logging for all operations.

Methods:

Name Description
create

AppointmentDTO) -> CreateAppointmentResponeType Creates a new appointment in the EHR system.

find_all

Optional[str] = None) -> GetAppointmentResponse Retrieves a paginated list of all appointments.

find_by_id

str) -> AppointmentResponse Retrieves a specific appointment by its unique reference.

exists

str) -> bool Checks if an appointment with the given reference exists.

delete

str) -> None Deletes an appointment by its unique reference.

update

UpdateAppointmentDTO) -> AppointmentResponse Updates an existing appointment with new data.

Args:
config (ClientConfig): API credentials and settings for service initialization.

Raises:

Type Description
EhrApiError

For validation, API, or unexpected errors during operations.

Example Usage
config = ClientConfig(
    api_key="your_api_key"
)
service = AppointmentService(config)
new_appt = AppointmentDTO(
    practitioner_reference="Pract123",
    patient_reference="Pat456",
    appointment_start_time=datetime(2025, 8, 10, 14, 30),
    appointment_end_time=datetime(2025, 8, 10, 15, 0),
    priority=AppointmentPriority.ROUTINE,
    organization_id="Org789",
    slot="Slot12"
)
created = await service.create(new_appt)
all_appts = await service.find_all()

create async

create(appointment_data: AppointmentDTO) -> CreateAppointmentResponeType

Creates a new appointment in the EHR system.

Sends a request to create an appointment with the specified details.

Parameters:

Name Type Description Default
appointment_data AppointmentDTO

Pydantic model containing all necessary appointment data.

required
Returns:
CreateAppointmentResponeType: Contains:
    - type (str): Status/type of response (e.g., "success").
    - message (str): Informational message about creation.
    - validationErrors (Optional[list]): List of any validation errors.
    - resource (ResourceType): The created appointment details.

Raises:

Type Description
EhrApiError

If the API request fails or returns an error.

Example
appt_data = AppointmentDTO(
    practitioner_reference="Pract123",
    patient_reference="Pat456",
    appointment_start_time=datetime(2025, 8, 10, 14, 30),
    appointment_end_time=datetime(2025, 8, 10, 15, 0),
    priority=AppointmentPriority.ROUTINE,
 )
response = await service.create(appt_data)
print(response.message)
Appointment created successfully.
Response:
Sample Output:
{
    "type": "success",
    "message": "Appointment created successfully.",
    "validationErrors": None,
    "resource": {
        "reference": "APT-001234",
        "practitionerReference": "Pract123",
        "patientReference": "Pat456",
        "slot": "Slot12",
        "priority": "ROUTINE",
        "start": "2025-08-10T14:30:00Z",
        "end": "2025-08-10T15:00:00Z",
        "organizationId": "Org789"
    }
}

find_all async

find_all(next_page: Optional[str] = None) -> GetAppointmentResponse

Retrieves a paginated list of all appointments accessible to the current user or organization.

Supports pagination via the next_page token to retrieve large datasets efficiently.

Parameters:

Name Type Description Default
next_page Optional[str]

Token indicating the next page of results.

None
Returns:
GetAppointmentResponse: Contains:
    - type (str): Response status/type.
    - message (str): Informational message.
    - request_resource (Optional[list[ResourceType]]): List of appointments in this page.
    - total_records (Optional[int]): Total number of appointments available.
    - next_page (Optional[str]): Token/link for the next page.

Raises:

Type Description
EhrApiError

If the API request fails or an unexpected error occurs.

Example
response = await service.find_all()
print(f"Total appointments: {response.total_records}")
for appt in response.request_resource or []:
    print(appt.appointment_reference, appt.patient_reference)
Response:
Sample Output:
{
    "type": "success",
    "message": "Appointments fetched successfully",
    "requestResource": [
        {
            "reference": "APT-001234",
            "practitionerReference": "Pract123",
            "patientReference": "Pat456",
            "slot": "Slot12",
            "priority": "ROUTINE",
            "start": "2025-08-10T14:30:00Z",
            "end": "2025-08-10T15:00:00Z",
            "organizationId": "Org789"
        },
        {
            "reference": "APT-001235",
            "practitionerReference": "Pract124",
            "patientReference": "Pat457",
            "slot": "Slot13",
            "priority": "EMERGENCY",
            "start": "2025-08-11T10:00:00Z",
            "end": "2025-08-11T10:30:00Z",
            "organizationId": "Org789"
        }
        ...
    ],
    "totalNumberOfRecords": 50,
    "nextPageLink": "token12345"
}

find_by_id async

find_by_id(appointment_reference: str) -> AppointmentResponse

Retrieves a specific appointment by its unique reference.

Parameters:

Name Type Description Default
appointment_reference str

Unique identifier of the appointment.

required
Returns:
AppointmentResponse: Contains:
    - type (str): Response status/type.
    - message (str): Informational message.
    - request_resource (Optional[ResourceType]): Detailed appointment.
    - total_records (Optional[int]): Always 1 or 0 here.
    - next_page (Optional[str]): Usually None for single record.

Raises:

Type Description
EhrApiError

If the reference is invalid or API call fails.

Example
response = await service.find_by_id("APT-001234")
print(response.request_resource.patient_reference)
Response :
Sample Output:
{
    "type": "success",
    "message": "Appointment found.",
    "requestResource": {
        "reference": "APT-001234",
        "practitionerReference": "Pract123",
        "patientReference": "Pat456",
        "slot": "Slot12",
        "priority": "ROUTINE",
        "start": "2025-08-10T14:30:00Z",
        "end": "2025-08-10T15:00:00Z",
        "organizationId": "Org789"
    },
    "totalNumberOfRecords": 1,
    "nextPageLink": None
}

exists async

exists(appointment_reference: str) -> bool

Checks if an appointment with the given reference exists.

Parameters:

Name Type Description Default
appointment_reference str

Unique appointment reference.

required
Returns:
bool: True if the appointment exists, False otherwise.

Raises:

Type Description
EhrApiError

If the API call fails unexpectedly.

Example
exists = await service.exists("APT-001234")
print("Exists:", exists)
Example Explanation:
If the appointment exists, the API returns a message like "Appointment Found !!!".
This method interprets that message to return True.

delete async

delete(appointment_reference: str) -> None

Deletes an appointment by its unique reference.

This operation is irreversible and removes the appointment entirely.

Parameters:

Name Type Description Default
appointment_reference str

Unique identifier of the appointment to delete.

required

Raises:

Type Description
EhrApiError

If deletion fails due to invalid ID or server error.

Example
await service.delete("APT-001234")
Deletion completed successfully.

update async

update(request_body: UpdateAppointmentDTO) -> AppointmentResponse

Updates an existing appointment's details.

Only the fields present in the request body are updated.

Parameters:

Name Type Description Default
request_body UpdateAppointmentDTO

Fields to update.

required
Returns:
AppointmentResponse: Updated appointment data and status.

Raises:

Type Description
EhrApiError

If update fails due to validation or server errors.

Example
update_data = UpdateAppointmentDTO(slot="Slot15", priority=AppointmentPriority.ROUTINE)
response = await service.update(update_data)
print(response.message)
Response:
Sample Output:
{
    "type": "success",
    "message": "Appointment updated successfully.",
    "requestResource": {
        "reference": "APT-001234",
        "practitionerReference": "Pract123",
        "patientReference": "Pat456",
        "slot": "Slot15",
        "priority": "ROUTINE",
        "start": "2025-08-10T14:30:00Z",
        "end": "2025-08-10T15:00:00Z",
        "organizationId": "Org789"
    },
    "totalNumberOfRecords": 1,
    "nextPageLink": None
}