Skip to content

Commit

Permalink
Add field to calculate litterMates
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber committed Jun 5, 2024
1 parent e551197 commit 8daa92a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mcc/resources/queries/study/demographicsLittermates.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<query xmlns="http://labkey.org/data/xml/query">
<description>Littermates of Any Animal</description>
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="demographicsLittermates" tableDbType="NOT_IN_DB">
<description>Littermates of Any Animal</description>
<columns>
<column columnName="Id">
<isKeyField>true</isKeyField>
<isHidden>true</isHidden>
</column>
<column columnName="litterId">

</column>
<column columnName="litterMates">
<columnTitle>Littermate(s)</columnTitle>
</column>
</columns>
<titleColumn>Relationship</titleColumn>
</table>
</tables>
</metadata>
</query>
16 changes: 16 additions & 0 deletions mcc/resources/queries/study/demographicsLittermates.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT

d1.Id,
d1.litterId,

GROUP_CONCAT(d2.Id, ',') as litterMates,

FROM study.Demographics d1

JOIN study.Demographics d2 ON (d1.litterId = d2.litterId AND d1.id != d2.id)

WHERE
d1.qcstate.publicdata = true AND
d2.qcstate.publicdata = true

GROUP BY d1.Id, d1.litterId
7 changes: 7 additions & 0 deletions mcc/src/org/labkey/mcc/query/MccEhrCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ private void customizeAnimalTable(AbstractTableInfo ti)
ti.addColumn(col);
}

if (ti.getColumn("littermates") == null)
{
var col = getWrappedIdCol(ti.getUserSchema(), ti, "littermates", "demographicsLittermates");
col.setLabel("Littermates");
col.setDescription("The IDs of ");
ti.addColumn(col);
}
}

private BaseColumnInfo getWrappedIdCol(UserSchema us, AbstractTableInfo ds, String name, String queryName)
Expand Down

0 comments on commit 8daa92a

Please sign in to comment.