Example #1
0
def find(host, port, calling_ae_title, called_ae_title, level, keys,
         decode_uids):
    query = odil.DataSet()
    for key in keys:
        if "=" in key:
            key, value = key.split("=", 1)
            value = value.split("\\")
        else:
            value = None

        tag = getattr(odil.registry, key)

        if value is not None:
            vr = odil.registry.public_dictionary[tag].vr
            if vr in ["DS", "FL", "FD"]:
                value = [float(x) for x in value]
            elif vr in ["IS", "SL", "SS", "UL", "US"]:
                value = [int(x) for x in value]

            query.add(tag, value)
        else:
            query.add(tag)

    sop_class = getattr(
        odil.registry,
        "{}RootQueryRetrieveInformationModelFind".format(level.capitalize()))

    find_pc = odil.AssociationParameters.PresentationContext(
        1, sop_class, [
            odil.registry.ImplicitVRLittleEndian,
            odil.registry.ExplicitVRLittleEndian
        ], odil.AssociationParameters.PresentationContext.Role.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([find_pc])
    association.associate()
    logging.info("Association established")

    find = odil.FindSCU(association)
    find.set_affected_sop_class(sop_class)
    data_sets = find.find(query)
    print("{} answer{}".format(len(data_sets),
                               "s" if len(data_sets) > 1 else ""))

    max_length = 0
    for data_set in data_sets:
        max_length = max(max_length, find_max_name_length(data_set))

    for data_set in data_sets:
        print_data_set(data_set, decode_uids, "", max_length,
                       odil.Value.Strings())
        print()

    association.release()
    logging.info("Association released")
Example #2
0
    def test_without_callback(self):
        find = odil.FindSCU(self.association)
        find.set_affected_sop_class(odil.registry.PatientRootQueryRetrieveInformationModelFind)
        data_sets = find.find(self.query)

        self.assertEqual(len(data_sets), 1)
        self.assertSequenceEqual(
            data_sets[0].as_string("PatientID"), [b"DJ001"])
Example #3
0
def find_abstract_syntaxes(host, port, calling_ae_title, called_ae_title,
                           level, keys):
    """ Return the abstract syntaxes corresponding to the query, based on 
        SOP Classes in Study.
    """

    query = odil.DataSet()
    for key in keys:
        key, value = key.split("=", 1)
        value = value.split("\\")

        if key in ["QueryRetrieveLevel", "SOPClassesInStudy"]:
            continue

        tag = getattr(odil.registry, key)

        vr = odil.registry.public_dictionary[tag].vr
        if vr in ["DS", "FL", "FD"]:
            value = [float(x) for x in value]
        elif vr in ["IS", "SL", "SS", "UL", "US"]:
            value = [int(x) for x in value]

        query.add(tag, value)
    query.add("QueryRetrieveLevel", ["STUDY"])
    query.add("SOPClassesInStudy")

    find_syntax = getattr(
        odil.registry,
        "{}RootQueryRetrieveInformationModelFind".format(level.capitalize()))

    transfer_syntaxes = [
        odil.registry.ImplicitVRLittleEndian,
        odil.registry.ExplicitVRLittleEndian
    ]

    find_pc = odil.AssociationParameters.PresentationContext(
        1, find_syntax, transfer_syntaxes,
        odil.AssociationParameters.PresentationContext.Role.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([find_pc])
    association.associate()
    logging.info("Association established")

    find = odil.FindSCU(association)
    find.set_affected_sop_class(find_syntax)
    data_sets = find.find(query)
    sop_classes = set()
    for data_set in data_sets:
        if "SOPClassesInStudy" in data_set:
            sop_classes.update(data_set.as_string("SOPClassesInStudy"))
    return sop_classes
Example #4
0
        [odil.registry.ExplicitVRLittleEndian], True, False)
]

association.update_parameters()\
    .set_calling_ae_title("myself")\
    .set_called_ae_title("AWSPIXELMEDPUB") \
    .set_presentation_contexts(presentation_contexts)
association.associate()

query = odil.DataSet()
query.add(odil.registry.PatientName, odil.Value.Strings(["*"]))
query.add(odil.registry.QueryRetrieveLevel, odil.Value.Strings(["STUDY"]))
query.add(odil.registry.StudyDescription)
query.add(odil.registry.StudyDate)

find = odil.FindSCU(association)
find.set_affected_sop_class(
    odil.registry.StudyRootQueryRetrieveInformationModelFIND)


def callback(data_set):
    print data_set.as_string(odil.registry.PatientName)[0]


find.find(query, callback)

data_sets = find.find(query)
print len(data_sets), "found"
for data_set in data_sets:
    print data_set.as_string(odil.registry.PatientName)[0]