All files / extensions/default/src/customizations thumbnailDetailsCustomization.ts

84.61% Statements 11/13
70% Branches 7/10
83.33% Functions 5/6
84.61% Lines 11/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92    205x                       205x 25133x     25133x                           5x 5x     5x 5x                   205x   9x                                                                           25133x        
import { utils } from '@ohif/core';
 
const { getLatestInstanceDateTime } = utils;
 
/**
 * Named sources for the study browser thumbnail detail items, so an item can
 * say where to get its value from without supplying a function - which is what
 * lets the whole thing be declared as data in a `?customization=` JSONC file.
 *
 * An item may name one of these as `source`, or supply its own `contentF`.
 *
 * Add to this with `$merge`: a `$set` replaces the registry, which takes away
 * the sources the default items name.
 */
export const thumbnailDetailSources = {
  seriesNumber: ({ displaySet }) => displaySet?.SeriesNumber,
 
  numInstances: ({ displaySet }) =>
    (displaySet?.numImageFrames ?? displaySet?.instances?.length) || 1,
 
  seriesDate: ({ displaySet, formatters }) => formatters.formatDate(displaySet?.SeriesDate),
 
  /**
   * When the display set was created, which is the date/time the series list is
   * sorted by - see `getLatestInstanceDateTime`.  Without this on the thumbnail, several
   * reports or segmentations saved on the same day all read as the same date and
   * their order looks arbitrary.
   *
   * Nothing below minutes is shown: the second a report was written says nothing
   * a reader can use, and it is not reliably recorded either.
   */
  instanceDateTime: ({ displaySet, instance, formatters }) => {
    const { SeriesDate, SeriesTime } = getLatestInstanceDateTime(instance ?? displaySet);
    Iif (!SeriesDate) {
      return '';
    }
    const date = formatters.formatDate(SeriesDate);
    return SeriesTime ? `${date} ${formatters.formatTime(SeriesTime, 'HH:mm')}` : date;
  },
};
 
/**
 * Named tests for the study browser thumbnail detail items, so an item can say
 * whether to include itself without supplying a function.
 *
 * An item may name one of these as `condition`, or supply its own function.
 */
export const thumbnailDetailTests = {
  /** SR, SEG, RTSTRUCT, PMAP and the other derived display sets. */
  isDerivedDisplaySet: ({ displaySet }) => !!displaySet?.isDerivedDisplaySet,
};
 
export default {
  'studyBrowser.thumbnailDetailSources': thumbnailDetailSources,
  'studyBrowser.thumbnailDetailTests': thumbnailDetailTests,
 
  /**
   * The items shown on the detail line of a study browser thumbnail, under the
   * modality and series description.  Declared the same way as the viewport
   * overlay items (`viewportOverlay.topLeft` and friends):
   *
   * - `id` names the item, and is what an override replaces or removes.
   * - `condition` decides whether to include it, either as a function of
   *   `{ displaySet, instance, formatters }` or the name of a
   *   `studyBrowser.thumbnailDetailTests` entry.  Omitted means always.
   * - the value comes from `contentF` (a function of the same properties),
   *   `source` (the name of a `studyBrowser.thumbnailDetailSources` entry) or
   *   `attribute` (an attribute of the instance the display set shows).  An item
   *   with no value, or naming a source or test that is not registered, is left
   *   out; if that leaves no items at all the thumbnail keeps its default detail
   *   line rather than showing an empty one.
   * - `label` prefixes the value, `title` is its tooltip, and `iconName` puts an
   *   icon before it - a name, or a function returning one.
   *
   * The default is the series number and the instance count, as the thumbnails
   * have always shown.  `platform/app/public/customizations/studyBrowser/
   * derivedDateTime.jsonc` is an example of adding to it.
   */
  'studyBrowser.thumbnailDetails': [
    {
      id: 'SeriesNumber',
      label: 'S:',
      source: 'seriesNumber',
    },
    {
      id: 'InstanceCount',
      source: 'numInstances',
      iconName: ({ displaySet }) => displaySet?.countIcon || 'InfoSeries',
    },
  ],
};