diff --git a/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.query.xml b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.query.xml new file mode 100644 index 000000000..7c2766652 --- /dev/null +++ b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.query.xml @@ -0,0 +1,28 @@ + + + + + Parentage Records With Mismatched Gender or Species + lsid + /ehr/manageRecord.view?schemaName=study&queryName=${queryName}&keyField=lsid&key=${lsid}&update=1 + + + + + + Parent Gender + + + Parent Species + + + true + + + true + + +
+
+
+
diff --git a/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.sql b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.sql new file mode 100644 index 000000000..66420ef13 --- /dev/null +++ b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.sql @@ -0,0 +1,59 @@ +SELECT + p.Id, + p.date, + p.Id.demographics.species, + p.relationship, + p.parent, + p.parent.demographics.gender as parentGender, + p.parent.demographics.species as parentSpecies, + p.lsid, + 'Parentage' as queryName +FROM study.parentage p + +WHERE p.qcstate.publicdata = true AND ( + -- Gender: + (p.parent.demographics.gender.origgender IS NOT NULL AND p.relationship = 'Sire' AND p.parent.demographics.gender.origgender != 'm') OR + (p.parent.demographics.gender.origgender IS NOT NULL AND p.relationship = 'Dam' AND p.parent.demographics.gender.origgender != 'f') OR + (p.parent.demographics.gender.origgender IS NOT NULL AND p.relationship = 'Foster Dam' AND p.parent.demographics.gender.origgender != 'f') OR + + -- Species + (p.Id.demographics.species IS NOT NULL AND p.parent.demographics.species IS NOT NULL AND p.Id.demographics.species != p.parent.demographics.species) +) + +UNION ALL + +SELECT + p.Id, + p.date, + p.Id.demographics.species, + 'dam' as relationship, + p.dam as parent, + d.gender as parentGender, + d.species as parentSpecies, + p.lsid, + 'Birth' as queryName +FROM study.birth p +JOIN study.demographics d on (p.dam = d.Id) +WHERE p.qcstate.publicdata = true AND ( + (d.gender.origgender IS NOT NULL AND d.gender.origgender != 'f') OR + (p.Id.demographics.species IS NOT NULL AND d.species IS NOT NULL AND p.Id.demographics.species != d.species) +) AND p.date >= '2000-01-01' + +UNION ALL + +SELECT + p.Id, + p.date, + p.Id.demographics.species, + 'sire' as relationship, + p.sire as parent, + d.gender as parentGender, + d.species as parentSpecies, + p.lsid, + 'Birth' as queryName +FROM study.birth p +JOIN study.demographics d on (p.sire = d.Id) +WHERE p.qcstate.publicdata = true AND ( + (d.gender.origgender IS NOT NULL AND d.gender.origgender != 'm') OR + (p.Id.demographics.species IS NOT NULL AND d.species IS NOT NULL AND p.Id.demographics.species != d.species) +) AND p.date >= '2000-01-01' diff --git a/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.query.xml b/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.query.xml new file mode 100644 index 000000000..5dfc5a114 --- /dev/null +++ b/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.query.xml @@ -0,0 +1,25 @@ + + + + + Parentage Records With Parents Younger Than Offspring + lsid + /ehr/manageRecord.view?schemaName=study&queryName=${queryName}&keyField=lsid&key=${lsid}&update=1 + + + + + + Parent Birth + + + true + + + true + + +
+
+
+
diff --git a/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.sql b/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.sql new file mode 100644 index 000000000..fda5f5ee2 --- /dev/null +++ b/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.sql @@ -0,0 +1,50 @@ +SELECT + p.Id, + p.parent, + p.relationship, + p.method, + p.Id.demographics.birth, + p.parent.demographics.birth as parentBirth, + p.lsid, + 'Parentage' as queryName + +FROM study.parentage p +WHERE + p.qcstate.publicdata = true AND + (p.Id.demographics.birth IS NOT NULL AND p.parent.demographics.birth IS NOT NULL AND p.Id.demographics.birth <= p.parent.demographics.birth) + +UNION ALL + +SELECT + p.Id, + p.dam as parent, + 'Dam' as relationship, + 'Observed' as method, + p.Id.demographics.birth, + d.birth as parentBirth, + p.lsid, + 'Birth' as queryName + +FROM study.birth p +JOIN study.demographics d on (p.dam = d.Id) +WHERE + p.qcstate.publicdata = true AND + (p.Id.demographics.birth IS NOT NULL AND d.birth IS NOT NULL AND p.Id.demographics.birth <= d.birth) + +UNION ALL + +SELECT + p.Id, + p.sire as parent, + 'Sire' as relationship, + 'Observed' as method, + p.Id.demographics.birth, + d.birth as parentBirth, + p.lsid, + 'Birth' as queryName + +FROM study.birth p +JOIN study.demographics d on (p.sire = d.Id) +WHERE + p.qcstate.publicdata = true AND + (p.Id.demographics.birth IS NOT NULL AND d.birth IS NOT NULL AND p.Id.demographics.birth <= d.birth) diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java index ae99c98e9..36e1636f8 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyAlertsNotification.java @@ -773,6 +773,27 @@ protected void birthRecordsWithoutDemographics(final Container c, User u, final } } + protected void pedigreeIssues(final Container c, User u, final StringBuilder msg) + { + TableSelector ts = new TableSelector(getStudySchema(c, u).getTable("parentage"), Collections.singleton(getStudy(c).getSubjectColumnName())); + long count = ts.getRowCount(); + if (count > 0) + { + msg.append("WARNING: There are " + count + " parentage records that are younger than their offspring.
\n"); + msg.append("

Click here to view them
\n\n"); + msg.append("


\n\n"); + } + + ts = new TableSelector(getStudySchema(c, u).getTable("parentsWrongGenderOrSpecies"), Collections.singleton(getStudy(c).getSubjectColumnName())); + count = ts.getRowCount(); + if (count > 0) + { + msg.append("WARNING: There are " + count + " parentage records listed with the wrong gender or species.
\n"); + msg.append("

Click here to view them
\n\n"); + msg.append("


\n\n"); + } + } + protected void incompleteBirthRecords(final Container c, User u, final StringBuilder msg) { SimpleFilter filter = new SimpleFilter(new SimpleFilter.OrClause( diff --git a/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyMgmtNotification.java b/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyMgmtNotification.java index af3cf80ba..c00394a6a 100644 --- a/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyMgmtNotification.java +++ b/onprc_ehr/src/org/labkey/onprc_ehr/notification/ColonyMgmtNotification.java @@ -82,6 +82,7 @@ public String getMessageBodyHTML(Container c, User u) offspringWithMother(c, u, msg, 250); offspringWithMother(c, u, msg, 365); incompleteBirthRecords(c, u, msg); + pedigreeIssues(c, u, msg); //only send if there are alerts if (msg.length() > 0)