DocumentAnnotation

Introduction #

The DocumentAnnotation model holds the annotated versions of a document. When staff annotate or sign a document in Canvas, Canvas saves the result as a new PDF and records it as a DocumentAnnotation, leaving the original file unchanged. Each save adds another annotation, so a document can have several. The newest one is the current version of the document, and it’s the version Canvas uses when it prints the document as a letter attachment.

An annotation links to the document it was made on: a LabReport, ImagingReport, ReferralReport, PatientAdministrativeDocument, or UncategorizedClinicalDocument. An annotation saved before the document was filed links to its IntegrationTask, and Canvas links it to the document as well when the document is filed.

Basic usage #

To get an annotation by identifier, use the get method on the DocumentAnnotation model manager:

from canvas_sdk.v1.data import DocumentAnnotation

annotation = DocumentAnnotation.objects.get(id="b5a0c1d2-e3f4-5678-9abc-def012345678")

A staff member’s annotations are available from the Staff model. document_annotations holds the annotations they saved, and signed_document_annotations holds the annotations that carry their signature:

from canvas_sdk.v1.data import Staff

staff = Staff.objects.get(id="4150cd20de8a470aa570a852859ac87e")

created = staff.document_annotations.all()
signed = staff.signed_document_annotations.all()

The annotations saved on an incoming document before it was filed are available from its integration task:

from canvas_sdk.v1.data import IntegrationTask

task = IntegrationTask.objects.get(id="d2194110-5c9a-4842-8733-ef09ea5ead11")
annotations = task.document_annotations.order_by("created")

Filtering #

Annotations can be filtered by any attribute that exists on the model.

Annotations on a document #

An annotation stores its document as a ContentType and an object_id. To find the annotations on a document, resolve the content type at runtime from its stable app_label and model, never the per-environment dbid, and match object_id against the document’s dbid. The newest annotation is the document’s current version:

from canvas_sdk.v1.data import ContentType, DocumentAnnotation, LabReport

report = LabReport.objects.get(id="7c9e6679-7425-40de-944b-e07fc1f90ae7")

content_type = ContentType.objects.filter(app_label="api", model="labreport").first()

latest = (
    DocumentAnnotation.objects.filter(content_type=content_type, object_id=report.dbid)
    .order_by("created")
    .last()
)

Annotations with a signature spot left #

has_signature_spot is True when the annotated PDF still has a spot marked for a signature, such as a form sent for signature that the provider hasn’t signed yet:

from canvas_sdk.v1.data import DocumentAnnotation

awaiting_signature = DocumentAnnotation.objects.filter(has_signature_spot=True)

Annotations signed by a staff member #

from canvas_sdk.v1.data import DocumentAnnotation, Staff

staff = Staff.objects.get(id="4150cd20de8a470aa570a852859ac87e")

signed = DocumentAnnotation.objects.filter(signers=staff)

The annotated document #

The document_url property returns a presigned S3 URL for the annotated PDF, or None when the annotation has no file. The URL is valid for one hour, so generate it when you need it rather than storing it.

The related_object property returns the document the annotation was made on, as its SDK model. It returns None when the annotation links to an integration task instead, or when the document isn’t available through the SDK, such as when it was deleted.

from canvas_sdk.v1.data import DocumentAnnotation

annotation = DocumentAnnotation.objects.get(id="b5a0c1d2-e3f4-5678-9abc-def012345678")

# Presigned S3 URL to the annotated PDF, or None
url = annotation.document_url

# The LabReport, ImagingReport, ReferralReport, PatientAdministrativeDocument,
# or UncategorizedClinicalDocument, or None
document = annotation.related_object

Attributes #

DocumentAnnotation #

Field NameTypeNotes
idUUID 
dbidInteger 
createdDateTimeWhen this version was saved
modifiedDateTime 
documentFile (S3 key)The annotated PDF
created_byStaffThe staff member who saved the annotation
signersStaff[]The staff members whose signatures were placed while annotating
has_signature_spotBooleanWhether the annotated PDF still has a spot marked for a signature
integration_taskIntegrationTaskThe incoming document the annotation was made on before it was filed, or None
content_typeContentTypeThe type of the annotated document, or None
object_idIntegerThe dbid of the annotated document, or None
document_urlString (computed)Presigned S3 URL for document, or None if unset
related_objectLabReport, ImagingReport, ReferralReport, PatientAdministrativeDocument, or UncategorizedClinicalDocument (computed)The annotated document, or None