Exemplo n.º 1
0
    def test_PatientContextStateContainer_final(self):
        def verifyEqual(origin, copied):
            self.assertEqual(copied.Handle, origin.Handle)
            self.assertEqual(copied.Givenname, origin.Givenname)
            self.assertEqual(copied.Middlename, origin.Middlename)
            self.assertEqual(copied.Familyname, origin.Familyname)
            self.assertEqual(copied.DateOfBirth, origin.DateOfBirth)
            self.assertEqual(copied.Height, origin.Height)
            self.assertEqual(copied.Weight, origin.Weight)
            self.assertEqual(copied.Race, origin.Race)
            self.assertEqual(copied.Identification, origin.Identification)
            self._verifyAbstractStateContainerDataEqual(copied, origin)

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

        self.assertTrue(sc.Handle is not None)

        sc.Givenname = 'Karl'
        sc.Middlename = 'M.'
        sc.Familyname = 'Klammer'
        sc.Height = pmtypes.Measurement(88.2, pmtypes.CodedValue('abc', 'def'))
        sc.Weight = pmtypes.Measurement(68.2, pmtypes.CodedValue('abc'))
        sc.Race = pmtypes.CodedValue('123', 'def')

        sc.DateOfBirth = datetime.date(2001, 3, 12)
        print(sc.DateOfBirth)

        sc.Identification.append(
            pmtypes.InstanceIdentifier('abc', pmtypes.CodedValue('123'), [
                pmtypes.LocalizedText('Peter', 'en'),
                pmtypes.LocalizedText('Paul'),
                pmtypes.LocalizedText('Mary')
            ]))
        sc.Identification.append(
            pmtypes.InstanceIdentifier('def', pmtypes.CodedValue('456'), [
                pmtypes.LocalizedText('John'),
                pmtypes.LocalizedText('Jim'),
                pmtypes.LocalizedText('Jane')
            ]))

        #test creation from node
        node = sc.mkStateNode()
        print(etree_.tostring(node, pretty_print=True))
        sc2 = statecontainers.PatientContextStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=node)
        verifyEqual(sc, sc2)

        #test update from node
        sc.Middlename = 'K.'
        sc.DateOfBirth = datetime.datetime(2001, 3, 12, 14, 30, 1)
        sc.incrementState()
        sc.Height._value = 42
        sc.Weight._value = 420
        node = sc.mkStateNode()
        sc2.updateFromNode(node)
        verifyEqual(sc, sc2)
Exemplo n.º 2
0
def setEnsembleContext(theMDIB, theClient):
    # calling operation on remote device
    print("Trying to set ensemble context of device A")
    # first we get the container to the element in the MDIB
    descriptorContainer = theMDIB.descriptions.NODETYPE.getOne(
        domTag('EnsembleContextDescriptor'))
    # get the context of our provider(client)
    contextClient = theClient.ContextService_client
    # start with empty operation handle and try to find the one we need
    operationHandle = None
    # iterate over all matching handles (can be 0..n)
    for oneOp in theMDIB.descriptions.NODETYPE.get(
            domTag('SetContextStateOperationDescriptor'), []):
        if oneOp.OperationTarget == descriptorContainer.handle:
            operationHandle = oneOp.Handle
    # now we should have a operatoin handle to work with
    # create a new ensemble context as parameter to this operation
    newEnsembleContext = contextClient.mkProposedContextObject(
        descriptorContainer.handle)
    newEnsembleContext.ContextAssociation = 'Assoc'
    newEnsembleContext.Identification = [
        pmtypes.InstanceIdentifier(root="1.2.3",
                                   extensionString="SupervisorSuperEnsemble")
    ]
    # execute the remote operation (based on handle) with the newly created ensemble as parameter
    contextClient.setContextState(operationHandle, [newEnsembleContext])
Exemplo n.º 3
0
def setLocalEnsembleContext(mdib, ensemble):
    descriptorContainer = mdib.descriptions.NODETYPE.getOne(
        domTag('EnsembleContextDescriptor'))
    if not descriptorContainer:
        print("No ensemble contexts in mdib")
        return
    allEnsembleContexts = mdib.contextStates.descriptorHandle.get(
        descriptorContainer.handle, [])
    with mdib.mdibUpdateTransaction() as mgr:
        # set all to currently associated Locations to Disassociated
        associatedEnsembles = [
            l for l in allEnsembleContexts
            if l.ContextAssociation == pmtypes.ContextAssociation.ASSOCIATED
        ]
        for l in associatedEnsembles:
            ensembleContext = mgr.getContextState(l.descriptorHandle, l.Handle)
            ensembleContext.ContextAssociation = pmtypes.ContextAssociation.DISASSOCIATED
            ensembleContext.UnbindingMdibVersion = mdib.mdibVersion  # UnbindingMdibVersion is the first version in which it is no longer bound ( == this version)

        newEnsState = mgr.getContextState(
            descriptorContainer.handle)  # this creates a new location state
        newEnsState.ContextAssociation = 'Assoc'
        newEnsState.Identification = [
            pmtypes.InstanceIdentifier(root="1.2.3", extensionString=ensemble)
        ]
