示例#1
0
 private DicomObject mkStgCmtResult(Association as, DicomObject rqdata) {
   DicomObject result = new BasicDicomObject();
   result.putString(Tag.TransactionUID, VR.UI, rqdata.getString(Tag.TransactionUID));
   DicomElement rqsq = rqdata.get(Tag.ReferencedSOPSequence);
   DicomElement resultsq = result.putSequence(Tag.ReferencedSOPSequence);
   if (stgcmtRetrieveAET != null) {
     result.putString(Tag.RetrieveAETitle, VR.AE, stgcmtRetrieveAET);
   }
   DicomElement failedsq = null;
   File dir = getDir(as);
   for (int i = 0, n = rqsq.countItems(); i < n; i++) {
     DicomObject rqItem = rqsq.getDicomObject(i);
     String uid = rqItem.getString(Tag.ReferencedSOPInstanceUID);
     DicomObject resultItem = new BasicDicomObject();
     rqItem.copyTo(resultItem);
     if (stgcmtRetrieveAETs != null) {
       resultItem.putString(Tag.RetrieveAETitle, VR.AE, stgcmtRetrieveAETs);
     }
     File f = new File(dir, uid);
     if (f.isFile()) {
       resultsq.addDicomObject(resultItem);
     } else {
       resultItem.putInt(Tag.FailureReason, VR.US, NO_SUCH_OBJECT_INSTANCE);
       if (failedsq == null) {
         failedsq = result.putSequence(Tag.FailedSOPSequence);
       }
       failedsq.addDicomObject(resultItem);
     }
   }
   return result;
 }
示例#2
0
 private DicomObject toSCN(DicomObject ian) {
   DicomObject scn = new BasicDicomObject();
   scn.putString(Tag.PatientID, VR.LO, ian.getString(Tag.PatientID));
   scn.putString(Tag.PatientName, VR.PN, ian.getString(Tag.PatientName));
   scn.putString(Tag.StudyID, VR.SH, ian.getString(Tag.StudyID));
   scn.putString(Tag.StudyInstanceUID, VR.UI, ian.getString(Tag.StudyInstanceUID));
   DicomElement ianSeriesSeq = ian.get(Tag.ReferencedSeriesSequence);
   DicomElement scnSeriesSeq = scn.putSequence(Tag.ReferencedSeriesSequence);
   DicomObject ianSeriesItem, scnSeriesItem, scnSOPItem;
   DicomElement ianSOPSeq, scnSOPSeq;
   for (int i = 0, n = ianSeriesSeq.countItems(); i < n; ++i) {
     ianSeriesItem = ianSeriesSeq.getDicomObject(i);
     scnSeriesItem = new BasicDicomObject();
     scnSeriesItem.putString(
         Tag.SeriesInstanceUID, VR.UI, ianSeriesItem.getString(Tag.SeriesInstanceUID));
     scnSeriesSeq.addDicomObject(scnSeriesItem);
     ianSOPSeq = ianSeriesItem.get(Tag.ReferencedSOPSequence);
     scnSOPSeq = scnSeriesItem.putSequence(Tag.ReferencedImageSequence);
     for (int j = 0, m = ianSOPSeq.countItems(); j < m; ++j) {
       scnSOPItem = new BasicDicomObject();
       ianSOPSeq.getDicomObject(j).exclude(INSTANCE_AVAILABILITY).copyTo(scnSOPItem);
       scnSOPSeq.addDicomObject(scnSOPItem);
     }
   }
   return scn;
 }
 /**
  * Set query attributes for C-Move
  *
  * @return DicomObject contains initial set of attributes for query
  */
 private DicomObject setCmoveAttributes() {
   DicomObject returnObject = new BasicDicomObject();
   returnObject.putString(Tag.SOPClassUID, VR.UI, UID.RTPlanStorage);
   returnObject.putString(Tag.SOPInstanceUID, VR.UI, "1.2.34.56");
   returnObject.putString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE");
   returnObject.putString(Tag.PatientID, VR.LO, "");
   returnObject.putString(Tag.StudyInstanceUID, VR.UI, "1.2.1.1");
   returnObject.putString(Tag.SeriesInstanceUID, VR.UI, "1.2.1.2");
   return returnObject;
 }
