-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcsv_hl7.py
64 lines (40 loc) · 1.23 KB
/
csv_hl7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# coding: utf-8
# In[1]:
#ashley hetrick, ahetrick@illinois.edu
#2020-03-30
# In[2]:
#import libraries
get_ipython().run_line_magic('pip', 'install hl7apy')
import csv
from hl7apy.core import Message
# In[3]:
#function definitions
def make_hl7(filename):
messages = []
with open(filename,newline='',encoding='utf-8-sig') as f:
reader = csv.reader(f, delimiter=',', quotechar='|')
for row in reader:
m = Message("ADT_A01",version='2.7')
m.msh.msh_3 = row[0]
m.pid.pid_3.pid_3_1 = row[1]
m.pid.pid_3.pid_3_2 = row[2]
m.pid.pid_3.pid_3_3 = row[3]
m.pid.pid_3.pid_3_4 = row[4]
m.pid.pid_5.pid_5_1 = row[5]
m.pid.pid_5.pid_5_2 = row[6]
m.pid.pid_5.pid_5_3 = row[7]
messages.append(m)
return messages
# In[4]:
def output_csv(hl7_object):
with open('hl7_messages.csv', 'w') as csvfile:
csvwriter = csv.writer(csvfile)
for message in hl7_object:
csvwriter.writerow([message.msh.to_er7() + message.pid.to_er7()])
# In[5]:
def main(filename):
output_csv(make_hl7(filename))
# In[6]:
#call to main function
main('data/csv_to_hl7.csv')