Skip to content
Partner Developer Portal

Definition

The Dbo Patientgphistory model records historical GP details associated with patients, including the GP’s title, forenames, surname and organisation identifier. It holds effective-from and effective-to dates with their date-part values and a child-assumed-GP flag, alongside patient and history identifiers.

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

dbo.patientgphistory with dbo.patient details

Section titled “dbo.patientgphistory with dbo.patient details”

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

SELECT
m."patientgphistoryid",
m."patientid",
p1."displayname" AS "patient_displayname"
FROM dbo.patientgphistory AS m
LEFT JOIN dbo.patient AS p1
ON p1."patientid" = m."patientid"
AND p1."organisation" = m."organisation";

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

SELECT
p."displayname" AS "patient_displayname",
COUNT(*) AS row_count
FROM dbo.patientgphistory 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;

Find dbo.patientgphistory records whose patientid has no matching dbo.patient record.

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