Skip to content

Commit 8f713f6

Browse files
authored
Add ONPRC parentage validation queries (#688)
* Add parentage validation queries
1 parent 79df7a2 commit 8f713f6

6 files changed

Lines changed: 184 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<query xmlns="http://labkey.org/data/xml/query">
2+
<metadata>
3+
<tables xmlns="http://labkey.org/data/xml">
4+
<table tableName="parentsWrongGenderOrSpecies" tableDbType="NOT_IN_DB">
5+
<tableTitle>Parentage Records With Mismatched Gender or Species</tableTitle>
6+
<pkColumnName>lsid</pkColumnName>
7+
<updateUrl>/ehr/manageRecord.view?schemaName=study&amp;queryName=${queryName}&amp;keyField=lsid&amp;key=${lsid}&amp;update=1</updateUrl>
8+
<columns>
9+
<column columnName="Id">
10+
11+
</column>
12+
<column columnName="parentGender">
13+
<columnTitle>Parent Gender</columnTitle>
14+
</column>
15+
<column columnName="parentSpecies">
16+
<columnTitle>Parent Species</columnTitle>
17+
</column>
18+
<column columnName="lsid">
19+
<isHidden>true</isHidden>
20+
</column>
21+
<column columnName="queryName">
22+
<isHidden>true</isHidden>
23+
</column>
24+
</columns>
25+
</table>
26+
</tables>
27+
</metadata>
28+
</query>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
SELECT
2+
p.Id,
3+
p.date,
4+
p.Id.demographics.species,
5+
p.relationship,
6+
p.parent,
7+
p.parent.demographics.gender as parentGender,
8+
p.parent.demographics.species as parentSpecies,
9+
p.lsid,
10+
'Parentage' as queryName
11+
FROM study.parentage p
12+
13+
WHERE p.qcstate.publicdata = true AND (
14+
-- Gender:
15+
(p.parent.demographics.gender.origgender IS NOT NULL AND p.relationship = 'Sire' AND p.parent.demographics.gender.origgender != 'm') OR
16+
(p.parent.demographics.gender.origgender IS NOT NULL AND p.relationship = 'Dam' AND p.parent.demographics.gender.origgender != 'f') OR
17+
(p.parent.demographics.gender.origgender IS NOT NULL AND p.relationship = 'Foster Dam' AND p.parent.demographics.gender.origgender != 'f') OR
18+
19+
-- Species
20+
(p.Id.demographics.species IS NOT NULL AND p.parent.demographics.species IS NOT NULL AND p.Id.demographics.species != p.parent.demographics.species)
21+
)
22+
23+
UNION ALL
24+
25+
SELECT
26+
p.Id,
27+
p.date,
28+
p.Id.demographics.species,
29+
'dam' as relationship,
30+
p.dam as parent,
31+
d.gender as parentGender,
32+
d.species as parentSpecies,
33+
p.lsid,
34+
'Birth' as queryName
35+
FROM study.birth p
36+
JOIN study.demographics d on (p.dam = d.Id)
37+
WHERE p.qcstate.publicdata = true AND (
38+
(d.gender.origgender IS NOT NULL AND d.gender.origgender != 'f') OR
39+
(p.Id.demographics.species IS NOT NULL AND d.species IS NOT NULL AND p.Id.demographics.species != d.species)
40+
) AND p.date >= '2000-01-01'
41+
42+
UNION ALL
43+
44+
SELECT
45+
p.Id,
46+
p.date,
47+
p.Id.demographics.species,
48+
'sire' as relationship,
49+
p.sire as parent,
50+
d.gender as parentGender,
51+
d.species as parentSpecies,
52+
p.lsid,
53+
'Birth' as queryName
54+
FROM study.birth p
55+
JOIN study.demographics d on (p.sire = d.Id)
56+
WHERE p.qcstate.publicdata = true AND (
57+
(d.gender.origgender IS NOT NULL AND d.gender.origgender != 'm') OR
58+
(p.Id.demographics.species IS NOT NULL AND d.species IS NOT NULL AND p.Id.demographics.species != d.species)
59+
) AND p.date >= '2000-01-01'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<query xmlns="http://labkey.org/data/xml/query">
2+
<metadata>
3+
<tables xmlns="http://labkey.org/data/xml">
4+
<table tableName="parentsYoungerThanOffspring" tableDbType="NOT_IN_DB">
5+
<tableTitle>Parentage Records With Parents Younger Than Offspring</tableTitle>
6+
<pkColumnName>lsid</pkColumnName>
7+
<updateUrl>/ehr/manageRecord.view?schemaName=study&amp;queryName=${queryName}&amp;keyField=lsid&amp;key=${lsid}&amp;update=1</updateUrl>
8+
<columns>
9+
<column columnName="Id">
10+
11+
</column>
12+
<column columnName="parentBirth">
13+
<columnTitle>Parent Birth</columnTitle>
14+
</column>
15+
<column columnName="lsid">
16+
<isHidden>true</isHidden>
17+
</column>
18+
<column columnName="queryName">
19+
<isHidden>true</isHidden>
20+
</column>
21+
</columns>
22+
</table>
23+
</tables>
24+
</metadata>
25+
</query>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
SELECT
2+
p.Id,
3+
p.parent,
4+
p.relationship,
5+
p.method,
6+
p.Id.demographics.birth,
7+
p.parent.demographics.birth as parentBirth,
8+
p.lsid,
9+
'Parentage' as queryName
10+
11+
FROM study.parentage p
12+
WHERE
13+
p.qcstate.publicdata = true AND
14+
(p.Id.demographics.birth IS NOT NULL AND p.parent.demographics.birth IS NOT NULL AND p.Id.demographics.birth <= p.parent.demographics.birth)
15+
16+
UNION ALL
17+
18+
SELECT
19+
p.Id,
20+
p.dam as parent,
21+
'Dam' as relationship,
22+
'Observed' as method,
23+
p.Id.demographics.birth,
24+
d.birth as parentBirth,
25+
p.lsid,
26+
'Birth' as queryName
27+
28+
FROM study.birth p
29+
JOIN study.demographics d on (p.dam = d.Id)
30+
WHERE
31+
p.qcstate.publicdata = true AND
32+
(p.Id.demographics.birth IS NOT NULL AND d.birth IS NOT NULL AND p.Id.demographics.birth <= d.birth)
33+
34+
UNION ALL
35+
36+
SELECT
37+
p.Id,
38+
p.sire as parent,
39+
'Sire' as relationship,
40+
'Observed' as method,
41+
p.Id.demographics.birth,
42+
d.birth as parentBirth,
43+
p.lsid,
44+
'Birth' as queryName
45+
46+
FROM study.birth p
47+
JOIN study.demographics d on (p.sire = d.Id)
48+
WHERE
49+
p.qcstate.publicdata = true AND
50+
(p.Id.demographics.birth IS NOT NULL AND d.birth IS NOT NULL AND p.Id.demographics.birth <= d.birth)

onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,27 @@ protected void birthRecordsWithoutDemographics(final Container c, User u, final
957957
}
958958
}
959959

