Exemplo n.º 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);
      }
    }
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);
      }
    }