Exemple #1
0
    def run(self):
    
        print '''
        A_7001_13:
        '''
        
        global tempRoot;
        global mesaDir;
        global mesaToolDir;
        global dataRoot;
        global dcm4CheDir;
        
        self.verifyEnvironment();
        
        testName = 'A_7001_13';
        numberOfSeriesPerStudy = 1;
        numberOfSOPsPerSeries = 1;  # This is the number of dicom images sent per unique series
        
        ## Testing Hosts ##
        edgeHost = '172.20.175.63'
        
        
        ## PACS Host ##
        pacsAeTitle = 'DCM4CHEE';
        pacsHost = 'localhost';
        pacsPort = '11112';
        
        ## MIRTH HL7 Connection
        mirthHl7Host = edgeHost;
        mirthHl7Port = '20000';
        
        ## XDS Clearinghouse Connections
        nistScriptDirectory = '/usr/local/tomcat1/bin'
        registryURL = 'http://localhost:9080/axis2/services/xdsregistryb';
        repositoryURL = 'http://localhost:9080/axis2/services/xdsrepositoryb';
        repositoryUID = '1.19.6.24.109.42.1.5';
        PATIENT_ID_ASSIGNING_AUTHORITY = '1.3.6.1.4.1.19376.2.840.1.1.1.1';
        PATIENT_ID_ASSIGNING_AUTHORITY_TYPE = 'ISO';
        
        testDataDir = dataRoot + '/A-7001/A-7001-01';
        baseTest = A_7001_01(testName, tempRoot, dcm4CheDir, mesaDir, mesaToolDir, edgeHost);
    
        ## XDS HL7 Connection
        xdsHl7JarPath = os.path.normpath(os.getcwd() + '/../util/HL7Receiver.jar');
        xdsHl7Port = 9082;
        
        ## --------------------------------------------------------- ##
        print 'Starting XDS HL7 Receiver'
        ## --------------------------------------------------------- ##
        self.xdsHl7 = HL7ReceiverManager(xdsHl7JarPath, xdsHl7Port, False, False);
        if self.xdsHl7.isAnInstanceRunning():
            return (False, 'HL7 Receiver already running.  Kill process before testing.');
        success = self.xdsHl7.startServer();
        if not success:
            return (False, 'Failed to start HL7 Receiver');
    
        ## --------------------------------------------------------- ##
        print 'Skip starting NIST Repository as Clearinghouse'
        ## --------------------------------------------------------- ##
        self.nist = NistRepositoryManager(nistScriptDirectory);

        ## --------------------------------------------------------- ##
        print 'Generate unique Study Instance UID'
        ## --------------------------------------------------------- ##
        studyUID = '9999.' + strftime('%Y%m%d%H%M%S', localtime());
        
        ## --------------------------------------------------------- ##
        print 'Generate dictionary used to fill hl7 message templates'
        ## --------------------------------------------------------- ##
        customFieldsDictionary = baseTest.generateCustomFields(studyUID);
        patientName = customFieldsDictionary['PATIENT_NAME'];
        print 'patientName:' + patientName;
        patientID = customFieldsDictionary['PATIENT_ID'];
        print 'patientID:' + patientID;
        accessionNumber = customFieldsDictionary['ACCESSION_NUMBER'];
        print 'accessionNumber:' + accessionNumber;
        studyUID = customFieldsDictionary['STUDY_INSTANCE_UID'];
        print 'studyUID:' + studyUID;
    
        # Create test directorys
        testTempDir = tempRoot + '/' + accessionNumber;
        os.makedirs(testTempDir);
        retreivedFilesDirectory = testTempDir + '/retrieved'; 
        os.makedirs(retreivedFilesDirectory);
        sentFilesDirectory = testTempDir + '/sent'; 
        os.makedirs(sentFilesDirectory);
    
        ## --------------------------------------------------------- ##
        print 'Generate ORM HL7 message and send to HL7 receiver - Creates Exam & Patient entries via MIRTH' 
        ## --------------------------------------------------------- ##
        status = baseTest.generateAndSendOrm(testDataDir, customFieldsDictionary, mirthHl7Host, mirthHl7Port);
        if(status != 'SCHEDULED'):
            return (False, 'Failed to schedule exam');
        
        ## --------------------------------------------------------- ##
        print 'Generate ORU HL7 message and send to HL7 receiver' 
        ## --------------------------------------------------------- ##
        status = baseTest.generateAndSendOru(testDataDir, customFieldsDictionary, mirthHl7Host, mirthHl7Port);
        if(status != 'FINALIZED'):
            return (False, 'Failed to finalize exam');
        
        ## --------------------------------------------------------- ##
        print 'Prepare DICOM files to with Study, Series, SOP UIDs' 
        ## --------------------------------------------------------- ##
        studySeriesSopUIDs = [];
        # SeriesUID format - StudyUID.N
        # SopUID format    - StudyUID.Series.N
        #   where N is a reasonably unique int
        n = int(strftime('%H%M%S', localtime()));
        for seriesIndex in range(numberOfSeriesPerStudy):
            seriesN = seriesIndex + n;
            seriesUID = str(studyUID) + '.' + str(seriesN)
            for sopIndex in range(numberOfSOPsPerSeries):
                sopN = sopIndex + n;
                sopUID = str(seriesUID) + '.'+ str(sopN)
                studySeriesSopUIDs.append([studyUID, seriesUID, sopUID]);
        success = baseTest.generateCustomDicomFiles(studySeriesSopUIDs, customFieldsDictionary, testDataDir + '/dicom_files/MR.dcm', sentFilesDirectory)
        if not success:
            return (False, 'Failed to generate custom dicom files');
        
        ## --------------------------------------------------------- ##
        print 'Send DICOM files to PACS' 
        ## --------------------------------------------------------- ##
        baseTest.sendDicomFileToPacs(pacsAeTitle, pacsHost, pacsPort, sentFilesDirectory, customFieldsDictionary);
        
        
        ## --------------------------------------------------------- ##
        print 'Instruct EDGE to retrieve DICOM files for pid & accession - Job, JobSet, Transactions entries in rsnadb';  
        ## --------------------------------------------------------- ##
        jobID = baseTest.startNewJobAndTransactionOnEdge(patientID, accessionNumber);
        

        
        ## --------------------------------------------------------- ##
        print 'Wait for EDGE to fail on communication with Clearinghouse' 
        ## --------------------------------------------------------- ##
        statusCode = baseTest.waitForTransactionStatusCode(jobID, -34, 240);

            
        ## --------------------------------------------------------- ##
        print 'Retrieve XDS documents from Clearinghouse repository'  
        ## --------------------------------------------------------- ##
        PATIENT_ID_ASSIGNING_AUTHORITY = '1.3.6.1.4.1.19376.2.840.1.1.1.1';
        PATIENT_ID_ASSIGNING_AUTHORITY_TYPE = 'ISO';
        singleUsePatientID = EdgeDbManager('rsnadb', edgeHost, 'edge', 'd17bK4#M').getSingleUsePatientID(jobID);
        fullPatientID = singleUsePatientID + r'^^^&' + PATIENT_ID_ASSIGNING_AUTHORITY + r'&' + PATIENT_ID_ASSIGNING_AUTHORITY_TYPE;
        baseTest.retrieveXdsDocuments(fullPatientID, registryURL, repositoryURL, repositoryUID, retreivedFilesDirectory);
          
        ## --------------------------------------------------------- ##
        print 'Expect transaction status code -34 and zero matching documents.'  
        ## --------------------------------------------------------- ##
        if(statusCode != -34):
            return (False, 'Transaction status code set to: ' +  str(statusCode));
        elif len(os.listdir(retreivedFilesDirectory)) > 0 :
            return (False, 'Failed Tests: Unexpected documents retrieved');
        else:
            print 'Transaction status:', statusCode, 'Zero matching documents retrieved.'
            
            
        return (True, 'Passed Tests'); 
