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

ENH: Added DICOMUtils convenience function library #421

Closed
wants to merge 1 commit into from

Conversation

cpinter
Copy link
Member

@cpinter cpinter commented Nov 24, 2015

Usage:
import DICOMLib
DICOMLib.DICOMUtils.loadPatientByName('SamplePatient')

# Get patient UID by patient name for easy loading of a patient
def patientUIDByPatientName(name):
if not hasattr(slicer,'dicomDatabase'):
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should an error or warning be logged ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, one sec.

@cpinter
Copy link
Member Author

cpinter commented Nov 24, 2015

I added a DICOM utility library to make it easier to do DICOM DB operations from python.

  • patientUIDByPatientName, loadPatientByUID, and loadPatientByName facilitate easy loading of DICOM patients with one-liner python calls.
  • openTemporaryDatabase and openDatabase can be used by self tests that download and import their own test data to easily switch to a temporary database and use that for the test, after which it can restore the original database (returned by openTemporaryDatabase). I haven't yet updated the core tests, but some of them can use these, such as JRC2013Vis, RSNAVisTutorial and SubjectHierarchyGenericSelfTest

def openDatabase(databaseDir):
if not hasattr(slicer,'dicomDatabase') or not hasattr(slicer.modules,'dicom'):
logging.error('DICOM module or database cannot be accessed!')
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to return with a different value depending on if the database could be successfully opened or not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I fixed it before saw your comment :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. So it should check if opening was successful?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be nice if you could check if the opening was successfull, too.


#------------------------------------------------------------------------------
# Get patient UID by patient name for easy loading of a patient
def patientUIDByPatientName(name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name is not very clear for me. getPatientUIDByPatientName or patientUIDFromPatientName would be more clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small improvement possibility (probably not important for tests but could be useful for general use): In DICOM usually the patient name and patient ID are used together to identify a patient. It may be useful to add an optional patientID parameter that would allow to search for a specific patient name AND id.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will rename the function.

This file will be open to additional methods for all developers if the need arises.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, "patientUID" should be replaced with "patientID". There is no such thing as "patient UID" (unfortunately!).

@lassoan
Copy link
Contributor

lassoan commented Nov 24, 2015

Thanks Csaba, this will be useful. Last time when somebody wanted to merge utility python functions I insisted that the utilities should be used by the Slicer core modules wherever it is applicable to serve as an example and to not duplicate code (see Slicer/Slicer#407). So, I'm afraid I would need to ask you the same: please update the JRC2013Vis, RSNAVisTutorial and SubjectHierarchyGenericSelfTest tests as well.

@cpinter
Copy link
Member Author

cpinter commented Nov 24, 2015

I didn't do that in the hope of quick merge, as I don't think touching the RSNA tutorial is wise right now.

@lassoan
Copy link
Contributor

lassoan commented Nov 24, 2015

RSNA demo will use stable and nothing will be merged until layer this week, when a new release will be created for additional RSNA activities. So, there will be no impact on RSNA.

Using the utility functions in the tests will also serves as tests for these new utility functions (in addition to serve as examples and reduce code duplication).

@cpinter
Copy link
Member Author

cpinter commented Nov 24, 2015

I changed the python tests using temporary databases to call the new utility functions

Usage examples:
from DICOMLib import DICOMUtils
with DICOMUtils.TemporaryDICOMDatabase(folderName):
  [ Code here to import SamplePatient from local storage ]
  DICOMUtils.loadPatientByName('SamplePatient')
@cpinter
Copy link
Member Author

cpinter commented Nov 25, 2015

I added the context manager for temporary databases.

@cpinter cpinter removed the wip label Nov 30, 2015
@jcfr
Copy link
Member

jcfr commented Dec 1, 2015

@cpinter After return the database in the context manager. LGTM 👍

@cpinter
Copy link
Member Author

cpinter commented Dec 1, 2015

Did the requested change.
Integrated in https://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=24795
Thanks!

@cpinter cpinter closed this Dec 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants