Here’s the query:
completed_visits =
from(v in Visit,
select: count("*"),
where: v.scheduled_for >= ^sixty_days_ago,
where: v.pal_id == ^pal.id,
where: v.state in ["completed", "reviewed"]
)
|> Repo.one()
future_visits =
from(v in Visit,
select: count("*"),
where: v.scheduled_for >= ^Timex.now(),
where: v.pal_id == ^pal.id
)
|> Repo.one()
The meat of this query is: they have a visit in either state OR they have a visit scheduled for the future.
How could I combine this into a single SQL query using Ecto? Found some documentation here, but having some trouble understand how to fit it into my current needs. https://hexdocs.pm/ecto/Ecto.Query.html#or_where/3-keywords-example