MD Link Jython code can access several convenient utility functions through an object called util. Below are the functions available on that object. To call any of these from your script, you must precede the name of the field or function with a reference to util - for example:
message = util.makeHL7Message()
A util object, and all of the functions within it, will be available to Jython scripts in all Jython scripts, everywhere within an MD Link solution.
These function are organized into the categories of HL7, XML, DICOM, X12, Date/Time, and Miscellaneous.
HL7Message makeHL7Message()
Creates a new HL7 message object. The object will be empty except for an MSH segment with some basic fields.
the new HL7 message object.
HL7Message makeHL7Message(string messageAsString)
Creates a new HL7 message object from a string.
the new HL7 message object.
java.lang.IllegalArgumentException - if the supplied message string could not be parsed.
HL7Message makeHL7MessageFromXMLDocument(Document xmlDoc)
Create an HL7Message object from the given XML document. This is typically used to parse the incoming message of an execution. For example:
hl7msg = util.makeHL7MessageFromXMLDocument(engine.inputDom)
the new HL7 message object.
java.lang.IllegalArgumentException - if an HL7 message could not be found in the supplied XML document.
HL7Segment makeHL7Segment(string segmentAsString)
Creates a new HL7 segment object. This segment object will not be a part of any message object until it is added to one, via HL7Message.addSegment(int,HL7Segment) or similar.
segmentAsString - an HL7 segment in string form. eg. 'ZYX|a|b|c'.
HL7Segment makeHL7Segment(string segmentId, int numFields)
Creates a new HL7 segment object. This segment object will not be a part of any message object until it is added to one, via HL7Message.addSegment(int,HL7Segment) or similar.
segmentId - the desired segment ID. Typically 3 characters, eg. 'EVN', 'PID', etc.
numFields - must be greater than or equal to 0.
InvalidArgumentException - if numFields is less than 0.
Document makeXMLDocumentFromHL7Message(string xmlPath, HL7Message hl7msg)
Create an XML document from the given HL7Message object. This is typically used to create the output message of a task execution, for example:
engine.outputDom = util.makeXMLDocumentFromHL7Message('TaskData', hl7msg)
You must pass in as the first argument the XML path of where you want the HL7 message text to be put. If the output schema of your Custom Task is something other than the default, then you will need to compensate for that here. For example:
engine.outputDom = util.makeXMLDocumentFromHL7Message('TaskData/outputMessage', hl7msg)
The new XML document.
Element addXMLElement(Document document, string newElementName, string text)
Like addXMLElement(org.w3c.dom.Element,string,string) but this method takes a document argument; the new element will be added to the document's root element.
Element addXMLElement(Element element, string newElementName, string text)
Creates a new XML element as a child of the specified element.
newElementName - the desired tag name for the new element.
text - text to add under the new element, if any. If no text is desired, pass in an empty string ('').
the new element. (It will have already been added to the document.)
void appendText(Document document, string text)
Like appendText(org.w3c.dom.Element,string) but this method takes a document argument; the text will be added to the document's root element.
void appendText(Element element, string text)
Add some text under the specified XML element.
Document makeXMLDocument(string rootElementName)
Creates a new XML document object.
the new XML document.
string xmlDocumentToString(Document document, boolean preserveSpace)
Get a string representation of an XML document.
preserveSpace - optional; defaults to False. If False, then the returned string representation will be formatted and indented in an easy-to-read way, rather than preserving the spacing of the original exactly.
a string representation of the specified XML document.
string xmlElementToString(Element element, boolean preserveSpace)
Get a string representation of an XML element. Same as xmlDocumentToString(Document,boolean) except that this functions takes an Element object instead.
preserveSpace - optional; defaults to False. If false, then the returned string representation will be formatted and indented in an easy-to-read way, rather than preserving the spacing of the original exactly.
a string representation of the specified XML element and all of its (recursive) children.
Element xmlCreateElement(Node node, string xpath)
Creates an empty element at the given XPath, relative to the given node (document or element).
node - Reference node - either a Document or Element object.
xpath - A simple XPath, for example 'ADT_A01/MSH/MSH.1-Field_Separator'.
the element that was created. It will have been already added to the document in question.
list xmlGetAllAttributeValues(Node node, string xpath)
Gets all values of a given XPath that identifies attributes.
node - Reference node - either a Document or Element object.
xpath - An XPath identifying the attributes. Can be of any complexity, for example, to get a list in a CDA document of all the 'assigningAuthorityName' values which are under a 'patientRole' element, and also under an 'id' element with a 'root' attribute value of 'OID1', you could use "//patientRole/id[@root='OID1']/@assigningAuthorityName".
Also, there is some support for namespace prefixes in the XPath. For example, if the 'patientRole' and 'id' elements had a namespace prefix of 'v3', then you could specify "//v3:patientRole/v3:id[@root='OID1']/@assigningAuthorityName".
A list of strings representing the values of all matched attributes.
list xmlGetAllElementsText(Node node, string xpath)
Gets the text contained in all of the elements identified by the given XPath.
node - Reference node - either a Document or Element object.
xpath - An XPath identifying the elements. Can be of any complexity, for example, to get a list in a CDA document of all of the 'originalText' values that are under an 'administrativeGenderCode' element which has a 'code' attribute of value 'F', you could use "//administrativeGenderCode[@code='F']/originalText".
Also, there is some support for namespace prefixes in the XPath. For example, if the 'administrativeGenderCode' and 'originalText' elements had a namespace prefix of 'v3', then you could specify "//v3:administrativeGenderCode[@code='F']/v3:originalText".
A list of strings representing the text content of all matched elements.
string xmlGetAttributeValue(Node node, string xpath)
Returns the value of the attribute specified by an XPath. If there is more than one such attribute, the first one is used.
node - Reference node - either a Document or Element object.
xpath - An XPath identifying the attribute. Can be of any complexity, for example, to get from a CDA document the first 'assigningAuthorityName' value which is under a 'patientRole' element, and also under an 'id' element with a 'root' attribute value of 'OID1', you could use "//patientRole/id[@root='OID1']/@assigningAuthorityName".
Also, there is some support for namespace prefixes in the XPath. For example, if the 'patientRole' and 'id' elements had a namespace prefix of 'v3', then you could specify "//v3:patientRole/v3:id[@root='OID1']/@assigningAuthorityName".
The attribute value as a string, of None if the attribute is not found in the document.
string xmlGetElementText(Node node, string xpath)
Gets the text contained in all the element identified by the given XPath. If there is more than one such element, then the first one is used.
node - Reference node - either a Document or Element object.
xpath - An XPath identifying the element. Can be of any complexity, for example, to get from a CDA document the first 'originalText' value that is under an 'administrativeGenderCode' element which has a 'code' attribute of value 'F', you could use "//administrativeGenderCode[@code='F']/originalText".
Also, there is some support for namespace prefixes in the XPath. For example, if the 'administrativeGenderCode' and 'originalText' elements had a namespace prefix of 'v3', then you could specify "//v3:administrativeGenderCode[@code='F']/v3:originalText".
The content of the element as a string, or None if the element is not found.
list xmlGetNodes(Node node, string xpath)
This function is like xmlGetAllElementsText and xmlGetAllAttributeValues combined, and does not get the text contents but rather returns the DOM nodes. It can accept an XPath argument that identifies both elements and attributes.
node - Reference node - either a Document or Element object.
xpath - An XPath string.
A list of DOM Node objects.
Document xmlMakeDocument(string inputString)
Creates an XML document from the given input string. The input string can be a root element name, or an entire XML document as a string. For example, both of the calls below will work:
util.xmlMakeDocument('TaskData')
util.xmlMakeDocument('''<TaskData> <group> <item>value1</item> <item>value2</item> </group> </TaskData>''')
inputString - a string: either an element name, or an entire XML document.
An XML DOM Document object.
Document xmlMakeDocumentFromFile(string filePath)
Parses an XML file on disk.
filePath - The absolute path (i.e. directory and filename) of the file which contains the XML document.
An Document object.
void xmlWriteDocumentToFile(string filePath, Document document)
Write an XML document to a file.
filePath - The absolute path (i.e. directory and filename) of the file to write to. If this file already exists, it will be overwritten.
document - The XML DOM document to be written.
Nothing.
void xmlRemoveAll(Node node, string xpath)
Remove nodes (such as elements or attributes) from an XML document.
node - Reference node - either a Document or Element object.
xpath - An XPath, of any complexity, which identifies the nodes to remove. For example, to remove all 'assigningAuthorityName' attributes which are under 'id' elements in a CDA XML document, you could use an XPath argument of "//id/@assigningAuthorityName".
Also, there is some support for namespace prefixes in the XPath argument. If the 'id' element had a namespace prefix of 'v3', then you could specify "//v3:id/@assigningAuthorityName".
Nothing.
void xmlSetAllAttributeValues(Node node, string xpath, string value)
Set all attributes that match a given XPath to a given value. If no such attributes exist in the document, then do nothing.
node - Reference node - either a Document or Element object.
xpath - An XPath, of any complexity, which identifies the attributes whose values should be set.
value - The desired attribute value.
Nothing.
void xmlSetAllElementsText(Node node, string xpath, string value)
For all elements that match a given XPath, set their text context to a given value. If no such elements exist in the document, then do nothing.
node - Reference node - either a Document or Element object.
xpath - An XPath, of any complexity, which identifies the elements whose text content should be set.
value - The desired text content of the elements.
Nothing.
void xmlSetAttributeValue(Node node, string xpath, string value)
Set the attribute that matches a given XPath to a given value. If more than one attribute in the document matches the xpath, then only the first one will be modified. If no such attribute exists in the document, then the attribute will be created, then the value set.
node - Reference node - either a Document or Element object.
xpath - An XPath which identifies the attribute whose value should be set. This can be an XPath of any complexity if the attribute already exists, but can only be a simple XPath if the element does not exist and needs to be created.
value - The desired attribute value.
Nothing.
xmlSetElementText(Node node, string xpath, string value)
For the element that matches a given XPath, set its text context to a given value. If more than one element in the document matches the xpath, then only the first one will be modified. If no such element exists in the document, then the element will be created, then the value set.
node - Reference node - either a Document or Element object.
xpath - An XPath, of any complexity which identifies the element whose text content should be set. This can be an XPath of any complexity if the element already exists, but can only be a simple XPath if the element does not exist and needs to be created.
value - The desired text content of the elements.
Nothing.
DicomElement dicomGetElement(org.dcm4che2.data.DicomObject dicomObject, tagObject)
Get the dicom element from the dicom object. eg. util.dicomGetElement(dicomObj, 'TransferSyntaxUID')
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
the dicom element from the dicom object.
void dicomRemoveElement(org.dcm4che2.data.DicomObject dicomObject, tagObject)
Remove the dicom element from the dicom object. eg. util.dicomRemoveElement(dicomObj, 'TransferSyntaxUID')
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
string dicomGetElementType(org.dcm4che2.data.DicomObject dicomObject, tagObject)
Get the dicom element type from the dicom object. eg. util.dicomGetElementType(dicomObj, 'TransferSyntaxUID')
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
the dicom element type.
int dicomGetElementVM(org.dcm4che2.data.DicomObject dicomObject, tagObject)
Get the dicom element value multiplicity(VM) from the dicom object. eg. util.dicomGetElementVM(dicomObj, 'TransferSyntaxUID')
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
the dicom element value multiplicity.
Object dicomGetElementValue(org.dcm4che2.data.DicomObject dicomObject, tagObject)
Get the dicom element value from the dicom object. eg. util.dicomGetElementValue(dicomObj, 'TransferSyntaxUID')
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
the dicom element value.
void dicomSetElementValue(org.dcm4che2.data.DicomObject dicomObject, tagObject, valueObject)
Set the element value of the dicom object. eg. util.dicomSetElementValue(dicomObj, 'TransferSyntaxUID' ,'1.2.840.10008.1.2')
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
valueObject - element value
boolean dicomElementHasItems(org.dcm4che2.data.DicomElement dicomElement)
Check for items in dicom element. eg. util.dicomElementHasItems(dicomElement)
dicomElement - DicomElement
true if dicom element has items.
int dicomElementItemsCount(org.dcm4che2.data.DicomElement dicomElement)
Find the number of items in the dicom element. eg. util.dicomElementItemsCount(dicomElement)
dicomElement - DicomElement
the number of items in the dicom element.
void dicomAddSequenceElement(org.dcm4che2.data.DicomObject dicomObject, tagObject)
Add the sequence element to the dicom object with the default capacity = 10.
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
void dicomAddSequenceElement(org.dcm4che2.data.DicomObject dicomObject, tagObject, int capacity)
Add the sequence element to the dicom object with provided capacity.
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
capacity - capacity number
void dicomElementAddDicomObject(org.dcm4che2.data.DicomElement dicomElement, org.dcm4che2.data.DicomObject dicomObject, int index)
Add the dicom object to the dicom element at the specified position. eg. util.dicomElementAddDicomObject(dicomElement, dicomObject, 2)
dicomElement - DicomElement
dicomObject - DicomObject
index - position
void dicomElementAddDicomObject(org.dcm4che2.data.DicomElement dicomElement, org.dcm4che2.data.DicomObject dicomObject)
Append the dicom object to the dicom element. eg. util.dicomElementAddDicomObject(dicomElement, dicomObject)
dicomElement - DicomElement
dicomObject - DicomObject
DicomObject dicomElementGetDicomObject(org.dcm4che2.data.DicomElement dicomElement, int index)
Get the dicom object from the dicom element at the specified position. eg. util.dicomElementGetDicomObject(dicomElement, 2)
dicomElement - DicomElement
index - position
the dicom object from the dicom element at the specified position.
boolean dicomElementHasDicomObjects(org.dcm4che2.data.DicomElement dicomElement)
Check whether the dicom element has dicom objects. eg. util.dicomElementHasDicomObjects(dicomElement)
dicomElement - DicomElement
true if the dicom element has dicom objects.
void dicomElementRemoveDicomObject(org.dcm4che2.data.DicomElement dicomElement, org.dcm4che2.data.DicomObject dicomObject)
Remove the dicom object from the dicom element. eg. util.dicomElementRemoveDicomObject(dicomElement, dicomObject)
dicomElement - DicomElement
dicomObject - DicomObject
void dicomElementRemoveDicomObject(org.dcm4che2.data.DicomElement dicomElement, int index)
Remove the dicom object from the dicom element at the specified position. eg. util.dicomElementRemoveDicomObject(dicomElement, 2)
dicomElement - DicomElement
index - position
void dicomElementSetDicomObject(org.dcm4che2.data.DicomElement dicomElement, org.dcm4che2.data.DicomObject dicomObject, int index)
Set the dicom object of the dicom element at the specified position. eg. util.dicomElementSetDicomObject(dicomElement, dicomObject, 2)
dicomElement - DicomElement
dicomObject - DicomObject
index - position
DicomObject dicomGetNestedDicom(org.dcm4che2.data.DicomObject dicomObject, tagObject)
Get the nested dicom object from the parent dicom object. eg. util.dicomGetNestedDicom(dicomObject, ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1])
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'ScheduledProcedureStepSequence' or tag num 0x00400100 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1] or tag num array [0x00400100, 1, 0x00400008, 1]
the nested dicom object from the parent dicom object.
DicomObject dicomGetFileMetaInfo(org.dcm4che2.data.DicomObject dicomObject)
Get the file meta info dicom object from the parent dicom object. eg. util.dicomGetFileMetaInfo(dicomObject)
dicomObject - DicomObject
the file meta info dicom object from the parent dicom object.
DicomObject dicomGetCommand(org.dcm4che2.data.DicomObject dicomObject)
Get the command dicom object from the parent dicom object. eg. util.dicomGetCommand(dicomObject)
dicomObject - DicomObject
the command dicom object from the parent dicom object.
DicomObject dicomGetDataset(org.dcm4che2.data.DicomObject dicomObject)
Get the dataset dicom object from the parent dicom object. eg. util.dicomGetDataset(dicomObject)
dicomObject - DicomObject
the dataset dicom object from the parent dicom object.
string dicomGetTagName(org.dcm4che2.data.DicomElement dicomElement)
Get the dicom element tag name. eg. util.dicomGetTagName(dicomElement)
dicomElement - DicomElement
the dicom element tag name.
string dicomGetDateTime(org.dcm4che2.data.DicomObject dicomObject, tagObject, string dateTimeFormat)
Get the date-time from the dicom object in the specified format.
Parameters
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
dateTimeFormat - format of the date-time -eg. 'yyyyMMdd'. For more formatting tips refer to SimpleDateFormat javadoc.
Returns
the date-time from the dicom object in the specified format.
string[] dicomGetDateTimes(org.dcm4che2.data.DicomObject dicomObject, tagObject, string dateTimeFormat)
Get the date-times from the dicom object in the specified format.
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
dateTimeFormat - format of the date-time -eg. 'yyyyMMdd'. For more formatting tips refer to SimpleDateFormat javadoc.
the date-times from the dicom object in the specified format.
String dicomGetDateTimeRange(org.dcm4che2.data.DicomObject dicomObject, tagObject, string dateTimeFormat)
Get the date-time range in the dicom object.
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
dateTimeFormat - format of the date-time -eg. 'yyyyMMdd'. For more formatting tips refer to SimpleDateFormat javadoc.
the date-time range in the dicom object.
void dicomSetDateTime(org.dcm4che2.data.DicomObject dicomObject, tagObject, string dateTimeFormat, string dateTime)
Set the date-time in the dicom object.
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
dateTimeFormat - format of the date-time -eg. 'yyyyMMdd'. For more formatting tips refer to SimpleDateFormat javadoc.
dateTime - eg. '20101218'
void dicomSetDateTimes(org.dcm4che2.data.DicomObject dicomObject, tagObject, string dateTimeFormat, string[] dateTimes)
Set the date-times in the dicom object.
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
dateTimeFormat - format of the date-time -eg. 'yyyyMMdd'. For more formatting tips refer to SimpleDateFormat javadoc.
dateTimes - eg. ['20131120', '20121017', '20090908']
void dicomSetDateTimeRange(org.dcm4che2.data.DicomObject dicomObject, tagObject, string dateTimeFormat, string fromDate, string toDate)
Set the date-time range in the dicom object.
dicomObject - DicomObject
tagObject - May be either a tag name -eg. 'PatientName' or tag num 0x00100010 or tag path array ['ScheduledProcedureStepSequence', 1, 'ScheduledProtocolCodeSequence', 1, 'CodeValue'] or tag num array [0x00400100, 1, 0x00400008, 1, 0x00080100]
dateTimeFormat - format of the date-time -eg. 'yyyyMMdd'. For more formatting tips refer to SimpleDateFormat javadoc.
fromDate - eg. '20101216'
toDate - eg. '20110625'
DicomObject dicomLoadObjectFromFile(string dicomFileName)
Load the dicom file into a dicom object.
dicomFileName - eg. r'C:\temp\input\sample.dcm'
the dicom object.
void dicomSaveObjectToFile(org.dcm4che2.data.DicomObject dicomObject, string outFileName)
Save dicom object to a file.
dicomObject - DicomObject
outFileName - eg. r'C:\temp\input\sample.dcm'
void dicomSaveImageToFile(string dicomFileName, int frameNum, string imageFormat, string outFileName)
Extract a image frame from the dicom input file and save it to the output file.
dicomFileName - eg. r'C:\temp\input\sample.dcm'
frameNum - image frame index eg. 3
imageFormat - eg. 'jpg'
outFileName - eg. r'C:\temp\input\imageFrame3.jpg'
Query the DICOM - Service Control Provider (SCP) for the dicom files and/or store the queried dicom files to a DICOM - Service Control User (SCU). The order should be followed for the first three parameters (respondingIp, respondingPort, respondingAE). For example:
respondingIp = '10.168.0.113'
respondingPort = '106'
respondingAE = 'PACS_SCP'
util.dicomQuery(respondingIp, respondingPort, respondingAE, \
q = {'PatientName':'Boris^Katich', 'StudyDate':'20091121'},\
options={'L' : 'QRSCU:11113',\
'cmove' : 'QRSCU', \
'cstore' : '1.2.840.10008.5.1.4.1.1.7', \
'cstoredest' : r'C:\temp\dicomReceivedFiles'})
respondingIp - string. DICOM Service Control Provider (SCP) IP.
respondingPort - string. DICOM Service Control Provider (SCP) port.
respondingAE - string. DICOM Service Control Provider (SCP) application entity.
q - dictionary. Multiple query filter options in the form of the python dictionary.
options - dictionary. Multiple query settings in the form of the python dictionary.
a list of matched dicom objects.
List dicomQueryModalityWorklist(...)
Query the DICOM - RIS system for the modality worklist entries. The order should be followed for the first three parameters (respondingIp, respondingPort, respondingAE). For example:
respondingIp = '10.168.0.113'
respondingPort = '106'
respondingAE = 'MW_SCP'
util.dicomQueryModalityWorklist(respondingIp, respondingPort, respondingAE, \
q = {'PatientName':'Boris^Katich'},\
options={'mod' : 'MA',\
'date' : util.getCurrentDateTime('yyyyMMdd')})
respondingIp - string. DICOM Service Control Provider (SCP) IP.
respondingPort - string. DICOM Service Control Provider (SCP) port.
respondingAE - string. DICOM Service Control Provider (SCP) application entity.
q - dictionary. Multiple query filter options in the form of the python dictionary.
options - dictionary. Multiple mwl query settings in the form of the python dictionary.
a list of matched dicom mwl objects.
Send the DICOM file to DICOM - Service Control Provider (SCP). The order should be followed for the first four parameters (filePath, receivingIp, receivingPort, receivingAE).
For example:
filePath = r'C:\temp\sample.dcm'
receivingIp = '10.168.0.113'
receivingPort = '106'
receivingAE = 'PACS_SCP'
util.dicomSendFile(filePath, receivingIp, receivingPort, receivingAE, \
options = {'L' : 'DVTK_QR_SCU:11113'})
filePath - string. DICOM file location.
receivingIp - string. DICOM Service Control Provider (SCP) IP.
receivingPort - string. DICOM Service Control Provider (SCP) port.
receivingAE - string. DICOM Service Control Provider (SCP) application entity.
options - dictionary. Multiple send settings in the form of the python dictionary.
MDLink is distributed with Google's X12 library . Here we provide some wrapper functions for that library, for convenience. Full documentation on this library is here.
X12Simple x12ParseTransactionFromFile(string filePath)
Reads a file on disk and turns it into a parsed X12 object.
filePath - Absolute path (i.e. directory and filename) of the file in question.
An 'X12Simple' object.
X12Simple x12ParseTransactionFromString(string x12Transaction)
Parses an X12 string.
x12Transaction - An X12 transaction in string format.
An 'X12Simple' object.
x12WriteTransactionToFile(string filePath, X12Simple x12Transaction)
Writes an X12 transaction object to a file.
filePath - Absolute path (i.e. directory and filename) of the file in question.
x12Transaction - An X12 transaction object.
string addToDate(string date, string field, int amount)
Add the amount to the date field. For example:
util.addToDate('20110216', 'DAY', 3)
returns '20110219'.
date - accept strings of the form yyyyMMdd.
field - should be one of ['YEAR', 'MONTH', 'DAY'].
amount - value to add to date field.
a string representation of the provided date after addition.
string addToTime(string time, string field, int amount)
Add the amount to the time field. For example:
util.addToTime('093420', 'MINUTE', -4)
returns '093020'.
time - accept strings of the form HHmmssSSS format (ss and SSS are optional).
field - should be one of ['HOUR', 'MINUTE', 'SECOND', 'MILLISECOND'].
amount - value to add to time field.
a string representation of the provided time after addition.
string addToDateTime(string dateTime, string field, int amount)
Add the amount to the dateTime field. For example:
util.addToDateTime('20120216093420347', 'MILLISECOND', -36)
returns '20120216093420311'.
dateTime - accept strings of the form yyyyMMddHHmmssSSS format (ss and SSS are optional).
field - should be one of ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND', 'MILLISECOND'].
amount - value to add to dateTime field.
a string representation of the provided dateTime after addition.
int yearsBetween(string oldDate, string newDate)
Calculate the number of years between oldDate and newDate. For example:
util.yearsBetween('19820915', '19960222')
returns 13.
oldDate - accept strings of the form yyyyMMdd.
newDate - accept strings of the form yyyyMMdd.
the number of years between oldDate and newDate.
Returns the age of a person, given their date of birth. For example:
util.age('19470318')
returns 66.
birthDate - accept strings of the form yyyyMMdd.
the age.
string getCurrentDateTime(string dateTimeFormat)
Get the current date time in the specified dateTimeFormat. For example:
util.getCurrentDateTime('yyyy-MM-dd-HH:mm:ss:SSS')
returns '2011-03-28-16:57:21:508'.
util.getCurrentDateTime("'Today is' dd 'and time is' HH:mm")
returns 'Today is 28 and time is 17:02'.
dateTimeFormat - accept strings in any form.'yyyy-MM-dd-HH', 'yyyy/MM/dd', 'HH:mm:ss:SSS' , "'Current time is' HH:mm" , etc. For more formatting tips refer to SimpleDateFormat javadoc.
the current date time in the specified dateTimeFormat.
string convertDateTimeFormat(string dateTime, string oldFormat, string newFormat)
Convert the specified dateTime into the newFormat. For example:
util.convertDateTimeFormat('10 11 2005', 'MM dd yyyy', 'yyyy-MM-dd')
returns '2005-10-11'.
util.convertDateTimeFormat('24/09-07 30/45:678', 'dd/MM-hh mm/ss:SSS', 'MM-dd-HH:mm:ss:SSS')
returns '09-24-07:30:45:678'.
dateTime - dateTime in the oldFormat. Accept strings in any form.'yyyy-MM-dd-HH', 'yyyy/MM/dd', 'HH:mm:ss:SSS' , "'Current time is' HH:mm" , etc. For more formatting tips refer to SimpleDateFormat javadoc.
oldFormat - format of dateTime. Accept strings in any form.'yyyy-MM-dd-HH', 'yyyy/MM/dd', 'HH:mm:ss:SSS' , "'Current time is' HH:mm" , etc. For more formatting tips refer to SimpleDateFormat javadoc.
newFormat - desired return date format.
a string representation of the provided dateTime in newFormat.
The number of milliseconds since the UNIX epoch (00:00:00 UTC January 1, 1970).
The number of seconds since the UNIX epoch (00:00:00 UTC January 1, 1970).
There are several functions for comparing dates and time strings. They all accept two string argument and return a boolean. Functions starting with 'date' accept strings of the form yyyyMMdd. Functions starting with 'time' accept strings of the form HHmmssSSS format (ss and SSS are optional). Functions starting with 'dateTime' accept strings of the form yyyyMMddHHmmssSSS format (ss and SSS are optional). Use these functions like this:
if util.timeIsGreaterThanOrEqualTo(timeFromMsg, '1200'):
...
The complete list of available functions is:
LookupTable createLookupTable(string path, ...)
Creates a new lookup object. The path parameter is mandatory. Other optional parameters are:
ignorecase, keycolumn, valuecolumn, delimiter, escape_char_for_doublequotes, reread_file_if_modified, defaultvalue, and defaultaction.
Among defaultvalue and defaultaction, only one should be provided. If neither defaultvalue nor defaultaction is provided as parameter, then default behavior on a nonexisting key is to fail execution. Optional parameters can be provided in any order. For example:
path = r'c:\cygwin\tmp\lookup.csv'
Creates a lookup with default values for optional parameters.
lookup = util.createLookupTable(path)
value = lookup.getValue('abc') #returns value for key = 'abc'.
Creates a lookup with keycolumn = 2, valuecolumn = 1 and returns value 'XYZ' for a nonexisting key.
lookup = util.createLookupTable(path, keycolumn = 2, valuecolumn = 1, defaultvalue = 'XYZ')
Creates a lookup which ignores case, uses backslash as escape char for double quotes and cancels execution on a nonexisting key.
lookup = util.createLookupTable(path, ignorecase = True, escape_char_for_doublequotes = '\\', defaultaction = 'cancel')
Creates a lookup which uses tab as delimiter and updates lookup if the file is modified.
lookup = util.createLookupTable(path, delimiter = '\t', reread_file_if_modified = True)
Note: For better performance create the lookup table object in the 'Load' script, rather than the beginning of the 'Run' script.
path - Absolute path to the lookup file. For example r'c:\cygwin\tmp\lookup.csv'
ignorecase - boolean. If set to True, ignores upper- and lower-case during key lookup. (default is False).
keycolumn - integer. Index of 'key' column. (default is 1).
valuecolumn - integer. Index of 'value' column. (default is 2).
delimiter - string (1 character only). Delimiter that separates fields. (default is ',').
escape_char_for_doublequotes - string (1 character only.) Escape character for double quotes. Accepts two values (default is ") and other is backslash '\\'.
reread_file_if_modified - boolean. If true, then the source lookup file will be re-read (and the lookup object's set key/value pairs fully updated) if the file is ever modified while the solution is running. (default is False).
defaultvalue - string. If provided, then getValue() will return this if the key argument does not exist in the lookup table.
defaultaction - string. Like the 'defaultvalue' option, this determines the behavior in the case where the key argument does not exist in the lookup table. This option allows you to specify an action other than outputting a constant string, as 'defaultvalue' does. Valid values are 'passthrough' (which will output the input value), 'cancel' (cancel the task execution), and 'fail' (fail the execution). Default is 'fail'.
a lookup object.
list splitTextByWidth(string text, int width)
Split the text by width. For example:
util.splitTextByWidth('The erythrocyte sedimentation rate (ESR), also called a sedimentation rate or Westergren ESR.', 30)
returns list - ['The erythrocyte ', 'sedimentation rate (ESR)', ', also called a sedimentation ', 'rate or Westergren ESR.'].
text - content to split.
width - max line length.
a list of strings.
string fileToString(string filepath)
Read the contents of a file, and return the contents as a string.
filepath - The absolute path (i.e. directory and filename) of the file you want to read.
The contents of that file, as a string.
string stringToFile(string filepath, string contents)
Write a string to a file.
filepath - The absolute path (i.e. directory and filename) of the file you want to write to. If this file already exists, it will be overwritten.
contents - The string that you want to write to the file.