From 7d199ab4628c231f0538d62c1b86e830c19e0be9 Mon Sep 17 00:00:00 2001 From: "Emanuel F. Oliveira" Date: Fri, 4 Nov 2016 09:08:57 -0200 Subject: [PATCH] OHIF-20 Documentation for parsingUtils.js library... --- Packages/viewerbase/lib/parsingUtils.js | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Packages/viewerbase/lib/parsingUtils.js b/Packages/viewerbase/lib/parsingUtils.js index a078ebdfa..4026b7b7f 100644 --- a/Packages/viewerbase/lib/parsingUtils.js +++ b/Packages/viewerbase/lib/parsingUtils.js @@ -1,10 +1,29 @@ import {dicomParser} from 'meteor/cornerstone'; +/** + * A small set of utilities to help parsing DICOM element values. + * In the future the functionality provided by this library might + * be incorporated into dicomParser library. + */ + export const parsingUtils = { + + /** + * Check if supplied argument is a valid instance of the dicomParser.DataSet class. + * @param data {Object} An instance of the dicomParser.DataSet class. + * @returns {Boolean} Returns true if data is a valid instance of the dicomParser.DataSet class. + */ isValidDataSet: function(data) { return (data instanceof dicomParser.DataSet); }, + + /** + * Parses an element tag according to the 'AT' VR definition. + * @param data {Object} An instance of the dicomParser.DataSet class. + * @param tag {String} A DICOM tag with in the format xGGGGEEEE. + * @returns {String} A string representation of a data element tag or null if the field is not present or data is not long enough. + */ attributeTag: function(data, tag) { if (this.isValidDataSet(data) && tag in data.elements) { let element = data.elements[tag]; @@ -17,6 +36,15 @@ export const parsingUtils = { } return null; }, + + /** + * Parses the string representation of a multi-valued element into an array of strings. If the parser + * parameter is passed and is a function, it will be applied to each element of the resulting array. + * @param data {Object} An instance of the dicomParser.DataSet class. + * @param tag {String} A DICOM tag with in the format xGGGGEEEE. + * @param parser {Function} An optional parser function that can be applied to each element of the array. + * @returns {Array} An array of floating point numbers or null if the field is not present or data is not long enough. + */ multiValue: function(data, tag, parser) { if (this.isValidDataSet(data) && tag in data.elements) { let element = data.elements[tag]; @@ -35,7 +63,15 @@ export const parsingUtils = { } return null; }, + + /** + * Parses a string to an array of floats for a multi-valued element. + * @param data {Object} An instance of the dicomParser.DataSet class. + * @param tag {String} A DICOM tag with in the format xGGGGEEEE. + * @returns {Array} An array of floating point numbers or null if the field is not present or data is not long enough. + */ floatArray: function(data, tag) { return this.multiValue(data, tag, parseFloat); } + };