Skip to main content

A simple HL7 parser

Project description

hl7parser - Parse HL7-Messages in Python

Build Status

hl7-parser is a parser for HL7 (Health Level 7) messages. It also has limited support for constructing messages.

Installation

hl7parser is available through PyPi and can be installed using pip: pip install hl7-parser

It is currently limited to Python 2.7, but Python 3 support will follow soon.

Usage

Parsing Messages

# This is an example message taken from the HL7 Wikipedia article
>>> message_text = """
... MSH|^~\&|MegaReg|XYZHospC|SuperOE|XYZImgCtr|20060529090131-0500||ADT^A01^ADT_A01|01052901|P|2.5
... EVN||200605290901||||200605290900
... PID|||56782445^^^UAReg^PI||KLEINSAMPLE^BARRY^Q^JR||19620910|M||2028-9^^HL70005^RA99113^^XYZ|260 GOODWIN CREST DRIVE^^BIRMINGHAM^AL^35209^^M~NICKELL’S PICKLES^10000 W 100TH AVE^BIRMINGHAM^AL^35200^^O|||||||0105I30001^^^99DEF^AN
... PV1||I|W^389^1^UABH^^^^3||||12345^MORGAN^REX^J^^^MD^0010^UAMC^L||67890^GRAINGER^LUCY^X^^^MD^0010^UAMC^L|MED|||||A0||13579^POTTER^SHERMAN^T^^^MD^0010^UAMC^L|||||||||||||||||||||||||||200605290900
... OBX|1|NM|^Body Height||1.80|m^Meter^ISO+|||||F
... OBX|2|NM|^Body Weight||79|kg^Kilogram^ISO+|||||F
... AL1|1||^ASPIRIN
... DG1|1||786.50^CHEST PAIN, UNSPECIFIED^I9|||A
... """.strip()

>>> from hl7parser.hl7 import HL7Message
>>> msg = HL7Message(message_text)
# access segments and their fields by name
>>> msg.evn.recorded_datetime.isoformat()
'2006-05-29T09:01:00'
# .. or index (
>>> msg.evn[1].isoformat()
'2006-05-29T09:01:00'

# repeating fields 
>>> str(msg.pid.patient_name[0])
'KLEINSAMPLE^BARRY^Q^JR'
# subfields
>>> str(msg.pid.patient_name[0][1])
'BARRY'

Some common segments are pre-defined and hl7parser will validate input on the fields:

  • MSH - Message Header
  • MSA - Message Acknowledgement
  • EVN - Event Type
  • PID - Patient Identification
  • PV1 - Patient Visit
  • and others

Segments which are not defined, will still work, but will lack input validation and you won't be able to access fields by name.

If you need support for other segments, file an issue or send a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hl7parser-0.6.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hl7parser-0.6.1-py2-none-any.whl (15.4 kB view details)

Uploaded Python 2

File details

Details for the file hl7parser-0.6.1.tar.gz.

File metadata

  • Download URL: hl7parser-0.6.1.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.12

File hashes

Hashes for hl7parser-0.6.1.tar.gz
Algorithm Hash digest
SHA256 c6e9208899bf9792d0b94fe179caa7ab8fadb8a7628796e770e25b9db946a609
MD5 0202c427311fb88f16fc7cf231821ad2
BLAKE2b-256 79e27fb4dec5580c0d7bb07636e23b4dec6aebcd1b6d84ff3ca92fd79a2b8054

See more details on using hashes here.

File details

Details for the file hl7parser-0.6.1-py2-none-any.whl.

File metadata

  • Download URL: hl7parser-0.6.1-py2-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.12

File hashes

Hashes for hl7parser-0.6.1-py2-none-any.whl
Algorithm Hash digest
SHA256 e26fe28908ea864c25752e6b94629f8e972931ca378be2ee9a6432b2d61c080a
MD5 693a733bca292732894f270faec9cea7
BLAKE2b-256 89f85fa3ac252515cbe397d0f7190cca532b66487fef35e432f16d2f047f909e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page