-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Sarfati
committed
Jun 21, 2015
0 parents
commit 5253ab2
Showing
6 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Source Files for *Python, HL7 v2.x and HL7apy* | ||
|
||
Michael Sarfati, June 2015 | ||
michael.sarfati@utoronto.ca | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Michael Sarfati (michael.sarfati@utoronto.ca), June 20, 2015 | ||
# http://msarfati.wordpress.com | ||
|
||
from hl7apy import parser | ||
from hl7apy.exceptions import UnsupportedVersion | ||
|
||
hl7 = open('sample.hl7', 'r').read() | ||
|
||
try: | ||
m = parser.parse_message(hl7) | ||
except UnsupportedVersion: | ||
m = parser.parse_message(hl7.replace("\n", "\r")) | ||
|
||
import datetime | ||
incoming_hl7 = { | ||
"type": m.msh.msh_9.value, | ||
"client_app": m.msh.msh_3.value, | ||
"client_fac": m.msh.msh_4.value, | ||
"control_id": m.msh.msh_10.value, | ||
"process_id": m.msh.msh_11.value, | ||
"timestamp": datetime.datetime.strptime(m.msh.msh_7.value, "%Y%m%d%H%M%S%f"), | ||
"hl7": m, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MSH|^~\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|2007509101832132||ADT^A01^ADT_A01|200760910183213200723|D|2.5 | ||
EVN||2007509101832132 | ||
PID|1||P410000^^^||""||196505|M|||^^^OR^97007 | ||
PV1|1|I||||||||||||||||||||||||||||||||||||||||||200750816122536 | ||
PV2|||^^^^POSSIBLE MENINGITIS OR CVA | ||
OBX|1|NM|21612-7^REPORTED PATIENT AGE^LN||40|a^Year^UCUM|||||F | ||
DG1|1||784.3^APHASIA^I9C||200750816|A | ||
DG1|2||784.0^HEADACHE^I9C||200750816|A | ||
DG1|3||781.6^MENINGISMUS^I9C||200750816|A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Michael Sarfati (michael.sarfati@utoronto.ca), June 21, 2015 | ||
# http://msarfati.wordpress.com | ||
""" | ||
This script constructs an HL7 ORM^O01 message of the following form: | ||
MSH|^~\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|20150414173000||ORM^O01^ORM_O01|168715|P|2.5 | ||
PID|1|A-10001||B-10001|Doe^John | ||
ORC|||||||||20150414120000 | ||
OBR|1|1|1100||||||||||| | ||
""" | ||
|
||
from hl7apy import core | ||
|
||
hl7 = core.Message("ORM_O01") | ||
|
||
hl7.msh.msh_3 = "SendingApp" | ||
hl7.msh.msh_4 = "SendingFac" | ||
hl7.msh.msh_5 = "ReceivingApp" | ||
hl7.msh.msh_6 = "ReceivingFac" | ||
hl7.msh.msh_9 = "ORM^O01^ORM_O01" | ||
hl7.msh.msh_10 = "168715" | ||
hl7.msh.msh_11 = "P" | ||
|
||
# PID | ||
hl7.add_group("ORM_O01_PATIENT") | ||
hl7.ORM_O01_PATIENT.pid.pid_2 = "1" | ||
hl7.ORM_O01_PATIENT.pid.pid_3 = "A-10001" | ||
hl7.ORM_O01_PATIENT.pid.pid_5 = "B-10001" | ||
hl7.ORM_O01_PATIENT.pid.pid_6 = "DOE^JOHN" | ||
|
||
# ORC | ||
hl7.ORM_O01_ORDER.orc.orc_1 = "1" | ||
hl7.ORM_O01_ORDER.ORC.orc_10 = "20150414120000" | ||
|
||
# OBR | ||
# We must explicitly add the OBR segment, then populate fields | ||
hl7.ORM_O01_ORDER.ORM_O01_ORDER_DETAIL.ORM_O01_OBSERVATION.ORM_O01_ORDER_CHOICE.add_segment("OBR") | ||
|
||
hl7.ORM_O01_ORDER.ORM_O01_ORDER_DETAIL.ORM_O01_OBSERVATION.ORM_O01_ORDER_CHOICE.OBR.obr_2 = "1" | ||
hl7.ORM_O01_ORDER.ORM_O01_ORDER_DETAIL.ORM_O01_OBSERVATION.ORM_O01_ORDER_CHOICE.OBR.obr_3 = "2" | ||
hl7.ORM_O01_ORDER.ORM_O01_ORDER_DETAIL.ORM_O01_OBSERVATION.ORM_O01_ORDER_CHOICE.OBR.obr_4 = "1100" | ||
|
||
assert hl7.validate() is True | ||
# Returns True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MSH|^~\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|20150414173000||ORM^O01^ORM_O01|168715|P|2.5 | ||
PID|1|A-10001||B-10001|Doe^John | ||
ORC|||||||||20150414120000 | ||
OBR|1|1|1100||||||||||| |