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

The following examples show how to use org.dcm4che3.data.Attributes#setString() . 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: 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 2
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonToAttributes_patientName() throws Exception {
  JSONObject jsonObj = new JSONObject("{\""
      + TagUtils.toHexString(Tag.PatientName)
      + "\": {\"vr\": \"PN\",\"Value\": [{"
      + "\"Alphabetic\": \"Yamada^Tarou\", "
      + "\"Ideographic\": \"山田^太郎\", "
      + "\"Phonetic\": \"やまだ^たろう\", "
      + "}]}}");

  Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj);

  Attributes expected = new Attributes();
  expected.setString(Tag.PatientName, VR.PN, "Yamada^Tarou=山田^太郎=やまだ^たろう");
  assertThat(attrs).isEqualTo(expected);
}
 
Example 3
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonToAttributes_integerString() throws Exception {
  // can be parsed as either string or int.
  JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.InstanceNumber)
      + "\": {\"vr\": \"IS\",\"Value\": [" + Integer.MAX_VALUE + "]}}");

  Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj);

  Attributes expectedAsInt = new Attributes();
  expectedAsInt.setInt(Tag.InstanceNumber, VR.IS, Integer.MAX_VALUE);
  assertThat(attrs).isEqualTo(expectedAsInt);

  Attributes expectedAsString = new Attributes();
  expectedAsString.setString(Tag.InstanceNumber, VR.IS, String.valueOf(Integer.MAX_VALUE));
  assertThat(attrs).isEqualTo(expectedAsString);
}
 
Example 4
Source File: StorageCommitmentServiceTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
@Test
public void testCommitmentService_found() throws Exception {
  Attributes rqAttrs = new Attributes();
  rqAttrs.setString(Tag.TransactionUID, VR.UI, "1");
  Sequence sequence = rqAttrs.newSequence(Tag.ReferencedSOPSequence, 1);
  Attributes seqItem = new Attributes();
  seqItem.setString(Tag.ReferencedSOPInstanceUID, VR.UI, "1");
  seqItem.setString(Tag.ReferencedSOPClassUID, VR.UI, "1");
  sequence.add(seqItem);

  Attributes expectReportAttrs = new Attributes(rqAttrs);
  expectReportAttrs.setString(Tag.RetrieveAETitle, VR.AE, serverAET);

  basicCommitmentServiceTest(new TestUtils.DicomWebClientTestBase() {
    @Override
    public JSONArray qidoRs(String path) throws DicomWebException {
      JSONArray instances = new JSONArray();
      instances.put(TestUtils.dummyQidorsInstance());
      return instances;
    }
  }, rqAttrs, Status.Success, expectReportAttrs);
}
 
Example 5
Source File: StorageCommitmentService.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
private Attributes makeDataset(List<CommitmentItem> presentInstances,
    List<CommitmentItem> absentInstances) {
  Attributes result = new Attributes();
  result.setString(Tag.TransactionUID, VR.UI, data.getString(Tag.TransactionUID));
  result.setString(Tag.RetrieveAETitle, VR.AE, applicationEntity.getAETitle());
  addCommitmentItemSequence(result, Tag.FailedSOPSequence, absentInstances);
  addCommitmentItemSequence(result, Tag.ReferencedSOPSequence, presentInstances);
  return result;
}
 
Example 6
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonToAttributes_stringType() throws Exception {
  JSONObject jsonObj = new JSONObject("{\""
      + TagUtils.toHexString(Tag.QueryRetrieveLevel)
      + "\": {\"vr\": \"CS\",\"Value\": [\"IMAGE\"]}}");

  Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj);

  Attributes expected = new Attributes();
  expected.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE");
  assertThat(attrs).isEqualTo(expected);
}
 
Example 7
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonToAttributes_decimalString() throws Exception {
  String value = "12345678901234567890.1234567890";
  JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.DecimalVisualAcuity)
      + "\": {\"vr\": \"DS\",\"Value\": [" + value + "]}}");

  Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj);

  Attributes expected = new Attributes();
  expected.setString(Tag.DecimalVisualAcuity, VR.DS, value);
  assertThat(attrs).isEqualTo(expected);
}
 
