Skip to content
36 changes: 36 additions & 0 deletions luminex/src/org/labkey/luminex/LeveyJenningsMenuForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.luminex;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.assay.actions.ProtocolIdForm;

public class LeveyJenningsMenuForm extends ProtocolIdForm
{
private String _analyte;

public @Nullable String getAnalyte()
{
return StringUtils.isBlank(_analyte) ? null : _analyte;
}

public void setAnalyte(String analyte)
{
_analyte = analyte;
}
}
119 changes: 92 additions & 27 deletions luminex/src/org/labkey/luminex/LeveyJenningsMenuView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package org.labkey.luminex;

import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.ContainerFilter;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.SqlSelector;
import org.labkey.api.data.TableInfo;
import org.labkey.api.exp.api.ExpProtocol;
import org.labkey.api.exp.api.ExperimentService;
import org.labkey.api.view.JspView;
Expand All @@ -35,14 +37,23 @@ public static class Bean
{

private final ExpProtocol _protocol;
private final String _analyte;
private final List<String> _titrations;
private final List<String> _singlePointControls;
private final List<String> _analytes;

public Bean(ExpProtocol protocol, List<String> titrations, List<String> singlePointControls)
public Bean(ExpProtocol protocol, @Nullable String analyte, List<String> titrations, List<String> singlePointControls, List<String> analytes)
{
_protocol = protocol;
_analyte = analyte;
_titrations = titrations;
_singlePointControls = singlePointControls;
_analytes = analytes;
}

public @Nullable String getAnalyte()
{
return _analyte;
}

public List<String> getTitrations()
Expand All @@ -55,40 +66,94 @@ public List<String> getSinglePointControls()
return _singlePointControls;
}

public List<String> getAnalytes()
{
return _analytes;
}

public ExpProtocol getProtocol()
{
return _protocol;
}
}

