health.dicom
Module health.dicom
API
Declarations
ballerinax/health.dicom Ballerina library
This base DICOM package provides DICOM data types, encoders, and validators.
Package Overview
The dicom (core) package is the base DICOM package. This package includes DICOM data types, data dictionaries, encoders, validators, and utility functions necessary for various DICOM-related tasks.
Compatibility
| Version | |
|---|---|
| Ballerina Language | Swan Lake 2201.8.2 |
Features
- DICOM Data Types: Includes DICOM data types, such as Tag, DataElement, and DataSet, etc.
- DICOM Encoders: Streamlined encoding functionality to convert DICOM entities into byte representations.
- DICOM Validators: Robust validators ensuring DICOM entities conform to standard specifications.
- Utility Functions: A set of utility functions designed to assist in common DICOM tasks.
Report Issues
To report bugs, request new features, start new discussions, view project boards, etc., go to the Ballerina Extended Library repository
Useful Links
- Discuss code changes of the Ballerina project in ballerina-dev@googlegroups.com.
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag
Functions
bytesToFloat
Converts a byte array representing a float to a float value.
Parameters
- bytes byte[] - The byte array containing the float data
- byteOrder ByteOrder - The byte order used in the byte array
bytesToInt
Converts a byte array representing an integer to an integer value.
Parameters
- bytes byte[] - The byte array containing the integer bytes
- byteOrder ByteOrder - The byte order used in the byte array
constructInvalidValueTypeErrorMsg
function constructInvalidValueTypeErrorMsg(Vr vr, DataElementValue value, string expectedType) returns stringConstructs an invalid value type error message.
Parameters
- vr Vr - The VR of the data element
- value DataElementValue - The invalid value
- expectedType string - The expected value type
Return Type
- string - The constructed invalid value type error message
floatToBytes
Converts a float value to its bytes representation.
Parameters
- n float - The float value to be converted
- byteOrder ByteOrder - The byte order to be used for the conversion
Return Type
- byte[]|Error - A
byte[]containing the encoded float, or anErrorif the conversion fails
getByteOrder
function getByteOrder(TransferSyntax transferSyntax) returns ByteOrderRetrieves the byte order associated with a DICOM transfer syntax.
Parameters
- transferSyntax TransferSyntax - The DICOM transfer syntax
Return Type
- ByteOrder - The corresponding
ByteOrder
getDataElement
function getDataElement(Dataset dataset, int tagInt) returns DataElement?Retrieves a data element from the dataset for a given tag integer.
Return Type
- DataElement? - The data element if found, or
()
getDataElementFromKeyword
function getDataElementFromKeyword(Dataset dataset, string tagKeyword) returns DataElement?Retrieves a data element from a dataset using its keyword.
Parameters
- dataset Dataset - The dataset to be searched
- tagKeyword string - The keyword of the data element to find
Return Type
- DataElement? - The data element with matching keyword if found, otherwise
()
getFloat
Extracts a float value from the dataset for a given tag integer.
getFloatArray
Extracts an array of floats from a multi-valued dataset element (separated by '').
getInt
Extracts an integer value from the dataset for a given tag integer.
getIntArray
Extracts an array of integers from a multi-valued dataset element (separated by '').
getPrivateTagInfo
Retrieves the tag information of a private DICOM tag.
Parameters
- tag Tag - The private tag
- privateCreatorID string - The private creator identifier of the tag
Return Type
- TagInfo? - The
TagInfoif tag information is found, otherwise()
getSequence
function getSequence(Dataset dataset, int tagInt) returns SequenceValue|ErrorExtracts a SequenceValue (SQ) from the dataset.
Return Type
- SequenceValue|Error - The
SequenceValueif found, orErrorif missing or invalid type
getSortedDataset
Sorts a DICOM dataset based on the tag numbers in ascending order.
Parameters
- dataset Dataset - The dataset to be sorted
Return Type
- Dataset - A new sorted dataset
getString
Retrieves a string value from the dataset for a given tag.
getStringArray
Extracts an array of strings from a multi-valued dataset element (separated by '').
getTagFromKeyword
Retrieves the tag from the keyword.
Parameters
- tagKeyword string - The keyword of the data element to search for
Return Type
- Tag? - The tag associated with the keyword if found, otherwise
()
getTagInfo
Retrieves the tag information of a tag.
Parameters
- tag Tag - The tag
Return Type
- TagInfo? - The
TagInfoif tag information is found, otherwise()
intToBytes
Converts an integer value to its bytes representation.
Parameters
- n int - The integer value to be converted
- byteOrder ByteOrder - The byte order to be used for the conversion
Return Type
- byte[]|Error - A
byte[]containing the encoded integer, or anErrorif the conversion fails
isBytesVr
Checks if a VR is a bytes type VR.
Parameters
- vr Vr - The VR to be checked
Return Type
- boolean -
trueif the VR is a bytes type VR, otherwisefalse
isCommandTag
Checks if a tag is a command tag.
Parameters
- tag Tag - The tag to be checked
Return Type
- boolean -
trueif the tag is a command tag, or elsefalse
isExplicitTransferSyntax
function isExplicitTransferSyntax(TransferSyntax transferSyntax) returns booleanChecks if a DICOM transfer syntax is an explicit type.
Parameters
- transferSyntax TransferSyntax - The DICOM transfer syntax to be evaluated
Return Type
- boolean -
trueif the transfer syntax is explicit, otherwisefalse
isFileMetaInfoTag
Checks if a tag is a file meta information tag.
Parameters
- tag Tag - The tag to be checked
Return Type
- boolean -
trueif the provided tag is a file meta information tag, otherwisefalse
isFloatVr
Checks if a VR is a float type VR.
Parameters
- vr Vr - The VR to be checked
Return Type
- boolean -
trueif the VR is a float type VR, otherwisefalse
isIntVr
Checks if a VR is an integer type VR.
Parameters
- vr Vr - The VR to be checked
Return Type
- boolean -
trueif the VR is an integer type VR, otherwisefalse
isPixelDataTag
Checks if a tag is a pixel data tag.
Parameters
- tag Tag - The tag to be checked
Return Type
- boolean -
trueif the provided tag is a pixel data tag, otherwisefalse
isPrivateCreatorTag
Checks if a tag is a private creator tag.
Parameters
- tag Tag - The tag to be checked
Return Type
- boolean -
trueif the provided Tag is a private creator tag, otherwisefalse
isPrivateTag
Checks if a tag is a private tag.
Parameters
- tag Tag - The tag to be checked
Return Type
- boolean -
trueif the Tag is a private tag, or elsefalse
isStringVr
Checks if a VR is a string type VR.
Parameters
- vr Vr - The VR to be checked
Return Type
- boolean -
trueif the VR is a string type VR, otherwisefalse
isValidKeyword
Checks if a string is a valid DICOM data element keyword.
Parameters
- keyword string - The string to be validated
Return Type
- boolean -
trueif the provided string is a valid DICOM keyword, otherwisefalse
isValidTag
Checks if a Tag is a valid DICOM tag.
Parameters
- tag Tag - The Tag to be validated
Return Type
- boolean -
trueif the provided Tag is a valid DICOM tag, otherwisefalse
isValidTagStr
Checks if a tag string represents a valid DICOM tag.
Parameters
- tagStr string - The tag string to be validated
Return Type
- boolean -
trueif the provided tag string is a valid DICOM tag, otherwisefalse
parseDate
Parses a DICOM Date string (DA VR) into a structured DicomDate record.
The DA VR format is YYYYMMDD.
Parameters
- daString string - The DICOM Date string (format: YYYYMMDD)
parsePersonName
function parsePersonName(string pnString) returns PersonNameParses a DICOM Person Name (PN VR) string into a structured PersonName record.
Parameters
- pnString string - The DICOM Person Name string
Return Type
- PersonName - The parsed
PersonNamerecord
parseTime
Parses a DICOM Time string (TM VR) into a structured DicomTime record.
The TM VR format is HHMMSS.FFFFFF (only HH is required; the rest are optional).
Parameters
- tmString string - The DICOM Time string (format: HH[MM[SS[.FFFFFF]]])
recordToDataset
function recordToDataset(record {} 'record, TransferSyntax transferSyntax, boolean validateDataElements) returns Dataset|ErrorTransforms a record into a Dataset.
Parameters
- 'record record {} - The record to be transformed
- transferSyntax TransferSyntax - The transfer syntax to be used during the transformation
- validateDataElements boolean (default true) - A boolean flag indicating whether to validate data elements during the transformation
resizeNumericBytes
Resizes a numeric byte array to a specified length respecting the byte order.
Parameters
- byteArray byte[] - The byte array to be resized
- byteOrder ByteOrder - The byte order used in the byte array
- newLength int - The desired new length of the byte array
Return Type
- byte[] - A new resized byte array
strToTag
Converts a tag string into a tag.
Parameters
- tagStr string - The tag string to be converted
strToVr
Converts a string representation of a VR to its corresponding VR type.
Parameters
- vrStr string - The string representation of the VR to be converted
tagToInt
Converts a tag to its integer representation.
Parameters
- tag Tag - The tag to be converted
tagToStr
Converts a tag to its string representation.
Parameters
- tag Tag - The tag to be converted
Return Type
- string - The string representation of the given tag
toBytes
function toBytes(Tag|DataElement|Dataset entity, TransferSyntax transferSyntax, boolean encodeSorted, boolean validateBeforeEncoding) returns byte[]|EncodingErrorEncodes a DICOM entity (tag, data element, or dataset) to a bytes.
Parameters
- entity Tag|DataElement|Dataset - The DICOM entity to be encoded
- transferSyntax TransferSyntax - The transfer syntax to be used for the encoding
- encodeSorted boolean (default false) - A boolean flag indicating whether the dataset should be sorted in ascending order before encoding. This is an optional parameter.
- validateBeforeEncoding boolean (default true) - A boolean flag indicating whether to validate the entity before encoding. This is an optional parameter.
Return Type
- byte[]|EncodingError - The encoded DICOM entity, or an
EncodingErrorif the encoding fails
validate
function validate(Tag|DataElement|Dataset entity, TransferSyntax transferSyntax) returns ValidationError?Validates a DICOM entity (tag, data element, or dataset).
Parameters
- entity Tag|DataElement|Dataset - The DICOM entity to be validated
- transferSyntax TransferSyntax - The transfer syntax of the entity
Return Type
- ValidationError? - A
ValidationErrorif the validation fails
Constants
health.dicom: ITEM_DELIMITER_TAG
Constant for item delimiter tag.
health.dicom: ITEM_TAG
Constant for sequence item tag.
health.dicom: NULL_BYTE
Constant for null byte.
health.dicom: PRIVATE_TAGS_DICT
DICOM private tags dictionary.
health.dicom: REPEATING_TAGS_DICT
DICOM repeatings groups' tags dictionary.
health.dicom: SEQUENCE_DELIMITER_TAG
Constant for sequence delimiter item.
health.dicom: SPACE_BYTE
Constant for space byte.
health.dicom: STANDARD_TAGS_DICT
DICOM standatd tags dictionary.