All files / dicomImageLoader/src/imageLoader/wadouri/metaData extractPositioningFromDataset.ts

56.09% Statements 23/41
44.18% Branches 19/43
85.71% Functions 6/7
56.09% Lines 23/41

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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187                                                          1044x   1044x                           1044x                     1044x   1044x                           1044x                     1620x     1620x                       1620x 1044x       1620x                     1620x     1620x                   1620x 1044x     1620x                   1620x       1620x               1620x                       1620x 288x 1332x                 1620x                    
import getNumberValues from './getNumberValues';
import isNMReconstructable from '../../isNMReconstructable';
 
/**
 * Get a subpart of Image Type dicom tag defined by index
 * @param {*} dataSet
 * @param {*} index 0 based index of the subtype
 */
function getImageTypeSubItemFromDataset(dataSet, index) {
  const imageType = dataSet.string('x00080008');
 
  if (imageType) {
    const subTypes = imageType.split('\\');
 
    if (subTypes.length > index) {
      return subTypes[index];
    }
  }
 
  return undefined;
}
/**
 * Extracts the orientation from NM multiframe dataset, if image type
 * equal to RECON TOMO or RECON GATED TOMO
 * @param {*} dataSet
 * @returns
 */
function extractOrientationFromNMMultiframeDataset(dataSet) {
  let imageOrientationPatient;
  const modality = dataSet.string('x00080060');
 
  Iif (modality?.includes('NM')) {
    const imageSubType = getImageTypeSubItemFromDataset(dataSet, 2);
 
    if (imageSubType && isNMReconstructable(imageSubType)) {
      if (dataSet.elements.x00540022) {
        imageOrientationPatient = getNumberValues(
          dataSet.elements.x00540022.items[0].dataSet,
          'x00200037',
          6
        );
      }
    }
  }
 
  return imageOrientationPatient;
}
 
/**
 * Extracts the position from NM multiframe dataset, if image type
 * equal to RECON TOMO or RECON GATED TOMO
 * @param {*} dataSet
 * @returns
 */
function extractPositionFromNMMultiframeDataset(dataSet) {
  let imagePositionPatient;
  const modality = dataSet.string('x00080060');
 
  Iif (modality?.includes('NM')) {
    const imageSubType = getImageTypeSubItemFromDataset(dataSet, 2);
 
    if (imageSubType && isNMReconstructable(imageSubType)) {
      if (dataSet.elements.x00540022) {
        imagePositionPatient = getNumberValues(
          dataSet.elements.x00540022.items[0].dataSet,
          'x00200032',
          3
        );
      }
    }
  }
 
  return imagePositionPatient;
}
 
/**
 * Extract orientation information from a dataset. It tries to get the orientation
 * from the Detector Information Sequence (for NM images) if image type equal
 * to RECON TOMO or RECON GATED TOMO
 * @param {*} dataSet
 * @returns
 */
function extractOrientationFromDataset(dataSet) {
  let imageOrientationPatient = getNumberValues(dataSet, 'x00200037', 6);
 
  // Trying to get the orientation from the Plane Orientation Sequence
  Iif (!imageOrientationPatient && dataSet.elements.x00209116) {
    imageOrientationPatient = getNumberValues(
      dataSet.elements.x00209116.items[0].dataSet,
      'x00200037',
      6
    );
  }
 
  // If orientation not valid to this point, trying to get the orientation
  // from the Detector Information Sequence (for NM images) with image type
  // equal to RECON TOMO or RECON GATED TOMO
 
  if (!imageOrientationPatient) {
    imageOrientationPatient =
      extractOrientationFromNMMultiframeDataset(dataSet);
  }
 
  return imageOrientationPatient;
}
 
/**
 * Extract position information from a dataset. It tries to get the position
 * from the Detector Information Sequence (for NM images) if image type equal
 * to RECON TOMO or RECON GATED TOMO
 * @param {*} dataSet
 * @returns
 */
function extractPositionFromDataset(dataSet) {
  let imagePositionPatient = getNumberValues(dataSet, 'x00200032', 3);
 
  // Trying to get the position from the Plane Position Sequence
  Iif (!imagePositionPatient && dataSet.elements.x00209113) {
    imagePositionPatient = getNumberValues(
      dataSet.elements.x00209113.items[0].dataSet,
      'x00200032',
      3
    );
  }
 
  // If position not valid to this point, trying to get the position
  // from the Detector Information Sequence (for NM images)
  if (!imagePositionPatient) {
    imagePositionPatient = extractPositionFromNMMultiframeDataset(dataSet);
  }
 
  return imagePositionPatient;
}
 
/**
 * Extract the pixelSpacing information. If exists, extracts this information
 * from Pixel Measures Sequence
 * @param {*} dataSet
 * @returns
 */
function extractSpacingFromDataset(dataSet) {
  let pixelSpacing = getNumberValues(dataSet, 'x00280030', 2);
 
  // If pixelSpacing not valid to this point, trying to get the spacing
  // from the Pixel Measures Sequence
  Iif (!pixelSpacing && dataSet.elements.x00289110) {
    pixelSpacing = getNumberValues(
      dataSet.elements.x00289110.items[0].dataSet,
      'x00280030',
      2
    );
  }
 
  return pixelSpacing;
}
 
/**
 * Extract the sliceThickness information. If exists, extracts this information
 * from Pixel Measures Sequence
 * @param {*} dataSet
 * @returns
 */
function extractSliceThicknessFromDataset(dataSet) {
  let sliceThickness;
 
  if (dataSet.elements.x00180050) {
    sliceThickness = dataSet.floatString('x00180050');
  } else Iif (
    dataSet.elements.x00289110 &&
    dataSet.elements.x00289110.items.length &&
    dataSet.elements.x00289110.items[0].dataSet.elements.x00180050
  ) {
    sliceThickness =
      dataSet.elements.x00289110.items[0].dataSet.floatString('x00180050');
  }
 
  return sliceThickness;
}
 
export {
  getImageTypeSubItemFromDataset,
  extractOrientationFromDataset,
  extractPositionFromDataset,
  extractSpacingFromDataset,
  extractSliceThicknessFromDataset,
};