1111import org .labkey .api .query .QueryService ;
1212import org .labkey .api .security .User ;
1313
14+ import java .util .Calendar ;
1415import java .util .Date ;
1516
1617
@@ -32,9 +33,14 @@ public String getEmailSubject(Container c)
3233 {
3334 return "Available Blood Volume Alert: " + getDateTimeFormat (c ).format (new Date ());
3435 }
35- /* From Hugh Crank:
36+
37+ /* Mathematica push:
3638 * Server mkt7: Runs at :55 from 4:55am to 7:55pm
3739 * Server mkt8: Runs at :25 from 4:25am to 7:25pm
40+ *
41+ * ABV ETL:
42+ * :01 and :31 after the hour for hours between 05:00 and 20:00
43+ * 0 1,31 5-20 ? * * *
3844 */
3945 @ Override
4046 public String getCronString ()
@@ -45,44 +51,52 @@ public String getCronString()
4551 @ Override
4652 public String getScheduleDescription ()
4753 {
48- return "15 minutes after every hour between 06:15 and 19:15." ;
54+ return "15 min past every hour from 06:15 to 19:15." ;
4955 }
5056
5157 @ Override
5258 public String getDescription ()
5359 {
54- return "Sends an alert on status of Available Blood Volume data from Mathematica." ;
60+ return "Sends status of available blood volume data from Mathematica." ;
5561 }
5662
5763 @ Override
5864 public String getMessageBodyHTML (Container c , User u )
5965 {
6066 StringBuilder msg = new StringBuilder ();
61-
62- AvailableBloodCheck (c , u , msg );
63-
67+ availableBloodCheck (c , u , msg );
6468 return msg .toString ();
6569 }
66- /* jonesga 5/8/2024 labkeyPublic.labkeyPublic.ValidateAvailableBloodProcess
67- */
68- protected void AvailableBloodCheck (final Container c , User u , final StringBuilder msg )
70+
71+ protected void availableBloodCheck (final Container c , User u , final StringBuilder msg )
6972 {
70- SimpleFilter filter = new SimpleFilter (FieldKey .fromString ("date" ), new Date (), CompareType .DATE_GTE );
71- TableInfo ti = QueryService .get ().getUserSchema (u , c , "onprc_ehr" ).getTable ("ValidateAvailableBloodProcess" , ContainerFilter .Type .AllFolders .create (c , u ));
72- // ((ContainerFilterable) ti).setContainerFilter(ContainerFilter.Type.AllFolders.create(u);
73- TableSelector ts = new TableSelector (ti , null , null );
73+ Calendar cal = Calendar .getInstance ();
74+ cal .add (Calendar .HOUR , -1 );
75+ Date staleTime = cal .getTime ();
76+
77+ TableInfo ti = QueryService .get ().getUserSchema (u , c , "onprc_ehr" ).getTable ("AvailableBloodVolume" , ContainerFilter .Type .AllFolders .create (c , u ));
7478
79+ if (ti == null )
80+ {
81+ msg .append ("<b>ERROR: Unable to access onprc_ehr.AvailableBloodVolume table.</b><br>\n " );
82+ return ;
83+ }
84+
85+ SimpleFilter filter = new SimpleFilter (FieldKey .fromString ("datecreated" ), staleTime , CompareType .LTE );
86+ TableSelector ts = new TableSelector (ti , filter , null );
7587 long count = ts .getRowCount ();
88+
7689 if (count > 0 )
7790 {
78- msg .append ("<b>The available blood volume data from Mathematica is stale.</b><br>\n " );
79- msg .append ("<p><a href='" + getExecuteQueryUrl (c , "onprc_ehr" , "ValidateAvailableBloodProcess " , null ) + "'>Click here to view labkeyPublic .AvailableBloodVolume. </a><br> \n \n " );
80- msg .append ("</p><br><hr >" );
91+ msg .append ("<b>WARNING: The available blood volume data from Mathematica is stale (last updated more than 1 hour ago) .</b><br>\n " );
92+ msg .append ("<p>View <a href='" ). append ( getExecuteQueryUrl (c , "onprc_ehr" , "AvailableBloodVolume " , null )). append ( "'>onprc_ehr .AvailableBloodVolume</a>.</p> \n " );
93+ msg .append ("<br >" );
8194 }
8295 else
8396 {
84- msg .append ("The available blood volume data from Mathematica is current.<br><hr> " );
85- msg .append ("<p><a href='" + getExecuteQueryUrl (c , "onprc_ehr" , "ValidateAvailableBloodProcess " , null ) + "'>Click here to view labkeyPublic .AvailableBloodVolume. </a><br> \n \n " );
86- msg .append ("</p><br><hr >" );
97+ msg .append ("<b>OK:</b> The available blood volume data from Mathematica is current (updated within the last hour) .<br>\n " );
98+ msg .append ("<p>View <a href='" ). append ( getExecuteQueryUrl (c , "onprc_ehr" , "AvailableBloodVolume " , null )). append ( "'>onprc_ehr .AvailableBloodVolume</a>.</p> \n " );
99+ msg .append ("<br >" );
87100 }
88- }}
101+ }
102+ }
0 commit comments