|
#!/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() |