Skip to content
Open
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 @@ -31,6 +31,14 @@
<fkColumnName>id</fkColumnName>
</fk>
</column>
<column columnName="surrogatedam">
<columnTitle>Surrogate Dam</columnTitle>
<fk>
<fkDbSchema>study</fkDbSchema>
<fkTable>animal</fkTable>
<fkColumnName>id</fkColumnName>
</fk>
</column>
<column columnName="geneticdam">
<columnTitle>Genetic Dam</columnTitle>
<fk>
Expand Down
16 changes: 13 additions & 3 deletions onprc_ehr/resources/queries/study/demographicsParents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,27 @@ SELECT
END as sireType,
p3.parent as fosterMom,
p3.method as fosterType,
p4.parent as SurrogateDam,
p4.method as SurrogateType,

(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, 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','Observed') 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','Observed') AND p2.relationship = 'Dam' AND p2.enddate IS NULL
GROUP BY p2.Id
) p2 ON (d.Id = p2.id)

Expand All @@ -58,5 +61,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, 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 study.birth b ON (b.id = d.id)

Loading