From 187dae0ee1182b28fc42d988eaf718904a52ebf3 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Sat, 21 Nov 2026 12:52:57 -0800 Subject: [PATCH 1/3] Provide specimen tables and the specimen sample type domain kind --- .../org/labkey/specimen/SpecimenModule.java | 55 ++++++-- .../SpecimenSampleTypeDomainKind.java | 92 ++++++++++++++ .../specimen/query/SpecimenCommentTable.java | 70 +++++++++++ .../specimen/query/SpecimenEventTable.java | 91 ++++++++++++++ .../query/SpecimenRequestStatusTable.java | 40 ++++++ .../specimen/query/SpecimenRequestTable.java | 75 +++++++++++ .../query/SpecimenVialCountTable.java | 119 ++++++++++++++++++ .../specimen/query/VialRequestTable.java | 98 +++++++++++++++ 8 files changed, 631 insertions(+), 9 deletions(-) create mode 100644 specimen/src/org/labkey/specimen/SpecimenSampleTypeDomainKind.java create mode 100644 specimen/src/org/labkey/specimen/query/SpecimenCommentTable.java create mode 100644 specimen/src/org/labkey/specimen/query/SpecimenEventTable.java create mode 100644 specimen/src/org/labkey/specimen/query/SpecimenRequestStatusTable.java create mode 100644 specimen/src/org/labkey/specimen/query/SpecimenRequestTable.java create mode 100644 specimen/src/org/labkey/specimen/query/SpecimenVialCountTable.java create mode 100644 specimen/src/org/labkey/specimen/query/VialRequestTable.java diff --git a/specimen/src/org/labkey/specimen/SpecimenModule.java b/specimen/src/org/labkey/specimen/SpecimenModule.java index 045c7589..3f91e03e 100644 --- a/specimen/src/org/labkey/specimen/SpecimenModule.java +++ b/specimen/src/org/labkey/specimen/SpecimenModule.java @@ -33,6 +33,7 @@ import org.labkey.api.data.SqlSelector; import org.labkey.api.data.TableInfo; import org.labkey.api.data.TableSelector; +import org.labkey.api.exp.property.PropertyService; import org.labkey.api.module.ModuleContext; import org.labkey.api.module.SpringModule; import org.labkey.api.pipeline.PipelineJob; @@ -42,7 +43,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 +57,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 +81,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 +116,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"); @@ -164,6 +178,7 @@ protected void init() RoleManager.registerRole(new SpecimenRequesterRole()); AttachmentService.get().registerAttachmentParentType(SpecimenRequestEventType.get()); + PropertyService.get().registerDomainKind(new SpecimenSampleTypeDomainKind()); addController("specimen", SpecimenController.class, "study-samples"); addController("specimen-api", SpecimenApiController.class, "study-samples-api", "specimens-api"); @@ -230,31 +245,53 @@ 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) + { + SpecimenCommentTable result = new SpecimenCommentTable(schema, cf, joinBackToSpecimens); + result.setContainerFilter(cf); + return result; + } + @Override public @Nullable SafeToRender getSpecimenSettingsLink(Container c, User user) { diff --git a/specimen/src/org/labkey/specimen/SpecimenSampleTypeDomainKind.java b/specimen/src/org/labkey/specimen/SpecimenSampleTypeDomainKind.java new file mode 100644 index 00000000..0d39f8f8 --- /dev/null +++ b/specimen/src/org/labkey/specimen/SpecimenSampleTypeDomainKind.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2019-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; + +import org.labkey.api.data.Container; +import org.labkey.api.exp.Lsid; +import org.labkey.api.exp.property.Domain; +import org.labkey.api.security.User; +import org.labkey.api.study.SpecimenService; +import org.labkey.api.view.ActionURL; +import org.labkey.api.writer.ContainerUser; +import org.labkey.api.exp.api.SampleTypeDomainKind; + +public class SpecimenSampleTypeDomainKind extends SampleTypeDomainKind +{ + public SpecimenSampleTypeDomainKind() + { + } + + @Override + public Priority getPriority(String domainURI) + { + Lsid lsid = new Lsid(domainURI); + String prefix = lsid.getNamespacePrefix(); + String name = lsid.getObjectId(); + if ("SampleSet".equals(prefix) && SpecimenService.SAMPLE_TYPE_NAME.equals(name)) + return Priority.HIGH; + return null; + } + + @Override + public String getStorageSchemaName() + { + // Don't provision table with no properties + return null; + } + + @Override + public ActionURL urlEditDefinition(Domain domain, ContainerUser containerUser) + { + return null; + } + + @Override + public boolean canEditDefinition(User user, Domain domain) + { + return false; + } + + @Override + public boolean canCreateDefinition(User user, Container container) + { + return false; + } + + @Override + public boolean canDeleteDefinition(User user, Domain domain) + { + return false; + } + + @Override + public ActionURL urlCreateDefinition(String schemaName, String queryName, Container container, User user) + { + return null; + } + + @Override + public boolean allowUniqueConstraintProperties() + { + return false; + } + + @Override + public boolean allowCalculatedFields() + { + return false; + } +} 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..d098da85 --- /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); + 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..4d0e5fba --- /dev/null +++ b/specimen/src/org/labkey/specimen/query/SpecimenVialCountTable.java @@ -0,0 +1,119 @@ +/* + * 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, StudySchema.getInstance().getTableInfoSpecimenVialCount()); + + addWrapColumn(_rootTable.getColumn("Container")).setHidden(true); + addWrapColumn(_rootTable.getColumn("SpecimenHash")).setHidden(true); + + addColumn(new AliasedColumn(this, "TotalCount", _rootTable.getColumn("VialCount"))); + + boolean enableSpecimenRequest = SampleManager.getInstance().getRepositorySettings(getContainer()).isEnableRequests(); + + addColumn(new AliasedColumn(this, "LockedInRequest", _rootTable.getColumn("LockedInRequestCount"))).setHidden(!enableSpecimenRequest); + addColumn(new AliasedColumn(this, "AtRepository", _rootTable.getColumn("AtRepositoryCount"))); + addColumn(new AliasedColumn(this, "Available", _rootTable.getColumn("AvailableCount"))).setHidden(!enableSpecimenRequest); + addColumn(new AliasedColumn(this, "ExpectedAvailable", _rootTable.getColumn("ExpectedAvailableCount"))).setHidden(!enableSpecimenRequest); +*/ + 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); + } + } + } +} From a94f61b082bf2f92c4398b9839c6c5e659f60818 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 23 Nov 2026 19:46:20 -0800 Subject: [PATCH 2/3] Leave the specimen sample type domain kind in study --- .../org/labkey/specimen/SpecimenModule.java | 2 - .../SpecimenSampleTypeDomainKind.java | 92 ------------------- 2 files changed, 94 deletions(-) delete mode 100644 specimen/src/org/labkey/specimen/SpecimenSampleTypeDomainKind.java diff --git a/specimen/src/org/labkey/specimen/SpecimenModule.java b/specimen/src/org/labkey/specimen/SpecimenModule.java index 3f91e03e..ad640b0d 100644 --- a/specimen/src/org/labkey/specimen/SpecimenModule.java +++ b/specimen/src/org/labkey/specimen/SpecimenModule.java @@ -33,7 +33,6 @@ import org.labkey.api.data.SqlSelector; import org.labkey.api.data.TableInfo; import org.labkey.api.data.TableSelector; -import org.labkey.api.exp.property.PropertyService; import org.labkey.api.module.ModuleContext; import org.labkey.api.module.SpringModule; import org.labkey.api.pipeline.PipelineJob; @@ -178,7 +177,6 @@ protected void init() RoleManager.registerRole(new SpecimenRequesterRole()); AttachmentService.get().registerAttachmentParentType(SpecimenRequestEventType.get()); - PropertyService.get().registerDomainKind(new SpecimenSampleTypeDomainKind()); addController("specimen", SpecimenController.class, "study-samples"); addController("specimen-api", SpecimenApiController.class, "study-samples-api", "specimens-api"); diff --git a/specimen/src/org/labkey/specimen/SpecimenSampleTypeDomainKind.java b/specimen/src/org/labkey/specimen/SpecimenSampleTypeDomainKind.java deleted file mode 100644 index 0d39f8f8..00000000 --- a/specimen/src/org/labkey/specimen/SpecimenSampleTypeDomainKind.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2019-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; - -import org.labkey.api.data.Container; -import org.labkey.api.exp.Lsid; -import org.labkey.api.exp.property.Domain; -import org.labkey.api.security.User; -import org.labkey.api.study.SpecimenService; -import org.labkey.api.view.ActionURL; -import org.labkey.api.writer.ContainerUser; -import org.labkey.api.exp.api.SampleTypeDomainKind; - -public class SpecimenSampleTypeDomainKind extends SampleTypeDomainKind -{ - public SpecimenSampleTypeDomainKind() - { - } - - @Override - public Priority getPriority(String domainURI) - { - Lsid lsid = new Lsid(domainURI); - String prefix = lsid.getNamespacePrefix(); - String name = lsid.getObjectId(); - if ("SampleSet".equals(prefix) && SpecimenService.SAMPLE_TYPE_NAME.equals(name)) - return Priority.HIGH; - return null; - } - - @Override - public String getStorageSchemaName() - { - // Don't provision table with no properties - return null; - } - - @Override - public ActionURL urlEditDefinition(Domain domain, ContainerUser containerUser) - { - return null; - } - - @Override - public boolean canEditDefinition(User user, Domain domain) - { - return false; - } - - @Override - public boolean canCreateDefinition(User user, Container container) - { - return false; - } - - @Override - public boolean canDeleteDefinition(User user, Domain domain) - { - return false; - } - - @Override - public ActionURL urlCreateDefinition(String schemaName, String queryName, Container container, User user) - { - return null; - } - - @Override - public boolean allowUniqueConstraintProperties() - { - return false; - } - - @Override - public boolean allowCalculatedFields() - { - return false; - } -} From 01462ba6dd71eae09dcc9e6126980c8442eb671b Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Tue, 24 Nov 2026 10:47:04 -0800 Subject: [PATCH 3/3] Apply the requested container filter to SpecimenComment and drop dead code --- .../src/org/labkey/specimen/SpecimenModule.java | 4 +--- .../specimen/query/SpecimenCommentTable.java | 2 +- .../specimen/query/SpecimenVialCountTable.java | 14 -------------- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/specimen/src/org/labkey/specimen/SpecimenModule.java b/specimen/src/org/labkey/specimen/SpecimenModule.java index ad640b0d..deb23052 100644 --- a/specimen/src/org/labkey/specimen/SpecimenModule.java +++ b/specimen/src/org/labkey/specimen/SpecimenModule.java @@ -285,9 +285,7 @@ public void addSpecimenTableNames(Set names) @Override public TableInfo createSpecimenCommentTable(AbstractStudyQuerySchema schema, ContainerFilter cf, boolean joinBackToSpecimens) { - SpecimenCommentTable result = new SpecimenCommentTable(schema, cf, joinBackToSpecimens); - result.setContainerFilter(cf); - return result; + return new SpecimenCommentTable(schema, cf, joinBackToSpecimens); } @Override diff --git a/specimen/src/org/labkey/specimen/query/SpecimenCommentTable.java b/specimen/src/org/labkey/specimen/query/SpecimenCommentTable.java index d098da85..9e024d5a 100644 --- a/specimen/src/org/labkey/specimen/query/SpecimenCommentTable.java +++ b/specimen/src/org/labkey/specimen/query/SpecimenCommentTable.java @@ -37,7 +37,7 @@ public SpecimenCommentTable(final AbstractStudyQuerySchema schema, ContainerFilt public SpecimenCommentTable(final AbstractStudyQuerySchema schema, ContainerFilter cf, boolean joinBackToSpecimens) { - super(SpecimenSchema.get().getTableInfoSpecimenComment(), schema); + super(SpecimenSchema.get().getTableInfoSpecimenComment(), schema, cf); for (ColumnInfo baseColumn : _rootTable.getColumns()) { String name = baseColumn.getName(); diff --git a/specimen/src/org/labkey/specimen/query/SpecimenVialCountTable.java b/specimen/src/org/labkey/specimen/query/SpecimenVialCountTable.java index 4d0e5fba..3a9022c6 100644 --- a/specimen/src/org/labkey/specimen/query/SpecimenVialCountTable.java +++ b/specimen/src/org/labkey/specimen/query/SpecimenVialCountTable.java @@ -33,20 +33,6 @@ public class SpecimenVialCountTable extends AbstractStudyTable