public LeveyJenningsMenuView(ExpProtocol protocol)
public LeveyJenningsMenuView(ExpProtocol protocol, @Nullable String analyte)
{
super("/org/labkey/luminex/view/leveyJenningsMenu.jsp");
ContainerFilter.AllFolders containerFilter = new ContainerFilter.AllFolders(getViewContext().getUser());
SQLFragment containerSQL = containerFilter.getSQLFragment(LuminexProtocolSchema.getSchema(), new SQLFragment("r.Container"));

SQLFragment titrationSQL = new SQLFragment("SELECT DISTINCT t.Name FROM ");
titrationSQL.append(LuminexProtocolSchema.getTableInfoTitration(), "t");
titrationSQL.append(", ");
titrationSQL.append(ExperimentService.get().getTinfoExperimentRun(), "r");
titrationSQL.append(" WHERE r.RowId = t.RunId AND r.ProtocolLSID = ? AND (t.Standard = ? OR t.QCControl = ?) AND ");
titrationSQL.add(protocol.getLSID());
titrationSQL.add(true);
titrationSQL.add(true);
titrationSQL.append(containerSQL);
titrationSQL.append(" ORDER BY t.Name");
List<String> titrations = new SqlSelector(LuminexProtocolSchema.getTableInfoTitration().getSchema(), titrationSQL).getArrayList(String.class);

SQLFragment singlePointControlSQL = new SQLFragment("SELECT DISTINCT s.Name FROM ");
singlePointControlSQL.append(LuminexProtocolSchema.getTableInfoSinglePointControl(), "s");
singlePointControlSQL.append(", ");
singlePointControlSQL.append(ExperimentService.get().getTinfoExperimentRun(), "r");
singlePointControlSQL.append(" WHERE s.RunId = r.RowId AND r.ProtocolLSID = ? AND ");
singlePointControlSQL.add(protocol.getLSID());
singlePointControlSQL.append(containerSQL);
singlePointControlSQL.append(" ORDER BY s.Name");
List<String> singlePointControls = new SqlSelector(LuminexProtocolSchema.getTableInfoTitration().getSchema(), singlePointControlSQL).getArrayList(String.class);

setModelBean(new Bean(protocol, titrations, singlePointControls));
SQLFragment containerSQL = containerFilter.getSQLFragment(LuminexProtocolSchema.getSchema(), SQLFragment.unsafe("r.Container"));

ControlSource titrationSource = new ControlSource(LuminexProtocolSchema.getTableInfoTitration(),
SQLFragment.unsafe(" AND (c.Standard = ? OR c.QCControl = ?)", true, true),
LuminexProtocolSchema.getTableInfoAnalyteTitration(), "TitrationId");
ControlSource singlePointControlSource = new ControlSource(LuminexProtocolSchema.getTableInfoSinglePointControl(), null,
LuminexProtocolSchema.getTableInfoAnalyteSinglePointControl(), "SinglePointControlId");

List<String> titrations = getControlNames(titrationSource, protocol, containerSQL, analyte);
List<String> singlePointControls = getControlNames(singlePointControlSource, protocol, containerSQL, analyte);

List<String> analytes = List.of();
if (analyte == null)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check isBlank instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the blank case is already handled in the code prior to this line (i.e. LeveyJenningsMenuForm.java line 29 already does return StringUtils.isBlank(_analyte) ? null : _analyte

{
SQLFragment analyteSQL = getAnalyteNamesSQL(titrationSource, protocol, containerSQL);
analyteSQL.append(SQLFragment.unsafe(" UNION "));
analyteSQL.append(getAnalyteNamesSQL(singlePointControlSource, protocol, containerSQL));
analyteSQL.append(SQLFragment.unsafe(" ORDER BY Name"));
analytes = new SqlSelector(LuminexProtocolSchema.getSchema(), analyteSQL).getArrayList(String.class);
}

setModelBean(new Bean(protocol, analyte, titrations, singlePointControls, analytes));
}

private record ControlSource(TableInfo controlTable, @Nullable SQLFragment controlFilter, TableInfo analyteJunctionTable, String junctionControlColumn) {}

private static List<String> getControlNames(ControlSource source, ExpProtocol protocol, SQLFragment containerSQL, @Nullable String analyte)
{
SQLFragment sql = SQLFragment.unsafe("SELECT DISTINCT c.Name");
sql.append(getControlsFromSQL(source, protocol, containerSQL));
if (analyte != null)
{
sql.append(SQLFragment.unsafe(" AND EXISTS (SELECT 1"));
sql.append(getAnalyteJunctionFromSQL(source));
sql.append(SQLFragment.unsafe(" = c.RowId AND a.Name = ?)", analyte));
}
sql.append(SQLFragment.unsafe(" ORDER BY c.Name"));
return new SqlSelector(LuminexProtocolSchema.getSchema(), sql).getArrayList(String.class);
}

private static SQLFragment getAnalyteNamesSQL(ControlSource source, ExpProtocol protocol, SQLFragment containerSQL)
{
SQLFragment sql = SQLFragment.unsafe("SELECT a.Name");
sql.append(getAnalyteJunctionFromSQL(source));
sql.append(SQLFragment.unsafe(" IN (SELECT c.RowId"));
sql.append(getControlsFromSQL(source, protocol, containerSQL));
sql.append(SQLFragment.unsafe(")"));
return sql;
}

/** FROM/WHERE for the protocol's controls (alias c) and their runs (alias r) in the container scope */
private static SQLFragment getControlsFromSQL(ControlSource source, ExpProtocol protocol, SQLFragment containerSQL)
{
SQLFragment sql = SQLFragment.unsafe(" FROM ");
sql.append(source.controlTable(), "c");
sql.append(SQLFragment.unsafe(" JOIN "));
sql.append(ExperimentService.get().getTinfoExperimentRun(), "r");
sql.append(SQLFragment.unsafe(" ON r.RowId = c.RunId WHERE r.ProtocolLSID = ? AND ", protocol.getLSID()));
sql.append(containerSQL);
if (source.controlFilter() != null)
sql.append(source.controlFilter());
return sql;
}

/** FROM the analyte junction (alias j) and analytes (alias a), ending with the junction's control column so the caller adds the comparison */
private static SQLFragment getAnalyteJunctionFromSQL(ControlSource source)
{
SQLFragment sql = SQLFragment.unsafe(" FROM ");
sql.append(source.analyteJunctionTable(), "j");
sql.append(SQLFragment.unsafe(" JOIN "));
sql.append(LuminexProtocolSchema.getTableInfoAnalytes(), "a");
sql.append(SQLFragment.unsafe(" ON a.RowId = j.AnalyteId WHERE "));
sql.append(source.analyteJunctionTable().getColumn(source.junctionControlColumn()).getValueSql("j"));
return sql;
}
}
8 changes: 4 additions & 4 deletions luminex/src/org/labkey/luminex/LuminexController.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,17 @@ public void addNavTrail(NavTree root)
}

