{"action":"created","comment":{"url":"https://api.github.com/repos/Slicer/Slicer/pulls/comments/45757438","id":45757438,"diff_hunk":"@@ -0,0 +1,96 @@\n+import os\n+import vtk, qt, ctk, slicer\n+import logging\n+\n+#########################################################\n+#\n+#\n+comment = \"\"\"\n+\n+  DICOMUtils is a collection of static-like DICOM\n+  utility functions facilitating convenient scripted\n+  use of the DICOM database\n+\n+\"\"\"\n+#\n+######################################################### \n+\n+#------------------------------------------------------------------------------\n+# Get patient UID by patient name for easy loading of a patient\n+def patientUIDByPatientName(name):\n+  if not hasattr(slicer,'dicomDatabase'):\n+    logging.error('DICOM database cannot be accessed!')\n+    return None\n+  patients = slicer.dicomDatabase.patients()\n+  for patientUID in patients:\n+    currentName = slicer.dicomDatabase.nameForPatient(patientUID)\n+    if currentName == name:\n+      return patientUID\n+  return None\n+\n+#------------------------------------------------------------------------------\n+# Load patient by patient UID from DICOM database\n+def loadPatientByUID(patientUID):\n+  if not hasattr(slicer,'dicomDatabase') or not hasattr(slicer.modules,'dicom'):\n+    logging.error('DICOM module or database cannot be accessed!')\n+    return\n+  dicomWidget = slicer.modules.dicom.widgetRepresentation().self()\n+\n+  # Select all series in selected patient\n+  studies = slicer.dicomDatabase.studiesForPatient(patientUID)\n+  series = [slicer.dicomDatabase.seriesForStudy(study) for study in studies]\n+  seriesUIDs = [uid for uidList in series for uid in uidList]\n+  dicomWidget.detailsPopup.offerLoadables(seriesUIDs, 'SeriesUIDList')\n+  dicomWidget.detailsPopup.examineForLoading()\n+\n+  # Load selected data\n+  dicomWidget.detailsPopup.loadCheckedLoadables()\n+\n+#------------------------------------------------------------------------------\n+# Load patient by patient name from DICOM database\n+def loadPatientByName(patientName):\n+  loadPatientByUID(patientUIDByPatientName(patientName))\n+\n+#------------------------------------------------------------------------------\n+# Open specified DICOM database\n+def openDatabase(databaseDir):\n+  if not hasattr(slicer,'dicomDatabase') or not hasattr(slicer.modules,'dicom'):\n+    logging.error('DICOM module or database cannot be accessed!')\n+    return\n+  if not os.access(databaseDir, os.F_OK):\n+    logging.error('Specified database directory ' + repr(databaseDir) + ' cannot be found!')\n+    return\n+  dicomWidget = slicer.modules.dicom.widgetRepresentation().self()\n+  dicomWidget.onDatabaseDirectoryChanged(databaseDir)\n+  if not slicer.dicomDatabase.isOpen:\n+    logging.error('Unable to open DICOM database ' + databaseDir)\n+\n+#------------------------------------------------------------------------------\n+# Open temporary DICOM database, return current database directory\n+def openTemporaryDatabase(folderName=None):","path":"Modules/Scripted/DICOMLib/DICOMUtils.py","position":70,"original_position":70,"commit_id":"06fddae7f5a2af37ff65608502f8a3456e7b7598","original_commit_id":"048db2cf22ce3a298982a5c034231a489547af47","user":{"login":"lassoan","id":307929,"avatar_url":"https://avatars.githubusercontent.com/u/307929?v=3","gravatar_id":"","url":"https://api.github.com/users/lassoan","html_url":"https://github.com/lassoan","followers_url":"https://api.github.com/users/lassoan/followers","following_url":"https://api.github.com/users/lassoan/following{/other_user}","gists_url":"https://api.github.com/users/lassoan/gists{/gist_id}","starred_url":"https://api.github.com/users/lassoan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lassoan/subscriptions","organizations_url":"https://api.github.com/users/lassoan/orgs","repos_url":"https://api.github.com/users/lassoan/repos","events_url":"https://api.github.com/users/lassoan/events{/privacy}","received_events_url":"https://api.github.com/users/lassoan/received_events","type":"User","site_admin":false},"body":"What happens to the temporary database after it is no longer needed?\r\nIt could be nice to have a closeTemporaryDatabase(originalDatabaseFolderName, cleanup=True) method that can delete the temporary database and restore the original database.\r\noriginalDatabaseFolder = openTemporaryDatabase()\r\n...\r\ncloseTemporaryDatabase(originalDatabaseFolder)","created_at":"2015-11-24T16:22:04Z","updated_at":"2015-11-24T16:22:04Z","html_url":"https://github.com/Slicer/Slicer/pull/421#discussion_r45757438","pull_request_url":"https://api.github.com/repos/Slicer/Slicer/pulls/421","_links":{"self":{"href":"https://api.github.com/repos/Slicer/Slicer/pulls/comments/45757438"},"html":{"href":"https://github.com/Slicer/Slicer/pull/421#discussion_r45757438"},"pull_request":{"href":"https://api.github.com/repos/Slicer/Slicer/pulls/421"}}},"pull_request":{"url":"https://api.github.com/repos/Slicer/Slicer/pulls/421","id":51677468,"html_url":"https://github.com/Slicer/Slicer/pull/421","diff_url":"https://github.com/Slicer/Slicer/pull/421.diff","patch_url":"https://github.com/Slicer/Slicer/pull/421.patch","issue_url":"https://api.github.com/repos/Slicer/Slicer/issues/421","number":421,"state":"open","locked":false,"title":"ENH: Added DICOMUtils convenience function library","user":{"login":"cpinter","id":1325980,"avatar_url":"https://avatars.githubusercontent.com/u/1325980?v=3","gravatar_id":"","url":"https://api.github.com/users/cpinter","html_url":"https://github.com/cpinter","followers_url":"https://api.github.com/users/cpinter/followers","following_url":"https://api.github.com/users/cpinter/following{/other_user}","gists_url":"https://api.github.com/users/cpinter/gists{/gist_id}","starred_url":"https://api.github.com/users/cpinter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpinter/subscriptions","organizations_url":"https://api.github.com/users/cpinter/orgs","repos_url":"https://api.github.com/users/cpinter/repos","events_url":"https://api.github.com/users/cpinter/events{/privacy}","received_events_url":"https://api.github.com/users/cpinter/received_events","type":"User","site_admin":false},"body":"Usage:\r\nimport DICOMLib\r\nDICOMLib.DICOMUtils.loadPatientByName('SamplePatient')","created_at":"2015-11-24T15:53:35Z","updated_at":"2015-11-24T16:22:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5631a55a90bb6b207d424f49cc375b0e81a64bf1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Slicer/Slicer/pulls/421/commits","review_comments_url":"https://api.github.com/repos/Slicer/Slicer/pulls/421/comments","review_comment_url":"https://api.github.com/repos/Slicer/Slicer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Slicer/Slicer/issues/421/comments","statuses_url":"https://api.github.com/repos/Slicer/Slicer/statuses/06fddae7f5a2af37ff65608502f8a3456e7b7598","head":{"label":"cpinter:dicom-python-utils","ref":"dicom-python-utils","sha":"06fddae7f5a2af37ff65608502f8a3456e7b7598","user":{"login":"cpinter","id":1325980,"avatar_url":"https://avatars.githubusercontent.com/u/1325980?v=3","gravatar_id":"","url":"https://api.github.com/users/cpinter","html_url":"https://github.com/cpinter","followers_url":"https://api.github.com/users/cpinter/followers","following_url":"https://api.github.com/users/cpinter/following{/other_user}","gists_url":"https://api.github.com/users/cpinter/gists{/gist_id}","starred_url":"https://api.github.com/users/cpinter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpinter/subscriptions","organizations_url":"https://api.github.com/users/cpinter/orgs","repos_url":"https://api.github.com/users/cpinter/repos","events_url":"https://api.github.com/users/cpinter/events{/privacy}","received_events_url":"https://api.github.com/users/cpinter/received_events","type":"User","site_admin":false},"repo":{"id":14346962,"name":"Slicer","full_name":"cpinter/Slicer","owner":{"login":"cpinter","id":1325980,"avatar_url":"https://avatars.githubusercontent.com/u/1325980?v=3","gravatar_id":"","url":"https://api.github.com/users/cpinter","html_url":"https://github.com/cpinter","followers_url":"https://api.github.com/users/cpinter/followers","following_url":"https://api.github.com/users/cpinter/following{/other_user}","gists_url":"https://api.github.com/users/cpinter/gists{/gist_id}","starred_url":"https://api.github.com/users/cpinter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpinter/subscriptions","organizations_url":"https://api.github.com/users/cpinter/orgs","repos_url":"https://api.github.com/users/cpinter/repos","events_url":"https://api.github.com/users/cpinter/events{/privacy}","received_events_url":"https://api.github.com/users/cpinter/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cpinter/Slicer","description":"Multi-platform, free open source software for visualization and image computing.","fork":true,"url":"https://api.github.com/repos/cpinter/Slicer","forks_url":"https://api.github.com/repos/cpinter/Slicer/forks","keys_url":"https://api.github.com/repos/cpinter/Slicer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cpinter/Slicer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cpinter/Slicer/teams","hooks_url":"https://api.github.com/repos/cpinter/Slicer/hooks","issue_events_url":"https://api.github.com/repos/cpinter/Slicer/issues/events{/number}","events_url":"https://api.github.com/repos/cpinter/Slicer/events","assignees_url":"https://api.github.com/repos/cpinter/Slicer/assignees{/user}","branches_url":"https://api.github.com/repos/cpinter/Slicer/branches{/branch}","tags_url":"https://api.github.com/repos/cpinter/Slicer/tags","blobs_url":"https://api.github.com/repos/cpinter/Slicer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cpinter/Slicer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cpinter/Slicer/git/refs{/sha}","trees_url":"https://api.github.com/repos/cpinter/Slicer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cpinter/Slicer/statuses/{sha}","languages_url":"https://api.github.com/repos/cpinter/Slicer/languages","stargazers_url":"https://api.github.com/repos/cpinter/Slicer/stargazers","contributors_url":"https://api.github.com/repos/cpinter/Slicer/contributors","subscribers_url":"https://api.github.com/repos/cpinter/Slicer/subscribers","subscription_url":"https://api.github.com/repos/cpinter/Slicer/subscription","commits_url":"https://api.github.com/repos/cpinter/Slicer/commits{/sha}","git_commits_url":"https://api.github.com/repos/cpinter/Slicer/git/commits{/sha}","comments_url":"https://api.github.com/repos/cpinter/Slicer/comments{/number}","issue_comment_url":"https://api.github.com/repos/cpinter/Slicer/issues/comments{/number}","contents_url":"https://api.github.com/repos/cpinter/Slicer/contents/{+path}","compare_url":"https://api.github.com/repos/cpinter/Slicer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cpinter/Slicer/merges","archive_url":"https://api.github.com/repos/cpinter/Slicer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cpinter/Slicer/downloads","issues_url":"https://api.github.com/repos/cpinter/Slicer/issues{/number}","pulls_url":"https://api.github.com/repos/cpinter/Slicer/pulls{/number}","milestones_url":"https://api.github.com/repos/cpinter/Slicer/milestones{/number}","notifications_url":"https://api.github.com/repos/cpinter/Slicer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cpinter/Slicer/labels{/name}","releases_url":"https://api.github.com/repos/cpinter/Slicer/releases{/id}","created_at":"2013-11-12T22:24:59Z","updated_at":"2015-02-27T16:08:09Z","pushed_at":"2015-11-24T16:10:39Z","git_url":"git://github.com/cpinter/Slicer.git","ssh_url":"git@github.com:cpinter/Slicer.git","clone_url":"https://github.com/cpinter/Slicer.git","svn_url":"https://github.com/cpinter/Slicer","homepage":"www.slicer.org","size":425325,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Slicer:master","ref":"master","sha":"670f0a7a12e632ac0924477aa78bc4953f25c3c7","user":{"login":"Slicer","id":324362,"avatar_url":"https://avatars.githubusercontent.com/u/324362?v=3","gravatar_id":"","url":"https://api.github.com/users/Slicer","html_url":"https://github.com/Slicer","followers_url":"https://api.github.com/users/Slicer/followers","following_url":"https://api.github.com/users/Slicer/following{/other_user}","gists_url":"https://api.github.com/users/Slicer/gists{/gist_id}","starred_url":"https://api.github.com/users/Slicer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Slicer/subscriptions","organizations_url":"https://api.github.com/users/Slicer/orgs","repos_url":"https://api.github.com/users/Slicer/repos","events_url":"https://api.github.com/users/Slicer/events{/privacy}","received_events_url":"https://api.github.com/users/Slicer/received_events","type":"Organization","site_admin":false},"repo":{"id":2006302,"name":"Slicer","full_name":"Slicer/Slicer","owner":{"login":"Slicer","id":324362,"avatar_url":"https://avatars.githubusercontent.com/u/324362?v=3","gravatar_id":"","url":"https://api.github.com/users/Slicer","html_url":"https://github.com/Slicer","followers_url":"https://api.github.com/users/Slicer/followers","following_url":"https://api.github.com/users/Slicer/following{/other_user}","gists_url":"https://api.github.com/users/Slicer/gists{/gist_id}","starred_url":"https://api.github.com/users/Slicer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Slicer/subscriptions","organizations_url":"https://api.github.com/users/Slicer/orgs","repos_url":"https://api.github.com/users/Slicer/repos","events_url":"https://api.github.com/users/Slicer/events{/privacy}","received_events_url":"https://api.github.com/users/Slicer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Slicer/Slicer","description":"Multi-platform, free open source software for visualization and image computing.","fork":false,"url":"https://api.github.com/repos/Slicer/Slicer","forks_url":"https://api.github.com/repos/Slicer/Slicer/forks","keys_url":"https://api.github.com/repos/Slicer/Slicer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Slicer/Slicer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Slicer/Slicer/teams","hooks_url":"https://api.github.com/repos/Slicer/Slicer/hooks","issue_events_url":"https://api.github.com/repos/Slicer/Slicer/issues/events{/number}","events_url":"https://api.github.com/repos/Slicer/Slicer/events","assignees_url":"https://api.github.com/repos/Slicer/Slicer/assignees{/user}","branches_url":"https://api.github.com/repos/Slicer/Slicer/branches{/branch}","tags_url":"https://api.github.com/repos/Slicer/Slicer/tags","blobs_url":"https://api.github.com/repos/Slicer/Slicer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Slicer/Slicer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Slicer/Slicer/git/refs{/sha}","trees_url":"https://api.github.com/repos/Slicer/Slicer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Slicer/Slicer/statuses/{sha}","languages_url":"https://api.github.com/repos/Slicer/Slicer/languages","stargazers_url":"https://api.github.com/repos/Slicer/Slicer/stargazers","contributors_url":"https://api.github.com/repos/Slicer/Slicer/contributors","subscribers_url":"https://api.github.com/repos/Slicer/Slicer/subscribers","subscription_url":"https://api.github.com/repos/Slicer/Slicer/subscription","commits_url":"https://api.github.com/repos/Slicer/Slicer/commits{/sha}","git_commits_url":"https://api.github.com/repos/Slicer/Slicer/git/commits{/sha}","comments_url":"https://api.github.com/repos/Slicer/Slicer/comments{/number}","issue_comment_url":"https://api.github.com/repos/Slicer/Slicer/issues/comments{/number}","contents_url":"https://api.github.com/repos/Slicer/Slicer/contents/{+path}","compare_url":"https://api.github.com/repos/Slicer/Slicer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Slicer/Slicer/merges","archive_url":"https://api.github.com/repos/Slicer/Slicer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Slicer/Slicer/downloads","issues_url":"https://api.github.com/repos/Slicer/Slicer/issues{/number}","pulls_url":"https://api.github.com/repos/Slicer/Slicer/pulls{/number}","milestones_url":"https://api.github.com/repos/Slicer/Slicer/milestones{/number}","notifications_url":"https://api.github.com/repos/Slicer/Slicer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Slicer/Slicer/labels{/name}","releases_url":"https://api.github.com/repos/Slicer/Slicer/releases{/id}","created_at":"2011-07-06T12:27:18Z","updated_at":"2015-11-24T11:31:33Z","pushed_at":"2015-11-24T16:10:39Z","git_url":"git://github.com/Slicer/Slicer.git","ssh_url":"git@github.com:Slicer/Slicer.git","clone_url":"https://github.com/Slicer/Slicer.git","svn_url":"https://github.com/Slicer/Slicer","homepage":"www.slicer.org","size":427403,"stargazers_count":178,"watchers_count":178,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":212,"mirror_url":null,"open_issues_count":15,"forks":212,"open_issues":15,"watchers":178,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Slicer/Slicer/pulls/421"},"html":{"href":"https://github.com/Slicer/Slicer/pull/421"},"issue":{"href":"https://api.github.com/repos/Slicer/Slicer/issues/421"},"comments":{"href":"https://api.github.com/repos/Slicer/Slicer/issues/421/comments"},"review_comments":{"href":"https://api.github.com/repos/Slicer/Slicer/pulls/421/comments"},"review_comment":{"href":"https://api.github.com/repos/Slicer/Slicer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Slicer/Slicer/pulls/421/commits"},"statuses":{"href":"https://api.github.com/repos/Slicer/Slicer/statuses/06fddae7f5a2af37ff65608502f8a3456e7b7598"}}}}