Пример #1
0
    def section_CreateSecondBranch(self):
        self.delayDisplay("Create second branch in subject hierarchy",
                          self.delayMs)

        from vtkSlicerSubjectHierarchyModuleMRML import vtkMRMLSubjectHierarchyNode

        patient2Node = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, None,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelPatient(),
            self.patient2Name)
        study2Node = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, patient2Node,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelStudy(),
            self.study2Name)
        seriesNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, study2Node,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelSeries(),
            self.testSeriesName)
        subseriesNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, seriesNode,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelSubseries(),
            self.testSubseriesName)

        # Check if the created nodes have the right parents
        self.assertTrue(study2Node.GetParentNode() == patient2Node)
        self.assertTrue(seriesNode.GetParentNode() == study2Node)
        self.assertTrue(subseriesNode.GetParentNode() == seriesNode)
Пример #2
0
    def section_MarkupRole(self):
        self.delayDisplay("Markup role", self.delayMs)

        # Create sample markups node
        markupsNode = slicer.vtkMRMLMarkupsFiducialNode()
        slicer.mrmlScene.AddNode(markupsNode)
        markupsNode.SetName(self.sampleMarkupName)
        fiducialPosition = [100.0, 0.0, 0.0]
        markupsNode.AddFiducialFromArray(fiducialPosition)

        # Add markups to subject hierarchy
        from vtkSlicerSubjectHierarchyModuleMRML import vtkMRMLSubjectHierarchyNode

        patientNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, None,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelPatient(),
            'Patient')
        studyNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, patientNode, self.studyName,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelStudy())
        markupsShNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, studyNode,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelSeries(),
            self.sampleMarkupName, markupsNode)

        self.assertIsNotNone(markupsShNode)
        self.assertEqual(markupsShNode.GetParentNode(), studyNode)
        self.assertEqual(markupsShNode.GetOwnerPluginName(), 'Markups')
Пример #3
0
    def section_CreateSecondBranch(self):
        self.delayDisplay("Create second branch in subject hierarchy",
                          self.delayMs)

        from vtkSlicerSubjectHierarchyModuleMRML import vtkMRMLSubjectHierarchyNode

        patientNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, None, 'Subject', 'Patient2')
        studyNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, patientNode, 'Study', self.study2Name)
        seriesNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, studyNode, 'Series', 'TestSeries_Empty')
        subseriesNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, seriesNode, 'Subseries', 'TestSuberies_Empty')
Пример #4
0
  def section_ChartRole(self):
    self.delayDisplay("Chart role",self.delayMs)

    # Create sample chart node
    chartNode = slicer.vtkMRMLChartNode()
    slicer.mrmlScene.AddNode(chartNode)
    chartNode.SetName(self.sampleChartName)

    # Add markups to subject hierarchy
    from vtkSlicerSubjectHierarchyModuleMRML import vtkMRMLSubjectHierarchyNode

    studyNode = slicer.util.getNode(self.studyName + slicer.vtkMRMLSubjectHierarchyConstants.GetSubjectHierarchyNodeNamePostfix())
    self.assertTrue( studyNode != None )

    chartShNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(slicer.mrmlScene, studyNode, slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelSeries(), self.sampleChartName, chartNode)

    self.assertTrue( chartShNode != None )
    self.assertTrue( chartShNode.GetParentNode() == studyNode )
    self.assertTrue( chartShNode.GetOwnerPluginName() == 'Charts' )