Example 8
Source File: ServiceUtil.java    From weasis-dicom-tools with Eclipse Public License 2.0 5 votes vote down vote up
public static void notifyProgession(DicomState state, String iuid, String cuid, int status, ProgressStatus ps,
    int numberOfSuboperations) {
    state.setStatus(status);
    DicomProgress p = state.getProgress();
    if (p != null) {
        Attributes cmd = Optional.ofNullable(p.getAttributes()).orElseGet(Attributes::new);
        cmd.setInt(Tag.Status, VR.US, status);
        cmd.setString(Tag.AffectedSOPInstanceUID, VR.UI, iuid);
        cmd.setString(Tag.AffectedSOPClassUID, VR.UI, cuid);
        notifyProgession(p, cmd, ps, numberOfSuboperations);
        p.setAttributes(cmd);
    }
}
 
Example 9
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
@Test
public void testAttributesToQidoPathArray_noModalitiesSet() throws Exception {
  Attributes attrs = new Attributes();
  attrs.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE");

  String[] results = AttributesUtil.attributesToQidoPathArray(attrs);

  assertThat(results.length).isEqualTo(1);
  assertThat(results[0]).isEqualTo("instances?limit=50000&");
}
 
Example 10
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
@Test
public void testAttributesToQidoPath_urlEncode() throws Exception {
  Attributes attrs = new Attributes();
  attrs.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE");
  attrs.setString(Tag.PatientName, VR.CS, "%&#^ ");

  String result = AttributesUtil.attributesToQidoPath(attrs);

  assertThat(result).isEqualTo(
      "instances?limit=50000&" + TagUtils.toHexString(Tag.PatientName) + "=%25%26%23%5E&");
}
 
Example 11
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
@Test
public void testAttributesToQidoPath_simple() throws Exception {
  Attributes attrs = new Attributes();
  attrs.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE");
  attrs.setString(Tag.SOPInstanceUID, VR.UI, "123");

  String result = AttributesUtil.attributesToQidoPath(attrs);

  assertThat(result).isEqualTo(
      "instances?limit=50000&" + TagUtils.toHexString(Tag.SOPInstanceUID) + "=123&");
}
 
Example 12
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
@Test(expected = DicomServiceException.class)
public void testAttributesToQidoPath_wrongQueryRetriveLevel() throws Exception {
  Attributes attrs = new Attributes();
  attrs.setString(Tag.QueryRetrieveLevel, VR.CS, "Wrong");

  AttributesUtil.attributesToQidoPath(attrs);
}
 
Example 13
Source File: CMoveServiceTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
public void basicCMoveServiceTest(IDicomWebClient serverDicomWebClient,
    ICStoreSenderFactory senderFactory,
    int expectedStatus,
    String moveDestinationAET) throws Exception {
  // Create C-STORE DICOM server.
  int serverPort = createDicomServer(serverDicomWebClient, senderFactory);

  // Associate with peer AE.
  Association association =
      associate(serverHostname, serverPort,
          UID.StudyRootQueryRetrieveInformationModelMOVE, UID.ExplicitVRLittleEndian);

  Attributes moveDataset = new Attributes();
  moveDataset.setString(Tag.QueryRetrieveLevel, VR.CS, "STUDY");
  moveDataset.setString(Tag.StudyInstanceUID, VR.UI, "");

  // Issue CMOVE
  DimseRSPAssert rspAssert = new DimseRSPAssert(association, expectedStatus);
  association.cmove(
      UID.StudyRootQueryRetrieveInformationModelMOVE,
      1,
      moveDataset,
      UID.ExplicitVRLittleEndian,
      moveDestinationAET,
      rspAssert);
  association.waitForOutstandingRSP();

  // Close the association.
  association.release();
  association.waitForSocketClose();

  rspAssert.assertResult();
}
 