示例#4
0
  protected static DicomObject createDicomMetaData(
      MimeType mimeType,
      String filename,
      String description,
      TCReferencedInstance ref,
      String patId,
      String issuerOfPatId,
      String patName,
      String modality) {
    Date now = new Date();

    DicomObject attrs = new BasicDicomObject();

    // patient level
    if (patId != null) {
      attrs.putString(Tag.PatientID, VR.LO, patId);
    }
    if (issuerOfPatId != null) {
      attrs.putString(Tag.IssuerOfPatientID, VR.LO, issuerOfPatId);
    }
    if (patName != null) {
      attrs.putString(Tag.PatientName, VR.PN, patName);
    }

    // study level
    attrs.putString(Tag.StudyInstanceUID, VR.UI, ref.getStudyUID());

    // series level
    attrs.putString(Tag.SeriesInstanceUID, VR.UI, ref.getSeriesUID());
    attrs.putString(Tag.SeriesDescription, VR.LO, SERIES_DESCRIPTION);
    attrs.putString(Tag.Modality, VR.CS, modality);

    // instance level
    attrs.putString(Tag.SOPInstanceUID, VR.UI, ref.getInstanceUID());
    attrs.putString(Tag.SOPClassUID, VR.UI, ref.getClassUID());
    attrs.putInt(Tag.InstanceNumber, VR.IS, ref.getInstanceNumber());
    attrs.putDate(Tag.InstanceCreationDate, VR.DA, now);
    attrs.putDate(Tag.InstanceCreationTime, VR.TM, now);
    attrs.putDate(Tag.ContentDate, VR.DA, now);
    attrs.putDate(Tag.ContentTime, VR.TM, now);
    attrs.putString(Tag.ContentLabel, VR.CS, filename);
    attrs.putString(
        Tag.ContentDescription,
        VR.CS,
        description != null && !description.isEmpty() ? description : getFileName(filename));

    return attrs;
  }
 private DicomStreamMetaData copyMeta(DicomImageReader reader, String tsuid) throws IOException {
   DicomStreamMetaData oldMeta = (DicomStreamMetaData) reader.getStreamMetadata();
   DicomStreamMetaData ret = new DicomStreamMetaData();
   DicomObject ds = oldMeta.getDicomObject();
   DicomObject newDs = new BasicDicomObject();
   ds.copyTo(newDs);
   newDs.putString(Tag.TransferSyntaxUID, VR.UI, tsuid);
   ret.setDicomObject(newDs);
   return ret;
 }
示例#6
0
 private int sendIAN(String aet, DicomObject ian)
     throws IOException, InterruptedException, GeneralSecurityException {
   String iuid = UIDUtils.createUID();
   Association assoc = open(aet);
   TransferCapability tc =
       assoc.getTransferCapabilityAsSCU(UID.InstanceAvailabilityNotificationSOPClass);
   RspHandler rspHandler = new RspHandler();
   if (tc == null) {
     tc = assoc.getTransferCapabilityAsSCU(UID.BasicStudyContentNotificationSOPClassRetired);
     if (tc == null) {
       throw new NoPresentationContextException(
           UIDDictionary.getDictionary()
               .prompt(
                   isOfferStudyContentNotification()
                       ? UID.BasicStudyContentNotificationSOPClassRetired
                       : UID.InstanceAvailabilityNotificationSOPClass));
     }
     String tsuid = tc.getTransferSyntax()[0];
     DicomObject scn = toSCN(ian);
     scn.putString(Tag.SOPInstanceUID, VR.UI, iuid);
     scn.putString(Tag.SOPClassUID, VR.UI, UID.BasicStudyContentNotificationSOPClassRetired);
     LOG.debug("Study Content Notification to {}:\n{}", aet, scn);
     assoc.cstore(
         UID.BasicStudyContentNotificationSOPClassRetired,
         iuid,
         priority,
         new DataWriterAdapter(scn),
         tsuid,
         rspHandler);
   } else {
     String tsuid = tc.getTransferSyntax()[0];
     LOG.debug("Instance Availability Notification to {}:\n{}", aet, ian);
     assoc.ncreate(UID.InstanceAvailabilityNotificationSOPClass, iuid, ian, tsuid, rspHandler);
   }
   assoc.waitForDimseRSP();
   try {
     assoc.release(true);
   } catch (InterruptedException t) {
     LOG.error("Association release failed! aet:" + aet, t);
   }
   return rspHandler.getStatus();
 }
示例#7
0
 public DicomObject getAttributes(boolean cfindrsp) {
   DicomObject dataset = DicomObjectUtils.decode(encodedAttributes);
   if (cfindrsp) {
     dataset.putInt(Tag.NumberOfSeriesRelatedInstances, VR.IS, numberOfSeriesRelatedInstances);
     if (fileSetUID != null && fileSetID != null) {
       dataset.putString(Tag.StorageMediaFileSetUID, VR.UI, fileSetUID);
       dataset.putString(Tag.StorageMediaFileSetID, VR.SH, fileSetID);
     }
     if (retrieveAETs != null || externalRetrieveAET != null) {
       dataset.putString(
           Tag.RetrieveAETitle,
           VR.AE,
           externalRetrieveAET == null
               ? retrieveAETs
               : retrieveAETs == null
                   ? externalRetrieveAET
                   : retrieveAETs + '\\' + externalRetrieveAET);
     }
     dataset.putString(Tag.InstanceAvailability, VR.CS, availability.name());
   }
   return dataset;
 }
示例#8
0
    public static TCEncapsulatedDocument create(
        TCObject tc, MimeType mimeType, String filename, InputStream in, String description)
        throws Exception {

      if (mimeType == null || !DOC_TYPES.contains(mimeType.getDocumentType())) {
        throw new Exception("Mime-Type is not supported (" + mimeType + ")");
      }

      TCReferencedInstance ref = createReferencedInstance(tc, UID.EncapsulatedPDFStorage, MODALITY);

      DicomObject metaData =
          TCDocumentObject.createDicomMetaData(
              mimeType,
              filename,
              description,
              ref,
              tc.getPatientId(),
              tc.getPatientIdIssuer(),
              tc.getPatientName(),
              MODALITY);
      metaData.putString(Tag.TransferSyntaxUID, VR.UI, UID.ExplicitVRLittleEndian);
      metaData.putString(
          Tag.DocumentTitle,
          VR.ST,
          description != null && !description.isEmpty() ? description : getFileName(filename));
      metaData.putString(Tag.MIMETypeOfEncapsulatedDocument, VR.LO, mimeType.getMimeTypeString());
      metaData.putString(Tag.BurnedInAnnotation, VR.CS, "NO"); // $NON-NLS-1$
      metaData.putSequence(Tag.ConceptNameCodeSequence, 0);

      try {
        return new TCEncapsulatedDocument(mimeType, ref, metaData, IOUtils.toByteArray(in));
      } finally {
        if (in != null) {
          in.close();
        }
      }
    }
示例#9
0
    private static DicomObject toDicom(BufferedImage image) throws Exception {
      int numSamples = image.getColorModel().getNumComponents();
      if (numSamples == 4) {
        numSamples = 3;
      }
      String pmi = numSamples > 1 ? "RGB" : "MONOCHROME2";
      int bits = image.getColorModel().getComponentSize(0);
      int allocated = 8;
      if (bits > 8) {
        allocated = 16;
      }

      DicomObject attrs = new BasicDicomObject();
      attrs.putString(Tag.TransferSyntaxUID, VR.UI, UID.ImplicitVRLittleEndian);
      attrs.putInt(Tag.Rows, VR.US, image.getHeight());
      attrs.putInt(Tag.Columns, VR.US, image.getWidth());
      attrs.putInt(Tag.SamplesPerPixel, VR.US, numSamples);
      attrs.putInt(Tag.BitsStored, VR.US, bits);
      attrs.putInt(Tag.BitsAllocated, VR.US, allocated);
      attrs.putInt(Tag.PixelRepresentation, VR.US, 0);
      attrs.putString(Tag.PhotometricInterpretation, VR.CS, pmi);

      if (numSamples > 1) {
        attrs.putInt(Tag.PlanarConfiguration, VR.US, 0);
      }

      int biType =
          numSamples == 3
              ? BufferedImage.TYPE_INT_RGB
              : allocated > 8 ? BufferedImage.TYPE_USHORT_GRAY : BufferedImage.TYPE_BYTE_GRAY;

      BufferedImage tmpImage = image;
      if (image.getType() != biType) {
        tmpImage = new BufferedImage(image.getWidth(), image.getHeight(), biType);
        tmpImage.getGraphics().drawImage(image, 0, 0, null);
      }

      byte[] pixelData = null;
      DataBuffer dataBuffer = tmpImage.getRaster().getDataBuffer();
      if (dataBuffer instanceof DataBufferInt) {
        final int[] data = (int[]) ((DataBufferInt) dataBuffer).getData();
        pixelData = new byte[data.length * 3];
        int index = 0;
        for (final int i : data) {
          pixelData[index++] = (byte) ((i >>> 16) & 0xFF);
          pixelData[index++] = (byte) ((i >>> 8) & 0xFF);
          pixelData[index++] = (byte) (i & 0xFF);
        }
      } else if (dataBuffer instanceof DataBufferUShort) {
        final short[] data = (short[]) ((DataBufferUShort) dataBuffer).getData();
        pixelData = new byte[data.length * 2];
        int index = 0;
        for (final int i : data) {
          pixelData[index++] = (byte) ((i >>> 8) & 0xFF);
          pixelData[index++] = (byte) (i & 0xFF);
        }
      } else if (dataBuffer instanceof DataBufferByte) {
        pixelData = ((DataBufferByte) dataBuffer).getData();
      }

      attrs.putBytes(Tag.PixelData, allocated > 8 ? VR.OW : VR.OB, pixelData);

      return attrs;
    }