Here is the answer to your specific question and by looking at the query, we wish it could have been done better.
SELECT form_encounter.pid AS enc_pid, form_encounter.encounter AS enc_encounter, form_encounter.provider_id AS enc_provider_id, billing.* FROM form_encounter LEFT OUTER JOIN billing ON billing.encounter = form_encounter.encounter AND billing.pid = form_encounter.pid AND billing.code_type LIKE ‘%’ AND billing.activity = 1 LEFT OUTER JOIN patient_data on patient_data.pid = form_encounter.pid LEFT OUTER JOIN claims on claims.patient_id = form_encounter.pid and claims.encounter_id = form_encounter.encounter LEFT OUTER JOIN insurance_data on insurance_data.pid = form_encounter.pid and insurance_data.type = ‘primary’ WHERE 1=1 AND (insurance_data.provider = ‘0’ or insurance_data.date > form_encounter.date) AND (form_encounter.date between ‘2019-06-02 00:00:00’ and ‘2019-06-08 23:59:59’) AND billing.billed = ‘1’ ORDER BY form_encounter.encounter, form_encounter.pid, billing.code_type, billing.code ASC;
Returns “0” rows, even though there are rows that qualifies the above criteria!!
Though, one expects there are rows that qualifies the above criteria, technically speaking there is NO row that qualifies the above criteria.
This is simply due to the well-known confusion on the user side in understanding the difference between the values of NULL, EMPTY, ‘0’ and 0.
One of the column in the where clause above is “insurance_data.provider = ‘0’ ”
which is incorrect as NO row will qualify because the provider value will be either ‘’ (empty) or NULL or will have some other value but not ‘0’.
There are few workarounds including changing the value of the provider in the database (bad idea!)to meet the current query. That is set all the unknown and null values to ‘0’ for the provider column.
The simple workaround is to change the query in the where clause:
from: insurance_data.provider = '0’
to: (insurance_data.provider = ‘’ or insurance_data.provider is NULL)
Also, the only “equality” or “inequality” where one should use in the WHERE CLAUSES are(if the data type is CHAR:
NULL, ‘’, or some valid string. It is INCORRECT to use ‘0’ or Integer 0 in the query where Clause .
This may NOT the total solution for the above query and this is one of the problem and this ONLY fixes the current problem!
-ViSolve OpenEMR Support Team