Enet4 / dicom-rs

Rust implementation of the DICOM standard
https://dicom-rs.github.io
Apache License 2.0
416 stars 81 forks source link

Decompose findscu to be more modular and have an easy-to-use library #352

Open qarmin opened 1 year ago

qarmin commented 1 year ago

Dicom, pynetdicom, dicom-rs I have been trying to understand and use them with varying degrees of success for 1 week, so as you can see my experience is limited, but I have noticed that it is quite difficult to use this library).

However, there are a few things that I found while trying to implement worklist(only find), so that for scheduled examinations from a given day I could send patient data(name, id, date of birth, etc.) to another application via e.g. Redis.

Apparently, I could try to parse the string output from findscu, but it would not look very good(additionally worklist not supported in this project).

https://github.com/Enet4/dicom-rs/blob/1ab8b09c9d76c10caeb0890937cf4983b88e8467/findscu/src/main.rs#L207-L243

import sys
from builtins import *
from pydantic import BaseModel
from pynetdicom import (
    AE,
    BasicWorklistManagementPresentationContexts,
    QueryRetrievePresentationContexts,
)
from pynetdicom.apps.common import create_dataset
from pynetdicom.sop_class import ModalityWorklistInformationFind

from typing import Optional

class Temp(BaseModel):
    addr = '127.0.0.1'
    port = 4242
    keyword = [
        'PatientID',
        'PatientName',
        'PatientBirthDate',
        'PatientSex',
        'ScheduledProcedureStepSequence[0].ScheduledStationAETitle',
        'ScheduledProcedureStepSequence[0].ScheduledProcedureStepStartDate=19951015',
        'ScheduledProcedureStepSequence[0].ScheduledProcedureStepStartTime'

    ]
    file: Optional[str] = None

def main():
    args = Temp()

    identifier = create_dataset(args, None)
    ae = AE()

    ae.requested_contexts = QueryRetrievePresentationContexts + BasicWorklistManagementPresentationContexts

    query_model = ModalityWorklistInformationFind

    assoc = ae.associate(
        args.addr,
        args.port,
    )
    if assoc.is_established:
        responses = assoc.send_c_find(identifier, query_model)
        for (status, rsp_identifier) in responses:
            if status and status.Status in [0xFF00, 0xFF01]:
                print(status)
                print(rsp_identifier)
                print(f"RRRR    {rsp_identifier.PatientID}")

        # Release the association
        assoc.release()
    else:
        sys.exit(1)

if __name__ == "__main__":
    main()
Enet4 commented 1 year ago

Thank you for your well informed feedback, @qarmin! I can comment on the two points in particular, but the short version is that I not only agree that the library APIs can be extended with better abstractions for building high level DICOM software, it is also in my plans to have them in the project.

This does not quite have to do with the lack of modularity in the project, but with missing pieces in these modules which need time and effort to develop. I have not had much of these two lately, and attracting contributors to close these tasks is one of the open challenges, but we will get there! I can try to split the feedback into separate issues in the meantime. See also the project roadmap.


Addendum: In DICOM-rs 0.6.0, a few things were introduced that make some of these things a bit easier:

¹ Constructing command objects is a bit easier using InMemDicomObject::command_from_element_iter: #365

² Constants to standard UIDs are now available in dicom-dictionary-std: #372

³ The operations API is already used in the latest version of dicom-findscu in order to let the user specify more complex queries (#326)

jmlaka commented 1 year ago

Hello,

As I am using dicom-rs for FindScu and FindSCP myself, I will contribute this part of higher level API in the future.

Unfortunately, contributing a piece of good code takes much more time than baking together some thing that works for my private project. So it might take some time.

The FindScu client is almost ready.

Juraj Mláka

Dňa pi 2. 6. 2023, 13:28 Eduardo Pinho @.***> napísal(a):

Thank you for your well informed feedback, @qarmin https://github.com/qarmin! I can comment on the two points in particular, but the short version is that I not only agree that the library APIs can be extended with better abstractions for building high level DICOM software, it is also in my plans to have them in the project.

  • dicom-findscu currently only exists as a command line tool, but it definitely makes sense for it to also incorporate a library. dicom-dump went through the process of starting out only as a tool, and now it is also a library (that is even used in findscu!). One of the reasons for this is that such a library would depend on the constructs for building full-fleshed SCUs and SCPs, which are still in their infancy.
  • A good portion of the code bloat found in the tool is due to having to work with lower level abstractions. Creating a DICOM object representing the command needs to be done manually (including the command group length, which admittedly is an error-prone process) and encoded into a PDU, so that it can be sent through the client association. This appears to have been better streamlined in Pynetdicom, which already offers common presentation contexts by name and a function to turn command-line arguments into data sets. Not having to wait for the aforementioned abstractions for creating DICOM network application entities meant that the project could have a proof of concept sooner, and from which further work and design decisions could be made. With that said, a better direction for developers to embed SCUs in their own software should indeed be made moving forward.

This does not quite have to do with the lack of modularity in the project, but with missing pieces in these modules which need time and effort to develop. I have not had much of these two lately, and attracting contributors to close these tasks is one of the open challenges, but we will get there! I can try to split the feedback into separate issues in the meantime. See also the project roadmap https://github.com/Enet4/dicom-rs/wiki/Roadmap#networking-and-service-class-implementation .

— Reply to this email directly, view it on GitHub https://github.com/Enet4/dicom-rs/issues/352#issuecomment-1573583477, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARWGC3BXYRU7UT7S33HQRO3XJHE6NANCNFSM6AAAAAAYYEQCLA . You are receiving this because you are subscribed to this thread.Message ID: @.***>