-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
2034 lines (1708 loc) · 92.7 KB
/
app.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import dash
import dash_bootstrap_components as dbc
#import dash_core_components as dcc
#import dash_table
from dash import dcc
from dash import dash_table
from dash import html, Input, Output, State, ALL
import pandas as pd
from dash.exceptions import PreventUpdate
import dash_ag_grid as dag
import arc as ARC
import dash_treeview_antd
import paperCRF
import generate_form # Aidan: added this for format choices
import json
import bridge_modals
from dash import callback_context
#from pdf2docx import Converter
from datetime import datetime
import io
from zipfile import ZipFile
import re
import random
from urllib.parse import parse_qs, urlparse
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP, 'https://use.fontawesome.com/releases/v5.8.1/css/all.css'],suppress_callback_exceptions=True)
app.title ='BRIDGE'
modified_list=[]
versions,recentVersion=ARC.getARCVersions()
currentVersion=recentVersion
current_datadicc,presets,commit=ARC.getARC(recentVersion)
print('Begining')
current_datadicc[['Sec', 'vari', 'mod']] = current_datadicc['Variable'].str.split('_', n=2, expand=True)
current_datadicc[['Sec_name', 'Expla']] = current_datadicc['Section'].str.split(r'[(|:]', n=1, expand=True)
'''
for i in current_datadicc:
print('#####################')
print(i)
'''
tree_items_data=ARC.getTreeItems(current_datadicc,recentVersion)
#List content Transformation
ARC_lists,list_variable_choices=ARC.getListContent(current_datadicc,currentVersion,commit)
current_datadicc=ARC.addTransformedRows(current_datadicc,ARC_lists,ARC.getVariableOrder(current_datadicc))
#User List content Transformation
ARC_ulist,ulist_variable_choices=ARC.getUserListContent(current_datadicc,currentVersion,modified_list,commit)
current_datadicc=ARC.addTransformedRows(current_datadicc,ARC_ulist,ARC.getVariableOrder(current_datadicc))
ARC_multilist,multilist_variable_choices=ARC.getMultuListContent(current_datadicc,currentVersion,commit)
current_datadicc=ARC.addTransformedRows(current_datadicc,ARC_multilist,ARC.getVariableOrder(current_datadicc))
initial_current_datadicc = current_datadicc.to_json(date_format='iso', orient='split')
initial_ulist_variable_choices = json.dumps(ulist_variable_choices)
initial_multilist_variable_choices = json.dumps(multilist_variable_choices)
navbar = dbc.Navbar(
dbc.Container(
[
html.A(
# Use row and col to control vertical alignment of logo / brand
dbc.Row(
[
dbc.Col(html.Img(src="/assets/ISARIC_logo_wh.png", height="60px")),
dbc.Col(dbc.NavbarBrand("BRIDGE - BioResearch Integrated Data tool GEnerator", className="ms-2")),
],
align="center",
className="g-0",
),
href="https://isaric.org/",
style={"textDecoration": "none"},
),
dbc.NavbarToggler(id="navbar-toggler", n_clicks=0),
]
),
color="#BA0225",
dark=True,
)
navbar_big = dbc.Navbar(
dbc.Container(
[
html.A(
# Use row and col to control vertical alignment of logo / brand
dbc.Row(
[
dbc.Col(html.Img(src="assets/ISARIC_logo_wh.png", height="100px")),
dbc.Col(dbc.NavbarBrand("BRIDGE - BioResearch Integrated Data tool GEnerator", className="ms-2")),
],
align="center",
className="g-0",
),
href="https://isaric.org/",
style={"textDecoration": "none"},
),
dbc.NavbarToggler(id="navbar-toggler", n_clicks=0),
]
),
color="#BA0225",
dark=True,
)
# Sidebar with icons
sidebar = html.Div(
[
#dbc.NavLink(html.I(className="fas fa-home"), id="toggle-settings-1", n_clicks=0),
#dbc.NavLink(html.I(className="fas fa-book"), id="toggle-settings-2", n_clicks=0),
# Add more icons as needed
dbc.NavLink(html.Img(src="/assets/icons/Settings_off.png", style={'width': '40px' },id='settings_icon'), id="toggle-settings-1", n_clicks=0),
dbc.NavLink(html.Img(src="/assets/icons/preset_off.png", style={'width': '40px'},id='preset_icon'), id="toggle-settings-2", n_clicks=0),
#dbc.NavLink(html.Img(src="/assets/icons/question_off.png", style={'width': '40px'},id='question_icon'), id="toggle-question", n_clicks=0),
],
style={
"position": "fixed",
"top": "5rem", # Height of the navbar
"left": 0,
"bottom": 0,
"width": "4rem",
"padding": "2rem 1rem",
"background-color": "#dddddd",
"display": "flex",
"flexDirection": "column",
"alignItems": "center",
#"z-index": 2000
}
)
ARC_versions = versions
ARC_versions_items = [dbc.DropdownMenuItem(version, id={"type": "dynamic-version", "index": i}) for i, version in enumerate(ARC_versions)]
# Grouping presets by the first column
grouped_presets = {}
for key, value in presets:
grouped_presets.setdefault(key, []).append(value)
initial_grouped_presets = json.dumps(grouped_presets)
# Creating the accordion items
accordion_items = []
for key, values in grouped_presets.items():
# For each group, create a checklist
checklist = dbc.Checklist(
options=[{"label": value, "value": value} for value in values],
value=[],
#id=f'checklist-{key}',
id={'type': 'template_check', 'index': key},
switch=True,
)
# Create an accordion item with the checklist
accordion_items.append(
dbc.AccordionItem(
title=key,
children=checklist
)
)
preset_accordion = dbc.Accordion(accordion_items)
preset_content= html.Div(
[html.H3("Templates", id="settings-text-1"),
preset_accordion
],style={"padding": "2rem"}
)
preset_column = dbc.Fade(
html.Div(
[
html.H3("Templates", id="settings-text-1"),
dbc.Accordion(id='preset-accordion') # ID to be updated dynamically
],
style={"padding": "2rem"}
),
id="presets-column",
is_in=False, # Initially hidden
style={
"position": "fixed",
"top": "5rem",
"left": "4rem",
"bottom": 0,
"width": "20rem",
"background-color": "#dddddd",
"z-index": 2001
}
)
settings_content = html.Div(
[
html.H3("Settings", id="settings-text-2"),
# ICC Version dropdown
html.Div([
dbc.InputGroup([
dbc.DropdownMenu(
label="ARC Version",
children=ARC_versions_items,
id="dropdown-ARC-version-menu"
),
dbc.Input(id="dropdown-ARC_version_input", placeholder="name")
]),
dcc.Store(id='selected-version-store'),
dcc.Store(id='selected_data-store'),
#dcc.Store(id='visibility-store', data={'display': 'block'})
], style={'margin-bottom': '20px'}),
# Output Files checkboxes
dcc.Store(id="output-files-store"),
# Checklist component
html.Div([
html.Label("Output Files", htmlFor="output-files-checkboxes"),
dbc.Checklist(
id="output-files-checkboxes",
options=[
{'label': 'ISARIC Clinical Characterization XML', 'value': 'redcap_xml'},
{'label': 'REDCap Data Dictionary', 'value': 'redcap_csv'},
{'label': 'Paper-like CRF', 'value': 'paper_like'},
# {'label': 'Completion Guide', 'value': 'completion_guide'},
],
value=['redcap_xml','redcap_csv','paper_like'], # Default selected values
inline=True
)
], style={'margin-bottom': '20px'}),
],
style={"padding": "2rem"}
)
'''html.Div([
html.Label("'Paperlike' Files", htmlFor="paperlike-files-checkboxes"),
dbc.Checklist(
id="paperlike-files-checkboxes",
options=[
{'label': 'pdf', 'value': 'PDF'},
{'label': 'word', 'value': 'Word'},
# Add more papers as needed
],
value=['paper1'], # Default selected values
inline=True
)
]),'''
settings_column = dbc.Fade(
settings_content,
id="settings-column",
is_in=False, # Initially hidden
style={
"position": "fixed",
"top": "5rem",
"left": "4rem",
"bottom": 0,
"width": "20rem",
"background-color": "#dddddd",
"z-index": 2001
}
)
tree_items = html.Div(
dash_treeview_antd.TreeView(
id='input',
multiple=False,
checkable=True,
checked=[],
data=tree_items_data),id='tree_items_container',
style={
'overflow-y': 'auto', # Vertical scrollbar when needed
'height': '100%', # Fixed height
'width': '100%' , # Fixed width, or you can specify a value in px
'white-space': 'normal', # Allow text to wrap
'overflow-x': 'hidden', # Hide overflowed content
'text-overflow': 'ellipsis', # Indicate more content with an ellipsis
'display': 'block'
}
)
tree_column = dbc.Fade(
tree_items,
#html.Div("Hello"),
id="tree-column",
is_in=True, # Initially show
style={
"position": "fixed",
"top": "5rem",
"left": "4rem",
"bottom": 0,
"width": "30rem",
"background-color": "#ffffff",
"z-index": 2
}
)
column_defs = [{'headerName': "Question", 'field': "Question", 'wrapText': True},
{'headerName': "Answer Options", 'field': "Answer Options", 'wrapText': True}]
row_data = [{'question': "", 'options': ""},
{'question': "", 'options': ""}]
grid = html.Div(
dag.AgGrid(
id='CRF_representation_grid',
columnDefs=column_defs,
rowData=row_data,
defaultColDef={"sortable": True, "filter": True, 'resizable': True},
columnSize="sizeToFit",
dashGridOptions={
"rowDragManaged": True,
"rowDragEntireRow": True,
"rowDragMultiRow": True, "rowSelection": "multiple",
"suppressMoveWhenRowDragging": True,
"autoHeight": True
},
rowClassRules={
"form-separator-row ": 'params.data.SeparatorType == "form"',
'section-separator-row': 'params.data.SeparatorType == "section"',
},
style={
'overflow-y': 'auto', # Vertical scrollbar when needed
'height': '99%', # Fixed height
'width': '100%' , # Fixed width, or you can specify a value in px
'white-space': 'normal', # Allow text to wrap
'overflow-x': 'hidden', # Hide overflowed content
}
),
style={
'overflow-y': 'auto', # Vertical scrollbar when needed
'height': '75vh', # Fixed height
'width': '100%' , # Fixed width, or you can specify a value in px
'white-space': 'normal', # Allow text to wrap
'overflow-x': 'hidden', # Hide overflowed content
'text-overflow': 'ellipsis' # Indicate more content with an ellipsis
}
)
# Main Content
main_content = dbc.Container(
[
dbc.Row(
[
dbc.Col([html.Div(),
#tree_items,
html.Div(id='output-expanded', style={'display': 'none'})
]
, width=5), # 45% width
dbc.Col(
[
dbc.Row([html.Div(),
grid]), # 90% height
dbc.Row(
[
dbc.Col(dbc.Input(placeholder="CRF Name", type="text",id='crf_name')),
dbc.Col(dbc.Button("Generate", color="primary", id='crf_generate'))
],
style={"height": "10%"} # Remaining height for input and button
),
dbc.Row(html.Div(["BRIDGE is being developed by ISARIC. For inquiries, support, or collaboration, please write to: ",html.A("data@isaric.org", href="mailto:data@isaric.org"),". ","Licensed under a ",
html.A("Creative Commons Attribution-ShareAlike 4.0 ",
href="https://creativecommons.org/licenses/by-sa/4.0/", target="_blank"),
"International License by ",
html.A("ISARIC", href="https://isaric.org/", target="_blank"),
" on behalf of Oxford University."]))
],
width=7 # 55% width
)
]
)
],
fluid=True,
style={"margin-top": "4rem", "margin-left": "4rem","z-index": 1,"width":"90vw"} # Adjust margin to accommodate navbar and sidebar
)
app.layout = html.Div(
[
dcc.Store(id='show-Take a Look at Our Other Tools', data=True), # Store to manage which page to display
dcc.Store(id='current_datadicc-store',data=initial_current_datadicc),
dcc.Store(id='ulist_variable_choices-store',data=initial_ulist_variable_choices),
dcc.Store(id='multilist_variable_choices-store',data=initial_multilist_variable_choices),
dcc.Store(id='grouped_presets-store',data=initial_grouped_presets),
dcc.Store(id='tree_items_data-store',data=initial_grouped_presets),
dcc.Store(id='templates_checks_ready', data=False),
#navbar,
#sidebar,
#settings_column,
#preset_column,
#tree_column,
#main_content,
dcc.Location(id='url', refresh=False),
#html.H1(id='titleURL'),
html.Div(id='page-content'),
dcc.Download(id="download-dataframe-csv"),
dcc.Download(id='download-compGuide-pdf'),
dcc.Download(id='download-projectxml-pdf'),
dcc.Download(id='download-paperlike-pdf'),
bridge_modals.variableInformation_modal(),
bridge_modals.researchQuestions_modal(),
dcc.Loading(id="loading-1",
type="default",
children=html.Div(id="loading-output-1"),
),
dcc.Store(id='selected-version-store'),
dcc.Store(id='commit-store'),
dcc.Store(id='selected_data-store')
]
)
#################################
#######HOME PAGE##################
def home_page():
return html.Div([
navbar_big,
# First Section: Big Slogan and Button
html.Section([
dbc.Row([
dbc.Col([
html.Div([
html.H1("BRIDGE: Tailoring Case Reports for Every Outbreak", className="display-4", style={'font-weight': 'bold', 'color': 'white'}),
html.P("ISARIC BRIDGE streamlines the CRF creation process, generating data dictionaries and XML for REDCap, along with paper-like CRFs and completion guides.", style={'color': 'white'}),
dbc.Button("Create a CRF", className="home-button", id='start-button'),
html.A("Visit GitHub", target="_blank",href="https://github.com/ISARICResearch", style={'display': 'block', 'margin-top': '10px', 'color': 'white'})
], style={'padding': '2rem'})
], md=6, style={'display': 'flex', 'align-items': 'center', 'background-color': '#475160'}),
dbc.Col([
html.Img(src="/assets/home_main.png", style={'width': '100%'})
], md=6)
])
], style={'padding': '0', 'margin': '0', 'background-color': '#475160'}),
html.Section([
dbc.Row([
dbc.Col([
html.H4("Accelerating Outbreak Research Response", className="mb-3"),
html.P("BRIDGE automates the creation of Case Report Forms (CRFs) for specific diseases and research contexts. It generates the necessary data dictionary and XML to create a REDCap database for data capture in the ARC structure. Learn more in our ", style={"font-size": "20px", "display": "inline"}),
html.A("guide for getting started.", href="https://ISARICResearch.github.io/Training/bridge_starting.html", target="_blank", style={"font-size": "20px", "display": "inline"})
], md=9)
], className="my-5"),
], className="container"),
html.Section([
dbc.Row([
dbc.Col([
dbc.Card([
dbc.CardBody([
html.H4("Choose", className="card-title"),
html.P([
"BRIDGE uses the machine-readable library ",
html.A("ARC", href="https://example.com", target="_blank"),
" and allows the user to choose the questions they want to include in the CRF. ",
"BRIDGE presents ARC as a tree structure with different levels: ARC version, forms, sections, and questions. Users navigate through this tree and select the questions they want to include in the CRF.",
html.Br(),
html.Br(),
"Additionally, users can start with one of our Presets, which are pre-selected groups of questions. They can click on the Pre-sets tab and select those they want to include in the CRF. All selected questions can be customized."
], className="card-text")
], className="card-body-fixed"),
dbc.CardImg(src="/assets/card1.png", bottom=True, className="card-img-small"),
], className="mb-3")
], md=4),
dbc.Col([
dbc.Card([
dbc.CardBody([
html.H4("Customize", className="card-title"),
html.P([
"BRIDGE allows customization of CRFs from chosen questions, as well as selection of measurement units and answer options where pertinent. ",
"Users click the relevant question, and a checkable list appears with options for the site or disease being researched.",
html.Br(),
html.Br(),
"This feature ensures that the CRF is tailored to specific needs, enhancing the precision and relevance of the data collected."
], className="card-text")
], className="card-body-fixed"),
dbc.CardImg(src="/assets/card2.png", bottom=True, className="card-img-small"),
], className="mb-3")
], md=4),
dbc.Col([
dbc.Card([
dbc.CardBody([
html.H4("Capture", className="card-title"),
html.P([
"BRIDGE generates files for creating databases within REDCap, including the data dictionary and XML needed to create a REDCap database for capturing data in the ARC structure. ",
"It also produces paper-like versions of the CRFs and completion guides. ",
html.Br(),
html.Br(),
"Once users are satisfied with their selections, they can name the CRF and click on generate to finalize the process, ensuring a seamless transition to data collection."
], className="card-text")
], className="card-body-fixed"),
dbc.CardImg(src="/assets/card3.png", bottom=True, className="card-img-small"),
], className="mb-3")
], md=4),
], className="my-5")
], className="container"),
html.Section([
html.Div([
html.Br(),
html.H3("In partnership with:", className="text-center my-4"),
# First Row
dbc.Row([
dbc.Col([
html.Div([
html.Img(src="/assets/logos/FIOCRUZ_logo.png", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto"),
dbc.Col([
html.Div([
html.Img(src="/assets/logos/global_health.png", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto"),
dbc.Col([
html.Div([
html.Img(src="/assets/logos/puc_rio.png", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto"),
], className="justify-content-center"),
# Second Row
html.Br(),
dbc.Row([
dbc.Col([
html.Div([
html.Img(src="/assets/logos/CONTAGIO_Logo.jpg", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto"),
dbc.Col([
html.Div([
html.Img(src="/assets/logos/LONG_CCCC.png", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto"),
dbc.Col([
html.Div([
html.Img(src="/assets/logos/penta_col.jpg", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto"),
dbc.Col([
html.Div([
html.Img(src="/assets/logos/VERDI_Logo.jpg", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto")
], className="justify-content-center")
])
]),
html.Section([
html.Div([
html.Br(),
html.H3("With funding from:", className="text-center my-4"),
dbc.Row([
dbc.Col([
html.Div([
html.Img(src="/assets/logos/wellcome-logo.png", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto"),
dbc.Col([
html.Div([
html.Img(src="/assets/logos/billmelinda-logo.png", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto"),
dbc.Col([
html.Div([
html.Img(src="/assets/logos/uk-international-logo.png", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto"),
dbc.Col([
html.Div([
html.Img(src="/assets/logos/FundedbytheEU.png", className="img-fluid", style={"height": "100px"})
], className="d-flex justify-content-center")
], width="auto")
], className="justify-content-center")
])
]),
# Fourth Section: Other Tools
# Section showcasing other tools
html.Section([
html.Div([
html.H3("Take a Look at Our Other Tools", className="text-center my-4"),
dbc.Row([
dbc.Col([
dbc.Card([
dbc.CardImg(src="/assets/logos/arc_logo.png", top=True),
dbc.CardBody([
html.H4("Analysis and ReseARC Compendium (ARC)", className="card-title"),
html.P([
"ARC is a comprehensive machine-readable document in CSV format, designed for use in Clinical Report Forms (CRFs) during disease outbreaks. ",
"It includes a library of questions covering demographics, comorbidities, symptoms, medications, and outcomes. ",
"Each question is based on a standardized schema, has specific definitions mapped to controlled terminologies, and has built-in quality control. ",
"ARC is openly accessible, with version control via GitHub ensuring document integrity and collaboration."
], className="card-text"),
html.A("Find Out More", target="_blank",href="https://github.com/ISARICResearch/ARC", style={'display': 'block', 'margin-top': '10px', 'color': '#BA0225'})
], className="card-tools-fixed")
])
], md=3),
dbc.Col([
dbc.Card([
dbc.CardImg(src="/assets/logos/fhirflat_logo.png", top=True),
dbc.CardBody([
html.H4("FHIRflat", className="card-title"),
html.P([
"FHIRflat is a versatile library designed to transform FHIR resources in NDJSON or native Python dictionaries into a flat structure, which can be easily written to a Parquet file. ",
"This facilitates reproducible analytical pipelines (RAP) by converting raw data into the FHIR R5 standard with ISARIC-specific extensions. ",
"Typically, FHIR resources are stored in databases served by specialized FHIR servers. However, for RAP development, which demands reproducibility and data snapshots, a flat file format is more practical. ",
], className="card-text")
,
html.A("Find Out More", target="_blank",href="https://fhirflat.readthedocs.io/en/latest/", style={'display': 'block', 'margin-top': '10px', 'color': '#BA0225'})
], className="card-tools-fixed")
])
], md=3),
dbc.Col([
dbc.Card([
dbc.CardImg(src="/assets/logos/polyflame_logo.png", top=True),
dbc.CardBody([
html.H4("Polymorphic FLexible Analytics and Modelling Engine (PolyFLAME)", className="card-title"),
html.P([
"PolyFLAME processes and transforms data using the FHIRflat library. ",
"Once input data is brought into FHIRflat, it is represented as a (optionally zipped) folder of FHIR resources, with a parquet file corresponding to each resource: patient.parquet, encounter.parquet, and so on. ",
"PolyFLAME is an easy-to-use library that can be utilized in Jupyter notebooks and other downstream code to query answers to common research questions in a reproducible analytical pipeline (RAP). "
], className="card-text"),
html.A("Find Out More", target="_blank",href="https://polyflame.readthedocs.io/en/latest/index.html", style={'display': 'block', 'margin-top': '10px', 'color': '#BA0225'})
], className="card-tools-fixed"),
])
], md=3),
dbc.Col([
dbc.Card([
dbc.CardImg(src="/assets/logos/vertex_logo.png", top=True),
dbc.CardBody([
html.H4("Visual Evidence & Research Tool for Exploration (VERTEX)", className="card-title"),
html.P([
"VERTEX is a web-based application designed to present graphs and tables based on relevant research questions that need quick answers during an outbreak. ",
"VERTEX uses reproducible analytical pipelines, currently focusing on identifying the spectrum of clinical features in a disease and determining risk factors for patient outcomes. ",
"New questions will be added by the ISARIC team and the wider scientific community, enabling the creation and sharing of new pipelines. ",
"Users can download the code for ARC-structured data visualization through VERTEX."
], className="card-text"),
html.A("Find Out More", target="_blank",href="https://github.com/ISARICResearch/VERTEX", style={'display': 'block', 'margin-top': '10px', 'color': '#BA0225'})
], className="card-tools-fixed")
])
], md=3)
], className="my-5")
], className="container")
], className="py-5"),
html.Footer([
html.Div([
html.P([
"Licensed under a ",
html.A("Creative Commons Attribution-ShareAlike 4.0",
href="https://creativecommons.org/licenses/by-sa/4.0/", target="_blank"),
" International License by ",
html.A("ISARIC", href="https://isaric.org/", target="_blank"),
" on behalf of Oxford University."
], className="text-center my-3")
], className="footer")
])
]),
def main_app():
return html.Div([
navbar,
sidebar,
settings_column,
preset_column,
tree_column,
main_content,
])
@app.callback(Output('page-content', 'children'),
Input('url', 'pathname'))
def display_page(pathname):
if pathname == '/':
return home_page()
else:
return main_app()
@app.callback(Output('url', 'pathname'),
Input('start-button', 'n_clicks'))
def start_app(n_clicks):
if n_clicks is None:
return '/'
else:
return '/main'
####################
# get URL parameter
####################
@app.callback(
#[Output('crf_name', 'value')] + [Output(f'checklist-{key}', 'value') for key in grouped_presets.keys()],
#[Output('crf_name', 'value')] ,
[Output('crf_name', 'value'), Output({'type': 'template_check', 'index': ALL}, 'value')],
[Input('templates_checks_ready', 'data')],
[State('url', 'href')],
prevent_initial_call=True,
)
def update_output_based_on_url(template_check_flag,href):
if not template_check_flag:
return dash.no_update
if href is None:
return [''] + [[] for _ in grouped_presets.keys()]
if '?param=' in href:
# Parse the URL to extract the parameters
parsed_url = urlparse(href)
params = parse_qs(parsed_url.query)
# Accessing the 'param' parameter
param_value = params.get('param', [''])[0] # Default to an empty string if the parameter is not present
# Example: Split param_value by underscore
group, value = param_value.split('_') if '_' in param_value else (None, None)
# Prepare the outputs
checklist_values = {key: [] for key in grouped_presets.keys()}
if group in grouped_presets and value in grouped_presets[group]:
checklist_values[group] = [value]
# Return the value for 'crf_name' and checklist values
return [value] , [checklist_values[key] for key in grouped_presets.keys()]
else:
return dash.no_update
#return [value]
#################################
@app.callback(
[Output("presets-column", "is_in"),
Output("settings-column", "is_in"),
Output("tree-column", 'is_in'),
Output("settings_icon", "src"),
Output("preset_icon", "src")],
[Input("toggle-settings-2", "n_clicks"),
Input("toggle-settings-1", "n_clicks")],
[State("presets-column", "is_in"),
State("settings-column", "is_in")],
prevent_initial_call=True
)
def toggle_columns(n_presets, n_settings, is_in_presets, is_in_settings):
ctx = dash.callback_context
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
# Initialize the state of icons
preset_icon_img = "/assets/icons/preset_off.png"
settings_icon_img = "/assets/icons/Settings_off.png"
# Toggle logic
if button_id == "toggle-settings-2":
# If settings is open, close it and open presets
if is_in_settings:
new_is_in_presets = True
new_is_in_settings = False
else:
# Toggle the state of presets
new_is_in_presets = not is_in_presets
new_is_in_settings = False
preset_icon_img = "/assets/icons/preset_on.png" if new_is_in_presets else "/assets/icons/preset_off.png"
elif button_id == "toggle-settings-1":
# If presets is open, close it and open settings
if is_in_presets:
new_is_in_settings = True
new_is_in_presets = False
else:
# Toggle the state of settings
new_is_in_settings = not is_in_settings
new_is_in_presets = False
settings_icon_img = "/assets/icons/Settings_on.png" if new_is_in_settings else "/assets/icons/Settings_off.png"
else:
# Default state if no button is clicked
new_is_in_presets = is_in_presets
new_is_in_settings = is_in_settings
# Determine tree-column visibility
is_in_tree = not (new_is_in_presets or new_is_in_settings)
return new_is_in_presets, new_is_in_settings, is_in_tree, settings_icon_img, preset_icon_img
@app.callback([Output('CRF_representation_grid','columnDefs'),
Output('CRF_representation_grid','rowData'),
Output('selected_data-store','data')],
[Input('input', 'checked')],
[State('current_datadicc-store','data')],
prevent_initial_call=True)
def display_checked(checked,current_datadicc_saved):
current_datadicc=pd.read_json(current_datadicc_saved, orient='split')
column_defs = [ {'headerName': "Question", 'field': "Question", 'wrapText': True},
{'headerName': "Answer Options", 'field': "Answer Options", 'wrapText': True}]
row_data = [{'question': "", 'options': ""},
{'question': "", 'options': ""}]
selected_variables = pd.DataFrame()
if checked and len(checked) > 0:
#selected_variables=current_datadicc.loc[current_datadicc['Variable'].isin(checked)]
#global selected_variables
selected_dependency_lists = current_datadicc['Dependencies'].loc[current_datadicc['Variable'].isin(checked)].tolist()
flat_selected_dependency = set()
for sublist in selected_dependency_lists:
flat_selected_dependency.update(sublist)
all_selected = set(checked).union(flat_selected_dependency)
selected_variables = current_datadicc.loc[current_datadicc['Variable'].isin(all_selected)]
#############################################################
#############################################################
## REDCAP Pipeline
delete_this_variables_with_units=[]
selected_variables=ARC.getIncludeNotShow(selected_variables['Variable'],current_datadicc)
#Select Units Transformation
arc_var_units_selected, delete_this_variables_with_units=ARC.getSelectUnits(selected_variables['Variable'],current_datadicc)
if arc_var_units_selected is not None:
selected_variables = ARC.addTransformedRows(selected_variables,arc_var_units_selected,ARC.getVariableOrder(current_datadicc))
if len(delete_this_variables_with_units)>0: # This remove all the unit variables that were included in a select unit type question
selected_variables = selected_variables.loc[~selected_variables['Variable'].isin(delete_this_variables_with_units)]
selected_variables = ARC.generateDailyDataType(selected_variables)
#############################################################
#############################################################
last_form, last_section = None, None
new_rows = []
selected_variables=selected_variables.fillna('')
for index, row in selected_variables.iterrows():
# Add form separator
if row['Form'] != last_form:
new_rows.append({'Question': f"{row['Form'].upper()}", 'Answer Options': '', 'IsSeparator': True, 'SeparatorType': 'form'})
last_form = row['Form']
# Add section separator
if row['Section'] != last_section and row['Section'] != '':
new_rows.append({'Question': f"{row['Section'].upper()}", 'Answer Options': '', 'IsSeparator': True, 'SeparatorType': 'section'})
last_section = row['Section']
# Process the actual row
if row['Type'] in ['radio', 'dropdown', 'checkbox','list','user_list','multi_list']:
formatted_choices = generate_form.format_choices(row['Answer Options'], row['Type'])
row['Answer Options'] = formatted_choices
elif row['Validation'] == 'date_dmy':
#date_str = """[<font color="lightgrey">_D_</font>][<font color="lightgrey">_D_</font>]/[<font color="lightgrey">_M_</font>][<font color="lightgrey">_M_</font>]/[_2_][_0_][<font color="lightgrey">_Y_</font>][<font color="lightgrey">_Y_</font>]"""
date_str = "[_D_][_D_]/[_M_][_M_]/[_2_][_0_][_Y_][_Y_]"
row['Answer Options'] = date_str
else:
row['Answer Options'] = paperCRF.line_placeholder
# Add the processed row to new_rows
new_row = row.to_dict()
new_row['IsSeparator'] = False
new_rows.append(new_row)
# Update selected_variables with new rows including separators
selected_variables_for_TableVisualization = pd.DataFrame(new_rows)
selected_variables_for_TableVisualization=selected_variables_for_TableVisualization.loc[selected_variables_for_TableVisualization['Type']!='group']
# Convert to dictionary for row_data
row_data = selected_variables_for_TableVisualization.to_dict(orient='records')
column_defs = [ {'headerName': "Question", 'field': "Question", 'wrapText': True},
{'headerName': "Answer Options", 'field': "Answer Options", 'wrapText': True}]
return column_defs, row_data, selected_variables.to_json(date_format='iso', orient='split')
@app.callback(Output('rq_modal', 'is_open'),
[Input("toggle-question", "n_clicks")],
prevent_initial_call=True)
def research_question(n_question):
return True
@app.callback([
Output('modal', 'is_open'),
Output('modal_title','children'),
Output('definition-text','children'),
Output('completion-guide-text','children'),
Output('options-checklist', 'style'),
Output('options-list-group', 'style'),
Output('options-checklist','options'),
Output('options-checklist','value'),
Output('options-list-group','children')],
[Input('input', 'selected')],
[State('ulist_variable_choices-store','data'),State('multilist_variable_choices-store','data'),State('modal', 'is_open')])
def display_selected(selected,ulist_variable_choices_saved,multilist_variable_choices_saved,is_open):
dict1 = json.loads(ulist_variable_choices_saved)
dict2 = json.loads(multilist_variable_choices_saved)
datatatata = dict1+dict2
#datatatata=json.loads(ulist_variable_choices_saved)
if (selected is not None):
if len(selected)>0:
if selected[0] in list(current_datadicc['Variable']):
question=current_datadicc['Question'].loc[current_datadicc['Variable']==selected[0]].iloc[0]
type=current_datadicc['Question'].loc[current_datadicc['Variable']==selected[0]].iloc[0]
definition=current_datadicc['Definition'].loc[current_datadicc['Variable']==selected[0]].iloc[0]
completion=current_datadicc['Completion Guideline'].loc[current_datadicc['Variable']==selected[0]].iloc[0]
ulist_variables = [i[0] for i in datatatata]
if selected[0] in ulist_variables:
for item in datatatata:
if item[0] == selected[0]:
options = []
checked_items = []
for i in item[1]:
options.append({"label":str(i[0])+', '+i[1],"value":str(i[0])+'_'+i[1]})
if i[2]==1:
checked_items.append(str(i[0])+'_'+i[1])
return True,question+' ['+selected[0]+']',definition,completion, {"padding": "20px", "maxHeight": "250px", "overflowY": "auto"}, {"display": "none"},options,checked_items,[]
else:
options = []
answ_options=current_datadicc['Answer Options'].loc[current_datadicc['Variable']==selected[0]].iloc[0]
if isinstance(answ_options, str):
for i in answ_options.split('|'):
options.append(dbc.ListGroupItem(i))
else:
options=[]
return True,question+' ['+selected[0]+']',definition,completion, {"display": "none"}, {"maxHeight": "250px", "overflowY": "auto"},[],[],options
return False,'','','',{"display": "none"}, {"display": "none"},[],[],[]
@app.callback(Output('output-expanded', 'children'),
[Input('input', 'expanded')])
def display_expanded(expanded):
return 'You have expanded {}'.format(expanded)
@app.callback(
[Output('selected-version-store', 'data', allow_duplicate=True),
Output('commit-store', 'data', allow_duplicate=True),
Output('preset-accordion', 'children', allow_duplicate=True),
Output('grouped_presets-store', 'data'),
Output('current_datadicc-store', 'data', allow_duplicate=True),
Output('templates_checks_ready', 'data')],
[Input({'type': 'dynamic-version', 'index': dash.ALL}, 'n_clicks')],
[State('selected-version-store', 'data')], # Obtenemos el valor actual del store
prevent_initial_call=True # Evita que se dispare al inicio
)