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;
 }
Ejemplo n.º 2
0
  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 + ")");
  }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
  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();
  }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 @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)
           });
   }
 }
Ejemplo n.º 8
0
 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, "*");
   }
 }
Ejemplo n.º 9
0
    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);
    }
 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;
 }
Ejemplo n.º 11
0
 public String getStudyInstanceUID() {
   return metaData.getString(Tag.StudyInstanceUID);
 }
Ejemplo n.º 12
0
 public String getSeriesInstanceUID() {
   return metaData.getString(Tag.SeriesInstanceUID);
 }
Ejemplo n.º 13
0
 public String getSOPClassUID() {
   return metaData.getString(Tag.SOPClassUID);
 }
Ejemplo n.º 14
0
    public boolean readValue(DicomInputStream in) throws IOException {
      int tag = in.tag();
      int len = in.valueLength();
      long pos = in.getStreamPosition();
      DicomObject attrs = in.getDicomObject();
      String uid;
      if (fmi && tag >= 0x00080000) {
        if (replacements == null)
          throw new NoFixException("File Meta Information (0002,eeee) is missing");
        if (FixJpegLS.this.implClassUID != null) {
          uid = attrs.getString(Tag.ImplementationClassUID);
          if (!FixJpegLS.this.implClassUID.equals(uid))
            throw new NoFixException("Implementation Class UID (0002,0012) = " + uid);
        }
        fmi = false;
      }
      switch (tag) {
        case Tag.FileMetaInformationGroupLength:
        case Tag.ItemDelimitationItem:
        case Tag.SequenceDelimitationItem:
          return in.readValue(in);
        case Tag.TransferSyntaxUID:
          in.readValue(in);
          uid = attrs.getString(Tag.TransferSyntaxUID);
          if (!UID.JPEGLSLossless.equals(uid))
            throw new NoFixException("Transfer Syntax UID (0002,0010) = " + DICT.prompt(uid));
          replacements = new ArrayList<Replacement>();
          return true;
        case Tag.ImplementationClassUID:
          if (replacements == null)
            throw new NoFixException("File Meta Information (0002,eeee) is missing");

          in.readValue(in);
          if (FixJpegLS.this.newImplClassUID != null)
            addImplClassUIDReplacements(pos, len, (int) in.getEndOfFileMetaInfoPosition());
          return true;
        case Tag.PixelData:
          if (in.level() == 0) {
            if (len != -1)
              throw new NoFixException("Pixel Data is not encapsulated into Data Fragments");

            pixelData = true;
          }
          return in.readValue(in);
        case Tag.Item:
          if (pixelData) {
            if (len == 0) return true;
            byte[] jpegheader = new byte[17];
            in.readFully(jpegheader);
            byte[] lse = selectLSE(jpegheader);
            in.skipFully(len - 18);
            addItemReplacements(pos, len, lse, in.read() == 0);
            numItems++;
            return true;
          }
      }
      pixelData = false;
      if (len == -1) return in.readValue(in);
      in.skipFully(len);
      return true;
    }
Ejemplo n.º 15
0
 private String getStringFromObject(int tag, DicomObject dicomObject) {
   String returnValue = dicomObject.getString(tag);
   return returnValue == null ? "[ Unknown ]" : returnValue;
 }
Ejemplo n.º 16
0
  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());
  }
Ejemplo n.º 17
0
 public String getDocumentName() {
   return getDocumentNameFromLabel(metaData.getString(Tag.ContentLabel), false);
 }
Ejemplo n.º 18
0
 public String getDocumentDescription() {
   return metaData.containsValue(Tag.DocumentTitle)
       ? metaData.getString(Tag.DocumentTitle)
       : metaData.getString(Tag.ContentDescription);
 }
Ejemplo n.º 19
0
 public void setAttributes(DicomObject attrs) {
   AttributeFilter filter = AttributeFilter.getSeriesAttributeFilter();
   this.seriesInstanceUID = attrs.getString(Tag.SeriesInstanceUID);
   this.seriesNumber = attrs.getString(Tag.SeriesNumber, "");
   this.seriesDescription =
       filter.toUpperCase(attrs.getString(Tag.SeriesDescription, ""), Tag.SeriesDescription);
   this.modality = filter.toUpperCase(attrs.getString(Tag.Modality, ""), Tag.Modality);
   this.institutionalDepartmentName =
       filter.toUpperCase(
           attrs.getString(Tag.InstitutionalDepartmentName, ""), Tag.InstitutionalDepartmentName);
   this.institutionName =
       filter.toUpperCase(attrs.getString(Tag.InstitutionName, ""), Tag.InstitutionName);
   this.stationName = filter.toUpperCase(attrs.getString(Tag.StationName, ""), Tag.StationName);
   String srcAET = attrs.getString(attrs.resolveTag(PrivateTag.CallingAET, PrivateTag.CreatorID));
   if (srcAET != null && srcAET.trim().length() > 1) this.sourceAET = srcAET;
   this.bodyPartExamined =
       filter.toUpperCase(attrs.getString(Tag.BodyPartExamined, ""), Tag.BodyPartExamined);
   this.laterality = filter.toUpperCase(attrs.getString(Tag.Laterality, ""), Tag.Laterality);
   PersonName pn = new PersonName(attrs.getString(Tag.PerformingPhysicianName));
   this.performingPhysicianName =
       pn.componentGroupString(PersonName.SINGLE_BYTE, false).toUpperCase();
   this.performingPhysicianIdeographicName =
       pn.componentGroupString(PersonName.IDEOGRAPHIC, false);
   this.performingPhysicianPhoneticName = pn.componentGroupString(PersonName.PHONETIC, false);
   if (AttributeFilter.isSoundexEnabled()) {
     this.performingPhysicianFamilyNameSoundex =
         AttributeFilter.toSoundex(pn, PersonName.FAMILY, "*");
     this.performingPhysicianGivenNameSoundex =
         AttributeFilter.toSoundex(pn, PersonName.GIVEN, "*");
   }
   this.performedProcedureStepStartDateTime =
       attrs.getDate(Tag.PerformedProcedureStepStartDate, Tag.PerformedProcedureStepStartTime);
   this.performedProcedureStepInstanceUID =
       attrs.getString(
           new int[] {
             Tag.ReferencedPerformedProcedureStepSequence, 0, Tag.ReferencedSOPInstanceUID
           });
   int[] fieldTags = filter.getFieldTags();
   for (int i = 0; i < fieldTags.length; i++) {
     try {
       setField(filter.getField(fieldTags[i]), attrs.getString(fieldTags[i], ""));
     } catch (Exception e) {
       throw new ConfigurationException(e);
     }
   }
   this.encodedAttributes =
       DicomObjectUtils.encode(filter.filter(attrs), filter.getTransferSyntaxUID());
 }