Java Code Examples for org.dcm4che3.data.Attributes#setInt()
The following examples show how to use
org.dcm4che3.data.Attributes#setInt() .
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: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 6 votes |
@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 2
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 6 votes |
@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 3
Source File: StorageCommitmentService.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
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 4
Source File: CMoveService.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
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 5
Source File: AttributesUtilTest.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Test public void testJsonToAttributes_intType() throws Exception { JSONObject jsonObj = new JSONObject("{\"" + TagUtils.toHexString(Tag.ConcatenationFrameOffsetNumber) + "\": {\"vr\": \"UL\",\"Value\": [1, 1]}}"); Attributes attrs = AttributesUtil.jsonToAttributes(jsonObj); Attributes expected = new Attributes(); expected.setInt(Tag.ConcatenationFrameOffsetNumber, VR.UL, 1, 1); assertThat(attrs).isEqualTo(expected); }
Example 6
Source File: StubCStoreService.java From healthcare-dicom-dicomweb-adapter with Apache License 2.0 | 5 votes |
@Override protected void store( Association association, PresentationContext presentationContext, Attributes request, PDVInputStream dataStream, Attributes response) throws DicomServiceException { response.setInt(Tag.Status, VR.US, statusCode); }
Example 7
Source File: AbstractStowrs.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
protected static void setEncapsulatedDocumentAttributes(Path bulkDataFile, Attributes metadata, String mimeType) { metadata.setInt(Tag.InstanceNumber, VR.IS, 1); metadata.setString(Tag.ContentDate, VR.DA, DateUtils.formatDA(null, new Date(bulkDataFile.toFile().lastModified()))); metadata.setString(Tag.ContentTime, VR.TM, DateUtils.formatTM(null, new Date(bulkDataFile.toFile().lastModified()))); metadata.setString(Tag.AcquisitionDateTime, VR.DT, DateUtils.formatTM(null, new Date(bulkDataFile.toFile().lastModified()))); metadata.setString(Tag.BurnedInAnnotation, VR.CS, "YES"); metadata.setNull(Tag.DocumentTitle, VR.ST); metadata.setNull(Tag.ConceptNameCodeSequence, VR.SQ); metadata.setString(Tag.MIMETypeOfEncapsulatedDocument, VR.LO, mimeType); }
Example 8
Source File: StoreScpForward.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
@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 9
Source File: ServiceUtil.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
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 10
Source File: ServiceUtil.java From weasis-dicom-tools with Eclipse Public License 2.0 | 5 votes |
public static void notifyProgession(DicomProgress p, Attributes cmd, ProgressStatus ps, int numberOfSuboperations) { if (p != null && cmd != null) { int c; int f; int r; int w; if (p.getAttributes() == null) { c = 0; f = 0; w = 0; r = numberOfSuboperations; } else { c = p.getNumberOfCompletedSuboperations(); f = p.getNumberOfFailedSuboperations(); w = p.getNumberOfWarningSuboperations(); r = numberOfSuboperations - (c + f + w); } if (r < 1) { r = 1; } if (ps == ProgressStatus.COMPLETED) { c++; } else if (ps == ProgressStatus.FAILED) { f++; } else if (ps == ProgressStatus.WARNING) { w++; } cmd.setInt(Tag.NumberOfCompletedSuboperations, VR.US, c); cmd.setInt(Tag.NumberOfFailedSuboperations, VR.US, f); cmd.setInt(Tag.NumberOfWarningSuboperations, VR.US, w); cmd.setInt(Tag.NumberOfRemainingSuboperations, VR.US, r - 1); } }
Example 11
Source File: StowrsMultiFiles.java From weasis-dicom-tools with Eclipse Public License 2.0 | 4 votes |
public DicomState uploadDicom(List<String> filesOrFolders, boolean recursive) throws IOException { HttpURLConnection httpPost = buildConnection(); DicomState state = new DicomState(new DicomProgress()); String message = null; int nbFile = 0; try (DataOutputStream out = new DataOutputStream(httpPost.getOutputStream())) { for (String entry : filesOrFolders) { File file = new File(entry); if (file.isDirectory()) { List<File> fileList = new ArrayList<>(); FileUtil.getAllFilesInDirectory(file, fileList, recursive); for (File f : fileList) { uploadFile(f, out); nbFile++; } } else { uploadFile(file, out); nbFile++; } } Attributes error = writeEndMarkers(httpPost, out); if (error == null) { state.setStatus(Status.Success); message = "all the files has been tranfered"; } else { message = "one or more files has not been tranfered"; state.setStatus(Status.OneOrMoreFailures); DicomProgress p = state.getProgress(); if (p != null) { Sequence seq = error.getSequence(Tag.FailedSOPSequence); if (seq != null && !seq.isEmpty()) { Attributes cmd = Optional.ofNullable(p.getAttributes()).orElseGet(Attributes::new); cmd.setInt(Tag.Status, VR.US, Status.OneOrMoreFailures); cmd.setInt(Tag.NumberOfCompletedSuboperations, VR.US, nbFile); cmd.setInt(Tag.NumberOfFailedSuboperations, VR.US, seq.size()); cmd.setInt(Tag.NumberOfWarningSuboperations, VR.US, 0); cmd.setInt(Tag.NumberOfRemainingSuboperations, VR.US, 0); p.setAttributes(cmd); message = seq.stream().map(s -> s.getString(Tag.ReferencedSOPInstanceUID, "Unknown SopUID") + " -> " + s.getString(Tag.FailureReason)).collect(Collectors.joining(",")); return DicomState.buildMessage(state, null, new RuntimeException("Failed instances: " + message)); } } } } catch (Exception e) { state.setStatus(Status.UnableToProcess); LOGGER.error("STOWRS: error when posting data", e); //$NON-NLS-1$ return DicomState.buildMessage(state, "STOWRS: error when posting data", e); } finally { removeConnection(httpPost); } return DicomState.buildMessage(state, message, null); }
Example 12
Source File: StoreSCP.java From weasis-dicom-tools with Eclipse Public License 2.0 | 4 votes |
@Override protected void store(Association as, PresentationContext pc, Attributes rq, PDVInputStream data, Attributes rsp) throws IOException { if (authorizedCallingNodes != null && !authorizedCallingNodes.isEmpty()) { DicomNode sourceNode = DicomNode.buildRemoteDicomNode(as); boolean valid = authorizedCallingNodes.stream().anyMatch(n -> n.getAet().equals(sourceNode.getAet()) && (!n.isValidateHostname() || n.equalsHostname(sourceNode.getHostname()))); if (!valid) { rsp.setInt(Tag.Status, VR.US, Status.NotAuthorized); LOGGER.error("Refused: not authorized (124H). Source node: {}. SopUID: {}", sourceNode, rq.getString(Tag.AffectedSOPInstanceUID)); return; } } rsp.setInt(Tag.Status, VR.US, status); String cuid = rq.getString(Tag.AffectedSOPClassUID); String iuid = rq.getString(Tag.AffectedSOPInstanceUID); String tsuid = pc.getTransferSyntax(); File file = new File(storageDir, TMP_DIR + File.separator + iuid); try { Attributes fmi = as.createFileMetaInformation(iuid, cuid, tsuid); storeTo(as, fmi, data, file); String filename; if (filePathFormat == null) { filename = iuid; } else { Attributes a = fmi; Matcher regexMatcher = regex.matcher(filePathFormat.toString()); while (regexMatcher.find()) { if (!regexMatcher.group(1).startsWith("0002")) { a = parse(file); a.addAll(fmi); break; } } filename = filePathFormat.format(a); } renameTo(as, file, new File(storageDir, filename)); } catch (Exception e) { deleteFile(as, file); throw new DicomServiceException(Status.ProcessingFailure, e); } }