示例#1
0
  @Override
  public void readValue(Object data, Tagable tagabale) {
    if (data instanceof MacroSeqData) {
      MacroSeqData macro = (MacroSeqData) data;
      Object val = getValue(macro.getAttributes());
      if (val instanceof Sequence) {
        Sequence seq = (Sequence) val;
        if (!seq.isEmpty()) {
          val = seq.get(0);
        }
      }

      if (val instanceof Attributes) {
        Attributes dataset = (Attributes) val;
        Predicate<? super Attributes> predicate = macro.getApplicable();
        if (predicate == null || predicate.test(dataset)) {
          for (TagW tag : macro.getTags()) {
            if (tag != null) {
              tag.readValue(dataset, tagabale);
            }
          }
        }
      }
    }
  }
示例#2
0
 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;
 }
  private void adjustReferencedImages(Attributes attrs, int sqtag) {
    Sequence sq = attrs.getSequence(sqtag);
    if (sq == null) return;

    ArrayList<Attributes> newRefs = new ArrayList<Attributes>();
    for (Iterator<Attributes> itr = sq.iterator(); itr.hasNext(); ) {
      Attributes ref = (Attributes) itr.next();
      String cuid = legacySOPClassUID(ref.getString(Tag.ReferencedSOPClassUID));
      if (cuid == null) continue;

      itr.remove();
      String iuid = uidMapper.get(ref.getString(Tag.ReferencedSOPInstanceUID));
      int[] frames = ref.getInts(Tag.ReferencedFrameNumber);
      int n = frames == null ? nofAccessor.getNumberOfFrames(iuid) : frames.length;
      ref.remove(Tag.ReferencedFrameNumber);
      ref.setString(Tag.ReferencedSOPClassUID, VR.UI, cuid);
      for (int i = 0; i < n; i++) {
        Attributes newRef = new Attributes(ref);
        newRef.setString(
            Tag.ReferencedSOPInstanceUID,
            VR.UI,
            iuid + '.' + (frames != null ? frames[i] : (i + 1)));
        newRefs.add(newRef);
      }
    }
    for (Attributes ref : newRefs) sq.add(ref);
  }
 private Attributes nestedKeys(int[] tags) {
   Attributes item = attrs;
   for (int i = 0; i < tags.length - 1; i++) {
     int tag = tags[i];
     Sequence sq = item.getSequence(tag);
     if (sq == null) sq = item.newSequence(tag, 1);
     if (sq.isEmpty()) sq.add(new Attributes());
     item = sq.get(0);
   }
   return item;
 }
示例#5
0
  private Attributes selectVOILUT(Attributes psAttrs, String iuid, int frame) {
    Sequence voiLUTs = psAttrs.getSequence(Tag.SoftcopyVOILUTSequence);
    if (voiLUTs != null)
      for (Attributes voiLUT : voiLUTs) {
        Sequence refImgs = voiLUT.getSequence(Tag.ReferencedImageSequence);
        if (refImgs == null || refImgs.isEmpty()) return voiLUT;
        for (Attributes refImg : refImgs) {
          if (iuid.equals(refImg.getString(Tag.ReferencedSOPInstanceUID))) {
            int[] refFrames = refImg.getInts(Tag.ReferencedFrameNumber);
            if (refFrames == null) return voiLUT;

            for (int refFrame : refFrames) if (refFrame == frame) return voiLUT;
          }
        }
      }
    return null;
  }
示例#6
0
  private void storageFailed(String iuid, String cuid, int failureReason) {
    Attributes sopRef = new Attributes(3);
    sopRef.setString(Tag.ReferencedSOPClassUID, VR.UI, cuid);
    sopRef.setString(Tag.ReferencedSOPInstanceUID, VR.UI, iuid);
    sopRef.setInt(Tag.FailureReason, VR.US, failureReason);
    if (failedSOPSequence == null)
      failedSOPSequence = response.newSequence(Tag.FailedSOPSequence, 10);

    failedSOPSequence.add(sopRef);
  }
