Referral

Introduction #

The Referral, ReferralReport, and ReferralReview models represent referral results and their reviews.

Basic Usage #

To retrieve a Referral, ReferralReport, or ReferralReview by identifier, use the get method on the model manager:

from canvas_sdk.v1.data.referral import Referral, ReferralReport, ReferralReview

referral = Referral.objects.get(id="d2194110-5c9a-4842-8733-ef09ea5ead11")
referral_report = ReferralReport.objects.get(id="c1a5a35a-4ee2-4a0e-85c0-21739dc8c4a8")
referral_review = ReferralReview.objects.get(id="b3e6f74c-2a1b-4c8d-9f2e-31842ae7d3b9")

If you have a patient object, the referrals, reports, and reviews can be accessed with the referral_set, referral_reports, and referral_reviews attributes, respectively on a Patient object:

from canvas_sdk.v1.data.patient import Patient

patient = Patient.objects.get(id="1eed3ea2a8d546a1b681a2a45de1d790")
referrals = patient.referral_set.all()
reports = patient.referral_reports.all()
reviews = patient.referral_reviews.all()

Filtering #

Referrals, reports, and reviews can be filtered by any attribute that exists on the models.

Filtering is done with the filter method on the Referral, ReferralReport, and ReferralReview model managers.

By attribute #

Specify an attribute with filter to filter by that attribute:

from canvas_sdk.v1.data.referral import Referral, ReferralReport, ReferralReview

referrals = Referral.objects.filter(priority="urgent")
reports = ReferralReport.objects.filter(requires_signature=True)
reviews = ReferralReview.objects.filter(status="completed")

By ValueSet #

See Value Sets for the library of built-in value sets and how to create your own.

ReferralReport supports ValueSet filtering through the find method on its model manager:

from canvas_sdk.v1.data.referral import ReferralReport
from canvas_sdk.value_set.v2022.procedure import DialysisServices

reports = ReferralReport.objects.find(DialysisServices)

find joins through the report’s codings reverse relation and matches on (system, code) pairs from the value set, so a coding must match both the code system and the code to be included.

Committed records #

The committed method returns Referral and ReferralReview records that have been committed and not entered in error:

from canvas_sdk.v1.data.referral import Referral, ReferralReview

committed_referrals = Referral.objects.committed()
committed_reviews = ReferralReview.objects.committed()

Related Tasks #

To retrieve an Referral’s related tasks, use the get_task_objects method on the Referral object.

from canvas_sdk.v1.data.referral import Referral

referral = Referral.objects.get(id="d2194110-5c9a-4842-8733-ef09ea5ead11")
tasks = referral.get_task_objects().all()

The task_list computed property returns the same related tasks as a list[Task]:

from canvas_sdk.v1.data.referral import Referral

referral = Referral.objects.get(id="d2194110-5c9a-4842-8733-ef09ea5ead11")
tasks = referral.task_list

Review assignment #

A referral report is assigned for review to staff members or to a team. reviewers holds the assigned staff members, and team holds the assigned team, or None when no team is assigned.

from canvas_sdk.v1.data import ReferralReport, Staff

referral_report = ReferralReport.objects.get(id="c1a5a35a-4ee2-4a0e-85c0-21739dc8c4a8")

# The staff members and the team the referral report is assigned to
reviewers = referral_report.reviewers.all()
team = referral_report.team

# Every referral report assigned to this staff member
staff = Staff.objects.get(id="4150cd20de8a470aa570a852859ac87e")
assigned = ReferralReport.objects.filter(reviewers__id=staff.id)

Delegations #

When staff send a referral report to a provider for signature, Canvas records a DocumentReviewDelegation. It records another when the provider signs the report and Canvas returns it. The delegations for a referral report are available through two accessors:

from canvas_sdk.v1.data import ReferralReport

referral_report = ReferralReport.objects.get(id="c1a5a35a-4ee2-4a0e-85c0-21739dc8c4a8")

# The full delegation history, oldest first.
history = referral_report.delegations

# The active delegation, or None when no delegation is in effect.
current = referral_report.active_delegation

For the report’s full timeline, including reassignments, comments, and signatures, see DocumentHistoryEvent.

Attached documents #

The documents sent with a referral are ReferralDocument records, available through the referral’s documents attribute. document_type names the kind of document, such as LAB REPORT, IMAGING REPORT, REFERRAL REPORT, UNCATEGORIZED DOCUMENT, or NOTE, and document_id holds that record’s dbid. For an uploaded file, url and bucket hold its S3 location instead.

from canvas_sdk.v1.data import LabReport, Referral

referral = Referral.objects.get(id="d2194110-5c9a-4842-8733-ef09ea5ead11")