@RequiresPermission(ReadPermission.class)
public static class LeveyJenningsMenuAction extends SimpleViewAction<ProtocolIdForm>
public static class LeveyJenningsMenuAction extends SimpleViewAction<LeveyJenningsMenuForm>
{
private ProtocolIdForm _form;
private LeveyJenningsMenuForm _form;

@Override
public ModelAndView getView(ProtocolIdForm form, BindException errors)
public ModelAndView getView(LeveyJenningsMenuForm form, BindException errors)
{
_form = form;
VBox result = new VBox();
result.addView(new AssayHeaderView(form.getProtocol(), form.getProvider(), false, true, null));
result.addView(new LeveyJenningsMenuView(form.getProtocol()));
result.addView(new LeveyJenningsMenuView(form.getProtocol(), form.getAnalyte()));
return result;
}

Expand Down
54 changes: 47 additions & 7 deletions luminex/src/org/labkey/luminex/view/leveyJenningsMenu.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@
LeveyJenningsMenuView.Bean bean = me.getModelBean();
%>

<p style="padding-top: 10px">
Click on a titration or single point control to view its Levey-Jennings report.
Click on an antigen to filter the Titrations and Single Point Controls lists to those used with that antigen.
</p>
<div style="display: flex; gap: 30px; align-items: flex-start">
<table class="labkey-data-region-legacy labkey-show-borders">
<tr>
<td valign="top" style="padding: 5px" class="labkey-column-header">
<th scope="col" style="padding: 5px; vertical-align: top; text-align: left" class="labkey-column-header">
<strong>Titrations</strong>
</td>
<td valign="top" style="padding: 5px" class="labkey-column-header">
</th>
<th scope="col" style="padding: 5px; vertical-align: top; text-align: left" class="labkey-column-header">
<strong>Single Point Controls</strong>
</td>
</th>
</tr>
<tr>
<td valign="top" style="padding: 5px" >
<td style="padding: 5px; vertical-align: top">
<% if (bean.getTitrations().isEmpty()) { %>
<em>No titrations</em> <%
}
Expand All @@ -47,10 +52,12 @@
url.addParameter("rowId", bean.getProtocol().getRowId());
url.addParameter("controlName", titrationName);
url.addParameter("controlType", LeveyJenningsForm.ControlType.Titration.toString());
if (bean.getAnalyte() != null)
url.addParameter("analyte", bean.getAnalyte());
%><%= link(titrationName, url) %><br/><%
}%>
</td>
<td valign="top" style="padding: 5px" >
<td style="padding: 5px; vertical-align: top">
<% if (bean.getSinglePointControls().isEmpty()) { %>
<em>No single point controls</em> <%
}
Expand All @@ -60,8 +67,41 @@
url.addParameter("rowId", bean.getProtocol().getRowId());
url.addParameter("controlName", singlePointControl);
url.addParameter("controlType", LeveyJenningsForm.ControlType.SinglePoint.toString());
if (bean.getAnalyte() != null)
url.addParameter("analyte", bean.getAnalyte());
%><%= link(singlePointControl, url) %><br/><%
}%>
</td>
</tr>
</table>
</table>
<table class="labkey-data-region-legacy labkey-show-borders">
<tr>
<th scope="col" style="padding: 5px; vertical-align: top; text-align: left" class="labkey-column-header">
<strong>Antigens</strong>
</th>
</tr>
<tr>
<td style="padding: 5px; vertical-align: top">
<% if (bean.getAnalyte() != null) {
ActionURL clearUrl = new ActionURL(LuminexController.LeveyJenningsMenuAction.class, getContainer());
clearUrl.addParameter("rowId", bean.getProtocol().getRowId());
%>
Selected: <strong><%=h(bean.getAnalyte())%></strong> <%=iconLink("fa fa-times", "Clear selection", clearUrl)%> <%
}
else if (bean.getAnalytes().isEmpty()) { %>
<em>No antigens</em> <%
}
else
{
for (String analyte : bean.getAnalytes())
{
ActionURL url = new ActionURL(LuminexController.LeveyJenningsMenuAction.class, getContainer());
url.addParameter("rowId", bean.getProtocol().getRowId());
url.addParameter("analyte", analyte);
%><%= link(analyte, url) %><br/><%
}
}%>
</td>
</tr>
</table>
</div>
Loading
Loading