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
20 changes: 18 additions & 2 deletions onprc_ehr/resources/queries/study/demographicsParents.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<isHidden>true</isHidden>
</column>
<column columnName="dam">
<columnTitle>Dam</columnTitle>
<columnTitle>Genetic Dam</columnTitle>
<fk>
<fkDbSchema>study</fkDbSchema>
<fkTable>animal</fkTable>
Expand All @@ -31,8 +31,16 @@
<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>
<columnTitle>Genetic Dam Type</columnTitle>
<fk>
<fkDbSchema>study</fkDbSchema>
<fkTable>animal</fkTable>
Expand All @@ -42,6 +50,14 @@
<column columnName="numParents">
<columnTitle>Number of Parents Known</columnTitle>
</column>

<column columnName="birthdam">
<columnTitle>Birth Record Dam</columnTitle>
</column>

<column columnName="surrogatedam">
<columnTitle>Surrogate Dam</columnTitle>
</column>
</columns>
</table>
</tables>
Expand Down
24 changes: 17 additions & 7 deletions onprc_ehr/resources/queries/study/demographicsParents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

SELECT
d.id,
coalesce(p2.parent, b.dam) as dam,
p2.parent as geneticdam,
CASE
WHEN p2.parent IS NOT NULL THEN p2.method
WHEN b.dam IS NOT NULL THEN 'Observed'
ELSE null
END as damType,
ELSE null
END as geneticdamType,

coalesce(p1.parent, b.sire) as sire,
CASE
Expand All @@ -31,24 +30,28 @@ SELECT
END as sireType,
p3.parent as fosterMom,
p3.method as fosterType,
p4.parent as SurrogateDam,
p4.method as SurrogateType,
b.dam as birthdam,

(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)