Beispiel #1
0
    protected void doSomethingWithDicomFileOnMedia(String mediaFileName) {
      // logLn("OurFirstPassMediaImporter.doSomethingWithDicomFile(): "+mediaFileName);
      try {
        DicomInputStream i = new DicomInputStream(new File(mediaFileName));
        AttributeList list = new AttributeList();
        list.read(i);
        i.close();

        String sopInstanceUID =
            Attribute.getSingleStringValueOrEmptyString(list, TagFromName.SOPInstanceUID);
        if (sopInstanceUID.length() > 0) {
          String studyInstanceUID =
              Attribute.getSingleStringValueOrEmptyString(list, TagFromName.StudyInstanceUID);
          if (studyInstanceUID.length() > 0) {
            mapOfSOPInstanceUIDToStudyInstanceUID.put(sopInstanceUID, studyInstanceUID);
          } else {
            throw new DicomException("Missing StudyInstanceUID");
          }

          {
            CompositeInstanceContext cic = new CompositeInstanceContext(list, false /*forSR*/);
            // remove all except patient context ...
            cic.removeStudy();
            cic.removeSeries();
            cic.removeEquipment();
            cic.removeFrameOfReference();
            cic.removeInstance();
            cic.removeSRDocumentGeneral();

            Group group = addToGroups(list);
            // System.err.println("group = "+group);
            mergePatientContext(group, cic);
          }
        } else {
          throw new DicomException("Missing SOPInstanceUID");
        }
      } catch (Exception e) {
        logLn("Error: File " + mediaFileName + " exception " + e);
      }
    }
 /**
  * @param association
  * @param affectedSOPClass
  * @param affectedSOPInstance
  * @param inputTransferSyntaxUID
  * @param din
  * @param presentationContextID
  * @param outputTransferSyntaxUID
  * @exception IOException
  * @exception DicomException
  * @exception DicomNetworkException
  * @exception AReleaseException
  */
 protected boolean sendOneSOPInstance(
     Association association,
     String affectedSOPClass,
     String affectedSOPInstance,
     String inputTransferSyntaxUID,
     DicomInputStream din,
     byte presentationContextID,
     String outputTransferSyntaxUID)
     throws AReleaseException, DicomNetworkException, DicomException, IOException {
   CStoreResponseHandler receivedDataHandler = new CStoreResponseHandler(debugLevel);
   association.setReceivedDataHandler(receivedDataHandler);
   if (inputTransferSyntaxUID.equals(outputTransferSyntaxUID)) {
     // din will already be positioned after meta-header and set for reading data set
     byte[] data = null;
     byte[] b = new byte[32768];
     while (true) {
       int bytesReceived = din.read(b, 0, 32768);
       if (bytesReceived == -1) {
         break;
       } else if (bytesReceived > 0) {
         if (data == null) {
           data = new byte[bytesReceived];
           System.arraycopy(b, 0, data, 0, bytesReceived);
         } else {
           data = ByteArray.concatenate(data, 0, data.length, b, 0, bytesReceived);
         }
       }
     }
     byte cStoreRequestCommandMessage[] =
         new CStoreRequestCommandMessage(affectedSOPClass, affectedSOPInstance).getBytes();
     association.send(presentationContextID, cStoreRequestCommandMessage, data);
   } else {
     throw new DicomException("Must be the same transfer syntax");
   }
   if (debugLevel > 1)
     System.err.println(
         new java.util.Date().toString()
             + ": TestSendingCommandAndDataInOnePDU.sendOneSOPInstance(): about to wait for PDUs");
   association.waitForCommandPDataPDUs();
   return receivedDataHandler.wasSuccessful();
 }
Beispiel #3
0
    protected void doSomethingWithDicomFileOnMedia(String mediaFileName) {
      // logLn("OurFirstPassMediaImporter.doSomethingWithDicomFile(): "+mediaFileName);
      try {
        DicomInputStream i = new DicomInputStream(new File(mediaFileName));
        AttributeList list = new AttributeList();
        list.read(i);
        i.close();

        String sopInstanceUID =
            Attribute.getSingleStringValueOrEmptyString(list, TagFromName.SOPInstanceUID);
        if (sopInstanceUID.length() > 0) {
          Group group = mapOfSOPInstanceUIDToGroup.get(sopInstanceUID);

          // System.err.println("group = "+group);
          // System.err.println("Groups size = "+groups.size());
          if (group == null) {
            if (groups.size() == 1) {
              group = groups.toArray(singleGroupArray)[0];
            } else {
              throw new DicomException(
                  "Cannot merge context for second set if more than one group");
            }
          }

          if (group != null) {
            logLn("In group " + group.identity);
            if (group.context != null) {
              CompositeInstanceContext.removePatient(
                  list); // remove anything hanging around, such as empty attributes
              list.putAll(
                  group.context
                      .getAttributeList()); // overwrite all patient context in list that was read
                                            // in
            } else {
              throw new DicomException(
                  "Missing group context for SOPInstanceUID on second pass"); // should not be
                                                                              // possible
            }

            ClinicalTrialsAttributes.addContributingEquipmentSequence(
                list,
                true,
                new CodedSequenceItem("109103", "DCM", "Modifying Equipment"),
                "PixelMed", // Manufacturer
                "PixelMed", // Institution Name
                "Software Development", // Institutional Department Name
                "Bangor, PA", // Institution Address
                null, // Station Name
                "com.pixelmed.apps.MergeCompositeContext", // Manufacturer's Model Name
                null, // Device Serial Number
                "Vers. " + VersionAndConstants.getBuildDate(), // Software Version(s)
                "Merged patient context");

            list.removeGroupLengthAttributes();
            list.removeMetaInformationHeaderAttributes();
            list.remove(TagFromName.DataSetTrailingPadding);
            FileMetaInformation.addFileMetaInformation(
                list, TransferSyntax.ExplicitVRLittleEndian, ourAETitle);

            File dstFile =
                new File(
                    dstFolderName,
                    MoveDicomFilesIntoHierarchy.makeHierarchicalPathFromAttributes(list));
            if (dstFile.exists()) {
              throw new DicomException(
                  "\""
                      + mediaFileName
                      + "\": new file \""
                      + dstFile
                      + "\" already exists - not overwriting");
            } else {
              File dstParentDirectory = dstFile.getParentFile();
              if (!dstParentDirectory.exists()) {
                if (!dstParentDirectory.mkdirs()) {
                  throw new DicomException(
                      "\""
                          + mediaFileName
                          + "\": parent directory creation failed for \""
                          + dstFile
                          + "\"");
                }
              }
              logLn("Writing with new context file " + dstFile);
              list.write(dstFile, TransferSyntax.ExplicitVRLittleEndian, true, true);
            }
          } else {
            throw new DicomException(
                "Missing group for SOPInstanceUID on second pass"); // should not be possible for
                                                                    // single set case
          }
        } else {
          throw new DicomException("Missing SOPInstanceUID");
        }
      } catch (Exception e) {
        logLn("Error: File " + mediaFileName + " exception " + e);
      }
    }