Can't get history from deceased and deactivated patients
Submitted by dadmin on Sun, 17/07/2011 - 22:00
I am trying to modify the patient history search report to include inactivated and deceased patients. I can't work out why it doesn't find them.
Here is my query:
select
c.name as customer,
c.description as description,
p.name as patient,
d1.value as dateOfBirth,
ls.name as species,
lb.name as breed,
ad.value as notesOrProblems,
part.activity_start_time as visitDate
from entities p
join entity_relationships r on r.target_id = p.entity_id
join entities c on r.source_id = c.entity_id
join entity_details d1 on d1.entity_id = p.entity_id and d1.name = "dateOfBirth"
join entity_details d2 on d2.entity_id = p.entity_id and d2.name = "species"
join lookups ls on ls.code = d2.value and ls.arch_short_name = "lookup.species"
join entity_details d3 on d3.entity_id = p.entity_id and d3.name = "breed"
join lookups lb on lb.code = d3.value and lb.arch_short_name = "lookup.breed"
join participations part ON part.`entity_id` = p.`entity_id`
join `acts` acts ON acts.`act_id` = part.`act_id`
join act_details ad ON ad.`act_id` = acts.`act_id`
where
ad.name like "note" and
ad.value like $P{HistorySearch} and
ls.name like $P{species} and
lb.name like $P{breed} and
(part.activity_start_time between $P{startDate} and $P{finishDate})
order by c.name
Can anyone give me a clew as to why this query won't find them?
Many thanks,
Matt Y.
Re: Can't get history from deceased and deactivated patients
If the patients don't have a breed, date of birth, or notes for the date range, then no results will be returned for them.
The following should solve the breed and date of birth issue.
If you want to find patients that have visits in the date range that may or may not have notes then the query is a little more complex.
Re: Can't get history from deceased and deactivated patients
Beat me too it.
Using arch_short_name when joining particpations (as Tim has in his edits) and acts as a general rule. It will significantly speed queries and decrease workload on server.
Also the way Tim has added criteria to the JOIN rather then the WHERE can also speed up some queries.
Matt C