Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
<column columnName="fosterMom">
<columnTitle>Foster Dam</columnTitle>
</column>
<column columnName="surrogateMom">
<columnTitle>Surrogate Dam</columnTitle>
<fk>
<fkDbSchema>study</fkDbSchema>
<fkTable>animal</fkTable>
<fkColumnName>id</fkColumnName>
</fk>
</column>

<column columnName="sire">
<columnTitle>Sire</columnTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ d2.status,
d2.geneticdam,
d2.observeddam,
d2.fosterMom,
d2.surrogateMom,
d2.sire,
d2.sireType,
d.qcstate
Expand All @@ -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)



Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<column name="geneticdam"/>
<column name="observeddam"/>
<column name="fosterMom"/>
<column name="surrogateMom"/>
<column name="sire"/>
<column name="sireType"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<column name="sire"/>
<column name="sireType"/>
<column name="fostermom"/>
<column name="surrogateMom"/>
<column name="fosterType"/>
<column name="numParents"/>
</columns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
<fkColumnName>id</fkColumnName>
</fk>
</column>
<column columnName="surrogateMom">
<columnTitle>Surrogate Dam</columnTitle>
<fk>
<fkDbSchema>study</fkDbSchema>
<fkTable>animal</fkTable>
<fkColumnName>id</fkColumnName>
</fk>
</column>

<column columnName="numParents">
<columnTitle>Number of Parents Known</columnTitle>
Expand Down
28 changes: 23 additions & 5 deletions onprc_ehr/resources/queries/study/demographicsParentsBSU.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)