YAKAMI DICOM Tools ver. 1.0.6.0 Copyright (C) Masahiro YAKAMI 2008. All rights reserved. ================================================================================ How to write scripts for DICOM-to-DICOM conversion ================================================================================ Index * How to write scripts for DICOM conversion * How to specify target tags (left side of "=") * How to specify process (right side of "=") * List of commands (in alphabetic order) * Appendix * {GROUP_NUMBER} * {TAG_NUMBER} * {ITEM_FORMAT_NUMBER} * {VR} * {DATA} ================================================================================ How to write scripts for DICOM-to-DICOM conversion You can manipulate DICOM headers with this DICOM-to-DICOM Conversion script. Script files are text files. They must be formatted in the following manner. The first line of a DICOM-to-DICOM conversion script must be started with "dcm_conv opt". Other lines are formatted as follows. {TARGET}={PROCESS} {TARGET} is to choose DICOM elements to process. {PROCESS} is to specify what to do with its targets. example: dcm_conv opt GRP 0010=empty TAG 0008 0080=empty SET private=del ================================================================================ How to specify target elements (the left side of "=") You can choose target DICOM elements with group number, element number, or element sets. The left side of "=" consists of a command and its argument(s). Commands and arguments are separated with space. Commands are "GRP", "TAG", or "SET". example: GRP 0010 GRP format: GRP {GROUP_NO} explanation: {GROUP_NO} is DICOM group number in base-16. For example, you can choose all elements of the group of patient information with the following command. example: GRP 0010 TAG format: TAG {GROUP_NO} {ELEMENT_NO} explanation: {GROUP_NO} is DICOM group number in base-16, and {ELEMENT_NO} is DICOM element number in base-16. For example, TAG 0010 0010 is patient name element (0010,0010). example: TAG 0010 0010 SET format: SET {ARG} explanation: {ARG} is "private" only for the time being. example: SET private ================================================================================ How to specify process (right side of "=") You can specify how to process target value with commands followed by arguments. Commands and arguments are separated with spaces. example: copy 0010 0010 ======================================== List of commands (in alphabetic order) add format: add {ELEMENT_TYPE} {VR} {VALUE} explanation: The action of this command depends on whether the target element(*1) exists or not. If *1 exists, this command does nothing. If *1 does not exist, this command creates a new element whose value is {VALUE} and whose VR is {VR}, and whose element type is {ELEMENT_TYPE}, and adds it as the target element. example: add 1 LO backslash\20encoded\20string result sample 1: backslash encoded string (If the target element does not exist.) result sample 2: original data (Suppose the target element exists and its value is "original data ".) copy format: copy {GROUP_NO} {ELEMENT_NO} explanation: The action of this command depends on whether the target element(*1) exists or not, and on the element specified with {GROUP_NO} and {ELEMENT_NO}(*2) exists or not. If *1 exists, this command does nothing. If *1 does not exist and *2 exists, this command copies *2 and add it as the target element. If *1 does not exist, and *2 does not exist, this command does nothing. example: copy 0010 0010 result sample: John Smith (Suppose the value of element:(0010,0010) is "John Smith") copy_or_add format: copy_or_add {GROUP_NO} {ELEMENT_NO} {ELEMENT_TYPE} {VR} {VALUE} explanation: The action of this command depends on whether the target element(*1) exists or not, and on the element specified with {GROUP_NO} and {ELEMENT_NO}(*2) exists or not. If *1 exists, this command does nothing. If *1 does not exist and *2 exists, this command copy the element and add it as the target element. If *1 does not exist and *2 does not exist, this command creates a new element whose value is {VALUE} and whose VR is {VR}, and whose element type is {ELEMENT_TYPE}, and adds it as the target element. example: copy_or_add 0010 0010 1 PN John\20Smith result sample 1: John Smith (Suppose *1 does not exist, *2 does not exist, and the value of element: (0010,0010) is "John Smith".) result sample 2: Jane Smith (Suppose *1 does not exist, *2 exists, and the value of *2 is "Jane Smith".) del format: del explanation: This command deletes the target element. This command does not require arguments. If the target element does not exist, this command does nothing. example: del emptify format: emptify explanation: This command emptifies the target element. This command does not require arguments. If the target element does not exist, this command does nothing. example: emptify decrypt format: decrypt {PASSWORD} explanation: This command decords the value of the target element assuming that the target element is encorded with "encrypt {PASSWORD}". If the target element does not exist, this command does nothing. example: decrypt password decrypt_text format: decrypt_text {PASSWORD} explanation: This command decords the value of the target element assuming that the target element is encorded with "encrypt_text {PASSWORD}". If the target element does not exist, this command does nothing. example: decrypt_text password encrypt format: encrypt {PASSWORD} explanation: This command encodes the value of the target element with {PASSWORD}. The cryptographic algorithm is DES. If the target element does not exist, this command does nothing. example: encrypt password encrypt_text format: encrypt_text explanation: This command encodes the value of the target element with {PASSWORD}, and converts it into text format. The cryptographic algorithm is DES. The conversion algorithm is base64. If the target element does not exist, this command does nothing. example: encrypt_text password initial format: initial explanation: This command converts the value of the target element into its initial. If the target element does not exist, this command does nothing. example: initial result sample: J S (Suppose the target element exists, and its value is "John Smith".) initial_or_add format: initial_or_add {ELEMENT_TYPE} {VR} {VALUE} explanation: The action of this command depends on whether the target element(*1) exists or not. If *1 exists, this command converts the value of the target element into its initial. If *1 does not exist, this command creates a new element whose value is {VALUE} and whose VR is {VR}, and whose element type is {ELEMENT_TYPE}, and adds it as the target element. example: initial 1 PN X\20X result sample 1: J S (Suppose *1 exists, and the value of tag:(0010,0010) is "John Smith".) result sample 2: X X (Suppose *1 does not exist.) ins_lt format: ins_lt {DATA} explanation: This command inserts {DATA} at the head of the value of the target. If the target element does not exist, this command does nothing. example: ins_lt backslash\20encoded\20string result sample: backslash encoded stringoriginal data (Suppose the target element exists, and its value is "original data ".) ins_lt_or_add format: ins_lt_or_add {DATA} {ELEMENT_TYPE} {VR} explanation: The action of this command depends on whether the target element(*1) exists or not. If *1 exists, this command inserts {DATA} at the head of the value of the target. If *1 does not exist, this command creates a new element whose value is {DATA} and whose VR is {VR}, and whose element type is {ELEMENT_TYPE}, and adds it as the target element. example: ins_lt_or_add backslash\20encoded\20string 1 LO result sample 1Fbackslash encoded stringoriginal data (Suppose the target element exists, and its value is "original data ".) result sample 2: backslash encoded string (Suppose the target element does not exist.) ins_rt format: ins_rt {DATA} explanation: This command inserts {DATA} at the tail of the value of the target. If the target element does not exist, this command does nothing. example: ins_rt backslash\20encoded\20string result sample: original data backslash encoded string (Suppose the target element exists, and its value is "original data ".) ins_rt_or_add format: ins_rt_or_add {DATA} {ELEMENT_TYPE} {VR} explanation: The action of this command depends on whether the target element(*1) exists or not. If *1 exists, this command inserts {DATA} at the tail of the value of the target. If *1 does not exist, this command creates a new element whose value is {DATA} and whose VR is {VR}, and whose element type is {ELEMENT_TYPE}, and adds it as the target element. example: ins_rt_or_add backslash\20encoded\20string 1 LO result sample 1: original data backslash encoded string (Suppose the target element exists, and its value is"original data ".) result sample 2: backslash encoded string (Suppose the target element does not exist.) lt_overwrite format: lt_overwrite {DEFAULT} explanation: This command overwrites {DEFAULT} with the data of the target element from the head of {DEFAULT}. If the target element does not exist, this command does nothing. example: lt_overwrite ---------- result sample 1: original-- (Suppose the target element exists, and its value is"original".) result sample 2: original data (Suppose the target element exists, and its value is"original data ".) nc format: nc explanation: This command does nothing. This command does not require arguments. example: nc result: overwrite format: overwrite {DATA} explanation: This command overwrites the target element with {DATA}. If the target element does not exist, this command does nothing. example: overwrite backslash\20encoded\20string result sampleFbackslash encoded string (Suppose the target element exists.) overwrite_or_add format: overwrite_or_add {DATA} {ELEMENT_TYPE} {VR} explanation: The action of this command depends on whether the target element(*1) exists or not. If *1 exists, this command overwrites the target element with {DATA}. If *1 does not exist, this command creates a new element whose value is {DATA} and whose VR is {VR}, and whose element type is {ELEMENT_TYPE}, and adds it as the target element. example: overwrite_or_add backslash\20encoded\20string 1 LO result sample: backslash encoded string rsubstring format: rsubstring {START} {LENGTH} explanation: This command extracts a substring from the target data. The substring starts at a specified character position {START} and has a specified length {LENGTH}. In this command, the last letter is counted as 0. If the arguments are invalid, this command returns "". If the target element does not exist, this command does nothing. example: rsubstring 4 2 resulst sample: da (Suppose the target element exists, and its value is"original data ".) rsubstring_or_add format: rsubstring_or_add {START} {LENGTH} {ELEMENT_TYPE} {VR} {VALUE} explanation: The action of this command depends on whether the target element(*1) exists or not. If *1 exists, this command extracts a substring from the target data. The substring starts at a specified character position {START} and has a specified length {LENGTH}. In this command, the last letter is counted as 0. If the arguments are invalid, this command returns "". If *1 does not exist, this command creates a new element whose value is {VALUE} and whose VR is {VR}, and whose element type is {ELEMENT_TYPE}, and adds it as the target element. example: rsubstring_or_add 4 2 1 LO backslash\20encoded\20string result sample 1: da (Suppose *1 exists, and its value is"original data ".) result sample 2: backslash encoded string (Suppose *1 does not exist.) rt_overwrite format: rt_overwrite {DEFAULT} explanation: This command overwrites {DEFAULT} with the data of the target element from the tail of {DEFAULT}. If the target element does not exist, this command does nothing. example: rt_overwrite ---------- result sample 1: --original (Suppose *1 exists, and its value is"original".) result sample 2Foriginal data (Suppose *1 exists, and its value is"original data ".) substring format: substring {START} {LENGTH} explanation: This command extracts a substring from the target data. The substring starts at a specified character position {START} and has a specified length {LENGTH}. In this command, the first letter is counted as 0. If the arguments are invalid, this command returns "". example: substring 4 2 result sample : in (Suppose the target element exists, and its value is"original data ".) substring_or_add format: substring_or_add {START} {LENGTH} {ELEMENT_TYPE} {VR} {VALUE} explanation: The action of this command depends on whether the target element(*1) exists or not. If *1 exists, This command extracts a substring from the target data. The substring starts at a specified character position {START} and has a specified length {LENGTH}. In this command, the first letter is counted as 0. If the arguments are invalid, this command returns "". If *1 does not exist, this command creates a new element whose value is {VALUE} and whose VR is {VR}, and whose element type is {ELEMENT_TYPE}, and adds it as the target element. example: substring_or_add 4 2 1 LO backslash\20encoded\20string result sample 1: in (Suppose the target element exists, and its value is"original data ".) result sample 2: backslash encoded string (Suppose the target element does not exist.) trim_end_ins_rt format: trim_end_ins_rt {DATA} explanation: This command removes all the trailing spaces of the target if they exist, and inserts {DATA} at the tail of the data of the target. If the target element does not exist, this command does nothing. example: trim_end_ins_rt backslash\20encoded\20string example: original databackslash encoded string (Suppose the target element exists, and its value is"original data ".) trim_end_ins_rt_or_add format: trim_end_ins_rt_or_add {DATA} {ELEMENT_TYPE} {VR} explanation: The action of this command depends on whether the target element(*1) exists or not. If *1 exists, this command removes all the trailing spaces of the target if they exist, and inserts {DATA} at the tail of the data of the target. If *1 does not exist, this command creates a new element whose value is {DATA} and whose VR is {VR}, and whose element type is {ELEMENT_TYPE}, and adds it as the target element. example: trim_end_ins_rt_or_add backslash\20encoded\20string 1 LO result sample 1: original databackslash encoded string (Suppose *1 exists, and its value is"original data ".) result sample 2: backslash encoded string (Suppose *1 does not exist.) trim_end_rt_overwrite format: trim_end_rt_overwrite {DEFAULT} explanation: This command removes all the trailing spaces of the target, and overwrites {DEFAULT} with the data of the target element from the tail of {DEFAULT}. If the target element does not exist, this command does nothing. example: trim_end_rt_overwrite ---------- result sample 1: --original (Suppose *1 exists, and its value is"original ".) result sample 2Foriginal data (Suppose *1 exists, and its value is"original data ".) ================================================================================ Appendix * {GROUP_NO} * {ELEMENT_NO} * {ELEMENT_TYPE} * {VR} * {DATA} ---------------------------------------- {GROUP_NO} This argument must be set by an interger in base-16. For example, you must set 0010 to specify the group containing patient information. ---------------------------------------- {ELEMENT_NO} This argument must be set by an interger in base-16. For example, you must set 0020 to specify the tag containing patient's ID. (0010,0020) Patient's ID ---------------------------------------- {ELEMENT_TYPE} This argument specifies type of DICOM element in the following numbers (1,2,3,5,6,7,8). 1: Data element with explicit VR OF OB, OW, OF, SQ, UT OR UN 2bytes: group number 2bytes: element number 2bytes: VR 2bytes: 00 00 4bytes: value length 'Value Length' bytes: value 2: Data element with explicit VR other than those 2bytes: group number 2bytes: element number 2bytes: VR 2bytes: value length 'Value Length' bytes: value 3: Data element with implicit VR 2bytes: group number 2bytes: element number 4bytes: value length 'Value Length' bytes: value 5: Nesting Data element with explicit VR, fixed length 2bytes: group number 2bytes: element number 2byte: VR 2byte: 00 00 4bytes: whole length 'Item Length' bytes: item : : (item: FF FE E0 00, item length in 4bytes, value) 6: Nesting Data element with explicit VR, undefigned length 2bytes: group number 2bytes: element number 2bytes: VR 2bytes: 00 00 4bytes: FF FF FF FF 'Item Length' bytes: item : : (fixed item: FF FE E0 00, value length in 4bytes, value) (unfixed item: FF FE E0 00 FF FF FF FF, value, FF FE E0 0D 00 00 00 00) 4bytes: FF FE E0 DD 4bytes: 00 00 00 00 7: Nesting Data element with implicit VR, fixed length 2bytes: group number 2bytes: element number 4bytes: whole length 'Item Length' bytes: item : : (item: FF FE E0 00, item length in 4bytes, value) 8: Nesting Data element with implicit VR, undefigned length 2bytes: group number 2bytes element number 4bytes: FF FF FF FF 'Item Length' bytes: item : : (fixed item: FF FE E0 00, value length in 4bytes, value) (unfixed item: FF FE E0 00 FF FF FF FF, value, FF FE E0 0D 00 00 00 00) 4bytes: FF FE E0 DD 4bytes: 00 00 00 00 ---------------------------------------- {VR} This argument specifies VR of DICOM standard. AE: Application Entity AS: Age String, 0-9, 'D', 'W', 'M', 'Y' AT: Attribute Tag, integer, 4-byte length of binary CS: Code String, 0-9, ' ', '_' DA: Date, 0-9, '.' DS: Decimal String, 0-9, '+', '-', 'E', 'e', '.' DT: Date Time, 0-9, '+', '-', '.' FL: Floating Point Single, 4-byte length of binary FD: Floating Point Double, 8-byte length of binary IS: Integer String, 0-9, '+', '-' LO: Long String LT: Long Text OB: Other Byte String OF: Other Float String OW: Other Word String PN: Person Name SH: Short String SL: Signed Long, 4-byte length of binary SQ: Sequence of Items SS: Signed Short, 2-byte length of binary ST: Short Text TM: Time, 0-9, '.' UI: Unique Identifier (UID), 0-9, '.' UL: Unsigned Long, 4-byte length of binary UN: Unknown US: Unsigned Short, 2-byte length of binary UT: Unlimited Text ---------------------------------------- {DATA} This argument must be specified in backslash encorded text format. * \xx is replaced with a byte specified with xx. 'x' is a number in base-16, 0-9 or a-f. * '\\' is replaced with '\'. * '\NC' is replaced with nothing. * '\YEAR' is replaced with the current year, e.g. 2008. * '\MONTH' is replaced with the current month, e.g. 12. * '\MDAY' is replaced with the current day of the month, e.g. 31. * '\HOUR' is replaced with the current hour, e.g. 23. * '\MIN' is replaced with the current minutes, e.g. 59. * '\SEC' is replaced with the current second, e.g. 59. * '\MSEC' is replaced with the current milisecond, e.g. 999. * '\RND' is replaced with a random digit in base 10, e.g. 9. * '\RNX' is replaced with a random digit in base 16, e.g. F. * Other characters are not changed. For example, "backslash\20encoded\20string" is converted into "backslash encoded string". ---- written by Masahiro Yakami (yakami@kuhp.kyoto-u.ac.jp) 9 Mar 2009 Copyright (C) Masahiro YAKAMI 2009. All rights reserved.