In [9]:
text = "MSH|^~\&|CERNER||PriorityHealth||||ORU^R01|Q479004375T431430612|P|2.3"

In [44]:
text_array_1 = text.split(sep="|")
tex_array_1


Out[44]:
[['MSH'],
 ['', '~\\&'],
 ['CERNER'],
 [''],
 ['PriorityHealth'],
 [''],
 [''],
 [''],
 ['ORU', 'R01'],
 ['Q479004375T431430612'],
 ['P'],
 ['2.3']]

In [11]:
text_array_2 = list(map(lambda x: x.split(sep="^"), text_array))

In [12]:
text_array_2


Out[12]:
[['MSH'],
 ['', '~\\&'],
 ['CERNER'],
 [''],
 ['PriorityHealth'],
 [''],
 [''],
 [''],
 ['ORU', 'R01'],
 ['Q479004375T431430612'],
 ['P'],
 ['2.3']]

In [15]:
text_array_2[8][1]


Out[15]:
'R01'

In [47]:
text2 = open("Sample_redone.txt", "r")
text3 = text2.read()

In [68]:
#text3a = text3.split(sep="^")
#text3a

In [69]:
text4 = text3.split(sep="/m")
text4


Out[69]:
['MSH|^~\\&|CERNER||PriorityHealth||||ORU^R01|Q479004375T431430612|P|2.3',
 'PID|||001677980||SMITH^CURTIS||19680219|M||||||||||929645156318|123456789',
 'PD1||||1234567890^LAST^FIRST^M^^^^^NPI',
 'OBR|1|341856649^HNAM_ORDERID|000002006326002362|648088^Basic Metabolic Panel||',
 '20061122151600|||||||||1620^Hooker^Robert^L||||||20061122154733|||F|||||||||||20061122140000',
 'OBX|1|NM|GLU^Glucose Lvl|59|mg/dL|65-99^65^99|L|||F|||20061122154733/n']

In [71]:
text5 = list(map(lambda x: x.split(sep="|"), text4))
text5[0]


Out[71]:
['MSH',
 '^~\\&',
 'CERNER',
 '',
 'PriorityHealth',
 '',
 '',
 '',
 'ORU^R01',
 'Q479004375T431430612',
 'P',
 '2.3']

In [76]:
list(map(lambda x: text5[x], text5))


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-76-8568734f5f09> in <module>()
----> 1 list(map(lambda x: text5[x], text5))

<ipython-input-76-8568734f5f09> in <lambda>(x)
----> 1 list(map(lambda x: text5[x], text5))

TypeError: list indices must be integers or slices, not list

In [73]:
text6 = list(map(lambda x: x.split(sep="^"), map(lambda x: text5[x], text5))


  File "<ipython-input-73-3c428c780b3b>", line 1
    text6 = list(map(lambda x: x.split(sep="^"), map(lambda x: text5[x]))
                                                                         ^
SyntaxError: unexpected EOF while parsing

In [50]:
text_final_1 = text3.split(sep="|")

In [52]:
text_finial_2 = list(map(lambda x: x.split(sep="/m"), text_final_1))
text_finial_2


Out[52]:
[['MSH'],
 ['^~\\&'],
 ['CERNER'],
 [''],
 ['PriorityHealth'],
 [''],
 [''],
 [''],
 ['ORU^R01'],
 ['Q479004375T431430612'],
 ['P'],
 ['2.3', 'PID'],
 [''],
 [''],
 ['001677980'],
 [''],
 ['SMITH^CURTIS'],
 [''],
 ['19680219'],
 ['M'],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 ['929645156318'],
 ['123456789', 'PD1'],
 [''],
 [''],
 [''],
 ['1234567890^LAST^FIRST^M^^^^^NPI', 'OBR'],
 ['1'],
 ['341856649^HNAM_ORDERID'],
 ['000002006326002362'],
 ['648088^Basic Metabolic Panel'],
 [''],
 ['', '20061122151600'],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 ['1620^Hooker^Robert^L'],
 [''],
 [''],
 [''],
 [''],
 [''],
 ['20061122154733'],
 [''],
 [''],
 ['F'],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 [''],
 ['20061122140000', 'OBX'],
 ['1'],
 ['NM'],
 ['GLU^Glucose Lvl'],
 ['59'],
 ['mg/dL'],
 ['65-99^65^99'],
 ['L'],
 [''],
 [''],
 ['F'],
 [''],
 [''],
 ['20061122154733/n']]

In [ ]: