Skip to content
Partner Developer Portal

Definition

The Unscheduledcare Dischargedestination model holds organisation details for recorded discharge destinations. Each entry contains a destination identifier, organisation identifier and name, ODS code and active flag, together with organisation information.

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

unscheduledcare.dischargedestination with dbo.organisation details

Section titled “unscheduledcare.dischargedestination with dbo.organisation details”

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

SELECT
m."dischargedestinationid",
m."organisationid",
p1."organisationdisplayname" AS "organisationdisplayname"
FROM unscheduledcare.dischargedestination AS m
LEFT JOIN dbo.organisation AS p1
ON p1."organisationid" = m."organisationid"
AND p1."organisation" = m."organisation";

unscheduledcare.attendancedetail count per unscheduledcare.dischargedestination

Section titled “unscheduledcare.attendancedetail count per unscheduledcare.dischargedestination”

Count related unscheduledcare.attendancedetail records for each unscheduledcare.dischargedestination record, joined on dischargedestinationid.

SELECT
m."dischargedestinationid",
m."organisationname",
COUNT(c."dischargedestinationid") AS attendancedetail_count
FROM unscheduledcare.dischargedestination AS m
LEFT JOIN unscheduledcare.attendancedetail AS c
ON m."dischargedestinationid" = c."dischargedestinationid"
AND m."organisation" = c."organisation"
GROUP BY m."dischargedestinationid", m."organisationname"
ORDER BY attendancedetail_count DESC;

Row count by dbo.organisation organisationdisplayname

Section titled “Row count by dbo.organisation organisationdisplayname”

Count unscheduledcare.dischargedestination records for each dbo.organisation value, joined on organisationid.

SELECT
p."organisationdisplayname" AS "organisationdisplayname",
COUNT(*) AS row_count
FROM unscheduledcare.dischargedestination 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;