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
8 changes: 1 addition & 7 deletions onprc_ehr/resources/queries/study/birth.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@
</url>
</column>
<column columnName="dam">
<!--<nullable>false</nullable>-->
<columnTitle>Dam</columnTitle>
<!--<fk>-->
<!--<fkDbSchema>study</fkDbSchema>-->
<!--<fkTable>animal</fkTable>-->
<!--<fkColumnName>id</fkColumnName>-->
<!--</fk>-->
<columnTitle>Birth Record Dam</columnTitle>
<url>/ehr/participantView.view?participantId=${dam}</url>
<isMvEnabled>true</isMvEnabled>
</column>
Expand Down
19 changes: 19 additions & 0 deletions onprc_ehr/resources/queries/study/demographicsParents.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
<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="fostertype">
<columnTitle>Foster Dam Type</columnTitle>
</column>
<column columnName="geneticdam">
<columnTitle>Genetic Dam</columnTitle>
<fk>
Expand All @@ -39,9 +50,17 @@
<fkColumnName>id</fkColumnName>
</fk>
</column>
<column columnName="geneticdamtype">
<columnTitle>Genetic Dam Type</columnTitle>
</column>
<column columnName="numParents">
<columnTitle>Number of Parents Known</columnTitle>
</column>

<column columnName="observeddam">
<columnTitle>Observed Dam</columnTitle>
</column>

</columns>
</table>
</tables>
Expand Down
31 changes: 25 additions & 6 deletions onprc_ehr/resources/queries/study/demographicsParents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
<column name="damType"/>
<column name="sire"/>
<column name="sireType"/>
<column name="geneticdam"/>
<column name="geneticdamtype"/>
<column name="fostermom"/>
<column name="surrogateMom"/>
<column name="fosterType"/>
<column name="surrogateMom"/>
<column name="surrogateType"/>
<column name="observeddam"/>
<column name="numParents"/>
</columns>
<sorts>
Expand Down