Skip to content
Partner Developer Portal

Definition

The Appointment Reason model holds appointment reason definitions, including descriptive text, a reason type and a duration in minutes. It also records a code identifier, a default DNA reason flag, organisation details and identifiers for the reason itself.

This model is separate from the configured reasons described in the Deferred Visits Enhancements guide. The enhanced workflow uses appointment.deferralreason, referenced by appointment.assignmentlistpatientschedule.deferralreasonid. Do not join that identifier to this model’s reasonid or assume matching descriptions identify the same reason.

The guide does not define new reasontype values for this model. Its deferral reason soft-delete and replacement rules apply to appointment.deferralreason; they should not be inferred for appointment.reason.

_deleted indicates whether the record has been deleted in the source system.

appointment.reason with dbo.organisation details

Section titled “appointment.reason with dbo.organisation details”

Return records alongside descriptive values from the related dbo.organisation record.

SELECT
m."reasonid",
m."organisationid",
p1."organisationdisplayname" AS "organisationdisplayname"
FROM appointment.reason AS m
LEFT JOIN dbo.organisation AS p1
ON p1."organisationid" = m."organisationid"
AND p1."organisation" = m."organisation";

Row count by dbo.organisation organisationdisplayname

Section titled “Row count by dbo.organisation organisationdisplayname”

Count appointment.reason records for each dbo.organisation value, joined on organisationid.

SELECT
p."organisationdisplayname" AS "organisationdisplayname",
COUNT(*) AS row_count
FROM appointment.reason AS m
INNER JOIN dbo.organisation AS p
ON p."organisationid" = m."organisationid"
AND p."organisation" = m."organisation"
GROUP BY p."organisationdisplayname"
ORDER BY row_count DESC;

Records without a matching dbo.organisation

Section titled “Records without a matching dbo.organisation”

Find appointment.reason records whose organisationid has no matching dbo.organisation record.

SELECT
COUNT(*) AS unmatched_count
FROM appointment.reason AS m
LEFT JOIN dbo.organisation AS p
ON p."organisationid" = m."organisationid"
AND p."organisation" = m."organisation"
WHERE m."organisationid" IS NOT NULL
AND p."organisationid" IS NULL;