Se agrega verificacion del tiempo de registro de mails

This commit is contained in:
aime.rolandi 2025-05-23 16:33:55 -03:00
parent 0166626299
commit 6b9c66c385

View File

@ -99,8 +99,8 @@ defmodule Api.EmailToSendContext do
end) end)
end end
queryable = from( queryable = from(
e in Emailtosend, e in Emailtosend,
where: ^filter_conditions, where: ^filter_conditions,
join: s in "study", on: s.idstudy == e.idstudy, join: s in "study", on: s.idstudy == e.idstudy,
join: p in "patient", on: p.idpatient == s.idpatient, join: p in "patient", on: p.idpatient == s.idpatient,
order_by: ^sort_values, order_by: ^sort_values,
@ -141,25 +141,28 @@ defmodule Api.EmailToSendContext do
end end
def get_next_email() do def get_next_email() do
one_day_ago = NaiveDateTime.utc_now() |> NaiveDateTime.add(-86400, :second)
from( from(
e in Emailtosend, e in Emailtosend,
join: s in "study", on: s.idstudy == e.idstudy, join: s in "study", on: s.idstudy == e.idstudy,
join: p in "patient", on: p.idpatient == s.idpatient, join: p in "patient", on: p.idpatient == s.idpatient,
where: where:
( (
e.patientemail != "notiene@notiene.com" and e.patientemail != "notiene@notiene.com" and
e.patientemail != "" and e.patientemail != "" and
not is_nil(e.patientemail) and not is_nil(e.patientemail) and
e.forcereprocess == true e.forcereprocess == true
) or ) or
( (
e.patientemail != "notiene@notiene.com" and e.patientemail != "notiene@notiene.com" and
e.patientemail != "" and e.patientemail != "" and
not is_nil(e.patientemail) and not is_nil(e.patientemail) and
e.hasreport == true and e.hasreport == true and
e.sent != true and e.sent != true and
e.retries < 10 e.retries < 10
), )
and e.registered >= ^one_day_ago,
limit: 1, limit: 1,
select: %{ select: %{
idemailtosend: e.idemailtosend, idemailtosend: e.idemailtosend,