1818 QDesktopWidget ,
1919)
2020from PyQt5 .QtGui import QIcon
21- from PyQt5 .QtCore import pyqtSignal , QDate , QTime
21+ from PyQt5 .QtCore import pyqtSignal
2222
2323from ulc_mm_package .scope_constants import EXPERIMENT_METADATA_KEYS
2424from ulc_mm_package .image_processing .processing_constants import TARGET_FLOWRATE
25- from PyQt5 .QtWidgets import QDateEdit , QTimeEdit
2625from ulc_mm_package .QtGUI .gui_constants import (
2726 ICON_PATH ,
2827 SITE_ENV_VAR ,
2928 SITE_LIST ,
3029 SAMPLE_LIST ,
3130 TOOLBAR_OFFSET ,
3231)
32+ import ulc_mm_package .QtGUI .study_metadata_form as study_form
3333
3434
3535class FormGUI (QDialog ):
@@ -42,22 +42,20 @@ def __init__(self):
4242
4343 self ._load_ui ()
4444
45+ def _study_select (self ) -> None :
46+ text = self .study_select_val .currentText ()
47+ if text != "" :
48+ self .start_btn .setText ("Enter additional study metadata" )
49+ else :
50+ self .start_btn .setText ("Start" )
51+
4552 def closeEvent (self , event ):
4653 if event .spontaneous ():
4754 self .close_event .emit ()
4855 event .ignore ()
4956 else :
5057 event .accept ()
5158
52- def _validate_temperature (self ):
53- text = self .sample_storage_temp .text ()
54- if not text .endswith (("C" , "F" , "c" , "f" )) or not text [:- 1 ].isdigit ():
55- self .sample_storage_temp .setStyleSheet ("border: 1px solid red;" )
56- self .start_btn .setEnabled (False )
57- else :
58- self .sample_storage_temp .setStyleSheet ("" )
59- self .start_btn .setEnabled (True )
60-
6159 def _load_ui (self ):
6260 self .setWindowTitle ("Experiment form" )
6361
@@ -87,35 +85,16 @@ def _load_ui(self):
8785
8886 # Labels
8987 self .operator_lbl = QLabel ("Operator ID" )
90- self .participant_lbl = QLabel ("Non-identifying participant ID" )
91- self .sample_collection_date_lbl = QLabel ("Sample collection date" )
92- self .sample_collection_time_lbl = QLabel ("Sample collection time" )
93- self .sample_storage_temp_lbl = QLabel ("Sample storage temperature (°C or °F)" )
88+ self .sample_id_lbl = QLabel ("Non-identifying sample ID" )
89+ self .study_select_lbl = QLabel ("Select study" )
9490 self .flowcell_lbl = QLabel ("Flowcell ID" )
9591 self .notes_lbl = QLabel ("Other notes" )
9692 self .site_lbl = QLabel ("Site" )
9793 self .sample_lbl = QLabel ("Sample type" )
9894
9995 # Text boxes
10096 self .operator_val = QLineEdit ()
101- self .participant_val = QLineEdit ()
102-
103- # Sample collection date
104- self .sample_collection_date = QDateEdit (QDate .currentDate ())
105- self .sample_collection_date .setCalendarPopup (True )
106- self .sample_collection_date .setDisplayFormat ("yyyy-MMM-dd" )
107-
108- # Sample collection time
109- self .sample_collection_time = QTimeEdit (QTime .currentTime ())
110- self .sample_collection_time .setDisplayFormat ("hh:mm AP" )
111- self .sample_collection_time .setCalendarPopup (True )
112-
113- # Sample storage temperature
114- self .sample_storage_temp = QLineEdit ()
115- self .sample_storage_temp .setPlaceholderText (
116- "Enter temperature (e.g. 25C or 77F)"
117- )
118- self .sample_storage_temp .textChanged .connect (self ._validate_temperature )
97+ self .sample_id_val = QLineEdit ()
11998
12099 self .flowcell_val = QLineEdit ()
121100 self .notes_val = QPlainTextEdit ()
@@ -127,9 +106,15 @@ def _load_ui(self):
127106 # Dropdown menus
128107 self .site_val = QComboBox ()
129108 self .sample_val = QComboBox ()
109+ self .study_select_val = QComboBox ()
110+ self .study_select_val .currentTextChanged .connect (self ._study_select )
130111
131112 self .site_val .addItems (SITE_LIST )
132113 self .sample_val .addItems (SAMPLE_LIST )
114+ self .study_select_val .addItems (
115+ list (study_form .list_available_studies ().keys ()) + ["" ]
116+ )
117+ self .study_select_val .setCurrentIndex (- 1 )
133118
134119 if SITE_ENV_VAR is not None :
135120 self .site_val .setEnabled (False )
@@ -139,21 +124,17 @@ def _load_ui(self):
139124
140125 # Place widgets
141126 self .main_layout .addWidget (self .operator_lbl , 0 , 0 )
142- self .main_layout .addWidget (self .participant_lbl , 1 , 0 )
143- self .main_layout .addWidget (self .sample_collection_date_lbl , 2 , 0 )
144- self .main_layout .addWidget (self .sample_collection_time_lbl , 3 , 0 )
145- self .main_layout .addWidget (self .sample_storage_temp_lbl , 4 , 0 )
127+ self .main_layout .addWidget (self .sample_id_lbl , 1 , 0 )
128+ self .main_layout .addWidget (self .study_select_lbl , 2 , 0 )
146129 self .main_layout .addWidget (self .flowcell_lbl , 5 , 0 )
147130 self .main_layout .addWidget (self .site_lbl , 6 , 0 )
148131 self .main_layout .addWidget (self .sample_lbl , 7 , 0 )
149132 self .main_layout .addWidget (self .notes_lbl , 8 , 0 )
150133 self .main_layout .addWidget (self .exit_btn , 9 , 0 )
151134
152135 self .main_layout .addWidget (self .operator_val , 0 , 1 )
153- self .main_layout .addWidget (self .participant_val , 1 , 1 )
154- self .main_layout .addWidget (self .sample_collection_date , 2 , 1 )
155- self .main_layout .addWidget (self .sample_collection_time , 3 , 1 )
156- self .main_layout .addWidget (self .sample_storage_temp , 4 , 1 )
136+ self .main_layout .addWidget (self .sample_id_val , 1 , 1 )
137+ self .main_layout .addWidget (self .study_select_val , 2 , 1 )
157138 self .main_layout .addWidget (self .flowcell_val , 5 , 1 )
158139 self .main_layout .addWidget (self .site_val , 6 , 1 )
159140 self .main_layout .addWidget (self .sample_val , 7 , 1 )
@@ -165,33 +146,24 @@ def _load_ui(self):
165146 self .start_btn .setDefault (True )
166147
167148 def get_form_input (self ) -> dict :
168- # Determine the sample age from the current time and the sample collection time
169- current_date = QDate .currentDate ()
170- current_time = QTime .currentTime ()
171-
172- sample_date = self .sample_collection_date .date ()
173- sample_time = self .sample_collection_time .time ()
174-
175- date_diff_in_hours = sample_date .daysTo (current_date ) * 24
176- time_diff_in_hours = sample_time .secsTo (current_time ) / 3600
177-
178- sample_age_hours = round (date_diff_in_hours + time_diff_in_hours , 2 )
149+ study_name = self .study_select_val .currentText ()
150+ if study_name != "" :
151+ study_id = study_form .get_study_id_from_name (study_name )
152+ else :
153+ study_id = None
179154
180155 form_metadata = {
181156 "operator_id" : self .operator_val .text (),
182- "participant_id " : self .participant_val .text (),
157+ "sample_id " : self .sample_id_val .text (),
183158 "flowcell_id" : self .flowcell_val .text (),
184- "sample_collection_date" : self .sample_collection_date .text (),
185- "sample_collection_time" : self .sample_collection_time .text (),
186- "sample_age_hours" : sample_age_hours ,
187- "sample_storage_temp" : self .sample_storage_temp .text (),
188159 "target_flowrate" : (
189160 TARGET_FLOWRATE .name .capitalize (),
190161 TARGET_FLOWRATE .value ,
191162 ), # fixed flowrate
192163 "site" : self .site_val .currentText (),
193164 "sample_type" : self .sample_val .currentText (),
194165 "notes" : self .notes_val .toPlainText (),
166+ "study_id" : study_id ,
195167 }
196168
197169 if not all (key in EXPERIMENT_METADATA_KEYS for key in form_metadata ):
@@ -201,15 +173,25 @@ def get_form_input(self) -> dict:
201173
202174 def reset_parameters (self ) -> None :
203175 """Clear specific inputs which are expected to be unique for the next run."""
204- self .participant_val .setText ("" )
176+ self .sample_id_val .setText ("" )
205177 self .flowcell_val .setText ("" )
206178 self .notes_val .setPlainText ("" )
207179
180+ def sf (self ) -> None :
181+ metadata = self .get_form_input ()
182+ cfg = study_form .get_cfg_from_study_id (metadata ["study_id" ])
183+ if cfg is not None :
184+ sf = study_form .StudyMetadata (cfg , gui )
185+ sf .show ()
186+ else :
187+ raise ValueError (f"Was unable to fetch { metadata ['study_id' ]} " )
188+
208189
209190if __name__ == "__main__" :
210191 app = QApplication (sys .argv )
211192 gui = FormGUI ()
212193 gui .exit_btn .clicked .connect (gui .close )
194+ gui .start_btn .clicked .connect (gui .sf )
213195
214196 print (gui .get_form_input ())
215197
0 commit comments