Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFE] Allow to pass file like object #26

Open
rpitonak opened this issue Sep 4, 2022 · 3 comments
Open

[RFE] Allow to pass file like object #26

rpitonak opened this issue Sep 4, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@rpitonak
Copy link

rpitonak commented Sep 4, 2022

Hello,

First of all, great work with the package, it is really helpful. I have a suggestion for improvement. When working with remote storage, using for example RaRe-Technologies/smart_open, or when you accept Dicom in a web application through the form, you may have the file(s) already in some variable, and to store them on the disk and pass the path may be a bit cumbersome.

pydicom is able to work with file-like object and does not need a file path, e.g

import pydicom
source_dcm = pydicom.dcmread(io.BytesIO(data.getvalue()))

It would be nice to have pdf2dcm API ready for such case. First shot at how it could look like

from pdf2dcm import Pdf2EncapsDCM
converter = Pdf2EncapsDCM()
encapsulated_pdf = converter.run(
    pdf=io.BytesIO(b"My pdf"), template_dcm=pydicom.dcmread(io.BytesIO(data.getvalue()), return_ds=True)
)

return_ds would prevent the file from being saved on the disk and it would return pydicom Dataset because sometimes you want to, for example, save some metadata to the database and you need to read the file repeatedly. Also, template_dcm could accept pydicom Dataset as well.

I would be glad for your feedback on these suggestions and I am willing to open the PR afterward. Of course, I will understand if this functionality is out of the scope of this package, but I think more people could benefit from it.

I am looking forward to your response!

Rado.

@a-parida12 a-parida12 added the enhancement New feature or request label Sep 4, 2022
@a-parida12
Copy link
Owner

Hi @rpitonak!

Thanks for your interest in the project and for suggesting changes to improve the current API. I feel it is a good feature to have.

In terms of the implementation maybe when initiating the class you could specify the output as a stream converter = Pdf2EncapsDCM(return_stream=True) and then you could modify the store function to return the stream. Check

def _store_ds(store_path: Path, ds: FileDataset) -> Path:

Let's focus on the Pdf2EncapsDCM as it may be easier than the Secondary Capture one. What do you think?

Looking forward to a PR from you.

@rpitonak
Copy link
Author

rpitonak commented Sep 5, 2022

Hello @a-parida12,

Thanks for pointing me to the store function, makes sense to do that modification.

Let's focus on the Pdf2EncapsDCM as it may be easier than the Secondary Capture one. What do you think?

Agreed

I will open the PR soon.

@a-parida12
Copy link
Owner

@rpitonak did you get a chance to look at the feature request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants