diff --git a/onprc_ehr/resources/queries/study/demographicsOffspringBSU.query.xml b/onprc_ehr/resources/queries/study/demographicsOffspringBSU.query.xml index 7404ad7f6..cb64f6f1d 100644 --- a/onprc_ehr/resources/queries/study/demographicsOffspringBSU.query.xml +++ b/onprc_ehr/resources/queries/study/demographicsOffspringBSU.query.xml @@ -43,6 +43,14 @@ Foster Dam + + Surrogate Dam + + study + animal + id + + Sire diff --git a/onprc_ehr/resources/queries/study/demographicsOffspringBSU.sql b/onprc_ehr/resources/queries/study/demographicsOffspringBSU.sql index 26a72138b..47fe27b8d 100644 --- a/onprc_ehr/resources/queries/study/demographicsOffspringBSU.sql +++ b/onprc_ehr/resources/queries/study/demographicsOffspringBSU.sql @@ -17,6 +17,7 @@ d2.status, d2.geneticdam, d2.observeddam, d2.fosterMom, +d2.surrogateMom, d2.sire, d2.sireType, d.qcstate @@ -25,7 +26,7 @@ FROM study.Demographics d INNER JOIN study.demographicsParentsBSU d2 - ON ((d2.sire = d.id OR d2.geneticdam = d.id OR d2.fostermom = d.id OR d2.observeddam = d.id) AND d.id != d2.id) + ON ((d2.sire = d.id OR d2.geneticdam = d.id OR d2.fosterMom = d.id OR d2.observeddam = d.id) AND d.id != d2.id) diff --git a/onprc_ehr/resources/queries/study/demographicsOffspringBSU/.qview.xml b/onprc_ehr/resources/queries/study/demographicsOffspringBSU/.qview.xml index 4a4679a82..fd9958bee 100644 --- a/onprc_ehr/resources/queries/study/demographicsOffspringBSU/.qview.xml +++ b/onprc_ehr/resources/queries/study/demographicsOffspringBSU/.qview.xml @@ -15,6 +15,7 @@ + diff --git a/onprc_ehr/resources/queries/study/demographicsParents/.qview.xml b/onprc_ehr/resources/queries/study/demographicsParents/.qview.xml index 2ab5905b4..01e76b9af 100644 --- a/onprc_ehr/resources/queries/study/demographicsParents/.qview.xml +++ b/onprc_ehr/resources/queries/study/demographicsParents/.qview.xml @@ -6,6 +6,7 @@ + diff --git a/onprc_ehr/resources/queries/study/demographicsParentsBSU.query.xml b/onprc_ehr/resources/queries/study/demographicsParentsBSU.query.xml index 5790dc400..e947589e1 100644 --- a/onprc_ehr/resources/queries/study/demographicsParentsBSU.query.xml +++ b/onprc_ehr/resources/queries/study/demographicsParentsBSU.query.xml @@ -48,6 +48,14 @@ id + + Surrogate Dam + + study + animal + id + + Number of Parents Known diff --git a/onprc_ehr/resources/queries/study/demographicsParentsBSU.sql b/onprc_ehr/resources/queries/study/demographicsParentsBSU.sql index 76f64855f..66657396f 100644 --- a/onprc_ehr/resources/queries/study/demographicsParentsBSU.sql +++ b/onprc_ehr/resources/queries/study/demographicsParentsBSU.sql @@ -39,12 +39,23 @@ SELECT ELSE null END as sireType, - p3.parent as fosterMom, - p3.method as fosterType, - (CASE WHEN p3.parent IS NOT NULL THEN 1 ELSE 0 END + - CASE WHEN coalesce(p2.parent, b.dam) IS NOT NULL THEN 1 ELSE 0 END + - CASE WHEN coalesce(p1.parent, b.sire) IS NOT NULL THEN 1 ELSE 0 END) as numParents + coalesce(p3.parent, '') as fosterMom, + CASE + WHEN p3.parent IS NOT NULL THEN p3.method + ELSE null + END as fosterType, + + coalesce(p4.parent, '') as surrogateMom, + CASE + WHEN p4.parent IS NOT NULL THEN p4.method + ELSE null + END as surrogateType, + + (CASE WHEN p4.parent IS NOT NULL THEN 1 ELSE 0 END + + CASE WHEN p3.parent IS NOT NULL THEN 1 ELSE 0 END + + CASE WHEN coalesce(p2.parent, b.dam) IS NOT NULL THEN 1 ELSE 0 END + + CASE WHEN coalesce(p1.parent, b.sire) IS NOT NULL THEN 1 ELSE 0 END) as numParents FROM study.demographics d @@ -68,5 +79,12 @@ LEFT JOIN ( WHERE p3.relationship = 'Foster Dam' AND p3.enddate IS NULL GROUP BY p3.Id ) p3 ON (d.Id = p3.id) + +LEFT JOIN ( + select p4.id, min(p4.method) as method, max(p4.parent) as parent + FROM study.parentage p4 + WHERE p4.relationship = 'Surrogate Dam' AND p4.enddate IS NULL + GROUP BY p4.Id +) p4 ON (d.Id = p4.id) LEFT JOIN study.birth b ON (b.id = d.id)