import xml.dom.minidom import time #Helpers def v3Indent(i): return i * '\t' def getText(nodelist): rc = "" for node in nodelist: if node.nodeType == node.TEXT_NODE: rc = rc + node.data return rc def getElement(Parent, Property): PropertyTag = Parent.getElementsByTagName(Property)[0] return getText(PropertyTag.childNodes) def getItem(DomMessage, TableName, Index, ColumnName): Table = DomMessage.getElementsByTagName(TableName)[Index] ColumnTag = Table.getElementsByTagName(ColumnName)[0] return getText(ColumnTag.childNodes) def getTableElement(DomMessage, TableName, Index, ColumnName): Table = DomMessage.getElementsByTagName(TableName)[Index] ColumnTag = Table.getElementsByTagName(ColumnName)[0] return Table, getText(ColumnTag.childNodes) #Functions that generate the different parts of the CDA document def BeginDocument(): value = '\n' value += '\n' return value def Header(): value = '\n' return value def typeID(): value = '\n' return value def id(): value = '\n' return value def code(): value = '\n' return value def effectiveTime(): value = '\n' return value def confidentialityCode(): value = '\n' return value def recordTarget(FirstName, LastName): value = '\n' value += v3Indent(1) + '\n' value += v3Indent(2) + '\n' value += v3Indent(2) + '\n' value += v3Indent(3) + '\n' value += v3Indent(4) + '' + FirstName + '\n' value += v3Indent(4) + '' + LastName + '\n' value += v3Indent(4) + '' + 'Senior' + '\n' value += v3Indent(3) + '\n' value += v3Indent(3) + '\n' value += v3Indent(3) + '\n' value += v3Indent(2) + '\n' value += v3Indent(2) + '\n' value += v3Indent(3) + '\n' value += v3Indent(2) + '\n' value += v3Indent(1) + '\n' value += v3Indent(0) + '\n' return value def author(): value = '\n' value += v3Indent(1) + '\n' return value def custodian(): value = '\n' value += v3Indent(1) + '\n' value += v3Indent(2) + '\n' value += v3Indent(3) + '\n' value += v3Indent(2) + '\n' value += v3Indent(1) + '\n' value += '\n' return value def Body(): value = '\n' value += '\n' value += v3Indent(1) + '\n' value += v3Indent(2) + '\n' value += v3Indent(3) + '
\n' value += v3Indent(4) + '\n' value += v3Indent(4) + 'History of Present Illness\n' value += v3Indent(4) + '\n' value += v3Indent(5) + 'Henry Levin, the 7th\n' value += v3Indent(5) + 'is a 67 year old male referred for further asthma management.\n' value += v3Indent(5) + 'Onset of asthma in his twenties\n' value += v3Indent(5) + 'teens.\n' value += v3Indent(5) + 'He was hospitalized twice last year, and already twice this year.\n' value += v3Indent(5) + 'He has not been able to be weaned off steroids for the past several\n' value += v3Indent(5) + 'He was hospitalized twice last year, and already twice this year.\n' value += v3Indent(5) + 'months.\n' value += v3Indent(4) + '\n' value += v3Indent(3) + '
\n' value += v3Indent(2) + '
\n' value += v3Indent(1) + '
\n' value += v3Indent(0) + '
\n' return value def EndDocument(): value = '
\n' return value def V2toCDA(PlainDataXml): InMsg = xml.dom.minidom.parseString(PlainDataXml) v3 = BeginDocument() v3 += Header() v3 += typeID() v3 += id() v3 += code() v3 += effectiveTime() v3 += confidentialityCode() v3 += recordTarget(getItem(InMsg, "Patient", 0, "PatientFirstName"), getItem(InMsg, "Patient", 0, "PatientLastName")) v3 += author() v3 += custodian() v3 += Body() v3 += EndDocument() return v3 value = V2toCDA(value[3:])