user_org_scheme_ids=Scheme.select(:id).where(owning_organisation_id:case_log.created_by.organisation_id).joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL",Time.zone.today)).map(&:id)
filtered_scheme_ids=schemes.joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL",Time.zone.today)).map(&:id)