diff --git a/nirc_ehr/resources/queries/study/treatmentSchedule.query.xml b/nirc_ehr/resources/queries/study/treatmentSchedule.query.xml index 9ff56692..91608544 100644 --- a/nirc_ehr/resources/queries/study/treatmentSchedule.query.xml +++ b/nirc_ehr/resources/queries/study/treatmentSchedule.query.xml @@ -2,6 +2,7 @@ + Treatment Schedule /EHR/treatmentDetails.view?key=${lsid} primaryKey diff --git a/nirc_ehr/resources/queries/study/treatmentSchedule.sql b/nirc_ehr/resources/queries/study/treatmentSchedule.sql index c8e64ae4..12d1eaf6 100644 --- a/nirc_ehr/resources/queries/study/treatmentSchedule.sql +++ b/nirc_ehr/resources/queries/study/treatmentSchedule.sql @@ -38,7 +38,6 @@ JOIN( timestampdiff('SQL_TSI_DAY', cast(t1.dateOnly AS timestamp), dr.dateOnly) + 1 AS daysElapsed, t1.enddate, t1.code, - t1.treatmentRecord, t1.volume, t1.vol_units, t1.concentration, diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/table/NIRC_EHRCustomizer.java b/nirc_ehr/src/org/labkey/nirc_ehr/table/NIRC_EHRCustomizer.java index 83b753b3..ebf419db 100644 --- a/nirc_ehr/src/org/labkey/nirc_ehr/table/NIRC_EHRCustomizer.java +++ b/nirc_ehr/src/org/labkey/nirc_ehr/table/NIRC_EHRCustomizer.java @@ -131,6 +131,11 @@ public void customize(TableInfo table) customizeTreatmentOrder(ti); } + if (matches(ti, "study", "treatmentSchedule")) + { + customizeTreatmentSchedule(ti); + } + if (matches(ti, "study", "prc_order")) { customizeProcedureOrder(ti); @@ -1065,88 +1070,18 @@ private void customizeTreatmentOrder(AbstractTableInfo ti) { WrappedColumn col = new WrappedColumn(ti.getColumn("objectid"), "treatmentRecord"); col.setLabel("Record Treatment"); - col.setDisplayColumnFactory(new DisplayColumnFactory() { - - @Override - public DisplayColumn createRenderer(final ColumnInfo colInfo) - { - return new DataColumn(colInfo){ - - @Override - public void renderGridCellContents(RenderContext ctx, HtmlWriter out) - { - String objectid = (String)getBoundColumn().getValue(ctx); - Date date = (Date)ctx.get("date"); - String caseid = (String)ctx.get("caseid"); - String category = (String)ctx.get("category"); - ActionURL url = new ActionURL("ehr", "dataEntryForm", ti.getUserSchema().getContainer()); - if (!ti.getUserSchema().getContainer().hasPermission(ti.getUserSchema().getUser(), EHRClinicalEntryPermission.class)) - return; - - if (category.equals("Behavior")) - { - if (caseid != null) - { - url.addParameter("formType", "Behavioral Rounds"); - url.addParameter("caseid", caseid); - } - else - { - url.addParameter("formType", "Bulk Behavior Entry"); - } - } - else - { - if (caseid != null) - { - url.addParameter("formType", "Clinical Rounds"); - url.addParameter("caseid", caseid); - } - else - { - url.addParameter("formType", "medicationTreatment"); - } - } - - url.addParameter("treatmentid", objectid); - url.addParameter("scheduledDate", date.toString()); - - String returnUrl = new ActionURL("ehr", "animalHistory", ti.getUserSchema().getContainer()) + "#inputType:none&showReport:0&activeReport:clinMedicationSchedule"; - url.addParameter("returnUrl", returnUrl); - - out.write(LinkBuilder.labkeyLink("Record Treatment", url).target("_blank")); - } - - @Override - public void addQueryFieldKeys(Set keys) - { - super.addQueryFieldKeys(keys); - keys.add(getBoundColumn().getFieldKey()); - keys.add(FieldKey.fromString("date")); - keys.add(FieldKey.fromString("caseid")); - keys.add(FieldKey.fromString("category")); - } - - @Override - public boolean isSortable() - { - return false; - } - - @Override - public boolean isFilterable() - { - return false; - } + col.setDisplayColumnFactory(new TreatmentDisplayColumnFactory(false)); + ti.addColumn(col); + } + } - @Override - public boolean isEditable() - { - return false; - } - }; - } - }); + private void customizeTreatmentSchedule(AbstractTableInfo ti) + { + if (ti.getColumn("treatmentRecord") == null && ti.getColumn("objectid") != null) + { + WrappedColumn col = new WrappedColumn(ti.getColumn("objectid"), "treatmentRecord"); + col.setLabel("Record Treatment"); + col.setDisplayColumnFactory(new TreatmentDisplayColumnFactory(true)); ti.addColumn(col); } } diff --git a/nirc_ehr/src/org/labkey/nirc_ehr/table/TreatmentDisplayColumnFactory.java b/nirc_ehr/src/org/labkey/nirc_ehr/table/TreatmentDisplayColumnFactory.java new file mode 100644 index 00000000..56ffb38b --- /dev/null +++ b/nirc_ehr/src/org/labkey/nirc_ehr/table/TreatmentDisplayColumnFactory.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2026 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.labkey.nirc_ehr.table; + +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.DataColumn; +import org.labkey.api.data.DisplayColumn; +import org.labkey.api.data.DisplayColumnFactory; +import org.labkey.api.data.RenderContext; +import org.labkey.api.ehr.security.EHRClinicalEntryPermission; +import org.labkey.api.query.FieldKey; +import org.labkey.api.util.DateUtil; +import org.labkey.api.util.LinkBuilder; +import org.labkey.api.view.ActionURL; +import org.labkey.api.writer.HtmlWriter; + +import java.util.Date; +import java.util.Set; + +/** + * Display column factory for creating Record Treatment links. When includeScheduledDate is set, the row's date is + * passed as the scheduledDate URL parameter, so it should only be set on tables whose date column is the scheduled + * slot being recorded (e.g. treatmentSchedule), not the treatment order's start date. + */ +public class TreatmentDisplayColumnFactory implements DisplayColumnFactory +{ + private final boolean _includeScheduledDate; + + public TreatmentDisplayColumnFactory(boolean includeScheduledDate) + { + _includeScheduledDate = includeScheduledDate; + } + + @Override + public DisplayColumn createRenderer(final ColumnInfo colInfo) + { + return new DataColumn(colInfo){ + + @Override + public void renderGridCellContents(RenderContext ctx, HtmlWriter out) + { + String objectid = (String)getBoundColumn().getValue(ctx); + Date date = (Date)ctx.get("date"); + String caseid = (String)ctx.get("caseid"); + String category = (String)ctx.get("category"); + ActionURL url = new ActionURL("ehr", "dataEntryForm", colInfo.getParentTable().getUserSchema().getContainer()); + if (!colInfo.getParentTable().getUserSchema().getContainer().hasPermission(colInfo.getParentTable().getUserSchema().getUser(), EHRClinicalEntryPermission.class)) + return; + + if (category == null) + return; + + if (category.equals("Behavior")) + { + if (caseid != null) + { + url.addParameter("formType", "Behavioral Rounds"); + url.addParameter("caseid", caseid); + } + else + { + url.addParameter("formType", "Bulk Behavior Entry"); + } + } + else + { + if (caseid != null) + { + url.addParameter("formType", "Clinical Rounds"); + url.addParameter("caseid", caseid); + } + else + { + url.addParameter("formType", "medicationTreatment"); + } + } + + url.addParameter("treatmentid", objectid); + if (_includeScheduledDate && date != null) + url.addParameter("scheduledDate", DateUtil.formatIsoDateShortTime(date)); + + String returnUrl = new ActionURL("ehr", "animalHistory", colInfo.getParentTable().getUserSchema().getContainer()) + "#inputType:none&showReport:0&activeReport:clinMedicationSchedule"; + url.addParameter("returnUrl", returnUrl); + + out.write(LinkBuilder.labkeyLink("Record Treatment", url).target("_blank")); + } + + @Override + public void addQueryFieldKeys(Set keys) + { + super.addQueryFieldKeys(keys); + keys.add(getBoundColumn().getFieldKey()); + keys.add(FieldKey.fromString("date")); + keys.add(FieldKey.fromString("caseid")); + keys.add(FieldKey.fromString("category")); + } + + @Override + public boolean isSortable() + { + return false; + } + + @Override + public boolean isFilterable() + { + return false; + } + + @Override + public boolean isEditable() + { + return false; + } + }; + } +}