code: def check_dicom_series_uid(dcm_phases, sort_instance=True):
      """Check if all dicom images have the same series UID.
  
      Args:
          dcm_phases (list): List of dicom dataset objects (phases)
          sort_instance (bool, optional): Whether sort images by InstanceNumber (i.e. phase number). Defaults to True.
  
      Returns:
          list: List of list(s) dicom phases.
      """
      series_ids = [dcm.SeriesInstanceUID for dcm in dcm_phases]
      unique_ids = np.unique(series_ids)
      if unique_ids.shape[0] > 1:
          dcms = {uid: [] for uid in unique_ids}
          for dcm in dcm_phases:
              dcms[dcm.SeriesInstanceUID].append(dcm)
          if sort_instance:
              for uid in dcms:
                  dcms[uid].sort(
                      key=lambda x: x.InstanceNumber, reverse=False
                  )
  
          dcms_out = []
          for uid in dcms:
              dcms_out.append(dcms[uid])
      else:
          dcms_out = [dcm_phases]
  
      return dcms_out
  
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 3 for calling a global function with example usage: check_dicom_series_uid(dcm_phases, sort_instance) and returns: dcms_out