Skip to content
Snippets Groups Projects
Commit 4de83243 authored by Josef Hardi's avatar Josef Hardi
Browse files

fix(optum): use today's data if the index_date unspecified

parent 754f60bb
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
import os
import re
import textwrap
from datetime import date
from redivis import bigquery
class Optum:
......@@ -100,7 +101,7 @@ class Optum:
ELSE SUBSTR(t0.Zipcode_5, 1, STRPOS(t0.Zipcode_5, '_') - 1)
END AS INT64) AS zip
FROM
`Optum ZIP5 Member` AS t0
`23224` AS t0
)"""
_CONDITION_OCCURRENCE = """
......@@ -109,7 +110,7 @@ class Optum:
t0.Patid AS person_id,
t0.Clmid AS claim_id,
t0.Diag AS condition_source_value
FROM `Optum ZIP5 Medical Diagnosis` as t0
FROM `23212` as t0
WHERE t0.Icd_Flag = 9
)"""
......@@ -125,7 +126,7 @@ class Optum:
t0.Clmid AS claim_id,
t0.Fst_Dt AS claim_date
FROM
`Optum ZIP5 Medical Claims` AS t0
`23236` AS t0
) AS t1
)"""
......@@ -141,7 +142,7 @@ class Optum:
t0.zip in ({valueset})
)
SELECT *
FROM person within_zipcodes
FROM person_within_zipcodes
{filters}"""
# SQL template for getting a cohort population
......@@ -267,27 +268,24 @@ class Optum:
filter_str = filter_template.format(value_1=self._GENDERS[v]['value'])
filters['gender'] = filter_str
elif k == 'ageGroup':
if not index_date: raise ValueError("Constraining the patient age requires the 'index_date' argument")
filter_template = "EXTRACT(YEAR FROM DATE '{index_date}')-year_of_birth >= {value_1} AND EXTRACT(YEAR FROM DATE '{index_date}')-year_of_birth <= {value_2}"
filter_str = filter_template.format(
index_date=index_date,
index_date=index_date if index_date else date.today().strftime("%Y-%m-%d"),
value_1=self._AGE_GROUPS[v]['start'],
value_2=self._AGE_GROUPS[v]['end'])
filters['age'] = filter_str
elif k == 'ageRange':
if not re.match(r"[0-9]*-[0-9]*", v): raise ValueError("Unable to parse value range expression. Some valid examples: -22, or 16-22, or 22-")
if not index_date: raise ValueError("Constraining the patient age requires the 'index_date' argument")
filter_template = "EXTRACT(YEAR FROM DATE '{index_date}')-year_of_birth >= {value_1} AND EXTRACT(YEAR FROM DATE '{index_date}')-year_of_birth <= {value_2}"
filter_str = filter_template.format(
index_date=index_date,
index_date=index_date if index_date else date.today().strftime("%Y-%m-%d"),
value_1=int(v.split('-')[0]) if v.split('-')[0] != '' else 0,
value_2=int(v.split('-')[1]) if v.split('-')[1] != '' else 999)
filters['age'] = filter_str
elif k == 'ageAt':
if not index_date: raise ValueError("Constraining the patient age requires the 'index_date' argument")
filter_template = "EXTRACT(YEAR FROM DATE '{index_date}')-year_of_birth = {value_1}"
filter_str = filter_template.format(
index_date=index_date,
index_date=index_date if index_date else date.today().strftime("%Y-%m-%d"),
value_1=v)
filters['age'] = filter_str
filters_sql = "WHERE {conditions}".format(conditions="\n AND ".join(v for v in filters.values()))
......@@ -299,8 +297,8 @@ class Optum:
filters=filters_sql))
# Execute the query
print(query)
# return self.evaluate(query)
# print(query)
return self.evaluate(query)
def get_cohort(self, zips, entry_criteria, inclusion_criteria=None, exit_criteria=None):
......@@ -361,6 +359,6 @@ class Optum:
inclusion_criteria=inclusion_criteria_sql))
# Execute the query
print(query)
# return self.evaluate(query)
# print(query)
return self.evaluate(query)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment