def test_prepare_query(self): sql = prepare_query("users") assert sql == 'SELECT * FROM users' sql = prepare_query("users", {"k1": "tommy", "k2": "*****@*****.**"}, ["k1", "k2", "k3"]) assert sql == 'SELECT * FROM users WHERE (k1="tommy" and k2="*****@*****.**")' sql = prepare_query("users", {"k1": "tommy", "k2": "*****@*****.**"}) assert sql == 'SELECT * FROM users WHERE (k1="tommy" and k2="*****@*****.**")'
def list_users_in_instance(self, instance_id): """ List all users belongs to instance_id instance. :param instance_id: :return: """ sql = prepare_query("instances_users", {"instance_id": instance_id}) cur = self.sql_connection.cursor() cur.execute(sql) result = cur.fetchall() self.sql_connection.commit() return result
def query(self, query_obj): """ Check if record exist by query_obj. :param query_obj: :return: None or record object. """ sql = prepare_query("label_candidates", query_obj, ["candidate_id", "instance_id", "label_type", "contour_label_value", "input_type", "text"]) cur = self.sql_connection.cursor() cur.execute(sql) result = cur.fetchall() result = [dict(item) for item in result] return result
def query(self, query_obj): """ Check if record exist by query_obj. :param query_obj: :return: None or record object. """ sql = prepare_query("instances", query_obj, ['instance_id', 'name', 'modality', 'description', 'data_path', 'has_audit', 'study_num', 'annotated_num', 'status']) cur = self.sql_connection.cursor() cur.execute(sql) result = cur.fetchall() result = [dict(item) for item in result] return result
def query(self, query_obj): """ Check if record exist by query_obj. :param query_obj: :return: None or record object. """ sql = prepare_query("studies", query_obj, ['study_id', 'instance_id', 'patient_uid', 'study_uid', 'suid', 'folder_name', 'total_files_number', 'annotators', 'auditors', 'status']) cur = self.sql_connection.cursor() cur.execute(sql) result = cur.fetchall() result = [dict(item) for item in result] return result
def query(self, query_obj): """ Check if record exist by query_obj. :param query_obj: :return: None or record object. """ sql = prepare_query("labels", query_obj, ["label_id", "series_id", "user_id", "file_id", "content"]) cur = self.sql_connection.cursor() cur.execute(sql) result = cur.fetchall() result = [dict(item) for item in result] for record in result: if isinstance(record['content'], bytes): record['content'] = record['content'].decode('utf-8') else: record['content'] = record['content'] return result
def query(self, query_obj): """ Check if record exist by query_obj. :param query_obj: :return: None or record object. """ sql = prepare_query("series", query_obj, [ 'series_id', 'study_id', 'series_description', 'series_path', 'series_files_list', 'series_files_number', 'window_width', 'window_level', 'x_spacing', 'y_spacing', 'z_spacing', 'x_dimension', 'y_dimension', 'z_dimension', 'patient_id', 'series_instance_uid', 'study_date', 'intercept', 'slop', 'status' ]) cur = self.sql_connection.cursor() cur.execute(sql) result = cur.fetchall() result = [dict(item) for item in result] return result
def query(self, query_obj): """ Check if the user exist :param query_obj: :return: None|User_Obj """ orig_pwd: str = "" if "pwd" in query_obj: # Need to transfer pwd to encrypted. orig_pwd = query_obj['pwd'] del query_obj['pwd'] sql = prepare_query( "users", query_obj, ['user_id', 'email', 'name', 'init_code', 'user_type']) cur = self.sql_connection.cursor() cur.execute(sql) user = cur.fetchall() user = [dict(item) for item in user] if len(user) > 0 and orig_pwd != "": user = user[0] encryp_pwd = user['pwd'] is_correct_pwd = UserService.is_correct_password( encryp_pwd, orig_pwd) if is_correct_pwd: del user['pwd'] return [user] return [] if len(user) > 0: app.logger.debug(f"user exist: {user}") for i in user: del i['pwd'] return user