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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions specimen/src/org/labkey/specimen/SpecimenRequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -764,15 +764,8 @@ private void updateVialCounts(Container container, User user, List<Vial> vials)

updateSql.append("WHERE ")
.append(tableInfoVial.getColumn("SpecimenId").getValueSql(tableInfoVialSelectName))
.append(" IN (");
String sep = "";
for (Long id : specimenIds)
{
updateSql.append(sep).append("?");
updateSql.add(id);
sep = ", ";
}
updateSql.append(")\n");
.appendInClause(specimenIds, SpecimenSchema.get().getSqlDialect())
.append("\n");
}

updateSql.append("\tGROUP BY SpecimenId\n) VialCounts\nWHERE ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,15 +798,8 @@ private void updateRequestability(Container container, User user, boolean resetT
updateSQL.add(null);
if (vials != null && !vials.isEmpty())
{
updateSQL.append("WHERE RowId IN (");
String sep = "";
for (Vial vial : vials)
{
updateSQL.append(sep).append("?");
sep = ", ";
updateSQL.add(vial.getRowId());
}
updateSQL.append(")");
updateSQL.append("WHERE RowId");
updateSQL.appendInClause(vials.stream().map(Vial::getRowId).toList(), schema.getSqlDialect());
}
new SqlExecutor(schema).execute(updateSQL);

Expand Down
16 changes: 2 additions & 14 deletions specimen/src/org/labkey/specimen/query/SpecimenQueryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,22 +608,10 @@ protected static SimpleFilter addFilterClause(SimpleFilter filter, List<Vial> vi
{
if (vials != null && !vials.isEmpty())
{
StringBuilder whereClause = new StringBuilder();
if (viewType.isVialView())
whereClause.append("RowId IN (");
filter = filter.addInClause(FieldKey.fromParts("RowId"), vials.stream().map(Vial::getRowId).toList());
else
whereClause.append("SpecimenHash IN (");
for (int i = 0; i < vials.size(); i++)
{
if (viewType.isVialView())
whereClause.append(vials.get(i).getRowId());
else
whereClause.append(vials.get(i).getSpecimenHash());
if (i < vials.size() - 1)
whereClause.append(", ");
}
whereClause.append(")");
filter = filter.addWhereClause(whereClause.toString(), null);
filter = filter.addInClause(FieldKey.fromParts("SpecimenHash"), vials.stream().map(Vial::getSpecimenHash).toList());
}
return filter;
}
Expand Down
45 changes: 5 additions & 40 deletions specimen/src/org/labkey/specimen/writer/SpecimenWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,20 @@ else if (null == column.getFkColumn())
String conjunction = "WHERE ";
if (ctx.getVisitIds() != null && !ctx.getVisitIds().isEmpty())
{
sql.append(conjunction).append("\n ParticipantVisitLookup.VisitRowId IN (");
sql.append(convertListToString(new ArrayList<>(ctx.getVisitIds()), false));
sql.append(")");
sql.append(conjunction).append("\n ParticipantVisitLookup.VisitRowId");
sql.appendInClause(ctx.getVisitIds(), dialect);
conjunction = " AND ";
}

if (null != ctx.getParticipants() && !ctx.getParticipants().isEmpty())
{
sql.append(conjunction);
if (ctx.isAlternateIds())
sql.append("\n ParticipantLookup.AlternateId IN (");
sql.append("\n ParticipantLookup.AlternateId");
else
sql.append("\n se.Ptid IN (");
sql.append("\n se.Ptid");

sql.append(convertListToString(ctx.getParticipants(), true));
sql.append(")");
sql.appendInClause(ctx.getParticipants(), dialect);
}

sql.append("\nORDER BY se.ExternalId");
Expand Down Expand Up @@ -248,41 +246,8 @@ private static boolean shouldRemovePhi(PHI exportPhiLevel, SpecimenColumn column
return false;
}

private static String convertListToString(List list, boolean withQuotes)
{
StringBuilder sb = new StringBuilder();
String sep = "";
for (Object obj : list)
{
sb.append(sep);
if (withQuotes) sb.append("'");
sb.append(obj.toString());
if (withQuotes) sb.append("'");
sep = ",";
}
return sb.toString();
}

public static class TestCase extends Assert
{
@Test
public void testConvertListToString()
{
List<Integer> ints = new ArrayList<>();
ints.add(1);
ints.add(2);
ints.add(3);
assertEquals("1,2,3", convertListToString(ints, false));
assertEquals("'1','2','3'", convertListToString(ints, true));

List<String> ptids = new ArrayList<>();
ptids.add("Ptid1");
ptids.add("Ptid2");
ptids.add("Ptid3");
assertEquals("Ptid1,Ptid2,Ptid3", convertListToString(ptids, false));
assertEquals("'Ptid1','Ptid2','Ptid3'", convertListToString(ptids, true));
}

@Test
public void testShouldRemovePhi()
{
Expand Down
Loading