Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions specimen/src/org/labkey/specimen/SpecimenModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -230,31 +243,51 @@ public boolean isEnableRequests(Container c)
}

@Override
public void addSpecimenPivotTableNames(Set<String> names)
public void addSpecimenTableNames(Set<String> 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)
{
Expand Down
70 changes: 70 additions & 0 deletions specimen/src/org/labkey/specimen/query/SpecimenCommentTable.java
Original file line number Diff line number Diff line change
@@ -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<AbstractStudyQuerySchema>
{
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");
}
}
91 changes: 91 additions & 0 deletions specimen/src/org/labkey/specimen/query/SpecimenEventTable.java
Original file line number Diff line number Diff line change
@@ -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<AbstractStudyQuerySchema>
{
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);
}
}
Original file line number Diff line number Diff line change
@@ -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<AbstractStudyQuerySchema>
{
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);
}
}
}
75 changes: 75 additions & 0 deletions specimen/src/org/labkey/specimen/query/SpecimenRequestTable.java
Original file line number Diff line number Diff line change
@@ -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<AbstractStudyQuerySchema>
{
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<FieldKey> 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);
}
}
Loading