示例#1
0
def store(host, port, calling_ae_title, called_ae_title, filenames):
    transfer_syntaxes = [
        odil.registry.ExplicitVRLittleEndian,
        odil.registry.ImplicitVRLittleEndian,
    ]

    # Find all SOP classes to negotiate at association time. We don't need to
    # read the whole data set for this
    sop_classes = set()
    for filename in filenames:
        with odil.open(filename) as stream:
            _, data_set = odil.Reader.read_file(
                stream,
                halt_condition=lambda tag: tag > odil.registry.SOPClassUID)
        sop_classes.update(data_set.as_string("SOPClassUID"))

    presentation_contexts = [
        odil.AssociationParameters.PresentationContext(
            2 * i + 1, sop_class, transfer_syntaxes,
            odil.AssociationParameters.PresentationContext.Role.SCU)
        for i, sop_class in enumerate(sop_classes)
    ]

    # Create the association and the Store SCU
    association = odil.Association()
    association.set_peer_host(host)
    association.set_peer_port(port)
    association.update_parameters()\
        .set_calling_ae_title(calling_ae_title)\
        .set_called_ae_title(called_ae_title)\
        .set_presentation_contexts(presentation_contexts)
    association.associate()

    negotiated_parameters = association.get_negotiated_parameters()
    negotiated_pc = negotiated_parameters.get_presentation_contexts()

    store = odil.StoreSCU(association)

    for filename in filenames:
        with odil.open(filename) as stream:
            _, data_set = odil.Reader.read_file(stream)

        try:
            store.set_affected_sop_class(data_set)
            store.store(data_set)
        except Exception as e:
            print("Could not store {}: {}".format(filename, e))

    association.release()
示例#2
0
    def test_store(self):
        store = odil.StoreSCU(self.association)

        store.set_affected_sop_class(self.data_set)
        store.store(self.data_set)
示例#3
0
 def test_affected_sop_class_uid(self):
     store = odil.StoreSCU(self.association)
     store.set_affected_sop_class(self.data_set)
     self.assertEqual(store.get_affected_sop_class().encode(),
                      odil.registry.RawDataStorage)
示例#4
0
 def test_affected_sop_class_uid(self):
     store = odil.StoreSCU(self.association)
     store.set_affected_sop_class("1.2.3")
     self.assertEqual(store.get_affected_sop_class(), "1.2.3")