Example 14
Source File: DefaultAttributeEditor.java    From weasis-dicom-tools with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean apply(Attributes data, AttributeEditorContext context) {
    if (data != null) {
        boolean update = false;
        if (generateUIDs) {
            if ("2.25".equals(UIDUtils.getRoot())) {
                UIDUtils.setRoot("2.25.35");
            }
            // New Study UID
            String oldStudyUID = data.getString(Tag.StudyInstanceUID);
            String studyUID = uidMap.computeIfAbsent(oldStudyUID, k -> UIDUtils.createUID());
            data.setString(Tag.StudyInstanceUID, VR.UI, studyUID);

            // New Series UID
            String oldSeriesUID = data.getString(Tag.SeriesInstanceUID);
            String seriesUID = uidMap.computeIfAbsent(oldSeriesUID, k -> UIDUtils.createUID());
            data.setString(Tag.SeriesInstanceUID, VR.UI, seriesUID);

            // New Sop UID
            String iuid = UIDUtils.createUID();
            data.setString(Tag.SOPInstanceUID, VR.UI, iuid);
            update = true;
        }
        if (tagToOverride != null && !tagToOverride.isEmpty()) {
            data.update(Attributes.UpdatePolicy.OVERWRITE, tagToOverride, null);
            update = true;
        }
        return update;
    }
    return false;
}
 
Example 15
Source File: CGetForwardNetTest.java    From weasis-dicom-tools with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testProcess() {
    BasicConfigurator.configure();

    DicomProgress progress = new DicomProgress();
    progress.addProgressListener(progress1 -> {
        System.out.println("DICOM Status:" + progress1.getStatus());
        System.out.println("NumberOfRemainingSuboperations:" + progress1.getNumberOfRemainingSuboperations());
        System.out.println("NumberOfCompletedSuboperations:" + progress1.getNumberOfCompletedSuboperations());
        System.out.println("NumberOfFailedSuboperations:" + progress1.getNumberOfFailedSuboperations());
        System.out.println("NumberOfWarningSuboperations:" + progress1.getNumberOfWarningSuboperations());
        if (progress1.isLastFailed()) {
            System.out.println("Last file has failed:" + progress1.getProcessedFile());
        }
    });

    AdvancedParams params = new AdvancedParams();
    ConnectOptions connectOptions = new ConnectOptions();
    connectOptions.setConnectTimeout(3000);
    connectOptions.setAcceptTimeout(5000);
    params.setConnectOptions(connectOptions);

    DicomNode calling = new DicomNode("WEASIS-SCU");
    DicomNode called = new DicomNode("DICOMSERVER", "dicomserver.co.uk", 11112);
    DicomNode destination = new DicomNode("DCM4CHEE", "localhost", 11112);
    String studyUID = "1.2.826.0.1.3680043.11.120.1";

    Attributes attrs = new Attributes();
    attrs.setString(Tag.PatientName, VR.PN, "Override^Patient^Name");
    attrs.setString(Tag.PatientID, VR.LO, "ModifiedPatientID");
    DefaultAttributeEditor editor = new DefaultAttributeEditor(true, attrs);

    DicomState state =
        CGetForward.processStudy(params, params, calling, called, destination, progress, studyUID, editor);
    // Should never happen
    Assert.assertNotNull(state);

    System.out.println("DICOM Status:" + state.getStatus());
    System.out.println(state.getMessage());
    System.out.println("NumberOfRemainingSuboperations:" + progress.getNumberOfRemainingSuboperations());
    System.out.println("NumberOfCompletedSuboperations:" + progress.getNumberOfCompletedSuboperations());
    System.out.println("NumberOfFailedSuboperations:" + progress.getNumberOfFailedSuboperations());
    System.out.println("NumberOfWarningSuboperations:" + progress.getNumberOfWarningSuboperations());

    // see org.dcm4che3.net.Status
    // See server log at http://dicomserver.co.uk/logs/
    Assert.assertThat(state.getMessage(), state.getStatus(), IsEqual.equalTo(Status.Pending));
}
 
Example 16
Source File: DicomGatewayMultiDestNetTest.java    From weasis-dicom-tools with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testProcess() {
    BasicConfigurator.configure();

    AdvancedParams params = new AdvancedParams();
    ConnectOptions connectOptions = new ConnectOptions();
    connectOptions.setConnectTimeout(3000);
    connectOptions.setAcceptTimeout(5000);
    // Concurrent DICOM operations
    connectOptions.setMaxOpsInvoked(15);
    connectOptions.setMaxOpsPerformed(15);
    params.setConnectOptions(connectOptions);

    DicomNode calling = new DicomNode("WEASIS-SCU");
    DicomNode called = new DicomNode("DICOMSERVER", "dicomserver.co.uk", 11112);
    DicomNode scpNode = new DicomNode("DICOMLISTENER", "localhost", 11113);
    DicomNode destination = new DicomNode("FWD-AET", "localhost", 11113);

    Map<ForwardDicomNode, List<ForwardDestination>> destinations = new HashMap<>();
    Attributes attrs = new Attributes();
    attrs.setString(Tag.PatientName, VR.PN, "Override^Patient^Name");
    attrs.setString(Tag.PatientID, VR.LO, "ModifiedPatientID");
    DefaultAttributeEditor editor = new DefaultAttributeEditor(true, attrs);

    DicomProgress progress = new DicomProgress();
    progress.addProgressListener(p -> {
        if (p.isLastFailed()) {
            System.out.println("Failed: DICOM Status:" + p.getStatus());
        }
    });
    List<ForwardDestination> list = new ArrayList<>();
    ForwardDicomNode fwdSrcNode = new ForwardDicomNode(destination.getAet());
    fwdSrcNode.addAcceptedSourceNode(calling.getAet(), "localhost");
    WebForwardDestination web = new WebForwardDestination(fwdSrcNode,
        "http://localhost:8080/dcm4chee-arc/aets/DCM4CHEE/rs/studies", progress, editor);
    list.add(web);
    destinations.put(fwdSrcNode, list);

    GatewayParams gparams = new GatewayParams(params, false, null, GatewayParams.getAcceptedCallingAETitles(destinations));

    DicomGateway gateway;
    try {
        gateway = new DicomGateway(destinations);
        gateway.start(scpNode, gparams);
    } catch (Exception e) {
        e.printStackTrace();
    }

    DicomProgress progress2 = new DicomProgress();
    progress2.addProgressListener(progress1 -> {
        System.out.println("DICOM Status:" + progress1.getStatus());
        System.out.println("NumberOfRemainingSuboperations:" + progress1.getNumberOfRemainingSuboperations());
        System.out.println("NumberOfCompletedSuboperations:" + progress1.getNumberOfCompletedSuboperations());
        System.out.println("NumberOfFailedSuboperations:" + progress1.getNumberOfFailedSuboperations());
        System.out.println("NumberOfWarningSuboperations:" + progress1.getNumberOfWarningSuboperations());
        if (progress1.isLastFailed()) {
            System.out.println("Last file has failed:" + progress1.getProcessedFile());
        }
    });

    String studyUID = "1.2.826.0.1.3680043.11.111";
    DicomState state = CGetForward.processStudy(params, params, calling, called, destination, progress2, studyUID);
    // String seriesUID = "1.2.528.1.1001.100.3.3865.6101.93503564261.20070711142700388";
    // DicomState state = CGetForward.processSeries(params, params, calling, called, destination, progress2, seriesUID);

    // Force to write endmarks and stop the connection
    web.stop();

    // Should never happen
    Assert.assertNotNull(state);

    System.out.println("DICOM Status for retrieving:" + state.getStatus());
    // see org.dcm4che3.net.Status
    // See server log at http://dicomserver.co.uk/logs/
    Assert.assertThat(state.getMessage(), state.getStatus(), IsEqual.equalTo(Status.Pending));
    
    System.out.println("DICOM Status for forwarding:" + web.getState().getStatus());
    Assert.assertThat(web.getState().getMessage(), web.getState().getStatus(), IsEqual.equalTo(Status.Pending));
    
}
 
