Giter Site home page Giter Site logo

hl7-parser's Introduction

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.

To see what's new in each version, please refer to the CHANGELOG.md file in the repository.

Installation

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

It supports Python 2.7 and Python >=3.5 (as of version 0.7).

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.

hl7-parser's People

Contributors

klugjohannes avatar mtraub80 avatar niklasmm avatar rectalogic avatar testingcan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hl7-parser's Issues

HL7 Datetime fails to parse DTM with precision filed

If the optional precision at the DTM data filed is not empty, the given datetime (DTM) can not be parsed,instead a ValueError is raised.

Example hl7 message to reproduce the error:

MSH|^~\&|||||||ADT^A01|12346789|P|2.7|
EVN|A01|20190924143134^YYYYMMDDHHMMSS||
PID|||59wrtt0w9suJ-^foo^bar||Hilde^Held||19660119|F|||||||||||||
PV1||0|7697^69^^MED2||||||||||||||||744784|||||||||||||||||||||||||20190916143134920350||
IN1|1||00818903|TKK||||4||||||||||||||||||||||||||||00597522|

Parser fails when parsing malformatted date/time field

The following message contains a datetime field with the value ""

PV1||I|XXX^^^XXX||30245245|||||0|||||||11|S|30245245||K|||K|||||||||||||||99196|||XXX^XXX||20160926060000|""|||||30245245

This causes the parser to fail ungracefully.
A fix should be made to treat this as an empty field.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.