code: def send_response(datastore, result, output, background_tasks):
      res_img = (
          result.get("file")
          if result.get("file")
          else result.get("label")
      )
      res_tag = result.get("tag")
      res_json = result.get("params")
  
      if res_img:
          if not os.path.exists(res_img):
              res_img = datastore.get_label_uri(res_img, res_tag)
          else:
              background_tasks.add_task(remove_file, res_img)
  
      if output == "json":
          return res_json
  
      m_type = get_mime_type(res_img)
  
      if output == "image":
          return FileResponse(
              res_img,
              media_type=m_type,
              filename=os.path.basename(res_img),
          )
  
      if output == "dicom_seg":
          res_dicom_seg = result.get("dicom_seg")
          if res_dicom_seg is None:
              raise HTTPException(
                  status_code=500, detail="Error processing inference"
              )
          else:
              return FileResponse(
                  res_dicom_seg,
                  media_type="application/dicom",
                  filename=os.path.basename(res_dicom_seg),
              )
  
      res_fields = dict()
      res_fields["params"] = (
          None,
          json.dumps(res_json),
          "application/json",
      )
      if res_img and os.path.exists(res_img):
          res_fields["image"] = (
              os.path.basename(res_img),
              open(res_img, "rb"),
              m_type,
          )
      else:
          logger.info(
              f"Return only Result Json as Result Image is not available: {res_img}"
          )
          return res_json
  
      return_message = MultipartEncoder(fields=res_fields)
      return Response(
          content=return_message.to_string(),
          media_type=return_message.content_type,
      )
  
imports: import json
  import logging
  import os
  import pathlib
  import shutil
  import tempfile
  from enum import Enum
  from typing import Optional
  from fastapi import APIRouter, Depends, File, Form, HTTPException, UploadFile
  from fastapi.background import BackgroundTasks
  from fastapi.responses import FileResponse, Response
  from requests_toolbelt import MultipartEncoder
  from monailabel.config import RBAC_USER, settings
  from monailabel.datastore.dicom import DICOMWebDatastore
  from monailabel.datastore.utils.convert import binary_to_image, nifti_to_dicom_seg
  from monailabel.endpoints.user.auth import RBAC, User
  from monailabel.interfaces.app import MONAILabelApp
  from monailabel.interfaces.utils.app import app_instance
  from monailabel.utils.others.generic import get_mime_type, remove_file
label_desc: Use image node_id 1 for calling a global function with example usage: send_response(datastore, result, output, background_tasks) and returns: Response, res_json, FileResponse, res_json, FileResponse