org.dcm4che3.data.Tag Java Examples

The following examples show how to use org.dcm4che3.data.Tag. 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: DicomQueryConfiguration.java    From weasis-pacs-connector with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void buildFromStudyAccessionNumber(CommonQueryParams params, String... accessionNumbers) {
    for (String accessionNumber : accessionNumbers) {
        if (!StringUtil.hasText(accessionNumber)) {
            continue;
        }
        DicomParam[] keysStudies = {
            // Matching Keys
            new DicomParam(Tag.AccessionNumber, accessionNumber),
            // Return Keys
            CFind.PatientID, CFind.IssuerOfPatientID, CFind.PatientName, CFind.PatientBirthDate, CFind.PatientSex,
            CFind.ReferringPhysicianName, CFind.StudyDescription, CFind.StudyDate, CFind.StudyTime,
            CFind.StudyInstanceUID, CFind.StudyID };

        fillStudy(keysStudies);
    }
}
 
Example #2
Source File: CMoveService.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
private void sendErrorResponse(int status, String message, List<String> failedInstanceUids) {
  switch (status) {
    case Status.Cancel:
      MonitoringService.addEvent(Event.CMOVE_CANCEL);
      break;
    case Status.OneOrMoreFailures:
      MonitoringService.addEvent(Event.CMOVE_WARNING);
      break;
    default:
      MonitoringService.addEvent(Event.CMOVE_ERROR);
  }

  Attributes cmdAttr = Commands.mkCMoveRSP(cmd, status);
  if (message != null) {
    cmdAttr.setString(Tag.ErrorComment, VR.LO, message);
  }

  if (failedInstanceUids != null && failedInstanceUids.size() > 0) {
    Attributes dataAttr = new Attributes();
    dataAttr.setString(Tag.FailedSOPInstanceUIDList, VR.UI,
        failedInstanceUids.toArray(new String[]{}));
    as.tryWriteDimseRSP(pc, cmdAttr, dataAttr);
  } else {
    as.tryWriteDimseRSP(pc, cmdAttr);
  }
}
 
Example #3
Source File: DicomQueryConfiguration.java    From weasis-pacs-connector with Eclipse Public License 2.0 6 votes vote down vote up
private static Study getStudy(Patient patient, final Attributes studyDataset) {
    if (studyDataset == null) {
        throw new IllegalArgumentException("studyDataset cannot be null");
    }
    String uid = studyDataset.getString(Tag.StudyInstanceUID);
    Study s = patient.getStudy(uid);
    if (s == null) {
        s = new Study(uid);
        s.setStudyDescription(studyDataset.getString(Tag.StudyDescription));
        s.setStudyDate(studyDataset.getString(Tag.StudyDate));
        s.setStudyTime(studyDataset.getString(Tag.StudyTime));
        s.setAccessionNumber(studyDataset.getString(Tag.AccessionNumber));
        s.setStudyID(studyDataset.getString(Tag.StudyID));
        s.setReferringPhysicianName(studyDataset.getString(Tag.ReferringPhysicianName));
        patient.addStudy(s);
    }
    return s;
}
 
Example #4
Source File: Patient.java    From weasis-dicom-tools with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void toXml(Writer result) throws IOException {
    if (patientID != null && patientName != null) {
        result.append("\n<");
        result.append(Xml.Level.PATIENT.getTagName());
        result.append(" ");

        Xml.addXmlAttribute(Tag.PatientID, patientID, result);
        Xml.addXmlAttribute(Tag.IssuerOfPatientID, issuerOfPatientID, result);
        Xml.addXmlAttribute(Tag.PatientName, patientName, result);
        Xml.addXmlAttribute(Tag.PatientBirthDate, patientBirthDate, result);
        Xml.addXmlAttribute(Tag.PatientBirthTime, patientBirthTime, result);
        Xml.addXmlAttribute(Tag.PatientSex, patientSex, result);
        result.append(">");

        List<Study> list = new ArrayList<>(studiesMap.values());
        Collections.sort(list);
        for (Study s : list) {
            s.toXml(result);
        }
        result.append("\n</");
        result.append(Xml.Level.PATIENT.getTagName());
        result.append(">");
    }
}
 
Example #5
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
@Test
public void testAttributesToQidoPathArray_manyModalitiesSet() throws Exception {
  Attributes attrs = new Attributes();
  attrs.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE");
  attrs.setString(Tag.ModalitiesInStudy, VR.CS, "MG", "CS", "CR");

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

  assertThat(results.length).isEqualTo(3);
  assertThat(results[0]).isEqualTo(
      "instances?limit=50000&" + TagUtils.toHexString(Tag.ModalitiesInStudy) + "=MG&");
  assertThat(results[1]).isEqualTo(
      "instances?limit=50000&" + TagUtils.toHexString(Tag.ModalitiesInStudy) + "=CS&");
  assertThat(results[2]).isEqualTo(
      "instances?limit=50000&" + TagUtils.toHexString(Tag.ModalitiesInStudy) + "=CR&");
}
 
Example #6
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 #7
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 #8
Source File: AttributesUtilTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonToAttributes_sequence() throws Exception {
  JSONObject jsonObj = new JSONObject("{\""
      + TagUtils.toHexString(Tag.FrameContentSequence)
      + "\": {\"vr\": \"SQ\", \"Value\": " +
      " [{ \"" + TagUtils.toHexString(Tag.DimensionIndexValues)
      + "\": {\"vr\": \"UL\", \"Value\": [1,1]} }] }}");

  Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj);

  Attributes expected = new Attributes();
  Sequence sequence = expected.newSequence(Tag.FrameContentSequence, 1);
  Attributes sequenceElement = new Attributes();
  sequenceElement.setInt(Tag.DimensionIndexValues, VR.UL, 1, 1);
  sequence.add(sequenceElement);
  assertThat(attrs).isEqualTo(expected);
}
 
Example #9
Source File: DicomQueryConfiguration.java    From weasis-pacs-connector with Eclipse Public License 2.0 6 votes vote down vote up
private static Series getSeries(Study study, final Attributes seriesDataset, Properties properties) {
    if (seriesDataset == null) {
        throw new IllegalArgumentException("seriesDataset cannot be null");
    }
    String uid = seriesDataset.getString(Tag.SeriesInstanceUID);
    Series s = study.getSeries(uid);
    if (s == null) {
        s = new Series(uid);
        s.setModality(seriesDataset.getString(Tag.Modality));
        s.setSeriesNumber(seriesDataset.getString(Tag.SeriesNumber));
        s.setSeriesDescription(seriesDataset.getString(Tag.SeriesDescription));
        String wadotTsuid = properties.getProperty("wado.request.tsuid");
        if (StringUtil.hasText(wadotTsuid)) {
            String[] val = wadotTsuid.split(":");
            if (val.length > 0) {
                s.setWadoTransferSyntaxUID(val[0]);
            }
            if (val.length > 1) {
                s.setWadoCompression(val[1]);
            }
        }
        study.addSeries(s);
    }
    return s;
}
 
Example #10
Source File: AttributesUtil.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
/**
 * Returns array of QIDO-RS paths (more than 1 if multiple ModalitiesInStudy are present)
 *
 * @param attrs dcm4che Attributes to convert
 * @param includeFields additonal includeFields for QIDO-RS
 */
public static String[] attributesToQidoPathArray(Attributes attrs, String... includeFields)
    throws IOException {
  if (!attrs.containsValue(Tag.ModalitiesInStudy)
      || attrs.getStrings(Tag.ModalitiesInStudy).length <= 1) {
    return new String[]{attributesToQidoPath(attrs, includeFields)};
  }

  List<String> result = new ArrayList<>();
  for (String modality : attrs.getStrings(Tag.ModalitiesInStudy)) {
    Attributes attrsCopy = new Attributes(attrs);
    attrsCopy.setString(Tag.ModalitiesInStudy, VR.CS, modality);
    result.add(attributesToQidoPath(attrsCopy, includeFields));
  }
  return result.toArray(new String[]{});
}
 
Example #11
Source File: DicomQueryConfiguration.java    From weasis-pacs-connector with Eclipse Public License 2.0 6 votes vote down vote up
private Patient getPatient(Attributes patientDataset) {
    if (patientDataset == null) {
        throw new IllegalArgumentException("patientDataset cannot be null");
    }

    fillPatientAttributes(patientDataset);

    String id = patientDataset.getString(Tag.PatientID, "Unknown");
    String ispid = patientDataset.getString(Tag.IssuerOfPatientID);
    Patient p = getPatient(id, ispid);
    if (p == null) {
        p = new Patient(id, ispid);
        p.setPatientName(patientDataset.getString(Tag.PatientName));
        // Only set birth date, birth time is often not consistent (00:00)
        p.setPatientBirthDate(patientDataset.getString(Tag.PatientBirthDate));
        p.setPatientSex(patientDataset.getString(Tag.PatientSex));
        addPatient(p);
    }
    return p;
}
 
Example #12
Source File: Series.java    From weasis-dicom-tools with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void toXml(Writer result) throws IOException {
    if (seriesInstanceUID != null) {
        result.append("\n<");
        result.append(Xml.Level.SERIES.getTagName());
        result.append(" ");
        Xml.addXmlAttribute(Tag.SeriesInstanceUID, seriesInstanceUID, result);
        Xml.addXmlAttribute(Tag.SeriesDescription, seriesDescription, result);
        Xml.addXmlAttribute(Tag.SeriesNumber, seriesNumber, result);
        Xml.addXmlAttribute(Tag.Modality, modality, result);
        Xml.addXmlAttribute("DirectDownloadThumbnail", thumbnail, result);
        Xml.addXmlAttribute("WadoTransferSyntaxUID", wadoTransferSyntaxUID, result);
        Xml.addXmlAttribute("WadoCompressionRate",
            wadoCompression < 1 ? null : Integer.toString(wadoCompression), result);
        result.append(">");

        List<SopInstance> list = new ArrayList<>(sopInstanceMap.values());
        Collections.sort(list);
        for (SopInstance s : list) {
            s.toXml(result);
        }
        result.append("\n</");
        result.append(Xml.Level.SERIES.getTagName());
        result.append(">");
    }
}
 
Example #13
Source File: Study.java    From weasis-dicom-tools with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void toXml(Writer result) throws IOException {
    if (studyInstanceUID != null) {
        result.append("\n<");
        result.append(Xml.Level.STUDY.getTagName());
        result.append(" ");
        Xml.addXmlAttribute(Tag.StudyInstanceUID, studyInstanceUID, result);
        Xml.addXmlAttribute(Tag.StudyDescription, studyDescription, result);
        Xml.addXmlAttribute(Tag.StudyDate, studyDate, result);
        Xml.addXmlAttribute(Tag.StudyTime, studyTime, result);
        Xml.addXmlAttribute(Tag.AccessionNumber, accessionNumber, result);
        Xml.addXmlAttribute(Tag.StudyID, studyID, result);
        Xml.addXmlAttribute(Tag.ReferringPhysicianName, referringPhysicianName, result);
        result.append(">");

        List<Series> list = new ArrayList<>(seriesMap.values());
        Collections.sort(list);
        for (Series s : list) {
            s.toXml(result);
        }

        result.append("\n</");
        result.append(Xml.Level.STUDY.getTagName());
        result.append(">");
    }
}
 
Example #14
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 #15
Source File: Dicomizer.java    From weasis-dicom-tools with Eclipse Public License 2.0 6 votes vote down vote up
private static boolean readPixelHeader(Parameters p, Attributes metadata, InputStream in, boolean mpeg) throws IOException {
    int grow = INIT_BUFFER_SIZE;
    while (p.realBufferLength == p.buffer.length && p.realBufferLength < MAX_BUFFER_SIZE) {
        grow += p.realBufferLength;
        p.buffer = Arrays.copyOf(p.buffer, grow);
        p.realBufferLength += StreamUtils.readAvailable(in, p.buffer, p.realBufferLength, p.buffer.length - p.realBufferLength);
        boolean jpgHeader;
        if (mpeg) {
            MPEGHeader mpegHeader = new MPEGHeader(p.buffer);
            jpgHeader = mpegHeader.toAttributes(metadata, p.fileLength) != null;
        } else {
            p.jpegHeader = new JPEGHeader(p.buffer, JPEG.SOS);
            jpgHeader = p.jpegHeader.toAttributes(metadata) != null;
        }
        if (jpgHeader) {
            ensureString(metadata, Tag.SOPClassUID, VR.UI,
                mpeg ? UID.VideoPhotographicImageStorage : UID.VLPhotographicImageStorage);
            return true;
        }
    }
    return false;
}
 
Example #16
Source File: DicomQueryConfiguration.java    From weasis-pacs-connector with Eclipse Public License 2.0 6 votes vote down vote up
private void fillSeries(Attributes studyDataSet) {
    String studyInstanceUID = studyDataSet.getString(Tag.StudyInstanceUID);
    if (StringUtil.hasText(studyInstanceUID)) {

        DicomParam[] keysSeries = {
            // Matching Keys
            new DicomParam(Tag.StudyInstanceUID, studyInstanceUID),
            // Return Keys
            CFind.SeriesInstanceUID, CFind.Modality, CFind.SeriesNumber, CFind.SeriesDescription };

        DicomState state =
            CFind.process(advancedParams, callingNode, calledNode, 0, QueryRetrieveLevel.SERIES, keysSeries);
        LOGGER.debug("C-FIND with StudyInstanceUID {}", state.getMessage());

        List<Attributes> series = state.getDicomRSP();
        if (series != null && !series.isEmpty()) {
            // Get patient from each study in case IssuerOfPatientID is different
            Patient patient = getPatient(studyDataSet);
            Study study = getStudy(patient, studyDataSet);
            for (Attributes seriesDataset : series) {
                fillInstance(seriesDataset, study);
            }
        }
    }
}
 
Example #17
Source File: DicomQueryConfiguration.java    From weasis-pacs-connector with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void buildFromStudyInstanceUID(CommonQueryParams params, String... studyInstanceUIDs) {
    for (String studyInstanceUID : studyInstanceUIDs) {
        if (!StringUtil.hasText(studyInstanceUID)) {
            continue;
        }
        DicomParam[] keysStudies = {
            // Matching Keys
            new DicomParam(Tag.StudyInstanceUID, studyInstanceUID),
            // Return Keys
            CFind.PatientID, CFind.IssuerOfPatientID, CFind.PatientName, CFind.PatientBirthDate, CFind.PatientSex,
            CFind.ReferringPhysicianName, CFind.StudyDescription, CFind.StudyDate, CFind.StudyTime,
            CFind.AccessionNumber, CFind.StudyID };

        fillStudy(keysStudies);
    }
}
 
Example #18
Source File: CFindNetTest.java    From weasis-dicom-tools with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testProcess() {
    BasicConfigurator.configure();
    
    DicomParam[] params = { new DicomParam(Tag.PatientID, "PAT001"), new DicomParam(Tag.StudyInstanceUID),
        new DicomParam(Tag.NumberOfStudyRelatedSeries) };
    DicomNode calling = new DicomNode("WEASIS-SCU");
    DicomNode called = new DicomNode("DICOMSERVER", "dicomserver.co.uk", 11112);
    DicomState state = CFind.process(calling, called, params);
    // Should never happen
    Assert.assertNotNull(state);

    List<Attributes> items = state.getDicomRSP();
    if (items != null) {
        for (int i = 0; i < items.size(); i++) {
            Attributes item = items.get(i);
            System.out.println("===========================================");
            System.out.println("CFind Item " + (i + 1));
            System.out.println("===========================================");
            System.out.println(item.toString(100, 150));
        }
    }

    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.Success));
    Assert.assertFalse("No DICOM RSP Object", state.getDicomRSP().isEmpty());
}
 
Example #19
Source File: CLIUtils.java    From weasis-dicom-tools with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean updateAttributes(Attributes data, Attributes attrs, String uidSuffix) {
    if (attrs.isEmpty() && uidSuffix == null) {
        return false;
    }
    if (uidSuffix != null) {
        data.setString(Tag.StudyInstanceUID, VR.UI, data.getString(Tag.StudyInstanceUID) + uidSuffix);
        data.setString(Tag.SeriesInstanceUID, VR.UI, data.getString(Tag.SeriesInstanceUID) + uidSuffix);
        data.setString(Tag.SOPInstanceUID, VR.UI, data.getString(Tag.SOPInstanceUID) + uidSuffix);
    }
    data.update(Attributes.UpdatePolicy.OVERWRITE, attrs, null);
    return true;
}
 
Example #20
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 #21
Source File: StoreScpForward.java    From weasis-dicom-tools with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void store(Association as, PresentationContext pc, Attributes rq, PDVInputStream data, Attributes rsp)
    throws IOException {
    Optional<ForwardDicomNode> sourceNode =
        destinations.keySet().stream().filter(n -> n.getForwardAETitle().equals(as.getCalledAET())).findFirst();
    if (!sourceNode.isPresent()) {
        throw new IllegalStateException("Cannot find the forward AeTitle " + as.getCalledAET());
    }
    ForwardDicomNode fwdNode = sourceNode.get();
    List<ForwardDestination> destList = destinations.get(fwdNode);
    if (destList == null || destList.isEmpty()) {
        throw new IllegalStateException("No DICOM destinations for " + fwdNode.toString());
    }

    DicomNode callingNode = DicomNode.buildRemoteDicomNode(as);
    Set<DicomNode> srcNodes = fwdNode.getAcceptedSourceNodes();
    boolean valid =
        srcNodes.isEmpty() || srcNodes.stream().anyMatch(n -> n.getAet().equals(callingNode.getAet())
            && (!n.isValidateHostname() || n.equalsHostname(callingNode.getHostname())));
    if (!valid) {
        rsp.setInt(Tag.Status, VR.US, Status.NotAuthorized);
        LOGGER.error("Refused: not authorized (124H). Source node: {}. SopUID: {}", callingNode,
            rq.getString(Tag.AffectedSOPInstanceUID));
        return;
    }

    rsp.setInt(Tag.Status, VR.US, status);

    try {
        Params p = new Params(rq.getString(Tag.AffectedSOPInstanceUID), rq.getString(Tag.AffectedSOPClassUID),
            pc.getTransferSyntax(), priority, data, as);

        ForwardUtil.storeMulitpleDestination(fwdNode, destList, p);

    } catch (Exception e) {
        throw new DicomServiceException(Status.ProcessingFailure, e);
    }
}
 
Example #22
Source File: DicomQueryConfiguration.java    From weasis-pacs-connector with Eclipse Public License 2.0 5 votes vote down vote up
private void fillInstance(Attributes seriesDataset, Study study) {
    String serieInstanceUID = seriesDataset.getString(Tag.SeriesInstanceUID);
    if (StringUtil.hasText(serieInstanceUID)) {
        DicomParam[] keysInstance = {
            // Matching Keys
            new DicomParam(Tag.StudyInstanceUID, study.getStudyInstanceUID()),
            new DicomParam(Tag.SeriesInstanceUID, serieInstanceUID),
            // Return Keys
            CFind.SOPInstanceUID, CFind.InstanceNumber };
        DicomState state =
            CFind.process(advancedParams, callingNode, calledNode, 0, QueryRetrieveLevel.IMAGE, keysInstance);
        LOGGER.debug(C_FIND_WITH_SERIESUID, state.getMessage());

        List<Attributes> instances = state.getDicomRSP();
        if (instances != null && !instances.isEmpty()) {
            Series s = getSeries(study, seriesDataset, properties);

            for (Attributes instanceDataSet : instances) {
                Integer frame = ServletUtil.getIntegerFromDicomElement(instanceDataSet, Tag.InstanceNumber, null);
                String sopUID = instanceDataSet.getString(Tag.SOPInstanceUID);
                SopInstance sop = s.getSopInstance(sopUID, frame);
                if (sop == null) {
                    s.addSopInstance(new SopInstance(sopUID, frame));
                }
            }
        }
    }
}
 
Example #23
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 #24
Source File: DicomProgress.java    From weasis-dicom-tools with Eclipse Public License 2.0 5 votes vote down vote up
public String getErrorComment() {
    Attributes dcm = attributes;
    if (dcm == null) {
        return null;
    }
    return dcm.getString(Tag.ErrorComment);
}
 
Example #25
Source File: DicomProgress.java    From weasis-dicom-tools with Eclipse Public License 2.0 5 votes vote down vote up
public int getStatus() {
    if (isCancel()) {
        return Status.Cancel;
    }
    Attributes dcm = attributes;
    if (dcm == null) {
        return Status.Pending;
    }
    return dcm.getInt(Tag.Status, Status.Pending);
}
 
Example #26
Source File: StorageCommitmentService.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
private void addCommitmentItemSequence(Attributes attrs, int tag, List<CommitmentItem> items) {
  if (items.size() > 0) {
    Sequence sequence = attrs.newSequence(tag, items.size());
    for (CommitmentItem item : items) {
      Attributes seqElementAttributes = new Attributes();
      seqElementAttributes
          .setString(Tag.ReferencedSOPInstanceUID, VR.UI, item.getInstanceUid());
      seqElementAttributes.setString(Tag.ReferencedSOPClassUID, VR.UI, item.getClassUid());
      if (item.getFailureReason() != null) {
        seqElementAttributes.setInt(Tag.FailureReason, VR.US, item.getFailureReason());
      }
      sequence.add(seqElementAttributes);
    }
  }
}
 
Example #27
Source File: CMoveService.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
private void sendPendingResponse(
    int remainingInstances,
    int successfullInstances,
    int failedInstances)
    throws CancellationException {
  Attributes attributes = new Attributes();
  attributes.setInt(Tag.NumberOfRemainingSuboperations, VR.US, remainingInstances);
  attributes.setInt(Tag.NumberOfCompletedSuboperations, VR.US, successfullInstances);
  attributes.setInt(Tag.NumberOfFailedSuboperations, VR.US, failedInstances);
  // no code path for warnings
  attributes.setInt(Tag.NumberOfWarningSuboperations, VR.US, 0);
  as.tryWriteDimseRSP(pc, Commands.mkCMoveRSP(cmd, Status.Pending), attributes);
}
 
Example #28
Source File: SopInstance.java    From weasis-dicom-tools with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void toXml(Writer result) throws IOException {
    result.append("\n<");
    result.append(Xml.Level.INSTANCE.getTagName());
    result.append(" ");
    Xml.addXmlAttribute(Tag.SOPInstanceUID, sopInstanceUID, result);
    // file_tsuid DICOM Transfer Syntax UID (0002,0010)
    Xml.addXmlAttribute(Tag.TransferSyntaxUID, transferSyntaxUID, result);
    Xml.addXmlAttribute(Tag.ImageComments, imageComments, result);
    Xml.addXmlAttribute(Tag.InstanceNumber, getStringInstanceNumber(), result);
    Xml.addXmlAttribute("DirectDownloadFile", directDownloadFile, result);
    result.append("/>");
}
 
Example #29
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 #30
Source File: CFindService.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
private static String getResultKey(JSONObject jsonObject) {
  return AttributesUtil.getTagValueOrNull(jsonObject,
      TagUtils.toHexString(Tag.StudyInstanceUID)) + "_" +
      AttributesUtil.getTagValueOrNull(jsonObject,
          TagUtils.toHexString(Tag.SeriesInstanceUID)) + "_" +
      AttributesUtil.getTagValueOrNull(jsonObject,
          TagUtils.toHexString(Tag.SOPInstanceUID));
}