All files / dicomImageLoader/src/imageLoader/wadors/metaData NMHelpers.ts

11.11% Statements 2/18
0% Branches 0/14
25% Functions 1/4
11.11% Lines 2/18

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                      3376x   3376x                                                                                                                                                        
import getTagValue from '../getTagValue';
import getValue from './getValue';
import isNMReconstructable from '../../isNMReconstructable';
import getNumberValues from './getNumberValues';
 
/**
 * Checks if the modality is Nuclear Medicine (NM)
 * @param metaData The metadata object containing DICOM tags
 * @returns True if the modality includes 'NM', false otherwise
 */
function isNMModality(metaData) {
  const modality = getValue(metaData['00080060']) as string;
 
  return modality.includes('NM');
}
 
/**
 * Get a subpart of Image Type dicom tag defined by index
 * @param {*} metaData
 * @param {*} index 0 based index of the subtype
 */
function getImageTypeSubItemFromMetadata(metaData, index) {
  const imageType = getTagValue(metaData['00080008'], false);
 
  if (imageType) {
    // const subTypes = imageType.split('\\');
 
    // if (subTypes.length > index) {
    //   return subTypes[index];
    // }
    return imageType[index];
  }
 
  return undefined;
}
/**
 * Extracts the orientation from NM multiframe metadata, if image type
 * equal to RECON TOMO or RECON GATED TOMO
 * @param {*} metaData
 * @returns
 */
function extractOrientationFromNMMultiframeMetadata(metaData) {
  let imageOrientationPatient;
  const imageSubType = getImageTypeSubItemFromMetadata(metaData, 2);
 
  if (imageSubType && isNMReconstructable(imageSubType)) {
    const detectorInformationSequence = getTagValue(metaData['00540022']);
 
    if (detectorInformationSequence) {
      imageOrientationPatient = getNumberValues(
        detectorInformationSequence['00200037'],
        6
      );
    }
  }
 
  return imageOrientationPatient;
}
 
/**
 * Extracts the position from NM multiframe dataset, if image type
 * equal to RECON TOMO or RECON GATED TOMO
 * @param {*} metaData
 * @returns
 */
function extractPositionFromNMMultiframeMetadata(metaData) {
  let imagePositionPatient;
  const imageSubType = getImageTypeSubItemFromMetadata(metaData, 2);
 
  if (imageSubType && isNMReconstructable(imageSubType)) {
    const detectorInformationSequence = getTagValue(metaData['00540022']);
 
    if (detectorInformationSequence) {
      imagePositionPatient = getNumberValues(
        detectorInformationSequence['00200032'],
        3
      );
    }
  }
 
  return imagePositionPatient;
}
 
export {
  extractOrientationFromNMMultiframeMetadata,
  extractPositionFromNMMultiframeMetadata,
  isNMModality,
  getImageTypeSubItemFromMetadata,
};