Reading tags from PDVInputStream - dcmqrscp

837 views
Skip to first unread message

NikDcm

unread,
May 10, 2014, 11:38:51 PM5/10/14
to
Hi all,

I'm trying to read a dicom tag (PatientName) from PDVInputStream and I'm getting a null value.

I added the lines in red. 

Any hint ?


    private void storeTo(Association as, Attributes fmi, 
            PDVInputStream data, File file) throws IOException  {
        LOG.info("{}: M-WRITE {}", as, file);
        file.getParentFile().mkdirs();
        DicomOutputStream out = new DicomOutputStream(file);
        
        try {
            out.writeFileMetaInformation(fmi);
            data.copyTo(out);
 
            
            String sPatientName = "";           
            String sTransferSyntax ="";
            sTransferSyntax = fmi.getString(org.dcm4che2.data.Tag.TransferSyntaxUID);
            sPatientName =  data.readDataset(sTransferSyntax).getString(Tag.PatientName);
            LOG.info("The patient name is : "+ sPatientName); 


             
        } finally {
            SafeClose.close(out);           
        }
    }

Btw, the dicom file has the next TransferSyntax

tsuid=1.2.840.10008.1.2.1 - Explicit VR Little Endian


Maybe the data.readDataset parameter, which is in this case (TransferSyntaxUID), it is not the one I need ??

Thanks !

Nicolas

NikDcm

unread,
May 11, 2014, 8:10:58 PM5/11/14
to
Hi,

In dcmqrscp from dcm4che3, I can't do this :

 DicomObject data = dataStream.readDataset();

Since DicomObject is no available  and also readDataset() from DicomInpuStream,  in dcm4che3.

hmm... that made me change the code like the below lines in blue :

    private void storeTo(Association as, Attributes fmi, 
            PDVInputStream data, File file) throws IOException  {
        LOG.info("{}: M-WRITE {}", as, file);
        file.getParentFile().mkdirs();
        DicomOutputStream out = new DicomOutputStream(file);
        
        try {
            out.writeFileMetaInformation(fmi);
            data.copyTo(out);
             
            String sPatientName = "";           
            String sTransferSyntax ="";
            sTransferSyntax = fmi.getString(org.dcm4che2.data.Tag.TransferSyntaxUID);
            FileInputStream f = new FileInputStream(file.getAbsolutePath());
            BufferedInputStream b = new BufferedInputStream(f);
            DicomInputStream din = new DicomInputStream(b,sTransferSyntax);
            Attributes attribs = din.readDataset(-1, Tag.PatientName);
            din.close();
            sPatientName = attribs.getString(Tag.PatientName);
            LOG.info("The patient name is : "+ sPatientName);             
             
        } finally {
            SafeClose.close(out);           
        }
    }


But when I start the listener 

DICOMDIR=/home/nicolas/herramientas/dicom/IDAPACS/idadcmqrscp/bin/DICOMDIR
PORT=104
IP=127.0.0.1
PACSAETITLE=IDADCMQRSCP
sudo ./dcmqrscp -b $PACSAETITLE@$IP:$PORT --dicomdir $DICOMDIR




I get this ...

