Fax

Introduction #

Canvas creates a Fax record for every fax it sends or receives. direction tells the two apart.

  • Sent faxes: when a user faxes a note, referral, imaging order, lab order, letter, or integration task, Canvas also records an action event on that document. Plugins can read them to see whether a fax was delivered, who sent it, and which number it went to.
  • Received faxes: each one has a Fax record with the sender’s number, the page count, and whether it was received successfully.

Each document type has its own action event model:

DocumentAction eventReverse accessor on the document
NoteNoteActionEventaction_events
ReferralReferralActionEventaction_events
ImagingOrderImagingOrderActionEventaction_events
LabOrderLabOrderActionEventaction_events
IntegrationTaskIntegrationTaskActionEventaction_events
LetterLetterActionEventletter_action_events

All six have the same action event fields and differ only in the document they point to.

Delivery status #

Canvas submits a fax to the faxing service, and the service later reports whether it reached the recipient. delivered_by_fax on the action event holds that outcome:

delivered_by_faxMeaning
NoneSubmitted. The faxing service hasn’t reported the outcome yet.
TrueDelivered to the recipient.
FalseNot delivered. fax_result_msg holds the reason the faxing service reported.

A submission the faxing service rejects doesn’t create an action event. So received_by_fax is True on every action event for a fax sent today, and success is True on every outbound Fax. Neither one tells you whether the fax was delivered.

Basic usage #

Faxes of a document #

Use the document’s action_events accessor:

from canvas_sdk.v1.data import Note

note = Note.objects.get(id="89992c23-c298-4118-864a-26cb3e1ae822")
faxes = note.action_events.filter(event_type="FAXED").select_related("fax")

Failed faxes, with the sender and the number #

originator is the CanvasUser who sent the fax, and fax.to_fax_number is the number it was sent to:

from canvas_sdk.v1.data import ReferralActionEvent

failed = ReferralActionEvent.objects.filter(delivered_by_fax=False).select_related(
    "referral", "originator", "fax"
)
for event in failed:
    sender = event.originator
    failed_number = event.fax.to_fax_number if event.fax else None

Faxes sent by a plugin #

A fax sent with the Fax Note effect is recorded as a NoteActionEvent on that note, with the Canvas Bot user as its originator. Canvas Bot’s staff id is 5eede137ecfe4124b8b773040e33be14 on every instance. To read the outcome, look the event up by the note, the number it was sent to, and that originator, so faxes staff sent to the same number are left out. Numbers are stored in E.164 format:

from canvas_sdk.v1.data import NoteActionEvent

CANVAS_BOT_STAFF_ID = "5eede137ecfe4124b8b773040e33be14"

latest = (
    NoteActionEvent.objects.filter(
        note__id="89992c23-c298-4118-864a-26cb3e1ae822",
        fax__to_fax_number="+15555550100",
        originator__staff__id=CANVAS_BOT_STAFF_ID,
    )
    .order_by("-created")
    .first()
)

Every plugin’s faxes are attributed to Canvas Bot, so this can’t tell your plugin’s faxes from another plugin’s. If more than one plugin faxes the same note to the same number, compare created with when your plugin returned the effect.

From a fax #

A Fax reaches its action events through noteactionevents, referralactionevents, imagingorderactionevents, laborderactionevents, letteractionevents, and integrationtaskactionevents:

from canvas_sdk.v1.data import Fax

fax = Fax.objects.get(id="d2a6c1f4-7b3e-4c1a-9f5e-0a8b7c6d5e4f")
note_events = fax.noteactionevents.all()

Faxes Canvas receives #

Filter on direction to read received faxes. success is False when the faxing service reported a problem receiving the fax, such as a call that dropped partway through. Canvas still creates an integration task with the pages that arrived, so the document may be incomplete.

from canvas_sdk.v1.data import Fax, FaxDirection

received = Fax.objects.filter(direction=FaxDirection.INBOUND).order_by("-date_utc")
failed = received.filter(success=False)

Attributes #

Fax #

Field NameTypeNotes
idUUID 
dbidInteger 
createdDateTime 
modifiedDateTime 
fax_idStringThe faxing service’s id for the fax
to_fax_numberStringThe number the fax was sent to, for example +15555550100. For a received fax, the Canvas number that received it
from_fax_numberStringThe number the fax was sent from. For a received fax, the sender’s number
date_utcDateTimeWhen the faxing service accepted a sent fax, or finished receiving a received fax
fax_pagesIntegerThe number of pages
directionFaxDirectionWhether Canvas sent or received the fax
successBooleanFor a sent fax, whether the faxing service accepted it. See Delivery status. For a received fax, whether it was received successfully
noteactioneventsQuerySet[NoteActionEvent]The note faxes sent as this fax
referralactioneventsQuerySet[ReferralActionEvent]The referral faxes sent as this fax
imagingorderactioneventsQuerySet[ImagingOrderActionEvent]The imaging order faxes sent as this fax
laborderactioneventsQuerySet[LabOrderActionEvent]The lab order faxes sent as this fax
letteractioneventsQuerySet[LetterActionEvent]The letter faxes sent as this fax
integrationtaskactioneventsQuerySet[IntegrationTaskActionEvent]The integration task faxes sent as this fax
fax_statusesQuerySet[FaxStatusModel]The status recorded when this fax was received

FaxStatusModel #

Canvas records a status when it receives a fax: Received, or Error if the faxing service reported a problem receiving it. It’s reachable through the fax’s fax_statuses accessor and matches the fax’s success value. Faxes sent from Canvas don’t get one. Use success on the fax instead, which every received fax has.

Field NameTypeNotes
idUUID 
dbidInteger 
createdDateTimeWhen the status was recorded
modifiedDateTime 
faxFaxThe fax the status belongs to
statusFaxStatus 

Action event fields #

These fields are on all six action event models.

Field NameTypeNotes
idUUID 
dbidInteger 
createdDateTime 
modifiedDateTime 
event_typeEventType 
send_fax_idStringThe faxing service’s id for the fax
received_by_faxBooleanWhether the faxing service accepted the fax
delivered_by_faxBooleanThe delivery outcome. See Delivery status.
fax_result_msgStringThe reason the faxing service gave for a failed delivery
originatorCanvasUserThe user who sent the fax
faxFaxThe fax record, including the number it was sent to

NoteActionEvent #

The action event fields, plus:

Field NameType
noteNote

ReferralActionEvent #

The action event fields, plus:

Field NameType
referralReferral

ImagingOrderActionEvent #

The action event fields, plus:

Field NameType
imaging_orderImagingOrder

LabOrderActionEvent #

The action event fields, plus:

Field NameType
lab_orderLabOrder

IntegrationTaskActionEvent #

The action event fields, plus:

Field NameType
integration_taskIntegrationTask

Enumeration types #

FaxDirection #

ValueLabel
OOutbound
IInbound

FaxStatus #

ValueLabel
PProcessing
SSent
RReceived
EError

Event Type #

ValueLabel
PRINTEDPrinted
FAXEDFaxed