Exemple #2
0
    def run(self):

        print '''
        A_7001_04:
        '''

        global tempRoot
        global mesaDir
        global mesaToolDir
        global dataRoot
        global dcm4CheDir

        self.verifyEnvironment()

        testName = 'A_7001_04'
        numberOfSeriesPerStudy = 3
        numberOfSOPsPerSeries = 3
        # This is the number of dicom images sent per unique series

        ## Testing Hosts ##
        edgeHost = '172.20.175.63'

        ## PACS Host ##
        pacsAeTitle = 'DCM4CHEE'
        pacsHost = 'localhost'
        pacsPort = '11112'

        ## MIRTH HL7 Connection
        mirthHl7Host = edgeHost
        mirthHl7Port = '20000'

        ## XDS Clearinghouse Connections
        nistScriptDirectory = '/usr/local/tomcat1/bin'
        registryURL = 'http://localhost:9080/axis2/services/xdsregistryb'
        repositoryURL = 'http://localhost:9080/axis2/services/xdsrepositoryb'
        repositoryUID = '1.19.6.24.109.42.1.5'
        PATIENT_ID_ASSIGNING_AUTHORITY = '1.3.6.1.4.1.19376.2.840.1.1.1.1'
        PATIENT_ID_ASSIGNING_AUTHORITY_TYPE = 'ISO'

        testDataDir = dataRoot + '/A-7001/A-7001-01'
        baseTest = A_7001_01(testName, tempRoot, dcm4CheDir, mesaDir,
                             mesaToolDir, edgeHost)

        ## XDS HL7 Connection
        xdsHl7JarPath = os.path.normpath(os.getcwd() +
                                         '/../util/HL7Receiver.jar')
        xdsHl7Port = 9082

        ## --------------------------------------------------------- ##
        print 'Starting XDS HL7 Receiver'
        ## --------------------------------------------------------- ##
        self.xdsHl7 = HL7ReceiverManager(xdsHl7JarPath, xdsHl7Port, False,
                                         False)
        if self.xdsHl7.isAnInstanceRunning():
            return (
                False,
                'HL7 Receiver already running.  Kill process before testing.')
        success = self.xdsHl7.startServer()
        if not success:
            return (False, 'Failed to start HL7 Receiver')

        ## --------------------------------------------------------- ##
        print 'Starting NIST Repository as Clearinghouse'
        ## --------------------------------------------------------- ##
        self.nist = NistRepositoryManager(nistScriptDirectory)
        success = self.nist.startServer()
        if not success:
            return (False, 'Failed to start NIST Repository')

        ## --------------------------------------------------------- ##
        print 'Generate unique Study Instance UID'
        ## --------------------------------------------------------- ##
        studyUID = '9999.' + strftime('%Y%m%d%H%M%S', localtime())

        ## --------------------------------------------------------- ##
        print 'Generate dictionary used to fill hl7 message templates'
        ## --------------------------------------------------------- ##
        customFieldsDictionary = baseTest.generateCustomFields(studyUID)
        patientName = customFieldsDictionary['PATIENT_NAME']
        print 'patientName:' + patientName
        patientID = customFieldsDictionary['PATIENT_ID']
        print 'patientID:' + patientID
        accessionNumber = customFieldsDictionary['ACCESSION_NUMBER']
        print 'accessionNumber:' + accessionNumber
        studyUID = customFieldsDictionary['STUDY_INSTANCE_UID']
        print 'studyUID:' + studyUID

        # Create test directorys
        testTempDir = tempRoot + '/' + accessionNumber
        os.makedirs(testTempDir)
        retreivedFilesDirectory = testTempDir + '/retrieved'
        os.makedirs(retreivedFilesDirectory)
        sentFilesDirectory = testTempDir + '/sent'
        os.makedirs(sentFilesDirectory)

        ## --------------------------------------------------------- ##
        print 'Generate ORM HL7 message and send to HL7 receiver - Creates Exam & Patient entries via MIRTH'
        ## --------------------------------------------------------- ##
        status = baseTest.generateAndSendOrm(testDataDir,
                                             customFieldsDictionary,
                                             mirthHl7Host, mirthHl7Port)
        if (status != 'SCHEDULED'):
            return (False, 'Failed to schedule exam')

        ## --------------------------------------------------------- ##
        print 'Generate ORU HL7 message and send to HL7 receiver'
        ## --------------------------------------------------------- ##
        status = baseTest.generateAndSendOru(testDataDir,
                                             customFieldsDictionary,
                                             mirthHl7Host, mirthHl7Port)
        if (status != 'FINALIZED'):
            return (False, 'Failed to finalize exam')

        ## --------------------------------------------------------- ##
        print 'Prepare DICOM files to with Study, Series, SOP UIDs'
        ## --------------------------------------------------------- ##
        studySeriesSopUIDs = []
        # SeriesUID format - StudyUID.N
        # SopUID format    - StudyUID.Series.N
        #   where N is a reasonably unique int
        n = int(strftime('%H%M%S', localtime()))
        for seriesIndex in range(numberOfSeriesPerStudy):
            seriesN = seriesIndex + n
            seriesUID = str(studyUID) + '.' + str(seriesN)
            for sopIndex in range(numberOfSOPsPerSeries):
                sopN = sopIndex + n
                sopUID = str(seriesUID) + '.' + str(sopN)
                studySeriesSopUIDs.append([studyUID, seriesUID, sopUID])
        success = baseTest.generateCustomDicomFiles(
            studySeriesSopUIDs, customFieldsDictionary,
            testDataDir + '/dicom_files/MR.dcm', sentFilesDirectory)
        if not success:
            return (False, 'Failed to generate custom dicom files')

        ## --------------------------------------------------------- ##
        print 'Send DICOM files to PACS'
        ## --------------------------------------------------------- ##
        baseTest.sendDicomFileToPacs(pacsAeTitle, pacsHost, pacsPort,
                                     sentFilesDirectory,
                                     customFieldsDictionary)

        ## --------------------------------------------------------- ##
        print 'Instruct EDGE to retrieve DICOM files for pid & accession - Job, JobSet, Transactions entries in rsnadb'
        ## --------------------------------------------------------- ##
        jobID = baseTest.startNewJobAndTransactionOnEdge(
            patientID, accessionNumber)

        ## --------------------------------------------------------- ##
        print 'Wait for EDGE to complete transfer to Clearinghouse'
        ## --------------------------------------------------------- ##
        statusCode = baseTest.waitForCompletedXdsXfer(jobID, 240)

        if (statusCode != 40):
            return (False,
                    'Transaction status code set to: ' + str(statusCode))

        ## --------------------------------------------------------- ##
        print 'Retrieve XDS documents from Clearinghouse repository'
        ## --------------------------------------------------------- ##
        PATIENT_ID_ASSIGNING_AUTHORITY = '1.3.6.1.4.1.19376.2.840.1.1.1.1'
        PATIENT_ID_ASSIGNING_AUTHORITY_TYPE = 'ISO'
        singleUsePatientID = EdgeDbManager(
            'rsnadb', edgeHost, 'edge',
            'd17bK4#M').getSingleUsePatientID(jobID)
        fullPatientID = singleUsePatientID + r'^^^&' + PATIENT_ID_ASSIGNING_AUTHORITY + r'&' + PATIENT_ID_ASSIGNING_AUTHORITY_TYPE
        baseTest.retrieveXdsDocuments(fullPatientID, registryURL,
                                      repositoryURL, repositoryUID,
                                      retreivedFilesDirectory)
        if len(os.listdir(retreivedFilesDirectory)) == 0:
            return (False, 'Zero documents retrieved')

        ## --------------------------------------------------------- ##
        print 'Validate retrieved documents'
        ## --------------------------------------------------------- ##
        success = baseTest.validateRetrievedMetaDataLegality(
            retreivedFilesDirectory)
        if not success:
            return (False, "Failed due to illegal meta-data.")

        success = baseTest.validateRetrievedMetaDataMatch(
            retreivedFilesDirectory, customFieldsDictionary)
        if not success:
            return (False, "Failed due to meta-data mismatch.")

        success = baseTest.validateDcmSentDcmRetrievedBinaryMatch(
            sentFilesDirectory, retreivedFilesDirectory)
        if not success:
            return (False,
                    "Failed due to sent-retrieved file binary mismatch.")

        success = baseTest.validateKosDcmMatch(retreivedFilesDirectory)
        if not success:
            return (False, "Failed due to manifest - retrieved file mismatch.")

        return (True, 'Passed Tests')
    def run(self):
    
        print '''
        A_5001_X8:
        Designed to run 7001-02 test as normal, with a breakpoint substituted
        for the job start code.  This should be completed with the token app.
        Afterward, this code should be allowed to complete. 
        '''
        
        global tempRoot;
        global mesaDir;
        global mesaToolDir;
        global dataRoot;
        global dcm4CheDir;
        
        self.verifyEnvironment();
        
        testName = 'A_5001_X8';
        numberOfSeriesPerStudy = 2;
        numberOfSOPsPerSeries = 2;  # This is the number of dicom images sent per unique series
        
        ## Testing Hosts ##
        edgeHost = '172.20.175.61'
        
        
        ## PACS Host ##
        pacsAeTitle = 'DCM4CHEE';
        pacsHost = 'localhost';
        pacsPort = '11112';
        
        ## MIRTH HL7 Connection
        mirthHl7Host = edgeHost;
        mirthHl7Port = '20000';
        
        ## XDS Clearinghouse Connections
        nistScriptDirectory = '/usr/local/tomcat1/bin'
        registryURL = 'http://localhost:9080/axis2/services/xdsregistryb';
        repositoryURL = 'http://localhost:9080/axis2/services/xdsrepositoryb';
        repositoryUID = '1.19.6.24.109.42.1.5';
        PATIENT_ID_ASSIGNING_AUTHORITY = '1.3.6.1.4.1.19376.2.840.1.1.1.1';
        PATIENT_ID_ASSIGNING_AUTHORITY_TYPE = 'ISO';
        
        testDataDir = dataRoot + '/A-7001/A-7001-01';
        baseTest = A_7001_01(testName, tempRoot, dcm4CheDir, mesaDir, mesaToolDir, edgeHost);
    
        ## XDS HL7 Connection
        xdsHl7JarPath = os.path.normpath(os.getcwd() + '/../util/HL7Receiver.jar');
        xdsHl7Port = 9082;
        
        ## --------------------------------------------------------- ##
        print 'Starting XDS HL7 Receiver'
        ## --------------------------------------------------------- ##
        self.xdsHl7 = HL7ReceiverManager(xdsHl7JarPath, xdsHl7Port, False, False);
        if self.xdsHl7.isAnInstanceRunning():
            return (False, 'HL7 Receiver already running.  Kill process before testing.');
        success = self.xdsHl7.startServer();
        if not success:
            return (False, 'Failed to start HL7 Receiver');
    
        ## --------------------------------------------------------- ##
        print 'Starting NIST Repository as Clearinghouse'
        ## --------------------------------------------------------- ##
        self.nist = NistRepositoryManager(nistScriptDirectory);
        success = self.nist.startServer();
        if not success:
            return (False, 'Failed to start NIST Repository');

        ## --------------------------------------------------------- ##
        print 'Generate unique Study Instance UID'
        ## --------------------------------------------------------- ##
        studyUID = '9999.' + strftime('%Y%m%d%H%M%S', localtime());
        
        ## --------------------------------------------------------- ##
        print 'Generate dictionary used to fill hl7 message templates'
        ## --------------------------------------------------------- ##
        customFieldsDictionary = baseTest.generateCustomFields(studyUID);
        patientName = customFieldsDictionary['PATIENT_NAME'];
        print 'patientName:' + patientName;
        patientID = customFieldsDictionary['PATIENT_ID'];
        print 'patientID:' + patientID;
        accessionNumber = customFieldsDictionary['ACCESSION_NUMBER'];
        print 'accessionNumber:' + accessionNumber;
        studyUID = customFieldsDictionary['STUDY_INSTANCE_UID'];
        print 'studyUID:' + studyUID;
    
        # Create test directorys
        testTempDir = tempRoot + '/' + accessionNumber;
        os.makedirs(testTempDir);
        retreivedFilesDirectory = testTempDir + '/retrieved'; 
        os.makedirs(retreivedFilesDirectory);
        sentFilesDirectory = testTempDir + '/sent'; 
        os.makedirs(sentFilesDirectory);
    
        ## --------------------------------------------------------- ##
        print 'Generate ORM HL7 message and send to HL7 receiver - Creates Exam & Patient entries via MIRTH' 
        ## --------------------------------------------------------- ##
        status = baseTest.generateAndSendOrm(testDataDir, customFieldsDictionary, mirthHl7Host, mirthHl7Port);
        if(status != 'SCHEDULED'):
            return (False, 'Failed to schedule exam');
        
        ## --------------------------------------------------------- ##
        print 'Generate ORU HL7 message and send to HL7 receiver' 
        ## --------------------------------------------------------- ##
        status = baseTest.generateAndSendOru(testDataDir, customFieldsDictionary, mirthHl7Host, mirthHl7Port);
        if(status != 'FINALIZED'):
            return (False, 'Failed to finalize exam');
        
        ## --------------------------------------------------------- ##
        print 'Prepare DICOM files to with Study, Series, SOP UIDs' 
        ## --------------------------------------------------------- ##
        studySeriesSopUIDs = [];
        # SeriesUID format - StudyUID.N
        # SopUID format    - StudyUID.Series.N
        #   where N is a reasonably unique int
        n = int(strftime('%H%M%S', localtime()));
        for seriesIndex in range(numberOfSeriesPerStudy):
            seriesN = seriesIndex + n;
            seriesUID = str(studyUID) + '.' + str(seriesN)
            for sopIndex in range(numberOfSOPsPerSeries):
                sopN = sopIndex + n;
                sopUID = str(seriesUID) + '.'+ str(sopN)
                studySeriesSopUIDs.append([studyUID, seriesUID, sopUID]);
        success = baseTest.generateCustomDicomFiles(studySeriesSopUIDs, customFieldsDictionary, testDataDir + '/dicom_files/CT.dcm', sentFilesDirectory)
        if not success:
            return (False, 'Failed to generate custom dicom files');
        
        ## --------------------------------------------------------- ##
        print 'Send DICOM files to PACS' 
        ## --------------------------------------------------------- ##
        baseTest.sendDicomFileToPacs(pacsAeTitle, pacsHost, pacsPort, sentFilesDirectory, customFieldsDictionary);
        
        
        ## --------------------------------------------------------- ##
        print 'Insert breakpoint, wait for transaction status to change to 40';  
        ## --------------------------------------------------------- ##
            
        print 'patientName:' + patientName;
        print 'patientID:' + patientID;
        print 'accessionNumber:' + accessionNumber;
        print 'studyUID:' + studyUID;
            
            
        return (True, 'Passed Tests');