# Load one patient onto screen

**URL:** https://discourse.slicer.org/t/load-one-patient-onto-screen/19319
**Category:** Support
**Created:** [August 23, 2021, 2:58pm UTC](https://discourse.slicer.org/t/load-one-patient-onto-screen/19319 "2021-08-23T14:58:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![alyssan](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alyssan](https://discourse.slicer.org/u/alyssan)
#### Post date: [August 23, 2021, 2:58pm UTC](https://discourse.slicer.org/t/load-one-patient-onto-screen/19319/1 "2021-08-23T14:58:51Z")

</div>

Hello, I have a folder of dicom files but would like to automatically load on patient onto the screen every time.

I have loaded my dicom files into the DICOM database using this code:

```python
dicomDataDir = "c:/my/folder/with/dicom-files" # input folder with DICOM files
loadedNodeIDs = [] # this list will contain the list of all loaded node IDs

from DICOMLib import DICOMUtils
with DICOMUtils.TemporaryDICOMDatabase() as db:
  DICOMUtils.importDicom(dicomDataDir, db)
  patientUIDs = db.patients()
  for patientUID in patientUIDs:
    loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))

```

How do I automatically access one patient and load it, do I have to use the patient uid and how do i find this?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [August 23, 2021, 4:09pm UTC](https://discourse.slicer.org/t/load-one-patient-onto-screen/19319/2 "2021-08-23T16:09:24Z")

</div>

If you just want to load the first patient then replace the last two lines by

```python
loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUIDs[0]))

```

---

<div class="post-metadata">

### Author: ![alyssan](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alyssan](https://discourse.slicer.org/u/alyssan)
#### Post date: [August 24, 2021, 1:36pm UTC](https://discourse.slicer.org/t/load-one-patient-onto-screen/19319/3 "2021-08-24T13:36:56Z")

</div>

Thank you this seems to be working I appreciate your help.  
I have a script set up but it was using sample data.

#Load Data  
import SampleData  
sampleDataLogic = SampleData.SampleDataLogic()  
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1()  
n = getNode(‘MRBrainTumor1’)

The masterVolumeNode variable is important and called in future code, how would I set this using my new data from dicom folder?

Thank you

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [August 24, 2021, 1:59pm UTC](https://discourse.slicer.org/t/load-one-patient-onto-screen/19319/4 "2021-08-24T13:59:41Z")

</div>

In the example above, `loadedNodeIDs` contain the IDs of the loaded nodes. For example, you can get the first node object (for example, it can be a volume node) by calling:

```python
n = slicer.mrmlScene.GetNodeByID(loadedNodeIDs[0])

```

---

<div class="post-metadata">

### Author: ![alyssan](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alyssan](https://discourse.slicer.org/u/alyssan)
#### Post date: [August 24, 2021, 3:44pm UTC](https://discourse.slicer.org/t/load-one-patient-onto-screen/19319/5 "2021-08-24T15:44:56Z")

</div>

Okay, I have tried it out.

masterVolumeNode = slicer.mrmlScene.GetNodeByID(loadedNodeIDs[0])

I am using this for segmentation and get the error “Master Volume Node is not set as either background or foreground”

Any ideas on how to fix this?

---

<div class="post-metadata">

### Author: ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)
#### Post date: [August 24, 2021, 4:27pm UTC](https://discourse.slicer.org/t/load-one-patient-onto-screen/19319/6 "2021-08-24T16:27:35Z")

</div>

> [@alyssan](#):
>
> I am using this for segmentation

What exactly is it you want to do? Please give more details …

---

<div class="post-metadata">

### Author: ![alyssan](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alyssan](https://discourse.slicer.org/u/alyssan)
#### Post date: [August 25, 2021, 4:41pm UTC](https://discourse.slicer.org/t/load-one-patient-onto-screen/19319/7 "2021-08-25T16:41:32Z")

</div>

I am following an example like this one:

> <https://gist.github.com/lassoan/1673b25d8e7913cbc245b4f09ed853f9>

I was asking how to define masterVolumeNode from loaded data from folder on my computer.

When I implemented:

masterVolumeNode = slicer.mrmlScene.GetNodeByID(loadedNodeIDs[0])

It said that masterVolume Node is not set as either the background or foreground
