0001 function subinfo = mysql_get_subinfo(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 ensemble_globals;
0023
0024
0025 subinfo = ensemble_init_data_struct;
0026
0027 extract_vars = {};
0028
0029
0030 narg = length(varargin);
0031 for iarg = 1:2:narg
0032 switch varargin{iarg}
0033 case {'subject_id','subject_ids'}
0034 subids = varargin{iarg+1};
0035 case {'mysql','ensemble'}
0036 params = varargin{iarg+1};
0037 case {'extract_vars'}
0038 extract_vars = varargin{iarg+1};
0039 otherwise
0040 fprintf('mysql_get_subinfo: Unknown input argument: %s\n', varargin{iarg});
0041 end
0042 end
0043
0044 if isfield(params,'conn_id')
0045 conn_id = params.conn_id;
0046 else
0047 conn_id = [];
0048 end
0049
0050 if isfield(params,'enc_key')
0051 enc_key = params.enc_key;
0052 else
0053 enc_key = '';
0054 end
0055
0056
0057 tmp_conn_id = false;
0058 if isempty(conn_id) || isempty(enc_key)
0059 if ~exist('params','var') || ~isfield(params,'conn_id') || ...
0060 ~isfield(params,'user') || ~isfield(params,'passwd') || ...
0061 ~isfield(params,'host') || ~isfield(params,'database')
0062 error('%s: Insufficient information for establishing database connection', mfilename)
0063 end
0064
0065 params.login_type = 'researcher';
0066 params = mysql_login(params);
0067
0068
0069
0070 if mysql(params.conn_id,'status')
0071 tmp_conn_id = true;
0072 else
0073 tmp_conn_id = false;
0074 end
0075
0076 conn_id = mysql_make_conn(params);
0077 end
0078
0079 subinfo.type = 'subject_info';
0080
0081
0082 enc_fields = encrypted_fields.subject;
0083
0084 [subinfo.data, subinfo.vars] = mysql_extract_data('table','subject',...
0085 'subject_id',subids,...
0086 'encrypted_fields',enc_fields,...
0087 'enc_key',params.enc_key, ...
0088 'extract_vars', extract_vars, ...
0089 'conn_id',conn_id);
0090
0091
0092 if tmp_conn_id
0093 mysql(conn_id,'close');
0094 end
0095
0096 return