Java Code Examples for org.dcm4che3.data.Attributes#setValue()

The following examples show how to use org.dcm4che3.data.Attributes#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttributesUtil.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
/**
 * Converts QIDO_RS json reply to dcm4che Attributes
 */
public static Attributes jsonToAttributes(JSONObject jsonDataset) throws DicomServiceException {
  Attributes attributes = new Attributes();
  for (String tag : jsonDataset.keySet()) {
    JSONObject element = jsonDataset.getJSONObject(tag);
    int tagInt = TagUtils.forName(tag);
    VR vr = VR.valueOf(element.getString("vr"));
    if (isBinaryVr(vr)) {
      throw new DicomServiceException(Status.ProcessingFailure,
          "Binary VR not supported: " + vr.toString());
    } else if (element.has("Value")) {
      setAttributeValue(attributes, tagInt, vr, (JSONArray) element.get("Value"));
    } else {
      attributes.setValue(tagInt, vr, null);
    }
  }
  return attributes;
}
 
Example 2
Source File: Dicomizer.java    From weasis-dicom-tools with Eclipse Public License 2.0 6 votes vote down vote up
public static void pdf(final Attributes attrs, File pdfFile, File dcmFile) throws IOException {
    attrs.setString(Tag.SOPClassUID, VR.UI, UID.EncapsulatedPDFStorage);
    ensureString(attrs, Tag.SpecificCharacterSet, VR.CS, "ISO_IR 192");// UTF-8
    ensureUID(attrs, Tag.StudyInstanceUID);
    ensureUID(attrs, Tag.SeriesInstanceUID);
    ensureUID(attrs, Tag.SOPInstanceUID);
    setCreationDate(attrs);

    BulkData bulk = new BulkData(pdfFile.toURI().toString(), 0, (int) pdfFile.length(), false);
    attrs.setValue(Tag.EncapsulatedDocument, VR.OB, bulk);
    attrs.setString(Tag.MIMETypeOfEncapsulatedDocument, VR.LO, "application/pdf");
    Attributes fmi = attrs.createFileMetaInformation(UID.ExplicitVRLittleEndian);
    try (DicomOutputStream dos = new DicomOutputStream(dcmFile)) {
        dos.writeDataset(fmi, attrs);
    }
}
 
Example 3
Source File: StowrsSingleFile.java    From weasis-dicom-tools with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void uploadEncapsulatedDocument(Attributes metadata, File bulkDataFile, String mimeType, String sopClassUID)
    throws Exception {
    HttpURLConnection httpPost = buildConnection();

    setEncapsulatedDocumentAttributes(bulkDataFile.toPath(), metadata, mimeType);
    if (metadata.getValue(Tag.EncapsulatedDocument) == null) {
        metadata.setValue(Tag.EncapsulatedDocument, VR.OB, new BulkData(null, "bulk", false));
    }
    metadata.setValue(Tag.SOPClassUID, VR.UI, sopClassUID);
    ensureUID(metadata, Tag.StudyInstanceUID);
    ensureUID(metadata, Tag.SeriesInstanceUID);
    ensureUID(metadata, Tag.SOPInstanceUID);

    try (ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                    DataOutputStream out = new DataOutputStream(httpPost.getOutputStream())) {
        if (getContentType() == Multipart.ContentType.JSON)
            try (JsonGenerator gen = Json.createGenerator(bOut)) {
                new JSONWriter(gen).write(metadata);
            }
        else {
            SAXTransformer.getSAXWriter(new StreamResult(bOut)).write(metadata);
        }

        writeContentMarkers(out);

        out.write(bOut.toByteArray());

        // Segment and headers for a part
        out.write(Multipart.Separator.BOUNDARY.getType());
        out.writeBytes(MULTIPART_BOUNDARY);
        byte[] fsep = Multipart.Separator.FIELD.getType();
        out.write(fsep);
        out.writeBytes("Content-Type: "); //$NON-NLS-1$
        out.writeBytes(mimeType);
        out.write(fsep);
        out.writeBytes("Content-Location: "); //$NON-NLS-1$
        out.writeBytes(getContentLocation(metadata));
        out.write(Multipart.Separator.HEADER.getType());

        Files.copy(bulkDataFile.toPath(), out);

        writeEndMarkers(httpPost, out, metadata.getString(Tag.SOPInstanceUID));
    } finally {
        removeConnection(httpPost);
    }
}