Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PHS Data Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Josef Hardi
PHS Data Library
Commits
4e2788b4
Commit
4e2788b4
authored
5 years ago
by
Josef Hardi
Browse files
Options
Downloads
Patches
Plain Diff
feature: adding observation_period table
parent
7ffa6726
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
phs/data/optum.py
+25
-10
25 additions, 10 deletions
phs/data/optum.py
with
25 additions
and
10 deletions
phs/data/optum.py
+
25
−
10
View file @
4e2788b4
...
...
@@ -109,6 +109,20 @@ class Optum:
}
}
_OBSERVATION_PERIOD
=
"""
observation_period AS (
SELECT DISTINCT
t0.Patid AS person_id,
t0.Eligeff AS observation_period_start_date,
t0.Eligend AS observation_period_end_date,
CAST(CASE
WHEN (STRPOS(t0.Zipcode_5,
'
_
'
) = 0) THEN t0.Zipcode_5
ELSE SUBSTR(t0.Zipcode_5, 1, STRPOS(t0.Zipcode_5,
'
_
'
) - 1)
END AS INT64) AS zip
FROM
{person_table} AS t0
)
"""
_PERSON
=
"""
person AS (
SELECT *
...
...
@@ -117,8 +131,6 @@ class Optum:
t0.Patid AS person_id,
t0.Gdr_Cd AS gender_source_value,
t0.Yrdob AS year_of_birth,
t0.Eligeff AS observation_period_start_date,
t0.Eligend AS observation_period_end_date,
CAST(CASE
WHEN (STRPOS(t0.Zipcode_5,
'
_
'
) = 0) THEN t0.Zipcode_5
ELSE SUBSTR(t0.Zipcode_5, 1, STRPOS(t0.Zipcode_5,
'
_
'
) - 1)
...
...
@@ -159,9 +171,9 @@ class Optum:
p.observation_period_end_date
FROM (
SELECT op.person_id, op.zip, op.observation_period_start_date, op.observation_period_end_date, e.condition_start_date
FROM
person
AS op
FROM
observation_period
AS op
JOIN (
SELECT p.person_id, c.condition_start_date
SELECT p.person_id,
p.zip,
c.condition_start_date
FROM person AS p
JOIN (
SELECT *, row_number() OVER (PARTITION BY person_id ORDER BY condition_start_date) AS ordinal
...
...
@@ -171,7 +183,7 @@ class Optum:
ON p.person_id = c.person_id
{event_occurrence_filters}
) AS e
ON op.person_id = e.person_id
ON op.person_id = e.person_id
AND op.zip = e.zip
AND e.condition_start_date >= op.observation_period_start_date
AND e.condition_start_date <= op.observation_period_end_date
{continuous_observation_filters}
...
...
@@ -223,22 +235,23 @@ class Optum:
SELECT p.person_id, p.zip
FROM qualifying_event AS p
JOIN (
SELECT
o
p.person_id,
o
p.zip, c.condition_start_date
FROM person AS
o
p
SELECT p
e
.person_id, p
e
.zip, c.condition_start_date
FROM person AS p
e
JOIN (
SELECT *
FROM condition_occurrence
WHERE condition_source_value IN ({event_valueset})
) AS c
ON
o
p.person_id = c.person_id
ON p
e
.person_id = c.person_id
{event_occurrence_filters}
) AS e
ON p.person_id = e.person_id
ON p.person_id = e.person_id
AND p.zip = e.zip
AND e.condition_start_date >= p.observation_period_start_date
AND e.condition_start_date <= p.observation_period_end_date
{event_occurrence_before_index_date}
{event_occurrence_after_index_date}
)
"""
_INCLUSION_EVENT
=
"""
inclusion_event AS (
...
...
@@ -258,7 +271,7 @@ class Optum:
# SQL template for getting a cohort population
_GET_COHORT_POPULATIONS
=
"""
WITH {person}, {condition_occurrence}, {qualifying_event}, {inclusion_criteria}, {inclusion_event},
WITH
{observation_period},
{person}, {condition_occurrence}, {qualifying_event}, {inclusion_criteria}, {inclusion_event},
cohort AS (
SELECT mg.person_id,
mg.zip,
...
...
@@ -503,6 +516,8 @@ class Optum:
query
=
textwrap
.
dedent
(
self
.
_GET_COHORT_POPULATIONS
.
format
(
observation_period
=
self
.
_OBSERVATION_PERIOD
.
format
(
person_table
=
self
.
_member_table_id
),
person
=
self
.
_PERSON
.
format
(
person_table
=
self
.
_member_table_id
,
zipcode_valueset
=
"
,
"
.
join
(
str
(
z
)
for
z
in
zips
)),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment