Hi @guy_livne!
Yes, visit_occurrence_id is a really handy field that can create linkages among CDM Domains. The challenge is that visit_occurrence_id is only a required field in some CDM Domains (e.g. VISIT_OCCURRENCE, VISIT_DETAIL). It is not required in CONDITION_OCCURRENCE, DRUG_EXPOSURE, PROCEDURE_OCCURRENCE, MEASUREMENT, OBSERVATION, and NOTE. This is true for both V5.3 and V5.4 specifications (See the CDM wiki here: OMOP CDM v5.3).
What this means is that if you build logic to restrict to the same visit occurrence for a feature that comes from one of these domains where it’s not required, you may be asking your CDM to join on visit_occurrence_id but there’s nothing populated. Because of that requirement you get a 0 count. However, when you change to a date range, you are no longer requiring that the visit_occurrence_id be populated. You are use date stamps to link features adjacent to that index date without imposing that the visit_occurrence_id exist to confirm it’s exactly the same visit occurrence. There’s a lot of reasons why visits (or encounters as some EHR users call them) get enumerated and all their pieces don’t always end up neatly tied together via this linkage ID. I’m sure @MPhilofsky can layer on more experience here.
I try not to mandate my queries pull from not required fields unless I know there’s been a local ETL project to populate that element. Most ETL teams start by filling in what’s absolutely required to build the OMOP CDM and over the years, go back and augment when they have capacity to do so.
Hope that helps clarify!
Kristin