Skip to content

Commit

Permalink
Augment kinship calculation to check modification date and only run a…
Browse files Browse the repository at this point in the history
…s-needed
  • Loading branch information
bbimber committed Sep 16, 2024
1 parent 5a5de09 commit cb8eaef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions onprc_ehr/resources/queries/study/demographicsParents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ SELECT

(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

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
FROM study.demographics d

LEFT JOIN (
select p1.id, min(p1.method) as method, max(p1.parent) as parent
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
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
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
GROUP BY p2.Id
) p2 ON (d.Id = p2.id)

LEFT JOIN (
select p3.id, min(p3.method) as method, max(p3.parent) as parent
select p3.id, min(p3.method) as method, max(p3.parent) as parent, max(p3.modified) as modified
FROM study.parentage p3
WHERE p3.relationship = 'Foster Dam' AND p3.enddate IS NULL
GROUP BY p3.Id
Expand Down
3 changes: 2 additions & 1 deletion onprc_ehr/resources/queries/study/pedigree.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ AS status,
d.id.demographics.calculated_status as status_code,
d.id.demographics.species,
'' as Display,
'Demographics' as source
'Demographics' as source,
d.modified

FROM study.demographicsParents d
WHERE d.numParents > 0

0 comments on commit cb8eaef

Please sign in to comment.