Skip to content
Partner Developer Portal

Definition

The Dbo Patienthistory model records patient status and type information with the date it was recorded. Each entry holds status, type and subtype identifiers and status notes, together with patient and history identifiers, a record GUID and organisation information.

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

dbo.patienthistory with dbo.patient, dbo.patientstatus and dbo.patienttype details

Section titled “dbo.patienthistory with dbo.patient, dbo.patientstatus and dbo.patienttype details”

Return records alongside descriptive values from the related tables.

SELECT
m."patienthistoryid",
m."patientid",
p1."displayname" AS "patient_displayname",
m."patientstatusid",
p2."patientstatusdescription" AS "patientstatusdescription",
m."patienttypeid",
p3."patienttypedescription" AS "patienttypedescription"
FROM dbo.patienthistory AS m
LEFT JOIN dbo.patient AS p1
ON p1."patientid" = m."patientid"
AND p1."organisation" = m."organisation"
LEFT JOIN dbo.patientstatus AS p2
ON p2."patientstatusid" = m."patientstatusid"
AND p2."organisation" = m."organisation"
LEFT JOIN dbo.patienttype AS p3
ON p3."patienttypeid" = m."patienttypeid"
AND p3."organisation" = m."organisation";

Count dbo.patienthistory records for each dbo.patient value, joined on patientid.

SELECT
p."displayname" AS "patient_displayname",
COUNT(*) AS row_count
FROM dbo.patienthistory AS m
INNER JOIN dbo.patient AS p
ON p."patientid" = m."patientid"
AND p."organisation" = m."organisation"
GROUP BY p."displayname"
ORDER BY row_count DESC;

Row count by dbo.patientstatus patientstatusdescription

Section titled “Row count by dbo.patientstatus patientstatusdescription”

Count dbo.patienthistory records for each dbo.patientstatus value, joined on patientstatusid.

SELECT
p."patientstatusdescription" AS "patientstatusdescription",
COUNT(*) AS row_count
FROM dbo.patienthistory AS m
INNER JOIN dbo.patientstatus AS p
ON p."patientstatusid" = m."patientstatusid"
AND p."organisation" = m."organisation"
GROUP BY p."patientstatusdescription"
ORDER BY row_count DESC;