lab_report_ids = [
    attachment.document_id
    for attachment in referral.documents.filter(document_type="LAB REPORT")
]
lab_reports = LabReport.objects.filter(dbid__in=lab_report_ids)

The document reference #

ReferralReport carries the consult report’s specialty, review state and comments, not the file. Canvas stores the file on a DocumentReference pointing back at the report, which is also how it appears in the FHIR API.

To read it, resolve the ContentType at runtime from its stable app_label and model — never hardcode the per-environment dbid — and match object_id against the report’s dbid:

from canvas_sdk.v1.data import ContentType, DocumentReference, ReferralReport

report = ReferralReport.objects.get(id="d2194110-5c9a-4842-8733-ef09ea5ead11")

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

document = DocumentReference.objects.filter(
    content_type=content_type, object_id=report.dbid
).first()

url = document.document_url if document else None

The incoming fax or upload #

A report filed from an incoming fax or upload links to it through integration_task_review, the IntegrationTaskReview of the document. The review’s task is the IntegrationTask, whose document_url points to the file as Canvas received it. The field can be None, so check it before reading the task.

from canvas_sdk.v1.data import ReferralReport

report = ReferralReport.objects.select_related("integration_task_review__task").get(
    id="d2194110-5c9a-4842-8733-ef09ea5ead11"
)

review = report.integration_task_review
url = review.task.document_url if review else None

The latest annotated version #

When staff annotate or sign a referral report in Canvas, Canvas saves the result as a new PDF in a DocumentAnnotation and leaves the original file unchanged. The newest annotation is the version Canvas shows. The document reference and the incoming fax or upload keep their stored files when the report is annotated, so look for an annotation first and fall back to the document reference when there’s none.

Find the annotations through the annotation’s link to its document: resolve the ContentType at runtime from its stable app_label and model, never the per-environment dbid, and match object_id against the report’s dbid. Annotations made in Data Integration before the report was filed are linked to the report when it’s filed, so the same lookup finds them.

from canvas_sdk.v1.data import ContentType, DocumentAnnotation, DocumentReference, ReferralReport

report = ReferralReport.objects.get(id="d2194110-5c9a-4842-8733-ef09ea5ead11")

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

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

if latest:
    url = latest.document_url
else:
    document = DocumentReference.objects.filter(
        content_type=content_type, object_id=report.dbid
    ).first()
    url = document.document_url if document else None

Attributes #

Referral #

Field NameType
idUUID
dbidInteger
createdDateTime
modifiedDateTime
originatorCanvasUser
committerCanvasUser
entered_in_errorCanvasUser
patientPatient
noteNote
assessmentAssessment
assessmentsAssessment
service_providerServiceProvider
clinical_questionString
priorityString
include_visit_noteBoolean
notesString
date_referredDateTime
internal_commentString
forwardedBoolean
ignoredBoolean
internal_task_commentTaskComment
task_idsString
reportsReferralReport[]
action_eventsReferralActionEvent[]
documentsReferralDocument[]

ReferralReport #

Field NameType
idUUID
dbidInteger
createdDateTime
modifiedDateTime
originatorCanvasUser
assigned_byCanvasUser
review_modeDocumentReviewMode
junkedBoolean
requires_signatureBoolean
assigned_dateDateTime
team_assigned_dateDateTime
teamTeam
reviewersStaff[]
patientPatient
referralReferral
integration_task_reviewIntegrationTaskReview
specialtyString
commentString
priorityBoolean
original_dateDate
reviewReferralReview
codingsReferralReportCoding[]
delegationsDocumentReviewDelegation[] (computed; the report’s delegations, oldest first)
active_delegationDocumentReviewDelegation (computed; the delegation in effect, or None)

ReferralReview #

Field NameType
idUUID
dbidInteger
createdDateTime
modifiedDateTime
originatorCanvasUser
committerCanvasUser
entered_in_errorCanvasUser
internal_commentString
message_to_patientString
statusString
noteNote
patientPatient
patient_communication_methodString
reportsReferralReport[]

ReferralDocument #

Field NameTypeNotes
dbidInteger 
createdDateTime 
modifiedDateTime 
referralReferralThe referral the document was sent with
document_typeStringThe kind of document: NOTE, LAB REPORT, IMAGING REPORT, REFERRAL REPORT, or UNCATEGORIZED DOCUMENT
document_idIntegerThe dbid of the attached record, or None
labelStringThe name shown for the attachment
urlStringThe S3 location of an uploaded file, or None
bucketStringThe S3 bucket of an uploaded file, or None

ReferralReportCoding #

Field NameType
dbidInteger
createdDateTime
modifiedDateTime
reportReferralReport
systemString
versionString
codeString
displayString
user_selectedBoolean
valueString