|
1 |
| -import datetime, os |
2 |
| -import pandas as pd |
3 |
| - |
4 |
| -from phenex.phenotypes.categorical_phenotype import CategoricalPhenotype |
5 |
| -from phenex.codelists import LocalCSVCodelistFactory |
6 |
| -from phenex.filters.date_range_filter import DateRangeFilter |
7 |
| -from phenex.filters.relative_time_range_filter import RelativeTimeRangeFilter |
8 |
| - |
9 |
| -from phenex.test.phenotype_test_generator import PhenotypeTestGenerator |
10 |
| -from phenex.filters.value import * |
11 |
| - |
12 |
| - |
13 |
| -class CategoricalPhenotypeTestGenerator(PhenotypeTestGenerator): |
14 |
| - name_space = "cgpt" |
15 |
| - |
16 |
| - def define_input_tables(self): |
17 |
| - def add_flag(df, flag_name, flag_values): |
18 |
| - dfs = [] |
19 |
| - for flag in flag_values: |
20 |
| - _df = df.copy() |
21 |
| - _df[flag_name] = flag |
22 |
| - dfs.append(_df) |
23 |
| - return pd.concat(dfs) |
24 |
| - |
25 |
| - df = pd.DataFrame() |
26 |
| - df["PERSON_ID"] = ["p1"] |
27 |
| - df["CODE"] = ["c1"] |
28 |
| - df["CODE_TYPE"] = ["ICD10CM"] |
29 |
| - df = add_flag(df, "x", ["x1", "x2"]) |
30 |
| - df = add_flag(df, "y", ["y1", "y2"]) |
31 |
| - df = add_flag(df, "z", ["z1", "z2"]) |
32 |
| - df["PERSON_ID"] = [f"P{i}" for i in range(df.shape[0])] |
33 |
| - |
34 |
| - return [{"condition_occurrence": "input", "df": df, "column_types": {}}] |
35 |
| - |
36 |
| - def define_phenotype_tests(self): |
37 |
| - c1 = { |
38 |
| - "name": "single_flag", |
39 |
| - "persons": [f"P{i}" for i in range(4)], |
40 |
| - "phenotype": CategoricalPhenotype( |
41 |
| - name_space=self.name_space, |
42 |
| - domain="condition_occurrence", |
43 |
| - categorical_filter=CategoricalFilter( |
44 |
| - allowed_values=["z1"], columnname="z" |
45 |
| - ), |
46 |
| - ), |
47 |
| - } |
48 |
| - |
49 |
| - c2 = { |
50 |
| - "name": "two_categorical_filter_or", |
51 |
| - "persons": [f"P{i}" for i in range(4)] + [f"P{i}" for i in range(6, 8)], |
52 |
| - "phenotype": CategoricalPhenotype( |
53 |
| - name_space=self.name_space, |
54 |
| - domain="condition_occurrence", |
55 |
| - categorical_filter=CategoricalFilter( |
56 |
| - allowed_values=["z1"], columnname="z" |
57 |
| - ) |
58 |
| - | CategoricalFilter(allowed_values=["y2"], columnname="y"), |
59 |
| - ), |
60 |
| - } |
61 |
| - |
62 |
| - c3 = { |
63 |
| - "name": "two_categorical_filter_and", |
64 |
| - "persons": [f"P{i}" for i in range(2, 4)], |
65 |
| - "phenotype": CategoricalPhenotype( |
66 |
| - name_space=self.name_space, |
67 |
| - domain="condition_occurrence", |
68 |
| - categorical_filter=CategoricalFilter( |
69 |
| - allowed_values=["z1"], columnname="z" |
70 |
| - ) |
71 |
| - & CategoricalFilter(allowed_values=["y2"], columnname="y"), |
72 |
| - ), |
73 |
| - } |
74 |
| - |
75 |
| - test_infos = [c1, c2, c3] |
76 |
| - for test_info in test_infos: |
77 |
| - test_info["refactor"] = True # TODO remove once refactored |
78 |
| - test_info["phenotype"].name_phenotype = test_info["name"] |
79 |
| - |
80 |
| - return test_infos |
81 |
| - |
82 |
| - |
83 |
| -def test_categorical_phenotype(): |
84 |
| - spg = CategoricalPhenotypeTestGenerator() |
85 |
| - spg.run_tests() |
86 |
| - |
87 |
| - |
88 |
| -if __name__ == "__main__": |
89 |
| - test_categorical_phenotype() |
| 1 | +# import datetime, os |
| 2 | +# import pandas as pd |
| 3 | + |
| 4 | +# from phenex.phenotypes.categorical_phenotype import CategoricalPhenotype |
| 5 | + |
| 6 | +# from phenex.test.phenotype_test_generator import PhenotypeTestGenerator |
| 7 | +# from phenex.filters.value import * |
| 8 | + |
| 9 | + |
| 10 | +# class CategoricalPhenotypeTestGenerator(PhenotypeTestGenerator): |
| 11 | +# name_space = "cgpt" |
| 12 | + |
| 13 | +# def define_input_tables(self): |
| 14 | +# def add_flag(df, flag_name, flag_values): |
| 15 | +# dfs = [] |
| 16 | +# for flag in flag_values: |
| 17 | +# _df = df.copy() |
| 18 | +# _df[flag_name] = flag |
| 19 | +# dfs.append(_df) |
| 20 | +# return pd.concat(dfs) |
| 21 | + |
| 22 | +# df = pd.DataFrame() |
| 23 | +# df["PERSON_ID"] = ["p1"] |
| 24 | +# df["CODE"] = ["c1"] |
| 25 | +# df["CODE_TYPE"] = ["ICD10CM"] |
| 26 | +# df = add_flag(df, "x", ["x1", "x2"]) |
| 27 | +# df = add_flag(df, "y", ["y1", "y2"]) |
| 28 | +# df = add_flag(df, "z", ["z1", "z2"]) |
| 29 | +# df["PERSON_ID"] = [f"P{i}" for i in range(df.shape[0])] |
| 30 | + |
| 31 | +# return [{"condition_occurrence": "input", "df": df, "column_types": {}}] |
| 32 | + |
| 33 | +# def define_phenotype_tests(self): |
| 34 | +# c1 = { |
| 35 | +# "name": "single_flag", |
| 36 | +# "persons": [f"P{i}" for i in range(4)], |
| 37 | +# "phenotype": CategoricalPhenotype( |
| 38 | +# name_space=self.name_space, |
| 39 | +# domain="condition_occurrence", |
| 40 | +# categorical_filter=CategoricalFilter( |
| 41 | +# allowed_values=["z1"], columnname="z" |
| 42 | +# ), |
| 43 | +# ), |
| 44 | +# } |
| 45 | + |
| 46 | +# c2 = { |
| 47 | +# "name": "two_categorical_filter_or", |
| 48 | +# "persons": [f"P{i}" for i in range(4)] + [f"P{i}" for i in range(6, 8)], |
| 49 | +# "phenotype": CategoricalPhenotype( |
| 50 | +# name_space=self.name_space, |
| 51 | +# domain="condition_occurrence", |
| 52 | +# categorical_filter=CategoricalFilter( |
| 53 | +# allowed_values=["z1"], columnname="z" |
| 54 | +# ) |
| 55 | +# | CategoricalFilter(allowed_values=["y2"], columnname="y"), |
| 56 | +# ), |
| 57 | +# } |
| 58 | + |
| 59 | +# c3 = { |
| 60 | +# "name": "two_categorical_filter_and", |
| 61 | +# "persons": [f"P{i}" for i in range(2, 4)], |
| 62 | +# "phenotype": CategoricalPhenotype( |
| 63 | +# name_space=self.name_space, |
| 64 | +# domain="condition_occurrence", |
| 65 | +# categorical_filter=CategoricalFilter( |
| 66 | +# allowed_values=["z1"], columnname="z" |
| 67 | +# ) |
| 68 | +# & CategoricalFilter(allowed_values=["y2"], columnname="y"), |
| 69 | +# ), |
| 70 | +# } |
| 71 | + |
| 72 | +# test_infos = [c1, c2, c3] |
| 73 | +# for test_info in test_infos: |
| 74 | +# test_info["refactor"] = True # TODO remove once refactored |
| 75 | +# test_info["phenotype"].name_phenotype = test_info["name"] |
| 76 | + |
| 77 | +# return test_infos |
| 78 | + |
| 79 | + |
| 80 | +# def test_categorical_phenotype(): |
| 81 | +# spg = CategoricalPhenotypeTestGenerator() |
| 82 | +# spg.run_tests() |
| 83 | + |
| 84 | + |
| 85 | +# if __name__ == "__main__": |
| 86 | +# test_categorical_phenotype() |
0 commit comments