示例#7
0
  private Response buildResponse() {
    //        if (sopSequence.isEmpty())
    //            throw new WebApplicationException(Status.CONFLICT);

    return Response.status(
            sopSequence.isEmpty()
                ? Status.CONFLICT
                : failedSOPSequence == null ? Status.OK : Status.ACCEPTED)
        .entity(
            new StreamingOutput() {

              @Override
              public void write(OutputStream out) throws IOException, WebApplicationException {
                try {
                  SAXTransformer.getSAXWriter(new StreamResult(out)).write(response);
                } catch (Exception e) {
                  throw new WebApplicationException(e);
                }
              }
            })
        .type(MediaTypes.APPLICATION_DICOM_XML_TYPE)
        .build();
  }
示例#8
0
  private void storeMetadataAndBulkdata(StoreSession session, MetaDataPathTSTuple part) {
    Attributes ds = null;
    if (creatorType == CreatorType.JSON_BULKDATA) {
      try {
        ds = parseJSON(part.getPath().toFile().getPath());
      } catch (Exception e) {
        storageFailed(NOT_PARSEABLE_IUID, NOT_PARSEABLE_CUID, METADATA_NOT_PARSEABLE);
        return;
      }
    } else {
      try {
        ds = SAXReader.parse(part.getPath().toUri().toString());
      } catch (Exception e) {
        storageFailed(NOT_PARSEABLE_IUID, NOT_PARSEABLE_CUID, METADATA_NOT_PARSEABLE);
        return;
      }
    }

    String iuid = ds.getString(Tag.SOPInstanceUID);
    String cuid = ds.getString(Tag.SOPClassUID);
    Attributes fmi = ds.createFileMetaInformation(part.getTransferSyntax());
    if (!resolveBulkdata(session, fmi, ds)) {
      storageFailed(iuid, cuid, MISSING_BULKDATA);
      return;
    }
    try {
      checkStudyInstanceUID(ds.getString(Tag.StudyInstanceUID));
      checkTransferCapability(cuid, fmi.getString(Tag.TransferSyntaxUID));
      StoreContext context = storeService.createStoreContext(session);
      storeService.writeSpoolFile(context, fmi, ds);
      storeService.store(context);
      sopSequence.add(sopRef(context));
    } catch (DicomServiceException e) {
      storageFailed(iuid, cuid, e.getStatus());
    }
  }
示例#9
0
 private void storeDicomObject(StoreSession session, InputStream in) throws DicomServiceException {
   StoreContext context;
   try {
     context = storeService.createStoreContext(session);
     storeService.writeSpoolFile(context, null, in);
     storeService.parseSpoolFile(context);
   } catch (DicomServiceException e) {
     if (e.getStatus() == StoreService.DATA_SET_NOT_PARSEABLE) {
       storageFailed(NOT_PARSEABLE_IUID, NOT_PARSEABLE_CUID, METADATA_NOT_PARSEABLE);
       return;
     }
     throw e;
   }
   Attributes attrs = context.getAttributes();
   try {
     checkStudyInstanceUID(attrs.getString(Tag.StudyInstanceUID));
     checkTransferCapability(attrs.getString(Tag.SOPClassUID), context.getTransferSyntax());
     storeService.store(context);
     sopSequence.add(sopRef(context));
   } catch (DicomServiceException e) {
     storageFailed(
         attrs.getString(Tag.SOPInstanceUID), attrs.getString(Tag.SOPClassUID), e.getStatus());
   }
 }
 @Test
 public void testPart10Deflated() throws Exception {
   Attributes attrs = readFromResource("report_dfl", IncludeBulkData.YES);
   Sequence seq = attrs.getSequence(null, Tag.ContentSequence);
   assertEquals(5, seq.size());
 }
 @Test
 public void testPart10ExplicitVR() throws Exception {
   Attributes attrs = readFromResource("DICOMDIR", IncludeBulkData.YES);
   Sequence seq = attrs.getSequence(null, Tag.DirectoryRecordSequence);
   assertEquals(44, seq.size());
 }