code: def dicom2arraylist(dicom_patient_list, return_patient_id=False):
      """Convert dicom datasets to arrays
  
      Args:
          dicom_patient_list (list): List of dicom patient lists.
          return_patient_id (bool, optional): Whether return PatientID. Defaults to False.
  
      Returns:
          list: list of array-like tensors.
          list (optional): list of PatientIDs.
      """
      n_samples = len(dicom_patient_list)
      image_list = (
          []
      )  # number of phases can be different across patients, using list to avoid the phase dimension issue
      patient_ids = []
      for i in range(n_samples):
          patient_ids.append(dicom_patient_list[i][0].PatientID)
          n_phases = len(dicom_patient_list[i])
          img_size = dicom_patient_list[i][0].pixel_array.shape
          img = np.zeros((n_phases,) + img_size)
          for j in range(n_phases):
              img[j, ...] = dicom_patient_list[i][j].pixel_array
          image_list.append(img)
      if return_patient_id:
          return image_list, patient_ids
      else:
          return image_list
  
imports: import glob
  import logging
  import os
  from enum import Enum
  import numpy
  import pydicom
  import torch
  from torchvision import datasets, transforms
  from kale.loaddata.dataset_access import DatasetAccess
  from kale.loaddata.mnistm import MNISTM
  from kale.loaddata.multi_domain import MultiDomainAccess, MultiDomainImageFolder
  from kale.loaddata.usps import USPS
  from kale.prepdata.image_transform import get_transform
  from kale.utils.download import download_file_by_url
label_desc: Use image node_id 5 for calling a global function with example usage: dicom2arraylist(dicom_patient_list, return_patient_id) and returns: image_list,  patient_ids, image_list