$search_value = GetVariable("search_value"); $search_type = GetVariable("search_type"); $search_swversion = GetVariable("search_swversion"); $imgperline = GetVariable("imgperline"); /* determine action */ switch($action) { case 'editform': DisplayStudyForm($id); break; case 'update': UpdateStudy($id, $modality, $studydatetime, $studyageatscan, $studyheight, $studyweight, $studytype, $studyoperator, $studyphysician, $studysite, $studynotes, $studydoradread, $studyradreaddate, $studyradreadfindings, $studyetsnellchart, $studyetvergence, $studyettracking, $studysnpchip, $studyaltid, $studyexperimenter); DisplayStudy($id, 0, 0, '', '', '', '','','',''); break; case 'movestudytosubject': MoveStudyToSubject($studyid, $enrollmentid, $newuid); break; case 'movestudytoproject': MoveStudyToProject($subjectid, $studyid, $newprojectid); break; case 'upload': Upload($modality, $studyid, $seriesid); DisplayStudy($studyid, 0, 0, '', '', '', '','','',''); break; case 'deleteconfirm': DeleteConfirm($id); break; case 'delete': Delete($id); break; case 'deleteseries':
function DoMergeSubjects($selectedid, $name, $dob, $gender, $ethnicity1, $ethnicity2, $handedness, $education, $phone1, $email, $maritalstatus, $smokingstatus, $altuid, $guid, $cancontact) { ?> <span class="tiny"> <ol> <? /* get list of subjectids that were not selected and will therefor be deleted*/ foreach ($name as $key => $value) { if ($key != $selectedid) { $extrasubjectids[] = $key; } } /* update the primary subject with the info */ /* perform data checks */ $name = mysql_real_escape_string($name[$selectedid]); $dob = mysql_real_escape_string($dob[$selectedid]); $gender = mysql_real_escape_string($gender[$selectedid]); $ethnicity1 = mysql_real_escape_string($ethnicity1[$selectedid]); $ethnicity2 = mysql_real_escape_string($ethnicity2[$selectedid]); $handedness = mysql_real_escape_string($handedness[$selectedid]); $education = mysql_real_escape_string($education[$selectedid]); $phone1 = mysql_real_escape_string($phone1[$selectedid]); $email = mysql_real_escape_string($email[$selectedid]); $maritalstatus = mysql_real_escape_string($maritalstatus[$selectedid]); $smokingstatus = mysql_real_escape_string($smokingstatus[$selectedid]); $cancontact = mysql_real_escape_string($cancontact[$selectedid]); $altuid = mysql_real_escape_string($altuid[$selectedid]); $guid = mysql_real_escape_string($guid[$selectedid]); $altuids = explode(',',$altuid); $sqlstring = "start transaction"; echo "<li><b>Starting transaction [$sqlstring]</b>"; $result = MySQLiQuery($sqlstring,__FILE__,__LINE__); /* move all of the studies from the other subjects to the primary subject */ $sqlstring = "select uid from subjects where subject_id = $selectedid"; echo "<li>Getting selected UID [$sqlstring]"; $result = MySQLQuery($sqlstring, __FILE__, __LINE__); $row = mysql_fetch_array($result, MYSQL_ASSOC); $newuid = $row['uid']; echo "<li>Getting study lists<ol>"; foreach ($extrasubjectids as $oldid) { /* get list of studies associated with the oldsubjectid */ $sqlstring = "select b.study_id from enrollment a left join studies b on a.enrollment_id = b.enrollment_id where a.subject_id = $oldid and b.study_id is not null"; echo "<li>Get study list for [$oldid] [$sqlstring]"; $result = MySQLQuery($sqlstring, __FILE__, __LINE__); echo "<ol>"; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $studyid = $row['study_id']; echo "<li>Running MoveStudyToSubject($studyid, $newuid)<br>"; MoveStudyToSubject($studyid, $newuid); } echo "</ol>"; /* delete the old subject after everything has been merged */ $sqlstring = "update subjects set isactive = 0 where subject_id = $oldid"; echo "<li>Deleting old subject [$oldid] [$sqlstring]"; $result = MySQLQuery($sqlstring, __FILE__, __LINE__); } echo "</ol>"; /* update the subject */ $sqlstring = "update subjects set name = '$name', birthdate = '$dob', gender = '$gender', ethnicity1 = '$ethnicity1', ethnicity2 = '$ethnicity2', handedness = '$handedness', education = '$education', phone1 = '$phone1', email = '$email', marital_status = '$maritalstatus', smoking_status = '$smokingstatus', guid = '$guid', cancontact = '$cancontact' where subject_id = $selectedid"; echo "<li>Updating subject [$sqlstring]"; $result = MySQLQuery($sqlstring, __FILE__, __LINE__); /* delete entries for this subject from the altuid table ... */ $sqlstring = "delete from subject_altuid where subject_id = $selectedid"; echo "<li>Deleting alternate IDs [$sqlstring]"; $result = MySQLQuery($sqlstring, __FILE__, __LINE__); echo "<ol>"; /* ... and insert the new rows into the altuids table */ foreach ($altuids as $altuid) { $altuid = trim($altuid); if (strpos($altuid, '*') !== FALSE) { $altuid = str_replace('*','',$altuid); $sqlstring = "insert ignore into subject_altuid (subject_id, altuid, isprimary) values ($selectedid, '$altuid',1)"; } else { $sqlstring = "insert ignore into subject_altuid (subject_id, altuid, isprimary) values ($selectedid, '$altuid',0)"; } echo "<li>Inserting new alternate UIDs [$sqlstring]"; $result = MySQLQuery($sqlstring, __FILE__, __LINE__); } /* ------ all done ------ */ $sqlstring = "commit"; //PrintSQL("$sqlstring"); echo "<li><b>Commit the transaction</b>"; $result = MySQLiQuery($sqlstring,__FILE__,__LINE__); ?></ol></ol><div align="center"><span class="message"><span class="uid"><?php echo FormatUID($uid); ?> </span> updated</span></div><br><br><? }