Example 17
Source File: Dicomizer.java    From weasis-dicom-tools with Eclipse Public License 2.0 4 votes vote down vote up
private static void ensureString(Attributes attrs, int tag, VR vr, String value) {
    if (!attrs.containsValue(tag)) {
        attrs.setString(tag, vr, value);
    }
}
 
Example 18
Source File: DicomGatewayOneDestNetTest.java    From weasis-dicom-tools with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testProcess() {
    BasicConfigurator.configure();

    AdvancedParams params = new AdvancedParams();
    ConnectOptions connectOptions = new ConnectOptions();
    connectOptions.setConnectTimeout(3000);
    connectOptions.setAcceptTimeout(5000);
    // Concurrent DICOM operations
    connectOptions.setMaxOpsInvoked(15);
    connectOptions.setMaxOpsPerformed(15);
    params.setConnectOptions(connectOptions);

    ForwardDicomNode calling = new ForwardDicomNode("FWD-AET", "localhost");
    DicomNode called = new DicomNode("DICOMSERVER", "dicomserver.co.uk", 11112);
    DicomNode destination = new DicomNode("DCM4CHEE", "localhost", 11112);
    DicomNode scpNode = new DicomNode("DICOMLISTENER", "localhost", 11113);

    Attributes attrs = new Attributes();
    attrs.setString(Tag.PatientName, VR.PN, "Override^Patient^Name");
    attrs.setString(Tag.PatientID, VR.LO, "ModifiedPatientID");
    DefaultAttributeEditor editor = new DefaultAttributeEditor(true, attrs);

    GatewayParams gparams = new GatewayParams(params, false, null, calling.getAet());

    DicomGateway gateway;
    try {
        gateway = new DicomGateway(params, calling, destination, editor);
        gateway.start(scpNode, gparams);
    } catch (Exception e) {
        e.printStackTrace();
    }

    DicomProgress progress = new DicomProgress();
    progress.addProgressListener(progress1 -> {
        System.out.println("DICOM Status:" + progress1.getStatus());
        System.out.println("NumberOfRemainingSuboperations:" + progress1.getNumberOfRemainingSuboperations());
        System.out.println("NumberOfCompletedSuboperations:" + progress1.getNumberOfCompletedSuboperations());
        System.out.println("NumberOfFailedSuboperations:" + progress1.getNumberOfFailedSuboperations());
        System.out.println("NumberOfWarningSuboperations:" + progress1.getNumberOfWarningSuboperations());
        if (progress1.isLastFailed()) {
            System.out.println("Last file has failed:" + progress1.getProcessedFile());
        }
    });

    String studyUID = "1.2.826.0.1.3680043.11.111";
    DicomNode calling2 = new DicomNode("WEASIS-SCU");
    DicomState state = CGetForward.processStudy(params, params, calling2, called, scpNode, progress, studyUID);
    // Should never happen
    Assert.assertNotNull(state);

    System.out.println("DICOM Status:" + state.getStatus());
    System.out.println(state.getMessage());

    // see org.dcm4che3.net.Status
    // See server log at http://dicomserver.co.uk/logs/
    Assert.assertThat(state.getMessage(), state.getStatus(), IsEqual.equalTo(Status.Pending));
}
 
Example 19
Source File: CFindService.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 4 votes vote down vote up
private void sendErrorResponse(int status, String message) {
  Attributes cmdAttr = Commands.mkCFindRSP(cmd, status);
  cmdAttr.setString(Tag.ErrorComment, VR.LO, message);
  as.tryWriteDimseRSP(pc, cmdAttr);
}
 
Example 20
Source File: AbstractStowrs.java    From weasis-dicom-tools with Eclipse Public License 2.0 4 votes vote down vote up
protected static void ensureUID(Attributes attrs, int tag) {
    if (!attrs.containsValue(tag)) {
        attrs.setString(tag, VR.UI, UIDUtils.createUID());
    }
}