diff --git a/study/api-src/org/labkey/api/specimen/SpecimenColumns.java b/specimen/src/org/labkey/specimen/SpecimenColumns.java similarity index 97% rename from study/api-src/org/labkey/api/specimen/SpecimenColumns.java rename to specimen/src/org/labkey/specimen/SpecimenColumns.java index 57fe759567d..613b660fc8c 100644 --- a/study/api-src/org/labkey/api/specimen/SpecimenColumns.java +++ b/specimen/src/org/labkey/specimen/SpecimenColumns.java @@ -1,9 +1,9 @@ -package org.labkey.api.specimen; +package org.labkey.specimen; -import org.labkey.api.specimen.importer.ImportTypes; -import org.labkey.api.specimen.importer.ImportableColumn; -import org.labkey.api.specimen.importer.SpecimenColumn; -import org.labkey.api.specimen.importer.TargetTable; +import org.labkey.specimen.importer.ImportTypes; +import org.labkey.specimen.importer.ImportableColumn; +import org.labkey.specimen.importer.SpecimenColumn; +import org.labkey.specimen.importer.TargetTable; import java.util.Arrays; import java.util.Collection; diff --git a/specimen/src/org/labkey/specimen/SpecimenManager.java b/specimen/src/org/labkey/specimen/SpecimenManager.java index 8165c3b5298..749ab6214c2 100644 --- a/specimen/src/org/labkey/specimen/SpecimenManager.java +++ b/specimen/src/org/labkey/specimen/SpecimenManager.java @@ -1,5 +1,6 @@ package org.labkey.specimen; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.labkey.api.audit.AuditLogService; import org.labkey.api.data.ColumnInfo; @@ -8,6 +9,7 @@ import org.labkey.api.data.SQLFragment; import org.labkey.api.data.SimpleFilter; import org.labkey.api.data.Sort; +import org.labkey.api.data.SqlExecutor; import org.labkey.api.data.SqlSelector; import org.labkey.api.data.Table; import org.labkey.api.data.TableInfo; @@ -18,9 +20,10 @@ import org.labkey.api.query.QueryService; import org.labkey.api.query.UserSchema; import org.labkey.api.security.User; +import org.labkey.api.specimen.SpecimenEvent; +import org.labkey.api.specimen.SpecimenEventManager; import org.labkey.api.specimen.SpecimenManagerNew; import org.labkey.api.specimen.SpecimenQuerySchema; -import org.labkey.api.specimen.SpecimenRequestException; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.Vial; import org.labkey.api.specimen.location.LocationImpl; @@ -34,6 +37,7 @@ import org.labkey.api.util.DateUtil; import org.labkey.api.util.HtmlString; import org.labkey.api.util.Path; +import org.labkey.api.view.NotFoundException; import org.labkey.api.view.ViewContext; import org.labkey.specimen.model.AdditiveType; import org.labkey.specimen.model.DerivativeType; @@ -347,7 +351,7 @@ public List getVials(Container container, User user, String participantId, SimpleFilter filter = SimpleFilter.createContainerFilter(container); filter.addClause(new SimpleFilter.SQLClause("LOWER(ptid) = LOWER(?)", new Object[] {participantId}, FieldKey.fromParts("ptid"))); filter.addCondition(FieldKey.fromParts("VisitValue"), visit); - return SpecimenManagerNew.get().getVials(container, user, filter); + return getVials(container, user, filter); } public List getVials(Container container, User user, int[] vialsRowIds) @@ -355,7 +359,7 @@ public List getVials(Container container, User user, int[] vialsRowIds) Set uniqueRowIds = new HashSet<>(vialsRowIds.length); for (int vialRowId : vialsRowIds) uniqueRowIds.add((long)vialRowId); - return SpecimenManagerNew.get().getVials(container, user, uniqueRowIds); + return getVials(container, user, uniqueRowIds); } public List getVials(Container container, User user, String[] globalUniqueIds) throws SpecimenRequestException @@ -365,7 +369,7 @@ public List getVials(Container container, User user, String[] globalUnique Collections.addAll(uniqueRowIds, globalUniqueIds); List ids = new ArrayList<>(uniqueRowIds); filter.addInClause(FieldKey.fromParts("GlobalUniqueId"), ids); - List vials = SpecimenManagerNew.get().getVials(container, user, filter); + List vials = getVials(container, user, filter); if (vials == null || vials.size() != ids.size()) throw new SpecimenRequestException("Vial not found."); // an id has no matching specimen, let caller determine what to report return vials; @@ -377,7 +381,7 @@ public List getVials(Container container, User user, String participantId, Calendar endCal = DateUtil.newCalendar(date.getTime()); endCal.add(Calendar.DATE, 1); filter.addClause(new SimpleFilter.SQLClause("DrawTimestamp >= ? AND DrawTimestamp < ?", new Object[] {date, endCal.getTime()})); - return SpecimenManagerNew.get().getVials(container, user, filter); + return getVials(container, user, filter); } @Nullable @@ -415,14 +419,14 @@ private List getDerivativeTypes(final Container container, @Null public boolean isSpecimensEmpty(Container container, User user) { - TableSelector selector = SpecimenManagerNew.get().getSpecimensSelector(container, user, null); + TableSelector selector = getSpecimensSelector(container, user, null); return !selector.exists(); } public Vial getVial(Container container, User user, String globalUniqueId) { SimpleFilter filter = new SimpleFilter(new SimpleFilter.SQLClause("LOWER(GlobalUniqueId) = LOWER(?)", new Object[] { globalUniqueId })); - List matches = SpecimenManagerNew.get().getVials(container, user, filter); + List matches = getVials(container, user, filter); if (matches == null || matches.isEmpty()) return null; if (matches.size() > 1) @@ -453,7 +457,7 @@ public List getRequestableVials(Container container, User user, Set { SimpleFilter filter = SimpleFilter.createContainerFilter(container); filter.addInClause(FieldKey.fromParts("RowId"), vialRowIds).addCondition(FieldKey.fromString("available"), true); - return SpecimenManagerNew.get().getVials(container, user, filter); + return getVials(container, user, filter); } public Map> getVialsForSpecimenHashes(Container container, User user, Collection hashes, boolean onlyAvailable) @@ -462,7 +466,7 @@ public Map> getVialsForSpecimenHashes(Container container, Use filter.addInClause(FieldKey.fromParts("SpecimenHash"), hashes); if (onlyAvailable) filter.addCondition(FieldKey.fromParts("Available"), true); - List vials = SpecimenManagerNew.get().getVials(container, user, filter); + List vials = getVials(container, user, filter); Map> map = new HashMap<>(); for (Vial vial : vials) { @@ -473,4 +477,117 @@ public Map> getVialsForSpecimenHashes(Container container, Use return map; } + + public List getVials(Container container, User user, Set vialRowIds) + { + // Take a set to eliminate dups - issue 26940 + + SimpleFilter filter = SimpleFilter.createContainerFilter(container); + filter.addInClause(FieldKey.fromParts("RowId"), vialRowIds); + List vials = getVials(container, user, filter); + if (vials.size() != vialRowIds.size()) + { + List unmatchedRowIds = new ArrayList<>(vialRowIds); + for (Vial vial : vials) + { + unmatchedRowIds.remove(vial.getRowId()); + } + throw new SpecimenRequestException("One or more specimen RowIds had no matching specimen: " + unmatchedRowIds); + } + return vials; + } + + public List getVials(final Container container, final User user, SimpleFilter filter) + { + // TODO: LinkedList? + final List vials = new ArrayList<>(); + + getSpecimensSelector(container, user, filter) + .forEachMap(map -> vials.add(new Vial(container, map))); + + return vials; + } + + public TableSelector getSpecimensSelector(final Container container, final User user, SimpleFilter filter) + { + Study study = StudyService.get().getStudy(container); + if (study == null) + { + throw new NotFoundException("No study in container " + container.getPath()); + } + UserSchema schema = SpecimenQuerySchema.get(study, user); + TableInfo specimenTable = schema.getTable(SpecimenQuerySchema.SPECIMEN_WRAP_TABLE_NAME); + return new TableSelector(specimenTable, filter, null); + } + + public Vial getVial(Container container, User user, long rowId) + { + SimpleFilter filter = new SimpleFilter(FieldKey.fromParts("RowId"), rowId); + List vials = getVials(container, user, filter); + if (vials.isEmpty()) + return null; + return vials.get(0); + } + + public void deleteSpecimen(@NotNull Vial vial, boolean clearCaches) + { + Container container = vial.getContainer(); + TableInfo tableInfoSpecimenEvent = SpecimenSchema.get().getTableInfoSpecimenEvent(container); + TableInfo tableInfoVial = SpecimenSchema.get().getTableInfoVial(container); + if (null == tableInfoSpecimenEvent || null == tableInfoVial) + return; + + String tableInfoSpecimenEventSelectName = tableInfoSpecimenEvent.getSelectName(); + String tableInfoVialSelectName = tableInfoVial.getSelectName(); + + SQLFragment sqlFragmentEvent = new SQLFragment("DELETE FROM "); + sqlFragmentEvent.append(tableInfoSpecimenEventSelectName).append(" WHERE VialId = ?"); + sqlFragmentEvent.add(vial.getRowId()); + new SqlExecutor(SpecimenSchema.get().getSchema()).execute(sqlFragmentEvent); + + SQLFragment sqlFragment = new SQLFragment("DELETE FROM "); + sqlFragment.append(tableInfoVialSelectName).append(" WHERE RowId = ?"); + sqlFragment.add(vial.getRowId()); + new SqlExecutor(SpecimenSchema.get().getSchema()).execute(sqlFragment); + + if (clearCaches) + { + SpecimenRequestManager.get().clearCaches(vial.getContainer()); + } + } + + public long getMaxExternalId(Container container) + { + TableInfo tableInfo = SpecimenSchema.get().getTableInfoSpecimenEvent(container); + SQLFragment sql = new SQLFragment("SELECT MAX(ExternalId) FROM "); + sql.append(tableInfo); + return new SqlSelector(tableInfo.getSchema(), sql).getArrayList(Long.class).get(0); + } + + public String getFirstProcessedByInitials(List dateOrderedEvents) + { + SpecimenEvent firstEvent = SpecimenEventManager.get().getFirstEvent(dateOrderedEvents); + return firstEvent != null ? firstEvent.getProcessedByInitials() : null; + } + + public List getSpecimenEvents(List vials, boolean includeObsolete) + { + if (vials == null || vials.isEmpty()) + return Collections.emptyList(); + Collection vialIds = new HashSet<>(); + Container container = null; + for (Vial vial : vials) + { + vialIds.add(vial.getRowId()); + if (container == null) + container = vial.getContainer(); + else if (!container.equals(vial.getContainer())) + throw new IllegalArgumentException("All specimens must be from the same container"); + } + SimpleFilter filter = new SimpleFilter(); + filter.addInClause(FieldKey.fromString("VialId"), vialIds); + if (!includeObsolete) + filter.addCondition(FieldKey.fromString("Obsolete"), false); + return SpecimenEventManager.get().getSpecimenEvents(container, filter); + } } diff --git a/specimen/src/org/labkey/specimen/SpecimenModule.java b/specimen/src/org/labkey/specimen/SpecimenModule.java index 01c6f48f9b2..e74bb9f6a1c 100644 --- a/specimen/src/org/labkey/specimen/SpecimenModule.java +++ b/specimen/src/org/labkey/specimen/SpecimenModule.java @@ -16,6 +16,7 @@ package org.labkey.specimen; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.collections4.bag.HashBag; import org.apache.commons.lang3.mutable.MutableInt; import org.apache.logging.log4j.Logger; @@ -36,21 +37,24 @@ import org.labkey.api.pipeline.PipelineJobException; import org.labkey.api.pipeline.PipelineService; import org.labkey.api.query.FieldKey; -import org.labkey.api.query.QueryParam; +import org.labkey.api.query.QuerySettings; +import org.labkey.api.query.QueryUpdateService; import org.labkey.api.query.QueryView; import org.labkey.api.query.ValidationException; +import org.labkey.api.reader.TabLoader; import org.labkey.api.security.User; import org.labkey.api.security.roles.RoleManager; import org.labkey.api.specimen.SpecimenMigrationService; import org.labkey.api.specimen.SpecimenQuerySchema; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.SpecimensPage; -import org.labkey.api.specimen.importer.SpecimenImporter; import org.labkey.api.specimen.settings.RepositorySettings; import org.labkey.api.specimen.settings.SettingsManager; +import org.labkey.api.study.MapArrayExcelWriter; import org.labkey.api.study.SpecimenService; import org.labkey.api.study.StudyInternalService; import org.labkey.api.study.StudyService; +import org.labkey.api.study.TimepointType; import org.labkey.api.study.importer.SimpleStudyImportContext; import org.labkey.api.study.importer.SimpleStudyImporterRegistry; import org.labkey.api.study.writer.SimpleStudyWriterRegistry; @@ -59,17 +63,23 @@ import org.labkey.api.util.logging.LogHelper; import org.labkey.api.view.ActionURL; import org.labkey.api.view.HttpView; +import org.labkey.api.view.ViewContext; import org.labkey.api.view.WebPartFactory; import org.labkey.specimen.actions.SpecimenApiController; import org.labkey.specimen.actions.SpecimenController; import org.labkey.specimen.importer.AbstractSpecimenTask; import org.labkey.specimen.importer.DefaultSpecimenImportStrategyFactory; +import org.labkey.specimen.importer.RequestabilityManager; +import org.labkey.specimen.importer.SimpleSpecimenImporter; +import org.labkey.specimen.importer.SpecimenImporter; import org.labkey.specimen.importer.SpecimenSchemaImporter; import org.labkey.specimen.importer.SpecimenSettingsImporter; import org.labkey.specimen.model.SpecimenRequestEventType; import org.labkey.specimen.pipeline.SampleMindedTransform; import org.labkey.specimen.pipeline.SampleMindedTransformTask; import org.labkey.specimen.pipeline.SpecimenPipeline; +import org.labkey.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenUpdateService; import org.labkey.specimen.security.roles.SpecimenCoordinatorRole; import org.labkey.specimen.security.roles.SpecimenRequesterRole; import org.labkey.specimen.view.ManageSpecimenView; @@ -82,6 +92,7 @@ import org.labkey.specimen.writer.SpecimenSettingsWriter; import org.labkey.specimen.writer.SpecimenWriter; +import java.io.IOException; import java.nio.file.Path; import java.util.Collection; import java.util.Collections; @@ -163,47 +174,63 @@ public ActionURL getSpecimensURL(Container c) } @Override - public ActionURL getSpecimenEventsURL(Container c, ActionURL returnURL) + public void importSpecimenArchive(@Nullable Path inputFile, PipelineJob job, SimpleStudyImportContext ctx, boolean merge, boolean syncParticipantVisit) throws PipelineJobException, ValidationException { - return new ActionURL(SpecimenController.SpecimenEventsAction.class, c).addReturnURL(returnURL); + AbstractSpecimenTask.doImport(inputFile, job, ctx, merge, syncParticipantVisit); } @Override - public ActionURL getInsertSpecimenQueryRowURL(Container c, String schemaName, TableInfo table) + public void clearRequestCaches(Container c) { - ActionURL url = new ActionURL(SpecimenController.InsertSpecimenQueryRowAction.class, c); - url.addParameter("schemaName", schemaName); - url.addParameter(QueryView.DATAREGIONNAME_DEFAULT + "." + QueryParam.queryName, table.getName()); + SpecimenRequestManager.get().clearCaches(c); + } + + @Override + public @Nullable QueryUpdateService getSpecimenQueryUpdateService(Container c, TableInfo queryTable) + { + return SettingsManager.get().getRepositorySettings(c).isSpecimenDataEditable() ? new SpecimenUpdateService(queryTable) : null; + } - return url; + @Override + public void importSpecimens(Container container, User user, List> specimens) throws ValidationException, IOException + { + SimpleSpecimenImporter importer = new SimpleSpecimenImporter(container, user); + importer.process(specimens, false); } @Override - public ActionURL getUpdateSpecimenQueryRowURL(Container c, String schemaName, TableInfo table) + public void exportSpecimens(Container container, User user, List> specimens, TimepointType timepointType, String participantIdLabel, HttpServletResponse response) { - ActionURL url = new ActionURL(SpecimenController.UpdateSpecimenQueryRowAction.class, c); - url.addParameter("schemaName", schemaName); - url.addParameter(QueryView.DATAREGIONNAME_DEFAULT + "." + QueryParam.queryName, table.getName()); + SimpleSpecimenImporter importer = new SimpleSpecimenImporter(container, user, timepointType, participantIdLabel); + MapArrayExcelWriter xlWriter = new MapArrayExcelWriter(specimens, importer.getSimpleSpecimenColumns()); + // Note: I don't think this is having any effect on the output because ExcelColumn.renderCaption() uses + // the DisplayColumn's caption, not its own caption. That seems wrong... + xlWriter.setColumnModifier(col -> col.setCaption(importer.label(col.getName()))); + xlWriter.renderWorkbook(response); + } - return url; + @Override + public Map getColumnLabelMap(Container container, User user) + { + return new SimpleSpecimenImporter(container, user).getColumnLabels(); } @Override - public void importSpecimenArchive(@Nullable Path inputFile, PipelineJob job, SimpleStudyImportContext ctx, boolean merge, boolean syncParticipantVisit) throws PipelineJobException, ValidationException + public void fixupSpecimenColumns(Container container, User user, TabLoader loader) throws IOException { - AbstractSpecimenTask.doImport(inputFile, job, ctx, merge, syncParticipantVisit); + new SimpleSpecimenImporter(container, user).fixupSpecimenColumns(loader); } @Override - public void clearRequestCaches(Container c) + public QueryView getSpecimenQueryView(ViewContext context, QuerySettings settings) { - SpecimenRequestManager.get().clearCaches(c); + return SpecimenQueryView.createView(context, settings, SpecimenQueryView.ViewType.VIALS); } @Override - public void updateVialCounts(Container container, User user) + public void setDefaultRequestabilityRules(Container container, User user) { - SpecimenRequestManager.get().updateVialCounts(container, user); + RequestabilityManager.getInstance().setDefaultRules(container, user); } }); } diff --git a/study/api-src/org/labkey/api/specimen/SpecimenRequestException.java b/specimen/src/org/labkey/specimen/SpecimenRequestException.java similarity index 86% rename from study/api-src/org/labkey/api/specimen/SpecimenRequestException.java rename to specimen/src/org/labkey/specimen/SpecimenRequestException.java index 8787a803798..9f1e6831aa1 100644 --- a/study/api-src/org/labkey/api/specimen/SpecimenRequestException.java +++ b/specimen/src/org/labkey/specimen/SpecimenRequestException.java @@ -1,4 +1,4 @@ -package org.labkey.api.specimen; +package org.labkey.specimen; public class SpecimenRequestException extends RuntimeException { diff --git a/specimen/src/org/labkey/specimen/SpecimenRequestManager.java b/specimen/src/org/labkey/specimen/SpecimenRequestManager.java index 2bcfff0f424..000f2d1b3f9 100644 --- a/specimen/src/org/labkey/specimen/SpecimenRequestManager.java +++ b/specimen/src/org/labkey/specimen/SpecimenRequestManager.java @@ -33,13 +33,9 @@ import org.labkey.api.query.ValidationException; import org.labkey.api.security.User; import org.labkey.api.settings.AppProps; -import org.labkey.api.specimen.SpecimenManagerNew; import org.labkey.api.specimen.SpecimenQuerySchema; -import org.labkey.api.specimen.SpecimenRequestException; -import org.labkey.api.specimen.SpecimenRequestStatus; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.Vial; -import org.labkey.api.specimen.importer.RequestabilityManager; import org.labkey.api.specimen.importer.RollupHelper; import org.labkey.api.specimen.importer.RollupInstance; import org.labkey.api.specimen.importer.VialSpecimenRollup; @@ -55,6 +51,7 @@ import org.labkey.api.util.Pair; import org.labkey.api.util.ReentrantLockWithName; import org.labkey.api.view.ActionURL; +import org.labkey.specimen.importer.RequestabilityManager; import org.labkey.specimen.model.SpecimenRequestEvent; import org.labkey.specimen.requirements.SpecimenRequest; import org.labkey.specimen.requirements.SpecimenRequestRequirement; @@ -73,6 +70,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.locks.ReentrantLock; @@ -167,11 +165,6 @@ public Set getRequestStatusIdsInUse(Container c) return uniqueStatuses; } - public List getRequestEvents(Container c) - { - return _requestEventHelper.getList(c); - } - public SpecimenRequestEvent getRequestEvent(Container c, int rowId) { return _requestEventHelper.get(c, rowId); @@ -432,10 +425,7 @@ else if (oldInputs.length != newInputs.length) private String getSafeString(String str) { - if (str == null) - return ""; - else - return str; + return Objects.requireNonNullElse(str, ""); } public void createRequestStatus(User user, SpecimenRequestStatus status) @@ -472,11 +462,6 @@ public void deleteRequestRequirement(User user, SpecimenRequestRequirement requi requirement.delete(); } - public void createRequestRequirement(User user, SpecimenRequestRequirement requirement, boolean createEvent) throws AttachmentService.DuplicateFilenameException - { - createRequestRequirement(user, requirement, createEvent, false); - } - public void createRequestRequirement(User user, SpecimenRequestRequirement requirement, boolean createEvent, boolean force) throws AttachmentService.DuplicateFilenameException { SpecimenRequest request = getRequest(requirement.getContainer(), requirement.getRequestId()); @@ -575,7 +560,7 @@ public void updateRequest(User user, SpecimenRequest request) throws Requestabil // update specimen states List vials = request.getVials(); - if (vials.size() > 0) + if (!vials.isEmpty()) { SpecimenRequestStatus status = getRequestStatus(request.getContainer(), request.getStatusId()); updateSpecimenStatus(vials, user, status.isSpecimensLocked()); @@ -589,7 +574,7 @@ public void updateRequest(User user, SpecimenRequest request) throws Requestabil public void createRequestSpecimenMapping(User user, SpecimenRequest request, List vials, boolean createEvents, boolean createRequirements) throws RequestabilityManager.InvalidRuleException, AttachmentService.DuplicateFilenameException, SpecimenRequestException { - if (vials == null || vials.size() == 0) + if (vials == null || vials.isEmpty()) return; DbScope scope = SpecimenSchema.get().getScope(); @@ -636,13 +621,13 @@ private void updateSpecimenStatus(List vials, User user, boolean lockedInR Table.update(user, SpecimenSchema.get().getTableInfoVial(vial.getContainer()), vial.getRowMap(), vial.getRowId()); } updateRequestabilityAndCounts(vials, user); - if (vials.size() > 0) + if (!vials.isEmpty()) clearCaches(getContainer(vials)); } private void updateRequestabilityAndCounts(List vials, User user) throws RequestabilityManager.InvalidRuleException { - if (vials.size() == 0) + if (vials.isEmpty()) return; Container container = getContainer(vials); @@ -807,7 +792,7 @@ void clearRequestEventHelper(Container c) _requestEventHelper.clearCache(c); } - private static class GroupedValueColumnHelper + public static class GroupedValueColumnHelper { private final String _viewColumnName; private final String _sqlColumnName; @@ -822,26 +807,11 @@ public GroupedValueColumnHelper(String sqlColumnName, String viewColumnName, Str _joinColumnName = joinColumnName; } - public String getViewColumnName() - { - return _viewColumnName; - } - - public String getSqlColumnName() - { - return _sqlColumnName; - } - public String getUrlFilterName() { return _urlFilterName; } - public String getJoinColumnName() - { - return _joinColumnName; - } - public FieldKey getFieldKey() { // constructs FieldKey whether it needs join or not @@ -1163,11 +1133,11 @@ public void deleteRequest(User user, SpecimenRequest request) throws Requestabil public void deleteRequestSpecimenMappings(User user, SpecimenRequest request, List vialIds, boolean createEvents) throws RequestabilityManager.InvalidRuleException, AttachmentService.DuplicateFilenameException { - if (vialIds == null || vialIds.size() == 0) + if (vialIds == null || vialIds.isEmpty()) return; Set vialRowIds = new HashSet<>(vialIds); - List vials = SpecimenManagerNew.get().getVials(request.getContainer(), user, vialRowIds); + List vials = SpecimenManager.get().getVials(request.getContainer(), user, vialRowIds); List globalUniqueIds = new ArrayList<>(vials.size()); List descriptions = new ArrayList<>(); for (Vial vial : vials) diff --git a/study/api-src/org/labkey/api/specimen/SpecimenRequestStatus.java b/specimen/src/org/labkey/specimen/SpecimenRequestStatus.java similarity index 98% rename from study/api-src/org/labkey/api/specimen/SpecimenRequestStatus.java rename to specimen/src/org/labkey/specimen/SpecimenRequestStatus.java index b8e239cf106..76348c49bb8 100644 --- a/study/api-src/org/labkey/api/specimen/SpecimenRequestStatus.java +++ b/specimen/src/org/labkey/specimen/SpecimenRequestStatus.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.labkey.api.specimen; +package org.labkey.specimen; import org.labkey.api.data.Container; import org.labkey.api.study.AbstractStudyCachable; diff --git a/specimen/src/org/labkey/specimen/SpecimenServiceImpl.java b/specimen/src/org/labkey/specimen/SpecimenServiceImpl.java index 6354073b5a1..28eb1180260 100644 --- a/specimen/src/org/labkey/specimen/SpecimenServiceImpl.java +++ b/specimen/src/org/labkey/specimen/SpecimenServiceImpl.java @@ -42,11 +42,10 @@ import org.labkey.api.query.ValidationException; import org.labkey.api.security.User; import org.labkey.api.specimen.DefaultSpecimenTablesTemplate; -import org.labkey.api.specimen.SpecimenColumns; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.Vial; -import org.labkey.api.specimen.importer.SimpleSpecimenImporter; -import org.labkey.api.specimen.importer.SpecimenColumn; +import org.labkey.specimen.importer.SimpleSpecimenImporter; +import org.labkey.specimen.importer.SpecimenColumn; import org.labkey.api.specimen.location.LocationCache; import org.labkey.api.specimen.model.SpecimenTablesProvider; import org.labkey.api.study.ParticipantVisit; @@ -473,7 +472,7 @@ public void fireSpecimensChanged(Container c, User user, Logger logger) @Override public void deleteAllSpecimenData(Container c, Set set, User user) { - // UNDONE: use transaction? + // Consider: Move this to a container listener? Stop clearing caches, since that's handled by SpecimenRequestContainerListener. SimpleFilter containerFilter = SimpleFilter.createContainerFilter(c); Table.delete(SpecimenSchema.get().getTableInfoSampleRequestSpecimen(), containerFilter); @@ -491,9 +490,6 @@ public void deleteAllSpecimenData(Container c, Set set, User user) SpecimenRequestManager.get().clearRequestStatusHelper(c); assert set.add(SpecimenSchema.get().getTableInfoSampleRequestStatus()); - new SpecimenTablesProvider(c, null, null).deleteTables(); - LocationCache.clear(c); - Table.delete(SpecimenSchema.get().getTableInfoSampleAvailabilityRule(), containerFilter); assert set.add(SpecimenSchema.get().getTableInfoSampleAvailabilityRule()); diff --git a/study/api-src/org/labkey/api/specimen/SpecimenTableManager.java b/specimen/src/org/labkey/specimen/SpecimenTableManager.java similarity index 97% rename from study/api-src/org/labkey/api/specimen/SpecimenTableManager.java rename to specimen/src/org/labkey/specimen/SpecimenTableManager.java index 4ae30cfdbd1..116caa3ac91 100644 --- a/study/api-src/org/labkey/api/specimen/SpecimenTableManager.java +++ b/specimen/src/org/labkey/specimen/SpecimenTableManager.java @@ -1,4 +1,4 @@ -package org.labkey.api.specimen; +package org.labkey.specimen; import org.labkey.api.data.Container; import org.labkey.api.data.JdbcType; @@ -8,12 +8,13 @@ import org.labkey.api.exp.property.Domain; import org.labkey.api.exp.property.DomainProperty; import org.labkey.api.security.User; +import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.importer.EventVialRollup; -import org.labkey.api.specimen.importer.ImportTypes; +import org.labkey.specimen.importer.ImportTypes; import org.labkey.api.specimen.importer.RollupHelper; import org.labkey.api.specimen.importer.RollupHelper.RollupMap; -import org.labkey.api.specimen.importer.SpecimenColumn; -import org.labkey.api.specimen.importer.TargetTable; +import org.labkey.specimen.importer.SpecimenColumn; +import org.labkey.specimen.importer.TargetTable; import org.labkey.api.specimen.model.SpecimenTablesProvider; import java.util.ArrayList; diff --git a/specimen/src/org/labkey/specimen/actions/ManageRequestBean.java b/specimen/src/org/labkey/specimen/actions/ManageRequestBean.java index 0488046bff8..0732f68750c 100644 --- a/specimen/src/org/labkey/specimen/actions/ManageRequestBean.java +++ b/specimen/src/org/labkey/specimen/actions/ManageRequestBean.java @@ -3,7 +3,6 @@ import org.labkey.api.data.ActionButton; import org.labkey.api.data.Container; import org.labkey.api.data.MenuButton; -import org.labkey.api.specimen.SpecimenRequestStatus; import org.labkey.api.specimen.Vial; import org.labkey.api.specimen.location.LocationImpl; import org.labkey.api.specimen.location.LocationManager; @@ -13,6 +12,7 @@ import org.labkey.api.view.DisplayElement; import org.labkey.api.view.ViewContext; import org.labkey.specimen.SpecimenRequestManager; +import org.labkey.specimen.SpecimenRequestStatus; import org.labkey.specimen.actions.SpecimenController.ImportVialIdsAction; import org.labkey.specimen.actions.SpecimenController.OverviewAction; import org.labkey.specimen.actions.SpecimenController.RemoveRequestSpecimensAction; diff --git a/specimen/src/org/labkey/specimen/actions/ParticipantCommentAction.java b/specimen/src/org/labkey/specimen/actions/ParticipantCommentAction.java index 6277560b6fc..f052a92ddfb 100644 --- a/specimen/src/org/labkey/specimen/actions/ParticipantCommentAction.java +++ b/specimen/src/org/labkey/specimen/actions/ParticipantCommentAction.java @@ -24,7 +24,6 @@ import org.labkey.api.security.User; import org.labkey.api.security.permissions.InsertPermission; import org.labkey.api.security.permissions.ReadPermission; -import org.labkey.api.specimen.SpecimenManagerNew; import org.labkey.api.specimen.Vial; import org.labkey.api.specimen.model.SpecimenComment; import org.labkey.api.study.InsertUpdateAction; @@ -67,7 +66,7 @@ public boolean handlePost(ParticipantCommentForm form, BindException errors) thr Container container = getContainer(); for (int rowId : form.getVialCommentsToClear()) { - Vial vial = SpecimenManagerNew.get().getVial(container, user, rowId); + Vial vial = SpecimenManager.get().getVial(container, user, rowId); if (vial != null) { SpecimenComment comment = SpecimenManager.get().getSpecimenCommentForVial(vial); diff --git a/specimen/src/org/labkey/specimen/actions/ShowUploadSpecimensAction.java b/specimen/src/org/labkey/specimen/actions/ShowUploadSpecimensAction.java index 9f7a40d8bc2..c23f49c6058 100644 --- a/specimen/src/org/labkey/specimen/actions/ShowUploadSpecimensAction.java +++ b/specimen/src/org/labkey/specimen/actions/ShowUploadSpecimensAction.java @@ -31,8 +31,7 @@ import org.labkey.api.security.RequiresPermission; import org.labkey.api.security.User; import org.labkey.api.security.permissions.AdminPermission; -import org.labkey.api.specimen.SpecimenManagerNew; -import org.labkey.api.specimen.importer.SimpleSpecimenImporter; +import org.labkey.specimen.importer.SimpleSpecimenImporter; import org.labkey.api.specimen.settings.RepositorySettings; import org.labkey.api.specimen.settings.SettingsManager; import org.labkey.api.study.Study; @@ -125,9 +124,9 @@ public boolean handlePost(UploadSpecimensForm form, BindException errors) throws columnAliases.put("additive", SimpleSpecimenImporter.ADDITIVE_TYPE); columnAliases.put("additiveType", SimpleSpecimenImporter.ADDITIVE_TYPE); columnAliases.put("additive Type", SimpleSpecimenImporter.ADDITIVE_TYPE); - columnAliases.put("derivative", SimpleSpecimenImporter.DERIVIATIVE_TYPE); - columnAliases.put("derivativeType", SimpleSpecimenImporter.DERIVIATIVE_TYPE); - columnAliases.put("derivative Type", SimpleSpecimenImporter.DERIVIATIVE_TYPE); + columnAliases.put("derivative", SimpleSpecimenImporter.DERIVATIVE_TYPE); + columnAliases.put("derivativeType", SimpleSpecimenImporter.DERIVATIVE_TYPE); + columnAliases.put("derivative Type", SimpleSpecimenImporter.DERIVATIVE_TYPE); columnAliases.put("drawTimestamp", SimpleSpecimenImporter.DRAW_TIMESTAMP); columnAliases.put("Draw Date", SimpleSpecimenImporter.DRAW_TIMESTAMP); columnAliases.put("Date", SimpleSpecimenImporter.DRAW_TIMESTAMP); diff --git a/specimen/src/org/labkey/specimen/actions/SpecimenApiController.java b/specimen/src/org/labkey/specimen/actions/SpecimenApiController.java index e091c85752a..568778354f1 100644 --- a/specimen/src/org/labkey/specimen/actions/SpecimenApiController.java +++ b/specimen/src/org/labkey/specimen/actions/SpecimenApiController.java @@ -31,10 +31,7 @@ import org.labkey.api.security.UserManager; import org.labkey.api.security.permissions.ReadPermission; import org.labkey.api.specimen.SpecimenManagerNew; -import org.labkey.api.specimen.SpecimenRequestException; -import org.labkey.api.specimen.SpecimenRequestStatus; import org.labkey.api.specimen.Vial; -import org.labkey.api.specimen.importer.RequestabilityManager; import org.labkey.api.specimen.location.LocationImpl; import org.labkey.api.specimen.location.LocationManager; import org.labkey.api.specimen.model.PrimaryType; @@ -48,7 +45,10 @@ import org.labkey.api.view.ViewContext; import org.labkey.specimen.RequestedSpecimens; import org.labkey.specimen.SpecimenManager; +import org.labkey.specimen.SpecimenRequestException; import org.labkey.specimen.SpecimenRequestManager; +import org.labkey.specimen.SpecimenRequestStatus; +import org.labkey.specimen.importer.RequestabilityManager; import org.labkey.specimen.model.AdditiveType; import org.labkey.specimen.model.DerivativeType; import org.labkey.specimen.requirements.SpecimenRequest; @@ -492,7 +492,7 @@ else if (IdTypes.RowId.name().equals(idType)) try { int id = Integer.parseInt(vialId); - vial = SpecimenManagerNew.get().getVial(getContainer(), getUser(), id); + vial = SpecimenManager.get().getVial(getContainer(), getUser(), id); } catch (NumberFormatException e) { diff --git a/specimen/src/org/labkey/specimen/actions/SpecimenController.java b/specimen/src/org/labkey/specimen/actions/SpecimenController.java index c8491c6bbcc..75da7aa3932 100644 --- a/specimen/src/org/labkey/specimen/actions/SpecimenController.java +++ b/specimen/src/org/labkey/specimen/actions/SpecimenController.java @@ -6,6 +6,7 @@ import jakarta.mail.internet.InternetAddress; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -15,6 +16,7 @@ import org.json.JSONObject; import org.labkey.api.action.ApiResponse; import org.labkey.api.action.ApiSimpleResponse; +import org.labkey.api.action.ExportAction; import org.labkey.api.action.FormHandlerAction; import org.labkey.api.action.FormViewAction; import org.labkey.api.action.HasViewContext; @@ -82,18 +84,13 @@ import org.labkey.api.security.permissions.AdminPermission; import org.labkey.api.security.permissions.ReadPermission; import org.labkey.api.security.permissions.UpdatePermission; -import org.labkey.api.specimen.SpecimenManagerNew; +import org.labkey.api.specimen.SpecimenMigrationService; import org.labkey.api.specimen.SpecimenQuerySchema; -import org.labkey.api.specimen.SpecimenRequestException; -import org.labkey.api.specimen.SpecimenRequestStatus; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.Vial; -import org.labkey.api.specimen.importer.RequestabilityManager; -import org.labkey.api.specimen.importer.SimpleSpecimenImporter; import org.labkey.api.specimen.location.LocationImpl; import org.labkey.api.specimen.location.LocationManager; import org.labkey.api.specimen.model.SpecimenComment; -import org.labkey.api.specimen.query.SpecimenQueryView; import org.labkey.api.specimen.security.permissions.EditSpecimenDataPermission; import org.labkey.api.specimen.security.permissions.ManageRequestSettingsPermission; import org.labkey.api.specimen.security.permissions.RequestSpecimensPermission; @@ -103,7 +100,6 @@ import org.labkey.api.specimen.settings.StatusSettings; import org.labkey.api.study.CohortFilter; import org.labkey.api.study.Dataset; -import org.labkey.api.study.MapArrayExcelWriter; import org.labkey.api.study.SpecimenService; import org.labkey.api.study.SpecimenTransform; import org.labkey.api.study.SpecimenUrls; @@ -152,7 +148,10 @@ import org.labkey.specimen.RequestEventType; import org.labkey.specimen.RequestedSpecimens; import org.labkey.specimen.SpecimenManager; +import org.labkey.specimen.SpecimenRequestException; import org.labkey.specimen.SpecimenRequestManager; +import org.labkey.specimen.SpecimenRequestStatus; +import org.labkey.specimen.importer.RequestabilityManager; import org.labkey.specimen.model.ExtendedSpecimenRequestView; import org.labkey.specimen.model.SpecimenRequestActor; import org.labkey.specimen.model.SpecimenRequestEvent; @@ -162,6 +161,7 @@ import org.labkey.specimen.pipeline.SpecimenArchive; import org.labkey.specimen.pipeline.SpecimenBatch; import org.labkey.specimen.query.SpecimenEventQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.specimen.query.SpecimenRequestQueryView; import org.labkey.specimen.requirements.SpecimenRequest; import org.labkey.specimen.requirements.SpecimenRequestRequirement; @@ -1120,30 +1120,17 @@ public void addNavTrail(NavTree root) } @RequiresPermission(AdminPermission.class) - public class GetSpecimenExcelAction extends SimpleViewAction + public class GetSpecimenExcelAction extends ExportAction { @Override - public ModelAndView getView(Object o, BindException errors) - { - List> defaultSpecimens = new ArrayList<>(); - SimpleSpecimenImporter importer = new SimpleSpecimenImporter(getContainer(), getUser(), - getStudyRedirectIfNull().getTimepointType(), StudyService.get().getSubjectNounSingular(getContainer())); - MapArrayExcelWriter xlWriter = new MapArrayExcelWriter(defaultSpecimens, importer.getSimpleSpecimenColumns()); - // Note: I don't think this is having any effect on the output because ExcelColumn.renderCaption() uses - // the DisplayColumn's caption, not its own caption. That seems wrong... - xlWriter.setColumnModifier(col -> col.setCaption(importer.label(col.getName()))); - xlWriter.renderWorkbook(getViewContext().getResponse()); - - return null; - } - - @Override - public void addNavTrail(NavTree root) + public void export(Object o, HttpServletResponse response, BindException errors) throws Exception { + SpecimenMigrationService.get().exportSpecimens(getContainer(), getUser(), new ArrayList<>(), + getStudyRedirectIfNull().getTimepointType(), StudyService.get().getSubjectNounSingular(getContainer()), response); } } - static class SpecimenEventForm + public static class SpecimenEventForm { private String _id; private Container _targetStudy; @@ -1366,7 +1353,7 @@ public ModelAndView getView(ViewEventForm viewEventForm, BindException errors) { Study study = getStudyThrowIfNull(); _showingSelectedSpecimens = viewEventForm.isSelected(); - Vial vial = SpecimenManagerNew.get().getVial(getContainer(), getUser(), viewEventForm.getId()); + Vial vial = SpecimenManager.get().getVial(getContainer(), getUser(), viewEventForm.getId()); if (vial == null) throw new NotFoundException("Specimen " + viewEventForm.getId() + " does not exist."); @@ -1990,7 +1977,7 @@ public static List getSpecimensFromRowIds(long[] requestedSampleIds, Conta List vials = new ArrayList<>(); for (long requestedSampleId : requestedSampleIds) { - Vial current = SpecimenManagerNew.get().getVial(container, user, requestedSampleId); + Vial current = SpecimenManager.get().getVial(container, user, requestedSampleId); if (current != null) vials.add(current); } @@ -2440,7 +2427,7 @@ else if (form.getDestinationLocation() > 0) vials = new ArrayList<>(); for (long specimenId : specimenIds) { - Vial vial = SpecimenManagerNew.get().getVial(container, user, specimenId); + Vial vial = SpecimenManager.get().getVial(container, user, specimenId); if (vial != null) { boolean isAvailable = vial.isAvailable(); @@ -4123,7 +4110,7 @@ public boolean handlePost(UpdateParticipantCommentsForm commentsForm, BindExcept Container container = getContainer(); List vials = new ArrayList<>(); for (int rowId : commentsForm.getRowId()) - vials.add(SpecimenManagerNew.get().getVial(container, user, rowId)); + vials.add(SpecimenManager.get().getVial(container, user, rowId)); Map currentComments = SpecimenManager.get().getSpecimenComments(vials); @@ -4132,7 +4119,7 @@ public boolean handlePost(UpdateParticipantCommentsForm commentsForm, BindExcept { if (commentsForm.getCopySampleId() != -1) { - Vial vial = SpecimenManagerNew.get().getVial(container, user, commentsForm.getCopySampleId()); + Vial vial = SpecimenManager.get().getVial(container, user, commentsForm.getCopySampleId()); if (vial != null) { _successUrl = new ActionURL(CopyParticipantCommentAction.class, container). @@ -5223,7 +5210,7 @@ public boolean handlePost(EmailSpecimenListForm form, BindException errors) thro protected List getSpecimenList() { SimpleFilter filter = getSpecimenListFilter(getSpecimenRequest(), originatingOrProvidingLocation, type); - return SpecimenManagerNew.get().getVials(container, user, filter); + return SpecimenManager.get().getVials(container, user, filter); // return new TableSelector(StudySchema.getInstance().getTableInfoSpecimenDetail(container), filter, null).getArrayList(Specimen.class); } diff --git a/specimen/src/org/labkey/specimen/actions/SpecimenHeaderBean.java b/specimen/src/org/labkey/specimen/actions/SpecimenHeaderBean.java index 3b01b1d218e..fe32d12dc24 100644 --- a/specimen/src/org/labkey/specimen/actions/SpecimenHeaderBean.java +++ b/specimen/src/org/labkey/specimen/actions/SpecimenHeaderBean.java @@ -5,7 +5,7 @@ import org.labkey.api.query.FieldKey; import org.labkey.api.query.QueryService; import org.labkey.api.specimen.SpecimenQuerySchema; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.study.Study; import org.labkey.api.study.StudyService; import org.labkey.api.util.Pair; diff --git a/specimen/src/org/labkey/specimen/actions/SpecimenSearchBean.java b/specimen/src/org/labkey/specimen/actions/SpecimenSearchBean.java index 6e5cca8b3f2..4c88a25b7e2 100644 --- a/specimen/src/org/labkey/specimen/actions/SpecimenSearchBean.java +++ b/specimen/src/org/labkey/specimen/actions/SpecimenSearchBean.java @@ -16,20 +16,10 @@ package org.labkey.specimen.actions; -import org.jetbrains.annotations.Nullable; -import org.labkey.api.data.DisplayColumn; -import org.labkey.api.data.TableInfo; -import org.labkey.api.query.UserSchema; -import org.labkey.api.specimen.SpecimenQuerySchema; -import org.labkey.api.specimen.query.SpecimenQueryView; -import org.labkey.api.study.StudyService; -import org.labkey.api.util.DemoMode; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.view.ActionURL; import org.labkey.api.view.ViewContext; -import java.util.ArrayList; -import java.util.List; - /** * User: brittp * Date: Oct 21, 2010 4:01:33 PM diff --git a/specimen/src/org/labkey/specimen/actions/SpecimenViewTypeForm.java b/specimen/src/org/labkey/specimen/actions/SpecimenViewTypeForm.java index cfff8bf5ccb..a170962db5d 100644 --- a/specimen/src/org/labkey/specimen/actions/SpecimenViewTypeForm.java +++ b/specimen/src/org/labkey/specimen/actions/SpecimenViewTypeForm.java @@ -1,7 +1,7 @@ package org.labkey.specimen.actions; import org.labkey.api.action.QueryViewAction; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; public class SpecimenViewTypeForm extends QueryViewAction.QueryExportForm { diff --git a/specimen/src/org/labkey/specimen/actions/SpecimensViewBean.java b/specimen/src/org/labkey/specimen/actions/SpecimensViewBean.java index 9c93d066e96..c2ef7fb823d 100644 --- a/specimen/src/org/labkey/specimen/actions/SpecimensViewBean.java +++ b/specimen/src/org/labkey/specimen/actions/SpecimensViewBean.java @@ -1,7 +1,7 @@ package org.labkey.specimen.actions; import org.labkey.api.specimen.Vial; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.view.ViewContext; import java.util.List; diff --git a/specimen/src/org/labkey/specimen/actions/ViewRequestsHeaderBean.java b/specimen/src/org/labkey/specimen/actions/ViewRequestsHeaderBean.java index b7888b517b0..df2ee08d65c 100644 --- a/specimen/src/org/labkey/specimen/actions/ViewRequestsHeaderBean.java +++ b/specimen/src/org/labkey/specimen/actions/ViewRequestsHeaderBean.java @@ -1,8 +1,8 @@ package org.labkey.specimen.actions; -import org.labkey.api.specimen.SpecimenRequestStatus; import org.labkey.api.view.ViewContext; import org.labkey.specimen.SpecimenRequestManager; +import org.labkey.specimen.SpecimenRequestStatus; import org.labkey.specimen.query.SpecimenRequestQueryView; import java.util.List; diff --git a/specimen/src/org/labkey/specimen/importer/AbstractSpecimenTask.java b/specimen/src/org/labkey/specimen/importer/AbstractSpecimenTask.java index d48db7d168a..ab8de4cba82 100644 --- a/specimen/src/org/labkey/specimen/importer/AbstractSpecimenTask.java +++ b/specimen/src/org/labkey/specimen/importer/AbstractSpecimenTask.java @@ -26,7 +26,6 @@ import org.labkey.api.pipeline.RecordedActionSet; import org.labkey.api.pipeline.TaskFactory; import org.labkey.api.query.ValidationException; -import org.labkey.api.specimen.importer.SpecimenImporter; import org.labkey.api.study.SpecimenService; import org.labkey.api.study.SpecimenTransform; import org.labkey.api.study.Study; diff --git a/specimen/src/org/labkey/specimen/importer/DefaultSpecimenImportStrategyFactory.java b/specimen/src/org/labkey/specimen/importer/DefaultSpecimenImportStrategyFactory.java index 3331ff1cda5..bb9ad140fb2 100644 --- a/specimen/src/org/labkey/specimen/importer/DefaultSpecimenImportStrategyFactory.java +++ b/specimen/src/org/labkey/specimen/importer/DefaultSpecimenImportStrategyFactory.java @@ -18,7 +18,6 @@ import org.labkey.api.data.Container; import org.labkey.api.data.DbSchema; -import org.labkey.api.specimen.importer.StandardSpecimenImportStrategy; import org.labkey.api.study.SpecimenImportStrategy; import org.labkey.api.study.SpecimenImportStrategyFactory; import org.labkey.api.writer.VirtualFile; diff --git a/study/api-src/org/labkey/api/specimen/importer/EditableSpecimenImporter.java b/specimen/src/org/labkey/specimen/importer/EditableSpecimenImporter.java similarity index 96% rename from study/api-src/org/labkey/api/specimen/importer/EditableSpecimenImporter.java rename to specimen/src/org/labkey/specimen/importer/EditableSpecimenImporter.java index 81d0b56c186..6f475eb1313 100644 --- a/study/api-src/org/labkey/api/specimen/importer/EditableSpecimenImporter.java +++ b/specimen/src/org/labkey/specimen/importer/EditableSpecimenImporter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -26,11 +26,14 @@ import org.labkey.api.data.TableInfo; import org.labkey.api.query.ValidationException; import org.labkey.api.security.User; -import org.labkey.api.specimen.SpecimenColumns; -import org.labkey.api.specimen.SpecimenMigrationService; import org.labkey.api.specimen.SpecimenSchema; +import org.labkey.api.specimen.importer.EventVialRollup; +import org.labkey.api.specimen.importer.RollupHelper; import org.labkey.api.specimen.importer.RollupHelper.RollupMap; +import org.labkey.api.specimen.importer.RollupInstance; import org.labkey.api.study.SpecimenImportStrategy; +import org.labkey.specimen.SpecimenColumns; +import org.labkey.specimen.SpecimenRequestManager; import java.io.IOException; import java.util.ArrayList; @@ -264,7 +267,7 @@ private int markEventsObsolete(List> rows) if (guidRowCount > 0) { - SpecimenMigrationService.get().clearRequestCaches(container); + SpecimenRequestManager.get().clearCaches(container); } return noGuidRowCount; } diff --git a/study/api-src/org/labkey/api/specimen/importer/FileSystemSpecimenImportFile.java b/specimen/src/org/labkey/specimen/importer/FileSystemSpecimenImportFile.java similarity index 98% rename from study/api-src/org/labkey/api/specimen/importer/FileSystemSpecimenImportFile.java rename to specimen/src/org/labkey/specimen/importer/FileSystemSpecimenImportFile.java index 3b61c0e805e..711187ba915 100644 --- a/study/api-src/org/labkey/api/specimen/importer/FileSystemSpecimenImportFile.java +++ b/specimen/src/org/labkey/specimen/importer/FileSystemSpecimenImportFile.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.labkey.api.reader.Readers; import org.labkey.api.reader.TabLoader; diff --git a/study/api-src/org/labkey/api/specimen/importer/ImportTypes.java b/specimen/src/org/labkey/specimen/importer/ImportTypes.java similarity index 93% rename from study/api-src/org/labkey/api/specimen/importer/ImportTypes.java rename to specimen/src/org/labkey/specimen/importer/ImportTypes.java index 9c9b07b0f1c..6e91ea1a5e6 100644 --- a/study/api-src/org/labkey/api/specimen/importer/ImportTypes.java +++ b/specimen/src/org/labkey/specimen/importer/ImportTypes.java @@ -1,4 +1,4 @@ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.labkey.api.specimen.SpecimenSchema; diff --git a/study/api-src/org/labkey/api/specimen/importer/ImportableColumn.java b/specimen/src/org/labkey/specimen/importer/ImportableColumn.java similarity index 99% rename from study/api-src/org/labkey/api/specimen/importer/ImportableColumn.java rename to specimen/src/org/labkey/specimen/importer/ImportableColumn.java index a440473e6ea..eb51de361ff 100644 --- a/study/api-src/org/labkey/api/specimen/importer/ImportableColumn.java +++ b/specimen/src/org/labkey/specimen/importer/ImportableColumn.java @@ -1,4 +1,4 @@ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.jetbrains.annotations.Nullable; import org.labkey.api.data.JdbcType; diff --git a/study/api-src/org/labkey/api/specimen/importer/IteratorSpecimenImportFile.java b/specimen/src/org/labkey/specimen/importer/IteratorSpecimenImportFile.java similarity index 97% rename from study/api-src/org/labkey/api/specimen/importer/IteratorSpecimenImportFile.java rename to specimen/src/org/labkey/specimen/importer/IteratorSpecimenImportFile.java index f3fcd2650c3..97c9de6a76c 100644 --- a/study/api-src/org/labkey/api/specimen/importer/IteratorSpecimenImportFile.java +++ b/specimen/src/org/labkey/specimen/importer/IteratorSpecimenImportFile.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.labkey.api.reader.DataLoader; import org.labkey.api.reader.MapLoader; diff --git a/study/api-src/org/labkey/api/specimen/importer/RequestabilityManager.java b/specimen/src/org/labkey/specimen/importer/RequestabilityManager.java similarity index 99% rename from study/api-src/org/labkey/api/specimen/importer/RequestabilityManager.java rename to specimen/src/org/labkey/specimen/importer/RequestabilityManager.java index b5c407c57e8..7e0f9aec739 100644 --- a/study/api-src/org/labkey/api/specimen/importer/RequestabilityManager.java +++ b/specimen/src/org/labkey/specimen/importer/RequestabilityManager.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; diff --git a/study/api-src/org/labkey/api/specimen/importer/SimpleSpecimenImporter.java b/specimen/src/org/labkey/specimen/importer/SimpleSpecimenImporter.java similarity index 97% rename from study/api-src/org/labkey/api/specimen/importer/SimpleSpecimenImporter.java rename to specimen/src/org/labkey/specimen/importer/SimpleSpecimenImporter.java index 514b5d79e66..2ae5d34520f 100644 --- a/study/api-src/org/labkey/api/specimen/importer/SimpleSpecimenImporter.java +++ b/specimen/src/org/labkey/specimen/importer/SimpleSpecimenImporter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.apache.commons.beanutils.ConvertUtils; import org.apache.logging.log4j.Logger; @@ -52,14 +52,8 @@ import java.util.Map; import java.util.Set; -/** - * User: Mark Igra - * Date: Apr 26, 2007 - * Time: 1:17:36 PM - */ public class SimpleSpecimenImporter extends SpecimenImporter { - public static final String RECORD_ID = "record_id"; public static final String VIAL_ID = "global_unique_specimen_id"; public static final String SAMPLE_ID = "specimen_number"; public static final String DRAW_TIMESTAMP = "draw_timestamp"; @@ -67,7 +61,7 @@ public class SimpleSpecimenImporter extends SpecimenImporter public static final String VOLUME = "volume"; public static final String UNITS = "volume_units"; public static final String PRIMARY_SPECIMEN_TYPE = "primary_specimen_type"; - public static final String DERIVIATIVE_TYPE = "derivative_type"; + public static final String DERIVATIVE_TYPE = "derivative_type"; public static final String ADDITIVE_TYPE = "additive_type"; public static final String PARTICIPANT_ID = "ptid"; @@ -84,7 +78,7 @@ public class SimpleSpecimenImporter extends SpecimenImporter DEFAULT_COLUMN_LABELS.put(UNITS, "Volume Units"); DEFAULT_COLUMN_LABELS.put(PRIMARY_SPECIMEN_TYPE, "Primary Type"); DEFAULT_COLUMN_LABELS.put(ADDITIVE_TYPE, "Additive Type"); - DEFAULT_COLUMN_LABELS.put(DERIVIATIVE_TYPE, "Derivative Type"); + DEFAULT_COLUMN_LABELS.put(DERIVATIVE_TYPE, "Derivative Type"); DEFAULT_COLUMN_LABELS.put(PARTICIPANT_ID, "Subject Id"); } @@ -110,7 +104,7 @@ public String label(String columnName) return str == null ? columnName : str; } - public Map getColumnLabels() + public Map getColumnLabels() { return _columnLabels; } @@ -176,7 +170,7 @@ public ColumnDescriptor[] getSimpleSpecimenColumns() VOLUME, UNITS, PRIMARY_SPECIMEN_TYPE, - DERIVIATIVE_TYPE, + DERIVATIVE_TYPE, ADDITIVE_TYPE)); if (_timepointType == TimepointType.VISIT) colNames.add(3, VISIT); diff --git a/study/api-src/org/labkey/api/specimen/importer/SpecimenColumn.java b/specimen/src/org/labkey/specimen/importer/SpecimenColumn.java similarity index 98% rename from study/api-src/org/labkey/api/specimen/importer/SpecimenColumn.java rename to specimen/src/org/labkey/specimen/importer/SpecimenColumn.java index 8f4b9364791..2cec7dcefd3 100644 --- a/study/api-src/org/labkey/api/specimen/importer/SpecimenColumn.java +++ b/specimen/src/org/labkey/specimen/importer/SpecimenColumn.java @@ -1,4 +1,4 @@ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.labkey.api.util.TimeOnlyDate; diff --git a/study/api-src/org/labkey/api/specimen/importer/SpecimenImportFile.java b/specimen/src/org/labkey/specimen/importer/SpecimenImportFile.java similarity index 95% rename from study/api-src/org/labkey/api/specimen/importer/SpecimenImportFile.java rename to specimen/src/org/labkey/specimen/importer/SpecimenImportFile.java index f9e5b694223..8102249c186 100644 --- a/study/api-src/org/labkey/api/specimen/importer/SpecimenImportFile.java +++ b/specimen/src/org/labkey/specimen/importer/SpecimenImportFile.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.labkey.api.reader.DataLoader; import org.labkey.api.study.SpecimenImportStrategy; diff --git a/study/api-src/org/labkey/api/specimen/importer/SpecimenImporter.java b/specimen/src/org/labkey/specimen/importer/SpecimenImporter.java similarity index 98% rename from study/api-src/org/labkey/api/specimen/importer/SpecimenImporter.java rename to specimen/src/org/labkey/specimen/importer/SpecimenImporter.java index 863298b437b..beedf7df846 100644 --- a/study/api-src/org/labkey/api/specimen/importer/SpecimenImporter.java +++ b/specimen/src/org/labkey/specimen/importer/SpecimenImporter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.MutableInt; @@ -27,7 +27,29 @@ import org.junit.Test; import org.labkey.api.collections.CaseInsensitiveHashMap; import org.labkey.api.collections.CaseInsensitiveHashSet; -import org.labkey.api.data.*; +import org.labkey.api.data.BaseColumnInfo; +import org.labkey.api.data.ColumnInfo; +import org.labkey.api.data.Container; +import org.labkey.api.data.DbSchema; +import org.labkey.api.data.DbScope; +import org.labkey.api.data.DbSequence; +import org.labkey.api.data.DbSequenceManager; +import org.labkey.api.data.JdbcType; +import org.labkey.api.data.Parameter; +import org.labkey.api.data.Results; +import org.labkey.api.data.ResultsImpl; +import org.labkey.api.data.RuntimeSQLException; +import org.labkey.api.data.SQLFragment; +import org.labkey.api.data.SimpleFilter; +import org.labkey.api.data.Sort; +import org.labkey.api.data.SqlExecutor; +import org.labkey.api.data.SqlSelector; +import org.labkey.api.data.Table; +import org.labkey.api.data.TableInfo; +import org.labkey.api.data.TableResultSet; +import org.labkey.api.data.TableSelector; +import org.labkey.api.data.TempTableInfo; +import org.labkey.api.data.UpdateableTableInfo; import org.labkey.api.data.dialect.SqlDialect; import org.labkey.api.dataiterator.DataIterator; import org.labkey.api.dataiterator.DataIteratorBuilder; @@ -56,14 +78,13 @@ import org.labkey.api.reader.DataLoader; import org.labkey.api.reader.Readers; import org.labkey.api.security.User; -import org.labkey.api.specimen.SpecimenColumns; import org.labkey.api.specimen.SpecimenEvent; import org.labkey.api.specimen.SpecimenEventDateComparator; import org.labkey.api.specimen.SpecimenEventManager; -import org.labkey.api.specimen.SpecimenMigrationService; import org.labkey.api.specimen.SpecimenSchema; -import org.labkey.api.specimen.SpecimenTableManager; import org.labkey.api.specimen.Vial; +import org.labkey.api.specimen.importer.EventVialRollup; +import org.labkey.api.specimen.importer.RollupInstance; import org.labkey.api.specimen.location.LocationCache; import org.labkey.api.specimen.location.LocationManager; import org.labkey.api.specimen.model.SpecimenComment; @@ -94,6 +115,10 @@ import org.labkey.api.util.StringUtilsLabKey; import org.labkey.api.util.TestContext; import org.labkey.api.writer.VirtualFile; +import org.labkey.specimen.SpecimenColumns; +import org.labkey.specimen.SpecimenManager; +import org.labkey.specimen.SpecimenRequestManager; +import org.labkey.specimen.SpecimenTableManager; import java.io.BufferedReader; import java.io.IOException; @@ -117,17 +142,17 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -import static org.labkey.api.specimen.SpecimenColumns.DRAW_TIMESTAMP; -import static org.labkey.api.specimen.SpecimenColumns.GLOBAL_UNIQUE_ID; -import static org.labkey.api.specimen.SpecimenColumns.GLOBAL_UNIQUE_ID_TSV_COL; -import static org.labkey.api.specimen.SpecimenColumns.LAB_ID; -import static org.labkey.api.specimen.SpecimenColumns.LAB_RECEIPT_DATE; -import static org.labkey.api.specimen.SpecimenColumns.SHIP_DATE; -import static org.labkey.api.specimen.SpecimenColumns.SITE_COLUMNS; -import static org.labkey.api.specimen.SpecimenColumns.SPEC_NUMBER_TSV_COL; -import static org.labkey.api.specimen.SpecimenColumns.STORAGE_DATE; -import static org.labkey.api.specimen.SpecimenColumns.VISIT_COL; -import static org.labkey.api.specimen.SpecimenColumns.VISIT_VALUE; +import static org.labkey.specimen.SpecimenColumns.DRAW_TIMESTAMP; +import static org.labkey.specimen.SpecimenColumns.GLOBAL_UNIQUE_ID; +import static org.labkey.specimen.SpecimenColumns.GLOBAL_UNIQUE_ID_TSV_COL; +import static org.labkey.specimen.SpecimenColumns.LAB_ID; +import static org.labkey.specimen.SpecimenColumns.LAB_RECEIPT_DATE; +import static org.labkey.specimen.SpecimenColumns.SHIP_DATE; +import static org.labkey.specimen.SpecimenColumns.SITE_COLUMNS; +import static org.labkey.specimen.SpecimenColumns.SPEC_NUMBER_TSV_COL; +import static org.labkey.specimen.SpecimenColumns.STORAGE_DATE; +import static org.labkey.specimen.SpecimenColumns.VISIT_COL; +import static org.labkey.specimen.SpecimenColumns.VISIT_VALUE; /** * User: brittp @@ -424,7 +449,7 @@ private void process(Map sifMap, boolean { _iTimer.setPhase(ImportPhases.ClearCaches); StudyInternalService.get().clearCaches(getContainer()); - SpecimenMigrationService.get().clearRequestCaches(getContainer()); + SpecimenRequestManager.get().clearCaches(getContainer()); info(_iTimer.getTimings("Timings for each phase of this import are listed below:", Order.HighToLow, "|")); } @@ -788,7 +813,7 @@ private void updateCalculatedSpecimenData(final boolean merge, final boolean edi _iTimer.setPhase(ImportPhases.VialUpdatePreLoopPrep); // clear caches before determining current sites: - SpecimenMigrationService.get().clearRequestCaches(getContainer()); + SpecimenRequestManager.get().clearCaches(getContainer()); final Map siteMap = new HashMap<>(); TableInfo vialTable = getTableInfoVial(); @@ -889,7 +914,7 @@ private void updateCalculatedSpecimenData(final boolean merge, final boolean edi _iTimer.setPhase(ImportPhases.GetProcessingLocationId); Integer processingLocation = LocationManager.get().getProcessingLocationId(dateOrderedEvents); _iTimer.setPhase(ImportPhases.GetFirstProcessedBy); - String firstProcessedByInitials = SpecimenEventManager.get().getFirstProcessedByInitials(dateOrderedEvents); + String firstProcessedByInitials = SpecimenManager.get().getFirstProcessedByInitials(dateOrderedEvents); _iTimer.setPhase(ImportPhases.GetCurrentLocationId); Integer currentLocation = LocationManager.get().getCurrentLocationId(dateOrderedEvents); @@ -1064,7 +1089,7 @@ private void updateCalculatedSpecimenData(final boolean merge, final boolean edi _iTimer.setPhase(ImportPhases.UpdateVialCounts); info("Updating cached vial counts..."); - SpecimenMigrationService.get().updateVialCounts(getContainer(), getUser()); + SpecimenRequestManager.get().updateVialCounts(getContainer(), getUser()); info("Vial count update complete."); } diff --git a/specimen/src/org/labkey/specimen/importer/SpecimenSettingsImporter.java b/specimen/src/org/labkey/specimen/importer/SpecimenSettingsImporter.java index 4fd362a0d98..c568389b7a4 100644 --- a/specimen/src/org/labkey/specimen/importer/SpecimenSettingsImporter.java +++ b/specimen/src/org/labkey/specimen/importer/SpecimenSettingsImporter.java @@ -20,8 +20,6 @@ import org.labkey.api.data.Container; import org.labkey.api.security.GroupManager; import org.labkey.api.security.SecurityManager; -import org.labkey.api.specimen.SpecimenRequestStatus; -import org.labkey.api.specimen.importer.RequestabilityManager; import org.labkey.api.specimen.location.LocationCache; import org.labkey.api.specimen.location.LocationImpl; import org.labkey.api.specimen.settings.DisplaySettings; @@ -35,6 +33,7 @@ import org.labkey.security.xml.GroupType; import org.labkey.specimen.SpecimenRequestManager; import org.labkey.specimen.SpecimenRequestManager.SpecimenRequestInput; +import org.labkey.specimen.SpecimenRequestStatus; import org.labkey.specimen.actions.ManageReqsBean; import org.labkey.specimen.model.SpecimenRequestActor; import org.labkey.specimen.requirements.RequirementType; diff --git a/study/api-src/org/labkey/api/specimen/importer/SpecimenTableType.java b/specimen/src/org/labkey/specimen/importer/SpecimenTableType.java similarity index 93% rename from study/api-src/org/labkey/api/specimen/importer/SpecimenTableType.java rename to specimen/src/org/labkey/specimen/importer/SpecimenTableType.java index c42625f65e3..e150702c446 100644 --- a/study/api-src/org/labkey/api/specimen/importer/SpecimenTableType.java +++ b/specimen/src/org/labkey/specimen/importer/SpecimenTableType.java @@ -1,4 +1,4 @@ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import java.util.Collection; diff --git a/study/api-src/org/labkey/api/specimen/importer/StandardSpecimenImportStrategy.java b/specimen/src/org/labkey/specimen/importer/StandardSpecimenImportStrategy.java similarity index 96% rename from study/api-src/org/labkey/api/specimen/importer/StandardSpecimenImportStrategy.java rename to specimen/src/org/labkey/specimen/importer/StandardSpecimenImportStrategy.java index 8b41917464f..b30278230b6 100644 --- a/study/api-src/org/labkey/api/specimen/importer/StandardSpecimenImportStrategy.java +++ b/specimen/src/org/labkey/specimen/importer/StandardSpecimenImportStrategy.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import org.labkey.api.data.Container; import org.labkey.api.data.Filter; diff --git a/study/api-src/org/labkey/api/specimen/importer/TargetTable.java b/specimen/src/org/labkey/specimen/importer/TargetTable.java similarity index 98% rename from study/api-src/org/labkey/api/specimen/importer/TargetTable.java rename to specimen/src/org/labkey/specimen/importer/TargetTable.java index cd740fd3ccc..3a39031c7ac 100644 --- a/study/api-src/org/labkey/api/specimen/importer/TargetTable.java +++ b/specimen/src/org/labkey/specimen/importer/TargetTable.java @@ -1,4 +1,4 @@ -package org.labkey.api.specimen.importer; +package org.labkey.specimen.importer; import java.util.ArrayList; import java.util.List; diff --git a/specimen/src/org/labkey/specimen/notifications/DefaultRequestNotification.java b/specimen/src/org/labkey/specimen/notifications/DefaultRequestNotification.java index b838346ba0a..c11d67e1638 100644 --- a/specimen/src/org/labkey/specimen/notifications/DefaultRequestNotification.java +++ b/specimen/src/org/labkey/specimen/notifications/DefaultRequestNotification.java @@ -25,7 +25,7 @@ import org.labkey.api.data.ExcelWriter; import org.labkey.api.data.TSVWriter; import org.labkey.api.specimen.Vial; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.view.ViewContext; import org.labkey.specimen.model.SpecimenRequestEvent; import org.labkey.specimen.requirements.SpecimenRequest; diff --git a/study/api-src/org/labkey/api/specimen/query/BaseSpecimenQueryView.java b/specimen/src/org/labkey/specimen/query/BaseSpecimenQueryView.java similarity index 96% rename from study/api-src/org/labkey/api/specimen/query/BaseSpecimenQueryView.java rename to specimen/src/org/labkey/specimen/query/BaseSpecimenQueryView.java index c10db096c47..e6f80e40776 100644 --- a/study/api-src/org/labkey/api/specimen/query/BaseSpecimenQueryView.java +++ b/specimen/src/org/labkey/specimen/query/BaseSpecimenQueryView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.labkey.api.specimen.query; +package org.labkey.specimen.query; import org.jetbrains.annotations.Nullable; import org.labkey.api.data.ButtonBar; @@ -31,11 +31,6 @@ import java.util.List; -/** - * User: brittp - * Date: Jan 26, 2007 - * Time: 10:03:34 AM - */ public abstract class BaseSpecimenQueryView extends QueryView { protected final SimpleFilter _filter; diff --git a/specimen/src/org/labkey/specimen/query/SpecimenEventQueryView.java b/specimen/src/org/labkey/specimen/query/SpecimenEventQueryView.java index 95d8cadb904..4eeb8f6d1b6 100644 --- a/specimen/src/org/labkey/specimen/query/SpecimenEventQueryView.java +++ b/specimen/src/org/labkey/specimen/query/SpecimenEventQueryView.java @@ -23,7 +23,6 @@ import org.labkey.api.query.UserSchema; import org.labkey.api.specimen.SpecimenQuerySchema; import org.labkey.api.specimen.Vial; -import org.labkey.api.specimen.query.BaseSpecimenQueryView; import org.labkey.api.study.Study; import org.labkey.api.study.StudyService; import org.labkey.api.view.ViewContext; diff --git a/study/api-src/org/labkey/api/specimen/query/SpecimenQueryView.java b/specimen/src/org/labkey/specimen/query/SpecimenQueryView.java similarity index 97% rename from study/api-src/org/labkey/api/specimen/query/SpecimenQueryView.java rename to specimen/src/org/labkey/specimen/query/SpecimenQueryView.java index 1bbb3d1670b..c0be0a59362 100644 --- a/study/api-src/org/labkey/api/specimen/query/SpecimenQueryView.java +++ b/specimen/src/org/labkey/specimen/query/SpecimenQueryView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.labkey.api.specimen.query; +package org.labkey.specimen.query; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; @@ -41,11 +41,12 @@ import org.labkey.api.data.TableInfo; import org.labkey.api.query.DetailsURL; import org.labkey.api.query.FieldKey; +import org.labkey.api.query.QueryParam; import org.labkey.api.query.QuerySettings; +import org.labkey.api.query.QueryView; import org.labkey.api.query.UserSchema; import org.labkey.api.reports.report.ReportUrls; import org.labkey.api.security.User; -import org.labkey.api.specimen.SpecimenMigrationService; import org.labkey.api.specimen.SpecimenQuerySchema; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.Vial; @@ -65,6 +66,7 @@ import org.labkey.api.view.ActionURL; import org.labkey.api.view.DataView; import org.labkey.api.view.ViewContext; +import org.labkey.specimen.actions.SpecimenController; import java.io.IOException; import java.io.Writer; @@ -211,7 +213,7 @@ private boolean isAvailable(RenderContext ctx) protected static ActionURL getHistoryLinkURL(ViewContext ctx, String containerId) { Container container = null != containerId ? ContainerManager.getForId(containerId) : ctx.getContainer(); - return SpecimenMigrationService.get().getSpecimenEventsURL(container, ctx.getActionURL()); + return new ActionURL(SpecimenController.SpecimenEventsAction.class, container).addReturnURL(ctx.getActionURL()); } private class SpecimenRestrictedDataRegion extends SpecimenDataRegion @@ -385,12 +387,16 @@ protected SpecimenQueryView(UserSchema schema, QuerySettings settings, SimpleFil if (isEditable) { AbstractTableInfo tableInfo = (AbstractTableInfo) getTable(); - ActionURL updateActionURL = SpecimenMigrationService.get().getUpdateSpecimenQueryRowURL(getContainer(), "study", tableInfo); - setUpdateURL(new DetailsURL(updateActionURL, Collections.singletonMap("RowId", "RowId"))); + ActionURL updateUrl = new ActionURL(SpecimenController.UpdateSpecimenQueryRowAction.class, getContainer()); + updateUrl.addParameter("schemaName", "study"); + updateUrl.addParameter(QueryView.DATAREGIONNAME_DEFAULT + "." + QueryParam.queryName, tableInfo.getName()); + setUpdateURL(new DetailsURL(updateUrl, Collections.singletonMap("RowId", "RowId"))); - ActionURL insertActionURL = SpecimenMigrationService.get().getInsertSpecimenQueryRowURL(getContainer(), "study", tableInfo); // we want a DetailsURL-like string so clear the container - insertActionURL.setContainer(ContainerManager.getRoot()); + ActionURL insertActionURL = new ActionURL(SpecimenController.InsertSpecimenQueryRowAction.class, ContainerManager.getRoot()); + insertActionURL.addParameter("schemaName", "study"); + insertActionURL.addParameter(QueryView.DATAREGIONNAME_DEFAULT + "." + QueryParam.queryName, tableInfo.getName()); + setInsertURL(insertActionURL.getLocalURIString(false)); } diff --git a/study/api-src/org/labkey/api/specimen/query/SpecimenRequestDisplayColumn.java b/specimen/src/org/labkey/specimen/query/SpecimenRequestDisplayColumn.java similarity index 96% rename from study/api-src/org/labkey/api/specimen/query/SpecimenRequestDisplayColumn.java rename to specimen/src/org/labkey/specimen/query/SpecimenRequestDisplayColumn.java index 750c0a00002..531ba316634 100644 --- a/study/api-src/org/labkey/api/specimen/query/SpecimenRequestDisplayColumn.java +++ b/specimen/src/org/labkey/specimen/query/SpecimenRequestDisplayColumn.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.labkey.api.specimen.query; +package org.labkey.specimen.query; -import org.labkey.api.annotations.Migrate; import org.labkey.api.data.ColumnInfo; import org.labkey.api.data.RenderContext; import org.labkey.api.data.SimpleDisplayColumn; @@ -28,7 +27,6 @@ import java.io.Writer; import java.util.Set; -@Migrate // TODO: Update SpecimenTest.exportSpecimenTest() after moving this class to specimen-main public class SpecimenRequestDisplayColumn extends SimpleDisplayColumn { private final boolean _showOneVialIndicator; diff --git a/specimen/src/org/labkey/specimen/query/SpecimenRequestQueryView.java b/specimen/src/org/labkey/specimen/query/SpecimenRequestQueryView.java index 87f0a443d75..8384b1bb3ce 100644 --- a/specimen/src/org/labkey/specimen/query/SpecimenRequestQueryView.java +++ b/specimen/src/org/labkey/specimen/query/SpecimenRequestQueryView.java @@ -29,8 +29,6 @@ import org.labkey.api.query.UserSchema; import org.labkey.api.security.User; import org.labkey.api.specimen.SpecimenQuerySchema; -import org.labkey.api.specimen.SpecimenRequestStatus; -import org.labkey.api.specimen.query.BaseSpecimenQueryView; import org.labkey.api.specimen.security.permissions.RequestSpecimensPermission; import org.labkey.api.specimen.settings.SettingsManager; import org.labkey.api.study.Study; @@ -41,6 +39,7 @@ import org.labkey.api.view.NavTree; import org.labkey.api.view.ViewContext; import org.labkey.specimen.SpecimenRequestManager; +import org.labkey.specimen.SpecimenRequestStatus; import org.labkey.specimen.actions.SpecimenController.DeleteRequestAction; import org.labkey.specimen.actions.SpecimenController.ManageRequestAction; import org.labkey.specimen.actions.SpecimenController.SubmitRequestAction; diff --git a/study/api-src/org/labkey/api/specimen/query/SpecimenUpdateService.java b/specimen/src/org/labkey/specimen/query/SpecimenUpdateService.java similarity index 95% rename from study/api-src/org/labkey/api/specimen/query/SpecimenUpdateService.java rename to specimen/src/org/labkey/specimen/query/SpecimenUpdateService.java index 958a284c2a1..7d3f968266f 100644 --- a/study/api-src/org/labkey/api/specimen/query/SpecimenUpdateService.java +++ b/specimen/src/org/labkey/specimen/query/SpecimenUpdateService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.labkey.api.specimen.query; +package org.labkey.specimen.query; import org.apache.commons.beanutils.converters.LongConverter; import org.apache.logging.log4j.Logger; @@ -39,17 +39,16 @@ import org.labkey.api.security.permissions.DeletePermission; import org.labkey.api.specimen.SpecimenEvent; import org.labkey.api.specimen.SpecimenEventManager; -import org.labkey.api.specimen.SpecimenManager; -import org.labkey.api.specimen.SpecimenManagerNew; -import org.labkey.api.specimen.SpecimenMigrationService; -import org.labkey.api.specimen.SpecimenRequestException; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.Vial; -import org.labkey.api.specimen.importer.EditableSpecimenImporter; import org.labkey.api.study.Study; import org.labkey.api.study.StudyService; import org.labkey.api.util.UnexpectedException; import org.labkey.api.view.UnauthorizedException; +import org.labkey.specimen.SpecimenManager; +import org.labkey.specimen.SpecimenRequestException; +import org.labkey.specimen.SpecimenRequestManager; +import org.labkey.specimen.importer.EditableSpecimenImporter; import java.io.IOException; import java.sql.SQLException; @@ -61,11 +60,6 @@ import java.util.Map; import java.util.Set; -/** - * User: davebradlee - * Date: 6/11/13 - * Time: 2:33 PM - */ public class SpecimenUpdateService extends AbstractQueryUpdateService { Logger _logger = null; @@ -110,7 +104,7 @@ public List> deleteRows(User user, Container container, List else throw new IllegalArgumentException("RowId not found for a row."); } - List vials = SpecimenManagerNew.get().getVials(container, user, rowIds); + List vials = SpecimenManager.get().getVials(container, user, rowIds); if (vials.size() != keys.size()) throw new IllegalStateException("Specimens should be same size as rows."); @@ -123,9 +117,7 @@ public List> deleteRows(User user, Container container, List for (Vial vial : vials) SpecimenManager.get().deleteSpecimen(vial, false); - SpecimenMigrationService SMS = SpecimenMigrationService.get(); - if (null != SMS) - SMS.clearRequestCaches(container); + SpecimenRequestManager.get().clearCaches(container); // Force recalculation of requestability and specimen table EditableSpecimenImporter importer = new EditableSpecimenImporter(container, user, false); @@ -158,7 +150,7 @@ protected Map deleteRow(User user, Container container, Map> updateRows(User user, Container container, List uniqueRows.put(rowId, row); } Map vials = new HashMap<>(); - for (Vial vial : SpecimenManagerNew.get().getVials(container, user, rowIds)) + for (Vial vial : SpecimenManager.get().getVials(container, user, rowIds)) { vials.put(vial.getRowId(), vial); } @@ -417,7 +409,7 @@ protected Map updateRow(User user, Container container, Map counts = new SqlSelector(getQueryTable().getSchema(), sql).getArrayList(Integer.class); if (counts.size() > 1) throw new ValidationException("Expected one and only one count of rows."); - else if (counts.size() > 0 && counts.get(0) != 0) + else if (!counts.isEmpty() && counts.get(0) != 0) throw new ValidationException("Specimen may not be deleted because it has been used in a request."); } private static Map getLastEventMap(Container container, Vial vial) { List vials = Collections.singletonList(vial); - SpecimenEvent specimenEvent = SpecimenEventManager.get().getLastEvent(SpecimenEventManager.get().getSpecimenEvents(vials, false)); + SpecimenEvent specimenEvent = SpecimenEventManager.get().getLastEvent(SpecimenManager.get().getSpecimenEvents(vials, false)); if (null == specimenEvent) throw new IllegalStateException("Expected at least one event for specimen."); TableInfo tableInfoSpecimenEvent = SpecimenSchema.get().getTableInfoSpecimenEvent(container); diff --git a/specimen/src/org/labkey/specimen/report/SpecimenVisitReport.java b/specimen/src/org/labkey/specimen/report/SpecimenVisitReport.java index 178a28988cf..1be3970bbac 100644 --- a/specimen/src/org/labkey/specimen/report/SpecimenVisitReport.java +++ b/specimen/src/org/labkey/specimen/report/SpecimenVisitReport.java @@ -24,7 +24,7 @@ import org.labkey.api.query.UserSchema; import org.labkey.api.security.User; import org.labkey.api.specimen.SpecimenQuerySchema; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.study.CohortFilter; import org.labkey.api.study.Study; import org.labkey.api.study.StudyService; diff --git a/specimen/src/org/labkey/specimen/report/request/RequestEnrollmentLocationReport.java b/specimen/src/org/labkey/specimen/report/request/RequestEnrollmentLocationReport.java index 42f594588dd..a3155c52dc0 100644 --- a/specimen/src/org/labkey/specimen/report/request/RequestEnrollmentLocationReport.java +++ b/specimen/src/org/labkey/specimen/report/request/RequestEnrollmentLocationReport.java @@ -16,7 +16,7 @@ package org.labkey.specimen.report.request; import org.labkey.api.data.SimpleFilter; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.study.Visit; import org.labkey.specimen.report.SpecimenTypeVisitReport; import org.labkey.specimen.report.SpecimenVisitReportParameters; diff --git a/specimen/src/org/labkey/specimen/report/request/RequestEnrollmentSiteReportFactory.java b/specimen/src/org/labkey/specimen/report/request/RequestEnrollmentSiteReportFactory.java index 35d011a76d5..fe3860955ef 100644 --- a/specimen/src/org/labkey/specimen/report/request/RequestEnrollmentSiteReportFactory.java +++ b/specimen/src/org/labkey/specimen/report/request/RequestEnrollmentSiteReportFactory.java @@ -21,7 +21,7 @@ import org.labkey.api.security.User; import org.labkey.api.specimen.location.LocationImpl; import org.labkey.api.specimen.location.LocationManager; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.study.Location; import org.labkey.api.study.Visit; import org.labkey.api.util.HtmlString; diff --git a/specimen/src/org/labkey/specimen/report/request/RequestLocationReport.java b/specimen/src/org/labkey/specimen/report/request/RequestLocationReport.java index db9284b5b3b..7b7c55f5410 100644 --- a/specimen/src/org/labkey/specimen/report/request/RequestLocationReport.java +++ b/specimen/src/org/labkey/specimen/report/request/RequestLocationReport.java @@ -16,7 +16,7 @@ package org.labkey.specimen.report.request; import org.labkey.api.data.SimpleFilter; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.study.Visit; import org.labkey.specimen.report.SpecimenTypeVisitReport; import org.labkey.specimen.report.SpecimenVisitReportParameters; diff --git a/specimen/src/org/labkey/specimen/report/request/RequestParticipantReport.java b/specimen/src/org/labkey/specimen/report/request/RequestParticipantReport.java index 75a4f2e314f..54758b3d4a2 100644 --- a/specimen/src/org/labkey/specimen/report/request/RequestParticipantReport.java +++ b/specimen/src/org/labkey/specimen/report/request/RequestParticipantReport.java @@ -16,7 +16,7 @@ package org.labkey.specimen.report.request; import org.labkey.api.data.SimpleFilter; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.study.Visit; import org.labkey.api.view.ActionURL; import org.labkey.specimen.actions.SpecimenController; diff --git a/specimen/src/org/labkey/specimen/report/request/RequestReport.java b/specimen/src/org/labkey/specimen/report/request/RequestReport.java index 9af593e9be0..59c895b8090 100644 --- a/specimen/src/org/labkey/specimen/report/request/RequestReport.java +++ b/specimen/src/org/labkey/specimen/report/request/RequestReport.java @@ -16,7 +16,7 @@ package org.labkey.specimen.report.request; import org.labkey.api.data.SimpleFilter; -import org.labkey.api.specimen.query.SpecimenQueryView; +import org.labkey.specimen.query.SpecimenQueryView; import org.labkey.api.study.Visit; import org.labkey.specimen.report.SpecimenTypeVisitReport; import org.labkey.specimen.report.SpecimenVisitReportParameters; diff --git a/specimen/src/org/labkey/specimen/settings/SettingsManager.java b/specimen/src/org/labkey/specimen/settings/SettingsManager.java index 6adfb2d86eb..f6bfdc43507 100644 --- a/specimen/src/org/labkey/specimen/settings/SettingsManager.java +++ b/specimen/src/org/labkey/specimen/settings/SettingsManager.java @@ -4,13 +4,13 @@ import org.labkey.api.data.Container; import org.labkey.api.data.PropertyManager; import org.labkey.api.security.UserManager; -import org.labkey.api.specimen.SpecimenRequestStatus; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.settings.DisplaySettings; import org.labkey.api.specimen.settings.RepositorySettings; import org.labkey.api.specimen.settings.StatusSettings; import org.labkey.api.study.QueryHelper; import org.labkey.specimen.SpecimenRequestManager; +import org.labkey.specimen.SpecimenRequestStatus; import java.util.List; import java.util.Map; diff --git a/specimen/src/org/labkey/specimen/view/NotificationBean.java b/specimen/src/org/labkey/specimen/view/NotificationBean.java index e9254b6f108..cf156ce4dfd 100644 --- a/specimen/src/org/labkey/specimen/view/NotificationBean.java +++ b/specimen/src/org/labkey/specimen/view/NotificationBean.java @@ -4,7 +4,6 @@ import org.labkey.api.attachments.Attachment; import org.labkey.api.data.Container; import org.labkey.api.security.User; -import org.labkey.api.specimen.SpecimenRequestStatus; import org.labkey.api.specimen.location.LocationManager; import org.labkey.api.study.Location; import org.labkey.api.study.SpecimenUrls; @@ -12,6 +11,7 @@ import org.labkey.api.view.ActionURL; import org.labkey.api.view.ViewContext; import org.labkey.specimen.SpecimenRequestManager; +import org.labkey.specimen.SpecimenRequestStatus; import org.labkey.specimen.model.SpecimenRequestEvent; import org.labkey.specimen.notifications.DefaultRequestNotification; diff --git a/specimen/src/org/labkey/specimen/view/configRequestabilityRules.jsp b/specimen/src/org/labkey/specimen/view/configRequestabilityRules.jsp index d21da96dade..f162164e78b 100644 --- a/specimen/src/org/labkey/specimen/view/configRequestabilityRules.jsp +++ b/specimen/src/org/labkey/specimen/view/configRequestabilityRules.jsp @@ -16,10 +16,10 @@ */ %> <%@ page import="org.labkey.api.data.Container"%> -<%@ page import="org.labkey.api.specimen.importer.RequestabilityManager"%> <%@ page import="org.labkey.api.study.StudyUrls"%> -<%@ page import="org.labkey.api.view.ActionURL" %> +<%@ page import="org.labkey.api.view.ActionURL"%> <%@ page import="org.labkey.api.view.template.ClientDependencies" %> +<%@ page import="org.labkey.specimen.importer.RequestabilityManager" %> <%@ page extends="org.labkey.api.jsp.JspBase" %> <%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %> <%! diff --git a/specimen/src/org/labkey/specimen/view/manageRequest.jsp b/specimen/src/org/labkey/specimen/view/manageRequest.jsp index 1fdc2d92c46..f8b3d78064e 100644 --- a/specimen/src/org/labkey/specimen/view/manageRequest.jsp +++ b/specimen/src/org/labkey/specimen/view/manageRequest.jsp @@ -20,10 +20,9 @@ <%@ page import="org.labkey.api.data.ContainerManager"%> <%@ page import="org.labkey.api.security.User"%> <%@ page import="org.labkey.api.security.UserManager"%> -<%@ page import="org.labkey.api.specimen.SpecimenRequestStatus"%> -<%@ page import="org.labkey.api.specimen.Vial" %> -<%@ page import="org.labkey.api.specimen.location.LocationImpl"%> -<%@ page import="org.labkey.api.specimen.location.LocationManager" %> +<%@ page import="org.labkey.api.specimen.Vial"%> +<%@ page import="org.labkey.api.specimen.location.LocationImpl" %> +<%@ page import="org.labkey.api.specimen.location.LocationManager"%> <%@ page import="org.labkey.api.specimen.settings.SettingsManager" %> <%@ page import="org.labkey.api.study.Location" %> <%@ page import="org.labkey.api.study.SpecimenService" %> @@ -36,6 +35,7 @@ <%@ page import="org.labkey.api.view.template.ClientDependencies" %> <%@ page import="org.labkey.specimen.SpecimenManager" %> <%@ page import="org.labkey.specimen.SpecimenRequestManager" %> +<%@ page import="org.labkey.specimen.SpecimenRequestStatus" %> <%@ page import="org.labkey.specimen.actions.ManageRequestBean" %> <%@ page import="org.labkey.specimen.actions.ShowSearchAction" %> <%@ page import="org.labkey.specimen.actions.SpecimenController" %> diff --git a/specimen/src/org/labkey/specimen/view/manageRequestStatus.jsp b/specimen/src/org/labkey/specimen/view/manageRequestStatus.jsp index 9c487201617..84f770bf3ef 100644 --- a/specimen/src/org/labkey/specimen/view/manageRequestStatus.jsp +++ b/specimen/src/org/labkey/specimen/view/manageRequestStatus.jsp @@ -15,11 +15,11 @@ * limitations under the License. */ %> -<%@ page import="org.labkey.api.specimen.SpecimenRequestStatus" %> <%@ page import="org.labkey.api.study.SpecimenService" %> -<%@ page import="org.labkey.api.view.HttpView"%> +<%@ page import="org.labkey.api.view.HttpView" %> <%@ page import="org.labkey.api.view.JspView"%> <%@ page import="org.labkey.specimen.SpecimenRequestManager"%> +<%@ page import="org.labkey.specimen.SpecimenRequestStatus"%> <%@ page import="org.labkey.specimen.actions.ManageRequestBean" %> <%@ page import="org.labkey.specimen.actions.SpecimenController" %> <%@ page import="org.labkey.specimen.notifications.ActorNotificationRecipientSet" %> diff --git a/specimen/src/org/labkey/specimen/view/manageStatusOrder.jsp b/specimen/src/org/labkey/specimen/view/manageStatusOrder.jsp index 7b70e9d640e..0fc93ccc1f7 100644 --- a/specimen/src/org/labkey/specimen/view/manageStatusOrder.jsp +++ b/specimen/src/org/labkey/specimen/view/manageStatusOrder.jsp @@ -15,11 +15,11 @@ * limitations under the License. */ %> -<%@ page import="org.labkey.api.specimen.SpecimenRequestStatus"%> <%@ page import="org.labkey.api.study.Study"%> <%@ page import="org.labkey.api.view.HttpView"%> <%@ page import="org.labkey.api.view.JspView"%> <%@ page import="org.labkey.specimen.SpecimenRequestManager"%> +<%@ page import="org.labkey.specimen.SpecimenRequestStatus"%> <%@ page import="org.labkey.specimen.actions.SpecimenController.ManageStatusOrderAction" %> <%@ page import="org.labkey.specimen.actions.SpecimenController.ManageStatusesAction" %> <%@ page import="java.util.List" %> diff --git a/specimen/src/org/labkey/specimen/view/manageStatuses.jsp b/specimen/src/org/labkey/specimen/view/manageStatuses.jsp index 7b684478daf..048a79af27a 100644 --- a/specimen/src/org/labkey/specimen/view/manageStatuses.jsp +++ b/specimen/src/org/labkey/specimen/view/manageStatuses.jsp @@ -15,15 +15,15 @@ * limitations under the License. */ %> -<%@ page import="org.labkey.api.specimen.SpecimenRequestStatus"%> <%@ page import="org.labkey.api.specimen.settings.SettingsManager"%> <%@ page import="org.labkey.api.specimen.settings.StatusSettings"%> <%@ page import="org.labkey.api.study.Study"%> <%@ page import="org.labkey.api.study.StudyUrls"%> -<%@ page import="org.labkey.api.view.ActionURL" %> +<%@ page import="org.labkey.api.view.ActionURL"%> <%@ page import="org.labkey.api.view.HttpView" %> <%@ page import="org.labkey.api.view.JspView" %> <%@ page import="org.labkey.specimen.SpecimenRequestManager" %> +<%@ page import="org.labkey.specimen.SpecimenRequestStatus" %> <%@ page import="org.labkey.specimen.actions.SpecimenController.DeleteStatusAction" %> <%@ page import="org.labkey.specimen.actions.SpecimenController.ManageStatusOrderAction" %> <%@ page import="org.labkey.specimen.actions.SpecimenController.ManageStatusesAction" %> diff --git a/specimen/src/org/labkey/specimen/view/viewRequestsHeader.jsp b/specimen/src/org/labkey/specimen/view/viewRequestsHeader.jsp index d5ae527b615..fbfcada48d7 100644 --- a/specimen/src/org/labkey/specimen/view/viewRequestsHeader.jsp +++ b/specimen/src/org/labkey/specimen/view/viewRequestsHeader.jsp @@ -15,11 +15,11 @@ * limitations under the License. */ %> -<%@ page import="org.labkey.api.specimen.SpecimenRequestStatus" %> <%@ page import="org.labkey.api.view.ActionURL" %> <%@ page import="org.labkey.api.view.HttpView" %> <%@ page import="org.labkey.api.view.JspView" %> <%@ page import="org.labkey.api.view.ViewContext" %> +<%@ page import="org.labkey.specimen.SpecimenRequestStatus" %> <%@ page import="org.labkey.specimen.actions.ViewRequestsHeaderBean" %> <%@ page extends="org.labkey.api.jsp.JspBase" %> <% diff --git a/specimen/src/org/labkey/specimen/writer/LocationSpecimenWriter.java b/specimen/src/org/labkey/specimen/writer/LocationSpecimenWriter.java index a49821d0383..c9fc5dfd8d3 100644 --- a/specimen/src/org/labkey/specimen/writer/LocationSpecimenWriter.java +++ b/specimen/src/org/labkey/specimen/writer/LocationSpecimenWriter.java @@ -18,7 +18,7 @@ import org.labkey.api.data.SQLFragment; import org.labkey.api.data.TableInfo; import org.labkey.api.data.dialect.SqlDialect; -import org.labkey.api.specimen.importer.ImportableColumn; +import org.labkey.specimen.importer.ImportableColumn; import org.labkey.api.study.writer.SimpleStudyExportContext; import java.util.Collection; diff --git a/specimen/src/org/labkey/specimen/writer/SpecimenArchiveWriter.java b/specimen/src/org/labkey/specimen/writer/SpecimenArchiveWriter.java index dc844fd4cda..b6775986f61 100644 --- a/specimen/src/org/labkey/specimen/writer/SpecimenArchiveWriter.java +++ b/specimen/src/org/labkey/specimen/writer/SpecimenArchiveWriter.java @@ -27,7 +27,7 @@ import org.labkey.api.data.TableInfoWriter; import org.labkey.api.exp.property.Domain; import org.labkey.api.exp.property.DomainProperty; -import org.labkey.api.specimen.SpecimenColumns; +import org.labkey.specimen.SpecimenColumns; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.model.SpecimenTablesProvider; import org.labkey.api.study.Study; diff --git a/specimen/src/org/labkey/specimen/writer/SpecimenSettingsWriter.java b/specimen/src/org/labkey/specimen/writer/SpecimenSettingsWriter.java index 8e9707f7795..ea6a07c5b5d 100644 --- a/specimen/src/org/labkey/specimen/writer/SpecimenSettingsWriter.java +++ b/specimen/src/org/labkey/specimen/writer/SpecimenSettingsWriter.java @@ -17,8 +17,6 @@ import org.jetbrains.annotations.Nullable; import org.labkey.api.security.GroupManager; -import org.labkey.api.specimen.SpecimenRequestStatus; -import org.labkey.api.specimen.importer.RequestabilityManager; import org.labkey.api.specimen.settings.DisplaySettings; import org.labkey.api.specimen.settings.RepositorySettings; import org.labkey.api.specimen.settings.SettingsManager; @@ -31,7 +29,9 @@ import org.labkey.security.xml.GroupsType; import org.labkey.specimen.SpecimenRequestManager; import org.labkey.specimen.SpecimenRequestManager.SpecimenRequestInput; +import org.labkey.specimen.SpecimenRequestStatus; import org.labkey.specimen.actions.ManageReqsBean; +import org.labkey.specimen.importer.RequestabilityManager; import org.labkey.specimen.model.SpecimenRequestActor; import org.labkey.specimen.requirements.SpecimenRequestRequirement; import org.labkey.specimen.requirements.SpecimenRequestRequirementProvider; diff --git a/specimen/src/org/labkey/specimen/writer/SpecimenWriter.java b/specimen/src/org/labkey/specimen/writer/SpecimenWriter.java index b797c1548f7..9265e940814 100644 --- a/specimen/src/org/labkey/specimen/writer/SpecimenWriter.java +++ b/specimen/src/org/labkey/specimen/writer/SpecimenWriter.java @@ -34,9 +34,9 @@ import org.labkey.api.exp.PropertyDescriptor; import org.labkey.api.query.UserSchema; import org.labkey.api.specimen.SpecimenSchema; -import org.labkey.api.specimen.SpecimenTableManager; -import org.labkey.api.specimen.importer.SpecimenColumn; -import org.labkey.api.specimen.importer.TargetTable; +import org.labkey.specimen.SpecimenTableManager; +import org.labkey.specimen.importer.SpecimenColumn; +import org.labkey.specimen.importer.TargetTable; import org.labkey.api.study.Study; import org.labkey.api.study.StudyService; import org.labkey.api.study.writer.SimpleStudyExportContext; diff --git a/specimen/src/org/labkey/specimen/writer/StandardSpecimenWriter.java b/specimen/src/org/labkey/specimen/writer/StandardSpecimenWriter.java index 840ba294595..f2b8b0b5e6c 100644 --- a/specimen/src/org/labkey/specimen/writer/StandardSpecimenWriter.java +++ b/specimen/src/org/labkey/specimen/writer/StandardSpecimenWriter.java @@ -25,7 +25,7 @@ import org.labkey.api.data.TSVGridWriter; import org.labkey.api.data.TableInfo; import org.labkey.api.specimen.SpecimenSchema; -import org.labkey.api.specimen.importer.ImportableColumn; +import org.labkey.specimen.importer.ImportableColumn; import org.labkey.api.study.writer.SimpleStudyExportContext; import org.labkey.api.writer.VirtualFile; import org.labkey.api.writer.Writer; diff --git a/study/api-src/org/labkey/api/specimen/SpecimenEventManager.java b/study/api-src/org/labkey/api/specimen/SpecimenEventManager.java index 4b303469213..8a8f92f7c08 100644 --- a/study/api-src/org/labkey/api/specimen/SpecimenEventManager.java +++ b/study/api-src/org/labkey/api/specimen/SpecimenEventManager.java @@ -9,9 +9,6 @@ import org.labkey.api.query.FieldKey; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.List; // Methods extracted from SpecimenManager to assist with migration. TODO: remove these or recombine with SpecimenManager @@ -65,46 +62,7 @@ public SpecimenEvent getLastEvent(List dateOrderedEvents) return dateOrderedEvents.get(dateOrderedEvents.size() - 1); } - public Integer getProcessingLocationId(List dateOrderedEvents) - { - SpecimenEvent firstEvent = getFirstEvent(dateOrderedEvents); - return firstEvent != null ? firstEvent.getLabId() : null; - } - - public String getFirstProcessedByInitials(List dateOrderedEvents) - { - SpecimenEvent firstEvent = getFirstEvent(dateOrderedEvents); - return firstEvent != null ? firstEvent.getProcessedByInitials() : null; - } - - public List getSpecimenEvents(@NotNull Vial vial) - { - SimpleFilter filter = new SimpleFilter(FieldKey.fromParts("VialId"), vial.getRowId()); - return getSpecimenEvents(vial.getContainer(), filter); - } - - public List getSpecimenEvents(List vials, boolean includeObsolete) - { - if (vials == null || vials.size() == 0) - return Collections.emptyList(); - Collection vialIds = new HashSet<>(); - Container container = null; - for (Vial vial : vials) - { - vialIds.add(vial.getRowId()); - if (container == null) - container = vial.getContainer(); - else if (!container.equals(vial.getContainer())) - throw new IllegalArgumentException("All specimens must be from the same container"); - } - SimpleFilter filter = new SimpleFilter(); - filter.addInClause(FieldKey.fromString("VialId"), vialIds); - if (!includeObsolete) - filter.addCondition(FieldKey.fromString("Obsolete"), false); - return getSpecimenEvents(container, filter); - } - - private List getSpecimenEvents(final Container container, Filter filter) + public List getSpecimenEvents(final Container container, Filter filter) { final List specimenEvents = new ArrayList<>(); TableInfo tableInfo = SpecimenSchema.get().getTableInfoSpecimenEvent(container); @@ -124,4 +82,10 @@ public List getDateOrderedEventList(Vial vial) eventList.sort(SpecimenEventDateComparator.get()); return eventList; } + + private List getSpecimenEvents(@NotNull Vial vial) + { + SimpleFilter filter = new SimpleFilter(FieldKey.fromParts("VialId"), vial.getRowId()); + return getSpecimenEvents(vial.getContainer(), filter); + } } diff --git a/study/api-src/org/labkey/api/specimen/SpecimenManager.java b/study/api-src/org/labkey/api/specimen/SpecimenManager.java index d0a473499b1..ca108138537 100644 --- a/study/api-src/org/labkey/api/specimen/SpecimenManager.java +++ b/study/api-src/org/labkey/api/specimen/SpecimenManager.java @@ -16,7 +16,6 @@ package org.labkey.api.specimen; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.labkey.api.data.ColumnInfo; import org.labkey.api.data.Container; @@ -61,14 +60,6 @@ public boolean isSpecimenModuleActive(Container c) return null != specimenModule && c.getActiveModules().contains(specimenModule); } - public long getMaxExternalId(Container container) - { - TableInfo tableInfo = SpecimenSchema.get().getTableInfoSpecimenEvent(container); - SQLFragment sql = new SQLFragment("SELECT MAX(ExternalId) FROM "); - sql.append(tableInfo); - return new SqlSelector(tableInfo.getSchema(), sql).getArrayList(Long.class).get(0); - } - public int getSpecimenCountForVisit(Visit visit) { Container container = visit.getContainer(); @@ -141,9 +132,9 @@ public void deleteSpecimensForVisit(Visit visit) new SqlExecutor(SpecimenSchema.get().getSchema()).execute(deleteSpecimenSql); - SpecimenMigrationService SMS = SpecimenMigrationService.get(); - if (null != SMS) - SMS.clearRequestCaches(visit.getContainer()); + SpecimenMigrationService sms = SpecimenMigrationService.get(); + if (null != sms) + sms.clearRequestCaches(visit.getContainer()); } @Nullable @@ -185,35 +176,6 @@ private SQLFragment getVisitRangeSql(Visit visit, TableInfo tinfoSpecimen, Strin return sqlVisitRange; } - public void deleteSpecimen(@NotNull Vial vial, boolean clearCaches) - { - Container container = vial.getContainer(); - TableInfo tableInfoSpecimenEvent = SpecimenSchema.get().getTableInfoSpecimenEvent(container); - TableInfo tableInfoVial = SpecimenSchema.get().getTableInfoVial(container); - if (null == tableInfoSpecimenEvent || null == tableInfoVial) - return; - - String tableInfoSpecimenEventSelectName = tableInfoSpecimenEvent.getSelectName(); - String tableInfoVialSelectName = tableInfoVial.getSelectName(); - - SQLFragment sqlFragmentEvent = new SQLFragment("DELETE FROM "); - sqlFragmentEvent.append(tableInfoSpecimenEventSelectName).append(" WHERE VialId = ?"); - sqlFragmentEvent.add(vial.getRowId()); - new SqlExecutor(SpecimenSchema.get().getSchema()).execute(sqlFragmentEvent); - - SQLFragment sqlFragment = new SQLFragment("DELETE FROM "); - sqlFragment.append(tableInfoVialSelectName).append(" WHERE RowId = ?"); - sqlFragment.add(vial.getRowId()); - new SqlExecutor(SpecimenSchema.get().getSchema()).execute(sqlFragment); - - if (clearCaches) - { - SpecimenMigrationService SMS = SpecimenMigrationService.get(); - if (null != SMS) - SMS.clearRequestCaches(vial.getContainer()); - } - } - public SpecimenComment[] getSpecimenCommentForSpecimen(Container container, String specimenHash) { return getSpecimenCommentForSpecimens(container, Collections.singleton(specimenHash)); diff --git a/study/api-src/org/labkey/api/specimen/SpecimenManagerNew.java b/study/api-src/org/labkey/api/specimen/SpecimenManagerNew.java index 8c69a10e5e2..0bfeaa690be 100644 --- a/study/api-src/org/labkey/api/specimen/SpecimenManagerNew.java +++ b/study/api-src/org/labkey/api/specimen/SpecimenManagerNew.java @@ -9,7 +9,6 @@ import org.labkey.api.data.SqlSelector; import org.labkey.api.data.TableInfo; import org.labkey.api.data.TableSelector; -import org.labkey.api.query.FieldKey; import org.labkey.api.query.UserSchema; import org.labkey.api.security.User; import org.labkey.api.specimen.model.PrimaryType; @@ -17,11 +16,9 @@ import org.labkey.api.specimen.model.SpecimenTypeSummaryRow; import org.labkey.api.study.Study; import org.labkey.api.study.StudyService; -import org.labkey.api.view.NotFoundException; import java.util.ArrayList; import java.util.List; -import java.util.Set; public class SpecimenManagerNew { @@ -36,57 +33,6 @@ public static SpecimenManagerNew get() return INSTANCE; } - public List getVials(Container container, User user, Set vialRowIds) - { - // Take a set to eliminate dups - issue 26940 - - SimpleFilter filter = SimpleFilter.createContainerFilter(container); - filter.addInClause(FieldKey.fromParts("RowId"), vialRowIds); - List vials = getVials(container, user, filter); - if (vials.size() != vialRowIds.size()) - { - List unmatchedRowIds = new ArrayList<>(vialRowIds); - for (Vial vial : vials) - { - unmatchedRowIds.remove(vial.getRowId()); - } - throw new SpecimenRequestException("One or more specimen RowIds had no matching specimen: " + unmatchedRowIds); - } - return vials; - } - - public List getVials(final Container container, final User user, SimpleFilter filter) - { - // TODO: LinkedList? - final List vials = new ArrayList<>(); - - getSpecimensSelector(container, user, filter) - .forEachMap(map -> vials.add(new Vial(container, map))); - - return vials; - } - - public TableSelector getSpecimensSelector(final Container container, final User user, SimpleFilter filter) - { - Study study = StudyService.get().getStudy(container); - if (study == null) - { - throw new NotFoundException("No study in container " + container.getPath()); - } - UserSchema schema = SpecimenQuerySchema.get(study, user); - TableInfo specimenTable = schema.getTable(SpecimenQuerySchema.SPECIMEN_WRAP_TABLE_NAME); - return new TableSelector(specimenTable, filter, null); - } - - public Vial getVial(Container container, User user, long rowId) - { - SimpleFilter filter = new SimpleFilter(FieldKey.fromParts("RowId"), rowId); - List vials = getVials(container, user, filter); - if (vials.isEmpty()) - return null; - return vials.get(0); - } - public List getPrimaryTypes(Container c) { return getPrimaryTypes(c, null, new Sort("ExternalId")); diff --git a/study/api-src/org/labkey/api/specimen/SpecimenMigrationService.java b/study/api-src/org/labkey/api/specimen/SpecimenMigrationService.java index 16fa8589a75..c40580e6a8f 100644 --- a/study/api-src/org/labkey/api/specimen/SpecimenMigrationService.java +++ b/study/api-src/org/labkey/api/specimen/SpecimenMigrationService.java @@ -1,22 +1,40 @@ package org.labkey.api.specimen; +import jakarta.servlet.http.HttpServletResponse; import org.jetbrains.annotations.Nullable; import org.labkey.api.data.Container; import org.labkey.api.data.TableInfo; import org.labkey.api.pipeline.PipelineJob; import org.labkey.api.pipeline.PipelineJobException; +import org.labkey.api.query.QuerySettings; +import org.labkey.api.query.QueryUpdateService; +import org.labkey.api.query.QueryView; import org.labkey.api.query.ValidationException; +import org.labkey.api.reader.TabLoader; import org.labkey.api.security.User; import org.labkey.api.services.ServiceRegistry; +import org.labkey.api.study.TimepointType; import org.labkey.api.study.importer.SimpleStudyImportContext; import org.labkey.api.view.ActionURL; +import org.labkey.api.view.ViewContext; +import java.io.IOException; import java.nio.file.Path; +import java.util.List; +import java.util.Map; // Temporary service that provides entry points to ease migration of code from study module to specimen module // These should all go away once the migration is complete public interface SpecimenMigrationService { + // These constants were copied from SimpleSpecimenImporter, allowing that class to move into specimen + String VIAL_ID = "global_unique_specimen_id"; + String SAMPLE_ID = "specimen_number"; + String DRAW_TIMESTAMP = "draw_timestamp"; + String VISIT = "visit_value"; + String DERIVATIVE_TYPE = "derivative_type"; + String PARTICIPANT_ID = "ptid"; + static SpecimenMigrationService get() { return ServiceRegistry.get().getService(SpecimenMigrationService.class); @@ -30,15 +48,21 @@ static void setInstance(SpecimenMigrationService impl) String SPECIMENS_ARCHIVE_TYPE = "Specimens"; ActionURL getBeginURL(Container c); - ActionURL getInsertSpecimenQueryRowURL(Container c, String schemaName, TableInfo table); ActionURL getSelectedSpecimensURL(Container c); - ActionURL getSpecimenEventsURL(Container c, ActionURL returnUrl); ActionURL getSpecimensURL(Container c); - ActionURL getUpdateSpecimenQueryRowURL(Container c, String schemaName, TableInfo table); void importSpecimenArchive(@Nullable Path inputFile, PipelineJob job, SimpleStudyImportContext ctx, boolean merge, boolean syncParticipantVisit) throws PipelineJobException, ValidationException; void clearRequestCaches(Container c); - void updateVialCounts(Container container, User user); + + @Nullable QueryUpdateService getSpecimenQueryUpdateService(Container c, TableInfo queryTable); + + void importSpecimens(Container container, User user, List> specimens) throws ValidationException, IOException; + void exportSpecimens(Container container, User user, List> specimens, TimepointType timepointType, String participantIdLabel, HttpServletResponse response); + Map getColumnLabelMap(Container container, User user); + void fixupSpecimenColumns(Container container, User user, TabLoader loader) throws IOException; + QueryView getSpecimenQueryView(ViewContext context, QuerySettings settings); + + void setDefaultRequestabilityRules(Container container, User user); } diff --git a/study/src/org/labkey/study/controllers/StudyController.java b/study/src/org/labkey/study/controllers/StudyController.java index ae2403bbb99..a1d15c4ddc4 100644 --- a/study/src/org/labkey/study/controllers/StudyController.java +++ b/study/src/org/labkey/study/controllers/StudyController.java @@ -165,7 +165,7 @@ import org.labkey.api.security.permissions.UpdatePermission; import org.labkey.api.settings.ExperimentalFeatureService; import org.labkey.api.specimen.SpecimenManager; -import org.labkey.api.specimen.importer.RequestabilityManager; +import org.labkey.api.specimen.SpecimenMigrationService; import org.labkey.api.specimen.location.LocationImpl; import org.labkey.api.specimen.location.LocationManager; import org.labkey.api.study.CohortFilter; @@ -299,10 +299,6 @@ import static org.labkey.study.model.QCStateSet.selectedQCStateLabelFromUrl; import static org.labkey.study.query.DatasetQueryView.EXPERIMENTAL_ALLOW_MERGE_WITH_MANAGED_KEYS; -/** - * User: Karl Lum - * Date: Nov 28, 2007 - */ public class StudyController extends BaseStudyController { private static final Logger _log = LogManager.getLogger(StudyController.class); @@ -1449,7 +1445,7 @@ public static StudyImpl createStudy(@Nullable StudyImpl study, Container c, User study.setSubjectColumnName(form.getSubjectColumnName()); study.setAssayPlan(form.getAssayPlan()); study.setDescription(form.getDescription()); - study.setDefaultTimepointDuration(form.getDefaultTimepointDuration() < 1 ? 1 : form.getDefaultTimepointDuration()); + study.setDefaultTimepointDuration(Math.max(form.getDefaultTimepointDuration(), 1)); if (form.getDescriptionRendererType() != null) study.setDescriptionRendererType(form.getDescriptionRendererType()); study.setGrant(form.getGrant()); @@ -1468,7 +1464,9 @@ public static StudyImpl createStudy(@Nullable StudyImpl study, Container c, User } study = StudyManager.getInstance().createStudy(user, study); - RequestabilityManager.getInstance().setDefaultRules(c, user); + SpecimenMigrationService sms = SpecimenMigrationService.get(); + if (null != sms) + sms.setDefaultRequestabilityRules(c, user); } return study; } diff --git a/study/src/org/labkey/study/controllers/designer/DesignerController.java b/study/src/org/labkey/study/controllers/designer/DesignerController.java index 1ebb8a89a7e..a9c1563ba63 100644 --- a/study/src/org/labkey/study/controllers/designer/DesignerController.java +++ b/study/src/org/labkey/study/controllers/designer/DesignerController.java @@ -18,6 +18,8 @@ import gwt.client.org.labkey.study.designer.client.model.GWTCohort; import gwt.client.org.labkey.study.designer.client.model.GWTStudyDefinition; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; import org.apache.commons.lang3.StringUtils; import org.json.JSONArray; import org.json.JSONObject; @@ -47,7 +49,7 @@ import org.labkey.api.security.permissions.DeletePermission; import org.labkey.api.security.permissions.ReadPermission; import org.labkey.api.security.permissions.UpdatePermission; -import org.labkey.api.specimen.importer.SimpleSpecimenImporter; +import org.labkey.api.specimen.SpecimenMigrationService; import org.labkey.api.study.MapArrayExcelWriter; import org.labkey.api.study.Study; import org.labkey.api.study.StudyService; @@ -77,8 +79,6 @@ import org.springframework.validation.Errors; import org.springframework.web.servlet.ModelAndView; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.http.HttpSession; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -405,6 +405,8 @@ public void setIncludeSubfolders(boolean includeSubfolders) _includeSubfolders = includeSubfolders; } } + + @SuppressWarnings("unused") // Invoked from createRepositoryWizard.jsp @RequiresPermission(ReadPermission.class) public class GetSpecimenExcelAction extends ExportAction { @@ -412,13 +414,12 @@ public class GetSpecimenExcelAction extends ExportAction public void export(CreateRepositoryForm form, HttpServletResponse response, BindException errors) { //Search for a template in all folders up to root. - SimpleSpecimenImporter importer = new SimpleSpecimenImporter(getContainer(), getUser(), TimepointType.DATE, "Subject"); - List> defaultSpecimens = StudyDesignManager.get().generateSampleList(getStudyDefinition(form), getParticipants(), form.getBeginDate()); - MapArrayExcelWriter xlWriter = new MapArrayExcelWriter(defaultSpecimens, importer.getSimpleSpecimenColumns()); - // Note: I don't think this is having any effect on the output because ExcelColumn.renderCaption() uses - // the DisplayColumn's caption, not its own caption. That seems wrong... - xlWriter.setColumnModifier(col -> col.setCaption(importer.label(col.getName()))); - xlWriter.renderWorkbook(response); + SpecimenMigrationService sms = SpecimenMigrationService.get(); + if (null != sms) + { + List> defaultSpecimens = StudyDesignManager.get().generateSampleList(getStudyDefinition(form), getParticipants(), form.getBeginDate()); + sms.exportSpecimens(getContainer(), getUser(), defaultSpecimens, TimepointType.DATE, "Subject", response); + } } } @@ -706,7 +707,7 @@ private static void fixupParticipantCols(TabLoader loader) throws IOException for (ColumnDescriptor col : PARTICIPANT_COLS) colMap.put(col.name, col); colMap.put("ptid", colMap.get("ParticipantId")); - colMap.put("SubjectId", colMap.get(SimpleSpecimenImporter.PARTICIPANT_ID)); + colMap.put("SubjectId", colMap.get(SpecimenMigrationService.PARTICIPANT_ID)); ColumnDescriptor[] newCols = new ColumnDescriptor[loaderCols.length]; for (int i = 0; i < loaderCols.length; i++) @@ -752,90 +753,92 @@ private void showSamples(CreateRepositoryForm form) throws IOException } @SuppressWarnings("unchecked") - private void handleUploadSamples(CreateRepositoryForm form) - throws IOException + private void handleUploadSamples(CreateRepositoryForm form) throws IOException { - Set errors = new LinkedHashSet<>(); - String specimenTSV = StringUtils.trimToNull(form.getSpecimenTSV()); - if (null == specimenTSV) - { - form.setMessage("Please provide specimen information."); - return; - } - TabLoader loader = new TabLoader(specimenTSV, true); - Map columnAliases = new HashMap(); - Map labels = new HashMap(); - //Make sure we accept the labels - SimpleSpecimenImporter importer = new SimpleSpecimenImporter(getContainer(), getUser()); - for (Map.Entry entry : importer.getColumnLabels().entrySet()) + SpecimenMigrationService sms = SpecimenMigrationService.get(); + if (null != sms) { - columnAliases.put(entry.getValue(), entry.getKey()); - labels.put(entry.getKey(), entry.getValue()); - } + Set errors = new LinkedHashSet<>(); + String specimenTSV = StringUtils.trimToNull(form.getSpecimenTSV()); + if (null == specimenTSV) + { + form.setMessage("Please provide specimen information."); + return; + } + TabLoader loader = new TabLoader(specimenTSV, true); + Map columnAliases = new HashMap<>(); + Map labels = new HashMap<>(); + //Make sure we accept the labels + for (Map.Entry entry : sms.getColumnLabelMap(getContainer(), getUser()).entrySet()) + { + columnAliases.put(entry.getValue(), entry.getKey()); + labels.put(entry.getKey(), entry.getValue()); + } - //And a few more aliases - columnAliases.put("ParticipantId", SimpleSpecimenImporter.PARTICIPANT_ID); - columnAliases.put("Date", SimpleSpecimenImporter.DRAW_TIMESTAMP); - columnAliases.put("Subject", SimpleSpecimenImporter.PARTICIPANT_ID); + //And a few more aliases + columnAliases.put("ParticipantId", SpecimenMigrationService.PARTICIPANT_ID); + columnAliases.put("Date", SpecimenMigrationService.DRAW_TIMESTAMP); + columnAliases.put("Subject", SpecimenMigrationService.PARTICIPANT_ID); - //Remember whether we used a different header so we can put up error messages that make sense - for (ColumnDescriptor c : loader.getColumns()) - { - if (columnAliases.containsKey(c.name)) + //Remember whether we used a different header so we can put up error messages that make sense + for (ColumnDescriptor c : loader.getColumns()) { - labels.put(columnAliases.get(c.name), c.name); - c.name = columnAliases.get(c.name); + if (columnAliases.containsKey(c.name)) + { + labels.put(columnAliases.get(c.name), c.name); + c.name = columnAliases.get(c.name); + } + else + labels.put(c.name, c.name); } - else - labels.put(c.name, c.name); - } - importer.fixupSpecimenColumns(loader); + sms.fixupSpecimenColumns(getContainer(), getUser(), loader); - List> specimenRows = loader.load(); - setSpecimens(specimenRows); - Set participants = new HashSet<>(); - int rowNum = 1; - for (Map row : specimenRows) - { - if (row.get(SimpleSpecimenImporter.VIAL_ID) == null && row.get(SimpleSpecimenImporter.SAMPLE_ID) == null) - errors.add("Error, Row " + rowNum + " must provide a sample or vial ID."); + List> specimenRows = loader.load(); + setSpecimens(specimenRows); + Set participants = new HashSet<>(); + int rowNum = 1; + for (Map row : specimenRows) + { + if (row.get(SpecimenMigrationService.VIAL_ID) == null && row.get(SpecimenMigrationService.SAMPLE_ID) == null) + errors.add("Error, Row " + rowNum + " must provide a sample or vial ID."); - String participant = (String) row.get(SimpleSpecimenImporter.PARTICIPANT_ID); - if (null == participant) - errors.add("Error, Row " + rowNum + " field " + labels.get(SimpleSpecimenImporter.PARTICIPANT_ID) + " is not supplied"); - else - participants.add(participant); + String participant = (String) row.get(SpecimenMigrationService.PARTICIPANT_ID); + if (null == participant) + errors.add("Error, Row " + rowNum + " field " + labels.get(SpecimenMigrationService.PARTICIPANT_ID) + " is not supplied"); + else + participants.add(participant); - for (String col : PageFlowUtil.set(SimpleSpecimenImporter.SAMPLE_ID, SimpleSpecimenImporter.DRAW_TIMESTAMP)) - if (null == row.get(col)) - errors.add("Error, Row " + rowNum + " does not contain a value for field " + (labels.containsKey(col) ? labels.get(col) : col)); + for (String col : PageFlowUtil.set(SpecimenMigrationService.SAMPLE_ID, SpecimenMigrationService.DRAW_TIMESTAMP)) + if (null == row.get(col)) + errors.add("Error, Row " + rowNum + " does not contain a value for field " + (labels.containsKey(col) ? labels.get(col) : col)); - if (errors.size() >= 3) - break; + if (errors.size() >= 3) + break; - rowNum++; - } - if (!form.isIgnoreWarnings()) - { - int nParticipantsExpected = 0; - for (GWTCohort cohort : getStudyDefinition(form).getGroups()) - nParticipantsExpected += cohort.getCount(); + rowNum++; + } + if (!form.isIgnoreWarnings()) + { + int nParticipantsExpected = 0; + for (GWTCohort cohort : getStudyDefinition(form).getGroups()) + nParticipantsExpected += cohort.getCount(); - if (participants.size() != nParticipantsExpected) - errors.add("Warning, Expected samples for " + nParticipantsExpected + " subjects, received samples for " + participants); + if (participants.size() != nParticipantsExpected) + errors.add("Warning, Expected samples for " + nParticipantsExpected + " subjects, received samples for " + participants); - form.setContainsWarnings(true); - } - if (errors.size() > 0) - { - StringBuilder sb = new StringBuilder(); - for (String e : errors) - sb.append(e).append("\n"); + form.setContainsWarnings(true); + } + if (!errors.isEmpty()) + { + StringBuilder sb = new StringBuilder(); + for (String e : errors) + sb.append(e).append("\n"); - form.setMessage(sb.toString()); + form.setMessage(sb.toString()); + } + else + form.setWizardStep(WizardStep.CONFIRM); } - else - form.setWizardStep(WizardStep.CONFIRM); } public static GWTStudyDefinition getStudyDefinition(CreateRepositoryForm form, User user, Container container) diff --git a/study/src/org/labkey/study/designer/StudyDesignManager.java b/study/src/org/labkey/study/designer/StudyDesignManager.java index ec32b029ceb..df284640d4e 100644 --- a/study/src/org/labkey/study/designer/StudyDesignManager.java +++ b/study/src/org/labkey/study/designer/StudyDesignManager.java @@ -48,7 +48,7 @@ import org.labkey.api.query.ValidationException; import org.labkey.api.security.SecurityManager; import org.labkey.api.security.User; -import org.labkey.api.specimen.importer.SimpleSpecimenImporter; +import org.labkey.api.specimen.SpecimenMigrationService; import org.labkey.api.study.Dataset; import org.labkey.api.study.Study; import org.labkey.api.study.TimepointType; @@ -395,7 +395,7 @@ public void deleteStudyDesign(Container container, int studyId) public Study generateStudyFromDesign(User user, Container parent, String folderName, Date startDate, String subjectNounSingular, String subjectNounPlural, String subjectColumnName, StudyDesignInfo info, - List> participantDataset, List> specimens) throws IOException, ValidationException + List> participantDataset, List> specimens) throws IOException, ValidationException { Container studyFolder = parent.getChild(folderName); if (null == studyFolder) @@ -476,8 +476,9 @@ else if (timepoint.getUnit() == GWTTimepoint.MONTHS) // for (DatasetDefinition dsd : dsds) // StudyManager.getInstance().updateVisitDatasetMapping(user, study.getContainer(), 1, dsd.getDatasetId(), VisitDatasetType.OPTIONAL); - SimpleSpecimenImporter importer = new SimpleSpecimenImporter(study.getContainer(), user); - importer.process(specimens, false); + SpecimenMigrationService sms = SpecimenMigrationService.get(); + if (null != sms) + sms.importSpecimens(study.getContainer(), user, specimens); //Move study design into study folder... moveStudyDesign(user, info, study.getContainer()); @@ -530,7 +531,7 @@ public List> generateParticipantDataset(User user, GWTStudyD * @param participantInfo * @return */ - public List> generateSampleList(GWTStudyDefinition studyDefinition, List> participantInfo, Date studyStartDate) + public List> generateSampleList(GWTStudyDefinition studyDefinition, List> participantInfo, Date studyStartDate) { GWTAssaySchedule assaySchedule = studyDefinition.getAssaySchedule(); List timepoints = assaySchedule.getTimepoints(); @@ -557,16 +558,12 @@ public List> generateSampleList(GWTStudyDefinition studyDefin } //CONSIDER: Use something like ArrayListMap to share hash table space - List> rows = new ArrayList<>(); + List> rows = new ArrayList<>(); int timepointIndex = 1; //Use one based for (GWTTimepoint tp : timepoints) { - List groups = studyDefinition.getGroups(); Map timepointSamples = vialsPerSampleType.get(tp); - String cohort = null; - int cohortIndex = 0; - int participantIndex = 0; - for (Map participant : participantInfo) + for (Map participant : participantInfo) { Date startDate = (Date) participant.get("StartDate"); if (startDate == null) @@ -576,13 +573,13 @@ public List> generateSampleList(GWTStudyDefinition studyDefin for (String st : timepointSamples.keySet()) { String sampleId = ptid + "-" + tp.getDays(); - Map m = new HashMap<>(); - m.put(SimpleSpecimenImporter.VISIT, timepointIndex); - m.put(SimpleSpecimenImporter.PARTICIPANT_ID, ptid); - m.put(SimpleSpecimenImporter.SAMPLE_ID, sampleId); - m.put(SimpleSpecimenImporter.VIAL_ID, sampleId + (timepointSamples.size() == 1 ? "" : st)); - m.put(SimpleSpecimenImporter.DERIVIATIVE_TYPE, st); - m.put(SimpleSpecimenImporter.DRAW_TIMESTAMP, getDay(startDate, tp.getDays())); + Map m = new HashMap<>(); + m.put(SpecimenMigrationService.VISIT, timepointIndex); + m.put(SpecimenMigrationService.PARTICIPANT_ID, ptid); + m.put(SpecimenMigrationService.SAMPLE_ID, sampleId); + m.put(SpecimenMigrationService.VIAL_ID, sampleId + (timepointSamples.size() == 1 ? "" : st)); + m.put(SpecimenMigrationService.DERIVATIVE_TYPE, st); + m.put(SpecimenMigrationService.DRAW_TIMESTAMP, getDay(startDate, tp.getDays())); rows.add(m); } } diff --git a/study/src/org/labkey/study/importer/CreateChildStudyPipelineJob.java b/study/src/org/labkey/study/importer/CreateChildStudyPipelineJob.java index 2ea4fa797e0..4d2526e530c 100644 --- a/study/src/org/labkey/study/importer/CreateChildStudyPipelineJob.java +++ b/study/src/org/labkey/study/importer/CreateChildStudyPipelineJob.java @@ -683,6 +683,7 @@ private void ensureGroupParticipants(List participantGroups, S sql.add(sourceStudy.getContainer()); new SqlExecutor(schema.getSchema()).execute(sql); + StudyManager.getInstance().clearParticipantCache(getDstContainer()); } } } diff --git a/study/src/org/labkey/study/model/StudyManager.java b/study/src/org/labkey/study/model/StudyManager.java index 2f4cf753221..a13a110ed8e 100644 --- a/study/src/org/labkey/study/model/StudyManager.java +++ b/study/src/org/labkey/study/model/StudyManager.java @@ -145,6 +145,7 @@ import org.labkey.api.specimen.SpecimenManager; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.location.LocationCache; +import org.labkey.api.specimen.model.SpecimenTablesProvider; import org.labkey.api.study.AssaySpecimenConfig; import org.labkey.api.study.Cohort; import org.labkey.api.study.Dataset; @@ -218,7 +219,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.WeakHashMap; -import java.util.stream.Collectors; import static org.labkey.api.action.SpringActionController.ERROR_MSG; import static org.labkey.study.query.StudyQuerySchema.PERSONNEL_TABLE_NAME; @@ -2829,6 +2829,10 @@ public void deleteAllStudyData(Container c, User user) if (null != ss) ss.deleteAllSpecimenData(c, deletedTables, user); + // Since study creates these tables, study needs to delete them + new SpecimenTablesProvider(c, null, null).deleteTables(); + LocationCache.clear(c); + // // assay schedule // @@ -3446,6 +3450,7 @@ private void setAlternateId(Study study, String containerId, String participantI SQLFragment sql = new SQLFragment("UPDATE ").append(SCHEMA.getTableInfoParticipant()).append(" SET AlternateId = ? WHERE Container = ? AND ParticipantId = ?") .addAll(alternateId, containerId, participantId); new SqlExecutor(StudySchema.getInstance().getSchema()).execute(sql); + StudyManager.getInstance().clearParticipantCache(study.getContainer()); } private void setAlternateIdAndDateOffset(Study study, String participantId, @Nullable String alternateId, @Nullable Integer dateOffset) @@ -3471,6 +3476,7 @@ private void setAlternateIdAndDateOffset(Study study, String participantId, @Nul sql.add(study.getContainer()); sql.add(participantId); new SqlExecutor(StudySchema.getInstance().getSchema()).execute(sql); + StudyManager.getInstance().clearParticipantCache(study.getContainer()); } } diff --git a/study/src/org/labkey/study/pipeline/ParticipantImportRunnable.java b/study/src/org/labkey/study/pipeline/ParticipantImportRunnable.java index 98dbb3928fe..45b25083799 100644 --- a/study/src/org/labkey/study/pipeline/ParticipantImportRunnable.java +++ b/study/src/org/labkey/study/pipeline/ParticipantImportRunnable.java @@ -33,6 +33,7 @@ import org.labkey.study.StudySchema; import org.labkey.study.model.DatasetDefinition; import org.labkey.study.model.StudyImpl; +import org.labkey.study.model.StudyManager; import java.io.BufferedReader; import java.io.IOException; @@ -92,6 +93,7 @@ public String validate() public void _run() throws IOException, SQLException { TabLoader loader = null; + Container container = getDatasetDefinition().getContainer(); try { @@ -101,7 +103,6 @@ public void _run() throws IOException, SQLException for (ColumnDescriptor c : loader.getColumns()) columnMap.put(c.name, c); - Container container = getDatasetDefinition().getContainer(); String subjectIdCol = StudyService.get().getSubjectColumnName(container); if (!columnMap.containsKey(subjectIdCol)) { @@ -146,6 +147,7 @@ public void _run() throws IOException, SQLException } finally { + StudyManager.getInstance().clearParticipantCache(container); if (loader != null) loader.close(); } diff --git a/study/src/org/labkey/study/query/SpecimenDetailTable.java b/study/src/org/labkey/study/query/SpecimenDetailTable.java index be33b0e8529..c8b08be5889 100644 --- a/study/src/org/labkey/study/query/SpecimenDetailTable.java +++ b/study/src/org/labkey/study/query/SpecimenDetailTable.java @@ -39,10 +39,10 @@ import org.labkey.api.query.QueryUpdateService; import org.labkey.api.security.UserPrincipal; import org.labkey.api.security.permissions.Permission; +import org.labkey.api.specimen.SpecimenMigrationService; import org.labkey.api.specimen.SpecimenSchema; import org.labkey.api.specimen.importer.RollupHelper; import org.labkey.api.specimen.model.SpecimenTablesProvider; -import org.labkey.api.specimen.query.SpecimenUpdateService; import org.labkey.api.specimen.settings.SettingsManager; import org.labkey.api.study.StudyService; import org.labkey.study.CohortForeignKey; @@ -359,9 +359,8 @@ public boolean hasPermissionOverridable(UserPrincipal user, Class