From ff447e80ea5c0ebfa97f85c7f6644260a4004d8f Mon Sep 17 00:00:00 2001 From: bbimber Date: Wed, 1 Mar 2023 16:48:58 -0800 Subject: [PATCH 1/2] Add parentage validation queries --- .../parentsWrongGenderOrSpecies.query.xml | 25 +++++++++++++++++++ .../study/parentsWrongGenderOrSpecies.sql | 18 +++++++++++++ .../parentsYoungerThanOffspring.query.xml | 22 ++++++++++++++++ .../study/parentsYoungerThanOffspring.sql | 13 ++++++++++ .../ColonyAlertsNotification.java | 21 ++++++++++++++++ .../notification/ColonyMgmtNotification.java | 1 + 6 files changed, 100 insertions(+) create mode 100644 onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.query.xml create mode 100644 onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.sql create mode 100644 onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.query.xml create mode 100644 onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.sql 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..9e1b969ad --- /dev/null +++ b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.query.xml @@ -0,0 +1,25 @@ + + + + + Parentage Records With Mismatched Gender or Species + lsid + /ehr/manageRecord.view?schemaName=study&queryName=Parentage&keyField=lsid&key=${lsid}&update=1 + + + + + + Parent Gender + + + Parent Species + + + 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..7763d0715 --- /dev/null +++ b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.sql @@ -0,0 +1,18 @@ +SELECT + p.Id, + p.Id.demographics.species, + p.relationship, + p.parent, + p.parent.demographics.gender as parentGender, + p.parent.demographics.species as parentSpecies, + p.lsid +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 + + -- 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) +) \ No newline at end of file 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..fc580db8a --- /dev/null +++ b/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.query.xml @@ -0,0 +1,22 @@ + + + + + Parentage Records With Parents Younger Than Offspring + lsid + /ehr/manageRecord.view?schemaName=study&queryName=Parentage&keyField=lsid&key=${lsid}&update=1 + + + + + + Parent Birth + + + 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..1d3d8af1f --- /dev/null +++ b/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.sql @@ -0,0 +1,13 @@ +SELECT + p.Id, + p.parent, + p.relationship, + p.method, + p.Id.demographics.birth, + p.parent.demographics.birth as parentBirth, + p.lsid + +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) 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) From 89e7a26175a71bc601443ae3b091673dcbd96e88 Mon Sep 17 00:00:00 2001 From: bbimber Date: Thu, 9 Mar 2023 20:56:09 -0800 Subject: [PATCH 2/2] Updates to SQL queries --- .../parentsWrongGenderOrSpecies.query.xml | 5 ++- .../study/parentsWrongGenderOrSpecies.sql | 45 ++++++++++++++++++- .../parentsYoungerThanOffspring.query.xml | 5 ++- .../study/parentsYoungerThanOffspring.sql | 39 +++++++++++++++- 4 files changed, 89 insertions(+), 5 deletions(-) diff --git a/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.query.xml b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.query.xml index 9e1b969ad..7c2766652 100644 --- a/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.query.xml +++ b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.query.xml @@ -4,7 +4,7 @@ Parentage Records With Mismatched Gender or Specieslsid - /ehr/manageRecord.view?schemaName=study&queryName=Parentage&keyField=lsid&key=${lsid}&update=1 + /ehr/manageRecord.view?schemaName=study&queryName=${queryName}&keyField=lsid&key=${lsid}&update=1 @@ -18,6 +18,9 @@ true + + true +
diff --git a/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.sql b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.sql index 7763d0715..66420ef13 100644 --- a/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.sql +++ b/onprc_ehr/resources/queries/study/parentsWrongGenderOrSpecies.sql @@ -1,18 +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 + 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) -) \ No newline at end of file +) + +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 index fc580db8a..5dfc5a114 100644 --- a/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.query.xml +++ b/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.query.xml @@ -4,7 +4,7 @@ Parentage Records With Parents Younger Than Offspringlsid - /ehr/manageRecord.view?schemaName=study&queryName=Parentage&keyField=lsid&key=${lsid}&update=1 + /ehr/manageRecord.view?schemaName=study&queryName=${queryName}&keyField=lsid&key=${lsid}&update=1 @@ -15,6 +15,9 @@ true + + true +
diff --git a/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.sql b/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.sql index 1d3d8af1f..fda5f5ee2 100644 --- a/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.sql +++ b/onprc_ehr/resources/queries/study/parentsYoungerThanOffspring.sql @@ -5,9 +5,46 @@ SELECT p.method, p.Id.demographics.birth, p.parent.demographics.birth as parentBirth, - p.lsid + 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)