finds.dev← search

// the find

senaranya/HL7

★ 199 · PHP · MIT · updated Sep 2026

PHP library for Parsing, Generation and Sending HL7 v2 messages

A PHP 8.2+ library for building, parsing, and sending HL7 v2 messages, aimed at PHP services that exchange messages with hospital and lab systems. It covers the client side: construct or parse a message, modify it, serialize it, and send it over a socket to a listener. It has no listener of its own, so the receiving loop is yours to write, though it can build the ACK you send back.

The parse, modify, serialize loop works on one Message object, so you can read an inbound message, change a field, and write it back out without splitting pipes by hand. The defined segment classes, about 30 of them, expose setters at the standard HL7 v2.3 positions, so setPatientName writes PID-5 and you never count fields. The ACK class builds a response directly from an inbound message, which is the step hand-rolled code tends to skimp on. The version table and the 3.x to 4.0 upgrade guide say plainly what breaks, and withHL7Version lets you target a specific HL7 version.

Empty subfields are removed by default, and keepEmptySubfields is opt-in until a future version flips it. An empty component can carry meaning by its position, so a parse and re-serialize round trip can change a message the receiving system then reads differently, with no error raised. The API is mid-migration: resetIndices, resetSegmentIndices, and reindexSegments overlap, new Message and setSegment are deprecated, and SEGMENT_ENDING_BAR is deprecated in favor of WITH_SEGMENT_ENDING_FIELD_SEPARATOR. The examples also check results with string tricks, str_contains for MSH to decide a send worked and $ackCode[1] for the acknowledgement code, which will misbehave on an empty or unexpected ACK. Connection is synchronous with a 10-second default timeout and needs ext-sockets, and the README says nothing about retries, TLS, or what a caller should do after a timeout.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →