Example #1
0
 def test_equal(self):
     loc1 = SdcLocation(bed='BedA500', root='myroot')
     loc2 = SdcLocation(bed='BedA500', root='myroot')
     self.assertEqual(loc1, loc2)
     for attrName in ('root', 'fac', 'bld', 'poc', 'flr', 'rm', 'bed'):
         print('different {} expected'.format(attrName))
         setattr(loc1, attrName, 'x')
         setattr(loc2, attrName, 'y')
         self.assertNotEqual(loc1, loc2)
         print('equal {} expected'.format(attrName))
         setattr(loc2, attrName, 'x')
         self.assertEqual(loc1, loc2)
Example #2
0
    def test_scopeString(self):
        expectedScopeStringSdc = self.scope_prefix + '/HOSP1%2F%2F%2FCU1%2F%2FBedA500?fac=HOSP1&poc=CU1&bed=BedA500'
        loc = SdcLocation(fac='HOSP1', poc='CU1', bed='BedA500')
        self.assertEqual(loc.root, self.default_root)
        self.assertEqual(loc.fac, 'HOSP1')
        self.assertEqual(loc.poc, 'CU1')
        self.assertEqual(loc.bed, 'BedA500')
        self.assertEqual(loc.rm, None)
        self.assertEqual(loc.bld, None)
        self.assertEqual(loc.flr, None)
        scopeString = loc.scopeStringSdc
        self.assertEqual(loc.scopeStringSdc, expectedScopeStringSdc)

        # this is an unusual scope with bed only plus root
        expectedScopeString = self.scheme + ':/myroot/%2F%2F%2F%2F%2FBedA500?bed=BedA500'
        loc = SdcLocation(bed='BedA500', root='myroot')
        self.assertEqual(loc.root, 'myroot')
        self.assertEqual(loc.fac, None)
        self.assertEqual(loc.poc, None)
        self.assertEqual(loc.bed, 'BedA500')
        self.assertEqual(loc.rm, None)
        self.assertEqual(loc.bld, None)
        self.assertEqual(loc.flr, None)
        scopeString = loc.scopeStringSdc
        self.assertEqual(scopeString, expectedScopeString)

        # this is an unusual scope with all parameters and spaces in them
        expectedScopeString = self.scheme + ':/some%20where/HOSP%201%2Fabc%201%2FCU%201%2Fflr%201%2FrM%201%2FBed%20A500?room=rM+1&flr=flr+1&bed=Bed+A500&bld=abc+1&fac=HOSP+1&poc=CU+1'
        loc = SdcLocation(fac='HOSP 1',
                          poc='CU 1',
                          bed='Bed A500',
                          flr='flr 1',
                          rm='rM 1',
                          bld='abc 1',
                          root='some where')
        self.assertEqual(loc.root, 'some where')
        self.assertEqual(loc.fac, 'HOSP 1')
        self.assertEqual(loc.poc, 'CU 1')
        self.assertEqual(loc.bed, 'Bed A500')
        self.assertEqual(loc.rm, 'rM 1')
        self.assertEqual(loc.bld, 'abc 1')
        self.assertEqual(loc.flr, 'flr 1')

        self.assertEqual(loc, SdcLocation.fromScopeString(loc.scopeStringSdc))
Example #3
0
    def setUpCocoDraft10(self):
        self.cocoFinalLocation = SdcLocation(fac='tklx', poc='CU1', bed='cocoDraft10Bed')

        self.sdcDeviceCoCoFinal = SomeDevice.fromMdibFile(self.wsdiscovery, None, '70041_MDIB_Final.xml')
        self.sdcDeviceCoCoFinal.startAll()
        self.sdcDeviceCoCoFinal.setLocation(self.cocoFinalLocation, self._locValidators)
        xAddr = self.sdcDeviceCoCoFinal.getXAddrs()
        self.sdcClientCocoFinal = SdcClient(xAddr[0],
                                            deviceType=self.sdcDeviceCoCoFinal.mdib.sdc_definitions.MedicalDeviceType,
                                            validate=True)
        self.sdcClientCocoFinal.startAll()
Example #4
0
    def test_fromScopeString(self):
        scopeStringSdc = self.scope_prefix + '/HOSP1%2F%2F%2FCU1%2F%2FBedA500?fac=HOSP1&poc=CU1&bed=BedA500'
        loc = SdcLocation.fromScopeString(scopeStringSdc)
        self.assertEqual(loc.root, self.default_root)
        self.assertEqual(loc.fac, 'HOSP1')
        self.assertEqual(loc.poc, 'CU1')
        self.assertEqual(loc.bed, 'BedA500')
        self.assertEqual(loc.rm, None)
        self.assertEqual(loc.bld, None)
        self.assertEqual(loc.flr, None)
        self.assertEqual(loc.scopeStringSdc, scopeStringSdc)

        # correct handling of scope with %20 spaces and + char in query
        scopeString = self.scheme + ':/some%20where/HOSP%201%2Fabc%201%2FCU%201%2Fflr%201%2FrM%201%2FBed%20A500?rm=rM+1&flr=flr+1&bed=Bed+A500&bldng=abc+1&fac=HOSP+1&poc=CU+1'
        loc = SdcLocation.fromScopeString(scopeString)
        self.assertEqual(loc.root, 'some where')
        self.assertEqual(loc.fac, 'HOSP 1')
        self.assertEqual(loc.poc, 'CU 1')
        self.assertEqual(loc.bed, 'Bed A500')
        self.assertEqual(loc.rm, 'rM 1')
        self.assertEqual(loc.bld, 'abc 1')
        self.assertEqual(loc.flr, 'flr 1')

        #if we can create another identical  DraegerLocation from loc, then scopeString also seems okay.
        self.assertEqual(loc, SdcLocation.fromScopeString(loc.scopeStringSdc))

        # correct handling of scope with %20 spaces also in query
        for scopeString in (
                self.scheme +
                ':/some%20where/HOSP%201%2Fabc%201%2FCU%201%2Fflr%201%2FrM%201%2FBed%20A500?rm=rM%201&flr=flr%201&bed=Bed+A500&bldng=abc+1&fac=HOSP+1&poc=CU+1',
                self.scheme +
                ':/some%20where/this_part_of string_does_not_matter?rm=rM%201&flr=flr%201&bed=Bed+A500&bldng=abc+1&fac=HOSP+1&poc=CU+1'
        ):
            loc = SdcLocation.fromScopeString(scopeString)
            self.assertEqual(loc.root, 'some where')
            self.assertEqual(loc.fac, 'HOSP 1')
            self.assertEqual(loc.poc, 'CU 1')
            self.assertEqual(loc.bed, 'Bed A500')
            self.assertEqual(loc.rm, 'rM 1')
            self.assertEqual(loc.bld, 'abc 1')
            self.assertEqual(loc.flr, 'flr 1')
Example #5
0
    def setUp(self):
        logging.getLogger('sdc').info('############### start setUp {} ##############'.format(self._testMethodName))
        self.wsd = wsdiscovery.WSDiscoveryWhitelist(['127.0.0.1'])
        self.wsd.start()
        location = SdcLocation(fac='tklx',
                               poc='CU1',
                               bed='Bed')
    
