예제 #1
0
파일: DcmRcv.java 프로젝트: Cledio/Oviyam2
 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
    @SuppressWarnings("restriction")
    public static TCImageDocument create(
        TCObject tc, MimeType mimeType, String filename, InputStream in, String description)
        throws Exception {

      mimeType = checkMimeType(mimeType);

      ByteArrayOutputStream out = null;

      try {
        BufferedImage image = null;

        if (MimeType.ImageJPEG.equals(mimeType)) {
          try {
            com.sun.image.codec.jpeg.JPEGImageDecoder decoder =
                com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(in);
            image = decoder.decodeAsBufferedImage();
          } catch (Exception e) {
            log.warn(null, e);
          }
        }

        if (image == null) {
          image = ImageIO.read(in);
        }

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

        DicomObject metaData =
            TCDocumentObject.createDicomMetaData(
                mimeType,
                filename,
                description,
                ref,
                tc.getPatientId(),
                tc.getPatientIdIssuer(),
                tc.getPatientName(),
                MODALITY);

        metaData.putInt(Tag.NumberOfFrames, VR.IS, 1);

        return new TCImageDocument(mimeType, ref, metaData, image);
      } finally {
        if (in != null) {
          try {
            in.close();
          } catch (Exception e) {
          }
        }
        if (out != null) {
          try {
            out.close();
          } catch (Exception e) {
          }
        }
      }
    }
예제 #3
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;
  }
예제 #4
0
파일: Series.java 프로젝트: DicomFlow/repos
 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;
 }
예제 #5
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;
    }