20:54:39,238 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,238 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,238 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,239 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,239 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,239 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,239 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,239 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,239 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,239 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,239 WARN  - Unrecogniced VR code: {0}H - treat as UN
20:54:39,304 WARN  - IOException during read of (0000,0000) #1296255300 @ 120
java.io.EOFException
at org.dcm4che3.util.StreamUtils.readFully(StreamUtils.java:63)
at org.dcm4che3.io.DicomInputStream.readFully(DicomInputStream.java:377)
at org.dcm4che3.io.DicomInputStream.readValue(DicomInputStream.java:711)
at org.dcm4che3.io.DicomInputStream.readValue(DicomInputStream.java:517)
at org.dcm4che3.io.DicomInputStream.readAttributes(DicomInputStream.java:488)
at org.dcm4che3.io.DicomInputStream.readDataset(DicomInputStream.java:418)
at org.dcm4che3.tool.dcmqrscp.DcmQRSCP.storeTo(DcmQRSCP.java:409)
at org.dcm4che3.tool.dcmqrscp.DcmQRSCP.access$1(DcmQRSCP.java:393)
at org.dcm4che3.tool.dcmqrscp.DcmQRSCP$CStoreSCPImpl.store(DcmQRSCP.java:181)
at org.dcm4che3.net.service.BasicCStoreSCP.onDimseRQ(BasicCStoreSCP.java:72)
at org.dcm4che3.net.service.DicomServiceRegistry.onDimseRQ(DicomServiceRegistry.java:86)
at org.dcm4che3.net.ApplicationEntity.onDimseRQ(ApplicationEntity.java:391)
at org.dcm4che3.net.Association.onDimseRQ(Association.java:646)
at org.dcm4che3.net.PDUDecoder.decodeDIMSE(PDUDecoder.java:459)
at org.dcm4che3.net.Association.handlePDataTF(Association.java:630)
at org.dcm4che3.net.State$4.onPDataTF(State.java:103)
at org.dcm4che3.net.Association.onPDataTF(Association.java:626)
at org.dcm4che3.net.PDUDecoder.nextPDU(PDUDecoder.java:177)
at org.dcm4che3.net.Association$2.run(Association.java:476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
20:54:39,313 INFO  - SENDER+1: processing 1:C-STORE-RQ[pcid=1, prior=2
  cuid=1.2.840.10008.5.1.4.1.1.1 - Computed Radiography Image Storage
  iuid=1.2.392.200036.9125.4.0.185563003.3873842944.84852432 - ?
  tsuid=1.2.840.10008.1.2.1 - Explicit VR Little Endian failed:
org.dcm4che3.net.service.DicomServiceException: java.io.EOFException
at org.dcm4che3.tool.dcmqrscp.DcmQRSCP$CStoreSCPImpl.store(DcmQRSCP.java:196)
at org.dcm4che3.net.service.BasicCStoreSCP.onDimseRQ(BasicCStoreSCP.java:72)
at org.dcm4che3.net.service.DicomServiceRegistry.onDimseRQ(DicomServiceRegistry.java:86)
at org.dcm4che3.net.ApplicationEntity.onDimseRQ(ApplicationEntity.java:391)
at org.dcm4che3.net.Association.onDimseRQ(Association.java:646)
at org.dcm4che3.net.PDUDecoder.decodeDIMSE(PDUDecoder.java:459)
at org.dcm4che3.net.Association.handlePDataTF(Association.java:630)
at org.dcm4che3.net.State$4.onPDataTF(State.java:103)
at org.dcm4che3.net.Association.onPDataTF(Association.java:626)
at org.dcm4che3.net.PDUDecoder.nextPDU(PDUDecoder.java:177)
at org.dcm4che3.net.Association$2.run(Association.java:476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at org.dcm4che3.util.StreamUtils.readFully(StreamUtils.java:63)
at org.dcm4che3.io.DicomInputStream.readFully(DicomInputStream.java:377)
at org.dcm4che3.io.DicomInputStream.readValue(DicomInputStream.java:711)
at org.dcm4che3.io.DicomInputStream.readValue(DicomInputStream.java:517)
at org.dcm4che3.io.DicomInputStream.readAttributes(DicomInputStream.java:488)
at org.dcm4che3.io.DicomInputStream.readDataset(DicomInputStream.java:418)
at org.dcm4che3.tool.dcmqrscp.DcmQRSCP.storeTo(DcmQRSCP.java:409)
at org.dcm4che3.tool.dcmqrscp.DcmQRSCP.access$1(DcmQRSCP.java:393)
at org.dcm4che3.tool.dcmqrscp.DcmQRSCP$CStoreSCPImpl.store(DcmQRSCP.java:181)
... 13 more
20:54:39,314 INFO  - SENDER+1 << 1:C-STORE-RSP[pcid=1, status=110H, errorComment=java.io.EOFException
  tsuid=1.2.840.10008.1.2.1 - Explicit VR Little Endian
20:54:39,315 DEBUG - Command:
(0000,0100) US [32769] CommandField
(0000,0120) US [1] MessageIDBeingRespondedTo
(0000,0800) US [257] CommandDataSetType
(0000,0900) US [272] Status
(0000,0902) LO [java.io.EOFException] ErrorComment


Holy crap .. This is getting worse ...
Despite I'm loading the dicom image from file again ..I know.

.

NikDcm

unread,
May 13, 2014, 10:20:55 AM5/13/14
to dcm...@googlegroups.com
Hi,

No one has an idea?

Please, Throw me a  bone ...

NikDcm

unread,
May 13, 2014, 6:39:19 PM5/13/14
to dcm...@googlegroups.com
Hi,

I've found this from Gunter :

The error is caused by the wrong encoding of items of private sequence
 
2526: (0029,1140) SQ #-1
2538: >(FFFE,E000) #-1 Item #1

They are encoded with Explicit VR Little Endian Transfer Syntax, but should be with Implicit VR Little Endian:

DICOM 2011 Part 5, p.32
6.2.2 Unknown (UN) Value Representation
Notes:

4. The length field of the Value Representation of UN may contain the value of unknown length”, in which
case the contents can be assumed to be encoded with implicit VR. See section 7.5.1 to determine how
to parse Data Elements with an unknown length.

Because the items are itself encoded with unknown length (= 0xffffffff), they cannot be simple skipped by the parser.

I will add a DicomInputStream property "decodeUNWithIVRLE"  which may be set to false, for reading such faulty decoded objects.

gunter


So , that means that the method readDataset only works with  Implicit VR Little-endian,  which is
1.2.840.10008.1.2


and  I do have this,

tsuid=1.2.840.10008.1.2.1 - Explicit VR Little Endian

I also tried with a different image, which is Implicit VR Little-endian, but It didn't work either.

...

Mehmet Şen

unread,
Jul 28, 2014, 9:29:54 AM7/28/14
to dcm...@googlegroups.com

 This is my way that works:

private BasicCStoreSCP cstoreSCP = new BasicCStoreSCP("*") {

       
@Override
       
protected void store(Association as, PresentationContext pc,
               
Attributes rq, PDVInputStream data, Attributes rsp)
               
throws IOException {
            rsp
.setInt(Tag.Status, VR.US, status);
           
            logger
.info("--------Let's start to store a dicom file!---------");            
           
           
if (destination == null) {
                logger
.info("Destination is null, please specify a storage destination!");
           
}
           
else{                
           
               
try {
                   
                       
String ipAddress  = as.getSocket().getInetAddress().getHostAddress(); //ip address                
                       
String cuid = rq.getString(Tag.AffectedSOPClassUID);
                       
String iuid = rq.getString(Tag.AffectedSOPInstanceUID);              
                       
String tsuid = pc.getTransferSyntax();    
                   
                       
File file  = new File(destination, iuid);        
                       
Attributes fmi = as.createFileMetaInformation(iuid, cuid, tsuid);                        
                       storeTo
(as, fmi, data, file);
                   
                   
                   
DicomInputStream in = null;
                   
Attributes attrs = null;
                   
try {
                       
in = new DicomInputStream(file);
                       
in.setIncludeBulkData(IncludeBulkData.URI);
                        attrs
= in.readDataset(-1, -1);
                   
}
                   
catch(Exception ex){
                        logger
.error(ex.getMessage());
                   
}
                   
                   
String studyiuid=null;
                   
String patID=null;
                   
String patName=null;
                   
String institutionName=null;
                   
                       
if(attrs != null){
                            studyiuid
= attrs.getString(Tag.StudyInstanceUID);                
                            patID
= attrs.getString(Tag.PatientID);
                            patID
= (patID == null || patID.length() == 0) ? "<UNKNOWN>" : patID;
                            patName
= attrs.getString(Tag.PatientName);
                            institutionName
= attrs.getString(Tag.InstitutionName);
                       
}
                     
                    logger
.info("New dicom file received -> StudyInstanceUID:"+studyiuid+" PatientID:"+patID+" PatientName:"+patName+ " InstitutionName:"+institutionName);                    
                    logger
.info("let's notify the listeners");
                   
                   
ResponseMsg response = new ResponseMsg("new file recieved", file, this, ipAddress, as);                    
                   
Event event = new Event(this, response);                    
                    notifyListeners
(event);
                   
               
} catch (Exception e) {                
                    logger
.error("Dicom Store Exception:"+e.getMessage());
                   
throw new DicomServiceException(Status.ProcessingFailure, e);
               
}
           
}
       
}

   
};




private void storeTo(Association as, Attributes fmi,
           
PDVInputStream data, File file) throws IOException  {

       
//LOG.info("{}: M-WRITE {}", as, file);
        logger
.info("We received the file. Let's store file to "+file.getParentFile().getAbsolutePath());

        file
.getParentFile().mkdirs();
       
DicomOutputStream out = new DicomOutputStream(file);
       
try {
           
out.writeFileMetaInformation(fmi);
            data
.copyTo(out);
           
       
} finally {
           
SafeClose.close(out);
       
}
   
}




On Saturday, May 10, 2014 10:35:25 PM UTC-5, NikDcm wrote:
Hi all,

I'm trying to read a dicom tag (PatientName) from PDVInputStream and I'm getting a null value.

I added the lines in red. 

Any hint ?
    private void storeTo(Association as, Attributes fmi, 
            PDVInputStream data, File file) throws IOException  {
        LOG.info("{}: M-WRITE {}", as, file);
        file.getParentFile().mkdirs();
        DicomOutputStream out = new DicomOutputStream(file);
        
        try {
            out.writeFileMetaInformation(fmi);
            data.copyTo(out);
 
            
            String sPatientName = "";           
            String sTransferSyntax ="";
            sTransferSyntax = fmi.getString(org.dcm4che2.data.Tag.TransferSyntaxUID);
            sPatientName =  data.readDataset(sTransferSyntax).getString(Tag.PatientName);
            LOG.info("The patient name is : "+ sPatientName); 


             
        } finally {
            SafeClose.close(out);           
        }
    }
Btw, the dicom file has the next TransferSyntax
tsuid=1.2.840.10008.1.2.1 - Explicit VR Little Endian


Maybe the data.readDataset parameter, which is in this case (TransferSyntaxUID), it is not the one I need ??

Thanks !

Nicolas

Reply all
Reply to author
Forward
0 new messages