diff --git a/specimen/src/org/labkey/specimen/SpecimenModule.java b/specimen/src/org/labkey/specimen/SpecimenModule.java index 045c7589..deb23052 100644 --- a/specimen/src/org/labkey/specimen/SpecimenModule.java +++ b/specimen/src/org/labkey/specimen/SpecimenModule.java @@ -42,7 +42,6 @@ import org.labkey.api.query.QuerySettings; import org.labkey.api.query.QueryUpdateService; import org.labkey.api.query.QueryView; -import org.labkey.api.query.UserSchema; import org.labkey.api.security.User; import org.labkey.api.security.permissions.Permission; import org.labkey.api.security.roles.RoleManager; @@ -57,6 +56,7 @@ import org.labkey.api.study.StudyUrls; import org.labkey.api.study.importer.SimpleStudyImportContext; import org.labkey.api.study.importer.SimpleStudyImporterRegistry; +import org.labkey.api.study.query.AbstractStudyQuerySchema; import org.labkey.api.study.writer.SimpleStudyWriterRegistry; import org.labkey.api.usageMetrics.UsageMetricsService; import org.labkey.api.util.LinkBuilder; @@ -80,11 +80,17 @@ import org.labkey.specimen.importer.SpecimenSettingsImporter; import org.labkey.specimen.model.SpecimenRequestEventType; import org.labkey.specimen.pipeline.SpecimenPipeline; +import org.labkey.specimen.query.SpecimenCommentTable; +import org.labkey.specimen.query.SpecimenEventTable; import org.labkey.specimen.query.SpecimenPivotByDerivativeType; import org.labkey.specimen.query.SpecimenPivotByPrimaryType; import org.labkey.specimen.query.SpecimenPivotByRequestingLocation; import org.labkey.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenRequestStatusTable; +import org.labkey.specimen.query.SpecimenRequestTable; import org.labkey.specimen.query.SpecimenUpdateService; +import org.labkey.specimen.query.SpecimenVialCountTable; +import org.labkey.specimen.query.VialRequestTable; import org.labkey.specimen.requirements.SpecimenRequestRequirementProvider; import org.labkey.specimen.security.permissions.EditSpecimenDataPermission; import org.labkey.specimen.security.permissions.ManageRequestSettingsPermission; @@ -109,6 +115,13 @@ import java.util.Set; import java.util.function.Supplier; +import static org.labkey.api.specimen.model.SpecimenTablesProvider.SPECIMEN_COMMENTS_TABLE_NAME; +import static org.labkey.api.specimen.model.SpecimenTablesProvider.SPECIMEN_EVENT_TABLE_NAME; +import static org.labkey.api.specimen.model.SpecimenTablesProvider.SPECIMEN_REQUEST_STATUSES_TABLE_NAME; +import static org.labkey.api.specimen.model.SpecimenTablesProvider.SPECIMEN_REQUEST_TABLE_NAME; +import static org.labkey.api.specimen.model.SpecimenTablesProvider.SPECIMEN_VIAL_COUNT_TABLE_NAME; +import static org.labkey.api.specimen.model.SpecimenTablesProvider.VIAL_REQUEST_TABLE_NAME; + public class SpecimenModule extends SpringModule { private static final Logger LOG = LogHelper.getLogger(SpecimenModule.class, "Specimen metrics"); @@ -230,31 +243,51 @@ public boolean isEnableRequests(Container c) } @Override - public void addSpecimenPivotTableNames(Set names) + public void addSpecimenTableNames(Set names) { + names.add(SPECIMEN_EVENT_TABLE_NAME); + names.add(SPECIMEN_VIAL_COUNT_TABLE_NAME); + names.add(SPECIMEN_REQUEST_TABLE_NAME); + names.add(SPECIMEN_REQUEST_STATUSES_TABLE_NAME); + names.add(VIAL_REQUEST_TABLE_NAME); + names.add(SPECIMEN_COMMENTS_TABLE_NAME); names.add(SpecimenPivotByPrimaryType.PIVOT_BY_PRIMARY_TYPE); names.add(SpecimenPivotByDerivativeType.PIVOT_BY_DERIVATIVE_TYPE); names.add(SpecimenPivotByRequestingLocation.PIVOT_BY_REQUESTING_LOCATION); } @Override - public @Nullable TableInfo getSpecimenPivotTable(UserSchema schema, String name, Study study, ContainerFilter cf) + public @Nullable TableInfo getSpecimenTable(AbstractStudyQuerySchema schema, String name, ContainerFilter cf) { + if (SPECIMEN_EVENT_TABLE_NAME.equalsIgnoreCase(name)) + return schema.getContainer().isRoot() ? null : new SpecimenEventTable(schema, cf); + if (SPECIMEN_VIAL_COUNT_TABLE_NAME.equalsIgnoreCase(name)) + return new SpecimenVialCountTable(schema, cf); + if (SPECIMEN_REQUEST_TABLE_NAME.equalsIgnoreCase(name)) + return new SpecimenRequestTable(schema, cf); + if (SPECIMEN_REQUEST_STATUSES_TABLE_NAME.equalsIgnoreCase(name)) + return new SpecimenRequestStatusTable(schema, cf); + if (VIAL_REQUEST_TABLE_NAME.equalsIgnoreCase(name)) + return new VialRequestTable(schema, cf); + if (SPECIMEN_COMMENTS_TABLE_NAME.equalsIgnoreCase(name)) + return new SpecimenCommentTable(schema, cf); + + Study study = schema.getStudy(); if (SpecimenPivotByPrimaryType.PIVOT_BY_PRIMARY_TYPE.equalsIgnoreCase(name)) - { return new SpecimenPivotByPrimaryType(schema, study, cf); - } if (SpecimenPivotByDerivativeType.PIVOT_BY_DERIVATIVE_TYPE.equalsIgnoreCase(name)) - { return new SpecimenPivotByDerivativeType(schema, study, cf); - } if (SpecimenPivotByRequestingLocation.PIVOT_BY_REQUESTING_LOCATION.equalsIgnoreCase(name)) - { return new SpecimenPivotByRequestingLocation(schema, study, cf); - } return null; } + @Override + public TableInfo createSpecimenCommentTable(AbstractStudyQuerySchema schema, ContainerFilter cf, boolean joinBackToSpecimens) + { + return new SpecimenCommentTable(schema, cf, joinBackToSpecimens); + } + @Override public @Nullable SafeToRender getSpecimenSettingsLink(Container c, User user) { diff --git a/specimen/src/org/labkey/specimen/query/SpecimenCommentTable.java b/specimen/src/org/labkey/specimen/query/SpecimenCommentTable.java new file mode 100644 index 00000000..9e024d5a --- /dev/null +++ b/specimen/src/org/labkey/specimen/query/SpecimenCommentTable.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2008-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.specimen.query; + +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.ContainerFilter; +import org.labkey.api.data.TableInfo; +import org.labkey.api.query.AliasedColumn; +import org.labkey.api.query.FilteredTable; +import org.labkey.api.query.LookupForeignKey; +import org.labkey.api.specimen.SpecimenSchema; +import org.labkey.api.study.query.AbstractStudyQuerySchema; + +/** + * User: brittp + * Created: July 15, 2008 11:13:43 AM + */ +public class SpecimenCommentTable extends FilteredTable +{ + public SpecimenCommentTable(final AbstractStudyQuerySchema schema, ContainerFilter cf) + { + this(schema, cf, true); + } + + public SpecimenCommentTable(final AbstractStudyQuerySchema schema, ContainerFilter cf, boolean joinBackToSpecimens) + { + super(SpecimenSchema.get().getTableInfoSpecimenComment(), schema, cf); + for (ColumnInfo baseColumn : _rootTable.getColumns()) + { + String name = baseColumn.getName(); + if (joinBackToSpecimens && "GlobalUniqueId".equalsIgnoreCase(name)) + { + AliasedColumn globalUniqueIdColumn = new AliasedColumn(this, "GlobalUniqueId", _rootTable.getColumn("GlobalUniqueId")); + globalUniqueIdColumn.setFk(new LookupForeignKey(null, (String) null, "GlobalUniqueId", "GlobalUniqueId") + { + @Override + public TableInfo getLookupTableInfo() + { + return schema.createSpecimenDetailLookupTable(cf); + } + }); + globalUniqueIdColumn.setKeyField(true); + addColumn(globalUniqueIdColumn); + } + else if (!"Container".equalsIgnoreCase(name)) + { + var wrappedColumn = addWrapColumn(baseColumn); + if ("RowId".equalsIgnoreCase(name) || "QualityControlFlagForced".equalsIgnoreCase(name)) + wrappedColumn.setHidden(true); + } + } + + addWrapColumn("Folder", _rootTable.getColumn("Container")); + + setTitleColumn("Comment"); + } +} \ No newline at end of file diff --git a/specimen/src/org/labkey/specimen/query/SpecimenEventTable.java b/specimen/src/org/labkey/specimen/query/SpecimenEventTable.java new file mode 100644 index 00000000..cf2f10a4 --- /dev/null +++ b/specimen/src/org/labkey/specimen/query/SpecimenEventTable.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2008-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.specimen.query; + +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.ContainerFilter; +import org.labkey.api.exp.property.Domain; +import org.labkey.api.specimen.SpecimenSchema; +import org.labkey.api.specimen.model.SpecimenTablesProvider; +import org.labkey.api.study.query.AbstractStudyQuerySchema; +import org.labkey.api.study.query.AbstractStudyTable; + +public class SpecimenEventTable extends AbstractStudyTable +{ + public SpecimenEventTable(AbstractStudyQuerySchema schema, ContainerFilter cf) + { + super(schema, SpecimenSchema.get().getTableInfoSpecimenEvent(schema.getContainer()), cf, true); + setName("SpecimenEvent"); + + var vid = addWrapColumn(_rootTable.getColumn("VialId")); + vid.setDisplayColumnFactory(ColumnInfo.NOWRAP_FACTORY); + addWrapColumn(_rootTable.getColumn("SpecimenNumber")); + addWrapLocationColumn("LabId", "LabId").setLabel("Location"); + addWrapColumn(_rootTable.getColumn("Stored")); + addWrapColumn(_rootTable.getColumn("StorageFlag")); + addWrapColumn(_rootTable.getColumn("StorageDate")); + addWrapColumn(_rootTable.getColumn("ShipFlag")); + addWrapColumn(_rootTable.getColumn("ShipBatchNumber")); + addWrapColumn(_rootTable.getColumn("ShipDate")); + addWrapColumn(_rootTable.getColumn("LabReceiptDate")); + addWrapColumn(_rootTable.getColumn("SpecimenCondition")); + addWrapColumn(_rootTable.getColumn("Comments")); + addWrapParticipantColumn("PTID").setKeyField(true); + addWrapColumn(_rootTable.getColumn("DrawTimestamp")); + addWrapColumn(_rootTable.getColumn("SalReceiptDate")); + addWrapTypeColumn("PrimaryType", "PrimaryTypeId"); + addWrapTypeColumn("DerivativeType", "DerivativeTypeId"); + addWrapTypeColumn("AdditiveType", "AdditiveTypeId"); + addWrapTypeColumn("DerivativeType2", "DerivativeTypeId2"); + addWrapColumn(_rootTable.getColumn("VisitValue")); + addWrapColumn(_rootTable.getColumn("VisitDescription")); + addWrapColumn(_rootTable.getColumn("ClassId")); + addWrapColumn(_rootTable.getColumn("ProtocolNumber")); + addWrapColumn(_rootTable.getColumn("Volume")); + addWrapColumn(_rootTable.getColumn("VolumeUnits")); + addWrapColumn(_rootTable.getColumn("SubAdditiveDerivative")); + addWrapLocationColumn("Clinic", "OriginatingLocationId"); + addWrapColumn(_rootTable.getColumn("FrozenTime")); + addWrapColumn(_rootTable.getColumn("ProcessingTime")); + addWrapColumn(_rootTable.getColumn("PrimaryVolume")); + addWrapColumn(_rootTable.getColumn("PrimaryVolumeUnits")); + addWrapColumn(_rootTable.getColumn("ProcessingDate")); + addWrapColumn(_rootTable.getColumn("ProcessedByInitials")); + addWrapColumn(_rootTable.getColumn("ShippedFromLab")); + addWrapColumn(_rootTable.getColumn("ShippedToLab")); + addWrapColumn(_rootTable.getColumn("ExpectedTimeValue")); + addWrapColumn(_rootTable.getColumn("ExpectedTimeUnit")); + addWrapColumn(_rootTable.getColumn("UpdateTimestamp")); + addWrapColumn(_rootTable.getColumn("TotalCellCount")); + addWrapColumn(_rootTable.getColumn("TubeType")); + addWrapColumn(_rootTable.getColumn("QualityComments")); + addWrapColumn(_rootTable.getColumn("ExternalId")).setHidden(true); + addWrapColumn(_rootTable.getColumn("OtherSpecimenId")); + addWrapColumn(_rootTable.getColumn("ParentSpecimenId")); + var obsoleteColumn = addWrapColumn(_rootTable.getColumn("Obsolete")); + obsoleteColumn.setHidden(true); + addContainerColumn(true); + + // Add optional fields + SpecimenTablesProvider specimenTablesProvider = new SpecimenTablesProvider(schema.getContainer(), null, null); + Domain specimenEventDomain = specimenTablesProvider.getDomain("SpecimenEvent", false, false); + if (null == specimenEventDomain) + throw new IllegalStateException("Expected SpecimenEvent table to already be created."); + + addOptionalColumns(specimenEventDomain.getNonBaseProperties(), false, null); + } +} diff --git a/specimen/src/org/labkey/specimen/query/SpecimenRequestStatusTable.java b/specimen/src/org/labkey/specimen/query/SpecimenRequestStatusTable.java new file mode 100644 index 00000000..3051895d --- /dev/null +++ b/specimen/src/org/labkey/specimen/query/SpecimenRequestStatusTable.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2008-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.specimen.query; + +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.ContainerFilter; +import org.labkey.api.specimen.SpecimenSchema; +import org.labkey.api.specimen.model.SpecimenTablesProvider; +import org.labkey.api.study.query.AbstractStudyQuerySchema; +import org.labkey.api.study.query.AbstractStudyTable; + +public class SpecimenRequestStatusTable extends AbstractStudyTable +{ + public SpecimenRequestStatusTable(AbstractStudyQuerySchema schema, ContainerFilter cf) + { + super(schema, SpecimenSchema.get().getTableInfoSampleRequestStatus(), cf); + setName(SpecimenTablesProvider.SPECIMEN_REQUEST_STATUSES_TABLE_NAME); + for (ColumnInfo baseColumn : _rootTable.getColumns()) + { + String name = baseColumn.getName(); + if ("Container".equalsIgnoreCase(name) || "EntityId".equalsIgnoreCase(name)) + continue; + addWrapColumn(baseColumn); + } + } +} diff --git a/specimen/src/org/labkey/specimen/query/SpecimenRequestTable.java b/specimen/src/org/labkey/specimen/query/SpecimenRequestTable.java new file mode 100644 index 00000000..c18e4531 --- /dev/null +++ b/specimen/src/org/labkey/specimen/query/SpecimenRequestTable.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008-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.specimen.query; + +import org.labkey.api.data.ContainerFilter; +import org.labkey.api.data.TableInfo; +import org.labkey.api.query.AliasedColumn; +import org.labkey.api.query.FieldKey; +import org.labkey.api.query.LookupForeignKey; +import org.labkey.api.specimen.SpecimenSchema; +import org.labkey.api.study.query.AbstractStudyQuerySchema; +import org.labkey.api.study.query.AbstractStudyTable; + +import java.util.ArrayList; +import java.util.List; + +import static org.labkey.api.specimen.model.SpecimenTablesProvider.SPECIMEN_REQUEST_TABLE_NAME; + +public class SpecimenRequestTable extends AbstractStudyTable +{ + public SpecimenRequestTable(AbstractStudyQuerySchema schema, ContainerFilter cf) + { + super(schema, SpecimenSchema.get().getTableInfoSampleRequest(), cf); + setName(SPECIMEN_REQUEST_TABLE_NAME); + + AliasedColumn rowIdColumn = new AliasedColumn(this, "RequestId", _rootTable.getColumn("RowId")); + rowIdColumn.setKeyField(true); + addColumn(rowIdColumn); + AliasedColumn statusColumn = new AliasedColumn(this, "Status", _rootTable.getColumn("StatusId")); + statusColumn.setFk(new LookupForeignKey(null, (String) null, "RowId", "Label") + { + @Override + public TableInfo getLookupTableInfo() + { + return new SpecimenRequestStatusTable(_userSchema, cf); + } + }); + statusColumn.setKeyField(true); + addColumn(statusColumn); + + addWrapLocationColumn("Destination", "DestinationSiteId").setKeyField(true); + addWrapColumn(_rootTable.getColumn("Comments")); + // there are links to filter by 'createdby' in the UI; it's necessary that this column always + // be available, so we set it as a key field. + addWrapColumn(_rootTable.getColumn("CreatedBy")).setKeyField(true); + addWrapColumn(_rootTable.getColumn("Created")); + addWrapColumn(_rootTable.getColumn("ModifiedBy")); + addWrapColumn(_rootTable.getColumn("Modified")); + var hiddenColumn = addWrapColumn(_rootTable.getColumn("Hidden")); + hiddenColumn.setHidden(true); + hiddenColumn.setIsUnselectable(true); + + List fieldKeys = new ArrayList<>(); + fieldKeys.add(FieldKey.fromParts("RequestId")); + fieldKeys.add(FieldKey.fromParts("Status")); + fieldKeys.add(FieldKey.fromParts("Destination")); + fieldKeys.add(FieldKey.fromParts("CreatedBy")); + fieldKeys.add(FieldKey.fromParts("Created")); + setDefaultVisibleColumns(fieldKeys); + } +} diff --git a/specimen/src/org/labkey/specimen/query/SpecimenVialCountTable.java b/specimen/src/org/labkey/specimen/query/SpecimenVialCountTable.java new file mode 100644 index 00000000..3a9022c6 --- /dev/null +++ b/specimen/src/org/labkey/specimen/query/SpecimenVialCountTable.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2009-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.specimen.query; + +import org.jetbrains.annotations.NotNull; +import org.labkey.api.data.ContainerFilter; +import org.labkey.api.data.JdbcType; +import org.labkey.api.data.SQLFragment; +import org.labkey.api.data.TableInfo; +import org.labkey.api.query.ExprColumn; +import org.labkey.api.specimen.SpecimenMigrationService; +import org.labkey.api.specimen.SpecimenSchema; +import org.labkey.api.study.query.AbstractStudyQuerySchema; +import org.labkey.api.study.query.AbstractStudyTable; + +import static org.labkey.api.specimen.model.SpecimenTablesProvider.SPECIMEN_VIAL_COUNT_TABLE_NAME; + +public class SpecimenVialCountTable extends AbstractStudyTable +{ + public SpecimenVialCountTable(AbstractStudyQuerySchema schema, ContainerFilter cf) + { + super(schema, SpecimenSchema.get().getTableInfoVial(schema.getContainer()), cf); + setName(SPECIMEN_VIAL_COUNT_TABLE_NAME); + setTitle("VialCounts"); + + addContainerColumn(true).setHidden(true); + addWrapColumn(_rootTable.getColumn("SpecimenHash")).setHidden(true); + + addColumn(new ExprColumn(this, "TotalCount", SQLFragment.unsafe(ExprColumn.STR_TABLE_ALIAS + ".VialCount"), JdbcType.INTEGER)); + + SpecimenMigrationService sms = SpecimenMigrationService.get(); + boolean enableSpecimenRequest = sms != null && sms.isEnableRequests(getContainer()); + + addColumn(new ExprColumn(this, "LockedInRequest", SQLFragment.unsafe(ExprColumn.STR_TABLE_ALIAS + ".LockedInRequestCount"), JdbcType.INTEGER)).setHidden(!enableSpecimenRequest); + addColumn(new ExprColumn(this, "AtRepository", SQLFragment.unsafe(ExprColumn.STR_TABLE_ALIAS + ".AtRepositoryCount"), JdbcType.INTEGER)); + addColumn(new ExprColumn(this, "Available", SQLFragment.unsafe(ExprColumn.STR_TABLE_ALIAS + ".AvailableCount"), JdbcType.INTEGER)).setHidden(!enableSpecimenRequest); + addColumn(new ExprColumn(this, "ExpectedAvailable", SQLFragment.unsafe(ExprColumn.STR_TABLE_ALIAS + ".ExpectedAvailableCount"), JdbcType.INTEGER)).setHidden(!enableSpecimenRequest); + } + + @NotNull + @Override + public SQLFragment getFromSQL(String alias) + { + checkReadBeforeExecute(); + TableInfo tableInfoVial = SpecimenSchema.get().getTableInfoVial(getContainer()); + if (null == tableInfoVial) + throw new IllegalStateException("Vial table not found."); + + SQLFragment sql = SQLFragment.unsafe("(SELECT ? As Container, Vial.specimenhash, sum(Vial.volume) AS totalvolume,\n" + + " sum(CASE Vial.available\n" + + " WHEN ? THEN Vial.volume\n" + + " ELSE 0\n" + + " END) AS availablevolume, count(Vial.globaluniqueid) AS vialcount, sum(\n" + + " CASE Vial.lockedinrequest\n" + + " WHEN ? THEN 1\n" + + " ELSE 0\n" + + " END) AS lockedinrequestcount, sum(\n" + + " CASE Vial.atrepository\n" + + " WHEN ? THEN 1\n" + + " ELSE 0\n" + + " END) AS atrepositorycount, sum(\n" + + " CASE Vial.available\n" + + " WHEN ? THEN 1\n" + + " ELSE 0\n" + + " END) AS availablecount, count(Vial.globaluniqueid) - sum(\n" + + " CASE \n" + + " CASE Vial.lockedinrequest\n" + + " WHEN ? THEN 1\n" + + " ELSE 0\n" + + " END | \n" + + " CASE Vial.requestable\n" + + " WHEN ? THEN 1\n" + + " ELSE 0\n" + + " END\n" + + " WHEN 1 THEN 1\n" + + " ELSE 0\n" + + " END) AS expectedavailablecount\n" + + " FROM "); + sql.add(getContainer()); + sql.add(Boolean.TRUE); + sql.add(Boolean.TRUE); + sql.add(Boolean.TRUE); + sql.add(Boolean.TRUE); + sql.add(Boolean.TRUE); + sql.add(Boolean.FALSE); + sql.append(tableInfoVial.getFromSQL("Vial")) + .unsafeAppend("\n GROUP BY Vial.specimenhash) ") + .appendIdentifier(alias); + return sql; + } +} diff --git a/specimen/src/org/labkey/specimen/query/VialRequestTable.java b/specimen/src/org/labkey/specimen/query/VialRequestTable.java new file mode 100644 index 00000000..f3f220ec --- /dev/null +++ b/specimen/src/org/labkey/specimen/query/VialRequestTable.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2009-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.specimen.query; + +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.ContainerFilter; +import org.labkey.api.data.DataColumn; +import org.labkey.api.data.DisplayColumn; +import org.labkey.api.data.DisplayColumnFactory; +import org.labkey.api.data.TableInfo; +import org.labkey.api.query.AliasedColumn; +import org.labkey.api.query.FilteredTable; +import org.labkey.api.query.LookupForeignKey; +import org.labkey.api.specimen.SpecimenSchema; +import org.labkey.api.study.query.AbstractStudyQuerySchema; + +import static org.labkey.api.specimen.model.SpecimenTablesProvider.VIAL_REQUEST_TABLE_NAME; + +public class VialRequestTable extends FilteredTable +{ + public VialRequestTable(final AbstractStudyQuerySchema schema, ContainerFilter cf) + { + super(SpecimenSchema.get().getTableInfoSampleRequestSpecimen(), schema, cf); + setName(VIAL_REQUEST_TABLE_NAME); + + for (ColumnInfo baseColumn : _rootTable.getColumns()) + { + String name = baseColumn.getName(); + if ("SpecimenGlobalUniqueId".equalsIgnoreCase(name)) + { + AliasedColumn globalUniqueIdColumn = new AliasedColumn(this, "Vial", _rootTable.getColumn("SpecimenGlobalUniqueId")) + { + @Override + public ColumnInfo getDisplayField() + { + return null; + } + }; + LookupForeignKey fk = new LookupForeignKey(null, (String) null, "GlobalUniqueId", "GlobalUniqueId") + { + @Override + public TableInfo getLookupTableInfo() + { + return schema.createSpecimenDetailLookupTable(cf); + } + }; + fk.setPrefixColumnCaption(false); + globalUniqueIdColumn.setFk(fk); + globalUniqueIdColumn.setKeyField(true); + globalUniqueIdColumn.setDisplayColumnFactory(new DisplayColumnFactory() + { + @Override + public DisplayColumn createRenderer(ColumnInfo colInfo) + { + return new DataColumn(colInfo, false); + } + }); + + addColumn(globalUniqueIdColumn); + } + else if ("SampleRequestId".equalsIgnoreCase(name)) + { + AliasedColumn requestIdColumn = new AliasedColumn(this, "Request", _rootTable.getColumn("SampleRequestId")); + LookupForeignKey fk = new LookupForeignKey(null, (String) null, "RequestId", "RequestId") + { + @Override + public TableInfo getLookupTableInfo() + { + return new SpecimenRequestTable(schema, cf); + } + }; + fk.setPrefixColumnCaption(false); + requestIdColumn.setFk(fk); + requestIdColumn.setKeyField(true); + addColumn(requestIdColumn); + } + else if (!"Container".equalsIgnoreCase(name)) + { + var wrappedColumn = addWrapColumn(baseColumn); + if ("RowId".equalsIgnoreCase(name)) + wrappedColumn.setHidden(true); + } + } + } +}