29 lines
1.2 KiB
SQL
29 lines
1.2 KiB
SQL
-- Snowflake version: Check prescribing by VTM (Virtual Therapeutic Moiety)
|
|
-- Uses unified PrimaryCareMedication table (combines EMIS + TPP)
|
|
|
|
SET StartDate = '2025-05-01';
|
|
SET EndDate = '2025-11-30';
|
|
|
|
WITH SnomedCodes AS (
|
|
SELECT "ProductSnomedCode", "ProductDescription"
|
|
FROM DATA_HUB.DWH."DimMedicineAndDevice"
|
|
WHERE "TherapeuticMoietySnomedCode" = '41145911000001106' -- Tirzepatide VTM
|
|
)
|
|
SELECT
|
|
DATE_TRUNC('MONTH', pcm."DateMedicationStart") AS PrescribingMonth,
|
|
COUNT(DISTINCT dp."PersonKey") AS UniquePatientCount
|
|
FROM DATA_HUB.PHM."PrimaryCareMedication" pcm
|
|
INNER JOIN DATA_HUB.DWH."DimPerson" dp
|
|
ON pcm."PatientPseudonym" = dp."PatientPseudonym"
|
|
INNER JOIN SnomedCodes sc
|
|
ON pcm."SNOMEDCode" = sc."ProductSnomedCode"
|
|
INNER JOIN DATA_HUB.DWH."DimOrganisationAndSite" dos
|
|
ON dp."CurrentGeneralPractice" = dos."SiteCode"
|
|
WHERE pcm."DateMedicationStart" BETWEEN $StartDate AND $EndDate
|
|
AND pcm."PatientPseudonym" IS NOT NULL
|
|
AND dos."OrganisationSubType" = 'GP Practice'
|
|
AND dos."IsSiteNorfolkAndWaveney" = 'Yes'
|
|
AND dos."IsSiteActive" = 'Yes'
|
|
GROUP BY DATE_TRUNC('MONTH', pcm."DateMedicationStart")
|
|
ORDER BY PrescribingMonth
|