0001 function sinfo = mysql_get_sinfo(subid,params)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 sinfo = [];
0039
0040
0041 msg = nargchk(1,2,nargin);
0042 if ~isempty(msg)
0043 disp(msg)
0044 return
0045 end
0046
0047
0048 if isempty(params) || ~isfield(params,'conn_id') || ...
0049 isempty(params.conn_id) || mysql(params.conn_id,'status')
0050 error('%s: Do not have a valid connection ID', mfilename);
0051 end
0052
0053
0054 sinfo = ...
0055 struct('datenum',[],'gender','','name_last','','name_first','','exp_ids',[],'sess_ids',[],'exp_date',[],'exp_names',{''});
0056
0057 if isfield(params,'enc_key') && ~isempty(params.enc_key)
0058 mysql_str = sprintf(['select date_entered, aes_decrypt(`dob`,''%s''),'...
0059 ' gender, aes_decrypt(`name_last`,''%s''), '...
0060 'aes_decrypt(`name_first`,''%s'') from subject '...
0061 'where subject_id="%s";'],...
0062 params.enc_key,params.enc_key,params.enc_key,subid);
0063 else
0064 mysql_str = sprintf(['select date_entered, dob, gender, name_last, '...
0065 'name_first from subject where subject_id="%s";'],subid);
0066 end
0067 [date_entered...
0068 sinfo.datenum, sinfo.gender, sinfo.name_last, sinfo.name_first] = ...
0069 mysql(params.conn_id, mysql_str);
0070
0071
0072 try sinfo.datenum = datenum(sinfo.datenum);
0073 catch sinfo.datenum = 'encrypted'; end
0074
0075
0076
0077
0078
0079
0080
0081
0082 crit_datenum = 732637;
0083
0084 if date_entered >= crit_datenum
0085
0086 mysql_str = sprintf('SELECT experiment_id, session_id, date_time FROM session WHERE subject_id="%s";', subid);
0087 [sinfo.exp_ids, sinfo.sess_ids, sinfo.exp_date] = mysql(params.conn_id, mysql_str);
0088
0089
0090 expids = sprintf('%d,', sinfo.exp_ids(:));
0091 expids(end) = [];
0092 mysql_str = sprintf(['SELECT experiment_title, experiment_id FROM experiment WHERE' ...
0093 ' experiment_id IN (%s);'], expids);
0094 [sinfo.exp_names, sinfo.exp_name_ids] = mysql(params.conn_id, mysql_str);
0095
0096 else
0097
0098
0099 mysql_str = 'SELECT experiment_id, experiment_title, response_table FROM experiment;';
0100 [expids, exptitles, resp_tbls] = mysql(params.conn_id, mysql_str);
0101
0102
0103
0104 ntbl = length(resp_tbls);
0105 tbl_mask = zeros(1,ntbl);
0106 for itbl = 1:ntbl
0107 if isempty(resp_tbls{itbl})
0108 continue
0109 end
0110 mysql_str = sprintf('SELECT subject_id FROM %s WHERE subject_id="%s";', resp_tbls{itbl}, subid);
0111 sublist = mysql(params.conn_id, mysql_str);
0112 if ~isempty(sublist)
0113 tbl_mask(itbl) = 1;
0114 end
0115 end
0116
0117 exp_idxs = find(tbl_mask);
0118 sinfo.exp_ids = expids(exp_idxs);
0119 sinfo.exp_names = exptitles(exp_idxs);
0120
0121
0122 for itbl = 1:length(exp_idxs)
0123 mysql_str = sprintf('SELECT date_time, session_id FROM %s where subject_id="%s"', resp_tbls{exp_idxs(itbl)}, subid);
0124 [dateinfo, session_ids] = mysql(params.conn_id, mysql_str);
0125 [sessids,sess_offsets] = unique(session_ids);
0126 for isess = 1:length(sessids)
0127 sinfo.exp_date{itbl}(isess) = dateinfo(sess_offsets(isess));
0128 end
0129 end
0130
0131 end