Skip to content

Instantly share code, notes, and snippets.

@ebridges
Last active December 12, 2023 14:47
Show Gist options
  • Save ebridges/17e63e89a500343926c0d3727567ff9e to your computer and use it in GitHub Desktop.
Save ebridges/17e63e89a500343926c0d3727567ff9e to your computer and use it in GitHub Desktop.
Generates cohort test cases
venv
cohort-cases

README

Setup

python3 -m venv venv
source venv/bin/activate
pip install PyYAML

Running a Single Chonky From CLI

Command Example

java \
    -Dnamespace=perf \
    -Dcluster=dev0-pinniped \
    -Dkube.config=.kube/config \
    -Ddatabase.username=root \
    -Ddatabase.password=aep  \
    -Demail=dta@aetion.com \
    -Dpassword="glAUtZTOoKe1THQWR5dg33tq6p8NjdPq" \
    -jar dispatcher-performance/target/dispatcher-performance-1.0.0-SNAPSHOT-jar-with-dependencies.jar \
    -c ../cohort-chonky/cohort-cases/cohort-regression-0001.yaml  \
    -r 1

Arguments

Property Definitions ("-D")

Arg Description
namespace
cluster dev0-pinniped
kube.config .kube/config
database.username root
database.password aep
email dta@aetion.com
password glAUtZTOoKe1THQWR5dg33tq6p8NjdPq

Program Flags

Arg Description
-c Filesystem path to chonky file
-r Number of times to run the test
#!/bin/env python
from itertools import product
from yaml import safe_load, dump
from copy import deepcopy
from pathlib import Path
case_dir = 'cohort-cases'
measure = {
'isPatientAttribute':'TRUE',
'name':'ENROLLMENT'
}
params = {
'useNewRelativeMeasure': ['TRUE', 'FALSE'],
'inclusion.newRelativeMeasure': [deepcopy(measure)],
'inclusion.measure': [deepcopy(measure)],
'enrollmentMeasure': [deepcopy(measure)],
'inclusion.priorUsePolicy': ['ALL', 'NEW'],
'inclusion.newWrtPolicy': ['BOTH', 'MINE'],
'inclusion.washoutDays': [180],
'inclusion.episodeType': ['NO_EPISODES', 'EPISODES_WITHOUT_GRACE', 'EPISODES_WITH_GRACE'],
'inclusion.expRiskDays': [14],
'inclusion.expGraceDays': [14],
'inclusion.useBooleansAsEvents': ['TRUE', 'FALSE'],
'useEntryDates': ['TRUE', 'FALSE'],
'usePriorEnrollmentDays': ['TRUE', 'FALSE'],
'priorEnrollmentDays': [0, 180],
'cohortEntryPolicy': ['FIRST', 'LAST', 'ALL'],
'applyExclusionPolicy': ['EVENT_BEFORE_EXCLUSIONS', 'EVENT_AFTER_EXCLUSIONS']
}
chonky_yaml = '''
---
version: 0.0.2
project:
name: Cohort Regression Tests
cohorts:
- name:
dataset: SYNPUF_SUBSET
cohortType: DESCRIPTIVE
entryParams:
'''
def main():
keys, values = zip(*params.items())
cases = [dict(zip(keys, v)) for v in product(*values)]
chonky_params = {}
cnt = 1
for case in cases:
chonky = safe_load(chonky_yaml)
chonky['cohorts'][0]['name'] = f'Cohort regression #{cnt}'
idx = str(cnt).zfill(4)
cnt = cnt + 1
for name, val in case.items():
if '.' in name:
k1, k2 = name.split('.')
if k1 not in chonky_params:
chonky_params[k1] = {}
chonky_params[k1][k2] = val
else:
chonky_params[name] = val
chonky['cohorts'][0]['entryParams'] = chonky_params
Path(case_dir).mkdir(parents=True, exist_ok=True)
with open(f'{case_dir}/cohort-regression-{idx}.yaml', 'w') as outfile:
dump(chonky, outfile, default_flow_style=False, sort_keys=False)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment