private int store(String aet, String cuid, DicomObject dataset) throws IOException, InterruptedException, GeneralSecurityException { if (cuid == null) { cuid = dataset.getString(Tag.SOPClassUID); } setTransferCapability( new TransferCapability[] { new TransferCapability(cuid, NATIVE_LE_TS, TransferCapability.SCU) }); Association assoc = open(aet); TransferCapability tc = assoc.getTransferCapabilityAsSCU(cuid); if (tc == null) { throw new NoPresentationContextException( UIDDictionary.getDictionary().prompt(UID.KeyObjectSelectionDocumentStorage)); } String tsuid = tc.getTransferSyntax()[0]; LOG.debug("Send C-STORE request to {}:\n{}", aet, dataset); RspHandler rspHandler = new RspHandler(); assoc.cstore( cuid, dataset.getString(Tag.SOPInstanceUID), priority, new DataWriterAdapter(dataset), tsuid, rspHandler); assoc.waitForDimseRSP(); try { assoc.release(true); } catch (InterruptedException t) { LOG.error("Failed to release association! aet:" + aet, t); } return rspHandler.getStatus(); }
private DicomObject doNCreate(DicomObject rq, DicomObject data, DicomObject rsp) throws DicomServiceException { String iuid = rq.getString(Tag.AffectedSOPInstanceUID); if (iuid == null) iuid = rsp.getString(Tag.AffectedSOPInstanceUID); File f = mkFile(iuid); if (f.exists()) { throw new DicomServiceException(rq, Status.DuplicateSOPinstance); } data.initFileMetaInformation( UID.ModalityPerformedProcedureStepSOPClass, iuid, UID.ExplicitVRLittleEndian); try { store(f, data); try { Context.openSession(); DicomUtils.updateStudyPerformedStatusByMpps(data); } catch (Exception e) { debug("Can not update database with"); debug(data.toString()); e.printStackTrace(); } finally { Context.closeSession(); } } catch (Exception e) { throw new DicomServiceException(rq, Status.ProcessingFailure); } return null; }
private BufferedImage windowMonochrome( ImageListViewCell displayedCell, BufferedImage srcImg, float windowLocation, float windowWidth) { BufferedImage destImg = new BufferedImage(srcImg.getWidth(), srcImg.getHeight(), BufferedImage.TYPE_INT_RGB); boolean isSigned = false; int minValue = 0; { // hack: try to determine signedness and minValue from DICOM metadata if available -- // the BufferedImage's metadata don't contain that information reliably. // Only works for some special cases ImageListViewModelElement elt = displayedCell.getDisplayedModelElement(); if (elt instanceof DicomImageListViewModelElement) { DicomImageListViewModelElement delt = (DicomImageListViewModelElement) elt; DicomObject imgMetadata = delt.getDicomImageMetaData(); int bitsAllocated = imgMetadata.getInt(Tag.BitsAllocated); isSigned = (1 == imgMetadata.getInt(Tag.PixelRepresentation)); if (isSigned && (bitsAllocated > 0)) { minValue = -(1 << (bitsAllocated - 1)); } } } final int windowedImageGrayscalesCount = 256; // for BufferedImage.TYPE_INT_RGB float scale = windowedImageGrayscalesCount / windowWidth; float offset = (windowWidth / 2 - windowLocation) * scale; if (!(srcImg.getColorModel().getColorSpace().getType() == ColorSpace.TYPE_GRAY)) { throw new IllegalArgumentException("source image must be grayscales"); } Raster srcRaster = srcImg.getRaster(); if (srcRaster.getNumBands() != 1) { throw new IllegalArgumentException( "grayscale source image must have one color band, but has " + srcRaster.getNumBands() + "??"); } WritableRaster resultRaster = destImg.getRaster(); for (int x = 0; x < srcImg.getWidth(); x++) { for (int y = 0; y < srcImg.getHeight(); y++) { int srcGrayValue = srcRaster.getSample(x, y, 0); if (isSigned) { srcGrayValue = (int) (short) srcGrayValue; // will only work for 16-bit signed... } float destGrayValue = scale * srcGrayValue + offset; // clamp if (destGrayValue < 0) { destGrayValue = 0; } else if (destGrayValue >= windowedImageGrayscalesCount) { destGrayValue = windowedImageGrayscalesCount - 1; } resultRaster.setSample(x, y, 0, destGrayValue); resultRaster.setSample(x, y, 1, destGrayValue); resultRaster.setSample(x, y, 2, destGrayValue); } } return destImg; }
public static TCEncapsulatedDocument create(TCReferencedInstance ref) throws Exception { Instance instance = ((TCQueryLocal) JNDIUtils.lookup(TCQueryLocal.JNDI_NAME)) .findInstanceByUID(ref.getInstanceUID()); List<org.dcm4chee.archive.entity.File> files = instance.getFiles(); DicomObject attrs = instance.getAttributes(false); attrs.remove(Tag.EncapsulatedDocument); MimeType mimeType = null; String mimeTypeStr = attrs.getString(Tag.MIMETypeOfEncapsulatedDocument); if (mimeTypeStr != null) { mimeType = MimeType.get(mimeTypeStr); } if (mimeType == null) { mimeType = getDocumentMimeTypeFromLabel(attrs.getString(Tag.ContentLabel)); } String fsId = files.get(0).getFileSystem().getDirectoryPath(); String fileId = files.get(0).getFilePath(); File file = fsId.startsWith("tar:") ? TarRetrieveDelegate.getInstance().retrieveFileFromTar(fsId, fileId) : FileUtils.resolve(new File(fsId, fileId)); return new TCEncapsulatedDocument(mimeType, ref, attrs, file); }
public static TCDocumentObject create(TCReferencedInstance ref) throws Exception { Instance instance = ((TCQueryLocal) JNDIUtils.lookup(TCQueryLocal.JNDI_NAME)) .findInstanceByUID(ref.getInstanceUID()); if (instance == null) { return null; } DicomObject attrs = instance.getAttributes(false); MimeType mimeType = null; String mimeTypeStr = attrs.getString(Tag.MIMETypeOfEncapsulatedDocument); if (mimeTypeStr != null) { mimeType = MimeType.get(mimeTypeStr); } if (mimeType == null) { mimeType = getDocumentMimeTypeFromLabel(attrs.getString(Tag.ContentLabel)); } if (mimeType != null) { DocumentType docType = mimeType.getDocumentType(); if (TCImageDocument.DOC_TYPES.contains(docType)) { return TCImageDocument.create(ref); } else if (TCEncapsulatedDocument.DOC_TYPES.contains(docType)) { return TCEncapsulatedDocument.create(ref); } } throw new Exception( "Unable to create TC encapsulated object: Mime type not supported (" + mimeTypeStr + ")"); }
@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) { } } } }
private DicomStreamMetaData copyMeta(DicomImageReader reader, String tsuid) throws IOException { DicomStreamMetaData oldMeta = (DicomStreamMetaData) reader.getStreamMetadata(); DicomStreamMetaData ret = new DicomStreamMetaData(); DicomObject ds = oldMeta.getDicomObject(); DicomObject newDs = new BasicDicomObject(); ds.copyTo(newDs); newDs.putString(Tag.TransferSyntaxUID, VR.UI, tsuid); ret.setDicomObject(newDs); return ret; }
private void insertDicomTags( int dcmobject_id, DicomObject obj, Integer parentId, PreparedStatement stmt) throws Exception { for (Iterator<DicomElement> it = obj.iterator(); it.hasNext(); ) { DicomElement e = it.next(); StringBuffer sb = new StringBuffer(); try { String[] values = e.getStrings(obj.getSpecificCharacterSet(), false); sb.append(values[0].replaceAll("\0", "")); int i; for (i = 1; i < values.length; i++) { sb.append("/").append(values[i].replaceAll("\0", "")); } } catch (Exception ee) { try { sb.append(e.getString(obj.getSpecificCharacterSet(), false)); } catch (Exception e2) { } } stmt.setInt(1, dcmobject_id); stmt.setString(2, DicomHeader.toTagString(e.tag())); stmt.setString(3, e.vr().toString()); // only the first 150 chars are saved if the tag-value is longer if (sb.length() > 150) { stmt.setString( 4, sb.toString().substring(0, 150).concat("*** end of tag-value not applicable ***")); } else { stmt.setString(4, sb.toString()); } stmt.setInt(5, itemOrder); if (parentId == null) { stmt.setNull(6, Types.INTEGER); } else { stmt.setInt(6, parentId); } stmt.addBatch(); // System.out.println( stmt ); itemOrder++; if (e.countItems() > 0) { if (e.hasDicomObjects()) { for (int i = 0; i < e.countItems(); i++) { insertDicomTags(dcmobject_id, e.getDicomObject(i), itemOrder - 1, stmt); } } } } }
public static TCImageDocument create(TCReferencedInstance ref) throws Exception { DicomObject attrs = ((TCQueryLocal) JNDIUtils.lookup(TCQueryLocal.JNDI_NAME)) .findInstanceByUID(ref.getInstanceUID()) .getAttributes(false); attrs.remove(Tag.PixelData); return new TCImageDocument( checkMimeType(getDocumentMimeTypeFromLabel(attrs.getString(Tag.ContentLabel))), ref, attrs); }
@Override public void onDimseRSP(Association as, DicomObject cmd, DicomObject data) { int status = cmd.getInt(Tag.Status); switch (status) { case 0: { LOG.debug("Dataset stored at {}", as.getCalledAET()); break; } case 0xA700: { LOG.error( "Failed to store dataset - Out Of Resources! (status: {}H, calledAET:{}, comment:{})", new Object[] { StringUtils.shortToHex(status), as.getCalledAET(), cmd.getString(Tag.ErrorComment) }); break; } case 0xA900: { LOG.error( "Failed to store dataset - Dataset doesn't match SOP class! (status: {}H, calledAET:{}, comment:{})", new Object[] { StringUtils.shortToHex(status), as.getCalledAET(), cmd.getString(Tag.ErrorComment) }); break; } case 0xC000: { LOG.error( "Failed to store dataset - Can't understand! (status: {}H, calledAET:{}, comment:{})", new Object[] { StringUtils.shortToHex(status), as.getCalledAET(), cmd.getString(Tag.ErrorComment) }); break; } case 0xB000: case 0xB006: case 0xB007: LOG.warn( "Dataset stored at {} with status {}H", as.getCalledAET(), StringUtils.shortToHex(status)); break; default: LOG.error( "Failed to store dataset! (status: {}H, calledAET:{}, comment:{})", new Object[] { StringUtils.shortToHex(status), as.getCalledAET(), cmd.getString(Tag.ErrorComment) }); } }
@Override public void addMedia(MediaElement media) { if (media instanceof DicomVideoElement) { if (media.getMediaReader() instanceof DicomMediaIO) { DicomMediaIO dicomImageLoader = (DicomMediaIO) media.getMediaReader(); frames = dicomImageLoader.getMediaElementNumber(); byte[] mpeg = null; try { width = dicomImageLoader.getWidth(0); height = dicomImageLoader.getHeight(0); DicomObject pixData = dicomImageLoader.readPixelData(); mpeg = pixData.get(TagW.PixelData.getId()).getFragment(1); } catch (Exception e) { e.printStackTrace(); } if (mpeg != null) { OutputStream tempFileStream = null; try { File videoFile = File.createTempFile( "video_", ".mpg", AbstractProperties.APP_TEMP_DIR); // $NON-NLS-1$ //$NON-NLS-2$ tempFileStream = new BufferedOutputStream(new FileOutputStream(videoFile)); tempFileStream.write(mpeg); DicomVideoElement dicom = (DicomVideoElement) media; dicom.setVideoFile(videoFile); this.add(dicom); } catch (Exception e) { e.printStackTrace(); } finally { // Close file. if (tempFileStream != null) { try { tempFileStream.close(); } catch (Exception e) { } } } } // DataExplorerModel model = (DataExplorerModel) getTagValue(TagW.ExplorerModel); // if (model != null) { // model.firePropertyChange(new ObservableEvent(ObservableEvent.BasicAction.Add, model, // null, // new SeriesEvent(SeriesEvent.Action.AddImage, this, insertIndex + frames))); // } } } }
public void setAttributes(DicomObject attrs) { PersonName pn = new PersonName(attrs.getString(Tag.HumanPerformerName)); this.humanPerformerName = pn.componentGroupString(PersonName.SINGLE_BYTE, false).toUpperCase(); this.humanPerformerIdeographicName = pn.componentGroupString(PersonName.IDEOGRAPHIC, false); this.humanPerformerPhoneticName = pn.componentGroupString(PersonName.PHONETIC, false); if (AttributeFilter.isSoundexEnabled()) { this.humanPerformerFamilyNameSoundex = AttributeFilter.toSoundex(pn, PersonName.FAMILY, "*"); this.humanPerformerGivenNameSoundex = AttributeFilter.toSoundex(pn, PersonName.GIVEN, "*"); } }
private int sendIAN(String aet, DicomObject ian) throws IOException, InterruptedException, GeneralSecurityException { String iuid = UIDUtils.createUID(); Association assoc = open(aet); TransferCapability tc = assoc.getTransferCapabilityAsSCU(UID.InstanceAvailabilityNotificationSOPClass); RspHandler rspHandler = new RspHandler(); if (tc == null) { tc = assoc.getTransferCapabilityAsSCU(UID.BasicStudyContentNotificationSOPClassRetired); if (tc == null) { throw new NoPresentationContextException( UIDDictionary.getDictionary() .prompt( isOfferStudyContentNotification() ? UID.BasicStudyContentNotificationSOPClassRetired : UID.InstanceAvailabilityNotificationSOPClass)); } String tsuid = tc.getTransferSyntax()[0]; DicomObject scn = toSCN(ian); scn.putString(Tag.SOPInstanceUID, VR.UI, iuid); scn.putString(Tag.SOPClassUID, VR.UI, UID.BasicStudyContentNotificationSOPClassRetired); LOG.debug("Study Content Notification to {}:\n{}", aet, scn); assoc.cstore( UID.BasicStudyContentNotificationSOPClassRetired, iuid, priority, new DataWriterAdapter(scn), tsuid, rspHandler); } else { String tsuid = tc.getTransferSyntax()[0]; LOG.debug("Instance Availability Notification to {}:\n{}", aet, ian); assoc.ncreate(UID.InstanceAvailabilityNotificationSOPClass, iuid, ian, tsuid, rspHandler); } assoc.waitForDimseRSP(); try { assoc.release(true); } catch (InterruptedException t) { LOG.error("Association release failed! aet:" + aet, t); } return rspHandler.getStatus(); }
public Date getDocumentAddedDate() { Date date = metaData.getDate(Tag.ContentDate); Date time = metaData.getDate(Tag.ContentTime); if (date != null && time != null) { return DateUtils.toDateTime(date, time); } else if (date != null) { return date; } return null; }
private DicomObject doNSet(DicomObject rq, DicomObject data) throws DicomServiceException { final String iuid = rq.getString(Tag.RequestedSOPInstanceUID); File f = mkFile(iuid); if (!f.exists()) { throw new DicomServiceException(rq, Status.NoSuchObjectInstance, iuid); } try { DicomObject mpps = dcmOF.load(f); String status = mpps.getString(Tag.PerformedProcedureStepStatus); if (!"IN PROGRESS".equals(status)) { DicomServiceException ex = new DicomServiceException( rq, Status.ProcessingFailure, "Performed Procedure Step Object may no longer be updated"); ex.setErrorID(0xA710); throw ex; } data.copyTo(mpps); store(f, mpps); try { Context.openSession(); DicomUtils.updateStudyPerformedStatusByMpps(mpps); } catch (Exception e) { debug("Can not update database with"); debug(mpps.toString()); e.printStackTrace(); } finally { Context.closeSession(); } } catch (DicomServiceException e) { throw e; } catch (Exception e) { throw new DicomServiceException(rq, Status.ProcessingFailure, e.getMessage()); } return null; }
/** * Set query attributes for C-Move * * @return DicomObject contains initial set of attributes for query */ private DicomObject setCmoveAttributes() { DicomObject returnObject = new BasicDicomObject(); returnObject.putString(Tag.SOPClassUID, VR.UI, UID.RTPlanStorage); returnObject.putString(Tag.SOPInstanceUID, VR.UI, "1.2.34.56"); returnObject.putString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE"); returnObject.putString(Tag.PatientID, VR.LO, ""); returnObject.putString(Tag.StudyInstanceUID, VR.UI, "1.2.1.1"); returnObject.putString(Tag.SeriesInstanceUID, VR.UI, "1.2.1.2"); return returnObject; }
@Override public void onDimseRSP(Association as, DicomObject cmd, DicomObject data) { int status = cmd.getInt(Tag.Status); switch (status) { case 0x0000: case 0x0001: case 0x0002: case 0x0003: break; case 0x0116: LOG.warn( "Received Warning Status 116H (=Attribute Value Out of Range) from remote AE {}", as.getCalledAET()); break; default: LOG.error( "Sending IAN(SCN) failed with status {}H at calledAET:{}", StringUtils.shortToHex(status), as.getCalledAET()); } }
public DicomObject getAttributes(boolean cfindrsp) { DicomObject dataset = DicomObjectUtils.decode(encodedAttributes); if (cfindrsp) { dataset.putInt(Tag.NumberOfSeriesRelatedInstances, VR.IS, numberOfSeriesRelatedInstances); if (fileSetUID != null && fileSetID != null) { dataset.putString(Tag.StorageMediaFileSetUID, VR.UI, fileSetUID); dataset.putString(Tag.StorageMediaFileSetID, VR.SH, fileSetID); } if (retrieveAETs != null || externalRetrieveAET != null) { dataset.putString( Tag.RetrieveAETitle, VR.AE, externalRetrieveAET == null ? retrieveAETs : retrieveAETs == null ? externalRetrieveAET : retrieveAETs + '\\' + externalRetrieveAET); } dataset.putString(Tag.InstanceAvailability, VR.CS, availability.name()); } return dataset; }
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(); } } }
private DicomObject toSCN(DicomObject ian) { DicomObject scn = new BasicDicomObject(); scn.putString(Tag.PatientID, VR.LO, ian.getString(Tag.PatientID)); scn.putString(Tag.PatientName, VR.PN, ian.getString(Tag.PatientName)); scn.putString(Tag.StudyID, VR.SH, ian.getString(Tag.StudyID)); scn.putString(Tag.StudyInstanceUID, VR.UI, ian.getString(Tag.StudyInstanceUID)); DicomElement ianSeriesSeq = ian.get(Tag.ReferencedSeriesSequence); DicomElement scnSeriesSeq = scn.putSequence(Tag.ReferencedSeriesSequence); DicomObject ianSeriesItem, scnSeriesItem, scnSOPItem; DicomElement ianSOPSeq, scnSOPSeq; for (int i = 0, n = ianSeriesSeq.countItems(); i < n; ++i) { ianSeriesItem = ianSeriesSeq.getDicomObject(i); scnSeriesItem = new BasicDicomObject(); scnSeriesItem.putString( Tag.SeriesInstanceUID, VR.UI, ianSeriesItem.getString(Tag.SeriesInstanceUID)); scnSeriesSeq.addDicomObject(scnSeriesItem); ianSOPSeq = ianSeriesItem.get(Tag.ReferencedSOPSequence); scnSOPSeq = scnSeriesItem.putSequence(Tag.ReferencedImageSequence); for (int j = 0, m = ianSOPSeq.countItems(); j < m; ++j) { scnSOPItem = new BasicDicomObject(); ianSOPSeq.getDicomObject(j).exclude(INSTANCE_AVAILABILITY).copyTo(scnSOPItem); scnSOPSeq.addDicomObject(scnSOPItem); } } return scn; }
public String getSeriesInstanceUID() { return metaData.getString(Tag.SeriesInstanceUID); }
private static int eventTypeIdOf(DicomObject result) { return result.contains(Tag.FailedSOPInstanceUIDList) ? 2 : 1; }
private DicomObject mkStgCmtResult(Association as, DicomObject rqdata) { DicomObject result = new BasicDicomObject(); result.putString(Tag.TransactionUID, VR.UI, rqdata.getString(Tag.TransactionUID)); DicomElement rqsq = rqdata.get(Tag.ReferencedSOPSequence); DicomElement resultsq = result.putSequence(Tag.ReferencedSOPSequence); if (stgcmtRetrieveAET != null) { result.putString(Tag.RetrieveAETitle, VR.AE, stgcmtRetrieveAET); } DicomElement failedsq = null; File dir = getDir(as); for (int i = 0, n = rqsq.countItems(); i < n; i++) { DicomObject rqItem = rqsq.getDicomObject(i); String uid = rqItem.getString(Tag.ReferencedSOPInstanceUID); DicomObject resultItem = new BasicDicomObject(); rqItem.copyTo(resultItem); if (stgcmtRetrieveAETs != null) { resultItem.putString(Tag.RetrieveAETitle, VR.AE, stgcmtRetrieveAETs); } File f = new File(dir, uid); if (f.isFile()) { resultsq.addDicomObject(resultItem); } else { resultItem.putInt(Tag.FailureReason, VR.US, NO_SUCH_OBJECT_INSTANCE); if (failedsq == null) { failedsq = result.putSequence(Tag.FailedSOPSequence); } failedsq.addDicomObject(resultItem); } } return result; }
void onCStoreRQ( Association as, int pcid, DicomObject rq, PDVInputStream dataStream, String tsuid, DicomObject rsp) throws IOException { String cuid = rq.getString(Tag.AffectedSOPClassUID); String iuid = rq.getString(Tag.AffectedSOPInstanceUID); DicomObject data = dataStream .readDataset(); // You have one shot to get the data. You can't read twice with // readDataset method. String suid = data.getString(Tag.StudyInstanceUID); // Calendar today = Calendar.getInstance(); // File struturedDestination = new File(destination.getAbsolutePath() + File.separator + // today.get(Calendar.YEAR) + File.separator + today.get(Calendar.MONTH) + File.separator + // today.get(Calendar.DATE) + File.separator + suid); File struturedDestination = new File( destination.getAbsolutePath() + File.separator + "oviyam2" + File.separator + suid); String child[] = struturedDestination.list(); if (child == null) { struturedDestination.mkdirs(); } File file = devnull != null ? struturedDestination : new File(struturedDestination, iuid); // LOG.info("M-WRITE {}", file); try { DicomOutputStream dos = new DicomOutputStream( new BufferedOutputStream(new FileOutputStream(file), fileBufferSize)); try { BasicDicomObject fmi = new BasicDicomObject(); fmi.initFileMetaInformation(cuid, iuid, tsuid); dos.writeFileMetaInformation(fmi); // dataStream.copyTo(dos); dos.writeDataset(data, tsuid); } finally { CloseUtils.safeClose(dos); } } catch (IOException e) { if (devnull == null && file != null) { if (file.delete()) { LOG.info("M-DELETE {}", file); } } throw new DicomServiceException(rq, Status.ProcessingFailure, e.getMessage()); } // Rename the file after it has been written. See DCM-279 /*if (devnull == null && file != null) { File rename = new File(file.getParent(), iuid); LOG.info("M-RENAME {} to {}", file, rename); file.renameTo(rename); if (cache.getJournalRootDir() != null) { cache.record(rename); } }*/ // NetworkQueueUpdateDelegate networkQueueUpdateDelegate = new NetworkQueueUpdateDelegate(); // networkQueueUpdateDelegate.updateReceiveTable(file, as.getCallingAET()); }
public String getStudyInstanceUID() { return metaData.getString(Tag.StudyInstanceUID); }
public String getDocumentName() { return getDocumentNameFromLabel(metaData.getString(Tag.ContentLabel), false); }
public String getDocumentDescription() { return metaData.containsValue(Tag.DocumentTitle) ? metaData.getString(Tag.DocumentTitle) : metaData.getString(Tag.ContentDescription); }
protected static DicomObject createDicomMetaData( MimeType mimeType, String filename, String description, TCReferencedInstance ref, String patId, String issuerOfPatId, String patName, String modality) { Date now = new Date(); DicomObject attrs = new BasicDicomObject(); // patient level if (patId != null) { attrs.putString(Tag.PatientID, VR.LO, patId); } if (issuerOfPatId != null) { attrs.putString(Tag.IssuerOfPatientID, VR.LO, issuerOfPatId); } if (patName != null) { attrs.putString(Tag.PatientName, VR.PN, patName); } // study level attrs.putString(Tag.StudyInstanceUID, VR.UI, ref.getStudyUID()); // series level attrs.putString(Tag.SeriesInstanceUID, VR.UI, ref.getSeriesUID()); attrs.putString(Tag.SeriesDescription, VR.LO, SERIES_DESCRIPTION); attrs.putString(Tag.Modality, VR.CS, modality); // instance level attrs.putString(Tag.SOPInstanceUID, VR.UI, ref.getInstanceUID()); attrs.putString(Tag.SOPClassUID, VR.UI, ref.getClassUID()); attrs.putInt(Tag.InstanceNumber, VR.IS, ref.getInstanceNumber()); attrs.putDate(Tag.InstanceCreationDate, VR.DA, now); attrs.putDate(Tag.InstanceCreationTime, VR.TM, now); attrs.putDate(Tag.ContentDate, VR.DA, now); attrs.putDate(Tag.ContentTime, VR.TM, now); attrs.putString(Tag.ContentLabel, VR.CS, filename); attrs.putString( Tag.ContentDescription, VR.CS, description != null && !description.isEmpty() ? description : getFileName(filename)); return attrs; }
private static DicomObject toDicom(BufferedImage image) throws Exception { int numSamples = image.getColorModel().getNumComponents(); if (numSamples == 4) { numSamples = 3; } String pmi = numSamples > 1 ? "RGB" : "MONOCHROME2"; int bits = image.getColorModel().getComponentSize(0); int allocated = 8; if (bits > 8) { allocated = 16; } DicomObject attrs = new BasicDicomObject(); attrs.putString(Tag.TransferSyntaxUID, VR.UI, UID.ImplicitVRLittleEndian); attrs.putInt(Tag.Rows, VR.US, image.getHeight()); attrs.putInt(Tag.Columns, VR.US, image.getWidth()); attrs.putInt(Tag.SamplesPerPixel, VR.US, numSamples); attrs.putInt(Tag.BitsStored, VR.US, bits); attrs.putInt(Tag.BitsAllocated, VR.US, allocated); attrs.putInt(Tag.PixelRepresentation, VR.US, 0); attrs.putString(Tag.PhotometricInterpretation, VR.CS, pmi); if (numSamples > 1) { attrs.putInt(Tag.PlanarConfiguration, VR.US, 0); } int biType = numSamples == 3 ? BufferedImage.TYPE_INT_RGB : allocated > 8 ? BufferedImage.TYPE_USHORT_GRAY : BufferedImage.TYPE_BYTE_GRAY; BufferedImage tmpImage = image; if (image.getType() != biType) { tmpImage = new BufferedImage(image.getWidth(), image.getHeight(), biType); tmpImage.getGraphics().drawImage(image, 0, 0, null); } byte[] pixelData = null; DataBuffer dataBuffer = tmpImage.getRaster().getDataBuffer(); if (dataBuffer instanceof DataBufferInt) { final int[] data = (int[]) ((DataBufferInt) dataBuffer).getData(); pixelData = new byte[data.length * 3]; int index = 0; for (final int i : data) { pixelData[index++] = (byte) ((i >>> 16) & 0xFF); pixelData[index++] = (byte) ((i >>> 8) & 0xFF); pixelData[index++] = (byte) (i & 0xFF); } } else if (dataBuffer instanceof DataBufferUShort) { final short[] data = (short[]) ((DataBufferUShort) dataBuffer).getData(); pixelData = new byte[data.length * 2]; int index = 0; for (final int i : data) { pixelData[index++] = (byte) ((i >>> 8) & 0xFF); pixelData[index++] = (byte) (i & 0xFF); } } else if (dataBuffer instanceof DataBufferByte) { pixelData = ((DataBufferByte) dataBuffer).getData(); } attrs.putBytes(Tag.PixelData, allocated > 8 ? VR.OW : VR.OB, pixelData); return attrs; }
@Override public DicomObject toDataset() throws Exception { DicomObject attrs = super.toDataset(); attrs.putBytes(Tag.EncapsulatedDocument, VR.OB, getDocumentContent()); return attrs; }