Exemplo n.º 4
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))
Exemplo n.º 5
0
 def setUp(self):
     self.wsdiscovery = WSDiscoverySingleAdapter(loopback_adapter)
     self.wsdiscovery.start()
     self._locValidators = [pmtypes.InstanceIdentifier('Validator', extensionString='System')]
Exemplo n.º 6
0
    def test_AbstractContextStateContainer(self):
        def verifyEqual(origin, copied):
            self.assertEqual(copied.ContextAssociation,
                             origin.ContextAssociation)
            self.assertEqual(copied.BindingMdibVersion,
                             origin.BindingMdibVersion)
            self.assertEqual(copied.UnbindingMdibVersion,
                             origin.UnbindingMdibVersion)
            self.assertEqual(copied.BindingStartTime, origin.BindingStartTime)
            self.assertEqual(copied.BindingEndTime, origin.BindingEndTime)
            self.assertEqual(copied.Validator, origin.Validator)
            self.assertEqual(copied.Identification, origin.Identification)
            self._verifyAbstractStateContainerDataEqual(copied, origin)

        sc = statecontainers.AbstractContextStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=None)
        self.assertEqual(sc.ContextAssociation, 'No')
        self.assertEqual(sc.BindingMdibVersion, None)
        self.assertEqual(sc.UnbindingMdibVersion, None)
        self.assertEqual(sc.BindingStartTime, None)
        self.assertEqual(sc.BindingEndTime, None)
        self.assertEqual(sc.Validator, [])
        self.assertEqual(sc.Identification, [])

        idents = [
            pmtypes.InstanceIdentifier(
                root='abc',
                type_codedValue=pmtypes.CodedValue('abc', 'def'),
                identifierNames=[pmtypes.LocalizedText('ABC')],
                extensionString='123')
        ]
        sc.Identification = idents
        self.assertEqual(sc.Identification, idents)

        validators = [
            pmtypes.InstanceIdentifier(
                root='ABC',
                type_codedValue=pmtypes.CodedValue('123', '456'),
                identifierNames=[pmtypes.LocalizedText('DEF')],
                extensionString='321')
        ]
        sc.Validator = validators
        self.assertEqual(sc.Validator, validators)

        for value in ('assoc', 'disassoc'):
            sc.ContextAssociation = value
            node = sc.mkStateNode()
            self.assertEqual(node.get('ContextAssociation'), value)

        for value in (12345.123, 67890.987):
            sc.BindingStartTime = value
            sc.BindingEndTime = value + 1
            node = sc.mkStateNode()
            self.assertEqual(
                node.get('BindingStartTime'),
                containerproperties.TimestampConverter.toXML(value))
            self.assertEqual(
                node.get('BindingEndTime'),
                containerproperties.TimestampConverter.toXML(value + 1))

        for value in (0, 42, 123):
            sc.BindingMdibVersion = value
            sc.UnbindingMdibVersion = value + 1
            node = sc.mkStateNode()
            self.assertEqual(node.get('BindingMdibVersion'),
                             containerproperties.IntegerConverter.toXML(value))
            self.assertEqual(
                node.get('UnbindingMdibVersion'),
                containerproperties.IntegerConverter.toXML(value + 1))

        node = etree_.Element(namespaces.domTag('State'),
                              attrib={
                                  'StateVersion': '2',
                                  'DescriptorHandle': '123',
                                  'BindingStartTime': '1234567',
                                  'BindingEndTime': '2345678',
                                  'Handle': sc.Handle
                              })
        sc.updateFromNode(node)
        self.assertEqual(sc.BindingStartTime, 1234.567)
        self.assertEqual(sc.BindingEndTime, 2345.678)
        self.assertEqual(sc.node.get('BindingStartTime'), '1234567')
        self.assertEqual(sc.node.get('BindingEndTime'), '2345678')
        self.assertEqual(sc.Identification, [])
        self.assertEqual(sc.Validator, [])

        #test creation from node
        sc.Identification = idents
        sc.Validator = validators
        node = sc.mkStateNode()
        sc2 = statecontainers.AbstractContextStateContainer(
            nsmapper=self.nsmapper, descriptorContainer=self.dc, node=node)
        verifyEqual(sc, sc2)