code: def dicom_to_nifti(series_dir, is_seg=False):
      start = time.time()
  
      if is_seg:
          output_file = dicom_seg_to_itk_image(series_dir)
      else:
          # https://simpleitk.readthedocs.io/en/master/link_DicomConvert_docs.html
          if (
              os.path.isdir(series_dir)
              and len(os.listdir(series_dir)) > 1
          ):
              reader = SimpleITK.ImageSeriesReader()
              dicom_names = reader.GetGDCMSeriesFileNames(series_dir)
              reader.SetFileNames(dicom_names)
              image = reader.Execute()
          else:
              filename = (
                  series_dir
                  if not os.path.isdir(series_dir)
                  else os.path.join(
                      series_dir, os.listdir(series_dir)[0]
                  )
              )
  
              file_reader = SimpleITK.ImageFileReader()
              file_reader.SetImageIO("GDCMImageIO")
              file_reader.SetFileName(filename)
              image = file_reader.Execute()
  
          logger.info(f"Image size: {image.GetSize()}")
          output_file = tempfile.NamedTemporaryFile(
              suffix=".nii.gz"
          ).name
          SimpleITK.WriteImage(image, output_file)
  
      logger.info(
          f"dicom_to_nifti latency : {time.time() - start} (sec)"
      )
      return output_file
  
imports: import json
  import logging
  import os
  import pathlib
  import tempfile
  import time
  import numpy
  import pydicom
  import pydicom_seg
  import SimpleITK
  from monai.transforms import LoadImage
  from pydicom.filereader import dcmread
  from monailabel.datastore.utils.colors import GENERIC_ANATOMY_COLORS
  from monailabel.transform.writer import write_itk
  from monailabel.utils.others.generic import run_command
label_desc: Use image node_id 1 for calling a global function with example usage: dicom_to_nifti(series_dir, is_seg) and returns: output_file