public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("Group "); buffer.append(identity); buffer.append(" seq "); buffer.append(sequenceNumber); buffer.append(":\n"); for (String sopInstanceUID : this) { buffer.append("\t"); buffer.append(sopInstanceUID); buffer.append("\n"); } buffer.append(context.toString()); return buffer.toString(); }
protected CompositeInstanceContext mergePatientContext( Group group, CompositeInstanceContext newContext) { if (group.context == null) { // System.err.println("mergePatientContext(): creating new context for group"); group.context = newContext; } else { AttributeList groupList = group.context.getAttributeList(); Iterator<Attribute> newListIterator = newContext.getAttributeList().values().iterator(); while (newListIterator.hasNext()) { Attribute a = newListIterator.next(); AttributeTag tag = a.getTag(); String groupValue = Attribute.getSingleStringValueOrEmptyString(groupList, tag); String newValue = a.getSingleStringValueOrEmptyString(); if (!newValue.equals(groupValue)) { String describeTag = tag + " " + groupList.getDictionary().getFullNameFromTag(tag); System.err.println( "mergePatientContext(): in group " + group.identity + " for " + describeTag + " values differ between existing group value <" + groupValue + "> and new value <" + newValue + ">"); if (newValue.length() > 0 && (groupValue.length() == 0 || isNonZeroLengthDummyValue(groupValue))) { System.err.println( "mergePatientContext(): in group " + group.identity + " for " + describeTag + " replacing absent/empty/dummy existing group value with new value <" + newValue + ">"); groupList.put(a); } } } } return group.context; }
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); } }
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); } }