Skip to content
Partner Developer Portal

Definition

The Dbo Patientassociatepatient model records relationships between patients and patient associates, including a relationship-type identifier and user-specified description. It holds notes and flags for caring, main-carer, next-of-kin and emergency-contact roles, record discussion and patient-merge involvement, together with deletion flags.

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

dbo.patientassociatepatient with dbo.patientassociate, dbo.patientassociatetype and dbo.patient details

Section titled “dbo.patientassociatepatient with dbo.patientassociate, dbo.patientassociatetype and dbo.patient details”

Return records alongside descriptive values from the related tables.

SELECT
m."_primary_key",
m."patientassociateid",
p1."displayname" AS "patientassociate_displayname",
m."patientassociatetypeid",
p2."description" AS "patientassociatetype_description",
m."patientid",
p3."displayname" AS "patient_displayname"
FROM dbo.patientassociatepatient AS m
LEFT JOIN dbo.patientassociate AS p1
ON p1."patientassociateid" = m."patientassociateid"
AND p1."organisation" = m."organisation"
LEFT JOIN dbo.patientassociatetype AS p2
ON p2."patientassociatetypeid" = m."patientassociatetypeid"
AND p2."organisation" = m."organisation"
LEFT JOIN dbo.patient AS p3
ON p3."patientid" = m."patientid"
AND p3."organisation" = m."organisation";

Row count by dbo.patientassociate displayname

Section titled “Row count by dbo.patientassociate displayname”

Count dbo.patientassociatepatient records for each dbo.patientassociate value, joined on patientassociateid.

SELECT
p."displayname" AS "patientassociate_displayname",
COUNT(*) AS row_count
FROM dbo.patientassociatepatient AS m
INNER JOIN dbo.patientassociate AS p
ON p."patientassociateid" = m."patientassociateid"
AND p."organisation" = m."organisation"
GROUP BY p."displayname"
ORDER BY row_count DESC;

Row count by dbo.patientassociatetype description

Section titled “Row count by dbo.patientassociatetype description”

Count dbo.patientassociatepatient records for each dbo.patientassociatetype value, joined on patientassociatetypeid.

SELECT
p."description" AS "patientassociatetype_description",
COUNT(*) AS row_count
FROM dbo.patientassociatepatient AS m
INNER JOIN dbo.patientassociatetype AS p
ON p."patientassociatetypeid" = m."patientassociatetypeid"
AND p."organisation" = m."organisation"
GROUP BY p."description"
ORDER BY row_count DESC;