This is my query:
from i0 in Infection,
right_join: u1 in UserPermission,
on: u1.facility_id == i0.facility_id, left_join: e2 in Encounter,
on: i0.encounter_id == e2.id, left_join: p3 in Patient,
on: e2.patient_id == p3.id, right_join: e4 in Encounter,
on: e4.id == i0.encounter_id, right_join: p5 in Patient,
on: ilike(p3.first_name, ^"%1364%") or ilike(p3.last_name, ^"%1364%") or (ilike(p3.identifier, ^"%1364%") or
p3.ssn == ^"1364" or i0.id == ^1364),
where: u1.user_id == ^1 and u1.facility_id in ^[1, 2, 3],
where: i0.instance_id == ^1, where: i0.is_active == ^true and ^true,
where: i0.is_complete == ^"true" and ^true,
where: i0.meets_criteria == ^"true" and ^true,
where: i0.nhsn_reportable == ^"false" and ^true, distinct: true,
select: count("*")
This query returned the total number of patients from the patient’s table, which is wrong but if I execute this query without select, it returned only 1 record from infection, which is correct.
It returns correct count without this line of code:
on: ilike(p3.first_name, ^"%1364%") or ilike(p3.last_name, ^"%1364%") or (ilike(p3.identifier, ^"%1364%") or
p3.ssn == ^"1364" or i0.id == ^1364)
I can’t understand why select(count) is counting records from the patient table and not from the infection table
Any help/guidance will be much appreciated
Thanks