960+
protected void pedigreeIssues(final Container c, User u, final StringBuilder msg)
961+
{
962+
TableSelector ts = new TableSelector(getStudySchema(c, u).getTable("parentsYoungerThanOffspring"), Collections.singleton(getStudy(c).getSubjectColumnName()));
963+
long count = ts.getRowCount();
964+
if (count > 0)
965+
{
966+
msg.append("<b>WARNING: There are " + count + " parentage records where the parent is younger than the offspring.</b><br>\n");
967+
msg.append("<p><a href='" + getExecuteQueryUrl(c, "study", "parentsYoungerThanOffspring", null) + "'>Click here to view them</a><br>\n\n");
968+
msg.append("<hr>\n\n");
969+
}
970+
971+
ts = new TableSelector(getStudySchema(c, u).getTable("parentsWrongGenderOrSpecies"), Collections.singleton(getStudy(c).getSubjectColumnName()));
972+
count = ts.getRowCount();
973+
if (count > 0)
974+
{
975+
msg.append("<b>WARNING: There are " + count + " parentage records listed with the wrong gender or species.</b><br>\n");
976+
msg.append("<p><a href='" + getExecuteQueryUrl(c, "study", "parentsWrongGenderOrSpecies", null) + "'>Click here to view them</a><br>\n\n");
977+
msg.append("<hr>\n\n");
978+
}
979+
}
980+
960981
protected void incompleteBirthRecords(final Container c, User u, final StringBuilder msg)
961982
{
962983
SimpleFilter filter = new SimpleFilter(new SimpleFilter.OrClause(

onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyMgmtNotification.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public String getMessageBodyHTML(Container c, User u)
8282
offspringWithMother(c, u, msg, 250);
8383
offspringWithMother(c, u, msg, 365);
8484
incompleteBirthRecords(c, u, msg);
85+
pedigreeIssues(c, u, msg);
8586

8687
//only send if there are alerts
8788
if (msg.length() > 0)

0 commit comments

Comments
 (0)