All files / dicomImageLoader/src/imageLoader getInstanceModule.ts

12.5% Statements 2/16
0% Branches 0/4
0% Functions 0/2
12.5% Lines 2/16

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                                                              428x     428x                                    
/**
 * Retrieves metadata from a DICOM image and returns it as an object with capitalized keys.
 * @param imageId - the imageId
 * @param metaDataProvider - The metadata provider either wadors or wadouri
 * @param types - An array of metadata types to retrieve.
 * @returns An object containing the retrieved metadata with capitalized keys.
 */
function getInstanceModule(imageId, metaDataProvider, types) {
  const result = {};
  for (const t of types) {
    try {
      const data = metaDataProvider(t, imageId);
      if (data) {
        const capitalizedData = {};
        for (const key in data) {
          if (key in data) {
            // each tag should get capitalized to match dcmjs style. Todo: move all of the tags to dcmjs style
            const capitalizedKey = capitalizeTag(key);
            capitalizedData[capitalizedKey] = data[key];
          }
        }
        Object.assign(result, capitalizedData);
      }
    } catch (error) {
      console.error(`Error retrieving ${t} data:`, error);
    }
  }
 
  return result;
}
 
const capitalizeTag = (tag: string) =>
  tag.charAt(0).toUpperCase() + tag.slice(1);
 
const instanceModuleNames = [
  'multiframeModule',
  'generalSeriesModule',
  'patientStudyModule',
  'imagePlaneModule',
  'nmMultiframeGeometryModule',
  'imagePixelModule',
  'modalityLutModule',
  'voiLutModule',
  'sopCommonModule',
  'petIsotopeModule',
  'overlayPlaneModule',
  'transferSyntax',
  'petSeriesModule',
  'petImageModule',
];
 
export { getInstanceModule, instanceModuleNames };