From 3c4d07e53a653337ce8a0b3f7b80161ad11dd42b Mon Sep 17 00:00:00 2001 From: labkey-martyp Date: Fri, 17 Feb 2023 05:42:50 -0800 Subject: [PATCH 1/3] Added animal record parents --- .../study/demographicsParents.query.xml | 31 +++++++++++++++++++ .../queries/study/demographicsParents.sql | 28 +++++++++++++++++ .../ehr/table/DefaultEHRCustomizer.java | 7 +++++ 3 files changed, 66 insertions(+) create mode 100644 ehr/resources/queries/study/demographicsParents.query.xml create mode 100644 ehr/resources/queries/study/demographicsParents.sql diff --git a/ehr/resources/queries/study/demographicsParents.query.xml b/ehr/resources/queries/study/demographicsParents.query.xml new file mode 100644 index 000000000..a151cf172 --- /dev/null +++ b/ehr/resources/queries/study/demographicsParents.query.xml @@ -0,0 +1,31 @@ + + + + + Parents + + + true + + + + study + animal + id + + + + + study + animal + id + + + + Number of Parents Known + + +
+
+
+
diff --git a/ehr/resources/queries/study/demographicsParents.sql b/ehr/resources/queries/study/demographicsParents.sql new file mode 100644 index 000000000..606693f4a --- /dev/null +++ b/ehr/resources/queries/study/demographicsParents.sql @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2015 LabKey Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +SELECT + d.id, + d.dam as dam, + 'Observed' as damType, + d.sire as sire, + 'Observed' as sireType, + CASE + WHEN d.dam IS NOT NULL AND d.sire IS NOT NULL THEN 2 + WHEN d.dam IS NOT NULL OR d.sire IS NOT NULL THEN 1 + ELSE 0 + END as numParents +FROM study.demographics d + diff --git a/ehr/src/org/labkey/ehr/table/DefaultEHRCustomizer.java b/ehr/src/org/labkey/ehr/table/DefaultEHRCustomizer.java index 22f5134b1..4cbf2a377 100644 --- a/ehr/src/org/labkey/ehr/table/DefaultEHRCustomizer.java +++ b/ehr/src/org/labkey/ehr/table/DefaultEHRCustomizer.java @@ -1124,6 +1124,13 @@ private void customizeAnimalTable(AbstractTableInfo ds) return; } + if (ds.getColumn("parents") == null) + { + var col = getWrappedCol(us, ds, "Parents", "demographicsParents", "Id", "Id"); + col.setLabel("Parents"); + ds.addColumn(col); + } + if (ds.getColumn("activeAnimalGroups") == null && -1 != StudyService.get().getDatasetIdByName( ds.getUserSchema().getContainer(), "animal_group_members")) { var col21 = getWrappedIdCol(us, ds, "activeAnimalGroups", "demographicsActiveAnimalGroups"); From 707cb21ff7cd367c7696037e2667735f245c136e Mon Sep 17 00:00:00 2001 From: labkey-martyp Date: Fri, 17 Feb 2023 12:23:47 -0800 Subject: [PATCH 2/3] Add supplemental pedigree --- .../queries/study/demographicsParents.sql | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ehr/resources/queries/study/demographicsParents.sql b/ehr/resources/queries/study/demographicsParents.sql index 606693f4a..a6d626354 100644 --- a/ehr/resources/queries/study/demographicsParents.sql +++ b/ehr/resources/queries/study/demographicsParents.sql @@ -14,10 +14,10 @@ * limitations under the License. */ SELECT - d.id, - d.dam as dam, + d.Id, + d.dam, 'Observed' as damType, - d.sire as sire, + d.sire, 'Observed' as sireType, CASE WHEN d.dam IS NOT NULL AND d.sire IS NOT NULL THEN 2 @@ -26,3 +26,18 @@ SELECT END as numParents FROM study.demographics d +UNION + +SELECT + s.Id, + s.dam, + 'Observed' as damType, + s.sire, + 'Observed' as sireType, + CASE + WHEN s.dam IS NOT NULL AND s.sire IS NOT NULL THEN 2 + WHEN s.dam IS NOT NULL OR s.sire IS NOT NULL THEN 1 + ELSE 0 + END as numParents +FROM ehr.supplemental_pedigree s + From 047119d77f8566a9632adfc77cab112e0deb2540 Mon Sep 17 00:00:00 2001 From: labkey-martyp Date: Fri, 17 Feb 2023 13:23:40 -0800 Subject: [PATCH 3/3] UNION ALL --- ehr/resources/queries/study/demographicsParents.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ehr/resources/queries/study/demographicsParents.sql b/ehr/resources/queries/study/demographicsParents.sql index a6d626354..a730c739e 100644 --- a/ehr/resources/queries/study/demographicsParents.sql +++ b/ehr/resources/queries/study/demographicsParents.sql @@ -26,7 +26,7 @@ SELECT END as numParents FROM study.demographics d -UNION +UNION ALL SELECT s.Id,