Skip to content

Commit 069ec4f

Browse files
Create case-only difference check for Postgres, supporting dashboard link
1 parent 1638ba8 commit 069ec4f

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

mGAP/resources/queries/mGAP/sampleSummary.query.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<metadata>
33
<tables xmlns="http://labkey.org/data/xml">
44
<table tableName="" tableDbType="TABLE">
5+
<javaCustomizer class="org.labkey.mgap.query.SampleSummaryCustomizer"/>
56
<pkColumnName>subjectName</pkColumnName>
67
<tableTitle>mGAP Subject/gVCF Summary</tableTitle>
78
<columns>

mGAP/resources/queries/mGAP/sampleSummary.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ FROM (SELECT
2727
) t
2828

2929
LEFT JOIN mgap.subjectsSource ss on (t.subjectId = ss.originalId)
30-
LEFT JOIN mgap.animalMapping am on (t.subjectId = am.subjectname)
30+
-- Matched case-insensitively so an id whose alias-table spelling differs only in case still resolves; SampleSummaryCustomizer surfaces those as subjectCaseMismatch
31+
LEFT JOIN mgap.animalMapping am on (LOWER(t.subjectId) = LOWER(am.subjectname))
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.labkey.mgap.query;
2+
3+
import org.labkey.api.data.AbstractTableInfo;
4+
import org.labkey.api.data.JdbcType;
5+
import org.labkey.api.data.SQLFragment;
6+
import org.labkey.api.data.TableInfo;
7+
import org.labkey.api.gwt.client.FacetingBehaviorType;
8+
import org.labkey.api.ldk.table.AbstractTableCustomizer;
9+
import org.labkey.api.query.ExprColumn;
10+
11+
public class SampleSummaryCustomizer extends AbstractTableCustomizer
12+
{
13+
@Override
14+
public void customize(TableInfo ti)
15+
{
16+
if (ti instanceof AbstractTableInfo ati)
17+
{
18+
customizeTable(ati);
19+
}
20+
}
21+
22+
private void customizeTable(AbstractTableInfo ti)
23+
{
24+
String fieldName = "subjectCaseMismatch";
25+
if (ti.getColumn(fieldName) != null)
26+
{
27+
return;
28+
}
29+
30+
// Pairs up with the case-insensitive join in sampleSummary.sql: that supplies aliasSubjectName for ids differing only in case, and this case-sensitive comparison is what spots them
31+
SQLFragment sql = new SQLFragment("CASE WHEN " + ExprColumn.STR_TABLE_ALIAS + ".subjectId = " + ExprColumn.STR_TABLE_ALIAS + ".aliasSubjectName THEN NULL ELSE " + ExprColumn.STR_TABLE_ALIAS + ".aliasSubjectName END");
32+
ExprColumn col = new ExprColumn(ti, fieldName, sql, JdbcType.VARCHAR, ti.getColumn("subjectId"), ti.getColumn("aliasSubjectName"));
33+
col.setLabel("Id Case Mismatch?");
34+
col.setFacetingBehaviorType(FacetingBehaviorType.ALWAYS_OFF);
35+
col.setDescription("If the case of the subjectId differs from the alias table, the updated case is shown");
36+
ti.addColumn(col);
37+
}
38+
}

0 commit comments

Comments
 (0)