-
Notifications
You must be signed in to change notification settings - Fork 1
/
trustscore_dua_generator_gui.py
191 lines (170 loc) · 5.85 KB
/
trustscore_dua_generator_gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import os
from pathlib import Path
import panel as pn
from dua.generator import DUAGenerator
from trustscore.generator import TrustScoreGenerator
PERMITTED_USE_OR_DISCLOSURE = [
"treatment",
"payment",
"health_care_operations",
"notification",
"public_health",
"limited_data_set",
]
DATA_CLASSES = [
"Allergy",
"CarePlan",
"Claim",
"ClaimTransaction",
"Condition",
"Device",
"Encounter",
"ImagingStudy",
"Immunization",
"Medication",
"Observation",
"Organization",
"Patient",
"PayerTransition",
"Payer",
"Procedure",
"Provider",
"Supply",
]
def main():
pn.extension(sizing_mode="stretch_width")
# Define a function to generate the dashboard
def generate_dashboard(
num_orgs_value,
num_orgs_dua_value,
num_user_per_org_value,
# num_requested_data,
dataclass_select_value,
dataclass_portion_slider_value,
permitted_use_or_disclosure_select_value,
usage_portion_slider_value,
random_seed_value,
save_path_value,
):
# Print the input values to the console
input_text = (
f"Number of organizations: {num_orgs_value}\n"
f"Number of organizations with DUA: {num_orgs_dua_value}\n"
f"User per organization: {num_user_per_org_value}\n"
# f"Number of requested data: {num_requested_data}\n"
f"Random seed: {random_seed_value}\n"
f"Save path: {save_path_value}\n"
)
print(input_text)
dua_generator = DUAGenerator()
dua_generator.num_organization = num_orgs_value
dua_generator.num_dua_org = num_orgs_dua_value
# dua_generator.num_requested_data = num_requested_data
dua_generator.main_dataclass = dataclass_select_value
dua_generator.main_dataclass_portion = dataclass_portion_slider_value
dua_generator.main_permitted_use_or_disclosure = (
permitted_use_or_disclosure_select_value
)
dua_generator.main_permitted_use_or_disclosure_portion = (
usage_portion_slider_value
)
dua_generator.seed = random_seed_value
dua_generator.save_path = save_path_value
dua_generator.generate_dua()
trustscore_generator = TrustScoreGenerator(
num_org=num_orgs_value, user_per_org=num_user_per_org_value
)
trustscore_generator.generate_trustscore(save_path=save_path_value)
output_text = f"Output saved to {save_path_value}\n"
print(output_text)
# Return the input and output text
return input_text, output_text
# Create the input widgets
num_orgs_input = pn.widgets.IntInput(name="Number of organizations:", value=10)
num_orgs_dua_slider = pn.widgets.IntSlider(
name="Percentage of organizations with DUA",
start=0,
end=100,
value=70,
step=10,
)
# num_orgs_dua_input = pn.widgets.IntInput(
# name="Number of organizations with DUA:", value=5
# )
num_user_per_org_input = pn.widgets.IntInput(
name="User per organization:", value=10
)
# num_requested_data_input = pn.widgets.IntInput(
# name="Number of requested data:", value=3
# )
random_seed_input = pn.widgets.IntInput(name="Random seed:", value=7)
save_path_input = pn.widgets.TextInput(name="Save path:", value="csv")
# Main data class selection
dataclass_select = pn.widgets.Select(
name="Main Data class", options=DATA_CLASSES, value="Patient"
)
# Main data class portion
dataclass_portion_slider = pn.widgets.IntSlider(
name="Main Data class portion", start=0, end=100, value=70
)
# Main permitted use or disclosure
permitted_use_or_disclosure_select = pn.widgets.Select(
name="Main permitted use or disclosure",
options=PERMITTED_USE_OR_DISCLOSURE,
value="public_health",
)
# Main permitted use or disclosure portion
usage_portion_slider = pn.widgets.IntSlider(
name="Main permitted use or disclosure portion", start=0, end=100, value=70
)
# Create the button widget and callback function
button = pn.widgets.Button(name="Generate Data", button_type="primary")
output_text = pn.pane.Str()
def button_callback(event):
pwd = Path(os.getcwd())
print(pwd)
save_path = (
pwd
/ Path(save_path_input.value).resolve()
/ str(num_orgs_input.value * num_user_per_org_input.value)
)
if not save_path.exists():
save_path.mkdir(parents=True)
num_orgs_dua = int(num_orgs_input.value * num_orgs_dua_slider.value / 100)
input_text, output_text_value = generate_dashboard(
num_orgs_input.value,
num_orgs_dua,
num_user_per_org_input.value,
# num_requested_data_input.value,
dataclass_select.value,
dataclass_portion_slider.value,
permitted_use_or_disclosure_select.value,
usage_portion_slider.value,
random_seed_input.value,
save_path,
)
# Set the output text value and update the widget
output_text.object = input_text + output_text_value
output_text.param.trigger("object")
button.on_click(button_callback)
# Create the dashboard layout
dashboard = pn.Column(
"# DUA and Trust Score Generator",
num_orgs_input,
num_orgs_dua_slider,
num_user_per_org_input,
# num_requested_data_input,
random_seed_input,
save_path_input,
dataclass_select,
dataclass_portion_slider,
permitted_use_or_disclosure_select,
usage_portion_slider,
button,
output_text,
)
# Launch the dashboard
# dashboard.servable()
pn.serve(dashboard)
if __name__ == "__main__":
main()