code: def _update_file(c, path, fname, studies, series, storage_instances):
      try:
          do = pydicom.dcmread(f"{path}/{fname}")
      except pydicom.filereader.InvalidDicomError:
          logger.debug("        not a DICOM file")
          return None
      try:
          study_comments = do.StudyComments
      except AttributeError:
          study_comments = ""
      try:
          logger.debug(f"        storage instance {do.SOPInstanceUID}")
          if str(do.StudyInstanceUID) not in studies:
              query = """INSERT INTO study (uid,
                                            date,
                                            time,
                                            comments,
                                            patient_name,
                                            patient_id,
                                            patient_birth_date,
                                            patient_sex)
                         VALUES (?, ?, ?, ?, ?, ?, ?, ?)"""
              params = (
                  str(do.StudyInstanceUID),
                  do.StudyDate,
                  do.StudyTime,
                  study_comments,
                  str(do.PatientName),
                  do.PatientID,
                  do.PatientBirthDate,
                  do.PatientSex,
              )
              c.execute(query, params)
              studies.append(str(do.StudyInstanceUID))
          if str(do.SeriesInstanceUID) not in series:
              query = """INSERT INTO series (uid,
                                             study,
                                             number,
                                             description,
                                             rows,
                                             columns,
                                             bits_allocated,
                                             bits_stored)
                         VALUES (?, ?, ?, ?, ?, ?, ?, ?)"""
              params = (
                  str(do.SeriesInstanceUID),
                  str(do.StudyInstanceUID),
                  do.SeriesNumber,
                  do.SeriesDescription,
                  do.Rows,
                  do.Columns,
                  do.BitsAllocated,
                  do.BitsStored,
              )
              c.execute(query, params)
              series.append(str(do.SeriesInstanceUID))
          if str(do.SOPInstanceUID) not in storage_instances:
              query = """INSERT INTO storage_instance (uid, instance_number, series)
                         VALUES (?, ?, ?)"""
              params = (
                  str(do.SOPInstanceUID),
                  do.InstanceNumber,
                  str(do.SeriesInstanceUID),
              )
              c.execute(query, params)
              storage_instances.append(str(do.SOPInstanceUID))
      except AttributeError as data:
          logger.debug(f"        {data}")
          return None
      return str(do.SOPInstanceUID)
  
imports: import contextlib
  import getpass
  import logging
  import os
  import sqlite3
  import tempfile
  import warnings
  from io import BytesIO
  from os.path import join
  import numpy
  from nibabel.optpkg import optional_package
  from .nifti1 import Nifti1Header
label_desc: Use image node_id 5 for calling a global function with example usage: _update_file(c, path, fname, studies, series, storage_instances) and returns: str, None, None