Пример #1
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) {
          }
        }
      }
    }
Пример #2
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();
        }
      }
    }