PHP Classes

Set dynamic variables on the fly

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  Set dynamic variables on the fly  
Subject:Set dynamic variables on the fly
Summary:DICOM file parsing
Messages:2
Author:Robert R. Brown
Date:2011-05-08 19:47:40
Update:2011-05-15 20:35:47
 

  1. Set dynamic variables on the fly   Reply   Report abuse  
Picture of Robert R. Brown Robert R. Brown - 2011-05-08 21:39:53
I have a database where I have 3 fields
-----------------------------------
Attribute_Name RV Tag
-----------------------------------

And the data looks like this:
-----------------------------------
Patient ID LO (0010,0020)
Patient Orientation CS (0020,0020)
Patient Orientation Code Sequence SQ (0054,0410)
Patient Orientation Modifier Code Sequence SQ (0054,0412)
Patient Position CS (0018,5100)
Patient Setup Number IS (300A,0182)
Patient Setup Sequence SQ (300A,0180)
Patient State LO (0038,0500)
Patient Support Angle DS (300A,0122)
Patient Support Angle Tolerance DS (300A,004C)
Patient Support Rotation Direction CS (300A,0123)
Patient Transport Arrangements LO (0040,1004)
Patient's Name PN (0010,0010)
Patient's Primary Language Code Modifier Sequence SQ (0010,0102)
Patient's Primary Language Code Sequence SQ (0010,0101)
Patient's Telephone Numbers SH (0010,2154)
Patient's Address LO (0010,1040)
Patient's Age AS (0010,1010)
Patient's Birth Date DA (0010,0030)
Patient's Birth Name PN (0010,1005)
Patient's Birth Time TM (0010,0032)
-----------------------------------


So I downloaded a DICOM parser class from http://www.nanodicom.org/
And I using one of the example to parse a DICOM Image file and the example works but I have to type in each "Attribute Name" and "Tag" so see the parsed data.

Orginal code looks like this:
-----------------------------------
// 5) Load simple and print certain value
try
{
echo "5) Load simple and print certain value\n";
$dicom = Nanodicom::factory($filename);
$dicom->parse();
echo $dicom->profiler_diff('parse')."\n";
echo 'Patient Name: '.$dicom->value(0x0010, 0x0010)."\n"; // Patient Name if exists
unset($dicom);
}
catch (Nanodicom_Exception $e)
{
echo 'File failed. '.$e->getMessage()."\n";
}
-----------------------------------

So what I'm trying to do is pull the data from the database and dynamically change the "0x0010, 0x0010" part of the "$dicom->value(0x0010, 0x0010)" line.

Here is my code:
-----------------------------------
$Database_Connection = mysql_connect($Database_Server, $Database_Username, $Database_Password) or die ("I can't connect to the database.");

require '../dicomparser/nanodicom.php';

$filename = 'B4IBG5A0';
$mode = 'LO';
$prefix = '0x';
$chars =array("(", ")", " ");

$sql = "SELECT * FROM premier_dicom.dicom_data WHERE VR = '".$mode."' ";
$rs = mysql_query($sql);


try
{
while($row = mysql_fetch_array($rs)) {
$row['Tag'] = str_replace($chars, "", $row['Tag']);
$tag_value = explode(',', $row['Tag']);
$tag_value_1 = $prefix.$tag_value['0'];
$tag_value_2 = $prefix.$tag_value['1'];
foreach($myarray as $key => $value) {
$dicom = Nanodicom::factory($filename);
$dicom->parse();
echo $key.': '.$dicom->value($tag_value_1, $tag_value_2);
echo "<br>";
//unset($dicom);
}
}
}
catch (Nanodicom_Exception $e)
{
echo 'File failed. '.$e->getMessage()."\n";
}
-----------------------------------

I have tried it a ton of different ways. And either it errors, displays nothing or diplays just the "(0x0010, 0x0010)". I have tried contacting the developer but no answer... his last post on his site was Dec 2010. So I'm assuming he isn't doing anything with the script anymore or something happened to him.

The weird part is if if I create an array like this:
-----------------------------------
$myArray['PatientName'] = $dicom->value(0x0010, 0x0010);

foreach($myArray as $key => $value) {
echo $key.': '.$value."<br>";
}
-----------------------------------
This works... but I can't dynamically create the $myArray as soon as I do this:

-----------------------------------
while($row = mysql_fetch_array($rs)) {
$row['Tag'] = str_replace($chars, "", $row['Tag']);
$tag_value = explode(',', $row['Tag']);
$tag_value_1 = $prefix.$tag_value['0'];
$tag_value_2 = $prefix.$tag_value['1'];
echo $myArray[$row['Attribute_Name']] => $dicom->value($tag_value_1, $tag_value_2);

-----------------------------------

When I loop through it doesn't work..

So can someone tell me how to dynamically change the "$dicom->value($tag_value_1, $tag_value_2)" line before I run out of hair? I have been messing with it for 4 days now.

Thanks,
Bob



There is 1 reply in this thread, which is not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.