@@ -101,7 +101,7 @@ class PACS implements PACSInterface {
* @var string $movescu
*/
private $ movescu = null ;
/**
* DCMTK EchoSCU binary location.
*
@@ -137,11 +137,11 @@ public function __construct($server_ip, $server_port, $user_aet = null) {
* @snippet test.pacs.class.php testPing()
*/
public function ping ($ timeout = 5 ){
$ command = $ this ->echoscu .' -to ' .$ timeout .' ' ;
$ command = $ this ->echoscu .' -to ' .$ timeout .' ' ;
$ this ->_finishCommand ($ command );
// execute the command, format it into a nice json and return it
return $ this ->_executeAndFormat ($ command );
$ this ->_finishCommand ($ command );
// execute the command, format it into a nice json and return it
return $ this ->_executeAndFormat ($ command );
}
/**
@@ -561,7 +561,7 @@ public function moveStudy(){
// execute query
$ output [] = $ query ;
shell_exec ($ query );
}
return $ output ;
@@ -584,7 +584,7 @@ public function moveSeries(){
{
$ command = $ this ->movescu .' -S' ;
$ command .= ' --aetitle ' .$ this ->user_aet ;
$ command .= ' --move ' . $ this -> user_aet ;
$ command .= ' --move FNNDSC-CHRISDEV' ;
$ command .= ' -k QueryRetrieveLevel=SERIES' ;
$ command .= ' -k StudyInstanceUID=' .$ this ->command_param ['StudyInstanceUID' ];
$ command .= ' -k SeriesInstanceUID=' .$ this ->command_param ['SeriesInstanceUID' ];
@@ -611,6 +611,13 @@ static public function process($filename){
$ requiered_fields .= ' +P InstanceNumber' ;
$ requiered_fields .= ' +P SeriesDescription' ;
// Study Information
$ requiered_fields .= ' +P Modality' ;
$ requiered_fields .= ' +P StudyDescription' ;
$ requiered_fields .= ' +P StudyDate' ;
$ requiered_fields .= ' +P StationName' ;
$ requiered_fields .= ' +P PatientAge' ;
// Patient information
$ requiered_fields .= ' +P PatientName' ;
$ requiered_fields .= ' +P PatientBirthDate' ;
@@ -794,39 +801,53 @@ static public function AddData(&$db, &$process_file, &$data_chris_id, &$series_d
//
$ dataObject ->uid = $ process_file ['SeriesInstanceUID' ][0 ];
//
// get data name (series description)
// get data name (protocol name)
//
if (array_key_exists ('ProtocolName' ,$ process_file ))
{
$ dataObject ->name = sanitize ($ process_file ['ProtocolName' ][0 ]);
}
else {
$ dataObject ->name = 'NoProtocolName' ;
}
//
// get data description (series description)
//
if (array_key_exists ('SeriesDescription' ,$ process_file ))
{
$ dataObject ->name = sanitize ($ process_file ['SeriesDescription' ][0 ]);
$ dataObject ->description = sanitize ($ process_file ['SeriesDescription' ][0 ]);
}
else {
$ dataObject ->name = 'NoSeriesDescription' ;
$ dataObject ->description = 'NoSeriesDescription' ;
}
$ series_description = $ dataObject ->name ;
//
// get data time ContentDate-ContentTime
//
// date
$ dataObject ->time = PACS ::getTime ($ process_file );
// get nb of files in data - only accessible through
// findscu query
/* $pacs = new PACS(PACS_SERVER, PACS_PORT, CHRIS_AETITLE);
$pacs->addParameter('RetrieveAETitle', '');
$pacs->addParameter('StudyInstanceUID', $result['StudyInstanceUID'][0]);
$pacs->addParameter('SeriesInstanceUID', $result['SeriesInstanceUID'][0]);
$pacs->addParameter('NumberOfSeriesRelatedInstances', '');
$all_results = $pacs->querySeries();
$dataObject->nb_files = $all_results['NumberOfSeriesRelatedInstances'][0]; */
//
// add the data model to db and get its id
//
$ data_chris_id = Mapper ::add ($ dataObject );
}
else {
$ data_chris_id = $ dataResult ['Data' ][0 ]->id ;
$ series_description = $ dataResult ['Data' ][0 ]->name ;
// todo: update time and status here...!
if ($ dataResult ['Data' ][0 ]->name == '' ){
if (array_key_exists ('ProtocolName' ,$ process_file ))
{
$ dataResult ['Data' ][0 ]->name = sanitize ($ process_file ['ProtocolName' ][0 ]);
}
else {
$ dataResult ['Data' ][0 ]->name = 'NoProtocolName' ;
}
$ series_description = $ dataResult ['Data' ][0 ]->name ;
Mapper ::update ($ dataResult ['Data' ][0 ], $ dataResult ['Data' ][0 ]->id );
}
else {
$ series_description = $ dataResult ['Data' ][0 ]->name ;
}
$ data_chris_id = $ dataResult ['Data' ][0 ]->id ;
}
}
else {
@@ -840,6 +861,107 @@ static public function AddData(&$db, &$process_file, &$data_chris_id, &$series_d
return 1 ;
}
static public 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 ->name = '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 );
}
$ study_description = $ studyObject ->date .'-' .$ studyObject ->description ;
$ studyObject ->age = PACS ::getAge ($ process_file );
$ studyObject ->location = PACS ::getLocation ($ process_file );
$ study_chris_id = Mapper ::add ($ studyObject );
}
else {
// Content to be updated
if ($ studyResult ['Study' ][0 ]->age == '' ){
//
// 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 ]->name = '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 );
$ study_description = $ studyResult ['Study' ][0 ]->date .'-' .$ studyResult ['Study' ][0 ]->description ;
$ study_chris_id = $ studyResult ['Study' ][0 ]->id ;
$ studyResult ['Study' ][0 ]->age = PACS ::getAge ($ process_file );
$ studyResult ['Study' ][0 ]->location = PACS ::getLocation ($ process_file );
Mapper ::update ($ studyResult ['Study' ][0 ], $ studyResult ['Study' ][0 ]->id );
}
// Content already up to date
else {
$ study_chris_id = $ studyResult ['Study' ][0 ]->id ;
$ study_description = $ studyResult ['Study' ][0 ]->date .'-' .$ 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 ;
}
static public function getTime ($ process_file ){
$ date = '' ;
if (array_key_exists ('ContentDate' ,$ process_file ))
@@ -863,5 +985,46 @@ static public function getTime($process_file){
return $ date .' ' . $ time ;
}
static public function getDate ($ process_file ){
$ date = '' ;
if (array_key_exists ('StudyDate' ,$ process_file ))
{
$ raw_date = $ process_file ['StudyDate' ][0 ];
$ date .= substr ($ raw_date , 0 , 4 ).'-' .substr ($ raw_date , 4 , 2 ).'-' .substr ($ raw_date , 6 , 2 );
}
else {
$ date .= '0000-00-00' ;
}
return $ date ;
}
static public function getAge ($ process_file ){
// should we use PatientAge tag???
$ age = '0' ;
if (array_key_exists ('ContentDate' ,$ process_file ) && array_key_exists ('PatientBirthDate' ,$ process_file ))
{
$ raw_bdate = $ process_file ['PatientBirthDate' ][0 ];
$ bdate = new DateTime (substr ($ raw_bdate , 0 , 4 ).'-' .substr ($ raw_bdate , 4 , 2 ).'-' .substr ($ raw_bdate , 6 , 2 ));
$ raw_cdate = $ process_file ['ContentDate' ][0 ];
$ cdate = new DateTime (substr ($ raw_cdate , 0 , 4 ).'-' .substr ($ raw_cdate , 4 , 2 ).'-' .substr ($ raw_cdate , 6 , 2 ));
$ raw_age = $ bdate ->diff ($ cdate );
$ age = $ raw_age ->days ;
}
return $ age ;
}
static public function getLocation ($ process_file ){
$ location = 'unknown' ;
if (array_key_exists ('StationName' ,$ process_file ))
{
$ location = $ process_file ['StationName' ][0 ];
}
return $ location ;
}
}
?>
?>