From 964b908c3a0b5a036410f1a26d6e5a4704546b88 Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Thu, 1 Jun 2023 11:03:56 -0500 Subject: [PATCH 01/13] Adding Lixit animals to the waterCalendar view. --- .../pages/husbandry/WaterCalendar.jsp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp index c41b8275c..dc987b96b 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp @@ -705,27 +705,37 @@ if ($animalId == 'undefined' || $animalId == "null" || $animalId == ''){ WebUtils.API.selectRows("study", "waterTotalByDateWithWeight", { "date~gte": fetchInfo.start.format('Y-m-d'), - "date~lte": fetchInfo.end.format('Y-m-d'), - "TotalWater~isnonblank":true + "date~lte": fetchInfo.end.format('Y-m-d') + //"TotalWater~isnonblank":true }).then(function (data) { var events = data.rows; successCallback( events.map(function (row) { let parsedTotalWater = 0; - if(row.TotalWater !== null){ + let eventTitle = ""; + if( row.conditionAtTime === 'regulated' ){ + if ( row.TotalWater === null ){ + row.TotalWater = 'none'; + } parsedTotalWater = row.TotalWater; + eventTitle = row.Id + " Total: " + parsedTotalWater; + }else{ + eventTitle = row.Id + " on Lixit"; } + var eventObj = { id : LABKEY.Utils.generateUUID(), - title: row.Id + " Total: " + parsedTotalWater, + title: eventTitle, start: new Date(row.date), allDay: true, textColor: '#000000', rawRowData: row }; - if (row.mlsPerKg >= row.InnerMlsPerKg){ + + + if (row.mlsPerKg >= row.InnerMlsPerKg || row.conditionAtTime === 'lixit'){ eventObj.color = '#FFFFFF'; }else{ eventObj.color = '#EE2020' From b592587ed67034dc7536a0036b57387daeede769 Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Fri, 2 Jun 2023 16:16:04 -0500 Subject: [PATCH 02/13] Modifying water alerts to include alert for supervisors. Moving functions to base notification --- .../org/labkey/wnprc_ehr/WNPRC_EHRModule.java | 4 +- ...oringAnimalWithOutEntriesNotification.java | 119 +----- ...lWithOutEntriesSupervisorNotification.java | 53 +++ .../WaterMonitoringNotification.java | 364 +++++++++++++----- .../WaterOrdersAlertNotification.java | 141 +------ 5 files changed, 342 insertions(+), 339 deletions(-) create mode 100644 WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesSupervisorNotification.java diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/WNPRC_EHRModule.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/WNPRC_EHRModule.java index e181029ef..a3065271a 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/WNPRC_EHRModule.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/WNPRC_EHRModule.java @@ -116,6 +116,7 @@ import org.labkey.wnprc_ehr.notification.VvcNotification; import org.labkey.wnprc_ehr.notification.WaterMonitoringAnimalWithOutEntriesNotification; import org.labkey.wnprc_ehr.notification.AnimalRequestNotification; +import org.labkey.wnprc_ehr.notification.WaterMonitoringAnimalWithOutEntriesSupervisorNotification; import org.labkey.wnprc_ehr.notification.WaterOrdersAlertNotification; import org.labkey.wnprc_ehr.pages.husbandry.WaterCalendarWebPartFactory; import org.labkey.wnprc_ehr.schemas.WNPRC_Schema; @@ -362,7 +363,8 @@ public void registerNotifications() { new ProjectRequestNotification(this), new IrregularObsBehaviorNotification(this), new WaterOrdersAlertNotification(this), - new WaterMonitoringAnimalWithOutEntriesNotification(this) + new WaterMonitoringAnimalWithOutEntriesNotification(this), + new WaterMonitoringAnimalWithOutEntriesSupervisorNotification(this) ); for (Notification notification : notifications) diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesNotification.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesNotification.java index 9c81a624b..d13b34e91 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesNotification.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesNotification.java @@ -40,7 +40,7 @@ import java.util.Map; -public class WaterMonitoringAnimalWithOutEntriesNotification extends AbstractEHRNotification +public class WaterMonitoringAnimalWithOutEntriesNotification extends WaterMonitoringNotification { public WaterMonitoringAnimalWithOutEntriesNotification(Module owner) { @@ -49,7 +49,7 @@ public WaterMonitoringAnimalWithOutEntriesNotification(Module owner) public String getName() { - return "Water Monitoring"; + return "Water Monitoring Animal For Vets and Lab"; } @@ -63,10 +63,6 @@ public String getEmailSubject(Container c) @Override public String getCronString() { return "0 0 15,19 * * ?"; } - public String getCategory(){ - return "Husbandry"; - } - @Override public String getScheduleDescription() { @@ -82,127 +78,24 @@ public String getDescription() public String getMessageBodyHTML(final Container c, User u) { final StringBuilder msg = new StringBuilder(); + int numDays = 5; //Find today's date Date now = new Date(); msg.append("This email contains a series of automatic alerts about the water monitoring system. It was run on: " + AbstractEHRNotification._dateFormat.format(now) + " at " + AbstractEHRNotification._timeFormat.format(now) + ".

"); + //Check animals that did not get any water for today and the last five days. + findAnimalsWithWaterEntries(c,u,msg,numDays); + //Check animals with less than 20 mls per kilogram of water for today findAnimalsWithEnoughWater(c,u,msg); - //Check animals that did not get any water for today and the last five days. - findAnimalsWithWaterEntries(c,u,msg); return msg.toString(); } - protected void findAnimalsWithEnoughWater(final Container c, final User u, final StringBuilder msg) - { - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - - - SimpleFilter.OrClause orClause = new SimpleFilter.OrClause(); - orClause.addClause(new SimpleFilter(FieldKey.fromString("mlsPerKg"), 20, CompareType.LT).getClauses().get(0)); - orClause.addClause(new SimpleFilter(FieldKey.fromString("mlsPerKg"),null, CompareType.ISBLANK).getClauses().get(0)); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("date"), cal.getTime(), CompareType.DATE_EQUAL); - filter.addClause(orClause); - - TableSelector ts = new TableSelector(getStudySchema(c, u).getTable("waterTotalByDateWithWeight"),PageFlowUtil.set("Id","date","mlsPerKg","TotalWater","project"), filter, null); - long count = ts.getRowCount(); - if (count > 0) - { - msg.append("WARNING: There are " + count + " animals that have remaining water for today.
\n"); - Map[] totalWaterForDay = ts.getMapArray(); - msg.append(""); - msg.append("" + - "" + - "" + - "" + - "\n"); - - Map>> projectMap = new HashMap<>(); - for(Map mapItem : totalWaterForDay){ - int projectNum = ConvertHelper.convert(mapItem.get("project"),Integer.class); - List> waterTotalsFromDb; - if (!projectMap.containsKey(projectNum)){ - waterTotalsFromDb = new ArrayList<>(); - projectMap.put(projectNum,waterTotalsFromDb); - }else{ - waterTotalsFromDb = projectMap.get(projectNum); - } - waterTotalsFromDb.add(mapItem); - } - - for (Map.Entry>> entry : projectMap.entrySet()){ - List> totalWaterByProject = entry.getValue(); - String mlsPerKg; - String totalWater; - for(Map mapItem : totalWaterByProject){ - LocalDateTime objectDateTime = ConvertHelper.convert(mapItem.get("date"),Date.class).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - - mlsPerKg = ConvertHelper.convert(mapItem.get("mlsPerKg"),String.class) == null ? " " : ConvertHelper.convert(mapItem.get("mlsPerKg"),String.class); - totalWater = ConvertHelper.convert(mapItem.get("TotalWater"),String.class) == null ? " " : ConvertHelper.convert(mapItem.get("TotalWater"),String.class); - - msg.append("" ); - - } - } - - - - - msg.append("
ProjectIdDatemlsPerKgTotal Water Given
" + ConvertHelper.convert(mapItem.get("project"),Integer.class) - + " " + ConvertHelper.convert(mapItem.get("Id"),String.class) - + " " + objectDateTime.format(formatter) - + " " + mlsPerKg - + " " + totalWater - +"
"); - msg.append("

Click here to view them
\n\n"); - msg.append("


\n\n"); - - } - } - - protected void findAnimalsWithWaterEntries(final Container c, final User u, final StringBuilder msg){ - - LocalDate date = LocalDate.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - int datesInPast = 5; - for (int i = 0; i parameters = new CaseInsensitiveHashMap<>(); - parameters.put("CheckDate", date); - - TableInfo ti = QueryService.get().getUserSchema(u, c, "study").getTable("waterScheduledAnimalWithOutEntries"); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("id","project"), null, null); - ts.setNamedParameters(parameters); - - long total = ts.getRowCount(); - - if (total == 0) - { - msg.append("All regulated animals have at least one entries for "+ date.getDayOfWeek().toString() +" ("+ date.format(formatter) + ").
"); - } - else - { - msg.append("There are " + total + " animals in the system that have no records in water given dataset for " + date.getDayOfWeek().toString() +" ("+ date.format(formatter) + ").
"); - Map[] animalsWithOutEntries = ts.getMapArray(); - for (Map mapItem : animalsWithOutEntries) - { - msg.append(ConvertHelper.convert(mapItem.get("project"), Integer.class) + " " + ConvertHelper.convert(mapItem.get("Id"), String.class) + "
"); - - } - msg.append("
"); - } - date = date.minusDays(1); - } - - - } } diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesSupervisorNotification.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesSupervisorNotification.java new file mode 100644 index 000000000..a965fd089 --- /dev/null +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesSupervisorNotification.java @@ -0,0 +1,53 @@ +package org.labkey.wnprc_ehr.notification; + +import org.labkey.api.data.Container; +import org.labkey.api.module.Module; +import org.labkey.api.security.User; + +import java.util.Date; + +public class WaterMonitoringAnimalWithOutEntriesSupervisorNotification extends WaterMonitoringNotification +{ + public WaterMonitoringAnimalWithOutEntriesSupervisorNotification(Module owner) + { + super(owner); + } + public String getName(){return "Water Monitoring Alert for Supervisors";} + + @Override + public String getEmailSubject(Container c) + { + return "Daily Water Monitoring for Supervisors: " + AbstractEHRNotification._dateTimeFormat.format(new Date()); + } + + @Override + public String getCronString() { return "0 0 15,19 * * ?"; } + + @Override + public String getScheduleDescription() + { + return "every day at 1500 and 1900"; + } + + public String getDescription() + { + return "The report is designed to report total amount of water animal had gotten and report if they have not gotten the required 20 mls per kilogram."; + } + + @Override + public String getMessageBodyHTML(final Container c, User u) + { + final StringBuilder msg = new StringBuilder(); + int numDays = 1; + + //Find today's date + Date now = new Date(); + msg.append("This email contains a series of automatic alerts about the water monitoring system. It was run on: " + AbstractEHRNotification._dateFormat.format(now) + " at " + AbstractEHRNotification._timeFormat.format(now) + ".

"); + + //Check animals that did not get any water for today and the last five days. + findAnimalsWithWaterEntries(c,u,msg,numDays); + + return msg.toString(); + } + +} diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java index 0aa988a0e..3b2d16cfa 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java @@ -18,8 +18,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.labkey.api.collections.CaseInsensitiveHashMap; +import org.labkey.api.data.ColumnInfo; import org.labkey.api.data.CompareType; import org.labkey.api.data.Container; +import org.labkey.api.data.ConvertHelper; import org.labkey.api.data.Selector; import org.labkey.api.data.SimpleFilter; import org.labkey.api.data.TableInfo; @@ -34,11 +36,19 @@ import org.labkey.api.query.BatchValidationException; import java.sql.ResultSet; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; /** * User: bbimber @@ -58,6 +68,10 @@ public String getName() return "Water Monitoring"; } + public String getCategory(){ + return "Husbandry"; + } + private static final Logger _log = LogManager.getLogger(WaterMonitoringNotification.class); @Override @@ -90,123 +104,297 @@ public String getMessageBodyHTML(final Container c, User u) Date now = new Date(); msg.append("This email contains a series of automatic alerts about the colony. It was run on: " + AbstractEHRNotification._dateFormat.format(now) + " at " + AbstractEHRNotification._timeFormat.format(now) + ".

"); - //assignments - doAssignmentChecks(c, u, msg); + return msg.toString(); } - - - - protected void doAssignmentChecks(final Container c, User u, final StringBuilder msg) + protected void findAnimalsWithEnoughWater(final Container c, final User u, final StringBuilder msg) { - waterRemaining(c, u, msg); + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); - } - protected void waterRemaining(final Container c, final User u, final StringBuilder msg) - { - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); //then we find all records with problems in the calculated_status field - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("WaterRemaining"), 0, CompareType.GT); - filter.addCondition(FieldKey.fromString("date"), cal.getTime(), CompareType.DATE_EQUAL); - //new SimpleFilter(FieldKey.fromString("Id/Dataset/Demographics/calculated_status"), "Alive", CompareType.NEQ_OR_NULL); - //filter.addCondition(FieldKey.fromString("isActive"), true, CompareType.EQUAL); - TableSelector ts = new TableSelector(getStudySchema(c, u).getTable("remainingWater"),PageFlowUtil.set("waterRemaining","id"), filter, null); + SimpleFilter.OrClause orClause = new SimpleFilter.OrClause(); + orClause.addClause(new SimpleFilter(FieldKey.fromString("mlsPerKg"), 20, CompareType.LT).getClauses().get(0)); + orClause.addClause(new SimpleFilter(FieldKey.fromString("mlsPerKg"),null, CompareType.ISBLANK).getClauses().get(0)); + SimpleFilter filter = new SimpleFilter(FieldKey.fromString("date"), cal.getTime(), CompareType.DATE_EQUAL); + filter.addClause(orClause); + + TableSelector ts = new TableSelector(getStudySchema(c, u).getTable("waterTotalByDateWithWeight"),PageFlowUtil.set("Id","date","mlsPerKg","TotalWater","project","currentWaterCondition"), filter, null); long count = ts.getRowCount(); if (count > 0) { - msg.append("WARNING: There are " + count + " animals that have remaining water for today.
\n"); - msg.append("

Click here to view them
\n\n"); - //"&query.isActive~eq=true&query.Id/Dataset/Demographics/calculated_status~neqornull=Alive'>Click here to view them
\n\n"); + + Map[] totalWaterForDay = ts.getMapArray(); + + //Organizing report by project + Map>> projectMap = new HashMap<>(); + int animalsWaterMeaning = 0; + Map>> lixitMap = new HashMap<>(); + int animalsInLixit = 0; + for(Map mapItem : totalWaterForDay){ + int projectNum = ConvertHelper.convert(mapItem.get("project"),Integer.class); + List> waterTotalsFromDb; + if (ConvertHelper.convert(mapItem.get("currentWaterCondition"),String.class).equals("regulated")){ + if (!projectMap.containsKey(projectNum)){ + waterTotalsFromDb = new ArrayList<>(); + projectMap.put(projectNum,waterTotalsFromDb); + }else{ + waterTotalsFromDb = projectMap.get(projectNum); + } + waterTotalsFromDb.add(mapItem); + animalsWaterMeaning++; + }else{ + if (!lixitMap.containsKey(projectNum)){ + waterTotalsFromDb = new ArrayList<>(); + lixitMap.put(projectNum,waterTotalsFromDb); + }else{ + waterTotalsFromDb = lixitMap.get(projectNum); + } + waterTotalsFromDb.add(mapItem); + animalsInLixit++; + + } + } + + msg.append("WARNING: There are " + animalsWaterMeaning + " animals that have remaining water for today.
\n"); + + msg.append(""); + msg.append("" + + "" + + "" + + "" + + "\n"); + + for (Map.Entry>> entry : projectMap.entrySet()){ + List> totalWaterByProject = entry.getValue(); + String mlsPerKg; + String totalWater; + for(Map mapItem : totalWaterByProject){ + LocalDateTime objectDateTime = ConvertHelper.convert(mapItem.get("date"),Date.class).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + mlsPerKg = ConvertHelper.convert(mapItem.get("mlsPerKg"),String.class) == null ? " " : ConvertHelper.convert(mapItem.get("mlsPerKg"),String.class); + totalWater = ConvertHelper.convert(mapItem.get("TotalWater"),String.class) == null ? " " : ConvertHelper.convert(mapItem.get("TotalWater"),String.class); + + msg.append("" ); + + } + } + + + + + msg.append("
ProjectIdDatemlsPerKgTotal Water Given
" + ConvertHelper.convert(mapItem.get("project"),Integer.class) + + " " + ConvertHelper.convert(mapItem.get("Id"),String.class) + + " " + objectDateTime.format(formatter) + + " " + mlsPerKg + + " " + totalWater + +"
"); + msg.append("

Click here to view them
\n\n"); msg.append("


\n\n"); - final GUID localtaskId = new GUID(); - - try{ - - //TableInfo tasksTable = getEHRSchema(c, u).getTable("tasks"); - List> tasks = new ArrayList<>(); - UserSchema us = QueryService.get().getUserSchema(u, c, "ehr"); - TableInfo tasksTable = us.getTable("tasks"); - //String maxtask = tasksTable.getFromSQL("SELECT MAX(taskid)+1 FROM ehr.tasks").toString(); - - //).getColumn("taskid"); - Map task = new CaseInsensitiveHashMap<>(); - - //task.put("rowid", 506360); - task.put("taskid",localtaskId.toString()); - task.put("qcstate", 4); - task.put("category", "Task"); - task.put("contaier", null); - task.put("title", "Water from Notifiaction"); - task.put("formtype","water_given"); - tasks.add(task); - //Map extraContext = getExtraContext(); - //extraContext.put("skipRequestInPastCheck", true);
 - BatchValidationException errors = new BatchValidationException(); - tasksTable.getUpdateService().insertRows(u, c, tasks, errors, null, null); - if (errors.hasErrors()) - throw errors; + msg.append("INFO: There are " + animalsInLixit + " animals that are in Lixit condition.
\n"); + msg.append(""); + msg.append("" + + "" + + "" + + "\n"); + + for (Map.Entry>> entry : lixitMap.entrySet()){ + List> AnimalsInLixit = entry.getValue(); + String condition; + + for(Map mapItem : AnimalsInLixit){ + LocalDateTime objectDateTime = ConvertHelper.convert(mapItem.get("date"),Date.class).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + condition = ConvertHelper.convert(mapItem.get("currentWaterCondition"),String.class) == null ? " " : ConvertHelper.convert(mapItem.get("currentWaterCondition"),String.class); + + msg.append("" ); + } } - catch (Exception e){ - //Unsure why these are getting swallowed and not logged? - _log.error(e.getMessage(), e); - //throw e; + msg.append("
ProjectIdDateCondition at Time
" + ConvertHelper.convert(mapItem.get("project"),Integer.class) + + " " + ConvertHelper.convert(mapItem.get("Id"),String.class) + + " " + objectDateTime.format(formatter) + + " " + condition + +"
"); + } + } + + protected void findAnimalsWithWaterEntries(final Container c, final User u, final StringBuilder msg, final int numberOfDates){ + + LocalDate date = LocalDate.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + int datesInPast = numberOfDates; + + for (int i = 0; i parameters = new CaseInsensitiveHashMap<>(); + parameters.put("CheckDate", date); + TableInfo ti = QueryService.get().getUserSchema(u, c, "study").getTable("waterScheduledAnimalWithOutEntries"); + TableSelector ts = new TableSelector(ti, PageFlowUtil.set("id","project"), null, null); + ts.setNamedParameters(parameters); + + long total = ts.getRowCount(); + + if (total == 0) + { + msg.append("All regulated animals have at least one entries for "+ date.getDayOfWeek().toString() +" ("+ date.format(formatter) + ").
"); + } + else + { + msg.append("There are " + total + " animals in the system that have no records in water given dataset for " + date.getDayOfWeek().toString() +" ("+ date.format(formatter) + ").
"); + Map[] animalsWithOutEntries = ts.getMapArray(); + for (Map mapItem : animalsWithOutEntries) + { + msg.append(ConvertHelper.convert(mapItem.get("project"), Integer.class) + " " + ConvertHelper.convert(mapItem.get("Id"), String.class) + "
"); + + } + msg.append("
"); } - ts.forEach(new Selector.ForEachBlock(){ + date = date.minusDays(1); + } + + + } + protected void findWaterOrdersNotCompleted(Container c,User u, StringBuilder msg, final LocalDateTime maxDate, boolean includeFuture){ + LocalDateTime currentTime = maxDate; + LocalDateTime amThreshold = LocalDateTime.now().withHour(10).withMinute(30); + + //Setting interval to start the water schedule, the system generates the calendar thirty days before + LocalDateTime roundedMax = maxDate; + roundedMax = roundedMax.plusDays(-5).truncatedTo(ChronoUnit.DAYS); + + //final String intervalLength = "10"; + + //Sending parameters to the query that generates the water schedule from water orders and water amounts + Map parameters = new CaseInsensitiveHashMap<>(); + parameters.put("NumDays", 6); + //static DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; + String dateFormat = roundedMax.format(DateTimeFormatter.ISO_DATE_TIME); + parameters.put("StartDate", roundedMax.toString()); + + TableInfo ti = QueryService.get().getUserSchema(u,c,"study").getTable("waterScheduleCoalesced"); + SimpleFilter filter = new SimpleFilter(FieldKey.fromString("QCState/label"),"Scheduled",CompareType.EQUAL); + + if (includeFuture){ + LocalDateTime futureDate = maxDate; + futureDate = futureDate.plusDays(1).truncatedTo(ChronoUnit.DAYS); - @Override - public void exec (ResultSet rs) - { - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); + filter.addCondition(FieldKey.fromString("dateOrdered"),futureDate, CompareType.LTE); + filter.addCondition(FieldKey.fromString("dateOrdered"),currentTime, CompareType.GT); - try{ + }else{ + filter.addCondition(FieldKey.fromString("dateOrdered"),currentTime, CompareType.LTE); + } + + filter.addCondition(FieldKey.fromString("dateOrdered"), roundedMax,CompareType.DATE_GTE); + // filter.addCondition(FieldKey.fromString("assignedTo"), "animalcare"); + filter.addCondition(FieldKey.fromString("actionRequired"),true,CompareType.EQUAL); + + Set columns = new HashSet<>(); + columns.add(FieldKey.fromString("Id")); + columns.add(FieldKey.fromString("dateOrdered")); + columns.add(FieldKey.fromString("volume")); + columns.add(FieldKey.fromString("frequencyMeaning")); + columns.add(FieldKey.fromString("displaytimeofday")); + columns.add(FieldKey.fromString("assignedTo")); - //TableInfo tasksTable = getEHRSchema(c, u).getTable("tasks"); - List> tasks = new ArrayList<>(); - UserSchema us = QueryService.get().getUserSchema(u, c, "study"); - TableInfo waterTask = us.getTable("water_given"); - Map task = new CaseInsensitiveHashMap<>(); - //task.put("rowid", 506360); - task.put("taskid",localtaskId.toString()); - task.put("qcstate", 10); - task.put("amount", null); - task.put("date", cal.getTime()); - task.put("Id", rs.getString("Id")); - task.put("assignto", "laboratory" ); - //task.put("title", "Water from Notifiaction"); - //task.put("formtype","water_given"); - tasks.add(task); - //Map extraContext = getExtraContext(); - //extraContext.put("skipRequestInPastCheck", true);
 - BatchValidationException errors = new BatchValidationException(); - waterTask.getUpdateService().insertRows(u, c, tasks, errors, null,null); - if (errors.hasErrors()) - throw errors; - } - catch (Exception e){ - //Unsure why these are getting swallowed and not logged? - _log.error(e.getMessage(), e); - //throw e; + final Map colMap = QueryService.get().getColumns(ti, columns); - } - } - } + TableSelector ts = new TableSelector(ti,colMap.values(), filter,null); + ts.setNamedParameters(parameters); + long total = ts.getRowCount(); - ); + String timeofday = "AM"; + if (currentTime.isAfter(amThreshold)){ + timeofday = "PM"; + } + if (total == 0 && !includeFuture){ + msg.append("All " + timeofday + " water orders are completed"); + }else if(total > 0){ + if(includeFuture && timeofday.equals("PM")){ + msg.append("

There are "+total+ " water orders that are scheduled for today and have not been completed
"); + }else{ + msg.append("

WARNING: There are "+total+ " water orders that have not been completed
"); + } + Map[] waterOrdersScheduled = ts.getMapArray(); + List > animalCareWaters = new ArrayList<>(); + List> researchStaffWaters = new ArrayList<>(); + List> spiWaters = new ArrayList<>(); + + + if(waterOrdersScheduled.length >0){ + for(Map waterSchedule : waterOrdersScheduled){ + String assignedTo = ConvertHelper.convert(waterSchedule.get("assignedTo"),String.class); + if (assignedTo.equals("animalcare")){ + animalCareWaters.add(waterSchedule); + }else if (assignedTo.equals("researchstaff")){ + researchStaffWaters.add(waterSchedule); + }else if (assignedTo.equals("spi")){ + spiWaters.add(waterSchedule); + } + } + StringBuilder htmlTable; + if (!animalCareWaters.isEmpty()) + { + htmlTable = createTable(animalCareWaters, "Animal Care"); + msg.append(htmlTable); + } + if (!researchStaffWaters.isEmpty()) + { + htmlTable = createTable(researchStaffWaters, "Research Staff"); + msg.append(htmlTable); + } + if (!spiWaters.isEmpty()) + { + htmlTable = createTable(spiWaters, "SPI"); + msg.append(htmlTable); + } + } + msg.append("
Click here to view schedule waters

"); } + + + } + private StringBuilder createTable (List> listOfDBObjects, String assignedTo){ + StringBuilder returnTable = new StringBuilder(); + returnTable.append("
"+ assignedTo +""); + returnTable.append(""); + returnTable.append("" + + "" + + "" + + "" + + "" + + "\n"); + for (Map dbObject : listOfDBObjects){ + LocalDateTime objectDateTime = ConvertHelper.convert(dbObject.get("dateOrdered"),Date.class).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + + returnTable.append("" ); + } + returnTable.append("
IdDate OrderedVolumeTime of DayFrequencyAssigned To
" + ConvertHelper.convert(dbObject.get("Id"),String.class) + + " " + objectDateTime.format(formatter) + + " " + ConvertHelper.convert(dbObject.get("volume"),String.class) + + " " + ConvertHelper.convert(dbObject.get("displaytimeofday"),String.class) + + " " + ConvertHelper.convert(dbObject.get("frequencyMeaning"),String.class) + + " " + ConvertHelper.convert(dbObject.get("assignedTo"),String.class) +"
"); + return returnTable; } + +} + diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterOrdersAlertNotification.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterOrdersAlertNotification.java index f9ab6bd88..f98ad4dc6 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterOrdersAlertNotification.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterOrdersAlertNotification.java @@ -26,7 +26,7 @@ * Author: Daniel Nicolalde * Date: 2021-07-28 */ -public class WaterOrdersAlertNotification extends AbstractEHRNotification +public class WaterOrdersAlertNotification extends WaterMonitoringNotification { public WaterOrdersAlertNotification(Module owner){ super(owner); @@ -49,10 +49,6 @@ public String getCronString() return "0 0 10,13,15,17,19 * * ?"; } - public String getCategory(){ - return "Husbandry"; - } - public String getScheduleDescription() { return "daily at 1000, 1300, 1500, 1700, 1900"; @@ -62,146 +58,17 @@ public String getScheduleDescription() public String getMessageBodyHTML(Container c, User u) { StringBuilder msg = new StringBuilder(); + int numDays = 1; final Date now = new Date(); msg.append("This email contains any water orders not marked as completed. It was run on: " + _dateFormat.format(now) + " at " + _timeFormat.format(now) + ".

"); + //Check animals that did not get any water for today and the last five days. + findAnimalsWithWaterEntries(c,u,msg,numDays); findWaterOrdersNotCompleted(c,u,msg,LocalDateTime.now(), false); findWaterOrdersNotCompleted(c,u,msg,LocalDateTime.now(), true); return msg.toString(); } - - private void findWaterOrdersNotCompleted(Container c,User u, StringBuilder msg, final LocalDateTime maxDate, boolean includeFuture){ - LocalDateTime currentTime = maxDate; - LocalDateTime amThreshold = LocalDateTime.now().withHour(10).withMinute(30); - - //Setting interval to start the water schedule, the system generates the calendar thirty days before - LocalDateTime roundedMax = maxDate; - roundedMax = roundedMax.plusDays(-5).truncatedTo(ChronoUnit.DAYS); - - //final String intervalLength = "10"; - - //Sending parameters to the query that generates the water schedule from water orders and water amounts - Map parameters = new CaseInsensitiveHashMap<>(); - parameters.put("NumDays", 6); - //static DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; - String dateFormat = roundedMax.format(DateTimeFormatter.ISO_DATE_TIME); - parameters.put("StartDate", roundedMax.toString()); - - TableInfo ti = QueryService.get().getUserSchema(u,c,"study").getTable("waterScheduleCoalesced"); - SimpleFilter filter = new SimpleFilter(FieldKey.fromString("QCState/label"),"Scheduled",CompareType.EQUAL); - - if (includeFuture){ - LocalDateTime futureDate = maxDate; - futureDate = futureDate.plusDays(1).truncatedTo(ChronoUnit.DAYS); - - filter.addCondition(FieldKey.fromString("dateOrdered"),futureDate, CompareType.LTE); - filter.addCondition(FieldKey.fromString("dateOrdered"),currentTime, CompareType.GT); - - }else{ - filter.addCondition(FieldKey.fromString("dateOrdered"),currentTime, CompareType.LTE); - } - - filter.addCondition(FieldKey.fromString("dateOrdered"), roundedMax,CompareType.DATE_GTE); - // filter.addCondition(FieldKey.fromString("assignedTo"), "animalcare"); - filter.addCondition(FieldKey.fromString("actionRequired"),true,CompareType.EQUAL); - - Set columns = new HashSet<>(); - columns.add(FieldKey.fromString("Id")); - columns.add(FieldKey.fromString("dateOrdered")); - columns.add(FieldKey.fromString("volume")); - columns.add(FieldKey.fromString("frequencyMeaning")); - columns.add(FieldKey.fromString("displaytimeofday")); - columns.add(FieldKey.fromString("assignedTo")); - - - - final Map colMap = QueryService.get().getColumns(ti, columns); - - - TableSelector ts = new TableSelector(ti,colMap.values(), filter,null); - ts.setNamedParameters(parameters); - long total = ts.getRowCount(); - - String timeofday = "AM"; - if (currentTime.isAfter(amThreshold)){ - timeofday = "PM"; - } - - if (total == 0 && !includeFuture){ - msg.append("All " + timeofday + " water orders are completed"); - }else if(total > 0){ - if(includeFuture && timeofday.equals("PM")){ - msg.append("

There are "+total+ " water orders that are scheduled for today and have not been completed
"); - }else{ - msg.append("

WARNING: There are "+total+ " water orders that have not been completed
"); - } - - Map[] waterOrdersScheduled = ts.getMapArray(); - List > animalCareWaters = new ArrayList<>(); - List> researchStaffWaters = new ArrayList<>(); - List> spiWaters = new ArrayList<>(); - - - if(waterOrdersScheduled.length >0){ - for(Map waterSchedule : waterOrdersScheduled){ - String assignedTo = ConvertHelper.convert(waterSchedule.get("assignedTo"),String.class); - if (assignedTo.equals("animalcare")){ - animalCareWaters.add(waterSchedule); - }else if (assignedTo.equals("researchstaff")){ - researchStaffWaters.add(waterSchedule); - }else if (assignedTo.equals("spi")){ - spiWaters.add(waterSchedule); - } - } - StringBuilder htmlTable; - if (!animalCareWaters.isEmpty()) - { - htmlTable = createTable(animalCareWaters, "Animal Care"); - msg.append(htmlTable); - } - if (!researchStaffWaters.isEmpty()) - { - htmlTable = createTable(researchStaffWaters, "Research Staff"); - msg.append(htmlTable); - } - if (!spiWaters.isEmpty()) - { - htmlTable = createTable(spiWaters, "SPI"); - msg.append(htmlTable); - } - } - msg.append("
Click here to view schedule waters

"); - } - } - - private StringBuilder createTable (List> listOfDBObjects, String assignedTo){ - StringBuilder returnTable = new StringBuilder(); - returnTable.append("
"+ assignedTo +""); - returnTable.append(""); - returnTable.append("" + - "" + - "" + - "" + - "" + - "\n"); - for (Map dbObject : listOfDBObjects){ - LocalDateTime objectDateTime = ConvertHelper.convert(dbObject.get("dateOrdered"),Date.class).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); - - returnTable.append("" ); - } - returnTable.append("
IdDate OrderedVolumeTime of DayFrequencyAssigned To
" + ConvertHelper.convert(dbObject.get("Id"),String.class) - + " " + objectDateTime.format(formatter) - + " " + ConvertHelper.convert(dbObject.get("volume"),String.class) - + " " + ConvertHelper.convert(dbObject.get("displaytimeofday"),String.class) - + " " + ConvertHelper.convert(dbObject.get("frequencyMeaning"),String.class) - + " " + ConvertHelper.convert(dbObject.get("assignedTo"),String.class) +"
"); - - return returnTable; - - } } From c9cf66b8afeccc8e80305d943e34ae6decb77f4c Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Tue, 6 Jun 2023 09:15:14 -0500 Subject: [PATCH 03/13] Adding location using labkey study lookup in .qview.xml --- WNPRC_EHR/resources/queries/study/waterTotalByDate.sql | 6 +----- .../resources/queries/study/waterTotalByDate/.qview.xml | 1 + .../resources/queries/study/waterTotalByDateWithWeight.sql | 1 - .../queries/study/waterTotalByDateWithWeight/.qview.xml | 1 + .../org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp | 2 +- 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql b/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql index def2bdf4d..0a4188340 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql @@ -17,9 +17,7 @@ SELECT waterSummary.performedConcat, odrwc.currentWaterCondition, waterSummary.project, - waterSummary.qcstate, - waterSummary.curRoom, - waterSummary.curCage + waterSummary.qcstate FROM ehr_lookups.calendar cal LEFT OUTER JOIN (SELECT drwc.Id AS Id, @@ -45,8 +43,6 @@ LEFT OUTER JOIN( COALESCE(GROUP_CONCAT(iwg.performedby, ';'),'') AS performedConcat, MAX(iwg.project) AS project, COALESCE(MAX(iwg.qcstate),1) AS qcstate, - MAX(iwg.id.curLocation.room) as curRoom, - MAX(iwg.id.curLocation.cage) as curCage, FROM study.waterGiven iwg WHERE qcstate.label = 'Completed' GROUP BY iwg.Id, CAST(iwg.date AS DATE) )waterSummary diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDate/.qview.xml b/WNPRC_EHR/resources/queries/study/waterTotalByDate/.qview.xml index 3b6994c6c..ca412aa40 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDate/.qview.xml +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDate/.qview.xml @@ -1,6 +1,7 @@ + diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql index 8f1af851d..0163b0b5e 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql @@ -19,7 +19,6 @@ SELECT wtbd.Id as Id, waterScheduledAnimalsOuter.project, wtbd.performedConcat, wtbd.qcstate, - wtbd.curRoom || '-' || wtbd.curCage AS location, 'waterTotal' AS dataSource FROM study.waterTotalByDate wtbd diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml index 0c1b84f68..433d247c3 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml @@ -1,6 +1,7 @@ + diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp index dc987b96b..b03415631 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp @@ -824,7 +824,7 @@ $('#waterInformation').collapse('hide'); $('#waterTotalInformation').collapse('show'); WebUtils.VM.taskDetails["volume"](info.event.extendedProps.rawRowData.TotalWater.toString()); - WebUtils.VM.taskDetails["location"](info.event.extendedProps.rawRowData.location.toString()); + WebUtils.VM.taskDetails["location"](info.event.extendedProps.rawRowData["Id/curLocation/location"].toString()); }else{ $('#waterInformation').collapse('show'); $('#waterTotalInformation').collapse('hide'); From ece11a3e15d49661a816d4b9da0378caeb7c8eee Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Wed, 7 Jun 2023 17:09:29 -0500 Subject: [PATCH 04/13] Adding Lixit to TotalWater to the row in the event calendar --- .../src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp | 1 + 1 file changed, 1 insertion(+) diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp index b03415631..f247950b4 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp @@ -721,6 +721,7 @@ parsedTotalWater = row.TotalWater; eventTitle = row.Id + " Total: " + parsedTotalWater; }else{ + row.TotalWater = 'Lixit' eventTitle = row.Id + " on Lixit"; } From cfdae98c8e06a6407e6fb3896f268fe82516785e Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Mon, 12 Jun 2023 16:39:31 -0500 Subject: [PATCH 05/13] Using conditionattime to modify the water Total details panel. --- .../queries/study/WaterScheduleWithWeight.sql | 1 + .../study/WaterScheduleWithWeight/.qview.xml | 32 +++++++ .../pages/husbandry/WaterCalendar.jsp | 83 +++++++++++-------- 3 files changed, 82 insertions(+), 34 deletions(-) create mode 100644 WNPRC_EHR/resources/queries/study/WaterScheduleWithWeight/.qview.xml diff --git a/WNPRC_EHR/resources/queries/study/WaterScheduleWithWeight.sql b/WNPRC_EHR/resources/queries/study/WaterScheduleWithWeight.sql index 95006540b..44e7abf98 100644 --- a/WNPRC_EHR/resources/queries/study/WaterScheduleWithWeight.sql +++ b/WNPRC_EHR/resources/queries/study/WaterScheduleWithWeight.sql @@ -13,6 +13,7 @@ SELECT provideFruit AS provideFruit, provideFruitTitle AS provideFruitTitle, dataSource AS dataSource, + waterSource AS conditionAtTime, assignedTo AS assignedToCoalesced, assignedToTitle AS assignedToTitleCoalesced, frequency AS frequencyCoalesced, diff --git a/WNPRC_EHR/resources/queries/study/WaterScheduleWithWeight/.qview.xml b/WNPRC_EHR/resources/queries/study/WaterScheduleWithWeight/.qview.xml new file mode 100644 index 000000000..94d6b88d0 --- /dev/null +++ b/WNPRC_EHR/resources/queries/study/WaterScheduleWithWeight/.qview.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp index f247950b4..ee6024cdd 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp @@ -214,7 +214,7 @@ function clearSelectedEvent() { selectedEvent = {}; for (let key in WebUtils.VM.taskDetails) { - if (key != 'animalLink' && key != 'displayDate' && key != 'mlsPerKgCal') { + if (key != 'animalLink' && key != 'displayDate' && key != 'mlsPerKgCal' && key != 'conditionAtTimeValue') { WebUtils.VM.taskDetails[key](null); } } @@ -298,7 +298,9 @@
Date:
{{displayDate}}
Animal ID:
{{Id}}
Current Location:
{{location}}
-
Total Volume:
{{volume}} ml
+
Total Volume:
{{volume}} ml + On Lixit +
ml Per Kg:
{{mlsPerKg}}
@@ -604,11 +606,12 @@ eventSources:[ { events: function (fetchInfo, successCallback, failureCallback) { - console.log(" startStr" + fetchInfo.startStr); + console.log(" startStr " + fetchInfo.startStr); + console.log(" startStr " + fetchInfo.endStr); console.log("inside eventSource " + allowProjects); - if ($animalId == 'undefined' || $animalId == "null"){ + if ($animalId === 'undefined' || $animalId === "null" || $animalId === ''){ let queryConfig ={}; queryConfig = queryConfigFunc(fetchInfo,isSuperUser,isAnimalCare); @@ -702,11 +705,11 @@ }, { events:function (fetchInfo, successCallback, failureCallback) { - if ($animalId == 'undefined' || $animalId == "null" || $animalId == ''){ + if ($animalId === 'undefined' || $animalId === "null" || $animalId === ''){ WebUtils.API.selectRows("study", "waterTotalByDateWithWeight", { "date~gte": fetchInfo.start.format('Y-m-d'), - "date~lte": fetchInfo.end.format('Y-m-d') - //"TotalWater~isnonblank":true + "date~lte": fetchInfo.end.format('Y-m-d'), + "date~lt": new Date() }).then(function (data) { var events = data.rows; @@ -724,7 +727,6 @@ row.TotalWater = 'Lixit' eventTitle = row.Id + " on Lixit"; } - var eventObj = { id : LABKEY.Utils.generateUUID(), title: eventTitle, @@ -733,9 +735,6 @@ textColor: '#000000', rawRowData: row }; - - - if (row.mlsPerKg >= row.InnerMlsPerKg || row.conditionAtTime === 'lixit'){ eventObj.color = '#FFFFFF'; }else{ @@ -745,7 +744,7 @@ }) ); failureCallback((function (data){ - console.log("error from waterPrePivot general"); + console.log("error from waterTotalByDateWithWeight"); })) }) @@ -755,31 +754,42 @@ WebUtils.API.selectRows("study", "waterTotalByDateWithWeight", { "date~gte": fetchInfo.start.format('Y-m-d'), "date~lte": fetchInfo.end.format('Y-m-d'), - "TotalWater~isnonblank":true, + "date~lt": new Date(), "Id~in": $animalId }).then(function (data) { var events = data.rows; - successCallback(events.map(function (row) { - let parsedTotalWater = 0; - if(row.TotalWater !== null){ - parsedTotalWater = row.TotalWater; - } - var eventObj = { - id : LABKEY.Utils.generateUUID(), - title: row.Id + " Total: " + parsedTotalWater, - start: new Date(row.date), - textColor: '#000000', - allDay: true, - rawRowData: row - }; - if (row.mlsPerKg >= row.InnerMlsPerKg){ - eventObj.color = '#FFFFFF'; - }else{ - eventObj.color = '#EE2020' - } + successCallback( + events.map(function (row) { + let parsedTotalWater = 0; + let eventTitle = ""; + if(row.conditionAtTime === 'regulated') { + if (row.TotalWater === null) { + row.TotalWater = 'none'; + } + parsedTotalWater = row.TotalWater; + eventTitle = row.Id + " Total: " + parsedTotalWater; + }else{ + row.TotalWater = 'Lixit' + eventTitle = row.Id + " on Lixit"; + + } + var eventObj = { + id : LABKEY.Utils.generateUUID(), + title: eventTitle, + start: new Date(row.date), + textColor: '#000000', + allDay: true, + rawRowData: row + }; + if (row.mlsPerKg >= row.InnerMlsPerKg || row.conditionAtTime === 'lixit'){ + eventObj.color = '#FFFFFF'; + }else{ + eventObj.color = '#EE2020' + } return eventObj; - })); + }) + ); failureCallback((function (data){ console.log("error from waterTotalByDateWithWeight"); })) @@ -980,7 +990,8 @@ frequencyMeaningCoalesced: ko.observable(), displaytimeofday: ko.observable(), rawDate: ko.observable(), - mlsPerKg: ko.observable() + mlsPerKg: ko.observable(), + conditionAtTime: ko.observable() }, form: { lsidForm: ko.observable(), @@ -1282,7 +1293,11 @@ }); WebUtils.VM.taskDetails.mlsPerKgCal = ko.pureComputed(function(){ - return !(WebUtils.VM.taskDetails.mlsPerKg() >= 20) + return !(WebUtils.VM.taskDetails.mlsPerKg() >= 20 || WebUtils.VM.taskDetails.conditionAtTime() === 'lixit') + }); + + WebUtils.VM.taskDetails.conditionAtTimeValue = ko.pureComputed(function(){ + return WebUtils.VM.taskDetails.conditionAtTime(); }); //Updating all the records of the form with data coming from the taskDeatils panel From 1dc1e0046dd458fd7d87e8568bd9124e7b40fa39 Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Tue, 20 Jun 2023 17:13:54 -0500 Subject: [PATCH 06/13] Adding location to the notification. --- ...graphicsMostRecentWaterCondition.query.xml | 2 +- .../demographicsMostRecentWaterCondition.sql | 6 +++- ...terScheduledAnimalWithOutEntries.query.xml | 33 +++++++++++++++++++ .../waterScheduledAnimalWithOutEntries.sql | 15 +++++++-- .../.qview.xml | 11 +++++++ .../WaterMonitoringNotification.java | 26 +++++++++++++-- 6 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries.query.xml create mode 100644 WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries/.qview.xml diff --git a/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.query.xml b/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.query.xml index 871d67700..710a31cf6 100644 --- a/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.query.xml +++ b/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.query.xml @@ -1,7 +1,7 @@ - +
diff --git a/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.sql b/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.sql index 099d2ce24..7e0e6de18 100644 --- a/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.sql +++ b/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.sql @@ -2,6 +2,7 @@ SELECT wsa.id, wsa.MostRecentWaterConditionDate, +wsa.room || '-' || wsa.cage as location, ( SELECT wsainner.project FROM study.waterScheduledAnimals wsainner @@ -23,7 +24,10 @@ wsa.MostRecentWaterConditionDate, FROM( SELECT wsaouter.id as id, - max(wsaouter.date) AS MostRecentWaterConditionDate + max(wsaouter.date) AS MostRecentWaterConditionDate, + max(wsaouter.id.dataset.activehousing.room) AS room, + max(wsaouter.id.dataset.activehousing.cage) AS cage, + FROM study.waterScheduledAnimals wsaouter WHERE wsaouter.qcstate.publicdata = true AND wsaouter.condition IS NOT NULL GROUP BY wsaouter.id diff --git a/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries.query.xml b/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries.query.xml new file mode 100644 index 000000000..e689ffea3 --- /dev/null +++ b/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries.query.xml @@ -0,0 +1,33 @@ + + + +
+ + + + + + + + + + + Date + yyyy-MM-dd + + + Project + + + Location + + ehr_lookups + cage + location + + + +
+
+
+
\ No newline at end of file diff --git a/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries.sql b/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries.sql index d70a8d1d5..2c59fc39c 100644 --- a/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries.sql +++ b/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries.sql @@ -1,7 +1,18 @@ PARAMETERS(CheckDate TIMESTAMP) -SELECT DISTINCT(id), CheckDate AS date, project AS project FROM - (SELECT a.id, a.MostRecentWaterCondition, a.MostRecentWaterConditionDate, a.project FROM study.demographicsMostRecentWaterCondition a +SELECT + DISTINCT(id), + CheckDate AS date, + project AS project, + location as location +FROM + (SELECT + a.id, + a.MostRecentWaterCondition, + a.MostRecentWaterConditionDate, + a.project, + a.location + FROM study.demographicsMostRecentWaterCondition a WHERE NOT EXISTS ( SELECT 1 FROM study.waterTotalByDate b WHERE a.id = b.id AND b.date = CheckDate AND b.TotalWater IS NOT NULL diff --git a/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries/.qview.xml b/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries/.qview.xml new file mode 100644 index 000000000..bba1d192b --- /dev/null +++ b/WNPRC_EHR/resources/queries/study/waterScheduledAnimalWithOutEntries/.qview.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java index 3b2d16cfa..b8bf721e5 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java @@ -113,14 +113,28 @@ protected void findAnimalsWithEnoughWater(final Container c, final User u, final Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); + TableInfo waterTotalByDateWithWeightReport = QueryService.get().getUserSchema(u,c,"study").getTable("waterTotalByDateWithWeight"); + SimpleFilter.OrClause orClause = new SimpleFilter.OrClause(); orClause.addClause(new SimpleFilter(FieldKey.fromString("mlsPerKg"), 20, CompareType.LT).getClauses().get(0)); orClause.addClause(new SimpleFilter(FieldKey.fromString("mlsPerKg"),null, CompareType.ISBLANK).getClauses().get(0)); SimpleFilter filter = new SimpleFilter(FieldKey.fromString("date"), cal.getTime(), CompareType.DATE_EQUAL); filter.addClause(orClause); + Set colKeys = new HashSet<>(); + colKeys.add(FieldKey.fromString("Id")); + colKeys.add(FieldKey.fromString("date")); + colKeys.add(FieldKey.fromString("mlsPerKg")); + colKeys.add(FieldKey.fromString("TotalWater")); + colKeys.add(FieldKey.fromString("project")); + colKeys.add(FieldKey.fromString("currentWaterCondition")); + colKeys.add(FieldKey.fromString("Id/curLocation/location")); + + final Map columns = QueryService.get().getColumns(waterTotalByDateWithWeightReport, colKeys); + - TableSelector ts = new TableSelector(getStudySchema(c, u).getTable("waterTotalByDateWithWeight"),PageFlowUtil.set("Id","date","mlsPerKg","TotalWater","project","currentWaterCondition"), filter, null); + TableSelector ts = new TableSelector(waterTotalByDateWithWeightReport, columns.values(), filter, null); + //TableSelector ts = new TableSelector(getStudySchema(c, u).getTable("waterTotalByDateWithWeight"),PageFlowUtil.set("Id","date","mlsPerKg","TotalWater","project","currentWaterCondition"), filter, null); long count = ts.getRowCount(); if (count > 0) { @@ -163,6 +177,7 @@ protected void findAnimalsWithEnoughWater(final Container c, final User u, final msg.append("Project" + "Id" + "Date" + + "Location" + "mlsPerKg" + "Total Water Given\n"); @@ -180,6 +195,7 @@ protected void findAnimalsWithEnoughWater(final Container c, final User u, final msg.append("" + ConvertHelper.convert(mapItem.get("project"),Integer.class) + " " + ConvertHelper.convert(mapItem.get("Id"),String.class) + " " + objectDateTime.format(formatter) + + " " + ConvertHelper.convert(mapItem.get("id_fs_curlocation_fs_location"),String.class) + " " + mlsPerKg + " " + totalWater +"" ); @@ -199,6 +215,7 @@ protected void findAnimalsWithEnoughWater(final Container c, final User u, final msg.append("Project" + "Id" + "Date" + + "Location" + "Condition at Time\n"); for (Map.Entry>> entry : lixitMap.entrySet()){ @@ -214,6 +231,7 @@ protected void findAnimalsWithEnoughWater(final Container c, final User u, final msg.append("" + ConvertHelper.convert(mapItem.get("project"),Integer.class) + " " + ConvertHelper.convert(mapItem.get("Id"),String.class) + " " + objectDateTime.format(formatter) + + " " + ConvertHelper.convert(mapItem.get("id_fs_curlocation_fs_location"),String.class) + " " + condition +"" ); } @@ -234,7 +252,8 @@ protected void findAnimalsWithWaterEntries(final Container c, final User u, fin parameters.put("CheckDate", date); TableInfo ti = QueryService.get().getUserSchema(u, c, "study").getTable("waterScheduledAnimalWithOutEntries"); - TableSelector ts = new TableSelector(ti, PageFlowUtil.set("id","project"), null, null); + TableSelector ts = new TableSelector(ti,PageFlowUtil.set("Id","project","location"), null, null); + //TableSelector ts = new TableSelector(ti, null, null); ts.setNamedParameters(parameters); long total = ts.getRowCount(); @@ -246,10 +265,11 @@ protected void findAnimalsWithWaterEntries(final Container c, final User u, fin else { msg.append("There are " + total + " animals in the system that have no records in water given dataset for " + date.getDayOfWeek().toString() +" ("+ date.format(formatter) + ").
"); + msg.append("Project - AnimalID - Location
"); Map[] animalsWithOutEntries = ts.getMapArray(); for (Map mapItem : animalsWithOutEntries) { - msg.append(ConvertHelper.convert(mapItem.get("project"), Integer.class) + " " + ConvertHelper.convert(mapItem.get("Id"), String.class) + "
"); + msg.append(ConvertHelper.convert(mapItem.get("project"), Integer.class) + " " + ConvertHelper.convert(mapItem.get("Id"), String.class) + " " + ConvertHelper.convert(mapItem.get("location"), String.class)+ "
"); } msg.append("
"); From 2f253458969160667cc768043a7a22ca57c83b06 Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Wed, 5 Jul 2023 17:55:33 -0500 Subject: [PATCH 07/13] Adding last day for condition and improving display for taskid --- .../queries/study/waterTotalByDate.sql | 76 +++++++---- .../queries/study/waterTotalByDate/.qview.xml | 1 + .../study/waterTotalByDateWithWeight.sql | 2 + .../waterTotalByDateWithWeight/.qview.xml | 2 + .../WaterMonitoringNotification.java | 7 +- .../pages/husbandry/WaterCalendar.jsp | 119 ++++++++++++++---- 6 files changed, 153 insertions(+), 54 deletions(-) diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql b/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql index 0a4188340..ceab892c2 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql @@ -16,35 +16,57 @@ SELECT waterSummary.volumeGivenInProcedure, waterSummary.performedConcat, odrwc.currentWaterCondition, + odrwc.latestConditionDate, waterSummary.project, waterSummary.qcstate FROM ehr_lookups.calendar cal - LEFT OUTER JOIN (SELECT drwc.Id AS Id, - MIN(drwc.date) AS firstDate, - (SELECT wsainner.condition - FROM study.waterScheduledAnimals wsainner - WHERE drwc.id = wsainner.id - ORDER BY wsainner.date DESC LIMIT 1) AS currentWaterCondition - + LEFT OUTER JOIN ( + SELECT + drwc.Id AS Id, + MIN(drwc.date) AS firstDate, + (SELECT + wsainner.condition + FROM study.waterScheduledAnimals wsainner + WHERE drwc.id = wsainner.id + ORDER BY wsainner.date DESC LIMIT 1) AS currentWaterCondition, + (SELECT + wsa2inner.date + FROM study.waterScheduledAnimals wsa2inner + WHERE drwc.id = wsa2inner.id + ORDER BY wsa2inner.date DESC LIMIT 1) AS latestConditionDate FROM study.waterScheduledAnimals drwc - GROUP BY Id) odrwc - ON cal.targetdate >= CAST (odrwc.firstDate AS DATE) AND cal.targetdate <= curdate() -LEFT OUTER JOIN( - SELECT Id AS innerId, - CAST(iwg.date as DATE) as date, - COALESCE (SUM(CASE WHEN iwg.location = 'lab' THEN iwg.volume ELSE 0 END),0) AS volumeGivenInLabSub, - COALESCE (SUM(CASE WHEN iwg.location = 'animalRoom' THEN iwg.volume ELSE 0 END),0) AS volumeGivenInCage, - COALESCE (SUM(CASE WHEN iwg.location = 'imaging' THEN iwg.volume ELSE 0 END), 0) AS volumeGivenInImage, - COALESCE (SUM(CASE WHEN iwg.location = 'procedureRoom' THEN iwg.volume ELSE 0 END), 0) AS volumeGivenInProcedure, - COALESCE(SUM(iwg.volume), 0) AS TotalWater, - COALESCE(GROUP_CONCAT(iwg.provideFruit.title,'; '),'') AS provideFruit, - COALESCE(GROUP_CONCAT(iwg.remarks,'; '),'') AS remark, - COALESCE(GROUP_CONCAT(iwg.performedby, ';'),'') AS performedConcat, - MAX(iwg.project) AS project, - COALESCE(MAX(iwg.qcstate),1) AS qcstate, - FROM study.waterGiven iwg WHERE qcstate.label = 'Completed' - GROUP BY iwg.Id, CAST(iwg.date AS DATE) - )waterSummary -ON CAST(cal.targetdate AS DATE) = waterSummary.date AND waterSummary.innerId = Id -WHERE cal.targetdate <= curdate() AND Id IS NOT NULL \ No newline at end of file + GROUP BY Id + ) odrwc + ON cal.targetdate >= CAST (odrwc.firstDate AS DATE) + AND cal.targetdate <= curdate() + AND ( Id.death.date IS NULL OR cal.targetdate <= CAST(Id.death.date AS DATE) ) + + LEFT OUTER JOIN ( + SELECT + Id AS innerId, + CAST(iwg.date as DATE) as date, + COALESCE (SUM(CASE WHEN iwg.location = 'lab' THEN iwg.volume ELSE 0 END),0) AS volumeGivenInLabSub, + COALESCE (SUM(CASE WHEN iwg.location = 'animalRoom' THEN iwg.volume ELSE 0 END),0) AS volumeGivenInCage, + COALESCE (SUM(CASE WHEN iwg.location = 'imaging' THEN iwg.volume ELSE 0 END), 0) AS volumeGivenInImage, + COALESCE (SUM(CASE WHEN iwg.location = 'procedureRoom' THEN iwg.volume ELSE 0 END), 0) AS volumeGivenInProcedure, + COALESCE(SUM(iwg.volume), 0) AS TotalWater, + COALESCE(GROUP_CONCAT(iwg.provideFruit.title,'; '),'') AS provideFruit, + COALESCE(GROUP_CONCAT(iwg.remarks,'; '),'') AS remark, + COALESCE(GROUP_CONCAT(iwg.performedby, ';'),'') AS performedConcat, + MAX(iwg.project) AS project, + COALESCE(MAX(iwg.qcstate),1) AS qcstate, + FROM study.waterGiven iwg + WHERE + qcstate.label = 'Completed' + AND ( iwg.Id.death.date IS NULL OR CAST(iwg.date as DATE) <= iwg.Id.death.date ) + GROUP BY + iwg.Id, + CAST(iwg.date AS DATE) + )waterSummary +ON + CAST(cal.targetdate AS DATE) = waterSummary.date + AND waterSummary.innerId = Id +WHERE + cal.targetdate <= curdate() + AND Id IS NOT NULL diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDate/.qview.xml b/WNPRC_EHR/resources/queries/study/waterTotalByDate/.qview.xml index ca412aa40..0c4356d01 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDate/.qview.xml +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDate/.qview.xml @@ -13,6 +13,7 @@ +
diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql index 0163b0b5e..e5629c3fd 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql @@ -15,6 +15,8 @@ SELECT wtbd.Id as Id, wtbd.volumeGivenInProcedure, wtbd.currentWaterCondition, waterScheduledAnimalsOuter.condition AS conditionAtTime, + waterScheduledAnimalsOuter.endDate as endDateCondition, + CAST(waterScheduledAnimalsOuter.mlsperKg AS NUMERIC) AS InnerMlsPerKg, waterScheduledAnimalsOuter.project, wtbd.performedConcat, diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml index 433d247c3..84cd6ed64 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml @@ -1,7 +1,9 @@ + + diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java index b8bf721e5..f157eaeb5 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java @@ -18,6 +18,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.labkey.api.collections.CaseInsensitiveHashMap; +import org.labkey.api.data.BaseColumnInfo; import org.labkey.api.data.ColumnInfo; import org.labkey.api.data.CompareType; import org.labkey.api.data.Container; @@ -130,6 +131,8 @@ protected void findAnimalsWithEnoughWater(final Container c, final User u, final colKeys.add(FieldKey.fromString("currentWaterCondition")); colKeys.add(FieldKey.fromString("Id/curLocation/location")); + String curLocationJdbcName = BaseColumnInfo.jdbcRsNameFromName("Id/curLocation/location"); + final Map columns = QueryService.get().getColumns(waterTotalByDateWithWeightReport, colKeys); @@ -195,7 +198,7 @@ protected void findAnimalsWithEnoughWater(final Container c, final User u, final msg.append("" + ConvertHelper.convert(mapItem.get("project"),Integer.class) + " " + ConvertHelper.convert(mapItem.get("Id"),String.class) + " " + objectDateTime.format(formatter) - + " " + ConvertHelper.convert(mapItem.get("id_fs_curlocation_fs_location"),String.class) + + " " + ConvertHelper.convert(mapItem.get(curLocationJdbcName),String.class) + " " + mlsPerKg + " " + totalWater +"" ); @@ -231,7 +234,7 @@ protected void findAnimalsWithEnoughWater(final Container c, final User u, final msg.append("" + ConvertHelper.convert(mapItem.get("project"),Integer.class) + " " + ConvertHelper.convert(mapItem.get("Id"),String.class) + " " + objectDateTime.format(formatter) - + " " + ConvertHelper.convert(mapItem.get("id_fs_curlocation_fs_location"),String.class) + + " " + ConvertHelper.convert(mapItem.get(curLocationJdbcName),String.class) + " " + condition +"" ); } diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp index ee6024cdd..7f034de98 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp @@ -214,7 +214,9 @@ function clearSelectedEvent() { selectedEvent = {}; for (let key in WebUtils.VM.taskDetails) { - if (key != 'animalLink' && key != 'displayDate' && key != 'mlsPerKgCal' && key != 'conditionAtTimeValue') { + if ( key != 'animalLink' && key != 'displayDate' && + key != 'mlsPerKgCal' && key != 'conditionAtTimeValue' && + key != 'taskLink' && key != 'calculatedStatusValue') { WebUtils.VM.taskDetails[key](null); } } @@ -234,7 +236,7 @@
DataSource:
{{dataSource}}
-
Task ID:
{{taskid}}
+
Task ID:
{{taskid}}
Animal ID:
{{Id}}
Location:
{{location}}
Assigned to:
{{assignedToTitleCoalesced}}
@@ -294,21 +296,29 @@
-
DataSource:
{{dataSource}}
-
Date:
{{displayDate}}
-
Animal ID:
{{Id}}
-
Current Location:
{{location}}
-
Total Volume:
{{volume}} ml - On Lixit -
-
ml Per Kg:
{{mlsPerKg}}
+
DataSource:
+
{{dataSource}}
+
Date:
+
{{displayDate}}
+
Animal ID:
+
{{Id}}
+
+ Current Location: + Last Location: +
+
{{location}}
+
Total Volume:
+
+ {{volume}} ml + On Lixit + Dead +
+
ml Per Kg:
+
{{mlsPerKg}}
Animal received less than 20 milliliter per kilogram of weight on this day.
- - - @@ -711,6 +721,7 @@ "date~lte": fetchInfo.end.format('Y-m-d'), "date~lt": new Date() }).then(function (data) { + debugger; var events = data.rows; successCallback( @@ -718,20 +729,34 @@ let parsedTotalWater = 0; let eventTitle = ""; if( row.conditionAtTime === 'regulated' ){ - if ( row.TotalWater === null ){ + if ( row.TotalWater === null && row['Id/Demographics/calculated_status'] === 'Alive'){ row.TotalWater = 'none'; + }else if( row.TotalWater === null && row['Id/Demographics/calculated_status'] === 'Dead'){ + row.TotalWater = 'Dead' + eventTitle = row.id + row['Id/Demographics/calculated_status'] + } + if (row['Id/Demographics/calculated_status'] === 'Alive'){ + parsedTotalWater = row.TotalWater; + eventTitle = row.Id + " Total: " + parsedTotalWater; + }else{ + eventTitle = row.Id + row['Id/Demographics/calculated_status'] } - parsedTotalWater = row.TotalWater; - eventTitle = row.Id + " Total: " + parsedTotalWater; + }else{ - row.TotalWater = 'Lixit' - eventTitle = row.Id + " on Lixit"; + if (row['Id/Demographics/calculated_status'] === 'Alive'){ + row.TotalWater = 'Lixit' + eventTitle = row.Id + " on Lixit"; + }else{ + row.TotalWater = 'Dead' + eventTitle = row.Id + row['Id/Demographics/calculated_status'] + } } var eventObj = { id : LABKEY.Utils.generateUUID(), title: eventTitle, start: new Date(row.date), allDay: true, + groupId : row.Id, textColor: '#000000', rawRowData: row }; @@ -763,15 +788,27 @@ events.map(function (row) { let parsedTotalWater = 0; let eventTitle = ""; + debugger; if(row.conditionAtTime === 'regulated') { - if (row.TotalWater === null) { + if (row.TotalWater === null && row['Id/Demographics/calculated_status'] === 'Alive') { row.TotalWater = 'none'; + }else if( row.TotalWater === null && row['Id/Demographics/calculated_status'] === 'Dead'){ + row.TotalWater = 'Dead' + eventTitle = row.Id + row['Id/Demographics/calculated_status'] } - parsedTotalWater = row.TotalWater; - eventTitle = row.Id + " Total: " + parsedTotalWater; + if (row['Id/Demographics/calculated_status'] === 'Alive'){ + parsedTotalWater = row.TotalWater; + eventTitle = row.Id + " Total: " + parsedTotalWater; + } + }else{ - row.TotalWater = 'Lixit' - eventTitle = row.Id + " on Lixit"; + if (row['Id/Demographics/calculated_status'] === 'Alive'){ + row.TotalWater = 'Lixit' + eventTitle = row.Id + " on Lixit"; + }else{ + row.TotalWater = 'Dead' + eventTitle = row.Id + row['Id/Demographics/calculated_status'] + } } var eventObj = { @@ -780,6 +817,7 @@ start: new Date(row.date), textColor: '#000000', allDay: true, + groupId : row.Id, rawRowData: row }; if (row.mlsPerKg >= row.InnerMlsPerKg || row.conditionAtTime === 'lixit'){ @@ -835,7 +873,13 @@ $('#waterInformation').collapse('hide'); $('#waterTotalInformation').collapse('show'); WebUtils.VM.taskDetails["volume"](info.event.extendedProps.rawRowData.TotalWater.toString()); - WebUtils.VM.taskDetails["location"](info.event.extendedProps.rawRowData["Id/curLocation/location"].toString()); + if (info.event.extendedProps.rawRowData["Id/curLocation/location"]){ + WebUtils.VM.taskDetails["location"](info.event.extendedProps.rawRowData["Id/curLocation/location"].toString()); + }else{ + WebUtils.VM.taskDetails["location"](info.event.extendedProps.rawRowData["Id/lastHousing/location"].toString()); + } + + }else{ $('#waterInformation').collapse('show'); $('#waterTotalInformation').collapse('hide'); @@ -991,7 +1035,8 @@ displaytimeofday: ko.observable(), rawDate: ko.observable(), mlsPerKg: ko.observable(), - conditionAtTime: ko.observable() + conditionAtTime: ko.observable(), + status: ko.observable() }, form: { lsidForm: ko.observable(), @@ -1288,6 +1333,23 @@ }); }); + WebUtils.VM.taskDetails.taskLink = ko.pureComputed(function() { + var taskidValue = WebUtils.VM.taskDetails.taskid(); + var formtype = ''; + if (WebUtils.VM.taskDetails.dataSource == 'waterAmount'){ + formtype = 'Enter Water Amounts' + + }else{ + formtype = 'Enter Water Orders' + } + + return LABKEY.ActionURL.buildURL('ehr', 'dataEntryFormDetails', null, { + formtype: formtype, + taskid: taskidValue + + }); + }); + WebUtils.VM.taskDetails.displayDate = ko.pureComputed(function(){ return WebUtils.VM.taskDetails.date(); }); @@ -1297,9 +1359,16 @@ }); WebUtils.VM.taskDetails.conditionAtTimeValue = ko.pureComputed(function(){ + if ( WebUtils.VM.taskDetails.conditionAtTime() === 'regulated' && WebUtils.VM.taskDetails.calculatedStatusValue() === 'Alive' ){ + + } return WebUtils.VM.taskDetails.conditionAtTime(); }); + WebUtils.VM.taskDetails.calculatedStatusValue = ko.pureComputed(function(){ + return WebUtils.VM.taskDetails.status(); + }); + //Updating all the records of the form with data coming from the taskDeatils panel //These records are not supposed to be change by the end users when adding or updating //a waterAmount record. From 6da7f68cc65e4215284cb2d02dfb79dc7a229c13 Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Mon, 23 Oct 2023 12:10:49 -0500 Subject: [PATCH 08/13] Adding demographics column to show water condition trough-tout the system. --- .../WaterMonitoringAnimalWithOutEntriesNotification.java | 2 +- .../src/org/labkey/wnprc_ehr/table/WNPRC_EHRCustomizer.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesNotification.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesNotification.java index d13b34e91..0a07a0fef 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesNotification.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesNotification.java @@ -87,7 +87,7 @@ public String getMessageBodyHTML(final Container c, User u) //Check animals that did not get any water for today and the last five days. findAnimalsWithWaterEntries(c,u,msg,numDays); - //Check animals with less than 20 mls per kilogram of water for today + //Check animals with less than 20 mls per kilogram of water for today, it also displays the animals on Lixit at the end of the notification findAnimalsWithEnoughWater(c,u,msg); diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/table/WNPRC_EHRCustomizer.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/table/WNPRC_EHRCustomizer.java index eab8cbf5e..f9f1dd25c 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/table/WNPRC_EHRCustomizer.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/table/WNPRC_EHRCustomizer.java @@ -388,6 +388,11 @@ private void customizeAnimalTable(AbstractTableInfo ds) col20.setLabel("PrimateId"); col20.setDescription("Unique PrimateID column to be shared across all datasets"); ds.addColumn(col20); + + BaseColumnInfo col21 = getWrappedIdCol(us, ds, "mostRecentWaterCondition", "demographicsMostRecentWaterCondition" ); + col21.setLabel("Most Recent Water Condition"); + col21.setDescription("Most Recent Water condition for animals in Water restricted protocols"); + ds.addColumn(col21); } if (ds.getColumn("totalOffspring") == null) From 6446651c8083b494a471c1634288ced979087226 Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Mon, 23 Oct 2023 12:12:24 -0500 Subject: [PATCH 09/13] Improving titles on the mostRecentWater demographics integration. --- .../study/demographicsMostRecentWaterCondition.query.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.query.xml b/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.query.xml index 710a31cf6..b588259fb 100644 --- a/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.query.xml +++ b/WNPRC_EHR/resources/queries/study/demographicsMostRecentWaterCondition.query.xml @@ -12,12 +12,12 @@ - Start Date + Start Date Water Condition yyyy-MM-dd - Condition + Water Condition ehr_lookups water_source From ac6189e3183aba3e8d778a966a26118dac7b80c3 Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Wed, 8 Nov 2023 15:57:00 -0600 Subject: [PATCH 10/13] Adding additional color to water calendar and displaying remarks to the Total Water by Date report. --- .../study/waterScheduleCoalesced.query.xml | 2 - .../Treatments.qview.xml | 4 +- .../queries/study/waterTotalByDate.sql | 4 +- .../waterTotalByDateWithWeight.query.xml | 3 ++ .../study/waterTotalByDateWithWeight.sql | 1 + .../waterTotalByDateWithWeight/.qview.xml | 3 +- .../tooLittleWater.qview.xml | 30 ++++++++++++++ .../reports/IncompleteTreatmentsReport.js | 18 +++++++- ...lWithOutEntriesSupervisorNotification.java | 3 ++ .../WaterMonitoringNotification.java | 41 +++++++++++++++++++ .../pages/husbandry/WaterCalendar.jsp | 14 +++++-- 11 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/tooLittleWater.qview.xml diff --git a/WNPRC_EHR/resources/queries/study/waterScheduleCoalesced.query.xml b/WNPRC_EHR/resources/queries/study/waterScheduleCoalesced.query.xml index 4ec8dfb29..90cc64908 100644 --- a/WNPRC_EHR/resources/queries/study/waterScheduleCoalesced.query.xml +++ b/WNPRC_EHR/resources/queries/study/waterScheduleCoalesced.query.xml @@ -138,7 +138,6 @@ ehr_lookups water_source value - title @@ -146,7 +145,6 @@ ehr_lookups husbandry_fruit value - title diff --git a/WNPRC_EHR/resources/queries/study/waterScheduleCoalesced/Treatments.qview.xml b/WNPRC_EHR/resources/queries/study/waterScheduleCoalesced/Treatments.qview.xml index 5bf412862..70db97c06 100644 --- a/WNPRC_EHR/resources/queries/study/waterScheduleCoalesced/Treatments.qview.xml +++ b/WNPRC_EHR/resources/queries/study/waterScheduleCoalesced/Treatments.qview.xml @@ -10,7 +10,7 @@ - + @@ -26,6 +26,6 @@ - + \ No newline at end of file diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql b/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql index ceab892c2..684034e2a 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDate.sql @@ -9,7 +9,7 @@ SELECT cal.targetdate AS date, waterSummary.TotalWater, waterSummary.provideFruit, - waterSummary.remark, + waterSummary.remarksConcat, waterSummary.volumeGivenInLabSub, waterSummary.volumeGivenInCage, waterSummary.volumeGivenInImage, @@ -52,7 +52,7 @@ FROM ehr_lookups.calendar cal COALESCE (SUM(CASE WHEN iwg.location = 'procedureRoom' THEN iwg.volume ELSE 0 END), 0) AS volumeGivenInProcedure, COALESCE(SUM(iwg.volume), 0) AS TotalWater, COALESCE(GROUP_CONCAT(iwg.provideFruit.title,'; '),'') AS provideFruit, - COALESCE(GROUP_CONCAT(iwg.remarks,'; '),'') AS remark, + COALESCE(GROUP_CONCAT(iwg.remarks,'; '),'') AS remarksConcat, COALESCE(GROUP_CONCAT(iwg.performedby, ';'),'') AS performedConcat, MAX(iwg.project) AS project, COALESCE(MAX(iwg.qcstate),1) AS qcstate, diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.query.xml b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.query.xml index efab38bb1..b338321e7 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.query.xml +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.query.xml @@ -39,6 +39,9 @@ Allowed MlsPerKg + + Water Given Remarks + diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql index e5629c3fd..af01c6cd8 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql @@ -14,6 +14,7 @@ SELECT wtbd.Id as Id, wtbd.volumeGivenInImage, wtbd.volumeGivenInProcedure, wtbd.currentWaterCondition, + wtbd.remarksConcat, waterScheduledAnimalsOuter.condition AS conditionAtTime, waterScheduledAnimalsOuter.endDate as endDateCondition, diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml index 84cd6ed64..75fb90ad9 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/.qview.xml @@ -7,17 +7,16 @@ + - - diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/tooLittleWater.qview.xml b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/tooLittleWater.qview.xml new file mode 100644 index 000000000..385542c83 --- /dev/null +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/tooLittleWater.qview.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WNPRC_EHR/resources/web/wnprc_ehr/reports/IncompleteTreatmentsReport.js b/WNPRC_EHR/resources/web/wnprc_ehr/reports/IncompleteTreatmentsReport.js index 76d9f3b76..bc54f04c6 100644 --- a/WNPRC_EHR/resources/web/wnprc_ehr/reports/IncompleteTreatmentsReport.js +++ b/WNPRC_EHR/resources/web/wnprc_ehr/reports/IncompleteTreatmentsReport.js @@ -12,7 +12,7 @@ EHR.reports.IncompleteTreatmentsReport = function (panel, tab) { reportStartDate = reportStartDate.format(LABKEY.extDefaultDateFormat) let config = panel.getQWPConfig({ - title: 'Water Treatments', + title: 'Incomplete Water Treatments', schemaName: 'study', queryName: 'WaterScheduleCoalesced', viewName: 'Treatments', @@ -21,6 +21,17 @@ EHR.reports.IncompleteTreatmentsReport = function (panel, tab) { removeableFilters: filterArray.removable, frame: true + }); + let configWaterTotal = panel.getQWPConfig({ + title: 'Water Below Limit (10ml/Kg)', + schemaName: 'study', + queryName: 'waterTotalByDateWithWeight', + viewName: 'tooLittleWater', + //parameters: {'NumDays': '180', 'StartDate': reportStartDate}, + filters: filterArray.nonRemovable, + removeableFilters: filterArray.removable, + frame: true + }); tab.add({ @@ -29,6 +40,11 @@ EHR.reports.IncompleteTreatmentsReport = function (panel, tab) { queryConfig: config }); + tab.add({ + xtype: 'ldk-querypanel', + style: 'margin-bottom:20px;', + queryConfig: configWaterTotal + }) target = tab.add({xtype: 'ldk-contentresizingpanel'}); diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesSupervisorNotification.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesSupervisorNotification.java index a965fd089..58c409e9b 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesSupervisorNotification.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringAnimalWithOutEntriesSupervisorNotification.java @@ -47,6 +47,9 @@ public String getMessageBodyHTML(final Container c, User u) //Check animals that did not get any water for today and the last five days. findAnimalsWithWaterEntries(c,u,msg,numDays); + //Animals on water restricted protocols that are on Lixit + animalOnLixit(c,u,msg); + return msg.toString(); } diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java index f157eaeb5..e01db7038 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/notification/WaterMonitoringNotification.java @@ -390,6 +390,47 @@ protected void findWaterOrdersNotCompleted(Container c,User u, StringBuilder msg + } + + protected void animalOnLixit(Container c,User u, StringBuilder msg){ + + TableInfo ti = QueryService.get().getUserSchema(u,c,"study").getTable("demographicsMostRecentWaterCondition"); + SimpleFilter filter = new SimpleFilter(FieldKey.fromString("MostRecentWaterCondition"),"lixit",CompareType.EQUAL); + + Set columns = new HashSet<>(); + columns.add(FieldKey.fromString("Id")); + columns.add(FieldKey.fromString("MostRecentWaterConditionDate")); + columns.add(FieldKey.fromString("MostRecentWaterCondition")); + + final Map colMap = QueryService.get().getColumns(ti, columns); + + TableSelector ts = new TableSelector(ti,colMap.values(), filter,null); + long total = ts.getRowCount(); + + if(total > 0){ + msg.append("

There are "+total+ " animal in water controlled protocol that are on Lixit/Ad lib
"); + } + + Map[] animalsOnLixit= ts.getMapArray(); + StringBuilder animalsLixitTable = new StringBuilder(); + animalsLixitTable.append("
Animals on Lixit /Ad lib"); + animalsLixitTable.append(""); + animalsLixitTable.append("" + + "" + + "\n"); + + for (Map lixitRecord: animalsOnLixit){ + LocalDateTime objectDateTime = ConvertHelper.convert(lixitRecord.get("MostRecentWaterConditionDate"),Date.class).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + animalsLixitTable.append("" ); + } + animalsLixitTable.append("
IdDateCurrent Water Condition
" + ConvertHelper.convert(lixitRecord.get("Id"),String.class) + + " " + objectDateTime.format(formatter) + + " " + ConvertHelper.convert(lixitRecord.get("MostRecentWaterCondition"),String.class) +"
"); + + msg.append(animalsLixitTable); + } private StringBuilder createTable (List> listOfDBObjects, String assignedTo){ StringBuilder returnTable = new StringBuilder(); diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp index ab9d660ba..b38c23576 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp @@ -488,7 +488,8 @@

- Total Water < 20 mL/Kg + Total Water < 10 mL/Kg + Total Water < 20 mL/Kg or set point Total Water >= 20 mL/Kg
@@ -764,7 +765,11 @@ }; if (row.mlsPerKg >= row.InnerMlsPerKg || row.conditionAtTime === 'lixit'){ eventObj.color = '#FFFFFF'; - }else{ + } + else if (row.mlsPerKg >= '10' && row.mlsPerKg < row.InnerMlsPerKg){ + eventObj.color = '#FF7F50'; + } + else{ eventObj.color = '#EE2020' } return eventObj; @@ -824,7 +829,10 @@ }; if (row.mlsPerKg >= row.InnerMlsPerKg || row.conditionAtTime === 'lixit'){ eventObj.color = '#FFFFFF'; - }else{ + }else if (row.mlsPerKg >= '10' && row.mlsPerKg < row.InnerMlsPerKg){ + eventObj.color = '#FF7F50'; + } + else{ eventObj.color = '#EE2020' } return eventObj; From f3a90bbdfae24b8547d0911f69b43b09423411b5 Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Mon, 13 Nov 2023 16:29:25 -0600 Subject: [PATCH 11/13] Fixing problem with water calendar --- .../src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp index b38c23576..3f7cdaf3f 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/pages/husbandry/WaterCalendar.jsp @@ -738,7 +738,7 @@ row.TotalWater = 'Dead' eventTitle = row.id + row['Id/Demographics/calculated_status'] } - if (row['Id/Demographics/calculated_status'] === 'Alive'){ + else if (row['Id/Demographics/calculated_status'] === 'Alive'){ parsedTotalWater = row.TotalWater; eventTitle = row.Id + " Total: " + parsedTotalWater; }else{ From 159c1af9fe7feeda97b6523f8e1b8aaf32c337f8 Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Mon, 13 Nov 2023 17:05:48 -0600 Subject: [PATCH 12/13] filter null or less than 10 mls on mlsPerKg --- .../resources/queries/study/waterTotalByDateWithWeight.sql | 1 + .../study/waterTotalByDateWithWeight/tooLittleWater.qview.xml | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql index af01c6cd8..20a3ed34d 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight.sql @@ -22,6 +22,7 @@ SELECT wtbd.Id as Id, waterScheduledAnimalsOuter.project, wtbd.performedConcat, wtbd.qcstate, + COALESCE(CAST(wtbd.TotalWater/weigthDates.weight AS NUMERIC), 0) AS zeroOrmlsPerKg, 'waterTotal' AS dataSource FROM study.waterTotalByDate wtbd diff --git a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/tooLittleWater.qview.xml b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/tooLittleWater.qview.xml index 385542c83..3ecdbc4d6 100644 --- a/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/tooLittleWater.qview.xml +++ b/WNPRC_EHR/resources/queries/study/waterTotalByDateWithWeight/tooLittleWater.qview.xml @@ -24,7 +24,8 @@ - + + \ No newline at end of file From 9371a908d2399143cb6bd61d64975b3b9e8ffa1e Mon Sep 17 00:00:00 2001 From: "F. Daniel Nicolalde" Date: Mon, 13 Nov 2023 17:06:34 -0600 Subject: [PATCH 13/13] When switching to Lixit remove the last day of the previous order --- WNPRC_EHR/src/org/labkey/wnprc_ehr/TriggerScriptHelper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WNPRC_EHR/src/org/labkey/wnprc_ehr/TriggerScriptHelper.java b/WNPRC_EHR/src/org/labkey/wnprc_ehr/TriggerScriptHelper.java index 580b37305..8c0d69b6d 100644 --- a/WNPRC_EHR/src/org/labkey/wnprc_ehr/TriggerScriptHelper.java +++ b/WNPRC_EHR/src/org/labkey/wnprc_ehr/TriggerScriptHelper.java @@ -2120,7 +2120,10 @@ public JSONArray changeWaterScheduled(String animalId, Date startDate, String wa Map updateWaterOrder = new CaseInsensitiveHashMap<>(); updateWaterOrder.put("lsid", lsid); - updateWaterOrder.put("enddate", startDate); + //closing water order the day before, new lixit orders have to be completed the first time. + java.time.LocalDateTime newEndDate = java.time.LocalDateTime.ofInstant(startDate.toInstant(),ZoneId.systemDefault()); + newEndDate.minusDays(1); + updateWaterOrder.put("enddate", Date.from(newEndDate.atZone(ZoneId.systemDefault()).toInstant())); updateWaterOrder.put("skipWaterRegulationCheck", true); toUpdate.add(updateWaterOrder);