Calendar

Introduction #

The Calendar model represents a Calendar in Canvas. Calendars are used to organize events for providers and can be either Clinic or Administrative type.

Basic usage #

To get a calendar by identifier, use the get method on the Calendar model manager:

from canvas_sdk.v1.data.calendar import Calendar

calendar = Calendar.objects.get(id="f53626e4-0683-43ac-a1b7-c52815639ce2")

Events #

The events associated with a calendar can be accessed with the events attribute on a Calendar object:

from canvas_sdk.v1.data.calendar import Calendar

calendar = Calendar.objects.get(id="f53626e4-0683-43ac-a1b7-c52815639ce2")
events = calendar.events.all()

To get a specific event by identifier:

from canvas_sdk.v1.data.calendar import Event

event = Event.objects.get(id="a1b2c3d4-5678-90ab-cdef-1234567890ab")

Filtering #

Calendars and events can be filtered by any attribute that exists on the model.

Filtering is done with the filter method on the model manager.

By attribute #

Specify an attribute with filter to filter by that attribute:

from canvas_sdk.v1.data.calendar import Calendar

# Filter calendars by title
calendars = Calendar.objects.filter(title__icontains="Clinic")

By calendar name #

To filter calendars by a specific provider name, calendar type, and location, use the for_calendar_name method:

from canvas_sdk.v1.data.calendar import Calendar

calendars = Calendar.objects.for_calendar_name(
    provider_name="Dr. Smith",
    calendar_type="Clinic",
    location="Main Office"
)

Attributes #

Calendar #

Field NameTypeDescription
idUUIDUnique identifier for the calendar
dbidIntegerDatabase identifier
titleStringThe title of the calendar
timezoneTimeZoneThe timezone for the calendar (default: UTC)
descriptionStringOptional description of the calendar’s purpose
eventsEvent[]Events associated with this calendar

Event #

Field NameTypeDescription
idUUIDUnique identifier for the event
dbidIntegerDatabase identifier
titleStringThe title of the event
descriptionStringDescription of the event
calendarCalendarThe calendar this event belongs to
starts_atDateTimeThe start date and time of the event
ends_atDateTimeThe end date and time of the event
recurrenceStringRecurrence rule for recurring events
recurrence_ends_atDateTimeThe date and time when the recurrence pattern ends
recurring_parent_eventEventThe parent event
original_starts_atDateTimeThe original start time for recurring event exceptions
is_all_dayBooleanWhether this is an all-day event (default: false)
is_cancelledBooleanWhether this event has been cancelled (default: false)
allowed_note_typesNoteType[]Note types that are allowed for this event

Examples #

Working with calendar events #

from canvas_sdk.v1.data.calendar import Calendar
from datetime import datetime
from logger import log

calendar = Calendar.objects.get(id="f53626e4-0683-43ac-a1b7-c52815639ce2")

# Get all upcoming events
upcoming_events = calendar.events.filter(
    starts_at__gte=datetime.now(),
    is_cancelled=False
).order_by('starts_at')

for event in upcoming_events:
    log.info(f"Event: {event.title}")
    log.info(f"Starts at: {event.starts_at}")
    log.info(f"Ends at: {event.ends_at}")

    if event.recurrence:
        log.info(f"Recurrence: {event.recurrence}")