From 6b9c66c385070989d18e2b132cdba29ad8316040 Mon Sep 17 00:00:00 2001 From: "aime.rolandi" Date: Fri, 23 May 2025 16:33:55 -0300 Subject: [PATCH] Se agrega verificacion del tiempo de registro de mails --- .../emailsender/contexts/emailstosendcontext.ex | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/api/emailsender/contexts/emailstosendcontext.ex b/lib/api/emailsender/contexts/emailstosendcontext.ex index 673c691..9a95cac 100644 --- a/lib/api/emailsender/contexts/emailstosendcontext.ex +++ b/lib/api/emailsender/contexts/emailstosendcontext.ex @@ -99,8 +99,8 @@ defmodule Api.EmailToSendContext do end) end queryable = from( - e in Emailtosend, - where: ^filter_conditions, + e in Emailtosend, + where: ^filter_conditions, join: s in "study", on: s.idstudy == e.idstudy, join: p in "patient", on: p.idpatient == s.idpatient, order_by: ^sort_values, @@ -141,25 +141,28 @@ defmodule Api.EmailToSendContext do end def get_next_email() do + one_day_ago = NaiveDateTime.utc_now() |> NaiveDateTime.add(-86400, :second) + from( e in Emailtosend, join: s in "study", on: s.idstudy == e.idstudy, 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 not is_nil(e.patientemail) and e.forcereprocess == true ) or - ( - e.patientemail != "notiene@notiene.com" and + ( + e.patientemail != "notiene@notiene.com" and e.patientemail != "" and not is_nil(e.patientemail) and e.hasreport == true and e.sent != true and e.retries < 10 - ), + ) + and e.registered >= ^one_day_ago, limit: 1, select: %{ idemailtosend: e.idemailtosend,