private Attributes sopRef(StoreContext ctx) { StoreSession session = ctx.getStoreSession(); Attributes attrs = ctx.getAttributes(); Attributes sopRef = new Attributes(5); String cuid = attrs.getString(Tag.SOPClassUID); String iuid = attrs.getString(Tag.SOPInstanceUID); String series_iuid = attrs.getString(Tag.SeriesInstanceUID); String study_iuid = attrs.getString(Tag.StudyInstanceUID); sopRef.setString(Tag.ReferencedSOPClassUID, VR.UI, cuid); sopRef.setString(Tag.ReferencedSOPInstanceUID, VR.UI, iuid); sopRef.setString( Tag.RetrieveURL, VR.UR, wadoURL + study_iuid + "/series/" + series_iuid + "/instances/" + iuid); Attributes coercedAttrs = ctx.getCoercedOriginalAttributes(); if (!coercedAttrs.isEmpty()) { sopRef.setInt(Tag.WarningReason, VR.US, org.dcm4che3.net.Status.CoercionOfDataElements); Attributes item = new Attributes(4); Sequence origAttrsSeq = sopRef.ensureSequence(Tag.OriginalAttributesSequence, 1); origAttrsSeq.add(item); item.setDate(Tag.AttributeModificationDateTime, VR.DT, new Date()); item.setString(Tag.ModifyingSystem, VR.LO, session.getStoreParam().getModifyingSystem()); item.setString(Tag.SourceOfPreviousValues, VR.LO, session.getRemoteAET()); item.newSequence(Tag.ModifiedAttributesSequence, 1).add(coercedAttrs); } return sopRef; }
@Override public StoreContext spool( String localAETitle, String remoteAETitle, InputStream in, InstanceAvailableCallback callback) throws Exception { StoreContext context; ApplicationEntity localAE = aeCache.findApplicationEntity(localAETitle); StoreSession session = storeService.createStoreSession(storeService); session.setSource( new GenericParticipant(localAE.getConnections().get(0).getHostname(), "WadoRS Fetch")); session.setRemoteAET(remoteAETitle); ArchiveAEExtension arcAEExt = aeCache.get(localAETitle).getAEExtension(ArchiveAEExtension.class); session.setArchiveAEExtension(arcAEExt); storeService.init(session); context = storeService.createStoreContext(session); try { DicomInputStream din = new DicomInputStream(in); Attributes fmi = din.getFileMetaInformation(); storeService.writeSpoolFile(context, fmi, din); } catch (Exception e) { throw new Exception("Failed to spool WadoRS response from AE " + remoteAETitle); } return context; }
@POST @Path("/studies") @Consumes({"multipart/related", "multipart/form-data"}) public Response storeInstances(InputStream in) throws Exception { String str = req.toString(); LOG.info(str); init(); final StoreSession session = storeService.createStoreSession(storeService); session.setSource(new HttpSource(request)); ApplicationEntity sourceAE = aeCache.findAE(new HttpSource(request)); session.setRemoteAET( sourceAE != null ? sourceAE.getAETitle() : null); // add AE for the web source session.setArchiveAEExtension(arcAE); storeService.initStorageSystem(session); storeService.initSpoolDirectory(session); storeService.initMetaDataStorageSystem(session); try { new MultipartParser(boundary) .parse( in, new MultipartParser.Handler() { @Override public void bodyPart(int partNumber, MultipartInputStream in) throws IOException { Map<String, List<String>> headerParams = in.readHeaderParams(); String transferSyntax = null; LOG.info("storeInstances: Extract Part #{}{}", partNumber, headerParams); String contentType = getHeaderParamValue(headerParams, "content-type"); String contentLocation = getHeaderParamValue(headerParams, "content-location"); MediaType mediaType; try { mediaType = contentType == null ? MediaType.TEXT_PLAIN_TYPE : MediaType.valueOf(contentType); } catch (IllegalArgumentException e) { LOG.info( "storeInstances: Ignore Part with illegal Content-Type={}", contentType); in.skipAll(); return; } // check for metadata transfer syntax if (contentLocation == null) { transferSyntax = contentType.contains("transfer-syntax=") ? contentType.split("transfer-syntax=")[1] : null; } if (!creatorType.readBodyPart( StowRS.this, session, in, mediaType, contentLocation, transferSyntax)) { LOG.info("storeInstances: Ignore Part with Content-Type={}", mediaType); in.skipAll(); } } }); creatorType.storeMetadataAndBulkdata(this, session); } finally { storeService.onClose(session); } return buildResponse(); }