#        self.sdcDevice = CoCoDeviceAnesthesia(self.wsd, my_uuid=None, useSSL=False)
        self.sdcDevice = SomeDevice.fromMdibFile(self.wsd, None, '70041_MDIB_Final.xml')
        self.sdcDevice.startAll()
        self._locValidators = [pmtypes.InstanceIdentifier('Validator', extensionString='System')]
        self.sdcDevice.setLocation(location, self._locValidators)

        time.sleep(0.1) # allow full init of device
        
        print ('############### setUp done {} ##############'.format(self._testMethodName))
        logging.getLogger('sdc').info('############### setUp done {} ##############'.format(self._testMethodName))
    def test_getContextStates(self):
        facility = 'HOSP42'
        poc = 'Care Unit 1'
        bed = 'my bed'
        loc = SdcLocation(fac=facility, poc=poc, bed=bed)
        for sdcDevice in self._alldevices:
            sdcDevice.mdib.setLocation(loc)
            contextService = sdcDevice._handler._ContextDispatcher
            endpoint_reference = '123'
            getEnv = self._mkGetRequest(sdcDevice,
                                        contextService.port_type_string,
                                        'GetContextStates', endpoint_reference)
            receivedEnv = AddressedSoap12Envelope.fromXMLString(
                getEnv.as_xml())
            httpHeader = {}
            response = contextService.dispatchSoapRequest(
                None, httpHeader, receivedEnv)
            print(response.as_xml(pretty=True))
            response.validateBody(sdcDevice.mdib.bicepsSchema.bmmSchema)
            _ns = sdcDevice.mdib.nsmapper  # shortcut
            query = '*/{}[@{}="{}"]'.format(
                _ns.docName(Prefix.MSG, 'ContextState'),
                _ns.docName(Prefix.XSI, 'type'),
                _ns.docName(Prefix.PM, 'LocationContextState'))
            locationContextNodes = response.bodyNode.xpath(
                query, namespaces=_ns.docNssmap)
            self.assertEqual(len(locationContextNodes), 1)
            identificationNode = locationContextNodes[0].find(
                domTag('Identification'))
            if sdcDevice is self.sdcDevice_final:
                self.assertEqual(identificationNode.get('Extension'),
                                 '{}///{}//{}'.format(facility, poc, bed))
            else:
                self.assertEqual(identificationNode.get('Extension'),
                                 '{}/{}/{}'.format(facility, poc, bed))

            locationDetailNode = locationContextNodes[0].find(
                domTag('LocationDetail'))
            self.assertEqual(locationDetailNode.get('PoC'), poc)
            self.assertEqual(locationDetailNode.get('Bed'), bed)
            self.assertEqual(locationDetailNode.get('Facility'), facility)
            print(response.as_xml(pretty=True))
Example #7
0
    def testRecording(self):
        testFile = "testFile"

        # create and start recorder
        rec = sdc11073.recording.ClientRecorder(self.sdcClientCocoFinal,
                                                ".",
                                                filename=testFile)
        rec.startRecording()
        self.cleanUpDirs.append(rec.currentRecordingPath)

        # make changes to the mdib
        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=False) as mgr:
            mst = mgr.getMetricState('0x34F00100')
            if mst.metricValue is None:
                mst.mkMetricValue()
            mst.metricValue.Value = 12
            mst.metricValue.Validity = 'Vld'
            mst.metricValue.DeterminationTime = time.time()
            metricDescriptor = mgr.getDescriptor('0x34F00100')
            metricDescriptor.DeterminationPeriod = 29.0
            numericMetricDescriptorContainer = NumericMetricDescriptorContainer(
                nsmapper=self.sdcDeviceCoCoFinal.mdib.nsmapper,
                nodeName=namespaces.domTag('Metric'),
                handle="testHandle",
                parentHandle='2.1.1.1'  #"COCO_2827", #""COCO_3120",
            )
            numericMetricDescriptorContainer.Type = CodedValue('11921', 'sys')
            numericMetricDescriptorContainer.Unit = CodedValue('11921', 'sys')
            numericMetricDescriptorContainer.Resolution = 0.01
            mgr.createDescriptor(numericMetricDescriptorContainer)

        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=False) as mgr:
            metricState = mgr.getMetricState("testHandle")
            metricState.Validity = 'Vld'

        time.sleep(1)

        mdsHandle = self.sdcDeviceCoCoFinal.mdib.descriptions.NODETYPE.getOne(
            sdc11073.namespaces.domTag('MdsDescriptor')).handle
        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction() as mgr:
            tst = mgr.getComponentState(mdsHandle)
            tst.ActivationState = "StndBy"
        time.sleep(1)

        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=True) as mgr:
            acst = mgr.getAlertState('0xD3C00100')
            acst.Presence = False
        time.sleep(1)

        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=True) as mgr:
            asst = mgr.getAlertState(
                '0xD3C00100.loc.Vis')  #('AlertSignal_0xD3C00100_Aud')
            asst.ActivationState = 'On'
        time.sleep(1)

        patientDescriptorContainer = self.sdcDeviceCoCoFinal.mdib.descriptions.NODETYPE.getOne(
            sdc11073.namespaces.domTag('PatientContextDescriptor'))
        # create a patient locally on device, then test update from client
        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction() as mgr:
            st = mgr.getContextState(patientDescriptorContainer.handle)
            st.Givenname = 'Max123'
            st.Middlename = 'Willy'
            st.Birthname = 'Mustermann \n'
            st.Familyname = 'Musterfrau'
            st.Title = 'Rex'
            st.Sex = 'M'
            st.PatientType = pmtypes.PatientType.ADULT
            st.Height = sdc11073.pmtypes.Measurement(
                88.2, sdc11073.pmtypes.CodedValue('abc', 'def'))
            st.Weight = sdc11073.pmtypes.Measurement(
                68.2, sdc11073.pmtypes.CodedValue('abc'))
            st.Race = sdc11073.pmtypes.CodedValue('123', 'def')

        newLocation = SdcLocation(fac='tasdaklx',
                                  poc='CsadU1',
                                  bed='cocoDraft10Bed')
        self.sdcDeviceCoCoFinal.setLocation(newLocation, [])

        paw = waveforms.SawtoothGenerator(min_value=0,
                                          max_value=10,
                                          waveformperiod=1.1,
                                          sampleperiod=0.01)
        self.sdcDeviceCoCoFinal.mdib.registerWaveformGenerator(
            '0x34F05500', paw)

        # record some waveforms and then stop
        for x in range(20):
            time.sleep(1)
            # make changes to the mdib
            with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                    setDeterminationTime=False) as mgr:
                mst = mgr.getMetricState('0x34F00100')
                mst.metricValue.Value = x

        with self.sdcDeviceCoCoFinal.mdib.mdibUpdateTransaction(
                setDeterminationTime=True) as mgr:
            asst = mgr.getAlertState(
                '0xD3C00100.loc.Vis')  #('AlertSignal_0xD3C00100_Aud')
            asst.ActivationState = 'Off'
        time.sleep(1)
        rec.stopRecording()
        # verify recording has stopped by monitoring the file size
        recordingFile = os.path.join(rec.currentRecordingPath,
                                     testFile) + ".rec"
        currentSize = os.path.getsize(recordingFile)
        time.sleep(1)
        self.assertEqual(currentSize, os.path.getsize(recordingFile))
        #
        # verify contents have metric and real time updates
        with open(recordingFile, 'r') as f:
            version = f.readline()
            self.assertTrue("pysdc ver" in version)

            mdib = f.readline()
            self.assertTrue("GetMdibResponse" in mdib)

            for line in f:
                nodeString = line.split("|", 1)[1]
                if nodeString.startswith("u'"):
                    nodeString = nodeString[2:-2]
                else:
                    nodeString = nodeString[1:-2]
                node = lxml.etree.fromstring(nodeString)

                if node.tag == namespaces.msgTag(
                        'DescriptionModificationReport'):
                    val = node.xpath('//dom:MetricValue',
                                     namespaces=namespaces.nsmap)
                    self.assertEqual(val[0].attrib['Value'], '12')
                    f.close()
                    break

        #verify archive has been created
        rec.archive()
        expectedZipFile = os.path.join(rec.currentRecordingPath,
                                       testFile) + ".zip"
        self.assertTrue(os.path.exists(expectedZipFile))
        rec_file = os.path.join(rec.currentRecordingPath, testFile) + ".rec"
        player = sdc11073.recording.MdibPlayer()
        mdib = player.readRecording(rec_file)

        model = DPWSThisModel(manufacturer="Draeger",
                              manufacturerUrl="draeger.com",
                              modelName="testMOdel",
                              modelNumber="231412411241",
                              modelUrl="draeger.com/testMOdel",
                              presentationUrl="draeger.com/testMOdel")
        device = DPWSThisDevice(friendlyName="SuperDevice",
                                firmwareVersion="v1.23",
                                serialNumber="MISAD31245124")

        self._publishingDevice = SdcDevice(self.wsdiscovery, uuid.uuid1(),
                                           model, device, mdib)
        # commLogger = commlog.CommLogger(log_folder="testcomm",
        #                                 log_out=True,
        #                                 log_in=False,
        #                                 broadcastIpFilter=None)
        # commlog.defaultLogger = commLogger

        self._publishingDevice.startAll()
        loca = SdcLocation(fac='Noneas', poc='CU1', bed='cocoDraft6Bed')
        self._publishingDevice.setLocation(loca, [])
        player.play(self._publishingDevice, loop=True)
        time.sleep(40)
        player.stop()
Example #8
0
    def test_LocationContextStateContainer(self):
        def verifyEqual(origin, copied):
            self.assertEqual(copied.Handle, origin.Handle)
            self.assertEqual(copied.PoC, origin.PoC)
            self.assertEqual(copied.Room, origin.Room)
            self.assertEqual(copied.Bed, origin.Bed)
            self.assertEqual(copied.Facility, origin.Facility)
            self.assertEqual(copied.Building, origin.Building)
            self.assertEqual(copied.Floor, origin.Floor)
            self._verifyAbstractStateContainerDataEqual(copied, origin)

        sc = statecontainers.LocationContextStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=None)

        self.assertTrue(sc.Handle is not None)
        self.assertEqual(sc.PoC, None)
        self.assertEqual(sc.Room, None)
        self.assertEqual(sc.Bed, None)
        self.assertEqual(sc.Facility, None)
        self.assertEqual(sc.Building, None)
        self.assertEqual(sc.Floor, None)

        #test creation from empty node
        node = sc.mkStateNode()
        self.assertEqual(node.get('Handle'), sc.Handle)
        print(etree_.tostring(node, pretty_print=True))
        sc2 = statecontainers.LocationContextStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=node)
        verifyEqual(sc, sc2)

        sc.Handle = 'xyz'
        sc.PoC = 'a'
        sc.Room = 'b'
        sc.Bed = 'c'
        sc.Facility = 'd'
        sc.Building = 'e'
        sc.Floor = 'f'

        #test creation from non-empty node
        node = sc.mkStateNode()
        sc2 = statecontainers.LocationContextStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=node)
        verifyEqual(sc, sc2)
        sc.PoC = 'aa'
        sc.Room = 'bb'
        sc.Bed = 'cc'
        sc.Facility = 'dd'
        sc.Building = 'ee'
        sc.Floor = 'ff'

        node = sc.mkStateNode()
        sc2.updateFromNode(node)
        verifyEqual(sc, sc2)

        loc = SdcLocation(fac='a',
                          poc='b',
                          bed='c',
                          bld='d',
                          flr='e',
                          rm='f',
                          root='g')
        bicepsSchema = xmlparsing.BicepsSchema(SDC_v1_Definitions)
        sc = statecontainers.LocationContextStateContainer.fromSdcLocation(
            nsmapper=self.nsmapper,
            descriptorContainer=self.dc,
            handle='abc',
            sdc_location=loc,
            bicepsSchema=bicepsSchema)
        self.assertEqual(sc.Handle, 'abc')
        self.assertEqual(sc.PoC, 'b')
        self.assertEqual(sc.Room, 'f')
        self.assertEqual(sc.Bed, 'c')
        self.assertEqual(sc.Facility, 'a')
        self.assertEqual(sc.Building, 'd')
        self.assertEqual(sc.Floor, 'e')

        #test creation from non-empty node
        node = sc.mkStateNode()
        sc2 = statecontainers.LocationContextStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=node)
        verifyEqual(sc, sc2)

        #Umlaut test
        dr = SdcLocation(fac=u'Dräger',
                         poc=u'b',
                         bed=u'c',
                         bld=u'd',
                         flr=u'e',
                         rm=u'f',
                         root=u'g')
        sc3 = statecontainers.LocationContextStateContainer.fromSdcLocation(
            nsmapper=self.nsmapper,
            descriptorContainer=self.dc,
            handle='abc',
            sdc_location=loc,
            bicepsSchema=bicepsSchema)
        sc2.updateFromSdcLocation(loc, bicepsSchema)
        verifyEqual(sc3, sc2)
Example #9
0
    def test_contains(self):
        whole_world = SdcLocation()
        my_bed = SdcLocation(fac='fac1',
                             poc='poc1',
                             bed='bed1',
                             bld='bld1',
                             flr='flr1',
                             rm='rm1')
        my_bld = SdcLocation(fac='fac1', poc='poc1', bld='bld1')
        other_bld = SdcLocation(fac='fac1', poc='poc1', bld='bld2')
        any_flr1 = SdcLocation(
            flr='flr1')  # any location that has flr1 will match
        self.assertTrue(my_bed in whole_world)
        self.assertFalse(whole_world in my_bed)
        self.assertTrue(my_bed in SdcLocation(fac='fac1'))
        self.assertTrue(my_bed in SdcLocation(fac='fac1', poc='poc1'))
        self.assertTrue(my_bed in SdcLocation(fac='fac1', bed='bed1'))
        self.assertTrue(my_bed in SdcLocation(bed='bed1'))
        self.assertTrue(my_bed in my_bld)
        self.assertFalse(my_bld in my_bed)
        self.assertTrue(my_bed in any_flr1)
        self.assertFalse(my_bld in any_flr1)
        self.assertFalse(my_bed in other_bld)

        # non-default root
        my_bed = SdcLocation(fac='fac1',
                             poc='poc1',
                             bed='bed1',
                             bld='bld1',
                             flr='flr1',
                             rm='rm1',
                             root='myroot')
        self.assertTrue(my_bed in SdcLocation(fac='fac1',
                                              poc='poc1',
                                              bed='bed1',
                                              bld='bld1',
                                              flr='flr1',
                                              rm='rm1',
                                              root='myroot'))
        self.assertTrue(my_bed in SdcLocation(fac='fac1', root='myroot'))
        self.assertFalse(my_bed in SdcLocation(fac='fac2', root='myroot'))
        self.assertFalse(my_bed in SdcLocation(fac='fac1'))
Example #10
0
        newEnsState.ContextAssociation = 'Assoc'
        newEnsState.Identification = [
            pmtypes.InstanceIdentifier(root="1.2.3", extensionString=ensemble)
        ]


if __name__ == '__main__':
    # start with discovery (MDPWS) that is running on the named adapter "Ethernet" (replace as you need it on your machine, e.g. "enet0" or "Ethernet")
    myDiscovery = WSDiscoverySingleAdapter("Ethernet")
    # start the discovery
    myDiscovery.start()
    # create a local mdib that will be sent out on the network, the mdib is based on a XML file
    my_mdib = DeviceMdibContainer.fromMdibFile("mdib.xml")
    print("My UUID is {}".format(my_uuid))
    # set a location context to allow easy discovery
    my_location = SdcLocation(fac='HOSP', poc='CU2', bed='BedSim')
    # set model information for discovery
    dpwsModel = DPWSThisModel(
        manufacturer='Draeger',
        manufacturerUrl='www.draeger.com',
        modelName='TestDevice',
        modelNumber='1.0',
        modelUrl='www.draeger.com/model',
        presentationUrl='www.draeger.com/model/presentation')
    dpwsDevice = DPWSThisDevice(friendlyName='TestDevice',
                                firmwareVersion='Version1',
                                serialNumber='12345')
    # create a device (provider) class that will do all the SDC magic
    sdcDevice = SdcDevice(ws_discovery=myDiscovery,
                          my_uuid=my_uuid,
                          model=dpwsModel,