Exemplo n.º 1
0
 protected void performRetrieve(
     AttributeList uniqueKeys, String selectionLevel, String retrieveAE) {
   try {
     AttributeList identifier = new AttributeList();
     if (uniqueKeys != null) {
       identifier.putAll(uniqueKeys);
       {
         AttributeTag t = TagFromName.QueryRetrieveLevel;
         Attribute a = new CodeStringAttribute(t);
         a.addValue(selectionLevel);
         identifier.put(t, a);
       }
       currentRemoteQueryInformationModel.performHierarchicalMoveFrom(identifier, retrieveAE);
     } else {
       // else do nothing, since no unique key to specify what to retrieve
       log.warning("UniqueKeys for retrieval are null");
     }
   } catch (Exception e) {
     e.printStackTrace(System.err);
   }
 }
Exemplo n.º 2
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);
      }
    }