function formatMetadata (metadata) {
  const loadJSONDataset = (elements) => {
    const dataset = {}
    Object.keys(elements).forEach(tag => {
      const keyword = tagToKeyword[tag]
      const vr = elements[tag].vr
      if ('BulkDataURI' in elements[tag]) {
        console.debug(`skip bulk data element "${keyword}"`)
      } else if ('Value' in elements[tag]) {
        const value = elements[tag].Value
        if (vr === 'SQ') {
          dataset[keyword] = value.map(item => loadJSONDataset(item))
        } else {
          // Handle value multiplicity.
          if (value.length === 1) {
            if (vr === 'DS' || vr === 'IS') {
              dataset[keyword] = Number(value[0])
            } else {
              dataset[keyword] = value[0]
            }
          } else {
            if (vr === 'DS' || vr === 'IS') {
              dataset[keyword] = value.map(v => Number(v))
            } else {
              dataset[keyword] = value
            }
          }
        }
      } else {
        if (vr === 'SQ') {
          dataset[keyword] = []
        } else {
          dataset[keyword] = null
        }
      }
    })
    return dataset
  }

  const dataset = loadJSONDataset(metadata)

  // The top level (lowest resolution) image may be a single frame image in
  // which case the "NumberOfFrames" attribute is optional. We include it for
  // consistency.
  if (dataset === undefined) {
    throw new Error('Could not format metadata: ', metadata)
  }
  if (!('NumberOfFrames' in dataset) && (dataset.Modality === 'SM')) {
    dataset.NumberOfFrames = 1
  }

  return dataset
}
/** Formats DICOM metadata structured according to the DICOM JSON model into a
 * more human friendly representation, where values of data elements can be
 * directly accessed via their keyword (e.g., "SOPInstanceUID").
 * Bulkdata elements will be skipped.
 *
 * @param {Object} Metadata structured according to the DICOM JSON model
 * @returns {Object} Formatted metadata
 * @memberof metadata
 */
Formats DICOM metadata structured according to the DICOM JSON model into a
more human friendly representation, where values of data elements can be
directly accessed via their keyword .
Bulkdata elements will be skipped.

@param {Object} Metadata structured according to the DICOM JSON model
@returns {Object} Formatted metadata
@memberof metadata
Formats DICOM metadata structured according to the DICOM JSON model into a more human friendly representation where values of data elements can be directly accessed via their keyword . Bulkdata elements will be skipped . @param { Object } Metadata structured according to the DICOM JSON model @returns { Object } Formatted metadata @memberof metadata
function formatMetadata (metadata) {
  const loadJSONDataset = (elements) => {
    const dataset = {}
    Object.keys(elements).forEach(tag => {
      const keyword = tagToKeyword[tag]
      const vr = elements[tag].vr
      if ('BulkDataURI' in elements[tag]) {
        console.debug(`skip bulk data element "${keyword}"`)
      } else if ('Value' in elements[tag]) {
        const value = elements[tag].Value
        if (vr === 'SQ') {
          dataset[keyword] = value.map(item => loadJSONDataset(item))
        } else {
          if (value.length === 1) {
            if (vr === 'DS' || vr === 'IS') {
              dataset[keyword] = Number(value[0])
            } else {
              dataset[keyword] = value[0]
            }
          } else {
            if (vr === 'DS' || vr === 'IS') {
              dataset[keyword] = value.map(v => Number(v))
            } else {
              dataset[keyword] = value
            }
          }
        }
      } else {
        if (vr === 'SQ') {
          dataset[keyword] = []
        } else {
          dataset[keyword] = null
        }
      }
    })
    return dataset
  }
  const dataset = loadJSONDataset(metadata)
  if (dataset === undefined) {
    throw new Error('Could not format metadata: ', metadata)
  }
  if (!('NumberOfFrames' in dataset) && (dataset.Modality === 'SM')) {
    dataset.NumberOfFrames = 1
  }
  return dataset
}
function formatMetadata ( metadata ) { const loadJSONDataset = ( elements ) => { const dataset = { } Object . keys ( elements ) . forEach ( tag => { const keyword = tagToKeyword [ tag ] const vr = elements [ tag ] . vr if ( 'BulkDataURI' in elements [ tag ] ) { console . debug ( ` ${ keyword } ` ) } else if ( 'Value' in elements [ tag ] ) { const value = elements [ tag ] . Value if ( vr === 'SQ' ) { dataset [ keyword ] = value . map ( item => loadJSONDataset ( item ) ) } else { if ( value . length === 1 ) { if ( vr === 'DS' || vr === 'IS' ) { dataset [ keyword ] = Number ( value [ 0 ] ) } else { dataset [ keyword ] = value [ 0 ] } } else { if ( vr === 'DS' || vr === 'IS' ) { dataset [ keyword ] = value . map ( v => Number ( v ) ) } else { dataset [ keyword ] = value } } } } else { if ( vr === 'SQ' ) { dataset [ keyword ] = [ ] } else { dataset [ keyword ] = null } } } ) return dataset } const dataset = loadJSONDataset ( metadata ) if ( dataset === undefined ) { throw new Error ( 'Could not format metadata: ' , metadata ) } if ( ! ( 'NumberOfFrames' in dataset ) && ( dataset . Modality === 'SM' ) ) { dataset . NumberOfFrames = 1 } return dataset }
Formats DICOM metadata structured according to the DICOM JSON model into a
 more human friendly representation, where values of data elements can be
 directly accessed via their keyword (e.g., "SOPInstanceUID").
Formats DICOM metadata structured according to the DICOM JSON model into a more human friendly representation where values of data elements can be directly accessed via their keyword ( e . g . " SOPInstanceUID " ) .
// Handle value multiplicity. // The top level (lowest resolution) image may be a single frame image in // which case the "NumberOfFrames" attribute is optional. We include it for // consistency.