public static function AddStudy(&$db, &$process_file, &$study_chris_id, &$study_description) { $db->lock('study', 'WRITE'); // Does data exist: SeriesInstanceUID if (array_key_exists('StudyInstanceUID', $process_file)) { // does study exist?? $studyMapper = new Mapper('Study'); $studyMapper->filter('uid = (?)', $process_file['StudyInstanceUID'][0]); $studyResult = $studyMapper->get(); // if study doesn't exist, create it if (count($studyResult['Study']) == 0) { // create object // create data model $studyObject = new Study(); // // get data uid // $studyObject->uid = $process_file['StudyInstanceUID'][0]; // // get data name (series description) // if (array_key_exists('StudyDescription', $process_file)) { $studyObject->description = sanitize($process_file['StudyDescription'][0]); } else { $studyObject->description = 'NoStudyDescription'; } if (array_key_exists('Modality', $process_file)) { $studyObject->modality = sanitize($process_file['Modality'][0]); } else { $studyObject->modality = 'NoModality'; } if (array_key_exists('StudyDate', $process_file)) { $studyObject->date = PACS::getDate($process_file); } $studyObject->age = PACS::getAge($process_file); $studyObject->location = PACS::getLocation($process_file); $study_description = formatStudy($studyObject->date, $studyObject->age, $studyObject->description); $study_chris_id = Mapper::add($studyObject); } else { // Content to be updated if ($studyResult['Study'][0]->age == -1) { // // get data name (series description) // if (array_key_exists('StudyDescription', $process_file)) { $studyResult['Study'][0]->description = sanitize($process_file['StudyDescription'][0]); } else { $studyResult['Study'][0]->description = 'NoStudyDescription'; } if (array_key_exists('Modality', $process_file)) { $studyResult['Study'][0]->modality = sanitize($process_file['Modality'][0]); } else { $studyResult['Study'][0]->modality = 'NoModality'; } $studyResult['Study'][0]->date = PACS::getDate($process_file); $studyResult['Study'][0]->age = PACS::getAge($process_file); $studyResult['Study'][0]->location = PACS::getLocation($process_file); $study_description = formatStudy($studyResult['Study'][0]->date, $studyResult['Study'][0]->age, $studyResult['Study'][0]->description); $study_chris_id = $studyResult['Study'][0]->id; Mapper::update($studyResult['Study'][0], $studyResult['Study'][0]->id); } else { $study_chris_id = $studyResult['Study'][0]->id; $study_description = formatStudy($studyResult['Study'][0]->date, $studyResult['Study'][0]->age, $studyResult['Study'][0]->description); } } } else { echo 'Study UID not provided in DICOM file' . PHP_EOL; // finish data table lock $db->unlock(); return 0; } // finish data table lock $db->unlock(); return 1; }
$patientMapper->ljoin('Patient', 'Patient.id = Data_Patient.patient_id'); $patientMapper->filter('Data_Patient.data_id = (?)', $dataResult['Data'][0]->id); $patientResult = $patientMapper->get(); // create feed patient directories // mkdir if dir doesn't exist // create folder if doesnt exists $datadirname = $output_directory . '/' . $patientResult['Patient'][0]->uid . '-' . $patientResult['Patient'][0]->id; if (!is_dir($datadirname)) { mkdir($datadirname); } // study directory // get study description $studyMapper = new Mapper('Study'); $studyMapper->filter('uid = (?)', $process_file['StudyInstanceUID'][0]); $studyResult = $studyMapper->get(); $study_dir_name = formatStudy($studyResult['Study'][0]->date, $studyResult['Study'][0]->age, $studyResult['Study'][0]->description) . '-' . $studyResult['Study'][0]->id; $studydirname = $datadirname . '/' . $study_dir_name; if (!is_dir($studydirname)) { mkdir($studydirname); } // create data soft links $targetbase = CHRIS_DATA . '/' . $patientResult['Patient'][0]->uid . '-' . $patientResult['Patient'][0]->id; $series_dir_name = $dataResult['Data'][0]->description . '-' . $dataResult['Data'][0]->name; $seriesdirnametarget = $targetbase . '/' . $study_dir_name . '/' . $series_dir_name . '-' . $dataResult['Data'][0]->id; $seriesdirnamelink = $datadirname . '/' . $study_dir_name . '/' . $series_dir_name . '-' . $dataResult['Data'][0]->id; if (!is_link($seriesdirnamelink)) { // create sof link symlink($seriesdirnametarget, $seriesdirnamelink); } $waiting = false; } else {
$processLog .= 'datemax: '. $input.PHP_EOL; */ } $fh = fopen($logFile, 'a') or die("can't open file"); fwrite($fh, $processLog); fclose($fh); $processLog = '=======================================' . PHP_EOL; $processLog .= date('Y-m-d h:i:s') . ' ---> Process results...' . PHP_EOL; $results = $mapper->get(); if (count($results['Data']) >= 1) { foreach ($results['Data'] as $key => $value) { $processLog .= $results['Patient'][$key]->id . PHP_EOL; // create patient directory $fs_location = $results['Patient'][$key]->uid . '-' . $results['Patient'][$key]->id; $patientdir = $output_dir . $fs_location; // create study directory $fs_location .= '/' . formatStudy($results['Study'][$key]->date, $results['Study'][$key]->age, $results['Study'][$key]->description) . '-' . $results['Study'][$key]->id; $studydir = $output_dir . $fs_location; // create data symlink // loop through results and create links $processLog .= date('Y-m-d h:i:s') . ' Creates soft link for Patient' . PHP_EOL; // create data soft links $name = ''; if (file_exists(CHRIS_DATA . '/' . $fs_location . '/' . $value->description . '-' . $value->name . '-' . $value->id)) { $name = $value->description . '-' . $value->name . '-' . $value->id; } else { if (file_exists(CHRIS_DATA . '/' . $fs_location . '/' . $value->name . '-' . $value->id)) { // legacy, old dicom listener $name = $value->name . '-' . $value->id; } } if ($name != '') {