Page 1 of 1
User query help
Posted: Mon Apr 06, 2020 11:59 am
by babysilvertooth
I found the query to find patients of a certain age range, but I want to include their home and cell phone numbers. Not sure where or how to add that to the code to get the information.
Thanks
Re: User query help
Posted: Tue Apr 07, 2020 2:59 am
by Tom Zaccaria
Post the code you have so far and I will see what help to offer you.
drtmz
Re: User query help
Posted: Thu Apr 09, 2020 12:56 pm
by babysilvertooth
I have this, but only shows the name, I want to add the phone number so I can call them instead of looking up each one.
Thanks
/*175 Patients of specifed age range and gender*/
SET @Young='1', @Old='100'; #Change age range here.
SET @Gender='1'; #Change gender here. 0-Male, 1-Female, 2-Unknown
SET @pos=0;
SELECT @pos:=@pos+1 AS 'Count', PatNum,
(YEAR(CURDATE())-YEAR(Birthdate)) - (RIGHT(CURDATE(),5)<RIGHT(Birthdate,5)) AS 'Age',
(CASE WHEN Gender=0 THEN 'M' WHEN Gender=1 THEN 'F' ELSE 'U' END) AS 'Gender'
FROM patient
WHERE ((YEAR(CURDATE())-YEAR(Birthdate)) - (RIGHT(CURDATE(),5)<RIGHT(Birthdate,5))) BETWEEN @Young AND @Old
AND Gender=@Gender
AND PatStatus=0
ORDER BY LName, FName;
Re: User query help
Posted: Thu Apr 09, 2020 2:28 pm
by Tom Zaccaria
This should do it. If you want work phone, it is easy to add
/*175 Patients of specifed age range and gender*/
SET @Young='1', @Old='100'; #Change age range here.
SET @Gender='1'; #Change gender here. 0-Male, 1-Female, 2-Unknown
SET @pos=0;
SELECT @pos:=@pos+1 AS 'Count', PatNum,
(YEAR(CURDATE())-YEAR(Birthdate)) - (RIGHT(CURDATE(),5)<RIGHT(Birthdate,5)) AS 'Age',
(CASE WHEN Gender=0 THEN 'M' WHEN Gender=1 THEN 'F' ELSE 'U' END) AS 'Gender', WirelessPhone, HmPhone
FROM patient
WHERE ((YEAR(CURDATE())-YEAR(Birthdate)) - (RIGHT(CURDATE(),5)<RIGHT(Birthdate,5))) BETWEEN @Young AND @Old
AND Gender=@Gender
AND PatStatus=0
ORDER BY LName, FName;
drtmz
Re: User query help
Posted: Fri Apr 10, 2020 2:10 pm
by babysilvertooth
Thank you! I'l try it
Re: User query help
Posted: Sat Apr 11, 2020 4:49 am
by Tom Zaccaria
Do do know that will only give one specific gender. You would have to run it once for males and again for females. If you want to remove the gender variable, let me know. And I think we can group it by age.
drtmz
Re: User query help
Posted: Sat Apr 11, 2020 4:59 am
by Tom Zaccaria
Ok. Here is the same code modified for both sexes grouped by age. I think this is what you want.
/*175 Patients of specified age range and gender*/
SET @Young='1', @Old='100'; #Change age range here.
SET @pos=0;
SELECT @pos:=@pos+1 AS 'Count', PatNum,
(YEAR(CURDATE())-YEAR(Birthdate)) - (RIGHT(CURDATE(),5)<RIGHT(Birthdate,5)) AS 'Age',
(CASE WHEN Gender=0 THEN 'M' WHEN Gender=1 THEN 'F' ELSE 'U' END) AS 'Gender', WirelessPhone, HmPhone
FROM patient
WHERE ((YEAR(CURDATE())-YEAR(Birthdate)) - (RIGHT(CURDATE(),5)<RIGHT(Birthdate,5))) BETWEEN @Young AND @Old
AND PatStatus=0
ORDER BY age;
drtmz
Re: User query help
Posted: Mon Apr 13, 2020 1:06 pm
by babysilvertooth
Thanks Tom, that is it, I ran the report and took it with me without reading it and realized it was single gender...started to work on the report and realized it.
One more request, can it only include only active patients?
Cheers!
Re: User query help
Posted: Tue Apr 14, 2020 3:05 am
by Tom Zaccaria
It does as written, PatStatus=0, is code for active patients.
Now you may have entry errors in that an archived patient is still coded as active. But the report will return only those patients that are listed as active.
drtmz