Пример #5
0
    def addSeriesInSubjectHierarchy(self, loadable, dataNode):
        """Add loaded DICOM series into subject hierarchy.
    The DICOM tags are read from the first file referenced by the
    given loadable. The dataNode argument is associated to the created
    series node and provides fallback name in case of empty series
    description.
    This function should be called from the load() function of
    each subclass of the DICOMPlugin class.
    """
        tags = {}
        tags['seriesInstanceUID'] = "0020,000E"
        tags['seriesModality'] = "0008,0060"
        tags['seriesNumber'] = "0020,0011"
        tags['studyInstanceUID'] = "0020,000D"
        tags['studyID'] = "0020,0010"
        tags['studyDescription'] = "0008,1030"
        tags['studyDate'] = "0008,0020"
        tags['studyTime'] = "0008,0030"
        tags['patientID'] = "0010,0020"
        tags['patientName'] = "0010,0010"
        tags['patientSex'] = "0010,0040"
        tags['patientBirthDate'] = "0010,0030"
        tags['patientComments'] = "0010,4000"
        tags['instanceUID'] = "0008,0018"

        # Import and check dependencies
        from vtkSlicerSubjectHierarchyModuleMRML import vtkMRMLSubjectHierarchyNode
        from vtkSlicerSubjectHierarchyModuleLogic import vtkSlicerSubjectHierarchyModuleLogic
        try:
            vtkMRMLSubjectHierarchyNode
            vtkSlicerSubjectHierarchyModuleLogic
        except AttributeError:
            import sys
            sys.stderr.write(
                'Unable to create SubjectHierarchy nodes: SubjectHierarchy module not found!'
            )
            return

        # Validate dataNode argument
        if dataNode is None or not dataNode.IsA('vtkMRMLNode'):
            import sys
            sys.stderr.write(
                'Unable to create SubjectHierarchy nodes: invalid data node provided!'
            )
            return

        # Get first file to access DICOM tags from it
        firstFile = loadable.files[0]

        # Set up subject hierarchy node
        seriesNode = vtkMRMLSubjectHierarchyNode.CreateSubjectHierarchyNode(
            slicer.mrmlScene, None,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelSeries(),
            slicer.util.toVTKString(loadable.name), dataNode)

        # Specify details of series node
        seriesInstanceUid = slicer.dicomDatabase.fileValue(
            firstFile, tags['seriesInstanceUID'])
        seriesNode.AddUID(
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMUIDName(),
            seriesInstanceUid)
        seriesNode.SetAttribute(
            slicer.vtkMRMLSubjectHierarchyConstants.
            GetDICOMSeriesModalityAttributeName(),
            slicer.dicomDatabase.fileValue(firstFile, tags['seriesModality']))
        seriesNode.SetAttribute(
            slicer.vtkMRMLSubjectHierarchyConstants.
            GetDICOMSeriesNumberAttributeName(),
            slicer.dicomDatabase.fileValue(firstFile, tags['seriesNumber']))
        # Set instance UIDs
        instanceUIDs = ""
        for file in loadable.files:
            uid = slicer.dicomDatabase.fileValue(file, tags['instanceUID'])
            if uid == "":
                uid = "Unknown"
            instanceUIDs += uid + " "
        instanceUIDs = instanceUIDs[:-1]  # strip last space
        seriesNode.AddUID(
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMInstanceUIDName(),
            instanceUIDs)

        # Set referenced instance UIDs from loadable to series
        referencedInstanceUIDs = ""
        if hasattr(loadable, 'referencedInstanceUIDs'):
            for instanceUID in loadable.referencedInstanceUIDs:
                referencedInstanceUIDs += instanceUID + " "
        referencedInstanceUIDs = referencedInstanceUIDs[:
                                                        -1]  # strip last space
        seriesNode.SetAttribute(
            slicer.vtkMRMLSubjectHierarchyConstants.
            GetDICOMReferencedInstanceUIDsAttributeName(),
            referencedInstanceUIDs)

        # Add series node to hierarchy under the right study and patient nodes. If they are present then used, if not, then created
        patientId = slicer.dicomDatabase.fileValue(firstFile,
                                                   tags['patientID'])
        patientNode = vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNodeByUID(
            slicer.mrmlScene,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMUIDName(),
            patientId)
        studyInstanceUid = slicer.dicomDatabase.fileValue(
            firstFile, tags['studyInstanceUID'])
        studyId = slicer.dicomDatabase.fileValue(firstFile, tags['studyID'])
        studyNode = vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNodeByUID(
            slicer.mrmlScene,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMUIDName(),
            studyInstanceUid)
        vtkSlicerSubjectHierarchyModuleLogic.InsertDicomSeriesInHierarchy(
            slicer.mrmlScene, patientId, studyInstanceUid, seriesInstanceUid)

        if patientNode is None:
            patientNode = vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNodeByUID(
                slicer.mrmlScene,
                slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMUIDName(),
                patientId)
            if patientNode is not None:
                # Add attributes for DICOM tags
                patientName = slicer.util.toVTKString(
                    slicer.dicomDatabase.fileValue(firstFile,
                                                   tags['patientName']))
                if patientName == '':
                    patientName = 'No name'
                patientNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMPatientNameAttributeName(), patientName)
                patientNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMPatientIDAttributeName(),
                    slicer.dicomDatabase.fileValue(firstFile,
                                                   tags['patientID']))
                patientNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMPatientSexAttributeName(),
                    slicer.dicomDatabase.fileValue(firstFile,
                                                   tags['patientSex']))
                patientNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMPatientBirthDateAttributeName(),
                    slicer.dicomDatabase.fileValue(firstFile,
                                                   tags['patientBirthDate']))
                patientNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMPatientCommentsAttributeName(),
                    slicer.dicomDatabase.fileValue(firstFile,
                                                   tags['patientComments']))
                # Set node name
                patientNode.SetName(patientName +
                                    slicer.vtkMRMLSubjectHierarchyConstants.
                                    GetSubjectHierarchyNodeNamePostfix())

        if studyNode is None:
            studyNode = vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNodeByUID(
                slicer.mrmlScene,
                slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMUIDName(),
                studyInstanceUid)
            if studyNode is not None:
                # Add attributes for DICOM tags
                studyDescription = slicer.util.toVTKString(
                    slicer.dicomDatabase.fileValue(firstFile,
                                                   tags['studyDescription']))
                if studyDescription == '':
                    studyDescription = 'No study description'
                studyNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMStudyDescriptionAttributeName(), studyDescription)
                studyDate = slicer.util.toVTKString(
                    slicer.dicomDatabase.fileValue(firstFile,
                                                   tags['studyDate']))
                studyNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMStudyInstanceUIDTagName(), studyInstanceUid)
                studyNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMStudyIDTagName(), studyId)
                studyNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMStudyDateAttributeName(), studyDate)
                studyNode.SetAttribute(
                    slicer.vtkMRMLSubjectHierarchyConstants.
                    GetDICOMStudyTimeAttributeName(),
                    slicer.dicomDatabase.fileValue(firstFile,
                                                   tags['studyTime']))
                # Set node name
                studyNode.SetName(studyDescription + ' (' + studyDate + ')' +
                                  slicer.vtkMRMLSubjectHierarchyConstants.
                                  GetSubjectHierarchyNodeNamePostfix())