diff --git a/onprc_ehr/resources/queries/study/birth.query.xml b/onprc_ehr/resources/queries/study/birth.query.xml
index 727fb0953..478366b3c 100644
--- a/onprc_ehr/resources/queries/study/birth.query.xml
+++ b/onprc_ehr/resources/queries/study/birth.query.xml
@@ -51,13 +51,7 @@
-
- Dam
-
-
-
-
-
+ Birth Record Dam
/ehr/participantView.view?participantId=${dam}
true
diff --git a/onprc_ehr/resources/queries/study/demographicsParents.query.xml b/onprc_ehr/resources/queries/study/demographicsParents.query.xml
index e3ef57f38..57a19f315 100644
--- a/onprc_ehr/resources/queries/study/demographicsParents.query.xml
+++ b/onprc_ehr/resources/queries/study/demographicsParents.query.xml
@@ -31,6 +31,17 @@
id
+
+ Surrogate Dam
+
+ study
+ animal
+ id
+
+
+
+ Foster Dam Type
+
Genetic Dam
@@ -39,9 +50,17 @@
id
+
+ Genetic Dam Type
+
Number of Parents Known
+
+
+ Observed Dam
+
+
diff --git a/onprc_ehr/resources/queries/study/demographicsParents.sql b/onprc_ehr/resources/queries/study/demographicsParents.sql
index 91f7029d2..f282b8bd2 100644
--- a/onprc_ehr/resources/queries/study/demographicsParents.sql
+++ b/onprc_ehr/resources/queries/study/demographicsParents.sql
@@ -16,7 +16,7 @@
SELECT
d.id,
- coalesce(p2.parent, b.dam) as dam,
+ coalesce(p2.parent, b.dam, p5.parent) as dam,
CASE
WHEN p2.parent IS NOT NULL THEN p2.method
WHEN b.dam IS NOT NULL THEN 'Observed'
@@ -29,26 +29,31 @@ SELECT
WHEN b.sire IS NOT NULL THEN 'Observed'
ELSE null
END as sireType,
- p3.parent as fosterMom,
- p3.method as fosterType,
+ p2.parent as geneticdam,
+ p2.method as geneticdamtype,
+ p3.parent as fostermom,
+ p3.method as fostertype,
+ p4.parent as surrogatedam,
+ coalesce(b.dam,p5.parent) as observeddam,
(CASE WHEN p3.parent IS NOT NULL THEN 1 ELSE 0 END +
+ CASE WHEN p4.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,
- greatest(d.modified, p1.modified, p2.modified, p3.modified, b.modified) as modified
+ greatest(d.modified, p1.modified, p2.modified, p3.modified, p4.modified,p5.modified, b.modified) as modified
FROM study.demographics d
LEFT JOIN (
select p1.id, min(p1.method) as method, max(p1.parent) as parent, max(p1.modified) as modified
FROM study.parentage p1
- WHERE (p1.method = 'Genetic' OR p1.method = 'Provisional Genetic') AND p1.relationship = 'Sire' AND p1.enddate IS NULL
+ WHERE p1.method in ('Genetic','Provisional Genetic') AND p1.relationship = 'Sire' AND p1.enddate IS NULL
GROUP BY p1.Id
) p1 ON (d.Id = p1.id)
LEFT JOIN (
select p2.id, min(p2.method) as method, max(p2.parent) as parent, max(p2.modified) as modified
FROM study.parentage p2
- WHERE (p2.method = 'Genetic' OR p2.method = 'Provisional Genetic') AND p2.relationship = 'Dam' AND p2.enddate IS NULL
+ WHERE p2.method in ('Genetic','Provisional Genetic') AND p2.relationship = 'Dam' AND p2.enddate IS NULL
GROUP BY p2.Id
) p2 ON (d.Id = p2.id)
@@ -58,5 +63,19 @@ 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, max(p4.modified) as modified
+ 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 (
+ select p5.id, min(p5.method) as method, max(p5.parent) as parent, max(p5.modified) as modified
+ FROM study.parentage p5
+ WHERE p5.relationship = 'Observed' AND p5.enddate IS NULL
+ GROUP BY p5.Id
+) p5 ON (d.Id = p5.id)
+
LEFT JOIN study.birth b ON (b.id = d.id)
diff --git a/onprc_ehr/resources/queries/study/demographicsParents/.qview.xml b/onprc_ehr/resources/queries/study/demographicsParents/.qview.xml
index 01e76b9af..c55f9e699 100644
--- a/onprc_ehr/resources/queries/study/demographicsParents/.qview.xml
+++ b/onprc_ehr/resources/queries/study/demographicsParents/.qview.xml
@@ -5,9 +5,13 @@
+
+
-
+
+
+